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  }
251  w_align = 8;
252  h_align = 8;
253  }
254  case AV_PIX_FMT_PAL8:
255  case AV_PIX_FMT_BGR8:
256  case AV_PIX_FMT_RGB8:
257  if (s->codec_id == AV_CODEC_ID_SMC) {
258  w_align = 4;
259  h_align = 4;
260  }
261  if (s->codec_id == AV_CODEC_ID_JV ||
263  w_align = 8;
264  h_align = 8;
265  }
266  break;
267  case AV_PIX_FMT_BGR24:
268  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
269  (s->codec_id == AV_CODEC_ID_ZLIB)) {
270  w_align = 4;
271  h_align = 4;
272  }
273  break;
274  default:
275  w_align = 1;
276  h_align = 1;
277  break;
278  }
279 
280  *width = FFALIGN(*width, w_align);
281  *height = FFALIGN(*height, h_align);
282  if (s->codec_id == AV_CODEC_ID_H264)
283  // some of the optimized chroma MC reads one line too much
284  *height += 2;
285 
286  for (i = 0; i < 4; i++)
287  linesize_align[i] = STRIDE_ALIGN;
288 }
289 
291 {
293  int chroma_shift = desc->log2_chroma_w;
294  int linesize_align[AV_NUM_DATA_POINTERS];
295  int align;
296 
297  avcodec_align_dimensions2(s, width, height, linesize_align);
298  align = FFMAX(linesize_align[0], linesize_align[3]);
299  linesize_align[1] <<= chroma_shift;
300  linesize_align[2] <<= chroma_shift;
301  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
302  *width = FFALIGN(*width, align);
303 }
304 
306  enum AVSampleFormat sample_fmt, const uint8_t *buf,
307  int buf_size, int align)
308 {
309  int ch, planar, needed_size, ret = 0;
310 
311  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
312  frame->nb_samples, sample_fmt,
313  align);
314  if (buf_size < needed_size)
315  return AVERROR(EINVAL);
316 
317  planar = av_sample_fmt_is_planar(sample_fmt);
318  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
319  if (!(frame->extended_data = av_mallocz(nb_channels *
320  sizeof(*frame->extended_data))))
321  return AVERROR(ENOMEM);
322  } else {
323  frame->extended_data = frame->data;
324  }
325 
326  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
327  buf, nb_channels, frame->nb_samples,
328  sample_fmt, align)) < 0) {
329  if (frame->extended_data != frame->data)
330  av_free(frame->extended_data);
331  return ret;
332  }
333  if (frame->extended_data != frame->data) {
334  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
335  frame->data[ch] = frame->extended_data[ch];
336  }
337 
338  return ret;
339 }
340 
341 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
342 {
343  FramePool *pool = avctx->internal->pool;
344  int i, ret;
345 
346  switch (avctx->codec_type) {
347  case AVMEDIA_TYPE_VIDEO: {
348  AVPicture picture;
349  int size[4] = { 0 };
350  int w = frame->width;
351  int h = frame->height;
352  int tmpsize, unaligned;
353 
354  if (pool->format == frame->format &&
355  pool->width == frame->width && pool->height == frame->height)
356  return 0;
357 
358  avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
359 
360  do {
361  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
362  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
363  av_image_fill_linesizes(picture.linesize, avctx->pix_fmt, w);
364  // increase alignment of w for next try (rhs gives the lowest bit set in w)
365  w += w & ~(w - 1);
366 
367  unaligned = 0;
368  for (i = 0; i < 4; i++)
369  unaligned |= picture.linesize[i] % pool->stride_align[i];
370  } while (unaligned);
371 
372  tmpsize = av_image_fill_pointers(picture.data, avctx->pix_fmt, h,
373  NULL, picture.linesize);
374  if (tmpsize < 0)
375  return -1;
376 
377  for (i = 0; i < 3 && picture.data[i + 1]; i++)
378  size[i] = picture.data[i + 1] - picture.data[i];
379  size[i] = tmpsize - (picture.data[i] - picture.data[0]);
380 
381  for (i = 0; i < 4; i++) {
382  av_buffer_pool_uninit(&pool->pools[i]);
383  pool->linesize[i] = picture.linesize[i];
384  if (size[i]) {
385  pool->pools[i] = av_buffer_pool_init(size[i] + 16, NULL);
386  if (!pool->pools[i]) {
387  ret = AVERROR(ENOMEM);
388  goto fail;
389  }
390  }
391  }
392  pool->format = frame->format;
393  pool->width = frame->width;
394  pool->height = frame->height;
395 
396  break;
397  }
398  case AVMEDIA_TYPE_AUDIO: {
400  int planar = av_sample_fmt_is_planar(frame->format);
401  int planes = planar ? ch : 1;
402 
403  if (pool->format == frame->format && pool->planes == planes &&
404  pool->channels == ch && frame->nb_samples == pool->samples)
405  return 0;
406 
407  av_buffer_pool_uninit(&pool->pools[0]);
408  ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
409  frame->nb_samples, frame->format, 0);
410  if (ret < 0)
411  goto fail;
412 
413  pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
414  if (!pool->pools[0]) {
415  ret = AVERROR(ENOMEM);
416  goto fail;
417  }
418 
419  pool->format = frame->format;
420  pool->planes = planes;
421  pool->channels = ch;
422  pool->samples = frame->nb_samples;
423  break;
424  }
425  default: av_assert0(0);
426  }
427  return 0;
428 fail:
429  for (i = 0; i < 4; i++)
430  av_buffer_pool_uninit(&pool->pools[i]);
431  pool->format = -1;
432  pool->planes = pool->channels = pool->samples = 0;
433  pool->width = pool->height = 0;
434  return ret;
435 }
436 
437 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
438 {
439  FramePool *pool = avctx->internal->pool;
440  int planes = pool->planes;
441  int i;
442 
443  frame->linesize[0] = pool->linesize[0];
444 
445  if (planes > AV_NUM_DATA_POINTERS) {
446  frame->extended_data = av_mallocz(planes * sizeof(*frame->extended_data));
447  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
448  frame->extended_buf = av_mallocz(frame->nb_extended_buf *
449  sizeof(*frame->extended_buf));
450  if (!frame->extended_data || !frame->extended_buf) {
451  av_freep(&frame->extended_data);
452  av_freep(&frame->extended_buf);
453  return AVERROR(ENOMEM);
454  }
455  } else
456  frame->extended_data = frame->data;
457 
458  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
459  frame->buf[i] = av_buffer_pool_get(pool->pools[0]);
460  if (!frame->buf[i])
461  goto fail;
462  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
463  }
464  for (i = 0; i < frame->nb_extended_buf; i++) {
465  frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]);
466  if (!frame->extended_buf[i])
467  goto fail;
468  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
469  }
470 
471  if (avctx->debug & FF_DEBUG_BUFFERS)
472  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame);
473 
474  return 0;
475 fail:
476  av_frame_unref(frame);
477  return AVERROR(ENOMEM);
478 }
479 
481 {
482  FramePool *pool = s->internal->pool;
483  int i;
484 
485  if (pic->data[0]) {
486  av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
487  return -1;
488  }
489 
490  memset(pic->data, 0, sizeof(pic->data));
491  pic->extended_data = pic->data;
492 
493  for (i = 0; i < 4 && pool->pools[i]; i++) {
494  pic->linesize[i] = pool->linesize[i];
495 
496  pic->buf[i] = av_buffer_pool_get(pool->pools[i]);
497  if (!pic->buf[i])
498  goto fail;
499 
500  pic->data[i] = pic->buf[i]->data;
501  }
502  for (; i < AV_NUM_DATA_POINTERS; i++) {
503  pic->data[i] = NULL;
504  pic->linesize[i] = 0;
505  }
506  if (pic->data[1] && !pic->data[2])
507  avpriv_set_systematic_pal2((uint32_t *)pic->data[1], s->pix_fmt);
508 
509  if (s->debug & FF_DEBUG_BUFFERS)
510  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic);
511 
512  return 0;
513 fail:
514  av_frame_unref(pic);
515  return AVERROR(ENOMEM);
516 }
517 
519 {
520  int ret;
521 
522  if ((ret = update_frame_pool(avctx, frame)) < 0)
523  return ret;
524 
525 #if FF_API_GET_BUFFER
527  frame->type = FF_BUFFER_TYPE_INTERNAL;
529 #endif
530 
531  switch (avctx->codec_type) {
532  case AVMEDIA_TYPE_VIDEO:
533  return video_get_buffer(avctx, frame);
534  case AVMEDIA_TYPE_AUDIO:
535  return audio_get_buffer(avctx, frame);
536  default:
537  return -1;
538  }
539 }
540 
541 #if FF_API_GET_BUFFER
544 {
545  return avcodec_default_get_buffer2(avctx, frame, 0);
546 }
547 
548 typedef struct CompatReleaseBufPriv {
552 
553 static void compat_free_buffer(void *opaque, uint8_t *data)
554 {
555  CompatReleaseBufPriv *priv = opaque;
556  if (priv->avctx.release_buffer)
557  priv->avctx.release_buffer(&priv->avctx, &priv->frame);
558  av_freep(&priv);
559 }
560 
561 static void compat_release_buffer(void *opaque, uint8_t *data)
562 {
563  AVBufferRef *buf = opaque;
564  av_buffer_unref(&buf);
565 }
567 #endif
568 
570 {
571  AVPacket *pkt = avctx->internal->pkt;
572  uint8_t *packet_sd;
573  int size;
574  AVFrameSideData *frame_sd;
575 
576  frame->color_primaries = avctx->color_primaries;
577  frame->color_trc = avctx->color_trc;
578  frame->colorspace = avctx->colorspace;
579  frame->color_range = avctx->color_range;
580  frame->chroma_location = avctx->chroma_sample_location;
581 
582  frame->reordered_opaque = avctx->reordered_opaque;
583  if (!pkt) {
584  frame->pkt_pts = AV_NOPTS_VALUE;
585  return 0;
586  }
587 
588  frame->pkt_pts = pkt->pts;
589 
590  /* copy the replaygain data to the output frame */
591  packet_sd = av_packet_get_side_data(pkt, AV_PKT_DATA_REPLAYGAIN, &size);
592  if (packet_sd) {
593  frame_sd = av_frame_new_side_data(frame, AV_FRAME_DATA_REPLAYGAIN, size);
594  if (!frame_sd)
595  return AVERROR(ENOMEM);
596 
597  memcpy(frame_sd->data, packet_sd, size);
598  }
599  /* copy the displaymatrix to the output frame */
600  packet_sd = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size);
601  if (packet_sd) {
602  frame_sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, size);
603  if (!frame_sd)
604  return AVERROR(ENOMEM);
605 
606  memcpy(frame_sd->data, packet_sd, size);
607  }
608  /* copy the stereo3d format to the output frame */
609  packet_sd = av_packet_get_side_data(pkt, AV_PKT_DATA_STEREO3D, &size);
610  if (packet_sd) {
611  frame_sd = av_frame_new_side_data(frame, AV_FRAME_DATA_STEREO3D, size);
612  if (!frame_sd)
613  return AVERROR(ENOMEM);
614 
615  memcpy(frame_sd->data, packet_sd, size);
616  }
617 
618  return 0;
619 }
620 
621 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
622 {
623  const AVHWAccel *hwaccel = avctx->hwaccel;
624  int override_dimensions = 1;
625  int ret;
626 
627  switch (avctx->codec_type) {
628  case AVMEDIA_TYPE_VIDEO:
629  if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) {
630  frame->width = frame->height = 0;
631  return AVERROR(EINVAL);
632  }
633  if (frame->width <= 0 || frame->height <= 0) {
634  frame->width = FFMAX(avctx->width, avctx->coded_width);
635  frame->height = FFMAX(avctx->height, avctx->coded_height);
636  override_dimensions = 0;
637  }
638  if (frame->format < 0)
639  frame->format = avctx->pix_fmt;
640  if (!frame->sample_aspect_ratio.num)
642 
643  if (av_image_check_sar(frame->width, frame->height,
644  frame->sample_aspect_ratio) < 0) {
645  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
646  frame->sample_aspect_ratio.num,
647  frame->sample_aspect_ratio.den);
648  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
649  }
650  break;
651  case AVMEDIA_TYPE_AUDIO:
652  if (!frame->sample_rate)
653  frame->sample_rate = avctx->sample_rate;
654  if (frame->format < 0)
655  frame->format = avctx->sample_fmt;
656  if (!frame->channel_layout) {
657  if (avctx->channel_layout) {
659  avctx->channels) {
660  av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
661  "configuration.\n");
662  return AVERROR(EINVAL);
663  }
664 
665  frame->channel_layout = avctx->channel_layout;
666  } else {
667  if (avctx->channels > FF_SANE_NB_CHANNELS) {
668  av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
669  avctx->channels);
670  return AVERROR(ENOSYS);
671  }
672 
674  if (!frame->channel_layout)
675  frame->channel_layout = (1ULL << avctx->channels) - 1;
676  }
677  }
678  break;
679  default: return AVERROR(EINVAL);
680  }
681 
682  ret = ff_decode_frame_props(avctx, frame);
683  if (ret < 0) {
684  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
685  frame->width = frame->height = 0;
686  return ret;
687  }
688 
689  if (hwaccel && hwaccel->alloc_frame) {
690  ret = hwaccel->alloc_frame(avctx, frame);
691  goto end;
692  }
693 
694 #if FF_API_GET_BUFFER
696  /*
697  * Wrap an old get_buffer()-allocated buffer in an bunch of AVBuffers.
698  * We wrap each plane in its own AVBuffer. Each of those has a reference to
699  * a dummy AVBuffer as its private data, unreffing it on free.
700  * When all the planes are freed, the dummy buffer's free callback calls
701  * release_buffer().
702  */
703  if (avctx->get_buffer) {
704  CompatReleaseBufPriv *priv = NULL;
705  AVBufferRef *dummy_buf = NULL;
706  int planes, i, ret;
707 
708  if (flags & AV_GET_BUFFER_FLAG_REF)
709  frame->reference = 1;
710 
711  ret = avctx->get_buffer(avctx, frame);
712  if (ret < 0) {
713  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
714  frame->width = frame->height = 0;
715  return ret;
716  }
717 
718  /* return if the buffers are already set up
719  * this would happen e.g. when a custom get_buffer() calls
720  * avcodec_default_get_buffer
721  */
722  if (frame->buf[0])
723  return 0;
724 
725  priv = av_mallocz(sizeof(*priv));
726  if (!priv) {
727  ret = AVERROR(ENOMEM);
728  goto fail;
729  }
730  priv->avctx = *avctx;
731  priv->frame = *frame;
732 
733  dummy_buf = av_buffer_create(NULL, 0, compat_free_buffer, priv, 0);
734  if (!dummy_buf) {
735  ret = AVERROR(ENOMEM);
736  goto fail;
737  }
738 
739 #define WRAP_PLANE(ref_out, data, data_size) \
740 do { \
741  AVBufferRef *dummy_ref = av_buffer_ref(dummy_buf); \
742  if (!dummy_ref) { \
743  ret = AVERROR(ENOMEM); \
744  goto fail; \
745  } \
746  ref_out = av_buffer_create(data, data_size, compat_release_buffer, \
747  dummy_ref, 0); \
748  if (!ref_out) { \
749  av_frame_unref(frame); \
750  ret = AVERROR(ENOMEM); \
751  goto fail; \
752  } \
753 } while (0)
754 
755  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
756  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
757 
758  planes = av_pix_fmt_count_planes(frame->format);
759  /* workaround for AVHWAccel plane count of 0, buf[0] is used as
760  check for allocated buffers: make libavcodec happy */
761  if (desc && desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
762  planes = 1;
763  if (!desc || planes <= 0) {
764  ret = AVERROR(EINVAL);
765  goto fail;
766  }
767 
768  for (i = 0; i < planes; i++) {
769  int v_shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
770  int plane_size = (frame->height >> v_shift) * frame->linesize[i];
771 
772  WRAP_PLANE(frame->buf[i], frame->data[i], plane_size);
773  }
774  } else {
775  int planar = av_sample_fmt_is_planar(frame->format);
776  planes = planar ? avctx->channels : 1;
777 
778  if (planes > FF_ARRAY_ELEMS(frame->buf)) {
779  frame->nb_extended_buf = planes - FF_ARRAY_ELEMS(frame->buf);
780  frame->extended_buf = av_malloc(sizeof(*frame->extended_buf) *
781  frame->nb_extended_buf);
782  if (!frame->extended_buf) {
783  ret = AVERROR(ENOMEM);
784  goto fail;
785  }
786  }
787 
788  for (i = 0; i < FFMIN(planes, FF_ARRAY_ELEMS(frame->buf)); i++)
789  WRAP_PLANE(frame->buf[i], frame->extended_data[i], frame->linesize[0]);
790 
791  for (i = 0; i < frame->nb_extended_buf; i++)
792  WRAP_PLANE(frame->extended_buf[i],
793  frame->extended_data[i + FF_ARRAY_ELEMS(frame->buf)],
794  frame->linesize[0]);
795  }
796 
797  av_buffer_unref(&dummy_buf);
798 
799  frame->width = avctx->width;
800  frame->height = avctx->height;
801 
802  return 0;
803 
804 fail:
805  avctx->release_buffer(avctx, frame);
806  av_freep(&priv);
807  av_buffer_unref(&dummy_buf);
808  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
809  frame->width = frame->height = 0;
810  return ret;
811  }
813 #endif
814 
815  ret = avctx->get_buffer2(avctx, frame, flags);
816 
817 end:
818  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) {
819  frame->width = avctx->width;
820  frame->height = avctx->height;
821  }
822 
823  if ((ret < 0) && (avctx->codec_type == AVMEDIA_TYPE_VIDEO))
824  frame->width = frame->height = 0;
825 
826  return ret;
827 }
828 
830 {
831  AVFrame *tmp;
832  int ret;
833 
835 
836  if (!frame->data[0])
837  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
838 
839  if (av_frame_is_writable(frame))
840  return ff_decode_frame_props(avctx, frame);
841 
842  tmp = av_frame_alloc();
843  if (!tmp)
844  return AVERROR(ENOMEM);
845 
846  av_frame_move_ref(tmp, frame);
847 
848  ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
849  if (ret < 0) {
850  av_frame_free(&tmp);
851  return ret;
852  }
853 
854  av_frame_copy(frame, tmp);
855  av_frame_free(&tmp);
856 
857  return 0;
858 }
859 
860 #if FF_API_GET_BUFFER
862 {
863  av_frame_unref(pic);
864 }
865 
867 {
868  av_assert0(0);
869  return AVERROR_BUG;
870 }
871 #endif
872 
873 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
874 {
875  int i;
876 
877  for (i = 0; i < count; i++) {
878  int r = func(c, (char *)arg + i * size);
879  if (ret)
880  ret[i] = r;
881  }
882  return 0;
883 }
884 
885 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
886 {
887  int i;
888 
889  for (i = 0; i < count; i++) {
890  int r = func(c, arg, i, 0);
891  if (ret)
892  ret[i] = r;
893  }
894  return 0;
895 }
896 
898 {
899  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
900  return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
901 }
902 
904 {
905  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
906  ++fmt;
907  return fmt[0];
908 }
909 
911  enum AVPixelFormat pix_fmt)
912 {
913  AVHWAccel *hwaccel = NULL;
914 
915  while ((hwaccel = av_hwaccel_next(hwaccel)))
916  if (hwaccel->id == codec_id
917  && hwaccel->pix_fmt == pix_fmt)
918  return hwaccel;
919  return NULL;
920 }
921 
922 
923 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
924 {
925  const AVPixFmtDescriptor *desc;
926  enum AVPixelFormat ret = avctx->get_format(avctx, fmt);
927 
928  desc = av_pix_fmt_desc_get(ret);
929  if (!desc)
930  return AV_PIX_FMT_NONE;
931 
932  if (avctx->hwaccel && avctx->hwaccel->uninit)
933  avctx->hwaccel->uninit(avctx);
935  avctx->hwaccel = NULL;
936 
937  if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
938  AVHWAccel *hwaccel;
939  int err;
940 
941  hwaccel = find_hwaccel(avctx->codec_id, ret);
942  if (!hwaccel) {
943  av_log(avctx, AV_LOG_ERROR,
944  "Could not find an AVHWAccel for the pixel format: %s",
945  desc->name);
946  return AV_PIX_FMT_NONE;
947  }
948 
949  if (hwaccel->priv_data_size) {
951  if (!avctx->internal->hwaccel_priv_data)
952  return AV_PIX_FMT_NONE;
953  }
954 
955  if (hwaccel->init) {
956  err = hwaccel->init(avctx);
957  if (err < 0) {
959  return AV_PIX_FMT_NONE;
960  }
961  }
962  avctx->hwaccel = hwaccel;
963  }
964 
965  return ret;
966 }
967 
968 #if FF_API_AVFRAME_LAVC
969 void avcodec_get_frame_defaults(AVFrame *frame)
970 {
971  if (frame->extended_data != frame->data)
972  av_freep(&frame->extended_data);
973 
974  memset(frame, 0, sizeof(AVFrame));
975 
976  frame->pts = AV_NOPTS_VALUE;
977  frame->key_frame = 1;
978  frame->sample_aspect_ratio = (AVRational) {0, 1 };
979  frame->format = -1; /* unknown */
980  frame->extended_data = frame->data;
981 }
982 
983 AVFrame *avcodec_alloc_frame(void)
984 {
985  AVFrame *frame = av_mallocz(sizeof(AVFrame));
986 
987  if (!frame)
988  return NULL;
989 
991  avcodec_get_frame_defaults(frame);
993 
994  return frame;
995 }
996 
997 void avcodec_free_frame(AVFrame **frame)
998 {
999  av_frame_free(frame);
1000 }
1001 #endif
1002 
1004 {
1005  int ret = 0;
1006  AVDictionary *tmp = NULL;
1007 
1008  if (avcodec_is_open(avctx))
1009  return 0;
1010 
1011  if ((!codec && !avctx->codec)) {
1012  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
1013  return AVERROR(EINVAL);
1014  }
1015  if ((codec && avctx->codec && codec != avctx->codec)) {
1016  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
1017  "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
1018  return AVERROR(EINVAL);
1019  }
1020  if (!codec)
1021  codec = avctx->codec;
1022 
1023  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
1024  return AVERROR(EINVAL);
1025 
1026  if (options)
1027  av_dict_copy(&tmp, *options, 0);
1028 
1029  /* If there is a user-supplied mutex locking routine, call it. */
1030  if (lockmgr_cb) {
1032  return -1;
1033  }
1034 
1036  if (entangled_thread_counter != 1) {
1037  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1038  ret = -1;
1039  goto end;
1040  }
1041 
1042  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
1043  if (!avctx->internal) {
1044  ret = AVERROR(ENOMEM);
1045  goto end;
1046  }
1047 
1048  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
1049  if (!avctx->internal->pool) {
1050  ret = AVERROR(ENOMEM);
1051  goto free_and_end;
1052  }
1053 
1054  avctx->internal->to_free = av_frame_alloc();
1055  if (!avctx->internal->to_free) {
1056  ret = AVERROR(ENOMEM);
1057  goto free_and_end;
1058  }
1059 
1060  if (codec->priv_data_size > 0) {
1061  if (!avctx->priv_data) {
1062  avctx->priv_data = av_mallocz(codec->priv_data_size);
1063  if (!avctx->priv_data) {
1064  ret = AVERROR(ENOMEM);
1065  goto end;
1066  }
1067  if (codec->priv_class) {
1068  *(const AVClass **)avctx->priv_data = codec->priv_class;
1070  }
1071  }
1072  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
1073  goto free_and_end;
1074  } else {
1075  avctx->priv_data = NULL;
1076  }
1077  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
1078  goto free_and_end;
1079 
1080  if (avctx->coded_width && avctx->coded_height && !avctx->width && !avctx->height)
1081  ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
1082  else if (avctx->width && avctx->height)
1083  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
1084  if (ret < 0)
1085  goto free_and_end;
1086 
1087  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
1088  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
1089  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
1090  av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
1091  ff_set_dimensions(avctx, 0, 0);
1092  }
1093 
1094  if (avctx->width > 0 && avctx->height > 0) {
1095  if (av_image_check_sar(avctx->width, avctx->height,
1096  avctx->sample_aspect_ratio) < 0) {
1097  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1098  avctx->sample_aspect_ratio.num,
1099  avctx->sample_aspect_ratio.den);
1100  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
1101  }
1102  }
1103 
1104  /* if the decoder init function was already called previously,
1105  * free the already allocated subtitle_header before overwriting it */
1106  if (av_codec_is_decoder(codec))
1107  av_freep(&avctx->subtitle_header);
1108 
1109  if (avctx->channels > FF_SANE_NB_CHANNELS) {
1110  ret = AVERROR(EINVAL);
1111  goto free_and_end;
1112  }
1113 
1114  avctx->codec = codec;
1115  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
1116  avctx->codec_id == AV_CODEC_ID_NONE) {
1117  avctx->codec_type = codec->type;
1118  avctx->codec_id = codec->id;
1119  }
1120  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
1121  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
1122  av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
1123  ret = AVERROR(EINVAL);
1124  goto free_and_end;
1125  }
1126  avctx->frame_number = 0;
1127 
1128  if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
1130  ret = AVERROR_EXPERIMENTAL;
1131  goto free_and_end;
1132  }
1133 
1134  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1135  (!avctx->time_base.num || !avctx->time_base.den)) {
1136  avctx->time_base.num = 1;
1137  avctx->time_base.den = avctx->sample_rate;
1138  }
1139 
1140  if (HAVE_THREADS) {
1141  ret = ff_thread_init(avctx);
1142  if (ret < 0) {
1143  goto free_and_end;
1144  }
1145  }
1146  if (!HAVE_THREADS && !(codec->capabilities & CODEC_CAP_AUTO_THREADS))
1147  avctx->thread_count = 1;
1148 
1149  if (av_codec_is_encoder(avctx->codec)) {
1150  int i;
1151  if (avctx->codec->sample_fmts) {
1152  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
1153  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
1154  break;
1155  if (avctx->channels == 1 &&
1158  avctx->sample_fmt = avctx->codec->sample_fmts[i];
1159  break;
1160  }
1161  }
1162  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
1163  av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
1164  ret = AVERROR(EINVAL);
1165  goto free_and_end;
1166  }
1167  }
1168  if (avctx->codec->pix_fmts) {
1169  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
1170  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
1171  break;
1172  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
1173  av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n");
1174  ret = AVERROR(EINVAL);
1175  goto free_and_end;
1176  }
1177  }
1178  if (avctx->codec->supported_samplerates) {
1179  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
1180  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
1181  break;
1182  if (avctx->codec->supported_samplerates[i] == 0) {
1183  av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
1184  ret = AVERROR(EINVAL);
1185  goto free_and_end;
1186  }
1187  }
1188  if (avctx->codec->channel_layouts) {
1189  if (!avctx->channel_layout) {
1190  av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
1191  } else {
1192  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
1193  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
1194  break;
1195  if (avctx->codec->channel_layouts[i] == 0) {
1196  av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
1197  ret = AVERROR(EINVAL);
1198  goto free_and_end;
1199  }
1200  }
1201  }
1202  if (avctx->channel_layout && avctx->channels) {
1204  av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
1205  ret = AVERROR(EINVAL);
1206  goto free_and_end;
1207  }
1208  } else if (avctx->channel_layout) {
1210  }
1211 
1212  if (!avctx->rc_initial_buffer_occupancy)
1213  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
1214  }
1215 
1216  if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) {
1217  ret = avctx->codec->init(avctx);
1218  if (ret < 0) {
1219  goto free_and_end;
1220  }
1221  }
1222 
1223  if (av_codec_is_decoder(avctx->codec)) {
1224  /* validate channel layout from the decoder */
1225  if (avctx->channel_layout) {
1226  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1227  if (!avctx->channels)
1228  avctx->channels = channels;
1229  else if (channels != avctx->channels) {
1230  av_log(avctx, AV_LOG_WARNING,
1231  "channel layout does not match number of channels\n");
1232  avctx->channel_layout = 0;
1233  }
1234  }
1235  if (avctx->channels && avctx->channels < 0 ||
1236  avctx->channels > FF_SANE_NB_CHANNELS) {
1237  ret = AVERROR(EINVAL);
1238  goto free_and_end;
1239  }
1240  }
1241 end:
1243 
1244  /* Release any user-supplied mutex. */
1245  if (lockmgr_cb) {
1246  (*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1247  }
1248  if (options) {
1249  av_dict_free(options);
1250  *options = tmp;
1251  }
1252 
1253  return ret;
1254 free_and_end:
1255  av_dict_free(&tmp);
1256  av_freep(&avctx->priv_data);
1257  if (avctx->internal) {
1258  av_frame_free(&avctx->internal->to_free);
1259  av_freep(&avctx->internal->pool);
1260  }
1261  av_freep(&avctx->internal);
1262  avctx->codec = NULL;
1263  goto end;
1264 }
1265 
1267 {
1268  if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
1269  return AVERROR(EINVAL);
1270 
1271  if (avpkt->data) {
1272  AVBufferRef *buf = avpkt->buf;
1273 #if FF_API_DESTRUCT_PACKET
1275  void *destruct = avpkt->destruct;
1277 #endif
1278 
1279  if (avpkt->size < size)
1280  return AVERROR(EINVAL);
1281 
1282  av_init_packet(avpkt);
1283 #if FF_API_DESTRUCT_PACKET
1285  avpkt->destruct = destruct;
1287 #endif
1288  avpkt->buf = buf;
1289  avpkt->size = size;
1290  return 0;
1291  } else {
1292  return av_new_packet(avpkt, size);
1293  }
1294 }
1295 
1299 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
1300 {
1301  AVFrame *frame = NULL;
1302  int ret;
1303 
1304  if (!(frame = av_frame_alloc()))
1305  return AVERROR(ENOMEM);
1306 
1307  frame->format = src->format;
1308  frame->channel_layout = src->channel_layout;
1309  frame->nb_samples = s->frame_size;
1310  ret = av_frame_get_buffer(frame, 32);
1311  if (ret < 0)
1312  goto fail;
1313 
1314  ret = av_frame_copy_props(frame, src);
1315  if (ret < 0)
1316  goto fail;
1317 
1318  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
1319  src->nb_samples, s->channels, s->sample_fmt)) < 0)
1320  goto fail;
1321  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
1322  frame->nb_samples - src->nb_samples,
1323  s->channels, s->sample_fmt)) < 0)
1324  goto fail;
1325 
1326  *dst = frame;
1327 
1328  return 0;
1329 
1330 fail:
1331  av_frame_free(&frame);
1332  return ret;
1333 }
1334 
1336  AVPacket *avpkt,
1337  const AVFrame *frame,
1338  int *got_packet_ptr)
1339 {
1340  AVFrame tmp;
1341  AVFrame *padded_frame = NULL;
1342  int ret;
1343  int user_packet = !!avpkt->data;
1344 
1345  *got_packet_ptr = 0;
1346 
1347  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1348  av_free_packet(avpkt);
1349  av_init_packet(avpkt);
1350  return 0;
1351  }
1352 
1353  /* ensure that extended_data is properly set */
1354  if (frame && !frame->extended_data) {
1355  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
1356  avctx->channels > AV_NUM_DATA_POINTERS) {
1357  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
1358  "with more than %d channels, but extended_data is not set.\n",
1360  return AVERROR(EINVAL);
1361  }
1362  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
1363 
1364  tmp = *frame;
1365  tmp.extended_data = tmp.data;
1366  frame = &tmp;
1367  }
1368 
1369  /* check for valid frame size */
1370  if (frame) {
1372  if (frame->nb_samples > avctx->frame_size)
1373  return AVERROR(EINVAL);
1374  } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
1375  if (frame->nb_samples < avctx->frame_size &&
1376  !avctx->internal->last_audio_frame) {
1377  ret = pad_last_frame(avctx, &padded_frame, frame);
1378  if (ret < 0)
1379  return ret;
1380 
1381  frame = padded_frame;
1382  avctx->internal->last_audio_frame = 1;
1383  }
1384 
1385  if (frame->nb_samples != avctx->frame_size) {
1386  ret = AVERROR(EINVAL);
1387  goto end;
1388  }
1389  }
1390  }
1391 
1392  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1393  if (!ret) {
1394  if (*got_packet_ptr) {
1395  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
1396  if (avpkt->pts == AV_NOPTS_VALUE)
1397  avpkt->pts = frame->pts;
1398  if (!avpkt->duration)
1399  avpkt->duration = ff_samples_to_time_base(avctx,
1400  frame->nb_samples);
1401  }
1402  avpkt->dts = avpkt->pts;
1403  } else {
1404  avpkt->size = 0;
1405  }
1406 
1407  if (!user_packet && avpkt->size) {
1408  ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
1409  if (ret >= 0)
1410  avpkt->data = avpkt->buf->data;
1411  }
1412 
1413  avctx->frame_number++;
1414  }
1415 
1416  if (ret < 0 || !*got_packet_ptr) {
1417  av_free_packet(avpkt);
1418  av_init_packet(avpkt);
1419  goto end;
1420  }
1421 
1422  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1423  * this needs to be moved to the encoders, but for now we can do it
1424  * here to simplify things */
1425  avpkt->flags |= AV_PKT_FLAG_KEY;
1426 
1427 end:
1428  av_frame_free(&padded_frame);
1429 
1430  return ret;
1431 }
1432 
1434  AVPacket *avpkt,
1435  const AVFrame *frame,
1436  int *got_packet_ptr)
1437 {
1438  int ret;
1439  int user_packet = !!avpkt->data;
1440 
1441  *got_packet_ptr = 0;
1442 
1443  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1444  av_free_packet(avpkt);
1445  av_init_packet(avpkt);
1446  avpkt->size = 0;
1447  return 0;
1448  }
1449 
1450  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
1451  return AVERROR(EINVAL);
1452 
1453  av_assert0(avctx->codec->encode2);
1454 
1455  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1456  if (!ret) {
1457  if (!*got_packet_ptr)
1458  avpkt->size = 0;
1459  else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
1460  avpkt->pts = avpkt->dts = frame->pts;
1461 
1462  if (!user_packet && avpkt->size) {
1463  ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
1464  if (ret >= 0)
1465  avpkt->data = avpkt->buf->data;
1466  }
1467 
1468  avctx->frame_number++;
1469  }
1470 
1471  if (ret < 0 || !*got_packet_ptr)
1472  av_free_packet(avpkt);
1473 
1474  emms_c();
1475  return ret;
1476 }
1477 
1478 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1479  const AVSubtitle *sub)
1480 {
1481  int ret;
1482  if (sub->start_display_time) {
1483  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1484  return -1;
1485  }
1486  if (sub->num_rects == 0 || !sub->rects)
1487  return -1;
1488  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
1489  avctx->frame_number++;
1490  return ret;
1491 }
1492 
1493 static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1494 {
1495  int size = 0, ret;
1496  const uint8_t *data;
1497  uint32_t flags;
1498 
1499  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1500  if (!data)
1501  return 0;
1502 
1503  if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) {
1504  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
1505  "changes, but PARAM_CHANGE side data was sent to it.\n");
1506  return AVERROR(EINVAL);
1507  }
1508 
1509  if (size < 4)
1510  goto fail;
1511 
1512  flags = bytestream_get_le32(&data);
1513  size -= 4;
1514 
1516  if (size < 4)
1517  goto fail;
1518  avctx->channels = bytestream_get_le32(&data);
1519  size -= 4;
1520  }
1522  if (size < 8)
1523  goto fail;
1524  avctx->channel_layout = bytestream_get_le64(&data);
1525  size -= 8;
1526  }
1528  if (size < 4)
1529  goto fail;
1530  avctx->sample_rate = bytestream_get_le32(&data);
1531  size -= 4;
1532  }
1534  if (size < 8)
1535  goto fail;
1536  avctx->width = bytestream_get_le32(&data);
1537  avctx->height = bytestream_get_le32(&data);
1538  size -= 8;
1539  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
1540  if (ret < 0)
1541  return ret;
1542  }
1543 
1544  return 0;
1545 fail:
1546  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
1547  return AVERROR_INVALIDDATA;
1548 }
1549 
1550 static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
1551 {
1552  int ret;
1553 
1554  /* move the original frame to our backup */
1555  av_frame_unref(avci->to_free);
1556  av_frame_move_ref(avci->to_free, frame);
1557 
1558  /* now copy everything except the AVBufferRefs back
1559  * note that we make a COPY of the side data, so calling av_frame_free() on
1560  * the caller's frame will work properly */
1561  ret = av_frame_copy_props(frame, avci->to_free);
1562  if (ret < 0)
1563  return ret;
1564 
1565  memcpy(frame->data, avci->to_free->data, sizeof(frame->data));
1566  memcpy(frame->linesize, avci->to_free->linesize, sizeof(frame->linesize));
1567  if (avci->to_free->extended_data != avci->to_free->data) {
1569  int size = planes * sizeof(*frame->extended_data);
1570 
1571  if (!size) {
1572  av_frame_unref(frame);
1573  return AVERROR_BUG;
1574  }
1575 
1576  frame->extended_data = av_malloc(size);
1577  if (!frame->extended_data) {
1578  av_frame_unref(frame);
1579  return AVERROR(ENOMEM);
1580  }
1581  memcpy(frame->extended_data, avci->to_free->extended_data,
1582  size);
1583  } else
1584  frame->extended_data = frame->data;
1585 
1586  frame->format = avci->to_free->format;
1587  frame->width = avci->to_free->width;
1588  frame->height = avci->to_free->height;
1589  frame->channel_layout = avci->to_free->channel_layout;
1590  frame->nb_samples = avci->to_free->nb_samples;
1591 
1592  return 0;
1593 }
1594 
1596  int *got_picture_ptr,
1597  AVPacket *avpkt)
1598 {
1599  AVCodecInternal *avci = avctx->internal;
1600  int ret;
1601 
1602  *got_picture_ptr = 0;
1603  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
1604  return -1;
1605 
1606  avctx->internal->pkt = avpkt;
1607  ret = apply_param_change(avctx, avpkt);
1608  if (ret < 0) {
1609  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
1610  if (avctx->err_recognition & AV_EF_EXPLODE)
1611  return ret;
1612  }
1613 
1614  av_frame_unref(picture);
1615 
1616  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
1618  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
1619  avpkt);
1620  else {
1621  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
1622  avpkt);
1623  picture->pkt_dts = avpkt->dts;
1624  /* get_buffer is supposed to set frame parameters */
1625  if (!(avctx->codec->capabilities & CODEC_CAP_DR1)) {
1626  picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
1627  picture->width = avctx->width;
1628  picture->height = avctx->height;
1629  picture->format = avctx->pix_fmt;
1630  }
1631  }
1632 
1633  emms_c(); //needed to avoid an emms_c() call before every return;
1634 
1635  if (*got_picture_ptr) {
1636  if (!avctx->refcounted_frames) {
1637  int err = unrefcount_frame(avci, picture);
1638  if (err < 0)
1639  return err;
1640  }
1641 
1642  avctx->frame_number++;
1643  } else
1644  av_frame_unref(picture);
1645  } else
1646  ret = 0;
1647 
1648  return ret;
1649 }
1650 
1652  AVFrame *frame,
1653  int *got_frame_ptr,
1654  AVPacket *avpkt)
1655 {
1656  AVCodecInternal *avci = avctx->internal;
1657  int ret = 0;
1658 
1659  *got_frame_ptr = 0;
1660 
1661  avctx->internal->pkt = avpkt;
1662 
1663  if (!avpkt->data && avpkt->size) {
1664  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1665  return AVERROR(EINVAL);
1666  }
1667 
1668  ret = apply_param_change(avctx, avpkt);
1669  if (ret < 0) {
1670  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
1671  if (avctx->err_recognition & AV_EF_EXPLODE)
1672  return ret;
1673  }
1674 
1675  av_frame_unref(frame);
1676 
1677  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1678  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1679  if (ret >= 0 && *got_frame_ptr) {
1680  avctx->frame_number++;
1681  frame->pkt_dts = avpkt->dts;
1682  if (frame->format == AV_SAMPLE_FMT_NONE)
1683  frame->format = avctx->sample_fmt;
1684 
1685  if (!avctx->refcounted_frames) {
1686  int err = unrefcount_frame(avci, frame);
1687  if (err < 0)
1688  return err;
1689  }
1690  } else
1691  av_frame_unref(frame);
1692  }
1693 
1694 
1695  return ret;
1696 }
1697 
1699  int *got_sub_ptr,
1700  AVPacket *avpkt)
1701 {
1702  int ret;
1703 
1704  avctx->internal->pkt = avpkt;
1705  *got_sub_ptr = 0;
1706  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1707  if (*got_sub_ptr)
1708  avctx->frame_number++;
1709  return ret;
1710 }
1711 
1713 {
1714  int i;
1715 
1716  for (i = 0; i < sub->num_rects; i++) {
1717  av_freep(&sub->rects[i]->pict.data[0]);
1718  av_freep(&sub->rects[i]->pict.data[1]);
1719  av_freep(&sub->rects[i]->pict.data[2]);
1720  av_freep(&sub->rects[i]->pict.data[3]);
1721  av_freep(&sub->rects[i]->text);
1722  av_freep(&sub->rects[i]->ass);
1723  av_freep(&sub->rects[i]);
1724  }
1725 
1726  av_freep(&sub->rects);
1727 
1728  memset(sub, 0, sizeof(AVSubtitle));
1729 }
1730 
1732 {
1733  if (avcodec_is_open(avctx)) {
1734  FramePool *pool = avctx->internal->pool;
1735  int i;
1736  if (HAVE_THREADS && avctx->internal->thread_ctx)
1737  ff_thread_free(avctx);
1738  if (avctx->codec && avctx->codec->close)
1739  avctx->codec->close(avctx);
1740  avctx->coded_frame = NULL;
1741  av_frame_free(&avctx->internal->to_free);
1742  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
1743  av_buffer_pool_uninit(&pool->pools[i]);
1744  av_freep(&avctx->internal->pool);
1745 
1746  if (avctx->hwaccel && avctx->hwaccel->uninit)
1747  avctx->hwaccel->uninit(avctx);
1749 
1750  av_freep(&avctx->internal);
1751  }
1752 
1753  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1754  av_opt_free(avctx->priv_data);
1755  av_opt_free(avctx);
1756  av_freep(&avctx->priv_data);
1757  if (av_codec_is_encoder(avctx->codec))
1758  av_freep(&avctx->extradata);
1759  avctx->codec = NULL;
1760  avctx->active_thread_type = 0;
1761 
1762  return 0;
1763 }
1764 
1765 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1766 {
1767  AVCodec *p, *experimental = NULL;
1768  p = first_avcodec;
1769  while (p) {
1770  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1771  p->id == id) {
1772  if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1773  experimental = p;
1774  } else
1775  return p;
1776  }
1777  p = p->next;
1778  }
1779  return experimental;
1780 }
1781 
1783 {
1784  return find_encdec(id, 1);
1785 }
1786 
1788 {
1789  AVCodec *p;
1790  if (!name)
1791  return NULL;
1792  p = first_avcodec;
1793  while (p) {
1794  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
1795  return p;
1796  p = p->next;
1797  }
1798  return NULL;
1799 }
1800 
1802 {
1803  return find_encdec(id, 0);
1804 }
1805 
1807 {
1808  AVCodec *p;
1809  if (!name)
1810  return NULL;
1811  p = first_avcodec;
1812  while (p) {
1813  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
1814  return p;
1815  p = p->next;
1816  }
1817  return NULL;
1818 }
1819 
1821 {
1822  int bit_rate;
1823  int bits_per_sample;
1824 
1825  switch (ctx->codec_type) {
1826  case AVMEDIA_TYPE_VIDEO:
1827  case AVMEDIA_TYPE_DATA:
1828  case AVMEDIA_TYPE_SUBTITLE:
1830  bit_rate = ctx->bit_rate;
1831  break;
1832  case AVMEDIA_TYPE_AUDIO:
1833  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1834  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1835  break;
1836  default:
1837  bit_rate = 0;
1838  break;
1839  }
1840  return bit_rate;
1841 }
1842 
1843 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1844 {
1845  int i, len, ret = 0;
1846 
1847 #define TAG_PRINT(x) \
1848  (((x) >= '0' && (x) <= '9') || \
1849  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
1850  ((x) == '.' || (x) == ' '))
1851 
1852  for (i = 0; i < 4; i++) {
1853  len = snprintf(buf, buf_size,
1854  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
1855  buf += len;
1856  buf_size = buf_size > len ? buf_size - len : 0;
1857  ret += len;
1858  codec_tag >>= 8;
1859  }
1860  return ret;
1861 }
1862 
1863 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1864 {
1865  const char *codec_name;
1866  const char *profile = NULL;
1867  const AVCodec *p;
1868  char buf1[32];
1869  int bitrate;
1870  AVRational display_aspect_ratio;
1871 
1872  if (enc->codec)
1873  p = enc->codec;
1874  else if (encode)
1875  p = avcodec_find_encoder(enc->codec_id);
1876  else
1877  p = avcodec_find_decoder(enc->codec_id);
1878 
1879  if (p) {
1880  codec_name = p->name;
1881  profile = av_get_profile_name(p, enc->profile);
1882  } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) {
1883  /* fake mpeg2 transport stream codec (currently not
1884  * registered) */
1885  codec_name = "mpeg2ts";
1886  } else {
1887  /* output avi tags */
1888  char tag_buf[32];
1889  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1890  snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
1891  codec_name = buf1;
1892  }
1893 
1894  switch (enc->codec_type) {
1895  case AVMEDIA_TYPE_VIDEO:
1896  snprintf(buf, buf_size,
1897  "Video: %s%s",
1898  codec_name, enc->mb_decision ? " (hq)" : "");
1899  if (profile)
1900  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1901  " (%s)", profile);
1902  if (enc->pix_fmt != AV_PIX_FMT_NONE) {
1903  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1904  ", %s",
1906  }
1907  if (enc->width) {
1908  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1909  ", %dx%d",
1910  enc->width, enc->height);
1911  if (enc->sample_aspect_ratio.num) {
1912  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1913  enc->width * enc->sample_aspect_ratio.num,
1914  enc->height * enc->sample_aspect_ratio.den,
1915  1024 * 1024);
1916  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1917  " [PAR %d:%d DAR %d:%d]",
1919  display_aspect_ratio.num, display_aspect_ratio.den);
1920  }
1921  if (av_log_get_level() >= AV_LOG_DEBUG) {
1922  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1923  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1924  ", %d/%d",
1925  enc->time_base.num / g, enc->time_base.den / g);
1926  }
1927  }
1928  if (encode) {
1929  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1930  ", q=%d-%d", enc->qmin, enc->qmax);
1931  }
1932  break;
1933  case AVMEDIA_TYPE_AUDIO:
1934  snprintf(buf, buf_size,
1935  "Audio: %s",
1936  codec_name);
1937  if (profile)
1938  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1939  " (%s)", profile);
1940  if (enc->sample_rate) {
1941  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1942  ", %d Hz", enc->sample_rate);
1943  }
1944  av_strlcat(buf, ", ", buf_size);
1945  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1946  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1947  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1948  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1949  }
1950  break;
1951  case AVMEDIA_TYPE_DATA:
1952  snprintf(buf, buf_size, "Data: %s", codec_name);
1953  break;
1954  case AVMEDIA_TYPE_SUBTITLE:
1955  snprintf(buf, buf_size, "Subtitle: %s", codec_name);
1956  break;
1958  snprintf(buf, buf_size, "Attachment: %s", codec_name);
1959  break;
1960  default:
1961  snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
1962  return;
1963  }
1964  if (encode) {
1965  if (enc->flags & CODEC_FLAG_PASS1)
1966  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1967  ", pass 1");
1968  if (enc->flags & CODEC_FLAG_PASS2)
1969  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1970  ", pass 2");
1971  }
1972  bitrate = get_bit_rate(enc);
1973  if (bitrate != 0) {
1974  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1975  ", %d kb/s", bitrate / 1000);
1976  }
1977 }
1978 
1979 const char *av_get_profile_name(const AVCodec *codec, int profile)
1980 {
1981  const AVProfile *p;
1982  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1983  return NULL;
1984 
1985  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1986  if (p->profile == profile)
1987  return p->name;
1988 
1989  return NULL;
1990 }
1991 
1992 unsigned avcodec_version(void)
1993 {
1994  return LIBAVCODEC_VERSION_INT;
1995 }
1996 
1997 const char *avcodec_configuration(void)
1998 {
1999  return LIBAV_CONFIGURATION;
2000 }
2001 
2002 const char *avcodec_license(void)
2003 {
2004 #define LICENSE_PREFIX "libavcodec license: "
2005  return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
2006 }
2007 
2009 {
2011  ff_thread_flush(avctx);
2012  else if (avctx->codec->flush)
2013  avctx->codec->flush(avctx);
2014 
2015  if (!avctx->refcounted_frames)
2016  av_frame_unref(avctx->internal->to_free);
2017 }
2018 
2020 {
2021  switch (codec_id) {
2022  case AV_CODEC_ID_ADPCM_CT:
2028  return 4;
2029  case AV_CODEC_ID_PCM_ALAW:
2030  case AV_CODEC_ID_PCM_MULAW:
2031  case AV_CODEC_ID_PCM_S8:
2032  case AV_CODEC_ID_PCM_U8:
2033  case AV_CODEC_ID_PCM_ZORK:
2034  return 8;
2035  case AV_CODEC_ID_PCM_S16BE:
2036  case AV_CODEC_ID_PCM_S16LE:
2038  case AV_CODEC_ID_PCM_U16BE:
2039  case AV_CODEC_ID_PCM_U16LE:
2040  return 16;
2042  case AV_CODEC_ID_PCM_S24BE:
2043  case AV_CODEC_ID_PCM_S24LE:
2045  case AV_CODEC_ID_PCM_U24BE:
2046  case AV_CODEC_ID_PCM_U24LE:
2047  return 24;
2048  case AV_CODEC_ID_PCM_S32BE:
2049  case AV_CODEC_ID_PCM_S32LE:
2051  case AV_CODEC_ID_PCM_U32BE:
2052  case AV_CODEC_ID_PCM_U32LE:
2053  case AV_CODEC_ID_PCM_F32BE:
2054  case AV_CODEC_ID_PCM_F32LE:
2055  return 32;
2056  case AV_CODEC_ID_PCM_F64BE:
2057  case AV_CODEC_ID_PCM_F64LE:
2058  return 64;
2059  default:
2060  return 0;
2061  }
2062 }
2063 
2065 {
2066  switch (codec_id) {
2068  return 2;
2070  return 3;
2074  case AV_CODEC_ID_ADPCM_SWF:
2075  case AV_CODEC_ID_ADPCM_MS:
2076  return 4;
2077  default:
2078  return av_get_exact_bits_per_sample(codec_id);
2079  }
2080 }
2081 
2082 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
2083 {
2084  int id, sr, ch, ba, tag, bps;
2085 
2086  id = avctx->codec_id;
2087  sr = avctx->sample_rate;
2088  ch = avctx->channels;
2089  ba = avctx->block_align;
2090  tag = avctx->codec_tag;
2091  bps = av_get_exact_bits_per_sample(avctx->codec_id);
2092 
2093  /* codecs with an exact constant bits per sample */
2094  if (bps > 0 && ch > 0 && frame_bytes > 0)
2095  return (frame_bytes * 8) / (bps * ch);
2096  bps = avctx->bits_per_coded_sample;
2097 
2098  /* codecs with a fixed packet duration */
2099  switch (id) {
2100  case AV_CODEC_ID_ADPCM_ADX: return 32;
2101  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
2102  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
2103  case AV_CODEC_ID_AMR_NB:
2104  case AV_CODEC_ID_GSM:
2105  case AV_CODEC_ID_QCELP:
2106  case AV_CODEC_ID_RA_144:
2107  case AV_CODEC_ID_RA_288: return 160;
2108  case AV_CODEC_ID_IMC: return 256;
2109  case AV_CODEC_ID_AMR_WB:
2110  case AV_CODEC_ID_GSM_MS: return 320;
2111  case AV_CODEC_ID_MP1: return 384;
2112  case AV_CODEC_ID_ATRAC1: return 512;
2113  case AV_CODEC_ID_ATRAC3: return 1024;
2114  case AV_CODEC_ID_MP2:
2115  case AV_CODEC_ID_MUSEPACK7: return 1152;
2116  case AV_CODEC_ID_AC3: return 1536;
2117  }
2118 
2119  if (sr > 0) {
2120  /* calc from sample rate */
2121  if (id == AV_CODEC_ID_TTA)
2122  return 256 * sr / 245;
2123 
2124  if (ch > 0) {
2125  /* calc from sample rate and channels */
2126  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
2127  return (480 << (sr / 22050)) / ch;
2128  }
2129  }
2130 
2131  if (ba > 0) {
2132  /* calc from block_align */
2133  if (id == AV_CODEC_ID_SIPR) {
2134  switch (ba) {
2135  case 20: return 160;
2136  case 19: return 144;
2137  case 29: return 288;
2138  case 37: return 480;
2139  }
2140  } else if (id == AV_CODEC_ID_ILBC) {
2141  switch (ba) {
2142  case 38: return 160;
2143  case 50: return 240;
2144  }
2145  }
2146  }
2147 
2148  if (frame_bytes > 0) {
2149  /* calc from frame_bytes only */
2150  if (id == AV_CODEC_ID_TRUESPEECH)
2151  return 240 * (frame_bytes / 32);
2152  if (id == AV_CODEC_ID_NELLYMOSER)
2153  return 256 * (frame_bytes / 64);
2154 
2155  if (bps > 0) {
2156  /* calc from frame_bytes and bits_per_coded_sample */
2157  if (id == AV_CODEC_ID_ADPCM_G726)
2158  return frame_bytes * 8 / bps;
2159  }
2160 
2161  if (ch > 0) {
2162  /* calc from frame_bytes and channels */
2163  switch (id) {
2164  case AV_CODEC_ID_ADPCM_4XM:
2166  return (frame_bytes - 4 * ch) * 2 / ch;
2168  return (frame_bytes - 4) * 2 / ch;
2170  return (frame_bytes - 8) * 2 / ch;
2171  case AV_CODEC_ID_ADPCM_XA:
2172  return (frame_bytes / 128) * 224 / ch;
2174  return (frame_bytes - 6 - ch) / ch;
2175  case AV_CODEC_ID_ROQ_DPCM:
2176  return (frame_bytes - 8) / ch;
2177  case AV_CODEC_ID_XAN_DPCM:
2178  return (frame_bytes - 2 * ch) / ch;
2179  case AV_CODEC_ID_MACE3:
2180  return 3 * frame_bytes / ch;
2181  case AV_CODEC_ID_MACE6:
2182  return 6 * frame_bytes / ch;
2183  case AV_CODEC_ID_PCM_LXF:
2184  return 2 * (frame_bytes / (5 * ch));
2185  }
2186 
2187  if (tag) {
2188  /* calc from frame_bytes, channels, and codec_tag */
2189  if (id == AV_CODEC_ID_SOL_DPCM) {
2190  if (tag == 3)
2191  return frame_bytes / ch;
2192  else
2193  return frame_bytes * 2 / ch;
2194  }
2195  }
2196 
2197  if (ba > 0) {
2198  /* calc from frame_bytes, channels, and block_align */
2199  int blocks = frame_bytes / ba;
2200  switch (avctx->codec_id) {
2202  return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2204  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2206  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2207  case AV_CODEC_ID_ADPCM_MS:
2208  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2209  }
2210  }
2211 
2212  if (bps > 0) {
2213  /* calc from frame_bytes, channels, and bits_per_coded_sample */
2214  switch (avctx->codec_id) {
2215  case AV_CODEC_ID_PCM_DVD:
2216  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2218  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
2219  case AV_CODEC_ID_S302M:
2220  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2221  }
2222  }
2223  }
2224  }
2225 
2226  return 0;
2227 }
2228 
2229 #if !HAVE_THREADS
2231 {
2232  return -1;
2233 }
2234 
2235 #endif
2236 
2237 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
2238 {
2239  unsigned int n = 0;
2240 
2241  while (v >= 0xff) {
2242  *s++ = 0xff;
2243  v -= 0xff;
2244  n++;
2245  }
2246  *s = v;
2247  n++;
2248  return n;
2249 }
2250 
2251 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
2252 {
2253  int i;
2254  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
2255  return i;
2256 }
2257 
2258 #if FF_API_MISSING_SAMPLE
2260 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
2261 {
2262  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your Libav "
2263  "version to the newest one from Git. If the problem still "
2264  "occurs, it means that your file has a feature which has not "
2265  "been implemented.\n", feature);
2266  if(want_sample)
2268 }
2269 
2270 void av_log_ask_for_sample(void *avc, const char *msg, ...)
2271 {
2272  va_list argument_list;
2273 
2274  va_start(argument_list, msg);
2275 
2276  if (msg)
2277  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
2278  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
2279  "of this file to ftp://upload.libav.org/incoming/ "
2280  "and contact the libav-devel mailing list.\n");
2281 
2282  va_end(argument_list);
2283 }
2285 #endif /* FF_API_MISSING_SAMPLE */
2286 
2288 
2290 {
2291  AVHWAccel **p = &first_hwaccel;
2292  while (*p)
2293  p = &(*p)->next;
2294  *p = hwaccel;
2295  hwaccel->next = NULL;
2296 }
2297 
2299 {
2300  return hwaccel ? hwaccel->next : first_hwaccel;
2301 }
2302 
2303 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
2304 {
2305  if (lockmgr_cb) {
2307  return -1;
2309  return -1;
2310  }
2311 
2312  lockmgr_cb = cb;
2313 
2314  if (lockmgr_cb) {
2316  return -1;
2318  return -1;
2319  }
2320  return 0;
2321 }
2322 
2324 {
2325  if (lockmgr_cb) {
2327  return -1;
2328  }
2329  return 0;
2330 }
2331 
2333 {
2334  if (lockmgr_cb) {
2336  return -1;
2337  }
2338  return 0;
2339 }
2340 
2341 unsigned int avpriv_toupper4(unsigned int x)
2342 {
2343  return av_toupper(x & 0xFF) +
2344  (av_toupper((x >> 8) & 0xFF) << 8) +
2345  (av_toupper((x >> 16) & 0xFF) << 16) +
2346  (av_toupper((x >> 24) & 0xFF) << 24);
2347 }
2348 
2350 {
2351  int ret;
2352 
2353  dst->owner = src->owner;
2354 
2355  ret = av_frame_ref(dst->f, src->f);
2356  if (ret < 0)
2357  return ret;
2358 
2359  if (src->progress &&
2360  !(dst->progress = av_buffer_ref(src->progress))) {
2361  ff_thread_release_buffer(dst->owner, dst);
2362  return AVERROR(ENOMEM);
2363  }
2364 
2365  return 0;
2366 }
2367 
2368 #if !HAVE_THREADS
2369 
2371 {
2372  f->owner = avctx;
2373  return ff_get_buffer(avctx, f->f, flags);
2374 }
2375 
2377 {
2378  if (f->f)
2379  av_frame_unref(f->f);
2380 }
2381 
2383 {
2384 }
2385 
2386 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
2387 {
2388 }
2389 
2390 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
2391 {
2392 }
2393 
2394 #endif
2395 
2397 {
2398  if (codec_id <= AV_CODEC_ID_NONE)
2399  return AVMEDIA_TYPE_UNKNOWN;
2400  else if (codec_id < AV_CODEC_ID_FIRST_AUDIO)
2401  return AVMEDIA_TYPE_VIDEO;
2402  else if (codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
2403  return AVMEDIA_TYPE_AUDIO;
2404  else if (codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
2405  return AVMEDIA_TYPE_SUBTITLE;
2406 
2407  return AVMEDIA_TYPE_UNKNOWN;
2408 }
2409 
2411 {
2412  return !!s->internal;
2413 }
2414 
2416  const uint8_t *end,
2417  uint32_t * restrict state)
2418 {
2419  int i;
2420 
2421  assert(p <= end);
2422  if (p >= end)
2423  return end;
2424 
2425  for (i = 0; i < 3; i++) {
2426  uint32_t tmp = *state << 8;
2427  *state = tmp + *(p++);
2428  if (tmp == 0x100 || p == end)
2429  return p;
2430  }
2431 
2432  while (p < end) {
2433  if (p[-1] > 1 ) p += 3;
2434  else if (p[-2] ) p += 2;
2435  else if (p[-3]|(p[-1]-1)) p++;
2436  else {
2437  p++;
2438  break;
2439  }
2440  }
2441 
2442  p = FFMIN(p, end) - 4;
2443  *state = AV_RB32(p);
2444 
2445  return p + 4;
2446 }
#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:2362
static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1493
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:1765
#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:3044
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:1782
int(* init)(AVCodecContext *avctx)
Initialize the hwaccel private data.
Definition: avcodec.h:3014
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:1244
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:2903
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:2303
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:4402
#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:2548
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:2180
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:1997
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1782
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:2002
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:2936
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:1445
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: utils.c:1299
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:1270
int samples
Definition: internal.h:56
unsigned num_rects
Definition: avcodec.h:3103
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:2825
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:1843
#define FF_ARRAY_ELEMS(a)
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:45
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:2897
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:1335
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:1698
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:861
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:1955
four components are given, that's all.
Definition: avcodec.h:3042
int profile
profile
Definition: avcodec.h:2638
AVCodec.
Definition: avcodec.h:2812
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1844
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:4399
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
attribute_deprecated void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:1969
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:3088
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:2260
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:3104
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:100
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:305
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:290
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2448
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:903
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1815
Lock the mutex.
Definition: avcodec.h:4401
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.
attribute_deprecated void(* destruct)(struct AVPacket *)
Definition: avcodec.h:994
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: avcodec.h:3043
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:829
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:1433
#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(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:55
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
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 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:2251
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2523
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:1789
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:561
#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:1787
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.
int(* close)(AVCodecContext *)
Definition: avcodec.h:2898
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:1731
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:2826
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:2836
#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:2064
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:4400
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:2341
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:2096
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:2575
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2410
g
Definition: yuv2rgb.c:535
int capabilities
Codec capabilities.
Definition: avcodec.h:2831
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:2230
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:2396
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:2819
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:3028
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:1868
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:2121
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
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:2883
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:910
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:341
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:2833
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2422
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3085
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2567
#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:2415
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:2019
int channels
Definition: internal.h:55
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: avcodec.h:2956
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:897
int width
picture width / height.
Definition: avcodec.h:1229
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2639
int priv_data_size
Definition: avcodec.h:2850
int profile
Definition: avcodec.h:2801
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:569
#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:1761
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:2403
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:2382
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:2841
int64_t reordered_opaque
opaque 64bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:2441
#define AV_EF_EXPLODE
Definition: avcodec.h:2433
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:480
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2078
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:1597
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:186
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:2270
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:1266
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:437
#define HAVE_THREADS
Definition: config.h:302
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:2556
int linesize[4]
Definition: internal.h:53
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:2008
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:1979
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1827
#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:518
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
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:2880
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:866
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:2909
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:1807
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:2378
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:1801
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2089
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1712
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
#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:2237
struct AVCodec * next
Definition: avcodec.h:2851
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
int coded_height
Definition: avcodec.h:1244
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
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
Definition: avcodec.h:1317
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:1775
rational number numerator/denominator
Definition: rational.h:43
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1768
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:2376
const char * name
short name for the profile
Definition: avcodec.h:2802
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
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:2065
static FF_ENABLE_DEPRECATION_WARNINGS AVHWAccel * first_hwaccel
Definition: utils.c:2287
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:1003
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:2082
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:2298
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:1806
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:621
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:2840
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
common internal api header.
Free mutex resources.
Definition: avcodec.h:4403
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:2323
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:2289
struct AVHWAccel * next
Definition: avcodec.h:2951
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:165
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: avcodec.h:3022
#define restrict
Definition: config.h:8
#define CONFIG_ME_CMP
Definition: config.h:427
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:104
uint32_t start_display_time
Definition: avcodec.h:3101
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:2800
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:2929
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:2386
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:885
unsigned bps
Definition: movenc.c:845
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1863
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
#define TAG_PRINT(x)
as in Berlin toast format
Definition: avcodec.h:396
int len
int channels
number of audio channels
Definition: avcodec.h:1808
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:2834
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:1992
Y , 16bpp, little-endian.
Definition: pixfmt.h:101
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3095
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:1820
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:1595
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:2390
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:1838
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:1550
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:923
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:2349
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:2835
AVMatrixEncoding
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2370
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:2332
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:76
int(* init)(AVCodecContext *)
Definition: avcodec.h:2882
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:549
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:1478
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:2895
#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:2357
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:553
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:873
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:2753
FF_DISABLE_DEPRECATION_WARNINGS int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:543
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:1651
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:154