Skip to content

Commit 301f91a

Browse files
committed
Extract QueueInput
1 parent 148dae8 commit 301f91a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+796
-716
lines changed

integration-tests/examples/encoded_channel_output.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,17 @@ fn main() {
7979
}),
8080
};
8181

82-
let input_options = RegisterInputOptions {
83-
input_options: ProtocolInputOptions::Mp4(Mp4InputOptions {
84-
source: Mp4InputSource::File(root_dir.join(BUNNY_FILE_PATH).into()),
85-
should_loop: false,
86-
video_decoders: Mp4InputVideoDecoders {
87-
h264: Some(VideoDecoderOptions::FfmpegH264),
88-
},
89-
buffer: InputBufferOptions::Const(None),
90-
seek: None,
91-
}),
92-
queue_options: QueueInputOptions {
93-
required: true,
94-
offset: Some(Duration::ZERO),
82+
let input_options = RegisterInputOptions::Mp4(Mp4InputOptions {
83+
source: Mp4InputSource::File(root_dir.join(BUNNY_FILE_PATH).into()),
84+
should_loop: false,
85+
video_decoders: Mp4InputVideoDecoders {
86+
h264: Some(VideoDecoderOptions::FfmpegH264),
9587
},
96-
};
88+
buffer: InputBufferOptions::Const(None),
89+
seek: None,
90+
required: true,
91+
offset: Some(Duration::ZERO),
92+
});
9793

9894
Pipeline::register_input(&state.pipeline().unwrap(), input_id.clone(), input_options).unwrap();
9995

integration-tests/examples/raw_channel_input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![recursion_limit = "256"]
2+
13
use core::panic;
24
use std::{
35
sync::{Arc, Mutex},
@@ -91,8 +93,6 @@ fn main() {
9193
video: true,
9294
audio: false,
9395
buffer_duration: None,
94-
},
95-
QueueInputOptions {
9696
required: true,
9797
offset: Some(Duration::ZERO),
9898
},

integration-tests/examples/raw_channel_output.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,17 @@ fn main() {
9090
}),
9191
};
9292

93-
let input_options = RegisterInputOptions {
94-
input_options: ProtocolInputOptions::Mp4(Mp4InputOptions {
95-
source: Mp4InputSource::File(integration_tests_root().join(BUNNY_FILE_PATH).into()),
96-
should_loop: false,
97-
video_decoders: Mp4InputVideoDecoders {
98-
h264: Some(VideoDecoderOptions::FfmpegH264),
99-
},
100-
buffer: InputBufferOptions::Const(None),
101-
seek: None,
102-
}),
103-
queue_options: QueueInputOptions {
104-
required: true,
105-
offset: Some(Duration::ZERO),
93+
let input_options = RegisterInputOptions::Mp4(Mp4InputOptions {
94+
source: Mp4InputSource::File(integration_tests_root().join(BUNNY_FILE_PATH).into()),
95+
should_loop: false,
96+
video_decoders: Mp4InputVideoDecoders {
97+
h264: Some(VideoDecoderOptions::FfmpegH264),
10698
},
107-
};
99+
buffer: InputBufferOptions::Const(None),
100+
seek: None,
101+
required: true,
102+
offset: Some(Duration::ZERO),
103+
});
108104

109105
Pipeline::register_input(&pipeline, input_id.clone(), input_options).unwrap();
110106

integration-tests/examples/v4l2_rust_api.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![recursion_limit = "256"]
2+
13
#[cfg(not(target_os = "linux"))]
24
fn main() {
35
panic!("Your OS does not support Video for Linux 2.");
@@ -63,18 +65,13 @@ mod main_module {
6365
.find(|d| d.formats.iter().any(|f| f.format == V4l2Format::Yuyv))
6466
.expect("no device supports the required format");
6567

66-
RegisterInputOptions {
67-
input_options: ProtocolInputOptions::V4l2(V4l2InputOptions {
68-
path: device.path,
69-
resolution: Some(VIDEO_RESOLUTION),
70-
format: V4l2Format::Yuyv,
71-
framerate: Some(Framerate { num: 30, den: 1 }),
72-
}),
73-
queue_options: QueueInputOptions {
74-
required: false,
75-
offset: None,
76-
},
77-
}
68+
RegisterInputOptions::V4l2(V4l2InputOptions {
69+
path: device.path,
70+
resolution: Some(VIDEO_RESOLUTION),
71+
format: V4l2Format::Yuyv,
72+
framerate: Some(Framerate { num: 30, den: 1 }),
73+
required: false,
74+
})
7875
}
7976

8077
#[cfg(target_os = "linux")]

integration-tests/src/bin/benchmark/benchmark_pass.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,17 @@ impl SingleBenchmarkPass {
285285
Pipeline::register_input(
286286
pipeline,
287287
input_id.clone(),
288-
RegisterInputOptions {
289-
input_options: ProtocolInputOptions::Mp4(Mp4InputOptions {
290-
should_loop: true,
291-
video_decoders: Mp4InputVideoDecoders {
292-
h264: Some(self.decoder),
293-
},
294-
source: Mp4InputSource::File(path.to_path_buf().into()),
295-
buffer: InputBufferOptions::Const(None),
296-
seek: None,
297-
}),
298-
queue_options: QueueInputOptions {
299-
offset: None,
300-
required: true,
288+
RegisterInputOptions::Mp4(Mp4InputOptions {
289+
should_loop: true,
290+
video_decoders: Mp4InputVideoDecoders {
291+
h264: Some(self.decoder),
301292
},
302-
},
293+
source: Mp4InputSource::File(path.to_path_buf().into()),
294+
buffer: InputBufferOptions::Const(None),
295+
seek: None,
296+
required: true,
297+
offset: None,
298+
}),
303299
)
304300
}
305301

@@ -315,10 +311,8 @@ impl SingleBenchmarkPass {
315311
video: true,
316312
audio: false,
317313
buffer_duration: None,
318-
},
319-
QueueInputOptions {
320-
offset: None,
321314
required: true,
315+
offset: None,
322316
},
323317
)?;
324318

smelter-api/src/input/decklink_into.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ impl TryFrom<DeckLink> for core::RegisterInputOptions {
66

77
#[cfg(feature = "decklink")]
88
fn try_from(value: DeckLink) -> Result<Self, Self::Error> {
9-
use super::queue_options::new_queue_options;
109
const ID_PARSE_ERROR_MESSAGE: &str =
1110
"\"persistent_id\" has to be a valid 32-bit hexadecimal number";
1211

@@ -20,16 +19,16 @@ impl TryFrom<DeckLink> for core::RegisterInputOptions {
2019
None => None,
2120
};
2221

23-
Ok(core::RegisterInputOptions {
24-
input_options: core::ProtocolInputOptions::DeckLink(core::DeckLinkInputOptions {
22+
Ok(core::RegisterInputOptions::DeckLink(
23+
core::DeckLinkInputOptions {
2524
subdevice_index: value.subdevice_index,
2625
display_name: value.display_name,
2726
persistent_id,
2827
enable_audio: value.enable_audio.unwrap_or(true),
2928
pixel_format: Some(core::DeckLinkPixelFormat::Format8BitYUV),
30-
}),
31-
queue_options: new_queue_options(value.required, None)?,
32-
})
29+
required: value.required.unwrap_or(false),
30+
},
31+
))
3332
}
3433

3534
#[cfg(not(feature = "decklink"))]

smelter-api/src/input/hls_into.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ impl TryFrom<HlsInput> for core::RegisterInputOptions {
1414
decoder_map,
1515
} = value;
1616

17-
let queue_options = new_queue_options(required, offset_ms)?;
18-
19-
let buffer = match &queue_options {
20-
core::QueueInputOptions {
21-
required: false,
22-
offset: None,
23-
} => core::InputBufferOptions::Adaptive,
24-
_ => core::InputBufferOptions::None,
17+
let (required, offset) = new_queue_options(required, offset_ms)?;
18+
19+
let buffer = if !required && offset.is_none() {
20+
core::InputBufferOptions::Adaptive
21+
} else {
22+
core::InputBufferOptions::None
2523
};
2624

2725
let h264 = decoder_map
@@ -39,11 +37,10 @@ impl TryFrom<HlsInput> for core::RegisterInputOptions {
3937
url,
4038
video_decoders,
4139
buffer,
40+
required,
41+
offset,
4242
};
4343

44-
Ok(core::RegisterInputOptions {
45-
input_options: core::ProtocolInputOptions::Hls(input_options),
46-
queue_options,
47-
})
44+
Ok(core::RegisterInputOptions::Hls(input_options))
4845
}
4946
}

smelter-api/src/input/mp4_into.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ impl TryFrom<Mp4Input> for core::RegisterInputOptions {
2121

2222
const BAD_URL_PATH_SPEC: &str = "Exactly one of `url` or `path` has to be specified in a register request for an mp4 input.";
2323

24-
let queue_options = new_queue_options(required, offset_ms)?;
24+
let (required, offset) = new_queue_options(required, offset_ms)?;
2525

26-
let buffer = match &queue_options {
27-
core::QueueInputOptions {
28-
required: false,
29-
offset: None,
30-
} => core::InputBufferOptions::Const(None),
31-
_ => core::InputBufferOptions::None,
26+
let buffer = if !required && offset.is_none() {
27+
core::InputBufferOptions::Const(None)
28+
} else {
29+
core::InputBufferOptions::None
3230
};
3331

3432
let source = match (url, path) {
@@ -55,15 +53,14 @@ impl TryFrom<Mp4Input> for core::RegisterInputOptions {
5553
.transpose()
5654
.map_err(|err| TypeError::new(format!("Invalid duration. {err}")))?;
5755

58-
Ok(core::RegisterInputOptions {
59-
input_options: core::ProtocolInputOptions::Mp4(core::Mp4InputOptions {
60-
source,
61-
should_loop: should_loop.unwrap_or(false),
62-
video_decoders,
63-
buffer,
64-
seek,
65-
}),
66-
queue_options,
67-
})
56+
Ok(core::RegisterInputOptions::Mp4(core::Mp4InputOptions {
57+
source,
58+
should_loop: should_loop.unwrap_or(false),
59+
video_decoders,
60+
buffer,
61+
seek,
62+
required,
63+
offset,
64+
}))
6865
}
6966
}

smelter-api/src/input/queue_options.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use crate::*;
55
pub(super) fn new_queue_options(
66
required: Option<bool>,
77
offset_ms: Option<f64>,
8-
) -> Result<smelter_core::QueueInputOptions, TypeError> {
9-
Ok(smelter_core::QueueInputOptions {
10-
required: required.unwrap_or(false),
11-
offset: offset_ms
12-
.map(|offset_ms| Duration::try_from_secs_f64(offset_ms / 1000.0))
13-
.transpose()
14-
.map_err(|err| TypeError::new(format!("Invalid duration. {err}")))?,
15-
})
8+
) -> Result<(bool, Option<Duration>), TypeError> {
9+
let required = required.unwrap_or(false);
10+
let offset = offset_ms
11+
.map(|offset_ms| Duration::try_from_secs_f64(offset_ms / 1000.0))
12+
.transpose()
13+
.map_err(|err| TypeError::new(format!("Invalid duration. {err}")))?;
14+
Ok((required, offset))
1615
}

smelter-api/src/input/rtmp_into.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ impl TryFrom<RtmpInput> for core::RegisterInputOptions {
1515
decoder_map,
1616
} = value;
1717

18-
let queue_options = new_queue_options(required, offset_ms)?;
19-
20-
let buffer = match &queue_options {
21-
core::QueueInputOptions {
22-
required: false,
23-
offset: None,
24-
} => core::InputBufferOptions::Const(None),
25-
_ => core::InputBufferOptions::None,
18+
let (required, offset) = new_queue_options(required, offset_ms)?;
19+
20+
let buffer = if !required && offset.is_none() {
21+
core::InputBufferOptions::Const(None)
22+
} else {
23+
core::InputBufferOptions::None
2624
};
2725

2826
let h264 = decoder_map
@@ -39,11 +37,10 @@ impl TryFrom<RtmpInput> for core::RegisterInputOptions {
3937
stream_key,
4038
decoders: core::RtmpServerInputDecoders { h264 },
4139
buffer,
40+
required,
41+
offset,
4242
};
4343

44-
Ok(core::RegisterInputOptions {
45-
input_options: core::ProtocolInputOptions::RtmpServer(input_options),
46-
queue_options,
47-
})
44+
Ok(core::RegisterInputOptions::RtmpServer(input_options))
4845
}
4946
}

0 commit comments

Comments
 (0)