h264_sei.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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_H264_SEI_H
  19. #define AVCODEC_H264_SEI_H
  20. #include "get_bits.h"
  21. #include "h264_ps.h"
  22. /**
  23. * SEI message types
  24. */
  25. typedef enum {
  26. H264_SEI_TYPE_BUFFERING_PERIOD = 0, ///< buffering period (H.264, D.1.1)
  27. H264_SEI_TYPE_PIC_TIMING = 1, ///< picture timing
  28. H264_SEI_TYPE_PAN_SCAN_RECT = 2, ///< pan-scan rectangle
  29. H264_SEI_TYPE_FILLER_PAYLOAD = 3, ///< filler data
  30. H264_SEI_TYPE_USER_DATA_REGISTERED = 4, ///< registered user data as specified by Rec. ITU-T T.35
  31. H264_SEI_TYPE_USER_DATA_UNREGISTERED = 5, ///< unregistered user data
  32. H264_SEI_TYPE_RECOVERY_POINT = 6, ///< recovery point (frame # to decoder sync)
  33. H264_SEI_TYPE_FRAME_PACKING = 45, ///< frame packing arrangement
  34. H264_SEI_TYPE_DISPLAY_ORIENTATION = 47, ///< display orientation
  35. H264_SEI_TYPE_GREEN_METADATA = 56, ///< GreenMPEG information
  36. H264_SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME = 137, ///< mastering display properties
  37. H264_SEI_TYPE_ALTERNATIVE_TRANSFER = 147, ///< alternative transfer
  38. } H264_SEI_Type;
  39. /**
  40. * pic_struct in picture timing SEI message
  41. */
  42. typedef enum {
  43. H264_SEI_PIC_STRUCT_FRAME = 0, ///< 0: %frame
  44. H264_SEI_PIC_STRUCT_TOP_FIELD = 1, ///< 1: top field
  45. H264_SEI_PIC_STRUCT_BOTTOM_FIELD = 2, ///< 2: bottom field
  46. H264_SEI_PIC_STRUCT_TOP_BOTTOM = 3, ///< 3: top field, bottom field, in that order
  47. H264_SEI_PIC_STRUCT_BOTTOM_TOP = 4, ///< 4: bottom field, top field, in that order
  48. H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP = 5, ///< 5: top field, bottom field, top field repeated, in that order
  49. H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, ///< 6: bottom field, top field, bottom field repeated, in that order
  50. H264_SEI_PIC_STRUCT_FRAME_DOUBLING = 7, ///< 7: %frame doubling
  51. H264_SEI_PIC_STRUCT_FRAME_TRIPLING = 8 ///< 8: %frame tripling
  52. } H264_SEI_PicStructType;
  53. /**
  54. * frame_packing_arrangement types
  55. */
  56. typedef enum {
  57. H264_SEI_FPA_TYPE_CHECKERBOARD = 0,
  58. H264_SEI_FPA_TYPE_INTERLEAVE_COLUMN = 1,
  59. H264_SEI_FPA_TYPE_INTERLEAVE_ROW = 2,
  60. H264_SEI_FPA_TYPE_SIDE_BY_SIDE = 3,
  61. H264_SEI_FPA_TYPE_TOP_BOTTOM = 4,
  62. H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL = 5,
  63. H264_SEI_FPA_TYPE_2D = 6,
  64. } H264_SEI_FpaType;
  65. typedef struct H264SEITimeCode {
  66. /* When not continuously receiving full timecodes, we have to reference
  67. the previous timecode received */
  68. int full;
  69. int frame;
  70. int seconds;
  71. int minutes;
  72. int hours;
  73. int dropframe;
  74. } H264SEITimeCode;
  75. typedef struct H264SEIPictureTiming {
  76. // maximum size of pic_timing according to the spec should be 274 bits
  77. uint8_t payload[40];
  78. int payload_size_bits;
  79. int present;
  80. H264_SEI_PicStructType pic_struct;
  81. /**
  82. * Bit set of clock types for fields/frames in picture timing SEI message.
  83. * For each found ct_type, appropriate bit is set (e.g., bit 1 for
  84. * interlaced).
  85. */
  86. int ct_type;
  87. /**
  88. * dpb_output_delay in picture timing SEI message, see H.264 C.2.2
  89. */
  90. int dpb_output_delay;
  91. /**
  92. * cpb_removal_delay in picture timing SEI message, see H.264 C.1.2
  93. */
  94. int cpb_removal_delay;
  95. /**
  96. * Maximum three timecodes in a pic_timing SEI.
  97. */
  98. H264SEITimeCode timecode[3];
  99. /**
  100. * Number of timecode in use
  101. */
  102. int timecode_cnt;
  103. } H264SEIPictureTiming;
  104. typedef struct H264SEIAFD {
  105. int present;
  106. uint8_t active_format_description;
  107. } H264SEIAFD;
  108. typedef struct H264SEIA53Caption {
  109. AVBufferRef *buf_ref;
  110. } H264SEIA53Caption;
  111. typedef struct H264SEIUnregistered {
  112. int x264_build;
  113. AVBufferRef **buf_ref;
  114. int nb_buf_ref;
  115. } H264SEIUnregistered;
  116. typedef struct H264SEIRecoveryPoint {
  117. /**
  118. * recovery_frame_cnt
  119. *
  120. * Set to -1 if no recovery point SEI message found or to number of frames
  121. * before playback synchronizes. Frames having recovery point are key
  122. * frames.
  123. */
  124. int recovery_frame_cnt;
  125. } H264SEIRecoveryPoint;
  126. typedef struct H264SEIBufferingPeriod {
  127. int present; ///< Buffering period SEI flag
  128. int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs
  129. } H264SEIBufferingPeriod;
  130. typedef struct H264SEIFramePacking {
  131. int present;
  132. int arrangement_id;
  133. int arrangement_cancel_flag; ///< is previous arrangement canceled, -1 if never received
  134. H264_SEI_FpaType arrangement_type;
  135. int arrangement_repetition_period;
  136. int content_interpretation_type;
  137. int quincunx_sampling_flag;
  138. int current_frame_is_frame0_flag;
  139. } H264SEIFramePacking;
  140. typedef struct H264SEIDisplayOrientation {
  141. int present;
  142. int anticlockwise_rotation;
  143. int hflip, vflip;
  144. } H264SEIDisplayOrientation;
  145. typedef struct H264SEIGreenMetaData {
  146. uint8_t green_metadata_type;
  147. uint8_t period_type;
  148. uint16_t num_seconds;
  149. uint16_t num_pictures;
  150. uint8_t percent_non_zero_macroblocks;
  151. uint8_t percent_intra_coded_macroblocks;
  152. uint8_t percent_six_tap_filtering;
  153. uint8_t percent_alpha_point_deblocking_instance;
  154. uint8_t xsd_metric_type;
  155. uint16_t xsd_metric_value;
  156. } H264SEIGreenMetaData;
  157. typedef struct H264SEIAlternativeTransfer {
  158. int present;
  159. int preferred_transfer_characteristics;
  160. } H264SEIAlternativeTransfer;
  161. typedef struct H264SEIContext {
  162. H264SEIPictureTiming picture_timing;
  163. H264SEIAFD afd;
  164. H264SEIA53Caption a53_caption;
  165. H264SEIUnregistered unregistered;
  166. H264SEIRecoveryPoint recovery_point;
  167. H264SEIBufferingPeriod buffering_period;
  168. H264SEIFramePacking frame_packing;
  169. H264SEIDisplayOrientation display_orientation;
  170. H264SEIGreenMetaData green_metadata;
  171. H264SEIAlternativeTransfer alternative_transfer;
  172. } H264SEIContext;
  173. struct H264ParamSets;
  174. int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb,
  175. const struct H264ParamSets *ps, void *logctx);
  176. /**
  177. * Reset SEI values at the beginning of the frame.
  178. */
  179. void ff_h264_sei_uninit(H264SEIContext *h);
  180. /**
  181. * Get stereo_mode string from the h264 frame_packing_arrangement
  182. */
  183. const char *ff_h264_sei_stereo_mode(const H264SEIFramePacking *h);
  184. /**
  185. * Parse the contents of a picture timing message given an active SPS.
  186. */
  187. int ff_h264_sei_process_picture_timing(H264SEIPictureTiming *h, const SPS *sps,
  188. void *logctx);
  189. #endif /* AVCODEC_H264_SEI_H */