macro_rules! impl_frame_push_stream_output {
($type:ident) => {
impl crate::output::StreamOutput for $type {
fn push_video(
&mut self,
frame: &ff_format::VideoFrame,
) -> Result<(), crate::error::StreamError> {
if self.finished {
return Err(crate::error::StreamError::InvalidConfig {
reason: "push_video called after finish()".into(),
});
}
let inner = self.inner.as_mut().ok_or_else(|| {
crate::error::StreamError::InvalidConfig {
reason: "push_video called before build()".into(),
}
})?;
inner.push_video(frame)
}
fn push_audio(
&mut self,
frame: &ff_format::AudioFrame,
) -> Result<(), crate::error::StreamError> {
if self.finished {
return Err(crate::error::StreamError::InvalidConfig {
reason: "push_audio called after finish()".into(),
});
}
let inner = self.inner.as_mut().ok_or_else(|| {
crate::error::StreamError::InvalidConfig {
reason: "push_audio called before build()".into(),
}
})?;
inner.push_audio(frame);
Ok(())
}
fn finish(mut self: Box<Self>) -> Result<(), crate::error::StreamError> {
if self.finished {
return Ok(());
}
self.finished = true;
let inner =
self.inner
.take()
.ok_or_else(|| crate::error::StreamError::InvalidConfig {
reason: "finish() called before build()".into(),
})?;
inner.flush_and_close();
Ok(())
}
}
};
}
macro_rules! impl_live_stream_setters {
($type:ident, required_audio) => {
impl $type {
#[must_use]
pub fn video(mut self, width: u32, height: u32, fps: f64) -> Self {
self.video_width = Some(width);
self.video_height = Some(height);
self.fps = Some(fps);
self
}
#[must_use]
pub fn audio(mut self, sample_rate: u32, channels: u32) -> Self {
self.sample_rate = sample_rate;
self.channels = channels;
self
}
#[must_use]
pub fn video_codec(mut self, codec: ff_format::VideoCodec) -> Self {
self.video_codec = codec;
self
}
#[must_use]
pub fn audio_codec(mut self, codec: ff_format::AudioCodec) -> Self {
self.audio_codec = codec;
self
}
#[must_use]
pub fn video_bitrate(mut self, bitrate: u64) -> Self {
self.video_bitrate = bitrate;
self
}
#[must_use]
pub fn audio_bitrate(mut self, bitrate: u64) -> Self {
self.audio_bitrate = bitrate;
self
}
}
};
($type:ident, optional_audio) => {
impl $type {
#[must_use]
pub fn video(mut self, width: u32, height: u32, fps: f64) -> Self {
self.video_width = Some(width);
self.video_height = Some(height);
self.fps = Some(fps);
self
}
#[must_use]
pub fn audio(mut self, sample_rate: u32, channels: u32) -> Self {
self.sample_rate = Some(sample_rate);
self.channels = Some(channels);
self
}
#[must_use]
pub fn video_codec(mut self, codec: ff_format::VideoCodec) -> Self {
self.video_codec = codec;
self
}
#[must_use]
pub fn audio_codec(mut self, codec: ff_format::AudioCodec) -> Self {
self.audio_codec = codec;
self
}
#[must_use]
pub fn video_bitrate(mut self, bitrate: u64) -> Self {
self.video_bitrate = bitrate;
self
}
#[must_use]
pub fn audio_bitrate(mut self, bitrate: u64) -> Self {
self.audio_bitrate = bitrate;
self
}
}
};
}