@@ -363,6 +363,7 @@ pub struct PcmMb {
363363 pub pcm_sample_chroma_cr : Vec < u8 > ,
364364}
365365
366+ // Macroblock of type I
366367#[ derive( Clone , Debug , Default ) ]
367368pub struct IMb {
368369 pub mb_type : IMbType ,
@@ -374,10 +375,59 @@ pub struct IMb {
374375 pub residual : Option < Box < Residual > > ,
375376}
376377
378+ #[ derive( Copy , Clone , Debug , Default , PartialEq , Eq ) ]
379+ pub struct MotionVector {
380+ pub x : i16 ,
381+ pub y : i16 ,
382+ }
383+
384+ // Holds prediction data for one partition
385+ #[ derive( Copy , Clone , Debug , Default , PartialEq , Eq ) ]
386+ pub struct PartitionInfo {
387+ pub ref_idx_l0 : u8 ,
388+ pub mv_l0 : MotionVector ,
389+ }
390+
391+ // Table 7-17 - Sub-macroblock types in P macroblock
392+ #[ allow( non_camel_case_types) ]
393+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Default , FromPrimitive ) ]
394+ pub enum SubMbType {
395+ #[ default]
396+ P_L0_8x8 = 0 ,
397+ P_L0_8x4 = 1 ,
398+ P_L0_4x8 = 2 ,
399+ P_L0_4x4 = 3 ,
400+ }
401+
402+ impl TryFrom < u32 > for SubMbType {
403+ type Error = & ' static str ;
404+ fn try_from ( value : u32 ) -> Result < Self , Self :: Error > {
405+ FromPrimitive :: from_u32 ( value) . ok_or ( "Unknown sub-mb type." )
406+ }
407+ }
408+
409+ // Holds data for a P_8x8 sub-macroblock
410+ #[ derive( Copy , Clone , Debug , Default ) ]
411+ pub struct SubMacroblock {
412+ pub sub_mb_type : SubMbType ,
413+ // A sub-macroblock can have up to 4 partitions (for 4x4)
414+ pub partitions : [ PartitionInfo ; 4 ] ,
415+ }
416+
417+ // Enum to hold the two different kinds of motion info
418+ #[ derive( Clone , Debug ) ]
419+ pub enum PMbMotion {
420+ // For 16x16, 16x8, 8x16 partitions
421+ Partitions ( [ PartitionInfo ; 4 ] ) ,
422+ // For P_8x8 and P_8x8ref0
423+ SubMacroblocks ( [ SubMacroblock ; 4 ] ) ,
424+ }
425+
377426// Macroblock of type P
378427#[ derive( Clone , Debug , Default ) ]
379428pub struct PMb {
380429 pub mb_type : PMbType ,
430+ pub motion : Option < PMbMotion > ,
381431 pub coded_block_pattern : CodedBlockPattern ,
382432 pub mb_qp_delta : i32 ,
383433 pub residual : Option < Box < Residual > > ,
0 commit comments