From f8a1cdbe991d29dd6a979a8f7cd9f6925cfdcd63 Mon Sep 17 00:00:00 2001 From: Davide Bertola Date: Wed, 28 Jun 2023 18:04:38 +0200 Subject: [PATCH] vp8 codec extra: use extended picture id --- src/packet/buffer_rx.rs | 2 +- src/packet/vp8.rs | 15 ++++++++++----- src/rtp/header.rs | 1 + src/rtp/mod.rs | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/packet/buffer_rx.rs b/src/packet/buffer_rx.rs index 202d2021..55a4de6a 100644 --- a/src/packet/buffer_rx.rs +++ b/src/packet/buffer_rx.rs @@ -202,7 +202,7 @@ impl DepacketizingBuffer { if allowed { let last = self.queue.get(stop).expect("entry for stop index"); trace!( - "gap allowed Seq: {} - {}, PIDs: {} - {}", + "Depack gap allowed for Seq: {} - {}, PIDs: {} - {}", last_seq, last.meta.seq_no, prev_pid, diff --git a/src/packet/vp8.rs b/src/packet/vp8.rs index 2eac4684..ddf4f19b 100644 --- a/src/packet/vp8.rs +++ b/src/packet/vp8.rs @@ -1,3 +1,5 @@ +use crate::rtp::{extend_u16, extend_u8}; + use super::{BitRead, CodecExtra, Depacketizer, MediaKind, PacketError, Packetizer}; pub const VP8_HEADER_SIZE: usize = 1; @@ -14,10 +16,8 @@ pub struct Vp8CodecExtra { /// Index of the vp8 temporal layer. /// Only 2 layers are possible in WebRTC pub layer_index: u8, - /// picture id if present - // TODO: use an *extended* format so the consumer of this api does not have to handle wrapping - // which would otherwise depend on whether this is represented as 8 or 16 bits - pub picture_id: Option, + /// extended picture id, if present + pub picture_id: Option, } /// Packetizes VP8 RTP packets. @@ -146,6 +146,9 @@ pub struct Vp8Depacketizer { /// Optional extension /// 8 or 16 bits, picture ID pub picture_id: u16, + // extended picture id + pub extended_pid: u64, + /// 8 bits temporal level zero index pub tl0_pic_idx: u8, /// 2 bits temporal layer index @@ -210,9 +213,11 @@ impl Depacketizer for Vp8Depacketizer { if b & 0x80 > 0 { // M == 1, PID is 16bit self.picture_id = (((b & 0x7f) as u16) << 8) | (reader.get_u8() as u16); + self.extended_pid = extend_u16(Some(self.extended_pid), self.picture_id); payload_index += 1; } else { self.picture_id = b as u16; + self.extended_pid = extend_u8(Some(self.extended_pid), b); } } @@ -252,7 +257,7 @@ impl Depacketizer for Vp8Depacketizer { sync: self.y == 1, layer_index: self.tid, picture_id: if self.i == 1 { - Some(self.picture_id) + Some(self.extended_pid) } else { None }, diff --git a/src/rtp/header.rs b/src/rtp/header.rs index 550a627c..5fc945c6 100644 --- a/src/rtp/header.rs +++ b/src/rtp/header.rs @@ -304,6 +304,7 @@ macro_rules! mk_extend { }; } +mk_extend!(extend_u8, u8); mk_extend!(extend_u16, u16); mk_extend!(extend_u32, u32); diff --git a/src/rtp/mod.rs b/src/rtp/mod.rs index 86d99795..768c16da 100644 --- a/src/rtp/mod.rs +++ b/src/rtp/mod.rs @@ -22,7 +22,7 @@ pub use mtime::MediaTime; mod header; pub use header::RtpHeader; -pub(crate) use header::{extend_u16, extend_u32}; +pub(crate) use header::{extend_u16, extend_u32, extend_u8}; mod srtp; pub(crate) use srtp::{SrtpContext, SrtpKey};