FFmpeg  3.3.8
utils.c
Go to the documentation of this file.
1 /*
2  * utils for libavcodec
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * utils.
26  */
27 
28 #include "config.h"
29 #include "libavutil/atomic.h"
30 #include "libavutil/attributes.h"
31 #include "libavutil/avassert.h"
32 #include "libavutil/avstring.h"
33 #include "libavutil/bprint.h"
35 #include "libavutil/crc.h"
36 #include "libavutil/frame.h"
37 #include "libavutil/hwcontext.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/mem_internal.h"
41 #include "libavutil/pixdesc.h"
42 #include "libavutil/imgutils.h"
43 #include "libavutil/samplefmt.h"
44 #include "libavutil/dict.h"
45 #include "libavutil/thread.h"
46 #include "avcodec.h"
47 #include "libavutil/opt.h"
48 #include "me_cmp.h"
49 #include "mpegvideo.h"
50 #include "thread.h"
51 #include "frame_thread_encoder.h"
52 #include "internal.h"
53 #include "raw.h"
54 #include "bytestream.h"
55 #include "version.h"
56 #include <stdlib.h>
57 #include <stdarg.h>
58 #include <limits.h>
59 #include <float.h>
60 #if CONFIG_ICONV
61 # include <iconv.h>
62 #endif
63 
64 #include "libavutil/ffversion.h"
65 const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
66 
67 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
68 static int default_lockmgr_cb(void **arg, enum AVLockOp op)
69 {
70  void * volatile * mutex = arg;
71  int err;
72 
73  switch (op) {
74  case AV_LOCK_CREATE:
75  return 0;
76  case AV_LOCK_OBTAIN:
77  if (!*mutex) {
79  if (!tmp)
80  return AVERROR(ENOMEM);
81  if ((err = pthread_mutex_init(tmp, NULL))) {
82  av_free(tmp);
83  return AVERROR(err);
84  }
85  if (avpriv_atomic_ptr_cas(mutex, NULL, tmp)) {
87  av_free(tmp);
88  }
89  }
90 
91  if ((err = pthread_mutex_lock(*mutex)))
92  return AVERROR(err);
93 
94  return 0;
95  case AV_LOCK_RELEASE:
96  if ((err = pthread_mutex_unlock(*mutex)))
97  return AVERROR(err);
98 
99  return 0;
100  case AV_LOCK_DESTROY:
101  if (*mutex)
102  pthread_mutex_destroy(*mutex);
103  av_free(*mutex);
104  avpriv_atomic_ptr_cas(mutex, *mutex, NULL);
105  return 0;
106  }
107  return 1;
108 }
109 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = default_lockmgr_cb;
110 #else
111 static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) = NULL;
112 #endif
113 
114 
115 volatile int ff_avcodec_locked;
116 static int volatile entangled_thread_counter = 0;
117 static void *codec_mutex;
118 static void *avformat_mutex;
119 
120 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
121 {
122  uint8_t **p = ptr;
123  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
124  av_freep(p);
125  *size = 0;
126  return;
127  }
128  if (!ff_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE, 1))
129  memset(*p + min_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
130 }
131 
132 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
133 {
134  uint8_t **p = ptr;
135  if (min_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
136  av_freep(p);
137  *size = 0;
138  return;
139  }
140  if (!ff_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE, 1))
141  memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE);
142 }
143 
144 /* encoder management */
147 
149 {
150  if (c)
151  return c->next;
152  else
153  return first_avcodec;
154 }
155 
156 static av_cold void avcodec_init(void)
157 {
158  static int initialized = 0;
159 
160  if (initialized != 0)
161  return;
162  initialized = 1;
163 
164  if (CONFIG_ME_CMP)
166 }
167 
168 int av_codec_is_encoder(const AVCodec *codec)
169 {
170  return codec && (codec->encode_sub || codec->encode2 ||codec->send_frame);
171 }
172 
173 int av_codec_is_decoder(const AVCodec *codec)
174 {
175  return codec && (codec->decode || codec->send_packet);
176 }
177 
179 {
180  AVCodec **p;
181  avcodec_init();
182  p = last_avcodec;
183  codec->next = NULL;
184 
185  while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
186  p = &(*p)->next;
187  last_avcodec = &codec->next;
188 
189  if (codec->init_static_data)
190  codec->init_static_data(codec);
191 }
192 
193 #if FF_API_EMU_EDGE
195 {
196  return EDGE_WIDTH;
197 }
198 #endif
199 
200 #if FF_API_SET_DIMENSIONS
202 {
203  int ret = ff_set_dimensions(s, width, height);
204  if (ret < 0) {
205  av_log(s, AV_LOG_WARNING, "Failed to set dimensions %d %d\n", width, height);
206  }
207 }
208 #endif
209 
211 {
212  int ret = av_image_check_size2(width, height, s->max_pixels, AV_PIX_FMT_NONE, 0, s);
213 
214  if (ret < 0)
215  width = height = 0;
216 
217  s->coded_width = width;
218  s->coded_height = height;
219  s->width = AV_CEIL_RSHIFT(width, s->lowres);
220  s->height = AV_CEIL_RSHIFT(height, s->lowres);
221 
222  return ret;
223 }
224 
226 {
227  int ret = av_image_check_sar(avctx->width, avctx->height, sar);
228 
229  if (ret < 0) {
230  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %d/%d\n",
231  sar.num, sar.den);
232  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
233  return ret;
234  } else {
235  avctx->sample_aspect_ratio = sar;
236  }
237  return 0;
238 }
239 
241  enum AVMatrixEncoding matrix_encoding)
242 {
243  AVFrameSideData *side_data;
244  enum AVMatrixEncoding *data;
245 
247  if (!side_data)
249  sizeof(enum AVMatrixEncoding));
250 
251  if (!side_data)
252  return AVERROR(ENOMEM);
253 
254  data = (enum AVMatrixEncoding*)side_data->data;
255  *data = matrix_encoding;
256 
257  return 0;
258 }
259 
261  int linesize_align[AV_NUM_DATA_POINTERS])
262 {
263  int i;
264  int w_align = 1;
265  int h_align = 1;
267 
268  if (desc) {
269  w_align = 1 << desc->log2_chroma_w;
270  h_align = 1 << desc->log2_chroma_h;
271  }
272 
273  switch (s->pix_fmt) {
274  case AV_PIX_FMT_YUV420P:
275  case AV_PIX_FMT_YUYV422:
276  case AV_PIX_FMT_YVYU422:
277  case AV_PIX_FMT_UYVY422:
278  case AV_PIX_FMT_YUV422P:
279  case AV_PIX_FMT_YUV440P:
280  case AV_PIX_FMT_YUV444P:
281  case AV_PIX_FMT_GBRP:
282  case AV_PIX_FMT_GBRAP:
283  case AV_PIX_FMT_GRAY8:
284  case AV_PIX_FMT_GRAY16BE:
285  case AV_PIX_FMT_GRAY16LE:
286  case AV_PIX_FMT_YUVJ420P:
287  case AV_PIX_FMT_YUVJ422P:
288  case AV_PIX_FMT_YUVJ440P:
289  case AV_PIX_FMT_YUVJ444P:
290  case AV_PIX_FMT_YUVA420P:
291  case AV_PIX_FMT_YUVA422P:
292  case AV_PIX_FMT_YUVA444P:
345  case AV_PIX_FMT_GBRP9LE:
346  case AV_PIX_FMT_GBRP9BE:
347  case AV_PIX_FMT_GBRP10LE:
348  case AV_PIX_FMT_GBRP10BE:
349  case AV_PIX_FMT_GBRP12LE:
350  case AV_PIX_FMT_GBRP12BE:
351  case AV_PIX_FMT_GBRP14LE:
352  case AV_PIX_FMT_GBRP14BE:
353  case AV_PIX_FMT_GBRP16LE:
354  case AV_PIX_FMT_GBRP16BE:
359  w_align = 16; //FIXME assume 16 pixel per macroblock
360  h_align = 16 * 2; // interlaced needs 2 macroblocks height
361  break;
362  case AV_PIX_FMT_YUV411P:
363  case AV_PIX_FMT_YUVJ411P:
365  w_align = 32;
366  h_align = 16 * 2;
367  break;
368  case AV_PIX_FMT_YUV410P:
369  if (s->codec_id == AV_CODEC_ID_SVQ1) {
370  w_align = 64;
371  h_align = 64;
372  }
373  break;
374  case AV_PIX_FMT_RGB555:
375  if (s->codec_id == AV_CODEC_ID_RPZA) {
376  w_align = 4;
377  h_align = 4;
378  }
380  w_align = 8;
381  h_align = 8;
382  }
383  break;
384  case AV_PIX_FMT_PAL8:
385  case AV_PIX_FMT_BGR8:
386  case AV_PIX_FMT_RGB8:
387  if (s->codec_id == AV_CODEC_ID_SMC ||
389  w_align = 4;
390  h_align = 4;
391  }
392  if (s->codec_id == AV_CODEC_ID_JV ||
394  w_align = 8;
395  h_align = 8;
396  }
397  break;
398  case AV_PIX_FMT_BGR24:
399  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
400  (s->codec_id == AV_CODEC_ID_ZLIB)) {
401  w_align = 4;
402  h_align = 4;
403  }
404  break;
405  case AV_PIX_FMT_RGB24:
406  if (s->codec_id == AV_CODEC_ID_CINEPAK) {
407  w_align = 4;
408  h_align = 4;
409  }
410  break;
411  default:
412  break;
413  }
414 
415  if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
416  w_align = FFMAX(w_align, 8);
417  }
418 
419  *width = FFALIGN(*width, w_align);
420  *height = FFALIGN(*height, h_align);
421  if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
424  ) {
425  // some of the optimized chroma MC reads one line too much
426  // which is also done in mpeg decoders with lowres > 0
427  *height += 2;
428 
429  // H.264 uses edge emulation for out of frame motion vectors, for this
430  // it requires a temporary area large enough to hold a 21x21 block,
431  // increasing witdth ensure that the temporary area is large enough,
432  // the next rounded up width is 32
433  *width = FFMAX(*width, 32);
434  }
435 
436  for (i = 0; i < 4; i++)
437  linesize_align[i] = STRIDE_ALIGN;
438 }
439 
441 {
443  int chroma_shift = desc->log2_chroma_w;
444  int linesize_align[AV_NUM_DATA_POINTERS];
445  int align;
446 
447  avcodec_align_dimensions2(s, width, height, linesize_align);
448  align = FFMAX(linesize_align[0], linesize_align[3]);
449  linesize_align[1] <<= chroma_shift;
450  linesize_align[2] <<= chroma_shift;
451  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
452  *width = FFALIGN(*width, align);
453 }
454 
455 int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
456 {
457  if (pos <= AVCHROMA_LOC_UNSPECIFIED || pos >= AVCHROMA_LOC_NB)
458  return AVERROR(EINVAL);
459  pos--;
460 
461  *xpos = (pos&1) * 128;
462  *ypos = ((pos>>1)^(pos<4)) * 128;
463 
464  return 0;
465 }
466 
468 {
469  int pos, xout, yout;
470 
471  for (pos = AVCHROMA_LOC_UNSPECIFIED + 1; pos < AVCHROMA_LOC_NB; pos++) {
472  if (avcodec_enum_to_chroma_pos(&xout, &yout, pos) == 0 && xout == xpos && yout == ypos)
473  return pos;
474  }
476 }
477 
479  enum AVSampleFormat sample_fmt, const uint8_t *buf,
480  int buf_size, int align)
481 {
482  int ch, planar, needed_size, ret = 0;
483 
484  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
485  frame->nb_samples, sample_fmt,
486  align);
487  if (buf_size < needed_size)
488  return AVERROR(EINVAL);
489 
490  planar = av_sample_fmt_is_planar(sample_fmt);
491  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
492  if (!(frame->extended_data = av_mallocz_array(nb_channels,
493  sizeof(*frame->extended_data))))
494  return AVERROR(ENOMEM);
495  } else {
496  frame->extended_data = frame->data;
497  }
498 
499  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
500  (uint8_t *)(intptr_t)buf, nb_channels, frame->nb_samples,
501  sample_fmt, align)) < 0) {
502  if (frame->extended_data != frame->data)
503  av_freep(&frame->extended_data);
504  return ret;
505  }
506  if (frame->extended_data != frame->data) {
507  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
508  frame->data[ch] = frame->extended_data[ch];
509  }
510 
511  return ret;
512 }
513 
515 {
516  FramePool *pool = avctx->internal->pool;
517  int i, ret;
518 
519  switch (avctx->codec_type) {
520  case AVMEDIA_TYPE_VIDEO: {
521  uint8_t *data[4];
522  int linesize[4];
523  int size[4] = { 0 };
524  int w = frame->width;
525  int h = frame->height;
526  int tmpsize, unaligned;
527 
528  if (pool->format == frame->format &&
529  pool->width == frame->width && pool->height == frame->height)
530  return 0;
531 
532  avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
533 
534  do {
535  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
536  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
537  ret = av_image_fill_linesizes(linesize, avctx->pix_fmt, w);
538  if (ret < 0)
539  return ret;
540  // increase alignment of w for next try (rhs gives the lowest bit set in w)
541  w += w & ~(w - 1);
542 
543  unaligned = 0;
544  for (i = 0; i < 4; i++)
545  unaligned |= linesize[i] % pool->stride_align[i];
546  } while (unaligned);
547 
548  tmpsize = av_image_fill_pointers(data, avctx->pix_fmt, h,
549  NULL, linesize);
550  if (tmpsize < 0)
551  return -1;
552 
553  for (i = 0; i < 3 && data[i + 1]; i++)
554  size[i] = data[i + 1] - data[i];
555  size[i] = tmpsize - (data[i] - data[0]);
556 
557  for (i = 0; i < 4; i++) {
558  av_buffer_pool_uninit(&pool->pools[i]);
559  pool->linesize[i] = linesize[i];
560  if (size[i]) {
561  pool->pools[i] = av_buffer_pool_init(size[i] + 16 + STRIDE_ALIGN - 1,
563  NULL :
565  if (!pool->pools[i]) {
566  ret = AVERROR(ENOMEM);
567  goto fail;
568  }
569  }
570  }
571  pool->format = frame->format;
572  pool->width = frame->width;
573  pool->height = frame->height;
574 
575  break;
576  }
577  case AVMEDIA_TYPE_AUDIO: {
578  int ch = av_frame_get_channels(frame); //av_get_channel_layout_nb_channels(frame->channel_layout);
579  int planar = av_sample_fmt_is_planar(frame->format);
580  int planes = planar ? ch : 1;
581 
582  if (pool->format == frame->format && pool->planes == planes &&
583  pool->channels == ch && frame->nb_samples == pool->samples)
584  return 0;
585 
586  av_buffer_pool_uninit(&pool->pools[0]);
587  ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
588  frame->nb_samples, frame->format, 0);
589  if (ret < 0)
590  goto fail;
591 
592  pool->pools[0] = av_buffer_pool_init(pool->linesize[0], NULL);
593  if (!pool->pools[0]) {
594  ret = AVERROR(ENOMEM);
595  goto fail;
596  }
597 
598  pool->format = frame->format;
599  pool->planes = planes;
600  pool->channels = ch;
601  pool->samples = frame->nb_samples;
602  break;
603  }
604  default: av_assert0(0);
605  }
606  return 0;
607 fail:
608  for (i = 0; i < 4; i++)
609  av_buffer_pool_uninit(&pool->pools[i]);
610  pool->format = -1;
611  pool->planes = pool->channels = pool->samples = 0;
612  pool->width = pool->height = 0;
613  return ret;
614 }
615 
617 {
618  FramePool *pool = avctx->internal->pool;
619  int planes = pool->planes;
620  int i;
621 
622  frame->linesize[0] = pool->linesize[0];
623 
624  if (planes > AV_NUM_DATA_POINTERS) {
625  frame->extended_data = av_mallocz_array(planes, sizeof(*frame->extended_data));
626  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
628  sizeof(*frame->extended_buf));
629  if (!frame->extended_data || !frame->extended_buf) {
630  av_freep(&frame->extended_data);
631  av_freep(&frame->extended_buf);
632  return AVERROR(ENOMEM);
633  }
634  } else {
635  frame->extended_data = frame->data;
636  av_assert0(frame->nb_extended_buf == 0);
637  }
638 
639  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
640  frame->buf[i] = av_buffer_pool_get(pool->pools[0]);
641  if (!frame->buf[i])
642  goto fail;
643  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
644  }
645  for (i = 0; i < frame->nb_extended_buf; i++) {
646  frame->extended_buf[i] = av_buffer_pool_get(pool->pools[0]);
647  if (!frame->extended_buf[i])
648  goto fail;
649  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
650  }
651 
652  if (avctx->debug & FF_DEBUG_BUFFERS)
653  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p", frame);
654 
655  return 0;
656 fail:
657  av_frame_unref(frame);
658  return AVERROR(ENOMEM);
659 }
660 
662 {
663  FramePool *pool = s->internal->pool;
665  int i;
666 
667  if (pic->data[0] || pic->data[1] || pic->data[2] || pic->data[3]) {
668  av_log(s, AV_LOG_ERROR, "pic->data[*]!=NULL in avcodec_default_get_buffer\n");
669  return -1;
670  }
671 
672  if (!desc) {
673  av_log(s, AV_LOG_ERROR,
674  "Unable to get pixel format descriptor for format %s\n",
676  return AVERROR(EINVAL);
677  }
678 
679  memset(pic->data, 0, sizeof(pic->data));
680  pic->extended_data = pic->data;
681 
682  for (i = 0; i < 4 && pool->pools[i]; i++) {
683  pic->linesize[i] = pool->linesize[i];
684 
685  pic->buf[i] = av_buffer_pool_get(pool->pools[i]);
686  if (!pic->buf[i])
687  goto fail;
688 
689  pic->data[i] = pic->buf[i]->data;
690  }
691  for (; i < AV_NUM_DATA_POINTERS; i++) {
692  pic->data[i] = NULL;
693  pic->linesize[i] = 0;
694  }
695  if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
697  avpriv_set_systematic_pal2((uint32_t *)pic->data[1], pic->format);
698 
699  if (s->debug & FF_DEBUG_BUFFERS)
700  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic);
701 
702  return 0;
703 fail:
704  av_frame_unref(pic);
705  return AVERROR(ENOMEM);
706 }
707 
708 void ff_color_frame(AVFrame *frame, const int c[4])
709 {
711  int p, y, x;
712 
714 
715  for (p = 0; p<desc->nb_components; p++) {
716  uint8_t *dst = frame->data[p];
717  int is_chroma = p == 1 || p == 2;
718  int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
719  int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
720  for (y = 0; y < height; y++) {
721  if (desc->comp[0].depth >= 9) {
722  for (x = 0; x<bytes; x++)
723  ((uint16_t*)dst)[x] = c[p];
724  }else
725  memset(dst, c[p], bytes);
726  dst += frame->linesize[p];
727  }
728  }
729 }
730 
732 {
733  int ret;
734 
735  if (avctx->hw_frames_ctx)
736  return av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
737 
738  if ((ret = update_frame_pool(avctx, frame)) < 0)
739  return ret;
740 
741  switch (avctx->codec_type) {
742  case AVMEDIA_TYPE_VIDEO:
743  return video_get_buffer(avctx, frame);
744  case AVMEDIA_TYPE_AUDIO:
745  return audio_get_buffer(avctx, frame);
746  default:
747  return -1;
748  }
749 }
750 
752 {
753  int size;
754  const uint8_t *side_metadata;
755 
756  AVDictionary **frame_md = avpriv_frame_get_metadatap(frame);
757 
758  side_metadata = av_packet_get_side_data(avpkt,
760  return av_packet_unpack_dictionary(side_metadata, size, frame_md);
761 }
762 
764 {
765  const AVPacket *pkt = avctx->internal->pkt;
766  int i;
767  static const struct {
768  enum AVPacketSideDataType packet;
770  } sd[] = {
777  };
778 
779  if (pkt) {
780  frame->pts = pkt->pts;
781 #if FF_API_PKT_PTS
783  frame->pkt_pts = pkt->pts;
785 #endif
786  av_frame_set_pkt_pos (frame, pkt->pos);
787  av_frame_set_pkt_duration(frame, pkt->duration);
788  av_frame_set_pkt_size (frame, pkt->size);
789 
790  for (i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
791  int size;
792  uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
793  if (packet_sd) {
794  AVFrameSideData *frame_sd = av_frame_new_side_data(frame,
795  sd[i].frame,
796  size);
797  if (!frame_sd)
798  return AVERROR(ENOMEM);
799 
800  memcpy(frame_sd->data, packet_sd, size);
801  }
802  }
803  add_metadata_from_side_data(pkt, frame);
804 
805  if (pkt->flags & AV_PKT_FLAG_DISCARD) {
806  frame->flags |= AV_FRAME_FLAG_DISCARD;
807  } else {
808  frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
809  }
810  } else {
811  frame->pts = AV_NOPTS_VALUE;
812 #if FF_API_PKT_PTS
814  frame->pkt_pts = AV_NOPTS_VALUE;
816 #endif
817  av_frame_set_pkt_pos (frame, -1);
818  av_frame_set_pkt_duration(frame, 0);
819  av_frame_set_pkt_size (frame, -1);
820  }
821  frame->reordered_opaque = avctx->reordered_opaque;
822 
824  frame->color_primaries = avctx->color_primaries;
825  if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
826  frame->color_trc = avctx->color_trc;
828  av_frame_set_colorspace(frame, avctx->colorspace);
830  av_frame_set_color_range(frame, avctx->color_range);
832  frame->chroma_location = avctx->chroma_sample_location;
833 
834  switch (avctx->codec->type) {
835  case AVMEDIA_TYPE_VIDEO:
836  frame->format = avctx->pix_fmt;
837  if (!frame->sample_aspect_ratio.num)
839 
840  if (frame->width && frame->height &&
841  av_image_check_sar(frame->width, frame->height,
842  frame->sample_aspect_ratio) < 0) {
843  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
844  frame->sample_aspect_ratio.num,
845  frame->sample_aspect_ratio.den);
846  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
847  }
848 
849  break;
850  case AVMEDIA_TYPE_AUDIO:
851  if (!frame->sample_rate)
852  frame->sample_rate = avctx->sample_rate;
853  if (frame->format < 0)
854  frame->format = avctx->sample_fmt;
855  if (!frame->channel_layout) {
856  if (avctx->channel_layout) {
858  avctx->channels) {
859  av_log(avctx, AV_LOG_ERROR, "Inconsistent channel "
860  "configuration.\n");
861  return AVERROR(EINVAL);
862  }
863 
864  frame->channel_layout = avctx->channel_layout;
865  } else {
866  if (avctx->channels > FF_SANE_NB_CHANNELS) {
867  av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n",
868  avctx->channels);
869  return AVERROR(ENOSYS);
870  }
871  }
872  }
873  av_frame_set_channels(frame, avctx->channels);
874  break;
875  }
876  return 0;
877 }
878 
880 {
881  return ff_init_buffer_info(avctx, frame);
882 }
883 
885 {
886  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
887  int i;
888  int num_planes = av_pix_fmt_count_planes(frame->format);
890  int flags = desc ? desc->flags : 0;
891  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
892  num_planes = 2;
893  for (i = 0; i < num_planes; i++) {
894  av_assert0(frame->data[i]);
895  }
896  // For now do not enforce anything for palette of pseudopal formats
897  if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PSEUDOPAL))
898  num_planes = 2;
899  // For formats without data like hwaccel allow unused pointers to be non-NULL.
900  for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
901  if (frame->data[i])
902  av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
903  frame->data[i] = NULL;
904  }
905  }
906 }
907 
909 {
910  const AVHWAccel *hwaccel = avctx->hwaccel;
911  int override_dimensions = 1;
912  int ret;
913 
914  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
915  if ((ret = av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
916  av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
917  return AVERROR(EINVAL);
918  }
919 
920  if (frame->width <= 0 || frame->height <= 0) {
921  frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
922  frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
923  override_dimensions = 0;
924  }
925 
926  if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
927  av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
928  return AVERROR(EINVAL);
929  }
930  }
931  ret = ff_decode_frame_props(avctx, frame);
932  if (ret < 0)
933  return ret;
934 
935  if (hwaccel) {
936  if (hwaccel->alloc_frame) {
937  ret = hwaccel->alloc_frame(avctx, frame);
938  goto end;
939  }
940  } else
941  avctx->sw_pix_fmt = avctx->pix_fmt;
942 
943  ret = avctx->get_buffer2(avctx, frame, flags);
944  if (ret >= 0)
945  validate_avframe_allocation(avctx, frame);
946 
947 end:
948  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) {
949  frame->width = avctx->width;
950  frame->height = avctx->height;
951  }
952 
953  return ret;
954 }
955 
957 {
958  int ret = get_buffer_internal(avctx, frame, flags);
959  if (ret < 0) {
960  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
961  frame->width = frame->height = 0;
962  }
963  return ret;
964 }
965 
967 {
968  AVFrame *tmp;
969  int ret;
970 
972 
973  if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
974  av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
975  frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
976  av_frame_unref(frame);
977  }
978 
979  ff_init_buffer_info(avctx, frame);
980 
981  if (!frame->data[0])
982  return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
983 
984  if (av_frame_is_writable(frame))
985  return ff_decode_frame_props(avctx, frame);
986 
987  tmp = av_frame_alloc();
988  if (!tmp)
989  return AVERROR(ENOMEM);
990 
991  av_frame_move_ref(tmp, frame);
992 
993  ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
994  if (ret < 0) {
995  av_frame_free(&tmp);
996  return ret;
997  }
998 
999  av_frame_copy(frame, tmp);
1000  av_frame_free(&tmp);
1001 
1002  return 0;
1003 }
1004 
1006 {
1007  int ret = reget_buffer_internal(avctx, frame);
1008  if (ret < 0)
1009  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1010  return ret;
1011 }
1012 
1013 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
1014 {
1015  int i;
1016 
1017  for (i = 0; i < count; i++) {
1018  int r = func(c, (char *)arg + i * size);
1019  if (ret)
1020  ret[i] = r;
1021  }
1022  emms_c();
1023  return 0;
1024 }
1025 
1026 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
1027 {
1028  int i;
1029 
1030  for (i = 0; i < count; i++) {
1031  int r = func(c, arg, i, 0);
1032  if (ret)
1033  ret[i] = r;
1034  }
1035  emms_c();
1036  return 0;
1037 }
1038 
1040  unsigned int fourcc)
1041 {
1042  while (tags->pix_fmt >= 0) {
1043  if (tags->fourcc == fourcc)
1044  return tags->pix_fmt;
1045  tags++;
1046  }
1047  return AV_PIX_FMT_NONE;
1048 }
1049 
1051 {
1052  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
1053  return desc->flags & AV_PIX_FMT_FLAG_HWACCEL;
1054 }
1055 
1057 {
1058  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
1059  ++fmt;
1060  return fmt[0];
1061 }
1062 
1064  enum AVPixelFormat pix_fmt)
1065 {
1066  AVHWAccel *hwaccel = NULL;
1067 
1068  while ((hwaccel = av_hwaccel_next(hwaccel)))
1069  if (hwaccel->id == codec_id
1070  && hwaccel->pix_fmt == pix_fmt)
1071  return hwaccel;
1072  return NULL;
1073 }
1074 
1075 static int setup_hwaccel(AVCodecContext *avctx,
1076  const enum AVPixelFormat fmt,
1077  const char *name)
1078 {
1079  AVHWAccel *hwa = find_hwaccel(avctx->codec_id, fmt);
1080  int ret = 0;
1081 
1082  if (!hwa) {
1083  av_log(avctx, AV_LOG_ERROR,
1084  "Could not find an AVHWAccel for the pixel format: %s",
1085  name);
1086  return AVERROR(ENOENT);
1087  }
1088 
1091  av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1092  hwa->name);
1093  return AVERROR_PATCHWELCOME;
1094  }
1095 
1096  if (hwa->priv_data_size) {
1098  if (!avctx->internal->hwaccel_priv_data)
1099  return AVERROR(ENOMEM);
1100  }
1101 
1102  if (hwa->init) {
1103  ret = hwa->init(avctx);
1104  if (ret < 0) {
1106  return ret;
1107  }
1108  }
1109 
1110  avctx->hwaccel = hwa;
1111 
1112  return 0;
1113 }
1114 
1116 {
1117  const AVPixFmtDescriptor *desc;
1118  enum AVPixelFormat *choices;
1119  enum AVPixelFormat ret;
1120  unsigned n = 0;
1121 
1122  while (fmt[n] != AV_PIX_FMT_NONE)
1123  ++n;
1124 
1125  av_assert0(n >= 1);
1126  avctx->sw_pix_fmt = fmt[n - 1];
1128 
1129  choices = av_malloc_array(n + 1, sizeof(*choices));
1130  if (!choices)
1131  return AV_PIX_FMT_NONE;
1132 
1133  memcpy(choices, fmt, (n + 1) * sizeof(*choices));
1134 
1135  for (;;) {
1136  if (avctx->hwaccel && avctx->hwaccel->uninit)
1137  avctx->hwaccel->uninit(avctx);
1139  avctx->hwaccel = NULL;
1140 
1141  av_buffer_unref(&avctx->hw_frames_ctx);
1142 
1143  ret = avctx->get_format(avctx, choices);
1144 
1145  desc = av_pix_fmt_desc_get(ret);
1146  if (!desc) {
1147  ret = AV_PIX_FMT_NONE;
1148  break;
1149  }
1150 
1151  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1152  break;
1153 #if FF_API_CAP_VDPAU
1155  break;
1156 #endif
1157 
1158  if (avctx->hw_frames_ctx) {
1159  AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1160  if (hw_frames_ctx->format != ret) {
1161  av_log(avctx, AV_LOG_ERROR, "Format returned from get_buffer() "
1162  "does not match the format of provided AVHWFramesContext\n");
1163  ret = AV_PIX_FMT_NONE;
1164  break;
1165  }
1166  }
1167 
1168  if (!setup_hwaccel(avctx, ret, desc->name))
1169  break;
1170 
1171  /* Remove failed hwaccel from choices */
1172  for (n = 0; choices[n] != ret; n++)
1173  av_assert0(choices[n] != AV_PIX_FMT_NONE);
1174 
1175  do
1176  choices[n] = choices[n + 1];
1177  while (choices[n++] != AV_PIX_FMT_NONE);
1178  }
1179 
1180  av_freep(&choices);
1181  return ret;
1182 }
1183 
1184 MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase)
1185 MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, codec_descriptor)
1186 MAKE_ACCESSORS(AVCodecContext, codec, int, lowres)
1187 MAKE_ACCESSORS(AVCodecContext, codec, int, seek_preroll)
1188 MAKE_ACCESSORS(AVCodecContext, codec, uint16_t*, chroma_intra_matrix)
1189 
1191 {
1192  return codec->properties;
1193 }
1194 
1196 {
1197  return codec->max_lowres;
1198 }
1199 
1202 }
1203 
1205 {
1206  memset(sub, 0, sizeof(*sub));
1207  sub->pts = AV_NOPTS_VALUE;
1208 }
1209 
1211 {
1212  int64_t bit_rate;
1213  int bits_per_sample;
1214 
1215  switch (ctx->codec_type) {
1216  case AVMEDIA_TYPE_VIDEO:
1217  case AVMEDIA_TYPE_DATA:
1218  case AVMEDIA_TYPE_SUBTITLE:
1220  bit_rate = ctx->bit_rate;
1221  break;
1222  case AVMEDIA_TYPE_AUDIO:
1223  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1224  bit_rate = bits_per_sample ? ctx->sample_rate * (int64_t)ctx->channels * bits_per_sample : ctx->bit_rate;
1225  break;
1226  default:
1227  bit_rate = 0;
1228  break;
1229  }
1230  return bit_rate;
1231 }
1232 
1234 {
1235  int ret = 0;
1236 
1237  ff_unlock_avcodec(codec);
1238 
1239  ret = avcodec_open2(avctx, codec, options);
1240 
1241  ff_lock_avcodec(avctx, codec);
1242  return ret;
1243 }
1244 
1246 {
1247  int ret = 0;
1248  AVDictionary *tmp = NULL;
1249  const AVPixFmtDescriptor *pixdesc;
1250 
1251  if (avcodec_is_open(avctx))
1252  return 0;
1253 
1254  if ((!codec && !avctx->codec)) {
1255  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2()\n");
1256  return AVERROR(EINVAL);
1257  }
1258  if ((codec && avctx->codec && codec != avctx->codec)) {
1259  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
1260  "but %s passed to avcodec_open2()\n", avctx->codec->name, codec->name);
1261  return AVERROR(EINVAL);
1262  }
1263  if (!codec)
1264  codec = avctx->codec;
1265 
1266  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
1267  return AVERROR(EINVAL);
1268 
1269  if (options)
1270  av_dict_copy(&tmp, *options, 0);
1271 
1272  ret = ff_lock_avcodec(avctx, codec);
1273  if (ret < 0)
1274  return ret;
1275 
1276  avctx->internal = av_mallocz(sizeof(*avctx->internal));
1277  if (!avctx->internal) {
1278  ret = AVERROR(ENOMEM);
1279  goto end;
1280  }
1281 
1282  avctx->internal->pool = av_mallocz(sizeof(*avctx->internal->pool));
1283  if (!avctx->internal->pool) {
1284  ret = AVERROR(ENOMEM);
1285  goto free_and_end;
1286  }
1287 
1288  avctx->internal->to_free = av_frame_alloc();
1289  if (!avctx->internal->to_free) {
1290  ret = AVERROR(ENOMEM);
1291  goto free_and_end;
1292  }
1293 
1294  avctx->internal->buffer_frame = av_frame_alloc();
1295  if (!avctx->internal->buffer_frame) {
1296  ret = AVERROR(ENOMEM);
1297  goto free_and_end;
1298  }
1299 
1300  avctx->internal->buffer_pkt = av_packet_alloc();
1301  if (!avctx->internal->buffer_pkt) {
1302  ret = AVERROR(ENOMEM);
1303  goto free_and_end;
1304  }
1305 
1306  avctx->internal->skip_samples_multiplier = 1;
1307 
1308  if (codec->priv_data_size > 0) {
1309  if (!avctx->priv_data) {
1310  avctx->priv_data = av_mallocz(codec->priv_data_size);
1311  if (!avctx->priv_data) {
1312  ret = AVERROR(ENOMEM);
1313  goto end;
1314  }
1315  if (codec->priv_class) {
1316  *(const AVClass **)avctx->priv_data = codec->priv_class;
1318  }
1319  }
1320  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
1321  goto free_and_end;
1322  } else {
1323  avctx->priv_data = NULL;
1324  }
1325  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
1326  goto free_and_end;
1327 
1328  if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
1329  av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
1330  ret = AVERROR(EINVAL);
1331  goto free_and_end;
1332  }
1333 
1334  // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
1335  if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
1336  (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
1337  if (avctx->coded_width && avctx->coded_height)
1338  ret = ff_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
1339  else if (avctx->width && avctx->height)
1340  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
1341  if (ret < 0)
1342  goto free_and_end;
1343  }
1344 
1345  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
1346  && ( av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0
1347  || av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)) {
1348  av_log(avctx, AV_LOG_WARNING, "Ignoring invalid width/height values\n");
1349  ff_set_dimensions(avctx, 0, 0);
1350  }
1351 
1352  if (avctx->width > 0 && avctx->height > 0) {
1353  if (av_image_check_sar(avctx->width, avctx->height,
1354  avctx->sample_aspect_ratio) < 0) {
1355  av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1356  avctx->sample_aspect_ratio.num,
1357  avctx->sample_aspect_ratio.den);
1358  avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
1359  }
1360  }
1361 
1362  /* if the decoder init function was already called previously,
1363  * free the already allocated subtitle_header before overwriting it */
1364  if (av_codec_is_decoder(codec))
1365  av_freep(&avctx->subtitle_header);
1366 
1367  if (avctx->channels > FF_SANE_NB_CHANNELS) {
1368  ret = AVERROR(EINVAL);
1369  goto free_and_end;
1370  }
1371 
1372  avctx->codec = codec;
1373  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
1374  avctx->codec_id == AV_CODEC_ID_NONE) {
1375  avctx->codec_type = codec->type;
1376  avctx->codec_id = codec->id;
1377  }
1378  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
1379  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
1380  av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
1381  ret = AVERROR(EINVAL);
1382  goto free_and_end;
1383  }
1384  avctx->frame_number = 0;
1386 
1387  if ((avctx->codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
1389  const char *codec_string = av_codec_is_encoder(codec) ? "encoder" : "decoder";
1390  AVCodec *codec2;
1391  av_log(avctx, AV_LOG_ERROR,
1392  "The %s '%s' is experimental but experimental codecs are not enabled, "
1393  "add '-strict %d' if you want to use it.\n",
1394  codec_string, codec->name, FF_COMPLIANCE_EXPERIMENTAL);
1395  codec2 = av_codec_is_encoder(codec) ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id);
1396  if (!(codec2->capabilities & AV_CODEC_CAP_EXPERIMENTAL))
1397  av_log(avctx, AV_LOG_ERROR, "Alternatively use the non experimental %s '%s'.\n",
1398  codec_string, codec2->name);
1399  ret = AVERROR_EXPERIMENTAL;
1400  goto free_and_end;
1401  }
1402 
1403  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
1404  (!avctx->time_base.num || !avctx->time_base.den)) {
1405  avctx->time_base.num = 1;
1406  avctx->time_base.den = avctx->sample_rate;
1407  }
1408 
1409  if (!HAVE_THREADS)
1410  av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
1411 
1413  ff_unlock_avcodec(codec); //we will instantiate a few encoders thus kick the counter to prevent false detection of a problem
1414  ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
1415  ff_lock_avcodec(avctx, codec);
1416  if (ret < 0)
1417  goto free_and_end;
1418  }
1419 
1420  if (HAVE_THREADS
1422  ret = ff_thread_init(avctx);
1423  if (ret < 0) {
1424  goto free_and_end;
1425  }
1426  }
1428  avctx->thread_count = 1;
1429 
1430  if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1431  av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1432  avctx->codec->max_lowres);
1433  avctx->lowres = avctx->codec->max_lowres;
1434  }
1435 
1436 #if FF_API_VISMV
1437  if (avctx->debug_mv)
1438  av_log(avctx, AV_LOG_WARNING, "The 'vismv' option is deprecated, "
1439  "see the codecview filter instead.\n");
1440 #endif
1441 
1442  if (av_codec_is_encoder(avctx->codec)) {
1443  int i;
1444 #if FF_API_CODED_FRAME
1446  avctx->coded_frame = av_frame_alloc();
1447  if (!avctx->coded_frame) {
1448  ret = AVERROR(ENOMEM);
1449  goto free_and_end;
1450  }
1452 #endif
1453 
1454  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
1455  av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
1456  ret = AVERROR(EINVAL);
1457  goto free_and_end;
1458  }
1459 
1460  if (avctx->codec->sample_fmts) {
1461  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
1462  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
1463  break;
1464  if (avctx->channels == 1 &&
1467  avctx->sample_fmt = avctx->codec->sample_fmts[i];
1468  break;
1469  }
1470  }
1471  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
1472  char buf[128];
1473  snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
1474  av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
1475  (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
1476  ret = AVERROR(EINVAL);
1477  goto free_and_end;
1478  }
1479  }
1480  if (avctx->codec->pix_fmts) {
1481  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
1482  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
1483  break;
1484  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE
1485  && !((avctx->codec_id == AV_CODEC_ID_MJPEG || avctx->codec_id == AV_CODEC_ID_LJPEG)
1487  char buf[128];
1488  snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
1489  av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
1490  (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
1491  ret = AVERROR(EINVAL);
1492  goto free_and_end;
1493  }
1494  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
1495  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
1496  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
1497  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
1498  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
1499  avctx->color_range = AVCOL_RANGE_JPEG;
1500  }
1501  if (avctx->codec->supported_samplerates) {
1502  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
1503  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
1504  break;
1505  if (avctx->codec->supported_samplerates[i] == 0) {
1506  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
1507  avctx->sample_rate);
1508  ret = AVERROR(EINVAL);
1509  goto free_and_end;
1510  }
1511  }
1512  if (avctx->sample_rate < 0) {
1513  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
1514  avctx->sample_rate);
1515  ret = AVERROR(EINVAL);
1516  goto free_and_end;
1517  }
1518  if (avctx->codec->channel_layouts) {
1519  if (!avctx->channel_layout) {
1520  av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
1521  } else {
1522  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
1523  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
1524  break;
1525  if (avctx->codec->channel_layouts[i] == 0) {
1526  char buf[512];
1527  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1528  av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
1529  ret = AVERROR(EINVAL);
1530  goto free_and_end;
1531  }
1532  }
1533  }
1534  if (avctx->channel_layout && avctx->channels) {
1535  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1536  if (channels != avctx->channels) {
1537  char buf[512];
1538  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1539  av_log(avctx, AV_LOG_ERROR,
1540  "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1541  buf, channels, avctx->channels);
1542  ret = AVERROR(EINVAL);
1543  goto free_and_end;
1544  }
1545  } else if (avctx->channel_layout) {
1547  }
1548  if (avctx->channels < 0) {
1549  av_log(avctx, AV_LOG_ERROR, "Specified number of channels %d is not supported\n",
1550  avctx->channels);
1551  ret = AVERROR(EINVAL);
1552  goto free_and_end;
1553  }
1554  if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1555  pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
1556  if ( avctx->bits_per_raw_sample < 0
1557  || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) {
1558  av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n",
1559  avctx->bits_per_raw_sample, pixdesc->comp[0].depth);
1560  avctx->bits_per_raw_sample = pixdesc->comp[0].depth;
1561  }
1562  if (avctx->width <= 0 || avctx->height <= 0) {
1563  av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
1564  ret = AVERROR(EINVAL);
1565  goto free_and_end;
1566  }
1567  }
1568  if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
1569  && avctx->bit_rate>0 && avctx->bit_rate<1000) {
1570  av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", (int64_t)avctx->bit_rate, (int64_t)avctx->bit_rate);
1571  }
1572 
1573  if (!avctx->rc_initial_buffer_occupancy)
1574  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4;
1575 
1576  if (avctx->ticks_per_frame && avctx->time_base.num &&
1577  avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
1578  av_log(avctx, AV_LOG_ERROR,
1579  "ticks_per_frame %d too large for the timebase %d/%d.",
1580  avctx->ticks_per_frame,
1581  avctx->time_base.num,
1582  avctx->time_base.den);
1583  goto free_and_end;
1584  }
1585 
1586  if (avctx->hw_frames_ctx) {
1587  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1588  if (frames_ctx->format != avctx->pix_fmt) {
1589  av_log(avctx, AV_LOG_ERROR,
1590  "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
1591  ret = AVERROR(EINVAL);
1592  goto free_and_end;
1593  }
1594  if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
1595  avctx->sw_pix_fmt != frames_ctx->sw_format) {
1596  av_log(avctx, AV_LOG_ERROR,
1597  "Mismatching AVCodecContext.sw_pix_fmt (%s) "
1598  "and AVHWFramesContext.sw_format (%s)\n",
1600  av_get_pix_fmt_name(frames_ctx->sw_format));
1601  ret = AVERROR(EINVAL);
1602  goto free_and_end;
1603  }
1604  avctx->sw_pix_fmt = frames_ctx->sw_format;
1605  }
1606  }
1607 
1609  avctx->pts_correction_num_faulty_dts = 0;
1610  avctx->pts_correction_last_pts =
1611  avctx->pts_correction_last_dts = INT64_MIN;
1612 
1613  if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1615  av_log(avctx, AV_LOG_WARNING,
1616  "gray decoding requested but not enabled at configuration time\n");
1617 
1618  if ( avctx->codec->init && (!(avctx->active_thread_type&FF_THREAD_FRAME)
1619  || avctx->internal->frame_thread_encoder)) {
1620  ret = avctx->codec->init(avctx);
1621  if (ret < 0) {
1622  goto free_and_end;
1623  }
1624  }
1625 
1626  ret=0;
1627 
1628 #if FF_API_AUDIOENC_DELAY
1629  if (av_codec_is_encoder(avctx->codec))
1630  avctx->delay = avctx->initial_padding;
1631 #endif
1632 
1633  if (av_codec_is_decoder(avctx->codec)) {
1634  if (!avctx->bit_rate)
1635  avctx->bit_rate = get_bit_rate(avctx);
1636  /* validate channel layout from the decoder */
1637  if (avctx->channel_layout) {
1638  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
1639  if (!avctx->channels)
1640  avctx->channels = channels;
1641  else if (channels != avctx->channels) {
1642  char buf[512];
1643  av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
1644  av_log(avctx, AV_LOG_WARNING,
1645  "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1646  "ignoring specified channel layout\n",
1647  buf, channels, avctx->channels);
1648  avctx->channel_layout = 0;
1649  }
1650  }
1651  if (avctx->channels && avctx->channels < 0 ||
1652  avctx->channels > FF_SANE_NB_CHANNELS) {
1653  ret = AVERROR(EINVAL);
1654  goto free_and_end;
1655  }
1656  if (avctx->sub_charenc) {
1657  if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1658  av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1659  "supported with subtitles codecs\n");
1660  ret = AVERROR(EINVAL);
1661  goto free_and_end;
1662  } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1663  av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1664  "subtitles character encoding will be ignored\n",
1665  avctx->codec_descriptor->name);
1667  } else {
1668  /* input character encoding is set for a text based subtitle
1669  * codec at this point */
1672 
1674 #if CONFIG_ICONV
1675  iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1676  if (cd == (iconv_t)-1) {
1677  ret = AVERROR(errno);
1678  av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1679  "with input character encoding \"%s\"\n", avctx->sub_charenc);
1680  goto free_and_end;
1681  }
1682  iconv_close(cd);
1683 #else
1684  av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1685  "conversion needs a libavcodec built with iconv support "
1686  "for this codec\n");
1687  ret = AVERROR(ENOSYS);
1688  goto free_and_end;
1689 #endif
1690  }
1691  }
1692  }
1693 
1694 #if FF_API_AVCTX_TIMEBASE
1695  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
1696  avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
1697 #endif
1698  }
1699  if (codec->priv_data_size > 0 && avctx->priv_data && codec->priv_class) {
1700  av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
1701  }
1702 
1703 end:
1704  ff_unlock_avcodec(codec);
1705  if (options) {
1706  av_dict_free(options);
1707  *options = tmp;
1708  }
1709 
1710  return ret;
1711 free_and_end:
1712  if (avctx->codec &&
1714  avctx->codec->close(avctx);
1715 
1716  if (codec->priv_class && codec->priv_data_size)
1717  av_opt_free(avctx->priv_data);
1718  av_opt_free(avctx);
1719 
1720 #if FF_API_CODED_FRAME
1722  av_frame_free(&avctx->coded_frame);
1724 #endif
1725 
1726  av_dict_free(&tmp);
1727  av_freep(&avctx->priv_data);
1728  if (avctx->internal) {
1729  av_frame_free(&avctx->internal->to_free);
1732  av_freep(&avctx->internal->pool);
1733  }
1734  av_freep(&avctx->internal);
1735  avctx->codec = NULL;
1736  goto end;
1737 }
1738 
1739 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
1740 {
1741  if (avpkt->size < 0) {
1742  av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
1743  return AVERROR(EINVAL);
1744  }
1745  if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
1746  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
1747  size, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
1748  return AVERROR(EINVAL);
1749  }
1750 
1751  if (avctx && 2*min_size < size) { // FIXME The factor needs to be finetuned
1752  av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);
1753  if (!avpkt->data || avpkt->size < size) {
1755  avpkt->data = avctx->internal->byte_buffer;
1756  avpkt->size = avctx->internal->byte_buffer_size;
1757  }
1758  }
1759 
1760  if (avpkt->data) {
1761  AVBufferRef *buf = avpkt->buf;
1762 
1763  if (avpkt->size < size) {
1764  av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %"PRId64")\n", avpkt->size, size);
1765  return AVERROR(EINVAL);
1766  }
1767 
1768  av_init_packet(avpkt);
1769  avpkt->buf = buf;
1770  avpkt->size = size;
1771  return 0;
1772  } else {
1773  int ret = av_new_packet(avpkt, size);
1774  if (ret < 0)
1775  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
1776  return ret;
1777  }
1778 }
1779 
1781 {
1782  return ff_alloc_packet2(NULL, avpkt, size, 0);
1783 }
1784 
1785 /**
1786  * Pad last frame with silence.
1787  */
1788 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
1789 {
1790  AVFrame *frame = NULL;
1791  int ret;
1792 
1793  if (!(frame = av_frame_alloc()))
1794  return AVERROR(ENOMEM);
1795 
1796  frame->format = src->format;
1797  frame->channel_layout = src->channel_layout;
1799  frame->nb_samples = s->frame_size;
1800  ret = av_frame_get_buffer(frame, 32);
1801  if (ret < 0)
1802  goto fail;
1803 
1804  ret = av_frame_copy_props(frame, src);
1805  if (ret < 0)
1806  goto fail;
1807 
1808  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
1809  src->nb_samples, s->channels, s->sample_fmt)) < 0)
1810  goto fail;
1811  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
1812  frame->nb_samples - src->nb_samples,
1813  s->channels, s->sample_fmt)) < 0)
1814  goto fail;
1815 
1816  *dst = frame;
1817 
1818  return 0;
1819 
1820 fail:
1821  av_frame_free(&frame);
1822  return ret;
1823 }
1824 
1826  AVPacket *avpkt,
1827  const AVFrame *frame,
1828  int *got_packet_ptr)
1829 {
1830  AVFrame *extended_frame = NULL;
1831  AVFrame *padded_frame = NULL;
1832  int ret;
1833  AVPacket user_pkt = *avpkt;
1834  int needs_realloc = !user_pkt.data;
1835 
1836  *got_packet_ptr = 0;
1837 
1838  if (!avctx->codec->encode2) {
1839  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
1840  return AVERROR(ENOSYS);
1841  }
1842 
1843  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
1844  av_packet_unref(avpkt);
1845  av_init_packet(avpkt);
1846  return 0;
1847  }
1848 
1849  /* ensure that extended_data is properly set */
1850  if (frame && !frame->extended_data) {
1851  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
1852  avctx->channels > AV_NUM_DATA_POINTERS) {
1853  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
1854  "with more than %d channels, but extended_data is not set.\n",
1856  return AVERROR(EINVAL);
1857  }
1858  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
1859 
1860  extended_frame = av_frame_alloc();
1861  if (!extended_frame)
1862  return AVERROR(ENOMEM);
1863 
1864  memcpy(extended_frame, frame, sizeof(AVFrame));
1865  extended_frame->extended_data = extended_frame->data;
1866  frame = extended_frame;
1867  }
1868 
1869  /* extract audio service type metadata */
1870  if (frame) {
1872  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
1873  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
1874  }
1875 
1876  /* check for valid frame size */
1877  if (frame) {
1879  if (frame->nb_samples > avctx->frame_size) {
1880  av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
1881  ret = AVERROR(EINVAL);
1882  goto end;
1883  }
1884  } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
1885  if (frame->nb_samples < avctx->frame_size &&
1886  !avctx->internal->last_audio_frame) {
1887  ret = pad_last_frame(avctx, &padded_frame, frame);
1888  if (ret < 0)
1889  goto end;
1890 
1891  frame = padded_frame;
1892  avctx->internal->last_audio_frame = 1;
1893  }
1894 
1895  if (frame->nb_samples != avctx->frame_size) {
1896  av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size);
1897  ret = AVERROR(EINVAL);
1898  goto end;
1899  }
1900  }
1901  }
1902 
1903  av_assert0(avctx->codec->encode2);
1904 
1905  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1906  if (!ret) {
1907  if (*got_packet_ptr) {
1908  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
1909  if (avpkt->pts == AV_NOPTS_VALUE)
1910  avpkt->pts = frame->pts;
1911  if (!avpkt->duration)
1912  avpkt->duration = ff_samples_to_time_base(avctx,
1913  frame->nb_samples);
1914  }
1915  avpkt->dts = avpkt->pts;
1916  } else {
1917  avpkt->size = 0;
1918  }
1919  }
1920  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
1921  needs_realloc = 0;
1922  if (user_pkt.data) {
1923  if (user_pkt.size >= avpkt->size) {
1924  memcpy(user_pkt.data, avpkt->data, avpkt->size);
1925  } else {
1926  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
1927  avpkt->size = user_pkt.size;
1928  ret = -1;
1929  }
1930  avpkt->buf = user_pkt.buf;
1931  avpkt->data = user_pkt.data;
1932  } else {
1933  if (av_dup_packet(avpkt) < 0) {
1934  ret = AVERROR(ENOMEM);
1935  }
1936  }
1937  }
1938 
1939  if (!ret) {
1940  if (needs_realloc && avpkt->data) {
1941  ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
1942  if (ret >= 0)
1943  avpkt->data = avpkt->buf->data;
1944  }
1945 
1946  avctx->frame_number++;
1947  }
1948 
1949  if (ret < 0 || !*got_packet_ptr) {
1950  av_packet_unref(avpkt);
1951  av_init_packet(avpkt);
1952  goto end;
1953  }
1954 
1955  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1956  * this needs to be moved to the encoders, but for now we can do it
1957  * here to simplify things */
1958  avpkt->flags |= AV_PKT_FLAG_KEY;
1959 
1960 end:
1961  av_frame_free(&padded_frame);
1962  av_free(extended_frame);
1963 
1964 #if FF_API_AUDIOENC_DELAY
1965  avctx->delay = avctx->initial_padding;
1966 #endif
1967 
1968  return ret;
1969 }
1970 
1972  AVPacket *avpkt,
1973  const AVFrame *frame,
1974  int *got_packet_ptr)
1975 {
1976  int ret;
1977  AVPacket user_pkt = *avpkt;
1978  int needs_realloc = !user_pkt.data;
1979 
1980  *got_packet_ptr = 0;
1981 
1982  if (!avctx->codec->encode2) {
1983  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
1984  return AVERROR(ENOSYS);
1985  }
1986 
1989  return ff_thread_video_encode_frame(avctx, avpkt, frame, got_packet_ptr);
1990 
1991  if ((avctx->flags&AV_CODEC_FLAG_PASS1) && avctx->stats_out)
1992  avctx->stats_out[0] = '\0';
1993 
1994  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
1995  av_packet_unref(avpkt);
1996  av_init_packet(avpkt);
1997  avpkt->size = 0;
1998  return 0;
1999  }
2000 
2001  if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
2002  return AVERROR(EINVAL);
2003 
2004  if (frame && frame->format == AV_PIX_FMT_NONE)
2005  av_log(avctx, AV_LOG_WARNING, "AVFrame.format is not set\n");
2006  if (frame && (frame->width == 0 || frame->height == 0))
2007  av_log(avctx, AV_LOG_WARNING, "AVFrame.width or height is not set\n");
2008 
2009  av_assert0(avctx->codec->encode2);
2010 
2011  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
2012  av_assert0(ret <= 0);
2013 
2014  emms_c();
2015 
2016  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
2017  needs_realloc = 0;
2018  if (user_pkt.data) {
2019  if (user_pkt.size >= avpkt->size) {
2020  memcpy(user_pkt.data, avpkt->data, avpkt->size);
2021  } else {
2022  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
2023  avpkt->size = user_pkt.size;
2024  ret = -1;
2025  }
2026  avpkt->buf = user_pkt.buf;
2027  avpkt->data = user_pkt.data;
2028  } else {
2029  if (av_dup_packet(avpkt) < 0) {
2030  ret = AVERROR(ENOMEM);
2031  }
2032  }
2033  }
2034 
2035  if (!ret) {
2036  if (!*got_packet_ptr)
2037  avpkt->size = 0;
2038  else if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
2039  avpkt->pts = avpkt->dts = frame->pts;
2040 
2041  if (needs_realloc && avpkt->data) {
2042  ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
2043  if (ret >= 0)
2044  avpkt->data = avpkt->buf->data;
2045  }
2046 
2047  avctx->frame_number++;
2048  }
2049 
2050  if (ret < 0 || !*got_packet_ptr)
2051  av_packet_unref(avpkt);
2052 
2053  return ret;
2054 }
2055 
2057  const AVSubtitle *sub)
2058 {
2059  int ret;
2060  if (sub->start_display_time) {
2061  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
2062  return -1;
2063  }
2064 
2065  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
2066  avctx->frame_number++;
2067  return ret;
2068 }
2069 
2070 /**
2071  * Attempt to guess proper monotonic timestamps for decoded video frames
2072  * which might have incorrect times. Input timestamps may wrap around, in
2073  * which case the output will as well.
2074  *
2075  * @param pts the pts field of the decoded AVPacket, as passed through
2076  * AVFrame.pts
2077  * @param dts the dts field of the decoded AVPacket
2078  * @return one of the input values, may be AV_NOPTS_VALUE
2079  */
2081  int64_t reordered_pts, int64_t dts)
2082 {
2083  int64_t pts = AV_NOPTS_VALUE;
2084 
2085  if (dts != AV_NOPTS_VALUE) {
2087  ctx->pts_correction_last_dts = dts;
2088  } else if (reordered_pts != AV_NOPTS_VALUE)
2089  ctx->pts_correction_last_dts = reordered_pts;
2090 
2091  if (reordered_pts != AV_NOPTS_VALUE) {
2092  ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts;
2093  ctx->pts_correction_last_pts = reordered_pts;
2094  } else if(dts != AV_NOPTS_VALUE)
2095  ctx->pts_correction_last_pts = dts;
2096 
2098  && reordered_pts != AV_NOPTS_VALUE)
2099  pts = reordered_pts;
2100  else
2101  pts = dts;
2102 
2103  return pts;
2104 }
2105 
2106 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
2107 {
2108  int size = 0, ret;
2109  const uint8_t *data;
2110  uint32_t flags;
2111  int64_t val;
2112 
2113  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
2114  if (!data)
2115  return 0;
2116 
2117  if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
2118  av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
2119  "changes, but PARAM_CHANGE side data was sent to it.\n");
2120  ret = AVERROR(EINVAL);
2121  goto fail2;
2122  }
2123 
2124  if (size < 4)
2125  goto fail;
2126 
2127  flags = bytestream_get_le32(&data);
2128  size -= 4;
2129 
2131  if (size < 4)
2132  goto fail;
2133  val = bytestream_get_le32(&data);
2134  if (val <= 0 || val > INT_MAX) {
2135  av_log(avctx, AV_LOG_ERROR, "Invalid channel count");
2136  ret = AVERROR_INVALIDDATA;
2137  goto fail2;
2138  }
2139  avctx->channels = val;
2140  size -= 4;
2141  }
2143  if (size < 8)
2144  goto fail;
2145  avctx->channel_layout = bytestream_get_le64(&data);
2146  size -= 8;
2147  }
2149  if (size < 4)
2150  goto fail;
2151  val = bytestream_get_le32(&data);
2152  if (val <= 0 || val > INT_MAX) {
2153  av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
2154  ret = AVERROR_INVALIDDATA;
2155  goto fail2;
2156  }
2157  avctx->sample_rate = val;
2158  size -= 4;
2159  }
2161  if (size < 8)
2162  goto fail;
2163  avctx->width = bytestream_get_le32(&data);
2164  avctx->height = bytestream_get_le32(&data);
2165  size -= 8;
2166  ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
2167  if (ret < 0)
2168  goto fail2;
2169  }
2170 
2171  return 0;
2172 fail:
2173  av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
2174  ret = AVERROR_INVALIDDATA;
2175 fail2:
2176  if (ret < 0) {
2177  av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
2178  if (avctx->err_recognition & AV_EF_EXPLODE)
2179  return ret;
2180  }
2181  return 0;
2182 }
2183 
2185 {
2186  int ret;
2187 
2188  /* move the original frame to our backup */
2189  av_frame_unref(avci->to_free);
2190  av_frame_move_ref(avci->to_free, frame);
2191 
2192  /* now copy everything except the AVBufferRefs back
2193  * note that we make a COPY of the side data, so calling av_frame_free() on
2194  * the caller's frame will work properly */
2195  ret = av_frame_copy_props(frame, avci->to_free);
2196  if (ret < 0)
2197  return ret;
2198 
2199  memcpy(frame->data, avci->to_free->data, sizeof(frame->data));
2200  memcpy(frame->linesize, avci->to_free->linesize, sizeof(frame->linesize));
2201  if (avci->to_free->extended_data != avci->to_free->data) {
2202  int planes = av_frame_get_channels(avci->to_free);
2203  int size = planes * sizeof(*frame->extended_data);
2204 
2205  if (!size) {
2206  av_frame_unref(frame);
2207  return AVERROR_BUG;
2208  }
2209 
2210  frame->extended_data = av_malloc(size);
2211  if (!frame->extended_data) {
2212  av_frame_unref(frame);
2213  return AVERROR(ENOMEM);
2214  }
2215  memcpy(frame->extended_data, avci->to_free->extended_data,
2216  size);
2217  } else
2218  frame->extended_data = frame->data;
2219 
2220  frame->format = avci->to_free->format;
2221  frame->width = avci->to_free->width;
2222  frame->height = avci->to_free->height;
2223  frame->channel_layout = avci->to_free->channel_layout;
2224  frame->nb_samples = avci->to_free->nb_samples;
2226 
2227  return 0;
2228 }
2229 
2231  int *got_picture_ptr,
2232  const AVPacket *avpkt)
2233 {
2234  AVCodecInternal *avci = avctx->internal;
2235  int ret;
2236  // copy to ensure we do not change avpkt
2237  AVPacket tmp = *avpkt;
2238 
2239  if (!avctx->codec)
2240  return AVERROR(EINVAL);
2241  if (avctx->codec->type != AVMEDIA_TYPE_VIDEO) {
2242  av_log(avctx, AV_LOG_ERROR, "Invalid media type for video\n");
2243  return AVERROR(EINVAL);
2244  }
2245 
2246  if (!avctx->codec->decode) {
2247  av_log(avctx, AV_LOG_ERROR, "This decoder requires using the avcodec_send_packet() API.\n");
2248  return AVERROR(ENOSYS);
2249  }
2250 
2251  *got_picture_ptr = 0;
2252  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
2253  return AVERROR(EINVAL);
2254 
2255  avctx->internal->pkt = avpkt;
2256  ret = apply_param_change(avctx, avpkt);
2257  if (ret < 0)
2258  return ret;
2259 
2260  av_frame_unref(picture);
2261 
2262  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size ||
2263  (avctx->active_thread_type & FF_THREAD_FRAME)) {
2264 #if FF_API_MERGE_SD
2266  int did_split = av_packet_split_side_data(&tmp);
2268 #endif
2269  ret = apply_param_change(avctx, &tmp);
2270  if (ret < 0)
2271  goto fail;
2272 
2273  avctx->internal->pkt = &tmp;
2275  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
2276  &tmp);
2277  else {
2278  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
2279  &tmp);
2281  picture->pkt_dts = avpkt->dts;
2282 
2283  if(!avctx->has_b_frames){
2284  av_frame_set_pkt_pos(picture, avpkt->pos);
2285  }
2286  //FIXME these should be under if(!avctx->has_b_frames)
2287  /* get_buffer is supposed to set frame parameters */
2288  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
2289  if (!picture->sample_aspect_ratio.num) picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
2290  if (!picture->width) picture->width = avctx->width;
2291  if (!picture->height) picture->height = avctx->height;
2292  if (picture->format == AV_PIX_FMT_NONE) picture->format = avctx->pix_fmt;
2293  }
2294  }
2295 
2296 fail:
2297  emms_c(); //needed to avoid an emms_c() call before every return;
2298 
2299  avctx->internal->pkt = NULL;
2300 #if FF_API_MERGE_SD
2301  if (did_split) {
2303  if(ret == tmp.size)
2304  ret = avpkt->size;
2305  }
2306 #endif
2307  if (picture->flags & AV_FRAME_FLAG_DISCARD) {
2308  *got_picture_ptr = 0;
2309  }
2310  if (*got_picture_ptr) {
2311  if (!avctx->refcounted_frames) {
2312  int err = unrefcount_frame(avci, picture);
2313  if (err < 0)
2314  return err;
2315  }
2316 
2317  avctx->frame_number++;
2319  guess_correct_pts(avctx,
2320  picture->pts,
2321  picture->pkt_dts));
2322  } else
2323  av_frame_unref(picture);
2324  } else
2325  ret = 0;
2326 
2327  /* many decoders assign whole AVFrames, thus overwriting extended_data;
2328  * make sure it's set correctly */
2329  av_assert0(!picture->extended_data || picture->extended_data == picture->data);
2330 
2331 #if FF_API_AVCTX_TIMEBASE
2332  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
2333  avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
2334 #endif
2335 
2336  return ret;
2337 }
2338 
2340  AVFrame *frame,
2341  int *got_frame_ptr,
2342  const AVPacket *avpkt)
2343 {
2344  AVCodecInternal *avci = avctx->internal;
2345  int ret = 0;
2346 
2347  *got_frame_ptr = 0;
2348 
2349  if (!avctx->codec)
2350  return AVERROR(EINVAL);
2351 
2352  if (!avctx->codec->decode) {
2353  av_log(avctx, AV_LOG_ERROR, "This decoder requires using the avcodec_send_packet() API.\n");
2354  return AVERROR(ENOSYS);
2355  }
2356 
2357  if (!avpkt->data && avpkt->size) {
2358  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
2359  return AVERROR(EINVAL);
2360  }
2361  if (avctx->codec->type != AVMEDIA_TYPE_AUDIO) {
2362  av_log(avctx, AV_LOG_ERROR, "Invalid media type for audio\n");
2363  return AVERROR(EINVAL);
2364  }
2365 
2366  av_frame_unref(frame);
2367 
2368  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
2369  uint8_t *side;
2370  int side_size;
2371  uint32_t discard_padding = 0;
2372  uint8_t skip_reason = 0;
2373  uint8_t discard_reason = 0;
2374  // copy to ensure we do not change avpkt
2375  AVPacket tmp = *avpkt;
2376 #if FF_API_MERGE_SD
2378  int did_split = av_packet_split_side_data(&tmp);
2380 #endif
2381  ret = apply_param_change(avctx, &tmp);
2382  if (ret < 0)
2383  goto fail;
2384 
2385  avctx->internal->pkt = &tmp;
2387  ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp);
2388  else {
2389  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, &tmp);
2390  av_assert0(ret <= tmp.size);
2391  frame->pkt_dts = avpkt->dts;
2392  }
2393  if (ret >= 0 && *got_frame_ptr) {
2394  avctx->frame_number++;
2396  guess_correct_pts(avctx,
2397  frame->pts,
2398  frame->pkt_dts));
2399  if (frame->format == AV_SAMPLE_FMT_NONE)
2400  frame->format = avctx->sample_fmt;
2401  if (!frame->channel_layout)
2402  frame->channel_layout = avctx->channel_layout;
2403  if (!av_frame_get_channels(frame))
2404  av_frame_set_channels(frame, avctx->channels);
2405  if (!frame->sample_rate)
2406  frame->sample_rate = avctx->sample_rate;
2407  }
2408 
2409  side= av_packet_get_side_data(avctx->internal->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
2410  if(side && side_size>=10) {
2411  avctx->internal->skip_samples = AV_RL32(side) * avctx->internal->skip_samples_multiplier;
2412  discard_padding = AV_RL32(side + 4);
2413  av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
2414  avctx->internal->skip_samples, (int)discard_padding);
2415  skip_reason = AV_RL8(side + 8);
2416  discard_reason = AV_RL8(side + 9);
2417  }
2418 
2419  if ((frame->flags & AV_FRAME_FLAG_DISCARD) && *got_frame_ptr &&
2420  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
2421  avctx->internal->skip_samples = FFMAX(0, avctx->internal->skip_samples - frame->nb_samples);
2422  *got_frame_ptr = 0;
2423  }
2424 
2425  if (avctx->internal->skip_samples > 0 && *got_frame_ptr &&
2426  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
2427  if(frame->nb_samples <= avctx->internal->skip_samples){
2428  *got_frame_ptr = 0;
2429  avctx->internal->skip_samples -= frame->nb_samples;
2430  av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
2431  avctx->internal->skip_samples);
2432  } else {
2434  frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format);
2435  if(avctx->pkt_timebase.num && avctx->sample_rate) {
2436  int64_t diff_ts = av_rescale_q(avctx->internal->skip_samples,
2437  (AVRational){1, avctx->sample_rate},
2438  avctx->pkt_timebase);
2439  if(frame->pts!=AV_NOPTS_VALUE)
2440  frame->pts += diff_ts;
2441 #if FF_API_PKT_PTS
2443  if(frame->pkt_pts!=AV_NOPTS_VALUE)
2444  frame->pkt_pts += diff_ts;
2446 #endif
2447  if(frame->pkt_dts!=AV_NOPTS_VALUE)
2448  frame->pkt_dts += diff_ts;
2449  if (av_frame_get_pkt_duration(frame) >= diff_ts)
2450  av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts);
2451  } else {
2452  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
2453  }
2454  av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
2455  avctx->internal->skip_samples, frame->nb_samples);
2456  frame->nb_samples -= avctx->internal->skip_samples;
2457  avctx->internal->skip_samples = 0;
2458  }
2459  }
2460 
2461  if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr &&
2462  !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
2463  if (discard_padding == frame->nb_samples) {
2464  *got_frame_ptr = 0;
2465  } else {
2466  if(avctx->pkt_timebase.num && avctx->sample_rate) {
2467  int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
2468  (AVRational){1, avctx->sample_rate},
2469  avctx->pkt_timebase);
2470  av_frame_set_pkt_duration(frame, diff_ts);
2471  } else {
2472  av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
2473  }
2474  av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
2475  (int)discard_padding, frame->nb_samples);
2476  frame->nb_samples -= discard_padding;
2477  }
2478  }
2479 
2480  if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL) && *got_frame_ptr) {
2482  if (fside) {
2483  AV_WL32(fside->data, avctx->internal->skip_samples);
2484  AV_WL32(fside->data + 4, discard_padding);
2485  AV_WL8(fside->data + 8, skip_reason);
2486  AV_WL8(fside->data + 9, discard_reason);
2487  avctx->internal->skip_samples = 0;
2488  }
2489  }
2490 fail:
2491  avctx->internal->pkt = NULL;
2492 #if FF_API_MERGE_SD
2493  if (did_split) {
2495  if(ret == tmp.size)
2496  ret = avpkt->size;
2497  }
2498 #endif
2499 
2500  if (ret >= 0 && *got_frame_ptr) {
2501  if (!avctx->refcounted_frames) {
2502  int err = unrefcount_frame(avci, frame);
2503  if (err < 0)
2504  return err;
2505  }
2506  } else
2507  av_frame_unref(frame);
2508  }
2509 
2510  av_assert0(ret <= avpkt->size);
2511 
2512  if (!avci->showed_multi_packet_warning &&
2513  ret >= 0 && ret != avpkt->size && !(avctx->codec->capabilities & AV_CODEC_CAP_SUBFRAMES)) {
2514  av_log(avctx, AV_LOG_WARNING, "Multiple frames in a packet.\n");
2515  avci->showed_multi_packet_warning = 1;
2516  }
2517 
2518  return ret;
2519 }
2520 
2521 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
2523  AVPacket *outpkt, const AVPacket *inpkt)
2524 {
2525 #if CONFIG_ICONV
2526  iconv_t cd = (iconv_t)-1;
2527  int ret = 0;
2528  char *inb, *outb;
2529  size_t inl, outl;
2530  AVPacket tmp;
2531 #endif
2532 
2533  if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0)
2534  return 0;
2535 
2536 #if CONFIG_ICONV
2537  cd = iconv_open("UTF-8", avctx->sub_charenc);
2538  av_assert0(cd != (iconv_t)-1);
2539 
2540  inb = inpkt->data;
2541  inl = inpkt->size;
2542 
2543  if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
2544  av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
2545  ret = AVERROR(ENOMEM);
2546  goto end;
2547  }
2548 
2549  ret = av_new_packet(&tmp, inl * UTF8_MAX_BYTES);
2550  if (ret < 0)
2551  goto end;
2552  outpkt->buf = tmp.buf;
2553  outpkt->data = tmp.data;
2554  outpkt->size = tmp.size;
2555  outb = outpkt->data;
2556  outl = outpkt->size;
2557 
2558  if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
2559  iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
2560  outl >= outpkt->size || inl != 0) {
2561  ret = FFMIN(AVERROR(errno), -1);
2562  av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
2563  "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
2564  av_packet_unref(&tmp);
2565  goto end;
2566  }
2567  outpkt->size -= outl;
2568  memset(outpkt->data + outpkt->size, 0, outl);
2569 
2570 end:
2571  if (cd != (iconv_t)-1)
2572  iconv_close(cd);
2573  return ret;
2574 #else
2575  av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
2576  return AVERROR(EINVAL);
2577 #endif
2578 }
2579 
2580 static int utf8_check(const uint8_t *str)
2581 {
2582  const uint8_t *byte;
2583  uint32_t codepoint, min;
2584 
2585  while (*str) {
2586  byte = str;
2587  GET_UTF8(codepoint, *(byte++), return 0;);
2588  min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
2589  1 << (5 * (byte - str) - 4);
2590  if (codepoint < min || codepoint >= 0x110000 ||
2591  codepoint == 0xFFFE /* BOM */ ||
2592  codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
2593  return 0;
2594  str = byte;
2595  }
2596  return 1;
2597 }
2598 
2599 #if FF_API_ASS_TIMING
2600 static void insert_ts(AVBPrint *buf, int ts)
2601 {
2602  if (ts == -1) {
2603  av_bprintf(buf, "9:59:59.99,");
2604  } else {
2605  int h, m, s;
2606 
2607  h = ts/360000; ts -= 360000*h;
2608  m = ts/ 6000; ts -= 6000*m;
2609  s = ts/ 100; ts -= 100*s;
2610  av_bprintf(buf, "%d:%02d:%02d.%02d,", h, m, s, ts);
2611  }
2612 }
2613 
2615 {
2616  int i;
2617  AVBPrint buf;
2618 
2620 
2621  for (i = 0; i < sub->num_rects; i++) {
2622  char *final_dialog;
2623  const char *dialog;
2624  AVSubtitleRect *rect = sub->rects[i];
2625  int ts_start, ts_duration = -1;
2626  long int layer;
2627 
2628  if (rect->type != SUBTITLE_ASS || !strncmp(rect->ass, "Dialogue: ", 10))
2629  continue;
2630 
2631  av_bprint_clear(&buf);
2632 
2633  /* skip ReadOrder */
2634  dialog = strchr(rect->ass, ',');
2635  if (!dialog)
2636  continue;
2637  dialog++;
2638 
2639  /* extract Layer or Marked */
2640  layer = strtol(dialog, (char**)&dialog, 10);
2641  if (*dialog != ',')
2642  continue;
2643  dialog++;
2644 
2645  /* rescale timing to ASS time base (ms) */
2646  ts_start = av_rescale_q(pkt->pts, tb, av_make_q(1, 100));
2647  if (pkt->duration != -1)
2648  ts_duration = av_rescale_q(pkt->duration, tb, av_make_q(1, 100));
2649  sub->end_display_time = FFMAX(sub->end_display_time, 10 * ts_duration);
2650 
2651  /* construct ASS (standalone file form with timestamps) string */
2652  av_bprintf(&buf, "Dialogue: %ld,", layer);
2653  insert_ts(&buf, ts_start);
2654  insert_ts(&buf, ts_duration == -1 ? -1 : ts_start + ts_duration);
2655  av_bprintf(&buf, "%s\r\n", dialog);
2656 
2657  final_dialog = av_strdup(buf.str);
2658  if (!av_bprint_is_complete(&buf) || !final_dialog) {
2659  av_freep(&final_dialog);
2660  av_bprint_finalize(&buf, NULL);
2661  return AVERROR(ENOMEM);
2662  }
2663  av_freep(&rect->ass);
2664  rect->ass = final_dialog;
2665  }
2666 
2667  av_bprint_finalize(&buf, NULL);
2668  return 0;
2669 }
2670 #endif
2671 
2673  int *got_sub_ptr,
2674  AVPacket *avpkt)
2675 {
2676  int i, ret = 0;
2677 
2678  if (!avpkt->data && avpkt->size) {
2679  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
2680  return AVERROR(EINVAL);
2681  }
2682  if (!avctx->codec)
2683  return AVERROR(EINVAL);
2684  if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
2685  av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
2686  return AVERROR(EINVAL);
2687  }
2688 
2689  *got_sub_ptr = 0;
2690  get_subtitle_defaults(sub);
2691 
2692  if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
2693  AVPacket pkt_recoded;
2694  AVPacket tmp = *avpkt;
2695 #if FF_API_MERGE_SD
2697  int did_split = av_packet_split_side_data(&tmp);
2698  //apply_param_change(avctx, &tmp);
2699 
2700  if (did_split) {
2701  /* FFMIN() prevents overflow in case the packet wasn't allocated with
2702  * proper padding.
2703  * If the side data is smaller than the buffer padding size, the
2704  * remaining bytes should have already been filled with zeros by the
2705  * original packet allocation anyway. */
2706  memset(tmp.data + tmp.size, 0,
2707  FFMIN(avpkt->size - tmp.size, AV_INPUT_BUFFER_PADDING_SIZE));
2708  }
2710 #endif
2711 
2712  pkt_recoded = tmp;
2713  ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
2714  if (ret < 0) {
2715  *got_sub_ptr = 0;
2716  } else {
2717  avctx->internal->pkt = &pkt_recoded;
2718 
2719  if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
2720  sub->pts = av_rescale_q(avpkt->pts,
2721  avctx->pkt_timebase, AV_TIME_BASE_Q);
2722  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded);
2723  av_assert1((ret >= 0) >= !!*got_sub_ptr &&
2724  !!*got_sub_ptr >= !!sub->num_rects);
2725 
2726 #if FF_API_ASS_TIMING
2728  && *got_sub_ptr && sub->num_rects) {
2729  const AVRational tb = avctx->pkt_timebase.num ? avctx->pkt_timebase
2730  : avctx->time_base;
2731  int err = convert_sub_to_old_ass_form(sub, avpkt, tb);
2732  if (err < 0)
2733  ret = err;
2734  }
2735 #endif
2736 
2737  if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
2738  avctx->pkt_timebase.num) {
2739  AVRational ms = { 1, 1000 };
2740  sub->end_display_time = av_rescale_q(avpkt->duration,
2741  avctx->pkt_timebase, ms);
2742  }
2743 
2745  sub->format = 0;
2746  else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
2747  sub->format = 1;
2748 
2749  for (i = 0; i < sub->num_rects; i++) {
2750  if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
2751  av_log(avctx, AV_LOG_ERROR,
2752  "Invalid UTF-8 in decoded subtitles text; "
2753  "maybe missing -sub_charenc option\n");
2754  avsubtitle_free(sub);
2755  ret = AVERROR_INVALIDDATA;
2756  break;
2757  }
2758  }
2759 
2760  if (tmp.data != pkt_recoded.data) { // did we recode?
2761  /* prevent from destroying side data from original packet */
2762  pkt_recoded.side_data = NULL;
2763  pkt_recoded.side_data_elems = 0;
2764 
2765  av_packet_unref(&pkt_recoded);
2766  }
2767  avctx->internal->pkt = NULL;
2768  }
2769 
2770 #if FF_API_MERGE_SD
2771  if (did_split) {
2773  if(ret == tmp.size)
2774  ret = avpkt->size;
2775  }
2776 #endif
2777 
2778  if (*got_sub_ptr)
2779  avctx->frame_number++;
2780  }
2781 
2782  return ret;
2783 }
2784 
2786 {
2787  int i;
2788 
2789  for (i = 0; i < sub->num_rects; i++) {
2790  av_freep(&sub->rects[i]->data[0]);
2791  av_freep(&sub->rects[i]->data[1]);
2792  av_freep(&sub->rects[i]->data[2]);
2793  av_freep(&sub->rects[i]->data[3]);
2794  av_freep(&sub->rects[i]->text);
2795  av_freep(&sub->rects[i]->ass);
2796  av_freep(&sub->rects[i]);
2797  }
2798 
2799  av_freep(&sub->rects);
2800 
2801  memset(sub, 0, sizeof(*sub));
2802 }
2803 
2804 static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
2805 {
2806  int got_frame = 0;
2807  int ret;
2808 
2809  av_assert0(!avctx->internal->buffer_frame->buf[0]);
2810 
2811  if (!pkt)
2812  pkt = avctx->internal->buffer_pkt;
2813 
2814  // This is the lesser evil. The field is for compatibility with legacy users
2815  // of the legacy API, and users using the new API should not be forced to
2816  // even know about this field.
2817  avctx->refcounted_frames = 1;
2818 
2819  // Some codecs (at least wma lossless) will crash when feeding drain packets
2820  // after EOF was signaled.
2821  if (avctx->internal->draining_done)
2822  return AVERROR_EOF;
2823 
2824  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
2825  ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,
2826  &got_frame, pkt);
2827  if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
2828  ret = pkt->size;
2829  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
2830  ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,
2831  &got_frame, pkt);
2832  } else {
2833  ret = AVERROR(EINVAL);
2834  }
2835 
2836  if (ret == AVERROR(EAGAIN))
2837  ret = pkt->size;
2838 
2839  if (avctx->internal->draining && !got_frame)
2840  avctx->internal->draining_done = 1;
2841 
2842  if (ret < 0)
2843  return ret;
2844 
2845  if (ret >= pkt->size) {
2847  } else {
2848  int consumed = ret;
2849 
2850  if (pkt != avctx->internal->buffer_pkt) {
2852  if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0)
2853  return ret;
2854  }
2855 
2856  avctx->internal->buffer_pkt->data += consumed;
2857  avctx->internal->buffer_pkt->size -= consumed;
2860  }
2861 
2862  if (got_frame)
2863  av_assert0(avctx->internal->buffer_frame->buf[0]);
2864 
2865  return 0;
2866 }
2867 
2869 {
2870  int ret;
2871 
2872  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
2873  return AVERROR(EINVAL);
2874 
2875  if (avctx->internal->draining)
2876  return AVERROR_EOF;
2877 
2878  if (avpkt && !avpkt->size && avpkt->data)
2879  return AVERROR(EINVAL);
2880 
2881  if (!avpkt || !avpkt->size) {
2882  avctx->internal->draining = 1;
2883  avpkt = NULL;
2884 
2885  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
2886  return 0;
2887  }
2888 
2889  if (avctx->codec->send_packet) {
2890  if (avpkt) {
2891  AVPacket tmp = *avpkt;
2892 #if FF_API_MERGE_SD
2894  int did_split = av_packet_split_side_data(&tmp);
2896 #endif
2897  ret = apply_param_change(avctx, &tmp);
2898  if (ret >= 0)
2899  ret = avctx->codec->send_packet(avctx, &tmp);
2900 #if FF_API_MERGE_SD
2901  if (did_split)
2903 #endif
2904  return ret;
2905  } else {
2906  return avctx->codec->send_packet(avctx, NULL);
2907  }
2908  }
2909 
2910  // Emulation via old API. Assume avpkt is likely not refcounted, while
2911  // decoder output is always refcounted, and avoid copying.
2912 
2913  if (avctx->internal->buffer_pkt->size || avctx->internal->buffer_frame->buf[0])
2914  return AVERROR(EAGAIN);
2915 
2916  // The goal is decoding the first frame of the packet without using memcpy,
2917  // because the common case is having only 1 frame per packet (especially
2918  // with video, but audio too). In other cases, it can't be avoided, unless
2919  // the user is feeding refcounted packets.
2920  return do_decode(avctx, (AVPacket *)avpkt);
2921 }
2922 
2924 {
2925  int ret;
2926 
2927  av_frame_unref(frame);
2928 
2929  if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
2930  return AVERROR(EINVAL);
2931 
2932  if (avctx->codec->receive_frame) {
2933  if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
2934  return AVERROR_EOF;
2935  ret = avctx->codec->receive_frame(avctx, frame);
2936  if (ret >= 0) {
2939  guess_correct_pts(avctx, frame->pts, frame->pkt_dts));
2940  }
2941  }
2942  return ret;
2943  }
2944 
2945  // Emulation via old API.
2946 
2947  if (!avctx->internal->buffer_frame->buf[0]) {
2948  if (!avctx->internal->buffer_pkt->size && !avctx->internal->draining)
2949  return AVERROR(EAGAIN);
2950 
2951  while (1) {
2952  if ((ret = do_decode(avctx, avctx->internal->buffer_pkt)) < 0) {
2954  return ret;
2955  }
2956  // Some audio decoders may consume partial data without returning
2957  // a frame (fate-wmapro-2ch). There is no way to make the caller
2958  // call avcodec_receive_frame() again without returning a frame,
2959  // so try to decode more in these cases.
2960  if (avctx->internal->buffer_frame->buf[0] ||
2961  !avctx->internal->buffer_pkt->size)
2962  break;
2963  }
2964  }
2965 
2966  if (!avctx->internal->buffer_frame->buf[0])
2967  return avctx->internal->draining ? AVERROR_EOF : AVERROR(EAGAIN);
2968 
2969  av_frame_move_ref(frame, avctx->internal->buffer_frame);
2970  return 0;
2971 }
2972 
2973 static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
2974 {
2975  int ret;
2976  *got_packet = 0;
2977 
2979  avctx->internal->buffer_pkt_valid = 0;
2980 
2981  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
2982  ret = avcodec_encode_video2(avctx, avctx->internal->buffer_pkt,
2983  frame, got_packet);
2984  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
2985  ret = avcodec_encode_audio2(avctx, avctx->internal->buffer_pkt,
2986  frame, got_packet);
2987  } else {
2988  ret = AVERROR(EINVAL);
2989  }
2990 
2991  if (ret >= 0 && *got_packet) {
2992  // Encoders must always return ref-counted buffers.
2993  // Side-data only packets have no data and can be not ref-counted.
2994  av_assert0(!avctx->internal->buffer_pkt->data || avctx->internal->buffer_pkt->buf);
2995  avctx->internal->buffer_pkt_valid = 1;
2996  ret = 0;
2997  } else {
2999  }
3000 
3001  return ret;
3002 }
3003 
3005 {
3006  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
3007  return AVERROR(EINVAL);
3008 
3009  if (avctx->internal->draining)
3010  return AVERROR_EOF;
3011 
3012  if (!frame) {
3013  avctx->internal->draining = 1;
3014 
3015  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
3016  return 0;
3017  }
3018 
3019  if (avctx->codec->send_frame)
3020  return avctx->codec->send_frame(avctx, frame);
3021 
3022  // Emulation via old API. Do it here instead of avcodec_receive_packet, because:
3023  // 1. if the AVFrame is not refcounted, the copying will be much more
3024  // expensive than copying the packet data
3025  // 2. assume few users use non-refcounted AVPackets, so usually no copy is
3026  // needed
3027 
3028  if (avctx->internal->buffer_pkt_valid)
3029  return AVERROR(EAGAIN);
3030 
3031  return do_encode(avctx, frame, &(int){0});
3032 }
3033 
3035 {
3036  av_packet_unref(avpkt);
3037 
3038  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
3039  return AVERROR(EINVAL);
3040 
3041  if (avctx->codec->receive_packet) {
3042  if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
3043  return AVERROR_EOF;
3044  return avctx->codec->receive_packet(avctx, avpkt);
3045  }
3046 
3047  // Emulation via old API.
3048 
3049  if (!avctx->internal->buffer_pkt_valid) {
3050  int got_packet;
3051  int ret;
3052  if (!avctx->internal->draining)
3053  return AVERROR(EAGAIN);
3054  ret = do_encode(avctx, NULL, &got_packet);
3055  if (ret < 0)
3056  return ret;
3057  if (ret >= 0 && !got_packet)
3058  return AVERROR_EOF;
3059  }
3060 
3061  av_packet_move_ref(avpkt, avctx->internal->buffer_pkt);
3062  avctx->internal->buffer_pkt_valid = 0;
3063  return 0;
3064 }
3065 
3067 {
3068  int i;
3069 
3070  if (!avctx)
3071  return 0;
3072 
3073  if (avcodec_is_open(avctx)) {
3074  FramePool *pool = avctx->internal->pool;
3076  avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
3078  }
3079  if (HAVE_THREADS && avctx->internal->thread_ctx)
3080  ff_thread_free(avctx);
3081  if (avctx->codec && avctx->codec->close)
3082  avctx->codec->close(avctx);
3083  avctx->internal->byte_buffer_size = 0;
3084  av_freep(&avctx->internal->byte_buffer);
3085  av_frame_free(&avctx->internal->to_free);
3088  for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
3089  av_buffer_pool_uninit(&pool->pools[i]);
3090  av_freep(&avctx->internal->pool);
3091 
3092  if (avctx->hwaccel && avctx->hwaccel->uninit)
3093  avctx->hwaccel->uninit(avctx);
3095 
3096  av_freep(&avctx->internal);
3097  }
3098 
3099  for (i = 0; i < avctx->nb_coded_side_data; i++)
3100  av_freep(&avctx->coded_side_data[i].data);
3101  av_freep(&avctx->coded_side_data);
3102  avctx->nb_coded_side_data = 0;
3103 
3104  av_buffer_unref(&avctx->hw_frames_ctx);
3105  av_buffer_unref(&avctx->hw_device_ctx);
3106 
3107  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
3108  av_opt_free(avctx->priv_data);
3109  av_opt_free(avctx);
3110  av_freep(&avctx->priv_data);
3111  if (av_codec_is_encoder(avctx->codec)) {
3112  av_freep(&avctx->extradata);
3113 #if FF_API_CODED_FRAME
3115  av_frame_free(&avctx->coded_frame);
3117 #endif
3118  }
3119  avctx->codec = NULL;
3120  avctx->active_thread_type = 0;
3121 
3122  return 0;
3123 }
3124 
3126 {
3127  switch(id){
3128  //This is for future deprecatec codec ids, its empty since
3129  //last major bump but will fill up again over time, please don't remove it
3130  default : return id;
3131  }
3132 }
3133 
3134 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
3135 {
3136  AVCodec *p, *experimental = NULL;
3137  p = first_avcodec;
3138  id= remap_deprecated_codec_id(id);
3139  while (p) {
3140  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
3141  p->id == id) {
3142  if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
3143  experimental = p;
3144  } else
3145  return p;
3146  }
3147  p = p->next;
3148  }
3149  return experimental;
3150 }
3151 
3153 {
3154  return find_encdec(id, 1);
3155 }
3156 
3158 {
3159  AVCodec *p;
3160  if (!name)
3161  return NULL;
3162  p = first_avcodec;
3163  while (p) {
3164  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
3165  return p;
3166  p = p->next;
3167  }
3168  return NULL;
3169 }
3170 
3172 {
3173  return find_encdec(id, 0);
3174 }
3175 
3177 {
3178  AVCodec *p;
3179  if (!name)
3180  return NULL;
3181  p = first_avcodec;
3182  while (p) {
3183  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
3184  return p;
3185  p = p->next;
3186  }
3187  return NULL;
3188 }
3189 
3190 const char *avcodec_get_name(enum AVCodecID id)
3191 {
3192  const AVCodecDescriptor *cd;
3193  AVCodec *codec;
3194 
3195  if (id == AV_CODEC_ID_NONE)
3196  return "none";
3197  cd = avcodec_descriptor_get(id);
3198  if (cd)
3199  return cd->name;
3200  av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
3201  codec = avcodec_find_decoder(id);
3202  if (codec)
3203  return codec->name;
3204  codec = avcodec_find_encoder(id);
3205  if (codec)
3206  return codec->name;
3207  return "unknown_codec";
3208 }
3209 
3210 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
3211 {
3212  int i, len, ret = 0;
3213 
3214 #define TAG_PRINT(x) \
3215  (((x) >= '0' && (x) <= '9') || \
3216  ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
3217  ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
3218 
3219  for (i = 0; i < 4; i++) {
3220  len = snprintf(buf, buf_size,
3221  TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
3222  buf += len;
3223  buf_size = buf_size > len ? buf_size - len : 0;
3224  ret += len;
3225  codec_tag >>= 8;
3226  }
3227  return ret;
3228 }
3229 
3230 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
3231 {
3232  const char *codec_type;
3233  const char *codec_name;
3234  const char *profile = NULL;
3235  int64_t bitrate;
3236  int new_line = 0;
3237  AVRational display_aspect_ratio;
3238  const char *separator = enc->dump_separator ? (const char *)enc->dump_separator : ", ";
3239 
3240  if (!buf || buf_size <= 0)
3241  return;
3242  codec_type = av_get_media_type_string(enc->codec_type);
3243  codec_name = avcodec_get_name(enc->codec_id);
3244  profile = avcodec_profile_name(enc->codec_id, enc->profile);
3245 
3246  snprintf(buf, buf_size, "%s: %s", codec_type ? codec_type : "unknown",
3247  codec_name);
3248  buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
3249 
3250  if (enc->codec && strcmp(enc->codec->name, codec_name))
3251  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", enc->codec->name);
3252 
3253  if (profile)
3254  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile);
3255  if ( enc->codec_type == AVMEDIA_TYPE_VIDEO
3257  && enc->refs)
3258  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3259  ", %d reference frame%s",
3260  enc->refs, enc->refs > 1 ? "s" : "");
3261 
3262  if (enc->codec_tag)
3263  snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s / 0x%04X)",
3264  av_fourcc2str(enc->codec_tag), enc->codec_tag);
3265 
3266  switch (enc->codec_type) {
3267  case AVMEDIA_TYPE_VIDEO:
3268  {
3269  char detail[256] = "(";
3270 
3271  av_strlcat(buf, separator, buf_size);
3272 
3273  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3274  "%s", enc->pix_fmt == AV_PIX_FMT_NONE ? "none" :
3276  if (enc->bits_per_raw_sample && enc->pix_fmt != AV_PIX_FMT_NONE &&
3278  av_strlcatf(detail, sizeof(detail), "%d bpc, ", enc->bits_per_raw_sample);
3280  av_strlcatf(detail, sizeof(detail), "%s, ",
3282 
3283  if (enc->colorspace != AVCOL_SPC_UNSPECIFIED ||
3285  enc->color_trc != AVCOL_TRC_UNSPECIFIED) {
3286  if (enc->colorspace != (int)enc->color_primaries ||
3287  enc->colorspace != (int)enc->color_trc) {
3288  new_line = 1;
3289  av_strlcatf(detail, sizeof(detail), "%s/%s/%s, ",
3293  } else
3294  av_strlcatf(detail, sizeof(detail), "%s, ",
3296  }
3297 
3298  if (enc->field_order != AV_FIELD_UNKNOWN) {
3299  const char *field_order = "progressive";
3300  if (enc->field_order == AV_FIELD_TT)
3301  field_order = "top first";
3302  else if (enc->field_order == AV_FIELD_BB)
3303  field_order = "bottom first";
3304  else if (enc->field_order == AV_FIELD_TB)
3305  field_order = "top coded first (swapped)";
3306  else if (enc->field_order == AV_FIELD_BT)
3307  field_order = "bottom coded first (swapped)";
3308 
3309  av_strlcatf(detail, sizeof(detail), "%s, ", field_order);
3310  }
3311 
3312  if (av_log_get_level() >= AV_LOG_VERBOSE &&
3314  av_strlcatf(detail, sizeof(detail), "%s, ",
3316 
3317  if (strlen(detail) > 1) {
3318  detail[strlen(detail) - 2] = 0;
3319  av_strlcatf(buf, buf_size, "%s)", detail);
3320  }
3321  }
3322 
3323  if (enc->width) {
3324  av_strlcat(buf, new_line ? separator : ", ", buf_size);
3325 
3326  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3327  "%dx%d",
3328  enc->width, enc->height);
3329 
3330  if (av_log_get_level() >= AV_LOG_VERBOSE &&
3331  (enc->width != enc->coded_width ||
3332  enc->height != enc->coded_height))
3333  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3334  " (%dx%d)", enc->coded_width, enc->coded_height);
3335 
3336  if (enc->sample_aspect_ratio.num) {
3337  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
3338  enc->width * (int64_t)enc->sample_aspect_ratio.num,
3339  enc->height * (int64_t)enc->sample_aspect_ratio.den,
3340  1024 * 1024);
3341  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3342  " [SAR %d:%d DAR %d:%d]",
3344  display_aspect_ratio.num, display_aspect_ratio.den);
3345  }
3346  if (av_log_get_level() >= AV_LOG_DEBUG) {
3347  int g = av_gcd(enc->time_base.num, enc->time_base.den);
3348  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3349  ", %d/%d",
3350  enc->time_base.num / g, enc->time_base.den / g);
3351  }
3352  }
3353  if (encode) {
3354  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3355  ", q=%d-%d", enc->qmin, enc->qmax);
3356  } else {
3358  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3359  ", Closed Captions");
3361  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3362  ", lossless");
3363  }
3364  break;
3365  case AVMEDIA_TYPE_AUDIO:
3366  av_strlcat(buf, separator, buf_size);
3367 
3368  if (enc->sample_rate) {
3369  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3370  "%d Hz, ", enc->sample_rate);
3371  }
3372  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
3373  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
3374  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3375  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
3376  }
3377  if ( enc->bits_per_raw_sample > 0
3379  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3380  " (%d bit)", enc->bits_per_raw_sample);
3381  if (av_log_get_level() >= AV_LOG_VERBOSE) {
3382  if (enc->initial_padding)
3383  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3384  ", delay %d", enc->initial_padding);
3385  if (enc->trailing_padding)
3386  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3387  ", padding %d", enc->trailing_padding);
3388  }
3389  break;
3390  case AVMEDIA_TYPE_DATA:
3391  if (av_log_get_level() >= AV_LOG_DEBUG) {
3392  int g = av_gcd(enc->time_base.num, enc->time_base.den);
3393  if (g)
3394  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3395  ", %d/%d",
3396  enc->time_base.num / g, enc->time_base.den / g);
3397  }
3398  break;
3399  case AVMEDIA_TYPE_SUBTITLE:
3400  if (enc->width)
3401  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3402  ", %dx%d", enc->width, enc->height);
3403  break;
3404  default:
3405  return;
3406  }
3407  if (encode) {
3408  if (enc->flags & AV_CODEC_FLAG_PASS1)
3409  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3410  ", pass 1");
3411  if (enc->flags & AV_CODEC_FLAG_PASS2)
3412  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3413  ", pass 2");
3414  }
3415  bitrate = get_bit_rate(enc);
3416  if (bitrate != 0) {
3417  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3418  ", %"PRId64" kb/s", bitrate / 1000);
3419  } else if (enc->rc_max_rate > 0) {
3420  snprintf(buf + strlen(buf), buf_size - strlen(buf),
3421  ", max. %"PRId64" kb/s", (int64_t)enc->rc_max_rate / 1000);
3422  }
3423 }
3424 
3425 const char *av_get_profile_name(const AVCodec *codec, int profile)
3426 {
3427  const AVProfile *p;
3428  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
3429  return NULL;
3430 
3431  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
3432  if (p->profile == profile)
3433  return p->name;
3434 
3435  return NULL;
3436 }
3437 
3439 {
3440  const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
3441  const AVProfile *p;
3442 
3443  if (profile == FF_PROFILE_UNKNOWN || !desc || !desc->profiles)
3444  return NULL;
3445 
3446  for (p = desc->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
3447  if (p->profile == profile)
3448  return p->name;
3449 
3450  return NULL;
3451 }
3452 
3453 unsigned avcodec_version(void)
3454 {
3455 // av_assert0(AV_CODEC_ID_V410==164);
3458 // av_assert0(AV_CODEC_ID_BMV_AUDIO==86071);
3459  av_assert0(AV_CODEC_ID_SRT==94216);
3461 
3462  return LIBAVCODEC_VERSION_INT;
3463 }
3464 
3465 const char *avcodec_configuration(void)
3466 {
3467  return FFMPEG_CONFIGURATION;
3468 }
3469 
3470 const char *avcodec_license(void)
3471 {
3472 #define LICENSE_PREFIX "libavcodec license: "
3473  return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
3474 }
3475 
3477 {
3478  avctx->internal->draining = 0;
3479  avctx->internal->draining_done = 0;
3482  avctx->internal->buffer_pkt_valid = 0;
3483 
3485  ff_thread_flush(avctx);
3486  else if (avctx->codec->flush)
3487  avctx->codec->flush(avctx);
3488 
3489  avctx->pts_correction_last_pts =
3490  avctx->pts_correction_last_dts = INT64_MIN;
3491 
3492  if (!avctx->refcounted_frames)
3493  av_frame_unref(avctx->internal->to_free);
3494 }
3495 
3497 {
3498  switch (codec_id) {
3499  case AV_CODEC_ID_8SVX_EXP:
3500  case AV_CODEC_ID_8SVX_FIB:
3501  case AV_CODEC_ID_ADPCM_CT:
3509  return 4;
3510  case AV_CODEC_ID_DSD_LSBF:
3511  case AV_CODEC_ID_DSD_MSBF:
3514  case AV_CODEC_ID_PCM_ALAW:
3515  case AV_CODEC_ID_PCM_MULAW:
3516  case AV_CODEC_ID_PCM_S8:
3518  case AV_CODEC_ID_PCM_U8:
3519  case AV_CODEC_ID_PCM_ZORK:
3520  case AV_CODEC_ID_SDX2_DPCM:
3521  return 8;
3522  case AV_CODEC_ID_PCM_S16BE:
3524  case AV_CODEC_ID_PCM_S16LE:
3526  case AV_CODEC_ID_PCM_U16BE:
3527  case AV_CODEC_ID_PCM_U16LE:
3528  return 16;
3530  case AV_CODEC_ID_PCM_S24BE:
3531  case AV_CODEC_ID_PCM_S24LE:
3533  case AV_CODEC_ID_PCM_U24BE:
3534  case AV_CODEC_ID_PCM_U24LE:
3535  return 24;
3536  case AV_CODEC_ID_PCM_S32BE:
3537  case AV_CODEC_ID_PCM_S32LE:
3539  case AV_CODEC_ID_PCM_U32BE:
3540  case AV_CODEC_ID_PCM_U32LE:
3541  case AV_CODEC_ID_PCM_F32BE:
3542  case AV_CODEC_ID_PCM_F32LE:
3543  case AV_CODEC_ID_PCM_F24LE:
3544  case AV_CODEC_ID_PCM_F16LE:
3545  return 32;
3546  case AV_CODEC_ID_PCM_F64BE:
3547  case AV_CODEC_ID_PCM_F64LE:
3548  case AV_CODEC_ID_PCM_S64BE:
3549  case AV_CODEC_ID_PCM_S64LE:
3550  return 64;
3551  default:
3552  return 0;
3553  }
3554 }
3555 
3557 {
3558  static const enum AVCodecID map[AV_SAMPLE_FMT_NB][2] = {
3564  [AV_SAMPLE_FMT_U8P ] = { AV_CODEC_ID_PCM_U8, AV_CODEC_ID_PCM_U8 },
3565  [AV_SAMPLE_FMT_S16P] = { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_S16BE },
3566  [AV_SAMPLE_FMT_S32P] = { AV_CODEC_ID_PCM_S32LE, AV_CODEC_ID_PCM_S32BE },
3568  [AV_SAMPLE_FMT_FLTP] = { AV_CODEC_ID_PCM_F32LE, AV_CODEC_ID_PCM_F32BE },
3569  [AV_SAMPLE_FMT_DBLP] = { AV_CODEC_ID_PCM_F64LE, AV_CODEC_ID_PCM_F64BE },
3570  };
3571  if (fmt < 0 || fmt >= AV_SAMPLE_FMT_NB)
3572  return AV_CODEC_ID_NONE;
3573  if (be < 0 || be > 1)
3574  be = AV_NE(1, 0);
3575  return map[fmt][be];
3576 }
3577 
3579 {
3580  switch (codec_id) {
3582  return 2;
3584  return 3;
3588  case AV_CODEC_ID_ADPCM_SWF:
3589  case AV_CODEC_ID_ADPCM_MS:
3590  return 4;
3591  default:
3592  return av_get_exact_bits_per_sample(codec_id);
3593  }
3594 }
3595 
3596 static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
3597  uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
3598  uint8_t * extradata, int frame_size, int frame_bytes)
3599 {
3601  int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
3602 
3603  /* codecs with an exact constant bits per sample */
3604  if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
3605  return (frame_bytes * 8LL) / (bps * ch);
3606  bps = bits_per_coded_sample;
3607 
3608  /* codecs with a fixed packet duration */
3609  switch (id) {
3610  case AV_CODEC_ID_ADPCM_ADX: return 32;
3611  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
3612  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
3613  case AV_CODEC_ID_AMR_NB:
3614  case AV_CODEC_ID_EVRC:
3615  case AV_CODEC_ID_GSM:
3616  case AV_CODEC_ID_QCELP:
3617  case AV_CODEC_ID_RA_288: return 160;
3618  case AV_CODEC_ID_AMR_WB:
3619  case AV_CODEC_ID_GSM_MS: return 320;
3620  case AV_CODEC_ID_MP1: return 384;
3621  case AV_CODEC_ID_ATRAC1: return 512;
3622  case AV_CODEC_ID_ATRAC3: return 1024 * framecount;
3623  case AV_CODEC_ID_ATRAC3P: return 2048;
3624  case AV_CODEC_ID_MP2:
3625  case AV_CODEC_ID_MUSEPACK7: return 1152;
3626  case AV_CODEC_ID_AC3: return 1536;
3627  }
3628 
3629  if (sr > 0) {
3630  /* calc from sample rate */
3631  if (id == AV_CODEC_ID_TTA)
3632  return 256 * sr / 245;
3633  else if (id == AV_CODEC_ID_DST)
3634  return 588 * sr / 44100;
3635 
3636  if (ch > 0) {
3637  /* calc from sample rate and channels */
3638  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
3639  return (480 << (sr / 22050)) / ch;
3640  }
3641  }
3642 
3643  if (ba > 0) {
3644  /* calc from block_align */
3645  if (id == AV_CODEC_ID_SIPR) {
3646  switch (ba) {
3647  case 20: return 160;
3648  case 19: return 144;
3649  case 29: return 288;
3650  case 37: return 480;
3651  }
3652  } else if (id == AV_CODEC_ID_ILBC) {
3653  switch (ba) {
3654  case 38: return 160;
3655  case 50: return 240;
3656  }
3657  }
3658  }
3659 
3660  if (frame_bytes > 0) {
3661  /* calc from frame_bytes only */
3662  if (id == AV_CODEC_ID_TRUESPEECH)
3663  return 240 * (frame_bytes / 32);
3664  if (id == AV_CODEC_ID_NELLYMOSER)
3665  return 256 * (frame_bytes / 64);
3666  if (id == AV_CODEC_ID_RA_144)
3667  return 160 * (frame_bytes / 20);
3668  if (id == AV_CODEC_ID_G723_1)
3669  return 240 * (frame_bytes / 24);
3670 
3671  if (bps > 0) {
3672  /* calc from frame_bytes and bits_per_coded_sample */
3673  if (id == AV_CODEC_ID_ADPCM_G726)
3674  return frame_bytes * 8 / bps;
3675  }
3676 
3677  if (ch > 0 && ch < INT_MAX/16) {
3678  /* calc from frame_bytes and channels */
3679  switch (id) {
3680  case AV_CODEC_ID_ADPCM_AFC:
3681  return frame_bytes / (9 * ch) * 16;
3682  case AV_CODEC_ID_ADPCM_PSX:
3683  case AV_CODEC_ID_ADPCM_DTK:
3684  return frame_bytes / (16 * ch) * 28;
3685  case AV_CODEC_ID_ADPCM_4XM:
3688  return (frame_bytes - 4 * ch) * 2 / ch;
3690  return (frame_bytes - 4) * 2 / ch;
3692  return (frame_bytes - 8) * 2 / ch;
3693  case AV_CODEC_ID_ADPCM_THP:
3695  if (extradata)
3696  return frame_bytes * 14 / (8 * ch);
3697  break;
3698  case AV_CODEC_ID_ADPCM_XA:
3699  return (frame_bytes / 128) * 224 / ch;
3701  return (frame_bytes - 6 - ch) / ch;
3702  case AV_CODEC_ID_ROQ_DPCM:
3703  return (frame_bytes - 8) / ch;
3704  case AV_CODEC_ID_XAN_DPCM:
3705  return (frame_bytes - 2 * ch) / ch;
3706  case AV_CODEC_ID_MACE3:
3707  return 3 * frame_bytes / ch;
3708  case AV_CODEC_ID_MACE6:
3709  return 6 * frame_bytes / ch;
3710  case AV_CODEC_ID_PCM_LXF:
3711  return 2 * (frame_bytes / (5 * ch));
3712  case AV_CODEC_ID_IAC:
3713  case AV_CODEC_ID_IMC:
3714  return 4 * frame_bytes / ch;
3715  }
3716 
3717  if (tag) {
3718  /* calc from frame_bytes, channels, and codec_tag */
3719  if (id == AV_CODEC_ID_SOL_DPCM) {
3720  if (tag == 3)
3721  return frame_bytes / ch;
3722  else
3723  return frame_bytes * 2 / ch;
3724  }
3725  }
3726 
3727  if (ba > 0) {
3728  /* calc from frame_bytes, channels, and block_align */
3729  int blocks = frame_bytes / ba;
3730  switch (id) {
3732  if (bps < 2 || bps > 5)
3733  return 0;
3734  return blocks * (1 + (ba - 4 * ch) / (bps * ch) * 8);
3736  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
3738  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
3740  return blocks * ((ba - 4 * ch) * 2 / ch);
3741  case AV_CODEC_ID_ADPCM_MS:
3742  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
3744  return blocks * (ba - 16) * 2 / ch;
3745  }
3746  }
3747 
3748  if (bps > 0) {
3749  /* calc from frame_bytes, channels, and bits_per_coded_sample */
3750  switch (id) {
3751  case AV_CODEC_ID_PCM_DVD:
3752  if(bps<4)
3753  return 0;
3754  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
3756  if(bps<4)
3757  return 0;
3758  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
3759  case AV_CODEC_ID_S302M:
3760  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
3761  }
3762  }
3763  }
3764  }
3765 
3766  /* Fall back on using frame_size */
3767  if (frame_size > 1 && frame_bytes)
3768  return frame_size;
3769 
3770  //For WMA we currently have no other means to calculate duration thus we
3771  //do it here by assuming CBR, which is true for all known cases.
3772  if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) {
3773  if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2)
3774  return (frame_bytes * 8LL * sr) / bitrate;
3775  }
3776 
3777  return 0;
3778 }
3779 
3780 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
3781 {
3782  return get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
3783  avctx->channels, avctx->block_align,
3784  avctx->codec_tag, avctx->bits_per_coded_sample,
3785  avctx->bit_rate, avctx->extradata, avctx->frame_size,
3786  frame_bytes);
3787 }
3788 
3790 {
3791  return get_audio_frame_duration(par->codec_id, par->sample_rate,
3792  par->channels, par->block_align,
3793  par->codec_tag, par->bits_per_coded_sample,
3794  par->bit_rate, par->extradata, par->frame_size,
3795  frame_bytes);
3796 }
3797 
3798 #if !HAVE_THREADS
3800 {
3801  return -1;
3802 }
3803 
3804 #endif
3805 
3806 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
3807 {
3808  unsigned int n = 0;
3809 
3810  while (v >= 0xff) {
3811  *s++ = 0xff;
3812  v -= 0xff;
3813  n++;
3814  }
3815  *s = v;
3816  n++;
3817  return n;
3818 }
3819 
3820 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
3821 {
3822  int i;
3823  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
3824  return i;
3825 }
3826 
3827 #if FF_API_MISSING_SAMPLE
3829 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
3830 {
3831  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your FFmpeg "
3832  "version to the newest one from Git. If the problem still "
3833  "occurs, it means that your file has a feature which has not "
3834  "been implemented.\n", feature);
3835  if(want_sample)
3837 }
3838 
3839 void av_log_ask_for_sample(void *avc, const char *msg, ...)
3840 {
3841  va_list argument_list;
3842 
3843  va_start(argument_list, msg);
3844 
3845  if (msg)
3846  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
3847  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
3848  "of this file to ftp://upload.ffmpeg.org/incoming/ "
3849  "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
3850 
3851  va_end(argument_list);
3852 }
3854 #endif /* FF_API_MISSING_SAMPLE */
3855 
3858 
3860 {
3861  AVHWAccel **p = last_hwaccel;
3862  hwaccel->next = NULL;
3863  while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
3864  p = &(*p)->next;
3865  last_hwaccel = &hwaccel->next;
3866 }
3867 
3869 {
3870  return hwaccel ? hwaccel->next : first_hwaccel;
3871 }
3872 
3873 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
3874 {
3875  if (lockmgr_cb) {
3876  // There is no good way to rollback a failure to destroy the
3877  // mutex, so we ignore failures.
3880  lockmgr_cb = NULL;
3881  codec_mutex = NULL;
3882  avformat_mutex = NULL;
3883  }
3884 
3885  if (cb) {
3886  void *new_codec_mutex = NULL;
3887  void *new_avformat_mutex = NULL;
3888  int err;
3889  if (err = cb(&new_codec_mutex, AV_LOCK_CREATE)) {
3890  return err > 0 ? AVERROR_UNKNOWN : err;
3891  }
3892  if (err = cb(&new_avformat_mutex, AV_LOCK_CREATE)) {
3893  // Ignore failures to destroy the newly created mutex.
3894  cb(&new_codec_mutex, AV_LOCK_DESTROY);
3895  return err > 0 ? AVERROR_UNKNOWN : err;
3896  }
3897  lockmgr_cb = cb;
3898  codec_mutex = new_codec_mutex;
3899  avformat_mutex = new_avformat_mutex;
3900  }
3901 
3902  return 0;
3903 }
3904 
3905 int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
3906 {
3907  if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
3908  return 0;
3909 
3910  if (lockmgr_cb) {
3912  return -1;
3913  }
3914 
3916  av_log(log_ctx, AV_LOG_ERROR,
3917  "Insufficient thread locking. At least %d threads are "
3918  "calling avcodec_open2() at the same time right now.\n",
3920  if (!lockmgr_cb)
3921  av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n");
3922  ff_avcodec_locked = 1;
3923  ff_unlock_avcodec(codec);
3924  return AVERROR(EINVAL);
3925  }
3927  ff_avcodec_locked = 1;
3928  return 0;
3929 }
3930 
3931 int ff_unlock_avcodec(const AVCodec *codec)
3932 {
3933  if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init)
3934  return 0;
3935 
3937  ff_avcodec_locked = 0;
3939  if (lockmgr_cb) {
3941  return -1;
3942  }
3943 
3944  return 0;
3945 }
3946 
3948 {
3949  if (lockmgr_cb) {
3951  return -1;
3952  }
3953  return 0;
3954 }
3955 
3957 {
3958  if (lockmgr_cb) {
3960  return -1;
3961  }
3962  return 0;
3963 }
3964 
3965 unsigned int avpriv_toupper4(unsigned int x)
3966 {
3967  return av_toupper(x & 0xFF) +
3968  (av_toupper((x >> 8) & 0xFF) << 8) +
3969  (av_toupper((x >> 16) & 0xFF) << 16) +
3970 ((unsigned)av_toupper((x >> 24) & 0xFF) << 24);
3971 }
3972 
3974 {
3975  int ret;
3976 
3977  dst->owner[0] = src->owner[0];
3978  dst->owner[1] = src->owner[1];
3979 
3980  ret = av_frame_ref(dst->f, src->f);
3981  if (ret < 0)
3982  return ret;
3983 
3984  av_assert0(!dst->progress);
3985 
3986  if (src->progress &&
3987  !(dst->progress = av_buffer_ref(src->progress))) {
3988  ff_thread_release_buffer(dst->owner[0], dst);
3989  return AVERROR(ENOMEM);
3990  }
3991 
3992  return 0;
3993 }
3994 
3995 #if !HAVE_THREADS
3996 
3998 {
3999  return ff_get_format(avctx, fmt);
4000 }
4001 
4003 {
4004  f->owner[0] = f->owner[1] = avctx;
4005  return ff_get_buffer(avctx, f->f, flags);
4006 }
4007 
4009 {
4010  if (f->f)
4011  av_frame_unref(f->f);
4012 }
4013 
4015 {
4016 }
4017 
4018 void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
4019 {
4020 }
4021 
4022 void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
4023 {
4024 }
4025 
4027 {
4028  return 1;
4029 }
4030 
4032 {
4033  return 0;
4034 }
4035 
4037 {
4038 }
4039 
4040 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
4041 {
4042 }
4043 
4044 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
4045 {
4046 }
4047 
4048 #endif
4049 
4051 {
4052  return !!s->internal;
4053 }
4054 
4055 int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
4056 {
4057  int ret;
4058  char *str;
4059 
4060  ret = av_bprint_finalize(buf, &str);
4061  if (ret < 0)
4062  return ret;
4063  if (!av_bprint_is_complete(buf)) {
4064  av_free(str);
4065  return AVERROR(ENOMEM);
4066  }
4067 
4068  avctx->extradata = str;
4069  /* Note: the string is NUL terminated (so extradata can be read as a
4070  * string), but the ending character is not accounted in the size (in
4071  * binary formats you are likely not supposed to mux that character). When
4072  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
4073  * zeros. */
4074  avctx->extradata_size = buf->len;
4075  return 0;
4076 }
4077 
4079  const uint8_t *end,
4080  uint32_t *av_restrict state)
4081 {
4082  int i;
4083 
4084  av_assert0(p <= end);
4085  if (p >= end)
4086  return end;
4087 
4088  for (i = 0; i < 3; i++) {
4089  uint32_t tmp = *state << 8;
4090  *state = tmp + *(p++);
4091  if (tmp == 0x100 || p == end)
4092  return p;
4093  }
4094 
4095  while (p < end) {
4096  if (p[-1] > 1 ) p += 3;
4097  else if (p[-2] ) p += 2;
4098  else if (p[-3]|(p[-1]-1)) p++;
4099  else {
4100  p++;
4101  break;
4102  }
4103  }
4104 
4105  p = FFMIN(p, end) - 4;
4106  *state = AV_RB32(p);
4107 
4108  return p + 4;
4109 }
4110 
4112 {
4113  AVCPBProperties *props = av_mallocz(sizeof(AVCPBProperties));
4114  if (!props)
4115  return NULL;
4116 
4117  if (size)
4118  *size = sizeof(*props);
4119 
4120  props->vbv_delay = UINT64_MAX;
4121 
4122  return props;
4123 }
4124 
4126 {
4128  AVCPBProperties *props;
4129  size_t size;
4130 
4131  props = av_cpb_properties_alloc(&size);
4132  if (!props)
4133  return NULL;
4134 
4135  tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
4136  if (!tmp) {
4137  av_freep(&props);
4138  return NULL;
4139  }
4140 
4141  avctx->coded_side_data = tmp;
4142  avctx->nb_coded_side_data++;
4143 
4145  avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
4146  avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
4147 
4148  return props;
4149 }
4150 
4152 {
4153  av_freep(&par->extradata);
4154 
4155  memset(par, 0, sizeof(*par));
4156 
4158  par->codec_id = AV_CODEC_ID_NONE;
4159  par->format = -1;
4166  par->sample_aspect_ratio = (AVRational){ 0, 1 };
4167  par->profile = FF_PROFILE_UNKNOWN;
4168  par->level = FF_LEVEL_UNKNOWN;
4169 }
4170 
4172 {
4173  AVCodecParameters *par = av_mallocz(sizeof(*par));
4174 
4175  if (!par)
4176  return NULL;
4178  return par;
4179 }
4180 
4182 {
4183  AVCodecParameters *par = *ppar;
4184 
4185  if (!par)
4186  return;
4188 
4189  av_freep(ppar);
4190 }
4191 
4193 {
4195  memcpy(dst, src, sizeof(*dst));
4196 
4197  dst->extradata = NULL;
4198  dst->extradata_size = 0;
4199  if (src->extradata) {
4201  if (!dst->extradata)
4202  return AVERROR(ENOMEM);
4203  memcpy(dst->extradata, src->extradata, src->extradata_size);
4204  dst->extradata_size = src->extradata_size;
4205  }
4206 
4207  return 0;
4208 }
4209 
4211  const AVCodecContext *codec)
4212 {
4214 
4215  par->codec_type = codec->codec_type;
4216  par->codec_id = codec->codec_id;
4217  par->codec_tag = codec->codec_tag;
4218 
4219  par->bit_rate = codec->bit_rate;
4222  par->profile = codec->profile;
4223  par->level = codec->level;
4224 
4225  switch (par->codec_type) {
4226  case AVMEDIA_TYPE_VIDEO:
4227  par->format = codec->pix_fmt;
4228  par->width = codec->width;
4229  par->height = codec->height;
4230  par->field_order = codec->field_order;
4231  par->color_range = codec->color_range;
4232  par->color_primaries = codec->color_primaries;
4233  par->color_trc = codec->color_trc;
4234  par->color_space = codec->colorspace;
4237  par->video_delay = codec->has_b_frames;
4238  break;
4239  case AVMEDIA_TYPE_AUDIO:
4240  par->format = codec->sample_fmt;
4241  par->channel_layout = codec->channel_layout;
4242  par->channels = codec->channels;
4243  par->sample_rate = codec->sample_rate;
4244  par->block_align = codec->block_align;
4245  par->frame_size = codec->frame_size;
4246  par->initial_padding = codec->initial_padding;
4247  par->trailing_padding = codec->trailing_padding;
4248  par->seek_preroll = codec->seek_preroll;
4249  break;
4250  case AVMEDIA_TYPE_SUBTITLE:
4251  par->width = codec->width;
4252  par->height = codec->height;
4253  break;
4254  }
4255 
4256  if (codec->extradata) {
4258  if (!par->extradata)
4259  return AVERROR(ENOMEM);
4260  memcpy(par->extradata, codec->extradata, codec->extradata_size);
4261  par->extradata_size = codec->extradata_size;
4262  }
4263 
4264  return 0;
4265 }
4266 
4268  const AVCodecParameters *par)
4269 {
4270  codec->codec_type = par->codec_type;
4271  codec->codec_id = par->codec_id;
4272  codec->codec_tag = par->codec_tag;
4273 
4274  codec->bit_rate = par->bit_rate;
4277  codec->profile = par->profile;
4278  codec->level = par->level;
4279 
4280  switch (par->codec_type) {
4281  case AVMEDIA_TYPE_VIDEO:
4282  codec->pix_fmt = par->format;
4283  codec->width = par->width;
4284  codec->height = par->height;
4285  codec->field_order = par->field_order;
4286  codec->color_range = par->color_range;
4287  codec->color_primaries = par->color_primaries;
4288  codec->color_trc = par->color_trc;
4289  codec->colorspace = par->color_space;
4292  codec->has_b_frames = par->video_delay;
4293  break;
4294  case AVMEDIA_TYPE_AUDIO:
4295  codec->sample_fmt = par->format;
4296  codec->channel_layout = par->channel_layout;
4297  codec->channels = par->channels;
4298  codec->sample_rate = par->sample_rate;
4299  codec->block_align = par->block_align;
4300  codec->frame_size = par->frame_size;
4301  codec->delay =
4302  codec->initial_padding = par->initial_padding;
4303  codec->trailing_padding = par->trailing_padding;
4304  codec->seek_preroll = par->seek_preroll;
4305  break;
4306  case AVMEDIA_TYPE_SUBTITLE:
4307  codec->width = par->width;
4308  codec->height = par->height;
4309  break;
4310  }
4311 
4312  if (par->extradata) {
4313  av_freep(&codec->extradata);
4315  if (!codec->extradata)
4316  return AVERROR(ENOMEM);
4317  memcpy(codec->extradata, par->extradata, par->extradata_size);
4318  codec->extradata_size = par->extradata_size;
4319  }
4320 
4321  return 0;
4322 }
4323 
4324 int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
4325  void **data, size_t *sei_size)
4326 {
4327  AVFrameSideData *side_data = NULL;
4328  uint8_t *sei_data;
4329 
4330  if (frame)
4331  side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC);
4332 
4333  if (!side_data) {
4334  *data = NULL;
4335  return 0;
4336  }
4337 
4338  *sei_size = side_data->size + 11;
4339  *data = av_mallocz(*sei_size + prefix_len);
4340  if (!*data)
4341  return AVERROR(ENOMEM);
4342  sei_data = (uint8_t*)*data + prefix_len;
4343 
4344  // country code
4345  sei_data[0] = 181;
4346  sei_data[1] = 0;
4347  sei_data[2] = 49;
4348 
4349  /**
4350  * 'GA94' is standard in North America for ATSC, but hard coding
4351  * this style may not be the right thing to do -- other formats
4352  * do exist. This information is not available in the side_data
4353  * so we are going with this right now.
4354  */
4355  AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4'));
4356  sei_data[7] = 3;
4357  sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40;
4358  sei_data[9] = 0;
4359 
4360  memcpy(sei_data + 10, side_data->data, side_data->size);
4361 
4362  sei_data[side_data->size+10] = 255;
4363 
4364  return 0;
4365 }
4366 
4368 {
4369  AVRational framerate = avctx->framerate;
4370  int bits_per_coded_sample = avctx->bits_per_coded_sample;
4371  int64_t bitrate;
4372 
4373  if (!(framerate.num && framerate.den))
4374  framerate = av_inv_q(avctx->time_base);
4375  if (!(framerate.num && framerate.den))
4376  return 0;
4377 
4378  if (!bits_per_coded_sample) {
4380  bits_per_coded_sample = av_get_bits_per_pixel(desc);
4381  }
4382  bitrate = (int64_t)bits_per_coded_sample * avctx->width * avctx->height *
4383  framerate.num / framerate.den;
4384 
4385  return bitrate;
4386 }
int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
Get an estimated video bitrate based on frame size, frame rate and coded bits per pixel...
Definition: utils.c:4367
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:132
#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
const char * name
Definition: avisynth_c.h:775
#define FF_SANE_NB_CHANNELS
Definition: internal.h:73
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2956
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
Definition: avcodec.h:2010
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:82
void av_frame_set_channels(AVFrame *frame, int val)
#define CONFIG_FRAME_THREAD_ENCODER
Definition: config.h:591
enum AVChromaLocation chroma_location
Definition: avcodec.h:4156
float, planar
Definition: samplefmt.h:69
#define UTF8_MAX_BYTES
Definition: utils.c:2521
#define FF_SUB_CHARENC_MODE_PRE_DECODER
the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv ...
Definition: avcodec.h:3487
attribute_deprecated int av_packet_split_side_data(AVPacket *pkt)
Definition: avpacket.c:432
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1741
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:177
AVRational framerate
Definition: avcodec.h:3429
const char const char void * val
Definition: avisynth_c.h:771
#define avpriv_atomic_int_add_and_fetch
Definition: atomic_gcc.h:42
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:4147
static int64_t get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:1210
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:3450
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:3134
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:289
const char * s
Definition: avisynth_c.h:768
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:266
uint32_t fourcc
Definition: hwcontext_qsv.c:90
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:4154
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:74
static enum AVPixelFormat pix_fmt
#define AV_NUM_DATA_POINTERS
Definition: frame.h:188
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
int64_t av_frame_get_pkt_duration(const AVFrame *frame)
static int shift(int a, int b)
Definition: sonic.c:82
AVPacketSideDataType
Definition: avcodec.h:1397
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:259
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:106
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
Definition: avcodec.h:3486
int64_t pts_correction_num_faulty_dts
Number of incorrect PTS values so far.
Definition: avcodec.h:3467
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: utils.c:879
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:125
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
Definition: common.h:361
int size
unsigned int fourcc
Definition: raw.h:35
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:3152
int stride_align[AV_NUM_DATA_POINTERS]
Definition: internal.h:97
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:263
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:170
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:112
#define AV_CODEC_FLAG2_SKIP_MANUAL
Do not skip samples and export skip information as frame side data.
Definition: avcodec.h:972
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1934
int capabilities
Hardware accelerated codec capabilities.
Definition: avcodec.h:3834
const char * fmt
Definition: avisynth_c.h:769
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:3873
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
Unlock the mutex.
Definition: avcodec.h:6251
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVFrame * f
Definition: thread.h:36
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1797
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2373
AVFrame * to_free
Definition: internal.h:134
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1677
enum AVColorRange av_frame_get_color_range(const AVFrame *frame)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:370
const char * g
Definition: vf_curves.c:112
const char * desc
Definition: nvenc.c:60
int width
Definition: internal.h:96
#define LIBAVCODEC_VERSION_MICRO
Definition: version.h:32
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:173
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2285
AVRational sample_aspect_ratio
Video only.
Definition: avcodec.h:4142
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2771
static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
Definition: utils.c:2804
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: utils.c:3034
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:264
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: avcodec.h:1471
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1291
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:3465
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2469
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:388
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:4066
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int ff_unlock_avcodec(const AVCodec *codec)
Definition: utils.c:3931
int num
Numerator.
Definition: rational.h:59
#define FF_SUB_CHARENC_MODE_DO_NOTHING
do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for inst...
Definition: avcodec.h:3485
int size
Definition: avcodec.h:1658
const char * b
Definition: vf_curves.c:113
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:3470
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:3828
static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
Definition: utils.c:908
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:2143
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: utils.c:1788
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:201
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:1825
double, planar
Definition: samplefmt.h:70
enum AVMediaType codec_type
Definition: rtp.c:37
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: avcodec.h:759
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1960
enum AVPixelFormat pix_fmt
Definition: raw.h:34
int samples
Definition: internal.h:101
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
Definition: utils.c:2339
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:202
Mastering display metadata associated with a video frame.
Definition: frame.h:118
unsigned num_rects
Definition: avcodec.h:4046
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
Definition: utils.c:1200
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:120
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:269
The following 12 formats have the disadvantage of needing 1 format for each bit depth.
Definition: pixfmt.h:167
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1049
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:524
mpegvideo header.
enum AVMediaType type
Definition: avcodec.h:3694
static int convert_sub_to_old_ass_form(AVSubtitle *sub, const AVPacket *pkt, AVRational tb)
Definition: utils.c:2614
AVBufferPool * pools[4]
Pools for each data plane.
Definition: internal.h:90
static AVPacket pkt
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3133
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: utils.c:3997
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: utils.c:455
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:1069
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:2672
int trailing_padding
Audio only.
Definition: avcodec.h:4202
#define src
Definition: vp8dsp.c:254
int(* alloc_frame)(AVCodecContext *avctx, AVFrame *frame)
Allocate a custom buffer.
Definition: avcodec.h:3848
void av_frame_set_pkt_size(AVFrame *frame, int val)
int profile
profile
Definition: avcodec.h:3235
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:268
AVCodec.
Definition: avcodec.h:3681
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:139
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2531
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
This struct describes the properties of an encoded stream.
Definition: avcodec.h:4058
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:6248
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
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:210
#define FFMPEG_LICENSE
Definition: config.h:5
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:4030
enum AVColorSpace color_space
Definition: avcodec.h:4155
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:194
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2664
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:3829
static void * codec_mutex
Definition: utils.c:117
int(* receive_packet)(AVCodecContext *avctx, AVPacket *avpkt)
Definition: avcodec.h:3780
int frame_size
Audio only.
Definition: avcodec.h:4187
Mastering display metadata (based on SMPTE-2086:2014).
Definition: avcodec.h:1579
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1869
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:675
AVSubtitleRect ** rects
Definition: avcodec.h:4047
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:173
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
Definition: avcodec.h:3926
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:2559
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
Definition: utils.c:4040
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill AVFrame audio data and linesize pointers.
Definition: utils.c:478
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:168
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:1376
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), little-endian ...
Definition: pixfmt.h:191
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:440
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:3334
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:3052
static int volatile entangled_thread_counter
Definition: utils.c:116
#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:1019
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:230
Public dictionary API.
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:202
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
#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:102
HMTX pthread_mutex_t
Definition: os2threads.h:49
int height
Definition: internal.h:96
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Definition: utils.c:1056
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2502
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
Lock the mutex.
Definition: avcodec.h:6250
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AV_SAMPLE_FMT_U8
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
Opaque data information usually continuous.
Definition: avutil.h:203
int width
Video only.
Definition: avcodec.h:4132
int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict)
Unpack a dictionary from side_data.
Definition: avpacket.c:516
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:73
AVOptions.
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: utils.c:4171
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:152
const char * av_color_range_name(enum AVColorRange range)
Definition: pixdesc.c:2646
#define AV_RB32
Definition: intreadwrite.h:130
void * thread_ctx
Definition: internal.h:138
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static int setup_hwaccel(AVCodecContext *avctx, const enum AVPixelFormat fmt, const char *name)
Definition: utils.c:1075
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1675
static AVCodec * first_avcodec
Definition: utils.c:145
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: avcodec.h:1465
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:240
int trailing_padding
Audio only.
Definition: avcodec.h:3607
#define AV_WL8(p, d)
Definition: intreadwrite.h:404
Multithreading support functions.
#define AV_NE(be, le)
Definition: common.h:50
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:388
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:265
#define emms_c()
Definition: internal.h:54
#define FF_CODEC_PROPERTY_LOSSLESS
Definition: avcodec.h:3551
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
#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:1005
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1847
#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:4267
const AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: internal.h:144
static AVFrame * frame
planar YUV 4:2:0 40bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:203
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:4125
int planes
Definition: internal.h:99
Public header for CRC hash function implementation.
void * frame_thread_encoder
Definition: internal.h:152
int initial_padding
Audio only.
Definition: avcodec.h:4195
const char data[16]
Definition: mxf.c:90
Structure to hold side data for an AVFrame.
Definition: frame.h:149
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:286
int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Call avcodec_open2 recursively by decrementing counter, unlocking mutex, calling the function and the...
Definition: utils.c:1233
static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:884
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:290
uint8_t * data
Definition: avcodec.h:1657
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:186
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:644
static int flags
Definition: log.c:57
int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
does needed setup of pkt_pts/pos and such for (re)get_buffer();
Definition: utils.c:763
uint32_t tag
Definition: movenc.c:1418
#define AV_CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
Definition: avcodec.h:1030
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
#define AVERROR_EOF
End of file.
Definition: error.h:55
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:206
#define av_restrict
Definition: config.h:10
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
uint8_t * data
Definition: avcodec.h:1601
static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba, uint32_t tag, int bits_per_coded_sample, int64_t bitrate, uint8_t *extradata, int frame_size, int frame_bytes)
Definition: utils.c:3596
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:3141
void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val)
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:84
int(* init)(AVCodecContext *avctx)
Initialize the hwaccel private data.
Definition: avcodec.h:3918
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:3820
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
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 bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:3126
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian
Definition: pixfmt.h:292
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:225
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2901
The data represents the AVSphericalMapping structure defined in libavutil/spherical.h.
Definition: frame.h:129
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:896
signed 32 bits
Definition: samplefmt.h:62
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array.
Definition: mem.c:184
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
Definition: utils.c:4111
const OptionDef options[]
Definition: ffserver.c:3948
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:2476
static void codec_parameters_reset(AVCodecParameters *par)
Definition: utils.c:4151
#define FFALIGN(x, a)
Definition: macros.h:48
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4168
#define av_log(a,...)
const char * name
Definition: pixdesc.h:82
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:598
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1739
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
FramePool * pool
Definition: internal.h:136
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:4095
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: avcodec.h:2955
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1689
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:3157
void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val)
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:260
static av_cold void avcodec_init(void)
Definition: utils.c:156
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
#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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:168
#define AV_RL8(x)
Definition: intreadwrite.h:403
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:201
Libavcodec version macros.
av_cold int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:3066
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:86
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:3443
enum AVCodecID id
Definition: avcodec.h:3695
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:3705
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:182
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:176
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition: pixdesc.c:2670
static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
Definition: utils.c:2973
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:214
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:4192
int width
width and height of the video frame
Definition: frame.h:239
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:2054
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:3578
#define avpriv_atomic_ptr_cas
Definition: atomic_gcc.h:48
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
Create a mutex.
Definition: avcodec.h:6249
#define AV_BPRINT_SIZE_UNLIMITED
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:237
AVAudioServiceType
Definition: avcodec.h:825
#define MAKE_ACCESSORS(str, name, type, field)
Definition: internal.h:90
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:144
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: avcodec.h:1429
#define AVERROR(e)
Definition: error.h:43
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:350
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:3965
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
void av_packet_free_side_data(AVPacket *pkt)
Convenience function to free all the side data stored.
Definition: avpacket.c:270
int(* send_frame)(AVCodecContext *avctx, const AVFrame *frame)
Decode/encode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3777
int qmax
maximum quantizer
Definition: avcodec.h:2682
void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val)
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:148
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
Definition: avcodec.h:3468
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:3180
enum AVColorPrimaries color_primaries
Definition: avcodec.h:4153
attribute_deprecated int av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:253
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:4050
int video_delay
Video only.
Definition: avcodec.h:4161
static struct @253 state
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
Definition: utils.c:2923
const char * r
Definition: vf_curves.c:111
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
Definition: avstring.c:419
AVFrame * buffer_frame
Definition: internal.h:174
int capabilities
Codec capabilities.
Definition: avcodec.h:3700
int initial_padding
Audio only.
Definition: avcodec.h:3420
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:57
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:3799
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
#define av_fourcc2str(fourcc)
Definition: avutil.h:348
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:194
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:4062
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1640
const char * arg
Definition: jacosubdec.c:66
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:172
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1827
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:140
simple assert() macros that are a bit more flexible than ISO C assert().
planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:262
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
enum AVPacketSideDataType type
Definition: avcodec.h:1603
int av_log_get_level(void)
Get the current log level.
Definition: log.c:386
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
const char * name
Name of the codec implementation.
Definition: avcodec.h:3688
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:142
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:49
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:3615
const struct AVProfile * profiles
If non-NULL, an array of profiles recognized for this codec.
Definition: avcodec.h:722
int av_buffer_realloc(AVBufferRef **pbuf, int size)
Reallocate a given buffer.
Definition: buffer.c:169
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:195
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:82
#define FFMAX(a, b)
Definition: common.h:94
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:4181
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:3789
static void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.h:229
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:404
#define fail()
Definition: checkasm.h:89
const char av_codec_ffversion[]
Definition: utils.c:65
av_cold void ff_me_cmp_init_static(void)
Definition: me_cmp.c:980
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:1073
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:733
int priv_data_size
Size of the private data to allocate in AVCodecInternal.hwaccel_priv_data.
Definition: avcodec.h:3932
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1663
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2652
reference-counted frame API
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3063
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2545
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:4084
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, big-endian)
Definition: pixfmt.h:196
uint32_t end_display_time
Definition: avcodec.h:4045
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
int64_t pts
Same as packet pts, in AV_TIME_BASE.
Definition: avcodec.h:4048
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2709
int(* send_packet)(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: avcodec.h:3778
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:356
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: avcodec.h:711
static AVCodec ** last_avcodec
Definition: utils.c:146
int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options)
common internal API header
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:216
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
int refs
number of reference frames
Definition: avcodec.h:2413
static AVHWAccel * find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
Definition: utils.c:1063
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:301
int block_align
Audio only.
Definition: avcodec.h:4183
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:514
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:3702
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:416
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:3020
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3172
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:1024
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:3807
#define FFMIN(a, b)
Definition: common.h:96
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:3560
Raw Video Codec.
signed 32 bits, planar
Definition: samplefmt.h:68
volatile int ff_avcodec_locked
Definition: utils.c:115
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:384
static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
Definition: utils.c:751
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:3496
int channels
Definition: internal.h:100
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:1050
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
Definition: utils.c:4044
int width
picture width / height.
Definition: avcodec.h:1919
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3585
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:3236
int priv_data_size
Definition: avcodec.h:3717
int profile
Definition: avcodec.h:3670
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:158
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: avcodec.h:1585
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:884
void av_frame_set_pkt_pos(AVFrame *frame, int64_t val)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2448
AVFrameSideDataType
Definition: frame.h:47
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: os2threads.h:98
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:200
packed YUV 4:2:2, 16bpp, Y0 Cr Y1 Cb
Definition: pixfmt.h:222
uint16_t format
Definition: avcodec.h:4043
int level
level
Definition: avcodec.h:3333
#define FF_DEBUG_BUFFERS
Definition: avcodec.h:2998
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:4014
#define AV_RL32
Definition: intreadwrite.h:146
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), big-endian
Definition: pixfmt.h:192
#define CONFIG_GRAY
Definition: config.h:531
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:3708
int64_t reordered_opaque
opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:3045
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:3031
int n
Definition: avisynth_c.h:684
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:661
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
Definition: avcodec.h:2664
unsigned 8 bits, planar
Definition: samplefmt.h:66
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1878
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:257
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:169
enum AVCodecID codec_id
Definition: vaapi_decode.c:235
enum AVColorRange color_range
Video only.
Definition: avcodec.h:4152
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:3839
Opaque data information usually sparse.
Definition: avutil.h:205
int ff_alloc_packet(AVPacket *avpkt, int size)
Definition: utils.c:1780
const char * av_get_colorspace_name(enum AVColorSpace val)
Get the name of a colorspace.
Definition: frame.c:83
static pthread_mutex_t * mutex
Definition: w32pthreads.h:258
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:616
enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
Definition: utils.c:1039
char * sub_charenc
DTS of the last frame.
Definition: avcodec.h:3476
if(ret< 0)
Definition: vf_mcdeint.c:282
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:178
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:4025
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:167
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
Definition: error.h:72
#define FF_ARRAY_ELEMS(a)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:3190
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:3161
int linesize[4]
Definition: internal.h:98
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:476
int sub_charenc_mode
Subtitles character encoding mode.
Definition: avcodec.h:3484
int av_codec_get_max_lowres(const AVCodec *codec)
Definition: utils.c:1195
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.
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:302
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
Definition: utils.c:3476
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:251
const AVS_VideoInfo int align
Definition: avisynth_c.h:795
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:2868
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:3425
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2514
#define attribute_align_arg
Definition: internal.h:61
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1346
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:84
static int width
Definition: utils.c:158
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:140
int frame_size
Definition: mxfenc.c:1820
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:237
int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: utils.c:731
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:111
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1740
A list of zero terminated key/value strings.
Definition: avcodec.h:1529
int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
Definition: utils.c:2230
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:83
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:51
enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be)
Return the PCM codec associated with a sample format.
Definition: utils.c:3556
enum AVCodecID codec_id
Definition: avcodec.h:1749
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
int seek_preroll
Number of samples to skip after a discontinuity.
Definition: avcodec.h:3508
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:536
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1589
int sample_rate
samples per second
Definition: avcodec.h:2494
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
int debug
debug
Definition: avcodec.h:2973
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:184
main external API structure.
Definition: avcodec.h:1732
int(* receive_frame)(AVCodecContext *avctx, AVFrame *frame)
Definition: avcodec.h:3779
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:3171
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:589
static int recode_subtitle(AVCodecContext *avctx, AVPacket *outpkt, const AVPacket *inpkt)
Definition: utils.c:2522
int skip_samples_multiplier
Definition: internal.h:178
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:204
uint8_t * data
The data buffer.
Definition: buffer.h:89
int qmin
minimum quantizer
Definition: avcodec.h:2675
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:2785
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:266
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:1764
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:63
uint8_t * data
Definition: frame.h:151
static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
Definition: utils.c:2106
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Definition: pixfmt.h:291
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:3004
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
Definition: avcodec.h:754
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:271
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:213
void * buf
Definition: avisynth_c.h:690
int extradata_size
Definition: avcodec.h:1848
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
int(* close)(AVCodecContext *)
Definition: avcodec.h:3765
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:3806
struct AVCodec * next
Definition: avcodec.h:3718
int nb_coded_side_data
Definition: avcodec.h:3561
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
planar YUV 4:2:2 48bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:205
AVCodecContext * owner[2]
Definition: thread.h:37
static int utf8_check(const uint8_t *str)
Definition: utils.c:2580
int coded_height
Definition: avcodec.h:1934
int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:346
enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame)
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:67
Describe the class of an AVClass context structure.
Definition: log.h:67
int sample_rate
Sample rate of the audio data.
Definition: frame.h:351
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:3552
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:2649
int showed_multi_packet_warning
Definition: internal.h:176
int av_frame_get_channels(const AVFrame *frame)
Definition: f_ebur128.c:91
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:89
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:207
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:667
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:231
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
Definition: avcodec.h:1044
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:275
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:119
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2462
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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:1971
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2455
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:4008
#define CONFIG_MEMORY_POISONING
Definition: config.h:569
const char * name
short name for the profile
Definition: avcodec.h:3671
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:4210
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_YASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
Definition: audioconvert.c:56
Recommmends skipping the specified number of samples.
Definition: avcodec.h:1513
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:117
planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:258
int sub_text_format
Control the form of AVSubtitle.rects[N]->ass.
Definition: avcodec.h:3592
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:379
int buffer_pkt_valid
Definition: internal.h:173
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:157
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:270
static FF_ENABLE_DEPRECATION_WARNINGS AVHWAccel * first_hwaccel
Definition: utils.c:3856
char * codec_whitelist
&#39;,&#39; separated list of allowed decoders.
Definition: avcodec.h:3543
planar YUV 4:2:0 22.5bpp, (1 Cr & Cb sample per 2x2 Y & A samples), big-endian
Definition: pixfmt.h:190
const VDPAUPixFmtMap * map
#define STRIDE_ALIGN
Definition: internal.h:82
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:703
enum AVChromaLocation chroma_location
Definition: frame.h:436
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:1245
#define snprintf
Definition: snprintf.h:34
static void insert_ts(AVBPrint *buf, int ts)
Definition: utils.c:2600
static AVHWAccel ** last_hwaccel
Definition: utils.c:3857
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:3780
static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
Definition: utils.c:3125
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:93
mfxU16 profile
Definition: qsvenc.c:44
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:3868
int seek_preroll
Audio only.
Definition: avcodec.h:4206
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:695
int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:4055
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:280
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:498
static int64_t pts
Global timestamp for the audio frames.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:79
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, little-endian)
Definition: pixfmt.h:199
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:3176
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: avcodec.h:1456
#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:956
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: avcodec.h:4121
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3707
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_YASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:174
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:143
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
void ff_color_frame(AVFrame *frame, const int c[4])
Definition: utils.c:708
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:279
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
int sample_rate
Audio only.
Definition: avcodec.h:4176
enum AVMediaType type
Definition: avcodec.h:697
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: avcodec.h:3706
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:172
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:287
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:78
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:261
Y , 8bpp.
Definition: pixfmt.h:70
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1544
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
Definition: avcodec.h:1696
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3764
common internal api header.
enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos)
Converts swscale x/y chroma position to AVChromaLocation.
Definition: utils.c:467
Free mutex resources.
Definition: avcodec.h:6252
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
Definition: buffer.c:238
int avpriv_lock_avformat(void)
Definition: utils.c:3947
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: internal.h:60
#define HWACCEL_CODEC_CAP_EXPERIMENTAL
HWAccel is experimental and is thus avoided in favor of non experimental codecs.
Definition: avcodec.h:1283
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:3859
struct AVHWAccel * next
Definition: avcodec.h:3843
#define AV_CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: avcodec.h:1065
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static int64_t guess_correct_pts(AVCodecContext *ctx, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
Definition: utils.c:2080
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:3785
signed 16 bits
Definition: samplefmt.h:61
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:183
int(* init)(AVCodecContext *)
Definition: avcodec.h:3749
static double c[64]
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: avcodec.h:4126
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:2658
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:162
uint32_t start_display_time
Definition: avcodec.h:4044
void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call...
Definition: utils.c:132
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:3750
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
AVProfile.
Definition: avcodec.h:3669
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:141
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: utils.c:4026
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:3152
enum AVCodecID id
Codec implemented by the hardware accelerator.
Definition: avcodec.h:3821
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:4018
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:87
static const uint64_t c2
Definition: murmur3.c:50
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:339
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int caps_internal
Internal codec capabilities.
Definition: avcodec.h:3790
unsigned properties
Definition: avcodec.h:3550
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
#define CONFIG_ME_CMP
Definition: config.h:619
int den
Denominator.
Definition: rational.h:60
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:1026
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:252
unsigned bps
Definition: movenc.c:1419
planar YUV 4:2:0 25bpp, (1 Cr & Cb sample per 2x2 Y & A samples, little-endian)
Definition: pixfmt.h:197
#define FFMPEG_CONFIGURATION
Definition: config.h:4
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:769
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:3230
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:888
static int lowres
Definition: ffplay.c:332
void * priv_data
Definition: avcodec.h:1774
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:3210
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition: avcodec.h:4002
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
Definition: utils.c:3905
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill plane data pointers and linesize for samples with sample format sample_fmt.
Definition: samplefmt.c:151
static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:966
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
#define av_free(p)
static void get_subtitle_defaults(AVSubtitle *sub)
Definition: utils.c:1204
uint8_t * dump_separator
dump format separator.
Definition: avcodec.h:3535
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3762
#define TAG_PRINT(x)
#define FFMPEG_VERSION
Definition: ffversion.h:4
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:267
as in Berlin toast format
Definition: avcodec.h:567
int len
int channels
number of audio channels
Definition: avcodec.h:2495
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
Definition: os2threads.h:120
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:3703
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1782
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:3453
Y , 16bpp, little-endian.
Definition: pixfmt.h:99
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:51
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:4037
This side data corresponds to the AVCPBProperties struct.
Definition: avcodec.h:1502
static void * avformat_mutex
Definition: utils.c:118
unsigned av_codec_get_codec_properties(const AVCodecContext *codec)
Definition: utils.c:1190
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:272
Not part of ABI.
Definition: pixfmt.h:503
signed 64 bits, planar
Definition: samplefmt.h:72
#define AV_FRAME_FLAG_DISCARD
A flag to mark the frames which need to be decoded, but shouldn&#39;t be output.
Definition: frame.h:408
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:1834
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:4108
enum AVColorPrimaries color_primaries
Definition: frame.h:425
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:4080
static const struct twinvq_data tab
unsigned int byte_buffer_size
Definition: internal.h:150
#define HAVE_THREADS
Definition: config.h:388
int channels
Audio only.
Definition: avcodec.h:4172
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:4022
planar YUV 4:2:2 30bpp, (1 Cr & Cb sample per 2x1 Y & A samples, big-endian)
Definition: pixfmt.h:198
static int height
Definition: utils.c:158
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1656
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
av_cold void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:178
int64_t pts_correction_last_dts
PTS of the last frame.
Definition: avcodec.h:3469
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
Definition: avcodec.h:905
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2525
int height
Definition: frame.h:239
void ff_frame_thread_encoder_free(AVCodecContext *avctx)
#define av_freep(p)
void INT64 INT64 count
Definition: avisynth_c.h:690
int64_t pts_correction_num_faulty_pts
Current statistics for PTS correction.
Definition: avcodec.h:3466
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
enum AVFieldOrder field_order
Field order.
Definition: avcodec.h:2491
signed 16 bits, planar
Definition: samplefmt.h:67
static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
Definition: utils.c:2184
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:3747
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:495
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:427
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:1115
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:3973
static int(* lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:111
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:187
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
Definition: os2threads.h:113
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:251
Recommmends skipping the specified number of samples.
Definition: frame.h:107
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:334
#define av_malloc_array(a, b)
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3704
AVMatrixEncoding
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:4002
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:4070
#define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS
Definition: avcodec.h:3595
int ff_alloc_entries(AVCodecContext *avctx, int count)
Definition: utils.c:4031
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
Definition: utils.c:4324
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:2249
planar YUV 4:2:2 27bpp, (1 Cr & Cb sample per 2x1 Y & A samples), little-endian
Definition: pixfmt.h:193
int avpriv_unlock_avformat(void)
Definition: utils.c:3956
const uint8_t * avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, uint32_t *av_restrict state)
Definition: utils.c:4078
int debug_mv
debug
Definition: avcodec.h:3009
void ff_reset_entries(AVCodecContext *avctx)
Definition: utils.c:4036
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:75
int depth
Number of bits in the component.
Definition: pixdesc.h:58
enum AVSubtitleType type
Definition: avcodec.h:4028
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:234
#define MKTAG(a, b, c, d)
Definition: common.h:342
int format
Definition: internal.h:95
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:231
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:3637
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:83
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:215
float min
enum AVCodecID id
Stereoscopic 3d metadata.
Definition: frame.h:62
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1634
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:149
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:3438
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: utils.c:2056
static int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
Definition: mem_internal.h:27
int delay
Codec delay.
Definition: avcodec.h:1902
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:1389
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:244
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:994
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:2951
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:256
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:1650
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:175
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3436
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:260
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:596
#define FFMAX3(a, b, c)
Definition: common.h:95
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:185
#define tb
Definition: regdef.h:68
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:1013
#define AV_WL32(p, v)
Definition: intreadwrite.h:431
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:2732
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...
Definition: internal.h:132
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: avcodec.h:1477
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:3365
static uint8_t tmp[11]
Definition: aes_ctr.c:26
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:171