您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

608 行
17KB

  1. #include "aom-av1.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include "mpeg4-bits.h"
  7. // https://aomediacodec.github.io/av1-isobmff
  8. // https://aomediacodec.github.io/av1-avif/
  9. enum
  10. {
  11. OBU_SEQUENCE_HEADER = 1,
  12. OBU_TEMPORAL_DELIMITER = 2,
  13. OBU_FRAME_HEADER = 3,
  14. OBU_TILE_GROUP = 4,
  15. OBU_METADATA = 5,
  16. OBU_FRAME = 6,
  17. OBU_REDUNDANT_FRAME_HEADER = 7,
  18. OBU_TILE_LIST = 8,
  19. // 9-14 Reserved
  20. OBU_PADDING = 15,
  21. };
  22. /*
  23. aligned (8) class AV1CodecConfigurationRecord {
  24. unsigned int (1) marker = 1;
  25. unsigned int (7) version = 1;
  26. unsigned int (3) seq_profile;
  27. unsigned int (5) seq_level_idx_0;
  28. unsigned int (1) seq_tier_0;
  29. unsigned int (1) high_bitdepth;
  30. unsigned int (1) twelve_bit;
  31. unsigned int (1) monochrome;
  32. unsigned int (1) chroma_subsampling_x;
  33. unsigned int (1) chroma_subsampling_y;
  34. unsigned int (2) chroma_sample_position;
  35. unsigned int (3) reserved = 0;
  36. unsigned int (1) initial_presentation_delay_present;
  37. if (initial_presentation_delay_present) {
  38. unsigned int (4) initial_presentation_delay_minus_one;
  39. } else {
  40. unsigned int (4) reserved = 0;
  41. }
  42. unsigned int (8)[] configOBUs;
  43. }
  44. */
  45. int aom_av1_codec_configuration_record_load(const uint8_t* data, size_t bytes, struct aom_av1_t* av1)
  46. {
  47. if (bytes < 4)
  48. return -1;
  49. av1->marker = data[0] >> 7;
  50. av1->version = data[0] & 0x7F;
  51. av1->seq_profile = data[1] >> 5;
  52. av1->seq_level_idx_0 = data[1] & 0x1F;
  53. av1->seq_tier_0 = data[2] >> 7;
  54. av1->high_bitdepth = (data[2] >> 6) & 0x01;
  55. av1->twelve_bit = (data[2] >> 5) & 0x01;
  56. av1->monochrome = (data[2] >> 4) & 0x01;
  57. av1->chroma_subsampling_x = (data[2] >> 3) & 0x01;
  58. av1->chroma_subsampling_y = (data[2] >> 2) & 0x01;
  59. av1->chroma_sample_position = data[2] & 0x03;
  60. av1->reserved = data[3] >> 5;
  61. av1->initial_presentation_delay_present = (data[3] >> 4) & 0x01;
  62. av1->initial_presentation_delay_minus_one = data[3] & 0x0F;
  63. if (bytes - 4 > sizeof(av1->data))
  64. return -1;
  65. av1->bytes = (uint16_t)(bytes - 4);
  66. memcpy(av1->data, data + 4, av1->bytes);
  67. return (int)bytes;
  68. }
  69. int aom_av1_codec_configuration_record_save(const struct aom_av1_t* av1, uint8_t* data, size_t bytes)
  70. {
  71. if (bytes < (size_t)av1->bytes + 4)
  72. return 0; // don't have enough memory
  73. data[0] = (uint8_t)((av1->marker << 7) | av1->version);
  74. data[1] = (uint8_t)((av1->seq_profile << 5) | av1->seq_level_idx_0);
  75. data[2] = (uint8_t)((av1->seq_tier_0 << 7) | (av1->high_bitdepth << 6) | (av1->twelve_bit << 5) | (av1->monochrome << 4) | (av1->chroma_subsampling_x << 3) | (av1->chroma_subsampling_y << 2) | av1->chroma_sample_position);
  76. data[3] = (uint8_t)((av1->initial_presentation_delay_present << 4) | av1->initial_presentation_delay_minus_one);
  77. memcpy(data + 4, av1->data, av1->bytes);
  78. return av1->bytes + 4;
  79. }
  80. static inline const uint8_t* leb128(const uint8_t* data, int bytes, uint64_t* v)
  81. {
  82. int i;
  83. uint64_t b;
  84. b = 0x80;
  85. for (*v = i = 0; i * 7 < 64 && i < bytes && 0 != (b & 0x80); i++)
  86. {
  87. b = data[i];
  88. *v |= (b & 0x7F) << (i * 7);
  89. }
  90. return data + i;
  91. }
  92. int aom_av1_annexb_split(const uint8_t* data, size_t bytes, int (*handler)(void* param, const uint8_t* obu, size_t bytes), void* param)
  93. {
  94. int r;
  95. uint64_t n[3];
  96. const uint8_t* temporal, * frame, * obu;
  97. r = 0;
  98. for (temporal = data; temporal < data + bytes && 0 == r; temporal += n[0])
  99. {
  100. // temporal_unit_size
  101. temporal = leb128(temporal, (int)(data + bytes - temporal), &n[0]);
  102. if (temporal + n[0] > data + bytes)
  103. return -1;
  104. for (frame = temporal; frame < temporal + n[0] && 0 == r; frame += n[1])
  105. {
  106. // frame_unit_size
  107. frame = leb128(frame, (int)(temporal + n[0] - frame), &n[1]);
  108. if (frame + n[1] > temporal + n[0])
  109. return -1;
  110. for (obu = frame; obu < frame + n[1] && 0 == r; obu += n[2])
  111. {
  112. obu = leb128(obu, (int)(frame + n[1] - obu), &n[2]);
  113. if (obu + n[2] > frame + n[1])
  114. return -1;
  115. r = handler(param, obu, (size_t)n[2]);
  116. }
  117. }
  118. }
  119. return r;
  120. }
  121. int aom_av1_obu_split(const uint8_t* data, size_t bytes, int (*handler)(void* param, const uint8_t* obu, size_t bytes), void* param)
  122. {
  123. int r;
  124. size_t i;
  125. size_t offset;
  126. uint64_t len;
  127. uint8_t obu_type;
  128. const uint8_t* ptr;
  129. for (i = r = 0; i < bytes && 0 == r; i += (size_t)len)
  130. {
  131. // http://aomedia.org/av1/specification/syntax/#obu-header-syntax
  132. obu_type = (data[i] >> 3) & 0x0F;
  133. if (data[i] & 0x04) // obu_extension_flag
  134. {
  135. // http://aomedia.org/av1/specification/syntax/#obu-extension-header-syntax
  136. // temporal_id = (obu[1] >> 5) & 0x07;
  137. // spatial_id = (obu[1] >> 3) & 0x03;
  138. offset = 2;
  139. }
  140. else
  141. {
  142. offset = 1;
  143. }
  144. if (data[i] & 0x02) // obu_has_size_field
  145. {
  146. ptr = leb128(data + i + offset, (int)(bytes - i - offset), &len);
  147. if (ptr + len > data + bytes)
  148. return -1;
  149. len += ptr - data - i;
  150. }
  151. else
  152. {
  153. len = bytes - i;
  154. }
  155. r = handler(param, data + i, (size_t)len);
  156. }
  157. return r;
  158. }
  159. // http://aomedia.org/av1/specification/syntax/#color-config-syntax
  160. static int aom_av1_color_config(struct mpeg4_bits_t* bits, struct aom_av1_t* av1)
  161. {
  162. uint8_t BitDepth;
  163. uint8_t color_primaries;
  164. uint8_t transfer_characteristics;
  165. uint8_t matrix_coefficients;
  166. av1->high_bitdepth = mpeg4_bits_read(bits);
  167. if (av1->seq_profile == 2 && av1->high_bitdepth)
  168. {
  169. av1->twelve_bit = mpeg4_bits_read(bits);
  170. BitDepth = av1->twelve_bit ? 12 : 10;
  171. }
  172. else if (av1->seq_profile <= 2)
  173. {
  174. BitDepth = av1->high_bitdepth ? 10 : 8;
  175. }
  176. else
  177. {
  178. assert(0);
  179. BitDepth = 8;
  180. }
  181. if (av1->seq_profile == 1)
  182. {
  183. av1->monochrome = 0;
  184. }
  185. else
  186. {
  187. av1->monochrome = mpeg4_bits_read(bits);
  188. }
  189. if (mpeg4_bits_read(bits)) // color_description_present_flag
  190. {
  191. color_primaries = mpeg4_bits_read_uint8(bits, 8); // color_primaries
  192. transfer_characteristics = mpeg4_bits_read_uint8(bits, 8); // transfer_characteristics
  193. matrix_coefficients = mpeg4_bits_read_uint8(bits, 8); // matrix_coefficients
  194. }
  195. else
  196. {
  197. // http://aomedia.org/av1/specification/semantics/#color-config-semantics
  198. color_primaries = 2; // CP_UNSPECIFIED;
  199. transfer_characteristics = 2; // TC_UNSPECIFIED;
  200. matrix_coefficients = 2; // MC_UNSPECIFIED;
  201. }
  202. if (av1->monochrome)
  203. {
  204. mpeg4_bits_read(bits); // color_range
  205. av1->chroma_subsampling_x = 1;
  206. av1->chroma_subsampling_y = 1;
  207. }
  208. else if (color_primaries == 1 /*CP_BT_709*/ && transfer_characteristics == 13 /*TC_SRGB*/ && matrix_coefficients == 0 /*MC_IDENTITY*/)
  209. {
  210. av1->chroma_subsampling_x = 0;
  211. av1->chroma_subsampling_y = 0;
  212. }
  213. else
  214. {
  215. mpeg4_bits_read(bits); // color_range
  216. if (av1->seq_profile == 0)
  217. {
  218. av1->chroma_subsampling_x = 1;
  219. av1->chroma_subsampling_y = 1;
  220. }
  221. else if (av1->seq_profile == 1)
  222. {
  223. av1->chroma_subsampling_x = 0;
  224. av1->chroma_subsampling_y = 0;
  225. }
  226. else
  227. {
  228. if (BitDepth == 12)
  229. {
  230. av1->chroma_subsampling_x = mpeg4_bits_read(bits);
  231. if (av1->chroma_subsampling_x)
  232. av1->chroma_subsampling_y = mpeg4_bits_read(bits);
  233. else
  234. av1->chroma_subsampling_y = 0;
  235. }
  236. else
  237. {
  238. av1->chroma_subsampling_x = 1;
  239. av1->chroma_subsampling_y = 0;
  240. }
  241. }
  242. if (av1->chroma_subsampling_x && av1->chroma_subsampling_y)
  243. av1->chroma_sample_position = mpeg4_bits_read_uint32(bits, 2);
  244. }
  245. mpeg4_bits_read(bits); // separate_uv_delta_q
  246. return 0;
  247. }
  248. // http://aomedia.org/av1/specification/syntax/#timing-info-syntax
  249. static int aom_av1_timing_info(struct mpeg4_bits_t* bits, struct aom_av1_t* av1)
  250. {
  251. (void)av1;
  252. mpeg4_bits_read_n(bits, 32); // num_units_in_display_tick
  253. mpeg4_bits_read_n(bits, 32); // time_scale
  254. if(mpeg4_bits_read(bits)) // equal_picture_interval
  255. mpeg4_bits_read_uvlc(bits); // num_ticks_per_picture_minus_1
  256. return 0;
  257. }
  258. // http://aomedia.org/av1/specification/syntax/#decoder-model-info-syntax
  259. static int aom_av1_decoder_model_info(struct mpeg4_bits_t* bits, struct aom_av1_t* av1)
  260. {
  261. av1->buffer_delay_length_minus_1 = mpeg4_bits_read_uint8(bits, 5); // buffer_delay_length_minus_1
  262. mpeg4_bits_read_n(bits, 32); // num_units_in_decoding_tick
  263. mpeg4_bits_read_n(bits, 5); // buffer_removal_time_length_minus_1
  264. mpeg4_bits_read_n(bits, 5); // frame_presentation_time_length_minus_1
  265. return 0;
  266. }
  267. // http://aomedia.org/av1/specification/syntax/#operating-parameters-info-syntax
  268. static int aom_av1_operating_parameters_info(struct mpeg4_bits_t* bits, struct aom_av1_t* av1, int op)
  269. {
  270. uint8_t n;
  271. n = av1->buffer_delay_length_minus_1 + 1;
  272. mpeg4_bits_read_n(bits, n); // decoder_buffer_delay[ op ]
  273. mpeg4_bits_read_n(bits, n); // encoder_buffer_delay[ op ]
  274. mpeg4_bits_read(bits); // low_delay_mode_flag[ op ]
  275. (void)op;
  276. return 0;
  277. }
  278. // http://aomedia.org/av1/specification/syntax/#sequence-header-obu-syntax
  279. static int aom_av1_obu_sequence_header(struct aom_av1_t* av1, const void* data, size_t bytes)
  280. {
  281. uint8_t i;
  282. uint8_t reduced_still_picture_header;
  283. uint8_t decoder_model_info_present_flag;
  284. uint8_t operating_points_cnt_minus_1;
  285. uint8_t frame_width_bits_minus_1;
  286. uint8_t frame_height_bits_minus_1;
  287. uint8_t enable_order_hint;
  288. uint8_t seq_force_screen_content_tools;
  289. struct mpeg4_bits_t bits;
  290. mpeg4_bits_init(&bits, (void*)data, bytes);
  291. av1->seq_profile = mpeg4_bits_read_uint32(&bits, 3);
  292. mpeg4_bits_read(&bits); // still_picture
  293. reduced_still_picture_header = mpeg4_bits_read_uint8(&bits, 1);
  294. if (reduced_still_picture_header)
  295. {
  296. av1->initial_presentation_delay_present = 0; // initial_display_delay_present_flag
  297. av1->seq_level_idx_0 = mpeg4_bits_read_uint32(&bits, 5);
  298. av1->seq_tier_0 = 0;
  299. decoder_model_info_present_flag = 0;
  300. }
  301. else
  302. {
  303. if (mpeg4_bits_read(&bits)) // timing_info_present_flag
  304. {
  305. // timing_info( )
  306. aom_av1_timing_info(&bits, av1);
  307. decoder_model_info_present_flag = mpeg4_bits_read_uint8(&bits, 1); // decoder_model_info_present_flag
  308. if (decoder_model_info_present_flag)
  309. {
  310. // decoder_model_info( )
  311. aom_av1_decoder_model_info(&bits, av1);
  312. }
  313. }
  314. else
  315. {
  316. decoder_model_info_present_flag = 0;
  317. }
  318. av1->initial_presentation_delay_present = mpeg4_bits_read(&bits); // initial_display_delay_present_flag =
  319. operating_points_cnt_minus_1 = mpeg4_bits_read_uint8(&bits, 5);
  320. for (i = 0; i <= operating_points_cnt_minus_1; i++)
  321. {
  322. uint8_t seq_level_idx;
  323. uint8_t seq_tier;
  324. uint8_t initial_display_delay_minus_1;
  325. mpeg4_bits_read_n(&bits, 12); // operating_point_idc[ i ]
  326. seq_level_idx = mpeg4_bits_read_uint8(&bits, 5); // seq_level_idx[ i ]
  327. if (seq_level_idx > 7)
  328. {
  329. seq_tier = mpeg4_bits_read_uint8(&bits, 1); // seq_tier[ i ]
  330. }
  331. else
  332. {
  333. seq_tier = 0;
  334. }
  335. if (decoder_model_info_present_flag)
  336. {
  337. if (mpeg4_bits_read(&bits)) // decoder_model_present_for_this_op[i]
  338. {
  339. aom_av1_operating_parameters_info(&bits, av1, i);
  340. }
  341. }
  342. if (av1->initial_presentation_delay_present && mpeg4_bits_read(&bits)) // initial_display_delay_present_for_this_op[ i ]
  343. initial_display_delay_minus_1 = mpeg4_bits_read_uint8(&bits, 4); // initial_display_delay_minus_1[ i ]
  344. else
  345. initial_display_delay_minus_1 = 0;
  346. if (0 == i)
  347. {
  348. av1->seq_level_idx_0 = seq_level_idx;
  349. av1->seq_tier_0 = seq_tier;
  350. av1->initial_presentation_delay_minus_one = initial_display_delay_minus_1;
  351. }
  352. }
  353. }
  354. // choose_operating_point( )
  355. frame_width_bits_minus_1 = mpeg4_bits_read_uint8(&bits, 4);
  356. frame_height_bits_minus_1 = mpeg4_bits_read_uint8(&bits, 4);
  357. av1->width = 1 + mpeg4_bits_read_uint32(&bits, frame_width_bits_minus_1 + 1); // max_frame_width_minus_1
  358. av1->height = 1 + mpeg4_bits_read_uint32(&bits, frame_height_bits_minus_1 + 1); // max_frame_height_minus_1
  359. if (!reduced_still_picture_header && mpeg4_bits_read(&bits)) // frame_id_numbers_present_flag
  360. {
  361. mpeg4_bits_read_n(&bits, 4); // delta_frame_id_length_minus_2
  362. mpeg4_bits_read_n(&bits, 3); // additional_frame_id_length_minus_1
  363. }
  364. mpeg4_bits_read(&bits); // use_128x128_superblock
  365. mpeg4_bits_read(&bits); // enable_filter_intra
  366. mpeg4_bits_read(&bits); // enable_intra_edge_filter
  367. if (!reduced_still_picture_header)
  368. {
  369. mpeg4_bits_read(&bits); // enable_interintra_compound
  370. mpeg4_bits_read(&bits); // enable_masked_compound
  371. mpeg4_bits_read(&bits); // enable_warped_motion
  372. mpeg4_bits_read(&bits); // enable_dual_filter
  373. enable_order_hint = mpeg4_bits_read_uint8(&bits, 1);
  374. if (enable_order_hint)
  375. {
  376. mpeg4_bits_read(&bits); // enable_jnt_comp
  377. mpeg4_bits_read(&bits); // enable_ref_frame_mvs
  378. }
  379. if (mpeg4_bits_read(&bits)) // seq_choose_screen_content_tools
  380. {
  381. seq_force_screen_content_tools = 2; // SELECT_SCREEN_CONTENT_TOOLS;
  382. }
  383. else
  384. {
  385. seq_force_screen_content_tools = mpeg4_bits_read_uint8(&bits, 1); // seq_force_screen_content_tools
  386. }
  387. if (seq_force_screen_content_tools > 0)
  388. {
  389. if (!mpeg4_bits_read(&bits)) // seq_choose_integer_mv
  390. mpeg4_bits_read(&bits); // seq_force_integer_mv
  391. //else
  392. // seq_force_integer_mv = SELECT_INTEGER_MV
  393. }
  394. else
  395. {
  396. //seq_force_integer_mv = SELECT_INTEGER_MV;
  397. }
  398. if (enable_order_hint)
  399. {
  400. mpeg4_bits_read_n(&bits, 3); // order_hint_bits_minus_1
  401. }
  402. }
  403. mpeg4_bits_read(&bits); // enable_superres
  404. mpeg4_bits_read(&bits); // enable_cdef
  405. mpeg4_bits_read(&bits); // enable_restoration
  406. // color_config( )
  407. aom_av1_color_config(&bits, av1);
  408. mpeg4_bits_read(&bits); // film_grain_params_present
  409. return mpeg4_bits_error(&bits) ? -1 : 0;
  410. }
  411. // http://aomedia.org/av1/specification/syntax/#general-obu-syntax
  412. static int aom_av1_extra_handler(void* param, const uint8_t* obu, size_t bytes)
  413. {
  414. uint64_t i;
  415. uint64_t len;
  416. size_t offset;
  417. uint8_t obu_type;
  418. const uint8_t* ptr;
  419. struct aom_av1_t* av1;
  420. av1 = (struct aom_av1_t*)param;
  421. if (bytes < 2)
  422. return -1;
  423. // http://aomedia.org/av1/specification/syntax/#obu-header-syntax
  424. obu_type = (obu[0] >> 3) & 0x0F;
  425. if (obu[0] & 0x04) // obu_extension_flag
  426. {
  427. // http://aomedia.org/av1/specification/syntax/#obu-extension-header-syntax
  428. // temporal_id = (obu[1] >> 5) & 0x07;
  429. // spatial_id = (obu[1] >> 3) & 0x03;
  430. offset = 2;
  431. }
  432. else
  433. {
  434. offset = 1;
  435. }
  436. if (obu[0] & 0x02) // obu_has_size_field
  437. {
  438. ptr = leb128(obu + offset, (int)(bytes - offset), &len);
  439. if (ptr + len > obu + bytes)
  440. return -1;
  441. }
  442. else
  443. {
  444. ptr = obu + offset;
  445. len = bytes - offset;
  446. }
  447. if (OBU_SEQUENCE_HEADER == obu_type || OBU_METADATA == obu_type)
  448. {
  449. if (av1->bytes + bytes + 8 /*leb128*/ >= sizeof(av1->data))
  450. return -1;
  451. av1->data[av1->bytes++] = obu[0] | 0x02 /*obu_has_size_field*/;
  452. if (obu[0] & 0x04) // obu_extension_flag
  453. av1->data[av1->bytes++] = obu[1];
  454. //if (0 == (obu[0] & 0x02))
  455. {
  456. // fill obu size, leb128
  457. for(i = len; i >= 0x80; av1->bytes++)
  458. {
  459. av1->data[av1->bytes] = (uint8_t)(i & 0x7F);
  460. av1->data[av1->bytes] |= 0x80;
  461. i >>= 7;
  462. }
  463. av1->data[av1->bytes++] = (uint8_t)(i & 0x7F);
  464. }
  465. memcpy(av1->data + av1->bytes, ptr, (size_t)len);
  466. av1->bytes += (uint16_t)len;
  467. }
  468. // http://aomedia.org/av1/specification/semantics/#obu-header-semantics
  469. if (obu_type == OBU_SEQUENCE_HEADER)
  470. {
  471. return aom_av1_obu_sequence_header(av1, ptr, (size_t)len);
  472. }
  473. return 0;
  474. }
  475. // https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-section
  476. int aom_av1_codec_configuration_record_init(struct aom_av1_t* av1, const void* data, size_t bytes)
  477. {
  478. av1->version = 1;
  479. av1->marker = 1;
  480. return aom_av1_obu_split((const uint8_t*)data, bytes, aom_av1_extra_handler, av1);
  481. }
  482. int aom_av1_codecs(const struct aom_av1_t* av1, char* codecs, size_t bytes)
  483. {
  484. unsigned int bitdepth;
  485. // AV1 5.5.2.Color config syntax
  486. if (2 == av1->seq_profile && av1->high_bitdepth)
  487. bitdepth = av1->twelve_bit ? 12 : 10;
  488. else
  489. bitdepth = av1->high_bitdepth ? 10 : 8;
  490. // https://aomediacodec.github.io/av1-isobmff/#codecsparam
  491. // https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter
  492. // <sample entry 4CC>.<profile>.<level><tier>.<bitDepth>.<monochrome>.<chromaSubsampling>.<colorPrimaries>.<transferCharacteristics>.<matrixCoefficients>.<videoFullRangeFlag>
  493. return snprintf(codecs, bytes, "av01.%u.%02u%c.%02u", (unsigned int)av1->seq_profile, (unsigned int)av1->seq_level_idx_0, av1->seq_tier_0 ? 'H' : 'M', (unsigned int)bitdepth);
  494. }
  495. #if defined(_DEBUG) || defined(DEBUG)
  496. void aom_av1_test(void)
  497. {
  498. const unsigned char src[] = {
  499. 0x81, 0x04, 0x0c, 0x00, 0x0a, 0x0b, 0x00, 0x00, 0x00, 0x24, 0xcf, 0x7f, 0x0d, 0xbf, 0xff, 0x30, 0x08
  500. };
  501. unsigned char data[sizeof(src)];
  502. struct aom_av1_t av1;
  503. assert(sizeof(src) == aom_av1_codec_configuration_record_load(src, sizeof(src), &av1));
  504. assert(1 == av1.version && 0 == av1.seq_profile && 4 == av1.seq_level_idx_0);
  505. assert(0 == av1.seq_tier_0 && 0 == av1.high_bitdepth && 0 == av1.twelve_bit && 0 == av1.monochrome && 1 == av1.chroma_subsampling_x && 1 == av1.chroma_subsampling_y && 0 == av1.chroma_sample_position);
  506. assert(0 == av1.initial_presentation_delay_present && 0 == av1.initial_presentation_delay_minus_one);
  507. assert(13 == av1.bytes);
  508. assert(sizeof(src) == aom_av1_codec_configuration_record_save(&av1, data, sizeof(data)));
  509. assert(0 == memcmp(src, data, sizeof(src)));
  510. aom_av1_codecs(&av1, (char*)data, sizeof(data));
  511. assert(0 == memcmp("av01.0.04M.08", data, 13));
  512. }
  513. void aom_av1_sequence_header_obu_test(void)
  514. {
  515. const uint8_t obu[] = { /*0x0A, 0x0B,*/ 0x00, 0x00, 0x00, 0x2C, 0xCF, 0x7F, 0x0D, 0xBF, 0xFF, 0x38, 0x18 };
  516. struct aom_av1_t av1;
  517. memset(&av1, 0, sizeof(av1));
  518. assert(0 == aom_av1_obu_sequence_header(&av1, obu, sizeof(obu)));
  519. }
  520. void aom_av1_obu_test(const char* file)
  521. {
  522. size_t n;
  523. FILE* fp;
  524. struct aom_av1_t av1;
  525. static uint8_t buffer[24 * 1024 * 1024];
  526. aom_av1_sequence_header_obu_test();
  527. memset(&av1, 0, sizeof(av1));
  528. fp = fopen(file, "rb");
  529. n = fread(buffer, 1, sizeof(buffer), fp);
  530. aom_av1_codec_configuration_record_init(&av1, buffer, n);
  531. fclose(fp);
  532. }
  533. #endif