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