codec_par.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Codec parameters public API
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_CODEC_PAR_H
  21. #define AVCODEC_CODEC_PAR_H
  22. #include <stdint.h>
  23. #include "libavutil/avutil.h"
  24. #include "libavutil/channel_layout.h"
  25. #include "libavutil/rational.h"
  26. #include "libavutil/pixfmt.h"
  27. #include "codec_id.h"
  28. /**
  29. * @addtogroup lavc_core
  30. */
  31. enum AVFieldOrder {
  32. AV_FIELD_UNKNOWN,
  33. AV_FIELD_PROGRESSIVE,
  34. AV_FIELD_TT, //< Top coded_first, top displayed first
  35. AV_FIELD_BB, //< Bottom coded first, bottom displayed first
  36. AV_FIELD_TB, //< Top coded first, bottom displayed first
  37. AV_FIELD_BT, //< Bottom coded first, top displayed first
  38. };
  39. /**
  40. * 此结构体描述已编码流的属性。
  41. *
  42. * sizeof(AVCodecParameters)不是公共ABI的一部分,
  43. * 这个结构必须用avcodec_parameters_alloc()分配,
  44. * 并用avcodec_parameters_free()释放。
  45. */
  46. typedef struct AVCodecParameters {
  47. /**
  48. * General type of the encoded data.
  49. */
  50. enum AVMediaType codec_type;
  51. /**
  52. * Specific type of the encoded data (the codec used).
  53. */
  54. enum AVCodecID codec_id;
  55. /**
  56. * Additional information about the codec (corresponds to the AVI FOURCC).
  57. */
  58. uint32_t codec_tag;
  59. /**
  60. * Extra binary data needed for initializing the decoder, codec-dependent.
  61. *
  62. * Must be allocated with av_malloc() and will be freed by
  63. * avcodec_parameters_free(). The allocated size of extradata must be at
  64. * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
  65. * bytes zeroed.
  66. */
  67. uint8_t *extradata;
  68. /**
  69. * Size of the extradata content in bytes.
  70. */
  71. int extradata_size;
  72. /**
  73. * - video: the pixel format, the value corresponds to enum AVPixelFormat.
  74. * - audio: the sample format, the value corresponds to enum AVSampleFormat.
  75. */
  76. int format;
  77. /**
  78. * The average bitrate of the encoded data (in bits per second).
  79. */
  80. int64_t bit_rate;
  81. /**
  82. * The number of bits per sample in the codedwords.
  83. *
  84. * This is basically the bitrate per sample. It is mandatory for a bunch of
  85. * formats to actually decode them. It's the number of bits for one sample in
  86. * the actual coded bitstream.
  87. *
  88. * This could be for example 4 for ADPCM
  89. * For PCM formats this matches bits_per_raw_sample
  90. * Can be 0
  91. */
  92. int bits_per_coded_sample;
  93. /**
  94. * This is the number of valid bits in each output sample. If the
  95. * sample format has more bits, the least significant bits are additional
  96. * padding bits, which are always 0. Use right shifts to reduce the sample
  97. * to its actual size. For example, audio formats with 24 bit samples will
  98. * have bits_per_raw_sample set to 24, and format set to AV_SAMPLE_FMT_S32.
  99. * To get the original sample use "(int32_t)sample >> 8"."
  100. *
  101. * For ADPCM this might be 12 or 16 or similar
  102. * Can be 0
  103. */
  104. int bits_per_raw_sample;
  105. /**
  106. * Codec-specific bitstream restrictions that the stream conforms to.
  107. */
  108. int profile;
  109. int level;
  110. /**
  111. * Video only. The dimensions of the video frame in pixels.
  112. */
  113. int width;
  114. int height;
  115. /**
  116. * Video only. The aspect ratio (width / height) which a single pixel
  117. * should have when displayed.
  118. *
  119. * When the aspect ratio is unknown / undefined, the numerator should be
  120. * set to 0 (the denominator may have any value).
  121. */
  122. AVRational sample_aspect_ratio;
  123. /**
  124. * Video only. The order of the fields in interlaced video.
  125. */
  126. enum AVFieldOrder field_order;
  127. /**
  128. * Video only. Additional colorspace characteristics.
  129. */
  130. enum AVColorRange color_range;
  131. enum AVColorPrimaries color_primaries;
  132. enum AVColorTransferCharacteristic color_trc;
  133. enum AVColorSpace color_space;
  134. enum AVChromaLocation chroma_location;
  135. /**
  136. * Video only. Number of delayed frames.
  137. */
  138. int video_delay;
  139. #if FF_API_OLD_CHANNEL_LAYOUT
  140. /**
  141. * Audio only. The channel layout bitmask. May be 0 if the channel layout is
  142. * unknown or unspecified, otherwise the number of bits set must be equal to
  143. * the channels field.
  144. * @deprecated use ch_layout
  145. */
  146. attribute_deprecated
  147. uint64_t channel_layout;
  148. /**
  149. * Audio only. The number of audio channels.
  150. * @deprecated use ch_layout.nb_channels
  151. */
  152. attribute_deprecated
  153. int channels;
  154. #endif
  155. /**
  156. * Audio only. The number of audio samples per second.
  157. */
  158. int sample_rate;
  159. /**
  160. * Audio only. The number of bytes per coded audio frame, required by some
  161. * formats.
  162. *
  163. * Corresponds to nBlockAlign in WAVEFORMATEX.
  164. */
  165. int block_align;
  166. /**
  167. * Audio only. Audio frame size, if known. Required by some formats to be static.
  168. */
  169. int frame_size;
  170. /**
  171. * Audio only. The amount of padding (in samples) inserted by the encoder at
  172. * the beginning of the audio. I.e. this number of leading decoded samples
  173. * must be discarded by the caller to get the original audio without leading
  174. * padding.
  175. */
  176. int initial_padding;
  177. /**
  178. * Audio only. The amount of padding (in samples) appended by the encoder to
  179. * the end of the audio. I.e. this number of decoded samples must be
  180. * discarded by the caller from the end of the stream to get the original
  181. * audio without any trailing padding.
  182. */
  183. int trailing_padding;
  184. /**
  185. * Audio only. Number of samples to skip after a discontinuity.
  186. */
  187. int seek_preroll;
  188. /**
  189. * Audio only. The channel layout and number of channels.
  190. */
  191. AVChannelLayout ch_layout;
  192. } AVCodecParameters;
  193. /**
  194. * Allocate a new AVCodecParameters and set its fields to default values
  195. * (unknown/invalid/0). The returned struct must be freed with
  196. * avcodec_parameters_free().
  197. */
  198. AVCodecParameters *avcodec_parameters_alloc(void);
  199. /**
  200. * Free an AVCodecParameters instance and everything associated with it and
  201. * write NULL to the supplied pointer.
  202. */
  203. void avcodec_parameters_free(AVCodecParameters **par);
  204. /**
  205. * Copy the contents of src to dst. Any allocated fields in dst are freed and
  206. * replaced with newly allocated duplicates of the corresponding fields in src.
  207. *
  208. * @return >= 0 on success, a negative AVERROR code on failure.
  209. */
  210. int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src);
  211. /**
  212. * This function is the same as av_get_audio_frame_duration(), except it works
  213. * with AVCodecParameters instead of an AVCodecContext.
  214. */
  215. int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
  216. /**
  217. * @}
  218. */
  219. #endif // AVCODEC_CODEC_PAR_H