Skip to content

Commit

Permalink
vp8 codec extra: use extended picture id
Browse files Browse the repository at this point in the history
  • Loading branch information
davibe committed Jun 28, 2023
1 parent 23f7855 commit f8a1cdb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/packet/buffer_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 10 additions & 5 deletions src/packet/vp8.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<u16>,
/// extended picture id, if present
pub picture_id: Option<u64>,
}

/// Packetizes VP8 RTP packets.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
},
Expand Down
1 change: 1 addition & 0 deletions src/rtp/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ macro_rules! mk_extend {
};
}

mk_extend!(extend_u8, u8);
mk_extend!(extend_u16, u16);
mk_extend!(extend_u32, u32);

Expand Down
2 changes: 1 addition & 1 deletion src/rtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit f8a1cdb

Please sign in to comment.