codec_par.h 7.5 KB

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