You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.7KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_CBS_SEI_H
  19. #define AVCODEC_CBS_SEI_H
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. #include "libavutil/buffer.h"
  23. #include "cbs.h"
  24. #include "sei.h"
  25. typedef struct SEIRawFillerPayload {
  26. uint32_t payload_size;
  27. } SEIRawFillerPayload;
  28. typedef struct SEIRawUserDataRegistered {
  29. uint8_t itu_t_t35_country_code;
  30. uint8_t itu_t_t35_country_code_extension_byte;
  31. uint8_t *data;
  32. AVBufferRef *data_ref;
  33. size_t data_length;
  34. } SEIRawUserDataRegistered;
  35. typedef struct SEIRawUserDataUnregistered {
  36. uint8_t uuid_iso_iec_11578[16];
  37. uint8_t *data;
  38. AVBufferRef *data_ref;
  39. size_t data_length;
  40. } SEIRawUserDataUnregistered;
  41. typedef struct SEIRawMasteringDisplayColourVolume {
  42. uint16_t display_primaries_x[3];
  43. uint16_t display_primaries_y[3];
  44. uint16_t white_point_x;
  45. uint16_t white_point_y;
  46. uint32_t max_display_mastering_luminance;
  47. uint32_t min_display_mastering_luminance;
  48. } SEIRawMasteringDisplayColourVolume;
  49. typedef struct SEIRawContentLightLevelInfo {
  50. uint16_t max_content_light_level;
  51. uint16_t max_pic_average_light_level;
  52. } SEIRawContentLightLevelInfo;
  53. typedef struct SEIRawAlternativeTransferCharacteristics {
  54. uint8_t preferred_transfer_characteristics;
  55. } SEIRawAlternativeTransferCharacteristics;
  56. typedef struct SEIRawMessage {
  57. uint32_t payload_type;
  58. uint32_t payload_size;
  59. void *payload;
  60. AVBufferRef *payload_ref;
  61. uint8_t *extension_data;
  62. AVBufferRef *extension_data_ref;
  63. size_t extension_bit_length;
  64. } SEIRawMessage;
  65. typedef struct SEIRawMessageList {
  66. SEIRawMessage *messages;
  67. int nb_messages;
  68. int nb_messages_allocated;
  69. } SEIRawMessageList;
  70. typedef struct SEIMessageState {
  71. // The type of the payload being written.
  72. uint32_t payload_type;
  73. // When reading, contains the size of the payload to allow finding the
  74. // end of variable-length fields (such as user_data_payload_byte[]).
  75. // (When writing, the size will be derived from the total number of
  76. // bytes actually written.)
  77. uint32_t payload_size;
  78. // When writing, indicates that payload extension data is present so
  79. // all extended fields must be written. May be updated by the writer
  80. // to indicate that extended fields have been written, so the extension
  81. // end bits must be written too.
  82. uint8_t extension_present;
  83. } SEIMessageState;
  84. struct GetBitContext;
  85. struct PutBitContext;
  86. typedef int (*SEIMessageReadFunction)(CodedBitstreamContext *ctx,
  87. struct GetBitContext *rw,
  88. void *current,
  89. SEIMessageState *sei);
  90. typedef int (*SEIMessageWriteFunction)(CodedBitstreamContext *ctx,
  91. struct PutBitContext *rw,
  92. void *current,
  93. SEIMessageState *sei);
  94. typedef struct SEIMessageTypeDescriptor {
  95. // Payload type for the message. (-1 in this field ends a list.)
  96. int type;
  97. // Valid in a prefix SEI NAL unit (always for H.264).
  98. uint8_t prefix;
  99. // Valid in a suffix SEI NAL unit (never for H.264).
  100. uint8_t suffix;
  101. // Size of the decomposed structure.
  102. size_t size;
  103. // Read bitstream into SEI message.
  104. SEIMessageReadFunction read;
  105. // Write bitstream from SEI message.
  106. SEIMessageWriteFunction write;
  107. } SEIMessageTypeDescriptor;
  108. // Macro for the read/write pair. The clumsy cast is needed because the
  109. // current pointer is typed in all of the read/write functions but has to
  110. // be void here to fit all cases.
  111. #define SEI_MESSAGE_RW(codec, name) \
  112. .read = (SEIMessageReadFunction) cbs_ ## codec ## _read_ ## name, \
  113. .write = (SEIMessageWriteFunction)cbs_ ## codec ## _write_ ## name
  114. // End-of-list sentinel element.
  115. #define SEI_MESSAGE_TYPE_END { .type = -1 }
  116. /**
  117. * Find the type descriptor for the given payload type.
  118. *
  119. * Returns NULL if the payload type is not known.
  120. */
  121. const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext *ctx,
  122. int payload_type);
  123. /**
  124. * Allocate a new payload for the given SEI message.
  125. */
  126. int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message,
  127. const SEIMessageTypeDescriptor *desc);
  128. /**
  129. * Allocate a new empty SEI message in a message list.
  130. *
  131. * The new message is in place nb_messages - 1.
  132. */
  133. int ff_cbs_sei_list_add(SEIRawMessageList *list);
  134. /**
  135. * Free all SEI messages in a message list.
  136. */
  137. void ff_cbs_sei_free_message_list(SEIRawMessageList *list);
  138. /**
  139. * Add an SEI message to an access unit.
  140. *
  141. * Will add to an existing SEI NAL unit, or create a new one for the
  142. * message if there is no suitable existing one.
  143. *
  144. * Takes a new reference to payload_buf, if set. If payload_buf is
  145. * NULL then the new message will not be reference counted.
  146. */
  147. int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
  148. CodedBitstreamFragment *au,
  149. int prefix,
  150. uint32_t payload_type,
  151. void *payload_data,
  152. AVBufferRef *payload_buf);
  153. /**
  154. * Iterate over messages with the given payload type in an access unit.
  155. *
  156. * Set message to NULL in the first call. Returns 0 while more messages
  157. * are available, AVERROR(ENOENT) when all messages have been found.
  158. */
  159. int ff_cbs_sei_find_message(CodedBitstreamContext *ctx,
  160. CodedBitstreamFragment *au,
  161. uint32_t payload_type,
  162. SEIRawMessage **message);
  163. /**
  164. * Delete all messages with the given payload type from an access unit.
  165. */
  166. void ff_cbs_sei_delete_message_type(CodedBitstreamContext *ctx,
  167. CodedBitstreamFragment *au,
  168. uint32_t payload_type);
  169. #endif /* AVCODEC_CBS_SEI_H */