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"
30 #include "libavutil/crc.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/audioconvert.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 "imgconvert.h"
41 #include "thread.h"
42 #include "audioconvert.h"
43 #include "internal.h"
44 #include "bytestream.h"
45 #include <stdlib.h>
46 #include <stdarg.h>
47 #include <limits.h>
48 #include <float.h>
49 
50 static int volatile entangled_thread_counter=0;
51 static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
52 static void *codec_mutex;
53 static void *avformat_mutex;
54 
55 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
56 {
57  if(min_size < *size)
58  return ptr;
59 
60  min_size= FFMAX(17*min_size/16 + 32, min_size);
61 
62  ptr= av_realloc(ptr, min_size);
63  if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
64  min_size= 0;
65 
66  *size= min_size;
67 
68  return ptr;
69 }
70 
71 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
72 {
73  void **p = ptr;
74  if (min_size < *size)
75  return;
76  min_size= FFMAX(17*min_size/16 + 32, min_size);
77  av_free(*p);
78  *p = av_malloc(min_size);
79  if (!*p) min_size = 0;
80  *size= min_size;
81 }
82 
83 /* encoder management */
85 
87  if(c) return c->next;
88  else return first_avcodec;
89 }
90 
91 #if !FF_API_AVCODEC_INIT
92 static
93 #endif
94 void avcodec_init(void)
95 {
96  static int initialized = 0;
97 
98  if (initialized != 0)
99  return;
100  initialized = 1;
101 
103 }
104 
106 {
107  return codec && (codec->encode || codec->encode2);
108 }
109 
111 {
112  return codec && codec->decode;
113 }
114 
116 {
117  AVCodec **p;
118  avcodec_init();
119  p = &first_avcodec;
120  while (*p != NULL) p = &(*p)->next;
121  *p = codec;
122  codec->next = NULL;
123 
124  if (codec->init_static_data)
125  codec->init_static_data(codec);
126 }
127 
129 {
130  return EDGE_WIDTH;
131 }
132 
134  s->coded_width = width;
135  s->coded_height= height;
136  s->width = -((-width )>>s->lowres);
137  s->height= -((-height)>>s->lowres);
138 }
139 
140 #define INTERNAL_BUFFER_SIZE (32+1)
141 
143  int linesize_align[AV_NUM_DATA_POINTERS])
144 {
145  int i;
146  int w_align= 1;
147  int h_align= 1;
148 
149  switch(s->pix_fmt){
150  case PIX_FMT_YUV420P:
151  case PIX_FMT_YUYV422:
152  case PIX_FMT_UYVY422:
153  case PIX_FMT_YUV422P:
154  case PIX_FMT_YUV440P:
155  case PIX_FMT_YUV444P:
156  case PIX_FMT_GBRP:
157  case PIX_FMT_GRAY8:
158  case PIX_FMT_GRAY16BE:
159  case PIX_FMT_GRAY16LE:
160  case PIX_FMT_YUVJ420P:
161  case PIX_FMT_YUVJ422P:
162  case PIX_FMT_YUVJ440P:
163  case PIX_FMT_YUVJ444P:
164  case PIX_FMT_YUVA420P:
165  case PIX_FMT_YUV420P9LE:
166  case PIX_FMT_YUV420P9BE:
167  case PIX_FMT_YUV420P10LE:
168  case PIX_FMT_YUV420P10BE:
169  case PIX_FMT_YUV422P9LE:
170  case PIX_FMT_YUV422P9BE:
171  case PIX_FMT_YUV422P10LE:
172  case PIX_FMT_YUV422P10BE:
173  case PIX_FMT_YUV444P9LE:
174  case PIX_FMT_YUV444P9BE:
175  case PIX_FMT_YUV444P10LE:
176  case PIX_FMT_YUV444P10BE:
177  case PIX_FMT_GBRP9LE:
178  case PIX_FMT_GBRP9BE:
179  case PIX_FMT_GBRP10LE:
180  case PIX_FMT_GBRP10BE:
181  w_align = 16; //FIXME assume 16 pixel per macroblock
182  h_align = 16 * 2; // interlaced needs 2 macroblocks height
183  break;
184  case PIX_FMT_YUV411P:
185  case PIX_FMT_UYYVYY411:
186  w_align=32;
187  h_align=8;
188  break;
189  case PIX_FMT_YUV410P:
190  if(s->codec_id == CODEC_ID_SVQ1){
191  w_align=64;
192  h_align=64;
193  }
194  case PIX_FMT_RGB555:
195  if(s->codec_id == CODEC_ID_RPZA){
196  w_align=4;
197  h_align=4;
198  }
199  case PIX_FMT_PAL8:
200  case PIX_FMT_BGR8:
201  case PIX_FMT_RGB8:
202  if(s->codec_id == CODEC_ID_SMC){
203  w_align=4;
204  h_align=4;
205  }
206  break;
207  case PIX_FMT_BGR24:
208  if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
209  w_align=4;
210  h_align=4;
211  }
212  break;
213  default:
214  w_align= 1;
215  h_align= 1;
216  break;
217  }
218 
219  *width = FFALIGN(*width , w_align);
220  *height= FFALIGN(*height, h_align);
221  if(s->codec_id == CODEC_ID_H264 || s->lowres)
222  *height+=2; // some of the optimized chroma MC reads one line too much
223  // which is also done in mpeg decoders with lowres > 0
224 
225  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
226  linesize_align[i] = STRIDE_ALIGN;
227 //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
228 //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
229 //picture size unneccessarily in some cases. The solution here is not
230 //pretty and better ideas are welcome!
231 #if HAVE_MMX
232  if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
233  s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
234  s->codec_id == CODEC_ID_VP6A) {
235  for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
236  linesize_align[i] = 16;
237  }
238 #endif
239 }
240 
242  int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
243  int linesize_align[AV_NUM_DATA_POINTERS];
244  int align;
245  avcodec_align_dimensions2(s, width, height, linesize_align);
246  align = FFMAX(linesize_align[0], linesize_align[3]);
247  linesize_align[1] <<= chroma_shift;
248  linesize_align[2] <<= chroma_shift;
249  align = FFMAX3(align, linesize_align[1], linesize_align[2]);
250  *width=FFALIGN(*width, align);
251 }
252 
254  enum AVSampleFormat sample_fmt, const uint8_t *buf,
255  int buf_size, int align)
256 {
257  int ch, planar, needed_size, ret = 0;
258 
259  needed_size = av_samples_get_buffer_size(NULL, nb_channels,
260  frame->nb_samples, sample_fmt,
261  align);
262  if (buf_size < needed_size)
263  return AVERROR(EINVAL);
264 
265  planar = av_sample_fmt_is_planar(sample_fmt);
266  if (planar && nb_channels > AV_NUM_DATA_POINTERS) {
267  if (!(frame->extended_data = av_mallocz(nb_channels *
268  sizeof(*frame->extended_data))))
269  return AVERROR(ENOMEM);
270  } else {
271  frame->extended_data = frame->data;
272  }
273 
274  if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0],
275  buf, nb_channels, frame->nb_samples,
276  sample_fmt, align)) < 0) {
277  if (frame->extended_data != frame->data)
278  av_free(frame->extended_data);
279  return ret;
280  }
281  if (frame->extended_data != frame->data) {
282  for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++)
283  frame->data[ch] = frame->extended_data[ch];
284  }
285 
286  return ret;
287 }
288 
289 static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
290 {
291  AVCodecInternal *avci = avctx->internal;
292  InternalBuffer *buf;
293  int buf_size, ret;
294 
295  buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
296  frame->nb_samples, avctx->sample_fmt,
297  32);
298  if (buf_size < 0)
299  return AVERROR(EINVAL);
300 
301  /* allocate InternalBuffer if needed */
302  if (!avci->buffer) {
303  avci->buffer = av_mallocz(sizeof(InternalBuffer));
304  if (!avci->buffer)
305  return AVERROR(ENOMEM);
306  }
307  buf = avci->buffer;
308 
309  /* if there is a previously-used internal buffer, check its size and
310  channel count to see if we can reuse it */
311  if (buf->extended_data) {
312  /* if current buffer is too small, free it */
313  if (buf->extended_data[0] && buf_size > buf->audio_data_size) {
314  av_free(buf->extended_data[0]);
315  if (buf->extended_data != buf->data)
316  av_free(&buf->extended_data);
317  buf->extended_data = NULL;
318  buf->data[0] = NULL;
319  }
320  /* if number of channels has changed, reset and/or free extended data
321  pointers but leave data buffer in buf->data[0] for reuse */
322  if (buf->nb_channels != avctx->channels) {
323  if (buf->extended_data != buf->data)
324  av_free(buf->extended_data);
325  buf->extended_data = NULL;
326  }
327  }
328 
329  /* if there is no previous buffer or the previous buffer cannot be used
330  as-is, allocate a new buffer and/or rearrange the channel pointers */
331  if (!buf->extended_data) {
332  if (!buf->data[0]) {
333  if (!(buf->data[0] = av_mallocz(buf_size)))
334  return AVERROR(ENOMEM);
335  buf->audio_data_size = buf_size;
336  }
337  if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
338  avctx->sample_fmt, buf->data[0],
339  buf->audio_data_size, 32)))
340  return ret;
341 
342  if (frame->extended_data == frame->data)
343  buf->extended_data = buf->data;
344  else
345  buf->extended_data = frame->extended_data;
346  memcpy(buf->data, frame->data, sizeof(frame->data));
347  buf->linesize[0] = frame->linesize[0];
348  buf->nb_channels = avctx->channels;
349  } else {
350  /* copy InternalBuffer info to the AVFrame */
351  frame->extended_data = buf->extended_data;
352  frame->linesize[0] = buf->linesize[0];
353  memcpy(frame->data, buf->data, sizeof(frame->data));
354  }
355 
356  frame->type = FF_BUFFER_TYPE_INTERNAL;
357 
358  if (avctx->pkt) frame->pkt_pts = avctx->pkt->pts;
359  else frame->pkt_pts = AV_NOPTS_VALUE;
360  frame->reordered_opaque = avctx->reordered_opaque;
361 
362  if (avctx->debug & FF_DEBUG_BUFFERS)
363  av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
364  "internal audio buffer used\n", frame);
365 
366  return 0;
367 }
368 
370 {
371  int i;
372  int w= s->width;
373  int h= s->height;
374  InternalBuffer *buf;
375  AVCodecInternal *avci = s->internal;
376 
377  if(pic->data[0]!=NULL) {
378  av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
379  return -1;
380  }
381  if(avci->buffer_count >= INTERNAL_BUFFER_SIZE) {
382  av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n");
383  return -1;
384  }
385 
386  if(av_image_check_size(w, h, 0, s))
387  return -1;
388 
389  if (!avci->buffer) {
391  sizeof(InternalBuffer));
392  }
393 
394  buf = &avci->buffer[avci->buffer_count];
395 
396  if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
398  av_log_missing_feature(s, "Width/height changing with frame threads is", 0);
399  return -1;
400  }
401 
402  for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
403  av_freep(&buf->base[i]);
404  buf->data[i]= NULL;
405  }
406  }
407 
408  if (!buf->base[0]) {
409  int h_chroma_shift, v_chroma_shift;
410  int size[4] = {0};
411  int tmpsize;
412  int unaligned;
414  int stride_align[AV_NUM_DATA_POINTERS];
415  const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1;
416 
417  avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
418 
419  avcodec_align_dimensions2(s, &w, &h, stride_align);
420 
421  if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
422  w+= EDGE_WIDTH*2;
423  h+= EDGE_WIDTH*2;
424  }
425 
426  do {
427  // NOTE: do not align linesizes individually, this breaks e.g. assumptions
428  // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
429  av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
430  // increase alignment of w for next try (rhs gives the lowest bit set in w)
431  w += w & ~(w-1);
432 
433  unaligned = 0;
434  for (i=0; i<4; i++){
435  unaligned |= picture.linesize[i] % stride_align[i];
436  }
437  } while (unaligned);
438 
439  tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
440  if (tmpsize < 0)
441  return -1;
442 
443  for (i=0; i<3 && picture.data[i+1]; i++)
444  size[i] = picture.data[i+1] - picture.data[i];
445  size[i] = tmpsize - (picture.data[i] - picture.data[0]);
446 
447  memset(buf->base, 0, sizeof(buf->base));
448  memset(buf->data, 0, sizeof(buf->data));
449 
450  for(i=0; i<4 && size[i]; i++){
451  const int h_shift= i==0 ? 0 : h_chroma_shift;
452  const int v_shift= i==0 ? 0 : v_chroma_shift;
453 
454  buf->linesize[i]= picture.linesize[i];
455 
456  buf->base[i]= av_malloc(size[i]+16); //FIXME 16
457  if(buf->base[i]==NULL) return -1;
458  memset(buf->base[i], 128, size[i]);
459 
460  // no edge if EDGE EMU or not planar YUV
461  if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
462  buf->data[i] = buf->base[i];
463  else
464  buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]);
465  }
466  for (; i < AV_NUM_DATA_POINTERS; i++) {
467  buf->base[i] = buf->data[i] = NULL;
468  buf->linesize[i] = 0;
469  }
470  if(size[1] && !size[2])
471  ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt);
472  buf->width = s->width;
473  buf->height = s->height;
474  buf->pix_fmt= s->pix_fmt;
475  }
477 
478  for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
479  pic->base[i]= buf->base[i];
480  pic->data[i]= buf->data[i];
481  pic->linesize[i]= buf->linesize[i];
482  }
483  pic->extended_data = pic->data;
484  avci->buffer_count++;
485 
486  if(s->pkt) pic->pkt_pts= s->pkt->pts;
487  else pic->pkt_pts= AV_NOPTS_VALUE;
489 
490  if(s->debug&FF_DEBUG_BUFFERS)
491  av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
492  "buffers used\n", pic, avci->buffer_count);
493 
494  return 0;
495 }
496 
498 {
499  switch (avctx->codec_type) {
500  case AVMEDIA_TYPE_VIDEO:
501  return video_get_buffer(avctx, frame);
502  case AVMEDIA_TYPE_AUDIO:
503  return audio_get_buffer(avctx, frame);
504  default:
505  return -1;
506  }
507 }
508 
510  int i;
511  InternalBuffer *buf, *last;
512  AVCodecInternal *avci = s->internal;
513 
514  assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
515 
516  assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
517  assert(avci->buffer_count);
518 
519  if (avci->buffer) {
520  buf = NULL; /* avoids warning */
521  for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize
522  buf = &avci->buffer[i];
523  if (buf->data[0] == pic->data[0])
524  break;
525  }
526  assert(i < avci->buffer_count);
527  avci->buffer_count--;
528  last = &avci->buffer[avci->buffer_count];
529 
530  if (buf != last)
531  FFSWAP(InternalBuffer, *buf, *last);
532  }
533 
534  for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
535  pic->data[i]=NULL;
536 // pic->base[i]=NULL;
537  }
538 //printf("R%X\n", pic->opaque);
539 
540  if(s->debug&FF_DEBUG_BUFFERS)
541  av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "
542  "buffers used\n", pic, avci->buffer_count);
543 }
544 
546  AVFrame temp_pic;
547  int i;
548 
549  assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
550 
551  /* If no picture return a new buffer */
552  if(pic->data[0] == NULL) {
553  /* We will copy from buffer, so must be readable */
555  return ff_get_buffer(s, pic);
556  }
557 
558  /* If internal buffer type return the same buffer */
559  if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
560  if(s->pkt) pic->pkt_pts= s->pkt->pts;
561  else pic->pkt_pts= AV_NOPTS_VALUE;
563  return 0;
564  }
565 
566  /*
567  * Not internal type and reget_buffer not overridden, emulate cr buffer
568  */
569  temp_pic = *pic;
570  for(i = 0; i < AV_NUM_DATA_POINTERS; i++)
571  pic->data[i] = pic->base[i] = NULL;
572  pic->opaque = NULL;
573  /* Allocate new frame */
574  if (ff_get_buffer(s, pic))
575  return -1;
576  /* Copy image data from old buffer to new buffer */
577  av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
578  s->height);
579  s->release_buffer(s, &temp_pic); // Release old frame
580  return 0;
581 }
582 
583 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
584  int i;
585 
586  for(i=0; i<count; i++){
587  int r= func(c, (char*)arg + i*size);
588  if(ret) ret[i]= r;
589  }
590  return 0;
591 }
592 
593 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
594  int i;
595 
596  for(i=0; i<count; i++){
597  int r= func(c, arg, i, 0);
598  if(ret) ret[i]= r;
599  }
600  return 0;
601 }
602 
604  while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
605  ++fmt;
606  return fmt[0];
607 }
608 
610  memset(pic, 0, sizeof(AVFrame));
611 
612  pic->pts= AV_NOPTS_VALUE;
613  pic->key_frame= 1;
614  pic->sample_aspect_ratio = (AVRational){0, 1};
615  pic->format = -1; /* unknown */
616 }
617 
619  AVFrame *pic= av_malloc(sizeof(AVFrame));
620 
621  if(pic==NULL) return NULL;
622 
624 
625  return pic;
626 }
627 
628 #if FF_API_AVCODEC_OPEN
629 int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
630 {
631  return avcodec_open2(avctx, codec, NULL);
632 }
633 #endif
634 
636 {
637  int ret = 0;
638  AVDictionary *tmp = NULL;
639 
640  if (avcodec_is_open(avctx))
641  return 0;
642 
643  if ((!codec && !avctx->codec)) {
644  av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n");
645  return AVERROR(EINVAL);
646  }
647  if ((codec && avctx->codec && codec != avctx->codec)) {
648  av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, "
649  "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name);
650  return AVERROR(EINVAL);
651  }
652  if (!codec)
653  codec = avctx->codec;
654 
655  if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
656  return AVERROR(EINVAL);
657 
658  if (options)
659  av_dict_copy(&tmp, *options, 0);
660 
661  /* If there is a user-supplied mutex locking routine, call it. */
662  if (ff_lockmgr_cb) {
664  return -1;
665  }
666 
668  if(entangled_thread_counter != 1){
669  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
670  ret = -1;
671  goto end;
672  }
673 
674  avctx->internal = av_mallocz(sizeof(AVCodecInternal));
675  if (!avctx->internal) {
676  ret = AVERROR(ENOMEM);
677  goto end;
678  }
679 
680  if (codec->priv_data_size > 0) {
681  if(!avctx->priv_data){
682  avctx->priv_data = av_mallocz(codec->priv_data_size);
683  if (!avctx->priv_data) {
684  ret = AVERROR(ENOMEM);
685  goto end;
686  }
687  if (codec->priv_class) {
688  *(AVClass**)avctx->priv_data= codec->priv_class;
690  }
691  }
692  if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0)
693  goto free_and_end;
694  } else {
695  avctx->priv_data = NULL;
696  }
697  if ((ret = av_opt_set_dict(avctx, &tmp)) < 0)
698  goto free_and_end;
699 
700  if(avctx->coded_width && avctx->coded_height)
701  avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
702  else if(avctx->width && avctx->height)
703  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
704 
705  if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height)
706  && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0
707  || av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)) {
708  av_log(avctx, AV_LOG_WARNING, "ignoring invalid width/height values\n");
709  avcodec_set_dimensions(avctx, 0, 0);
710  }
711 
712  /* if the decoder init function was already called previously,
713  free the already allocated subtitle_header before overwriting it */
714  if (codec_is_decoder(codec))
715  av_freep(&avctx->subtitle_header);
716 
717 #define SANE_NB_CHANNELS 128U
718  if (avctx->channels > SANE_NB_CHANNELS) {
719  ret = AVERROR(EINVAL);
720  goto free_and_end;
721  }
722 
723  avctx->codec = codec;
724  if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
725  avctx->codec_id == CODEC_ID_NONE) {
726  avctx->codec_type = codec->type;
727  avctx->codec_id = codec->id;
728  }
729  if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
730  && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
731  av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
732  ret = AVERROR(EINVAL);
733  goto free_and_end;
734  }
735  avctx->frame_number = 0;
736 #if FF_API_ER
737 
738  av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition separate: %d; %d\n",
739  avctx->error_recognition, avctx->err_recognition);
740  /* FF_ER_CAREFUL (==1) implies AV_EF_CRCCHECK (== 1<<1 - 1),
741  FF_ER_COMPLIANT (==2) implies AV_EF_{CRCCHECK,BITSTREAM} (== 1<<2 - 1), et cetera} */
742  avctx->err_recognition |= (1<<(avctx->error_recognition-(avctx->error_recognition>=FF_ER_VERY_AGGRESSIVE))) - 1;
743  av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition combined: %d; %d\n",
744  avctx->error_recognition, avctx->err_recognition);
745 #endif
746 
747  if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
748  (!avctx->time_base.num || !avctx->time_base.den)) {
749  avctx->time_base.num = 1;
750  avctx->time_base.den = avctx->sample_rate;
751  }
752 
753  if (HAVE_THREADS && !avctx->thread_opaque) {
754  ret = ff_thread_init(avctx);
755  if (ret < 0) {
756  goto free_and_end;
757  }
758  }
760  avctx->thread_count = 1;
761 
762  if (avctx->codec->max_lowres < avctx->lowres) {
763  av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
764  avctx->codec->max_lowres);
765  ret = AVERROR(EINVAL);
766  goto free_and_end;
767  }
768  if (codec_is_encoder(avctx->codec)) {
769  int i;
770  if (avctx->codec->sample_fmts) {
771  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++)
772  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
773  break;
774  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
775  av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
776  ret = AVERROR(EINVAL);
777  goto free_and_end;
778  }
779  }
780  if (avctx->codec->supported_samplerates) {
781  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
782  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
783  break;
784  if (avctx->codec->supported_samplerates[i] == 0) {
785  av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n");
786  ret = AVERROR(EINVAL);
787  goto free_and_end;
788  }
789  }
790  if (avctx->codec->channel_layouts) {
791  if (!avctx->channel_layout) {
792  av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n");
793  } else {
794  for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
795  if (avctx->channel_layout == avctx->codec->channel_layouts[i])
796  break;
797  if (avctx->codec->channel_layouts[i] == 0) {
798  av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n");
799  ret = AVERROR(EINVAL);
800  goto free_and_end;
801  }
802  }
803  }
804  if (avctx->channel_layout && avctx->channels) {
806  av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n");
807  ret = AVERROR(EINVAL);
808  goto free_and_end;
809  }
810  } else if (avctx->channel_layout) {
812  }
813 
814  if (!avctx->rc_initial_buffer_occupancy)
815  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4;
816  }
817 
818  if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){
819  ret = avctx->codec->init(avctx);
820  if (ret < 0) {
821  goto free_and_end;
822  }
823  }
824 end:
826 
827  /* Release any user-supplied mutex. */
828  if (ff_lockmgr_cb) {
829  (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
830  }
831  if (options) {
832  av_dict_free(options);
833  *options = tmp;
834  }
835 
836  return ret;
837 free_and_end:
838  av_dict_free(&tmp);
839  av_freep(&avctx->priv_data);
840  av_freep(&avctx->internal);
841  avctx->codec= NULL;
842  goto end;
843 }
844 
845 int ff_alloc_packet(AVPacket *avpkt, int size)
846 {
847  if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
848  return AVERROR(EINVAL);
849 
850  if (avpkt->data) {
851  uint8_t *pkt_data;
852  int pkt_size;
853 
854  if (avpkt->size < size)
855  return AVERROR(EINVAL);
856 
857  pkt_data = avpkt->data;
858  pkt_size = avpkt->size;
859  av_init_packet(avpkt);
860  avpkt->data = pkt_data;
861  avpkt->size = pkt_size;
862  return 0;
863  } else {
864  return av_new_packet(avpkt, size);
865  }
866 }
867 
869  AVPacket *avpkt,
870  const AVFrame *frame,
871  int *got_packet_ptr)
872 {
873  int ret;
874  int user_packet = !!avpkt->data;
875  int nb_samples;
876 
877  if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {
878  av_init_packet(avpkt);
879  avpkt->size = 0;
880  return 0;
881  }
882 
883  /* check for valid frame size */
884  if (frame) {
885  nb_samples = frame->nb_samples;
887  if (nb_samples > avctx->frame_size)
888  return AVERROR(EINVAL);
889  } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) {
890  if (nb_samples != avctx->frame_size)
891  return AVERROR(EINVAL);
892  }
893  } else {
894  nb_samples = avctx->frame_size;
895  }
896 
897  if (avctx->codec->encode2) {
898  *got_packet_ptr = 0;
899  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
900  if (!ret && *got_packet_ptr &&
901  !(avctx->codec->capabilities & CODEC_CAP_DELAY)) {
902  avpkt->pts = frame->pts;
903  avpkt->duration = av_rescale_q(frame->nb_samples,
904  (AVRational){ 1, avctx->sample_rate },
905  avctx->time_base);
906  }
907  } else {
908  /* for compatibility with encoders not supporting encode2(), we need to
909  allocate a packet buffer if the user has not provided one or check
910  the size otherwise */
911  int fs_tmp = 0;
912  int buf_size = avpkt->size;
913  if (!user_packet) {
916  buf_size = nb_samples * avctx->channels *
917  av_get_bits_per_sample(avctx->codec_id) / 8;
918  } else {
919  /* this is a guess as to the required size.
920  if an encoder needs more than this, it should probably
921  implement encode2() */
922  buf_size = 2 * avctx->frame_size * avctx->channels *
924  buf_size += FF_MIN_BUFFER_SIZE;
925  }
926  }
927  if ((ret = ff_alloc_packet(avpkt, buf_size)))
928  return ret;
929 
930  /* Encoders using AVCodec.encode() that support
931  CODEC_CAP_SMALL_LAST_FRAME require avctx->frame_size to be set to
932  the smaller size when encoding the last frame.
933  This code can be removed once all encoders supporting
934  CODEC_CAP_SMALL_LAST_FRAME use encode2() */
936  nb_samples < avctx->frame_size) {
937  fs_tmp = avctx->frame_size;
938  avctx->frame_size = nb_samples;
939  }
940 
941  /* encode the frame */
942  ret = avctx->codec->encode(avctx, avpkt->data, avpkt->size,
943  frame ? frame->data[0] : NULL);
944  if (ret >= 0) {
945  if (!ret) {
946  /* no output. if the packet data was allocated by libavcodec,
947  free it */
948  if (!user_packet)
949  av_freep(&avpkt->data);
950  } else {
951  if (avctx->coded_frame)
952  avpkt->pts = avctx->coded_frame->pts;
953  /* Set duration for final small packet. This can be removed
954  once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use
955  encode2() */
956  if (fs_tmp) {
957  avpkt->duration = av_rescale_q(avctx->frame_size,
958  (AVRational){ 1, avctx->sample_rate },
959  avctx->time_base);
960  }
961  }
962  avpkt->size = ret;
963  *got_packet_ptr = (ret > 0);
964  ret = 0;
965  }
966 
967  if (fs_tmp)
968  avctx->frame_size = fs_tmp;
969  }
970  if (!ret)
971  avctx->frame_number++;
972 
973  /* NOTE: if we add any audio encoders which output non-keyframe packets,
974  this needs to be moved to the encoders, but for now we can do it
975  here to simplify things */
976  avpkt->flags |= AV_PKT_FLAG_KEY;
977 
978  return ret;
979 }
980 
981 #if FF_API_OLD_DECODE_AUDIO
982 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
983  uint8_t *buf, int buf_size,
984  const short *samples)
985 {
986  AVPacket pkt;
987  AVFrame frame0;
988  AVFrame *frame;
989  int ret, samples_size, got_packet;
990 
991  av_init_packet(&pkt);
992  pkt.data = buf;
993  pkt.size = buf_size;
994 
995  if (samples) {
996  frame = &frame0;
998 
999  if (avctx->frame_size) {
1000  frame->nb_samples = avctx->frame_size;
1001  } else {
1002  /* if frame_size is not set, the number of samples must be
1003  calculated from the buffer size */
1004  int64_t nb_samples;
1005  if (!av_get_bits_per_sample(avctx->codec_id)) {
1006  av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not "
1007  "support this codec\n");
1008  return AVERROR(EINVAL);
1009  }
1010  nb_samples = (int64_t)buf_size * 8 /
1011  (av_get_bits_per_sample(avctx->codec_id) *
1012  avctx->channels);
1013  if (nb_samples >= INT_MAX)
1014  return AVERROR(EINVAL);
1015  frame->nb_samples = nb_samples;
1016  }
1017 
1018  /* it is assumed that the samples buffer is large enough based on the
1019  relevant parameters */
1020  samples_size = av_samples_get_buffer_size(NULL, avctx->channels,
1021  frame->nb_samples,
1022  avctx->sample_fmt, 1);
1023  if ((ret = avcodec_fill_audio_frame(frame, avctx->channels,
1024  avctx->sample_fmt,
1025  samples, samples_size, 1)))
1026  return ret;
1027 
1028  /* fabricate frame pts from sample count.
1029  this is needed because the avcodec_encode_audio() API does not have
1030  a way for the user to provide pts */
1031  frame->pts = av_rescale_q(avctx->internal->sample_count,
1032  (AVRational){ 1, avctx->sample_rate },
1033  avctx->time_base);
1034  avctx->internal->sample_count += frame->nb_samples;
1035  } else {
1036  frame = NULL;
1037  }
1038 
1039  got_packet = 0;
1040  ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet);
1041  if (!ret && got_packet && avctx->coded_frame) {
1042  avctx->coded_frame->pts = pkt.pts;
1043  avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
1044  }
1045  /* free any side data since we cannot return it */
1046  if (pkt.side_data_elems > 0) {
1047  int i;
1048  for (i = 0; i < pkt.side_data_elems; i++)
1049  av_free(pkt.side_data[i].data);
1050  av_freep(&pkt.side_data);
1051  pkt.side_data_elems = 0;
1052  }
1053 
1054  if (frame && frame->extended_data != frame->data)
1055  av_free(frame->extended_data);
1056 
1057  return ret ? ret : pkt.size;
1058 }
1059 #endif
1060 
1061 int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1062  const AVFrame *pict)
1063 {
1064  if(buf_size < FF_MIN_BUFFER_SIZE){
1065  av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
1066  return -1;
1067  }
1068  if(av_image_check_size(avctx->width, avctx->height, 0, avctx))
1069  return -1;
1070  if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
1071  int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
1072  avctx->frame_number++;
1073  emms_c(); //needed to avoid an emms_c() call before every return;
1074 
1075  return ret;
1076  }else
1077  return 0;
1078 }
1079 
1080 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
1081  const AVSubtitle *sub)
1082 {
1083  int ret;
1084  if(sub->start_display_time) {
1085  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
1086  return -1;
1087  }
1088  if(sub->num_rects == 0 || !sub->rects)
1089  return -1;
1090  ret = avctx->codec->encode(avctx, buf, buf_size, sub);
1091  avctx->frame_number++;
1092  return ret;
1093 }
1094 
1095 static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
1096 {
1097  int size = 0;
1098  const uint8_t *data;
1099  uint32_t flags;
1100 
1101  if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE))
1102  return;
1103 
1104  data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
1105  if (!data || size < 4)
1106  return;
1107  flags = bytestream_get_le32(&data);
1108  size -= 4;
1109  if (size < 4) /* Required for any of the changes */
1110  return;
1112  avctx->channels = bytestream_get_le32(&data);
1113  size -= 4;
1114  }
1116  if (size < 8)
1117  return;
1118  avctx->channel_layout = bytestream_get_le64(&data);
1119  size -= 8;
1120  }
1121  if (size < 4)
1122  return;
1124  avctx->sample_rate = bytestream_get_le32(&data);
1125  size -= 4;
1126  }
1128  if (size < 8)
1129  return;
1130  avctx->width = bytestream_get_le32(&data);
1131  avctx->height = bytestream_get_le32(&data);
1132  avcodec_set_dimensions(avctx, avctx->width, avctx->height);
1133  size -= 8;
1134  }
1135 }
1136 
1138  int *got_picture_ptr,
1139  AVPacket *avpkt)
1140 {
1141  int ret;
1142 
1143  *got_picture_ptr= 0;
1144  if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
1145  return -1;
1146 
1147  avctx->pkt = avpkt;
1148  apply_param_change(avctx, avpkt);
1149 
1150  if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){
1152  ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
1153  avpkt);
1154  else {
1155  ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
1156  avpkt);
1157  picture->pkt_dts= avpkt->dts;
1158  picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
1159  picture->width = avctx->width;
1160  picture->height = avctx->height;
1161  picture->format = avctx->pix_fmt;
1162  }
1163 
1164  emms_c(); //needed to avoid an emms_c() call before every return;
1165 
1166  if (*got_picture_ptr)
1167  avctx->frame_number++;
1168  }else
1169  ret= 0;
1170 
1171  return ret;
1172 }
1173 
1174 #if FF_API_OLD_DECODE_AUDIO
1175 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
1176  int *frame_size_ptr,
1177  AVPacket *avpkt)
1178 {
1179  AVFrame frame;
1180  int ret, got_frame = 0;
1181 
1182  if (avctx->get_buffer != avcodec_default_get_buffer) {
1183  av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with"
1184  "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
1185  av_log(avctx, AV_LOG_ERROR, "Please port your application to "
1186  "avcodec_decode_audio4()\n");
1188  }
1189 
1190  ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
1191 
1192  if (ret >= 0 && got_frame) {
1193  int ch, plane_size;
1194  int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
1195  int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
1196  frame.nb_samples,
1197  avctx->sample_fmt, 1);
1198  if (*frame_size_ptr < data_size) {
1199  av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
1200  "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1201  return AVERROR(EINVAL);
1202  }
1203 
1204  memcpy(samples, frame.extended_data[0], plane_size);
1205 
1206  if (planar && avctx->channels > 1) {
1207  uint8_t *out = ((uint8_t *)samples) + plane_size;
1208  for (ch = 1; ch < avctx->channels; ch++) {
1209  memcpy(out, frame.extended_data[ch], plane_size);
1210  out += plane_size;
1211  }
1212  }
1213  *frame_size_ptr = data_size;
1214  } else {
1215  *frame_size_ptr = 0;
1216  }
1217  return ret;
1218 }
1219 #endif
1220 
1222  AVFrame *frame,
1223  int *got_frame_ptr,
1224  AVPacket *avpkt)
1225 {
1226  int ret = 0;
1227 
1228  *got_frame_ptr = 0;
1229 
1230  avctx->pkt = avpkt;
1231 
1232  if (!avpkt->data && avpkt->size) {
1233  av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
1234  return AVERROR(EINVAL);
1235  }
1236 
1237  apply_param_change(avctx, avpkt);
1238 
1239  if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
1240  ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt);
1241  if (ret >= 0 && *got_frame_ptr) {
1242  avctx->frame_number++;
1243  frame->pkt_dts = avpkt->dts;
1244  if (frame->format == AV_SAMPLE_FMT_NONE)
1245  frame->format = avctx->sample_fmt;
1246  }
1247  }
1248  return ret;
1249 }
1250 
1252  int *got_sub_ptr,
1253  AVPacket *avpkt)
1254 {
1255  int ret;
1256 
1257  avctx->pkt = avpkt;
1258  *got_sub_ptr = 0;
1259  ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
1260  if (*got_sub_ptr)
1261  avctx->frame_number++;
1262  return ret;
1263 }
1264 
1266 {
1267  int i;
1268 
1269  for (i = 0; i < sub->num_rects; i++)
1270  {
1271  av_freep(&sub->rects[i]->pict.data[0]);
1272  av_freep(&sub->rects[i]->pict.data[1]);
1273  av_freep(&sub->rects[i]->pict.data[2]);
1274  av_freep(&sub->rects[i]->pict.data[3]);
1275  av_freep(&sub->rects[i]->text);
1276  av_freep(&sub->rects[i]->ass);
1277  av_freep(&sub->rects[i]);
1278  }
1279 
1280  av_freep(&sub->rects);
1281 
1282  memset(sub, 0, sizeof(AVSubtitle));
1283 }
1284 
1286 {
1287  /* If there is a user-supplied mutex locking routine, call it. */
1288  if (ff_lockmgr_cb) {
1290  return -1;
1291  }
1292 
1294  if(entangled_thread_counter != 1){
1295  av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
1297  return -1;
1298  }
1299 
1300  if (avcodec_is_open(avctx)) {
1301  if (HAVE_THREADS && avctx->thread_opaque)
1302  ff_thread_free(avctx);
1303  if (avctx->codec && avctx->codec->close)
1304  avctx->codec->close(avctx);
1306  avctx->coded_frame = NULL;
1307  av_freep(&avctx->internal);
1308  }
1309 
1310  if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
1311  av_opt_free(avctx->priv_data);
1312  av_opt_free(avctx);
1313  av_freep(&avctx->priv_data);
1314  if (codec_is_encoder(avctx->codec))
1315  av_freep(&avctx->extradata);
1316  avctx->codec = NULL;
1317  avctx->active_thread_type = 0;
1319 
1320  /* Release any user-supplied mutex. */
1321  if (ff_lockmgr_cb) {
1322  (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
1323  }
1324  return 0;
1325 }
1326 
1328 {
1329  AVCodec *p, *experimental=NULL;
1330  p = first_avcodec;
1331  while (p) {
1332  if (codec_is_encoder(p) && p->id == id) {
1333  if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
1334  experimental = p;
1335  } else
1336  return p;
1337  }
1338  p = p->next;
1339  }
1340  return experimental;
1341 }
1342 
1344 {
1345  AVCodec *p;
1346  if (!name)
1347  return NULL;
1348  p = first_avcodec;
1349  while (p) {
1350  if (codec_is_encoder(p) && strcmp(name,p->name) == 0)
1351  return p;
1352  p = p->next;
1353  }
1354  return NULL;
1355 }
1356 
1358 {
1359  AVCodec *p;
1360  p = first_avcodec;
1361  while (p) {
1362  if (codec_is_decoder(p) && p->id == id)
1363  return p;
1364  p = p->next;
1365  }
1366  return NULL;
1367 }
1368 
1370 {
1371  AVCodec *p;
1372  if (!name)
1373  return NULL;
1374  p = first_avcodec;
1375  while (p) {
1376  if (codec_is_decoder(p) && strcmp(name,p->name) == 0)
1377  return p;
1378  p = p->next;
1379  }
1380  return NULL;
1381 }
1382 
1384 {
1385  int bit_rate;
1386  int bits_per_sample;
1387 
1388  switch(ctx->codec_type) {
1389  case AVMEDIA_TYPE_VIDEO:
1390  case AVMEDIA_TYPE_DATA:
1391  case AVMEDIA_TYPE_SUBTITLE:
1393  bit_rate = ctx->bit_rate;
1394  break;
1395  case AVMEDIA_TYPE_AUDIO:
1396  bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
1397  bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
1398  break;
1399  default:
1400  bit_rate = 0;
1401  break;
1402  }
1403  return bit_rate;
1404 }
1405 
1406 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
1407 {
1408  int i, len, ret = 0;
1409 
1410  for (i = 0; i < 4; i++) {
1411  len = snprintf(buf, buf_size,
1412  isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
1413  buf += len;
1414  buf_size = buf_size > len ? buf_size - len : 0;
1415  ret += len;
1416  codec_tag>>=8;
1417  }
1418  return ret;
1419 }
1420 
1421 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
1422 {
1423  const char *codec_name;
1424  const char *profile = NULL;
1425  AVCodec *p;
1426  char buf1[32];
1427  int bitrate;
1428  AVRational display_aspect_ratio;
1429 
1430  if (encode)
1431  p = avcodec_find_encoder(enc->codec_id);
1432  else
1433  p = avcodec_find_decoder(enc->codec_id);
1434 
1435  if (p) {
1436  codec_name = p->name;
1437  profile = av_get_profile_name(p, enc->profile);
1438  } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
1439  /* fake mpeg2 transport stream codec (currently not
1440  registered) */
1441  codec_name = "mpeg2ts";
1442  } else if (enc->codec_name[0] != '\0') {
1443  codec_name = enc->codec_name;
1444  } else {
1445  /* output avi tags */
1446  char tag_buf[32];
1447  av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
1448  snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
1449  codec_name = buf1;
1450  }
1451 
1452  switch(enc->codec_type) {
1453  case AVMEDIA_TYPE_VIDEO:
1454  snprintf(buf, buf_size,
1455  "Video: %s%s",
1456  codec_name, enc->mb_decision ? " (hq)" : "");
1457  if (profile)
1458  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1459  " (%s)", profile);
1460  if (enc->pix_fmt != PIX_FMT_NONE) {
1461  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1462  ", %s",
1464  }
1465  if (enc->width) {
1466  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1467  ", %dx%d",
1468  enc->width, enc->height);
1469  if (enc->sample_aspect_ratio.num) {
1470  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1471  enc->width*enc->sample_aspect_ratio.num,
1472  enc->height*enc->sample_aspect_ratio.den,
1473  1024*1024);
1474  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1475  " [PAR %d:%d DAR %d:%d]",
1477  display_aspect_ratio.num, display_aspect_ratio.den);
1478  }
1479  if(av_log_get_level() >= AV_LOG_DEBUG){
1480  int g= av_gcd(enc->time_base.num, enc->time_base.den);
1481  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1482  ", %d/%d",
1483  enc->time_base.num/g, enc->time_base.den/g);
1484  }
1485  }
1486  if (encode) {
1487  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1488  ", q=%d-%d", enc->qmin, enc->qmax);
1489  }
1490  break;
1491  case AVMEDIA_TYPE_AUDIO:
1492  snprintf(buf, buf_size,
1493  "Audio: %s",
1494  codec_name);
1495  if (profile)
1496  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1497  " (%s)", profile);
1498  if (enc->sample_rate) {
1499  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1500  ", %d Hz", enc->sample_rate);
1501  }
1502  av_strlcat(buf, ", ", buf_size);
1503  av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
1504  if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {
1505  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1506  ", %s", av_get_sample_fmt_name(enc->sample_fmt));
1507  }
1508  break;
1509  case AVMEDIA_TYPE_DATA:
1510  snprintf(buf, buf_size, "Data: %s", codec_name);
1511  break;
1512  case AVMEDIA_TYPE_SUBTITLE:
1513  snprintf(buf, buf_size, "Subtitle: %s", codec_name);
1514  break;
1516  snprintf(buf, buf_size, "Attachment: %s", codec_name);
1517  break;
1518  default:
1519  snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
1520  return;
1521  }
1522  if (encode) {
1523  if (enc->flags & CODEC_FLAG_PASS1)
1524  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1525  ", pass 1");
1526  if (enc->flags & CODEC_FLAG_PASS2)
1527  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1528  ", pass 2");
1529  }
1530  bitrate = get_bit_rate(enc);
1531  if (bitrate != 0) {
1532  snprintf(buf + strlen(buf), buf_size - strlen(buf),
1533  ", %d kb/s", bitrate / 1000);
1534  }
1535 }
1536 
1537 const char *av_get_profile_name(const AVCodec *codec, int profile)
1538 {
1539  const AVProfile *p;
1540  if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
1541  return NULL;
1542 
1543  for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
1544  if (p->profile == profile)
1545  return p->name;
1546 
1547  return NULL;
1548 }
1549 
1550 unsigned avcodec_version( void )
1551 {
1552  return LIBAVCODEC_VERSION_INT;
1553 }
1554 
1555 const char *avcodec_configuration(void)
1556 {
1557  return LIBAV_CONFIGURATION;
1558 }
1559 
1560 const char *avcodec_license(void)
1561 {
1562 #define LICENSE_PREFIX "libavcodec license: "
1563  return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
1564 }
1565 
1567 {
1569  ff_thread_flush(avctx);
1570  else if(avctx->codec->flush)
1571  avctx->codec->flush(avctx);
1572 }
1573 
1575 {
1576  AVCodecInternal *avci = s->internal;
1577  int i, j;
1578 
1579  if (!avci->buffer)
1580  return;
1581 
1582  if (avci->buffer_count)
1583  av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n",
1584  avci->buffer_count);
1585  for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
1586  InternalBuffer *buf = &avci->buffer[i];
1587  for(j=0; j<4; j++){
1588  av_freep(&buf->base[j]);
1589  buf->data[j]= NULL;
1590  }
1591  }
1592  av_freep(&avci->buffer);
1593 
1594  avci->buffer_count=0;
1595 }
1596 
1598 {
1599  AVCodecInternal *avci = avctx->internal;
1600  InternalBuffer *buf;
1601 
1602  if (!avci->buffer)
1603  return;
1604  buf = avci->buffer;
1605 
1606  if (buf->extended_data) {
1607  av_free(buf->extended_data[0]);
1608  if (buf->extended_data != buf->data)
1609  av_free(buf->extended_data);
1610  }
1611  av_freep(&avci->buffer);
1612 }
1613 
1615 {
1616  switch (avctx->codec_type) {
1617  case AVMEDIA_TYPE_VIDEO:
1618  video_free_buffers(avctx);
1619  break;
1620  case AVMEDIA_TYPE_AUDIO:
1621  audio_free_buffers(avctx);
1622  break;
1623  default:
1624  break;
1625  }
1626 }
1627 
1628 #if FF_API_OLD_FF_PICT_TYPES
1629 char av_get_pict_type_char(int pict_type){
1630  return av_get_picture_type_char(pict_type);
1631 }
1632 #endif
1633 
1635  switch(codec_id){
1637  return 2;
1639  return 3;
1641  case CODEC_ID_ADPCM_CT:
1643  case CODEC_ID_ADPCM_IMA_QT:
1644  case CODEC_ID_ADPCM_SWF:
1645  case CODEC_ID_ADPCM_MS:
1646  case CODEC_ID_ADPCM_YAMAHA:
1647  case CODEC_ID_ADPCM_G722:
1648  return 4;
1649  case CODEC_ID_PCM_ALAW:
1650  case CODEC_ID_PCM_MULAW:
1651  case CODEC_ID_PCM_S8:
1652  case CODEC_ID_PCM_U8:
1653  case CODEC_ID_PCM_ZORK:
1654  return 8;
1655  case CODEC_ID_PCM_S16BE:
1656  case CODEC_ID_PCM_S16LE:
1658  case CODEC_ID_PCM_U16BE:
1659  case CODEC_ID_PCM_U16LE:
1660  return 16;
1661  case CODEC_ID_PCM_S24DAUD:
1662  case CODEC_ID_PCM_S24BE:
1663  case CODEC_ID_PCM_S24LE:
1664  case CODEC_ID_PCM_U24BE:
1665  case CODEC_ID_PCM_U24LE:
1666  return 24;
1667  case CODEC_ID_PCM_S32BE:
1668  case CODEC_ID_PCM_S32LE:
1669  case CODEC_ID_PCM_U32BE:
1670  case CODEC_ID_PCM_U32LE:
1671  case CODEC_ID_PCM_F32BE:
1672  case CODEC_ID_PCM_F32LE:
1673  return 32;
1674  case CODEC_ID_PCM_F64BE:
1675  case CODEC_ID_PCM_F64LE:
1676  return 64;
1677  default:
1678  return 0;
1679  }
1680 }
1681 
1682 #if FF_API_OLD_SAMPLE_FMT
1683 int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
1684  return av_get_bytes_per_sample(sample_fmt) << 3;
1685 }
1686 #endif
1687 
1688 #if !HAVE_THREADS
1690  return -1;
1691 }
1692 #endif
1693 
1694 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1695 {
1696  unsigned int n = 0;
1697 
1698  while(v >= 0xff) {
1699  *s++ = 0xff;
1700  v -= 0xff;
1701  n++;
1702  }
1703  *s = v;
1704  n++;
1705  return n;
1706 }
1707 
1708 int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
1709  int i;
1710  for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
1711  return i;
1712 }
1713 
1714 void av_log_missing_feature(void *avc, const char *feature, int want_sample)
1715 {
1716  av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your Libav "
1717  "version to the newest one from Git. If the problem still "
1718  "occurs, it means that your file has a feature which has not "
1719  "been implemented.\n", feature);
1720  if(want_sample)
1722 }
1723 
1724 void av_log_ask_for_sample(void *avc, const char *msg, ...)
1725 {
1726  va_list argument_list;
1727 
1728  va_start(argument_list, msg);
1729 
1730  if (msg)
1731  av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
1732  av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
1733  "of this file to ftp://upload.libav.org/incoming/ "
1734  "and contact the libav-devel mailing list.\n");
1735 
1736  va_end(argument_list);
1737 }
1738 
1740 
1742 {
1743  AVHWAccel **p = &first_hwaccel;
1744  while (*p)
1745  p = &(*p)->next;
1746  *p = hwaccel;
1747  hwaccel->next = NULL;
1748 }
1749 
1751 {
1752  return hwaccel ? hwaccel->next : first_hwaccel;
1753 }
1754 
1756 {
1757  AVHWAccel *hwaccel=NULL;
1758 
1759  while((hwaccel= av_hwaccel_next(hwaccel))){
1760  if ( hwaccel->id == codec_id
1761  && hwaccel->pix_fmt == pix_fmt)
1762  return hwaccel;
1763  }
1764  return NULL;
1765 }
1766 
1767 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1768 {
1769  if (ff_lockmgr_cb) {
1771  return -1;
1773  return -1;
1774  }
1775 
1776  ff_lockmgr_cb = cb;
1777 
1778  if (ff_lockmgr_cb) {
1780  return -1;
1782  return -1;
1783  }
1784  return 0;
1785 }
1786 
1788 {
1789  if (ff_lockmgr_cb) {
1791  return -1;
1792  }
1793  return 0;
1794 }
1795 
1797 {
1798  if (ff_lockmgr_cb) {
1800  return -1;
1801  }
1802  return 0;
1803 }
1804 
1805 unsigned int avpriv_toupper4(unsigned int x)
1806 {
1807  return toupper( x &0xFF)
1808  + (toupper((x>>8 )&0xFF)<<8 )
1809  + (toupper((x>>16)&0xFF)<<16)
1810  + (toupper((x>>24)&0xFF)<<24);
1811 }
1812 
1813 #if !HAVE_THREADS
1814 
1816 {
1817  f->owner = avctx;
1818  return ff_get_buffer(avctx, f);
1819 }
1820 
1822 {
1823  f->owner->release_buffer(f->owner, f);
1824 }
1825 
1827 {
1828 }
1829 
1830 void ff_thread_report_progress(AVFrame *f, int progress, int field)
1831 {
1832 }
1833 
1834 void ff_thread_await_progress(AVFrame *f, int progress, int field)
1835 {
1836 }
1837 
1838 #endif
1839 
1840 #if FF_API_THREAD_INIT
1841 int avcodec_thread_init(AVCodecContext *s, int thread_count)
1842 {
1844  return ff_thread_init(s);
1845 }
1846 #endif
1847 
1849 {
1850  if (codec_id <= CODEC_ID_NONE)
1851  return AVMEDIA_TYPE_UNKNOWN;
1852  else if (codec_id < CODEC_ID_FIRST_AUDIO)
1853  return AVMEDIA_TYPE_VIDEO;
1854  else if (codec_id < CODEC_ID_FIRST_SUBTITLE)
1855  return AVMEDIA_TYPE_AUDIO;
1856  else if (codec_id < CODEC_ID_FIRST_UNKNOWN)
1857  return AVMEDIA_TYPE_SUBTITLE;
1858 
1859  return AVMEDIA_TYPE_UNKNOWN;
1860 }
1861 
1863 {
1864  return !!s->internal;
1865 }
1866 
1868 {
1869  switch (avctx->codec_type) {
1870  case AVMEDIA_TYPE_VIDEO:
1871  if (av_image_check_size(avctx->width, avctx->height, 0, avctx)) {
1872  av_log(avctx, AV_LOG_ERROR, "Invalid dimensions %dx%d\n",
1873  avctx->width, avctx->height);
1874  return AVERROR_INVALIDDATA;
1875  }
1876  }
1877  return avctx->get_buffer(avctx, frame);
1878 }
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:800
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, 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:127
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:68
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:154
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
Definition: avcodec.h:1726
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
Definition: avcodec.h:1426
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:1537
Unlock the mutex.
Definition: avcodec.h:4723
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
int size
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
Definition: avcodec.h:3369
static av_always_inline int codec_is_encoder(AVCodec *codec)
Definition: utils.c:105
enum PixelFormat pix_fmt
Supported pixel format.
Definition: avcodec.h:3303
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:128
Audio Video Frame.
Definition: avcodec.h:985
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:509
#define c2
Definition: idct_sh4.c:28
static short * samples
Definition: ffmpeg.c:233
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:96
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:1830
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:1767
int coded_width
Bitstream width / height, may be different from width/height if lowres enabled.
Definition: avcodec.h:2543
int buffer_hints
codec suggestion on buffer type if != 0
Definition: avcodec.h:1195
enum AVMediaType avcodec_get_type(enum CodecID codec_id)
Get the type of the given codec.
Definition: utils.c:1848
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:151
void(* flush)(AVCodecContext *)
Flush buffers.
Definition: avcodec.h:3214
Create a mutex.
Definition: avcodec.h:4721
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:1737
misc image utilities
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2000
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:60
int buffer_count
internal buffer count used by default get/release/reget_buffer().
Definition: internal.h:49
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:117
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2343
planar GBR 4:4:4 27bpp, little endian
Definition: pixfmt.h:155
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:598
enum PixelFormat pix_fmt
Definition: v4l.c:65
void * opaque
for some private data of the user
Definition: avcodec.h:1132
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
int num
numerator
Definition: rational.h:44
struct AVCodecContext * owner
the AVCodecContext which ff_thread_get_buffer() was last called on
Definition: avcodec.h:1251
int size
Definition: avcodec.h:909
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:1862
char codec_name[32]
Definition: avcodec.h:1573
AVOptions.
int width
Definition: rotozoom.c:164
InternalBuffer * buffer
internal buffers used by default get/release/reget_buffer().
Definition: internal.h:55
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:77
#define CODEC_CAP_PARAM_CHANGE
Codec supports changed parameters at any point.
Definition: avcodec.h:796
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:71
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:1993
enum CodecID id
Definition: avcodec.h:3198
void ff_thread_free(AVCodecContext *avctx)
Definition: pthread.c:1043
unsigned num_rects
Definition: avcodec.h:3444
#define b
Definition: swscale.c:1335
enum AVMediaType type
Definition: avcodec.h:3197
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:954
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: utils.c:1815
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:71
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
Definition: avcodec.h:3203
int nb_channels
Definition: internal.h:41
struct AVCodec * codec
Definition: avcodec.h:1529
four components are given, that's all.
Definition: avcodec.h:3367
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
Definition: utils.c:1555
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
Definition: utils.c:583
int profile
profile
Definition: avcodec.h:2462
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:638
AVCodec.
Definition: avcodec.h:3189
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
A dummy ID pointing at the start of various fake codecs.
Definition: avcodec.h:413
#define v(n)
Definition: regs.h:34
char * text
0 terminated plain UTF-8 text
Definition: avcodec.h:3430
#define FFALIGN(x, a)
Definition: common.h:60
static void * codec_mutex
Definition: utils.c:52
static void video_free_buffers(AVCodecContext *s)
Definition: utils.c:1574
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1398
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:147
AVSubtitleRect ** rects
Definition: avcodec.h:3445
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:55
void av_picture_copy(AVPicture *dst, const AVPicture *src, enum PixelFormat pix_fmt, int width, int height)
Copy image src to dst.
Definition: imgconvert.c:664
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:46
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:78
static int volatile entangled_thread_counter
Definition: utils.c:50
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:86
Public dictionary API.
static int thread_count
Definition: ffmpeg.c:214
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:83
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1464
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:64
int av_log_get_level(void)
Definition: log.c:157
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:82
#define av_cold
Definition: attributes.h:71
uint8_t * base[AV_NUM_DATA_POINTERS]
Definition: internal.h:33
Opaque data information usually continuous.
Definition: avutil.h:232
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:70
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: avcodec.h:3368
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
Definition: utils.c:1550
static AVCodec * first_avcodec
Definition: utils.c:84
int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:497
static void audio_free_buffers(AVCodecContext *avctx)
Definition: utils.c:1597
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:545
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
Definition: avcodec.h:1037
#define PIX_FMT_RGB555
Definition: pixfmt.h:177
#define LIBAVCODEC_VERSION_INT
Definition: version.h:27
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1387
#define LICENSE_PREFIX
const char data[16]
Definition: mxf.c:60
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:153
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:590
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:76
int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat 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:93
uint8_t * data
Definition: avcodec.h:908
static int flags
Definition: log.c:34
AVCodec * av_codec_next(AVCodec *c)
If c is NULL, returns the first registered codec, if c is non-NULL, returns the next registered codec...
Definition: utils.c:86
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:43
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:618
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:2536
int ff_set_systematic_pal2(uint32_t pal[256], enum PixelFormat pix_fmt)
Definition: imgutils.c:136
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:1708
#define LIBAV_LICENSE
Definition: config.h:5
void ff_thread_await_progress(AVFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: utils.c:1834
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:930
#define FF_BUFFER_TYPE_INTERNAL
Definition: avcodec.h:864
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: utils.c:1343
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:149
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:755
const char * avcodec_license(void)
Return the libavcodec license.
Definition: utils.c:1560
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: utils.c:1421
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Definition: log.c:152
audio conversion routines
Y , 16bpp, little-endian.
Definition: pixfmt.h:98
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:132
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:114
A dummy ID pointing at the start of subtitle codecs.
Definition: avcodec.h:401
int(* close)(AVCodecContext *)
Definition: avcodec.h:3202
int nb_channels
Definition: audioconvert.c:62
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:1867
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:3224
static AVHWAccel * first_hwaccel
Definition: utils.c:1739
enum CodecID codec_id
Definition: mov_chan.c:417
int width
width and height of the video frame
Definition: avcodec.h:1299
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:1714
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:137
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:639
Multithreading support functions.
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:142
#define AVERROR(e)
Definition: error.h:43
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:1805
int qmax
maximum quantizer
Definition: avcodec.h:1497
AVCodec * avcodec_find_encoder(enum CodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:1327
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:3116
g
Definition: yuv2rgb.c:481
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:146
int capabilities
Codec capabilities.
Definition: avcodec.h:3208
int ff_thread_init(AVCodecContext *s)
Definition: utils.c:1689
uint8_t * base[AV_NUM_DATA_POINTERS]
pointer to the first allocated byte of the picture.
Definition: avcodec.h:1016
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:1137
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:100
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: audioconvert.c:126
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:142
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1355
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:133
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:804
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:71
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
const char * name
Name of the codec implementation.
Definition: avcodec.h:3196
AVCodec * avcodec_find_decoder(enum CodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:1357
int side_data_elems
Definition: avcodec.h:924
int(* encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data)
Definition: avcodec.h:3201
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:635
planar GBR 4:4:4 27bpp, big endian
Definition: pixfmt.h:154
void * thread_opaque
thread opaque Can be used by execute() to store some per AVCodecContext stuff.
Definition: avcodec.h:2411
uint8_t ** extended_data
Definition: internal.h:39
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
Definition: pixdesc.c:119
#define AV_NUM_DATA_POINTERS
Definition: avcodec.h:989
#define FFMAX(a, b)
Definition: common.h:53
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
Definition: utils.c:1694
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:69
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:914
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2870
#define CODEC_FLAG_EMU_EDGE
Don't draw edges.
Definition: avcodec.h:641
static av_always_inline void emms_c(void)
Empty mmx state.
Definition: internal.h:240
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1830
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
#define INTERNAL_BUFFER_SIZE
Definition: utils.c:140
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
Definition: internal.h:110
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:213
int bit_rate
the average bitrate
Definition: avcodec.h:1340
static AVFrame * picture
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:3155
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: utils.c:1265
AVPicture pict
data+linesize for the bitmap of this subtitle.
Definition: avcodec.h:3427
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3108
#define f(n)
Definition: regs.h:33
AVLockOp
Lock operation used by lockmgr.
Definition: avcodec.h:4720
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:147
int width
picture width / height.
Definition: avcodec.h:1408
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:144
int type
type of the buffer (to keep track of who has to deallocate data[*])
Definition: avcodec.h:1147
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
Definition: utils.c:1251
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2463
int priv_data_size
Definition: avcodec.h:3199
int profile
Definition: avcodec.h:3180
Lock the mutex.
Definition: avcodec.h:4722
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:100
const char * av_get_pix_fmt_name(enum PixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1104
enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt)
Definition: utils.c:603
#define FF_DEBUG_BUFFERS
Definition: avcodec.h:2023
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:1826
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ...
Definition: avcodec.h:3227
int64_t reordered_opaque
opaque 64bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
Definition: avcodec.h:2856
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
Definition: utils.c:369
int mb_decision
macroblock decision mode
Definition: avcodec.h:2259
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:229
void av_log_ask_for_sample(void *avc, const char *msg,...)
Definition: utils.c:1724
Opaque data information usually sparse.
Definition: avutil.h:234
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:845
static pthread_mutex_t * mutex
Definition: w32pthreads.h:64
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:289
enum PixelFormat pix_fmt
Definition: internal.h:38
int av_get_bits_per_sample(enum CodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1634
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:45
#define SANE_NB_CHANNELS
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2392
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:141
planar GBR 4:4:4 30bpp, big endian
Definition: pixfmt.h:156
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:75
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:185
int format
format of the frame, -1 if unknown or unset Values correspond to enum PixelFormat for video frames...
Definition: avcodec.h:1308
int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict)
Encode a video frame from pict into buf.
Definition: utils.c:1061
int frame_size
Samples per packet, initialized when calling 'init'.
Definition: avcodec.h:1470
#define attribute_align_arg
Definition: internal.h:51
NULL
Definition: eval.c:50
int audio_data_size
Definition: internal.h:40
enum CodecID id
Codec implemented by the hardware accelerator.
Definition: avcodec.h:3296
void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
Definition: imgconvert.c:411
#define STRIDE_ALIGN
Definition: dsputil.h:678
static av_always_inline int codec_is_decoder(AVCodec *codec)
Definition: utils.c:110
external API header
enum AVMediaType codec_type
Definition: avcodec.h:1574
AVHWAccel * ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
Return the hardware accelerated codec for codec codec_id and pixel format pix_fmt.
Definition: utils.c:1755
void(* init_static_data)(struct AVCodec *codec)
Initialize codec static data, called from avcodec_register().
Definition: avcodec.h:3257
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
Definition: utils.c:609
AVHWAccel.
Definition: avcodec.h:3276
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:726
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:241
int sample_rate
samples per second
Definition: avcodec.h:1456
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: internal.h:34
int debug
debug
Definition: avcodec.h:2007
static const OptionDef options[]
Definition: avconv.c:105
main external API structure.
Definition: avcodec.h:1329
int qmin
minimum quantizer
Definition: avcodec.h:1490
AVRational sample_aspect_ratio
sample aspect ratio for the video frame, 0/1 if unknown
Definition: avcodec.h:1292
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1590
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:65
static int(* ff_lockmgr_cb)(void **mutex, enum AVLockOp op)
Definition: utils.c:51
int extradata_size
Definition: avcodec.h:1388
planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:140
struct AVCodec * next
Definition: avcodec.h:3209
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:64
int coded_height
Definition: avcodec.h:2543
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: avcodec.h:1223
Describe the class of an AVClass context structure.
Definition: log.h:33
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
Definition: avcodec.h:503
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:89
rational number numerator/denominator
Definition: rational.h:43
const char * name
short name for the profile
Definition: avcodec.h:3181
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition: avcodec.h:418
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:35
AVMediaType
Definition: avutil.h:228
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:497
#define FF_BUFFER_HINTS_READABLE
Definition: avcodec.h:881
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
Definition: pthread.c:877
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:67
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: utils.c:1821
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:74
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:1285
int64_t pkt_pts
reordered pts from the last AVPacket that has been input into the decoder
Definition: avcodec.h:1237
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:868
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:776
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:1221
void avcodec_default_free_buffers(AVCodecContext *avctx)
Definition: utils.c:1614
av_cold void dsputil_static_init(void)
Definition: dsputil.c:2752
const AVClass * priv_class
AVClass for the private context.
Definition: avcodec.h:3226
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
A dummy id pointing at the start of audio codecs.
Definition: avcodec.h:259
const char * name
Definition: audioconvert.c:61
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:148
int height
Definition: gxfenc.c:73
struct AVPacket::@10 * side_data
Additional packet data that can be provided by the container.
Audio format conversion routines.
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: avcodec.h:3225
int64_t pkt_dts
dts from the last AVPacket that has been input into the decoder
Definition: avcodec.h:1244
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
Definition: avcodec.h:3084
#define r(n)
Definition: regs.h:32
PixelFormat
Pixel format.
Definition: pixfmt.h:62
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:718
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:143
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:125
int avpriv_lock_avformat(void)
Definition: utils.c:1787
static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt)
Definition: utils.c:1095
struct AVHWAccel * next
Definition: avcodec.h:3311
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
static void avcodec_init(void)
Definition: utils.c:94
uint32_t start_display_time
Definition: avcodec.h:3442
AVSampleFormat
all in native-endian format
Definition: samplefmt.h:27
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:75
AVProfile.
Definition: avcodec.h:3179
planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:150
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:593
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:145
DSP utils.
CodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:83
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: utils.c:1369
void * priv_data
Definition: avcodec.h:1531
void avcodec_flush_buffers(AVCodecContext *avctx)
Flush buffers, should be called when seeking or when switching to a different stream.
Definition: utils.c:1566
int len
int channels
number of audio channels
Definition: avcodec.h:1457
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:3222
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:3167
#define HAVE_THREADS
Definition: config.h:149
char * ass
0 terminated ASS/SSA compatible event line.
Definition: avcodec.h:3437
static void * avformat_mutex
Definition: utils.c:53
#define EDGE_WIDTH
Definition: dsputil.h:520
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1022
static int get_bit_rate(AVCodecContext *ctx)
Definition: utils.c:1383
#define LIBAV_CONFIGURATION
Definition: config.h:4
Free mutex resources.
Definition: avcodec.h:4724
static const struct @46 tab
TwinVQ codebooks.
planar GBR 4:4:4 30bpp, little endian
Definition: pixfmt.h:157
void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
Definition: utils.c:115
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:907
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:253
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: utils.c:1080
void av_register_hwaccel(AVHWAccel *hwaccel)
Register the hardware accelerator hwaccel.
Definition: utils.c:1741
int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt)
Determine whether pix_fmt is a hardware accelerated format.
Definition: imgconvert.c:424
int frame_number
audio or video frame number
Definition: avcodec.h:1471
int height
Definition: avcodec.h:1299
static int op(uint8_t **dst, const uint8_t *dst_end, const uint8_t **buf, const uint8_t *buf_end, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:74
#define av_always_inline
Definition: attributes.h:39
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3223
Y , 8bpp.
Definition: pixfmt.h:72
int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:62
#define FFSWAP(type, a, b)
Definition: common.h:58
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:750
int avpriv_unlock_avformat(void)
Definition: utils.c:1796
int(* init)(AVCodecContext *)
Definition: avcodec.h:3200
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: avcodec.h:1285
AVHWAccel * av_hwaccel_next(AVHWAccel *hwaccel)
If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL...
Definition: utils.c:1750
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:1406
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3269
int linesize[AV_NUM_DATA_POINTERS]
Definition: internal.h:35
int nb_samples
number of audio samples (per channel) described by this frame
Definition: avcodec.h:1265
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:901
#define FFMAX3(a, b, c)
Definition: common.h:54
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:271
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.
Definition: audioconvert.c:92
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
enum CodecID codec_id
Definition: avcodec.h:1575
uint8_t * subtitle_header
Header containing style information for text subtitles.
Definition: avcodec.h:3074