Libav
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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
28 #include "config.h"
29 #include "libavutil/attributes.h"
30 #include "libavutil/avassert.h"
31 #include "libavutil/avstring.h"
33 #include "libavutil/crc.h"
34 #include "libavutil/frame.h"
35 #include "libavutil/internal.h"
36 #include "libavutil/mathematics.h"
37 #include "libavutil/pixdesc.h"
38 #include "libavutil/imgutils.h"
39 #include "libavutil/samplefmt.h"
40 #include "libavutil/dict.h"
41 #include "avcodec.h"
42 #include "dsputil.h"
43 #include "libavutil/opt.h"
44 #include "thread.h"
45 #include "internal.h"
46 #include "bytestream.h"
47 #include "version.h"
48 #include <stdlib.h>
49 #include <stdarg.h>
50 #include <limits.h>
51 #include <float.h>
52 
53 static int volatile entangled_thread_counter = 0;
54 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op);
55 static void *codec_mutex;
56 static void *avformat_mutex;
57 
58 #if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
59 FF_SYMVER(void*, av_fast_realloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
60 {
61  return av_fast_realloc(ptr, size, min_size);
62 }
63 
64 FF_SYMVER(void, av_fast_malloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
65 {
66  av_fast_malloc(ptr, size, min_size);
67 }
68 #endif
69 
70 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
71 {
72  void **p = ptr;
73  if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
74  av_freep(p);
75  *size = 0;
76  return;
77  }
78  av_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE);
79  if (*size)
80  memset((uint8_t *)*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
81 }
82 
83 /* encoder management */
85 
87 {
88  if (c)
89  return c->next;
90  else
91  return first_avcodec;
92 }
93 
94 static av_cold void avcodec_init(void)
95 {
96  static int initialized = 0;
97 
98  if (initialized != 0)
99  return;
100  initialized = 1;
101 
102  if (CONFIG_DSPUTIL)
104 }
105 
106 int av_codec_is_encoder(const AVCodec *codec)
107 {
108  return codec && (codec->encode_sub || codec->encode2);
109 }
110 
111 int av_codec_is_decoder(const AVCodec *codec)
112 {
113  return codec && codec->decode;
114 }
115 
117 {
118  AVCodec **p;
119  avcodec_init();
120  p = &first_avcodec;
121  while (*p != NULL)
122  p = &(*p)->next;
123  *p = codec;
124  codec->next = NULL;
125 
126  if (codec->init_static_data)
127  codec->init_static_data(codec);
128 }
129 
130 #if FF_API_EMU_EDGE
132 {
133  return EDGE_WIDTH;
134 }
135 #endif
136 
137 #if FF_API_SET_DIMENSIONS
139 {
140  ff_set_dimensions(s, width, height);
141 }
142 #endif
143 
145 {
146  int ret = av_image_check_size(width, height, 0, s);
147 
148  if (ret < 0)
149  width = height = 0;
150  s->width = s->coded_width = width;
151  s->height = s->coded_height = height;
152 
153  return ret;
154 }
155 
157  enum AVMatrixEncoding matrix_encoding)
158 {
159  AVFrameSideData *side_data;
160  enum AVMatrixEncoding *data;
161 
163  if (!side_data)
165  sizeof(enum AVMatrixEncoding));
166 
167  if (!side_data)
168  return AVERROR(ENOMEM);
169 
170  data = (enum AVMatrixEncoding*)side_data->data;
171  *data = matrix_encoding;
172 
173  return 0;
174 }
175 
176 #if HAVE_NEON || ARCH_PPC || HAVE_MMX
177 # define STRIDE_ALIGN 16
178 #else
179 # define STRIDE_ALIGN 8
180 #endif
181 
183  int linesize_align[AV_NUM_DATA_POINTERS])
184 {
185  int i;
186  int w_align = 1;
187  int h_align = 1;
188 
189  switch (s->pix_fmt) {
190  case AV_PIX_FMT_YUV420P:
191  case AV_PIX_FMT_YUYV422:
192  case AV_PIX_FMT_UYVY422:
193  case AV_PIX_FMT_YUV422P:
194  case AV_PIX_FMT_YUV440P:
195  case AV_PIX_FMT_YUV444P:
196  case AV_PIX_FMT_GBRP:
197  case AV_PIX_FMT_GRAY8:
198  case AV_PIX_FMT_GRAY16BE:
199  case AV_PIX_FMT_GRAY16LE:
200  case AV_PIX_FMT_YUVJ420P:
201  case AV_PIX_FMT_YUVJ422P:
202  case AV_PIX_FMT_YUVJ440P:
203  case AV_PIX_FMT_YUVJ444P:
204  case AV_PIX_FMT_YUVA420P:
205  case AV_PIX_FMT_YUVA422P:
206  case AV_PIX_FMT_YUVA444P:
223  case AV_PIX_FMT_GBRP9LE:
224  case AV_PIX_FMT_GBRP9BE:
225  case AV_PIX_FMT_GBRP10LE:
226  case AV_PIX_FMT_GBRP10BE:
227  w_align = 16; //FIXME assume 16 pixel per macroblock
228  h_align = 16 * 2; // interlaced needs 2 macroblocks height
229  break;
230  case AV_PIX_FMT_YUV411P:
232  w_align = 32;
233  h_align = 8;
234  break;
235  case AV_PIX_FMT_YUV410P:
236  if (s->codec_id == AV_CODEC_ID_SVQ1) {
237  w_align = 64;
238  h_align = 64;
239  }
240  case AV_PIX_FMT_RGB555:
241  if (s->codec_id == AV_CODEC_ID_RPZA) {
242  w_align = 4;
243  h_align = 4;
244  }
245  case AV_PIX_FMT_PAL8:
246  case AV_PIX_FMT_BGR8:
247  case AV_PIX_FMT_RGB8:
248  if (s->codec_id == AV_CODEC_ID_SMC) {
249  w_align = 4;
250  h_align = 4;
251  }
252  break;
253  case AV_PIX_FMT_BGR24:
254  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
255  (s->codec_id == AV_CODEC_ID_ZLIB)) {
256  w_align = 4;
257  h_align = 4;
258  }
259  break;
260  default:
261  w_align = 1;
262  h_align = 1;
263  break;
264  }
265 
266  *width = FFALIGN(*width, w_align);
267  *height = FFALIGN(*height, h_align);
268  if (s->codec_id == AV_CODEC_ID_H264)
269  // some of the optimized chroma MC reads one line too much
270  *height += 2;
271 
272  for (i = 0; i < 4; i++)
273  linesize_align[i] = STRIDE_ALIGN;
274 }
275 
277 {
279  int chroma_shift = desc->log2_chroma_w;
280  int linesize_align[AV_NUM_DATA_POINTERS];
281  int align;
282 
283  avcodec_align_dimensions2(s, width, height, linesize_align);
284  align = FFMAX(linesize_align[0], linesize_align[3]);
285  linesize_align[1] <<= chroma_shift;
286  linesize_align[2] <<= chroma_shift;
287  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
288  *width = FFALIGN(*width, align);
289 }
290 
292  enum AVSampleFormat sample_fmt, const uint8_t *buf,
293  int buf_size, int align)
294 {
295  int ch, planar, needed_size, ret = 0;
296 
297  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
298  frame->nb_samples, sample_fmt,
299  align);
300  if (buf_size < needed_size)
301  return AVERROR(EINVAL);
302 
303  planar = av_sample_fmt_is_planar(sample_fmt);
304  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
305  if (!(frame->extended_data = av_mallocz(nb_channels *
306  sizeof(*frame->extended_data))))
307  return AVERROR(ENOMEM);
308  } else {
309  frame->extended_data = frame->data;
310  }
311 
312  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
313  buf, nb_channels, frame->nb_samples,
314  sample_fmt, align)) < 0) {
315  if (frame->extended_data != frame->data)
316  av_free(frame->extended_data);
317  return ret;
318  }
319  if (frame->extended_data != frame->data) {
320  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
321  frame->data[ch] = frame->extended_data[ch];
322  }
323 
324  return ret;
325 }
326 
327 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
328 {
329  FramePool *pool = avctx->internal->pool;
330  int i, ret;
331 
332  switch (avctx->codec_type) {
333  case AVMEDIA_TYPE_VIDEO: {
335  int size[4] = { 0 };
336  int w = frame->width;
337  int h = frame->height;
338  int tmpsize, unaligned;
339 
340  if (pool->format == frame->format &&
341  pool->width == frame->width && pool->height == frame->height)
342  return 0;
343 
344  avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
345 
346  if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
347  w += EDGE_WIDTH * 2;
348  h += EDGE_WIDTH * 2;
349  }
350 
351  do {
352  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
353  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
354  av_image_fill_linesizes(picture.linesize, avctx->pix_fmt, w);
355  // increase alignment of w for next try (rhs gives the lowest bit set in w)
356  w += w & ~(w - 1);
357 
358  unaligned = 0;
359  for (i = 0; i < 4; i++)
360  unaligned |= picture.linesize[i] % pool->stride_align[i];
361  } while (unaligned);
362 
363  tmpsize = av_image_fill_pointers(picture.data, avctx->pix_fmt, h,
364  NULL, picture.linesize);
365  if (tmpsize < 0)
366  return -1;
367 
368  for (i = 0; i < 3 && picture.data[i + 1]; i++)
369  size[i] = picture.data[i + 1] - picture.data[i];
370  size[i] = tmpsize - (picture.data[i] - picture.data[0]);
371 
372  for (i = 0; i < 4; i++) {
373  av_buffer_pool_uninit(&pool->pools[i]);
374  pool->linesize[i] = picture.linesize[i];
375  if (size[i]) {
376  pool->pools[i] = av_buffer_pool_init(size[i] + 16, NULL);
377  if (!pool->pools[i]) {
378  ret = AVERROR(ENOMEM);
379  goto fail;
380  }
381  }
382  }
383  pool->format = frame->format;
384  pool->width = frame->width;
385  pool->height = frame->height;
386 
387  break;
388  }
389  case AVMEDIA_TYPE_AUDIO: {
391  int planar = av_sample_fmt_is_planar(frame->format);
392  int planes = planar ? ch : 1;
393 
394  if (pool->format == frame->format && pool->planes == planes &&
395  pool->channels == ch && frame->nb_samples == pool->samples)
396  return 0;
397 
398  av_buffer_pool_uninit(&pool->pools[0]);
399  ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
400  frame->nb_samples, frame->format, 0);
401  if (ret < 0)
402  goto fail;
403 
404  pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
405  if (!pool->pools[0]) {
406  ret = AVERROR(ENOMEM);
407  goto fail;
408  }
409 
410  pool->format = frame->format;
411  pool->planes = planes;
412  pool->channels = ch;
413  pool->samples = frame->nb_samples;
414  break;
415  }
416  default: av_assert0(0);
417  }
418  return 0;
419 fail:
420  for (i = 0; i < 4; i++)
421  av_buffer_pool_uninit(&pool->pools[i]);
422  pool->format = -1;
423  pool->planes = pool->channels = pool->samples = 0;
424  pool->width = pool->height = 0;
425  return ret;
426 }
427 
428 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
429 {
430  FramePool *pool = avctx->internal->pool;
431  int planes = pool->planes;
432  int i;
433 
434  frame->linesize[0] = pool->linesize[0];
435 
436  if (planes > AV_NUM_DATA_POINTERS) {
437  frame->extended_data = av_mallocz(planes * sizeof(*frame->extended_data));
438  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
439  frame->extended_buf = av_mallocz(frame->nb_extended_buf *
440  sizeof(*frame->extended_buf));
441  if (!frame->extended_data || !frame->extended_buf) {
442  av_freep(&frame->extended_data);
443  av_freep(&frame->extended_buf);
444  return AVERROR(ENOMEM);
445  }
446  } else
447  frame->extended_data = frame->data;
448 
449  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
450  frame->buf[i] = av_buffer_pool_get(pool->pools[0]);
451  if (!frame->buf[i])
452  goto fail;
453  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
454  }
455  for (i = 0; i < frame->nb_extended_buf; i++) {
456  frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]);
457  if (!frame->extended_buf[i])
458  goto fail;
459  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
460  }
461 
462  if (avctx->debug & FF_DEBUG_BUFFERS)
463  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame);
464 
465  return 0;
466 fail:
467  av_frame_unref(frame);
468  return AVERROR(ENOMEM);
469 }
470 
472 {
473  FramePool *pool = s->internal->pool;
474  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format);
475  int pixel_size = desc->comp[0].step_minus1 + 1;
476  int h_chroma_shift, v_chroma_shift;
477  int i;
478 
479  if (pic->data[0] != NULL) {
480  av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
481  return -1;
482  }
483 
484  memset(pic->data, 0, sizeof(pic->data));
485  pic->extended_data = pic->data;
486 
487  av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
488 
489  for (i = 0; i < 4 && pool->pools[i]; i++) {
490  const int h_shift = i == 0 ? 0 : h_chroma_shift;
491  const int v_shift = i == 0 ? 0 : v_chroma_shift;
492 
493  pic->linesize[i] = pool->linesize[i];
494 
495  pic->buf[i] = av_buffer_pool_get(pool->pools[i]);
496  if (!pic->buf[i])
497  goto fail;
498 
499  // no edge if EDGE EMU or not planar YUV
500  if ((s->flags & CODEC_FLAG_EMU_EDGE) || !pool->pools[2])
501  pic->data[i] = pic->buf[i]->data;
502  else {
503  pic->data[i] = pic->buf[i]->data +
504  FFALIGN((pic->linesize[i] * EDGE_WIDTH >> v_shift) +
505  (pixel_size * EDGE_WIDTH >> h_shift), pool->stride_align[i]);
506  }
507  }
508  for (; i < AV_NUM_DATA_POINTERS; i++) {
509  pic->data[i] = NULL;
510  pic->linesize[i] = 0;
511  }
512  if (pic->data[1] && !pic->data[2])
513  avpriv_set_systematic_pal2((uint32_t *)pic->data[1], s->pix_fmt);
514 
515  if (s->debug & FF_DEBUG_BUFFERS)
516  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic);
517 
518  return 0;
519 fail:
520  av_frame_unref(pic);
521  return AVERROR(ENOMEM);
522 }
523 
525 {
526  int ret;
527 
528  if ((ret = update_frame_pool(avctx, frame)) < 0)
529  return ret;
530 
531 #if FF_API_GET_BUFFER
533  frame->type = FF_BUFFER_TYPE_INTERNAL;
535 #endif
536 
537  switch (avctx->codec_type) {
538  case AVMEDIA_TYPE_VIDEO:
539  return video_get_buffer(avctx, frame);
540  case AVMEDIA_TYPE_AUDIO:
541  return audio_get_buffer(avctx, frame);
542  default:
543  return -1;
544  }
545 }
546 
547 #if FF_API_GET_BUFFER
550 {
551  return avcodec_default_get_buffer2(avctx, frame, 0);
552 }
553 
554 typedef struct CompatReleaseBufPriv {
558 
559 static void compat_free_buffer(void *opaque, uint8_t *data)
560 {
561  CompatReleaseBufPriv *priv = opaque;
562  if (priv->avctx.release_buffer)
563  priv->avctx.release_buffer(&priv->avctx, &priv->frame);
564  av_freep(&priv);
565 }
566 
567 static void compat_release_buffer(void *opaque, uint8_t *data)
568 {
569  AVBufferRef *buf = opaque;
570  av_buffer_unref(&buf);
571 }
573 #endif
574 
575 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
576 {
577  int override_dimensions = 1;
578  int ret;
579 
580  switch (avctx->codec_type) {
581  case AVMEDIA_TYPE_VIDEO:
582  if (frame->width <= 0 || frame->height <= 0) {
583  frame->width = FFMAX(avctx->width, avctx->coded_width);
584  frame->height = FFMAX(avctx->height, avctx->coded_height);
585  override_dimensions = 0;
586  }
587  if (frame->format < 0)
588  frame->format = avctx->pix_fmt;
589  if (!frame->sample_aspect_ratio.num)
591 
592  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
593  return ret;
594  break;
595  case AVMEDIA_TYPE_AUDIO:
596  if (!frame->sample_rate)
597  frame->sample_rate = avctx->sample_rate;
598  if (frame->format < 0)
599  frame->format = avctx->sample_fmt;
600  if (!frame->channel_layout) {
601  if (avctx->channel_layout) {
603  avctx->channels) {
604  av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
605  "configuration.\n");
606  return AVERROR(EINVAL);
607  }
608 
609  frame->channel_layout = avctx->channel_layout;
610  } else {
611  if (avctx->channels > FF_SANE_NB_CHANNELS) {
612  av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
613  avctx->channels);
614  return AVERROR(ENOSYS);
615  }
616 
618  if (!frame->channel_layout)
619  frame->channel_layout = (1ULL << avctx->channels) - 1;
620  }
621  }
622  break;
623  default: return AVERROR(EINVAL);
624  }
625 
626  frame->pkt_pts = avctx->internal->pkt ? avctx->internal->pkt->pts : AV_NOPTS_VALUE;
627  frame->reordered_opaque = avctx->reordered_opaque;
628 
629 #if FF_API_GET_BUFFER
631  /*
632  * Wrap an old get_buffer()-allocated buffer in an bunch of AVBuffers.
633  * We wrap each plane in its own AVBuffer. Each of those has a reference to
634  * a dummy AVBuffer as its private data, unreffing it on free.
635  * When all the planes are freed, the dummy buffer's free callback calls
636  * release_buffer().
637  */
638  if (avctx->get_buffer) {
639  CompatReleaseBufPriv *priv = NULL;
640  AVBufferRef *dummy_buf = NULL;
641  int planes, i, ret;
642 
643  if (flags & AV_GET_BUFFER_FLAG_REF)
644  frame->reference = 1;
645 
646  ret = avctx->get_buffer(avctx, frame);
647  if (ret < 0)
648  return ret;
649 
650  /* return if the buffers are already set up
651  * this would happen e.g. when a custom get_buffer() calls
652  * avcodec_default_get_buffer
653  */
654  if (frame->buf[0])
655  return 0;
656 
657  priv = av_mallocz(sizeof(*priv));
658  if (!priv) {
659  ret = AVERROR(ENOMEM);
660  goto fail;
661  }
662  priv->avctx = *avctx;
663  priv->frame = *frame;
664 
665  dummy_buf = av_buffer_create(NULL, 0, compat_free_buffer, priv, 0);
666  if (!dummy_buf) {
667  ret = AVERROR(ENOMEM);
668  goto fail;
669  }
670 
671 #define WRAP_PLANE(ref_out, data, data_size) \
672 do { \
673  AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
674  if (!dummy_ref) { \
675  ret = AVERROR(ENOMEM); \
676  goto fail; \
677  } \
678  ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
679  dummy_ref, 0); \
680  if (!ref_out) { \
681  av_frame_unref(frame); \
682  ret = AVERROR(ENOMEM); \
683  goto fail; \
684  } \
685 } while (0)
686 
687  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
688  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
689 
690  planes = av_pix_fmt_count_planes(frame->format);
691  /* workaround for AVHWAccel plane count of 0, buf[0] is used as
692  check for allocated buffers: make libavcodec happy */
693  if (desc && desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
694  planes = 1;
695  if (!desc || planes <= 0) {
696  ret = AVERROR(EINVAL);
697  goto fail;
698  }
699 
700  for (i = 0; i < planes; i++) {
701  int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
702  int plane_size = (frame->height >> v_shift) * frame->linesize[i];
703 
704  WRAP_PLANE(frame->buf[i], frame->data[i], plane_size);
705  }
706  } else {
707  int planar = av_sample_fmt_is_planar(frame->format);
708  planes = planar ? avctx->channels : 1;
709 
710  if (planes > FF_ARRAY_ELEMS(frame->buf)) {
711  frame->nb_extended_buf = planes - FF_ARRAY_ELEMS(frame->buf);
712  frame->extended_buf = av_malloc(sizeof(*frame->extended_buf) *
713  frame->nb_extended_buf);
714  if (!frame->extended_buf) {
715  ret = AVERROR(ENOMEM);
716  goto fail;
717  }
718  }
719 
720  for (i = 0; i < FFMIN(planes, FF_ARRAY_ELEMS(frame->buf)); i++)
721  WRAP_PLANE(frame->buf[i], frame->extended_data[i], frame->linesize[0]);
722 
723  for (i = 0; i < frame->nb_extended_buf; i++)
724  WRAP_PLANE(frame->extended_buf[i],
725  frame->extended_data[i + FF_ARRAY_ELEMS(frame->buf)],
726  frame->linesize[0]);
727  }
728 
729  av_buffer_unref(&dummy_buf);
730 
731  frame->width = avctx->width;
732  frame->height = avctx->height;
733 
734  return 0;
735 
736 fail:
737  avctx->release_buffer(avctx, frame);
738  av_freep(&priv);
739  av_buffer_unref(&dummy_buf);
740  return ret;
741  }
743 #endif
744 
745  ret = avctx->get_buffer2(avctx, frame, flags);
746 
747  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) {
748  frame->width = avctx->width;
749  frame->height = avctx->height;
750  }
751 
752  return ret;
753 }
754 
756 {
757  AVFrame tmp;
758  int ret;
759 
761 
762  if (!frame->data[0])
763  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
764 
765  if (av_frame_is_writable(frame)) {
766  frame->pkt_pts = avctx->internal->pkt ? avctx->internal->pkt->pts : AV_NOPTS_VALUE;
767  frame->reordered_opaque = avctx->reordered_opaque;
768  return 0;
769  }
770 
771  av_frame_move_ref(&tmp, frame);
772 
773  ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
774  if (ret < 0) {
775  av_frame_unref(&tmp);
776  return ret;
777  }
778 
779  av_image_copy(frame->data, frame->linesize, tmp.data, tmp.linesize,
780  frame->format, frame->width, frame->height);
781 
782  av_frame_unref(&tmp);
783 
784  return 0;
785 }
786 
787 #if FF_API_GET_BUFFER
789 {
790  av_frame_unref(pic);
791 }
792 
794 {
795  av_assert0(0);
796  return AVERROR_BUG;
797 }
798 #endif
799 
800 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
801 {
802  int i;
803 
804  for (i = 0; i < count; i++) {
805  int r = func(c, (char *)arg + i * size);
806  if (ret)
807  ret[i] = r;
808  }
809  return 0;
810 }
811 
812 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
813 {
814  int i;
815 
816  for (i = 0; i < count; i++) {
817  int r = func(c, arg, i, 0);
818  if (ret)
819  ret[i] = r;
820  }
821  return 0;
822 }
823 
825 {
826  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
827  return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
828 }
829 
831 {
832  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
833  ++fmt;
834  return fmt[0];
835 }
836 
837 #if FF_API_AVFRAME_LAVC
838 void avcodec_get_frame_defaults(AVFrame *frame)
839 {
840  if (frame->extended_data != frame->data)
841  av_freep(&frame->extended_data);
842 
843  memset(frame, 0, sizeof(AVFrame));
844 
845  frame->pts = AV_NOPTS_VALUE;
846  frame->key_frame = 1;
847  frame->sample_aspect_ratio = (AVRational) {0, 1 };
848  frame->format = -1; /* unknown */
849  frame->extended_data = frame->data;
850 }
851 
852 AVFrame *avcodec_alloc_frame(void)
853 {
854  AVFrame *frame = av_mallocz(sizeof(AVFrame));
855 
856  if (frame == NULL)
857  return NULL;
858 
860  avcodec_get_frame_defaults(frame);
862 
863  return frame;
864 }
865 
866 void avcodec_free_frame(AVFrame **frame)
867 {
868  av_frame_free(frame);
869 }
870 #endif
871 
873 {
874  int ret = 0;
875  AVDictionary *tmp = NULL;
876 
877  if (avcodec_is_open(avctx))
878  return 0;
879 
880  if ((!codec && !avctx->codec)) {
881  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
882  return AVERROR(EINVAL);
883  }
884  if ((codec && avctx->codec && codec != avctx->codec)) {
885  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
886  "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
887  return AVERROR(EINVAL);
888  }
889  if (!codec)
890  codec = avctx->codec;
891 
892  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
893  return AVERROR(EINVAL);
894 
895  if (options)
896  av_dict_copy(&tmp, *options, 0);
897 
898  /* If there is a user-supplied mutex locking routine, call it. */
899  if (lockmgr_cb) {
901  return -1;
902  }
903 
905  if (entangled_thread_counter != 1) {
906  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
907  ret = -1;
908  goto end;
909  }
910 
911  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
912  if (!avctx->internal) {
913  ret = AVERROR(ENOMEM);
914  goto end;
915  }
916 
917  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
918  if (!avctx->internal->pool) {
919  ret = AVERROR(ENOMEM);
920  goto free_and_end;
921  }
922 
923  avctx->internal->to_free = av_frame_alloc();
924  if (!avctx->internal->to_free) {
925  ret = AVERROR(ENOMEM);
926  goto free_and_end;
927  }
928 
929  if (codec->priv_data_size > 0) {
930  if (!avctx->priv_data) {
931  avctx->priv_data = av_mallocz(codec->priv_data_size);
932  if (!avctx->priv_data) {
933  ret = AVERROR(ENOMEM);
934  goto end;
935  }
936  if (codec->priv_class) {
937  *(const AVClass **)avctx->priv_data = codec->priv_class;
939  }
940  }
941  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
942  goto free_and_end;
943  } else {
944  avctx->priv_data = NULL;
945  }
946  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
947  goto free_and_end;
948 
949  if (avctx->coded_width && avctx->coded_height && !avctx->width && !avctx->height)
950  ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
951  else if (avctx->width && avctx->height)
952  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
953  if (ret < 0)
954  goto free_and_end;
955 
956  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
957  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
958  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
959  av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
960  ff_set_dimensions(avctx, 0, 0);
961  }
962 
963  /* if the decoder init function was already called previously,
964  * free the already allocated subtitle_header before overwriting it */
965  if (av_codec_is_decoder(codec))
966  av_freep(&avctx->subtitle_header);
967 
968  if (avctx->channels > FF_SANE_NB_CHANNELS) {
969  ret = AVERROR(EINVAL);
970  goto free_and_end;
971  }
972 
973  avctx->codec = codec;
974  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
975  avctx->codec_id == AV_CODEC_ID_NONE) {
976  avctx->codec_type = codec->type;
977  avctx->codec_id = codec->id;
978  }
979  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
980  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
981  av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
982  ret = AVERROR(EINVAL);
983  goto free_and_end;
984  }
985  avctx->frame_number = 0;
986 
987  if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
989  ret = AVERROR_EXPERIMENTAL;
990  goto free_and_end;
991  }
992 
993  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
994  (!avctx->time_base.num || !avctx->time_base.den)) {
995  avctx->time_base.num = 1;
996  avctx->time_base.den = avctx->sample_rate;
997  }
998 
999  if (HAVE_THREADS) {
1000  ret = ff_thread_init(avctx);
1001  if (ret < 0) {
1002  goto free_and_end;
1003  }
1004  }
1005  if (!HAVE_THREADS && !(codec->capabilities & CODEC_CAP_AUTO_THREADS))
1006  avctx->thread_count = 1;
1007 
1008  if (av_codec_is_encoder(avctx->codec)) {
1009  int i;
1010  if (avctx->codec->sample_fmts) {
1011  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
1012  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
1013  break;
1014  if (avctx->channels == 1 &&
1017  avctx->sample_fmt = avctx->codec->sample_fmts[i];
1018  break;
1019  }
1020  }
1021  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
1022  av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
1023  ret = AVERROR(EINVAL);
1024  goto free_and_end;
1025  }
1026  }
1027  if (avctx->codec->pix_fmts) {
1028  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
1029  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
1030  break;
1031  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
1032  av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n");
1033  ret = AVERROR(EINVAL);
1034  goto free_and_end;
1035  }
1036  }
1037  if (avctx->codec->supported_samplerates) {
1038  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
1039  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
1040  break;
1041  if (avctx->codec->supported_samplerates[i] == 0) {
1042  av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
1043  ret = AVERROR(EINVAL);
1044  goto free_and_end;
1045  }
1046  }
1047  if (avctx->codec->channel_layouts) {
1048  if (!avctx->channel_layout) {
1049  av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
1050  } else {
1051  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
1052  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
1053  break;
1054  if (avctx->codec->channel_layouts[i] == 0) {
1055  av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
1056  ret = AVERROR(EINVAL);
1057  goto free_and_end;
1058  }
1059  }
1060  }
1061  if (avctx->channel_layout && avctx->channels) {
1063  av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
1064  ret = AVERROR(EINVAL);
1065  goto free_and_end;
1066  }
1067  } else if (avctx->channel_layout) {
1069  }
1070 
1071  if (!avctx->rc_initial_buffer_occupancy)
1072  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
1073  }
1074 
1075  if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) {
1076  ret = avctx->codec->init(avctx);
1077  if (ret < 0) {
1078  goto free_and_end;
1079  }
1080  }
1081 
1082  if (av_codec_is_decoder(avctx->codec)) {
1083  /* validate channel layout from the decoder */
1084  if (avctx->channel_layout) {
1085  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1086  if (!avctx->channels)
1087  avctx->channels = channels;
1088  else if (channels != avctx->channels) {
1089  av_log(avctx, AV_LOG_WARNING,
1090  "channel layout does not match number of channels\n");
1091  avctx->channel_layout = 0;
1092  }
1093  }
1094  if (avctx->channels && avctx->channels < 0 ||
1095  avctx->channels > FF_SANE_NB_CHANNELS) {
1096  ret = AVERROR(EINVAL);
1097  goto free_and_end;
1098  }
1099  }
1100 end:
1102 
1103  /* Release any user-supplied mutex. */
1104  if (lockmgr_cb) {
1105  (*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1106  }
1107  if (options) {
1108  av_dict_free(options);
1109  *options = tmp;
1110  }
1111 
1112  return ret;
1113 free_and_end:
1114  av_dict_free(&tmp);
1115  av_freep(&avctx->priv_data);
1116  if (avctx->internal) {
1117  av_frame_free(&avctx->internal->to_free);
1118  av_freep(&avctx->internal->pool);
1119  }
1120  av_freep(&avctx->internal);
1121  avctx->codec = NULL;
1122  goto end;
1123 }
1124 
1126 {
1127  if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
1128  return AVERROR(EINVAL);
1129 
1130  if (avpkt->data) {
1131  AVBufferRef *buf = avpkt->buf;
1132 #if FF_API_DESTRUCT_PACKET
1134  void *destruct = avpkt->destruct;
1136 #endif
1137 
1138  if (avpkt->size < size)
1139  return AVERROR(EINVAL);
1140 
1141  av_init_packet(avpkt);
1142 #if FF_API_DESTRUCT_PACKET
1144  avpkt->destruct = destruct;
1146 #endif
1147  avpkt->buf = buf;
1148  avpkt->size = size;
1149  return 0;
1150  } else {
1151  return av_new_packet(avpkt, size);
1152  }
1153 }
1154 
1158 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
1159 {
1160  AVFrame *frame = NULL;
1161  int ret;
1162 
1163  if (!(frame = av_frame_alloc()))
1164  return AVERROR(ENOMEM);
1165 
1166  frame->format = src->format;
1167  frame->channel_layout = src->channel_layout;
1168  frame->nb_samples = s->frame_size;
1169  ret = av_frame_get_buffer(frame, 32);
1170  if (ret < 0)
1171  goto fail;
1172 
1173  ret = av_frame_copy_props(frame, src);
1174  if (ret < 0)
1175  goto fail;
1176 
1177  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
1178  src->nb_samples, s->channels, s->sample_fmt)) < 0)
1179  goto fail;
1180  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
1181  frame->nb_samples - src->nb_samples,
1182  s->channels, s->sample_fmt)) < 0)
1183  goto fail;
1184 
1185  *dst = frame;
1186 
1187  return 0;
1188 
1189 fail:
1190  av_frame_free(&frame);
1191  return ret;
1192 }
1193 
1195  AVPacket *avpkt,
1196  const AVFrame *frame,
1197  int *got_packet_ptr)
1198 {
1199  AVFrame tmp;
1200  AVFrame *padded_frame = NULL;
1201  int ret;
1202  int user_packet = !!avpkt->data;
1203 
1204  *got_packet_ptr = 0;
1205 
1206  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1207  av_free_packet(avpkt);
1208  av_init_packet(avpkt);
1209  return 0;
1210  }
1211 
1212  /* ensure that extended_data is properly set */
1213  if (frame && !frame->extended_data) {
1214  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
1215  avctx->channels > AV_NUM_DATA_POINTERS) {
1216  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
1217  "with more than %d channels, but extended_data is not set.\n",
1219  return AVERROR(EINVAL);
1220  }
1221  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
1222 
1223  tmp = *frame;
1224  tmp.extended_data = tmp.data;
1225  frame = &tmp;
1226  }
1227 
1228  /* check for valid frame size */
1229  if (frame) {
1231  if (frame->nb_samples > avctx->frame_size)
1232  return AVERROR(EINVAL);
1233  } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
1234  if (frame->nb_samples < avctx->frame_size &&
1235  !avctx->internal->last_audio_frame) {
1236  ret = pad_last_frame(avctx, &padded_frame, frame);
1237  if (ret < 0)
1238  return ret;
1239 
1240  frame = padded_frame;
1241  avctx->internal->last_audio_frame = 1;
1242  }
1243 
1244  if (frame->nb_samples != avctx->frame_size) {
1245  ret = AVERROR(EINVAL);
1246  goto end;
1247  }
1248  }
1249  }
1250 
1251  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1252  if (!ret) {
1253  if (*got_packet_ptr) {
1254  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
1255  if (avpkt->pts == AV_NOPTS_VALUE)
1256  avpkt->pts = frame->pts;
1257  if (!avpkt->duration)
1258  avpkt->duration = ff_samples_to_time_base(avctx,
1259  frame->nb_samples);
1260  }
1261  avpkt->dts = avpkt->pts;
1262  } else {
1263  avpkt->size = 0;
1264  }
1265 
1266  if (!user_packet && avpkt->size) {
1267  ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
1268  if (ret >= 0)
1269  avpkt->data = avpkt->buf->data;
1270  }
1271 
1272  avctx->frame_number++;
1273  }
1274 
1275  if (ret < 0 || !*got_packet_ptr) {
1276  av_free_packet(avpkt);
1277  av_init_packet(avpkt);
1278  goto end;
1279  }
1280 
1281  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1282  * this needs to be moved to the encoders, but for now we can do it
1283  * here to simplify things */
1284  avpkt->flags |= AV_PKT_FLAG_KEY;
1285 
1286 end:
1287  av_frame_free(&padded_frame);
1288 
1289  return ret;
1290 }
1291 
1293  AVPacket *avpkt,
1294  const AVFrame *frame,
1295  int *got_packet_ptr)
1296 {
1297  int ret;
1298  int user_packet = !!avpkt->data;
1299 
1300  *got_packet_ptr = 0;
1301 
1302  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1303  av_free_packet(avpkt);
1304  av_init_packet(avpkt);
1305  avpkt->size = 0;
1306  return 0;
1307  }
1308 
1309  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
1310  return AVERROR(EINVAL);
1311 
1312  av_assert0(avctx->codec->encode2);
1313 
1314  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1315  if (!ret) {
1316  if (!*got_packet_ptr)
1317  avpkt->size = 0;
1318  else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
1319  avpkt->pts = avpkt->dts = frame->pts;
1320 
1321  if (!user_packet && avpkt->size) {
1322  ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
1323  if (ret >= 0)
1324  avpkt->data = avpkt->buf->data;
1325  }
1326 
1327  avctx->frame_number++;
1328  }
1329 
1330  if (ret < 0 || !*got_packet_ptr)
1331  av_free_packet(avpkt);
1332 
1333  emms_c();
1334  return ret;
1335 }
1336 
1337 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1338  const AVSubtitle *sub)
1339 {
1340  int ret;
1341  if (sub->start_display_time) {
1342  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1343  return -1;
1344  }
1345  if (sub->num_rects == 0 || !sub->rects)
1346  return -1;
1347  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
1348  avctx->frame_number++;
1349  return ret;
1350 }
1351 
1352 static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1353 {
1354  int size = 0, ret;
1355  const uint8_t *data;
1356  uint32_t flags;
1357 
1358  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1359  if (!data)
1360  return 0;
1361 
1362  if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) {
1363  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
1364  "changes, but PARAM_CHANGE side data was sent to it.\n");
1365  return AVERROR(EINVAL);
1366  }
1367 
1368  if (size < 4)
1369  goto fail;
1370 
1371  flags = bytestream_get_le32(&data);
1372  size -= 4;
1373 
1375  if (size < 4)
1376  goto fail;
1377  avctx->channels = bytestream_get_le32(&data);
1378  size -= 4;
1379  }
1381  if (size < 8)
1382  goto fail;
1383  avctx->channel_layout = bytestream_get_le64(&data);
1384  size -= 8;
1385  }
1387  if (size < 4)
1388  goto fail;
1389  avctx->sample_rate = bytestream_get_le32(&data);
1390  size -= 4;
1391  }
1393  if (size < 8)
1394  goto fail;
1395  avctx->width = bytestream_get_le32(&data);
1396  avctx->height = bytestream_get_le32(&data);
1397  size -= 8;
1398  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
1399  if (ret < 0)
1400  return ret;
1401  }
1402 
1403  return 0;
1404 fail:
1405  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
1406  return AVERROR_INVALIDDATA;
1407 }
1408 
1409 static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
1410 {
1411  int ret;
1412 
1413  /* move the original frame to our backup */
1414  av_frame_unref(avci->to_free);
1415  av_frame_move_ref(avci->to_free, frame);
1416 
1417  /* now copy everything except the AVBufferRefs back
1418  * note that we make a COPY of the side data, so calling av_frame_free() on
1419  * the caller's frame will work properly */
1420  ret = av_frame_copy_props(frame, avci->to_free);
1421  if (ret < 0)
1422  return ret;
1423 
1424  memcpy(frame->data, avci->to_free->data, sizeof(frame->data));
1425  memcpy(frame->linesize, avci->to_free->linesize, sizeof(frame->linesize));
1426  if (avci->to_free->extended_data != avci->to_free->data) {
1428  int size = planes * sizeof(*frame->extended_data);
1429 
1430  if (!size) {
1431  av_frame_unref(frame);
1432  return AVERROR_BUG;
1433  }
1434 
1435  frame->extended_data = av_malloc(size);
1436  if (!frame->extended_data) {
1437  av_frame_unref(frame);
1438  return AVERROR(ENOMEM);
1439  }
1440  memcpy(frame->extended_data, avci->to_free->extended_data,
1441  size);
1442  } else
1443  frame->extended_data = frame->data;
1444 
1445  frame->format = avci->to_free->format;
1446  frame->width = avci->to_free->width;
1447  frame->height = avci->to_free->height;
1448  frame->channel_layout = avci->to_free->channel_layout;
1449  frame->nb_samples = avci->to_free->nb_samples;
1450 
1451  return 0;
1452 }
1453 
1455  int *got_picture_ptr,
1456  AVPacket *avpkt)
1457 {
1458  AVCodecInternal *avci = avctx->internal;
1459  int ret;
1460 
1461  *got_picture_ptr = 0;
1462  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
1463  return -1;
1464 
1465  avctx->internal->pkt = avpkt;
1466  ret = apply_param_change(avctx, avpkt);
1467  if (ret < 0) {
1468  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
1469  if (avctx->err_recognition & AV_EF_EXPLODE)
1470  return ret;
1471  }
1472 
1473  av_frame_unref(picture);
1474 
1475  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
1477  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
1478  avpkt);
1479  else {
1480  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
1481  avpkt);
1482  picture->pkt_dts = avpkt->dts;
1483  /* get_buffer is supposed to set frame parameters */
1484  if (!(avctx->codec->capabilities & CODEC_CAP_DR1)) {
1485  picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
1486  picture->width = avctx->width;
1487  picture->height = avctx->height;
1488  picture->format = avctx->pix_fmt;
1489  }
1490  }
1491 
1492  emms_c(); //needed to avoid an emms_c() call before every return;
1493 
1494  if (*got_picture_ptr) {
1495  if (!avctx->refcounted_frames) {
1496  int err = unrefcount_frame(avci, picture);
1497  if (err < 0)
1498  return err;
1499  }
1500 
1501  avctx->frame_number++;
1502  } else
1503  av_frame_unref(picture);
1504  } else
1505  ret = 0;
1506 
1507  return ret;
1508 }
1509 
1511  AVFrame *frame,
1512  int *got_frame_ptr,
1513  AVPacket *avpkt)
1514 {
1515  AVCodecInternal *avci = avctx->internal;
1516  int ret = 0;
1517 
1518  *got_frame_ptr = 0;
1519 
1520  avctx->internal->pkt = avpkt;
1521 
1522  if (!avpkt->data && avpkt->size) {
1523  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1524  return AVERROR(EINVAL);
1525  }
1526 
1527  ret = apply_param_change(avctx, avpkt);
1528  if (ret < 0) {
1529  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
1530  if (avctx->err_recognition & AV_EF_EXPLODE)
1531  return ret;
1532  }
1533 
1534  av_frame_unref(frame);
1535 
1536  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1537  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1538  if (ret >= 0 && *got_frame_ptr) {
1539  avctx->frame_number++;
1540  frame->pkt_dts = avpkt->dts;
1541  if (frame->format == AV_SAMPLE_FMT_NONE)
1542  frame->format = avctx->sample_fmt;
1543 
1544  if (!avctx->refcounted_frames) {
1545  int err = unrefcount_frame(avci, frame);
1546  if (err < 0)
1547  return err;
1548  }
1549  } else
1550  av_frame_unref(frame);
1551  }
1552 
1553 
1554  return ret;
1555 }
1556 
1558  int *got_sub_ptr,
1559  AVPacket *avpkt)
1560 {
1561  int ret;
1562 
1563  avctx->internal->pkt = avpkt;
1564  *got_sub_ptr = 0;
1565  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1566  if (*got_sub_ptr)
1567  avctx->frame_number++;
1568  return ret;
1569 }
1570 
1572 {
1573  int i;
1574 
1575  for (i = 0; i < sub->num_rects; i++) {
1576  av_freep(&sub->rects[i]->pict.data[0]);
1577  av_freep(&sub->rects[i]->pict.data[1]);
1578  av_freep(&sub->rects[i]->pict.data[2]);
1579  av_freep(&sub->rects[i]->pict.data[3]);
1580  av_freep(&sub->rects[i]->text);
1581  av_freep(&sub->rects[i]->ass);
1582  av_freep(&sub->rects[i]);
1583  }
1584 
1585  av_freep(&sub->rects);
1586 
1587  memset(sub, 0, sizeof(AVSubtitle));
1588 }
1589 
1591 {
1592  /* If there is a user-supplied mutex locking routine, call it. */
1593  if (lockmgr_cb) {
1595  return -1;
1596  }
1597 
1599  if (entangled_thread_counter != 1) {
1600  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1602  return -1;
1603  }
1604 
1605  if (avcodec_is_open(avctx)) {
1606  FramePool *pool = avctx->internal->pool;
1607  int i;
1608  if (HAVE_THREADS && avctx->internal->thread_ctx)
1609  ff_thread_free(avctx);
1610  if (avctx->codec && avctx->codec->close)
1611  avctx->codec->close(avctx);
1612  avctx->coded_frame = NULL;
1613  av_frame_free(&avctx->internal->to_free);
1614  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
1615  av_buffer_pool_uninit(&pool->pools[i]);
1616  av_freep(&avctx->internal->pool);
1617  av_freep(&avctx->internal);
1618  }
1619 
1620  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1621  av_opt_free(avctx->priv_data);
1622  av_opt_free(avctx);
1623  av_freep(&avctx->priv_data);
1624  if (av_codec_is_encoder(avctx->codec))
1625  av_freep(&avctx->extradata);
1626  avctx->codec = NULL;
1627  avctx->active_thread_type = 0;
1629 
1630  /* Release any user-supplied mutex. */
1631  if (lockmgr_cb) {
1632  (*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1633  }
1634  return 0;
1635 }
1636 
1637 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1638 {
1639  AVCodec *p, *experimental = NULL;
1640  p = first_avcodec;
1641  while (p) {
1642  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1643  p->id == id) {
1644  if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1645  experimental = p;
1646  } else
1647  return p;
1648  }
1649  p = p->next;
1650  }
1651  return experimental;
1652 }
1653 
1655 {
1656  return find_encdec(id, 1);
1657 }
1658 
1660 {
1661  AVCodec *p;
1662  if (!name)
1663  return NULL;
1664  p = first_avcodec;
1665  while (p) {
1666  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
1667  return p;
1668  p = p->next;
1669  }
1670  return NULL;
1671 }
1672 
1674 {
1675  return find_encdec(id, 0);
1676 }
1677 
1679 {
1680  AVCodec *p;
1681  if (!name)
1682  return NULL;
1683  p = first_avcodec;
1684  while (p) {
1685  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
1686  return p;
1687  p = p->next;
1688  }
1689  return NULL;
1690 }
1691 
1693 {
1694  int bit_rate;
1695  int bits_per_sample;
1696 
1697  switch (ctx->codec_type) {
1698  case AVMEDIA_TYPE_VIDEO:
1699  case AVMEDIA_TYPE_DATA:
1700  case AVMEDIA_TYPE_SUBTITLE:
1702  bit_rate = ctx->bit_rate;
1703  break;
1704  case AVMEDIA_TYPE_AUDIO:
1705  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1706  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1707  break;
1708  default:
1709  bit_rate = 0;
1710  break;
1711  }
1712  return bit_rate;
1713 }
1714 
1715 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1716 {
1717  int i, len, ret = 0;
1718 
1719 #define TAG_PRINT(x) \
1720  (((x) >= '0' && (x) <= '9') || \
1721  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
1722  ((x) == '.' || (x) == ' '))
1723 
1724  for (i = 0; i < 4; i++) {
1725  len = snprintf(buf, buf_size,
1726  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
1727  buf += len;
1728  buf_size = buf_size > len ? buf_size - len : 0;
1729  ret += len;
1730  codec_tag >>= 8;
1731  }
1732  return ret;
1733 }
1734 
1735 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1736 {
1737  const char *codec_name;
1738  const char *profile = NULL;
1739  const AVCodec *p;
1740  char buf1[32];
1741  int bitrate;
1742  AVRational display_aspect_ratio;
1743 
1744  if (enc->codec)
1745  p = enc->codec;
1746  else if (encode)
1747  p = avcodec_find_encoder(enc->codec_id);
1748  else
1749  p = avcodec_find_decoder(enc->codec_id);
1750 
1751  if (p) {
1752  codec_name = p->name;
1753  profile = av_get_profile_name(p, enc->profile);
1754  } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) {
1755  /* fake mpeg2 transport stream codec (currently not
1756  * registered) */
1757  codec_name = "mpeg2ts";
1758  } else if (enc->codec_name[0] != '\0') {
1759  codec_name = enc->codec_name;
1760  } else {
1761  /* output avi tags */
1762  char tag_buf[32];
1763  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1764  snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
1765  codec_name = buf1;
1766  }
1767 
1768  switch (enc->codec_type) {
1769  case AVMEDIA_TYPE_VIDEO:
1770  snprintf(buf, buf_size,
1771  "Video: %s%s",
1772  codec_name, enc->mb_decision ? " (hq)" : "");
1773  if (profile)
1774  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1775  " (%s)", profile);
1776  if (enc->pix_fmt != AV_PIX_FMT_NONE) {
1777  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1778  ", %s",
1780  }
1781  if (enc->width) {
1782  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1783  ", %dx%d",
1784  enc->width, enc->height);
1785  if (enc->sample_aspect_ratio.num) {
1786  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1787  enc->width * enc->sample_aspect_ratio.num,
1788  enc->height * enc->sample_aspect_ratio.den,
1789  1024 * 1024);
1790  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1791  " [PAR %d:%d DAR %d:%d]",
1793  display_aspect_ratio.num, display_aspect_ratio.den);
1794  }
1795  if (av_log_get_level() >= AV_LOG_DEBUG) {
1796  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1797  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1798  ", %d/%d",
1799  enc->time_base.num / g, enc->time_base.den / g);
1800  }
1801  }
1802  if (encode) {
1803  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1804  ", q=%d-%d", enc->qmin, enc->qmax);
1805  }
1806  break;
1807  case AVMEDIA_TYPE_AUDIO:
1808  snprintf(buf, buf_size,
1809  "Audio: %s",
1810  codec_name);
1811  if (profile)
1812  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1813  " (%s)", profile);
1814  if (enc->sample_rate) {
1815  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1816  ", %d Hz", enc->sample_rate);
1817  }
1818  av_strlcat(buf, ", ", buf_size);
1819  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1820  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1821  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1822  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1823  }
1824  break;
1825  case AVMEDIA_TYPE_DATA:
1826  snprintf(buf, buf_size, "Data: %s", codec_name);
1827  break;
1828  case AVMEDIA_TYPE_SUBTITLE:
1829  snprintf(buf, buf_size, "Subtitle: %s", codec_name);
1830  break;
1832  snprintf(buf, buf_size, "Attachment: %s", codec_name);
1833  break;
1834  default:
1835  snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
1836  return;
1837  }
1838  if (encode) {
1839  if (enc->flags & CODEC_FLAG_PASS1)
1840  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1841  ", pass 1");
1842  if (enc->flags & CODEC_FLAG_PASS2)
1843  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1844  ", pass 2");
1845  }
1846  bitrate = get_bit_rate(enc);
1847  if (bitrate != 0) {
1848  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1849  ", %d kb/s", bitrate / 1000);
1850  }
1851 }
1852 
1853 const char *av_get_profile_name(const AVCodec *codec, int profile)
1854 {
1855  const AVProfile *p;
1856  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1857  return NULL;
1858 
1859  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1860  if (p->profile == profile)
1861  return p->name;
1862 
1863  return NULL;
1864 }
1865 
1866 unsigned avcodec_version(void)
1867 {
1868  return LIBAVCODEC_VERSION_INT;
1869 }
1870 
1871 const char *avcodec_configuration(void)
1872 {
1873  return LIBAV_CONFIGURATION;
1874 }
1875 
1876 const char *avcodec_license(void)
1877 {
1878 #define LICENSE_PREFIX "libavcodec license: "
1879  return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1880 }
1881 
1883 {
1885  ff_thread_flush(avctx);
1886  else if (avctx->codec->flush)
1887  avctx->codec->flush(avctx);
1888 
1889  if (!avctx->refcounted_frames)
1890  av_frame_unref(avctx->internal->to_free);
1891 }
1892 
1894 {
1895  switch (codec_id) {
1896  case AV_CODEC_ID_ADPCM_CT:
1902  return 4;
1903  case AV_CODEC_ID_PCM_ALAW:
1904  case AV_CODEC_ID_PCM_MULAW:
1905  case AV_CODEC_ID_PCM_S8:
1906  case AV_CODEC_ID_PCM_U8:
1907  case AV_CODEC_ID_PCM_ZORK:
1908  return 8;
1909  case AV_CODEC_ID_PCM_S16BE:
1910  case AV_CODEC_ID_PCM_S16LE:
1912  case AV_CODEC_ID_PCM_U16BE:
1913  case AV_CODEC_ID_PCM_U16LE:
1914  return 16;
1916  case AV_CODEC_ID_PCM_S24BE:
1917  case AV_CODEC_ID_PCM_S24LE:
1919  case AV_CODEC_ID_PCM_U24BE:
1920  case AV_CODEC_ID_PCM_U24LE:
1921  return 24;
1922  case AV_CODEC_ID_PCM_S32BE:
1923  case AV_CODEC_ID_PCM_S32LE:
1925  case AV_CODEC_ID_PCM_U32BE:
1926  case AV_CODEC_ID_PCM_U32LE:
1927  case AV_CODEC_ID_PCM_F32BE:
1928  case AV_CODEC_ID_PCM_F32LE:
1929  return 32;
1930  case AV_CODEC_ID_PCM_F64BE:
1931  case AV_CODEC_ID_PCM_F64LE:
1932  return 64;
1933  default:
1934  return 0;
1935  }
1936 }
1937 
1939 {
1940  switch (codec_id) {
1942  return 2;
1944  return 3;
1948  case AV_CODEC_ID_ADPCM_SWF:
1949  case AV_CODEC_ID_ADPCM_MS:
1950  return 4;
1951  default:
1952  return av_get_exact_bits_per_sample(codec_id);
1953  }
1954 }
1955 
1956 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
1957 {
1958  int id, sr, ch, ba, tag, bps;
1959 
1960  id = avctx->codec_id;
1961  sr = avctx->sample_rate;
1962  ch = avctx->channels;
1963  ba = avctx->block_align;
1964  tag = avctx->codec_tag;
1965  bps = av_get_exact_bits_per_sample(avctx->codec_id);
1966 
1967  /* codecs with an exact constant bits per sample */
1968  if (bps > 0 && ch > 0 && frame_bytes > 0)
1969  return (frame_bytes * 8) / (bps * ch);
1970  bps = avctx->bits_per_coded_sample;
1971 
1972  /* codecs with a fixed packet duration */
1973  switch (id) {
1974  case AV_CODEC_ID_ADPCM_ADX: return 32;
1975  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
1976  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
1977  case AV_CODEC_ID_AMR_NB:
1978  case AV_CODEC_ID_GSM:
1979  case AV_CODEC_ID_QCELP:
1980  case AV_CODEC_ID_RA_144:
1981  case AV_CODEC_ID_RA_288: return 160;
1982  case AV_CODEC_ID_IMC: return 256;
1983  case AV_CODEC_ID_AMR_WB:
1984  case AV_CODEC_ID_GSM_MS: return 320;
1985  case AV_CODEC_ID_MP1: return 384;
1986  case AV_CODEC_ID_ATRAC1: return 512;
1987  case AV_CODEC_ID_ATRAC3: return 1024;
1988  case AV_CODEC_ID_MP2:
1989  case AV_CODEC_ID_MUSEPACK7: return 1152;
1990  case AV_CODEC_ID_AC3: return 1536;
1991  }
1992 
1993  if (sr > 0) {
1994  /* calc from sample rate */
1995  if (id == AV_CODEC_ID_TTA)
1996  return 256 * sr / 245;
1997 
1998  if (ch > 0) {
1999  /* calc from sample rate and channels */
2000  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
2001  return (480 << (sr / 22050)) / ch;
2002  }
2003  }
2004 
2005  if (ba > 0) {
2006  /* calc from block_align */
2007  if (id == AV_CODEC_ID_SIPR) {
2008  switch (ba) {
2009  case 20: return 160;
2010  case 19: return 144;
2011  case 29: return 288;
2012  case 37: return 480;
2013  }
2014  } else if (id == AV_CODEC_ID_ILBC) {
2015  switch (ba) {
2016  case 38: return 160;
2017  case 50: return 240;
2018  }
2019  }
2020  }
2021 
2022  if (frame_bytes > 0) {
2023  /* calc from frame_bytes only */
2024  if (id == AV_CODEC_ID_TRUESPEECH)
2025  return 240 * (frame_bytes / 32);
2026  if (id == AV_CODEC_ID_NELLYMOSER)
2027  return 256 * (frame_bytes / 64);
2028 
2029  if (bps > 0) {
2030  /* calc from frame_bytes and bits_per_coded_sample */
2031  if (id == AV_CODEC_ID_ADPCM_G726)
2032  return frame_bytes * 8 / bps;
2033  }
2034 
2035  if (ch > 0) {
2036  /* calc from frame_bytes and channels */
2037  switch (id) {
2038  case AV_CODEC_ID_ADPCM_4XM:
2040  return (frame_bytes - 4 * ch) * 2 / ch;
2042  return (frame_bytes - 4) * 2 / ch;
2044  return (frame_bytes - 8) * 2 / ch;
2045  case AV_CODEC_ID_ADPCM_XA:
2046  return (frame_bytes / 128) * 224 / ch;
2048  return (frame_bytes - 6 - ch) / ch;
2049  case AV_CODEC_ID_ROQ_DPCM:
2050  return (frame_bytes - 8) / ch;
2051  case AV_CODEC_ID_XAN_DPCM:
2052  return (frame_bytes - 2 * ch) / ch;
2053  case AV_CODEC_ID_MACE3:
2054  return 3 * frame_bytes / ch;
2055  case AV_CODEC_ID_MACE6:
2056  return 6 * frame_bytes / ch;
2057  case AV_CODEC_ID_PCM_LXF:
2058  return 2 * (frame_bytes / (5 * ch));
2059  }
2060 
2061  if (tag) {
2062  /* calc from frame_bytes, channels, and codec_tag */
2063  if (id == AV_CODEC_ID_SOL_DPCM) {
2064  if (tag == 3)
2065  return frame_bytes / ch;
2066  else
2067  return frame_bytes * 2 / ch;
2068  }
2069  }
2070 
2071  if (ba > 0) {
2072  /* calc from frame_bytes, channels, and block_align */
2073  int blocks = frame_bytes / ba;
2074  switch (avctx->codec_id) {
2076  return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2078  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2080  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2081  case AV_CODEC_ID_ADPCM_MS:
2082  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2083  }
2084  }
2085 
2086  if (bps > 0) {
2087  /* calc from frame_bytes, channels, and bits_per_coded_sample */
2088  switch (avctx->codec_id) {
2089  case AV_CODEC_ID_PCM_DVD:
2090  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2092  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
2093  case AV_CODEC_ID_S302M:
2094  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2095  }
2096  }
2097  }
2098  }
2099 
2100  return 0;
2101 }
2102 
2103 #if !HAVE_THREADS
2105 {
2106  return -1;
2107 }
2108 
2109 #endif
2110 
2111 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
2112 {
2113  unsigned int n = 0;
2114 
2115  while (v >= 0xff) {
2116  *s++ = 0xff;
2117  v -= 0xff;
2118  n++;
2119  }
2120  *s = v;
2121  n++;
2122  return n;
2123 }
2124 
2125 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
2126 {
2127  int i;
2128  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
2129  return i;
2130 }
2131 
2132 #if FF_API_MISSING_SAMPLE
2134 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
2135 {
2136  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your Libav "
2137  "version to the newest one from Git. If the problem still "
2138  "occurs, it means that your file has a feature which has not "
2139  "been implemented.\n", feature);
2140  if(want_sample)
2142 }
2143 
2144 void av_log_ask_for_sample(void *avc, const char *msg, ...)
2145 {
2146  va_list argument_list;
2147 
2148  va_start(argument_list, msg);
2149 
2150  if (msg)
2151  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
2152  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
2153  "of this file to ftp://upload.libav.org/incoming/ "
2154  "and contact the libav-devel mailing list.\n");
2155 
2156  va_end(argument_list);
2157 }
2159 #endif /* FF_API_MISSING_SAMPLE */
2160 
2162 
2164 {
2165  AVHWAccel **p = &first_hwaccel;
2166  while (*p)
2167  p = &(*p)->next;
2168  *p = hwaccel;
2169  hwaccel->next = NULL;
2170 }
2171 
2173 {
2174  return hwaccel ? hwaccel->next : first_hwaccel;
2175 }
2176 
2178 {
2179  enum AVCodecID codec_id = avctx->codec->id;
2180  enum AVPixelFormat pix_fmt = avctx->pix_fmt;
2181 
2182  AVHWAccel *hwaccel = NULL;
2183 
2184  while ((hwaccel = av_hwaccel_next(hwaccel)))
2185  if (hwaccel->id == codec_id
2186  && hwaccel->pix_fmt == pix_fmt)
2187  return hwaccel;
2188  return NULL;
2189 }
2190 
2191 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
2192 {
2193  if (lockmgr_cb) {
2195  return -1;
2197  return -1;
2198  }
2199 
2200  lockmgr_cb = cb;
2201 
2202  if (lockmgr_cb) {
2204  return -1;
2206  return -1;
2207  }
2208  return 0;
2209 }
2210 
2212 {
2213  if (lockmgr_cb) {
2215  return -1;
2216  }
2217  return 0;
2218 }
2219 
2221 {
2222  if (lockmgr_cb) {
2224  return -1;
2225  }
2226  return 0;
2227 }
2228 
2229 unsigned int avpriv_toupper4(unsigned int x)
2230 {
2231  return av_toupper(x & 0xFF) +
2232  (av_toupper((x >> 8) & 0xFF) << 8) +
2233  (av_toupper((x >> 16) & 0xFF) << 16) +
2234  (av_toupper((x >> 24) & 0xFF) << 24);
2235 }
2236 
2238 {
2239  int ret;
2240 
2241  dst->owner = src->owner;
2242 
2243  ret = av_frame_ref(dst->f, src->f);
2244  if (ret < 0)
2245  return ret;
2246 
2247  if (src->progress &&
2248  !(dst->progress = av_buffer_ref(src->progress))) {
2249  ff_thread_release_buffer(dst->owner, dst);
2250  return AVERROR(ENOMEM);
2251  }
2252 
2253  return 0;
2254 }
2255 
2256 #if !HAVE_THREADS
2257 
2259 {
2260  f->owner = avctx;
2261  return ff_get_buffer(avctx, f->f, flags);
2262 }
2263 
2265 {
2266  av_frame_unref(f->f);
2267 }
2268 
2270 {
2271 }
2272 
2273 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
2274 {
2275 }
2276 
2277 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
2278 {
2279 }
2280 
2281 #endif
2282 
2284 {
2285  if (codec_id <= AV_CODEC_ID_NONE)
2286  return AVMEDIA_TYPE_UNKNOWN;
2287  else if (codec_id < AV_CODEC_ID_FIRST_AUDIO)
2288  return AVMEDIA_TYPE_VIDEO;
2289  else if (codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
2290  return AVMEDIA_TYPE_AUDIO;
2291  else if (codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
2292  return AVMEDIA_TYPE_SUBTITLE;
2293 
2294  return AVMEDIA_TYPE_UNKNOWN;
2295 }
2296 
2298 {
2299  return !!s->internal;
2300 }
2301 
2303  const uint8_t *end,
2304  uint32_t * restrict state)
2305 {
2306  int i;
2307 
2308  assert(p <= end);
2309  if (p >= end)
2310  return end;
2311 
2312  for (i = 0; i < 3; i++) {
2313  uint32_t tmp = *state << 8;
2314  *state = tmp + *(p++);
2315  if (tmp == 0x100 || p == end)
2316  return p;
2317  }
2318 
2319  while (p < end) {
2320  if (p[-1] > 1 ) p += 3;
2321  else if (p[-2] ) p += 2;
2322  else if (p[-3]|(p[-1]-1)) p++;
2323  else {
2324  p++;
2325  break;
2326  }
2327  }
2328 
2329  p = FFMIN(p, end) - 4;
2330  *state = AV_RB32(p);
2331 
2332  return p + 4;
2333 }
#define WRAP_PLANE(ref_out, data, data_size)
#define FF_SANE_NB_CHANNELS
Definition: internal.h:36
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2332
static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1352
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:84
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
FF_ENABLE_DEPRECATION_WARNINGS int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:575
#define CONFIG_DSPUTIL
Definition: config.h:356
const struct AVCodec * codec
Definition: avcodec.h:1063
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:157
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:1637
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define AV_NUM_DATA_POINTERS
Definition: frame.h:108
#define HAVE_THREADS
Definition: config.h:250
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
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:2952
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1507
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:1654
#define c2
Definition: idct_sh4.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:108
int stride_align[AV_NUM_DATA_POINTERS]
Definition: internal.h:50
A dummy id pointing at the start of audio codecs.
Definition: avcodec.h:289
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:150
enum AVCodecID id
Definition: mxfenc.c:84
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:669
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:798
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1227
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:2846
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:2191
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
misc image utilities
Unlock the mutex.
Definition: avcodec.h:4292
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
AVFrame * f
Definition: thread.h:36
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1545
AVFrame * to_free
Definition: internal.h:87
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:365
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:668
static AVFrame * picture
Definition: output.c:179
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2506
int width
Definition: internal.h:49
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:153
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2152
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:504
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:1871
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:383
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:160
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:974
char codec_name[32]
Definition: avcodec.h:1064
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:1876
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:2879
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:1422
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: utils.c:1158
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: internal.h:97
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:180
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
int samples
Definition: internal.h:54
unsigned num_rects
Definition: avcodec.h:3011
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer with padding, reusing the given one if large enough.
Definition: utils.c:70
A dummy ID pointing at the start of various fake codecs.
Definition: avcodec.h:449
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:147
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:292
enum AVMediaType type
Definition: avcodec.h:2768
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:1715
#define FF_ARRAY_ELEMS(a)
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:43
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:2840
int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
Definition: utils.c:1194
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:1557
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:788
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:1927
four components are given, that's all.
Definition: avcodec.h:2950
int profile
profile
Definition: avcodec.h:2596
AVCodec.
Definition: avcodec.h:2755
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1816
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:68
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:4289
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:144
attribute_deprecated void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:1941
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:2996
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:131
Macro definitions for various function/variable attributes.
#define FFALIGN(x, a)
Definition: common.h:62
FF_DISABLE_DEPRECATION_WARNINGS void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
Definition: utils.c:2134
static void * codec_mutex
Definition: utils.c:55
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1173
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:469
AVSubtitleRect ** rects
Definition: avcodec.h:3012
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:111
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill audio frame data and linesize.
Definition: utils.c:291
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:106
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:276
static int volatile entangled_thread_counter
Definition: utils.c:53
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
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 channel data pointers and linesize for samples with sample format sample_fmt.
Definition: samplefmt.c:140
Public dictionary API.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:104
int height
Definition: internal.h:49
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Definition: utils.c:830
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1787
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:85
Lock the mutex.
Definition: avcodec.h:4291
uint8_t
#define av_cold
Definition: attributes.h:66
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:43
Opaque data information usually continuous.
Definition: avutil.h:189
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
AVOptions.
attribute_deprecated void(* destruct)(struct AVPacket *)
Definition: avcodec.h:998
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: avcodec.h:2951
#define AV_RB32
Definition: intreadwrite.h:130
void * thread_ctx
Definition: internal.h:91
static AVCodec * first_avcodec
Definition: utils.c:84
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
Definition: utils.c:156
Multithreading support functions.
#define b
Definition: input.c:52
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:174
#define emms_c()
Definition: internal.h:46
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:183
#define LIBAVCODEC_VERSION_INT
Definition: version.h:35
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:755
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1162
const char * name
#define LICENSE_PREFIX
int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
Definition: utils.c:1292
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:711
int planes
Definition: internal.h:52
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:973
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:73
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:103
static int(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:54
static int flags
Definition: log.c:44
uint32_t tag
Definition: movenc.c:822
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
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:2125
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2481
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:995
AVCodecContext * owner
Definition: thread.h:37
#define FF_BUFFER_TYPE_INTERNAL
Definition: avcodec.h:863
#define r
Definition: input.c:51
FramePool * pool
Definition: internal.h:89
static void compat_release_buffer(void *opaque, uint8_t *data)
Definition: utils.c:567
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1023
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:1659
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:182
static av_cold void avcodec_init(void)
Definition: utils.c:94
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:148
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:173
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:138
Libavcodec version macros.
int(* close)(AVCodecContext *)
Definition: avcodec.h:2841
av_cold int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:1590
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:80
enum AVCodecID id
Definition: avcodec.h:2769
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:2779
#define STRIDE_ALIGN
Definition: utils.c:179
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:161
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:156
AVHWAccel * av_hwaccel_next(AVHWAccel *hwaccel)
If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL...
Definition: utils.c:2172
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:167
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:105
int width
width and height of the video frame
Definition: frame.h:146
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1938
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
Create a mutex.
Definition: avcodec.h:4290
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: mem.c:349
#define CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: avcodec.h:790
#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:740
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: avcodec.h:904
#define AVERROR(e)
Definition: error.h:43
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2229
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:55
int qmax
maximum quantizer
Definition: avcodec.h:2068
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:86
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:745
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2533
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2297
g
Definition: yuv2rgb.c:535
int capabilities
Codec capabilities.
Definition: avcodec.h:2774
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:2104
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:159
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:956
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:152
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1142
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:103
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:53
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
Definition: utils.c:2283
int av_log_get_level(void)
Get the current log level.
Definition: log.c:165
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:139
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
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_buffer_realloc(AVBufferRef **pbuf, int size)
Reallocate a given buffer.
Definition: buffer.c:146
enum AVCodecID codec_id
Definition: mov_chan.c:432
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:82
#define FFMAX(a, b)
Definition: common.h:55
#define LIBAV_CONFIGURATION
Definition: config.h:4
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:244
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
reference-counted frame API
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1840
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2093
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:353
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:2826
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:509
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:130
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:220
static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:327
int bit_rate
the average bitrate
Definition: avcodec.h:1112
audio channel layout utility functions
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2776
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2390
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:2993
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2525
#define FFMIN(a, b)
Definition: common.h:57
const uint8_t * avpriv_find_start_code(const uint8_t *restrict p, const uint8_t *end, uint32_t *restrict state)
Definition: utils.c:2302
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:206
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:379
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1893
int channels
Definition: internal.h:53
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:824
int width
picture width / height.
Definition: avcodec.h:1217
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2597
int priv_data_size
Definition: avcodec.h:2793
int profile
Definition: avcodec.h:2744
attribute_deprecated int reference
Definition: frame.h:211
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:794
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:179
#define FF_DEBUG_BUFFERS
Definition: avcodec.h:2371
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
Definition: utils.c:2269
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:2784
int64_t reordered_opaque
opaque 64bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:2410
#define AV_EF_EXPLODE
Definition: avcodec.h:2401
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:471
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2050
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:149
int mb_decision
macroblock decision mode
Definition: avcodec.h:1571
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:186
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:2144
Opaque data information usually sparse.
Definition: avutil.h:191
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1125
enum AVPixelFormat pix_fmt
Definition: movenc.c:821
static pthread_mutex_t * mutex
Definition: w32pthreads.h:68
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:428
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
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:158
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
Definition: error.h:62
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2514
int linesize[4]
Definition: internal.h:51
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:1882
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:158
AVBufferRef * progress
Definition: thread.h:40
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:1853
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1799
#define attribute_align_arg
Definition: internal.h:53
NULL
Definition: eval.c:55
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:86
static int width
Definition: utils.c:156
sample_fmt
Definition: avconv_filter.c:68
int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: utils.c:524
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:97
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1062
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:2823
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:793
enum AVCodecID codec_id
Definition: avcodec.h:1065
AVHWAccel.
Definition: avcodec.h:2852
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:301
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:621
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:68
int sample_rate
samples per second
Definition: avcodec.h:1779
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:125
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:168
uint8_t flags
Definition: pixdesc.h:78
int debug
debug
Definition: avcodec.h:2348
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:163
main external API structure.
Definition: avcodec.h:1054
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:1673
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2061
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1571
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:178
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:187
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1080
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:66
uint8_t * data
Definition: frame.h:76
int extradata_size
Definition: avcodec.h:1163
#define AVERROR_BUG
Bug detected, please report the issue.
Definition: error.h:60
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:2111
struct AVCodec * next
Definition: avcodec.h:2794
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
int coded_height
Definition: avcodec.h:1227
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:324
Describe the class of an AVClass context structure.
Definition: log.h:33
int sample_rate
Sample rate of the audio data.
Definition: frame.h:348
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:66
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:436
av_cold void ff_dsputil_static_init(void)
Definition: dsputil.c:2411
Y , 16bpp, big-endian.
Definition: pixfmt.h:100
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:226
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:101
rational number numerator/denominator
Definition: rational.h:43
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:2264
const char * name
short name for the profile
Definition: avcodec.h:2745
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:37
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:160
AVMediaType
Definition: avutil.h:185
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:2037
static FF_ENABLE_DEPRECATION_WARNINGS AVHWAccel * first_hwaccel
Definition: utils.c:2161
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:872
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:1956
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:91
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:188
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:161
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:273
static uint32_t state
Definition: trasher.c:27
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:178
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:1678
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:2783
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:113
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:154
int height
Definition: gxfenc.c:72
static int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:172
const OptionDef options[]
Definition: avserver.c:4624
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:193
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
Definition: avcodec.h:676
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:368
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
Y , 8bpp.
Definition: pixfmt.h:73
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:613
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:75
common internal api header.
Free mutex resources.
Definition: avcodec.h:4293
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
Definition: buffer.c:196
int avpriv_lock_avformat(void)
Definition: utils.c:2211
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:2163
struct AVHWAccel * next
Definition: avcodec.h:2887
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:162
uint32_t start_display_time
Definition: avcodec.h:3009
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:91
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:768
AVProfile.
Definition: avcodec.h:2743
FF_ENABLE_DEPRECATION_WARNINGS 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:1533
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:79
enum AVCodecID id
Codec implemented by the hardware accelerator.
Definition: avcodec.h:2872
void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: utils.c:2273
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:89
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:214
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
AVHWAccel * ff_find_hwaccel(AVCodecContext *avctx)
Return the hardware accelerated codec for codec codec_id and pixel format pix_fmt.
Definition: utils.c:2177
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:46
int den
denominator
Definition: rational.h:45
int avcodec_default_execute2(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
Definition: utils.c:812
unsigned bps
Definition: movenc.c:823
DSP utils.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1735
void * priv_data
Definition: avcodec.h:1090
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition: avcodec.h:454
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:76
#define TAG_PRINT(x)
as in Berlin toast format
Definition: avcodec.h:386
int len
int channels
number of audio channels
Definition: avcodec.h:1780
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:2777
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1098
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:1866
Y , 16bpp, little-endian.
Definition: pixfmt.h:101
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3003
static void * avformat_mutex
Definition: utils.c:56
#define EDGE_WIDTH
Definition: dsputil.h:255
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:163
static int get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:1692
int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
Definition: utils.c:1454
static const struct twinvq_data tab
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:2277
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:177
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:972
av_cold void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:116
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1810
int height
Definition: frame.h:146
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:102
static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
Definition: utils.c:1409
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:286
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:2237
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:153
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:314
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2778
AVMatrixEncoding
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2258
int nb_channels
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1449
int avpriv_unlock_avformat(void)
Definition: utils.c:2220
#define LIBAV_LICENSE
Definition: config.h:5
int(* init)(AVCodecContext *)
Definition: avcodec.h:2825
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:141
int format
Definition: internal.h:48
attribute_deprecated int type
Definition: frame.h:280
#define restrict
Definition: config.h:8
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:85
AVCodecContext avctx
Definition: utils.c:555
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
This structure stores compressed data.
Definition: avcodec.h:950
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: utils.c:1337
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:2838
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:877
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:151
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2327
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:66
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:155
A dummy ID pointing at the start of subtitle codecs.
Definition: avcodec.h:437
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:362
#define FFMAX3(a, b, c)
Definition: common.h:56
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228
static void compat_free_buffer(void *opaque, uint8_t *data)
Definition: utils.c:559
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:164
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:800
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:85
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:2711
FF_DISABLE_DEPRECATION_WARNINGS int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:549
int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
Definition: utils.c:1510
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:151