Skip to content

Commit b2f5f66

Browse files
committed
Refactor output types
1 parent 258fa42 commit b2f5f66

38 files changed

+3182
-3006
lines changed

compositor_api/src/output/whip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::*;
99
#[serde(deny_unknown_fields)]
1010
pub struct WhipOutput {
1111
/// WHIP server endpoint
12-
pub endpoint_url: String,
12+
pub endpoint_url: Arc<str>,
1313
// Bearer token
1414
pub bearer_token: Option<Arc<str>>,
1515
/// Video track configuration.

compositor_pipeline/src/error.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use compositor_render::{
66
InputId, OutputId,
77
};
88

9-
use crate::pipeline::{decoder::AacDecoderError, output::whip, VideoCodec};
9+
use crate::pipeline::{decoder::AacDecoderError, output::whip, AudioCodec, VideoCodec};
1010
use fdk_aac_sys as fdk;
1111

1212
#[derive(Debug, thiserror::Error)]
@@ -42,9 +42,6 @@ pub enum RegisterOutputError {
4242
#[error("Failed to register output stream. Stream \"{0}\" is already registered.")]
4343
AlreadyRegistered(OutputId),
4444

45-
#[error("Encoder error while registering output stream for stream \"{0}\".")]
46-
EncoderError(OutputId, #[source] EncoderInitError),
47-
4845
#[error("Output initialization error while registering output for stream \"{0}\".")]
4946
OutputError(OutputId, #[source] OutputInitError),
5047

@@ -85,9 +82,15 @@ pub enum UnregisterOutputError {
8582

8683
#[derive(Debug, thiserror::Error)]
8784
pub enum OutputInitError {
88-
#[error("An unsupported codec was requested: {0:?}.")]
85+
#[error("Failed to initialize encoder.")]
86+
EncoderError(#[from] EncoderInitError),
87+
88+
#[error("An unsupported video codec was requested: {0:?}.")]
8989
UnsupportedVideoCodec(VideoCodec),
9090

91+
#[error("An unsupported audio codec was requested: {0:?}.")]
92+
UnsupportedAudioCodec(AudioCodec),
93+
9194
#[error(transparent)]
9295
SocketError(#[from] std::io::Error),
9396

@@ -204,7 +207,6 @@ impl From<&RegisterInputError> for PipelineErrorInfo {
204207
}
205208

206209
const OUTPUT_STREAM_ALREADY_REGISTERED: &str = "OUTPUT_STREAM_ALREADY_REGISTERED";
207-
const ENCODER_ERROR: &str = "OUTPUT_STREAM_ENCODER_ERROR";
208210
const OUTPUT_ERROR: &str = "OUTPUT_STREAM_OUTPUT_ERROR";
209211
const UNSUPPORTED_RESOLUTION: &str = "UNSUPPORTED_RESOLUTION";
210212
const NO_VIDEO_OR_AUDIO_FOR_OUTPUT: &str = "NO_VIDEO_OR_AUDIO_FOR_OUTPUT";
@@ -216,15 +218,9 @@ impl From<&RegisterOutputError> for PipelineErrorInfo {
216218
RegisterOutputError::AlreadyRegistered(_) => {
217219
PipelineErrorInfo::new(OUTPUT_STREAM_ALREADY_REGISTERED, ErrorType::UserError)
218220
}
219-
220-
RegisterOutputError::EncoderError(_, _) => {
221-
PipelineErrorInfo::new(ENCODER_ERROR, ErrorType::ServerError)
222-
}
223-
224221
RegisterOutputError::OutputError(_, _) => {
225222
PipelineErrorInfo::new(OUTPUT_ERROR, ErrorType::ServerError)
226223
}
227-
228224
RegisterOutputError::UnsupportedResolution(_) => {
229225
PipelineErrorInfo::new(UNSUPPORTED_RESOLUTION, ErrorType::UserError)
230226
}

compositor_pipeline/src/pipeline.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ use crossbeam_channel::{bounded, Receiver};
2323
use glyphon::fontdb;
2424
use input::InputInitInfo;
2525
use input::RawDataInputOptions;
26+
use output::encoded_data::EncodedDataOutput;
27+
use output::new_external_output;
28+
use output::raw_data::RawDataOutput;
2629
use output::EncodedDataOutputOptions;
2730
use output::OutputOptions;
2831
use output::RawDataOutputOptions;
2932
use pipeline_output::register_pipeline_output;
33+
use pipeline_output::OutputInfo;
3034
use tokio::runtime::Runtime;
3135
use tokio::sync::oneshot;
3236
use tracing::{error, info, trace, warn};
@@ -311,9 +315,9 @@ impl Pipeline {
311315
register_pipeline_output(
312316
pipeline,
313317
output_id,
314-
&register_options.output_options,
315318
register_options.video,
316319
register_options.audio,
320+
|ctx, output_id| new_external_output(ctx, output_id, register_options.output_options),
317321
)
318322
}
319323

@@ -325,9 +329,13 @@ impl Pipeline {
325329
register_pipeline_output(
326330
pipeline,
327331
output_id,
328-
&register_options.output_options,
329332
register_options.video,
330333
register_options.audio,
334+
|ctx, output_id| {
335+
let (output, result) =
336+
EncodedDataOutput::new(output_id, ctx, register_options.output_options)?;
337+
Ok((Box::new(output), result))
338+
},
331339
)
332340
}
333341

@@ -339,9 +347,12 @@ impl Pipeline {
339347
register_pipeline_output(
340348
pipeline,
341349
output_id,
342-
&register_options.output_options,
343350
register_options.video,
344351
register_options.audio,
352+
|_ctx, _output_id| {
353+
let (output, result) = RawDataOutput::new(register_options.output_options)?;
354+
Ok((Box::new(output), result))
355+
},
345356
)
346357
}
347358

@@ -398,7 +409,13 @@ impl Pipeline {
398409
return Err(RequestKeyframeError::OutputNotRegistered(output_id.clone()));
399410
};
400411

401-
output.output.request_keyframe(output_id)
412+
match output.output.video() {
413+
Some(video) => video
414+
.keyframe_request_sender
415+
.send(())
416+
.map_err(|_| RequestKeyframeError::KeyframesUnsupported(output_id.clone())),
417+
None => Err(RequestKeyframeError::NoVideoOutput(output_id.clone())),
418+
}
402419
}
403420

404421
pub fn register_font(&self, font_source: fontdb::Source) {
@@ -443,17 +460,18 @@ impl Pipeline {
443460
}
444461
}
445462

446-
let (Some(resolution), Some(frame_format)) = (
447-
output.output.resolution(),
448-
output.output.output_frame_format(),
449-
) else {
463+
let Some(video_output) = output.output.video() else {
450464
return Err(UpdateSceneError::AudioVideoNotMatching(output_id));
451465
};
452466

453467
info!(?output_id, "Update scene {:#?}", scene_root);
454468

455-
self.renderer
456-
.update_scene(output_id, resolution, frame_format, scene_root)
469+
self.renderer.update_scene(
470+
output_id,
471+
video_output.resolution,
472+
video_output.frame_format,
473+
scene_root,
474+
)
457475
}
458476

459477
fn update_audio(
@@ -500,8 +518,15 @@ impl Pipeline {
500518
self.inputs.iter()
501519
}
502520

503-
pub fn outputs(&self) -> impl Iterator<Item = (&OutputId, &PipelineOutput)> {
504-
self.outputs.iter()
521+
pub fn outputs(&self) -> impl Iterator<Item = (&OutputId, OutputInfo)> {
522+
self.outputs.iter().map(|(id, output)| {
523+
(
524+
id,
525+
OutputInfo {
526+
kind: output.output.kind(),
527+
},
528+
)
529+
})
505530
}
506531
}
507532

0 commit comments

Comments
 (0)