/src/x265/source/encoder/sei.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Steve Borho <steve@borho.org> |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
19 | | * |
20 | | * This program is also available under a commercial proprietary license. |
21 | | * For more information, contact us at license @ x265.com. |
22 | | *****************************************************************************/ |
23 | | |
24 | | #ifndef X265_SEI_H |
25 | | #define X265_SEI_H |
26 | | |
27 | | #include "common.h" |
28 | | #include "bitstream.h" |
29 | | #include "slice.h" |
30 | | #include "nal.h" |
31 | | #include "md5.h" |
32 | | |
33 | | namespace X265_NS { |
34 | | // private namespace |
35 | | |
36 | | class SEI : public SyntaxElementWriter |
37 | | { |
38 | | public: |
39 | | /* SEI users call writeSEImessages() to marshal an SEI to a bitstream. |
40 | | * The writeSEImessages() method calls writeSEI() which encodes the header */ |
41 | | void writeSEImessages(Bitstream& bs, const SPS& sps, NalUnitType nalUnitType, NALList& list, int isNested, int layerId = 0); |
42 | | void setSize(uint32_t size); |
43 | | static char* base64Decode(char encodedString[], int base64EncodeLength, char* base64Decode); |
44 | 0 | virtual ~SEI() {} |
45 | | protected: |
46 | | SEIPayloadType m_payloadType; |
47 | | uint32_t m_payloadSize; |
48 | | virtual void writeSEI(const SPS&) = 0; |
49 | | void writeByteAlign(); |
50 | | }; |
51 | | |
52 | | //seongnam.oh@samsung.com :: for the Creative Intent Meta Data Encoding |
53 | | class SEIuserDataRegistered : public SEI |
54 | | { |
55 | | public: |
56 | | SEIuserDataRegistered() |
57 | 0 | { |
58 | 0 | m_payloadType = USER_DATA_REGISTERED_ITU_T_T35; |
59 | 0 | m_payloadSize = 0; |
60 | 0 | } |
61 | | |
62 | | uint8_t *m_userData; |
63 | | |
64 | | // daniel.vt@samsung.com :: for the Creative Intent Meta Data Encoding ( seongnam.oh@samsung.com ) |
65 | | void writeSEI(const SPS&) |
66 | 0 | { |
67 | 0 | if (!m_userData) |
68 | 0 | return; |
69 | | |
70 | 0 | uint32_t i = 0; |
71 | 0 | for (; i < m_payloadSize; ++i) |
72 | 0 | WRITE_CODE(m_userData[i], 8, "creative_intent_metadata"); |
73 | 0 | } |
74 | | }; |
75 | | |
76 | | /* Film grain characteristics */ |
77 | | class FilmGrainCharacteristics : public SEI |
78 | | { |
79 | | public: |
80 | | |
81 | | FilmGrainCharacteristics() |
82 | 0 | { |
83 | 0 | m_payloadType = FILM_GRAIN_CHARACTERISTICS; |
84 | 0 | m_payloadSize = 0; |
85 | 0 | } |
86 | | |
87 | | struct CompModelIntensityValues |
88 | | { |
89 | | uint8_t intensityIntervalLowerBound; |
90 | | uint8_t intensityIntervalUpperBound; |
91 | | int* compModelValue; |
92 | | }; |
93 | | |
94 | | struct CompModel |
95 | | { |
96 | | bool bPresentFlag; |
97 | | uint8_t numModelValues; |
98 | | uint8_t m_filmGrainNumIntensityIntervalMinus1; |
99 | | CompModelIntensityValues* intensityValues; |
100 | | }; |
101 | | |
102 | | CompModel m_compModel[MAX_NUM_COMPONENT]; |
103 | | bool m_filmGrainCharacteristicsPersistenceFlag; |
104 | | bool m_filmGrainCharacteristicsCancelFlag; |
105 | | bool m_separateColourDescriptionPresentFlag; |
106 | | bool m_filmGrainFullRangeFlag; |
107 | | uint8_t m_filmGrainModelId; |
108 | | uint8_t m_blendingModeId; |
109 | | uint8_t m_log2ScaleFactor; |
110 | | uint8_t m_filmGrainBitDepthLumaMinus8; |
111 | | uint8_t m_filmGrainBitDepthChromaMinus8; |
112 | | uint8_t m_filmGrainColourPrimaries; |
113 | | uint8_t m_filmGrainTransferCharacteristics; |
114 | | uint8_t m_filmGrainMatrixCoeffs; |
115 | | |
116 | | void writeSEI(const SPS&) |
117 | 0 | { |
118 | 0 | WRITE_FLAG(m_filmGrainCharacteristicsCancelFlag, "film_grain_characteristics_cancel_flag"); |
119 | |
|
120 | 0 | if (!m_filmGrainCharacteristicsCancelFlag) |
121 | 0 | { |
122 | 0 | WRITE_CODE(m_filmGrainModelId, 2, "film_grain_model_id"); |
123 | 0 | WRITE_FLAG(m_separateColourDescriptionPresentFlag, "separate_colour_description_present_flag"); |
124 | 0 | if (m_separateColourDescriptionPresentFlag) |
125 | 0 | { |
126 | 0 | WRITE_CODE(m_filmGrainBitDepthLumaMinus8, 3, "film_grain_bit_depth_luma_minus8"); |
127 | 0 | WRITE_CODE(m_filmGrainBitDepthChromaMinus8, 3, "film_grain_bit_depth_chroma_minus8"); |
128 | 0 | WRITE_FLAG(m_filmGrainFullRangeFlag, "film_grain_full_range_flag"); |
129 | 0 | WRITE_CODE(m_filmGrainColourPrimaries, X265_BYTE, "film_grain_colour_primaries"); |
130 | 0 | WRITE_CODE(m_filmGrainTransferCharacteristics, X265_BYTE, "film_grain_transfer_characteristics"); |
131 | 0 | WRITE_CODE(m_filmGrainMatrixCoeffs, X265_BYTE, "film_grain_matrix_coeffs"); |
132 | 0 | } |
133 | 0 | WRITE_CODE(m_blendingModeId, 2, "blending_mode_id"); |
134 | 0 | WRITE_CODE(m_log2ScaleFactor, 4, "log2_scale_factor"); |
135 | 0 | for (uint8_t c = 0; c < 3; c++) |
136 | 0 | { |
137 | 0 | WRITE_FLAG(m_compModel[c].bPresentFlag && m_compModel[c].m_filmGrainNumIntensityIntervalMinus1 + 1 > 0 && m_compModel[c].numModelValues > 0, "comp_model_present_flag[c]"); |
138 | 0 | } |
139 | 0 | for (uint8_t c = 0; c < 3; c++) |
140 | 0 | { |
141 | 0 | if (m_compModel[c].bPresentFlag && m_compModel[c].m_filmGrainNumIntensityIntervalMinus1 + 1 > 0 && m_compModel[c].numModelValues > 0) |
142 | 0 | { |
143 | 0 | assert(m_compModel[c].m_filmGrainNumIntensityIntervalMinus1 + 1 <= 256); |
144 | 0 | assert(m_compModel[c].numModelValues <= X265_BYTE); |
145 | 0 | WRITE_CODE(m_compModel[c].m_filmGrainNumIntensityIntervalMinus1 , X265_BYTE, "num_intensity_intervals_minus1[c]"); |
146 | 0 | WRITE_CODE(m_compModel[c].numModelValues - 1, 3, "num_model_values_minus1[c]"); |
147 | 0 | for (uint8_t interval = 0; interval < m_compModel[c].m_filmGrainNumIntensityIntervalMinus1 + 1; interval++) |
148 | 0 | { |
149 | 0 | WRITE_CODE(m_compModel[c].intensityValues[interval].intensityIntervalLowerBound, X265_BYTE, "intensity_interval_lower_bound[c][i]"); |
150 | 0 | WRITE_CODE(m_compModel[c].intensityValues[interval].intensityIntervalUpperBound, X265_BYTE, "intensity_interval_upper_bound[c][i]"); |
151 | 0 | for (uint8_t j = 0; j < m_compModel[c].numModelValues; j++) |
152 | 0 | { |
153 | 0 | WRITE_SVLC(m_compModel[c].intensityValues[interval].compModelValue[j],"comp_model_value[c][i]"); |
154 | 0 | } |
155 | 0 | } |
156 | 0 | } |
157 | 0 | } |
158 | 0 | WRITE_FLAG(m_filmGrainCharacteristicsPersistenceFlag, "film_grain_characteristics_persistence_flag"); |
159 | 0 | } |
160 | 0 | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
161 | 0 | { |
162 | 0 | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
163 | 0 | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
164 | 0 | { |
165 | 0 | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
166 | 0 | } |
167 | 0 | } |
168 | 0 | } |
169 | | }; |
170 | | |
171 | | class AomFilmGrainCharacteristics : public SEI { |
172 | | |
173 | | public: |
174 | | |
175 | | AomFilmGrainCharacteristics() |
176 | 0 | { |
177 | 0 | m_payloadType = USER_DATA_REGISTERED_ITU_T_T35; |
178 | 0 | m_payloadSize = 0; |
179 | 0 | } |
180 | | |
181 | | int32_t m_apply_grain; |
182 | | int32_t m_update_grain; |
183 | | int32_t m_scaling_points_y[14][2]; |
184 | | int32_t m_num_y_points; |
185 | | int32_t m_scaling_points_cb[10][2]; |
186 | | int32_t m_num_cb_points; |
187 | | int32_t m_scaling_points_cr[10][2]; |
188 | | int32_t m_num_cr_points; |
189 | | int32_t m_scaling_shift; |
190 | | int32_t m_ar_coeff_lag; |
191 | | int32_t m_ar_coeffs_y[24]; |
192 | | int32_t m_ar_coeffs_cb[25]; |
193 | | int32_t m_ar_coeffs_cr[25]; |
194 | | int32_t m_ar_coeff_shift; |
195 | | int32_t m_cb_mult; |
196 | | int32_t m_cb_luma_mult; |
197 | | int32_t m_cb_offset; |
198 | | int32_t m_cr_mult; |
199 | | int32_t m_cr_luma_mult; |
200 | | int32_t m_cr_offset; |
201 | | int32_t m_overlap_flag; |
202 | | int32_t m_clip_to_restricted_range; |
203 | | int32_t m_bitDepth; |
204 | | int32_t m_chroma_scaling_from_luma; |
205 | | int32_t m_grain_scale_shift; |
206 | | uint16_t m_grain_seed; |
207 | | |
208 | | void writeSEI(const SPS&) |
209 | 0 | { |
210 | 0 | WRITE_CODE(0x26, 8, "country_code"); |
211 | 0 | WRITE_CODE(0x5890, 16, "provider_code"); |
212 | 0 | WRITE_CODE(0x0001, 16, "provider_oriented_code"); |
213 | 0 | WRITE_FLAG(m_apply_grain, "afgs1_enable_flag"); |
214 | 0 | WRITE_CODE(m_grain_seed, 16, "grain_seed"); |
215 | 0 | WRITE_CODE(0, 3, "film_grain_param_set_idx"); |
216 | 0 | WRITE_CODE(m_update_grain, 1, "update_grain"); |
217 | 0 | WRITE_CODE(m_num_y_points, 4, "num_y_points"); |
218 | 0 | if (m_num_y_points) |
219 | 0 | { |
220 | 0 | for (int i = 0; i < m_num_y_points; i++) |
221 | 0 | { |
222 | 0 | for (int j = 0; j < 2; j++) |
223 | 0 | { |
224 | 0 | WRITE_CODE(m_scaling_points_y[i][j], 8, "scaling_points_y[i][j]"); |
225 | 0 | } |
226 | 0 | } |
227 | 0 | } |
228 | 0 | WRITE_FLAG(m_num_cb_points == 0 && m_num_cr_points == 0, "luma_only_flag"); |
229 | 0 | WRITE_FLAG(0, "chroma_scaling_from_luma"); |
230 | 0 | WRITE_CODE(m_num_cb_points, 4, "num_cb_points"); |
231 | 0 | if (m_num_cb_points) |
232 | 0 | { |
233 | 0 | for (int i = 0; i < m_num_cb_points; i++) |
234 | 0 | { |
235 | 0 | for (int j = 0; j < 2; j++) |
236 | 0 | { |
237 | 0 | WRITE_CODE(m_scaling_points_cb[i][j], 8, "scaling_points_cb[i][j]"); |
238 | 0 | } |
239 | 0 | } |
240 | 0 | } |
241 | 0 | WRITE_CODE(m_num_cr_points, 4, "num_cr_points"); |
242 | 0 | if (m_num_cr_points) |
243 | 0 | { |
244 | 0 | for (int i = 0; i < m_num_cr_points; i++) |
245 | 0 | { |
246 | 0 | for (int j = 0; j < 2; j++) |
247 | 0 | { |
248 | 0 | WRITE_CODE(m_scaling_points_cr[i][j], 8, "scaling_points_cr[i][j]"); |
249 | 0 | } |
250 | 0 | } |
251 | 0 | } |
252 | 0 | WRITE_CODE(m_scaling_shift - 8, 2, "scaling_shift"); |
253 | 0 | WRITE_CODE(m_ar_coeff_lag, 2, "ar_coeff_lag"); |
254 | 0 | if (m_num_y_points) |
255 | 0 | { |
256 | 0 | for (int i = 0; i < 24; i++) |
257 | 0 | { |
258 | 0 | WRITE_CODE(m_ar_coeffs_y[i] + 128, 8, "ar_coeff_y[i]"); |
259 | 0 | } |
260 | 0 | } |
261 | 0 | if (m_num_cb_points || m_chroma_scaling_from_luma) |
262 | 0 | { |
263 | 0 | for (int i = 0; i < 25; i++) |
264 | 0 | { |
265 | 0 | WRITE_CODE(m_ar_coeffs_cb[i] + 128, 8, "ar_coeff_cb[i]"); |
266 | 0 | } |
267 | 0 | } |
268 | 0 | if (m_num_cr_points || m_chroma_scaling_from_luma) |
269 | 0 | { |
270 | 0 | for (int i = 0; i < 25; i++) |
271 | 0 | { |
272 | 0 | WRITE_CODE(m_ar_coeffs_cr[i] + 128, 8, "ar_coeff_cr[i]"); |
273 | 0 | } |
274 | 0 | } |
275 | 0 | WRITE_CODE(m_ar_coeff_shift - 6, 2, "ar_coeff_shift"); |
276 | 0 | WRITE_CODE(m_grain_scale_shift, 2, "grain_scale_shift"); |
277 | 0 | if (m_num_cb_points) |
278 | 0 | { |
279 | 0 | WRITE_CODE(m_cb_mult, 8, "cb_mult"); |
280 | 0 | WRITE_CODE(m_cb_luma_mult, 8, "cb_luma_mult"); |
281 | 0 | WRITE_CODE(m_cb_offset, 9, "cb_offset"); |
282 | 0 | } |
283 | 0 | if (m_num_cr_points) |
284 | 0 | { |
285 | 0 | WRITE_CODE(m_cr_mult, 8, "cr_mult"); |
286 | 0 | WRITE_CODE(m_cr_luma_mult, 8, "cr_luma_mult"); |
287 | 0 | WRITE_CODE(m_cr_offset, 9, "cr_offset"); |
288 | 0 | } |
289 | 0 | WRITE_FLAG(m_overlap_flag, "overlap_flag"); |
290 | 0 | WRITE_FLAG(m_clip_to_restricted_range, "clip_to_restricted_range"); |
291 | 0 | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
292 | 0 | { |
293 | 0 | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
294 | 0 | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
295 | 0 | { |
296 | 0 | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
297 | 0 | } |
298 | 0 | } |
299 | 0 | } |
300 | | }; |
301 | | |
302 | | static const uint32_t ISO_IEC_11578_LEN = 16; |
303 | | |
304 | | class SEIuserDataUnregistered : public SEI |
305 | | { |
306 | | public: |
307 | | SEIuserDataUnregistered() : m_userData(NULL) |
308 | 0 | { |
309 | 0 | m_payloadType = USER_DATA_UNREGISTERED; |
310 | 0 | m_payloadSize = 0; |
311 | 0 | } |
312 | | static const uint8_t m_uuid_iso_iec_11578[ISO_IEC_11578_LEN]; |
313 | | uint8_t *m_userData; |
314 | | void writeSEI(const SPS&) |
315 | 0 | { |
316 | 0 | for (uint32_t i = 0; i < ISO_IEC_11578_LEN; i++) |
317 | 0 | WRITE_CODE(m_uuid_iso_iec_11578[i], 8, "sei.uuid_iso_iec_11578[i]"); |
318 | 0 | for (uint32_t i = 0; i < m_payloadSize; i++) |
319 | 0 | WRITE_CODE(m_userData[i], 8, "user_data"); |
320 | 0 | } |
321 | | }; |
322 | | |
323 | | #if ENABLE_ALPHA |
324 | | class SEIAlphaChannelInfo : public SEI |
325 | | { |
326 | | public: |
327 | | SEIAlphaChannelInfo() |
328 | | { |
329 | | m_payloadType = ALPHA_CHANNEL_INFO; |
330 | | m_payloadSize = 0; |
331 | | } |
332 | | |
333 | | bool alpha_channel_cancel_flag; |
334 | | void writeSEI(const SPS&) |
335 | | { |
336 | | WRITE_CODE(alpha_channel_cancel_flag, 1, "alpha_channel_cancel_flag"); |
337 | | if (!alpha_channel_cancel_flag) |
338 | | { |
339 | | WRITE_CODE(0, 3, "alpha_channel_use_idc"); |
340 | | WRITE_CODE(0, 3, "alpha_channel_bit_depth_minus8"); |
341 | | WRITE_CODE(0, 9, "alpha_transparent_value"); |
342 | | WRITE_CODE(255, 9, "alpha_opaque_value"); |
343 | | WRITE_CODE(0, 1, "alpha_channel_incr_flag"); |
344 | | WRITE_CODE(0, 1, "alpha_channel_clip_flag"); |
345 | | } |
346 | | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
347 | | { |
348 | | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
349 | | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
350 | | { |
351 | | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
352 | | } |
353 | | } |
354 | | } |
355 | | }; |
356 | | #endif |
357 | | |
358 | | #if ENABLE_MULTIVIEW |
359 | | class SEIThreeDimensionalReferenceDisplaysInfo : public SEI |
360 | | { |
361 | | public: |
362 | | SEIThreeDimensionalReferenceDisplaysInfo() |
363 | | : m_numRefDisplaysMinus1(0), |
364 | | m_refViewingDistanceFlag(false), |
365 | | m_additionalShiftPresentFlag(false) |
366 | | { |
367 | | m_payloadType = THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO; |
368 | | m_payloadSize = 0; |
369 | | } |
370 | | |
371 | | int m_numRefDisplaysMinus1; |
372 | | bool m_refViewingDistanceFlag; |
373 | | bool m_additionalShiftPresentFlag; |
374 | | void writeSEI(const SPS&) |
375 | | { |
376 | | WRITE_UVLC(31, "prec_ref_display_width"); |
377 | | WRITE_FLAG(m_refViewingDistanceFlag, "ref_viewing_distance_flag"); |
378 | | if (m_refViewingDistanceFlag) |
379 | | { |
380 | | WRITE_UVLC(0, "prec_ref_viewing_dist"); |
381 | | } |
382 | | WRITE_UVLC(0, "num_ref_displays_minus1"); |
383 | | for (int i = 0; i <= m_numRefDisplaysMinus1; i++) |
384 | | { |
385 | | WRITE_UVLC(0, "left_view_id"); |
386 | | WRITE_UVLC(1, "right_view_id"); |
387 | | WRITE_CODE(0, 6, "exponent_ref_display_width"); |
388 | | WRITE_CODE(0, 2, "mantissa_ref_display_width"); |
389 | | if (m_refViewingDistanceFlag) |
390 | | { |
391 | | WRITE_CODE(0, 6, "exponent_ref_viewing_distance"); |
392 | | WRITE_CODE(0, 1, "mantissa_ref_viewing_distance"); |
393 | | } |
394 | | WRITE_FLAG(m_additionalShiftPresentFlag, "additional_shift_present_flag"); |
395 | | if (m_additionalShiftPresentFlag) |
396 | | { |
397 | | WRITE_CODE(0, 10, "num_sample_shift_plus512"); |
398 | | } |
399 | | } |
400 | | WRITE_FLAG(0, "three_dimensional_reference_displays_extension_flag"); |
401 | | |
402 | | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
403 | | { |
404 | | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
405 | | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
406 | | { |
407 | | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
408 | | } |
409 | | } |
410 | | } |
411 | | |
412 | | }; |
413 | | |
414 | | class SEIMultiviewSceneInfo : public SEI |
415 | | { |
416 | | public: |
417 | | SEIMultiviewSceneInfo() |
418 | | { |
419 | | m_payloadType = MULTIVIEW_SCENE_INFO; |
420 | | m_payloadSize = 0; |
421 | | } |
422 | | void writeSEI(const SPS&) |
423 | | { |
424 | | WRITE_SVLC(-333, "min_disparity"); |
425 | | WRITE_UVLC(2047, "max_disparity_range"); |
426 | | |
427 | | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
428 | | { |
429 | | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
430 | | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
431 | | { |
432 | | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
433 | | } |
434 | | } |
435 | | } |
436 | | }; |
437 | | |
438 | | static int temp_sign_r[3][3] = { {0,1,0},{1,0,0},{0,1,1} }; |
439 | | static int temp_exponent_r[3][3] = { {10,20,11},{10,5,11},{2,20,11} }; |
440 | | static int temp_mantissa_r[3][3] = { {4,9,1},{0,3,4},{3,3,7} }; |
441 | | static int temp_sign_t[1][3] = { { 0,1,0 } }; |
442 | | static int temp_exponent_t[1][3] = { { 0,10,5 } }; |
443 | | static int temp_mantissa_t[1][3] = { { 1,8,9 } }; |
444 | | static int temp_length_mantissa_r[3][3] = { {10,20,11},{10,5,11},{2,20,11} }; |
445 | | static int temp_length_mantissa_t[1][3] = { { 1,10,5 } }; |
446 | | |
447 | | class SEIMultiviewAcquisitionInfo : public SEI |
448 | | { |
449 | | public: |
450 | | SEIMultiviewAcquisitionInfo() |
451 | | :sign_r(), |
452 | | exponent_r(), |
453 | | mantissa_r(), |
454 | | sign_t(), |
455 | | exponent_t(), |
456 | | mantissa_t(), |
457 | | length_mantissa_r(), |
458 | | length_mantissa_t(), |
459 | | m_intrinsicParamFlag(true), |
460 | | m_extrinsicParamFlag(true), |
461 | | m_intrinsicParamsEqualFlag(true) |
462 | | { |
463 | | m_payloadType = MULTIVIEW_ACQUISITION_INFO; |
464 | | m_payloadSize = 0; |
465 | | |
466 | | for (int i = 0; i <= 0; i++) |
467 | | { |
468 | | for (int j = 0; j <= 2; j++) /* row */ |
469 | | { |
470 | | for (int k = 0; k <= 2; k++) /* column */ |
471 | | { |
472 | | sign_r[j][k] = temp_sign_r[j][k]; |
473 | | exponent_r[j][k] = temp_exponent_r[j][k]; |
474 | | mantissa_r[j][k] = temp_mantissa_r[j][k]; |
475 | | length_mantissa_r[j][k] = temp_length_mantissa_r[j][k]; |
476 | | } |
477 | | sign_t[i][j] = temp_sign_t[i][j]; |
478 | | exponent_t[i][j] = temp_exponent_t[i][j]; |
479 | | mantissa_t[i][j] = temp_mantissa_t[i][j]; |
480 | | length_mantissa_t[i][j] = temp_length_mantissa_t[i][j]; |
481 | | } |
482 | | } |
483 | | } |
484 | | |
485 | | int sign_r[3][3]; |
486 | | int exponent_r[3][3]; |
487 | | int mantissa_r[3][3]; |
488 | | int sign_t[1][3]; |
489 | | int exponent_t[1][3]; |
490 | | int mantissa_t[1][3]; |
491 | | int length_mantissa_r[3][3]; |
492 | | int length_mantissa_t[1][3]; |
493 | | |
494 | | bool m_intrinsicParamFlag; |
495 | | bool m_extrinsicParamFlag; |
496 | | bool m_intrinsicParamsEqualFlag; |
497 | | |
498 | | void writeSEI(const SPS& sps) |
499 | | { |
500 | | WRITE_FLAG(m_intrinsicParamFlag, "intrinsic_param_flag"); |
501 | | WRITE_FLAG(m_extrinsicParamFlag, "extrinsic_param_flag"); |
502 | | if (m_intrinsicParamFlag) |
503 | | { |
504 | | WRITE_FLAG(m_intrinsicParamsEqualFlag, "intrinsic_params_equal_flag"); |
505 | | WRITE_UVLC(31, "prec_focal_length"); |
506 | | WRITE_UVLC(31, "prec_principal_point"); |
507 | | WRITE_UVLC(31, "prec_skew_factor"); |
508 | | |
509 | | for (int i = 0; i <= (m_intrinsicParamsEqualFlag ? 0 : sps.maxViews - 1); i++) |
510 | | { |
511 | | WRITE_FLAG(0, "sign_focal_length_x"); |
512 | | WRITE_CODE(0, 6, "exponent_focal_length_x"); |
513 | | WRITE_CODE(0, 1, "mantissa_focal_length_x"); |
514 | | WRITE_FLAG(0, "sign_focal_length_y"); |
515 | | WRITE_CODE(0, 6, "exponent_focal_length_y"); |
516 | | WRITE_CODE(0, 1, "mantissa_focal_length_y"); |
517 | | WRITE_FLAG(0, "sign_principal_point_x"); |
518 | | WRITE_CODE(0, 6, "exponent_principal_point_x"); |
519 | | WRITE_CODE(0, 1, "mantissa_principal_point_x"); |
520 | | WRITE_FLAG(0, "sign_principal_point_y"); |
521 | | WRITE_CODE(0, 6, "exponent_principal_point_y"); |
522 | | WRITE_CODE(0, 1, "mantissa_principal_point_y"); |
523 | | WRITE_FLAG(0, "sign_skew_factor"); |
524 | | WRITE_CODE(0, 6, "exponent_skew_factor"); |
525 | | WRITE_CODE(0, 1, "mantissa_skew_factor"); |
526 | | } |
527 | | } |
528 | | |
529 | | if (m_extrinsicParamFlag) |
530 | | { |
531 | | WRITE_UVLC(31, "prec_rotation_param"); |
532 | | WRITE_UVLC(31, "prec_translation_param"); |
533 | | for (int i = 0; i <= 0; i++) |
534 | | { |
535 | | for (int j = 0; j <= 2; j++) /* row */ |
536 | | { |
537 | | for (int k = 0; k <= 2; k++) /* column */ |
538 | | { |
539 | | WRITE_FLAG(sign_r[j][k], "sign_r"); |
540 | | WRITE_CODE(exponent_r[j][k], 6, "exponent_r"); |
541 | | WRITE_CODE(mantissa_r[j][k], length_mantissa_r[j][k], "mantissa_r"); |
542 | | } |
543 | | WRITE_FLAG(sign_t[i][j], "sign_t"); |
544 | | WRITE_CODE(exponent_t[i][j], 6, "exponent_t"); |
545 | | WRITE_CODE(mantissa_t[i][j], length_mantissa_t[i][j], "mantissa_t"); |
546 | | } |
547 | | } |
548 | | } |
549 | | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
550 | | { |
551 | | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
552 | | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
553 | | { |
554 | | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
555 | | } |
556 | | } |
557 | | } |
558 | | }; |
559 | | |
560 | | class SEIMultiviewViewPosition : public SEI |
561 | | { |
562 | | public: |
563 | | SEIMultiviewViewPosition() |
564 | | { |
565 | | m_payloadType = MULTIVIEW_VIEW_POSITION; |
566 | | m_payloadSize = 0; |
567 | | } |
568 | | void writeSEI(const SPS& sps) |
569 | | { |
570 | | WRITE_UVLC(sps.maxViews - 1, "num_views_minus1"); |
571 | | for (int i = 0; i <= sps.maxViews - 1; i++) |
572 | | { |
573 | | WRITE_UVLC(!i, "view_position"); |
574 | | } |
575 | | |
576 | | if (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
577 | | { |
578 | | WRITE_FLAG(1, "payload_bit_equal_to_one"); |
579 | | while (m_bitIf->getNumberOfWrittenBits() % X265_BYTE != 0) |
580 | | { |
581 | | WRITE_FLAG(0, "payload_bit_equal_to_zero"); |
582 | | } |
583 | | } |
584 | | } |
585 | | }; |
586 | | #endif |
587 | | |
588 | | class SEIMasteringDisplayColorVolume : public SEI |
589 | | { |
590 | | public: |
591 | | SEIMasteringDisplayColorVolume() |
592 | 0 | { |
593 | 0 | m_payloadType = MASTERING_DISPLAY_INFO; |
594 | 0 | m_payloadSize = (8 * 2 + 2 * 4); |
595 | 0 | } |
596 | | uint16_t displayPrimaryX[3]; |
597 | | uint16_t displayPrimaryY[3]; |
598 | | uint16_t whitePointX, whitePointY; |
599 | | uint32_t maxDisplayMasteringLuminance; |
600 | | uint32_t minDisplayMasteringLuminance; |
601 | | bool parse(const char* value) |
602 | 0 | { |
603 | 0 | return sscanf(value, "G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)", |
604 | 0 | &displayPrimaryX[0], &displayPrimaryY[0], |
605 | 0 | &displayPrimaryX[1], &displayPrimaryY[1], |
606 | 0 | &displayPrimaryX[2], &displayPrimaryY[2], |
607 | 0 | &whitePointX, &whitePointY, |
608 | 0 | &maxDisplayMasteringLuminance, &minDisplayMasteringLuminance) == 10; |
609 | 0 | } |
610 | | void writeSEI(const SPS&) |
611 | 0 | { |
612 | 0 | for (uint32_t i = 0; i < 3; i++) |
613 | 0 | { |
614 | 0 | WRITE_CODE(displayPrimaryX[i], 16, "display_primaries_x[ c ]"); |
615 | 0 | WRITE_CODE(displayPrimaryY[i], 16, "display_primaries_y[ c ]"); |
616 | 0 | } |
617 | 0 | WRITE_CODE(whitePointX, 16, "white_point_x"); |
618 | 0 | WRITE_CODE(whitePointY, 16, "white_point_y"); |
619 | 0 | WRITE_CODE(maxDisplayMasteringLuminance, 32, "max_display_mastering_luminance"); |
620 | 0 | WRITE_CODE(minDisplayMasteringLuminance, 32, "min_display_mastering_luminance"); |
621 | 0 | } |
622 | | }; |
623 | | |
624 | | class SEIContentLightLevel : public SEI |
625 | | { |
626 | | public: |
627 | | SEIContentLightLevel() |
628 | 0 | { |
629 | 0 | m_payloadType = CONTENT_LIGHT_LEVEL_INFO; |
630 | 0 | m_payloadSize = 4; |
631 | 0 | } |
632 | | uint16_t max_content_light_level; |
633 | | uint16_t max_pic_average_light_level; |
634 | | void writeSEI(const SPS&) |
635 | 0 | { |
636 | 0 | WRITE_CODE(max_content_light_level, 16, "max_content_light_level"); |
637 | 0 | WRITE_CODE(max_pic_average_light_level, 16, "max_pic_average_light_level"); |
638 | 0 | } |
639 | | }; |
640 | | |
641 | | class SEIDecodedPictureHash : public SEI |
642 | | { |
643 | | public: |
644 | | SEIDecodedPictureHash() |
645 | 0 | { |
646 | 0 | m_payloadType = DECODED_PICTURE_HASH; |
647 | 0 | m_payloadSize = 0; |
648 | 0 | } |
649 | | enum Method |
650 | | { |
651 | | MD5, |
652 | | CRC, |
653 | | CHECKSUM, |
654 | | } m_method; |
655 | | |
656 | | MD5Context m_state[3]; |
657 | | uint32_t m_crc[3]; |
658 | | uint32_t m_checksum[3]; |
659 | | uint8_t m_digest[3][16]; |
660 | | |
661 | | void writeSEI(const SPS& sps) |
662 | 0 | { |
663 | 0 | int planes = (sps.chromaFormatIdc != X265_CSP_I400) ? 3 : 1; |
664 | 0 | WRITE_CODE(m_method, 8, "hash_type"); |
665 | 0 | for (int yuvIdx = 0; yuvIdx < planes; yuvIdx++) |
666 | 0 | { |
667 | 0 | if (m_method == MD5) |
668 | 0 | { |
669 | 0 | for (uint32_t i = 0; i < 16; i++) |
670 | 0 | WRITE_CODE(m_digest[yuvIdx][i], 8, "picture_md5"); |
671 | 0 | } |
672 | 0 | else if (m_method == CRC) |
673 | 0 | { |
674 | 0 | uint32_t val = (m_digest[yuvIdx][0] << 8) + m_digest[yuvIdx][1]; |
675 | 0 | WRITE_CODE(val, 16, "picture_crc"); |
676 | 0 | } |
677 | 0 | else if (m_method == CHECKSUM) |
678 | 0 | { |
679 | 0 | uint32_t val = (m_digest[yuvIdx][0] << 24) + (m_digest[yuvIdx][1] << 16) + (m_digest[yuvIdx][2] << 8) + m_digest[yuvIdx][3]; |
680 | 0 | WRITE_CODE(val, 32, "picture_checksum"); |
681 | 0 | } |
682 | 0 | } |
683 | 0 | } |
684 | | }; |
685 | | |
686 | | class SEIActiveParameterSets : public SEI |
687 | | { |
688 | | public: |
689 | | SEIActiveParameterSets() |
690 | 0 | { |
691 | 0 | m_payloadType = ACTIVE_PARAMETER_SETS; |
692 | 0 | m_payloadSize = 0; |
693 | 0 | } |
694 | | bool m_selfContainedCvsFlag; |
695 | | bool m_noParamSetUpdateFlag; |
696 | | |
697 | | void writeSEI(const SPS&) |
698 | 0 | { |
699 | 0 | WRITE_CODE(0, 4, "active_vps_id"); |
700 | 0 | WRITE_FLAG(m_selfContainedCvsFlag, "self_contained_cvs_flag"); |
701 | 0 | WRITE_FLAG(m_noParamSetUpdateFlag, "no_param_set_update_flag"); |
702 | 0 | WRITE_UVLC(0, "num_sps_ids_minus1"); |
703 | 0 | WRITE_UVLC(0, "active_seq_param_set_id"); |
704 | 0 | writeByteAlign(); |
705 | 0 | } |
706 | | }; |
707 | | |
708 | | class SEIBufferingPeriod : public SEI |
709 | | { |
710 | | public: |
711 | | SEIBufferingPeriod() |
712 | 0 | : m_cpbDelayOffset(0) |
713 | 0 | , m_dpbDelayOffset(0) |
714 | 0 | , m_concatenationFlag(0) |
715 | 0 | , m_auCpbRemovalDelayDelta(1) |
716 | 0 | { |
717 | 0 | m_payloadType = BUFFERING_PERIOD; |
718 | 0 | m_payloadSize = 0; |
719 | 0 | } |
720 | | bool m_cpbDelayOffset; |
721 | | bool m_dpbDelayOffset; |
722 | | bool m_concatenationFlag; |
723 | | uint32_t m_initialCpbRemovalDelay; |
724 | | uint32_t m_initialCpbRemovalDelayOffset; |
725 | | uint32_t m_auCpbRemovalDelayDelta; |
726 | | |
727 | | void writeSEI(const SPS& sps) |
728 | 0 | { |
729 | 0 | const HRDInfo& hrd = sps.vuiParameters.hrdParameters; |
730 | |
|
731 | 0 | WRITE_UVLC(0, "bp_seq_parameter_set_id"); |
732 | 0 | WRITE_FLAG(0, "rap_cpb_params_present_flag"); |
733 | 0 | WRITE_FLAG(m_concatenationFlag, "concatenation_flag"); |
734 | 0 | WRITE_CODE(m_auCpbRemovalDelayDelta - 1, hrd.cpbRemovalDelayLength, "au_cpb_removal_delay_delta_minus1"); |
735 | 0 | WRITE_CODE(m_initialCpbRemovalDelay, hrd.initialCpbRemovalDelayLength, "initial_cpb_removal_delay"); |
736 | 0 | WRITE_CODE(m_initialCpbRemovalDelayOffset, hrd.initialCpbRemovalDelayLength, "initial_cpb_removal_delay_offset"); |
737 | |
|
738 | 0 | writeByteAlign(); |
739 | 0 | } |
740 | | }; |
741 | | |
742 | | class SEIPictureTiming : public SEI |
743 | | { |
744 | | public: |
745 | | SEIPictureTiming() |
746 | 0 | { |
747 | 0 | m_payloadType = PICTURE_TIMING; |
748 | 0 | m_payloadSize = 0; |
749 | 0 | } |
750 | | uint32_t m_picStruct; |
751 | | uint32_t m_sourceScanType; |
752 | | bool m_duplicateFlag; |
753 | | |
754 | | uint32_t m_auCpbRemovalDelay; |
755 | | uint32_t m_picDpbOutputDelay; |
756 | | |
757 | | void writeSEI(const SPS& sps) |
758 | 0 | { |
759 | 0 | const VUI *vui = &sps.vuiParameters; |
760 | 0 | const HRDInfo *hrd = &vui->hrdParameters; |
761 | |
|
762 | 0 | if (vui->frameFieldInfoPresentFlag) |
763 | 0 | { |
764 | 0 | WRITE_CODE(m_picStruct, 4, "pic_struct"); |
765 | 0 | WRITE_CODE(m_sourceScanType, 2, "source_scan_type"); |
766 | 0 | WRITE_FLAG(m_duplicateFlag, "duplicate_flag"); |
767 | 0 | } |
768 | |
|
769 | 0 | if (vui->hrdParametersPresentFlag) |
770 | 0 | { |
771 | 0 | WRITE_CODE(m_auCpbRemovalDelay - 1, hrd->cpbRemovalDelayLength, "au_cpb_removal_delay_minus1"); |
772 | 0 | WRITE_CODE(m_picDpbOutputDelay, hrd->dpbOutputDelayLength, "pic_dpb_output_delay"); |
773 | | /* Removed sub-pic signaling June 2014 */ |
774 | 0 | } |
775 | 0 | writeByteAlign(); |
776 | 0 | } |
777 | | }; |
778 | | |
779 | | class SEIRecoveryPoint : public SEI |
780 | | { |
781 | | public: |
782 | | SEIRecoveryPoint() |
783 | 0 | { |
784 | 0 | m_payloadType = RECOVERY_POINT; |
785 | 0 | m_payloadSize = 0; |
786 | 0 | } |
787 | | int m_recoveryPocCnt; |
788 | | bool m_exactMatchingFlag; |
789 | | bool m_brokenLinkFlag; |
790 | | |
791 | | void writeSEI(const SPS&) |
792 | 0 | { |
793 | 0 | WRITE_SVLC(m_recoveryPocCnt, "recovery_poc_cnt"); |
794 | 0 | WRITE_FLAG(m_exactMatchingFlag, "exact_matching_flag"); |
795 | 0 | WRITE_FLAG(m_brokenLinkFlag, "broken_link_flag"); |
796 | 0 | writeByteAlign(); |
797 | 0 | } |
798 | | }; |
799 | | |
800 | | class SEIAlternativeTC : public SEI |
801 | | { |
802 | | public: |
803 | | int m_preferredTransferCharacteristics; |
804 | | SEIAlternativeTC() |
805 | 0 | { |
806 | 0 | m_payloadType = ALTERNATIVE_TRANSFER_CHARACTERISTICS; |
807 | 0 | m_payloadSize = 0; |
808 | 0 | m_preferredTransferCharacteristics = -1; |
809 | 0 | } |
810 | | |
811 | | void writeSEI(const SPS&) |
812 | 0 | { |
813 | 0 | WRITE_CODE(m_preferredTransferCharacteristics, 8, "Preferred transfer characteristics"); |
814 | 0 | } |
815 | | }; |
816 | | |
817 | | } |
818 | | #endif // ifndef X265_SEI_H |