FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utils.c
Go to the documentation of this file.
1 /*
2  * utils for libavcodec
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * utils.
26  */
27 
28 #include "config.h"
29 #include "libavutil/atomic.h"
30 #include "libavutil/attributes.h"
31 #include "libavutil/avassert.h"
32 #include "libavutil/avstring.h"
33 #include "libavutil/bprint.h"
35 #include "libavutil/crc.h"
36 #include "libavutil/frame.h"
37 #include "libavutil/hwcontext.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/mem_internal.h"
41 #include "libavutil/pixdesc.h"
42 #include "libavutil/imgutils.h"
43 #include "libavutil/samplefmt.h"
44 #include "libavutil/dict.h"
45 #include "libavutil/thread.h"
46 #include "avcodec.h"
47 #include "decode.h"
48 #include "hwaccel.h"
49 #include "libavutil/opt.h"
50 #include "me_cmp.h"
51 #include "mpegvideo.h"
52 #include "thread.h"
53 #include "frame_thread_encoder.h"
54 #include "internal.h"
55 #include "raw.h"
56 #include "bytestream.h"
57 #include "version.h"
58 #include <stdlib.h>
59 #include <stdarg.h>
60 #include <stdatomic.h>
61 #include <limits.h>
62 #include <float.h>
63 #if CONFIG_ICONV
64 # include <iconv.h>
65 #endif
66 
67 #include "libavutil/ffversion.h"
68 const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
69 
70 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
71 static int default_lockmgr_cb(void **arg, enum AVLockOp op)
72 {
73  void * volatile * mutex = arg;
74  int err;
75 
76  switch (op) {
77  case AV_LOCK_CREATE:
78  return 0;
79  case AV_LOCK_OBTAIN:
80  if (!*mutex) {
82  if (!tmp)
83  return AVERROR(ENOMEM);
84  if ((err = pthread_mutex_init(tmp, NULL))) {
85  av_free(tmp);
86  return AVERROR(err);
87  }
88  if (avpriv_atomic_ptr_cas(mutex, NULL, tmp)) {
90  av_free(tmp);
91  }
92  }
93 
94  if ((err = pthread_mutex_lock(*mutex)))
95  return AVERROR(err);
96 
97  return 0;
98  case AV_LOCK_RELEASE:
99  if ((err = pthread_mutex_unlock(*mutex)))
100  return AVERROR(err);
101 
102  return 0;
103  case AV_LOCK_DESTROY:
104  if (*mutex)
105  pthread_mutex_destroy(*mutex);
106  av_free(*mutex);
107  avpriv_atomic_ptr_cas(mutex, *mutex, NULL);
108  return 0;
109  }
110  return 1;
111 }
112 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = default_lockmgr_cb;
113 #else
114 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = NULL;
115 #endif
116 
117 
118 volatile int ff_avcodec_locked;
120 static void *codec_mutex;
121 static void *avformat_mutex;
122 
123 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
124 {
125  uint8_t **p = ptr;
126  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
127  av_freep(p);
128  *size = 0;
129  return;
130  }
131  if (!ff_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE, 1))
132  memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
133 }
134 
135 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
136 {
137  uint8_t **p = ptr;
138  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
139  av_freep(p);
140  *size = 0;
141  return;
142  }
143  if (!ff_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE, 1))
144  memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
145 }
146 
147 /* encoder management */
150 
152 {
153  if (c)
154  return c->next;
155  else
156  return first_avcodec;
157 }
158 
159 static av_cold void avcodec_init(void)
160 {
161  static int initialized = 0;
162 
163  if (initialized != 0)
164  return;
165  initialized = 1;
166 
167  if (CONFIG_ME_CMP)
169 }
170 
171 int av_codec_is_encoder(const AVCodec *codec)
172 {
173  return codec && (codec->encode_sub || codec->encode2 ||codec->send_frame);
174 }
175 
176 int av_codec_is_decoder(const AVCodec *codec)
177 {
178  return codec && (codec->decode || codec->receive_frame);
179 }
180 
182 {
183  AVCodec **p;
184  avcodec_init();
185  p = last_avcodec;
186  codec->next = NULL;
187 
188  while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
189  p = &(*p)->next;
190  last_avcodec = &codec->next;
191 
192  if (codec->init_static_data)
193  codec->init_static_data(codec);
194 }
195 
197 {
198  int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
199 
200  if (ret < 0)
201  width = height = 0;
202 
203  s->coded_width = width;
204  s->coded_height = height;
205  s->width = AV_CEIL_RSHIFT(width, s->lowres);
206  s->height = AV_CEIL_RSHIFT(height, s->lowres);
207 
208  return ret;
209 }
210 
212 {
213  int ret = av_image_check_sar(avctx->width, avctx->height, sar);
214 
215  if (ret < 0) {
216  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
217  sar.num, sar.den);
218  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
219  return ret;
220  } else {
221  avctx->sample_aspect_ratio = sar;
222  }
223  return 0;
224 }
225 
227  enum AVMatrixEncoding matrix_encoding)
228 {
229  AVFrameSideData *side_data;
230  enum AVMatrixEncoding *data;
231 
233  if (!side_data)
235  sizeof(enum AVMatrixEncoding));
236 
237  if (!side_data)
238  return AVERROR(ENOMEM);
239 
240  data = (enum AVMatrixEncoding*)side_data->data;
241  *data = matrix_encoding;
242 
243  return 0;
244 }
245 
247  int linesize_align[AV_NUM_DATA_POINTERS])
248 {
249  int i;
250  int w_align = 1;
251  int h_align = 1;
253 
254  if (desc) {
255  w_align = 1 << desc->log2_chroma_w;
256  h_align = 1 << desc->log2_chroma_h;
257  }
258 
259  switch (s->pix_fmt) {
260  case AV_PIX_FMT_YUV420P:
261  case AV_PIX_FMT_YUYV422:
262  case AV_PIX_FMT_YVYU422:
263  case AV_PIX_FMT_UYVY422:
264  case AV_PIX_FMT_YUV422P:
265  case AV_PIX_FMT_YUV440P:
266  case AV_PIX_FMT_YUV444P:
267  case AV_PIX_FMT_GBRP:
268  case AV_PIX_FMT_GBRAP:
269  case AV_PIX_FMT_GRAY8:
270  case AV_PIX_FMT_GRAY16BE:
271  case AV_PIX_FMT_GRAY16LE:
272  case AV_PIX_FMT_YUVJ420P:
273  case AV_PIX_FMT_YUVJ422P:
274  case AV_PIX_FMT_YUVJ440P:
275  case AV_PIX_FMT_YUVJ444P:
276  case AV_PIX_FMT_YUVA420P:
277  case AV_PIX_FMT_YUVA422P:
278  case AV_PIX_FMT_YUVA444P:
331  case AV_PIX_FMT_GBRP9LE:
332  case AV_PIX_FMT_GBRP9BE:
333  case AV_PIX_FMT_GBRP10LE:
334  case AV_PIX_FMT_GBRP10BE:
335  case AV_PIX_FMT_GBRP12LE:
336  case AV_PIX_FMT_GBRP12BE:
337  case AV_PIX_FMT_GBRP14LE:
338  case AV_PIX_FMT_GBRP14BE:
339  case AV_PIX_FMT_GBRP16LE:
340  case AV_PIX_FMT_GBRP16BE:
345  w_align = 16; //FIXME assume 16 pixel per macroblock
346  h_align = 16 * 2; // interlaced needs 2 macroblocks height
347  break;
348  case AV_PIX_FMT_YUV411P:
349  case AV_PIX_FMT_YUVJ411P:
351  w_align = 32;
352  h_align = 16 * 2;
353  break;
354  case AV_PIX_FMT_YUV410P:
355  if (s->codec_id == AV_CODEC_ID_SVQ1) {
356  w_align = 64;
357  h_align = 64;
358  }
359  break;
360  case AV_PIX_FMT_RGB555:
361  if (s->codec_id == AV_CODEC_ID_RPZA) {
362  w_align = 4;
363  h_align = 4;
364  }
366  w_align = 8;
367  h_align = 8;
368  }
369  break;
370  case AV_PIX_FMT_PAL8:
371  case AV_PIX_FMT_BGR8:
372  case AV_PIX_FMT_RGB8:
373  if (s->codec_id == AV_CODEC_ID_SMC ||
375  w_align = 4;
376  h_align = 4;
377  }
378  if (s->codec_id == AV_CODEC_ID_JV ||
380  w_align = 8;
381  h_align = 8;
382  }
383  break;
384  case AV_PIX_FMT_BGR24:
385  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
386  (s->codec_id == AV_CODEC_ID_ZLIB)) {
387  w_align = 4;
388  h_align = 4;
389  }
390  break;
391  case AV_PIX_FMT_RGB24:
392  if (s->codec_id == AV_CODEC_ID_CINEPAK) {
393  w_align = 4;
394  h_align = 4;
395  }
396  break;
397  default:
398  break;
399  }
400 
401  if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
402  w_align = FFMAX(w_align, 8);
403  }
404 
405  *width = FFALIGN(*width, w_align);
406  *height = FFALIGN(*height, h_align);
407  if (s->codec_id == AV_CODEC_ID_H264 || s->lowres) {
408  // some of the optimized chroma MC reads one line too much
409  // which is also done in mpeg decoders with lowres > 0
410  *height += 2;
411 
412  // H.264 uses edge emulation for out of frame motion vectors, for this
413  // it requires a temporary area large enough to hold a 21x21 block,
414  // increasing witdth ensure that the temporary area is large enough,
415  // the next rounded up width is 32
416  *width = FFMAX(*width, 32);
417  }
418 
419  for (i = 0; i < 4; i++)
420  linesize_align[i] = STRIDE_ALIGN;
421 }
422 
424 {
426  int chroma_shift = desc->log2_chroma_w;
427  int linesize_align[AV_NUM_DATA_POINTERS];
428  int align;
429 
430  avcodec_align_dimensions2(s, width, height, linesize_align);
431  align = FFMAX(linesize_align[0], linesize_align[3]);
432  linesize_align[1] <<= chroma_shift;
433  linesize_align[2] <<= chroma_shift;
434  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
435  *width = FFALIGN(*width, align);
436 }
437 
438 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
439 {
440  if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB)
441  return AVERROR(EINVAL);
442  pos--;
443 
444  *xpos = (pos&1) * 128;
445  *ypos = ((pos>>1)^(pos<4)) * 128;
446 
447  return 0;
448 }
449 
451 {
452  int pos, xout, yout;
453 
454  for (pos = AVCHROMA_LOC_UNSPECIFIED + 1; pos < AVCHROMA_LOC_NB; pos++) {
455  if (avcodec_enum_to_chroma_pos(&xout, &yout, pos) == 0 && xout == xpos && yout == ypos)
456  return pos;
457  }
459 }
460 
462  enum AVSampleFormat sample_fmt, const uint8_t *buf,
463  int buf_size, int align)
464 {
465  int ch, planar, needed_size, ret = 0;
466 
467  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
468  frame->nb_samples, sample_fmt,
469  align);
470  if (buf_size < needed_size)
471  return AVERROR(EINVAL);
472 
473  planar = av_sample_fmt_is_planar(sample_fmt);
474  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
475  if (!(frame->extended_data = av_mallocz_array(nb_channels,
476  sizeof(*frame->extended_data))))
477  return AVERROR(ENOMEM);
478  } else {
479  frame->extended_data = frame->data;
480  }
481 
482  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
483  (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
484  sample_fmt, align)) < 0) {
485  if (frame->extended_data != frame->data)
486  av_freep(&frame->extended_data);
487  return ret;
488  }
489  if (frame->extended_data != frame->data) {
490  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
491  frame->data[ch] = frame->extended_data[ch];
492  }
493 
494  return ret;
495 }
496 
497 void ff_color_frame(AVFrame *frame, const int c[4])
498 {
500  int p, y, x;
501 
503 
504  for (p = 0; p<desc->nb_components; p++) {
505  uint8_t *dst = frame->data[p];
506  int is_chroma = p == 1 || p == 2;
507  int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
508  int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
509  for (y = 0; y < height; y++) {
510  if (desc->comp[0].depth >= 9) {
511  for (x = 0; x<bytes; x++)
512  ((uint16_t*)dst)[x] = c[p];
513  }else
514  memset(dst, c[p], bytes);
515  dst += frame->linesize[p];
516  }
517  }
518 }
519 
520 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
521 {
522  int i;
523 
524  for (i = 0; i < count; i++) {
525  int r = func(c, (char *)arg + i * size);
526  if (ret)
527  ret[i] = r;
528  }
529  emms_c();
530  return 0;
531 }
532 
533 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
534 {
535  int i;
536 
537  for (i = 0; i < count; i++) {
538  int r = func(c, arg, i, 0);
539  if (ret)
540  ret[i] = r;
541  }
542  emms_c();
543  return 0;
544 }
545 
547  unsigned int fourcc)
548 {
549  while (tags->pix_fmt >= 0) {
550  if (tags->fourcc == fourcc)
551  return tags->pix_fmt;
552  tags++;
553  }
554  return AV_PIX_FMT_NONE;
555 }
556 
557 #if FF_API_CODEC_GET_SET
558 MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
559 MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, codec_descriptor)
560 MAKE_ACCESSORS(AVCodecContext, codec, int, lowres)
561 MAKE_ACCESSORS(AVCodecContext, codec, int, seek_preroll)
562 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
563 
564 unsigned av_codec_get_codec_properties(const AVCodecContext *codec)
565 {
566  return codec->properties;
567 }
568 
570 {
571  return codec->max_lowres;
572 }
573 #endif
574 
577 }
578 
580 {
581  int64_t bit_rate;
582  int bits_per_sample;
583 
584  switch (ctx->codec_type) {
585  case AVMEDIA_TYPE_VIDEO:
586  case AVMEDIA_TYPE_DATA:
589  bit_rate = ctx->bit_rate;
590  break;
591  case AVMEDIA_TYPE_AUDIO:
592  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
593  bit_rate = bits_per_sample ? ctx->sample_rate * (int64_t)ctx->channels * bits_per_sample : ctx->bit_rate;
594  break;
595  default:
596  bit_rate = 0;
597  break;
598  }
599  return bit_rate;
600 }
601 
602 int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
603 {
604  int ret = 0;
605 
606  ff_unlock_avcodec(codec);
607 
608  ret = avcodec_open2(avctx, codec, options);
609 
610  ff_lock_avcodec(avctx, codec);
611  return ret;
612 }
613 
614 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
615 {
616  int ret = 0;
617  AVDictionary *tmp = NULL;
618  const AVPixFmtDescriptor *pixdesc;
619 
620  if (avcodec_is_open(avctx))
621  return 0;
622 
623  if ((!codec && !avctx->codec)) {
624  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
625  return AVERROR(EINVAL);
626  }
627  if ((codec && avctx->codec && codec != avctx->codec)) {
628  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
629  "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
630  return AVERROR(EINVAL);
631  }
632  if (!codec)
633  codec = avctx->codec;
634 
635  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
636  return AVERROR(EINVAL);
637 
638  if (options)
639  av_dict_copy(&tmp, *options, 0);
640 
641  ret = ff_lock_avcodec(avctx, codec);
642  if (ret < 0)
643  return ret;
644 
645  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
646  if (!avctx->internal) {
647  ret = AVERROR(ENOMEM);
648  goto end;
649  }
650 
651  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
652  if (!avctx->internal->pool) {
653  ret = AVERROR(ENOMEM);
654  goto free_and_end;
655  }
656 
657  avctx->internal->to_free = av_frame_alloc();
658  if (!avctx->internal->to_free) {
659  ret = AVERROR(ENOMEM);
660  goto free_and_end;
661  }
662 
664  if (!avctx->internal->compat_decode_frame) {
665  ret = AVERROR(ENOMEM);
666  goto free_and_end;
667  }
668 
670  if (!avctx->internal->buffer_frame) {
671  ret = AVERROR(ENOMEM);
672  goto free_and_end;
673  }
674 
675  avctx->internal->buffer_pkt = av_packet_alloc();
676  if (!avctx->internal->buffer_pkt) {
677  ret = AVERROR(ENOMEM);
678  goto free_and_end;
679  }
680 
681  avctx->internal->ds.in_pkt = av_packet_alloc();
682  if (!avctx->internal->ds.in_pkt) {
683  ret = AVERROR(ENOMEM);
684  goto free_and_end;
685  }
686 
688  if (!avctx->internal->last_pkt_props) {
689  ret = AVERROR(ENOMEM);
690  goto free_and_end;
691  }
692 
693  avctx->internal->skip_samples_multiplier = 1;
694 
695  if (codec->priv_data_size > 0) {
696  if (!avctx->priv_data) {
697  avctx->priv_data = av_mallocz(codec->priv_data_size);
698  if (!avctx->priv_data) {
699  ret = AVERROR(ENOMEM);
700  goto end;
701  }
702  if (codec->priv_class) {
703  *(const AVClass **)avctx->priv_data = codec->priv_class;
705  }
706  }
707  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
708  goto free_and_end;
709  } else {
710  avctx->priv_data = NULL;
711  }
712  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
713  goto free_and_end;
714 
715  if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
716  av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
717  ret = AVERROR(EINVAL);
718  goto free_and_end;
719  }
720 
721  // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
722  if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
723  (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
724  if (avctx->coded_width && avctx->coded_height)
725  ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
726  else if (avctx->width && avctx->height)
727  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
728  if (ret < 0)
729  goto free_and_end;
730  }
731 
732  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
733  && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
734  || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
735  av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
736  ff_set_dimensions(avctx, 0, 0);
737  }
738 
739  if (avctx->width > 0 && avctx->height > 0) {
740  if (av_image_check_sar(avctx->width, avctx->height,
741  avctx->sample_aspect_ratio) < 0) {
742  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
743  avctx->sample_aspect_ratio.num,
744  avctx->sample_aspect_ratio.den);
745  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
746  }
747  }
748 
749  /* if the decoder init function was already called previously,
750  * free the already allocated subtitle_header before overwriting it */
751  if (av_codec_is_decoder(codec))
752  av_freep(&avctx->subtitle_header);
753 
754  if (avctx->channels > FF_SANE_NB_CHANNELS) {
755  ret = AVERROR(EINVAL);
756  goto free_and_end;
757  }
758 
759  avctx->codec = codec;
760  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
761  avctx->codec_id == AV_CODEC_ID_NONE) {
762  avctx->codec_type = codec->type;
763  avctx->codec_id = codec->id;
764  }
765  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
766  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
767  av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
768  ret = AVERROR(EINVAL);
769  goto free_and_end;
770  }
771  avctx->frame_number = 0;
773 
774  if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
776  const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
777  AVCodec *codec2;
778  av_log(avctx, AV_LOG_ERROR,
779  "The %s '%s' is experimental but experimental codecs are not enabled, "
780  "add '-strict %d' if you want to use it.\n",
781  codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
782  codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
783  if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
784  av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
785  codec_string, codec2->name);
786  ret = AVERROR_EXPERIMENTAL;
787  goto free_and_end;
788  }
789 
790  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
791  (!avctx->time_base.num || !avctx->time_base.den)) {
792  avctx->time_base.num = 1;
793  avctx->time_base.den = avctx->sample_rate;
794  }
795 
796  if (!HAVE_THREADS)
797  av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
798 
799  if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) {
800  ff_unlock_avcodec(codec); //we will instantiate a few encoders thus kick the counter to prevent false detection of a problem
801  ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
802  ff_lock_avcodec(avctx, codec);
803  if (ret < 0)
804  goto free_and_end;
805  }
806 
807  if (HAVE_THREADS
809  ret = ff_thread_init(avctx);
810  if (ret < 0) {
811  goto free_and_end;
812  }
813  }
814  if (!HAVE_THREADS && !(codec->capabilities & AV_CODEC_CAP_AUTO_THREADS))
815  avctx->thread_count = 1;
816 
817  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
818  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
819  avctx->codec->max_lowres);
820  avctx->lowres = avctx->codec->max_lowres;
821  }
822 
823  if (av_codec_is_encoder(avctx->codec)) {
824  int i;
825 #if FF_API_CODED_FRAME
827  avctx->coded_frame = av_frame_alloc();
828  if (!avctx->coded_frame) {
829  ret = AVERROR(ENOMEM);
830  goto free_and_end;
831  }
833 #endif
834 
835  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
836  av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
837  ret = AVERROR(EINVAL);
838  goto free_and_end;
839  }
840 
841  if (avctx->codec->sample_fmts) {
842  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
843  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
844  break;
845  if (avctx->channels == 1 &&
848  avctx->sample_fmt = avctx->codec->sample_fmts[i];
849  break;
850  }
851  }
852  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
853  char buf[128];
854  snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
855  av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
856  (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
857  ret = AVERROR(EINVAL);
858  goto free_and_end;
859  }
860  }
861  if (avctx->codec->pix_fmts) {
862  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
863  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
864  break;
865  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
866  && !((avctx->codec_id == AV_CODEC_ID_MJPEG || avctx->codec_id == AV_CODEC_ID_LJPEG)
868  char buf[128];
869  snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
870  av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
871  (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
872  ret = AVERROR(EINVAL);
873  goto free_and_end;
874  }
875  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
876  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
877  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
878  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
879  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
880  avctx->color_range = AVCOL_RANGE_JPEG;
881  }
882  if (avctx->codec->supported_samplerates) {
883  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
884  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
885  break;
886  if (avctx->codec->supported_samplerates[i] == 0) {
887  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
888  avctx->sample_rate);
889  ret = AVERROR(EINVAL);
890  goto free_and_end;
891  }
892  }
893  if (avctx->sample_rate < 0) {
894  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
895  avctx->sample_rate);
896  ret = AVERROR(EINVAL);
897  goto free_and_end;
898  }
899  if (avctx->codec->channel_layouts) {
900  if (!avctx->channel_layout) {
901  av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
902  } else {
903  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
904  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
905  break;
906  if (avctx->codec->channel_layouts[i] == 0) {
907  char buf[512];
908  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
909  av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
910  ret = AVERROR(EINVAL);
911  goto free_and_end;
912  }
913  }
914  }
915  if (avctx->channel_layout && avctx->channels) {
917  if (channels != avctx->channels) {
918  char buf[512];
919  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
920  av_log(avctx, AV_LOG_ERROR,
921  "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
922  buf, channels, avctx->channels);
923  ret = AVERROR(EINVAL);
924  goto free_and_end;
925  }
926  } else if (avctx->channel_layout) {
928  }
929  if (avctx->channels < 0) {
930  av_log(avctx, AV_LOG_ERROR, "Specified number of channels %d is not supported\n",
931  avctx->channels);
932  ret = AVERROR(EINVAL);
933  goto free_and_end;
934  }
935  if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
936  pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
937  if ( avctx->bits_per_raw_sample < 0
938  || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) {
939  av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n",
940  avctx->bits_per_raw_sample, pixdesc->comp[0].depth);
941  avctx->bits_per_raw_sample = pixdesc->comp[0].depth;
942  }
943  if (avctx->width <= 0 || avctx->height <= 0) {
944  av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
945  ret = AVERROR(EINVAL);
946  goto free_and_end;
947  }
948  }
949  if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
950  && avctx->bit_rate>0 && avctx->bit_rate<1000) {
951  av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate);
952  }
953 
954  if (!avctx->rc_initial_buffer_occupancy)
955  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4;
956 
957  if (avctx->ticks_per_frame && avctx->time_base.num &&
958  avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
959  av_log(avctx, AV_LOG_ERROR,
960  "ticks_per_frame %d too large for the timebase %d/%d.",
961  avctx->ticks_per_frame,
962  avctx->time_base.num,
963  avctx->time_base.den);
964  goto free_and_end;
965  }
966 
967  if (avctx->hw_frames_ctx) {
968  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
969  if (frames_ctx->format != avctx->pix_fmt) {
970  av_log(avctx, AV_LOG_ERROR,
971  "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
972  ret = AVERROR(EINVAL);
973  goto free_and_end;
974  }
975  if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
976  avctx->sw_pix_fmt != frames_ctx->sw_format) {
977  av_log(avctx, AV_LOG_ERROR,
978  "Mismatching AVCodecContext.sw_pix_fmt (%s) "
979  "and AVHWFramesContext.sw_format (%s)\n",
981  av_get_pix_fmt_name(frames_ctx->sw_format));
982  ret = AVERROR(EINVAL);
983  goto free_and_end;
984  }
985  avctx->sw_pix_fmt = frames_ctx->sw_format;
986  }
987  }
988 
991  avctx->pts_correction_last_pts =
992  avctx->pts_correction_last_dts = INT64_MIN;
993 
994  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
996  av_log(avctx, AV_LOG_WARNING,
997  "gray decoding requested but not enabled at configuration time\n");
998 
999  if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME)
1000  || avctx->internal->frame_thread_encoder)) {
1001  ret = avctx->codec->init(avctx);
1002  if (ret < 0) {
1003  goto free_and_end;
1004  }
1005  }
1006 
1007  ret=0;
1008 
1009  if (av_codec_is_decoder(avctx->codec)) {
1010  if (!avctx->bit_rate)
1011  avctx->bit_rate = get_bit_rate(avctx);
1012  /* validate channel layout from the decoder */
1013  if (avctx->channel_layout) {
1015  if (!avctx->channels)
1016  avctx->channels = channels;
1017  else if (channels != avctx->channels) {
1018  char buf[512];
1019  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1020  av_log(avctx, AV_LOG_WARNING,
1021  "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1022  "ignoring specified channel layout\n",
1023  buf, channels, avctx->channels);
1024  avctx->channel_layout = 0;
1025  }
1026  }
1027  if (avctx->channels && avctx->channels < 0 ||
1028  avctx->channels > FF_SANE_NB_CHANNELS) {
1029  ret = AVERROR(EINVAL);
1030  goto free_and_end;
1031  }
1032  if (avctx->sub_charenc) {
1033  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1034  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1035  "supported with subtitles codecs\n");
1036  ret = AVERROR(EINVAL);
1037  goto free_and_end;
1038  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1039  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1040  "subtitles character encoding will be ignored\n",
1041  avctx->codec_descriptor->name);
1043  } else {
1044  /* input character encoding is set for a text based subtitle
1045  * codec at this point */
1048 
1050 #if CONFIG_ICONV
1051  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1052  if (cd == (iconv_t)-1) {
1053  ret = AVERROR(errno);
1054  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1055  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1056  goto free_and_end;
1057  }
1058  iconv_close(cd);
1059 #else
1060  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1061  "conversion needs a libavcodec built with iconv support "
1062  "for this codec\n");
1063  ret = AVERROR(ENOSYS);
1064  goto free_and_end;
1065 #endif
1066  }
1067  }
1068  }
1069 
1070 #if FF_API_AVCTX_TIMEBASE
1071  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
1072  avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
1073 #endif
1074  }
1075  if (codec->priv_data_size > 0 && avctx->priv_data && codec->priv_class) {
1076  av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
1077  }
1078 
1079 end:
1080  ff_unlock_avcodec(codec);
1081  if (options) {
1083  *options = tmp;
1084  }
1085 
1086  return ret;
1087 free_and_end:
1088  if (avctx->codec &&
1089  (avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))
1090  avctx->codec->close(avctx);
1091 
1092  if (codec->priv_class && codec->priv_data_size)
1093  av_opt_free(avctx->priv_data);
1094  av_opt_free(avctx);
1095 
1096 #if FF_API_CODED_FRAME
1098  av_frame_free(&avctx->coded_frame);
1100 #endif
1101 
1102  av_dict_free(&tmp);
1103  av_freep(&avctx->priv_data);
1104  if (avctx->internal) {
1105  av_frame_free(&avctx->internal->to_free);
1106  av_frame_free(&avctx->internal->compat_decode_frame);
1107  av_frame_free(&avctx->internal->buffer_frame);
1108  av_packet_free(&avctx->internal->buffer_pkt);
1109  av_packet_free(&avctx->internal->last_pkt_props);
1110 
1111  av_packet_free(&avctx->internal->ds.in_pkt);
1112 
1113  av_freep(&avctx->internal->pool);
1114  }
1115  av_freep(&avctx->internal);
1116  avctx->codec = NULL;
1117  goto end;
1118 }
1119 
1121 {
1122  int i;
1123 
1124  for (i = 0; i < sub->num_rects; i++) {
1125  av_freep(&sub->rects[i]->data[0]);
1126  av_freep(&sub->rects[i]->data[1]);
1127  av_freep(&sub->rects[i]->data[2]);
1128  av_freep(&sub->rects[i]->data[3]);
1129  av_freep(&sub->rects[i]->text);
1130  av_freep(&sub->rects[i]->ass);
1131  av_freep(&sub->rects[i]);
1132  }
1133 
1134  av_freep(&sub->rects);
1135 
1136  memset(sub, 0, sizeof(AVSubtitle));
1137 }
1138 
1140 {
1141  int i;
1142 
1143  if (!avctx)
1144  return 0;
1145 
1146  if (avcodec_is_open(avctx)) {
1147  FramePool *pool = avctx->internal->pool;
1148  if (CONFIG_FRAME_THREAD_ENCODER &&
1149  avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
1151  }
1152  if (HAVE_THREADS && avctx->internal->thread_ctx)
1153  ff_thread_free(avctx);
1154  if (avctx->codec && avctx->codec->close)
1155  avctx->codec->close(avctx);
1156  avctx->internal->byte_buffer_size = 0;
1157  av_freep(&avctx->internal->byte_buffer);
1158  av_frame_free(&avctx->internal->to_free);
1163 
1164  av_packet_free(&avctx->internal->ds.in_pkt);
1165 
1166  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
1167  av_buffer_pool_uninit(&pool->pools[i]);
1168  av_freep(&avctx->internal->pool);
1169 
1170  if (avctx->hwaccel && avctx->hwaccel->uninit)
1171  avctx->hwaccel->uninit(avctx);
1173 
1174  ff_decode_bsfs_uninit(avctx);
1175 
1176  av_freep(&avctx->internal);
1177  }
1178 
1179  for (i = 0; i < avctx->nb_coded_side_data; i++)
1180  av_freep(&avctx->coded_side_data[i].data);
1181  av_freep(&avctx->coded_side_data);
1182  avctx->nb_coded_side_data = 0;
1183 
1184  av_buffer_unref(&avctx->hw_frames_ctx);
1185  av_buffer_unref(&avctx->hw_device_ctx);
1186 
1187  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1188  av_opt_free(avctx->priv_data);
1189  av_opt_free(avctx);
1190  av_freep(&avctx->priv_data);
1191  if (av_codec_is_encoder(avctx->codec)) {
1192  av_freep(&avctx->extradata);
1193 #if FF_API_CODED_FRAME
1195  av_frame_free(&avctx->coded_frame);
1197 #endif
1198  }
1199  avctx->codec = NULL;
1200  avctx->active_thread_type = 0;
1201 
1202  return 0;
1203 }
1204 
1206 {
1207  switch(id){
1208  //This is for future deprecatec codec ids, its empty since
1209  //last major bump but will fill up again over time, please don't remove it
1210  default : return id;
1211  }
1212 }
1213 
1214 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1215 {
1216  AVCodec *p, *experimental = NULL;
1217  p = first_avcodec;
1218  id= remap_deprecated_codec_id(id);
1219  while (p) {
1220  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1221  p->id == id) {
1222  if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
1223  experimental = p;
1224  } else
1225  return p;
1226  }
1227  p = p->next;
1228  }
1229  return experimental;
1230 }
1231 
1233 {
1234  return find_encdec(id, 1);
1235 }
1236 
1238 {
1239  AVCodec *p;
1240  if (!name)
1241  return NULL;
1242  p = first_avcodec;
1243  while (p) {
1244  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
1245  return p;
1246  p = p->next;
1247  }
1248  return NULL;
1249 }
1250 
1252 {
1253  return find_encdec(id, 0);
1254 }
1255 
1257 {
1258  AVCodec *p;
1259  if (!name)
1260  return NULL;
1261  p = first_avcodec;
1262  while (p) {
1263  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
1264  return p;
1265  p = p->next;
1266  }
1267  return NULL;
1268 }
1269 
1270 const char *avcodec_get_name(enum AVCodecID id)
1271 {
1272  const AVCodecDescriptor *cd;
1273  AVCodec *codec;
1274 
1275  if (id == AV_CODEC_ID_NONE)
1276  return "none";
1277  cd = avcodec_descriptor_get(id);
1278  if (cd)
1279  return cd->name;
1280  av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
1281  codec = avcodec_find_decoder(id);
1282  if (codec)
1283  return codec->name;
1284  codec = avcodec_find_encoder(id);
1285  if (codec)
1286  return codec->name;
1287  return "unknown_codec";
1288 }
1289 
1290 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1291 {
1292  int i, len, ret = 0;
1293 
1294 #define TAG_PRINT(x) \
1295  (((x) >= '0' && (x) <= '9') || \
1296  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
1297  ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
1298 
1299  for (i = 0; i < 4; i++) {
1300  len = snprintf(buf, buf_size,
1301  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
1302  buf += len;
1303  buf_size = buf_size > len ? buf_size - len : 0;
1304  ret += len;
1305  codec_tag >>= 8;
1306  }
1307  return ret;
1308 }
1309 
1310 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1311 {
1312  const char *codec_type;
1313  const char *codec_name;
1314  const char *profile = NULL;
1315  int64_t bitrate;
1316  int new_line = 0;
1317  AVRational display_aspect_ratio;
1318  const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
1319 
1320  if (!buf || buf_size <= 0)
1321  return;
1322  codec_type = av_get_media_type_string(enc->codec_type);
1323  codec_name = avcodec_get_name(enc->codec_id);
1324  profile = avcodec_profile_name(enc->codec_id, enc->profile);
1325 
1326  snprintf(buf, buf_size, "%s: %s", codec_type ? codec_type : "unknown",
1327  codec_name);
1328  buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
1329 
1330  if (enc->codec && strcmp(enc->codec->name, codec_name))
1331  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", enc->codec->name);
1332 
1333  if (profile)
1334  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
1335  if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
1337  && enc->refs)
1338  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1339  ", %d reference frame%s",
1340  enc->refs, enc->refs > 1 ? "s" : "");
1341 
1342  if (enc->codec_tag)
1343  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s / 0x%04X)",
1344  av_fourcc2str(enc->codec_tag), enc->codec_tag);
1345 
1346  switch (enc->codec_type) {
1347  case AVMEDIA_TYPE_VIDEO:
1348  {
1349  char detail[256] = "(";
1350 
1351  av_strlcat(buf, separator, buf_size);
1352 
1353  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1354  "%s", enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
1356  if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE &&
1358  av_strlcatf(detail, sizeof(detail), "%d bpc, ", enc->bits_per_raw_sample);
1360  av_strlcatf(detail, sizeof(detail), "%s, ",
1362 
1363  if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
1365  enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
1366  if (enc->colorspace != (int)enc->color_primaries ||
1367  enc->colorspace != (int)enc->color_trc) {
1368  new_line = 1;
1369  av_strlcatf(detail, sizeof(detail), "%s/%s/%s, ",
1373  } else
1374  av_strlcatf(detail, sizeof(detail), "%s, ",
1376  }
1377 
1378  if (enc->field_order != AV_FIELD_UNKNOWN) {
1379  const char *field_order = "progressive";
1380  if (enc->field_order == AV_FIELD_TT)
1381  field_order = "top first";
1382  else if (enc->field_order == AV_FIELD_BB)
1383  field_order = "bottom first";
1384  else if (enc->field_order == AV_FIELD_TB)
1385  field_order = "top coded first (swapped)";
1386  else if (enc->field_order == AV_FIELD_BT)
1387  field_order = "bottom coded first (swapped)";
1388 
1389  av_strlcatf(detail, sizeof(detail), "%s, ", field_order);
1390  }
1391 
1392  if (av_log_get_level() >= AV_LOG_VERBOSE &&
1394  av_strlcatf(detail, sizeof(detail), "%s, ",
1396 
1397  if (strlen(detail) > 1) {
1398  detail[strlen(detail) - 2] = 0;
1399  av_strlcatf(buf, buf_size, "%s)", detail);
1400  }
1401  }
1402 
1403  if (enc->width) {
1404  av_strlcat(buf, new_line ? separator : ", ", buf_size);
1405 
1406  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1407  "%dx%d",
1408  enc->width, enc->height);
1409 
1410  if (av_log_get_level() >= AV_LOG_VERBOSE &&
1411  (enc->width != enc->coded_width ||
1412  enc->height != enc->coded_height))
1413  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1414  " (%dx%d)", enc->coded_width, enc->coded_height);
1415 
1416  if (enc->sample_aspect_ratio.num) {
1417  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1418  enc->width * (int64_t)enc->sample_aspect_ratio.num,
1419  enc->height * (int64_t)enc->sample_aspect_ratio.den,
1420  1024 * 1024);
1421  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1422  " [SAR %d:%d DAR %d:%d]",
1424  display_aspect_ratio.num, display_aspect_ratio.den);
1425  }
1426  if (av_log_get_level() >= AV_LOG_DEBUG) {
1427  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1428  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1429  ", %d/%d",
1430  enc->time_base.num / g, enc->time_base.den / g);
1431  }
1432  }
1433  if (encode) {
1434  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1435  ", q=%d-%d", enc->qmin, enc->qmax);
1436  } else {
1438  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1439  ", Closed Captions");
1441  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1442  ", lossless");
1443  }
1444  break;
1445  case AVMEDIA_TYPE_AUDIO:
1446  av_strlcat(buf, separator, buf_size);
1447 
1448  if (enc->sample_rate) {
1449  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1450  "%d Hz, ", enc->sample_rate);
1451  }
1452  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1453  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1454  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1455  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1456  }
1457  if ( enc->bits_per_raw_sample > 0
1459  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1460  " (%d bit)", enc->bits_per_raw_sample);
1461  if (av_log_get_level() >= AV_LOG_VERBOSE) {
1462  if (enc->initial_padding)
1463  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1464  ", delay %d", enc->initial_padding);
1465  if (enc->trailing_padding)
1466  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1467  ", padding %d", enc->trailing_padding);
1468  }
1469  break;
1470  case AVMEDIA_TYPE_DATA:
1471  if (av_log_get_level() >= AV_LOG_DEBUG) {
1472  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1473  if (g)
1474  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1475  ", %d/%d",
1476  enc->time_base.num / g, enc->time_base.den / g);
1477  }
1478  break;
1479  case AVMEDIA_TYPE_SUBTITLE:
1480  if (enc->width)
1481  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1482  ", %dx%d", enc->width, enc->height);
1483  break;
1484  default:
1485  return;
1486  }
1487  if (encode) {
1488  if (enc->flags & AV_CODEC_FLAG_PASS1)
1489  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1490  ", pass 1");
1491  if (enc->flags & AV_CODEC_FLAG_PASS2)
1492  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1493  ", pass 2");
1494  }
1495  bitrate = get_bit_rate(enc);
1496  if (bitrate != 0) {
1497  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1498  ", %"PRId64" kb/s", bitrate / 1000);
1499  } else if (enc->rc_max_rate > 0) {
1500  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1501  ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000);
1502  }
1503 }
1504 
1505 const char *av_get_profile_name(const AVCodec *codec, int profile)
1506 {
1507  const AVProfile *p;
1508  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1509  return NULL;
1510 
1511  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1512  if (p->profile == profile)
1513  return p->name;
1514 
1515  return NULL;
1516 }
1517 
1519 {
1520  const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
1521  const AVProfile *p;
1522 
1523  if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
1524  return NULL;
1525 
1526  for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1527  if (p->profile == profile)
1528  return p->name;
1529 
1530  return NULL;
1531 }
1532 
1533 unsigned avcodec_version(void)
1534 {
1535 // av_assert0(AV_CODEC_ID_V410==164);
1538 // av_assert0(AV_CODEC_ID_BMV_AUDIO==86071);
1539  av_assert0(AV_CODEC_ID_SRT==94216);
1541 
1542  return LIBAVCODEC_VERSION_INT;
1543 }
1544 
1545 const char *avcodec_configuration(void)
1546 {
1547  return FFMPEG_CONFIGURATION;
1548 }
1549 
1550 const char *avcodec_license(void)
1551 {
1552 #define LICENSE_PREFIX "libavcodec license: "
1553  return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1554 }
1555 
1557 {
1558  switch (codec_id) {
1559  case AV_CODEC_ID_8SVX_EXP:
1560  case AV_CODEC_ID_8SVX_FIB:
1561  case AV_CODEC_ID_ADPCM_CT:
1569  return 4;
1570  case AV_CODEC_ID_DSD_LSBF:
1571  case AV_CODEC_ID_DSD_MSBF:
1574  case AV_CODEC_ID_PCM_ALAW:
1575  case AV_CODEC_ID_PCM_MULAW:
1576  case AV_CODEC_ID_PCM_S8:
1578  case AV_CODEC_ID_PCM_U8:
1579  case AV_CODEC_ID_PCM_ZORK:
1580  case AV_CODEC_ID_SDX2_DPCM:
1581  return 8;
1582  case AV_CODEC_ID_PCM_S16BE:
1584  case AV_CODEC_ID_PCM_S16LE:
1586  case AV_CODEC_ID_PCM_U16BE:
1587  case AV_CODEC_ID_PCM_U16LE:
1588  return 16;
1590  case AV_CODEC_ID_PCM_S24BE:
1591  case AV_CODEC_ID_PCM_S24LE:
1593  case AV_CODEC_ID_PCM_U24BE:
1594  case AV_CODEC_ID_PCM_U24LE:
1595  return 24;
1596  case AV_CODEC_ID_PCM_S32BE:
1597  case AV_CODEC_ID_PCM_S32LE:
1599  case AV_CODEC_ID_PCM_U32BE:
1600  case AV_CODEC_ID_PCM_U32LE:
1601  case AV_CODEC_ID_PCM_F32BE:
1602  case AV_CODEC_ID_PCM_F32LE:
1603  case AV_CODEC_ID_PCM_F24LE:
1604  case AV_CODEC_ID_PCM_F16LE:
1605  return 32;
1606  case AV_CODEC_ID_PCM_F64BE:
1607  case AV_CODEC_ID_PCM_F64LE:
1608  case AV_CODEC_ID_PCM_S64BE:
1609  case AV_CODEC_ID_PCM_S64LE:
1610  return 64;
1611  default:
1612  return 0;
1613  }
1614 }
1615 
1617 {
1618  static const enum AVCodecID map[AV_SAMPLE_FMT_NB][2] = {
1630  };
1631  if (fmt < 0 || fmt >= AV_SAMPLE_FMT_NB)
1632  return AV_CODEC_ID_NONE;
1633  if (be < 0 || be > 1)
1634  be = AV_NE(1, 0);
1635  return map[fmt][be];
1636 }
1637 
1639 {
1640  switch (codec_id) {
1642  return 2;
1644  return 3;
1648  case AV_CODEC_ID_ADPCM_SWF:
1649  case AV_CODEC_ID_ADPCM_MS:
1650  return 4;
1651  default:
1652  return av_get_exact_bits_per_sample(codec_id);
1653  }
1654 }
1655 
1656 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
1657  uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
1658  uint8_t * extradata, int frame_size, int frame_bytes)
1659 {
1661  int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
1662 
1663  /* codecs with an exact constant bits per sample */
1664  if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
1665  return (frame_bytes * 8LL) / (bps * ch);
1666  bps = bits_per_coded_sample;
1667 
1668  /* codecs with a fixed packet duration */
1669  switch (id) {
1670  case AV_CODEC_ID_ADPCM_ADX: return 32;
1671  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
1672  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
1673  case AV_CODEC_ID_AMR_NB:
1674  case AV_CODEC_ID_EVRC:
1675  case AV_CODEC_ID_GSM:
1676  case AV_CODEC_ID_QCELP:
1677  case AV_CODEC_ID_RA_288: return 160;
1678  case AV_CODEC_ID_AMR_WB:
1679  case AV_CODEC_ID_GSM_MS: return 320;
1680  case AV_CODEC_ID_MP1: return 384;
1681  case AV_CODEC_ID_ATRAC1: return 512;
1682  case AV_CODEC_ID_ATRAC3: return 1024 * framecount;
1683  case AV_CODEC_ID_ATRAC3P: return 2048;
1684  case AV_CODEC_ID_MP2:
1685  case AV_CODEC_ID_MUSEPACK7: return 1152;
1686  case AV_CODEC_ID_AC3: return 1536;
1687  }
1688 
1689  if (sr > 0) {
1690  /* calc from sample rate */
1691  if (id == AV_CODEC_ID_TTA)
1692  return 256 * sr / 245;
1693  else if (id == AV_CODEC_ID_DST)
1694  return 588 * sr / 44100;
1695 
1696  if (ch > 0) {
1697  /* calc from sample rate and channels */
1698  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
1699  return (480 << (sr / 22050)) / ch;
1700  }
1701 
1702  if (id == AV_CODEC_ID_MP3)
1703  return sr <= 24000 ? 576 : 1152;
1704  }
1705 
1706  if (ba > 0) {
1707  /* calc from block_align */
1708  if (id == AV_CODEC_ID_SIPR) {
1709  switch (ba) {
1710  case 20: return 160;
1711  case 19: return 144;
1712  case 29: return 288;
1713  case 37: return 480;
1714  }
1715  } else if (id == AV_CODEC_ID_ILBC) {
1716  switch (ba) {
1717  case 38: return 160;
1718  case 50: return 240;
1719  }
1720  }
1721  }
1722 
1723  if (frame_bytes > 0) {
1724  /* calc from frame_bytes only */
1725  if (id == AV_CODEC_ID_TRUESPEECH)
1726  return 240 * (frame_bytes / 32);
1727  if (id == AV_CODEC_ID_NELLYMOSER)
1728  return 256 * (frame_bytes / 64);
1729  if (id == AV_CODEC_ID_RA_144)
1730  return 160 * (frame_bytes / 20);
1731  if (id == AV_CODEC_ID_G723_1)
1732  return 240 * (frame_bytes / 24);
1733 
1734  if (bps > 0) {
1735  /* calc from frame_bytes and bits_per_coded_sample */
1737  return frame_bytes * 8 / bps;
1738  }
1739 
1740  if (ch > 0 && ch < INT_MAX/16) {
1741  /* calc from frame_bytes and channels */
1742  switch (id) {
1743  case AV_CODEC_ID_ADPCM_AFC:
1744  return frame_bytes / (9 * ch) * 16;
1745  case AV_CODEC_ID_ADPCM_PSX:
1746  case AV_CODEC_ID_ADPCM_DTK:
1747  return frame_bytes / (16 * ch) * 28;
1748  case AV_CODEC_ID_ADPCM_4XM:
1751  return (frame_bytes - 4 * ch) * 2 / ch;
1753  return (frame_bytes - 4) * 2 / ch;
1755  return (frame_bytes - 8) * 2 / ch;
1756  case AV_CODEC_ID_ADPCM_THP:
1758  if (extradata)
1759  return frame_bytes * 14 / (8 * ch);
1760  break;
1761  case AV_CODEC_ID_ADPCM_XA:
1762  return (frame_bytes / 128) * 224 / ch;
1764  return (frame_bytes - 6 - ch) / ch;
1765  case AV_CODEC_ID_ROQ_DPCM:
1766  return (frame_bytes - 8) / ch;
1767  case AV_CODEC_ID_XAN_DPCM:
1768  return (frame_bytes - 2 * ch) / ch;
1769  case AV_CODEC_ID_MACE3:
1770  return 3 * frame_bytes / ch;
1771  case AV_CODEC_ID_MACE6:
1772  return 6 * frame_bytes / ch;
1773  case AV_CODEC_ID_PCM_LXF:
1774  return 2 * (frame_bytes / (5 * ch));
1775  case AV_CODEC_ID_IAC:
1776  case AV_CODEC_ID_IMC:
1777  return 4 * frame_bytes / ch;
1778  }
1779 
1780  if (tag) {
1781  /* calc from frame_bytes, channels, and codec_tag */
1782  if (id == AV_CODEC_ID_SOL_DPCM) {
1783  if (tag == 3)
1784  return frame_bytes / ch;
1785  else
1786  return frame_bytes * 2 / ch;
1787  }
1788  }
1789 
1790  if (ba > 0) {
1791  /* calc from frame_bytes, channels, and block_align */
1792  int blocks = frame_bytes / ba;
1793  switch (id) {
1795  if (bps < 2 || bps > 5)
1796  return 0;
1797  return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
1799  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
1801  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
1803  return blocks * ((ba - 4 * ch) * 2 / ch);
1804  case AV_CODEC_ID_ADPCM_MS:
1805  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
1807  return blocks * (ba - 16) * 2 / ch;
1808  }
1809  }
1810 
1811  if (bps > 0) {
1812  /* calc from frame_bytes, channels, and bits_per_coded_sample */
1813  switch (id) {
1814  case AV_CODEC_ID_PCM_DVD:
1815  if(bps<4 || frame_bytes<3)
1816  return 0;
1817  return 2 * ((frame_bytes - 3) / ((bps * 2 / 8) * ch));
1819  if(bps<4 || frame_bytes<4)
1820  return 0;
1821  return (frame_bytes - 4) / ((FFALIGN(ch, 2) * bps) / 8);
1822  case AV_CODEC_ID_S302M:
1823  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
1824  }
1825  }
1826  }
1827  }
1828 
1829  /* Fall back on using frame_size */
1830  if (frame_size > 1 && frame_bytes)
1831  return frame_size;
1832 
1833  //For WMA we currently have no other means to calculate duration thus we
1834  //do it here by assuming CBR, which is true for all known cases.
1835  if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
1836  if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
1837  return (frame_bytes * 8LL * sr) / bitrate;
1838  }
1839 
1840  return 0;
1841 }
1842 
1843 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
1844 {
1845  return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
1846  avctx->channels, avctx->block_align,
1847  avctx->codec_tag, avctx->bits_per_coded_sample,
1848  avctx->bit_rate, avctx->extradata, avctx->frame_size,
1849  frame_bytes);
1850 }
1851 
1853 {
1854  return get_audio_frame_duration(par->codec_id, par->sample_rate,
1855  par->channels, par->block_align,
1856  par->codec_tag, par->bits_per_coded_sample,
1857  par->bit_rate, par->extradata, par->frame_size,
1858  frame_bytes);
1859 }
1860 
1861 #if !HAVE_THREADS
1863 {
1864  return -1;
1865 }
1866 
1867 #endif
1868 
1869 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1870 {
1871  unsigned int n = 0;
1872 
1873  while (v >= 0xff) {
1874  *s++ = 0xff;
1875  v -= 0xff;
1876  n++;
1877  }
1878  *s = v;
1879  n++;
1880  return n;
1881 }
1882 
1883 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
1884 {
1885  int i;
1886  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
1887  return i;
1888 }
1889 
1891 {
1892  int i;
1893  if (!codec->hw_configs || index < 0)
1894  return NULL;
1895  for (i = 0; i <= index; i++)
1896  if (!codec->hw_configs[i])
1897  return NULL;
1898  return &codec->hw_configs[index]->public;
1899 }
1900 
1901 #if FF_API_USER_VISIBLE_AVHWACCEL
1903 {
1904  return NULL;
1905 }
1906 
1908 {
1909 }
1910 #endif
1911 
1912 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1913 {
1914  if (lockmgr_cb) {
1915  // There is no good way to rollback a failure to destroy the
1916  // mutex, so we ignore failures.
1919  lockmgr_cb = NULL;
1920  codec_mutex = NULL;
1921  avformat_mutex = NULL;
1922  }
1923 
1924  if (cb) {
1925  void *new_codec_mutex = NULL;
1926  void *new_avformat_mutex = NULL;
1927  int err;
1928  if (err = cb(&new_codec_mutex, AV_LOCK_CREATE)) {
1929  return err > 0 ? AVERROR_UNKNOWN : err;
1930  }
1931  if (err = cb(&new_avformat_mutex, AV_LOCK_CREATE)) {
1932  // Ignore failures to destroy the newly created mutex.
1933  cb(&new_codec_mutex, AV_LOCK_DESTROY);
1934  return err > 0 ? AVERROR_UNKNOWN : err;
1935  }
1936  lockmgr_cb = cb;
1937  codec_mutex = new_codec_mutex;
1938  avformat_mutex = new_avformat_mutex;
1939  }
1940 
1941  return 0;
1942 }
1943 
1944 int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
1945 {
1946  if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
1947  return 0;
1948 
1949  if (lockmgr_cb) {
1951  return -1;
1952  }
1953 
1955  av_log(log_ctx, AV_LOG_ERROR,
1956  "Insufficient thread locking. At least %d threads are "
1957  "calling avcodec_open2() at the same time right now.\n",
1959  if (!lockmgr_cb)
1960  av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n");
1961  ff_avcodec_locked = 1;
1962  ff_unlock_avcodec(codec);
1963  return AVERROR(EINVAL);
1964  }
1966  ff_avcodec_locked = 1;
1967  return 0;
1968 }
1969 
1970 int ff_unlock_avcodec(const AVCodec *codec)
1971 {
1972  if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
1973  return 0;
1974 
1976  ff_avcodec_locked = 0;
1978  if (lockmgr_cb) {
1980  return -1;
1981  }
1982 
1983  return 0;
1984 }
1985 
1987 {
1988  if (lockmgr_cb) {
1990  return -1;
1991  }
1992  return 0;
1993 }
1994 
1996 {
1997  if (lockmgr_cb) {
1999  return -1;
2000  }
2001  return 0;
2002 }
2003 
2004 unsigned int avpriv_toupper4(unsigned int x)
2005 {
2006  return av_toupper(x & 0xFF) +
2007  (av_toupper((x >> 8) & 0xFF) << 8) +
2008  (av_toupper((x >> 16) & 0xFF) << 16) +
2009 ((unsigned)av_toupper((x >> 24) & 0xFF) << 24);
2010 }
2011 
2013 {
2014  int ret;
2015 
2016  dst->owner[0] = src->owner[0];
2017  dst->owner[1] = src->owner[1];
2018 
2019  ret = av_frame_ref(dst->f, src->f);
2020  if (ret < 0)
2021  return ret;
2022 
2023  av_assert0(!dst->progress);
2024 
2025  if (src->progress &&
2026  !(dst->progress = av_buffer_ref(src->progress))) {
2027  ff_thread_release_buffer(dst->owner[0], dst);
2028  return AVERROR(ENOMEM);
2029  }
2030 
2031  return 0;
2032 }
2033 
2034 #if !HAVE_THREADS
2035 
2037 {
2038  return ff_get_format(avctx, fmt);
2039 }
2040 
2042 {
2043  f->owner[0] = f->owner[1] = avctx;
2044  return ff_get_buffer(avctx, f->f, flags);
2045 }
2046 
2048 {
2049  if (f->f)
2050  av_frame_unref(f->f);
2051 }
2052 
2054 {
2055 }
2056 
2057 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
2058 {
2059 }
2060 
2061 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
2062 {
2063 }
2064 
2066 {
2067  return 1;
2068 }
2069 
2071 {
2072  return 0;
2073 }
2074 
2076 {
2077 }
2078 
2079 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
2080 {
2081 }
2082 
2083 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
2084 {
2085 }
2086 
2087 #endif
2088 
2090 {
2091  return !!s->internal;
2092 }
2093 
2094 int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
2095 {
2096  int ret;
2097  char *str;
2098 
2099  ret = av_bprint_finalize(buf, &str);
2100  if (ret < 0)
2101  return ret;
2102  if (!av_bprint_is_complete(buf)) {
2103  av_free(str);
2104  return AVERROR(ENOMEM);
2105  }
2106 
2107  avctx->extradata = str;
2108  /* Note: the string is NUL terminated (so extradata can be read as a
2109  * string), but the ending character is not accounted in the size (in
2110  * binary formats you are likely not supposed to mux that character). When
2111  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
2112  * zeros. */
2113  avctx->extradata_size = buf->len;
2114  return 0;
2115 }
2116 
2117 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
2118  const uint8_t *end,
2119  uint32_t *av_restrict state)
2120 {
2121  int i;
2122 
2123  av_assert0(p <= end);
2124  if (p >= end)
2125  return end;
2126 
2127  for (i = 0; i < 3; i++) {
2128  uint32_t tmp = *state << 8;
2129  *state = tmp + *(p++);
2130  if (tmp == 0x100 || p == end)
2131  return p;
2132  }
2133 
2134  while (p < end) {
2135  if (p[-1] > 1 ) p += 3;
2136  else if (p[-2] ) p += 2;
2137  else if (p[-3]|(p[-1]-1)) p++;
2138  else {
2139  p++;
2140  break;
2141  }
2142  }
2143 
2144  p = FFMIN(p, end) - 4;
2145  *state = AV_RB32(p);
2146 
2147  return p + 4;
2148 }
2149 
2151 {
2152  AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
2153  if (!props)
2154  return NULL;
2155 
2156  if (size)
2157  *size = sizeof(*props);
2158 
2159  props->vbv_delay = UINT64_MAX;
2160 
2161  return props;
2162 }
2163 
2165 {
2167  AVCPBProperties *props;
2168  size_t size;
2169 
2170  props = av_cpb_properties_alloc(&size);
2171  if (!props)
2172  return NULL;
2173 
2174  tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
2175  if (!tmp) {
2176  av_freep(&props);
2177  return NULL;
2178  }
2179 
2180  avctx->coded_side_data = tmp;
2181  avctx->nb_coded_side_data++;
2182 
2184  avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
2185  avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
2186 
2187  return props;
2188 }
2189 
2191 {
2192  av_freep(&par->extradata);
2193 
2194  memset(par, 0, sizeof(*par));
2195 
2197  par->codec_id = AV_CODEC_ID_NONE;
2198  par->format = -1;
2205  par->sample_aspect_ratio = (AVRational){ 0, 1 };
2206  par->profile = FF_PROFILE_UNKNOWN;
2207  par->level = FF_LEVEL_UNKNOWN;
2208 }
2209 
2211 {
2212  AVCodecParameters *par = av_mallocz(sizeof(*par));
2213 
2214  if (!par)
2215  return NULL;
2217  return par;
2218 }
2219 
2221 {
2222  AVCodecParameters *par = *ppar;
2223 
2224  if (!par)
2225  return;
2227 
2228  av_freep(ppar);
2229 }
2230 
2232 {
2234  memcpy(dst, src, sizeof(*dst));
2235 
2236  dst->extradata = NULL;
2237  dst->extradata_size = 0;
2238  if (src->extradata) {
2240  if (!dst->extradata)
2241  return AVERROR(ENOMEM);
2242  memcpy(dst->extradata, src->extradata, src->extradata_size);
2243  dst->extradata_size = src->extradata_size;
2244  }
2245 
2246  return 0;
2247 }
2248 
2250  const AVCodecContext *codec)
2251 {
2253 
2254  par->codec_type = codec->codec_type;
2255  par->codec_id = codec->codec_id;
2256  par->codec_tag = codec->codec_tag;
2257 
2258  par->bit_rate = codec->bit_rate;
2261  par->profile = codec->profile;
2262  par->level = codec->level;
2263 
2264  switch (par->codec_type) {
2265  case AVMEDIA_TYPE_VIDEO:
2266  par->format = codec->pix_fmt;
2267  par->width = codec->width;
2268  par->height = codec->height;
2269  par->field_order = codec->field_order;
2270  par->color_range = codec->color_range;
2271  par->color_primaries = codec->color_primaries;
2272  par->color_trc = codec->color_trc;
2273  par->color_space = codec->colorspace;
2276  par->video_delay = codec->has_b_frames;
2277  break;
2278  case AVMEDIA_TYPE_AUDIO:
2279  par->format = codec->sample_fmt;
2280  par->channel_layout = codec->channel_layout;
2281  par->channels = codec->channels;
2282  par->sample_rate = codec->sample_rate;
2283  par->block_align = codec->block_align;
2284  par->frame_size = codec->frame_size;
2285  par->initial_padding = codec->initial_padding;
2286  par->trailing_padding = codec->trailing_padding;
2287  par->seek_preroll = codec->seek_preroll;
2288  break;
2289  case AVMEDIA_TYPE_SUBTITLE:
2290  par->width = codec->width;
2291  par->height = codec->height;
2292  break;
2293  }
2294 
2295  if (codec->extradata) {
2297  if (!par->extradata)
2298  return AVERROR(ENOMEM);
2299  memcpy(par->extradata, codec->extradata, codec->extradata_size);
2300  par->extradata_size = codec->extradata_size;
2301  }
2302 
2303  return 0;
2304 }
2305 
2307  const AVCodecParameters *par)
2308 {
2309  codec->codec_type = par->codec_type;
2310  codec->codec_id = par->codec_id;
2311  codec->codec_tag = par->codec_tag;
2312 
2313  codec->bit_rate = par->bit_rate;
2316  codec->profile = par->profile;
2317  codec->level = par->level;
2318 
2319  switch (par->codec_type) {
2320  case AVMEDIA_TYPE_VIDEO:
2321  codec->pix_fmt = par->format;
2322  codec->width = par->width;
2323  codec->height = par->height;
2324  codec->field_order = par->field_order;
2325  codec->color_range = par->color_range;
2326  codec->color_primaries = par->color_primaries;
2327  codec->color_trc = par->color_trc;
2328  codec->colorspace = par->color_space;
2331  codec->has_b_frames = par->video_delay;
2332  break;
2333  case AVMEDIA_TYPE_AUDIO:
2334  codec->sample_fmt = par->format;
2335  codec->channel_layout = par->channel_layout;
2336  codec->channels = par->channels;
2337  codec->sample_rate = par->sample_rate;
2338  codec->block_align = par->block_align;
2339  codec->frame_size = par->frame_size;
2340  codec->delay =
2341  codec->initial_padding = par->initial_padding;
2342  codec->trailing_padding = par->trailing_padding;
2343  codec->seek_preroll = par->seek_preroll;
2344  break;
2345  case AVMEDIA_TYPE_SUBTITLE:
2346  codec->width = par->width;
2347  codec->height = par->height;
2348  break;
2349  }
2350 
2351  if (par->extradata) {
2352  av_freep(&codec->extradata);
2354  if (!codec->extradata)
2355  return AVERROR(ENOMEM);
2356  memcpy(codec->extradata, par->extradata, par->extradata_size);
2357  codec->extradata_size = par->extradata_size;
2358  }
2359 
2360  return 0;
2361 }
2362 
2363 int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
2364  void **data, size_t *sei_size)
2365 {
2366  AVFrameSideData *side_data = NULL;
2367  uint8_t *sei_data;
2368 
2369  if (frame)
2370  side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
2371 
2372  if (!side_data) {
2373  *data = NULL;
2374  return 0;
2375  }
2376 
2377  *sei_size = side_data->size + 11;
2378  *data = av_mallocz(*sei_size + prefix_len);
2379  if (!*data)
2380  return AVERROR(ENOMEM);
2381  sei_data = (uint8_t*)*data + prefix_len;
2382 
2383  // country code
2384  sei_data[0] = 181;
2385  sei_data[1] = 0;
2386  sei_data[2] = 49;
2387 
2388  /**
2389  * 'GA94' is standard in North America for ATSC, but hard coding
2390  * this style may not be the right thing to do -- other formats
2391  * do exist. This information is not available in the side_data
2392  * so we are going with this right now.
2393  */
2394  AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4'));
2395  sei_data[7] = 3;
2396  sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40;
2397  sei_data[9] = 0;
2398 
2399  memcpy(sei_data + 10, side_data->data, side_data->size);
2400 
2401  sei_data[side_data->size+10] = 255;
2402 
2403  return 0;
2404 }
2405 
2407 {
2408  AVRational framerate = avctx->framerate;
2409  int bits_per_coded_sample = avctx->bits_per_coded_sample;
2410  int64_t bitrate;
2411 
2412  if (!(framerate.num && framerate.den))
2413  framerate = av_inv_q(avctx->time_base);
2414  if (!(framerate.num && framerate.den))
2415  return 0;
2416 
2417  if (!bits_per_coded_sample) {
2419  bits_per_coded_sample = av_get_bits_per_pixel(desc);
2420  }
2421  bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
2422  framerate.num / framerate.den;
2423 
2424  return bitrate;
2425 }
int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
Get an estimated video bitrate based on frame size, frame rate and coded bits per pixel...
Definition: utils.c:2406
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define FF_SANE_NB_CHANNELS
Definition: internal.h:86
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2565
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:77
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwaccel.h:34
enum AVChromaLocation chroma_location
Definition: avcodec.h:3928
float, planar
Definition: samplefmt.h:69
#define FF_SUB_CHARENC_MODE_PRE_DECODER
the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv ...
Definition: avcodec.h:3070
#define ATOMIC_VAR_INIT(value)
Definition: stdatomic.h:31
#define NULL
Definition: coverity.c:32
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1288
const struct AVCodec * codec
Definition: avcodec.h:1511
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:162
AVRational framerate
Definition: avcodec.h:3012
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:3919
static int64_t get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:579
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:3033
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:1214
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:271
const char * s
Definition: avisynth_c.h:768
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:248
uint32_t fourcc
Definition: hwcontext_qsv.c:90
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:3926
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:74
#define AV_NUM_DATA_POINTERS
Definition: frame.h:202
static int shift(int a, int b)
Definition: sonic.c:82
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:241
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:106
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition: avcodec.h:3069
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: avcodec.h:3050
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
unsigned int fourcc
Definition: raw.h:36
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2363
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
#define pthread_mutex_lock(a)
Definition: ffprobe.c:61
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:1232
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:245
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:155
const struct AVCodecHWConfigInternal ** hw_configs
Array of pointers to hardware configurations supported by the codec, or NULL if no hardware supported...
Definition: avcodec.h:3503
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1689
const char * fmt
Definition: avisynth_c.h:769
int av_lockmgr_register(int(*cb)(void **mutex, enum AVLockOp op))
Register a user provided lock manager supporting the operations specified by AVLockOp.
Definition: utils.c:1912
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition: internal.h:170
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
Unlock the mutex.
Definition: avcodec.h:5940
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVFrame * f
Definition: thread.h:36
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1552
AVFrame * to_free
Definition: internal.h:157
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
const char * g
Definition: vf_curves.c:112
const char * desc
Definition: nvenc.c:63
#define LIBAVCODEC_VERSION_MICRO
Definition: version.h:32
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:158
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2315
AVRational sample_aspect_ratio
Video only.
Definition: avcodec.h:3914
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2403
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:246
channels
Definition: aptx.c:30
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1291
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:1545
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2132
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3838
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
int ff_unlock_avcodec(const AVCodec *codec)
Definition: utils.c:1970
int num
Numerator.
Definition: rational.h:59
#define FF_SUB_CHARENC_MODE_DO_NOTHING
do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for inst...
Definition: avcodec.h:3068
const char * b
Definition: vf_curves.c:113
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:1550
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1880
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:185
double, planar
Definition: samplefmt.h:70
enum AVMediaType codec_type
Definition: rtp.c:37
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1711
enum AVPixelFormat pix_fmt
Definition: raw.h:35
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:207
unsigned num_rects
Definition: avcodec.h:3818
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
Definition: utils.c:575
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:123
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:251
The following 12 formats have the disadvantage of needing 1 format for each bit depth.
Definition: pixfmt.h:152
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1004
mpegvideo header.
enum AVMediaType type
Definition: avcodec.h:3378
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:103
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3460
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2725
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: utils.c:2036
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: utils.c:438
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:1024
intptr_t atomic_int
Definition: stdatomic.h:55
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2658
int trailing_padding
Audio only.
Definition: avcodec.h:3974
#define src
Definition: vp8dsp.c:254
int profile
profile
Definition: avcodec.h:2827
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:250
AVCodec.
Definition: avcodec.h:3365
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:127
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2194
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3830
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:5937
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:196
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:3802
enum AVColorSpace color_space
Definition: avcodec.h:3927
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2747
Macro definitions for various function/variable attributes.
static void * codec_mutex
Definition: utils.c:120
void ff_decode_bsfs_uninit(AVCodecContext *avctx)
Definition: decode.c:1969
int frame_size
Audio only.
Definition: avcodec.h:3959
static atomic_int entangled_thread_counter
Definition: utils.c:119
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1624
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:688
AVSubtitleRect ** rects
Definition: avcodec.h:3819
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:176
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
Definition: utils.c:2079
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill AVFrame audio data and linesize pointers.
Definition: utils.c:461
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:171
uint64_t vbv_delay
The delay between the time the packet this structure is associated with is received and the time when...
Definition: avcodec.h:1126
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian ...
Definition: pixfmt.h:175
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
Definition: utils.c:423
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:2926
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:212
Public dictionary API.
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:186
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:106
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:97
HMTX pthread_mutex_t
Definition: os2threads.h:49
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2165
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
Lock the mutex.
Definition: avcodec.h:5939
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AV_SAMPLE_FMT_U8
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
Opaque data information usually continuous.
Definition: avutil.h:203
int width
Video only.
Definition: avcodec.h:3904
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:73
AVOptions.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: utils.c:2210
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:2690
void * thread_ctx
Definition: internal.h:161
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static AVCodec * first_avcodec
Definition: utils.c:148
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
Definition: utils.c:226
int trailing_padding
Audio only.
Definition: avcodec.h:3190
Multithreading support functions.
#define AV_NE(be, le)
Definition: common.h:50
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:400
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:247
#define FF_CODEC_PROPERTY_LOSSLESS
Definition: avcodec.h:3134
#define LIBAVCODEC_VERSION_INT
Definition: version.h:34
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1602
#define LICENSE_PREFIX
static struct @281 state
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:87
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:2306
static AVFrame * frame
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:187
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:2164
Public header for CRC hash function implementation.
void * frame_thread_encoder
Definition: internal.h:178
int initial_padding
Audio only.
Definition: avcodec.h:3967
Structure to hold side data for an AVFrame.
Definition: frame.h:163
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
Definition: imgutils.c:287
int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Call avcodec_open2 recursively by decrementing counter, unlocking mutex, calling the function and the...
Definition: utils.c:602
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:272
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:170
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:96
static int(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:114
static int flags
Definition: log.c:57
uint32_t tag
Definition: movenc.c:1448
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:190
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
uint8_t * data
Definition: avcodec.h:1358
static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, uint32_t tag, int bits_per_coded_sample, int64_t bitrate, uint8_t *extradata, int frame_size, int frame_bytes)
Definition: utils.c:1656
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:2733
int av_codec_get_max_lowres(const AVCodec *codec)
Definition: utils.c:569
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:84
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
Definition: utils.c:1883
ptrdiff_t size
Definition: opengl_enc.c:101
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2718
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:274
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:211
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:858
signed 32 bits
Definition: samplefmt.h:62
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:198
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
Definition: utils.c:2150
const OptionDef options[]
Definition: ffserver.c:3948
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:2139
static void codec_parameters_reset(AVCodecParameters *par)
Definition: utils.c:2190
#define FFALIGN(x, a)
Definition: macros.h:48
uint64_t channel_layout
Audio only.
Definition: avcodec.h:3940
#define av_log(a,...)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
FramePool * pool
Definition: internal.h:159
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3867
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: avcodec.h:2564
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:1237
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
Definition: utils.c:246
static av_cold void avcodec_init(void)
Definition: utils.c:159
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:1907
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:153
int(* send_frame)(AVCodecContext *avctx, const AVFrame *frame)
Encode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3470
Libavcodec version macros.
int(* close)(AVCodecContext *)
Definition: avcodec.h:3461
av_cold int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:1139
enum AVCodecID id
Definition: avcodec.h:3379
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:3389
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:166
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:161
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition: pixdesc.c:2766
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:172
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
unsigned av_codec_get_codec_properties(const AVCodecContext *codec)
Definition: utils.c:564
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:2231
int width
Definition: frame.h:259
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1791
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1638
#define avpriv_atomic_ptr_cas
Definition: atomic_gcc.h:48
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
Create a mutex.
Definition: avcodec.h:5938
#define atomic_load(object)
Definition: stdatomic.h:93
#define MAKE_ACCESSORS(str, name, type, field)
Definition: internal.h:91
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:132
#define AVERROR(e)
Definition: error.h:43
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2004
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
int qmax
maximum quantizer
Definition: avcodec.h:2346
AVCodec * av_codec_next(const AVCodec *c)
If c is NULL, returns the first registered codec, if c is non-NULL, returns the next registered codec...
Definition: utils.c:151
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:3051
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2772
enum AVColorPrimaries color_primaries
Definition: avcodec.h:3925
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2089
int video_delay
Video only.
Definition: avcodec.h:3933
const char * r
Definition: vf_curves.c:111
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
Definition: avstring.c:442
AVFrame * buffer_frame
Definition: internal.h:200
int capabilities
Codec capabilities.
Definition: avcodec.h:3384
int initial_padding
Audio only.
Definition: avcodec.h:3003
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:58
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:1862
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:552
#define av_fourcc2str(fourcc)
Definition: avutil.h:348
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:178
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3834
const char * arg
Definition: jacosubdec.c:66
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:157
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1582
uint16_t width
Definition: gdv.c:47
simple assert() macros that are a bit more flexible than ISO C assert().
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:244
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
enum AVPacketSideDataType type
Definition: avcodec.h:1360
int av_log_get_level(void)
Get the current log level.
Definition: log.c:386
const char * name
Name of the codec implementation.
Definition: avcodec.h:3372
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:130
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:49
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:3198
const struct AVProfile * profiles
If non-NULL, an array of profiles recognized for this codec.
Definition: avcodec.h:723
GLsizei count
Definition: opengl_enc.c:109
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:179
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:82
#define FFMAX(a, b)
Definition: common.h:94
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: utils.c:2220
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:1852
const char av_codec_ffversion[]
Definition: utils.c:68
av_cold void ff_me_cmp_init_static(void)
Definition: me_cmp.c:980
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2709
reference-counted frame API
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3110
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2208
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3856
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:180
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2360
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:712
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:3446
static AVCodec ** last_avcodec
Definition: utils.c:149
int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options)
common internal API header
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:256
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
int refs
number of reference frames
Definition: avcodec.h:2085
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:283
int block_align
Audio only.
Definition: avcodec.h:3955
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
audio channel layout utility functions
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3386
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2764
#define FFMIN(a, b)
Definition: common.h:96
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:3143
Raw Video Codec.
signed 32 bits, planar
Definition: samplefmt.h:68
volatile int ff_avcodec_locked
Definition: utils.c:118
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1556
AVFrame * compat_decode_frame
Definition: internal.h:211
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
Definition: utils.c:2083
int width
picture width / height.
Definition: avcodec.h:1674
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3168
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2828
int priv_data_size
Definition: avcodec.h:3413
int profile
Definition: avcodec.h:3299
AVPacket * in_pkt
Definition: internal.h:118
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:846
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2111
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: os2threads.h:98
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:184
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:206
int level
level
Definition: avcodec.h:2925
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
Definition: utils.c:2053
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:176
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:3392
int n
Definition: avisynth_c.h:684
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
unsigned 8 bits, planar
Definition: samplefmt.h:66
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1633
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:239
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:154
enum AVCodecID codec_id
Definition: vaapi_decode.c:236
enum AVColorRange color_range
Video only.
Definition: avcodec.h:3924
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
Opaque data information usually sparse.
Definition: avutil.h:205
const char * av_get_colorspace_name(enum AVColorSpace val)
Get the name of a colorspace.
Definition: frame.c:83
#define pthread_mutex_unlock(a)
Definition: ffprobe.c:65
DecodeSimpleContext ds
Definition: internal.h:163
static pthread_mutex_t * mutex
Definition: w32pthreads.h:258
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
Definition: utils.c:546
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:3059
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:163
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3797
#define FF_ARRAY_ELEMS(a)
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
Definition: error.h:72
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:1270
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2753
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:499
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:3067
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:284
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:274
const AVS_VideoInfo int align
Definition: avisynth_c.h:795
AVBufferRef * progress
Definition: thread.h:40
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:1505
#define atomic_fetch_add(object, operand)
Definition: stdatomic.h:131
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2177
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1096
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:79
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:128
int frame_size
Definition: mxfenc.c:1947
AVHWAccel * av_hwaccel_next(const AVHWAccel *hwaccel)
If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL...
Definition: utils.c:1902
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1510
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:3443
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
Return the PCM codec associated with a sample format.
Definition: utils.c:1616
enum AVCodecID codec_id
Definition: avcodec.h:1512
int seek_preroll
Number of samples to skip after a discontinuity.
Definition: avcodec.h:3091
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1589
int sample_rate
samples per second
Definition: avcodec.h:2157
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:173
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition: utils.c:1890
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:168
main external API structure.
Definition: avcodec.h:1502
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:1251
int skip_samples_multiplier
Definition: internal.h:215
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:188
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2339
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
Definition: audioconvert.c:56
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1120
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1527
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:63
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1886
static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output)
Definition: encode_audio.c:95
uint8_t * data
Definition: frame.h:165
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:273
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
Definition: avcodec.h:755
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:253
void * buf
Definition: avisynth_c.h:690
int extradata_size
Definition: avcodec.h:1603
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1869
struct AVCodec * next
Definition: avcodec.h:3414
int nb_coded_side_data
Definition: avcodec.h:3144
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:189
AVCodecContext * owner[2]
Definition: thread.h:37
int coded_height
Definition: avcodec.h:1689
Describe the class of an AVClass context structure.
Definition: log.h:67
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:3135
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:191
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:680
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:231
Y , 16bpp, big-endian.
Definition: pixfmt.h:93
int index
Definition: gxfenc.c:89
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:275
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:119
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2125
Rational number (pair of numerator and denominator).
Definition: rational.h:58
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2118
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:2047
const char * name
short name for the profile
Definition: avcodec.h:3300
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: utils.c:2249
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:122
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:240
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:67
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:252
char * codec_whitelist
',' separated list of allowed decoders.
Definition: avcodec.h:3126
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:174
const VDPAUPixFmtMap * map
#define STRIDE_ALIGN
Definition: internal.h:95
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:704
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:614
#define snprintf
Definition: snprintf.h:34
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:1843
static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
Definition: utils.c:1205
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
Definition: avstring.c:93
mfxU16 profile
Definition: qsvenc.c:44
int seek_preroll
Audio only.
Definition: avcodec.h:3978
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:696
int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:2094
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:510
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:76
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:183
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:1256
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: avcodec.h:3893
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3391
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:159
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:131
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
void ff_color_frame(AVFrame *frame, const int c[4])
Definition: utils.c:497
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
int sample_rate
Audio only.
Definition: avcodec.h:3948
enum AVMediaType type
Definition: avcodec.h:698
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: avcodec.h:3390
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:198
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:78
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:243
Y , 8bpp.
Definition: pixfmt.h:70
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1544
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
common internal api header.
enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
Converts swscale x/y chroma position to AVChromaLocation.
Definition: utils.c:450
Free mutex resources.
Definition: avcodec.h:5941
if(ret< 0)
Definition: vf_mcdeint.c:279
int avpriv_lock_avformat(void)
Definition: utils.c:1986
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: internal.h:60
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
signed 16 bits
Definition: samplefmt.h:61
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:167
static double c[64]
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:3898
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:2728
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: avcodec.h:3668
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:188
void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call...
Definition: utils.c:135
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AVProfile.
Definition: avcodec.h:3298
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:129
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: utils.c:2065
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2744
void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: utils.c:2057
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:82
static const uint64_t c2
Definition: murmur3.c:50
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:356
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int caps_internal
Internal codec capabilities.
Definition: avcodec.h:3488
unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:3133
int den
Denominator.
Definition: rational.h:60
int avcodec_default_execute2(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
Definition: utils.c:533
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:253
unsigned bps
Definition: movenc.c:1449
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:181
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:770
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1310
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:850
static int lowres
Definition: ffplay.c:331
void * priv_data
Definition: avcodec.h:1529
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
Definition: utils.c:1290
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
Definition: utils.c:1944
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill plane data pointers and linesize for samples with sample format sample_fmt.
Definition: samplefmt.c:151
#define av_free(p)
uint8_t * dump_separator
dump format separator.
Definition: avcodec.h:3118
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:85
#define TAG_PRINT(x)
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:249
as in Berlin toast format
Definition: avcodec.h:569
int len
int channels
number of audio channels
Definition: avcodec.h:2158
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:3387
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1537
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:1533
Y , 16bpp, little-endian.
Definition: pixfmt.h:94
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:51
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3809
This side data corresponds to the AVCPBProperties struct.
Definition: avcodec.h:1245
static void * avformat_mutex
Definition: utils.c:121
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:254
Not part of ABI.
Definition: pixfmt.h:526
signed 64 bits, planar
Definition: samplefmt.h:72
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:3880
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3852
static const struct twinvq_data tab
unsigned int byte_buffer_size
Definition: internal.h:176
int channels
Audio only.
Definition: avcodec.h:3944
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:2061
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:182
static int height
Definition: utils.c:158
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
av_cold void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:181
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: avcodec.h:3052
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2188
int height
Definition: frame.h:259
void ff_frame_thread_encoder_free(AVCodecContext *avctx)
#define av_freep(p)
int64_t pts_correction_num_faulty_pts
Current statistics for PTS correction.
Definition: avcodec.h:3049
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:95
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:2154
signed 16 bits, planar
Definition: samplefmt.h:67
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:518
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:2012
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:171
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3388
AVMatrixEncoding
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2041
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3842
int ff_alloc_entries(AVCodecContext *avctx, int count)
Definition: utils.c:2070
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
Definition: utils.c:2363
int nb_channels
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2279
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:177
int avpriv_unlock_avformat(void)
Definition: utils.c:1995
const uint8_t * avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, uint32_t *av_restrict state)
Definition: utils.c:2117
void ff_reset_entries(AVCodecContext *avctx)
Definition: utils.c:2075
int(* init)(AVCodecContext *)
Definition: avcodec.h:3445
int depth
Number of bits in the component.
Definition: pixdesc.h:58
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
#define MKTAG(a, b, c, d)
Definition: common.h:366
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:213
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:3220
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:78
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:220
enum AVCodecID id
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:175
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:1518
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3458
static int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
Definition: mem_internal.h:27
int delay
Codec delay.
Definition: avcodec.h:1657
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:2560
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:238
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:67
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:160
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3019
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:242
#define FFMAX3(a, b, c)
Definition: common.h:95
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:169
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:520
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:2375
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:191
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
const char * name
Definition: opengl_enc.c:103
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:2957
static uint8_t tmp[11]
Definition: aes_ctr.c:26
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:156
int(* receive_frame)(AVCodecContext *avctx, AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3478