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  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
469  return AVERROR_INVALIDDATA;
470  frame->width = avctx->width;
471  frame->height = avctx->height;
472  frame->format = avctx->pix_fmt;
474  break;
475  case AVMEDIA_TYPE_AUDIO:
476  frame->sample_rate = avctx->sample_rate;
477  frame->format = avctx->sample_fmt;
478  frame->channel_layout = avctx->channel_layout;
479  break;
480  default: return AVERROR(EINVAL);
481  }
482 
483  frame->pkt_pts = avctx->pkt ? avctx->pkt->pts : AV_NOPTS_VALUE;
484  frame->reordered_opaque = avctx->reordered_opaque;
485 
486  return avctx->get_buffer(avctx, frame);
487 }
488 
490 {
491  int i;
492  InternalBuffer *buf, *last;
493  AVCodecInternal *avci = s->internal;
494 
495  assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
496 
497  assert(pic->type == FF_BUFFER_TYPE_INTERNAL);
498  assert(avci->buffer_count);
499 
500  if (avci->buffer) {
501  buf = NULL; /* avoids warning */
502  for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize
503  buf = &avci->buffer[i];
504  if (buf->data[0] == pic->data[0])
505  break;
506  }
507  assert(i < avci->buffer_count);
508  avci->buffer_count--;
509  last = &avci->buffer[avci->buffer_count];
510 
511  if (buf != last)
512  FFSWAP(InternalBuffer, *buf, *last);
513  }
514 
515  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
516  pic->data[i] = NULL;
517 // pic->base[i]=NULL;
518 
519  if (s->debug & FF_DEBUG_BUFFERS)
520  av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "
521  "buffers used\n", pic, avci->buffer_count);
522 }
523 
525 {
526  AVFrame temp_pic;
527  int i;
528 
529  assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
530 
531  /* If no picture return a new buffer */
532  if (pic->data[0] == NULL) {
533  /* We will copy from buffer, so must be readable */
535  return ff_get_buffer(s, pic);
536  }
537 
538  assert(s->pix_fmt == pic->format);
539 
540  /* If internal buffer type return the same buffer */
541  if (pic->type == FF_BUFFER_TYPE_INTERNAL) {
542  if (s->pkt)
543  pic->pkt_pts = s->pkt->pts;
544  else
545  pic->pkt_pts = AV_NOPTS_VALUE;
547  return 0;
548  }
549 
550  /*
551  * Not internal type and reget_buffer not overridden, emulate cr buffer
552  */
553  temp_pic = *pic;
554  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
555  pic->data[i] = pic->base[i] = NULL;
556  pic->opaque = NULL;
557  /* Allocate new frame */
558  if (ff_get_buffer(s, pic))
559  return -1;
560  /* Copy image data from old buffer to new buffer */
561  av_picture_copy((AVPicture *)pic, (AVPicture *)&temp_pic, s->pix_fmt, s->width,
562  s->height);
563  s->release_buffer(s, &temp_pic); // Release old frame
564  return 0;
565 }
566 
567 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
568 {
569  int i;
570 
571  for (i = 0; i < count; i++) {
572  int r = func(c, (char *)arg + i * size);
573  if (ret)
574  ret[i] = r;
575  }
576  return 0;
577 }
578 
579 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
580 {
581  int i;
582 
583  for (i = 0; i < count; i++) {
584  int r = func(c, arg, i, 0);
585  if (ret)
586  ret[i] = r;
587  }
588  return 0;
589 }
590 
592 {
593  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
594  return desc->flags & PIX_FMT_HWACCEL;
595 }
596 
598 {
599  while (*fmt != AV_PIX_FMT_NONE && is_hwaccel_pix_fmt(*fmt))
600  ++fmt;
601  return fmt[0];
602 }
603 
605 {
606  if (frame->extended_data != frame->data)
607  av_freep(&frame->extended_data);
608 
609  memset(frame, 0, sizeof(AVFrame));
610 
611  frame->pts = AV_NOPTS_VALUE;
612  frame->key_frame = 1;
613  frame->sample_aspect_ratio = (AVRational) {0, 1 };
614  frame->format = -1; /* unknown */
615  frame->extended_data = frame->data;
616 }
617 
619 {
620  AVFrame *frame = av_mallocz(sizeof(AVFrame));
621 
622  if (frame == NULL)
623  return NULL;
624 
626 
627  return frame;
628 }
629 
631 {
632  AVFrame *f;
633 
634  if (!frame || !*frame)
635  return;
636 
637  f = *frame;
638 
639  if (f->extended_data != f->data)
640  av_freep(&f->extended_data);
641 
642  av_freep(frame);
643 }
644 
646 {
647  int ret = 0;
648  AVDictionary *tmp = NULL;
649 
650  if (avcodec_is_open(avctx))
651  return 0;
652 
653  if ((!codec && !avctx->codec)) {
654  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
655  return AVERROR(EINVAL);
656  }
657  if ((codec && avctx->codec && codec != avctx->codec)) {
658  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
659  "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
660  return AVERROR(EINVAL);
661  }
662  if (!codec)
663  codec = avctx->codec;
664 
665  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
666  return AVERROR(EINVAL);
667 
668  if (options)
669  av_dict_copy(&tmp, *options, 0);
670 
671  /* If there is a user-supplied mutex locking routine, call it. */
672  if (ff_lockmgr_cb) {
674  return -1;
675  }
676 
678  if (entangled_thread_counter != 1) {
679  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
680  ret = -1;
681  goto end;
682  }
683 
684  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
685  if (!avctx->internal) {
686  ret = AVERROR(ENOMEM);
687  goto end;
688  }
689 
690  if (codec->priv_data_size > 0) {
691  if (!avctx->priv_data) {
692  avctx->priv_data = av_mallocz(codec->priv_data_size);
693  if (!avctx->priv_data) {
694  ret = AVERROR(ENOMEM);
695  goto end;
696  }
697  if (codec->priv_class) {
698  *(const AVClass **)avctx->priv_data = codec->priv_class;
700  }
701  }
702  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
703  goto free_and_end;
704  } else {
705  avctx->priv_data = NULL;
706  }
707  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
708  goto free_and_end;
709 
710  if (avctx->coded_width && avctx->coded_height)
711  avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
712  else if (avctx->width && avctx->height)
713  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
714 
715  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
716  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
717  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
718  av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
719  avcodec_set_dimensions(avctx, 0, 0);
720  }
721 
722  /* if the decoder init function was already called previously,
723  * free the already allocated subtitle_header before overwriting it */
724  if (av_codec_is_decoder(codec))
725  av_freep(&avctx->subtitle_header);
726 
727  if (avctx->channels > FF_SANE_NB_CHANNELS) {
728  ret = AVERROR(EINVAL);
729  goto free_and_end;
730  }
731 
732  avctx->codec = codec;
733  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
734  avctx->codec_id == AV_CODEC_ID_NONE) {
735  avctx->codec_type = codec->type;
736  avctx->codec_id = codec->id;
737  }
738  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
739  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
740  av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
741  ret = AVERROR(EINVAL);
742  goto free_and_end;
743  }
744  avctx->frame_number = 0;
745 
746  if (avctx->codec->capabilities & CODEC_CAP_EXPERIMENTAL &&
748  ret = AVERROR_EXPERIMENTAL;
749  goto free_and_end;
750  }
751 
752  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
753  (!avctx->time_base.num || !avctx->time_base.den)) {
754  avctx->time_base.num = 1;
755  avctx->time_base.den = avctx->sample_rate;
756  }
757 
758  if (HAVE_THREADS && !avctx->thread_opaque) {
759  ret = ff_thread_init(avctx);
760  if (ret < 0) {
761  goto free_and_end;
762  }
763  }
765  avctx->thread_count = 1;
766 
767  if (av_codec_is_encoder(avctx->codec)) {
768  int i;
769  if (avctx->codec->sample_fmts) {
770  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
771  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
772  break;
773  if (avctx->channels == 1 &&
776  avctx->sample_fmt = avctx->codec->sample_fmts[i];
777  break;
778  }
779  }
780  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
781  av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
782  ret = AVERROR(EINVAL);
783  goto free_and_end;
784  }
785  }
786  if (avctx->codec->pix_fmts) {
787  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
788  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
789  break;
790  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
791  av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n");
792  ret = AVERROR(EINVAL);
793  goto free_and_end;
794  }
795  }
796  if (avctx->codec->supported_samplerates) {
797  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
798  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
799  break;
800  if (avctx->codec->supported_samplerates[i] == 0) {
801  av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
802  ret = AVERROR(EINVAL);
803  goto free_and_end;
804  }
805  }
806  if (avctx->codec->channel_layouts) {
807  if (!avctx->channel_layout) {
808  av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
809  } else {
810  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
811  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
812  break;
813  if (avctx->codec->channel_layouts[i] == 0) {
814  av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
815  ret = AVERROR(EINVAL);
816  goto free_and_end;
817  }
818  }
819  }
820  if (avctx->channel_layout && avctx->channels) {
822  av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
823  ret = AVERROR(EINVAL);
824  goto free_and_end;
825  }
826  } else if (avctx->channel_layout) {
828  }
829 
830  if (!avctx->rc_initial_buffer_occupancy)
831  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
832  }
833 
834  if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) {
835  ret = avctx->codec->init(avctx);
836  if (ret < 0) {
837  goto free_and_end;
838  }
839  }
840 
841  if (av_codec_is_decoder(avctx->codec)) {
842  /* validate channel layout from the decoder */
843  if (avctx->channel_layout) {
844  int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
845  if (!avctx->channels)
846  avctx->channels = channels;
847  else if (channels != avctx->channels) {
848  av_log(avctx, AV_LOG_WARNING,
849  "channel layout does not match number of channels\n");
850  avctx->channel_layout = 0;
851  }
852  }
853  if (avctx->channels && avctx->channels < 0 ||
854  avctx->channels > FF_SANE_NB_CHANNELS) {
855  ret = AVERROR(EINVAL);
856  goto free_and_end;
857  }
858  }
859 end:
861 
862  /* Release any user-supplied mutex. */
863  if (ff_lockmgr_cb) {
864  (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
865  }
866  if (options) {
867  av_dict_free(options);
868  *options = tmp;
869  }
870 
871  return ret;
872 free_and_end:
873  av_dict_free(&tmp);
874  av_freep(&avctx->priv_data);
875  av_freep(&avctx->internal);
876  avctx->codec = NULL;
877  goto end;
878 }
879 
880 int ff_alloc_packet(AVPacket *avpkt, int size)
881 {
882  if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
883  return AVERROR(EINVAL);
884 
885  if (avpkt->data) {
886  void *destruct = avpkt->destruct;
887 
888  if (avpkt->size < size)
889  return AVERROR(EINVAL);
890 
891  av_init_packet(avpkt);
892  avpkt->destruct = destruct;
893  avpkt->size = size;
894  return 0;
895  } else {
896  return av_new_packet(avpkt, size);
897  }
898 }
899 
903 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
904 {
905  AVFrame *frame = NULL;
906  uint8_t *buf = NULL;
907  int ret;
908 
909  if (!(frame = avcodec_alloc_frame()))
910  return AVERROR(ENOMEM);
911  *frame = *src;
912 
913  if ((ret = av_samples_get_buffer_size(&frame->linesize[0], s->channels,
914  s->frame_size, s->sample_fmt, 0)) < 0)
915  goto fail;
916 
917  if (!(buf = av_malloc(ret))) {
918  ret = AVERROR(ENOMEM);
919  goto fail;
920  }
921 
922  frame->nb_samples = s->frame_size;
923  if ((ret = avcodec_fill_audio_frame(frame, s->channels, s->sample_fmt,
924  buf, ret, 0)) < 0)
925  goto fail;
926  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
927  src->nb_samples, s->channels, s->sample_fmt)) < 0)
928  goto fail;
929  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
930  frame->nb_samples - src->nb_samples,
931  s->channels, s->sample_fmt)) < 0)
932  goto fail;
933 
934  *dst = frame;
935 
936  return 0;
937 
938 fail:
939  if (frame->extended_data != frame->data)
940  av_freep(&frame->extended_data);
941  av_freep(&buf);
942  av_freep(&frame);
943  return ret;
944 }
945 
947  AVPacket *avpkt,
948  const AVFrame *frame,
949  int *got_packet_ptr)
950 {
951  AVFrame tmp;
952  AVFrame *padded_frame = NULL;
953  int ret;
954  int user_packet = !!avpkt->data;
955 
956  *got_packet_ptr = 0;
957 
958  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
959  av_free_packet(avpkt);
960  av_init_packet(avpkt);
961  return 0;
962  }
963 
964  /* ensure that extended_data is properly set */
965  if (frame && !frame->extended_data) {
966  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
967  avctx->channels > AV_NUM_DATA_POINTERS) {
968  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
969  "with more than %d channels, but extended_data is not set.\n",
971  return AVERROR(EINVAL);
972  }
973  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
974 
975  tmp = *frame;
976  tmp.extended_data = tmp.data;
977  frame = &tmp;
978  }
979 
980  /* check for valid frame size */
981  if (frame) {
983  if (frame->nb_samples > avctx->frame_size)
984  return AVERROR(EINVAL);
985  } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
986  if (frame->nb_samples < avctx->frame_size &&
987  !avctx->internal->last_audio_frame) {
988  ret = pad_last_frame(avctx, &padded_frame, frame);
989  if (ret < 0)
990  return ret;
991 
992  frame = padded_frame;
993  avctx->internal->last_audio_frame = 1;
994  }
995 
996  if (frame->nb_samples != avctx->frame_size) {
997  ret = AVERROR(EINVAL);
998  goto end;
999  }
1000  }
1001  }
1002 
1003  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1004  if (!ret) {
1005  if (*got_packet_ptr) {
1006  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
1007  if (avpkt->pts == AV_NOPTS_VALUE)
1008  avpkt->pts = frame->pts;
1009  if (!avpkt->duration)
1010  avpkt->duration = ff_samples_to_time_base(avctx,
1011  frame->nb_samples);
1012  }
1013  avpkt->dts = avpkt->pts;
1014  } else {
1015  avpkt->size = 0;
1016  }
1017 
1018  if (!user_packet && avpkt->size) {
1019  uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
1020  if (new_data)
1021  avpkt->data = new_data;
1022  }
1023 
1024  avctx->frame_number++;
1025  }
1026 
1027  if (ret < 0 || !*got_packet_ptr) {
1028  av_free_packet(avpkt);
1029  av_init_packet(avpkt);
1030  goto end;
1031  }
1032 
1033  /* NOTE: if we add any audio encoders which output non-keyframe packets,
1034  * this needs to be moved to the encoders, but for now we can do it
1035  * here to simplify things */
1036  avpkt->flags |= AV_PKT_FLAG_KEY;
1037 
1038 end:
1039  if (padded_frame) {
1040  av_freep(&padded_frame->data[0]);
1041  if (padded_frame->extended_data != padded_frame->data)
1042  av_freep(&padded_frame->extended_data);
1043  av_freep(&padded_frame);
1044  }
1045 
1046  return ret;
1047 }
1048 
1049 #if FF_API_OLD_ENCODE_AUDIO
1050 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
1051  uint8_t *buf, int buf_size,
1052  const short *samples)
1053 {
1054  AVPacket pkt;
1055  AVFrame frame0 = { { 0 } };
1056  AVFrame *frame;
1057  int ret, samples_size, got_packet;
1058 
1059  av_init_packet(&pkt);
1060  pkt.data = buf;
1061  pkt.size = buf_size;
1062 
1063  if (samples) {
1064  frame = &frame0;
1066 
1067  if (avctx->frame_size) {
1068  frame->nb_samples = avctx->frame_size;
1069  } else {
1070  /* if frame_size is not set, the number of samples must be
1071  * calculated from the buffer size */
1072  int64_t nb_samples;
1073  if (!av_get_bits_per_sample(avctx->codec_id)) {
1074  av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not "
1075  "support this codec\n");
1076  return AVERROR(EINVAL);
1077  }
1078  nb_samples = (int64_t)buf_size * 8 /
1079  (av_get_bits_per_sample(avctx->codec_id) *
1080  avctx->channels);
1081  if (nb_samples >= INT_MAX)
1082  return AVERROR(EINVAL);
1083  frame->nb_samples = nb_samples;
1084  }
1085 
1086  /* it is assumed that the samples buffer is large enough based on the
1087  * relevant parameters */
1088  samples_size = av_samples_get_buffer_size(NULL, avctx->channels,
1089  frame->nb_samples,
1090  avctx->sample_fmt, 1);
1091  if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
1092  avctx->sample_fmt,
1093  (const uint8_t *)samples,
1094  samples_size, 1)))
1095  return ret;
1096 
1097  /* fabricate frame pts from sample count.
1098  * this is needed because the avcodec_encode_audio() API does not have
1099  * a way for the user to provide pts */
1100  frame->pts = ff_samples_to_time_base(avctx,
1101  avctx->internal->sample_count);
1102  avctx->internal->sample_count += frame->nb_samples;
1103  } else {
1104  frame = NULL;
1105  }
1106 
1107  got_packet = 0;
1108  ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);
1109  if (!ret && got_packet && avctx->coded_frame) {
1110  avctx->coded_frame->pts = pkt.pts;
1111  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1112  }
1113  /* free any side data since we cannot return it */
1114  if (pkt.side_data_elems > 0) {
1115  int i;
1116  for (i = 0; i < pkt.side_data_elems; i++)
1117  av_free(pkt.side_data[i].data);
1118  av_freep(&pkt.side_data);
1119  pkt.side_data_elems = 0;
1120  }
1121 
1122  if (frame && frame->extended_data != frame->data)
1123  av_free(frame->extended_data);
1124 
1125  return ret ? ret : pkt.size;
1126 }
1127 
1128 #endif
1129 
1130 #if FF_API_OLD_ENCODE_VIDEO
1131 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1132  const AVFrame *pict)
1133 {
1134  AVPacket pkt;
1135  int ret, got_packet = 0;
1136 
1137  if (buf_size < FF_MIN_BUFFER_SIZE) {
1138  av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
1139  return -1;
1140  }
1141 
1142  av_init_packet(&pkt);
1143  pkt.data = buf;
1144  pkt.size = buf_size;
1145 
1146  ret = avcodec_encode_video2(avctx, &pkt, pict, &got_packet);
1147  if (!ret && got_packet && avctx->coded_frame) {
1148  avctx->coded_frame->pts = pkt.pts;
1149  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1150  }
1151 
1152  /* free any side data since we cannot return it */
1153  if (pkt.side_data_elems > 0) {
1154  int i;
1155  for (i = 0; i < pkt.side_data_elems; i++)
1156  av_free(pkt.side_data[i].data);
1157  av_freep(&pkt.side_data);
1158  pkt.side_data_elems = 0;
1159  }
1160 
1161  return ret ? ret : pkt.size;
1162 }
1163 
1164 #endif
1165 
1167  AVPacket *avpkt,
1168  const AVFrame *frame,
1169  int *got_packet_ptr)
1170 {
1171  int ret;
1172  int user_packet = !!avpkt->data;
1173 
1174  *got_packet_ptr = 0;
1175 
1176  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
1177  av_free_packet(avpkt);
1178  av_init_packet(avpkt);
1179  avpkt->size = 0;
1180  return 0;
1181  }
1182 
1183  if (av_image_check_size(avctx->width, avctx->height, 0, avctx))
1184  return AVERROR(EINVAL);
1185 
1186  av_assert0(avctx->codec->encode2);
1187 
1188  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
1189  if (!ret) {
1190  if (!*got_packet_ptr)
1191  avpkt->size = 0;
1192  else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
1193  avpkt->pts = avpkt->dts = frame->pts;
1194 
1195  if (!user_packet && avpkt->size) {
1196  uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
1197  if (new_data)
1198  avpkt->data = new_data;
1199  }
1200 
1201  avctx->frame_number++;
1202  }
1203 
1204  if (ret < 0 || !*got_packet_ptr)
1205  av_free_packet(avpkt);
1206 
1207  emms_c();
1208  return ret;
1209 }
1210 
1211 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1212  const AVSubtitle *sub)
1213 {
1214  int ret;
1215  if (sub->start_display_time) {
1216  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1217  return -1;
1218  }
1219  if (sub->num_rects == 0 || !sub->rects)
1220  return -1;
1221  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
1222  avctx->frame_number++;
1223  return ret;
1224 }
1225 
1226 static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1227 {
1228  int size = 0;
1229  const uint8_t *data;
1230  uint32_t flags;
1231 
1232  if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE))
1233  return;
1234 
1235  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1236  if (!data || size < 4)
1237  return;
1238  flags = bytestream_get_le32(&data);
1239  size -= 4;
1240  if (size < 4) /* Required for any of the changes */
1241  return;
1243  avctx->channels = bytestream_get_le32(&data);
1244  size -= 4;
1245  }
1247  if (size < 8)
1248  return;
1249  avctx->channel_layout = bytestream_get_le64(&data);
1250  size -= 8;
1251  }
1252  if (size < 4)
1253  return;
1255  avctx->sample_rate = bytestream_get_le32(&data);
1256  size -= 4;
1257  }
1259  if (size < 8)
1260  return;
1261  avctx->width = bytestream_get_le32(&data);
1262  avctx->height = bytestream_get_le32(&data);
1263  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
1264  size -= 8;
1265  }
1266 }
1267 
1269  int *got_picture_ptr,
1270  AVPacket *avpkt)
1271 {
1272  int ret;
1273 
1274  *got_picture_ptr = 0;
1275  if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
1276  return -1;
1277 
1278  avctx->pkt = avpkt;
1279  apply_param_change(avctx, avpkt);
1280 
1281  avcodec_get_frame_defaults(picture);
1282 
1283  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
1285  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
1286  avpkt);
1287  else {
1288  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
1289  avpkt);
1290  picture->pkt_dts = avpkt->dts;
1291  /* get_buffer is supposed to set frame parameters */
1292  if (!(avctx->codec->capabilities & CODEC_CAP_DR1)) {
1293  picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
1294  picture->width = avctx->width;
1295  picture->height = avctx->height;
1296  picture->format = avctx->pix_fmt;
1297  }
1298  }
1299 
1300  emms_c(); //needed to avoid an emms_c() call before every return;
1301 
1302  if (*got_picture_ptr)
1303  avctx->frame_number++;
1304  } else
1305  ret = 0;
1306 
1307  /* many decoders assign whole AVFrames, thus overwriting extended_data;
1308  * make sure it's set correctly */
1309  picture->extended_data = picture->data;
1310 
1311  return ret;
1312 }
1313 
1314 #if FF_API_OLD_DECODE_AUDIO
1315 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
1316  int *frame_size_ptr,
1317  AVPacket *avpkt)
1318 {
1319  AVFrame frame = { { 0 } };
1320  int ret, got_frame = 0;
1321 
1322  if (avctx->get_buffer != avcodec_default_get_buffer) {
1323  av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
1324  "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
1325  av_log(avctx, AV_LOG_ERROR, "Please port your application to "
1326  "avcodec_decode_audio4()\n");
1328  }
1329 
1330  ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
1331 
1332  if (ret >= 0 && got_frame) {
1333  int ch, plane_size;
1334  int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
1335  int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
1336  frame.nb_samples,
1337  avctx->sample_fmt, 1);
1338  if (*frame_size_ptr < data_size) {
1339  av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
1340  "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1341  return AVERROR(EINVAL);
1342  }
1343 
1344  memcpy(samples, frame.extended_data[0], plane_size);
1345 
1346  if (planar && avctx->channels > 1) {
1347  uint8_t *out = ((uint8_t *)samples) + plane_size;
1348  for (ch = 1; ch < avctx->channels; ch++) {
1349  memcpy(out, frame.extended_data[ch], plane_size);
1350  out += plane_size;
1351  }
1352  }
1353  *frame_size_ptr = data_size;
1354  } else {
1355  *frame_size_ptr = 0;
1356  }
1357  return ret;
1358 }
1359 
1360 #endif
1361 
1363  AVFrame *frame,
1364  int *got_frame_ptr,
1365  AVPacket *avpkt)
1366 {
1367  int planar, channels;
1368  int ret = 0;
1369 
1370  *got_frame_ptr = 0;
1371 
1372  avctx->pkt = avpkt;
1373 
1374  if (!avpkt->data && avpkt->size) {
1375  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1376  return AVERROR(EINVAL);
1377  }
1378 
1379  apply_param_change(avctx, avpkt);
1380 
1382 
1383  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1384  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1385  if (ret >= 0 && *got_frame_ptr) {
1386  avctx->frame_number++;
1387  frame->pkt_dts = avpkt->dts;
1388  if (frame->format == AV_SAMPLE_FMT_NONE)
1389  frame->format = avctx->sample_fmt;
1390  }
1391  }
1392 
1393  /* many decoders assign whole AVFrames, thus overwriting extended_data;
1394  * make sure it's set correctly; assume decoders that actually use
1395  * extended_data are doing it correctly */
1396  planar = av_sample_fmt_is_planar(frame->format);
1398  if (!(planar && channels > AV_NUM_DATA_POINTERS))
1399  frame->extended_data = frame->data;
1400 
1401  return ret;
1402 }
1403 
1405  int *got_sub_ptr,
1406  AVPacket *avpkt)
1407 {
1408  int ret;
1409 
1410  avctx->pkt = avpkt;
1411  *got_sub_ptr = 0;
1412  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1413  if (*got_sub_ptr)
1414  avctx->frame_number++;
1415  return ret;
1416 }
1417 
1419 {
1420  int i;
1421 
1422  for (i = 0; i < sub->num_rects; i++) {
1423  av_freep(&sub->rects[i]->pict.data[0]);
1424  av_freep(&sub->rects[i]->pict.data[1]);
1425  av_freep(&sub->rects[i]->pict.data[2]);
1426  av_freep(&sub->rects[i]->pict.data[3]);
1427  av_freep(&sub->rects[i]->text);
1428  av_freep(&sub->rects[i]->ass);
1429  av_freep(&sub->rects[i]);
1430  }
1431 
1432  av_freep(&sub->rects);
1433 
1434  memset(sub, 0, sizeof(AVSubtitle));
1435 }
1436 
1438 {
1439  /* If there is a user-supplied mutex locking routine, call it. */
1440  if (ff_lockmgr_cb) {
1442  return -1;
1443  }
1444 
1446  if (entangled_thread_counter != 1) {
1447  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1449  return -1;
1450  }
1451 
1452  if (avcodec_is_open(avctx)) {
1453  if (HAVE_THREADS && avctx->thread_opaque)
1454  ff_thread_free(avctx);
1455  if (avctx->codec && avctx->codec->close)
1456  avctx->codec->close(avctx);
1458  avctx->coded_frame = NULL;
1459  av_freep(&avctx->internal);
1460  }
1461 
1462  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1463  av_opt_free(avctx->priv_data);
1464  av_opt_free(avctx);
1465  av_freep(&avctx->priv_data);
1466  if (av_codec_is_encoder(avctx->codec))
1467  av_freep(&avctx->extradata);
1468  avctx->codec = NULL;
1469  avctx->active_thread_type = 0;
1471 
1472  /* Release any user-supplied mutex. */
1473  if (ff_lockmgr_cb) {
1474  (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1475  }
1476  return 0;
1477 }
1478 
1479 static AVCodec *find_encdec(enum AVCodecID id, int encoder)
1480 {
1481  AVCodec *p, *experimental = NULL;
1482  p = first_avcodec;
1483  while (p) {
1484  if ((encoder ? av_codec_is_encoder(p) : av_codec_is_decoder(p)) &&
1485  p->id == id) {
1486  if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1487  experimental = p;
1488  } else
1489  return p;
1490  }
1491  p = p->next;
1492  }
1493  return experimental;
1494 }
1495 
1497 {
1498  return find_encdec(id, 1);
1499 }
1500 
1502 {
1503  AVCodec *p;
1504  if (!name)
1505  return NULL;
1506  p = first_avcodec;
1507  while (p) {
1508  if (av_codec_is_encoder(p) && strcmp(name, p->name) == 0)
1509  return p;
1510  p = p->next;
1511  }
1512  return NULL;
1513 }
1514 
1516 {
1517  return find_encdec(id, 0);
1518 }
1519 
1521 {
1522  AVCodec *p;
1523  if (!name)
1524  return NULL;
1525  p = first_avcodec;
1526  while (p) {
1527  if (av_codec_is_decoder(p) && strcmp(name, p->name) == 0)
1528  return p;
1529  p = p->next;
1530  }
1531  return NULL;
1532 }
1533 
1535 {
1536  int bit_rate;
1537  int bits_per_sample;
1538 
1539  switch (ctx->codec_type) {
1540  case AVMEDIA_TYPE_VIDEO:
1541  case AVMEDIA_TYPE_DATA:
1542  case AVMEDIA_TYPE_SUBTITLE:
1544  bit_rate = ctx->bit_rate;
1545  break;
1546  case AVMEDIA_TYPE_AUDIO:
1547  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1548  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1549  break;
1550  default:
1551  bit_rate = 0;
1552  break;
1553  }
1554  return bit_rate;
1555 }
1556 
1557 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1558 {
1559  int i, len, ret = 0;
1560 
1561  for (i = 0; i < 4; i++) {
1562  len = snprintf(buf, buf_size,
1563  isprint(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);
1564  buf += len;
1565  buf_size = buf_size > len ? buf_size - len : 0;
1566  ret += len;
1567  codec_tag >>= 8;
1568  }
1569  return ret;
1570 }
1571 
1572 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1573 {
1574  const char *codec_name;
1575  const char *profile = NULL;
1576  const AVCodec *p;
1577  char buf1[32];
1578  int bitrate;
1579  AVRational display_aspect_ratio;
1580 
1581  if (enc->codec)
1582  p = enc->codec;
1583  else if (encode)
1584  p = avcodec_find_encoder(enc->codec_id);
1585  else
1586  p = avcodec_find_decoder(enc->codec_id);
1587 
1588  if (p) {
1589  codec_name = p->name;
1590  profile = av_get_profile_name(p, enc->profile);
1591  } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) {
1592  /* fake mpeg2 transport stream codec (currently not
1593  * registered) */
1594  codec_name = "mpeg2ts";
1595  } else if (enc->codec_name[0] != '\0') {
1596  codec_name = enc->codec_name;
1597  } else {
1598  /* output avi tags */
1599  char tag_buf[32];
1600  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1601  snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
1602  codec_name = buf1;
1603  }
1604 
1605  switch (enc->codec_type) {
1606  case AVMEDIA_TYPE_VIDEO:
1607  snprintf(buf, buf_size,
1608  "Video: %s%s",
1609  codec_name, enc->mb_decision ? " (hq)" : "");
1610  if (profile)
1611  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1612  " (%s)", profile);
1613  if (enc->pix_fmt != AV_PIX_FMT_NONE) {
1614  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1615  ", %s",
1617  }
1618  if (enc->width) {
1619  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1620  ", %dx%d",
1621  enc->width, enc->height);
1622  if (enc->sample_aspect_ratio.num) {
1623  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1624  enc->width * enc->sample_aspect_ratio.num,
1625  enc->height * enc->sample_aspect_ratio.den,
1626  1024 * 1024);
1627  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1628  " [PAR %d:%d DAR %d:%d]",
1630  display_aspect_ratio.num, display_aspect_ratio.den);
1631  }
1632  if (av_log_get_level() >= AV_LOG_DEBUG) {
1633  int g = av_gcd(enc->time_base.num, enc->time_base.den);
1634  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1635  ", %d/%d",
1636  enc->time_base.num / g, enc->time_base.den / g);
1637  }
1638  }
1639  if (encode) {
1640  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1641  ", q=%d-%d", enc->qmin, enc->qmax);
1642  }
1643  break;
1644  case AVMEDIA_TYPE_AUDIO:
1645  snprintf(buf, buf_size,
1646  "Audio: %s",
1647  codec_name);
1648  if (profile)
1649  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1650  " (%s)", profile);
1651  if (enc->sample_rate) {
1652  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1653  ", %d Hz", enc->sample_rate);
1654  }
1655  av_strlcat(buf, ", ", buf_size);
1656  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1657  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1658  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1659  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1660  }
1661  break;
1662  case AVMEDIA_TYPE_DATA:
1663  snprintf(buf, buf_size, "Data: %s", codec_name);
1664  break;
1665  case AVMEDIA_TYPE_SUBTITLE:
1666  snprintf(buf, buf_size, "Subtitle: %s", codec_name);
1667  break;
1669  snprintf(buf, buf_size, "Attachment: %s", codec_name);
1670  break;
1671  default:
1672  snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
1673  return;
1674  }
1675  if (encode) {
1676  if (enc->flags & CODEC_FLAG_PASS1)
1677  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1678  ", pass 1");
1679  if (enc->flags & CODEC_FLAG_PASS2)
1680  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1681  ", pass 2");
1682  }
1683  bitrate = get_bit_rate(enc);
1684  if (bitrate != 0) {
1685  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1686  ", %d kb/s", bitrate / 1000);
1687  }
1688 }
1689 
1690 const char *av_get_profile_name(const AVCodec *codec, int profile)
1691 {
1692  const AVProfile *p;
1693  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1694  return NULL;
1695 
1696  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1697  if (p->profile == profile)
1698  return p->name;
1699 
1700  return NULL;
1701 }
1702 
1703 unsigned avcodec_version(void)
1704 {
1705  return LIBAVCODEC_VERSION_INT;
1706 }
1707 
1708 const char *avcodec_configuration(void)
1709 {
1710  return LIBAV_CONFIGURATION;
1711 }
1712 
1713 const char *avcodec_license(void)
1714 {
1715 #define LICENSE_PREFIX "libavcodec license: "
1716  return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1717 }
1718 
1720 {
1722  ff_thread_flush(avctx);
1723  else if (avctx->codec->flush)
1724  avctx->codec->flush(avctx);
1725 }
1726 
1728 {
1729  AVCodecInternal *avci = s->internal;
1730  int i, j;
1731 
1732  if (!avci->buffer)
1733  return;
1734 
1735  if (avci->buffer_count)
1736  av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n",
1737  avci->buffer_count);
1738  for (i = 0; i < INTERNAL_BUFFER_SIZE; i++) {
1739  InternalBuffer *buf = &avci->buffer[i];
1740  for (j = 0; j < 4; j++) {
1741  av_freep(&buf->base[j]);
1742  buf->data[j] = NULL;
1743  }
1744  }
1745  av_freep(&avci->buffer);
1746 
1747  avci->buffer_count = 0;
1748 }
1749 
1751 {
1752  AVCodecInternal *avci = avctx->internal;
1753  av_freep(&avci->audio_data);
1754 }
1755 
1757 {
1758  switch (avctx->codec_type) {
1759  case AVMEDIA_TYPE_VIDEO:
1760  video_free_buffers(avctx);
1761  break;
1762  case AVMEDIA_TYPE_AUDIO:
1763  audio_free_buffers(avctx);
1764  break;
1765  default:
1766  break;
1767  }
1768 }
1769 
1771 {
1772  switch (codec_id) {
1773  case AV_CODEC_ID_ADPCM_CT:
1779  return 4;
1780  case AV_CODEC_ID_PCM_ALAW:
1781  case AV_CODEC_ID_PCM_MULAW:
1782  case AV_CODEC_ID_PCM_S8:
1783  case AV_CODEC_ID_PCM_U8:
1784  case AV_CODEC_ID_PCM_ZORK:
1785  return 8;
1786  case AV_CODEC_ID_PCM_S16BE:
1787  case AV_CODEC_ID_PCM_S16LE:
1789  case AV_CODEC_ID_PCM_U16BE:
1790  case AV_CODEC_ID_PCM_U16LE:
1791  return 16;
1793  case AV_CODEC_ID_PCM_S24BE:
1794  case AV_CODEC_ID_PCM_S24LE:
1795  case AV_CODEC_ID_PCM_U24BE:
1796  case AV_CODEC_ID_PCM_U24LE:
1797  return 24;
1798  case AV_CODEC_ID_PCM_S32BE:
1799  case AV_CODEC_ID_PCM_S32LE:
1800  case AV_CODEC_ID_PCM_U32BE:
1801  case AV_CODEC_ID_PCM_U32LE:
1802  case AV_CODEC_ID_PCM_F32BE:
1803  case AV_CODEC_ID_PCM_F32LE:
1804  return 32;
1805  case AV_CODEC_ID_PCM_F64BE:
1806  case AV_CODEC_ID_PCM_F64LE:
1807  return 64;
1808  default:
1809  return 0;
1810  }
1811 }
1812 
1814 {
1815  switch (codec_id) {
1817  return 2;
1819  return 3;
1823  case AV_CODEC_ID_ADPCM_SWF:
1824  case AV_CODEC_ID_ADPCM_MS:
1825  return 4;
1826  default:
1827  return av_get_exact_bits_per_sample(codec_id);
1828  }
1829 }
1830 
1831 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
1832 {
1833  int id, sr, ch, ba, tag, bps;
1834 
1835  id = avctx->codec_id;
1836  sr = avctx->sample_rate;
1837  ch = avctx->channels;
1838  ba = avctx->block_align;
1839  tag = avctx->codec_tag;
1840  bps = av_get_exact_bits_per_sample(avctx->codec_id);
1841 
1842  /* codecs with an exact constant bits per sample */
1843  if (bps > 0 && ch > 0 && frame_bytes > 0)
1844  return (frame_bytes * 8) / (bps * ch);
1845  bps = avctx->bits_per_coded_sample;
1846 
1847  /* codecs with a fixed packet duration */
1848  switch (id) {
1849  case AV_CODEC_ID_ADPCM_ADX: return 32;
1850  case AV_CODEC_ID_ADPCM_IMA_QT: return 64;
1851  case AV_CODEC_ID_ADPCM_EA_XAS: return 128;
1852  case AV_CODEC_ID_AMR_NB:
1853  case AV_CODEC_ID_GSM:
1854  case AV_CODEC_ID_QCELP:
1855  case AV_CODEC_ID_RA_144:
1856  case AV_CODEC_ID_RA_288: return 160;
1857  case AV_CODEC_ID_IMC: return 256;
1858  case AV_CODEC_ID_AMR_WB:
1859  case AV_CODEC_ID_GSM_MS: return 320;
1860  case AV_CODEC_ID_MP1: return 384;
1861  case AV_CODEC_ID_ATRAC1: return 512;
1862  case AV_CODEC_ID_ATRAC3: return 1024;
1863  case AV_CODEC_ID_MP2:
1864  case AV_CODEC_ID_MUSEPACK7: return 1152;
1865  case AV_CODEC_ID_AC3: return 1536;
1866  }
1867 
1868  if (sr > 0) {
1869  /* calc from sample rate */
1870  if (id == AV_CODEC_ID_TTA)
1871  return 256 * sr / 245;
1872 
1873  if (ch > 0) {
1874  /* calc from sample rate and channels */
1875  if (id == AV_CODEC_ID_BINKAUDIO_DCT)
1876  return (480 << (sr / 22050)) / ch;
1877  }
1878  }
1879 
1880  if (ba > 0) {
1881  /* calc from block_align */
1882  if (id == AV_CODEC_ID_SIPR) {
1883  switch (ba) {
1884  case 20: return 160;
1885  case 19: return 144;
1886  case 29: return 288;
1887  case 37: return 480;
1888  }
1889  } else if (id == AV_CODEC_ID_ILBC) {
1890  switch (ba) {
1891  case 38: return 160;
1892  case 50: return 240;
1893  }
1894  }
1895  }
1896 
1897  if (frame_bytes > 0) {
1898  /* calc from frame_bytes only */
1899  if (id == AV_CODEC_ID_TRUESPEECH)
1900  return 240 * (frame_bytes / 32);
1901  if (id == AV_CODEC_ID_NELLYMOSER)
1902  return 256 * (frame_bytes / 64);
1903 
1904  if (bps > 0) {
1905  /* calc from frame_bytes and bits_per_coded_sample */
1906  if (id == AV_CODEC_ID_ADPCM_G726)
1907  return frame_bytes * 8 / bps;
1908  }
1909 
1910  if (ch > 0) {
1911  /* calc from frame_bytes and channels */
1912  switch (id) {
1913  case AV_CODEC_ID_ADPCM_4XM:
1915  return (frame_bytes - 4 * ch) * 2 / ch;
1917  return (frame_bytes - 4) * 2 / ch;
1919  return (frame_bytes - 8) * 2 / ch;
1920  case AV_CODEC_ID_ADPCM_XA:
1921  return (frame_bytes / 128) * 224 / ch;
1923  return (frame_bytes - 6 - ch) / ch;
1924  case AV_CODEC_ID_ROQ_DPCM:
1925  return (frame_bytes - 8) / ch;
1926  case AV_CODEC_ID_XAN_DPCM:
1927  return (frame_bytes - 2 * ch) / ch;
1928  case AV_CODEC_ID_MACE3:
1929  return 3 * frame_bytes / ch;
1930  case AV_CODEC_ID_MACE6:
1931  return 6 * frame_bytes / ch;
1932  case AV_CODEC_ID_PCM_LXF:
1933  return 2 * (frame_bytes / (5 * ch));
1934  }
1935 
1936  if (tag) {
1937  /* calc from frame_bytes, channels, and codec_tag */
1938  if (id == AV_CODEC_ID_SOL_DPCM) {
1939  if (tag == 3)
1940  return frame_bytes / ch;
1941  else
1942  return frame_bytes * 2 / ch;
1943  }
1944  }
1945 
1946  if (ba > 0) {
1947  /* calc from frame_bytes, channels, and block_align */
1948  int blocks = frame_bytes / ba;
1949  switch (avctx->codec_id) {
1951  return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
1953  return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
1955  return blocks * (1 + (ba - 4 * ch) * 2 / ch);
1956  case AV_CODEC_ID_ADPCM_MS:
1957  return blocks * (2 + (ba - 7 * ch) * 2 / ch);
1958  }
1959  }
1960 
1961  if (bps > 0) {
1962  /* calc from frame_bytes, channels, and bits_per_coded_sample */
1963  switch (avctx->codec_id) {
1964  case AV_CODEC_ID_PCM_DVD:
1965  return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
1967  return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8);
1968  case AV_CODEC_ID_S302M:
1969  return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
1970  }
1971  }
1972  }
1973  }
1974 
1975  return 0;
1976 }
1977 
1978 #if !HAVE_THREADS
1980 {
1981  return -1;
1982 }
1983 
1984 #endif
1985 
1986 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1987 {
1988  unsigned int n = 0;
1989 
1990  while (v >= 0xff) {
1991  *s++ = 0xff;
1992  v -= 0xff;
1993  n++;
1994  }
1995  *s = v;
1996  n++;
1997  return n;
1998 }
1999 
2000 int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
2001 {
2002  int i;
2003  for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ;
2004  return i;
2005 }
2006 
2007 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
2008 {
2009  av_log(avc, AV_LOG_WARNING, "%s is not implemented. Update your Libav "
2010  "version to the newest one from Git. If the problem still "
2011  "occurs, it means that your file has a feature which has not "
2012  "been implemented.\n", feature);
2013  if(want_sample)
2015 }
2016 
2017 void av_log_ask_for_sample(void *avc, const char *msg, ...)
2018 {
2019  va_list argument_list;
2020 
2021  va_start(argument_list, msg);
2022 
2023  if (msg)
2024  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
2025  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
2026  "of this file to ftp://upload.libav.org/incoming/ "
2027  "and contact the libav-devel mailing list.\n");
2028 
2029  va_end(argument_list);
2030 }
2031 
2033 
2035 {
2036  AVHWAccel **p = &first_hwaccel;
2037  while (*p)
2038  p = &(*p)->next;
2039  *p = hwaccel;
2040  hwaccel->next = NULL;
2041 }
2042 
2044 {
2045  return hwaccel ? hwaccel->next : first_hwaccel;
2046 }
2047 
2049 {
2050  AVHWAccel *hwaccel = NULL;
2051 
2052  while ((hwaccel = av_hwaccel_next(hwaccel)))
2053  if (hwaccel->id == codec_id
2054  && hwaccel->pix_fmt == pix_fmt)
2055  return hwaccel;
2056  return NULL;
2057 }
2058 
2059 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
2060 {
2061  if (ff_lockmgr_cb) {
2063  return -1;
2065  return -1;
2066  }
2067 
2068  ff_lockmgr_cb = cb;
2069 
2070  if (ff_lockmgr_cb) {
2072  return -1;
2074  return -1;
2075  }
2076  return 0;
2077 }
2078 
2080 {
2081  if (ff_lockmgr_cb) {
2083  return -1;
2084  }
2085  return 0;
2086 }
2087 
2089 {
2090  if (ff_lockmgr_cb) {
2092  return -1;
2093  }
2094  return 0;
2095 }
2096 
2097 unsigned int avpriv_toupper4(unsigned int x)
2098 {
2099  return toupper(x & 0xFF)
2100  + (toupper((x >> 8) & 0xFF) << 8)
2101  + (toupper((x >> 16) & 0xFF) << 16)
2102  + (toupper((x >> 24) & 0xFF) << 24);
2103 }
2104 
2105 #if !HAVE_THREADS
2106 
2108 {
2109  f->owner = avctx;
2110  return ff_get_buffer(avctx, f);
2111 }
2112 
2114 {
2115  f->owner->release_buffer(f->owner, f);
2116 }
2117 
2119 {
2120 }
2121 
2122 void ff_thread_report_progress(AVFrame *f, int progress, int field)
2123 {
2124 }
2125 
2126 void ff_thread_await_progress(AVFrame *f, int progress, int field)
2127 {
2128 }
2129 
2130 #endif
2131 
2133 {
2134  if (codec_id <= AV_CODEC_ID_NONE)
2135  return AVMEDIA_TYPE_UNKNOWN;
2136  else if (codec_id < AV_CODEC_ID_FIRST_AUDIO)
2137  return AVMEDIA_TYPE_VIDEO;
2138  else if (codec_id < AV_CODEC_ID_FIRST_SUBTITLE)
2139  return AVMEDIA_TYPE_AUDIO;
2140  else if (codec_id < AV_CODEC_ID_FIRST_UNKNOWN)
2141  return AVMEDIA_TYPE_SUBTITLE;
2142 
2143  return AVMEDIA_TYPE_UNKNOWN;
2144 }
2145 
2147 {
2148  return !!s->internal;
2149 }
#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:1479
static int16_t * samples
#define HAVE_THREADS
Definition: config.h:236
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:1496
#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:2122
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:2059
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:1708
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:1713
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:2034
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:903
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:1557
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:2107
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:946
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:1404
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:1727
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:597
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:1750
#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:1166
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:2000
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:2126
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:1501
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:1437
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:2032
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:2043
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:1813
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:2097
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:2146
g
Definition: yuv2rgb.c:540
int capabilities
Codec capabilities.
Definition: avcodec.h:2979
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:1979
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:2132
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:2048
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:618
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:1770
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
Definition: utils.c:591
int width
picture width / height.
Definition: avcodec.h:1508
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:524
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:2118
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:2017
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:880
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:1719
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:1690
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:1515
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:1418
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:1756
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:489
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:1986
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:604
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:2007
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:645
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:2113
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:1831
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:1520
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:2079
static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1226
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:579
unsigned bps
Definition: movenc.c:803
DSP utils.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1572
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:1703
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:1534
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:1268
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:630
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:2088
#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:1211
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:567
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:1362
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:145