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/hwcontext.h"
36 #include "libavutil/internal.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/pixdesc.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/samplefmt.h"
41 #include "libavutil/dict.h"
42 #include "avcodec.h"
43 #include "libavutil/opt.h"
44 #include "me_cmp.h"
45 #include "mpegvideo.h"
46 #include "thread.h"
47 #include "internal.h"
48 #include "bytestream.h"
49 #include "version.h"
50 #include <stdlib.h>
51 #include <stdarg.h>
52 #include <limits.h>
53 #include <float.h>
54 
55 static int volatile entangled_thread_counter = 0;
56 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op);
57 static void *codec_mutex;
58 static void *avformat_mutex;
59 
60 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
61 {
62  void **p = ptr;
63  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
64  av_freep(p);
65  *size = 0;
66  return;
67  }
68  av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
69  if (*size)
70  memset((uint8_t *)*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
71 }
72 
73 /* encoder management */
75 
77 {
78  if (c)
79  return c->next;
80  else
81  return first_avcodec;
82 }
83 
84 static av_cold void avcodec_init(void)
85 {
86  static int initialized = 0;
87 
88  if (initialized != 0)
89  return;
90  initialized = 1;
91 
92  if (CONFIG_ME_CMP)
94 }
95 
96 int av_codec_is_encoder(const AVCodec *codec)
97 {
98  return codec && (codec->encode_sub || codec->encode2 ||codec->send_frame);
99 }
100 
101 int av_codec_is_decoder(const AVCodec *codec)
102 {
103  return codec && (codec->decode || codec->send_packet);
104 }
105 
107 {
108  AVCodec **p;
109  avcodec_init();
110  p = &first_avcodec;
111  while (*p)
112  p = &(*p)->next;
113  *p = codec;
114  codec->next = NULL;
115 
116  if (codec->init_static_data)
117  codec->init_static_data(codec);
118 }
119 
120 #if FF_API_EMU_EDGE
122 {
123  return EDGE_WIDTH;
124 }
125 #endif
126 
127 #if FF_API_SET_DIMENSIONS
129 {
130  ff_set_dimensions(s, width, height);
131 }
132 #endif
133 
135 {
136  int ret = av_image_check_size(width, height, 0, s);
137 
138  if (ret < 0)
139  width = height = 0;
140  s->width = s->coded_width = width;
141  s->height = s->coded_height = height;
142 
143  return ret;
144 }
145 
147 {
148  int ret = av_image_check_sar(avctx->width, avctx->height, sar);
149 
150  if (ret < 0) {
151  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
152  sar.num, sar.den);
153  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
154  return ret;
155  } else {
156  avctx->sample_aspect_ratio = sar;
157  }
158  return 0;
159 }
160 
162  enum AVMatrixEncoding matrix_encoding)
163 {
164  AVFrameSideData *side_data;
165  enum AVMatrixEncoding *data;
166 
168  if (!side_data)
170  sizeof(enum AVMatrixEncoding));
171 
172  if (!side_data)
173  return AVERROR(ENOMEM);
174 
175  data = (enum AVMatrixEncoding*)side_data->data;
176  *data = matrix_encoding;
177 
178  return 0;
179 }
180 
181 #if HAVE_SIMD_ALIGN_32
182 # define STRIDE_ALIGN 32
183 #elif HAVE_SIMD_ALIGN_16
184 # define STRIDE_ALIGN 16
185 #else
186 # define STRIDE_ALIGN 8
187 #endif
188 
190  int linesize_align[AV_NUM_DATA_POINTERS])
191 {
192  int i;
193  int w_align = 1;
194  int h_align = 1;
195 
196  switch (s->pix_fmt) {
197  case AV_PIX_FMT_YUV420P:
198  case AV_PIX_FMT_YUYV422:
199  case AV_PIX_FMT_YVYU422:
200  case AV_PIX_FMT_UYVY422:
201  case AV_PIX_FMT_YUV422P:
202  case AV_PIX_FMT_YUV440P:
203  case AV_PIX_FMT_YUV444P:
204  case AV_PIX_FMT_GBRP:
205  case AV_PIX_FMT_GBRAP:
206  case AV_PIX_FMT_GRAY8:
207  case AV_PIX_FMT_GRAY16BE:
208  case AV_PIX_FMT_GRAY16LE:
209  case AV_PIX_FMT_YUVJ420P:
210  case AV_PIX_FMT_YUVJ422P:
211  case AV_PIX_FMT_YUVJ440P:
212  case AV_PIX_FMT_YUVJ444P:
213  case AV_PIX_FMT_YUVA420P:
214  case AV_PIX_FMT_YUVA422P:
215  case AV_PIX_FMT_YUVA444P:
232  case AV_PIX_FMT_GBRP9LE:
233  case AV_PIX_FMT_GBRP9BE:
234  case AV_PIX_FMT_GBRP10LE:
235  case AV_PIX_FMT_GBRP10BE:
236  w_align = 16; //FIXME assume 16 pixel per macroblock
237  h_align = 16 * 2; // interlaced needs 2 macroblocks height
238  break;
239  case AV_PIX_FMT_YUV411P:
241  w_align = 32;
242  h_align = 8;
243  break;
244  case AV_PIX_FMT_YUV410P:
245  if (s->codec_id == AV_CODEC_ID_SVQ1) {
246  w_align = 64;
247  h_align = 64;
248  }
249  case AV_PIX_FMT_RGB555:
250  if (s->codec_id == AV_CODEC_ID_RPZA) {
251  w_align = 4;
252  h_align = 4;
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  break;
262  case AV_PIX_FMT_BGR24:
263  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
264  (s->codec_id == AV_CODEC_ID_ZLIB)) {
265  w_align = 4;
266  h_align = 4;
267  }
268  break;
269  default:
270  w_align = 1;
271  h_align = 1;
272  break;
273  }
274 
275  *width = FFALIGN(*width, w_align);
276  *height = FFALIGN(*height, h_align);
277  if (s->codec_id == AV_CODEC_ID_H264)
278  // some of the optimized chroma MC reads one line too much
279  *height += 2;
280 
281  for (i = 0; i < 4; i++)
282  linesize_align[i] = STRIDE_ALIGN;
283 }
284 
286 {
288  int chroma_shift = desc->log2_chroma_w;
289  int linesize_align[AV_NUM_DATA_POINTERS];
290  int align;
291 
292  avcodec_align_dimensions2(s, width, height, linesize_align);
293  align = FFMAX(linesize_align[0], linesize_align[3]);
294  linesize_align[1] <<= chroma_shift;
295  linesize_align[2] <<= chroma_shift;
296  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
297  *width = FFALIGN(*width, align);
298 }
299 
301  enum AVSampleFormat sample_fmt, const uint8_t *buf,
302  int buf_size, int align)
303 {
304  int ch, planar, needed_size, ret = 0;
305 
306  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
307  frame->nb_samples, sample_fmt,
308  align);
309  if (buf_size < needed_size)
310  return AVERROR(EINVAL);
311 
312  planar = av_sample_fmt_is_planar(sample_fmt);
313  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
314  if (!(frame->extended_data = av_mallocz(nb_channels *
315  sizeof(*frame->extended_data))))
316  return AVERROR(ENOMEM);
317  } else {
318  frame->extended_data = frame->data;
319  }
320 
321  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
322  buf, nb_channels, frame->nb_samples,
323  sample_fmt, align)) < 0) {
324  if (frame->extended_data != frame->data)
325  av_free(frame->extended_data);
326  return ret;
327  }
328  if (frame->extended_data != frame->data) {
329  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
330  frame->data[ch] = frame->extended_data[ch];
331  }
332 
333  return ret;
334 }
335 
336 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
337 {
338  FramePool *pool = avctx->internal->pool;
339  int i, ret;
340 
341  switch (avctx->codec_type) {
342  case AVMEDIA_TYPE_VIDEO: {
343  uint8_t *data[4];
344  int linesize[4];
345  int size[4] = { 0 };
346  int w = frame->width;
347  int h = frame->height;
348  int tmpsize, unaligned;
349 
350  if (pool->format == frame->format &&
351  pool->width == frame->width && pool->height == frame->height)
352  return 0;
353 
354  avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
355 
356  do {
357  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
358  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
359  av_image_fill_linesizes(linesize, avctx->pix_fmt, w);
360  // increase alignment of w for next try (rhs gives the lowest bit set in w)
361  w += w & ~(w - 1);
362 
363  unaligned = 0;
364  for (i = 0; i < 4; i++)
365  unaligned |= linesize[i] % pool->stride_align[i];
366  } while (unaligned);
367 
368  tmpsize = av_image_fill_pointers(data, avctx->pix_fmt, h,
369  NULL, linesize);
370  if (tmpsize < 0)
371  return -1;
372 
373  for (i = 0; i < 3 && data[i + 1]; i++)
374  size[i] = data[i + 1] - data[i];
375  size[i] = tmpsize - (data[i] - data[0]);
376 
377  for (i = 0; i < 4; i++) {
378  av_buffer_pool_uninit(&pool->pools[i]);
379  pool->linesize[i] = linesize[i];
380  if (size[i]) {
381  pool->pools[i] = av_buffer_pool_init(size[i] + 16, NULL);
382  if (!pool->pools[i]) {
383  ret = AVERROR(ENOMEM);
384  goto fail;
385  }
386  }
387  }
388  pool->format = frame->format;
389  pool->width = frame->width;
390  pool->height = frame->height;
391 
392  break;
393  }
394  case AVMEDIA_TYPE_AUDIO: {
396  int planar = av_sample_fmt_is_planar(frame->format);
397  int planes = planar ? ch : 1;
398 
399  if (pool->format == frame->format && pool->planes == planes &&
400  pool->channels == ch && frame->nb_samples == pool->samples)
401  return 0;
402 
403  av_buffer_pool_uninit(&pool->pools[0]);
404  ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
405  frame->nb_samples, frame->format, 0);
406  if (ret < 0)
407  goto fail;
408 
409  pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
410  if (!pool->pools[0]) {
411  ret = AVERROR(ENOMEM);
412  goto fail;
413  }
414 
415  pool->format = frame->format;
416  pool->planes = planes;
417  pool->channels = ch;
418  pool->samples = frame->nb_samples;
419  break;
420  }
421  default: av_assert0(0);
422  }
423  return 0;
424 fail:
425  for (i = 0; i < 4; i++)
426  av_buffer_pool_uninit(&pool->pools[i]);
427  pool->format = -1;
428  pool->planes = pool->channels = pool->samples = 0;
429  pool->width = pool->height = 0;
430  return ret;
431 }
432 
433 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
434 {
435  FramePool *pool = avctx->internal->pool;
436  int planes = pool->planes;
437  int i;
438 
439  frame->linesize[0] = pool->linesize[0];
440 
441  if (planes > AV_NUM_DATA_POINTERS) {
442  frame->extended_data = av_mallocz(planes * sizeof(*frame->extended_data));
443  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
444  frame->extended_buf = av_mallocz(frame->nb_extended_buf *
445  sizeof(*frame->extended_buf));
446  if (!frame->extended_data || !frame->extended_buf) {
447  av_freep(&frame->extended_data);
448  av_freep(&frame->extended_buf);
449  return AVERROR(ENOMEM);
450  }
451  } else
452  frame->extended_data = frame->data;
453 
454  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
455  frame->buf[i] = av_buffer_pool_get(pool->pools[0]);
456  if (!frame->buf[i])
457  goto fail;
458  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
459  }
460  for (i = 0; i < frame->nb_extended_buf; i++) {
461  frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]);
462  if (!frame->extended_buf[i])
463  goto fail;
464  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
465  }
466 
467  if (avctx->debug & FF_DEBUG_BUFFERS)
468  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame);
469 
470  return 0;
471 fail:
472  av_frame_unref(frame);
473  return AVERROR(ENOMEM);
474 }
475 
477 {
478  FramePool *pool = s->internal->pool;
479  int i;
480 
481  if (pic->data[0]) {
482  av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
483  return -1;
484  }
485 
486  memset(pic->data, 0, sizeof(pic->data));
487  pic->extended_data = pic->data;
488 
489  for (i = 0; i < 4 && pool->pools[i]; i++) {
490  pic->linesize[i] = pool->linesize[i];
491 
492  pic->buf[i] = av_buffer_pool_get(pool->pools[i]);
493  if (!pic->buf[i])
494  goto fail;
495 
496  pic->data[i] = pic->buf[i]->data;
497  }
498  for (; i < AV_NUM_DATA_POINTERS; i++) {
499  pic->data[i] = NULL;
500  pic->linesize[i] = 0;
501  }
502  if (pic->data[1] && !pic->data[2])
503  avpriv_set_systematic_pal2((uint32_t *)pic->data[1], s->pix_fmt);
504 
505  if (s->debug & FF_DEBUG_BUFFERS)
506  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic);
507 
508  return 0;
509 fail:
510  av_frame_unref(pic);
511  return AVERROR(ENOMEM);
512 }
513 
515 {
516  int ret;
517 
518  if (avctx->hw_frames_ctx)
519  return av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
520 
521  if ((ret = update_frame_pool(avctx, frame)) < 0)
522  return ret;
523 
524  switch (avctx->codec_type) {
525  case AVMEDIA_TYPE_VIDEO:
526  return video_get_buffer(avctx, frame);
527  case AVMEDIA_TYPE_AUDIO:
528  return audio_get_buffer(avctx, frame);
529  default:
530  return -1;
531  }
532 }
533 
535 {
536  AVPacket *pkt = avctx->internal->pkt;
537  int i;
538  struct {
539  enum AVPacketSideDataType packet;
540  enum AVFrameSideDataType frame;
541  } sd[] = {
546  };
547 
548  frame->color_primaries = avctx->color_primaries;
549  frame->color_trc = avctx->color_trc;
550  frame->colorspace = avctx->colorspace;
551  frame->color_range = avctx->color_range;
552  frame->chroma_location = avctx->chroma_sample_location;
553 
554  frame->reordered_opaque = avctx->reordered_opaque;
555  if (!pkt) {
556 #if FF_API_PKT_PTS
558  frame->pkt_pts = AV_NOPTS_VALUE;
560 #endif
561  frame->pts = AV_NOPTS_VALUE;
562  return 0;
563  }
564 
565 #if FF_API_PKT_PTS
567  frame->pkt_pts = pkt->pts;
569 #endif
570  frame->pts = pkt->pts;
571 
572  for (i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
573  int size;
574  uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
575  if (packet_sd) {
576  AVFrameSideData *frame_sd = av_frame_new_side_data(frame,
577  sd[i].frame,
578  size);
579  if (!frame_sd)
580  return AVERROR(ENOMEM);
581 
582  memcpy(frame_sd->data, packet_sd, size);
583  }
584  }
585 
586  return 0;
587 }
588 
589 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
590 {
591  const AVHWAccel *hwaccel = avctx->hwaccel;
592  int override_dimensions = 1;
593  int ret;
594 
595  switch (avctx->codec_type) {
596  case AVMEDIA_TYPE_VIDEO:
597  if (frame->width <= 0 || frame->height <= 0) {
598  frame->width = FFMAX(avctx->width, avctx->coded_width);
599  frame->height = FFMAX(avctx->height, avctx->coded_height);
600  override_dimensions = 0;
601  }
602  if (frame->format < 0)
603  frame->format = avctx->pix_fmt;
604  if (!frame->sample_aspect_ratio.num)
606 
607  if (av_image_check_sar(frame->width, frame->height,
608  frame->sample_aspect_ratio) < 0) {
609  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
610  frame->sample_aspect_ratio.num,
611  frame->sample_aspect_ratio.den);
612  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
613  }
614 
615  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
616  return ret;
617  break;
618  case AVMEDIA_TYPE_AUDIO:
619  if (!frame->sample_rate)
620  frame->sample_rate = avctx->sample_rate;
621  if (frame->format < 0)
622  frame->format = avctx->sample_fmt;
623  if (!frame->channel_layout) {
624  if (avctx->channel_layout) {
626  avctx->channels) {
627  av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
628  "configuration.\n");
629  return AVERROR(EINVAL);
630  }
631 
632  frame->channel_layout = avctx->channel_layout;
633  } else {
634  if (avctx->channels > FF_SANE_NB_CHANNELS) {
635  av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
636  avctx->channels);
637  return AVERROR(ENOSYS);
638  }
639 
641  if (!frame->channel_layout)
642  frame->channel_layout = (1ULL << avctx->channels) - 1;
643  }
644  }
645  break;
646  default: return AVERROR(EINVAL);
647  }
648 
649  ret = ff_decode_frame_props(avctx, frame);
650  if (ret < 0)
651  return ret;
652 
653  if (hwaccel) {
654  if (hwaccel->alloc_frame) {
655  ret = hwaccel->alloc_frame(avctx, frame);
656  goto end;
657  }
658  } else
659  avctx->sw_pix_fmt = avctx->pix_fmt;
660 
661  ret = avctx->get_buffer2(avctx, frame, flags);
662 
663 end:
664  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) {
665  frame->width = avctx->width;
666  frame->height = avctx->height;
667  }
668 
669  return ret;
670 }
671 
673 {
674  AVFrame *tmp;
675  int ret;
676 
678 
679  if (!frame->data[0])
680  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
681 
682  if (av_frame_is_writable(frame))
683  return ff_decode_frame_props(avctx, frame);
684 
685  tmp = av_frame_alloc();
686  if (!tmp)
687  return AVERROR(ENOMEM);
688 
689  av_frame_move_ref(tmp, frame);
690 
691  ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
692  if (ret < 0) {
693  av_frame_free(&tmp);
694  return ret;
695  }
696 
697  av_frame_copy(frame, tmp);
698  av_frame_free(&tmp);
699 
700  return 0;
701 }
702 
703 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
704 {
705  int i;
706 
707  for (i = 0; i < count; i++) {
708  int r = func(c, (char *)arg + i * size);
709  if (ret)
710  ret[i] = r;
711  }
712  return 0;
713 }
714 
715 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
716 {
717  int i;
718 
719  for (i = 0; i < count; i++) {
720  int r = func(c, arg, i, 0);
721  if (ret)
722  ret[i] = r;
723  }
724  return 0;
725 }
726 
728 {
729  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
730  return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
731 }
732 
734 {
735  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
736  ++fmt;
737  return fmt[0];
738 }
739 
741  enum AVPixelFormat pix_fmt)
742 {
743  AVHWAccel *hwaccel = NULL;
744 
745  while ((hwaccel = av_hwaccel_next(hwaccel)))
746  if (hwaccel->id == codec_id
747  && hwaccel->pix_fmt == pix_fmt)
748  return hwaccel;
749  return NULL;
750 }
751 
752 static int setup_hwaccel(AVCodecContext *avctx,
753  const enum AVPixelFormat fmt,
754  const char *name)
755 {
756  AVHWAccel *hwa = find_hwaccel(avctx->codec_id, fmt);
757  int ret = 0;
758 
759  if (!hwa) {
760  av_log(avctx, AV_LOG_ERROR,
761  "Could not find an AVHWAccel for the pixel format: %s",
762  name);
763  return AVERROR(ENOENT);
764  }
765 
766  if (hwa->priv_data_size) {
768  if (!avctx->internal->hwaccel_priv_data)
769  return AVERROR(ENOMEM);
770  }
771 
772  if (hwa->init) {
773  ret = hwa->init(avctx);
774  if (ret < 0) {
776  return ret;
777  }
778  }
779 
780  avctx->hwaccel = hwa;
781 
782  return 0;
783 }
784 
785 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
786 {
787  const AVPixFmtDescriptor *desc;
788  enum AVPixelFormat *choices;
789  enum AVPixelFormat ret;
790  unsigned n = 0;
791 
792  while (fmt[n] != AV_PIX_FMT_NONE)
793  ++n;
794 
795  av_assert0(n >= 1);
796  avctx->sw_pix_fmt = fmt[n - 1];
798 
799  choices = av_malloc_array(n + 1, sizeof(*choices));
800  if (!choices)
801  return AV_PIX_FMT_NONE;
802 
803  memcpy(choices, fmt, (n + 1) * sizeof(*choices));
804 
805  for (;;) {
806  if (avctx->hwaccel && avctx->hwaccel->uninit)
807  avctx->hwaccel->uninit(avctx);
809  avctx->hwaccel = NULL;
810 
812 
813  ret = avctx->get_format(avctx, choices);
814 
815  desc = av_pix_fmt_desc_get(ret);
816  if (!desc) {
817  ret = AV_PIX_FMT_NONE;
818  break;
819  }
820 
821  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
822  break;
823 
824  if (avctx->hw_frames_ctx) {
825  AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
826  if (hw_frames_ctx->format != ret) {
827  av_log(avctx, AV_LOG_ERROR, "Format returned from get_buffer() "
828  "does not match the format of provided AVHWFramesContext\n");
829  ret = AV_PIX_FMT_NONE;
830  break;
831  }
832  }
833 
834  if (!setup_hwaccel(avctx, ret, desc->name))
835  break;
836 
837  /* Remove failed hwaccel from choices */
838  for (n = 0; choices[n] != ret; n++)
839  av_assert0(choices[n] != AV_PIX_FMT_NONE);
840 
841  do
842  choices[n] = choices[n + 1];
843  while (choices[n++] != AV_PIX_FMT_NONE);
844  }
845 
846  av_freep(&choices);
847  return ret;
848 }
849 
851 {
852  int ret = 0;
853  AVDictionary *tmp = NULL;
854 
855  if (avcodec_is_open(avctx))
856  return 0;
857 
858  if ((!codec && !avctx->codec)) {
859  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
860  return AVERROR(EINVAL);
861  }
862  if ((codec && avctx->codec && codec != avctx->codec)) {
863  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
864  "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
865  return AVERROR(EINVAL);
866  }
867  if (!codec)
868  codec = avctx->codec;
869 
870  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
871  return AVERROR(EINVAL);
872 
873  if (options)
874  av_dict_copy(&tmp, *options, 0);
875 
876  /* If there is a user-supplied mutex locking routine, call it. */
877  if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init) {
878  if (lockmgr_cb) {
880  return -1;
881  }
882 
884  if (entangled_thread_counter != 1) {
885  av_log(avctx, AV_LOG_ERROR,
886  "Insufficient thread locking. At least %d threads are "
887  "calling avcodec_open2() at the same time right now.\n",
889  ret = -1;
890  goto end;
891  }
892  }
893 
894  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
895  if (!avctx->internal) {
896  ret = AVERROR(ENOMEM);
897  goto end;
898  }
899 
900  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
901  if (!avctx->internal->pool) {
902  ret = AVERROR(ENOMEM);
903  goto free_and_end;
904  }
905 
906  avctx->internal->to_free = av_frame_alloc();
907  if (!avctx->internal->to_free) {
908  ret = AVERROR(ENOMEM);
909  goto free_and_end;
910  }
911 
913  if (!avctx->internal->buffer_frame) {
914  ret = AVERROR(ENOMEM);
915  goto free_and_end;
916  }
917 
918  avctx->internal->buffer_pkt = av_packet_alloc();
919  if (!avctx->internal->buffer_pkt) {
920  ret = AVERROR(ENOMEM);
921  goto free_and_end;
922  }
923 
924  if (codec->priv_data_size > 0) {
925  if (!avctx->priv_data) {
926  avctx->priv_data = av_mallocz(codec->priv_data_size);
927  if (!avctx->priv_data) {
928  ret = AVERROR(ENOMEM);
929  goto end;
930  }
931  if (codec->priv_class) {
932  *(const AVClass **)avctx->priv_data = codec->priv_class;
934  }
935  }
936  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
937  goto free_and_end;
938  } else {
939  avctx->priv_data = NULL;
940  }
941  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
942  goto free_and_end;
943 
944  if (avctx->coded_width && avctx->coded_height && !avctx->width && !avctx->height)
945  ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
946  else if (avctx->width && avctx->height)
947  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
948  if (ret < 0)
949  goto free_and_end;
950 
951  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
952  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
953  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
954  av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
955  ff_set_dimensions(avctx, 0, 0);
956  }
957 
958  if (avctx->width > 0 && avctx->height > 0) {
959  if (av_image_check_sar(avctx->width, avctx->height,
960  avctx->sample_aspect_ratio) < 0) {
961  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
962  avctx->sample_aspect_ratio.num,
963  avctx->sample_aspect_ratio.den);
964  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
965  }
966  }
967 
968  /* if the decoder init function was already called previously,
969  * free the already allocated subtitle_header before overwriting it */
970  if (av_codec_is_decoder(codec))
971  av_freep(&avctx->subtitle_header);
972 
973  if (avctx->channels > FF_SANE_NB_CHANNELS) {
974  ret = AVERROR(EINVAL);
975  goto free_and_end;
976  }
977 
978  avctx->codec = codec;
979  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
980  avctx->codec_id == AV_CODEC_ID_NONE) {
981  avctx->codec_type = codec->type;
982  avctx->codec_id = codec->id;
983  }
984  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
985  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
986  av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
987  ret = AVERROR(EINVAL);
988  goto free_and_end;
989  }
990  avctx->frame_number = 0;
991 
992  if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
994  ret = AVERROR_EXPERIMENTAL;
995  goto free_and_end;
996  }
997 
998  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
999  (!avctx->time_base.num || !avctx->time_base.den)) {
1000  avctx->time_base.num = 1;
1001  avctx->time_base.den = avctx->sample_rate;
1002  }
1003 
1004  if (HAVE_THREADS) {
1005  ret = ff_thread_init(avctx);
1006  if (ret < 0) {
1007  goto free_and_end;
1008  }
1009  }
1011  avctx->thread_count = 1;
1012 
1013  if (av_codec_is_encoder(avctx->codec)) {
1014  int i;
1015 #if FF_API_CODED_FRAME
1017  avctx->coded_frame = av_frame_alloc();
1018  if (!avctx->coded_frame) {
1019  ret = AVERROR(ENOMEM);
1020  goto free_and_end;
1021  }
1023 #endif
1024 
1025  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
1026  av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
1027  ret = AVERROR(EINVAL);
1028  goto free_and_end;
1029  }
1030 
1031  if (avctx->codec->sample_fmts) {
1032  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
1033  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
1034  break;
1035  if (avctx->channels == 1 &&
1038  avctx->sample_fmt = avctx->codec->sample_fmts[i];
1039  break;
1040  }
1041  }
1042  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
1043  av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
1044  ret = AVERROR(EINVAL);
1045  goto free_and_end;
1046  }
1047  }
1048  if (avctx->codec->pix_fmts) {
1049  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
1050  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
1051  break;
1052  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
1053  av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n");
1054  ret = AVERROR(EINVAL);
1055  goto free_and_end;
1056  }
1057  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
1058  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
1059  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
1060  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
1061  avctx->color_range = AVCOL_RANGE_JPEG;
1062  }
1063  if (avctx->codec->supported_samplerates) {
1064  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
1065  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
1066  break;
1067  if (avctx->codec->supported_samplerates[i] == 0) {
1068  av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
1069  ret = AVERROR(EINVAL);
1070  goto free_and_end;
1071  }
1072  }
1073  if (avctx->codec->channel_layouts) {
1074  if (!avctx->channel_layout) {
1075  av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
1076  } else {
1077  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
1078  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
1079  break;
1080  if (avctx->codec->channel_layouts[i] == 0) {
1081  av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
1082  ret = AVERROR(EINVAL);
1083  goto free_and_end;
1084  }
1085  }
1086  }
1087  if (avctx->channel_layout && avctx->channels) {
1089  av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
1090  ret = AVERROR(EINVAL);
1091  goto free_and_end;
1092  }
1093  } else if (avctx->channel_layout) {
1095  }
1096 
1097  if (!avctx->rc_initial_buffer_occupancy)
1098  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
1099 
1100  if (avctx->ticks_per_frame &&
1101  avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
1102  av_log(avctx, AV_LOG_ERROR,
1103  "ticks_per_frame %d too large for the timebase %d/%d.",
1104  avctx->ticks_per_frame,
1105  avctx->time_base.num,
1106  avctx->time_base.den);
1107  goto free_and_end;
1108  }
1109 
1110  if (avctx->hw_frames_ctx) {
1111  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1112  if (frames_ctx->format != avctx->pix_fmt) {
1113  av_log(avctx, AV_LOG_ERROR,
1114  "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
1115  ret = AVERROR(EINVAL);
1116  goto free_and_end;
1117  }
1118  if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
1119  avctx->sw_pix_fmt != frames_ctx->sw_format) {
1120  av_log(avctx, AV_LOG_ERROR,
1121  "Mismatching AVCodecContext.sw_pix_fmt (%s) "
1122  "and AVHWFramesContext.sw_format (%s)\n",
1124  av_get_pix_fmt_name(frames_ctx->sw_format));
1125  ret = AVERROR(EINVAL);
1126  goto free_and_end;
1127  }
1128  avctx->sw_pix_fmt = frames_ctx->sw_format;
1129  }
1130  }
1131 
1132  if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) {
1133  ret = avctx->codec->init(avctx);
1134  if (ret < 0) {
1135  goto free_and_end;
1136  }
1137  }
1138 
1139 #if FF_API_AUDIOENC_DELAY
1140  if (av_codec_is_encoder(avctx->codec))
1141  avctx->delay = avctx->initial_padding;
1142 #endif
1143 
1144  if (av_codec_is_decoder(avctx->codec)) {
1145  /* validate channel layout from the decoder */
1146  if (avctx->channel_layout) {
1147  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1148  if (!avctx->channels)
1149  avctx->channels = channels;
1150  else if (channels != avctx->channels) {
1151  av_log(avctx, AV_LOG_WARNING,
1152  "channel layout does not match number of channels\n");
1153  avctx->channel_layout = 0;
1154  }
1155  }
1156  if (avctx->channels && avctx->channels < 0 ||
1157  avctx->channels > FF_SANE_NB_CHANNELS) {
1158  ret = AVERROR(EINVAL);
1159  goto free_and_end;
1160  }
1161 
1162 #if FF_API_AVCTX_TIMEBASE
1163  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
1164  avctx->time_base = av_inv_q(avctx->framerate);
1165 #endif
1166  }
1167 end:
1168  if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE) && codec->init) {
1170 
1171  /* Release any user-supplied mutex. */
1172  if (lockmgr_cb) {
1173  (*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1174  }
1175  }
1176 
1177  if (options) {
1178  av_dict_free(options);
1179  *options = tmp;
1180  }
1181 
1182  return ret;
1183 free_and_end:
1184  if (avctx->codec &&
1186  avctx->codec->close(avctx);
1187 
1188  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1189  av_opt_free(avctx->priv_data);
1190  av_opt_free(avctx);
1191 
1192 #if FF_API_CODED_FRAME
1194  av_frame_free(&avctx->coded_frame);
1196 #endif
1197 
1198  av_dict_free(&tmp);
1199  av_freep(&avctx->priv_data);
1200  if (avctx->internal) {
1201  av_frame_free(&avctx->internal->to_free);
1204  av_freep(&avctx->internal->pool);
1205  }
1206  av_freep(&avctx->internal);
1207  avctx->codec = NULL;
1208  goto end;
1209 }
1210 
1212 {
1213  if (size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
1214  return AVERROR(EINVAL);
1215 
1216  if (avpkt->data) {
1217  AVBufferRef *buf = avpkt->buf;
1218 
1219  if (avpkt->size < size)
1220  return AVERROR(EINVAL);
1221 
1222  av_init_packet(avpkt);
1223  avpkt->buf = buf;
1224  avpkt->size = size;
1225  return 0;
1226  } else {
1227  return av_new_packet(avpkt, size);
1228  }
1229 }
1230 
1234 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
1235 {
1236  AVFrame *frame = NULL;
1237  int ret;
1238 
1239  if (!(frame = av_frame_alloc()))
1240  return AVERROR(ENOMEM);
1241 
1242  frame->format = src->format;
1243  frame->channel_layout = src->channel_layout;
1244  frame->nb_samples = s->frame_size;
1245  ret = av_frame_get_buffer(frame, 32);
1246  if (ret < 0)
1247  goto fail;
1248 
1249  ret = av_frame_copy_props(frame, src);
1250  if (ret < 0)
1251  goto fail;
1252 
1253  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
1254  src->nb_samples, s->channels, s->sample_fmt)) < 0)
1255  goto fail;
1256  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
1257  frame->nb_samples - src->nb_samples,
1258  s->channels, s->sample_fmt)) < 0)
1259  goto fail;
1260 
1261  *dst = frame;
1262 
1263  return 0;
1264 
1265 fail:
1266  av_frame_free(&frame);
1267  return ret;
1268 }
1269 
1271  AVPacket *avpkt,
1272  const AVFrame *frame,
1273  int *got_packet_ptr)
1274 {
1275  AVFrame tmp;
1276  AVFrame *padded_frame = NULL;
1277  int ret;
1278  int user_packet = !!avpkt->data;
1279 
1280  *got_packet_ptr = 0;
1281 
1282  if (!avctx->codec->encode2) {
1283  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
1284  return AVERROR(ENOSYS);
1285  }
1286 
1287  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
1288  av_packet_unref(avpkt);
1289  av_init_packet(avpkt);
1290  return 0;
1291  }
1292 
1293  /* ensure that extended_data is properly set */
1294  if (frame && !frame->extended_data) {
1295  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
1296  avctx->channels > AV_NUM_DATA_POINTERS) {
1297  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
1298  "with more than %d channels, but extended_data is not set.\n",
1300  return AVERROR(EINVAL);
1301  }
1302  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
1303 
1304  tmp = *frame;
1305  tmp.extended_data = tmp.data;
1306  frame = &tmp;
1307  }
1308 
1309  /* extract audio service type metadata */
1310  if (frame) {
1312  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
1313  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
1314  }
1315 
1316  /* check for valid frame size */
1317  if (frame) {
1319  if (frame->nb_samples > avctx->frame_size)
1320  return AVERROR(EINVAL);
1321  } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
1322  if (frame->nb_samples < avctx->frame_size &&
1323  !avctx->internal->last_audio_frame) {
1324  ret = pad_last_frame(avctx, &padded_frame, frame);
1325  if (ret < 0)
1326  return ret;
1327 
1328  frame = padded_frame;
1329  avctx->internal->last_audio_frame = 1;
1330  }
1331 
1332  if (frame->nb_samples != avctx->frame_size) {
1333  ret = AVERROR(EINVAL);
1334  goto end;
1335  }
1336  }
1337  }
1338 
1339  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1340  if (!ret) {
1341  if (*got_packet_ptr) {
1342  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
1343  if (avpkt->pts == AV_NOPTS_VALUE)
1344  avpkt->pts = frame->pts;
1345  if (!avpkt->duration)
1346  avpkt->duration = ff_samples_to_time_base(avctx,
1347  frame->nb_samples);
1348  }
1349  avpkt->dts = avpkt->pts;
1350  } else {
1351  avpkt->size = 0;
1352  }
1353 
1354  if (!user_packet && avpkt->size) {
1355  ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
1356  if (ret >= 0)
1357  avpkt->data = avpkt->buf->data;
1358  }
1359 
1360  avctx->frame_number++;
1361  }
1362 
1363  if (ret < 0 || !*got_packet_ptr) {
1364  av_packet_unref(avpkt);
1365  av_init_packet(avpkt);
1366  goto end;
1367  }
1368 
1369  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1370  * this needs to be moved to the encoders, but for now we can do it
1371  * here to simplify things */
1372  avpkt->flags |= AV_PKT_FLAG_KEY;
1373 
1374 end:
1375  av_frame_free(&padded_frame);
1376 
1377 #if FF_API_AUDIOENC_DELAY
1378  avctx->delay = avctx->initial_padding;
1379 #endif
1380 
1381  return ret;
1382 }
1383 
1385  AVPacket *avpkt,
1386  const AVFrame *frame,
1387  int *got_packet_ptr)
1388 {
1389  int ret;
1390  int user_packet = !!avpkt->data;
1391 
1392  *got_packet_ptr = 0;
1393 
1394  if (!avctx->codec->encode2) {
1395  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
1396  return AVERROR(ENOSYS);
1397  }
1398 
1399  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
1400  av_packet_unref(avpkt);
1401  av_init_packet(avpkt);
1402  avpkt->size = 0;
1403  return 0;
1404  }
1405 
1406  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
1407  return AVERROR(EINVAL);
1408 
1409  av_assert0(avctx->codec->encode2);
1410 
1411  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1412  if (!ret) {
1413  if (!*got_packet_ptr)
1414  avpkt->size = 0;
1415  else if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
1416  avpkt->pts = avpkt->dts = frame->pts;
1417 
1418  if (!user_packet && avpkt->size) {
1419  ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
1420  if (ret >= 0)
1421  avpkt->data = avpkt->buf->data;
1422  }
1423 
1424  avctx->frame_number++;
1425  }
1426 
1427  if (ret < 0 || !*got_packet_ptr)
1428  av_packet_unref(avpkt);
1429 
1430  emms_c();
1431  return ret;
1432 }
1433 
1434 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1435  const AVSubtitle *sub)
1436 {
1437  int ret;
1438  if (sub->start_display_time) {
1439  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1440  return -1;
1441  }
1442  if (sub->num_rects == 0 || !sub->rects)
1443  return -1;
1444  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
1445  avctx->frame_number++;
1446  return ret;
1447 }
1448 
1449 static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1450 {
1451  int size = 0, ret;
1452  const uint8_t *data;
1453  uint32_t flags;
1454 
1455  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1456  if (!data)
1457  return 0;
1458 
1459  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
1460  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
1461  "changes, but PARAM_CHANGE side data was sent to it.\n");
1462  ret = AVERROR(EINVAL);
1463  goto fail2;
1464  }
1465 
1466  if (size < 4)
1467  goto fail;
1468 
1469  flags = bytestream_get_le32(&data);
1470  size -= 4;
1471 
1473  if (size < 4)
1474  goto fail;
1475  avctx->channels = bytestream_get_le32(&data);
1476  size -= 4;
1477  }
1479  if (size < 8)
1480  goto fail;
1481  avctx->channel_layout = bytestream_get_le64(&data);
1482  size -= 8;
1483  }
1485  if (size < 4)
1486  goto fail;
1487  avctx->sample_rate = bytestream_get_le32(&data);
1488  size -= 4;
1489  }
1491  if (size < 8)
1492  goto fail;
1493  avctx->width = bytestream_get_le32(&data);
1494  avctx->height = bytestream_get_le32(&data);
1495  size -= 8;
1496  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
1497  if (ret < 0)
1498  goto fail2;
1499  }
1500 
1501  return 0;
1502 fail:
1503  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
1504  ret = AVERROR_INVALIDDATA;
1505 fail2:
1506  if (ret < 0) {
1507  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
1508  if (avctx->err_recognition & AV_EF_EXPLODE)
1509  return ret;
1510  }
1511  return 0;
1512 }
1513 
1514 static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
1515 {
1516  int ret;
1517 
1518  /* move the original frame to our backup */
1519  av_frame_unref(avci->to_free);
1520  av_frame_move_ref(avci->to_free, frame);
1521 
1522  /* now copy everything except the AVBufferRefs back
1523  * note that we make a COPY of the side data, so calling av_frame_free() on
1524  * the caller's frame will work properly */
1525  ret = av_frame_copy_props(frame, avci->to_free);
1526  if (ret < 0)
1527  return ret;
1528 
1529  memcpy(frame->data, avci->to_free->data, sizeof(frame->data));
1530  memcpy(frame->linesize, avci->to_free->linesize, sizeof(frame->linesize));
1531  if (avci->to_free->extended_data != avci->to_free->data) {
1533  int size = planes * sizeof(*frame->extended_data);
1534 
1535  if (!size) {
1536  av_frame_unref(frame);
1537  return AVERROR_BUG;
1538  }
1539 
1540  frame->extended_data = av_malloc(size);
1541  if (!frame->extended_data) {
1542  av_frame_unref(frame);
1543  return AVERROR(ENOMEM);
1544  }
1545  memcpy(frame->extended_data, avci->to_free->extended_data,
1546  size);
1547  } else
1548  frame->extended_data = frame->data;
1549 
1550  frame->format = avci->to_free->format;
1551  frame->width = avci->to_free->width;
1552  frame->height = avci->to_free->height;
1553  frame->channel_layout = avci->to_free->channel_layout;
1554  frame->nb_samples = avci->to_free->nb_samples;
1555 
1556  return 0;
1557 }
1558 
1560  int *got_picture_ptr,
1561  AVPacket *avpkt)
1562 {
1563  AVCodecInternal *avci = avctx->internal;
1564  int ret;
1565 
1566  *got_picture_ptr = 0;
1567  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
1568  return -1;
1569 
1570  if (!avctx->codec->decode) {
1571  av_log(avctx, AV_LOG_ERROR, "This decoder requires using the avcodec_send_packet() API.\n");
1572  return AVERROR(ENOSYS);
1573  }
1574 
1575  avctx->internal->pkt = avpkt;
1576  ret = apply_param_change(avctx, avpkt);
1577  if (ret < 0)
1578  return ret;
1579 
1580  av_frame_unref(picture);
1581 
1582  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size ||
1583  (avctx->active_thread_type & FF_THREAD_FRAME)) {
1585  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
1586  avpkt);
1587  else {
1588  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
1589  avpkt);
1591  picture->pkt_dts = avpkt->dts;
1592  /* get_buffer is supposed to set frame parameters */
1593  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
1594  picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
1595  picture->width = avctx->width;
1596  picture->height = avctx->height;
1597  picture->format = avctx->pix_fmt;
1598  }
1599  }
1600 
1601  emms_c(); //needed to avoid an emms_c() call before every return;
1602 
1603  if (*got_picture_ptr) {
1604  if (!avctx->refcounted_frames) {
1605  int err = unrefcount_frame(avci, picture);
1606  if (err < 0)
1607  return err;
1608  }
1609 
1610  avctx->frame_number++;
1611  } else
1612  av_frame_unref(picture);
1613  } else
1614  ret = 0;
1615 
1616 #if FF_API_AVCTX_TIMEBASE
1617  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
1618  avctx->time_base = av_inv_q(avctx->framerate);
1619 #endif
1620 
1621  return ret;
1622 }
1623 
1625  AVFrame *frame,
1626  int *got_frame_ptr,
1627  AVPacket *avpkt)
1628 {
1629  AVCodecInternal *avci = avctx->internal;
1630  int ret = 0;
1631 
1632  *got_frame_ptr = 0;
1633 
1634  if (!avctx->codec->decode) {
1635  av_log(avctx, AV_LOG_ERROR, "This decoder requires using the avcodec_send_packet() API.\n");
1636  return AVERROR(ENOSYS);
1637  }
1638 
1639  avctx->internal->pkt = avpkt;
1640 
1641  if (!avpkt->data && avpkt->size) {
1642  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1643  return AVERROR(EINVAL);
1644  }
1645 
1646  ret = apply_param_change(avctx, avpkt);
1647  if (ret < 0)
1648  return ret;
1649 
1650  av_frame_unref(frame);
1651 
1652  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
1653  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1654  if (ret >= 0 && *got_frame_ptr) {
1655  avctx->frame_number++;
1656  frame->pkt_dts = avpkt->dts;
1657  if (frame->format == AV_SAMPLE_FMT_NONE)
1658  frame->format = avctx->sample_fmt;
1659 
1660  if (!avctx->refcounted_frames) {
1661  int err = unrefcount_frame(avci, frame);
1662  if (err < 0)
1663  return err;
1664  }
1665  } else
1666  av_frame_unref(frame);
1667  }
1668 
1669 
1670  return ret;
1671 }
1672 
1674  int *got_sub_ptr,
1675  AVPacket *avpkt)
1676 {
1677  int ret;
1678 
1679  avctx->internal->pkt = avpkt;
1680  *got_sub_ptr = 0;
1681  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1682  if (*got_sub_ptr)
1683  avctx->frame_number++;
1684  return ret;
1685 }
1686 
1688 {
1689  int i;
1690 
1691  for (i = 0; i < sub->num_rects; i++) {
1692  av_freep(&sub->rects[i]->data[0]);
1693  av_freep(&sub->rects[i]->data[1]);
1694  av_freep(&sub->rects[i]->data[2]);
1695  av_freep(&sub->rects[i]->data[3]);
1696  av_freep(&sub->rects[i]->text);
1697  av_freep(&sub->rects[i]->ass);
1698  av_freep(&sub->rects[i]);
1699  }
1700 
1701  av_freep(&sub->rects);
1702 
1703  memset(sub, 0, sizeof(AVSubtitle));
1704 }
1705 
1706 static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
1707 {
1708  int got_frame;
1709  int ret;
1710 
1711  av_assert0(!avctx->internal->buffer_frame->buf[0]);
1712 
1713  if (!pkt)
1714  pkt = avctx->internal->buffer_pkt;
1715 
1716  // This is the lesser evil. The field is for compatibility with legacy users
1717  // of the legacy API, and users using the new API should not be forced to
1718  // even know about this field.
1719  avctx->refcounted_frames = 1;
1720 
1721  // Some codecs (at least wma lossless) will crash when feeding drain packets
1722  // after EOF was signaled.
1723  if (avctx->internal->draining_done)
1724  return AVERROR_EOF;
1725 
1726  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1727  ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,
1728  &got_frame, pkt);
1729  if (ret >= 0)
1730  ret = pkt->size;
1731  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1732  ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,
1733  &got_frame, pkt);
1734  } else {
1735  ret = AVERROR(EINVAL);
1736  }
1737 
1738  if (ret < 0)
1739  return ret;
1740 
1741  if (avctx->internal->draining && !got_frame)
1742  avctx->internal->draining_done = 1;
1743 
1744  if (ret >= pkt->size) {
1746  } else {
1747  int consumed = ret;
1748 
1749  if (pkt != avctx->internal->buffer_pkt) {
1751  if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0)
1752  return ret;
1753  }
1754 
1755  avctx->internal->buffer_pkt->data += consumed;
1756  avctx->internal->buffer_pkt->size -= consumed;
1759  }
1760 
1761  if (got_frame)
1762  av_assert0(avctx->internal->buffer_frame->buf[0]);
1763 
1764  return 0;
1765 }
1766 
1768 {
1769  int ret;
1770 
1771  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
1772  return AVERROR(EINVAL);
1773 
1774  if (avctx->internal->draining)
1775  return AVERROR_EOF;
1776 
1777  if (!avpkt || !avpkt->size) {
1778  avctx->internal->draining = 1;
1779  avpkt = NULL;
1780 
1781  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
1782  return 0;
1783  }
1784 
1785  if (avctx->codec->send_packet) {
1786  if (avpkt) {
1787  ret = apply_param_change(avctx, (AVPacket *)avpkt);
1788  if (ret < 0)
1789  return ret;
1790  }
1791  return avctx->codec->send_packet(avctx, avpkt);
1792  }
1793 
1794  // Emulation via old API. Assume avpkt is likely not refcounted, while
1795  // decoder output is always refcounted, and avoid copying.
1796 
1797  if (avctx->internal->buffer_pkt->size || avctx->internal->buffer_frame->buf[0])
1798  return AVERROR(EAGAIN);
1799 
1800  // The goal is decoding the first frame of the packet without using memcpy,
1801  // because the common case is having only 1 frame per packet (especially
1802  // with video, but audio too). In other cases, it can't be avoided, unless
1803  // the user is feeding refcounted packets.
1804  return do_decode(avctx, (AVPacket *)avpkt);
1805 }
1806 
1808 {
1809  int ret;
1810 
1811  av_frame_unref(frame);
1812 
1813  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
1814  return AVERROR(EINVAL);
1815 
1816  if (avctx->codec->receive_frame) {
1817  if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
1818  return AVERROR_EOF;
1819  return avctx->codec->receive_frame(avctx, frame);
1820  }
1821 
1822  // Emulation via old API.
1823 
1824  if (!avctx->internal->buffer_frame->buf[0]) {
1825  if (!avctx->internal->buffer_pkt->size && !avctx->internal->draining)
1826  return AVERROR(EAGAIN);
1827 
1828  while (1) {
1829  if ((ret = do_decode(avctx, avctx->internal->buffer_pkt)) < 0) {
1831  return ret;
1832  }
1833  // Some audio decoders may consume partial data without returning
1834  // a frame (fate-wmapro-2ch). There is no way to make the caller
1835  // call avcodec_receive_frame() again without returning a frame,
1836  // so try to decode more in these cases.
1837  if (avctx->internal->buffer_frame->buf[0] ||
1838  !avctx->internal->buffer_pkt->size)
1839  break;
1840  }
1841  }
1842 
1843  if (!avctx->internal->buffer_frame->buf[0])
1844  return avctx->internal->draining ? AVERROR_EOF : AVERROR(EAGAIN);
1845 
1846  av_frame_move_ref(frame, avctx->internal->buffer_frame);
1847  return 0;
1848 }
1849 
1850 static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
1851 {
1852  int ret;
1853  *got_packet = 0;
1854 
1856  avctx->internal->buffer_pkt_valid = 0;
1857 
1858  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1859  ret = avcodec_encode_video2(avctx, avctx->internal->buffer_pkt,
1860  frame, got_packet);
1861  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1862  ret = avcodec_encode_audio2(avctx, avctx->internal->buffer_pkt,
1863  frame, got_packet);
1864  } else {
1865  ret = AVERROR(EINVAL);
1866  }
1867 
1868  if (ret >= 0 && *got_packet) {
1869  // Encoders must always return ref-counted buffers.
1870  // Side-data only packets have no data and can be not ref-counted.
1871  av_assert0(!avctx->internal->buffer_pkt->data || avctx->internal->buffer_pkt->buf);
1872  avctx->internal->buffer_pkt_valid = 1;
1873  ret = 0;
1874  } else {
1876  }
1877 
1878  return ret;
1879 }
1880 
1882 {
1883  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
1884  return AVERROR(EINVAL);
1885 
1886  if (avctx->internal->draining)
1887  return AVERROR_EOF;
1888 
1889  if (!frame) {
1890  avctx->internal->draining = 1;
1891 
1892  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
1893  return 0;
1894  }
1895 
1896  if (avctx->codec->send_frame)
1897  return avctx->codec->send_frame(avctx, frame);
1898 
1899  // Emulation via old API. Do it here instead of avcodec_receive_packet, because:
1900  // 1. if the AVFrame is not refcounted, the copying will be much more
1901  // expensive than copying the packet data
1902  // 2. assume few users use non-refcounted AVPackets, so usually no copy is
1903  // needed
1904 
1905  if (avctx->internal->buffer_pkt_valid)
1906  return AVERROR(EAGAIN);
1907 
1908  return do_encode(avctx, frame, &(int){0});
1909 }
1910 
1912 {
1913  av_packet_unref(avpkt);
1914 
1915  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
1916  return AVERROR(EINVAL);
1917 
1918  if (avctx->codec->receive_packet) {
1919  if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
1920  return AVERROR_EOF;
1921  return avctx->codec->receive_packet(avctx, avpkt);
1922  }
1923 
1924  // Emulation via old API.
1925 
1926  if (!avctx->internal->buffer_pkt_valid) {
1927  int got_packet;
1928  int ret;
1929  if (!avctx->internal->draining)
1930  return AVERROR(EAGAIN);
1931  ret = do_encode(avctx, NULL, &got_packet);
1932  if (ret < 0)
1933  return ret;
1934  if (ret >= 0 && !got_packet)
1935  return AVERROR_EOF;
1936  }
1937 
1938  av_packet_move_ref(avpkt, avctx->internal->buffer_pkt);
1939  avctx->internal->buffer_pkt_valid = 0;
1940  return 0;
1941 }
1942 
1944 {
1945  int i;
1946 
1947  if (avcodec_is_open(avctx)) {
1948  FramePool *pool = avctx->internal->pool;
1949 
1950  if (HAVE_THREADS && avctx->internal->thread_ctx)
1951  ff_thread_free(avctx);
1952  if (avctx->codec && avctx->codec->close)
1953  avctx->codec->close(avctx);
1954  av_frame_free(&avctx->internal->to_free);
1957  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
1958  av_buffer_pool_uninit(&pool->pools[i]);
1959  av_freep(&avctx->internal->pool);
1960 
1961  if (avctx->hwaccel && avctx->hwaccel->uninit)
1962  avctx->hwaccel->uninit(avctx);
1964 
1965  av_freep(&avctx->internal);
1966  }
1967 
1968  for (i = 0; i < avctx->nb_coded_side_data; i++)
1969  av_freep(&avctx->coded_side_data[i].data);
1970  av_freep(&avctx->coded_side_data);
1971  avctx->nb_coded_side_data = 0;
1972 
1973  av_buffer_unref(&avctx->hw_frames_ctx);
1974 
1975  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1976  av_opt_free(avctx->priv_data);
1977  av_opt_free(avctx);
1978  av_freep(&avctx->priv_data);
1979  if (av_codec_is_encoder(avctx->codec)) {
1980  av_freep(&avctx->extradata);
1981 #if FF_API_CODED_FRAME
1983  av_frame_free(&avctx->coded_frame);
1985 #endif
1986  }
1987  avctx->codec = NULL;
1988  avctx->active_thread_type = 0;
1989 
1990  return 0;
1991 }
1992 
1993 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1994 {
1995  AVCodec *p, *experimental = NULL;
1996  p = first_avcodec;
1997  while (p) {
1998  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1999  p->id == id) {
2000  if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
2001  experimental = p;
2002  } else
2003  return p;
2004  }
2005  p = p->next;
2006  }
2007  return experimental;
2008 }
2009 
2011 {
2012  return find_encdec(id, 1);
2013 }
2014 
2016 {
2017  AVCodec *p;
2018  if (!name)
2019  return NULL;
2020  p = first_avcodec;
2021  while (p) {
2022  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
2023  return p;
2024  p = p->next;
2025  }
2026  return NULL;
2027 }
2028 
2030 {
2031  return find_encdec(id, 0);
2032 }
2033 
2035 {
2036  AVCodec *p;
2037  if (!name)
2038  return NULL;
2039  p = first_avcodec;
2040  while (p) {
2041  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
2042  return p;
2043  p = p->next;
2044  }
2045  return NULL;
2046 }
2047 
2049 {
2050  int bit_rate;
2051  int bits_per_sample;
2052 
2053  switch (ctx->codec_type) {
2054  case AVMEDIA_TYPE_VIDEO:
2055  case AVMEDIA_TYPE_DATA:
2056  case AVMEDIA_TYPE_SUBTITLE:
2058  bit_rate = ctx->bit_rate;
2059  break;
2060  case AVMEDIA_TYPE_AUDIO:
2061  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
2062  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
2063  break;
2064  default:
2065  bit_rate = 0;
2066  break;
2067  }
2068  return bit_rate;
2069 }
2070 
2071 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
2072 {
2073  int i, len, ret = 0;
2074 
2075 #define TAG_PRINT(x) \
2076  (((x) >= '0' && (x) <= '9') || \
2077  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2078  ((x) == '.' || (x) == ' '))
2079 
2080  for (i = 0; i < 4; i++) {
2081  len = snprintf(buf, buf_size,
2082  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
2083  buf += len;
2084  buf_size = buf_size > len ? buf_size - len : 0;
2085  ret += len;
2086  codec_tag >>= 8;
2087  }
2088  return ret;
2089 }
2090 
2091 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
2092 {
2093  const char *codec_name;
2094  const char *profile = NULL;
2095  char buf1[32];
2096  int bitrate;
2097  int new_line = 0;
2098  AVRational display_aspect_ratio;
2100 
2101  if (desc) {
2102  codec_name = desc->name;
2103  profile = avcodec_profile_name(enc->codec_id, enc->profile);
2104  } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) {
2105  /* fake mpeg2 transport stream codec (currently not
2106  * registered) */
2107  codec_name = "mpeg2ts";
2108  } else {
2109  /* output avi tags */
2110  char tag_buf[32];
2111  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
2112  snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
2113  codec_name = buf1;
2114  }
2115 
2116  switch (enc->codec_type) {
2117  case AVMEDIA_TYPE_VIDEO:
2118  snprintf(buf, buf_size,
2119  "Video: %s%s",
2120  codec_name, enc->mb_decision ? " (hq)" : "");
2121  if (profile)
2122  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2123  " (%s)", profile);
2124  if (enc->codec_tag) {
2125  char tag_buf[32];
2126  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
2127  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2128  " [%s / 0x%04X]", tag_buf, enc->codec_tag);
2129  }
2130 
2131  av_strlcat(buf, "\n ", buf_size);
2132  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2133  "%s", enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
2135 
2137  snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s",
2139  if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
2141  enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
2142  new_line = 1;
2143  snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s/%s/%s",
2147  }
2148  if (av_log_get_level() >= AV_LOG_DEBUG &&
2150  snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s",
2152 
2153  if (enc->width) {
2154  av_strlcat(buf, new_line ? "\n " : ", ", buf_size);
2155 
2156  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2157  "%dx%d",
2158  enc->width, enc->height);
2159 
2160  if (av_log_get_level() >= AV_LOG_VERBOSE &&
2161  (enc->width != enc->coded_width ||
2162  enc->height != enc->coded_height))
2163  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2164  " (%dx%d)", enc->coded_width, enc->coded_height);
2165 
2166  if (enc->sample_aspect_ratio.num) {
2167  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
2168  enc->width * enc->sample_aspect_ratio.num,
2169  enc->height * enc->sample_aspect_ratio.den,
2170  1024 * 1024);
2171  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2172  " [PAR %d:%d DAR %d:%d]",
2174  display_aspect_ratio.num, display_aspect_ratio.den);
2175  }
2176  if (av_log_get_level() >= AV_LOG_DEBUG) {
2177  int g = av_gcd(enc->time_base.num, enc->time_base.den);
2178  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2179  ", %d/%d",
2180  enc->time_base.num / g, enc->time_base.den / g);
2181  }
2182  }
2183  if (encode) {
2184  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2185  ", q=%d-%d", enc->qmin, enc->qmax);
2186  }
2187  break;
2188  case AVMEDIA_TYPE_AUDIO:
2189  snprintf(buf, buf_size,
2190  "Audio: %s",
2191  codec_name);
2192  if (profile)
2193  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2194  " (%s)", profile);
2195  if (enc->codec_tag) {
2196  char tag_buf[32];
2197  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
2198  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2199  " [%s / 0x%04X]", tag_buf, enc->codec_tag);
2200  }
2201 
2202  av_strlcat(buf, "\n ", buf_size);
2203  if (enc->sample_rate) {
2204  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2205  "%d Hz, ", enc->sample_rate);
2206  }
2207  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
2208  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
2209  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2210  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
2211  }
2212  break;
2213  case AVMEDIA_TYPE_DATA:
2214  snprintf(buf, buf_size, "Data: %s", codec_name);
2215  break;
2216  case AVMEDIA_TYPE_SUBTITLE:
2217  snprintf(buf, buf_size, "Subtitle: %s", codec_name);
2218  break;
2220  snprintf(buf, buf_size, "Attachment: %s", codec_name);
2221  break;
2222  default:
2223  snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
2224  return;
2225  }
2226  if (encode) {
2227  if (enc->flags & AV_CODEC_FLAG_PASS1)
2228  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2229  ", pass 1");
2230  if (enc->flags & AV_CODEC_FLAG_PASS2)
2231  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2232  ", pass 2");
2233  }
2234  bitrate = get_bit_rate(enc);
2235  if (bitrate != 0) {
2236  snprintf(buf + strlen(buf), buf_size - strlen(buf),
2237  ", %d kb/s", bitrate / 1000);
2238  }
2239 }
2240 
2241 const char *av_get_profile_name(const AVCodec *codec, int profile)
2242 {
2243  const AVProfile *p;
2244  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
2245  return NULL;
2246 
2247  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
2248  if (p->profile == profile)
2249  return p->name;
2250 
2251  return NULL;
2252 }
2253 
2255 {
2256  const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
2257  const AVProfile *p;
2258 
2259  if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
2260  return NULL;
2261 
2262  for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
2263  if (p->profile == profile)
2264  return p->name;
2265 
2266  return NULL;
2267 }
2268 
2269 unsigned avcodec_version(void)
2270 {
2271  return LIBAVCODEC_VERSION_INT;
2272 }
2273 
2274 const char *avcodec_configuration(void)
2275 {
2276  return LIBAV_CONFIGURATION;
2277 }
2278 
2279 const char *avcodec_license(void)
2280 {
2281 #define LICENSE_PREFIX "libavcodec license: "
2282  return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
2283 }
2284 
2286 {
2287  avctx->internal->draining = 0;
2288  avctx->internal->draining_done = 0;
2291  avctx->internal->buffer_pkt_valid = 0;
2292 
2294  ff_thread_flush(avctx);
2295  else if (avctx->codec->flush)
2296  avctx->codec->flush(avctx);
2297 
2298  if (!avctx->refcounted_frames)
2299  av_frame_unref(avctx->internal->to_free);
2300 }
2301 
2303 {
2304  switch (codec_id) {
2305  case AV_CODEC_ID_ADPCM_CT:
2311  return 4;
2312  case AV_CODEC_ID_PCM_ALAW:
2313  case AV_CODEC_ID_PCM_MULAW:
2314  case AV_CODEC_ID_PCM_S8:
2315  case AV_CODEC_ID_PCM_U8:
2316  case AV_CODEC_ID_PCM_ZORK:
2317  return 8;
2318  case AV_CODEC_ID_PCM_S16BE:
2320  case AV_CODEC_ID_PCM_S16LE:
2322  case AV_CODEC_ID_PCM_U16BE:
2323  case AV_CODEC_ID_PCM_U16LE:
2324  return 16;
2326  case AV_CODEC_ID_PCM_S24BE:
2327  case AV_CODEC_ID_PCM_S24LE:
2329  case AV_CODEC_ID_PCM_U24BE:
2330  case AV_CODEC_ID_PCM_U24LE:
2331  return 24;
2332  case AV_CODEC_ID_PCM_S32BE:
2333  case AV_CODEC_ID_PCM_S32LE:
2335  case AV_CODEC_ID_PCM_U32BE:
2336  case AV_CODEC_ID_PCM_U32LE:
2337  case AV_CODEC_ID_PCM_F32BE:
2338  case AV_CODEC_ID_PCM_F32LE:
2339  return 32;
2340  case AV_CODEC_ID_PCM_F64BE:
2341  case AV_CODEC_ID_PCM_F64LE:
2342  return 64;
2343  default:
2344  return 0;
2345  }
2346 }
2347 
2349 {
2350  switch (codec_id) {
2352  return 2;
2354  return 3;
2358  case AV_CODEC_ID_ADPCM_SWF:
2359  case AV_CODEC_ID_ADPCM_MS:
2360  return 4;
2361  default:
2362  return av_get_exact_bits_per_sample(codec_id);
2363  }
2364 }
2365 
2366 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
2367  uint32_t tag, int bits_per_coded_sample, int frame_bytes)
2368 {
2370 
2371  /* codecs with an exact constant bits per sample */
2372  if (bps > 0 && ch > 0 && frame_bytes > 0)
2373  return (frame_bytes * 8) / (bps * ch);
2374  bps = bits_per_coded_sample;
2375 
2376  /* codecs with a fixed packet duration */
2377  switch (id) {
2378  case AV_CODEC_ID_ADPCM_ADX: return 32;
2379  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
2380  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
2381  case AV_CODEC_ID_AMR_NB:
2382  case AV_CODEC_ID_GSM:
2383  case AV_CODEC_ID_QCELP:
2384  case AV_CODEC_ID_RA_144:
2385  case AV_CODEC_ID_RA_288: return 160;
2386  case AV_CODEC_ID_IMC: return 256;
2387  case AV_CODEC_ID_AMR_WB:
2388  case AV_CODEC_ID_GSM_MS: return 320;
2389  case AV_CODEC_ID_MP1: return 384;
2390  case AV_CODEC_ID_ATRAC1: return 512;
2391  case AV_CODEC_ID_ATRAC3: return 1024;
2392  case AV_CODEC_ID_MP2:
2393  case AV_CODEC_ID_MUSEPACK7: return 1152;
2394  case AV_CODEC_ID_AC3: return 1536;
2395  }
2396 
2397  if (sr > 0) {
2398  /* calc from sample rate */
2399  if (id == AV_CODEC_ID_TTA)
2400  return 256 * sr / 245;
2401 
2402  if (ch > 0) {
2403  /* calc from sample rate and channels */
2404  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
2405  return (480 << (sr / 22050)) / ch;
2406  }
2407  }
2408 
2409  if (ba > 0) {
2410  /* calc from block_align */
2411  if (id == AV_CODEC_ID_SIPR) {
2412  switch (ba) {
2413  case 20: return 160;
2414  case 19: return 144;
2415  case 29: return 288;
2416  case 37: return 480;
2417  }
2418  } else if (id == AV_CODEC_ID_ILBC) {
2419  switch (ba) {
2420  case 38: return 160;
2421  case 50: return 240;
2422  }
2423  }
2424  }
2425 
2426  if (frame_bytes > 0) {
2427  /* calc from frame_bytes only */
2428  if (id == AV_CODEC_ID_TRUESPEECH)
2429  return 240 * (frame_bytes / 32);
2430  if (id == AV_CODEC_ID_NELLYMOSER)
2431  return 256 * (frame_bytes / 64);
2432 
2433  if (bps > 0) {
2434  /* calc from frame_bytes and bits_per_coded_sample */
2435  if (id == AV_CODEC_ID_ADPCM_G726)
2436  return frame_bytes * 8 / bps;
2437  }
2438 
2439  if (ch > 0) {
2440  /* calc from frame_bytes and channels */
2441  switch (id) {
2442  case AV_CODEC_ID_ADPCM_4XM:
2444  return (frame_bytes - 4 * ch) * 2 / ch;
2446  return (frame_bytes - 4) * 2 / ch;
2448  return (frame_bytes - 8) * 2 / ch;
2449  case AV_CODEC_ID_ADPCM_XA:
2450  return (frame_bytes / 128) * 224 / ch;
2452  return (frame_bytes - 6 - ch) / ch;
2453  case AV_CODEC_ID_ROQ_DPCM:
2454  return (frame_bytes - 8) / ch;
2455  case AV_CODEC_ID_XAN_DPCM:
2456  return (frame_bytes - 2 * ch) / ch;
2457  case AV_CODEC_ID_MACE3:
2458  return 3 * frame_bytes / ch;
2459  case AV_CODEC_ID_MACE6:
2460  return 6 * frame_bytes / ch;
2461  case AV_CODEC_ID_PCM_LXF:
2462  return 2 * (frame_bytes / (5 * ch));
2463  }
2464 
2465  if (tag) {
2466  /* calc from frame_bytes, channels, and codec_tag */
2467  if (id == AV_CODEC_ID_SOL_DPCM) {
2468  if (tag == 3)
2469  return frame_bytes / ch;
2470  else
2471  return frame_bytes * 2 / ch;
2472  }
2473  }
2474 
2475  if (ba > 0) {
2476  /* calc from frame_bytes, channels, and block_align */
2477  int blocks = frame_bytes / ba;
2478  switch (id) {
2480  return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2482  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2484  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2485  case AV_CODEC_ID_ADPCM_MS:
2486  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2487  }
2488  }
2489 
2490  if (bps > 0) {
2491  /* calc from frame_bytes, channels, and bits_per_coded_sample */
2492  switch (id) {
2493  case AV_CODEC_ID_PCM_DVD:
2494  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2496  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
2497  case AV_CODEC_ID_S302M:
2498  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2499  }
2500  }
2501  }
2502  }
2503 
2504  return 0;
2505 }
2506 
2507 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
2508 {
2509  return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
2510  avctx->channels, avctx->block_align,
2511  avctx->codec_tag, avctx->bits_per_coded_sample,
2512  frame_bytes);
2513 }
2514 
2516 {
2517  return get_audio_frame_duration(par->codec_id, par->sample_rate,
2518  par->channels, par->block_align,
2519  par->codec_tag, par->bits_per_coded_sample,
2520  frame_bytes);
2521 }
2522 
2523 #if !HAVE_THREADS
2525 {
2526  return -1;
2527 }
2528 
2529 #endif
2530 
2531 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
2532 {
2533  unsigned int n = 0;
2534 
2535  while (v >= 0xff) {
2536  *s++ = 0xff;
2537  v -= 0xff;
2538  n++;
2539  }
2540  *s = v;
2541  n++;
2542  return n;
2543 }
2544 
2545 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
2546 {
2547  int i;
2548  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
2549  return i;
2550 }
2551 
2552 #if FF_API_MISSING_SAMPLE
2554 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
2555 {
2556  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your Libav "
2557  "version to the newest one from Git. If the problem still "
2558  "occurs, it means that your file has a feature which has not "
2559  "been implemented.\n", feature);
2560  if(want_sample)
2562 }
2563 
2564 void av_log_ask_for_sample(void *avc, const char *msg, ...)
2565 {
2566  va_list argument_list;
2567 
2568  va_start(argument_list, msg);
2569 
2570  if (msg)
2571  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
2572  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
2573  "of this file to ftp://upload.libav.org/incoming/ "
2574  "and contact the libav-devel mailing list.\n");
2575 
2576  va_end(argument_list);
2577 }
2579 #endif /* FF_API_MISSING_SAMPLE */
2580 
2582 
2584 {
2585  AVHWAccel **p = &first_hwaccel;
2586  while (*p)
2587  p = &(*p)->next;
2588  *p = hwaccel;
2589  hwaccel->next = NULL;
2590 }
2591 
2593 {
2594  return hwaccel ? hwaccel->next : first_hwaccel;
2595 }
2596 
2597 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
2598 {
2599  if (lockmgr_cb) {
2600  // There is no good way to rollback a failure to destroy the
2601  // mutex, so we ignore failures.
2604  lockmgr_cb = NULL;
2605  codec_mutex = NULL;
2606  avformat_mutex = NULL;
2607  }
2608 
2609  if (cb) {
2610  void *new_codec_mutex = NULL;
2611  void *new_avformat_mutex = NULL;
2612  int err;
2613  if (err = cb(&new_codec_mutex, AV_LOCK_CREATE)) {
2614  return err > 0 ? AVERROR_UNKNOWN : err;
2615  }
2616  if (err = cb(&new_avformat_mutex, AV_LOCK_CREATE)) {
2617  // Ignore failures to destroy the newly created mutex.
2618  cb(&new_codec_mutex, AV_LOCK_DESTROY);
2619  return err > 0 ? AVERROR_UNKNOWN : err;
2620  }
2621  lockmgr_cb = cb;
2622  codec_mutex = new_codec_mutex;
2623  avformat_mutex = new_avformat_mutex;
2624  }
2625 
2626  return 0;
2627 }
2628 
2630 {
2631  if (lockmgr_cb) {
2633  return -1;
2634  }
2635  return 0;
2636 }
2637 
2639 {
2640  if (lockmgr_cb) {
2642  return -1;
2643  }
2644  return 0;
2645 }
2646 
2647 unsigned int avpriv_toupper4(unsigned int x)
2648 {
2649  return av_toupper(x & 0xFF) +
2650  (av_toupper((x >> 8) & 0xFF) << 8) +
2651  (av_toupper((x >> 16) & 0xFF) << 16) +
2652  (av_toupper((x >> 24) & 0xFF) << 24);
2653 }
2654 
2656 {
2657  int ret;
2658 
2659  dst->owner = src->owner;
2660 
2661  ret = av_frame_ref(dst->f, src->f);
2662  if (ret < 0)
2663  return ret;
2664 
2665  if (src->progress &&
2666  !(dst->progress = av_buffer_ref(src->progress))) {
2667  ff_thread_release_buffer(dst->owner, dst);
2668  return AVERROR(ENOMEM);
2669  }
2670 
2671  return 0;
2672 }
2673 
2674 #if !HAVE_THREADS
2675 
2677 {
2678  f->owner = avctx;
2679  return ff_get_buffer(avctx, f->f, flags);
2680 }
2681 
2683 {
2684  if (f->f)
2685  av_frame_unref(f->f);
2686 }
2687 
2689 {
2690 }
2691 
2692 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
2693 {
2694 }
2695 
2696 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
2697 {
2698 }
2699 
2700 #endif
2701 
2703 {
2704  return !!s->internal;
2705 }
2706 
2708  const uint8_t *end,
2709  uint32_t * restrict state)
2710 {
2711  int i;
2712 
2713  assert(p <= end);
2714  if (p >= end)
2715  return end;
2716 
2717  for (i = 0; i < 3; i++) {
2718  uint32_t tmp = *state << 8;
2719  *state = tmp + *(p++);
2720  if (tmp == 0x100 || p == end)
2721  return p;
2722  }
2723 
2724  while (p < end) {
2725  if (p[-1] > 1 ) p += 3;
2726  else if (p[-2] ) p += 2;
2727  else if (p[-3]|(p[-1]-1)) p++;
2728  else {
2729  p++;
2730  break;
2731  }
2732  }
2733 
2734  p = FFMIN(p, end) - 4;
2735  *state = AV_RB32(p);
2736 
2737  return p + 4;
2738 }
2739 
2741 {
2742  AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
2743  if (!props)
2744  return NULL;
2745 
2746  if (size)
2747  *size = sizeof(*props);
2748 
2749  props->vbv_delay = UINT64_MAX;
2750 
2751  return props;
2752 }
2753 
2755 {
2757  AVCPBProperties *props;
2758  size_t size;
2759 
2760  props = av_cpb_properties_alloc(&size);
2761  if (!props)
2762  return NULL;
2763 
2764  tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
2765  if (!tmp) {
2766  av_freep(&props);
2767  return NULL;
2768  }
2769 
2770  avctx->coded_side_data = tmp;
2771  avctx->nb_coded_side_data++;
2772 
2774  avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
2775  avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
2776 
2777  return props;
2778 }
2779 
2781 {
2782  av_freep(&par->extradata);
2783 
2784  memset(par, 0, sizeof(*par));
2785 
2787  par->codec_id = AV_CODEC_ID_NONE;
2788  par->format = -1;
2795  par->sample_aspect_ratio = (AVRational){ 0, 1 };
2796 }
2797 
2799 {
2800  AVCodecParameters *par = av_mallocz(sizeof(*par));
2801 
2802  if (!par)
2803  return NULL;
2805  return par;
2806 }
2807 
2809 {
2810  AVCodecParameters *par = *ppar;
2811 
2812  if (!par)
2813  return;
2815 
2816  av_freep(ppar);
2817 }
2818 
2820 {
2822  memcpy(dst, src, sizeof(*dst));
2823 
2824  dst->extradata = NULL;
2825  dst->extradata_size = 0;
2826  if (src->extradata) {
2828  if (!dst->extradata)
2829  return AVERROR(ENOMEM);
2830  memcpy(dst->extradata, src->extradata, src->extradata_size);
2831  dst->extradata_size = src->extradata_size;
2832  }
2833 
2834  return 0;
2835 }
2836 
2838  const AVCodecContext *codec)
2839 {
2841 
2842  par->codec_type = codec->codec_type;
2843  par->codec_id = codec->codec_id;
2844  par->codec_tag = codec->codec_tag;
2845 
2846  par->bit_rate = codec->bit_rate;
2848  par->profile = codec->profile;
2849  par->level = codec->level;
2850 
2851  switch (par->codec_type) {
2852  case AVMEDIA_TYPE_VIDEO:
2853  par->format = codec->pix_fmt;
2854  par->width = codec->width;
2855  par->height = codec->height;
2856  par->field_order = codec->field_order;
2857  par->color_range = codec->color_range;
2858  par->color_primaries = codec->color_primaries;
2859  par->color_trc = codec->color_trc;
2860  par->color_space = codec->colorspace;
2863  break;
2864  case AVMEDIA_TYPE_AUDIO:
2865  par->format = codec->sample_fmt;
2866  par->channel_layout = codec->channel_layout;
2867  par->channels = codec->channels;
2868  par->sample_rate = codec->sample_rate;
2869  par->block_align = codec->block_align;
2870  par->initial_padding = codec->initial_padding;
2871  break;
2872  }
2873 
2874  if (codec->extradata) {
2876  if (!par->extradata)
2877  return AVERROR(ENOMEM);
2878  memcpy(par->extradata, codec->extradata, codec->extradata_size);
2879  par->extradata_size = codec->extradata_size;
2880  }
2881 
2882  return 0;
2883 }
2884 
2886  const AVCodecParameters *par)
2887 {
2888  codec->codec_type = par->codec_type;
2889  codec->codec_id = par->codec_id;
2890  codec->codec_tag = par->codec_tag;
2891 
2892  codec->bit_rate = par->bit_rate;
2894  codec->profile = par->profile;
2895  codec->level = par->level;
2896 
2897  switch (par->codec_type) {
2898  case AVMEDIA_TYPE_VIDEO:
2899  codec->pix_fmt = par->format;
2900  codec->width = par->width;
2901  codec->height = par->height;
2902  codec->field_order = par->field_order;
2903  codec->color_range = par->color_range;
2904  codec->color_primaries = par->color_primaries;
2905  codec->color_trc = par->color_trc;
2906  codec->colorspace = par->color_space;
2909  break;
2910  case AVMEDIA_TYPE_AUDIO:
2911  codec->sample_fmt = par->format;
2912  codec->channel_layout = par->channel_layout;
2913  codec->channels = par->channels;
2914  codec->sample_rate = par->sample_rate;
2915  codec->block_align = par->block_align;
2916  codec->initial_padding = par->initial_padding;
2917  break;
2918  }
2919 
2920  if (par->extradata) {
2921  av_freep(&codec->extradata);
2923  if (!codec->extradata)
2924  return AVERROR(ENOMEM);
2925  memcpy(codec->extradata, par->extradata, par->extradata_size);
2926  codec->extradata_size = par->extradata_size;
2927  }
2928 
2929  return 0;
2930 }
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define FF_SANE_NB_CHANNELS
Definition: internal.h:74
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2610
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
Definition: avcodec.h:1671
static int apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1449
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:78
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
enum AVChromaLocation chroma_location
Definition: avcodec.h:3549
const struct AVCodec * codec
Definition: avcodec.h:1418
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:159
AVRational framerate
Definition: avcodec.h:3063
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
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:3540
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:1993
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:3547
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define AV_NUM_DATA_POINTERS
Definition: frame.h:141
AVPacketSideDataType
Definition: avcodec.h:1191
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: utils.c:534
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
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:2010
int stride_align[AV_NUM_DATA_POINTERS]
Definition: internal.h:90
#define LIBAV_CONFIGURATION
Definition: config.h:4
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:152
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:94
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1595
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:2597
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:64
misc image utilities
Unlock the mutex.
Definition: avcodec.h:5253
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
AVFrame * f
Definition: thread.h:36
AVFrame * to_free
Definition: internal.h:127
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:308
const char * desc
Definition: nvenc.c:101
int width
Definition: internal.h:89
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:155
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:1624
AVRational sample_aspect_ratio
Video only.
Definition: avcodec.h:3535
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2426
static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
Definition: utils.c:1706
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: utils.c:1911
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: avcodec.h:1260
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:599
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:2274
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2127
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:326
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:162
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:2279
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:3265
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:1804
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: utils.c:1234
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: internal.h:137
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:182
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:1270
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
int samples
Definition: internal.h:94
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:189
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:202
unsigned num_rects
Definition: avcodec.h:3463
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:60
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:149
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:885
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:319
mpegvideo header.
enum AVMediaType type
Definition: avcodec.h:3133
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:2071
#define FF_ARRAY_ELEMS(a)
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:83
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:905
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:1673
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: avcodec.h:3285
int profile
profile
Definition: avcodec.h:2880
AVCodec.
Definition: avcodec.h:3120
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2189
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:91
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3475
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:5250
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:134
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:3448
enum AVColorSpace color_space
Definition: avcodec.h:3548
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:121
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:1890
Macro definitions for various function/variable attributes.
FF_DISABLE_DEPRECATION_WARNINGS void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
Definition: utils.c:2554
static void * codec_mutex
Definition: utils.c:57
int(* receive_packet)(AVCodecContext *avctx, AVPacket *avpkt)
Definition: avcodec.h:3221
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1535
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:202
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:501
AVSubtitleRect ** rects
Definition: avcodec.h:3464
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:101
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: avcodec.h:3351
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:2217
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:300
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:96
uint64_t vbv_delay
The delay between the time the packet this structure is associated with is received and the time when...
Definition: avcodec.h:1170
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:285
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2696
static int volatile entangled_thread_counter
Definition: utils.c:55
#define AV_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:863
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:98
int height
Definition: internal.h:89
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:60
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Definition: utils.c:733
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2160
Lock the mutex.
Definition: avcodec.h:5252
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:68
Opaque data information usually continuous.
Definition: avutil.h:196
int width
Video only.
Definition: avcodec.h:3525
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:70
AVOptions.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: utils.c:2798
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:142
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:1872
#define AV_RB32
Definition: intreadwrite.h:130
void * thread_ctx
Definition: internal.h:131
static int setup_hwaccel(AVCodecContext *avctx, const enum AVPixelFormat fmt, const char *name)
Definition: utils.c:752
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1364
static AVCodec * first_avcodec
Definition: utils.c:74
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: avcodec.h:1254
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:161
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:199
#define emms_c()
Definition: internal.h:48
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:34
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:672
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1523
#define LICENSE_PREFIX
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: utils.c:2885
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:2754
int planes
Definition: internal.h:92
int initial_padding
Audio only.
Definition: avcodec.h:3579
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:234
uint8_t * data
Definition: avcodec.h:1346
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:97
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:401
static int flags
Definition: log.c:50
uint32_t tag
Definition: movenc.c:854
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:72
#define AVERROR_EOF
End of file.
Definition: error.h:51
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:140
uint8_t * data
Definition: avcodec.h:1290
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:73
int(* init)(AVCodecContext *avctx)
Initialize the hwaccel private data.
Definition: avcodec.h:3343
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:2545
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2769
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:146
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
Definition: utils.c:2740
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:2134
static void codec_parameters_reset(AVCodecParameters *par)
Definition: utils.c:2780
#define FFALIGN(x, a)
Definition: macros.h:48
uint64_t channel_layout
Audio only.
Definition: avcodec.h:3556
AVCodecContext * owner
Definition: thread.h:37
const char * name
Definition: pixdesc.h:81
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:129
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:2015
const OptionDef options[]
Definition: avconv_opt.c:2447
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:189
static av_cold void avcodec_init(void)
Definition: utils.c:84
#define EDGE_WIDTH
Definition: mpegpicture.h:33
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:150
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:128
Libavcodec version macros.
#define src
Definition: vp8dsp.c:254
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:1943
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:84
static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, uint32_t tag, int bits_per_coded_sample, int frame_bytes)
Definition: utils.c:2366
enum AVCodecID id
Definition: avcodec.h:3134
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:3144
#define STRIDE_ALIGN
Definition: utils.c:186
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:163
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:158
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition: pixdesc.c:1896
static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
Definition: utils.c:1850
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:169
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:193
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:2819
int width
width and height of the video frame
Definition: frame.h:179
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:2348
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
Create a mutex.
Definition: avcodec.h:5251
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
AVAudioServiceType
Definition: avcodec.h:692
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: avcodec.h:1218
#define AVERROR(e)
Definition: error.h:43
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2647
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:80
int(* send_frame)(AVCodecContext *avctx, const AVFrame *frame)
Decode/encode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3218
int qmax
maximum quantizer
Definition: avcodec.h:2337
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:76
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2825
enum AVColorPrimaries color_primaries
Definition: avcodec.h:3546
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2702
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
Definition: utils.c:1807
g
Definition: yuv2rgb.c:546
AVFrame * buffer_frame
Definition: internal.h:154
int capabilities
Codec capabilities.
Definition: avcodec.h:3139
enum AVColorRange color_range
Definition: frame.h:351
int initial_padding
Audio only.
Definition: avcodec.h:3054
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:2524
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:175
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
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:1329
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:154
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1503
enum AVColorSpace colorspace
Definition: frame.h:357
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:142
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:32
enum AVPacketSideDataType type
Definition: avcodec.h:1292
int av_log_get_level(void)
Get the current log level.
Definition: log.c:200
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
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
const struct AVProfile * profiles
If non-NULL, an array of profiles recognized for this codec.
Definition: avcodec.h:601
int av_buffer_realloc(AVBufferRef **pbuf, int size)
Reallocate a given buffer.
Definition: buffer.c:147
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:82
#define FFMAX(a, b)
Definition: common.h:64
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: utils.c:2808
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:2515
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:394
#define fail()
Definition: checkasm.h:80
av_cold void ff_me_cmp_init_static(void)
Definition: me_cmp.c:887
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:909
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:556
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
Definition: avcodec.h:3357
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:1878
reference-counted frame API
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2462
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2203
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:63
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2364
int(* send_packet)(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: avcodec.h:3219
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:294
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 bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3512
common internal API header
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:179
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:105
static AVHWAccel * find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
Definition: utils.c:740
int block_align
Audio only.
Definition: avcodec.h:3571
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:223
const char * name
Definition: qsvenc.c:44
static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:336
int bit_rate
the average bitrate
Definition: avcodec.h:1473
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:3141
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2670
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2817
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:868
#define FFMIN(a, b)
Definition: common.h:66
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:3078
const uint8_t * avpriv_find_start_code(const uint8_t *restrict p, const uint8_t *end, uint32_t *restrict state)
Definition: utils.c:2707
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:322
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:71
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:2302
int channels
Definition: internal.h:93
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:727
enum AVCodecID codec_id
Definition: avconv_vaapi.c:149
int width
picture width / height.
Definition: avcodec.h:1580
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3102
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2881
int priv_data_size
Definition: avcodec.h:3158
int profile
Definition: avcodec.h:3109
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:751
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2106
AVFrameSideDataType
Definition: frame.h:47
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:181
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:201
int level
level
Definition: avcodec.h:2970
#define FF_DEBUG_BUFFERS
Definition: avcodec.h:2651
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:2688
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:3149
int64_t reordered_opaque
opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:2689
#define AV_EF_EXPLODE
Definition: avcodec.h:2681
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:476
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2319
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1544
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:62
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:151
enum AVColorRange color_range
Video only.
Definition: avcodec.h:3545
int mb_decision
macroblock decision mode
Definition: avcodec.h:1953
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:193
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:2564
Opaque data information usually sparse.
Definition: avutil.h:198
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1211
enum AVPixelFormat pix_fmt
Definition: movenc.c:853
static pthread_mutex_t * mutex
Definition: w32pthreads.h:245
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:433
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:160
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3443
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:147
#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:2806
int linesize[4]
Definition: internal.h:91
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:365
if(ac->has_optimized_func)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:2285
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:191
AVBufferRef * progress
Definition: thread.h:40
int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: utils.c:1767
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:2241
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2172
#define attribute_align_arg
Definition: internal.h:55
#define LIBAV_LICENSE
Definition: config.h:5
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1140
NULL
Definition: eval.c:55
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:80
static int width
Definition: utils.c:156
int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: utils.c:514
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:100
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1417
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:60
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:83
enum AVCodecID codec_id
Definition: avcodec.h:1426
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:328
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:735
int sample_rate
samples per second
Definition: avcodec.h:2152
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
void(* func)(void)
Definition: checkasm.c:65
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:170
int debug
debug
Definition: avcodec.h:2626
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:80
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:165
main external API structure.
Definition: avcodec.h:1409
int(* receive_frame)(AVCodecContext *avctx, AVFrame *frame)
Definition: avcodec.h:3220
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:2029
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:347
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2330
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1687
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" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:1441
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:60
uint8_t * data
Definition: frame.h:109
int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
Definition: utils.c:1881
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:1524
int(* close)(AVCodecContext *)
Definition: avcodec.h:3206
#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:2531
struct AVCodec * next
Definition: avcodec.h:3159
int nb_coded_side_data
Definition: avcodec.h:3079
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:65
int coded_height
Definition: avcodec.h:1595
int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:284
Describe the class of an AVClass context structure.
Definition: log.h:34
int sample_rate
Sample rate of the audio data.
Definition: frame.h:289
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:2304
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:69
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:468
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:182
Y , 16bpp, big-endian.
Definition: pixfmt.h:94
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:254
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:2120
rational number numerator/denominator
Definition: rational.h:43
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:1384
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2113
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:2682
const char * name
short name for the profile
Definition: avcodec.h:3110
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: utils.c:2837
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
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:195
int buffer_pkt_valid
Definition: internal.h:153
static FF_ENABLE_DEPRECATION_WARNINGS AVHWAccel * first_hwaccel
Definition: utils.c:2581
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:588
enum AVChromaLocation chroma_location
Definition: frame.h:359
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:850
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:2507
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
mfxU16 profile
Definition: qsvenc.c:43
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:2592
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:580
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:186
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:302
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:180
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:2034
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: avcodec.h:1245
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
Definition: internal.h:55
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
static void * av_malloc_array(size_t nmemb, size_t size)
Definition: mem.h:92
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3148
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:156
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:219
int height
Definition: gxfenc.c:72
int sample_rate
Audio only.
Definition: avcodec.h:3564
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:152
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:225
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
static struct @174 state
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:394
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
Y , 8bpp.
Definition: pixfmt.h:67
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:715
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3205
common internal api header.
Free mutex resources.
Definition: avcodec.h:5254
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
Definition: buffer.c:217
int avpriv_lock_avformat(void)
Definition: utils.c:2629
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:2583
struct AVHWAccel * next
Definition: avcodec.h:3280
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: avcodec.h:901
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:208
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:3226
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:164
int(* init)(AVCodecContext *)
Definition: avcodec.h:3190
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:3519
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:1884
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:142
uint32_t start_display_time
Definition: avcodec.h:3461
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:3191
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
AVProfile.
Definition: avcodec.h:3108
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:73
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2797
enum AVCodecID id
Codec implemented by the hardware accelerator.
Definition: avcodec.h:3258
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:2692
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:83
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:251
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:161
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:66
int caps_internal
Internal codec capabilities.
Definition: avcodec.h:3231
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:31
#define CONFIG_ME_CMP
Definition: config.h:480
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:715
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:61
unsigned bps
Definition: movenc.c:855
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:2091
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:755
int av_packet_ref(AVPacket *dst, AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:356
void * priv_data
Definition: avcodec.h:1451
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition: avcodec.h:567
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:78
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3203
#define TAG_PRINT(x)
as in Berlin toast format
Definition: avcodec.h:496
int len
int channels
number of audio channels
Definition: avcodec.h:2153
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:3142
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1459
static uint8_t tmp[8]
Definition: des.c:38
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:2269
Y , 16bpp, little-endian.
Definition: pixfmt.h:95
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:49
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3455
This side data corresponds to the AVCPBProperties struct.
Definition: avcodec.h:1286
static void * avformat_mutex
Definition: utils.c:58
static int get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:2048
int bits_per_coded_sample
Definition: avcodec.h:3514
enum AVColorPrimaries color_primaries
Definition: frame.h:353
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3497
static const struct twinvq_data tab
#define HAVE_THREADS
Definition: config.h:321
#define restrict
Definition: config.h:8
int channels
Audio only.
Definition: avcodec.h:3560
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:2696
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:179
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1345
av_cold void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:106
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2183
int height
Definition: frame.h:179
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:96
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:2149
static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
Definition: utils.c:1514
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:3188
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:355
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:284
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:785
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:2655
static int(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:56
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:202
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:310
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3143
AVMatrixEncoding
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2676
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3487
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:1704
int avpriv_unlock_avformat(void)
Definition: utils.c:2638
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:75
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:1559
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:174
int format
Definition: internal.h:88
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:79
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:215
Stereoscopic 3d metadata.
Definition: frame.h:62
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
This structure stores compressed data.
Definition: avcodec.h:1323
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:2254
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: utils.c:1434
int delay
Codec delay.
Definition: avcodec.h:1563
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:1183
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:184
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:211
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:2605
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:66
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:157
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3070
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:386
#define FFMAX3(a, b, c)
Definition: common.h:65
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:166
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:703
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:125
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: avcodec.h:1266
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:2999
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:153