codec_par.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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/rational.h"
  25. #include "libavutil/pixfmt.h"
  26. #include "codec_id.h"
  27. /**
  28. * @addtogroup lavc_core
  29. */
  30. enum AVFieldOrder {
  31. AV_FIELD_UNKNOWN,
  32. AV_FIELD_PROGRESSIVE,
  33. AV_FIELD_TT, //< Top coded_first, top displayed first
  34. AV_FIELD_BB, //< Bottom coded first, bottom displayed first
  35. AV_FIELD_TB, //< Top coded first, bottom displayed first
  36. AV_FIELD_BT, //< Bottom coded first, top displayed first
  37. };
  38. /**
  39. * This struct describes the properties of an encoded stream.
  40. *
  41. * sizeof(AVCodecParameters) is not a part of the public ABI, this struct must
  42. * be allocated with avcodec_parameters_alloc() and freed with
  43. * avcodec_parameters_free().
  44. */
  45. typedef struct AVCodecParameters {
  46. /**
  47. * General type of the encoded data.
  48. */
  49. enum AVMediaType codec_type;
  50. /**
  51. * Specific type of the encoded data (the codec used).
  52. */
  53. enum AVCodecID codec_id;
  54. /**
  55. * Additional information about the codec (corresponds to the AVI FOURCC).
  56. */
  57. uint32_t codec_tag;
  58. /**
  59. * Extra binary data needed for initializing the decoder, codec-dependent.
  60. *
  61. * Must be allocated with av_malloc() and will be freed by
  62. * avcodec_parameters_free(). The allocated size of extradata must be at
  63. * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
  64. * bytes zeroed.
  65. */
  66. uint8_t *extradata;
  67. /**
  68. * Size of the extradata content in bytes.
  69. */
  70. int extradata_size;
  71. /**
  72. * - video: the pixel format, the value corresponds to enum AVPixelFormat.
  73. * - audio: the sample format, the value corresponds to enum AVSampleFormat.
  74. */
  75. int format;
  76. /**
  77. * The average bitrate of the encoded data (in bits per second).
  78. */
  79. int64_t bit_rate;
  80. /**
  81. * The number of bits per sample in the codedwords.
  82. *
  83. * This is basically the bitrate per sample. It is mandatory for a bunch of
  84. * formats to actually decode them. It's the number of bits for one sample in
  85. * the actual coded bitstream.
  86. *
  87. * This could be for example 4 for ADPCM
  88. * For PCM formats this matches bits_per_raw_sample
  89. * Can be 0
  90. */
  91. int bits_per_coded_sample;
  92. /**
  93. * This is the number of valid bits in each output sample. If the
  94. * sample format has more bits, the least significant bits are additional
  95. * padding bits, which are always 0. Use right shifts to reduce the sample
  96. * to its actual size. For example, audio formats with 24 bit samples will
  97. * have bits_per_raw_sample set to 24, and format set to AV_SAMPLE_FMT_S32.
  98. * To get the original sample use "(int32_t)sample >> 8"."
  99. *
  100. * For ADPCM this might be 12 or 16 or similar
  101. * Can be 0
  102. */
  103. int bits_per_raw_sample;
  104. /**
  105. * Codec-specific bitstream restrictions that the stream conforms to.
  106. */
  107. int profile;
  108. int level;
  109. /**
  110. * Video only. The dimensions of the video frame in pixels.
  111. */
  112. int width;
  113. int height;
  114. /**
  115. * Video only. The aspect ratio (width / height) which a single pixel
  116. * should have when displayed.
  117. *
  118. * When the aspect ratio is unknown / undefined, the numerator should be
  119. * set to 0 (the denominator may have any value).
  120. */
  121. AVRational sample_aspect_ratio;
  122. /**
  123. * Video only. The order of the fields in interlaced video.
  124. */
  125. enum AVFieldOrder field_order;
  126. /**
  127. * Video only. Additional colorspace characteristics.
  128. */
  129. enum AVColorRange color_range;
  130. enum AVColorPrimaries color_primaries;
  131. enum AVColorTransferCharacteristic color_trc;
  132. enum AVColorSpace color_space;
  133. enum AVChromaLocation chroma_location;
  134. /**
  135. * Video only. Number of delayed frames.
  136. */
  137. int video_delay;
  138. /**
  139. * Audio only. The channel layout bitmask. May be 0 if the channel layout is
  140. * unknown or unspecified, otherwise the number of bits set must be equal to
  141. * the channels field.
  142. */
  143. uint64_t channel_layout;
  144. /**
  145. * Audio only. The number of audio channels.
  146. */
  147. int channels;
  148. /**
  149. * Audio only. The number of audio samples per second.
  150. */
  151. int sample_rate;
  152. /**
  153. * Audio only. The number of bytes per coded audio frame, required by some
  154. * formats.
  155. *
  156. * Corresponds to nBlockAlign in WAVEFORMATEX.
  157. */
  158. int block_align;
  159. /**
  160. * Audio only. Audio frame size, if known. Required by some formats to be static.
  161. */
  162. int frame_size;
  163. /**
  164. * Audio only. The amount of padding (in samples) inserted by the encoder at
  165. * the beginning of the audio. I.e. this number of leading decoded samples
  166. * must be discarded by the caller to get the original audio without leading
  167. * padding.
  168. */
  169. int initial_padding;
  170. /**
  171. * Audio only. The amount of padding (in samples) appended by the encoder to
  172. * the end of the audio. I.e. this number of decoded samples must be
  173. * discarded by the caller from the end of the stream to get the original
  174. * audio without any trailing padding.
  175. */
  176. int trailing_padding;
  177. /**
  178. * Audio only. Number of samples to skip after a discontinuity.
  179. */
  180. int seek_preroll;
  181. } AVCodecParameters;
  182. /**
  183. * Allocate a new AVCodecParameters and set its fields to default values
  184. * (unknown/invalid/0). The returned struct must be freed with
  185. * avcodec_parameters_free().
  186. */
  187. AVCodecParameters *avcodec_parameters_alloc(void);
  188. /**
  189. * Free an AVCodecParameters instance and everything associated with it and
  190. * write NULL to the supplied pointer.
  191. */
  192. void avcodec_parameters_free(AVCodecParameters **par);
  193. /**
  194. * Copy the contents of src to dst. Any allocated fields in dst are freed and
  195. * replaced with newly allocated duplicates of the corresponding fields in src.
  196. *
  197. * @return >= 0 on success, a negative AVERROR code on failure.
  198. */
  199. int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src);
  200. /**
  201. * @}
  202. */
  203. #endif // AVCODEC_CODEC_PAR_H