FFmpeg  2.1.1
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"
34 #include "libavutil/channel_layout.h"
35 #include "libavutil/crc.h"
36 #include "libavutil/frame.h"
37 #include "libavutil/internal.h"
38 #include "libavutil/mathematics.h"
39 #include "libavutil/pixdesc.h"
40 #include "libavutil/imgutils.h"
41 #include "libavutil/samplefmt.h"
42 #include "libavutil/dict.h"
43 #include "avcodec.h"
44 #include "dsputil.h"
45 #include "libavutil/opt.h"
46 #include "thread.h"
47 #include "frame_thread_encoder.h"
48 #include "internal.h"
49 #include "bytestream.h"
50 #include "version.h"
51 #include <stdlib.h>
52 #include <stdarg.h>
53 #include <limits.h>
54 #include <float.h>
55 #if CONFIG_ICONV
56 # include <iconv.h>
57 #endif
58 
59 #if HAVE_PTHREADS
60 #include <pthread.h>
61 #elif HAVE_W32THREADS
62 #include "compat/w32pthreads.h"
63 #elif HAVE_OS2THREADS
64 #include "compat/os2threads.h"
65 #endif
66 
67 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
68 static int default_lockmgr_cb(void **arg, enum AVLockOp op)
69 {
70  void * volatile * mutex = arg;
71  int err;
72 
73  switch (op) {
74  case AV_LOCK_CREATE:
75  return 0;
76  case AV_LOCK_OBTAIN:
77  if (!*mutex) {
79  if (!tmp)
80  return AVERROR(ENOMEM);
81  if ((err = pthread_mutex_init(tmp, NULL))) {
82  av_free(tmp);
83  return AVERROR(err);
84  }
85  if (avpriv_atomic_ptr_cas(mutex, NULL, tmp)) {
87  av_free(tmp);
88  }
89  }
90 
91  if ((err = pthread_mutex_lock(*mutex)))
92  return AVERROR(err);
93 
94  return 0;
95  case AV_LOCK_RELEASE:
96  if ((err = pthread_mutex_unlock(*mutex)))
97  return AVERROR(err);
98 
99  return 0;
100  case AV_LOCK_DESTROY:
101  if (*mutex)
102  pthread_mutex_destroy(*mutex);
103  av_free(*mutex);
104  avpriv_atomic_ptr_cas(mutex, *mutex, NULL);
105  return 0;
106  }
107  return 1;
108 }
109 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = default_lockmgr_cb;
110 #else
111 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = NULL;
112 #endif
113 
114 
115 volatile int ff_avcodec_locked;
116 static int volatile entangled_thread_counter = 0;
117 static void *codec_mutex;
118 static void *avformat_mutex;
119 
120 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
121 {
122  if (min_size < *size)
123  return ptr;
124 
125  min_size = FFMAX(17 * min_size / 16 + 32, min_size);
126 
127  ptr = av_realloc(ptr, min_size);
128  /* we could set this to the unmodified min_size but this is safer
129  * if the user lost the ptr and uses NULL now
130  */
131  if (!ptr)
132  min_size = 0;
133 
134  *size = min_size;
135 
136  return ptr;
137 }
138 
139 static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
140 {
141  void **p = ptr;
142  if (min_size < *size)
143  return 0;
144  min_size = FFMAX(17 * min_size / 16 + 32, min_size);
145  av_free(*p);
146  *p = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
147  if (!*p)
148  min_size = 0;
149  *size = min_size;
150  return 1;
151 }
152 
153 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
154 {
155  ff_fast_malloc(ptr, size, min_size, 0);
156 }
157 
158 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
159 {
160  uint8_t **p = ptr;
161  if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
162  av_freep(p);
163  *size = 0;
164  return;
165  }
166  if (!ff_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1))
167  memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
168 }
169 
170 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
171 {
172  uint8_t **p = ptr;
173  if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
174  av_freep(p);
175  *size = 0;
176  return;
177  }
178  if (!ff_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1))
179  memset(*p, 0, min_size + FF_INPUT_BUFFER_PADDING_SIZE);
180 }
181 
182 /* encoder management */
183 static AVCodec *first_avcodec = NULL;
184 
186 {
187  if (c)
188  return c->next;
189  else
190  return first_avcodec;
191 }
192 
193 static av_cold void avcodec_init(void)
194 {
195  static int initialized = 0;
196 
197  if (initialized != 0)
198  return;
199  initialized = 1;
200 
201  if (CONFIG_DSPUTIL)
203 }
204 
205 int av_codec_is_encoder(const AVCodec *codec)
206 {
207  return codec && (codec->encode_sub || codec->encode2);
208 }
209 
210 int av_codec_is_decoder(const AVCodec *codec)
211 {
212  return codec && codec->decode;
213 }
214 
216 {
217  AVCodec **p;
218  avcodec_init();
219  p = &first_avcodec;
220  codec->next = NULL;
221  while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
222  p = &(*p)->next;
223 
224  if (codec->init_static_data)
225  codec->init_static_data(codec);
226 }
227 
229 {
230  return EDGE_WIDTH;
231 }
232 
234 {
235  s->coded_width = width;
236  s->coded_height = height;
237  s->width = FF_CEIL_RSHIFT(width, s->lowres);
238  s->height = FF_CEIL_RSHIFT(height, s->lowres);
239 }
240 
241 #if HAVE_NEON || ARCH_PPC || HAVE_MMX
242 # define STRIDE_ALIGN 16
243 #else
244 # define STRIDE_ALIGN 8
245 #endif
246 
248  int linesize_align[AV_NUM_DATA_POINTERS])
249 {
250  int i;
251  int w_align = 1;
252  int h_align = 1;
253 
254  switch (s->pix_fmt) {
255  case AV_PIX_FMT_YUV420P:
256  case AV_PIX_FMT_YUYV422:
257  case AV_PIX_FMT_UYVY422:
258  case AV_PIX_FMT_YUV422P:
259  case AV_PIX_FMT_YUV440P:
260  case AV_PIX_FMT_YUV444P:
261  case AV_PIX_FMT_GBRAP:
262  case AV_PIX_FMT_GBRP:
263  case AV_PIX_FMT_GRAY8:
264  case AV_PIX_FMT_GRAY16BE:
265  case AV_PIX_FMT_GRAY16LE:
266  case AV_PIX_FMT_YUVJ420P:
267  case AV_PIX_FMT_YUVJ422P:
268  case AV_PIX_FMT_YUVJ440P:
269  case AV_PIX_FMT_YUVJ444P:
270  case AV_PIX_FMT_YUVA420P:
271  case AV_PIX_FMT_YUVA422P:
272  case AV_PIX_FMT_YUVA444P:
321  case AV_PIX_FMT_GBRP9LE:
322  case AV_PIX_FMT_GBRP9BE:
323  case AV_PIX_FMT_GBRP10LE:
324  case AV_PIX_FMT_GBRP10BE:
325  case AV_PIX_FMT_GBRP12LE:
326  case AV_PIX_FMT_GBRP12BE:
327  case AV_PIX_FMT_GBRP14LE:
328  case AV_PIX_FMT_GBRP14BE:
329  w_align = 16; //FIXME assume 16 pixel per macroblock
330  h_align = 16 * 2; // interlaced needs 2 macroblocks height
331  break;
332  case AV_PIX_FMT_YUV411P:
333  case AV_PIX_FMT_YUVJ411P:
335  w_align = 32;
336  h_align = 8;
337  break;
338  case AV_PIX_FMT_YUV410P:
339  if (s->codec_id == AV_CODEC_ID_SVQ1) {
340  w_align = 64;
341  h_align = 64;
342  }
343  break;
344  case AV_PIX_FMT_RGB555:
345  if (s->codec_id == AV_CODEC_ID_RPZA) {
346  w_align = 4;
347  h_align = 4;
348  }
349  break;
350  case AV_PIX_FMT_PAL8:
351  case AV_PIX_FMT_BGR8:
352  case AV_PIX_FMT_RGB8:
353  if (s->codec_id == AV_CODEC_ID_SMC ||
355  w_align = 4;
356  h_align = 4;
357  }
358  break;
359  case AV_PIX_FMT_BGR24:
360  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
361  (s->codec_id == AV_CODEC_ID_ZLIB)) {
362  w_align = 4;
363  h_align = 4;
364  }
365  break;
366  case AV_PIX_FMT_RGB24:
367  if (s->codec_id == AV_CODEC_ID_CINEPAK) {
368  w_align = 4;
369  h_align = 4;
370  }
371  break;
372  default:
373  w_align = 1;
374  h_align = 1;
375  break;
376  }
377 
379  w_align = FFMAX(w_align, 8);
380  }
381 
382  *width = FFALIGN(*width, w_align);
383  *height = FFALIGN(*height, h_align);
384  if (s->codec_id == AV_CODEC_ID_H264 || s->lowres)
385  // some of the optimized chroma MC reads one line too much
386  // which is also done in mpeg decoders with lowres > 0
387  *height += 2;
388 
389  for (i = 0; i < 4; i++)
390  linesize_align[i] = STRIDE_ALIGN;
391 }
392 
394 {
396  int chroma_shift = desc->log2_chroma_w;
397  int linesize_align[AV_NUM_DATA_POINTERS];
398  int align;
399 
400  avcodec_align_dimensions2(s, width, height, linesize_align);
401  align = FFMAX(linesize_align[0], linesize_align[3]);
402  linesize_align[1] <<= chroma_shift;
403  linesize_align[2] <<= chroma_shift;
404  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
405  *width = FFALIGN(*width, align);
406 }
407 
408 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
409 {
410  if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB)
411  return AVERROR(EINVAL);
412  pos--;
413 
414  *xpos = (pos&1) * 128;
415  *ypos = ((pos>>1)^(pos<4)) * 128;
416 
417  return 0;
418 }
419 
421 {
422  int pos, xout, yout;
423 
424  for (pos = AVCHROMA_LOC_UNSPECIFIED + 1; pos < AVCHROMA_LOC_NB; pos++) {
425  if (avcodec_enum_to_chroma_pos(&xout, &yout, pos) == 0 && xout == xpos && yout == ypos)
426  return pos;
427  }
429 }
430 
432  enum AVSampleFormat sample_fmt, const uint8_t *buf,
433  int buf_size, int align)
434 {
435  int ch, planar, needed_size, ret = 0;
436 
437  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
438  frame->nb_samples, sample_fmt,
439  align);
440  if (buf_size < needed_size)
441  return AVERROR(EINVAL);
442 
443  planar = av_sample_fmt_is_planar(sample_fmt);
444  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
445  if (!(frame->extended_data = av_mallocz(nb_channels *
446  sizeof(*frame->extended_data))))
447  return AVERROR(ENOMEM);
448  } else {
449  frame->extended_data = frame->data;
450  }
451 
452  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
453  (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
454  sample_fmt, align)) < 0) {
455  if (frame->extended_data != frame->data)
456  av_freep(&frame->extended_data);
457  return ret;
458  }
459  if (frame->extended_data != frame->data) {
460  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
461  frame->data[ch] = frame->extended_data[ch];
462  }
463 
464  return ret;
465 }
466 
468 {
469  FramePool *pool = avctx->internal->pool;
470  int i, ret;
471 
472  switch (avctx->codec_type) {
473  case AVMEDIA_TYPE_VIDEO: {
474  AVPicture picture;
475  int size[4] = { 0 };
476  int w = frame->width;
477  int h = frame->height;
478  int tmpsize, unaligned;
479 
480  if (pool->format == frame->format &&
481  pool->width == frame->width && pool->height == frame->height)
482  return 0;
483 
484  avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
485 
486  if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
487  w += EDGE_WIDTH * 2;
488  h += EDGE_WIDTH * 2;
489  }
490 
491  do {
492  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
493  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
494  av_image_fill_linesizes(picture.linesize, avctx->pix_fmt, w);
495  // increase alignment of w for next try (rhs gives the lowest bit set in w)
496  w += w & ~(w - 1);
497 
498  unaligned = 0;
499  for (i = 0; i < 4; i++)
500  unaligned |= picture.linesize[i] % pool->stride_align[i];
501  } while (unaligned);
502 
503  tmpsize = av_image_fill_pointers(picture.data, avctx->pix_fmt, h,
504  NULL, picture.linesize);
505  if (tmpsize < 0)
506  return -1;
507 
508  for (i = 0; i < 3 && picture.data[i + 1]; i++)
509  size[i] = picture.data[i + 1] - picture.data[i];
510  size[i] = tmpsize - (picture.data[i] - picture.data[0]);
511 
512  for (i = 0; i < 4; i++) {
513  av_buffer_pool_uninit(&pool->pools[i]);
514  pool->linesize[i] = picture.linesize[i];
515  if (size[i]) {
516  pool->pools[i] = av_buffer_pool_init(size[i] + 16 + STRIDE_ALIGN - 1,
518  NULL :
520  if (!pool->pools[i]) {
521  ret = AVERROR(ENOMEM);
522  goto fail;
523  }
524  }
525  }
526  pool->format = frame->format;
527  pool->width = frame->width;
528  pool->height = frame->height;
529 
530  break;
531  }
532  case AVMEDIA_TYPE_AUDIO: {
533  int ch = av_frame_get_channels(frame); //av_get_channel_layout_nb_channels(frame->channel_layout);
534  int planar = av_sample_fmt_is_planar(frame->format);
535  int planes = planar ? ch : 1;
536 
537  if (pool->format == frame->format && pool->planes == planes &&
538  pool->channels == ch && frame->nb_samples == pool->samples)
539  return 0;
540 
541  av_buffer_pool_uninit(&pool->pools[0]);
542  ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
543  frame->nb_samples, frame->format, 0);
544  if (ret < 0)
545  goto fail;
546 
547  pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
548  if (!pool->pools[0]) {
549  ret = AVERROR(ENOMEM);
550  goto fail;
551  }
552 
553  pool->format = frame->format;
554  pool->planes = planes;
555  pool->channels = ch;
556  pool->samples = frame->nb_samples;
557  break;
558  }
559  default: av_assert0(0);
560  }
561  return 0;
562 fail:
563  for (i = 0; i < 4; i++)
564  av_buffer_pool_uninit(&pool->pools[i]);
565  pool->format = -1;
566  pool->planes = pool->channels = pool->samples = 0;
567  pool->width = pool->height = 0;
568  return ret;
569 }
570 
572 {
573  FramePool *pool = avctx->internal->pool;
574  int planes = pool->planes;
575  int i;
576 
577  frame->linesize[0] = pool->linesize[0];
578 
579  if (planes > AV_NUM_DATA_POINTERS) {
580  frame->extended_data = av_mallocz(planes * sizeof(*frame->extended_data));
581  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
582  frame->extended_buf = av_mallocz(frame->nb_extended_buf *
583  sizeof(*frame->extended_buf));
584  if (!frame->extended_data || !frame->extended_buf) {
585  av_freep(&frame->extended_data);
586  av_freep(&frame->extended_buf);
587  return AVERROR(ENOMEM);
588  }
589  } else {
590  frame->extended_data = frame->data;
591  av_assert0(frame->nb_extended_buf == 0);
592  }
593 
594  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
595  frame->buf[i] = av_buffer_pool_get(pool->pools[0]);
596  if (!frame->buf[i])
597  goto fail;
598  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
599  }
600  for (i = 0; i < frame->nb_extended_buf; i++) {
601  frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]);
602  if (!frame->extended_buf[i])
603  goto fail;
604  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
605  }
606 
607  if (avctx->debug & FF_DEBUG_BUFFERS)
608  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame);
609 
610  return 0;
611 fail:
612  av_frame_unref(frame);
613  return AVERROR(ENOMEM);
614 }
615 
617 {
618  FramePool *pool = s->internal->pool;
619  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format);
620  int pixel_size = desc->comp[0].step_minus1 + 1;
621  int h_chroma_shift, v_chroma_shift;
622  int i;
623 
624  if (pic->data[0] != NULL) {
625  av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
626  return -1;
627  }
628 
629  memset(pic->data, 0, sizeof(pic->data));
630  pic->extended_data = pic->data;
631 
632  av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
633 
634  for (i = 0; i < 4 && pool->pools[i]; i++) {
635  const int h_shift = i == 0 ? 0 : h_chroma_shift;
636  const int v_shift = i == 0 ? 0 : v_chroma_shift;
637  int is_planar = pool->pools[2] || (i==0 && s->pix_fmt == AV_PIX_FMT_GRAY8);
638 
639  pic->linesize[i] = pool->linesize[i];
640 
641  pic->buf[i] = av_buffer_pool_get(pool->pools[i]);
642  if (!pic->buf[i])
643  goto fail;
644 
645  // no edge if EDGE EMU or not planar YUV
646  if ((s->flags & CODEC_FLAG_EMU_EDGE) || !is_planar)
647  pic->data[i] = pic->buf[i]->data;
648  else {
649  pic->data[i] = pic->buf[i]->data +
650  FFALIGN((pic->linesize[i] * EDGE_WIDTH >> v_shift) +
651  (pixel_size * EDGE_WIDTH >> h_shift), pool->stride_align[i]);
652  }
653  }
654  for (; i < AV_NUM_DATA_POINTERS; i++) {
655  pic->data[i] = NULL;
656  pic->linesize[i] = 0;
657  }
658  if (pic->data[1] && !pic->data[2])
659  avpriv_set_systematic_pal2((uint32_t *)pic->data[1], s->pix_fmt);
660 
661  if (s->debug & FF_DEBUG_BUFFERS)
662  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic);
663 
664  return 0;
665 fail:
666  av_frame_unref(pic);
667  return AVERROR(ENOMEM);
668 }
669 
670 void avpriv_color_frame(AVFrame *frame, const int c[4])
671 {
672  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
673  int p, y, x;
674 
676 
677  for (p = 0; p<desc->nb_components; p++) {
678  uint8_t *dst = frame->data[p];
679  int is_chroma = p == 1 || p == 2;
680  int bytes = is_chroma ? FF_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
681  int height = is_chroma ? FF_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
682  for (y = 0; y < height; y++) {
683  if (desc->comp[0].depth_minus1 >= 8) {
684  for (x = 0; x<bytes; x++)
685  ((uint16_t*)dst)[x] = c[p];
686  }else
687  memset(dst, c[p], bytes);
688  dst += frame->linesize[p];
689  }
690  }
691 }
692 
694 {
695  int ret;
696 
697  if ((ret = update_frame_pool(avctx, frame)) < 0)
698  return ret;
699 
700 #if FF_API_GET_BUFFER
702  frame->type = FF_BUFFER_TYPE_INTERNAL;
704 #endif
705 
706  switch (avctx->codec_type) {
707  case AVMEDIA_TYPE_VIDEO:
708  return video_get_buffer(avctx, frame);
709  case AVMEDIA_TYPE_AUDIO:
710  return audio_get_buffer(avctx, frame);
711  default:
712  return -1;
713  }
714 }
715 
717 {
718  if (avctx->pkt) {
719  frame->pkt_pts = avctx->pkt->pts;
720  av_frame_set_pkt_pos (frame, avctx->pkt->pos);
721  av_frame_set_pkt_duration(frame, avctx->pkt->duration);
722  av_frame_set_pkt_size (frame, avctx->pkt->size);
723  } else {
724  frame->pkt_pts = AV_NOPTS_VALUE;
725  av_frame_set_pkt_pos (frame, -1);
726  av_frame_set_pkt_duration(frame, 0);
727  av_frame_set_pkt_size (frame, -1);
728  }
729  frame->reordered_opaque = avctx->reordered_opaque;
730 
731  switch (avctx->codec->type) {
732  case AVMEDIA_TYPE_VIDEO:
733  frame->width = FFMAX(avctx->width, FF_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
734  frame->height = FFMAX(avctx->height, FF_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
735  if (frame->format < 0)
736  frame->format = avctx->pix_fmt;
737  if (!frame->sample_aspect_ratio.num)
740  av_frame_set_colorspace(frame, avctx->colorspace);
742  av_frame_set_color_range(frame, avctx->color_range);
743  break;
744  case AVMEDIA_TYPE_AUDIO:
745  if (!frame->sample_rate)
746  frame->sample_rate = avctx->sample_rate;
747  if (frame->format < 0)
748  frame->format = avctx->sample_fmt;
749  if (!frame->channel_layout) {
750  if (avctx->channel_layout) {
752  avctx->channels) {
753  av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
754  "configuration.\n");
755  return AVERROR(EINVAL);
756  }
757 
758  frame->channel_layout = avctx->channel_layout;
759  } else {
760  if (avctx->channels > FF_SANE_NB_CHANNELS) {
761  av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
762  avctx->channels);
763  return AVERROR(ENOSYS);
764  }
765  }
766  }
767  av_frame_set_channels(frame, avctx->channels);
768  break;
769  }
770  return 0;
771 }
772 
773 #if FF_API_GET_BUFFER
776 {
777  return avcodec_default_get_buffer2(avctx, frame, 0);
778 }
779 
780 typedef struct CompatReleaseBufPriv {
781  AVCodecContext avctx;
782  AVFrame frame;
783 } CompatReleaseBufPriv;
784 
785 static void compat_free_buffer(void *opaque, uint8_t *data)
786 {
787  CompatReleaseBufPriv *priv = opaque;
788  if (priv->avctx.release_buffer)
789  priv->avctx.release_buffer(&priv->avctx, &priv->frame);
790  av_freep(&priv);
791 }
792 
793 static void compat_release_buffer(void *opaque, uint8_t *data)
794 {
795  AVBufferRef *buf = opaque;
796  av_buffer_unref(&buf);
797 }
799 #endif
800 
802 {
803  int ret;
804 
805  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
806  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0 || avctx->pix_fmt<0) {
807  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
808  return AVERROR(EINVAL);
809  }
810  }
811  if ((ret = ff_init_buffer_info(avctx, frame)) < 0)
812  return ret;
813 
814 #if FF_API_GET_BUFFER
816  /*
817  * Wrap an old get_buffer()-allocated buffer in a bunch of AVBuffers.
818  * We wrap each plane in its own AVBuffer. Each of those has a reference to
819  * a dummy AVBuffer as its private data, unreffing it on free.
820  * When all the planes are freed, the dummy buffer's free callback calls
821  * release_buffer().
822  */
823  if (avctx->get_buffer) {
824  CompatReleaseBufPriv *priv = NULL;
825  AVBufferRef *dummy_buf = NULL;
826  int planes, i, ret;
827 
828  if (flags & AV_GET_BUFFER_FLAG_REF)
829  frame->reference = 1;
830 
831  ret = avctx->get_buffer(avctx, frame);
832  if (ret < 0)
833  return ret;
834 
835  /* return if the buffers are already set up
836  * this would happen e.g. when a custom get_buffer() calls
837  * avcodec_default_get_buffer
838  */
839  if (frame->buf[0])
840  goto end;
841 
842  priv = av_mallocz(sizeof(*priv));
843  if (!priv) {
844  ret = AVERROR(ENOMEM);
845  goto fail;
846  }
847  priv->avctx = *avctx;
848  priv->frame = *frame;
849 
850  dummy_buf = av_buffer_create(NULL, 0, compat_free_buffer, priv, 0);
851  if (!dummy_buf) {
852  ret = AVERROR(ENOMEM);
853  goto fail;
854  }
855 
856 #define WRAP_PLANE(ref_out, data, data_size) \
857 do { \
858  AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
859  if (!dummy_ref) { \
860  ret = AVERROR(ENOMEM); \
861  goto fail; \
862  } \
863  ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
864  dummy_ref, 0); \
865  if (!ref_out) { \
866  av_frame_unref(frame); \
867  ret = AVERROR(ENOMEM); \
868  goto fail; \
869  } \
870 } while (0)
871 
872  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
873  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
874 
875  planes = av_pix_fmt_count_planes(frame->format);
876  /* workaround for AVHWAccel plane count of 0, buf[0] is used as
877  check for allocated buffers: make libavcodec happy */
878  if (desc && desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
879  planes = 1;
880  if (!desc || planes <= 0) {
881  ret = AVERROR(EINVAL);
882  goto fail;
883  }
884 
885  for (i = 0; i < planes; i++) {
886  int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
887  int plane_size = (frame->height >> v_shift) * frame->linesize[i];
888 
889  WRAP_PLANE(frame->buf[i], frame->data[i], plane_size);
890  }
891  } else {
892  int planar = av_sample_fmt_is_planar(frame->format);
893  planes = planar ? avctx->channels : 1;
894 
895  if (planes > FF_ARRAY_ELEMS(frame->buf)) {
896  frame->nb_extended_buf = planes - FF_ARRAY_ELEMS(frame->buf);
897  frame->extended_buf = av_malloc(sizeof(*frame->extended_buf) *
898  frame->nb_extended_buf);
899  if (!frame->extended_buf) {
900  ret = AVERROR(ENOMEM);
901  goto fail;
902  }
903  }
904 
905  for (i = 0; i < FFMIN(planes, FF_ARRAY_ELEMS(frame->buf)); i++)
906  WRAP_PLANE(frame->buf[i], frame->extended_data[i], frame->linesize[0]);
907 
908  for (i = 0; i < frame->nb_extended_buf; i++)
909  WRAP_PLANE(frame->extended_buf[i],
910  frame->extended_data[i + FF_ARRAY_ELEMS(frame->buf)],
911  frame->linesize[0]);
912  }
913 
914  av_buffer_unref(&dummy_buf);
915 
916 end:
917  frame->width = avctx->width;
918  frame->height = avctx->height;
919 
920  return 0;
921 
922 fail:
923  avctx->release_buffer(avctx, frame);
924  av_freep(&priv);
925  av_buffer_unref(&dummy_buf);
926  return ret;
927  }
929 #endif
930 
931  ret = avctx->get_buffer2(avctx, frame, flags);
932 
933  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
934  frame->width = avctx->width;
935  frame->height = avctx->height;
936  }
937 
938  return ret;
939 }
940 
942 {
943  int ret = get_buffer_internal(avctx, frame, flags);
944  if (ret < 0)
945  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
946  return ret;
947 }
948 
950 {
951  AVFrame tmp;
952  int ret;
953 
955 
956  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
957  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
958  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
959  av_frame_unref(frame);
960  }
961 
962  ff_init_buffer_info(avctx, frame);
963 
964  if (!frame->data[0])
965  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
966 
967  if (av_frame_is_writable(frame))
968  return 0;
969 
970  av_frame_move_ref(&tmp, frame);
971 
972  ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
973  if (ret < 0) {
974  av_frame_unref(&tmp);
975  return ret;
976  }
977 
978  av_image_copy(frame->data, frame->linesize, tmp.data, tmp.linesize,
979  frame->format, frame->width, frame->height);
980 
981  av_frame_unref(&tmp);
982 
983  return 0;
984 }
985 
987 {
988  int ret = reget_buffer_internal(avctx, frame);
989  if (ret < 0)
990  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
991  return ret;
992 }
993 
994 #if FF_API_GET_BUFFER
996 {
998 
999  av_frame_unref(pic);
1000 }
1001 
1003 {
1004  av_assert0(0);
1005  return AVERROR_BUG;
1006 }
1007 #endif
1008 
1009 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
1010 {
1011  int i;
1012 
1013  for (i = 0; i < count; i++) {
1014  int r = func(c, (char *)arg + i * size);
1015  if (ret)
1016  ret[i] = r;
1017  }
1018  return 0;
1019 }
1020 
1021 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
1022 {
1023  int i;
1024 
1025  for (i = 0; i < count; i++) {
1026  int r = func(c, arg, i, 0);
1027  if (ret)
1028  ret[i] = r;
1029  }
1030  return 0;
1031 }
1032 
1034 {
1035  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
1036  return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
1037 }
1038 
1040 {
1041  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
1042  ++fmt;
1043  return fmt[0];
1044 }
1045 
1047 {
1048 #if LIBAVCODEC_VERSION_MAJOR >= 55
1049  // extended_data should explicitly be freed when needed, this code is unsafe currently
1050  // also this is not compatible to the <55 ABI/API
1051  if (frame->extended_data != frame->data && 0)
1052  av_freep(&frame->extended_data);
1053 #endif
1054 
1055  memset(frame, 0, sizeof(AVFrame));
1056 
1057  frame->pts =
1058  frame->pkt_dts =
1059  frame->pkt_pts = AV_NOPTS_VALUE;
1061  av_frame_set_pkt_duration (frame, 0);
1062  av_frame_set_pkt_pos (frame, -1);
1063  av_frame_set_pkt_size (frame, -1);
1064  frame->key_frame = 1;
1065  frame->sample_aspect_ratio = (AVRational) {0, 1 };
1066  frame->format = -1; /* unknown */
1067  frame->extended_data = frame->data;
1069 }
1070 
1072 {
1073  AVFrame *frame = av_malloc(sizeof(AVFrame));
1074 
1075  if (frame == NULL)
1076  return NULL;
1077 
1078  frame->extended_data = NULL;
1080 
1081  return frame;
1082 }
1083 
1085 {
1086  AVFrame *f;
1087 
1088  if (!frame || !*frame)
1089  return;
1090 
1091  f = *frame;
1092 
1093  if (f->extended_data != f->data)
1094  av_freep(&f->extended_data);
1095 
1096  av_freep(frame);
1097 }
1098 
1099 MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
1100 MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, codec_descriptor)
1101 MAKE_ACCESSORS(AVCodecContext, codec, int, lowres)
1102 MAKE_ACCESSORS(AVCodecContext, codec, int, seek_preroll)
1103 
1105 {
1106  return codec->max_lowres;
1107 }
1108 
1110 {
1111  memset(sub, 0, sizeof(*sub));
1112  sub->pts = AV_NOPTS_VALUE;
1113 }
1114 
1116 {
1117  int bit_rate;
1118  int bits_per_sample;
1119 
1120  switch (ctx->codec_type) {
1121  case AVMEDIA_TYPE_VIDEO:
1122  case AVMEDIA_TYPE_DATA:
1123  case AVMEDIA_TYPE_SUBTITLE:
1125  bit_rate = ctx->bit_rate;
1126  break;
1127  case AVMEDIA_TYPE_AUDIO:
1128  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1129  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1130  break;
1131  default:
1132  bit_rate = 0;
1133  break;
1134  }
1135  return bit_rate;
1136 }
1137 
1138 #if FF_API_AVCODEC_OPEN
1139 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
1140 {
1141  return avcodec_open2(avctx, codec, NULL);
1142 }
1143 #endif
1144 
1146 {
1147  int ret = 0;
1148 
1150 
1151  ret = avcodec_open2(avctx, codec, options);
1152 
1153  ff_lock_avcodec(avctx);
1154  return ret;
1155 }
1156 
1158 {
1159  int ret = 0;
1160  AVDictionary *tmp = NULL;
1161 
1162  if (avcodec_is_open(avctx))
1163  return 0;
1164 
1165  if ((!codec && !avctx->codec)) {
1166  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
1167  return AVERROR(EINVAL);
1168  }
1169  if ((codec && avctx->codec && codec != avctx->codec)) {
1170  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
1171  "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
1172  return AVERROR(EINVAL);
1173  }
1174  if (!codec)
1175  codec = avctx->codec;
1176 
1177  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
1178  return AVERROR(EINVAL);
1179 
1180  if (options)
1181  av_dict_copy(&tmp, *options, 0);
1182 
1183  ret = ff_lock_avcodec(avctx);
1184  if (ret < 0)
1185  return ret;
1186 
1187  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
1188  if (!avctx->internal) {
1189  ret = AVERROR(ENOMEM);
1190  goto end;
1191  }
1192 
1193  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
1194  if (!avctx->internal->pool) {
1195  ret = AVERROR(ENOMEM);
1196  goto free_and_end;
1197  }
1198 
1199  if (codec->priv_data_size > 0) {
1200  if (!avctx->priv_data) {
1201  avctx->priv_data = av_mallocz(codec->priv_data_size);
1202  if (!avctx->priv_data) {
1203  ret = AVERROR(ENOMEM);
1204  goto end;
1205  }
1206  if (codec->priv_class) {
1207  *(const AVClass **)avctx->priv_data = codec->priv_class;
1209  }
1210  }
1211  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
1212  goto free_and_end;
1213  } else {
1214  avctx->priv_data = NULL;
1215  }
1216  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
1217  goto free_and_end;
1218 
1219  // only call avcodec_set_dimensions() for non H.264/VP6F codecs so as not to overwrite previously setup dimensions
1220  if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
1221  (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F))) {
1222  if (avctx->coded_width && avctx->coded_height)
1223  avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
1224  else if (avctx->width && avctx->height)
1225  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
1226  }
1227 
1228  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
1229  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
1230  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
1231  av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
1232  avcodec_set_dimensions(avctx, 0, 0);
1233  }
1234 
1235  /* if the decoder init function was already called previously,
1236  * free the already allocated subtitle_header before overwriting it */
1237  if (av_codec_is_decoder(codec))
1238  av_freep(&avctx->subtitle_header);
1239 
1240  if (avctx->channels > FF_SANE_NB_CHANNELS) {
1241  ret = AVERROR(EINVAL);
1242  goto free_and_end;
1243  }
1244 
1245  avctx->codec = codec;
1246  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
1247  avctx->codec_id == AV_CODEC_ID_NONE) {
1248  avctx->codec_type = codec->type;
1249  avctx->codec_id = codec->id;
1250  }
1251  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
1252  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
1253  av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
1254  ret = AVERROR(EINVAL);
1255  goto free_and_end;
1256  }
1257  avctx->frame_number = 0;
1259 
1260  if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
1262  const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
1263  AVCodec *codec2;
1264  av_log(avctx, AV_LOG_ERROR,
1265  "The %s '%s' is experimental but experimental codecs are not enabled, "
1266  "add '-strict %d' if you want to use it.\n",
1267  codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
1268  codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
1269  if (!(codec2->capabilities & CODEC_CAP_EXPERIMENTAL))
1270  av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
1271  codec_string, codec2->name);
1272  ret = AVERROR_EXPERIMENTAL;
1273  goto free_and_end;
1274  }
1275 
1276  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1277  (!avctx->time_base.num || !avctx->time_base.den)) {
1278  avctx->time_base.num = 1;
1279  avctx->time_base.den = avctx->sample_rate;
1280  }
1281 
1282  if (!HAVE_THREADS)
1283  av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
1284 
1286  ff_unlock_avcodec(); //we will instanciate a few encoders thus kick the counter to prevent false detection of a problem
1287  ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
1288  ff_lock_avcodec(avctx);
1289  if (ret < 0)
1290  goto free_and_end;
1291  }
1292 
1293  if (HAVE_THREADS
1295  ret = ff_thread_init(avctx);
1296  if (ret < 0) {
1297  goto free_and_end;
1298  }
1299  }
1300  if (!HAVE_THREADS && !(codec->capabilities & CODEC_CAP_AUTO_THREADS))
1301  avctx->thread_count = 1;
1302 
1303  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1304  av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
1305  avctx->codec->max_lowres);
1306  ret = AVERROR(EINVAL);
1307  goto free_and_end;
1308  }
1309 
1310  if (av_codec_is_encoder(avctx->codec)) {
1311  int i;
1312  if (avctx->codec->sample_fmts) {
1313  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
1314  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
1315  break;
1316  if (avctx->channels == 1 &&
1319  avctx->sample_fmt = avctx->codec->sample_fmts[i];
1320  break;
1321  }
1322  }
1323  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
1324  char buf[128];
1325  snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
1326  av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
1327  (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
1328  ret = AVERROR(EINVAL);
1329  goto free_and_end;
1330  }
1331  }
1332  if (avctx->codec->pix_fmts) {
1333  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
1334  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
1335  break;
1336  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
1337  && !((avctx->codec_id == AV_CODEC_ID_MJPEG || avctx->codec_id == AV_CODEC_ID_LJPEG)
1339  char buf[128];
1340  snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
1341  av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
1342  (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
1343  ret = AVERROR(EINVAL);
1344  goto free_and_end;
1345  }
1346  }
1347  if (avctx->codec->supported_samplerates) {
1348  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
1349  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
1350  break;
1351  if (avctx->codec->supported_samplerates[i] == 0) {
1352  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
1353  avctx->sample_rate);
1354  ret = AVERROR(EINVAL);
1355  goto free_and_end;
1356  }
1357  }
1358  if (avctx->codec->channel_layouts) {
1359  if (!avctx->channel_layout) {
1360  av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
1361  } else {
1362  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
1363  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
1364  break;
1365  if (avctx->codec->channel_layouts[i] == 0) {
1366  char buf[512];
1367  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1368  av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
1369  ret = AVERROR(EINVAL);
1370  goto free_and_end;
1371  }
1372  }
1373  }
1374  if (avctx->channel_layout && avctx->channels) {
1375  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1376  if (channels != avctx->channels) {
1377  char buf[512];
1378  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1379  av_log(avctx, AV_LOG_ERROR,
1380  "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1381  buf, channels, avctx->channels);
1382  ret = AVERROR(EINVAL);
1383  goto free_and_end;
1384  }
1385  } else if (avctx->channel_layout) {
1387  }
1388  if(avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
1389  avctx->codec_id != AV_CODEC_ID_PNG // For mplayer
1390  ) {
1391  if (avctx->width <= 0 || avctx->height <= 0) {
1392  av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
1393  ret = AVERROR(EINVAL);
1394  goto free_and_end;
1395  }
1396  }
1397  if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
1398  && avctx->bit_rate>0 && avctx->bit_rate<1000) {
1399  av_log(avctx, AV_LOG_WARNING, "Bitrate %d is extremely low, maybe you mean %dk\n", avctx->bit_rate, avctx->bit_rate);
1400  }
1401 
1402  if (!avctx->rc_initial_buffer_occupancy)
1403  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
1404  }
1405 
1407  avctx->pts_correction_num_faulty_dts = 0;
1408  avctx->pts_correction_last_pts =
1409  avctx->pts_correction_last_dts = INT64_MIN;
1410 
1411  if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME)
1412  || avctx->internal->frame_thread_encoder)) {
1413  ret = avctx->codec->init(avctx);
1414  if (ret < 0) {
1415  goto free_and_end;
1416  }
1417  }
1418 
1419  ret=0;
1420 
1421  if (av_codec_is_decoder(avctx->codec)) {
1422  if (!avctx->bit_rate)
1423  avctx->bit_rate = get_bit_rate(avctx);
1424  /* validate channel layout from the decoder */
1425  if (avctx->channel_layout) {
1426  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1427  if (!avctx->channels)
1428  avctx->channels = channels;
1429  else if (channels != avctx->channels) {
1430  char buf[512];
1431  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1432  av_log(avctx, AV_LOG_WARNING,
1433  "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1434  "ignoring specified channel layout\n",
1435  buf, channels, avctx->channels);
1436  avctx->channel_layout = 0;
1437  }
1438  }
1439  if (avctx->channels && avctx->channels < 0 ||
1440  avctx->channels > FF_SANE_NB_CHANNELS) {
1441  ret = AVERROR(EINVAL);
1442  goto free_and_end;
1443  }
1444  if (avctx->sub_charenc) {
1445  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1446  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1447  "supported with subtitles codecs\n");
1448  ret = AVERROR(EINVAL);
1449  goto free_and_end;
1450  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1451  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1452  "subtitles character encoding will be ignored\n",
1453  avctx->codec_descriptor->name);
1455  } else {
1456  /* input character encoding is set for a text based subtitle
1457  * codec at this point */
1460 
1462 #if CONFIG_ICONV
1463  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1464  if (cd == (iconv_t)-1) {
1465  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1466  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1467  ret = AVERROR(errno);
1468  goto free_and_end;
1469  }
1470  iconv_close(cd);
1471 #else
1472  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1473  "conversion needs a libavcodec built with iconv support "
1474  "for this codec\n");
1475  ret = AVERROR(ENOSYS);
1476  goto free_and_end;
1477 #endif
1478  }
1479  }
1480  }
1481  }
1482 end:
1484  if (options) {
1485  av_dict_free(options);
1486  *options = tmp;
1487  }
1488 
1489  return ret;
1490 free_and_end:
1491  av_dict_free(&tmp);
1492  av_freep(&avctx->priv_data);
1493  if (avctx->internal)
1494  av_freep(&avctx->internal->pool);
1495  av_freep(&avctx->internal);
1496  avctx->codec = NULL;
1497  goto end;
1498 }
1499 
1500 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
1501 {
1502  if (avpkt->size < 0) {
1503  av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
1504  return AVERROR(EINVAL);
1505  }
1506  if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
1507  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
1508  size, INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE);
1509  return AVERROR(EINVAL);
1510  }
1511 
1512  if (avctx) {
1513  av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);
1514  if (!avpkt->data || avpkt->size < size) {
1516  avpkt->data = avctx->internal->byte_buffer;
1517  avpkt->size = avctx->internal->byte_buffer_size;
1518  avpkt->destruct = NULL;
1519  }
1520  }
1521 
1522  if (avpkt->data) {
1523  AVBufferRef *buf = avpkt->buf;
1524 #if FF_API_DESTRUCT_PACKET
1526  void *destruct = avpkt->destruct;
1528 #endif
1529 
1530  if (avpkt->size < size) {
1531  av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %"PRId64")\n", avpkt->size, size);
1532  return AVERROR(EINVAL);
1533  }
1534 
1535  av_init_packet(avpkt);
1536 #if FF_API_DESTRUCT_PACKET
1538  avpkt->destruct = destruct;
1540 #endif
1541  avpkt->buf = buf;
1542  avpkt->size = size;
1543  return 0;
1544  } else {
1545  int ret = av_new_packet(avpkt, size);
1546  if (ret < 0)
1547  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
1548  return ret;
1549  }
1550 }
1551 
1553 {
1554  return ff_alloc_packet2(NULL, avpkt, size);
1555 }
1556 
1557 /**
1558  * Pad last frame with silence.
1559  */
1560 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
1561 {
1562  AVFrame *frame = NULL;
1563  int ret;
1564 
1565  if (!(frame = avcodec_alloc_frame()))
1566  return AVERROR(ENOMEM);
1567 
1568  frame->format = src->format;
1569  frame->channel_layout = src->channel_layout;
1571  frame->nb_samples = s->frame_size;
1572  ret = av_frame_get_buffer(frame, 32);
1573  if (ret < 0)
1574  goto fail;
1575 
1576  ret = av_frame_copy_props(frame, src);
1577  if (ret < 0)
1578  goto fail;
1579 
1580  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
1581  src->nb_samples, s->channels, s->sample_fmt)) < 0)
1582  goto fail;
1583  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
1584  frame->nb_samples - src->nb_samples,
1585  s->channels, s->sample_fmt)) < 0)
1586  goto fail;
1587 
1588  *dst = frame;
1589 
1590  return 0;
1591 
1592 fail:
1593  av_frame_free(&frame);
1594  return ret;
1595 }
1596 
1598  AVPacket *avpkt,
1599  const AVFrame *frame,
1600  int *got_packet_ptr)
1601 {
1602  AVFrame tmp;
1603  AVFrame *padded_frame = NULL;
1604  int ret;
1605  AVPacket user_pkt = *avpkt;
1606  int needs_realloc = !user_pkt.data;
1607 
1608  *got_packet_ptr = 0;
1609 
1610  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1611  av_free_packet(avpkt);
1612  av_init_packet(avpkt);
1613  return 0;
1614  }
1615 
1616  /* ensure that extended_data is properly set */
1617  if (frame && !frame->extended_data) {
1618  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
1619  avctx->channels > AV_NUM_DATA_POINTERS) {
1620  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
1621  "with more than %d channels, but extended_data is not set.\n",
1623  return AVERROR(EINVAL);
1624  }
1625  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
1626 
1627  tmp = *frame;
1628  tmp.extended_data = tmp.data;
1629  frame = &tmp;
1630  }
1631 
1632  /* check for valid frame size */
1633  if (frame) {
1635  if (frame->nb_samples > avctx->frame_size) {
1636  av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
1637  return AVERROR(EINVAL);
1638  }
1639  } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
1640  if (frame->nb_samples < avctx->frame_size &&
1641  !avctx->internal->last_audio_frame) {
1642  ret = pad_last_frame(avctx, &padded_frame, frame);
1643  if (ret < 0)
1644  return ret;
1645 
1646  frame = padded_frame;
1647  avctx->internal->last_audio_frame = 1;
1648  }
1649 
1650  if (frame->nb_samples != avctx->frame_size) {
1651  av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size);
1652  ret = AVERROR(EINVAL);
1653  goto end;
1654  }
1655  }
1656  }
1657 
1658  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1659  if (!ret) {
1660  if (*got_packet_ptr) {
1661  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
1662  if (avpkt->pts == AV_NOPTS_VALUE)
1663  avpkt->pts = frame->pts;
1664  if (!avpkt->duration)
1665  avpkt->duration = ff_samples_to_time_base(avctx,
1666  frame->nb_samples);
1667  }
1668  avpkt->dts = avpkt->pts;
1669  } else {
1670  avpkt->size = 0;
1671  }
1672  }
1673  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
1674  needs_realloc = 0;
1675  if (user_pkt.data) {
1676  if (user_pkt.size >= avpkt->size) {
1677  memcpy(user_pkt.data, avpkt->data, avpkt->size);
1678  } else {
1679  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
1680  avpkt->size = user_pkt.size;
1681  ret = -1;
1682  }
1683  avpkt->buf = user_pkt.buf;
1684  avpkt->data = user_pkt.data;
1685  avpkt->destruct = user_pkt.destruct;
1686  } else {
1687  if (av_dup_packet(avpkt) < 0) {
1688  ret = AVERROR(ENOMEM);
1689  }
1690  }
1691  }
1692 
1693  if (!ret) {
1694  if (needs_realloc && avpkt->data) {
1695  ret = av_buffer_realloc(&avpkt->buf, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
1696  if (ret >= 0)
1697  avpkt->data = avpkt->buf->data;
1698  }
1699 
1700  avctx->frame_number++;
1701  }
1702 
1703  if (ret < 0 || !*got_packet_ptr) {
1704  av_free_packet(avpkt);
1705  av_init_packet(avpkt);
1706  goto end;
1707  }
1708 
1709  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1710  * this needs to be moved to the encoders, but for now we can do it
1711  * here to simplify things */
1712  avpkt->flags |= AV_PKT_FLAG_KEY;
1713 
1714 end:
1715  av_frame_free(&padded_frame);
1716 
1717  return ret;
1718 }
1719 
1720 #if FF_API_OLD_ENCODE_AUDIO
1722  uint8_t *buf, int buf_size,
1723  const short *samples)
1724 {
1725  AVPacket pkt;
1726  AVFrame frame0 = { { 0 } };
1727  AVFrame *frame;
1728  int ret, samples_size, got_packet;
1729 
1730  av_init_packet(&pkt);
1731  pkt.data = buf;
1732  pkt.size = buf_size;
1733 
1734  if (samples) {
1735  frame = &frame0;
1737 
1738  if (avctx->frame_size) {
1739  frame->nb_samples = avctx->frame_size;
1740  } else {
1741  /* if frame_size is not set, the number of samples must be
1742  * calculated from the buffer size */
1743  int64_t nb_samples;
1744  if (!av_get_bits_per_sample(avctx->codec_id)) {
1745  av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not "
1746  "support this codec\n");
1747  return AVERROR(EINVAL);
1748  }
1749  nb_samples = (int64_t)buf_size * 8 /
1750  (av_get_bits_per_sample(avctx->codec_id) *
1751  avctx->channels);
1752  if (nb_samples >= INT_MAX)
1753  return AVERROR(EINVAL);
1754  frame->nb_samples = nb_samples;
1755  }
1756 
1757  /* it is assumed that the samples buffer is large enough based on the
1758  * relevant parameters */
1759  samples_size = av_samples_get_buffer_size(NULL, avctx->channels,
1760  frame->nb_samples,
1761  avctx->sample_fmt, 1);
1762  if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
1763  avctx->sample_fmt,
1764  (const uint8_t *)samples,
1765  samples_size, 1)) < 0)
1766  return ret;
1767 
1768  /* fabricate frame pts from sample count.
1769  * this is needed because the avcodec_encode_audio() API does not have
1770  * a way for the user to provide pts */
1771  if (avctx->sample_rate && avctx->time_base.num)
1772  frame->pts = ff_samples_to_time_base(avctx,
1773  avctx->internal->sample_count);
1774  else
1775  frame->pts = AV_NOPTS_VALUE;
1776  avctx->internal->sample_count += frame->nb_samples;
1777  } else {
1778  frame = NULL;
1779  }
1780 
1781  got_packet = 0;
1782  ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);
1783  if (!ret && got_packet && avctx->coded_frame) {
1784  avctx->coded_frame->pts = pkt.pts;
1785  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1786  }
1787  /* free any side data since we cannot return it */
1789 
1790  if (frame && frame->extended_data != frame->data)
1791  av_freep(&frame->extended_data);
1792 
1793  return ret ? ret : pkt.size;
1794 }
1795 
1796 #endif
1797 
1798 #if FF_API_OLD_ENCODE_VIDEO
1799 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1800  const AVFrame *pict)
1801 {
1802  AVPacket pkt;
1803  int ret, got_packet = 0;
1804 
1805  if (buf_size < FF_MIN_BUFFER_SIZE) {
1806  av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
1807  return -1;
1808  }
1809 
1810  av_init_packet(&pkt);
1811  pkt.data = buf;
1812  pkt.size = buf_size;
1813 
1814  ret = avcodec_encode_video2(avctx, &pkt, pict, &got_packet);
1815  if (!ret && got_packet && avctx->coded_frame) {
1816  avctx->coded_frame->pts = pkt.pts;
1817  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1818  }
1819 
1820  /* free any side data since we cannot return it */
1821  if (pkt.side_data_elems > 0) {
1822  int i;
1823  for (i = 0; i < pkt.side_data_elems; i++)
1824  av_free(pkt.side_data[i].data);
1825  av_freep(&pkt.side_data);
1826  pkt.side_data_elems = 0;
1827  }
1828 
1829  return ret ? ret : pkt.size;
1830 }
1831 
1832 #endif
1833 
1835  AVPacket *avpkt,
1836  const AVFrame *frame,
1837  int *got_packet_ptr)
1838 {
1839  int ret;
1840  AVPacket user_pkt = *avpkt;
1841  int needs_realloc = !user_pkt.data;
1842 
1843  *got_packet_ptr = 0;
1844 
1847  return ff_thread_video_encode_frame(avctx, avpkt, frame, got_packet_ptr);
1848 
1849  if ((avctx->flags&CODEC_FLAG_PASS1) && avctx->stats_out)
1850  avctx->stats_out[0] = '\0';
1851 
1852  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1853  av_free_packet(avpkt);
1854  av_init_packet(avpkt);
1855  avpkt->size = 0;
1856  return 0;
1857  }
1858 
1859  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
1860  return AVERROR(EINVAL);
1861 
1862  av_assert0(avctx->codec->encode2);
1863 
1864  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1865  av_assert0(ret <= 0);
1866 
1867  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
1868  needs_realloc = 0;
1869  if (user_pkt.data) {
1870  if (user_pkt.size >= avpkt->size) {
1871  memcpy(user_pkt.data, avpkt->data, avpkt->size);
1872  } else {
1873  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
1874  avpkt->size = user_pkt.size;
1875  ret = -1;
1876  }
1877  avpkt->buf = user_pkt.buf;
1878  avpkt->data = user_pkt.data;
1879  avpkt->destruct = user_pkt.destruct;
1880  } else {
1881  if (av_dup_packet(avpkt) < 0) {
1882  ret = AVERROR(ENOMEM);
1883  }
1884  }
1885  }
1886 
1887  if (!ret) {
1888  if (!*got_packet_ptr)
1889  avpkt->size = 0;
1890  else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
1891  avpkt->pts = avpkt->dts = frame->pts;
1892 
1893  if (needs_realloc && avpkt->data) {
1894  ret = av_buffer_realloc(&avpkt->buf, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
1895  if (ret >= 0)
1896  avpkt->data = avpkt->buf->data;
1897  }
1898 
1899  avctx->frame_number++;
1900  }
1901 
1902  if (ret < 0 || !*got_packet_ptr)
1903  av_free_packet(avpkt);
1904  else
1906 
1907  emms_c();
1908  return ret;
1909 }
1910 
1911 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1912  const AVSubtitle *sub)
1913 {
1914  int ret;
1915  if (sub->start_display_time) {
1916  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1917  return -1;
1918  }
1919 
1920  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
1921  avctx->frame_number++;
1922  return ret;
1923 }
1924 
1925 /**
1926  * Attempt to guess proper monotonic timestamps for decoded video frames
1927  * which might have incorrect times. Input timestamps may wrap around, in
1928  * which case the output will as well.
1929  *
1930  * @param pts the pts field of the decoded AVPacket, as passed through
1931  * AVFrame.pkt_pts
1932  * @param dts the dts field of the decoded AVPacket
1933  * @return one of the input values, may be AV_NOPTS_VALUE
1934  */
1935 static int64_t guess_correct_pts(AVCodecContext *ctx,
1936  int64_t reordered_pts, int64_t dts)
1937 {
1938  int64_t pts = AV_NOPTS_VALUE;
1939 
1940  if (dts != AV_NOPTS_VALUE) {
1942  ctx->pts_correction_last_dts = dts;
1943  }
1944  if (reordered_pts != AV_NOPTS_VALUE) {
1945  ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
1946  ctx->pts_correction_last_pts = reordered_pts;
1947  }
1949  && reordered_pts != AV_NOPTS_VALUE)
1950  pts = reordered_pts;
1951  else
1952  pts = dts;
1953 
1954  return pts;
1955 }
1956 
1957 static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1958 {
1959  int size = 0;
1960  const uint8_t *data;
1961  uint32_t flags;
1962 
1963  if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE))
1964  return;
1965 
1966  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1967  if (!data || size < 4)
1968  return;
1969  flags = bytestream_get_le32(&data);
1970  size -= 4;
1971  if (size < 4) /* Required for any of the changes */
1972  return;
1974  avctx->channels = bytestream_get_le32(&data);
1975  size -= 4;
1976  }
1978  if (size < 8)
1979  return;
1980  avctx->channel_layout = bytestream_get_le64(&data);
1981  size -= 8;
1982  }
1983  if (size < 4)
1984  return;
1986  avctx->sample_rate = bytestream_get_le32(&data);
1987  size -= 4;
1988  }
1990  if (size < 8)
1991  return;
1992  avctx->width = bytestream_get_le32(&data);
1993  avctx->height = bytestream_get_le32(&data);
1994  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
1995  size -= 8;
1996  }
1997 }
1998 
2000 {
2001  int size, ret = 0;
2002  const uint8_t *side_metadata;
2003  const uint8_t *end;
2004 
2005  side_metadata = av_packet_get_side_data(avctx->pkt,
2007  if (!side_metadata)
2008  goto end;
2009  end = side_metadata + size;
2010  if (size && end[-1])
2011  return AVERROR_INVALIDDATA;
2012  while (side_metadata < end) {
2013  const uint8_t *key = side_metadata;
2014  const uint8_t *val = side_metadata + strlen(key) + 1;
2015  int ret;
2016 
2017  if (val >= end)
2018  return AVERROR_INVALIDDATA;
2019 
2020  ret = av_dict_set(avpriv_frame_get_metadatap(frame), key, val, 0);
2021  if (ret < 0)
2022  break;
2023  side_metadata = val + strlen(val) + 1;
2024  }
2025 end:
2026  return ret;
2027 }
2028 
2030  int *got_picture_ptr,
2031  const AVPacket *avpkt)
2032 {
2033  AVCodecInternal *avci = avctx->internal;
2034  int ret;
2035  // copy to ensure we do not change avpkt
2036  AVPacket tmp = *avpkt;
2037 
2038  if (!avctx->codec)
2039  return AVERROR(EINVAL);
2040  if (avctx->codec->type != AVMEDIA_TYPE_VIDEO) {
2041  av_log(avctx, AV_LOG_ERROR, "Invalid media type for video\n");
2042  return AVERROR(EINVAL);
2043  }
2044 
2045  *got_picture_ptr = 0;
2046  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
2047  return AVERROR(EINVAL);
2048 
2049  avcodec_get_frame_defaults(picture);
2050 
2051  if (!avctx->refcounted_frames)
2052  av_frame_unref(&avci->to_free);
2053 
2054  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
2055  int did_split = av_packet_split_side_data(&tmp);
2056  apply_param_change(avctx, &tmp);
2057  avctx->pkt = &tmp;
2059  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
2060  &tmp);
2061  else {
2062  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
2063  &tmp);
2064  picture->pkt_dts = avpkt->dts;
2065 
2066  if(!avctx->has_b_frames){
2067  av_frame_set_pkt_pos(picture, avpkt->pos);
2068  }
2069  //FIXME these should be under if(!avctx->has_b_frames)
2070  /* get_buffer is supposed to set frame parameters */
2071  if (!(avctx->codec->capabilities & CODEC_CAP_DR1)) {
2072  if (!picture->sample_aspect_ratio.num) picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
2073  if (!picture->width) picture->width = avctx->width;
2074  if (!picture->height) picture->height = avctx->height;
2075  if (picture->format == AV_PIX_FMT_NONE) picture->format = avctx->pix_fmt;
2076  }
2077  }
2078  add_metadata_from_side_data(avctx, picture);
2079 
2080  emms_c(); //needed to avoid an emms_c() call before every return;
2081 
2082  avctx->pkt = NULL;
2083  if (did_split) {
2085  if(ret == tmp.size)
2086  ret = avpkt->size;
2087  }
2088 
2089  if (ret < 0 && picture->data[0])
2090  av_frame_unref(picture);
2091 
2092  if (*got_picture_ptr) {
2093  if (!avctx->refcounted_frames) {
2094  avci->to_free = *picture;
2095  avci->to_free.extended_data = avci->to_free.data;
2096  memset(picture->buf, 0, sizeof(picture->buf));
2097  }
2098 
2099  avctx->frame_number++;
2101  guess_correct_pts(avctx,
2102  picture->pkt_pts,
2103  picture->pkt_dts));
2104  }
2105  } else
2106  ret = 0;
2107 
2108  /* many decoders assign whole AVFrames, thus overwriting extended_data;
2109  * make sure it's set correctly */
2110  picture->extended_data = picture->data;
2111 
2112  return ret;
2113 }
2114 
2115 #if FF_API_OLD_DECODE_AUDIO
2116 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
2117  int *frame_size_ptr,
2118  AVPacket *avpkt)
2119 {
2120  AVFrame frame = { { 0 } };
2121  int ret, got_frame = 0;
2122 
2123  if (avctx->get_buffer != avcodec_default_get_buffer) {
2124  av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
2125  "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
2126  av_log(avctx, AV_LOG_ERROR, "Please port your application to "
2127  "avcodec_decode_audio4()\n");
2130  }
2131 
2132  ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
2133 
2134  if (ret >= 0 && got_frame) {
2135  int ch, plane_size;
2136  int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
2137  int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
2138  frame.nb_samples,
2139  avctx->sample_fmt, 1);
2140  if (*frame_size_ptr < data_size) {
2141  av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
2142  "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
2143  return AVERROR(EINVAL);
2144  }
2145 
2146  memcpy(samples, frame.extended_data[0], plane_size);
2147 
2148  if (planar && avctx->channels > 1) {
2149  uint8_t *out = ((uint8_t *)samples) + plane_size;
2150  for (ch = 1; ch < avctx->channels; ch++) {
2151  memcpy(out, frame.extended_data[ch], plane_size);
2152  out += plane_size;
2153  }
2154  }
2155  *frame_size_ptr = data_size;
2156  } else {
2157  *frame_size_ptr = 0;
2158  }
2159  return ret;
2160 }
2161 
2162 #endif
2163 
2165  AVFrame *frame,
2166  int *got_frame_ptr,
2167  const AVPacket *avpkt)
2168 {
2169  AVCodecInternal *avci = avctx->internal;
2170  int planar, channels;
2171  int ret = 0;
2172 
2173  *got_frame_ptr = 0;
2174 
2175  if (!avpkt->data && avpkt->size) {
2176  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
2177  return AVERROR(EINVAL);
2178  }
2179  if (!avctx->codec)
2180  return AVERROR(EINVAL);
2181  if (avctx->codec->type != AVMEDIA_TYPE_AUDIO) {
2182  av_log(avctx, AV_LOG_ERROR, "Invalid media type for audio\n");
2183  return AVERROR(EINVAL);
2184  }
2185 
2187 
2188  if (!avctx->refcounted_frames)
2189  av_frame_unref(&avci->to_free);
2190 
2191  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
2192  uint8_t *side;
2193  int side_size;
2194  uint32_t discard_padding = 0;
2195  // copy to ensure we do not change avpkt
2196  AVPacket tmp = *avpkt;
2197  int did_split = av_packet_split_side_data(&tmp);
2198  apply_param_change(avctx, &tmp);
2199 
2200  avctx->pkt = &tmp;
2202  ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp);
2203  else {
2204  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, &tmp);
2205  frame->pkt_dts = avpkt->dts;
2206  }
2207  if (ret >= 0 && *got_frame_ptr) {
2208  add_metadata_from_side_data(avctx, frame);
2209  avctx->frame_number++;
2211  guess_correct_pts(avctx,
2212  frame->pkt_pts,
2213  frame->pkt_dts));
2214  if (frame->format == AV_SAMPLE_FMT_NONE)
2215  frame->format = avctx->sample_fmt;
2216  if (!frame->channel_layout)
2217  frame->channel_layout = avctx->channel_layout;
2218  if (!av_frame_get_channels(frame))
2219  av_frame_set_channels(frame, avctx->channels);
2220  if (!frame->sample_rate)
2221  frame->sample_rate = avctx->sample_rate;
2222  }
2223 
2224  side= av_packet_get_side_data(avctx->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
2225  if(side && side_size>=10) {
2226  avctx->internal->skip_samples = AV_RL32(side);
2227  av_log(avctx, AV_LOG_DEBUG, "skip %d samples due to side data\n",
2228  avctx->internal->skip_samples);
2229  discard_padding = AV_RL32(side + 4);
2230  }
2231  if (avctx->internal->skip_samples && *got_frame_ptr) {
2232  if(frame->nb_samples <= avctx->internal->skip_samples){
2233  *got_frame_ptr = 0;
2234  avctx->internal->skip_samples -= frame->nb_samples;
2235  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
2236  avctx->internal->skip_samples);
2237  } else {
2239  frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format);
2240  if(avctx->pkt_timebase.num && avctx->sample_rate) {
2241  int64_t diff_ts = av_rescale_q(avctx->internal->skip_samples,
2242  (AVRational){1, avctx->sample_rate},
2243  avctx->pkt_timebase);
2244  if(frame->pkt_pts!=AV_NOPTS_VALUE)
2245  frame->pkt_pts += diff_ts;
2246  if(frame->pkt_dts!=AV_NOPTS_VALUE)
2247  frame->pkt_dts += diff_ts;
2248  if (av_frame_get_pkt_duration(frame) >= diff_ts)
2249  av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts);
2250  } else {
2251  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
2252  }
2253  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
2254  avctx->internal->skip_samples, frame->nb_samples);
2255  frame->nb_samples -= avctx->internal->skip_samples;
2256  avctx->internal->skip_samples = 0;
2257  }
2258  }
2259 
2260  if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) {
2261  if (discard_padding == frame->nb_samples) {
2262  *got_frame_ptr = 0;
2263  } else {
2264  if(avctx->pkt_timebase.num && avctx->sample_rate) {
2265  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
2266  (AVRational){1, avctx->sample_rate},
2267  avctx->pkt_timebase);
2268  if (av_frame_get_pkt_duration(frame) >= diff_ts)
2269  av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts);
2270  } else {
2271  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
2272  }
2273  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
2274  discard_padding, frame->nb_samples);
2275  frame->nb_samples -= discard_padding;
2276  }
2277  }
2278 
2279  avctx->pkt = NULL;
2280  if (did_split) {
2282  if(ret == tmp.size)
2283  ret = avpkt->size;
2284  }
2285 
2286  if (ret >= 0 && *got_frame_ptr) {
2287  if (!avctx->refcounted_frames) {
2288  avci->to_free = *frame;
2289  avci->to_free.extended_data = avci->to_free.data;
2290  memset(frame->buf, 0, sizeof(frame->buf));
2291  frame->extended_buf = NULL;
2292  frame->nb_extended_buf = 0;
2293  }
2294  } else if (frame->data[0])
2295  av_frame_unref(frame);
2296  }
2297 
2298  /* many decoders assign whole AVFrames, thus overwriting extended_data;
2299  * make sure it's set correctly; assume decoders that actually use
2300  * extended_data are doing it correctly */
2301  if (*got_frame_ptr) {
2302  planar = av_sample_fmt_is_planar(frame->format);
2303  channels = av_frame_get_channels(frame);
2304  if (!(planar && channels > AV_NUM_DATA_POINTERS))
2305  frame->extended_data = frame->data;
2306  } else {
2307  frame->extended_data = NULL;
2308  }
2309 
2310  return ret;
2311 }
2312 
2313 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
2315  AVPacket *outpkt, const AVPacket *inpkt)
2316 {
2317 #if CONFIG_ICONV
2318  iconv_t cd = (iconv_t)-1;
2319  int ret = 0;
2320  char *inb, *outb;
2321  size_t inl, outl;
2322  AVPacket tmp;
2323 #endif
2324 
2325  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0)
2326  return 0;
2327 
2328 #if CONFIG_ICONV
2329  cd = iconv_open("UTF-8", avctx->sub_charenc);
2330  av_assert0(cd != (iconv_t)-1);
2331 
2332  inb = inpkt->data;
2333  inl = inpkt->size;
2334 
2335  if (inl >= INT_MAX / UTF8_MAX_BYTES - FF_INPUT_BUFFER_PADDING_SIZE) {
2336  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
2337  ret = AVERROR(ENOMEM);
2338  goto end;
2339  }
2340 
2341  ret = av_new_packet(&tmp, inl * UTF8_MAX_BYTES);
2342  if (ret < 0)
2343  goto end;
2344  outpkt->buf = tmp.buf;
2345  outpkt->data = tmp.data;
2346  outpkt->size = tmp.size;
2347  outb = outpkt->data;
2348  outl = outpkt->size;
2349 
2350  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
2351  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
2352  outl >= outpkt->size || inl != 0) {
2353  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
2354  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
2355  av_free_packet(&tmp);
2356  ret = AVERROR(errno);
2357  goto end;
2358  }
2359  outpkt->size -= outl;
2360  memset(outpkt->data + outpkt->size, 0, outl);
2361 
2362 end:
2363  if (cd != (iconv_t)-1)
2364  iconv_close(cd);
2365  return ret;
2366 #else
2367  av_assert0(!"requesting subtitles recoding without iconv");
2368 #endif
2369 }
2370 
2371 static int utf8_check(const uint8_t *str)
2372 {
2373  const uint8_t *byte;
2374  uint32_t codepoint, min;
2375 
2376  while (*str) {
2377  byte = str;
2378  GET_UTF8(codepoint, *(byte++), return 0;);
2379  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2380  1 << (5 * (byte - str) - 4);
2381  if (codepoint < min || codepoint >= 0x110000 ||
2382  codepoint == 0xFFFE /* BOM */ ||
2383  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
2384  return 0;
2385  str = byte;
2386  }
2387  return 1;
2388 }
2389 
2391  int *got_sub_ptr,
2392  AVPacket *avpkt)
2393 {
2394  int i, ret = 0;
2395 
2396  if (!avpkt->data && avpkt->size) {
2397  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
2398  return AVERROR(EINVAL);
2399  }
2400  if (!avctx->codec)
2401  return AVERROR(EINVAL);
2402  if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
2403  av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
2404  return AVERROR(EINVAL);
2405  }
2406 
2407  *got_sub_ptr = 0;
2409 
2410  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
2411  AVPacket pkt_recoded;
2412  AVPacket tmp = *avpkt;
2413  int did_split = av_packet_split_side_data(&tmp);
2414  //apply_param_change(avctx, &tmp);
2415 
2416  pkt_recoded = tmp;
2417  ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
2418  if (ret < 0) {
2419  *got_sub_ptr = 0;
2420  } else {
2421  avctx->pkt = &pkt_recoded;
2422 
2423  if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
2424  sub->pts = av_rescale_q(avpkt->pts,
2425  avctx->pkt_timebase, AV_TIME_BASE_Q);
2426  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2427  av_assert1((ret >= 0) >= !!*got_sub_ptr &&
2428  !!*got_sub_ptr >= !!sub->num_rects);
2429 
2430  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
2431  avctx->pkt_timebase.num) {
2432  AVRational ms = { 1, 1000 };
2433  sub->end_display_time = av_rescale_q(avpkt->duration,
2434  avctx->pkt_timebase, ms);
2435  }
2436 
2437  for (i = 0; i < sub->num_rects; i++) {
2438  if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
2439  av_log(avctx, AV_LOG_ERROR,
2440  "Invalid UTF-8 in decoded subtitles text; "
2441  "maybe missing -sub_charenc option\n");
2442  avsubtitle_free(sub);
2443  return AVERROR_INVALIDDATA;
2444  }
2445  }
2446 
2447  if (tmp.data != pkt_recoded.data) { // did we recode?
2448  /* prevent from destroying side data from original packet */
2449  pkt_recoded.side_data = NULL;
2450  pkt_recoded.side_data_elems = 0;
2451 
2452  av_free_packet(&pkt_recoded);
2453  }
2455  sub->format = 0;
2456  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
2457  sub->format = 1;
2458  avctx->pkt = NULL;
2459  }
2460 
2461  if (did_split) {
2463  if(ret == tmp.size)
2464  ret = avpkt->size;
2465  }
2466 
2467  if (*got_sub_ptr)
2468  avctx->frame_number++;
2469  }
2470 
2471  return ret;
2472 }
2473 
2475 {
2476  int i;
2477 
2478  for (i = 0; i < sub->num_rects; i++) {
2479  av_freep(&sub->rects[i]->pict.data[0]);
2480  av_freep(&sub->rects[i]->pict.data[1]);
2481  av_freep(&sub->rects[i]->pict.data[2]);
2482  av_freep(&sub->rects[i]->pict.data[3]);
2483  av_freep(&sub->rects[i]->text);
2484  av_freep(&sub->rects[i]->ass);
2485  av_freep(&sub->rects[i]);
2486  }
2487 
2488  av_freep(&sub->rects);
2489 
2490  memset(sub, 0, sizeof(AVSubtitle));
2491 }
2492 
2494 {
2495  int ret = 0;
2496 
2498 
2499  ret = avcodec_close(avctx);
2500 
2501  ff_lock_avcodec(NULL);
2502  return ret;
2503 }
2504 
2506 {
2507  int ret;
2508 
2509  if (!avctx)
2510  return 0;
2511 
2512  ret = ff_lock_avcodec(avctx);
2513  if (ret < 0)
2514  return ret;
2515 
2516  if (avcodec_is_open(avctx)) {
2517  FramePool *pool = avctx->internal->pool;
2518  int i;
2520  avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
2523  ff_lock_avcodec(avctx);
2524  }
2525  if (HAVE_THREADS && avctx->thread_opaque)
2526  ff_thread_free(avctx);
2527  if (avctx->codec && avctx->codec->close)
2528  avctx->codec->close(avctx);
2529  avctx->coded_frame = NULL;
2530  avctx->internal->byte_buffer_size = 0;
2531  av_freep(&avctx->internal->byte_buffer);
2532  if (!avctx->refcounted_frames)
2533  av_frame_unref(&avctx->internal->to_free);
2534  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
2535  av_buffer_pool_uninit(&pool->pools[i]);
2536  av_freep(&avctx->internal->pool);
2537  av_freep(&avctx->internal);
2538  }
2539 
2540  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
2541  av_opt_free(avctx->priv_data);
2542  av_opt_free(avctx);
2543  av_freep(&avctx->priv_data);
2544  if (av_codec_is_encoder(avctx->codec))
2545  av_freep(&avctx->extradata);
2546  avctx->codec = NULL;
2547  avctx->active_thread_type = 0;
2548 
2550  return 0;
2551 }
2552 
2554 {
2555  switch(id){
2556  //This is for future deprecatec codec ids, its empty since
2557  //last major bump but will fill up again over time, please don't remove it
2558 // case AV_CODEC_ID_UTVIDEO_DEPRECATED: return AV_CODEC_ID_UTVIDEO;
2566  default : return id;
2567  }
2568 }
2569 
2570 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
2571 {
2572  AVCodec *p, *experimental = NULL;
2573  p = first_avcodec;
2574  id= remap_deprecated_codec_id(id);
2575  while (p) {
2576  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
2577  p->id == id) {
2578  if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
2579  experimental = p;
2580  } else
2581  return p;
2582  }
2583  p = p->next;
2584  }
2585  return experimental;
2586 }
2587 
2589 {
2590  return find_encdec(id, 1);
2591 }
2592 
2594 {
2595  AVCodec *p;
2596  if (!name)
2597  return NULL;
2598  p = first_avcodec;
2599  while (p) {
2600  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
2601  return p;
2602  p = p->next;
2603  }
2604  return NULL;
2605 }
2606 
2608 {
2609  return find_encdec(id, 0);
2610 }
2611 
2613 {
2614  AVCodec *p;
2615  if (!name)
2616  return NULL;
2617  p = first_avcodec;
2618  while (p) {
2619  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
2620  return p;
2621  p = p->next;
2622  }
2623  return NULL;
2624 }
2625 
2626 const char *avcodec_get_name(enum AVCodecID id)
2627 {
2628  const AVCodecDescriptor *cd;
2629  AVCodec *codec;
2630 
2631  if (id == AV_CODEC_ID_NONE)
2632  return "none";
2633  cd = avcodec_descriptor_get(id);
2634  if (cd)
2635  return cd->name;
2636  av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
2637  codec = avcodec_find_decoder(id);
2638  if (codec)
2639  return codec->name;
2640  codec = avcodec_find_encoder(id);
2641  if (codec)
2642  return codec->name;
2643  return "unknown_codec";
2644 }
2645 
2646 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
2647 {
2648  int i, len, ret = 0;
2649 
2650 #define TAG_PRINT(x) \
2651  (((x) >= '0' && (x) <= '9') || \
2652  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2653  ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2654 
2655  for (i = 0; i < 4; i++) {
2656  len = snprintf(buf, buf_size,
2657  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
2658  buf += len;
2659  buf_size = buf_size > len ? buf_size - len : 0;
2660  ret += len;
2661  codec_tag >>= 8;
2662  }
2663  return ret;
2664 }
2665 
2666 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
2667 {
2668  const char *codec_type;
2669  const char *codec_name;
2670  const char *profile = NULL;
2671  const AVCodec *p;
2672  int bitrate;
2673  AVRational display_aspect_ratio;
2674 
2675  if (!buf || buf_size <= 0)
2676  return;
2677  codec_type = av_get_media_type_string(enc->codec_type);
2678  codec_name = avcodec_get_name(enc->codec_id);
2679  if (enc->profile != FF_PROFILE_UNKNOWN) {
2680  if (enc->codec)
2681  p = enc->codec;
2682  else
2683  p = encode ? avcodec_find_encoder(enc->codec_id) :
2685  if (p)
2686  profile = av_get_profile_name(p, enc->profile);
2687  }
2688 
2689  snprintf(buf, buf_size, "%s: %s", codec_type ? codec_type : "unknown",
2690  codec_name);
2691  buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
2692 
2693  if (enc->codec && strcmp(enc->codec->name, codec_name))
2694  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", enc->codec->name);
2695 
2696  if (profile)
2697  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
2698  if (enc->codec_tag) {
2699  char tag_buf[32];
2700  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
2701  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2702  " (%s / 0x%04X)", tag_buf, enc->codec_tag);
2703  }
2704 
2705  switch (enc->codec_type) {
2706  case AVMEDIA_TYPE_VIDEO:
2707  if (enc->pix_fmt != AV_PIX_FMT_NONE) {
2708  char detail[256] = "(";
2709  const char *colorspace_name;
2710  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2711  ", %s",
2713  if (enc->bits_per_raw_sample &&
2715  av_strlcatf(detail, sizeof(detail), "%d bpc, ", enc->bits_per_raw_sample);
2717  av_strlcatf(detail, sizeof(detail),
2718  enc->color_range == AVCOL_RANGE_MPEG ? "tv, ": "pc, ");
2719 
2720  colorspace_name = av_get_colorspace_name(enc->colorspace);
2721  if (colorspace_name)
2722  av_strlcatf(detail, sizeof(detail), "%s, ", colorspace_name);
2723 
2724  if (strlen(detail) > 1) {
2725  detail[strlen(detail) - 2] = 0;
2726  av_strlcatf(buf, buf_size, "%s)", detail);
2727  }
2728  }
2729  if (enc->width) {
2730  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2731  ", %dx%d",
2732  enc->width, enc->height);
2733  if (enc->sample_aspect_ratio.num) {
2734  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
2735  enc->width * enc->sample_aspect_ratio.num,
2736  enc->height * enc->sample_aspect_ratio.den,
2737  1024 * 1024);
2738  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2739  " [SAR %d:%d DAR %d:%d]",
2741  display_aspect_ratio.num, display_aspect_ratio.den);
2742  }
2743  if (av_log_get_level() >= AV_LOG_DEBUG) {
2744  int g = av_gcd(enc->time_base.num, enc->time_base.den);
2745  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2746  ", %d/%d",
2747  enc->time_base.num / g, enc->time_base.den / g);
2748  }
2749  }
2750  if (encode) {
2751  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2752  ", q=%d-%d", enc->qmin, enc->qmax);
2753  }
2754  break;
2755  case AVMEDIA_TYPE_AUDIO:
2756  if (enc->sample_rate) {
2757  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2758  ", %d Hz", enc->sample_rate);
2759  }
2760  av_strlcat(buf, ", ", buf_size);
2761  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
2762  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
2763  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2764  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
2765  }
2766  break;
2767  case AVMEDIA_TYPE_DATA:
2768  if (av_log_get_level() >= AV_LOG_DEBUG) {
2769  int g = av_gcd(enc->time_base.num, enc->time_base.den);
2770  if (g)
2771  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2772  ", %d/%d",
2773  enc->time_base.num / g, enc->time_base.den / g);
2774  }
2775  break;
2776  case AVMEDIA_TYPE_SUBTITLE:
2777  if (enc->width)
2778  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2779  ", %dx%d", enc->width, enc->height);
2780  break;
2781  default:
2782  return;
2783  }
2784  if (encode) {
2785  if (enc->flags & CODEC_FLAG_PASS1)
2786  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2787  ", pass 1");
2788  if (enc->flags & CODEC_FLAG_PASS2)
2789  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2790  ", pass 2");
2791  }
2792  bitrate = get_bit_rate(enc);
2793  if (bitrate != 0) {
2794  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2795  ", %d kb/s", bitrate / 1000);
2796  } else if (enc->rc_max_rate > 0) {
2797  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2798  ", max. %d kb/s", enc->rc_max_rate / 1000);
2799  }
2800 }
2801 
2802 const char *av_get_profile_name(const AVCodec *codec, int profile)
2803 {
2804  const AVProfile *p;
2805  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
2806  return NULL;
2807 
2808  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
2809  if (p->profile == profile)
2810  return p->name;
2811 
2812  return NULL;
2813 }
2814 
2815 unsigned avcodec_version(void)
2816 {
2817 // av_assert0(AV_CODEC_ID_V410==164);
2820 // av_assert0(AV_CODEC_ID_BMV_AUDIO==86071);
2821  av_assert0(AV_CODEC_ID_SRT==94216);
2823 
2829  return LIBAVCODEC_VERSION_INT;
2830 }
2831 
2832 const char *avcodec_configuration(void)
2833 {
2834  return FFMPEG_CONFIGURATION;
2835 }
2836 
2837 const char *avcodec_license(void)
2838 {
2839 #define LICENSE_PREFIX "libavcodec license: "
2840  return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
2841 }
2842 
2844 {
2846  ff_thread_flush(avctx);
2847  else if (avctx->codec->flush)
2848  avctx->codec->flush(avctx);
2849 
2850  avctx->pts_correction_last_pts =
2851  avctx->pts_correction_last_dts = INT64_MIN;
2852 
2853  if (!avctx->refcounted_frames)
2854  av_frame_unref(&avctx->internal->to_free);
2855 }
2856 
2858 {
2859  switch (codec_id) {
2860  case AV_CODEC_ID_8SVX_EXP:
2861  case AV_CODEC_ID_8SVX_FIB:
2862  case AV_CODEC_ID_ADPCM_CT:
2869  return 4;
2870  case AV_CODEC_ID_PCM_ALAW:
2871  case AV_CODEC_ID_PCM_MULAW:
2872  case AV_CODEC_ID_PCM_S8:
2874  case AV_CODEC_ID_PCM_U8:
2875  case AV_CODEC_ID_PCM_ZORK:
2876  return 8;
2877  case AV_CODEC_ID_PCM_S16BE:
2879  case AV_CODEC_ID_PCM_S16LE:
2881  case AV_CODEC_ID_PCM_U16BE:
2882  case AV_CODEC_ID_PCM_U16LE:
2883  return 16;
2885  case AV_CODEC_ID_PCM_S24BE:
2886  case AV_CODEC_ID_PCM_S24LE:
2888  case AV_CODEC_ID_PCM_U24BE:
2889  case AV_CODEC_ID_PCM_U24LE:
2890  return 24;
2891  case AV_CODEC_ID_PCM_S32BE:
2892  case AV_CODEC_ID_PCM_S32LE:
2894  case AV_CODEC_ID_PCM_U32BE:
2895  case AV_CODEC_ID_PCM_U32LE:
2896  case AV_CODEC_ID_PCM_F32BE:
2897  case AV_CODEC_ID_PCM_F32LE:
2898  return 32;
2899  case AV_CODEC_ID_PCM_F64BE:
2900  case AV_CODEC_ID_PCM_F64LE:
2901  return 64;
2902  default:
2903  return 0;
2904  }
2905 }
2906 
2908 {
2909  static const enum AVCodecID map[AV_SAMPLE_FMT_NB][2] = {
2920  };
2921  if (fmt < 0 || fmt >= AV_SAMPLE_FMT_NB)
2922  return AV_CODEC_ID_NONE;
2923  if (be < 0 || be > 1)
2924  be = AV_NE(1, 0);
2925  return map[fmt][be];
2926 }
2927 
2929 {
2930  switch (codec_id) {
2932  return 2;
2934  return 3;
2938  case AV_CODEC_ID_ADPCM_SWF:
2939  case AV_CODEC_ID_ADPCM_MS:
2940  return 4;
2941  default:
2942  return av_get_exact_bits_per_sample(codec_id);
2943  }
2944 }
2945 
2946 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
2947 {
2948  int id, sr, ch, ba, tag, bps;
2949 
2950  id = avctx->codec_id;
2951  sr = avctx->sample_rate;
2952  ch = avctx->channels;
2953  ba = avctx->block_align;
2954  tag = avctx->codec_tag;
2955  bps = av_get_exact_bits_per_sample(avctx->codec_id);
2956 
2957  /* codecs with an exact constant bits per sample */
2958  if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2959  return (frame_bytes * 8LL) / (bps * ch);
2960  bps = avctx->bits_per_coded_sample;
2961 
2962  /* codecs with a fixed packet duration */
2963  switch (id) {
2964  case AV_CODEC_ID_ADPCM_ADX: return 32;
2965  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
2966  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
2967  case AV_CODEC_ID_AMR_NB:
2968  case AV_CODEC_ID_EVRC:
2969  case AV_CODEC_ID_GSM:
2970  case AV_CODEC_ID_QCELP:
2971  case AV_CODEC_ID_RA_288: return 160;
2972  case AV_CODEC_ID_AMR_WB:
2973  case AV_CODEC_ID_GSM_MS: return 320;
2974  case AV_CODEC_ID_MP1: return 384;
2975  case AV_CODEC_ID_ATRAC1: return 512;
2976  case AV_CODEC_ID_ATRAC3: return 1024;
2977  case AV_CODEC_ID_MP2:
2978  case AV_CODEC_ID_MUSEPACK7: return 1152;
2979  case AV_CODEC_ID_AC3: return 1536;
2980  }
2981 
2982  if (sr > 0) {
2983  /* calc from sample rate */
2984  if (id == AV_CODEC_ID_TTA)
2985  return 256 * sr / 245;
2986 
2987  if (ch > 0) {
2988  /* calc from sample rate and channels */
2989  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
2990  return (480 << (sr / 22050)) / ch;
2991  }
2992  }
2993 
2994  if (ba > 0) {
2995  /* calc from block_align */
2996  if (id == AV_CODEC_ID_SIPR) {
2997  switch (ba) {
2998  case 20: return 160;
2999  case 19: return 144;
3000  case 29: return 288;
3001  case 37: return 480;
3002  }
3003  } else if (id == AV_CODEC_ID_ILBC) {
3004  switch (ba) {
3005  case 38: return 160;
3006  case 50: return 240;
3007  }
3008  }
3009  }
3010 
3011  if (frame_bytes > 0) {
3012  /* calc from frame_bytes only */
3013  if (id == AV_CODEC_ID_TRUESPEECH)
3014  return 240 * (frame_bytes / 32);
3015  if (id == AV_CODEC_ID_NELLYMOSER)
3016  return 256 * (frame_bytes / 64);
3017  if (id == AV_CODEC_ID_RA_144)
3018  return 160 * (frame_bytes / 20);
3019  if (id == AV_CODEC_ID_G723_1)
3020  return 240 * (frame_bytes / 24);
3021 
3022  if (bps > 0) {
3023  /* calc from frame_bytes and bits_per_coded_sample */
3024  if (id == AV_CODEC_ID_ADPCM_G726)
3025  return frame_bytes * 8 / bps;
3026  }
3027 
3028  if (ch > 0) {
3029  /* calc from frame_bytes and channels */
3030  switch (id) {
3031  case AV_CODEC_ID_ADPCM_AFC:
3032  return frame_bytes / (9 * ch) * 16;
3033  case AV_CODEC_ID_ADPCM_DTK:
3034  return frame_bytes / (16 * ch) * 28;
3035  case AV_CODEC_ID_ADPCM_4XM:
3037  return (frame_bytes - 4 * ch) * 2 / ch;
3039  return (frame_bytes - 4) * 2 / ch;
3041  return (frame_bytes - 8) * 2 / ch;
3042  case AV_CODEC_ID_ADPCM_XA:
3043  return (frame_bytes / 128) * 224 / ch;
3045  return (frame_bytes - 6 - ch) / ch;
3046  case AV_CODEC_ID_ROQ_DPCM:
3047  return (frame_bytes - 8) / ch;
3048  case AV_CODEC_ID_XAN_DPCM:
3049  return (frame_bytes - 2 * ch) / ch;
3050  case AV_CODEC_ID_MACE3:
3051  return 3 * frame_bytes / ch;
3052  case AV_CODEC_ID_MACE6:
3053  return 6 * frame_bytes / ch;
3054  case AV_CODEC_ID_PCM_LXF:
3055  return 2 * (frame_bytes / (5 * ch));
3056  case AV_CODEC_ID_IAC:
3057  case AV_CODEC_ID_IMC:
3058  return 4 * frame_bytes / ch;
3059  }
3060 
3061  if (tag) {
3062  /* calc from frame_bytes, channels, and codec_tag */
3063  if (id == AV_CODEC_ID_SOL_DPCM) {
3064  if (tag == 3)
3065  return frame_bytes / ch;
3066  else
3067  return frame_bytes * 2 / ch;
3068  }
3069  }
3070 
3071  if (ba > 0) {
3072  /* calc from frame_bytes, channels, and block_align */
3073  int blocks = frame_bytes / ba;
3074  switch (avctx->codec_id) {
3076  if (bps < 2 || bps > 5)
3077  return 0;
3078  return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3080  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3082  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3084  return blocks * ((ba - 4 * ch) * 2 / ch);
3085  case AV_CODEC_ID_ADPCM_MS:
3086  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3087  }
3088  }
3089 
3090  if (bps > 0) {
3091  /* calc from frame_bytes, channels, and bits_per_coded_sample */
3092  switch (avctx->codec_id) {
3093  case AV_CODEC_ID_PCM_DVD:
3094  if(bps<4)
3095  return 0;
3096  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3098  if(bps<4)
3099  return 0;
3100  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
3101  case AV_CODEC_ID_S302M:
3102  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3103  }
3104  }
3105  }
3106  }
3107 
3108  return 0;
3109 }
3110 
3111 #if !HAVE_THREADS
3113 {
3114  return -1;
3115 }
3116 
3117 #endif
3118 
3119 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
3120 {
3121  unsigned int n = 0;
3122 
3123  while (v >= 0xff) {
3124  *s++ = 0xff;
3125  v -= 0xff;
3126  n++;
3127  }
3128  *s = v;
3129  n++;
3130  return n;
3131 }
3132 
3133 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
3134 {
3135  int i;
3136  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
3137  return i;
3138 }
3139 
3140 #if FF_API_MISSING_SAMPLE
3142 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
3143 {
3144  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your FFmpeg "
3145  "version to the newest one from Git. If the problem still "
3146  "occurs, it means that your file has a feature which has not "
3147  "been implemented.\n", feature);
3148  if(want_sample)
3149  av_log_ask_for_sample(avc, NULL);
3150 }
3151 
3152 void av_log_ask_for_sample(void *avc, const char *msg, ...)
3153 {
3154  va_list argument_list;
3155 
3156  va_start(argument_list, msg);
3157 
3158  if (msg)
3159  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
3160  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
3161  "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
3162  "and contact the ffmpeg-devel mailing list.\n");
3163 
3164  va_end(argument_list);
3165 }
3167 #endif /* FF_API_MISSING_SAMPLE */
3168 
3169 static AVHWAccel *first_hwaccel = NULL;
3170 
3172 {
3173  AVHWAccel **p = &first_hwaccel;
3174  hwaccel->next = NULL;
3175  while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
3176  p = &(*p)->next;
3177 }
3178 
3180 {
3181  return hwaccel ? hwaccel->next : first_hwaccel;
3182 }
3183 
3185 {
3186  AVHWAccel *hwaccel = NULL;
3187 
3188  while ((hwaccel = av_hwaccel_next(hwaccel)))
3189  if (hwaccel->id == codec_id
3190  && hwaccel->pix_fmt == pix_fmt)
3191  return hwaccel;
3192  return NULL;
3193 }
3194 
3195 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
3196 {
3197  if (lockmgr_cb) {
3198  if (lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
3199  return -1;
3200  if (lockmgr_cb(&avformat_mutex, AV_LOCK_DESTROY))
3201  return -1;
3202  }
3203 
3204  lockmgr_cb = cb;
3205 
3206  if (lockmgr_cb) {
3207  if (lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
3208  return -1;
3209  if (lockmgr_cb(&avformat_mutex, AV_LOCK_CREATE))
3210  return -1;
3211  }
3212  return 0;
3213 }
3214 
3216 {
3217  if (lockmgr_cb) {
3218  if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
3219  return -1;
3220  }
3221  entangled_thread_counter++;
3222  if (entangled_thread_counter != 1) {
3223  av_log(log_ctx, AV_LOG_ERROR, "Insufficient thread locking around avcodec_open/close()\n");
3224  if (!lockmgr_cb)
3225  av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n");
3226  ff_avcodec_locked = 1;
3228  return AVERROR(EINVAL);
3229  }
3230  av_assert0(!ff_avcodec_locked);
3231  ff_avcodec_locked = 1;
3232  return 0;
3233 }
3234 
3236 {
3237  av_assert0(ff_avcodec_locked);
3238  ff_avcodec_locked = 0;
3239  entangled_thread_counter--;
3240  if (lockmgr_cb) {
3241  if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE))
3242  return -1;
3243  }
3244  return 0;
3245 }
3246 
3248 {
3249  if (lockmgr_cb) {
3250  if ((*lockmgr_cb)(&avformat_mutex, AV_LOCK_OBTAIN))
3251  return -1;
3252  }
3253  return 0;
3254 }
3255 
3257 {
3258  if (lockmgr_cb) {
3259  if ((*lockmgr_cb)(&avformat_mutex, AV_LOCK_RELEASE))
3260  return -1;
3261  }
3262  return 0;
3263 }
3264 
3265 unsigned int avpriv_toupper4(unsigned int x)
3266 {
3267  return av_toupper(x & 0xFF) +
3268  (av_toupper((x >> 8) & 0xFF) << 8) +
3269  (av_toupper((x >> 16) & 0xFF) << 16) +
3270  (av_toupper((x >> 24) & 0xFF) << 24);
3271 }
3272 
3274 {
3275  int ret;
3276 
3277  dst->owner = src->owner;
3278 
3279  ret = av_frame_ref(dst->f, src->f);
3280  if (ret < 0)
3281  return ret;
3282 
3283  if (src->progress &&
3284  !(dst->progress = av_buffer_ref(src->progress))) {
3285  ff_thread_release_buffer(dst->owner, dst);
3286  return AVERROR(ENOMEM);
3287  }
3288 
3289  return 0;
3290 }
3291 
3292 #if !HAVE_THREADS
3293 
3295 {
3296  return avctx->get_format(avctx, fmt);
3297 }
3298 
3300 {
3301  f->owner = avctx;
3302  return ff_get_buffer(avctx, f->f, flags);
3303 }
3304 
3306 {
3307  av_frame_unref(f->f);
3308 }
3309 
3311 {
3312 }
3313 
3314 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
3315 {
3316 }
3317 
3318 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
3319 {
3320 }
3321 
3323 {
3324  return 1;
3325 }
3326 
3328 {
3329  return 0;
3330 }
3331 
3333 {
3334 }
3335 
3336 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
3337 {
3338 }
3339 
3340 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
3341 {
3342 }
3343 
3344 #endif
3345 
3347 {
3348  AVCodec *c= avcodec_find_decoder(codec_id);
3349  if(!c)
3350  c= avcodec_find_encoder(codec_id);
3351  if(c)
3352  return c->type;
3353 
3354  if (codec_id <= AV_CODEC_ID_NONE)
3355  return AVMEDIA_TYPE_UNKNOWN;
3356  else if (codec_id < AV_CODEC_ID_FIRST_AUDIO)
3357  return AVMEDIA_TYPE_VIDEO;
3358  else if (codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
3359  return AVMEDIA_TYPE_AUDIO;
3360  else if (codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
3361  return AVMEDIA_TYPE_SUBTITLE;
3362 
3363  return AVMEDIA_TYPE_UNKNOWN;
3364 }
3365 
3367 {
3368  return !!s->internal;
3369 }
3370 
3372 {
3373  int ret;
3374  char *str;
3375 
3376  ret = av_bprint_finalize(buf, &str);
3377  if (ret < 0)
3378  return ret;
3379  avctx->extradata = str;
3380  /* Note: the string is NUL terminated (so extradata can be read as a
3381  * string), but the ending character is not accounted in the size (in
3382  * binary formats you are likely not supposed to mux that character). When
3383  * extradata is copied, it is also padded with FF_INPUT_BUFFER_PADDING_SIZE
3384  * zeros. */
3385  avctx->extradata_size = buf->len;
3386  return 0;
3387 }
3388 
3390  const uint8_t *end,
3391  uint32_t *av_restrict state)
3392 {
3393  int i;
3394 
3395  av_assert0(p <= end);
3396  if (p >= end)
3397  return end;
3398 
3399  for (i = 0; i < 3; i++) {
3400  uint32_t tmp = *state << 8;
3401  *state = tmp + *(p++);
3402  if (tmp == 0x100 || p == end)
3403  return p;
3404  }
3405 
3406  while (p < end) {
3407  if (p[-1] > 1 ) p += 3;
3408  else if (p[-2] ) p += 2;
3409  else if (p[-3]|(p[-1]-1)) p++;
3410  else {
3411  p++;
3412  break;
3413  }
3414  }
3415 
3416  p = FFMIN(p, end) - 4;
3417  *state = AV_RB32(p);
3418 
3419  return p + 4;
3420 }
const char * name
Definition: avisynth_c.h:675
#define FF_SANE_NB_CHANNELS
Definition: internal.h:35
int ff_unlock_avcodec(void)
Definition: utils.c:3235
#define CONFIG_FRAME_THREAD_ENCODER
Definition: config.h:423
#define UTF8_MAX_BYTES
Definition: utils.c:2313
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: pthread.c:920
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1500
planar YUV 4:2:0 40bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples, big-endian)
Definition: avcodec.h:4668
const char const char void * val
Definition: avisynth_c.h:671
planar YUV 4:4:4 40bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples, big-endian)
Definition: avcodec.h:4666
planar YUV 4:4:4, 27bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), big-endian
Definition: avcodec.h:4626
planar YUV 4:2:2 48bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples, little-endian)
Definition: avcodec.h:4671
float v
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:2570
const char * s
Definition: avisynth_c.h:668
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:2832
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
static int shift(int a, int b)
Definition: sonic.c:78
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:90
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:2837
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: avcodec.h:2850
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1979
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:105
int size
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:279
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
int avcodec_default_execute2(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2, int, int), void *arg, int *ret, int count)
#define c2
Definition: idct_sh4.c:27
int avpriv_unlock_avformat(void)
Definition: utils.c:3256
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:47
int stride_align[AV_NUM_DATA_POINTERS]
Definition: internal.h:49
A dummy id pointing at the start of audio codecs.
Definition: avcodec.h:309
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:234
enum AVCodecID id
Definition: mxfenc.c:90
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:704
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:827
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1324
const char * fmt
Definition: avisynth_c.h:669
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:3013
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:3195
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2945
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:3123
Unlock the mutex.
Definition: avcodec.h:4959
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: avcodec.h:4153
AVFrame * f
Definition: thread.h:36
planar GBR 4:4:4 27bpp, big-endian
Definition: avcodec.h:4641
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:63
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1092
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:2788
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
Definition: pthread.c:592
planar YUV 4:2:2, 18bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), little-endian
Definition: avcodec.h:4631
const char * g
Definition: vf_curves.c:104
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:703
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:535
int width
Definition: internal.h:48
planar YUV 4:2:2, 20bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), big-endian
Definition: avcodec.h:4624
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: pthread.c:995
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2250
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:1071
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2619
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1064
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: avcodec.h:4536
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1848
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:384
planar YUV 4:4:4, 30bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), little-endian
Definition: avcodec.h:4629
planar YUV 4:2:0 40bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples, little-endian)
Definition: avcodec.h:4669
planar YUV 4:4:4, 30bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), big-endian
Definition: avcodec.h:4628
planar YUV 4:2:2, 16bpp, (1 Cr &amp; Cb sample per 2x1 Y samples)
Definition: avcodec.h:4538
int num
numerator
Definition: rational.h:44
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:233
int size
Definition: avcodec.h:1064
const char * b
Definition: vf_curves.c:105
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:140
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:88
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:3048
static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: utils.c:801
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:1860
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:1517
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: utils.c:1560
enum AVMediaType codec_type
Definition: rtp.c:37
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: avcodec.h:570
os2threads to pthreads wrapper
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1342
int samples
Definition: internal.h:53
unsigned num_rects
Definition: avcodec.h:3180
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:158
A dummy ID pointing at the start of various fake codecs.
Definition: avcodec.h:499
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
Definition: pthread.c:1147
enum AVMediaType type
Definition: avcodec.h:2935
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:2646
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:42
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3007
AVChromaLocation
X X 3 4 X X are luma samples, 1 2 1-6 are possible chroma positions X X 5 6 X 0 is undefined/unknown ...
Definition: avcodec.h:646
planar YUV 4:2:2,24bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), little-endian
Definition: avcodec.h:4701
planar YUV 4:4:4 32bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples)
Definition: avcodec.h:4693
int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
Definition: utils.c:1597
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2570
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
Definition: pthread.c:1136
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: utils.c:408
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: avcodec.h:4553
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:2390
attribute_deprecated void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
Pixel format.
Definition: avcodec.h:4533
int av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:247
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:382
attribute_deprecated int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
Definition: avcodec.h:2022
Picture data structure.
Definition: avcodec.h:3121
int profile
profile
Definition: avcodec.h:2678
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
void av_frame_set_channels(AVFrame *frame, int val)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1910
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:68
Y , 8bpp.
Definition: avcodec.h:4542
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:4956
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1254
attribute_deprecated void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2036
#define FFMPEG_LICENSE
Definition: config.h:5
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:82
planar YUV 4:4:4 40bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples, little-endian)
Definition: avcodec.h:4667
attribute_deprecated void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
static void * codec_mutex
Definition: utils.c:117
planar YUV 4:2:2, 32bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), little-endian
Definition: avcodec.h:4598
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1046
unsigned 8 bits
Definition: samplefmt.h:51
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1265
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
#define FFMAX3(a, b, c)
Definition: avcodec.h:924
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:210
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:431
planar YUV 4:2:0 25bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples, big-endian)
Definition: avcodec.h:4662
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:205
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: avcodec.h:4537
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:393
static int volatile entangled_thread_counter
Definition: utils.c:116
planar YUV 4:2:0,18bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), little-endian
Definition: avcodec.h:4697
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: utils.c:153
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:96
#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:2868
HMTX pthread_mutex_t
Definition: os2threads.h:38
int height
Definition: internal.h:48
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Definition: utils.c:1039
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1881
Lock the mutex.
Definition: avcodec.h:4958
uint8_t
#define CONFIG_DSPUTIL
Definition: config.h:421
planar YUV 4:4:4, 48bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), big-endian
Definition: avcodec.h:4601
#define AV_PIX_FMT_RGB555
Definition: avcodec.h:4938
signed 32 bits, planar
Definition: samplefmt.h:59
attribute_deprecated void(* destruct)(struct AVPacket *)
Definition: avcodec.h:1088
planar YUV 4:2:2 30bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples, big-endian)
Definition: avcodec.h:4664
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: avcodec.h:4552
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
static AVCodec * first_avcodec
Definition: utils.c:183
Multithreading support functions.
planar YUV 4:4:4 64bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples, big-endian)
Definition: avcodec.h:4672
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:2612
#define emms_c()
Definition: internal.h:49
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:182
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
#define LICENSE_PREFIX
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
Definition: frame.c:247
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
Definition: utils.c:1834
planar YUV 4:2:0 22.5bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples), big-endian
Definition: avcodec.h:4656
#define FF_CEIL_RSHIFT(a, b)
Definition: avcodec.h:916
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:27
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:125
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:742
int planes
Definition: internal.h:51
void * frame_thread_encoder
Definition: internal.h:104
signed 32 bits
Definition: samplefmt.h:53
const char data[16]
Definition: mxf.c:68
attribute_deprecated void void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:3171
static int(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:111
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1190
uint32_t tag
Definition: movenc.c:961
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:3273
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: avcodec.h:4556
int ff_thread_init(AVCodecContext *avctx)
Definition: pthread.c:1112
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:155
#define av_restrict
Definition: config.h:9
planar YUV 4:2:2 24bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples)
Definition: avcodec.h:4694
planar YUV 4:4:4 36bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples), big-endian
Definition: avcodec.h:4660
enum AVPixelFormat pix_fmt
Definition: v4l.c:62
planar YUV 4:2:0, 13.5bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), little-endian
Definition: avcodec.h:4621
planar YUV 4:2:0, 20bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples)
Definition: avcodec.h:4571
#define AV_NUM_DATA_POINTERS
Definition: frame.h:97
int lowres
low resolution decoding, 1-&gt; 1/2 size, 2-&gt;1/4 size
Definition: avcodec.h:2580
struct AVPacket::@25 * side_data
Additional packet data that can be provided by the container.
AVHWAccel * av_hwaccel_next(AVHWAccel *hwaccel)
If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL...
Definition: utils.c:3179
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2563
uint8_t * data[AV_NUM_DATA_POINTERS]
pointers to the image data planes
Definition: avcodec.h:3122
int duration
Duration of this packet in AVStream-&gt;time_base units, 0 if unknown.
Definition: avcodec.h:1085
const OptionDef options[]
Definition: ffserver.c:4682
int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:3371
#define AVERROR_EXPERIMENTAL
planar YUV 4:4:4 36bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples), little-endian
Definition: avcodec.h:4661
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
AVCodecContext * owner
Definition: thread.h:37
#define FF_BUFFER_TYPE_INTERNAL
Definition: avcodec.h:896
signed 16 bits
Definition: samplefmt.h:52
FramePool * pool
Definition: internal.h:96
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1113
static AVFrame * frame
Definition: demuxing.c:51
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:247
static av_cold void avcodec_init(void)
Definition: utils.c:193
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:289
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:176
Libavcodec version macros.
int(* close)(AVCodecContext *)
Definition: avcodec.h:3008
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:2505
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:83
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:2822
enum AVCodecID id
Definition: avcodec.h:2936
#define STRIDE_ALIGN
Definition: utils.c:244
static AVHWAccel * first_hwaccel
Definition: utils.c:3169
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: pthread.c:684
AVSubtitleRect ** rects
Definition: avcodec.h:3181
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:45
int64_t av_frame_get_pkt_duration(const AVFrame *frame)
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:102
int width
width and height of the video frame
Definition: frame.h:145
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1427
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:2928
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
#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:77
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt-&gt;size from avpkt-&gt;data into picture.
Definition: utils.c:2029
Create a mutex.
Definition: avcodec.h:4957
int 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:1145
#define CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: avcodec.h:819
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:769
#define MAKE_ACCESSORS(str, name, type, field)
Definition: internal.h:88
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: avcodec.h:937
planar GBRA 4:4:4:4 32bpp
Definition: avcodec.h:4712
void av_packet_free_side_data(AVPacket *pkt)
Convenience function to free all the side data stored.
Definition: avpacket.c:270
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: avcodec.h:4548
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:2588
int qmax
maximum quantizer
Definition: avcodec.h:2166
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:774
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:2851
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2615
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:3366
const char * r
Definition: vf_curves.c:103
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: avcodec.h:4570
int capabilities
Codec capabilities.
Definition: avcodec.h:2941
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:2626
struct AVCodec * codec
Definition: avcodec.h:1155
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
const char * arg
Definition: jacosubdec.c:69
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1234
planar YUV 4:1:1, 12bpp, (1 Cr &amp; Cb sample per 4x1 Y samples)
Definition: avcodec.h:4541
planar YUV 4:2:2 27bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples), little-endian
Definition: avcodec.h:4659
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
int rc_max_rate
maximum bitrate
Definition: avcodec.h:2213
int64_t av_const av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:55
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
Definition: utils.c:3346
int av_log_get_level(void)
Get the current log level.
Definition: log.c:288
int av_frame_get_channels(const AVFrame *frame)
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:150
enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame)
int side_data_elems
Definition: avcodec.h:1079
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val)
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: pthread.c:1029
planar YUV 4:4:4,42bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), little-endian
Definition: avcodec.h:4707
int av_buffer_realloc(AVBufferRef **buf, int size)
Reallocate a given buffer.
Definition: buffer.c:156
enum AVCodecID codec_id
Definition: mov_chan.c:433
planar YUV 4:1:1, 12bpp, (1 Cr &amp; Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: avcodec.h:4715
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:1128
int avpriv_lock_avformat(void)
Definition: utils.c:3247
unsigned 8 bits, planar
Definition: samplefmt.h:57
Libavcodec external API header.
void * thread_opaque
thread opaque Can be used by execute() to store some per AVCodecContext stuff.
Definition: avcodec.h:2664
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
int av_samples_copy(uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:225
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:257
#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:2870
void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val)
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1069
planar YUV 4:4:4, 48bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), little-endian
Definition: avcodec.h:4600
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1934
uint32_t end_display_time
Definition: avcodec.h:3179
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:3182
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2191
int av_packet_merge_side_data(AVPacket *pkt)
Definition: avpacket.c:340
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:354
struct AVHWAccel * next
Definition: avcodec.h:3056
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:543
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition: avcodec.h:2869
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(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:2993
goto fail
Definition: avfilter.c:963
int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options)
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:70
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:580
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:155
#define FF_ARRAY_ELEMS(a)
Definition: avcodec.h:929
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:231
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:59
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: utils.c:986
Buffer to print data progressively.
Definition: bprint.h:77
static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:467
int bit_rate
the average bitrate
Definition: avcodec.h:1204
attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt)
Wrapper function which calls avcodec_decode_audio4.
uint8_t * data
The data buffer.
Definition: buffer.h:89
Opaque data information usually continuous.
Definition: avcodec.h:2233
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3161
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:351
void * av_realloc(void *ptr, size_t size) 1(2)
Allocate or reallocate a block of memory.
Definition: mem.c:141
float y
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
Definition: avcodec.h:587
void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val)
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:2857
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread.c:1021
int channels
Definition: internal.h:52
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:1033
ret
Definition: avfilter.c:961
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:323
int width
picture width / height.
Definition: avcodec.h:1314
Not part of ABI.
Definition: avcodec.h:654
int priv_data_size
Definition: avcodec.h:2960
int profile
Definition: avcodec.h:2911
attribute_deprecated int reference
Definition: frame.h:212
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
#define LIBAVCODEC_VERSION_MICRO
Definition: version.h:33
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx-&gt;thread_count == 0 (auto).
Definition: avcodec.h:823
#define FFMIN(a, b)
Definition: avcodec.h:925
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: os2threads.h:83
planar GBR 4:4:4 27bpp, little-endian
Definition: avcodec.h:4642
uint16_t format
Definition: avcodec.h:3177
planar GBR 4:4:4 36bpp, little-endian
Definition: avcodec.h:4709
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt-&gt;size from avpkt-&gt;data into frame.
Definition: utils.c:2164
int ff_alloc_packet(AVPacket *avpkt, int size)
Definition: utils.c:1552
planar YUV 4:2:2, 20bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), little-endian
Definition: avcodec.h:4625
int64_t reordered_opaque
opaque 64bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:2494
int n
Definition: avisynth_c.h:588
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:616
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2148
int ff_alloc_entries(AVCodecContext *avctx, int count)
Definition: pthread.c:1163
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2679
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3171
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers, this array will hold all the references which cannot fit into AVFrame.buf.
Definition: frame.h:380
#define LIBAVCODEC_VERSION_INT
Definition: version.h:35
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2376
static pthread_mutex_t * mutex
Definition: w32pthreads.h:69
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:571
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:329
static int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
Definition: utils.c:139
void ff_reset_entries(AVCodecContext *avctx)
Definition: pthread.c:1189
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2426
planar YUV 4:4:4,36bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), little-endian
Definition: avcodec.h:4705
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2596
planar YUV 4:2:0, 15bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), big-endian
Definition: avcodec.h:4622
int linesize[4]
Definition: internal.h:50
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
Definition: utils.c:120
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:2867
planar YUV 4:2:0, 15bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), little-endian
Definition: avcodec.h:4623
int av_packet_split_side_data(AVPacket *pkt)
Definition: avpacket.c:380
planar YUV 4:2:2, 32bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), big-endian
Definition: avcodec.h:4599
int av_codec_get_max_lowres(const AVCodec *codec)
Definition: utils.c:1104
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:2843
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: avcodec.h:4546
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:2607
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:157
const AVS_VideoInfo int align
Definition: avisynth_c.h:695
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:185
AVBufferRef * progress
Definition: thread.h:40
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1893
#define attribute_align_arg
Definition: internal.h:56
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor Code outside libavcodec should access this field using: av_codec_{get,set}_codec_descriptor(avctx)
Definition: avcodec.h:2831
planar YUV 4:2:0, 12bpp, (1 Cr &amp; Cb sample per 2x2 Y samples)
Definition: avcodec.h:4534
AVFrame to_free
Definition: internal.h:94
planar YUV 4:4:0 (1 Cr &amp; Cb sample per 1x2 Y samples)
Definition: avcodec.h:4569
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:106
static int width
Definition: utils.c:158
planar GBR 4:4:4 42bpp, big-endian
Definition: avcodec.h:4710
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:2859
planar YUV 4:2:2,28bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), big-endian
Definition: avcodec.h:4702
attribute_deprecated void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
AVS_Value src
Definition: avisynth_c.h:523
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: utils.c:693
planar YUV 4:2:2 30bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples, little-endian)
Definition: avcodec.h:4665
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:108
static int add_metadata_from_side_data(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:1999
enum AVMediaType codec_type
Definition: avcodec.h:1154
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:2990
A list of zero terminated key/value strings.
Definition: avcodec.h:985
attribute_deprecated int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
#define FFMAX(a, b)
Definition: avcodec.h:923
enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
Return the PCM codec associated with a sample format.
Definition: utils.c:2907
enum AVCodecID codec_id
Definition: avcodec.h:1157
AVHWAccel.
Definition: avcodec.h:3021
planar YUV 4:2:0 22.5bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples), little-endian ...
Definition: avcodec.h:4657
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avcodec.h:2290
int av_opt_set_dict(void *obj, struct AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1326
int sample_rate
samples per second
Definition: avcodec.h:1873
planar YUV 4:4:4 64bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples, little-endian)
Definition: avcodec.h:4673
struct AVCodec * next
Definition: avcodec.h:2961
void avpriv_color_frame(AVFrame *frame, const int color[4])
Definition: utils.c:670
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:228
planar YUV 4:2:0,21bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), little-endian
Definition: avcodec.h:4699
uint8_t flags
Definition: pixdesc.h:78
int debug
debug
Definition: avcodec.h:2442
const char * name
short name for the profile
Definition: avcodec.h:2912
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: avcodec.h:4535
planar YUV 4:2:2 48bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples, big-endian)
Definition: avcodec.h:4670
main external API structure.
Definition: avcodec.h:1146
static int recode_subtitle(AVCodecContext *avctx, AVPacket *outpkt, const AVPacket *inpkt)
Definition: utils.c:2314
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2607
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:373
planar GBR 4:4:4 36bpp, big-endian
Definition: avcodec.h:4708
int qmin
minimum quantizer
Definition: avcodec.h:2159
volatile int ff_avcodec_locked
Definition: utils.c:115
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:2474
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:177
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:941
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
Definition: pthread.c:892
unsigned int codec_tag
fourcc (LSB first, so &quot;ABCD&quot; -&gt; (&#39;D&#39;&lt;&lt;24) + (&#39;C&#39;&lt;&lt;16) + (&#39;B&#39;&lt;&lt;8) + &#39;A&#39;).
Definition: avcodec.h:1172
planar GBR 4:4:4 24bpp
Definition: avcodec.h:4640
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect-&gt;pict fiel...
Definition: avcodec.h:565
void av_frame_set_pkt_pos(AVFrame *frame, int64_t val)
void * buf
Definition: avisynth_c.h:594
attribute_deprecated int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict)
int extradata_size
Definition: avcodec.h:1255
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:366
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
static void avcodec_get_subtitle_defaults(AVSubtitle *sub)
Definition: utils.c:1109
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:3119
int ff_init_buffer_info(AVCodecContext *s, AVFrame *frame)
does needed setup of pkt_pts/pos and such for (re)get_buffer();
Definition: utils.c:716
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
static int utf8_check(const uint8_t *str)
Definition: utils.c:2371
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:1046
int coded_height
Definition: avcodec.h:1324
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:325
Describe the class of an AVClass context structure.
Definition: log.h:50
int sample_rate
Sample rate of the audio data.
Definition: frame.h:349
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:81
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
Definition: avcodec.h:1389
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:86
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:110
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: avcodec.h:2425
av_cold void ff_dsputil_static_init(void)
Definition: dsputil.c:2647
void av_buffer_pool_uninit(AVBufferPool **pool)
Mark the pool as being available for freeing.
Definition: buffer.c:236
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:3265
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1841
rational number numerator/denominator
Definition: rational.h:43
#define CONFIG_MEMORY_POISONING
Definition: config.h:403
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2588
uint8_t * data
Definition: avcodec.h:1063
Recommmends skipping the specified number of samples.
Definition: avcodec.h:969
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:37
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:47
void 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:281
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:70
AVHWAccel * ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
Return the hardware accelerated codec for codec codec_id and pixel format pix_fmt.
Definition: utils.c:3184
AVMediaType
Definition: avutil.h:180
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:2944
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:109
planar YUV 4:4:4, 24bpp, (1 Cr &amp; Cb sample per 1x1 Y samples)
Definition: avcodec.h:4539
#define AV_NE(be, le)
Definition: avcodec.h:908
planar YUV 4:2:2,28bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), little-endian
Definition: avcodec.h:4703
const char * av_get_colorspace_name(enum AVColorSpace val)
Get the name of a colorspace.
Definition: frame.c:73
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
Definition: avcodec.h:2135
#define FF_DEBUG_BUFFERS
Definition: avcodec.h:2458
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avcodec.h:2230
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:1157
#define snprintf
Definition: snprintf.h:34
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:2946
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: pthread.c:666
static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
Definition: utils.c:2553
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:92
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:527
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:187
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
planar GBR 4:4:4 30bpp, big-endian
Definition: avcodec.h:4643
void * priv_data
Definition: avcodec.h:1182
static uint32_t state
Definition: trasher.c:27
int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples)
Encode an audio frame from samples into buf.
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:249
static int flags
Definition: cpu.c:45
planar YUV 4:2:2, 18bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), big-endian
Definition: avcodec.h:4630
enum AVColorRange av_frame_get_color_range(const AVFrame *frame)
Y , 16bpp, little-endian.
Definition: avcodec.h:4568
static int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:206
uint8_t max_lowres
maximum value for lowres supported by the decoder, no direct access, use av_codec_get_max_lowres() ...
Definition: avcodec.h:2948
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:194
A reference to a data buffer.
Definition: buffer.h:81
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:76
#define CODEC_FLAG_EMU_EDGE
Don&#39;t draw edges.
Definition: avcodec.h:706
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:1318
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:1967
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
Definition: buffer.c:206
common internal api header.
planar YUV 4:2:0,21bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), big-endian
Definition: avcodec.h:4698
enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
Converts swscale x/y chroma position to AVChromaLocation.
Definition: utils.c:420
Free mutex resources.
Definition: avcodec.h:4960
planar YUV 4:2:0, 24bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), little-endian
Definition: avcodec.h:4596
static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1957
static int64_t guess_correct_pts(AVCodecContext *ctx, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
Definition: utils.c:1935
static double c[64]
uint32_t start_display_time
Definition: avcodec.h:3178
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:170
#define FFALIGN(x, a)
Definition: avcodec.h:930
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:797
AVProfile.
Definition: avcodec.h:2910
enum AVCodecID id
Codec implemented by the hardware accelerator.
Definition: avcodec.h:3041
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:49
int den
denominator
Definition: rational.h:45
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:2802
planar YUV 4:2:0, 24bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), big-endian
Definition: avcodec.h:4597
unsigned bps
Definition: movenc.c:962
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2943
planar YUV 4:2:0 25bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples, little-endian)
Definition: avcodec.h:4663
#define FFMPEG_CONFIGURATION
Definition: config.h:4
DSP utils.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:2666
planar YUV 4:4:4,42bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), big-endian
Definition: avcodec.h:4706
static int lowres
Definition: ffplay.c:310
planar YUV 4:2:0,18bpp, (1 Cr &amp; Cb sample per 2x2 Y samples), big-endian
Definition: avcodec.h:4696
#define AV_RB32(x)
Definition: intreadwrite.h:258
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: avcodec.h:4551
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:949
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:91
#define AVERROR_BUG
#define AVERROR_INVALIDDATA
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
#define TAG_PRINT(x)
as in Berlin toast format
Definition: avcodec.h:415
#define AV_RL32(x)
Definition: intreadwrite.h:275
int len
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int channels
number of audio channels
Definition: avcodec.h:1874
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
Definition: os2threads.h:104
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:2950
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:2815
static void * avformat_mutex
Definition: utils.c:118
#define EDGE_WIDTH
Definition: dsputil.h:261
int key_frame
1 -&gt; keyframe, 0-&gt; not
Definition: frame.h:162
static int get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:1115
Opaque data information usually sparse.
Definition: avcodec.h:2235
planar GBR 4:4:4 42bpp, little-endian
Definition: avcodec.h:4711
w32threads to pthreads wrapper
#define AVERROR(e)
float, planar
Definition: samplefmt.h:60
planar YUV 4:4:4,36bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), big-endian
Definition: avcodec.h:4704
static struct twinvq_data tab
unsigned int byte_buffer_size
Definition: internal.h:102
#define HAVE_THREADS
Definition: config.h:286
void avcodec_free_frame(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: utils.c:1084
int64_t dts
Decompression timestamp in AVStream-&gt;time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1062
void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:215
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: avcodec.h:2852
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1904
int height
Definition: frame.h:145
void ff_frame_thread_encoder_free(AVCodecContext *avctx)
the normal 219*2^(n-8) &quot;MPEG&quot; YUV ranges
Definition: frame.h:48
void INT64 INT64 count
Definition: avisynth_c.h:594
int64_t pts_correction_num_faulty_pts
Current statistics for PTS correction.
Definition: avcodec.h:2849
planar YUV 4:2:2,24bpp, (1 Cr &amp; Cb sample per 2x1 Y samples), big-endian
Definition: avcodec.h:4700
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
Definition: os2threads.h:97
signed 16 bits, planar
Definition: samplefmt.h:58
int ff_codec_close_recursive(AVCodecContext *avctx)
Call avcodec_close recursively, counterpart to avcodec_open2_recursive.
Definition: utils.c:2493
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void av_frame_set_pkt_size(AVFrame *frame, int val)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
Definition: internal.h:181
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: pthread.c:702
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:3164
static AVPacket pkt
Definition: demuxing.c:52
int nb_channels
8 bit with PIX_FMT_RGB32 palette
Definition: avcodec.h:4545
planar GBR 4:4:4 30bpp, little-endian
Definition: avcodec.h:4644
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: avcodec.h:2805
double, planar
Definition: samplefmt.h:61
planar YUV 4:4:4, 27bpp, (1 Cr &amp; Cb sample per 1x1 Y samples), little-endian
Definition: avcodec.h:4627
int(* init)(AVCodecContext *)
Definition: avcodec.h:2992
int format
Definition: internal.h:47
attribute_deprecated int type
Definition: frame.h:281
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:2593
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: avcodec.h:4547
float min
#define GET_UTF8(val, GET_BYTE, ERROR)
This structure stores compressed data.
Definition: avcodec.h:1040
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:101
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: utils.c:1911
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3005
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:910
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:150
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2421
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:2946
int64_t pts
Presentation timestamp in AVStream-&gt;time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1056
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...) av_printf_format(3
Append output to a string, according to a format.
A dummy ID pointing at the start of subtitle codecs.
Definition: avcodec.h:474
planar YUV 4:1:0, 9bpp, (1 Cr &amp; Cb sample per 4x4 Y samples)
Definition: avcodec.h:4540
Y , 16bpp, big-endian.
Definition: avcodec.h:4567
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:3133
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avcodec.h:2278
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:2951
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:1009
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.
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...
Definition: internal.h:92
The following 12 formats have the disadvantage of needing 1 format for each bit depth.
Definition: avcodec.h:4620
planar YUV 4:2:2 27bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples), big-endian
Definition: avcodec.h:4658
attribute_deprecated int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic)
int ff_lock_avcodec(AVCodecContext *log_ctx)
Definition: utils.c:3215