scuffle_h265/sps/sps_3d_extension.rs
1use std::io;
2
3use scuffle_bytes_util::{BitReader, range_check};
4use scuffle_expgolomb::BitReaderExpGolombExt;
5
6/// Sequence parameter set 3D extension.
7///
8/// `sps_3d_extension()`
9///
10/// - ISO/IEC 23008-2 - I.7.3.2.2.5
11/// - ISO/IEC 23008-2 - I.7.4.3.2.5
12#[derive(Debug, Clone, PartialEq)]
13pub struct Sps3dExtension {
14 /// All values for `d=0`
15 pub d0: Sps3dExtensionD0,
16 /// All values for `d=1`
17 pub d1: Sps3dExtensionD1,
18}
19
20/// Directly part of [SPS 3D extension](Sps3dExtension).
21#[derive(Debug, Clone, PartialEq)]
22pub struct Sps3dExtensionD0 {
23 /// Equal to `true` specifies that the derivation process for inter-view predicted
24 /// merging candidates and the derivation process for disparity information merging candidates may be used
25 /// in the decoding process of layers with `DepthFlag` equal to **0**.
26 ///
27 /// Equal to `false` specifies
28 /// that derivation process for inter-view predicted merging candidates and the derivation process for
29 /// disparity information merging candidates is not used in the decoding process of layers with `DepthFlag`
30 /// equal to **0**.
31 pub iv_di_mc_enabled_flag: bool,
32 /// Equal to `true` specifies that motion vectors used for inter-view prediction may
33 /// be scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **0**.
34 ///
35 /// Equal to `false` specifies that motion vectors used for inter-view prediction are
36 /// not scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **0**.
37 pub iv_mv_scal_enabled_flag: bool,
38 /// When [`iv_di_mc_enabled_flag`](Sps3dExtensionD0::iv_di_mc_enabled_flag) is equal to `true`, is
39 /// used to derive the minimum size of sub-block partitions used in the derivation process for sub-block
40 /// partition motion vectors for an inter-layer predicted merging candidate in the decoding process of layers
41 /// with `DepthFlag` equal to 0.
42 ///
43 /// The value is in range
44 /// \[[`MinCbLog2SizeY`](crate::SpsRbsp::min_cb_log2_size_y) - 3, [`CtbLog2SizeY`](crate::SpsRbsp::ctb_log2_size_y) - 3\].
45 pub log2_ivmc_sub_pb_size_minus3: u64,
46 /// Equal to `true` specifies that the `iv_res_pred_weight_idx` syntax element may
47 /// be present in coding units of layers with `DepthFlag` equal to 0.
48 ///
49 /// Equal to 0 specifies that the `iv_res_pred_weight_idx` syntax element is not present coding units of layers with
50 /// `DepthFlag` equal to 0.
51 pub iv_res_pred_enabled_flag: bool,
52 /// Equal to `true` specifies that the derivation process for a depth or disparity
53 /// sample array from a depth picture may be used in the derivation process for a disparity vector for texture
54 /// layers in the decoding process of layers with `DepthFlag` equal to 0.
55 ///
56 /// Equal to `false` specifies that derivation process for a depth or disparity sample array from
57 /// a depth picture is not used in the derivation process for a disparity vector for texture layers in
58 /// the decoding process of layers with `DepthFlag` equal to 0.
59 pub depth_ref_enabled_flag: bool,
60 /// Equal to `true` specifies that the derivation process for a view synthesis prediction
61 /// merging candidate may be used in the decoding process of layers with `DepthFlag` equal to 0.
62 ///
63 /// Equal to `false` specifies that the derivation process for a view synthesis prediction
64 /// merging candidate is not used in the decoding process of layers with `DepthFlag` equal to 0.
65 pub vsp_mc_enabled_flag: bool,
66 /// Equal to `true` specifies that the `dbbp_flag` syntax element may be present in coding
67 /// units of layers with `DepthFlag` equal to 0.
68 ///
69 /// Equal to `false` specifies that the `dbbp_flag`
70 /// syntax element is not present in coding units of layers with `DepthFlag` equal to 0.
71 pub dbbp_enabled_flag: bool,
72}
73
74/// Directly part of [SPS 3D extension](Sps3dExtension).
75#[derive(Debug, Clone, PartialEq)]
76pub struct Sps3dExtensionD1 {
77 /// Equal to `true` specifies that the derivation process for inter-view predicted
78 /// merging candidates and the derivation process for disparity information merging candidates may be used
79 /// in the decoding process of layers with `DepthFlag` equal to **1**.
80 ///
81 /// Equal to `false` specifies
82 /// that derivation process for inter-view predicted merging candidates and the derivation process for
83 /// disparity information merging candidates is not used in the decoding process of layers with `DepthFlag`
84 /// equal to **1**.
85 pub iv_di_mc_enabled_flag: bool,
86 /// Equal to `true` specifies that motion vectors used for inter-view prediction may
87 /// be scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **1**.
88 ///
89 /// Equal to `false` specifies that motion vectors used for inter-view prediction are
90 /// not scaled based on `view_id_val` values in the decoding process of layers with `DepthFlag` equal to **1**.
91 pub iv_mv_scal_enabled_flag: bool,
92 /// Equal to `true` specifies that the derivation process for motion vectors for the
93 /// texture merge candidate may be used in the decoding process of layers with `DepthFlag` equal to 1.
94 ///
95 /// Equal to `false` specifies that the derivation process for motion vectors for the texture
96 /// merge candidate is not used in the decoding process of layers with `DepthFlag` equal to 1.
97 pub tex_mc_enabled_flag: bool,
98 /// When this value is equal to `true`, is used to derive the
99 /// minimum size of sub-block partitions used in the derivation process for sub-block partition motion
100 /// vectors for an inter-layer predicted merging candidate in the decoding process of layers with `DepthFlag`
101 /// equal to 1.
102 ///
103 /// The value is in range
104 /// \[[`MinCbLog2SizeY`](crate::SpsRbsp::min_cb_log2_size_y) - 3, [`CtbLog2SizeY`](crate::SpsRbsp::ctb_log2_size_y) - 3\].
105 pub log2_texmc_sub_pb_size_minus3: u64,
106 /// Equal to `true` specifies that the intra prediction mode `INTRA_CONTOUR`
107 /// using depth intra contour prediction may be used in the decoding process of layers with `DepthFlag` equal
108 /// to 1.
109 ///
110 /// Equal to `false` specifies that the intra prediction mode `INTRA_CONTOUR`
111 /// using depth intra contour prediction is not used in the decoding process of layers with `DepthFlag` equal
112 /// to 1.
113 pub intra_contour_enabled_flag: bool,
114 /// Equal to `true` specifies that the `dc_only_flag` syntax element may be
115 /// present in coding units coded in an intra prediction mode of layers with `DepthFlag` equal to 1, and that
116 /// the intra prediction mode `INTRA_WEDGE` may be used in the decoding process of layers with `DepthFlag`
117 /// equal to 1.
118 ///
119 /// Equal to `false` specifies that the `dc_only_flag` syntax element
120 /// is not present in coding units coded in an intra prediction mode of layers with `DepthFlag` equal to 1 and
121 /// that the intra prediction mode `INTRA_WEDGE` is not used in the decoding process of layers with
122 /// `DepthFlag` equal to 1.
123 pub intra_dc_only_wedge_enabled_flag: bool,
124 /// Equal to `true` specifies that coding quadtree and coding unit
125 /// partitioning information may be inter-component predicted in the decoding process of layers with
126 /// `DepthFlag` equal to 1.
127 ///
128 /// Equal to `false` specifies that coding quadtree and
129 /// coding unit partitioning information are not inter-component predicted in the decoding process of layers
130 /// with `DepthFlag` equal to 1.
131 pub cqt_cu_part_pred_enabled_flag: bool,
132 /// Equal to `true` specifies that the dc_only_flag syntax element may be present
133 /// in coding units coded an in inter prediction mode of layers with `DepthFlag` equal to 1.
134 ///
135 /// Equal to `false` specifies that the dc_only_flag syntax element is not present in
136 /// coding units coded in an inter prediction mode of layers with `DepthFlag` equal to 1.
137 pub inter_dc_only_enabled_flag: bool,
138 /// Equal to `true` specifies that the `skip_intra_flag` syntax element may be present
139 /// in coding units of layers with `DepthFlag` equal to 1.
140 ///
141 /// Equal to `false` specifies that
142 /// the `skip_intra_flag` syntax element is not present in coding units of layers with `DepthFlag` equal to 1.
143 pub skip_intra_enabled_flag: bool,
144}
145
146impl Sps3dExtension {
147 pub(crate) fn parse<R: io::Read>(
148 bit_reader: &mut BitReader<R>,
149 min_cb_log2_size_y: u64,
150 ctb_log2_size_y: u64,
151 ) -> io::Result<Self> {
152 let iv_di_mc_enabled_flag = bit_reader.read_bit()?;
153 let iv_mv_scal_enabled_flag = bit_reader.read_bit()?;
154 let log2_ivmc_sub_pb_size_minus3 = bit_reader.read_exp_golomb()?;
155 range_check!(
156 log2_ivmc_sub_pb_size_minus3,
157 min_cb_log2_size_y.saturating_sub(3),
158 ctb_log2_size_y.saturating_sub(3)
159 )?;
160
161 let d0 = Sps3dExtensionD0 {
162 iv_di_mc_enabled_flag,
163 iv_mv_scal_enabled_flag,
164 log2_ivmc_sub_pb_size_minus3,
165 iv_res_pred_enabled_flag: bit_reader.read_bit()?,
166 depth_ref_enabled_flag: bit_reader.read_bit()?,
167 vsp_mc_enabled_flag: bit_reader.read_bit()?,
168 dbbp_enabled_flag: bit_reader.read_bit()?,
169 };
170
171 let tex_mc_enabled_flag = bit_reader.read_bit()?;
172 let log2_texmc_sub_pb_size_minus3 = bit_reader.read_exp_golomb()?;
173 range_check!(
174 log2_texmc_sub_pb_size_minus3,
175 min_cb_log2_size_y.saturating_sub(3),
176 ctb_log2_size_y.saturating_sub(3)
177 )?;
178
179 let d1 = Sps3dExtensionD1 {
180 iv_di_mc_enabled_flag: d0.iv_di_mc_enabled_flag,
181 iv_mv_scal_enabled_flag: d0.iv_mv_scal_enabled_flag,
182 tex_mc_enabled_flag,
183 log2_texmc_sub_pb_size_minus3,
184 intra_contour_enabled_flag: bit_reader.read_bit()?,
185 intra_dc_only_wedge_enabled_flag: bit_reader.read_bit()?,
186 cqt_cu_part_pred_enabled_flag: bit_reader.read_bit()?,
187 inter_dc_only_enabled_flag: bit_reader.read_bit()?,
188 skip_intra_enabled_flag: bit_reader.read_bit()?,
189 };
190
191 Ok(Sps3dExtension { d0, d1 })
192 }
193}