utils.c
Go to the documentation of this file.
1 /*
2  * utils for libavcodec
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
31 #include "libavutil/crc.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/imgutils.h"
35 #include "libavutil/samplefmt.h"
36 #include "libavutil/dict.h"
37 #include "avcodec.h"
38 #include "dsputil.h"
39 #include "libavutil/opt.h"
40 #include "thread.h"
41 #include "internal.h"
42 #include "bytestream.h"
43 #include <stdlib.h>
44 #include <stdarg.h>
45 #include <limits.h>
46 #include <float.h>
47 
48 static int volatile entangled_thread_counter = 0;
49 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
50 static void *codec_mutex;
51 static void *avformat_mutex;
52 
53 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
54 {
55  if (min_size < *size)
56  return ptr;
57 
58  min_size = FFMAX(17 * min_size / 16 + 32, min_size);
59 
60  ptr = av_realloc(ptr, min_size);
61  /* we could set this to the unmodified min_size but this is safer
62  * if the user lost the ptr and uses NULL now
63  */
64  if (!ptr)
65  min_size = 0;
66 
67  *size = min_size;
68 
69  return ptr;
70 }
71 
72 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
73 {
74  void **p = ptr;
75  if (min_size < *size)
76  return;
77  min_size = FFMAX(17 * min_size / 16 + 32, min_size);
78  av_free(*p);
79  *p = av_malloc(min_size);
80  if (!*p)
81  min_size = 0;
82  *size = min_size;
83 }
84 
85 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
86 {
87  void **p = ptr;
88  if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
89  av_freep(p);
90  *size = 0;
91  return;
92  }
93  av_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE);
94  if (*size)
95  memset((uint8_t *)*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
96 }
97 
98 /* encoder management */
100 
102 {
103  if (c)
104  return c->next;
105  else
106  return first_avcodec;
107 }
108 
109 static void avcodec_init(void)
110 {
111  static int initialized = 0;
112 
113  if (initialized != 0)
114  return;
115  initialized = 1;
116 
118 }
119 
120 int av_codec_is_encoder(const AVCodec *codec)
121 {
122  return codec && (codec->encode_sub || codec->encode2);
123 }
124 
125 int av_codec_is_decoder(const AVCodec *codec)
126 {
127  return codec && codec->decode;
128 }
129 
131 {
132  AVCodec **p;
133  avcodec_init();
134  p = &first_avcodec;
135  while (*p != NULL)
136  p = &(*p)->next;
137  *p = codec;
138  codec->next = NULL;
139 
140  if (codec->init_static_data)
141  codec->init_static_data(codec);
142 }
143 
145 {
146  return EDGE_WIDTH;
147 }
148 
150 {
151  s->coded_width = width;
152  s->coded_height = height;
153  s->width = width;
154  s->height = height;
155 }
156 
157 #define INTERNAL_BUFFER_SIZE (32 + 1)
158 
160  int linesize_align[AV_NUM_DATA_POINTERS])
161 {
162  int i;
163  int w_align = 1;
164  int h_align = 1;
165 
166  switch (s->pix_fmt) {
167  case AV_PIX_FMT_YUV420P:
168  case AV_PIX_FMT_YUYV422:
169  case AV_PIX_FMT_UYVY422:
170  case AV_PIX_FMT_YUV422P:
171  case AV_PIX_FMT_YUV440P:
172  case AV_PIX_FMT_YUV444P:
173  case AV_PIX_FMT_GBRP:
174  case AV_PIX_FMT_GRAY8:
175  case AV_PIX_FMT_GRAY16BE:
176  case AV_PIX_FMT_GRAY16LE:
177  case AV_PIX_FMT_YUVJ420P:
178  case AV_PIX_FMT_YUVJ422P:
179  case AV_PIX_FMT_YUVJ440P:
180  case AV_PIX_FMT_YUVJ444P:
181  case AV_PIX_FMT_YUVA420P:
182  case AV_PIX_FMT_YUVA422P:
183  case AV_PIX_FMT_YUVA444P:
196  case AV_PIX_FMT_GBRP9LE:
197  case AV_PIX_FMT_GBRP9BE:
198  case AV_PIX_FMT_GBRP10LE:
199  case AV_PIX_FMT_GBRP10BE:
200  w_align = 16; //FIXME assume 16 pixel per macroblock
201  h_align = 16 * 2; // interlaced needs 2 macroblocks height
202  break;
203  case AV_PIX_FMT_YUV411P:
205  w_align = 32;
206  h_align = 8;
207  break;
208  case AV_PIX_FMT_YUV410P:
209  if (s->codec_id == AV_CODEC_ID_SVQ1) {
210  w_align = 64;
211  h_align = 64;
212  }
213  case AV_PIX_FMT_RGB555:
214  if (s->codec_id == AV_CODEC_ID_RPZA) {
215  w_align = 4;
216  h_align = 4;
217  }
218  case AV_PIX_FMT_PAL8:
219  case AV_PIX_FMT_BGR8:
220  case AV_PIX_FMT_RGB8:
221  if (s->codec_id == AV_CODEC_ID_SMC) {
222  w_align = 4;
223  h_align = 4;
224  }
225  break;
226  case AV_PIX_FMT_BGR24:
227  if ((s->codec_id == AV_CODEC_ID_MSZH) ||
228  (s->codec_id == AV_CODEC_ID_ZLIB)) {
229  w_align = 4;
230  h_align = 4;
231  }
232  break;
233  default:
234  w_align = 1;
235  h_align = 1;
236  break;
237  }
238 
239  *width = FFALIGN(*width, w_align);
240  *height = FFALIGN(*height, h_align);
241  if (s->codec_id == AV_CODEC_ID_H264)
242  // some of the optimized chroma MC reads one line too much
243  *height += 2;
244 
245  for (i = 0; i < 4; i++)
246  linesize_align[i] = STRIDE_ALIGN;
247 }
248 
250 {
252  int chroma_shift = desc->log2_chroma_w;
253  int linesize_align[AV_NUM_DATA_POINTERS];
254  int align;
255 
256  avcodec_align_dimensions2(s, width, height, linesize_align);
257  align = FFMAX(linesize_align[0], linesize_align[3]);
258  linesize_align[1] <<= chroma_shift;
259  linesize_align[2] <<= chroma_shift;
260  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
261  *width = FFALIGN(*width, align);
262 }
263 
265  enum AVSampleFormat sample_fmt, const uint8_t *buf,
266  int buf_size, int align)
267 {
268  int ch, planar, needed_size, ret = 0;
269 
270  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
271  frame->nb_samples, sample_fmt,
272  align);
273  if (buf_size < needed_size)
274  return AVERROR(EINVAL);
275 
276  planar = av_sample_fmt_is_planar(sample_fmt);
277  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
278  if (!(frame->extended_data = av_mallocz(nb_channels *
279  sizeof(*frame->extended_data))))
280  return AVERROR(ENOMEM);
281  } else {
282  frame->extended_data = frame->data;
283  }
284 
285  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
286  buf, nb_channels, frame->nb_samples,
287  sample_fmt, align)) < 0) {
288  if (frame->extended_data != frame->data)
289  av_free(frame->extended_data);
290  return ret;
291  }
292  if (frame->extended_data != frame->data) {
293  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
294  frame->data[ch] = frame->extended_data[ch];
295  }
296 
297  return ret;
298 }
299 
300 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
301 {
302  AVCodecInternal *avci = avctx->internal;
303  int buf_size, ret;
304 
305  av_freep(&avci->audio_data);
306  buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
307  frame->nb_samples, avctx->sample_fmt,
308  0);
309  if (buf_size < 0)
310  return AVERROR(EINVAL);
311 
312  frame->data[0] = av_mallocz(buf_size);
313  if (!frame->data[0])
314  return AVERROR(ENOMEM);
315 
316  ret = avcodec_fill_audio_frame(frame, avctx->channels, avctx->sample_fmt,
317  frame->data[0], buf_size, 0);
318  if (ret < 0) {
319  av_freep(&frame->data[0]);
320  return ret;
321  }
322 
323  avci->audio_data = frame->data[0];
324  if (avctx->debug & FF_DEBUG_BUFFERS)
325  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
326  "internal audio buffer used\n", frame);
327 
328  return 0;
329 }
330 
332 {
333  int i;
334  int w = s->width;
335  int h = s->height;
336  InternalBuffer *buf;
337  AVCodecInternal *avci = s->internal;
338 
339  if (pic->data[0] != NULL) {
340  av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
341  return -1;
342  }
343  if (avci->buffer_count >= INTERNAL_BUFFER_SIZE) {
344  av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n");
345  return -1;
346  }
347 
348  if (av_image_check_size(w, h, 0, s))
349  return -1;
350 
351  if (!avci->buffer) {
352  avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE + 1) *
353  sizeof(InternalBuffer));
354  }
355 
356  buf = &avci->buffer[avci->buffer_count];
357 
358  if (buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)) {
359  for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
360  av_freep(&buf->base[i]);
361  buf->data[i] = NULL;
362  }
363  }
364 
365  if (!buf->base[0]) {
366  int h_chroma_shift, v_chroma_shift;
367  int size[4] = { 0 };
368  int tmpsize;
369  int unaligned;
371  int stride_align[AV_NUM_DATA_POINTERS];
373  const int pixel_size = desc->comp[0].step_minus1 + 1;
374 
375  av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift,
376  &v_chroma_shift);
377 
378  avcodec_align_dimensions2(s, &w, &h, stride_align);
379 
380  if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {
381  w += EDGE_WIDTH * 2;
382  h += EDGE_WIDTH * 2;
383  }
384 
385  do {
386  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
387  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
388  av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
389  // increase alignment of w for next try (rhs gives the lowest bit set in w)
390  w += w & ~(w - 1);
391 
392  unaligned = 0;
393  for (i = 0; i < 4; i++)
394  unaligned |= picture.linesize[i] % stride_align[i];
395  } while (unaligned);
396 
397  tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
398  if (tmpsize < 0)
399  return -1;
400 
401  for (i = 0; i < 3 && picture.data[i + 1]; i++)
402  size[i] = picture.data[i + 1] - picture.data[i];
403  size[i] = tmpsize - (picture.data[i] - picture.data[0]);
404 
405  memset(buf->base, 0, sizeof(buf->base));
406  memset(buf->data, 0, sizeof(buf->data));
407 
408  for (i = 0; i < 4 && size[i]; i++) {
409  const int h_shift = i == 0 ? 0 : h_chroma_shift;
410  const int v_shift = i == 0 ? 0 : v_chroma_shift;
411 
412  buf->linesize[i] = picture.linesize[i];
413 
414  buf->base[i] = av_malloc(size[i] + 16); //FIXME 16
415  if (buf->base[i] == NULL)
416  return -1;
417  memset(buf->base[i], 128, size[i]);
418 
419  // no edge if EDGE EMU or not planar YUV
420  if ((s->flags & CODEC_FLAG_EMU_EDGE) || !size[2])
421  buf->data[i] = buf->base[i];
422  else
423  buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i] * EDGE_WIDTH >> v_shift) + (pixel_size * EDGE_WIDTH >> h_shift), stride_align[i]);
424  }
425  for (; i < AV_NUM_DATA_POINTERS; i++) {
426  buf->base[i] = buf->data[i] = NULL;
427  buf->linesize[i] = 0;
428  }
429  if (size[1] && !size[2])
430  avpriv_set_systematic_pal2((uint32_t *)buf->data[1], s->pix_fmt);
431  buf->width = s->width;
432  buf->height = s->height;
433  buf->pix_fmt = s->pix_fmt;
434  }
435 
436  for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
437  pic->base[i] = buf->base[i];
438  pic->data[i] = buf->data[i];
439  pic->linesize[i] = buf->linesize[i];
440  }
441  pic->extended_data = pic->data;
442  avci->buffer_count++;
443 
444  if (s->debug & FF_DEBUG_BUFFERS)
445  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
446  "buffers used\n", pic, avci->buffer_count);
447 
448  return 0;
449 }
450 
452 {
453  frame->type = FF_BUFFER_TYPE_INTERNAL;
454  switch (avctx->codec_type) {
455  case AVMEDIA_TYPE_VIDEO:
456  return video_get_buffer(avctx, frame);
457  case AVMEDIA_TYPE_AUDIO:
458  return audio_get_buffer(avctx, frame);
459  default:
460  return -1;
461  }
462 }
463 
465 {
466  switch (avctx->codec_type) {
467  case AVMEDIA_TYPE_VIDEO:
468  frame->width = avctx->width;
469  frame->height = avctx->height;
470  frame->format = avctx->pix_fmt;
472  break;
473  case AVMEDIA_TYPE_AUDIO:
474  frame->sample_rate = avctx->sample_rate;
475  frame->format = avctx->sample_fmt;
476  frame->channel_layout = avctx->channel_layout;
477  break;
478  default: return AVERROR(EINVAL);
479  }
480 
481  frame->pkt_pts = avctx->pkt ? avctx->pkt->pts : AV_NOPTS_VALUE;
482  frame->reordered_opaque = avctx->reordered_opaque;
483 
484  return avctx->get_buffer(avctx, frame);
485 }
486 
488 {
489  int i;
490  InternalBuffer *buf, *last;
491  AVCodecInternal *avci = s->internal;
492 
493  assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
494 
495  assert(pic->type == FF_BUFFER_TYPE_INTERNAL);
496  assert(avci->buffer_count);
497 
498  if (avci->buffer) {
499  buf = NULL; /* avoids warning */
500  for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize
501  buf = &avci->buffer[i];
502  if (buf->data[0] == pic->data[0])
503  break;
504  }
505  assert(i < avci->buffer_count);
506  avci->buffer_count--;
507  last = &avci->buffer[avci->buffer_count];
508 
509  if (buf != last)
510  FFSWAP(InternalBuffer, *buf, *last);
511  }
512 
513  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
514  pic->data[i] = NULL;
515 // pic->base[i]=NULL;
516 
517  if (s->debug & FF_DEBUG_BUFFERS)
518  av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "
519  "buffers used\n", pic, avci->buffer_count);
520 }
521 
523 {
524  AVFrame temp_pic;
525  int i;
526 
527  assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
528 
529  /* If no picture return a new buffer */
530  if (pic->data[0] == NULL) {
531  /* We will copy from buffer, so must be readable */
533  return ff_get_buffer(s, pic);
534  }
535 
536  assert(s->pix_fmt == pic->format);
537 
538  /* If internal buffer type return the same buffer */
539  if (pic->type == FF_BUFFER_TYPE_INTERNAL) {
540  if (s->pkt)
541  pic->pkt_pts = s->pkt->pts;
542  else
543  pic->pkt_pts = AV_NOPTS_VALUE;
545  return 0;
546  }
547 
548  /*
549  * Not internal type and reget_buffer not overridden, emulate cr buffer
550  */
551  temp_pic = *pic;
552  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
553  pic->data[i] = pic->base[i] = NULL;
554  pic->opaque = NULL;
555  /* Allocate new frame */
556  if (ff_get_buffer(s, pic))
557  return -1;
558  /* Copy image data from old buffer to new buffer */
559  av_picture_copy((AVPicture *)pic, (AVPicture *)&temp_pic, s->pix_fmt, s->width,
560  s->height);
561  s->release_buffer(s, &temp_pic); // Release old frame
562  return 0;
563 }
564 
565 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
566 {
567  int i;
568 
569  for (i = 0; i < count; i++) {
570  int r = func(c, (char *)arg + i * size);
571  if (ret)
572  ret[i] = r;
573  }
574  return 0;
575 }
576 
577 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
578 {
579  int i;
580 
581  for (i = 0; i < count; i++) {
582  int r = func(c, arg, i, 0);
583  if (ret)
584  ret[i] = r;
585  }
586  return 0;
587 }
588 
590 {
591  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
592  return desc->flags & PIX_FMT_HWACCEL;
593 }
594 
596 {
597  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
598  ++fmt;
599  return fmt[0];
600 }
601 
603 {
604  if (frame->extended_data != frame->data)
605  av_freep(&frame->extended_data);
606 
607  memset(frame, 0, sizeof(AVFrame));
608 
609  frame->pts = AV_NOPTS_VALUE;
610  frame->key_frame = 1;
611  frame->sample_aspect_ratio = (AVRational) {0, 1 };
612  frame->format = -1; /* unknown */
613  frame->extended_data = frame->data;
614 }
615 
617 {
618  AVFrame *frame = av_mallocz(sizeof(AVFrame));
619 
620  if (frame == NULL)
621  return NULL;
622 
624 
625  return frame;
626 }
627 
629 {
630  AVFrame *f;
631 
632  if (!frame || !*frame)
633  return;
634 
635  f = *frame;
636 
637  if (f->extended_data != f->data)
638  av_freep(&f->extended_data);
639 
640  av_freep(frame);
641 }
642 
644 {
645  int ret = 0;
646  AVDictionary *tmp = NULL;
647 
648  if (avcodec_is_open(avctx))
649  return 0;
650 
651  if ((!codec && !avctx->codec)) {
652  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
653  return AVERROR(EINVAL);
654  }
655  if ((codec && avctx->codec && codec != avctx->codec)) {
656  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
657  "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
658  return AVERROR(EINVAL);
659  }
660  if (!codec)
661  codec = avctx->codec;
662 
663  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
664  return AVERROR(EINVAL);
665 
666  if (options)
667  av_dict_copy(&tmp, *options, 0);
668 
669  /* If there is a user-supplied mutex locking routine, call it. */
670  if (ff_lockmgr_cb) {
672  return -1;
673  }
674 
676  if (entangled_thread_counter != 1) {
677  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
678  ret = -1;
679  goto end;
680  }
681 
682  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
683  if (!avctx->internal) {
684  ret = AVERROR(ENOMEM);
685  goto end;
686  }
687 
688  if (codec->priv_data_size > 0) {
689  if (!avctx->priv_data) {
690  avctx->priv_data = av_mallocz(codec->priv_data_size);
691  if (!avctx->priv_data) {
692  ret = AVERROR(ENOMEM);
693  goto end;
694  }
695  if (codec->priv_class) {
696  *(const AVClass **)avctx->priv_data = codec->priv_class;
698  }
699  }
700  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
701  goto free_and_end;
702  } else {
703  avctx->priv_data = NULL;
704  }
705  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
706  goto free_and_end;
707 
708  if (avctx->coded_width && avctx->coded_height)
709  avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
710  else if (avctx->width && avctx->height)
711  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
712 
713  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
714  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
715  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
716  av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
717  avcodec_set_dimensions(avctx, 0, 0);
718  }
719 
720  /* if the decoder init function was already called previously,
721  * free the already allocated subtitle_header before overwriting it */
722  if (av_codec_is_decoder(codec))
723  av_freep(&avctx->subtitle_header);
724 
725  if (avctx->channels > FF_SANE_NB_CHANNELS) {
726  ret = AVERROR(EINVAL);
727  goto free_and_end;
728  }
729 
730  avctx->codec = codec;
731  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
732  avctx->codec_id == AV_CODEC_ID_NONE) {
733  avctx->codec_type = codec->type;
734  avctx->codec_id = codec->id;
735  }
736  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
737  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
738  av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
739  ret = AVERROR(EINVAL);
740  goto free_and_end;
741  }
742  avctx->frame_number = 0;
743 
744  if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
746  ret = AVERROR_EXPERIMENTAL;
747  goto free_and_end;
748  }
749 
750  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
751  (!avctx->time_base.num || !avctx->time_base.den)) {
752  avctx->time_base.num = 1;
753  avctx->time_base.den = avctx->sample_rate;
754  }
755 
756  if (HAVE_THREADS && !avctx->thread_opaque) {
757  ret = ff_thread_init(avctx);
758  if (ret < 0) {
759  goto free_and_end;
760  }
761  }
763  avctx->thread_count = 1;
764 
765  if (av_codec_is_encoder(avctx->codec)) {
766  int i;
767  if (avctx->codec->sample_fmts) {
768  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
769  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
770  break;
771  if (avctx->channels == 1 &&
774  avctx->sample_fmt = avctx->codec->sample_fmts[i];
775  break;
776  }
777  }
778  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
779  av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
780  ret = AVERROR(EINVAL);
781  goto free_and_end;
782  }
783  }
784  if (avctx->codec->pix_fmts) {
785  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
786  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
787  break;
788  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
789  av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n");
790  ret = AVERROR(EINVAL);
791  goto free_and_end;
792  }
793  }
794  if (avctx->codec->supported_samplerates) {
795  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
796  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
797  break;
798  if (avctx->codec->supported_samplerates[i] == 0) {
799  av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
800  ret = AVERROR(EINVAL);
801  goto free_and_end;
802  }
803  }
804  if (avctx->codec->channel_layouts) {
805  if (!avctx->channel_layout) {
806  av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
807  } else {
808  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
809  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
810  break;
811  if (avctx->codec->channel_layouts[i] == 0) {
812  av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
813  ret = AVERROR(EINVAL);
814  goto free_and_end;
815  }
816  }
817  }
818  if (avctx->channel_layout && avctx->channels) {
820  av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
821  ret = AVERROR(EINVAL);
822  goto free_and_end;
823  }
824  } else if (avctx->channel_layout) {
826  }
827 
828  if (!avctx->rc_initial_buffer_occupancy)
829  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
830  }
831 
832  if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) {
833  ret = avctx->codec->init(avctx);
834  if (ret < 0) {
835  goto free_and_end;
836  }
837  }
838 
839  if (av_codec_is_decoder(avctx->codec)) {
840  /* validate channel layout from the decoder */
841  if (avctx->channel_layout) {
842  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
843  if (!avctx->channels)
844  avctx->channels = channels;
845  else if (channels != avctx->channels) {
846  av_log(avctx, AV_LOG_WARNING,
847  "channel layout does not match number of channels\n");
848  avctx->channel_layout = 0;
849  }
850  }
851  if (avctx->channels && avctx->channels < 0 ||
852  avctx->channels > FF_SANE_NB_CHANNELS) {
853  ret = AVERROR(EINVAL);
854  goto free_and_end;
855  }
856  }
857 end:
859 
860  /* Release any user-supplied mutex. */
861  if (ff_lockmgr_cb) {
862  (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
863  }
864  if (options) {
865  av_dict_free(options);
866  *options = tmp;
867  }
868 
869  return ret;
870 free_and_end:
871  av_dict_free(&tmp);
872  av_freep(&avctx->priv_data);
873  av_freep(&avctx->internal);
874  avctx->codec = NULL;
875  goto end;
876 }
877 
878 int ff_alloc_packet(AVPacket *avpkt, int size)
879 {
880  if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
881  return AVERROR(EINVAL);
882 
883  if (avpkt->data) {
884  void *destruct = avpkt->destruct;
885 
886  if (avpkt->size < size)
887  return AVERROR(EINVAL);
888 
889  av_init_packet(avpkt);
890  avpkt->destruct = destruct;
891  avpkt->size = size;
892  return 0;
893  } else {
894  return av_new_packet(avpkt, size);
895  }
896 }
897 
901 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
902 {
903  AVFrame *frame = NULL;
904  uint8_t *buf = NULL;
905  int ret;
906 
907  if (!(frame = avcodec_alloc_frame()))
908  return AVERROR(ENOMEM);
909  *frame = *src;
910 
911  if ((ret = av_samples_get_buffer_size(&frame->linesize[0], s->channels,
912  s->frame_size, s->sample_fmt, 0)) < 0)
913  goto fail;
914 
915  if (!(buf = av_malloc(ret))) {
916  ret = AVERROR(ENOMEM);
917  goto fail;
918  }
919 
920  frame->nb_samples = s->frame_size;
921  if ((ret = avcodec_fill_audio_frame(frame, s->channels, s->sample_fmt,
922  buf, ret, 0)) < 0)
923  goto fail;
924  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
925  src->nb_samples, s->channels, s->sample_fmt)) < 0)
926  goto fail;
927  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
928  frame->nb_samples - src->nb_samples,
929  s->channels, s->sample_fmt)) < 0)
930  goto fail;
931 
932  *dst = frame;
933 
934  return 0;
935 
936 fail:
937  if (frame->extended_data != frame->data)
938  av_freep(&frame->extended_data);
939  av_freep(&buf);
940  av_freep(&frame);
941  return ret;
942 }
943 
945  AVPacket *avpkt,
946  const AVFrame *frame,
947  int *got_packet_ptr)
948 {
949  AVFrame tmp;
950  AVFrame *padded_frame = NULL;
951  int ret;
952  int user_packet = !!avpkt->data;
953 
954  *got_packet_ptr = 0;
955 
956  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
957  av_free_packet(avpkt);
958  av_init_packet(avpkt);
959  return 0;
960  }
961 
962  /* ensure that extended_data is properly set */
963  if (frame && !frame->extended_data) {
964  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
965  avctx->channels > AV_NUM_DATA_POINTERS) {
966  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
967  "with more than %d channels, but extended_data is not set.\n",
969  return AVERROR(EINVAL);
970  }
971  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
972 
973  tmp = *frame;
974  tmp.extended_data = tmp.data;
975  frame = &tmp;
976  }
977 
978  /* check for valid frame size */
979  if (frame) {
981  if (frame->nb_samples > avctx->frame_size)
982  return AVERROR(EINVAL);
983  } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
984  if (frame->nb_samples < avctx->frame_size &&
985  !avctx->internal->last_audio_frame) {
986  ret = pad_last_frame(avctx, &padded_frame, frame);
987  if (ret < 0)
988  return ret;
989 
990  frame = padded_frame;
991  avctx->internal->last_audio_frame = 1;
992  }
993 
994  if (frame->nb_samples != avctx->frame_size) {
995  ret = AVERROR(EINVAL);
996  goto end;
997  }
998  }
999  }
1000 
1001  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1002  if (!ret) {
1003  if (*got_packet_ptr) {
1004  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
1005  if (avpkt->pts == AV_NOPTS_VALUE)
1006  avpkt->pts = frame->pts;
1007  if (!avpkt->duration)
1008  avpkt->duration = ff_samples_to_time_base(avctx,
1009  frame->nb_samples);
1010  }
1011  avpkt->dts = avpkt->pts;
1012  } else {
1013  avpkt->size = 0;
1014  }
1015 
1016  if (!user_packet && avpkt->size) {
1017  uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
1018  if (new_data)
1019  avpkt->data = new_data;
1020  }
1021 
1022  avctx->frame_number++;
1023  }
1024 
1025  if (ret < 0 || !*got_packet_ptr) {
1026  av_free_packet(avpkt);
1027  av_init_packet(avpkt);
1028  goto end;
1029  }
1030 
1031  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1032  * this needs to be moved to the encoders, but for now we can do it
1033  * here to simplify things */
1034  avpkt->flags |= AV_PKT_FLAG_KEY;
1035 
1036 end:
1037  if (padded_frame) {
1038  av_freep(&padded_frame->data[0]);
1039  if (padded_frame->extended_data != padded_frame->data)
1040  av_freep(&padded_frame->extended_data);
1041  av_freep(&padded_frame);
1042  }
1043 
1044  return ret;
1045 }
1046 
1047 #if FF_API_OLD_ENCODE_AUDIO
1048 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
1049  uint8_t *buf, int buf_size,
1050  const short *samples)
1051 {
1052  AVPacket pkt;
1053  AVFrame frame0 = { { 0 } };
1054  AVFrame *frame;
1055  int ret, samples_size, got_packet;
1056 
1057  av_init_packet(&pkt);
1058  pkt.data = buf;
1059  pkt.size = buf_size;
1060 
1061  if (samples) {
1062  frame = &frame0;
1064 
1065  if (avctx->frame_size) {
1066  frame->nb_samples = avctx->frame_size;
1067  } else {
1068  /* if frame_size is not set, the number of samples must be
1069  * calculated from the buffer size */
1070  int64_t nb_samples;
1071  if (!av_get_bits_per_sample(avctx->codec_id)) {
1072  av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not "
1073  "support this codec\n");
1074  return AVERROR(EINVAL);
1075  }
1076  nb_samples = (int64_t)buf_size * 8 /
1077  (av_get_bits_per_sample(avctx->codec_id) *
1078  avctx->channels);
1079  if (nb_samples >= INT_MAX)
1080  return AVERROR(EINVAL);
1081  frame->nb_samples = nb_samples;
1082  }
1083 
1084  /* it is assumed that the samples buffer is large enough based on the
1085  * relevant parameters */
1086  samples_size = av_samples_get_buffer_size(NULL, avctx->channels,
1087  frame->nb_samples,
1088  avctx->sample_fmt, 1);
1089  if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
1090  avctx->sample_fmt,
1091  (const uint8_t *)samples,
1092  samples_size, 1)))
1093  return ret;
1094 
1095  /* fabricate frame pts from sample count.
1096  * this is needed because the avcodec_encode_audio() API does not have
1097  * a way for the user to provide pts */
1098  frame->pts = ff_samples_to_time_base(avctx,
1099  avctx->internal->sample_count);
1100  avctx->internal->sample_count += frame->nb_samples;
1101  } else {
1102  frame = NULL;
1103  }
1104 
1105  got_packet = 0;
1106  ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);
1107  if (!ret && got_packet && avctx->coded_frame) {
1108  avctx->coded_frame->pts = pkt.pts;
1109  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1110  }
1111  /* free any side data since we cannot return it */
1112  if (pkt.side_data_elems > 0) {
1113  int i;
1114  for (i = 0; i < pkt.side_data_elems; i++)
1115  av_free(pkt.side_data[i].data);
1116  av_freep(&pkt.side_data);
1117  pkt.side_data_elems = 0;
1118  }
1119 
1120  if (frame && frame->extended_data != frame->data)
1121  av_free(frame->extended_data);
1122 
1123  return ret ? ret : pkt.size;
1124 }
1125 
1126 #endif
1127 
1128 #if FF_API_OLD_ENCODE_VIDEO
1129 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1130  const AVFrame *pict)
1131 {
1132  AVPacket pkt;
1133  int ret, got_packet = 0;
1134 
1135  if (buf_size < FF_MIN_BUFFER_SIZE) {
1136  av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
1137  return -1;
1138  }
1139 
1140  av_init_packet(&pkt);
1141  pkt.data = buf;
1142  pkt.size = buf_size;
1143 
1144  ret = avcodec_encode_video2(avctx, &pkt, pict, &got_packet);
1145  if (!ret && got_packet && avctx->coded_frame) {
1146  avctx->coded_frame->pts = pkt.pts;
1147  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1148  }
1149 
1150  /* free any side data since we cannot return it */
1151  if (pkt.side_data_elems > 0) {
1152  int i;
1153  for (i = 0; i < pkt.side_data_elems; i++)
1154  av_free(pkt.side_data[i].data);
1155  av_freep(&pkt.side_data);
1156  pkt.side_data_elems = 0;
1157  }
1158 
1159  return ret ? ret : pkt.size;
1160 }
1161 
1162 #endif
1163 
1165  AVPacket *avpkt,
1166  const AVFrame *frame,
1167  int *got_packet_ptr)
1168 {
1169  int ret;
1170  int user_packet = !!avpkt->data;
1171 
1172  *got_packet_ptr = 0;
1173 
1174  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1175  av_free_packet(avpkt);
1176  av_init_packet(avpkt);
1177  avpkt->size = 0;
1178  return 0;
1179  }
1180 
1181  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
1182  return AVERROR(EINVAL);
1183 
1184  av_assert0(avctx->codec->encode2);
1185 
1186  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1187  if (!ret) {
1188  if (!*got_packet_ptr)
1189  avpkt->size = 0;
1190  else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
1191  avpkt->pts = avpkt->dts = frame->pts;
1192 
1193  if (!user_packet && avpkt->size) {
1194  uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
1195  if (new_data)
1196  avpkt->data = new_data;
1197  }
1198 
1199  avctx->frame_number++;
1200  }
1201 
1202  if (ret < 0 || !*got_packet_ptr)
1203  av_free_packet(avpkt);
1204 
1205  emms_c();
1206  return ret;
1207 }
1208 
1209 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1210  const AVSubtitle *sub)
1211 {
1212  int ret;
1213  if (sub->start_display_time) {
1214  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1215  return -1;
1216  }
1217  if (sub->num_rects == 0 || !sub->rects)
1218  return -1;
1219  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
1220  avctx->frame_number++;
1221  return ret;
1222 }
1223 
1224 static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1225 {
1226  int size = 0;
1227  const uint8_t *data;
1228  uint32_t flags;
1229 
1230  if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE))
1231  return;
1232 
1233  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1234  if (!data || size < 4)
1235  return;
1236  flags = bytestream_get_le32(&data);
1237  size -= 4;
1238  if (size < 4) /* Required for any of the changes */
1239  return;
1241  avctx->channels = bytestream_get_le32(&data);
1242  size -= 4;
1243  }
1245  if (size < 8)
1246  return;
1247  avctx->channel_layout = bytestream_get_le64(&data);
1248  size -= 8;
1249  }
1250  if (size < 4)
1251  return;
1253  avctx->sample_rate = bytestream_get_le32(&data);
1254  size -= 4;
1255  }
1257  if (size < 8)
1258  return;
1259  avctx->width = bytestream_get_le32(&data);
1260  avctx->height = bytestream_get_le32(&data);
1261  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
1262  size -= 8;
1263  }
1264 }
1265 
1267  int *got_picture_ptr,
1268  AVPacket *avpkt)
1269 {
1270  int ret;
1271 
1272  *got_picture_ptr = 0;
1273  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
1274  return -1;
1275 
1276  avctx->pkt = avpkt;
1277  apply_param_change(avctx, avpkt);
1278 
1279  avcodec_get_frame_defaults(picture);
1280 
1281  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
1283  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
1284  avpkt);
1285  else {
1286  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
1287  avpkt);
1288  picture->pkt_dts = avpkt->dts;
1289  /* get_buffer is supposed to set frame parameters */
1290  if (!(avctx->codec->capabilities & CODEC_CAP_DR1)) {
1291  picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
1292  picture->width = avctx->width;
1293  picture->height = avctx->height;
1294  picture->format = avctx->pix_fmt;
1295  }
1296  }
1297 
1298  emms_c(); //needed to avoid an emms_c() call before every return;
1299 
1300  if (*got_picture_ptr)
1301  avctx->frame_number++;
1302  } else
1303  ret = 0;
1304 
1305  /* many decoders assign whole AVFrames, thus overwriting extended_data;
1306  * make sure it's set correctly */
1307  picture->extended_data = picture->data;
1308 
1309  return ret;
1310 }
1311 
1312 #if FF_API_OLD_DECODE_AUDIO
1313 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
1314  int *frame_size_ptr,
1315  AVPacket *avpkt)
1316 {
1317  AVFrame frame = { { 0 } };
1318  int ret, got_frame = 0;
1319 
1320  if (avctx->get_buffer != avcodec_default_get_buffer) {
1321  av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
1322  "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
1323  av_log(avctx, AV_LOG_ERROR, "Please port your application to "
1324  "avcodec_decode_audio4()\n");
1326  }
1327 
1328  ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
1329 
1330  if (ret >= 0 && got_frame) {
1331  int ch, plane_size;
1332  int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
1333  int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
1334  frame.nb_samples,
1335  avctx->sample_fmt, 1);
1336  if (*frame_size_ptr < data_size) {
1337  av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
1338  "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1339  return AVERROR(EINVAL);
1340  }
1341 
1342  memcpy(samples, frame.extended_data[0], plane_size);
1343 
1344  if (planar && avctx->channels > 1) {
1345  uint8_t *out = ((uint8_t *)samples) + plane_size;
1346  for (ch = 1; ch < avctx->channels; ch++) {
1347  memcpy(out, frame.extended_data[ch], plane_size);
1348  out += plane_size;
1349  }
1350  }
1351  *frame_size_ptr = data_size;
1352  } else {
1353  *frame_size_ptr = 0;
1354  }
1355  return ret;
1356 }
1357 
1358 #endif
1359 
1361  AVFrame *frame,
1362  int *got_frame_ptr,
1363  AVPacket *avpkt)
1364 {
1365  int planar, channels;
1366  int ret = 0;
1367 
1368  *got_frame_ptr = 0;
1369 
1370  avctx->pkt = avpkt;
1371 
1372  if (!avpkt->data && avpkt->size) {
1373  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1374  return AVERROR(EINVAL);
1375  }
1376 
1377  apply_param_change(avctx, avpkt);
1378 
1380 
1381  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1382  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1383  if (ret >= 0 && *got_frame_ptr) {
1384  avctx->frame_number++;
1385  frame->pkt_dts = avpkt->dts;
1386  if (frame->format == AV_SAMPLE_FMT_NONE)
1387  frame->format = avctx->sample_fmt;
1388  }
1389  }
1390 
1391  /* many decoders assign whole AVFrames, thus overwriting extended_data;
1392  * make sure it's set correctly; assume decoders that actually use
1393  * extended_data are doing it correctly */
1394  planar = av_sample_fmt_is_planar(frame->format);
1396  if (!(planar && channels > AV_NUM_DATA_POINTERS))
1397  frame->extended_data = frame->data;
1398 
1399  return ret;
1400 }
1401 
1403  int *got_sub_ptr,
1404  AVPacket *avpkt)
1405 {
1406  int ret;
1407 
1408  avctx->pkt = avpkt;
1409  *got_sub_ptr = 0;
1410  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1411  if (*got_sub_ptr)
1412  avctx->frame_number++;
1413  return ret;
1414 }
1415 
1417 {
1418  int i;
1419 
1420  for (i = 0; i < sub->num_rects; i++) {
1421  av_freep(&sub->rects[i]->pict.data[0]);
1422  av_freep(&sub->rects[i]->pict.data[1]);
1423  av_freep(&sub->rects[i]->pict.data[2]);
1424  av_freep(&sub->rects[i]->pict.data[3]);
1425  av_freep(&sub->rects[i]->text);
1426  av_freep(&sub->rects[i]->ass);
1427  av_freep(&sub->rects[i]);
1428  }
1429 
1430  av_freep(&sub->rects);
1431 
1432  memset(sub, 0, sizeof(AVSubtitle));
1433 }
1434 
1436 {
1437  /* If there is a user-supplied mutex locking routine, call it. */
1438  if (ff_lockmgr_cb) {
1440  return -1;
1441  }
1442 
1444  if (entangled_thread_counter != 1) {
1445  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1447  return -1;
1448  }
1449 
1450  if (avcodec_is_open(avctx)) {
1451  if (HAVE_THREADS && avctx->thread_opaque)
1452  ff_thread_free(avctx);
1453  if (avctx->codec && avctx->codec->close)
1454  avctx->codec->close(avctx);
1456  avctx->coded_frame = NULL;
1457  av_freep(&avctx->internal);
1458  }
1459 
1460  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1461  av_opt_free(avctx->priv_data);
1462  av_opt_free(avctx);
1463  av_freep(&avctx->priv_data);
1464  if (av_codec_is_encoder(avctx->codec))
1465  av_freep(&avctx->extradata);
1466  avctx->codec = NULL;
1467  avctx->active_thread_type = 0;
1469 
1470  /* Release any user-supplied mutex. */
1471  if (ff_lockmgr_cb) {
1472  (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1473  }
1474  return 0;
1475 }
1476 
1477 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1478 {
1479  AVCodec *p, *experimental = NULL;
1480  p = first_avcodec;
1481  while (p) {
1482  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1483  p->id == id) {
1484  if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1485  experimental = p;
1486  } else
1487  return p;
1488  }
1489  p = p->next;
1490  }
1491  return experimental;
1492 }
1493 
1495 {
1496  return find_encdec(id, 1);
1497 }
1498 
1500 {
1501  AVCodec *p;
1502  if (!name)
1503  return NULL;
1504  p = first_avcodec;
1505  while (p) {
1506  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
1507  return p;
1508  p = p->next;
1509  }
1510  return NULL;
1511 }
1512 
1514 {
1515  return find_encdec(id, 0);
1516 }
1517 
1519 {
1520  AVCodec *p;
1521  if (!name)
1522  return NULL;
1523  p = first_avcodec;
1524  while (p) {
1525  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
1526  return p;
1527  p = p->next;
1528  }
1529  return NULL;
1530 }
1531 
1533 {
1534  int bit_rate;
1535  int bits_per_sample;
1536 
1537  switch (ctx->codec_type) {
1538  case AVMEDIA_TYPE_VIDEO:
1539  case AVMEDIA_TYPE_DATA:
1540  case AVMEDIA_TYPE_SUBTITLE:
1542  bit_rate = ctx->bit_rate;
1543  break;
1544  case AVMEDIA_TYPE_AUDIO:
1545  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1546  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1547  break;
1548  default:
1549  bit_rate = 0;
1550  break;
1551  }
1552  return bit_rate;
1553 }
1554 
1555 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1556 {
1557  int i, len, ret = 0;
1558 
1559  for (i = 0; i < 4; i++) {
1560  len = snprintf(buf, buf_size,
1561  isprint(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
1562  buf += len;
1563  buf_size = buf_size > len ? buf_size - len : 0;
1564  ret += len;
1565  codec_tag >>= 8;
1566  }
1567  return ret;
1568 }
1569 
1570 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1571 {
1572  const char *codec_name;
1573  const char *profile = NULL;
1574  const AVCodec *p;
1575  char buf1[32];
1576  int bitrate;
1577  AVRational display_aspect_ratio;
1578 
1579  if (enc->codec)
1580  p = enc->codec;
1581  else if (encode)
1582  p = avcodec_find_encoder(enc->codec_id);
1583  else
1584  p = avcodec_find_decoder(enc->codec_id);
1585 
1586  if (p) {
1587  codec_name = p->name;
1588  profile = av_get_profile_name(p, enc->profile);
1589  } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) {
1590  /* fake mpeg2 transport stream codec (currently not
1591  * registered) */
1592  codec_name = "mpeg2ts";
1593  } else if (enc->codec_name[0] != '\0') {
1594  codec_name = enc->codec_name;
1595  } else {
1596  /* output avi tags */
1597  char tag_buf[32];
1598  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1599  snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
1600  codec_name = buf1;
1601  }
1602 
1603  switch (enc->codec_type) {
1604  case AVMEDIA_TYPE_VIDEO:
1605  snprintf(buf, buf_size,
1606  "Video: %s%s",
1607  codec_name, enc->mb_decision ? " (hq)" : "");
1608  if (profile)
1609  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1610  " (%s)", profile);
1611  if (enc->pix_fmt != AV_PIX_FMT_NONE) {
1612  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1613  ", %s",
1615  }
1616  if (enc->width) {
1617  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1618  ", %dx%d",
1619  enc->width, enc->height);
1620  if (enc->sample_aspect_ratio.num) {
1621  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1622  enc->width * enc->sample_aspect_ratio.num,
1623  enc->height * enc->sample_aspect_ratio.den,
1624  1024 * 1024);
1625  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1626  " [PAR %d:%d DAR %d:%d]",
1628  display_aspect_ratio.num, display_aspect_ratio.den);
1629  }
1630  if (av_log_get_level() >= AV_LOG_DEBUG) {
1631  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1632  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1633  ", %d/%d",
1634  enc->time_base.num / g, enc->time_base.den / g);
1635  }
1636  }
1637  if (encode) {
1638  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1639  ", q=%d-%d", enc->qmin, enc->qmax);
1640  }
1641  break;
1642  case AVMEDIA_TYPE_AUDIO:
1643  snprintf(buf, buf_size,
1644  "Audio: %s",
1645  codec_name);
1646  if (profile)
1647  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1648  " (%s)", profile);
1649  if (enc->sample_rate) {
1650  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1651  ", %d Hz", enc->sample_rate);
1652  }
1653  av_strlcat(buf, ", ", buf_size);
1654  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1655  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1656  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1657  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1658  }
1659  break;
1660  case AVMEDIA_TYPE_DATA:
1661  snprintf(buf, buf_size, "Data: %s", codec_name);
1662  break;
1663  case AVMEDIA_TYPE_SUBTITLE:
1664  snprintf(buf, buf_size, "Subtitle: %s", codec_name);
1665  break;
1667  snprintf(buf, buf_size, "Attachment: %s", codec_name);
1668  break;
1669  default:
1670  snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
1671  return;
1672  }
1673  if (encode) {
1674  if (enc->flags & CODEC_FLAG_PASS1)
1675  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1676  ", pass 1");
1677  if (enc->flags & CODEC_FLAG_PASS2)
1678  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1679  ", pass 2");
1680  }
1681  bitrate = get_bit_rate(enc);
1682  if (bitrate != 0) {
1683  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1684  ", %d kb/s", bitrate / 1000);
1685  }
1686 }
1687 
1688 const char *av_get_profile_name(const AVCodec *codec, int profile)
1689 {
1690  const AVProfile *p;
1691  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1692  return NULL;
1693 
1694  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1695  if (p->profile == profile)
1696  return p->name;
1697 
1698  return NULL;
1699 }
1700 
1701 unsigned avcodec_version(void)
1702 {
1703  return LIBAVCODEC_VERSION_INT;
1704 }
1705 
1706 const char *avcodec_configuration(void)
1707 {
1708  return LIBAV_CONFIGURATION;
1709 }
1710 
1711 const char *avcodec_license(void)
1712 {
1713 #define LICENSE_PREFIX "libavcodec license: "
1714  return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1715 }
1716 
1718 {
1720  ff_thread_flush(avctx);
1721  else if (avctx->codec->flush)
1722  avctx->codec->flush(avctx);
1723 }
1724 
1726 {
1727  AVCodecInternal *avci = s->internal;
1728  int i, j;
1729 
1730  if (!avci->buffer)
1731  return;
1732 
1733  if (avci->buffer_count)
1734  av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n",
1735  avci->buffer_count);
1736  for (i = 0; i < INTERNAL_BUFFER_SIZE; i++) {
1737  InternalBuffer *buf = &avci->buffer[i];
1738  for (j = 0; j < 4; j++) {
1739  av_freep(&buf->base[j]);
1740  buf->data[j] = NULL;
1741  }
1742  }
1743  av_freep(&avci->buffer);
1744 
1745  avci->buffer_count = 0;
1746 }
1747 
1749 {
1750  AVCodecInternal *avci = avctx->internal;
1751  av_freep(&avci->audio_data);
1752 }
1753 
1755 {
1756  switch (avctx->codec_type) {
1757  case AVMEDIA_TYPE_VIDEO:
1758  video_free_buffers(avctx);
1759  break;
1760  case AVMEDIA_TYPE_AUDIO:
1761  audio_free_buffers(avctx);
1762  break;
1763  default:
1764  break;
1765  }
1766 }
1767 
1769 {
1770  switch (codec_id) {
1771  case AV_CODEC_ID_ADPCM_CT:
1777  return 4;
1778  case AV_CODEC_ID_PCM_ALAW:
1779  case AV_CODEC_ID_PCM_MULAW:
1780  case AV_CODEC_ID_PCM_S8:
1781  case AV_CODEC_ID_PCM_U8:
1782  case AV_CODEC_ID_PCM_ZORK:
1783  return 8;
1784  case AV_CODEC_ID_PCM_S16BE:
1785  case AV_CODEC_ID_PCM_S16LE:
1787  case AV_CODEC_ID_PCM_U16BE:
1788  case AV_CODEC_ID_PCM_U16LE:
1789  return 16;
1791  case AV_CODEC_ID_PCM_S24BE:
1792  case AV_CODEC_ID_PCM_S24LE:
1793  case AV_CODEC_ID_PCM_U24BE:
1794  case AV_CODEC_ID_PCM_U24LE:
1795  return 24;
1796  case AV_CODEC_ID_PCM_S32BE:
1797  case AV_CODEC_ID_PCM_S32LE:
1798  case AV_CODEC_ID_PCM_U32BE:
1799  case AV_CODEC_ID_PCM_U32LE:
1800  case AV_CODEC_ID_PCM_F32BE:
1801  case AV_CODEC_ID_PCM_F32LE:
1802  return 32;
1803  case AV_CODEC_ID_PCM_F64BE:
1804  case AV_CODEC_ID_PCM_F64LE:
1805  return 64;
1806  default:
1807  return 0;
1808  }
1809 }
1810 
1812 {
1813  switch (codec_id) {
1815  return 2;
1817  return 3;
1821  case AV_CODEC_ID_ADPCM_SWF:
1822  case AV_CODEC_ID_ADPCM_MS:
1823  return 4;
1824  default:
1825  return av_get_exact_bits_per_sample(codec_id);
1826  }
1827 }
1828 
1829 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
1830 {
1831  int id, sr, ch, ba, tag, bps;
1832 
1833  id = avctx->codec_id;
1834  sr = avctx->sample_rate;
1835  ch = avctx->channels;
1836  ba = avctx->block_align;
1837  tag = avctx->codec_tag;
1838  bps = av_get_exact_bits_per_sample(avctx->codec_id);
1839 
1840  /* codecs with an exact constant bits per sample */
1841  if (bps > 0 && ch > 0 && frame_bytes > 0)
1842  return (frame_bytes * 8) / (bps * ch);
1843  bps = avctx->bits_per_coded_sample;
1844 
1845  /* codecs with a fixed packet duration */
1846  switch (id) {
1847  case AV_CODEC_ID_ADPCM_ADX: return 32;
1848  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
1849  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
1850  case AV_CODEC_ID_AMR_NB:
1851  case AV_CODEC_ID_GSM:
1852  case AV_CODEC_ID_QCELP:
1853  case AV_CODEC_ID_RA_144:
1854  case AV_CODEC_ID_RA_288: return 160;
1855  case AV_CODEC_ID_IMC: return 256;
1856  case AV_CODEC_ID_AMR_WB:
1857  case AV_CODEC_ID_GSM_MS: return 320;
1858  case AV_CODEC_ID_MP1: return 384;
1859  case AV_CODEC_ID_ATRAC1: return 512;
1860  case AV_CODEC_ID_ATRAC3: return 1024;
1861  case AV_CODEC_ID_MP2:
1862  case AV_CODEC_ID_MUSEPACK7: return 1152;
1863  case AV_CODEC_ID_AC3: return 1536;
1864  }
1865 
1866  if (sr > 0) {
1867  /* calc from sample rate */
1868  if (id == AV_CODEC_ID_TTA)
1869  return 256 * sr / 245;
1870 
1871  if (ch > 0) {
1872  /* calc from sample rate and channels */
1873  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
1874  return (480 << (sr / 22050)) / ch;
1875  }
1876  }
1877 
1878  if (ba > 0) {
1879  /* calc from block_align */
1880  if (id == AV_CODEC_ID_SIPR) {
1881  switch (ba) {
1882  case 20: return 160;
1883  case 19: return 144;
1884  case 29: return 288;
1885  case 37: return 480;
1886  }
1887  } else if (id == AV_CODEC_ID_ILBC) {
1888  switch (ba) {
1889  case 38: return 160;
1890  case 50: return 240;
1891  }
1892  }
1893  }
1894 
1895  if (frame_bytes > 0) {
1896  /* calc from frame_bytes only */
1897  if (id == AV_CODEC_ID_TRUESPEECH)
1898  return 240 * (frame_bytes / 32);
1899  if (id == AV_CODEC_ID_NELLYMOSER)
1900  return 256 * (frame_bytes / 64);
1901 
1902  if (bps > 0) {
1903  /* calc from frame_bytes and bits_per_coded_sample */
1904  if (id == AV_CODEC_ID_ADPCM_G726)
1905  return frame_bytes * 8 / bps;
1906  }
1907 
1908  if (ch > 0) {
1909  /* calc from frame_bytes and channels */
1910  switch (id) {
1911  case AV_CODEC_ID_ADPCM_4XM:
1913  return (frame_bytes - 4 * ch) * 2 / ch;
1915  return (frame_bytes - 4) * 2 / ch;
1917  return (frame_bytes - 8) * 2 / ch;
1918  case AV_CODEC_ID_ADPCM_XA:
1919  return (frame_bytes / 128) * 224 / ch;
1921  return (frame_bytes - 6 - ch) / ch;
1922  case AV_CODEC_ID_ROQ_DPCM:
1923  return (frame_bytes - 8) / ch;
1924  case AV_CODEC_ID_XAN_DPCM:
1925  return (frame_bytes - 2 * ch) / ch;
1926  case AV_CODEC_ID_MACE3:
1927  return 3 * frame_bytes / ch;
1928  case AV_CODEC_ID_MACE6:
1929  return 6 * frame_bytes / ch;
1930  case AV_CODEC_ID_PCM_LXF:
1931  return 2 * (frame_bytes / (5 * ch));
1932  }
1933 
1934  if (tag) {
1935  /* calc from frame_bytes, channels, and codec_tag */
1936  if (id == AV_CODEC_ID_SOL_DPCM) {
1937  if (tag == 3)
1938  return frame_bytes / ch;
1939  else
1940  return frame_bytes * 2 / ch;
1941  }
1942  }
1943 
1944  if (ba > 0) {
1945  /* calc from frame_bytes, channels, and block_align */
1946  int blocks = frame_bytes / ba;
1947  switch (avctx->codec_id) {
1949  return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
1951  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
1953  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
1954  case AV_CODEC_ID_ADPCM_MS:
1955  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
1956  }
1957  }
1958 
1959  if (bps > 0) {
1960  /* calc from frame_bytes, channels, and bits_per_coded_sample */
1961  switch (avctx->codec_id) {
1962  case AV_CODEC_ID_PCM_DVD:
1963  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
1965  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
1966  case AV_CODEC_ID_S302M:
1967  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
1968  }
1969  }
1970  }
1971  }
1972 
1973  return 0;
1974 }
1975 
1976 #if !HAVE_THREADS
1978 {
1979  return -1;
1980 }
1981 
1982 #endif
1983 
1984 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1985 {
1986  unsigned int n = 0;
1987 
1988  while (v >= 0xff) {
1989  *s++ = 0xff;
1990  v -= 0xff;
1991  n++;
1992  }
1993  *s = v;
1994  n++;
1995  return n;
1996 }
1997 
1998 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
1999 {
2000  int i;
2001  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
2002  return i;
2003 }
2004 
2005 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
2006 {
2007  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your Libav "
2008  "version to the newest one from Git. If the problem still "
2009  "occurs, it means that your file has a feature which has not "
2010  "been implemented.\n", feature);
2011  if(want_sample)
2013 }
2014 
2015 void av_log_ask_for_sample(void *avc, const char *msg, ...)
2016 {
2017  va_list argument_list;
2018 
2019  va_start(argument_list, msg);
2020 
2021  if (msg)
2022  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
2023  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
2024  "of this file to ftp://upload.libav.org/incoming/ "
2025  "and contact the libav-devel mailing list.\n");
2026 
2027  va_end(argument_list);
2028 }
2029 
2031 
2033 {
2034  AVHWAccel **p = &first_hwaccel;
2035  while (*p)
2036  p = &(*p)->next;
2037  *p = hwaccel;
2038  hwaccel->next = NULL;
2039 }
2040 
2042 {
2043  return hwaccel ? hwaccel->next : first_hwaccel;
2044 }
2045 
2047 {
2048  AVHWAccel *hwaccel = NULL;
2049 
2050  while ((hwaccel = av_hwaccel_next(hwaccel)))
2051  if (hwaccel->id == codec_id
2052  && hwaccel->pix_fmt == pix_fmt)
2053  return hwaccel;
2054  return NULL;
2055 }
2056 
2057 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
2058 {
2059  if (ff_lockmgr_cb) {
2061  return -1;
2063  return -1;
2064  }
2065 
2066  ff_lockmgr_cb = cb;
2067 
2068  if (ff_lockmgr_cb) {
2070  return -1;
2072  return -1;
2073  }
2074  return 0;
2075 }
2076 
2078 {
2079  if (ff_lockmgr_cb) {
2081  return -1;
2082  }
2083  return 0;
2084 }
2085 
2087 {
2088  if (ff_lockmgr_cb) {
2090  return -1;
2091  }
2092  return 0;
2093 }
2094 
2095 unsigned int avpriv_toupper4(unsigned int x)
2096 {
2097  return toupper(x & 0xFF)
2098  + (toupper((x >> 8) & 0xFF) << 8)
2099  + (toupper((x >> 16) & 0xFF) << 16)
2100  + (toupper((x >> 24) & 0xFF) << 24);
2101 }
2102 
2103 #if !HAVE_THREADS
2104 
2106 {
2107  f->owner = avctx;
2108  return ff_get_buffer(avctx, f);
2109 }
2110 
2112 {
2113  f->owner->release_buffer(f->owner, f);
2114 }
2115 
2117 {
2118 }
2119 
2120 void ff_thread_report_progress(AVFrame *f, int progress, int field)
2121 {
2122 }
2123 
2124 void ff_thread_await_progress(AVFrame *f, int progress, int field)
2125 {
2126 }
2127 
2128 #endif
2129 
2131 {
2132  if (codec_id <= AV_CODEC_ID_NONE)
2133  return AVMEDIA_TYPE_UNKNOWN;
2134  else if (codec_id < AV_CODEC_ID_FIRST_AUDIO)
2135  return AVMEDIA_TYPE_VIDEO;
2136  else if (codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
2137  return AVMEDIA_TYPE_AUDIO;
2138  else if (codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
2139  return AVMEDIA_TYPE_SUBTITLE;
2140 
2141  return AVMEDIA_TYPE_UNKNOWN;
2142 }
2143 
2145 {
2146  return !!s->internal;
2147 }
#define FF_SANE_NB_CHANNELS
Definition: internal.h:33
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:82
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
Definition: avcodec.h:2248
const struct AVCodec * codec
Definition: avcodec.h:1348
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:151
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:61
static AVCodec * find_encdec(enum AVCodecID id, int encoder)
Definition: utils.c:1477
static int16_t * samples
#define HAVE_THREADS
Definition: config.h:235
int size
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:3155
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:153
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1435
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:1494
#define c2
Definition: idct_sh4.c:28
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:108
A dummy id pointing at the start of audio codecs.
Definition: avcodec.h:270
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:144
void ff_thread_report_progress(AVFrame *f, int progress, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: utils.c:2120
enum AVCodecID id
Definition: mxfenc.c:85
int coded_width
Bitstream width / height, may be different from width/height.
Definition: avcodec.h:1515
int buffer_hints
codec suggestion on buffer type if != 0
Definition: avcodec.h:1253
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:3049
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:2057
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
misc image utilities
Unlock the mutex.
Definition: avcodec.h:4594
enum AVPixelFormat pix_fmt
Definition: internal.h:41
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:147
int buffer_count
internal buffer count used by default get/release/reget_buffer().
Definition: internal.h:49
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2376
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:505
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:1706
void * opaque
for some private data of the user
Definition: avcodec.h:1202
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:154
int num
numerator
Definition: rational.h:44
struct AVCodecContext * owner
the AVCodecContext which ff_thread_get_buffer() was last called on
Definition: avcodec.h:1287
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:149
int size
Definition: avcodec.h:916
char codec_name[32]
Definition: avcodec.h:1349
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:1711
InternalBuffer * buffer
internal buffers used by default get/release/reget_buffer().
Definition: internal.h:55
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:2032
enum AVPixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:3082
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:1724
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: utils.c:901
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:1060
unsigned num_rects
Definition: avcodec.h:3214
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer with padding, reusing the given one if large enough.
Definition: utils.c:85
A dummy ID pointing at the start of various fake codecs.
Definition: avcodec.h:425
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:141
enum AVMediaType type
Definition: avcodec.h:2973
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:1555
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2105
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3043
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:944
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:1402
four components are given, that's all.
Definition: avcodec.h:3153
int profile
profile
Definition: avcodec.h:2815
AVCodec.
Definition: avcodec.h:2960
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2141
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:4591
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:3199
static void * codec_mutex
Definition: utils.c:50
static void video_free_buffers(AVCodecContext *s)
Definition: utils.c:1725
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1465
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
AVSubtitleRect ** rects
Definition: avcodec.h:3215
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:125
void av_picture_copy(AVPicture *dst, const AVPicture *src, enum AVPixelFormat pix_fmt, int width, int height)
Copy image src to dst.
Definition: avpicture.c:119
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill audio frame data and linesize.
Definition: utils.c:264
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:120
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:249
static int volatile entangled_thread_counter
Definition: utils.c:48
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: utils.c:72
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill channel data pointers and linesize for samples with sample format sample_fmt.
Definition: samplefmt.c:140
Public dictionary API.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Definition: utils.c:595
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:83
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2112
Lock the mutex.
Definition: avcodec.h:4593
uint8_t
int av_log_get_level(void)
Definition: log.c:163
uint8_t * base[AV_NUM_DATA_POINTERS]
Definition: internal.h:36
Opaque data information usually continuous.
Definition: avutil.h:181
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
AVOptions.
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: avcodec.h:3154
static AVCodec * first_avcodec
Definition: utils.c:99
#define b
Definition: input.c:52
static void audio_free_buffers(AVCodecContext *avctx)
Definition: utils.c:1748
#define emms_c()
Definition: internal.h:145
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
Definition: avcodec.h:1088
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1454
const char * name
#define LICENSE_PREFIX
int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
Definition: utils.c:1164
const char data[16]
Definition: mxf.c:66
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
Definition: pthread.c:593
uint8_t * data
Definition: avcodec.h:915
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:73
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:101
static int flags
Definition: log.c:42
uint32_t tag
Definition: movenc.c:802
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
Definition: utils.c:1998
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2704
void ff_thread_await_progress(AVFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:2124
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:937
#define r
Definition: input.c:51
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Definition: log.c:158
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:1499
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:159
void(* destruct)(struct AVPacket *)
Definition: avcodec.h:938
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:142
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:127
int(* close)(AVCodecContext *)
Definition: avcodec.h:3044
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:1435
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:56
enum AVCodecID id
Definition: avcodec.h:2974
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:2984
static AVHWAccel * first_hwaccel
Definition: utils.c:2030
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:155
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:150
AVHWAccel * av_hwaccel_next(AVHWAccel *hwaccel)
If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL...
Definition: utils.c:2041
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:161
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:95
int width
width and height of the video frame
Definition: avcodec.h:1035
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1811
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
Create a mutex.
Definition: avcodec.h:4592
Multithreading support functions.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
Definition: utils.c:53
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: avcodec.h:852
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2095
int qmax
maximum quantizer
Definition: avcodec.h:2292
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:101
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:1460
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2752
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2144
g
Definition: yuv2rgb.c:540
int capabilities
Codec capabilities.
Definition: avcodec.h:2979
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:1977
uint8_t * base[AV_NUM_DATA_POINTERS]
pointer to the first allocated byte of the picture.
Definition: avcodec.h:1073
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:113
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:146
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1434
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:53
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
Definition: utils.c:2130
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
Definition: imgutils.c:139
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
int side_data_elems
Definition: avcodec.h:931
enum AVCodecID codec_id
Definition: mov_chan.c:432
void * thread_opaque
thread opaque Can be used by execute() to store some per AVCodecContext stuff.
Definition: avcodec.h:2801
#define LIBAV_CONFIGURATION
Definition: config.h:4
AVHWAccel * ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt)
Return the hardware accelerated codec for codec codec_id and pixel format pix_fmt.
Definition: utils.c:2046
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:921
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2165
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2317
uint64_t channel_layout
Channel layout of the audio data.
Definition: avcodec.h:1318
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:3029
#define INTERNAL_BUFFER_SIZE
Definition: utils.c:157
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:117
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:616
struct AVRational AVRational
rational number numerator/denominator
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:220
int bit_rate
the average bitrate
Definition: avcodec.h:1404
static AVFrame * picture
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:2981
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3196
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:206
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1768
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:589
int width
picture width / height.
Definition: avcodec.h:1508
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:522
int type
type of the buffer (to keep track of who has to deallocate data[*])
Definition: avcodec.h:1217
int priv_data_size
Definition: avcodec.h:2996
int profile
Definition: avcodec.h:2949
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:2116
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:2987
int64_t reordered_opaque
opaque 64bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:2615
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:331
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:143
int mb_decision
macroblock decision mode
Definition: avcodec.h:1882
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:178
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:2015
Opaque data information usually sparse.
Definition: avutil.h:183
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:878
enum AVPixelFormat pix_fmt
Definition: movenc.c:801
static pthread_mutex_t * mutex
Definition: w32pthreads.h:67
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:300
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:152
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2733
void avcodec_flush_buffers(AVCodecContext *avctx)
Flush buffers, should be called when seeking or when switching to a different stream.
Definition: utils.c:1717
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: avcodec.h:1051
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:1688
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2124
#define attribute_align_arg
Definition: internal.h:46
#define PIX_FMT_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:89
NULL
Definition: eval.c:52
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:84
uint8_t * audio_data
The data for the last allocated audio frame.
Definition: internal.h:83
static int width
Definition: utils.c:156
#define STRIDE_ALIGN
Definition: dsputil.h:576
sample_fmt
Definition: avconv_filter.c:63
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:97
external API header
enum AVMediaType codec_type
Definition: avcodec.h:1347
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:3026
enum AVCodecID codec_id
Definition: avcodec.h:1350
AVHWAccel.
Definition: avcodec.h:3055
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:615
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:63
int sample_rate
samples per second
Definition: avcodec.h:2104
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:162
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:144
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: internal.h:37
uint8_t flags
Definition: pixdesc.h:76
int debug
debug
Definition: avcodec.h:2568
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:157
main external API structure.
Definition: avcodec.h:1339
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:1513
int qmin
minimum quantizer
Definition: avcodec.h:2285
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1416
AVRational sample_aspect_ratio
sample aspect ratio for the video frame, 0/1 if unknown/unspecified
Definition: avcodec.h:1080
int av_samples_copy(uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:187
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1365
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:66
out nb_samples
void avcodec_default_free_buffers(AVCodecContext *avctx)
Definition: utils.c:1754
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:487
static int(* ff_lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:49
int extradata_size
Definition: avcodec.h:1455
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1984
struct AVCodec * next
Definition: avcodec.h:2997
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:602
int coded_height
Definition: avcodec.h:1515
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: avcodec.h:1273
Describe the class of an AVClass context structure.
Definition: log.h:33
int sample_rate
Sample rate of the audio data.
Definition: avcodec.h:1310
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:66
av_cold void ff_dsputil_static_init(void)
Definition: dsputil.c:2619
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:101
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:2005
rational number numerator/denominator
Definition: rational.h:43
const char * name
short name for the profile
Definition: avcodec.h:2950
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:35
AVMediaType
Definition: avutil.h:177
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:643
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
Definition: pthread.c:877
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:2111
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:1829
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:77
int64_t pkt_pts
pts copied from the AVPacket that was decoded to produce this frame
Definition: avcodec.h:1095
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:1518
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:2986
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:148
int height
Definition: gxfenc.c:72
const OptionDef options[]
Definition: avserver.c:4665
int64_t pkt_dts
dts copied from the AVPacket that triggered returning this frame
Definition: avcodec.h:1102
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: avcodec.h:2934
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:72
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
Y , 8bpp.
Definition: pixfmt.h:73
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:607
common internal api header.
Free mutex resources.
Definition: avcodec.h:4595
int avpriv_lock_avformat(void)
Definition: utils.c:2077
static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1224
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:116
struct AVHWAccel * next
Definition: avcodec.h:3090
static void avcodec_init(void)
Definition: utils.c:109
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:156
uint32_t start_display_time
Definition: avcodec.h:3212
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
AVProfile.
Definition: avcodec.h:2948
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:79
enum AVCodecID id
Codec implemented by the hardware accelerator.
Definition: avcodec.h:3075
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:87
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:42
int den
denominator
Definition: rational.h:45
int avcodec_default_execute2(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
Definition: utils.c:577
unsigned bps
Definition: movenc.c:803
DSP utils.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1570
void * priv_data
Definition: avcodec.h:1382
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition: avcodec.h:430
as in Berlin toast format
Definition: avcodec.h:365
int len
int channels
number of audio channels
Definition: avcodec.h:2105
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:2982
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1390
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:1701
Y , 16bpp, little-endian.
Definition: pixfmt.h:99
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3206
static void * avformat_mutex
Definition: utils.c:51
#define EDGE_WIDTH
Definition: dsputil.h:440
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
struct AVPacket::@11 * side_data
Additional packet data that can be provided by the container.
static int get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:1532
int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
Definition: utils.c:1266
static const struct twinvq_data tab
void avcodec_free_frame(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: utils.c:628
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:914
void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:130
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2135
int height
Definition: avcodec.h:1035
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:190
int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:451
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:140
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:2983
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:1377
int avpriv_unlock_avformat(void)
Definition: utils.c:2086
#define LIBAV_LICENSE
Definition: config.h:5
int(* init)(AVCodecContext *)
Definition: avcodec.h:3028
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: avcodec.h:1028
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:83
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
This structure stores compressed data.
Definition: avcodec.h:898
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: utils.c:1209
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3041
int linesize[AV_NUM_DATA_POINTERS]
Definition: internal.h:38
int nb_samples
number of audio samples (per channel) described by this frame
Definition: avcodec.h:1042
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:158
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2547
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:908
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:149
A dummy ID pointing at the start of subtitle codecs.
Definition: avcodec.h:413
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:158
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:565
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...
Definition: internal.h:77
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:2917
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)
int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
Definition: utils.c:1360
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:145