av1_config.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2018, Alliance for Open Media. All rights reserved
  3. *
  4. * This source code is subject to the terms of the BSD 2 Clause License and
  5. * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
  6. * was not distributed with this source code in the LICENSE file, you can
  7. * obtain it at www.aomedia.org/license/software. If the Alliance for Open
  8. * Media Patent License 1.0 was not distributed with this source code in the
  9. * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  10. */
  11. #ifndef AOM_COMMON_AV1_CONFIG_H_
  12. #define AOM_COMMON_AV1_CONFIG_H_
  13. #include "aom/aom_integer.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. // Struct representing ISOBMFF/Matroska AV1 config. See:
  18. // https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-syntax
  19. //
  20. // The AV1 config has the following format:
  21. //
  22. // unsigned int (1) marker = 1;
  23. // unsigned int (7) version = 1;
  24. // unsigned int (3) seq_profile;
  25. // unsigned int (5) seq_level_idx_0;
  26. // unsigned int (1) seq_tier_0;
  27. // unsigned int (1) high_bitdepth;
  28. // unsigned int (1) twelve_bit;
  29. // unsigned int (1) monochrome;
  30. // unsigned int (1) chroma_subsampling_x;
  31. // unsigned int (1) chroma_subsampling_y;
  32. // unsigned int (2) chroma_sample_position;
  33. // unsigned int (3) reserved = 0;
  34. //
  35. // unsigned int (1) initial_presentation_delay_present;
  36. // if (initial_presentation_delay_present) {
  37. // unsigned int (4) initial_presentation_delay_minus_one;
  38. // } else {
  39. // unsigned int (4) reserved = 0;
  40. // }
  41. //
  42. // unsigned int (8)[] configOBUs;
  43. //
  44. // Note: get_av1config_from_obu() does not currently store 'configOBUs' data, so
  45. // the field is omitted.
  46. typedef struct _Av1Config {
  47. uint8_t marker;
  48. uint8_t version;
  49. uint8_t seq_profile;
  50. uint8_t seq_level_idx_0;
  51. uint8_t seq_tier_0;
  52. uint8_t high_bitdepth;
  53. uint8_t twelve_bit;
  54. uint8_t monochrome;
  55. uint8_t chroma_subsampling_x;
  56. uint8_t chroma_subsampling_y;
  57. uint8_t chroma_sample_position;
  58. uint8_t initial_presentation_delay_present;
  59. uint8_t initial_presentation_delay_minus_one;
  60. } Av1Config;
  61. // Attempts to parse a Sequence Header OBU and set the paramenters of 'config'.
  62. // Returns 0 upon success, and -1 upon failure. 'buffer' can contain multiple
  63. // OBUs, but the Sequence Header OBU must be the first OBU within the buffer.
  64. int get_av1config_from_obu(const uint8_t *buffer, size_t length, int is_annexb,
  65. Av1Config *config);
  66. // Attempts to parse an AV1 config from 'buffer'. Returns 0 upon success.
  67. // Returns -1 when 'buffer_length' is less than 4, when passed NULL pointers, or
  68. // when parsing of 'buffer' fails.
  69. int read_av1config(const uint8_t *buffer, size_t buffer_length,
  70. size_t *bytes_read, Av1Config *config);
  71. // Writes 'config' to 'buffer'. Returns 0 upon successful write to 'buffer'.
  72. // Returns -1 when passed NULL pointers or when 'capacity' insufficient.
  73. int write_av1config(const Av1Config *config, size_t capacity,
  74. size_t *bytes_written, uint8_t *buffer);
  75. #ifdef __cplusplus
  76. } /* extern "C" */
  77. #endif
  78. #endif // AOM_COMMON_AV1_CONFIG_H_