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 "libavutil/opt.h"
49 #include "me_cmp.h"
50 #include "mpegvideo.h"
51 #include "thread.h"
52 #include "frame_thread_encoder.h"
53 #include "internal.h"
54 #include "raw.h"
55 #include "bytestream.h"
56 #include "version.h"
57 #include <stdlib.h>
58 #include <stdarg.h>
59 #include <limits.h>
60 #include <float.h>
61 #if CONFIG_ICONV
62 # include <iconv.h>
63 #endif
64 
65 #include "libavutil/ffversion.h"
66 const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
67 
68 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
69 static int default_lockmgr_cb(void **arg, enum AVLockOp op)
70 {
71  void * volatile * mutex = arg;
72  int err;
73 
74  switch (op) {
75  case AV_LOCK_CREATE:
76  return 0;
77  case AV_LOCK_OBTAIN:
78  if (!*mutex) {
80  if (!tmp)
81  return AVERROR(ENOMEM);
82  if ((err = pthread_mutex_init(tmp, NULL))) {
83  av_free(tmp);
84  return AVERROR(err);
85  }
86  if (avpriv_atomic_ptr_cas(mutex, NULL, tmp)) {
88  av_free(tmp);
89  }
90  }
91 
92  if ((err = pthread_mutex_lock(*mutex)))
93  return AVERROR(err);
94 
95  return 0;
96  case AV_LOCK_RELEASE:
97  if ((err = pthread_mutex_unlock(*mutex)))
98  return AVERROR(err);
99 
100  return 0;
101  case AV_LOCK_DESTROY:
102  if (*mutex)
103  pthread_mutex_destroy(*mutex);
104  av_free(*mutex);
105  avpriv_atomic_ptr_cas(mutex, *mutex, NULL);
106  return 0;
107  }
108  return 1;
109 }
110 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = default_lockmgr_cb;
111 #else
112 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = NULL;
113 #endif
114 
115 
116 volatile int ff_avcodec_locked;
117 static int volatile entangled_thread_counter = 0;
118 static void *codec_mutex;
119 static void *avformat_mutex;
120 
121 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
122 {
123  uint8_t **p = ptr;
124  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
125  av_freep(p);
126  *size = 0;
127  return;
128  }
129  if (!ff_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE, 1))
130  memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
131 }
132 
133 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
134 {
135  uint8_t **p = ptr;
136  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
137  av_freep(p);
138  *size = 0;
139  return;
140  }
141  if (!ff_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE, 1))
142  memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
143 }
144 
145 /* encoder management */
148 
150 {
151  if (c)
152  return c->next;
153  else
154  return first_avcodec;
155 }
156 
157 static av_cold void avcodec_init(void)
158 {
159  static int initialized = 0;
160 
161  if (initialized != 0)
162  return;
163  initialized = 1;
164 
165  if (CONFIG_ME_CMP)
167 }
168 
169 int av_codec_is_encoder(const AVCodec *codec)
170 {
171  return codec && (codec->encode_sub || codec->encode2 ||codec->send_frame);
172 }
173 
174 int av_codec_is_decoder(const AVCodec *codec)
175 {
176  return codec && (codec->decode || codec->receive_frame);
177 }
178 
180 {
181  AVCodec **p;
182  avcodec_init();
183  p = last_avcodec;
184  codec->next = NULL;
185 
186  while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
187  p = &(*p)->next;
188  last_avcodec = &codec->next;
189 
190  if (codec->init_static_data)
191  codec->init_static_data(codec);
192 }
193 
194 #if FF_API_EMU_EDGE
196 {
197  return EDGE_WIDTH;
198 }
199 #endif
200 
201 #if FF_API_SET_DIMENSIONS
203 {
204  int ret = ff_set_dimensions(s, width, height);
205  if (ret < 0) {
206  av_log(s, AV_LOG_WARNING, "Failed to set dimensions %d %d\n", width, height);
207  }
208 }
209 #endif
210 
212 {
213  int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
214 
215  if (ret < 0)
216  width = height = 0;
217 
218  s->coded_width = width;
219  s->coded_height = height;
220  s->width = AV_CEIL_RSHIFT(width, s->lowres);
221  s->height = AV_CEIL_RSHIFT(height, s->lowres);
222 
223  return ret;
224 }
225 
227 {
228  int ret = av_image_check_sar(avctx->width, avctx->height, sar);
229 
230  if (ret < 0) {
231  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
232  sar.num, sar.den);
233  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
234  return ret;
235  } else {
236  avctx->sample_aspect_ratio = sar;
237  }
238  return 0;
239 }
240 
242  enum AVMatrixEncoding matrix_encoding)
243 {
244  AVFrameSideData *side_data;
245  enum AVMatrixEncoding *data;
246 
248  if (!side_data)
250  sizeof(enum AVMatrixEncoding));
251 
252  if (!side_data)
253  return AVERROR(ENOMEM);
254 
255  data = (enum AVMatrixEncoding*)side_data->data;
256  *data = matrix_encoding;
257 
258  return 0;
259 }
260 
262  int linesize_align[AV_NUM_DATA_POINTERS])
263 {
264  int i;
265  int w_align = 1;
266  int h_align = 1;
268 
269  if (desc) {
270  w_align = 1 << desc->log2_chroma_w;
271  h_align = 1 << desc->log2_chroma_h;
272  }
273 
274  switch (s->pix_fmt) {
275  case AV_PIX_FMT_YUV420P:
276  case AV_PIX_FMT_YUYV422:
277  case AV_PIX_FMT_YVYU422:
278  case AV_PIX_FMT_UYVY422:
279  case AV_PIX_FMT_YUV422P:
280  case AV_PIX_FMT_YUV440P:
281  case AV_PIX_FMT_YUV444P:
282  case AV_PIX_FMT_GBRP:
283  case AV_PIX_FMT_GBRAP:
284  case AV_PIX_FMT_GRAY8:
285  case AV_PIX_FMT_GRAY16BE:
286  case AV_PIX_FMT_GRAY16LE:
287  case AV_PIX_FMT_YUVJ420P:
288  case AV_PIX_FMT_YUVJ422P:
289  case AV_PIX_FMT_YUVJ440P:
290  case AV_PIX_FMT_YUVJ444P:
291  case AV_PIX_FMT_YUVA420P:
292  case AV_PIX_FMT_YUVA422P:
293  case AV_PIX_FMT_YUVA444P:
346  case AV_PIX_FMT_GBRP9LE:
347  case AV_PIX_FMT_GBRP9BE:
348  case AV_PIX_FMT_GBRP10LE:
349  case AV_PIX_FMT_GBRP10BE:
350  case AV_PIX_FMT_GBRP12LE:
351  case AV_PIX_FMT_GBRP12BE:
352  case AV_PIX_FMT_GBRP14LE:
353  case AV_PIX_FMT_GBRP14BE:
354  case AV_PIX_FMT_GBRP16LE:
355  case AV_PIX_FMT_GBRP16BE:
360  w_align = 16; //FIXME assume 16 pixel per macroblock
361  h_align = 16 * 2; // interlaced needs 2 macroblocks height
362  break;
363  case AV_PIX_FMT_YUV411P:
364  case AV_PIX_FMT_YUVJ411P:
366  w_align = 32;
367  h_align = 16 * 2;
368  break;
369  case AV_PIX_FMT_YUV410P:
370  if (s->codec_id == AV_CODEC_ID_SVQ1) {
371  w_align = 64;
372  h_align = 64;
373  }
374  break;
375  case AV_PIX_FMT_RGB555:
376  if (s->codec_id == AV_CODEC_ID_RPZA) {
377  w_align = 4;
378  h_align = 4;
379  }
381  w_align = 8;
382  h_align = 8;
383  }
384  break;
385  case AV_PIX_FMT_PAL8:
386  case AV_PIX_FMT_BGR8:
387  case AV_PIX_FMT_RGB8:
388  if (s->codec_id == AV_CODEC_ID_SMC ||
390  w_align = 4;
391  h_align = 4;
392  }
393  if (s->codec_id == AV_CODEC_ID_JV ||
395  w_align = 8;
396  h_align = 8;
397  }
398  break;
399  case AV_PIX_FMT_BGR24:
400  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
401  (s->codec_id == AV_CODEC_ID_ZLIB)) {
402  w_align = 4;
403  h_align = 4;
404  }
405  break;
406  case AV_PIX_FMT_RGB24:
407  if (s->codec_id == AV_CODEC_ID_CINEPAK) {
408  w_align = 4;
409  h_align = 4;
410  }
411  break;
412  default:
413  break;
414  }
415 
416  if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
417  w_align = FFMAX(w_align, 8);
418  }
419 
420  *width = FFALIGN(*width, w_align);
421  *height = FFALIGN(*height, h_align);
422  if (s->codec_id == AV_CODEC_ID_H264 || s->lowres) {
423  // some of the optimized chroma MC reads one line too much
424  // which is also done in mpeg decoders with lowres > 0
425  *height += 2;
426 
427  // H.264 uses edge emulation for out of frame motion vectors, for this
428  // it requires a temporary area large enough to hold a 21x21 block,
429  // increasing witdth ensure that the temporary area is large enough,
430  // the next rounded up width is 32
431  *width = FFMAX(*width, 32);
432  }
433 
434  for (i = 0; i < 4; i++)
435  linesize_align[i] = STRIDE_ALIGN;
436 }
437 
439 {
441  int chroma_shift = desc->log2_chroma_w;
442  int linesize_align[AV_NUM_DATA_POINTERS];
443  int align;
444 
445  avcodec_align_dimensions2(s, width, height, linesize_align);
446  align = FFMAX(linesize_align[0], linesize_align[3]);
447  linesize_align[1] <<= chroma_shift;
448  linesize_align[2] <<= chroma_shift;
449  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
450  *width = FFALIGN(*width, align);
451 }
452 
453 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
454 {
455  if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB)
456  return AVERROR(EINVAL);
457  pos--;
458 
459  *xpos = (pos&1) * 128;
460  *ypos = ((pos>>1)^(pos<4)) * 128;
461 
462  return 0;
463 }
464 
466 {
467  int pos, xout, yout;
468 
469  for (pos = AVCHROMA_LOC_UNSPECIFIED + 1; pos < AVCHROMA_LOC_NB; pos++) {
470  if (avcodec_enum_to_chroma_pos(&xout, &yout, pos) == 0 && xout == xpos && yout == ypos)
471  return pos;
472  }
474 }
475 
477  enum AVSampleFormat sample_fmt, const uint8_t *buf,
478  int buf_size, int align)
479 {
480  int ch, planar, needed_size, ret = 0;
481 
482  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
483  frame->nb_samples, sample_fmt,
484  align);
485  if (buf_size < needed_size)
486  return AVERROR(EINVAL);
487 
488  planar = av_sample_fmt_is_planar(sample_fmt);
489  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
490  if (!(frame->extended_data = av_mallocz_array(nb_channels,
491  sizeof(*frame->extended_data))))
492  return AVERROR(ENOMEM);
493  } else {
494  frame->extended_data = frame->data;
495  }
496 
497  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
498  (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
499  sample_fmt, align)) < 0) {
500  if (frame->extended_data != frame->data)
501  av_freep(&frame->extended_data);
502  return ret;
503  }
504  if (frame->extended_data != frame->data) {
505  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
506  frame->data[ch] = frame->extended_data[ch];
507  }
508 
509  return ret;
510 }
511 
512 void ff_color_frame(AVFrame *frame, const int c[4])
513 {
515  int p, y, x;
516 
518 
519  for (p = 0; p<desc->nb_components; p++) {
520  uint8_t *dst = frame->data[p];
521  int is_chroma = p == 1 || p == 2;
522  int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
523  int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
524  for (y = 0; y < height; y++) {
525  if (desc->comp[0].depth >= 9) {
526  for (x = 0; x<bytes; x++)
527  ((uint16_t*)dst)[x] = c[p];
528  }else
529  memset(dst, c[p], bytes);
530  dst += frame->linesize[p];
531  }
532  }
533 }
534 
535 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
536 {
537  int i;
538 
539  for (i = 0; i < count; i++) {
540  int r = func(c, (char *)arg + i * size);
541  if (ret)
542  ret[i] = r;
543  }
544  emms_c();
545  return 0;
546 }
547 
548 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
549 {
550  int i;
551 
552  for (i = 0; i < count; i++) {
553  int r = func(c, arg, i, 0);
554  if (ret)
555  ret[i] = r;
556  }
557  emms_c();
558  return 0;
559 }
560 
562  unsigned int fourcc)
563 {
564  while (tags->pix_fmt >= 0) {
565  if (tags->fourcc == fourcc)
566  return tags->pix_fmt;
567  tags++;
568  }
569  return AV_PIX_FMT_NONE;
570 }
571 
572 MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
573 MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, codec_descriptor)
574 MAKE_ACCESSORS(AVCodecContext, codec, int, lowres)
575 MAKE_ACCESSORS(AVCodecContext, codec, int, seek_preroll)
576 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
577 
578 unsigned av_codec_get_codec_properties(const AVCodecContext *codec)
579 {
580  return codec->properties;
581 }
582 
584 {
585  return codec->max_lowres;
586 }
587 
590 }
591 
593 {
594  int64_t bit_rate;
595  int bits_per_sample;
596 
597  switch (ctx->codec_type) {
598  case AVMEDIA_TYPE_VIDEO:
599  case AVMEDIA_TYPE_DATA:
602  bit_rate = ctx->bit_rate;
603  break;
604  case AVMEDIA_TYPE_AUDIO:
605  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
606  bit_rate = bits_per_sample ? ctx->sample_rate * (int64_t)ctx->channels * bits_per_sample : ctx->bit_rate;
607  break;
608  default:
609  bit_rate = 0;
610  break;
611  }
612  return bit_rate;
613 }
614 
616 {
617  int ret = 0;
618 
619  ff_unlock_avcodec(codec);
620 
621  ret = avcodec_open2(avctx, codec, options);
622 
623  ff_lock_avcodec(avctx, codec);
624  return ret;
625 }
626 
628 {
629  int ret = 0;
630  AVDictionary *tmp = NULL;
631  const AVPixFmtDescriptor *pixdesc;
632 
633  if (avcodec_is_open(avctx))
634  return 0;
635 
636  if ((!codec && !avctx->codec)) {
637  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
638  return AVERROR(EINVAL);
639  }
640  if ((codec && avctx->codec && codec != avctx->codec)) {
641  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
642  "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
643  return AVERROR(EINVAL);
644  }
645  if (!codec)
646  codec = avctx->codec;
647 
648  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
649  return AVERROR(EINVAL);
650 
651  if (options)
652  av_dict_copy(&tmp, *options, 0);
653 
654  ret = ff_lock_avcodec(avctx, codec);
655  if (ret < 0)
656  return ret;
657 
658  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
659  if (!avctx->internal) {
660  ret = AVERROR(ENOMEM);
661  goto end;
662  }
663 
664  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
665  if (!avctx->internal->pool) {
666  ret = AVERROR(ENOMEM);
667  goto free_and_end;
668  }
669 
670  avctx->internal->to_free = av_frame_alloc();
671  if (!avctx->internal->to_free) {
672  ret = AVERROR(ENOMEM);
673  goto free_and_end;
674  }
675 
677  if (!avctx->internal->compat_decode_frame) {
678  ret = AVERROR(ENOMEM);
679  goto free_and_end;
680  }
681 
683  if (!avctx->internal->buffer_frame) {
684  ret = AVERROR(ENOMEM);
685  goto free_and_end;
686  }
687 
688  avctx->internal->buffer_pkt = av_packet_alloc();
689  if (!avctx->internal->buffer_pkt) {
690  ret = AVERROR(ENOMEM);
691  goto free_and_end;
692  }
693 
694  avctx->internal->ds.in_pkt = av_packet_alloc();
695  if (!avctx->internal->ds.in_pkt) {
696  ret = AVERROR(ENOMEM);
697  goto free_and_end;
698  }
699 
701  if (!avctx->internal->last_pkt_props) {
702  ret = AVERROR(ENOMEM);
703  goto free_and_end;
704  }
705 
706  avctx->internal->skip_samples_multiplier = 1;
707 
708  if (codec->priv_data_size > 0) {
709  if (!avctx->priv_data) {
710  avctx->priv_data = av_mallocz(codec->priv_data_size);
711  if (!avctx->priv_data) {
712  ret = AVERROR(ENOMEM);
713  goto end;
714  }
715  if (codec->priv_class) {
716  *(const AVClass **)avctx->priv_data = codec->priv_class;
718  }
719  }
720  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
721  goto free_and_end;
722  } else {
723  avctx->priv_data = NULL;
724  }
725  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
726  goto free_and_end;
727 
728  if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
729  av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
730  ret = AVERROR(EINVAL);
731  goto free_and_end;
732  }
733 
734  // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
735  if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
736  (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
737  if (avctx->coded_width && avctx->coded_height)
738  ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
739  else if (avctx->width && avctx->height)
740  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
741  if (ret < 0)
742  goto free_and_end;
743  }
744 
745  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
746  && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
747  || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
748  av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
749  ff_set_dimensions(avctx, 0, 0);
750  }
751 
752  if (avctx->width > 0 && avctx->height > 0) {
753  if (av_image_check_sar(avctx->width, avctx->height,
754  avctx->sample_aspect_ratio) < 0) {
755  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
756  avctx->sample_aspect_ratio.num,
757  avctx->sample_aspect_ratio.den);
758  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
759  }
760  }
761 
762  /* if the decoder init function was already called previously,
763  * free the already allocated subtitle_header before overwriting it */
764  if (av_codec_is_decoder(codec))
765  av_freep(&avctx->subtitle_header);
766 
767  if (avctx->channels > FF_SANE_NB_CHANNELS) {
768  ret = AVERROR(EINVAL);
769  goto free_and_end;
770  }
771 
772  avctx->codec = codec;
773  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
774  avctx->codec_id == AV_CODEC_ID_NONE) {
775  avctx->codec_type = codec->type;
776  avctx->codec_id = codec->id;
777  }
778  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
779  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
780  av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
781  ret = AVERROR(EINVAL);
782  goto free_and_end;
783  }
784  avctx->frame_number = 0;
786 
787  if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
789  const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
790  AVCodec *codec2;
791  av_log(avctx, AV_LOG_ERROR,
792  "The %s '%s' is experimental but experimental codecs are not enabled, "
793  "add '-strict %d' if you want to use it.\n",
794  codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
795  codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
796  if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
797  av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
798  codec_string, codec2->name);
799  ret = AVERROR_EXPERIMENTAL;
800  goto free_and_end;
801  }
802 
803  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
804  (!avctx->time_base.num || !avctx->time_base.den)) {
805  avctx->time_base.num = 1;
806  avctx->time_base.den = avctx->sample_rate;
807  }
808 
809  if (!HAVE_THREADS)
810  av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
811 
812  if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) {
813  ff_unlock_avcodec(codec); //we will instantiate a few encoders thus kick the counter to prevent false detection of a problem
814  ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
815  ff_lock_avcodec(avctx, codec);
816  if (ret < 0)
817  goto free_and_end;
818  }
819 
820  if (HAVE_THREADS
822  ret = ff_thread_init(avctx);
823  if (ret < 0) {
824  goto free_and_end;
825  }
826  }
827  if (!HAVE_THREADS && !(codec->capabilities & AV_CODEC_CAP_AUTO_THREADS))
828  avctx->thread_count = 1;
829 
830  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
831  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
832  avctx->codec->max_lowres);
833  avctx->lowres = avctx->codec->max_lowres;
834  }
835 
836 #if FF_API_VISMV
837  if (avctx->debug_mv)
838  av_log(avctx, AV_LOG_WARNING, "The 'vismv' option is deprecated, "
839  "see the codecview filter instead.\n");
840 #endif
841 
842  if (av_codec_is_encoder(avctx->codec)) {
843  int i;
844 #if FF_API_CODED_FRAME
846  avctx->coded_frame = av_frame_alloc();
847  if (!avctx->coded_frame) {
848  ret = AVERROR(ENOMEM);
849  goto free_and_end;
850  }
852 #endif
853 
854  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
855  av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
856  ret = AVERROR(EINVAL);
857  goto free_and_end;
858  }
859 
860  if (avctx->codec->sample_fmts) {
861  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
862  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
863  break;
864  if (avctx->channels == 1 &&
867  avctx->sample_fmt = avctx->codec->sample_fmts[i];
868  break;
869  }
870  }
871  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
872  char buf[128];
873  snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
874  av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
875  (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
876  ret = AVERROR(EINVAL);
877  goto free_and_end;
878  }
879  }
880  if (avctx->codec->pix_fmts) {
881  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
882  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
883  break;
884  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
885  && !((avctx->codec_id == AV_CODEC_ID_MJPEG || avctx->codec_id == AV_CODEC_ID_LJPEG)
887  char buf[128];
888  snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
889  av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
890  (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
891  ret = AVERROR(EINVAL);
892  goto free_and_end;
893  }
894  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
895  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
896  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
897  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
898  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
899  avctx->color_range = AVCOL_RANGE_JPEG;
900  }
901  if (avctx->codec->supported_samplerates) {
902  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
903  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
904  break;
905  if (avctx->codec->supported_samplerates[i] == 0) {
906  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
907  avctx->sample_rate);
908  ret = AVERROR(EINVAL);
909  goto free_and_end;
910  }
911  }
912  if (avctx->sample_rate < 0) {
913  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
914  avctx->sample_rate);
915  ret = AVERROR(EINVAL);
916  goto free_and_end;
917  }
918  if (avctx->codec->channel_layouts) {
919  if (!avctx->channel_layout) {
920  av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
921  } else {
922  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
923  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
924  break;
925  if (avctx->codec->channel_layouts[i] == 0) {
926  char buf[512];
927  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
928  av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
929  ret = AVERROR(EINVAL);
930  goto free_and_end;
931  }
932  }
933  }
934  if (avctx->channel_layout && avctx->channels) {
935  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
936  if (channels != avctx->channels) {
937  char buf[512];
938  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
939  av_log(avctx, AV_LOG_ERROR,
940  "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
941  buf, channels, avctx->channels);
942  ret = AVERROR(EINVAL);
943  goto free_and_end;
944  }
945  } else if (avctx->channel_layout) {
947  }
948  if (avctx->channels < 0) {
949  av_log(avctx, AV_LOG_ERROR, "Specified number of channels %d is not supported\n",
950  avctx->channels);
951  ret = AVERROR(EINVAL);
952  goto free_and_end;
953  }
954  if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
955  pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
956  if ( avctx->bits_per_raw_sample < 0
957  || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) {
958  av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n",
959  avctx->bits_per_raw_sample, pixdesc->comp[0].depth);
960  avctx->bits_per_raw_sample = pixdesc->comp[0].depth;
961  }
962  if (avctx->width <= 0 || avctx->height <= 0) {
963  av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
964  ret = AVERROR(EINVAL);
965  goto free_and_end;
966  }
967  }
968  if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
969  && avctx->bit_rate>0 && avctx->bit_rate<1000) {
970  av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate);
971  }
972 
973  if (!avctx->rc_initial_buffer_occupancy)
974  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4;
975 
976  if (avctx->ticks_per_frame && avctx->time_base.num &&
977  avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
978  av_log(avctx, AV_LOG_ERROR,
979  "ticks_per_frame %d too large for the timebase %d/%d.",
980  avctx->ticks_per_frame,
981  avctx->time_base.num,
982  avctx->time_base.den);
983  goto free_and_end;
984  }
985 
986  if (avctx->hw_frames_ctx) {
987  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
988  if (frames_ctx->format != avctx->pix_fmt) {
989  av_log(avctx, AV_LOG_ERROR,
990  "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
991  ret = AVERROR(EINVAL);
992  goto free_and_end;
993  }
994  if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
995  avctx->sw_pix_fmt != frames_ctx->sw_format) {
996  av_log(avctx, AV_LOG_ERROR,
997  "Mismatching AVCodecContext.sw_pix_fmt (%s) "
998  "and AVHWFramesContext.sw_format (%s)\n",
1000  av_get_pix_fmt_name(frames_ctx->sw_format));
1001  ret = AVERROR(EINVAL);
1002  goto free_and_end;
1003  }
1004  avctx->sw_pix_fmt = frames_ctx->sw_format;
1005  }
1006  }
1007 
1009  avctx->pts_correction_num_faulty_dts = 0;
1010  avctx->pts_correction_last_pts =
1011  avctx->pts_correction_last_dts = INT64_MIN;
1012 
1013  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1015  av_log(avctx, AV_LOG_WARNING,
1016  "gray decoding requested but not enabled at configuration time\n");
1017 
1018  if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME)
1019  || avctx->internal->frame_thread_encoder)) {
1020  ret = avctx->codec->init(avctx);
1021  if (ret < 0) {
1022  goto free_and_end;
1023  }
1024  }
1025 
1026  ret=0;
1027 
1028 #if FF_API_AUDIOENC_DELAY
1029  if (av_codec_is_encoder(avctx->codec))
1030  avctx->delay = avctx->initial_padding;
1031 #endif
1032 
1033  if (av_codec_is_decoder(avctx->codec)) {
1034  if (!avctx->bit_rate)
1035  avctx->bit_rate = get_bit_rate(avctx);
1036  /* validate channel layout from the decoder */
1037  if (avctx->channel_layout) {
1038  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1039  if (!avctx->channels)
1040  avctx->channels = channels;
1041  else if (channels != avctx->channels) {
1042  char buf[512];
1043  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1044  av_log(avctx, AV_LOG_WARNING,
1045  "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1046  "ignoring specified channel layout\n",
1047  buf, channels, avctx->channels);
1048  avctx->channel_layout = 0;
1049  }
1050  }
1051  if (avctx->channels && avctx->channels < 0 ||
1052  avctx->channels > FF_SANE_NB_CHANNELS) {
1053  ret = AVERROR(EINVAL);
1054  goto free_and_end;
1055  }
1056  if (avctx->sub_charenc) {
1057  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1058  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1059  "supported with subtitles codecs\n");
1060  ret = AVERROR(EINVAL);
1061  goto free_and_end;
1062  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1063  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1064  "subtitles character encoding will be ignored\n",
1065  avctx->codec_descriptor->name);
1067  } else {
1068  /* input character encoding is set for a text based subtitle
1069  * codec at this point */
1072 
1074 #if CONFIG_ICONV
1075  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1076  if (cd == (iconv_t)-1) {
1077  ret = AVERROR(errno);
1078  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1079  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1080  goto free_and_end;
1081  }
1082  iconv_close(cd);
1083 #else
1084  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1085  "conversion needs a libavcodec built with iconv support "
1086  "for this codec\n");
1087  ret = AVERROR(ENOSYS);
1088  goto free_and_end;
1089 #endif
1090  }
1091  }
1092  }
1093 
1094 #if FF_API_AVCTX_TIMEBASE
1095  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
1096  avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
1097 #endif
1098  }
1099  if (codec->priv_data_size > 0 && avctx->priv_data && codec->priv_class) {
1100  av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
1101  }
1102 
1103 end:
1104  ff_unlock_avcodec(codec);
1105  if (options) {
1107  *options = tmp;
1108  }
1109 
1110  return ret;
1111 free_and_end:
1112  if (avctx->codec &&
1113  (avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))
1114  avctx->codec->close(avctx);
1115 
1116  if (codec->priv_class && codec->priv_data_size)
1117  av_opt_free(avctx->priv_data);
1118  av_opt_free(avctx);
1119 
1120 #if FF_API_CODED_FRAME
1122  av_frame_free(&avctx->coded_frame);
1124 #endif
1125 
1126  av_dict_free(&tmp);
1127  av_freep(&avctx->priv_data);
1128  if (avctx->internal) {
1129  av_frame_free(&avctx->internal->to_free);
1130  av_frame_free(&avctx->internal->compat_decode_frame);
1131  av_frame_free(&avctx->internal->buffer_frame);
1132  av_packet_free(&avctx->internal->buffer_pkt);
1133  av_packet_free(&avctx->internal->last_pkt_props);
1134 
1135  av_packet_free(&avctx->internal->ds.in_pkt);
1136 
1137  av_freep(&avctx->internal->pool);
1138  }
1139  av_freep(&avctx->internal);
1140  avctx->codec = NULL;
1141  goto end;
1142 }
1143 
1145 {
1146  int i;
1147 
1148  for (i = 0; i < sub->num_rects; i++) {
1149  av_freep(&sub->rects[i]->data[0]);
1150  av_freep(&sub->rects[i]->data[1]);
1151  av_freep(&sub->rects[i]->data[2]);
1152  av_freep(&sub->rects[i]->data[3]);
1153  av_freep(&sub->rects[i]->text);
1154  av_freep(&sub->rects[i]->ass);
1155  av_freep(&sub->rects[i]);
1156  }
1157 
1158  av_freep(&sub->rects);
1159 
1160  memset(sub, 0, sizeof(AVSubtitle));
1161 }
1162 
1164 {
1165  int i;
1166 
1167  if (!avctx)
1168  return 0;
1169 
1170  if (avcodec_is_open(avctx)) {
1171  FramePool *pool = avctx->internal->pool;
1172  if (CONFIG_FRAME_THREAD_ENCODER &&
1173  avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
1175  }
1176  if (HAVE_THREADS && avctx->internal->thread_ctx)
1177  ff_thread_free(avctx);
1178  if (avctx->codec && avctx->codec->close)
1179  avctx->codec->close(avctx);
1180  avctx->internal->byte_buffer_size = 0;
1181  av_freep(&avctx->internal->byte_buffer);
1182  av_frame_free(&avctx->internal->to_free);
1187 
1188  av_packet_free(&avctx->internal->ds.in_pkt);
1189 
1190  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
1191  av_buffer_pool_uninit(&pool->pools[i]);
1192  av_freep(&avctx->internal->pool);
1193 
1194  if (avctx->hwaccel && avctx->hwaccel->uninit)
1195  avctx->hwaccel->uninit(avctx);
1197 
1198  ff_decode_bsfs_uninit(avctx);
1199 
1200  av_freep(&avctx->internal);
1201  }
1202 
1203  for (i = 0; i < avctx->nb_coded_side_data; i++)
1204  av_freep(&avctx->coded_side_data[i].data);
1205  av_freep(&avctx->coded_side_data);
1206  avctx->nb_coded_side_data = 0;
1207 
1208  av_buffer_unref(&avctx->hw_frames_ctx);
1209  av_buffer_unref(&avctx->hw_device_ctx);
1210 
1211  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1212  av_opt_free(avctx->priv_data);
1213  av_opt_free(avctx);
1214  av_freep(&avctx->priv_data);
1215  if (av_codec_is_encoder(avctx->codec)) {
1216  av_freep(&avctx->extradata);
1217 #if FF_API_CODED_FRAME
1219  av_frame_free(&avctx->coded_frame);
1221 #endif
1222  }
1223  avctx->codec = NULL;
1224  avctx->active_thread_type = 0;
1225 
1226  return 0;
1227 }
1228 
1230 {
1231  switch(id){
1232  //This is for future deprecatec codec ids, its empty since
1233  //last major bump but will fill up again over time, please don't remove it
1234  default : return id;
1235  }
1236 }
1237 
1238 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1239 {
1240  AVCodec *p, *experimental = NULL;
1241  p = first_avcodec;
1242  id= remap_deprecated_codec_id(id);
1243  while (p) {
1244  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1245  p->id == id) {
1246  if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
1247  experimental = p;
1248  } else
1249  return p;
1250  }
1251  p = p->next;
1252  }
1253  return experimental;
1254 }
1255 
1257 {
1258  return find_encdec(id, 1);
1259 }
1260 
1262 {
1263  AVCodec *p;
1264  if (!name)
1265  return NULL;
1266  p = first_avcodec;
1267  while (p) {
1268  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
1269  return p;
1270  p = p->next;
1271  }
1272  return NULL;
1273 }
1274 
1276 {
1277  return find_encdec(id, 0);
1278 }
1279 
1281 {
1282  AVCodec *p;
1283  if (!name)
1284  return NULL;
1285  p = first_avcodec;
1286  while (p) {
1287  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
1288  return p;
1289  p = p->next;
1290  }
1291  return NULL;
1292 }
1293 
1294 const char *avcodec_get_name(enum AVCodecID id)
1295 {
1296  const AVCodecDescriptor *cd;
1297  AVCodec *codec;
1298 
1299  if (id == AV_CODEC_ID_NONE)
1300  return "none";
1301  cd = avcodec_descriptor_get(id);
1302  if (cd)
1303  return cd->name;
1304  av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
1305  codec = avcodec_find_decoder(id);
1306  if (codec)
1307  return codec->name;
1308  codec = avcodec_find_encoder(id);
1309  if (codec)
1310  return codec->name;
1311  return "unknown_codec";
1312 }
1313 
1314 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1315 {
1316  int i, len, ret = 0;
1317 
1318 #define TAG_PRINT(x) \
1319  (((x) >= '0' && (x) <= '9') || \
1320  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
1321  ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
1322 
1323  for (i = 0; i < 4; i++) {
1324  len = snprintf(buf, buf_size,
1325  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
1326  buf += len;
1327  buf_size = buf_size > len ? buf_size - len : 0;
1328  ret += len;
1329  codec_tag >>= 8;
1330  }
1331  return ret;
1332 }
1333 
1334 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1335 {
1336  const char *codec_type;
1337  const char *codec_name;
1338  const char *profile = NULL;
1339  int64_t bitrate;
1340  int new_line = 0;
1341  AVRational display_aspect_ratio;
1342  const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
1343 
1344  if (!buf || buf_size <= 0)
1345  return;
1346  codec_type = av_get_media_type_string(enc->codec_type);
1347  codec_name = avcodec_get_name(enc->codec_id);
1348  profile = avcodec_profile_name(enc->codec_id, enc->profile);
1349 
1350  snprintf(buf, buf_size, "%s: %s", codec_type ? codec_type : "unknown",
1351  codec_name);
1352  buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
1353 
1354  if (enc->codec && strcmp(enc->codec->name, codec_name))
1355  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", enc->codec->name);
1356 
1357  if (profile)
1358  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
1359  if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
1361  && enc->refs)
1362  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1363  ", %d reference frame%s",
1364  enc->refs, enc->refs > 1 ? "s" : "");
1365 
1366  if (enc->codec_tag)
1367  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s / 0x%04X)",
1368  av_fourcc2str(enc->codec_tag), enc->codec_tag);
1369 
1370  switch (enc->codec_type) {
1371  case AVMEDIA_TYPE_VIDEO:
1372  {
1373  char detail[256] = "(";
1374 
1375  av_strlcat(buf, separator, buf_size);
1376 
1377  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1378  "%s", enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
1380  if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE &&
1382  av_strlcatf(detail, sizeof(detail), "%d bpc, ", enc->bits_per_raw_sample);
1384  av_strlcatf(detail, sizeof(detail), "%s, ",
1386 
1387  if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
1389  enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
1390  if (enc->colorspace != (int)enc->color_primaries ||
1391  enc->colorspace != (int)enc->color_trc) {
1392  new_line = 1;
1393  av_strlcatf(detail, sizeof(detail), "%s/%s/%s, ",
1397  } else
1398  av_strlcatf(detail, sizeof(detail), "%s, ",
1400  }
1401 
1402  if (enc->field_order != AV_FIELD_UNKNOWN) {
1403  const char *field_order = "progressive";
1404  if (enc->field_order == AV_FIELD_TT)
1405  field_order = "top first";
1406  else if (enc->field_order == AV_FIELD_BB)
1407  field_order = "bottom first";
1408  else if (enc->field_order == AV_FIELD_TB)
1409  field_order = "top coded first (swapped)";
1410  else if (enc->field_order == AV_FIELD_BT)
1411  field_order = "bottom coded first (swapped)";
1412 
1413  av_strlcatf(detail, sizeof(detail), "%s, ", field_order);
1414  }
1415 
1416  if (av_log_get_level() >= AV_LOG_VERBOSE &&
1418  av_strlcatf(detail, sizeof(detail), "%s, ",
1420 
1421  if (strlen(detail) > 1) {
1422  detail[strlen(detail) - 2] = 0;
1423  av_strlcatf(buf, buf_size, "%s)", detail);
1424  }
1425  }
1426 
1427  if (enc->width) {
1428  av_strlcat(buf, new_line ? separator : ", ", buf_size);
1429 
1430  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1431  "%dx%d",
1432  enc->width, enc->height);
1433 
1434  if (av_log_get_level() >= AV_LOG_VERBOSE &&
1435  (enc->width != enc->coded_width ||
1436  enc->height != enc->coded_height))
1437  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1438  " (%dx%d)", enc->coded_width, enc->coded_height);
1439 
1440  if (enc->sample_aspect_ratio.num) {
1441  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1442  enc->width * (int64_t)enc->sample_aspect_ratio.num,
1443  enc->height * (int64_t)enc->sample_aspect_ratio.den,
1444  1024 * 1024);
1445  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1446  " [SAR %d:%d DAR %d:%d]",
1448  display_aspect_ratio.num, display_aspect_ratio.den);
1449  }
1450  if (av_log_get_level() >= AV_LOG_DEBUG) {
1451  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1452  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1453  ", %d/%d",
1454  enc->time_base.num / g, enc->time_base.den / g);
1455  }
1456  }
1457  if (encode) {
1458  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1459  ", q=%d-%d", enc->qmin, enc->qmax);
1460  } else {
1462  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1463  ", Closed Captions");
1465  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1466  ", lossless");
1467  }
1468  break;
1469  case AVMEDIA_TYPE_AUDIO:
1470  av_strlcat(buf, separator, buf_size);
1471 
1472  if (enc->sample_rate) {
1473  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1474  "%d Hz, ", enc->sample_rate);
1475  }
1476  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1477  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1478  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1479  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1480  }
1481  if ( enc->bits_per_raw_sample > 0
1483  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1484  " (%d bit)", enc->bits_per_raw_sample);
1485  if (av_log_get_level() >= AV_LOG_VERBOSE) {
1486  if (enc->initial_padding)
1487  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1488  ", delay %d", enc->initial_padding);
1489  if (enc->trailing_padding)
1490  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1491  ", padding %d", enc->trailing_padding);
1492  }
1493  break;
1494  case AVMEDIA_TYPE_DATA:
1495  if (av_log_get_level() >= AV_LOG_DEBUG) {
1496  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1497  if (g)
1498  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1499  ", %d/%d",
1500  enc->time_base.num / g, enc->time_base.den / g);
1501  }
1502  break;
1503  case AVMEDIA_TYPE_SUBTITLE:
1504  if (enc->width)
1505  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1506  ", %dx%d", enc->width, enc->height);
1507  break;
1508  default:
1509  return;
1510  }
1511  if (encode) {
1512  if (enc->flags & AV_CODEC_FLAG_PASS1)
1513  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1514  ", pass 1");
1515  if (enc->flags & AV_CODEC_FLAG_PASS2)
1516  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1517  ", pass 2");
1518  }
1519  bitrate = get_bit_rate(enc);
1520  if (bitrate != 0) {
1521  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1522  ", %"PRId64" kb/s", bitrate / 1000);
1523  } else if (enc->rc_max_rate > 0) {
1524  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1525  ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000);
1526  }
1527 }
1528 
1529 const char *av_get_profile_name(const AVCodec *codec, int profile)
1530 {
1531  const AVProfile *p;
1532  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1533  return NULL;
1534 
1535  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1536  if (p->profile == profile)
1537  return p->name;
1538 
1539  return NULL;
1540 }
1541 
1543 {
1544  const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
1545  const AVProfile *p;
1546 
1547  if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
1548  return NULL;
1549 
1550  for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1551  if (p->profile == profile)
1552  return p->name;
1553 
1554  return NULL;
1555 }
1556 
1557 unsigned avcodec_version(void)
1558 {
1559 // av_assert0(AV_CODEC_ID_V410==164);
1562 // av_assert0(AV_CODEC_ID_BMV_AUDIO==86071);
1563  av_assert0(AV_CODEC_ID_SRT==94216);
1565 
1566  return LIBAVCODEC_VERSION_INT;
1567 }
1568 
1569 const char *avcodec_configuration(void)
1570 {
1571  return FFMPEG_CONFIGURATION;
1572 }
1573 
1574 const char *avcodec_license(void)
1575 {
1576 #define LICENSE_PREFIX "libavcodec license: "
1577  return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1578 }
1579 
1581 {
1582  switch (codec_id) {
1583  case AV_CODEC_ID_8SVX_EXP:
1584  case AV_CODEC_ID_8SVX_FIB:
1585  case AV_CODEC_ID_ADPCM_CT:
1593  return 4;
1594  case AV_CODEC_ID_DSD_LSBF:
1595  case AV_CODEC_ID_DSD_MSBF:
1598  case AV_CODEC_ID_PCM_ALAW:
1599  case AV_CODEC_ID_PCM_MULAW:
1600  case AV_CODEC_ID_PCM_S8:
1602  case AV_CODEC_ID_PCM_U8:
1603  case AV_CODEC_ID_PCM_ZORK:
1604  case AV_CODEC_ID_SDX2_DPCM:
1605  return 8;
1606  case AV_CODEC_ID_PCM_S16BE:
1608  case AV_CODEC_ID_PCM_S16LE:
1610  case AV_CODEC_ID_PCM_U16BE:
1611  case AV_CODEC_ID_PCM_U16LE:
1612  return 16;
1614  case AV_CODEC_ID_PCM_S24BE:
1615  case AV_CODEC_ID_PCM_S24LE:
1617  case AV_CODEC_ID_PCM_U24BE:
1618  case AV_CODEC_ID_PCM_U24LE:
1619  return 24;
1620  case AV_CODEC_ID_PCM_S32BE:
1621  case AV_CODEC_ID_PCM_S32LE:
1623  case AV_CODEC_ID_PCM_U32BE:
1624  case AV_CODEC_ID_PCM_U32LE:
1625  case AV_CODEC_ID_PCM_F32BE:
1626  case AV_CODEC_ID_PCM_F32LE:
1627  case AV_CODEC_ID_PCM_F24LE:
1628  case AV_CODEC_ID_PCM_F16LE:
1629  return 32;
1630  case AV_CODEC_ID_PCM_F64BE:
1631  case AV_CODEC_ID_PCM_F64LE:
1632  case AV_CODEC_ID_PCM_S64BE:
1633  case AV_CODEC_ID_PCM_S64LE:
1634  return 64;
1635  default:
1636  return 0;
1637  }
1638 }
1639 
1641 {
1642  static const enum AVCodecID map[AV_SAMPLE_FMT_NB][2] = {
1654  };
1655  if (fmt < 0 || fmt >= AV_SAMPLE_FMT_NB)
1656  return AV_CODEC_ID_NONE;
1657  if (be < 0 || be > 1)
1658  be = AV_NE(1, 0);
1659  return map[fmt][be];
1660 }
1661 
1663 {
1664  switch (codec_id) {
1666  return 2;
1668  return 3;
1672  case AV_CODEC_ID_ADPCM_SWF:
1673  case AV_CODEC_ID_ADPCM_MS:
1674  return 4;
1675  default:
1676  return av_get_exact_bits_per_sample(codec_id);
1677  }
1678 }
1679 
1680 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
1681  uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
1682  uint8_t * extradata, int frame_size, int frame_bytes)
1683 {
1685  int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
1686 
1687  /* codecs with an exact constant bits per sample */
1688  if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
1689  return (frame_bytes * 8LL) / (bps * ch);
1690  bps = bits_per_coded_sample;
1691 
1692  /* codecs with a fixed packet duration */
1693  switch (id) {
1694  case AV_CODEC_ID_ADPCM_ADX: return 32;
1695  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
1696  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
1697  case AV_CODEC_ID_AMR_NB:
1698  case AV_CODEC_ID_EVRC:
1699  case AV_CODEC_ID_GSM:
1700  case AV_CODEC_ID_QCELP:
1701  case AV_CODEC_ID_RA_288: return 160;
1702  case AV_CODEC_ID_AMR_WB:
1703  case AV_CODEC_ID_GSM_MS: return 320;
1704  case AV_CODEC_ID_MP1: return 384;
1705  case AV_CODEC_ID_ATRAC1: return 512;
1706  case AV_CODEC_ID_ATRAC3: return 1024 * framecount;
1707  case AV_CODEC_ID_ATRAC3P: return 2048;
1708  case AV_CODEC_ID_MP2:
1709  case AV_CODEC_ID_MUSEPACK7: return 1152;
1710  case AV_CODEC_ID_AC3: return 1536;
1711  }
1712 
1713  if (sr > 0) {
1714  /* calc from sample rate */
1715  if (id == AV_CODEC_ID_TTA)
1716  return 256 * sr / 245;
1717  else if (id == AV_CODEC_ID_DST)
1718  return 588 * sr / 44100;
1719 
1720  if (ch > 0) {
1721  /* calc from sample rate and channels */
1722  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
1723  return (480 << (sr / 22050)) / ch;
1724  }
1725 
1726  if (id == AV_CODEC_ID_MP3)
1727  return sr <= 24000 ? 576 : 1152;
1728  }
1729 
1730  if (ba > 0) {
1731  /* calc from block_align */
1732  if (id == AV_CODEC_ID_SIPR) {
1733  switch (ba) {
1734  case 20: return 160;
1735  case 19: return 144;
1736  case 29: return 288;
1737  case 37: return 480;
1738  }
1739  } else if (id == AV_CODEC_ID_ILBC) {
1740  switch (ba) {
1741  case 38: return 160;
1742  case 50: return 240;
1743  }
1744  }
1745  }
1746 
1747  if (frame_bytes > 0) {
1748  /* calc from frame_bytes only */
1749  if (id == AV_CODEC_ID_TRUESPEECH)
1750  return 240 * (frame_bytes / 32);
1751  if (id == AV_CODEC_ID_NELLYMOSER)
1752  return 256 * (frame_bytes / 64);
1753  if (id == AV_CODEC_ID_RA_144)
1754  return 160 * (frame_bytes / 20);
1755  if (id == AV_CODEC_ID_G723_1)
1756  return 240 * (frame_bytes / 24);
1757 
1758  if (bps > 0) {
1759  /* calc from frame_bytes and bits_per_coded_sample */
1761  return frame_bytes * 8 / bps;
1762  }
1763 
1764  if (ch > 0 && ch < INT_MAX/16) {
1765  /* calc from frame_bytes and channels */
1766  switch (id) {
1767  case AV_CODEC_ID_ADPCM_AFC:
1768  return frame_bytes / (9 * ch) * 16;
1769  case AV_CODEC_ID_ADPCM_PSX:
1770  case AV_CODEC_ID_ADPCM_DTK:
1771  return frame_bytes / (16 * ch) * 28;
1772  case AV_CODEC_ID_ADPCM_4XM:
1775  return (frame_bytes - 4 * ch) * 2 / ch;
1777  return (frame_bytes - 4) * 2 / ch;
1779  return (frame_bytes - 8) * 2 / ch;
1780  case AV_CODEC_ID_ADPCM_THP:
1782  if (extradata)
1783  return frame_bytes * 14 / (8 * ch);
1784  break;
1785  case AV_CODEC_ID_ADPCM_XA:
1786  return (frame_bytes / 128) * 224 / ch;
1788  return (frame_bytes - 6 - ch) / ch;
1789  case AV_CODEC_ID_ROQ_DPCM:
1790  return (frame_bytes - 8) / ch;
1791  case AV_CODEC_ID_XAN_DPCM:
1792  return (frame_bytes - 2 * ch) / ch;
1793  case AV_CODEC_ID_MACE3:
1794  return 3 * frame_bytes / ch;
1795  case AV_CODEC_ID_MACE6:
1796  return 6 * frame_bytes / ch;
1797  case AV_CODEC_ID_PCM_LXF:
1798  return 2 * (frame_bytes / (5 * ch));
1799  case AV_CODEC_ID_IAC:
1800  case AV_CODEC_ID_IMC:
1801  return 4 * frame_bytes / ch;
1802  }
1803 
1804  if (tag) {
1805  /* calc from frame_bytes, channels, and codec_tag */
1806  if (id == AV_CODEC_ID_SOL_DPCM) {
1807  if (tag == 3)
1808  return frame_bytes / ch;
1809  else
1810  return frame_bytes * 2 / ch;
1811  }
1812  }
1813 
1814  if (ba > 0) {
1815  /* calc from frame_bytes, channels, and block_align */
1816  int blocks = frame_bytes / ba;
1817  switch (id) {
1819  if (bps < 2 || bps > 5)
1820  return 0;
1821  return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
1823  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
1825  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
1827  return blocks * ((ba - 4 * ch) * 2 / ch);
1828  case AV_CODEC_ID_ADPCM_MS:
1829  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
1831  return blocks * (ba - 16) * 2 / ch;
1832  }
1833  }
1834 
1835  if (bps > 0) {
1836  /* calc from frame_bytes, channels, and bits_per_coded_sample */
1837  switch (id) {
1838  case AV_CODEC_ID_PCM_DVD:
1839  if(bps<4)
1840  return 0;
1841  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
1843  if(bps<4)
1844  return 0;
1845  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
1846  case AV_CODEC_ID_S302M:
1847  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
1848  }
1849  }
1850  }
1851  }
1852 
1853  /* Fall back on using frame_size */
1854  if (frame_size > 1 && frame_bytes)
1855  return frame_size;
1856 
1857  //For WMA we currently have no other means to calculate duration thus we
1858  //do it here by assuming CBR, which is true for all known cases.
1859  if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
1860  if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
1861  return (frame_bytes * 8LL * sr) / bitrate;
1862  }
1863 
1864  return 0;
1865 }
1866 
1867 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
1868 {
1869  return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
1870  avctx->channels, avctx->block_align,
1871  avctx->codec_tag, avctx->bits_per_coded_sample,
1872  avctx->bit_rate, avctx->extradata, avctx->frame_size,
1873  frame_bytes);
1874 }
1875 
1877 {
1878  return get_audio_frame_duration(par->codec_id, par->sample_rate,
1879  par->channels, par->block_align,
1880  par->codec_tag, par->bits_per_coded_sample,
1881  par->bit_rate, par->extradata, par->frame_size,
1882  frame_bytes);
1883 }
1884 
1885 #if !HAVE_THREADS
1887 {
1888  return -1;
1889 }
1890 
1891 #endif
1892 
1893 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1894 {
1895  unsigned int n = 0;
1896 
1897  while (v >= 0xff) {
1898  *s++ = 0xff;
1899  v -= 0xff;
1900  n++;
1901  }
1902  *s = v;
1903  n++;
1904  return n;
1905 }
1906 
1907 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
1908 {
1909  int i;
1910  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
1911  return i;
1912 }
1913 
1914 #if FF_API_MISSING_SAMPLE
1916 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
1917 {
1918  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your FFmpeg "
1919  "version to the newest one from Git. If the problem still "
1920  "occurs, it means that your file has a feature which has not "
1921  "been implemented.\n", feature);
1922  if(want_sample)
1924 }
1925 
1926 void av_log_ask_for_sample(void *avc, const char *msg, ...)
1927 {
1928  va_list argument_list;
1929 
1930  va_start(argument_list, msg);
1931 
1932  if (msg)
1933  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
1934  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
1935  "of this file to ftp://upload.ffmpeg.org/incoming/ "
1936  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
1937 
1938  va_end(argument_list);
1939 }
1941 #endif /* FF_API_MISSING_SAMPLE */
1942 
1945 
1947 {
1948  AVHWAccel **p = last_hwaccel;
1949  hwaccel->next = NULL;
1950  while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
1951  p = &(*p)->next;
1952  last_hwaccel = &hwaccel->next;
1953 }
1954 
1956 {
1957  return hwaccel ? hwaccel->next : first_hwaccel;
1958 }
1959 
1960 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1961 {
1962  if (lockmgr_cb) {
1963  // There is no good way to rollback a failure to destroy the
1964  // mutex, so we ignore failures.
1967  lockmgr_cb = NULL;
1968  codec_mutex = NULL;
1969  avformat_mutex = NULL;
1970  }
1971 
1972  if (cb) {
1973  void *new_codec_mutex = NULL;
1974  void *new_avformat_mutex = NULL;
1975  int err;
1976  if (err = cb(&new_codec_mutex, AV_LOCK_CREATE)) {
1977  return err > 0 ? AVERROR_UNKNOWN : err;
1978  }
1979  if (err = cb(&new_avformat_mutex, AV_LOCK_CREATE)) {
1980  // Ignore failures to destroy the newly created mutex.
1981  cb(&new_codec_mutex, AV_LOCK_DESTROY);
1982  return err > 0 ? AVERROR_UNKNOWN : err;
1983  }
1984  lockmgr_cb = cb;
1985  codec_mutex = new_codec_mutex;
1986  avformat_mutex = new_avformat_mutex;
1987  }
1988 
1989  return 0;
1990 }
1991 
1992 int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
1993 {
1994  if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
1995  return 0;
1996 
1997  if (lockmgr_cb) {
1999  return -1;
2000  }
2001 
2003  av_log(log_ctx, AV_LOG_ERROR,
2004  "Insufficient thread locking. At least %d threads are "
2005  "calling avcodec_open2() at the same time right now.\n",
2007  if (!lockmgr_cb)
2008  av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n");
2009  ff_avcodec_locked = 1;
2010  ff_unlock_avcodec(codec);
2011  return AVERROR(EINVAL);
2012  }
2014  ff_avcodec_locked = 1;
2015  return 0;
2016 }
2017 
2018 int ff_unlock_avcodec(const AVCodec *codec)
2019 {
2020  if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
2021  return 0;
2022 
2024  ff_avcodec_locked = 0;
2026  if (lockmgr_cb) {
2028  return -1;
2029  }
2030 
2031  return 0;
2032 }
2033 
2035 {
2036  if (lockmgr_cb) {
2038  return -1;
2039  }
2040  return 0;
2041 }
2042 
2044 {
2045  if (lockmgr_cb) {
2047  return -1;
2048  }
2049  return 0;
2050 }
2051 
2052 unsigned int avpriv_toupper4(unsigned int x)
2053 {
2054  return av_toupper(x & 0xFF) +
2055  (av_toupper((x >> 8) & 0xFF) << 8) +
2056  (av_toupper((x >> 16) & 0xFF) << 16) +
2057 ((unsigned)av_toupper((x >> 24) & 0xFF) << 24);
2058 }
2059 
2061 {
2062  int ret;
2063 
2064  dst->owner[0] = src->owner[0];
2065  dst->owner[1] = src->owner[1];
2066 
2067  ret = av_frame_ref(dst->f, src->f);
2068  if (ret < 0)
2069  return ret;
2070 
2071  av_assert0(!dst->progress);
2072 
2073  if (src->progress &&
2074  !(dst->progress = av_buffer_ref(src->progress))) {
2075  ff_thread_release_buffer(dst->owner[0], dst);
2076  return AVERROR(ENOMEM);
2077  }
2078 
2079  return 0;
2080 }
2081 
2082 #if !HAVE_THREADS
2083 
2085 {
2086  return ff_get_format(avctx, fmt);
2087 }
2088 
2090 {
2091  f->owner[0] = f->owner[1] = avctx;
2092  return ff_get_buffer(avctx, f->f, flags);
2093 }
2094 
2096 {
2097  if (f->f)
2098  av_frame_unref(f->f);
2099 }
2100 
2102 {
2103 }
2104 
2105 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
2106 {
2107 }
2108 
2109 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
2110 {
2111 }
2112 
2114 {
2115  return 1;
2116 }
2117 
2119 {
2120  return 0;
2121 }
2122 
2124 {
2125 }
2126 
2127 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
2128 {
2129 }
2130 
2131 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
2132 {
2133 }
2134 
2135 #endif
2136 
2138 {
2139  return !!s->internal;
2140 }
2141 
2142 int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
2143 {
2144  int ret;
2145  char *str;
2146 
2147  ret = av_bprint_finalize(buf, &str);
2148  if (ret < 0)
2149  return ret;
2150  if (!av_bprint_is_complete(buf)) {
2151  av_free(str);
2152  return AVERROR(ENOMEM);
2153  }
2154 
2155  avctx->extradata = str;
2156  /* Note: the string is NUL terminated (so extradata can be read as a
2157  * string), but the ending character is not accounted in the size (in
2158  * binary formats you are likely not supposed to mux that character). When
2159  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
2160  * zeros. */
2161  avctx->extradata_size = buf->len;
2162  return 0;
2163 }
2164 
2165 const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
2166  const uint8_t *end,
2167  uint32_t *av_restrict state)
2168 {
2169  int i;
2170 
2171  av_assert0(p <= end);
2172  if (p >= end)
2173  return end;
2174 
2175  for (i = 0; i < 3; i++) {
2176  uint32_t tmp = *state << 8;
2177  *state = tmp + *(p++);
2178  if (tmp == 0x100 || p == end)
2179  return p;
2180  }
2181 
2182  while (p < end) {
2183  if (p[-1] > 1 ) p += 3;
2184  else if (p[-2] ) p += 2;
2185  else if (p[-3]|(p[-1]-1)) p++;
2186  else {
2187  p++;
2188  break;
2189  }
2190  }
2191 
2192  p = FFMIN(p, end) - 4;
2193  *state = AV_RB32(p);
2194 
2195  return p + 4;
2196 }
2197 
2199 {
2200  AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
2201  if (!props)
2202  return NULL;
2203 
2204  if (size)
2205  *size = sizeof(*props);
2206 
2207  props->vbv_delay = UINT64_MAX;
2208 
2209  return props;
2210 }
2211 
2213 {
2215  AVCPBProperties *props;
2216  size_t size;
2217 
2218  props = av_cpb_properties_alloc(&size);
2219  if (!props)
2220  return NULL;
2221 
2222  tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
2223  if (!tmp) {
2224  av_freep(&props);
2225  return NULL;
2226  }
2227 
2228  avctx->coded_side_data = tmp;
2229  avctx->nb_coded_side_data++;
2230 
2232  avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
2233  avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
2234 
2235  return props;
2236 }
2237 
2239 {
2240  av_freep(&par->extradata);
2241 
2242  memset(par, 0, sizeof(*par));
2243 
2245  par->codec_id = AV_CODEC_ID_NONE;
2246  par->format = -1;
2253  par->sample_aspect_ratio = (AVRational){ 0, 1 };
2254  par->profile = FF_PROFILE_UNKNOWN;
2255  par->level = FF_LEVEL_UNKNOWN;
2256 }
2257 
2259 {
2260  AVCodecParameters *par = av_mallocz(sizeof(*par));
2261 
2262  if (!par)
2263  return NULL;
2265  return par;
2266 }
2267 
2269 {
2270  AVCodecParameters *par = *ppar;
2271 
2272  if (!par)
2273  return;
2275 
2276  av_freep(ppar);
2277 }
2278 
2280 {
2282  memcpy(dst, src, sizeof(*dst));
2283 
2284  dst->extradata = NULL;
2285  dst->extradata_size = 0;
2286  if (src->extradata) {
2288  if (!dst->extradata)
2289  return AVERROR(ENOMEM);
2290  memcpy(dst->extradata, src->extradata, src->extradata_size);
2291  dst->extradata_size = src->extradata_size;
2292  }
2293 
2294  return 0;
2295 }
2296 
2298  const AVCodecContext *codec)
2299 {
2301 
2302  par->codec_type = codec->codec_type;
2303  par->codec_id = codec->codec_id;
2304  par->codec_tag = codec->codec_tag;
2305 
2306  par->bit_rate = codec->bit_rate;
2309  par->profile = codec->profile;
2310  par->level = codec->level;
2311 
2312  switch (par->codec_type) {
2313  case AVMEDIA_TYPE_VIDEO:
2314  par->format = codec->pix_fmt;
2315  par->width = codec->width;
2316  par->height = codec->height;
2317  par->field_order = codec->field_order;
2318  par->color_range = codec->color_range;
2319  par->color_primaries = codec->color_primaries;
2320  par->color_trc = codec->color_trc;
2321  par->color_space = codec->colorspace;
2324  par->video_delay = codec->has_b_frames;
2325  break;
2326  case AVMEDIA_TYPE_AUDIO:
2327  par->format = codec->sample_fmt;
2328  par->channel_layout = codec->channel_layout;
2329  par->channels = codec->channels;
2330  par->sample_rate = codec->sample_rate;
2331  par->block_align = codec->block_align;
2332  par->frame_size = codec->frame_size;
2333  par->initial_padding = codec->initial_padding;
2334  par->trailing_padding = codec->trailing_padding;
2335  par->seek_preroll = codec->seek_preroll;
2336  break;
2337  case AVMEDIA_TYPE_SUBTITLE:
2338  par->width = codec->width;
2339  par->height = codec->height;
2340  break;
2341  }
2342 
2343  if (codec->extradata) {
2345  if (!par->extradata)
2346  return AVERROR(ENOMEM);
2347  memcpy(par->extradata, codec->extradata, codec->extradata_size);
2348  par->extradata_size = codec->extradata_size;
2349  }
2350 
2351  return 0;
2352 }
2353 
2355  const AVCodecParameters *par)
2356 {
2357  codec->codec_type = par->codec_type;
2358  codec->codec_id = par->codec_id;
2359  codec->codec_tag = par->codec_tag;
2360 
2361  codec->bit_rate = par->bit_rate;
2364  codec->profile = par->profile;
2365  codec->level = par->level;
2366 
2367  switch (par->codec_type) {
2368  case AVMEDIA_TYPE_VIDEO:
2369  codec->pix_fmt = par->format;
2370  codec->width = par->width;
2371  codec->height = par->height;
2372  codec->field_order = par->field_order;
2373  codec->color_range = par->color_range;
2374  codec->color_primaries = par->color_primaries;
2375  codec->color_trc = par->color_trc;
2376  codec->colorspace = par->color_space;
2379  codec->has_b_frames = par->video_delay;
2380  break;
2381  case AVMEDIA_TYPE_AUDIO:
2382  codec->sample_fmt = par->format;
2383  codec->channel_layout = par->channel_layout;
2384  codec->channels = par->channels;
2385  codec->sample_rate = par->sample_rate;
2386  codec->block_align = par->block_align;
2387  codec->frame_size = par->frame_size;
2388  codec->delay =
2389  codec->initial_padding = par->initial_padding;
2390  codec->trailing_padding = par->trailing_padding;
2391  codec->seek_preroll = par->seek_preroll;
2392  break;
2393  case AVMEDIA_TYPE_SUBTITLE:
2394  codec->width = par->width;
2395  codec->height = par->height;
2396  break;
2397  }
2398 
2399  if (par->extradata) {
2400  av_freep(&codec->extradata);
2402  if (!codec->extradata)
2403  return AVERROR(ENOMEM);
2404  memcpy(codec->extradata, par->extradata, par->extradata_size);
2405  codec->extradata_size = par->extradata_size;
2406  }
2407 
2408  return 0;
2409 }
2410 
2411 int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
2412  void **data, size_t *sei_size)
2413 {
2414  AVFrameSideData *side_data = NULL;
2415  uint8_t *sei_data;
2416 
2417  if (frame)
2418  side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
2419 
2420  if (!side_data) {
2421  *data = NULL;
2422  return 0;
2423  }
2424 
2425  *sei_size = side_data->size + 11;
2426  *data = av_mallocz(*sei_size + prefix_len);
2427  if (!*data)
2428  return AVERROR(ENOMEM);
2429  sei_data = (uint8_t*)*data + prefix_len;
2430 
2431  // country code
2432  sei_data[0] = 181;
2433  sei_data[1] = 0;
2434  sei_data[2] = 49;
2435 
2436  /**
2437  * 'GA94' is standard in North America for ATSC, but hard coding
2438  * this style may not be the right thing to do -- other formats
2439  * do exist. This information is not available in the side_data
2440  * so we are going with this right now.
2441  */
2442  AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4'));
2443  sei_data[7] = 3;
2444  sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40;
2445  sei_data[9] = 0;
2446 
2447  memcpy(sei_data + 10, side_data->data, side_data->size);
2448 
2449  sei_data[side_data->size+10] = 255;
2450 
2451  return 0;
2452 }
2453 
2455 {
2456  AVRational framerate = avctx->framerate;
2457  int bits_per_coded_sample = avctx->bits_per_coded_sample;
2458  int64_t bitrate;
2459 
2460  if (!(framerate.num && framerate.den))
2461  framerate = av_inv_q(avctx->time_base);
2462  if (!(framerate.num && framerate.den))
2463  return 0;
2464 
2465  if (!bits_per_coded_sample) {
2467  bits_per_coded_sample = av_get_bits_per_pixel(desc);
2468  }
2469  bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
2470  framerate.num / framerate.den;
2471 
2472  return bitrate;
2473 }
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:2454
#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:90
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2986
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:82
enum AVChromaLocation chroma_location
Definition: avcodec.h:4242
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:3518
#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:1184
const struct AVCodec * codec
Definition: avcodec.h:1770
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:177
AVRational framerate
Definition: avcodec.h:3460
#define avpriv_atomic_int_add_and_fetch
Definition: atomic_gcc.h:42
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:4233
static int64_t get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:592
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:3481
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:1238
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:289
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:266
uint32_t fourcc
Definition: hwcontext_qsv.c:90
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:4240
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:259
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:3517
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: avcodec.h:3498
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:35
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2419
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:1256
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:263
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:170
static struct @260 state
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1963
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:1960
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
Definition: internal.h:174
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:6334
#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:1826
AVFrame * to_free
Definition: internal.h:161
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:60
#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:173
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:2371
AVRational sample_aspect_ratio
Video only.
Definition: avcodec.h:4228
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2801
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:264
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:1569
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2498
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:4152
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int ff_unlock_avcodec(const AVCodec *codec)
Definition: utils.c:2018
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:3516
const char * b
Definition: vf_curves.c:113
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:1574
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:2172
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:201
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:1989
enum AVPixelFormat pix_fmt
Definition: raw.h:34
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:206
unsigned num_rects
Definition: avcodec.h:4132
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
Definition: utils.c:588
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:121
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:269
The following 12 formats have the disadvantage of needing 1 format for each bit depth.
Definition: pixfmt.h:167
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1057
mpegvideo header.
enum AVMediaType type
Definition: avcodec.h:3752
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:107
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3822
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3164
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: utils.c:2084
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: utils.c:453
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:1077
int trailing_padding
Audio only.
Definition: avcodec.h:4288
#define src
Definition: vp8dsp.c:254
int profile
profile
Definition: avcodec.h:3266
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:268
AVCodec.
Definition: avcodec.h:3739
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:139
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2560
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:4144
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:6331
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:211
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:4116
enum AVColorSpace color_space
Definition: avcodec.h:4241
unsigned avcodec_get_edge_width(void)
Return the amount of padding in pixels which the get_buffer callback must provide around the edge of ...
Definition: utils.c:195
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2803
Macro definitions for various function/variable attributes.
FF_DISABLE_DEPRECATION_WARNINGS void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
Definition: utils.c:1916
static void * codec_mutex
Definition: utils.c:118
void ff_decode_bsfs_uninit(AVCodecContext *avctx)
Definition: decode.c:1752
int frame_size
Audio only.
Definition: avcodec.h:4273
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1898
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:682
AVSubtitleRect ** rects
Definition: avcodec.h:4133
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:174
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
Definition: utils.c:2127
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:476
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:169
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:1384
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian ...
Definition: pixfmt.h:191
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:438
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:3365
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:3082
static int volatile entangled_thread_counter
Definition: utils.c:117
#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:230
Public dictionary API.
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:202
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:102
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:2531
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
Lock the mutex.
Definition: avcodec.h:6333
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:4218
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:2258
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:2746
void * thread_ctx
Definition: internal.h:165
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static AVCodec * first_avcodec
Definition: utils.c:146
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
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:241
int trailing_padding
Audio only.
Definition: avcodec.h:3638
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:395
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:265
#define emms_c()
Definition: internal.h:54
#define FF_CODEC_PROPERTY_LOSSLESS
Definition: avcodec.h:3582
#define LIBAVCODEC_VERSION_INT
Definition: version.h:34
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1876
#define LICENSE_PREFIX
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:2354
static AVFrame * frame
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:203
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
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:2212
Public header for CRC hash function implementation.
void * frame_thread_encoder
Definition: internal.h:182
int initial_padding
Audio only.
Definition: avcodec.h:4281
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:286
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:615
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:290
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:186
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
static int(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:112
static int flags
Definition: log.c:57
uint32_t tag
Definition: movenc.c:1409
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:206
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
uint8_t * data
Definition: avcodec.h:1623
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:1680
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:3172
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:1907
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:3157
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:292
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:226
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:904
signed 32 bits
Definition: samplefmt.h:62
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:184
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
Definition: utils.c:2198
const OptionDef options[]
Definition: ffserver.c:3948
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:2505
static void codec_parameters_reset(AVCodecParameters *par)
Definition: utils.c:2238
#define FFALIGN(x, a)
Definition: macros.h:48
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4254
#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:163
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:4181
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: avcodec.h:2985
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:1261
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:261
static av_cold void avcodec_init(void)
Definition: utils.c:157
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
#define EDGE_WIDTH
Definition: mpegpicture.h:33
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:168
int(* send_frame)(AVCodecContext *avctx, const AVFrame *frame)
Encode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3832
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:202
Libavcodec version macros.
int(* close)(AVCodecContext *)
Definition: avcodec.h:3823
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:1163
enum AVCodecID id
Definition: avcodec.h:3753
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:3763
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:182
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:176
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition: pixdesc.c:2822
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:214
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:2279
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:2083
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1662
#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:6332
#define MAKE_ACCESSORS(str, name, type, field)
Definition: internal.h:90
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:144
#define AVERROR(e)
Definition: error.h:43
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2052
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:2712
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:149
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:3499
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:3211
enum AVColorPrimaries color_primaries
Definition: avcodec.h:4239
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2137
int video_delay
Video only.
Definition: avcodec.h:4247
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:204
int capabilities
Codec capabilities.
Definition: avcodec.h:3758
int initial_padding
Audio only.
Definition: avcodec.h:3451
#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:1886
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:557
#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:194
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:4148
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:172
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1856
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:262
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:1625
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:3746
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:142
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:3646
const struct AVProfile * profiles
If non-NULL, an array of profiles recognized for this codec.
Definition: avcodec.h:730
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:195
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:2268
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:1876
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
const char av_codec_ffversion[]
Definition: utils.c:66
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:2765
reference-counted frame API
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3121
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2574
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:4170
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:196
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:2739
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:719
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:3808
static AVCodec ** last_avcodec
Definition: utils.c:147
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:260
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
int refs
number of reference frames
Definition: avcodec.h:2442
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:301
int block_align
Audio only.
Definition: avcodec.h:4269
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:3760
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3203
#define FFMIN(a, b)
Definition: common.h:96
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:3591
Raw Video Codec.
signed 32 bits, planar
Definition: samplefmt.h:68
volatile int ff_avcodec_locked
Definition: utils.c:116
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:1580
AVFrame * compat_decode_frame
Definition: internal.h:215
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
Definition: utils.c:2131
int width
picture width / height.
Definition: avcodec.h:1948
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3616
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:3267
int priv_data_size
Definition: avcodec.h:3775
int profile
Definition: avcodec.h:3728
AVPacket * in_pkt
Definition: internal.h:122
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:892
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2477
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:200
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:222
int level
level
Definition: avcodec.h:3364
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:2101
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:192
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:3766
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:1907
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:257
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:169
enum AVCodecID codec_id
Definition: vaapi_decode.c:235
enum AVColorRange color_range
Video only.
Definition: avcodec.h:4238
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:1926
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:167
static pthread_mutex_t * mutex
Definition: w32pthreads.h:258
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
Definition: utils.c:561
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:3507
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:178
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:4111
#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:1294
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:3192
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:510
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:3515
int av_codec_get_max_lowres(const AVCodec *codec)
Definition: utils.c:583
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:302
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:1529
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2543
#define attribute_align_arg
Definition: internal.h:61
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1354
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:84
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:140
int frame_size
Definition: mxfenc.c:1896
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1769
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:3805
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:1640
enum AVCodecID codec_id
Definition: avcodec.h:1778
int seek_preroll
Number of samples to skip after a discontinuity.
Definition: avcodec.h:3539
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:2523
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:189
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:184
main external API structure.
Definition: avcodec.h:1761
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:1275
int skip_samples_multiplier
Definition: internal.h:219
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:204
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2705
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1144
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1793
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:1669
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:291
#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:762
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:271
void * buf
Definition: avisynth_c.h:690
int extradata_size
Definition: avcodec.h:1877
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1893
struct AVCodec * next
Definition: avcodec.h:3776
int nb_coded_side_data
Definition: avcodec.h:3592
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:205
AVCodecContext * owner[2]
Definition: thread.h:37
int coded_height
Definition: avcodec.h:1963
Describe the class of an AVClass context structure.
Definition: log.h:67
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:3583
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:207
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:674
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:98
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:2491
Rational number (pair of numerator and denominator).
Definition: rational.h:58
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2484
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:2095
const char * name
short name for the profile
Definition: avcodec.h:3729
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:2297
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:121
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:258
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level...
Definition: log.c:379
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:270
static FF_ENABLE_DEPRECATION_WARNINGS AVHWAccel * first_hwaccel
Definition: utils.c:1943
char * codec_whitelist
',' separated list of allowed decoders.
Definition: avcodec.h:3574
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:190
const VDPAUPixFmtMap * map
#define STRIDE_ALIGN
Definition: internal.h:99
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:711
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:627
#define snprintf
Definition: snprintf.h:34
static AVHWAccel ** last_hwaccel
Definition: utils.c:1944
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:1867
static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
Definition: utils.c:1229
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
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:1955
int seek_preroll
Audio only.
Definition: avcodec.h:4292
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:703
int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:2142
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:505
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:79
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:199
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:1280
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: avcodec.h:4207
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3765
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:174
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:143
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:512
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:4262
enum AVMediaType type
Definition: avcodec.h:705
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: avcodec.h:3764
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:202
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:261
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:83
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:465
Free mutex resources.
Definition: avcodec.h:6335
if(ret< 0)
Definition: vf_mcdeint.c:279
int avpriv_lock_avformat(void)
Definition: utils.c:2034
#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
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:1946
struct AVHWAccel * next
Definition: avcodec.h:3909
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
signed 16 bits
Definition: samplefmt.h:61
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:183
static double c[64]
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:4212
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:2784
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: avcodec.h:3992
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:192
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:133
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AVProfile.
Definition: avcodec.h:3727
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:141
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:2113
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:3183
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:2105
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:87
static const uint64_t c2
Definition: murmur3.c:50
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:367
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:3850
unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:3581
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:548
#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:252
unsigned bps
Definition: movenc.c:1410
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:197
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:777
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1334
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:896
static int lowres
Definition: ffplay.c:331
void * priv_data
Definition: avcodec.h:1803
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:1314
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
Definition: utils.c:1992
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:3566
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
#define TAG_PRINT(x)
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:267
as in Berlin toast format
Definition: avcodec.h:574
int len
int channels
number of audio channels
Definition: avcodec.h:2524
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:3761
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1811
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:1557
Y , 16bpp, little-endian.
Definition: pixfmt.h:99
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:4123
This side data corresponds to the AVCPBProperties struct.
Definition: avcodec.h:1510
static void * avformat_mutex
Definition: utils.c:119
unsigned av_codec_get_codec_properties(const AVCodecContext *codec)
Definition: utils.c:578
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:272
Not part of ABI.
Definition: pixfmt.h:537
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:4194
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:4166
static const struct twinvq_data tab
unsigned int byte_buffer_size
Definition: internal.h:180
int channels
Audio only.
Definition: avcodec.h:4258
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:2109
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:198
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:179
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: avcodec.h:3500
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2554
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:3497
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:2520
signed 16 bits, planar
Definition: samplefmt.h:67
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:529
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:2060
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:187
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3762
AVMatrixEncoding
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2089
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:4156
int ff_alloc_entries(AVCodecContext *avctx, int count)
Definition: utils.c:2118
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:2411
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:2335
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:193
int avpriv_unlock_avformat(void)
Definition: utils.c:2043
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:2165
int debug_mv
debug
Definition: avcodec.h:3039
void ff_reset_entries(AVCodecContext *avctx)
Definition: utils.c:2123
int(* init)(AVCodecContext *)
Definition: avcodec.h:3807
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:342
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:231
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:3668
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:83
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:219
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:179
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:1542
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3820
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:1931
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:2981
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:256
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:175
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3467
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:260
#define FFMAX3(a, b, c)
Definition: common.h:95
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:185
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:535
#define AV_WL32(p, v)
Definition: intreadwrite.h:431
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:2762
#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:3396
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:171
int(* receive_frame)(AVCodecContext *avctx, AVFrame *frame)
Decode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3840