Skip to content

Commit

Permalink
enum ObuMetaType: make a real enum
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Mar 1, 2024
1 parent b40cfa5 commit 1b5cf6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
19 changes: 11 additions & 8 deletions src/levels.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::ffi::c_uint;
use std::ops::Neg;
use strum::EnumCount;

pub type ObuMetaType = c_uint;
pub const OBU_META_TIMECODE: ObuMetaType = 5;
pub const OBU_META_ITUT_T35: ObuMetaType = 4;
pub const OBU_META_SCALABILITY: ObuMetaType = 3;
pub const OBU_META_HDR_MDCV: ObuMetaType = 2;
pub const OBU_META_HDR_CLL: ObuMetaType = 1;
use strum::{EnumCount, FromRepr};

#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr)]
pub enum ObuMetaType {
OBU_META_HDR_CLL = 1,
OBU_META_HDR_MDCV = 2,
OBU_META_SCALABILITY = 3,
OBU_META_ITUT_T35 = 4,
OBU_META_TIMECODE = 5,
}

pub type TxfmSize = u8;
pub const N_TX_SIZES: usize = 5;
Expand Down
21 changes: 8 additions & 13 deletions src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ use crate::src::internal::Rav1dContext;
use crate::src::internal::Rav1dTileGroup;
use crate::src::internal::Rav1dTileGroupHeader;
use crate::src::levels::ObuMetaType;
use crate::src::levels::OBU_META_HDR_CLL;
use crate::src::levels::OBU_META_HDR_MDCV;
use crate::src::levels::OBU_META_ITUT_T35;
use crate::src::levels::OBU_META_SCALABILITY;
use crate::src::levels::OBU_META_TIMECODE;
use crate::src::log::Rav1dLog as _;
use crate::src::picture::rav1d_picture_copy_props;
use crate::src::picture::rav1d_thread_picture_ref;
Expand Down Expand Up @@ -2349,14 +2344,14 @@ unsafe fn parse_obus(
let debug = Debug::new(false, "OBU", &gb);

// obu metadata type field
let meta_type = gb.get_uleb128() as ObuMetaType;
let meta_type = gb.get_uleb128();
let meta_type_len = ((gb.pos() - init_bit_pos) >> 3) as c_int;
if gb.has_error() != 0 {
return Err(EINVAL);
}

match meta_type {
OBU_META_HDR_CLL => {
match ObuMetaType::from_repr(meta_type) {
Some(ObuMetaType::OBU_META_HDR_CLL) => {
let debug = debug.named("CLLOBU");
let max_content_light_level = gb.get_bits(16) as c_int;
debug.log(
Expand All @@ -2383,7 +2378,7 @@ unsafe fn parse_obus(
max_frame_average_light_level,
})); // TODO(kkysen) fallible allocation
}
OBU_META_HDR_MDCV => {
Some(ObuMetaType::OBU_META_HDR_MDCV) => {
let debug = debug.named("MDCVOBU");
let primaries = array::from_fn(|i| {
let primary = [gb.get_bits(16) as u16, gb.get_bits(16) as u16];
Expand Down Expand Up @@ -2413,7 +2408,7 @@ unsafe fn parse_obus(
min_luminance,
})); // TODO(kkysen) fallible allocation
}
OBU_META_ITUT_T35 => {
Some(ObuMetaType::OBU_META_ITUT_T35) => {
let mut payload_size = len as c_int;
// Don't take into account all the trailing bits for `payload_size`.
while payload_size > 0 && r#in[init_byte_pos + payload_size as usize - 1] == 0 {
Expand Down Expand Up @@ -2446,10 +2441,10 @@ unsafe fn parse_obus(
}))); // TODO(kkysen) fallible allocation
}
}
OBU_META_SCALABILITY | OBU_META_TIMECODE => {} // Ignore metadata OBUs we don't care about.
_ => {
Some(ObuMetaType::OBU_META_SCALABILITY | ObuMetaType::OBU_META_TIMECODE) => {} // Ignore metadata OBUs we don't care about.
None => {
// Print a warning, but don't fail for unknown types.
writeln!(c.logger, "Unknown Metadata OBU type {meta_type}",);
writeln!(c.logger, "Unknown Metadata OBU type {meta_type}");
}
}
}
Expand Down

0 comments on commit 1b5cf6f

Please sign in to comment.