Add support for ffmpeg 6.0
- Use the new send_frame/receive_packet API for encoding
- Use the new channel layout API for audio
- Fix audio recording
- Copy codec parameters to the stream parameters
- Set correct pts for audio frames
- Read audio samples from file directly to the refcounted AVFrame buffer instead of the `g_pSamples` buffer
- Use global AVPackets allocated with `av_packet_alloc`
- Stop trying to write more audio frames when `WriteAudioFrame` fails with a negative error code
- Fix segfault with `g_pContainer->url`. The field has to be allocated with `av_malloc` before writing to it. It's set to `NULL` by default.
- Properly free allocations with `avcodec_free_context` and `avformat_free_context`
use fpnum::FPNum;
use std::{collections::BinaryHeap, num::NonZeroU16, ops::Add};
pub type GearId = NonZeroU16;
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
#[repr(transparent)]
pub struct Millis(u32);
impl Millis {
#[inline]
pub const fn new(value: u32) -> Self {
Self(value)
}
#[inline]
pub const fn get(self) -> u32 {
self.0
}
#[inline]
pub fn to_fixed(self) -> FPNum {
FPNum::new(self.0 as i32, 1)
}
}
impl Add for Millis {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}
pub struct GearAllocator {
max_id: u16,
free_ids: BinaryHeap<GearId>,
}
impl GearAllocator {
pub fn new() -> Self {
Self {
max_id: 0,
free_ids: BinaryHeap::with_capacity(1024),
}
}
pub fn alloc(&mut self) -> Option<GearId> {
self.free_ids.pop().or_else(|| {
self.max_id.checked_add(1).and_then(|new_max_id| {
self.max_id = new_max_id;
NonZeroU16::new(new_max_id)
})
})
}
pub fn free(&mut self, gear_id: GearId) {
self.free_ids.push(gear_id)
}
}