Libav
flvdec.c
Go to the documentation of this file.
1 /*
2  * FLV demuxer
3  * Copyright (c) 2003 The Libav Project
4  *
5  * This demuxer will generate a 1 byte extradata for VP6F content.
6  * It is composed of:
7  * - upper 4bits: difference between encoded width and visible width
8  * - lower 4bits: difference between encoded height and visible height
9  *
10  * This file is part of Libav.
11  *
12  * Libav is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * Libav is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with Libav; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 #include "libavutil/avstring.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intfloat.h"
32 #include "libavutil/mathematics.h"
33 #include "libavcodec/bytestream.h"
34 #include "libavcodec/mpeg4audio.h"
35 #include "avformat.h"
36 #include "internal.h"
37 #include "avio_internal.h"
38 #include "flv.h"
39 
40 #define KEYFRAMES_TAG "keyframes"
41 #define KEYFRAMES_TIMESTAMP_TAG "times"
42 #define KEYFRAMES_BYTEOFFSET_TAG "filepositions"
43 
44 #define VALIDATE_INDEX_TS_THRESH 2500
45 
46 typedef struct {
47  const AVClass *class;
49  int wrong_dts;
50  uint8_t *new_extradata[2];
51  int new_extradata_size[2];
54  struct {
55  int64_t dts;
56  int64_t pos;
57  } validate_index[2];
60 } FLVContext;
61 
62 static int flv_probe(AVProbeData *p)
63 {
64  const uint8_t *d;
65 
66  d = p->buf;
67  if (d[0] == 'F' &&
68  d[1] == 'L' &&
69  d[2] == 'V' &&
70  d[3] < 5 && d[5] == 0 &&
71  AV_RB32(d + 5) > 8) {
72  return AVPROBE_SCORE_MAX;
73  }
74  return 0;
75 }
76 
78 {
80  if (!st)
81  return NULL;
83  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
84  return st;
85 }
86 
87 static int flv_same_audio_codec(AVCodecContext *acodec, int flags)
88 {
89  int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
90  int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
91  int codec_id;
92 
93  if (!acodec->codec_id && !acodec->codec_tag)
94  return 1;
95 
96  if (acodec->bits_per_coded_sample != bits_per_coded_sample)
97  return 0;
98 
99  switch (flv_codecid) {
100  // no distinction between S16 and S8 PCM codec flags
101  case FLV_CODECID_PCM:
102  codec_id = bits_per_coded_sample == 8
104 #if HAVE_BIGENDIAN
106 #else
108 #endif
109  return codec_id == acodec->codec_id;
110  case FLV_CODECID_PCM_LE:
111  codec_id = bits_per_coded_sample == 8
114  return codec_id == acodec->codec_id;
115  case FLV_CODECID_AAC:
116  return acodec->codec_id == AV_CODEC_ID_AAC;
117  case FLV_CODECID_ADPCM:
118  return acodec->codec_id == AV_CODEC_ID_ADPCM_SWF;
119  case FLV_CODECID_SPEEX:
120  return acodec->codec_id == AV_CODEC_ID_SPEEX;
121  case FLV_CODECID_MP3:
122  return acodec->codec_id == AV_CODEC_ID_MP3;
126  return acodec->codec_id == AV_CODEC_ID_NELLYMOSER;
128  return acodec->sample_rate == 8000 &&
129  acodec->codec_id == AV_CODEC_ID_PCM_MULAW;
131  return acodec->sample_rate == 8000 &&
132  acodec->codec_id == AV_CODEC_ID_PCM_ALAW;
133  default:
134  return acodec->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
135  }
136 }
137 
139  AVCodecContext *acodec, int flv_codecid)
140 {
141  switch (flv_codecid) {
142  // no distinction between S16 and S8 PCM codec flags
143  case FLV_CODECID_PCM:
144  acodec->codec_id = acodec->bits_per_coded_sample == 8
146 #if HAVE_BIGENDIAN
148 #else
150 #endif
151  break;
152  case FLV_CODECID_PCM_LE:
153  acodec->codec_id = acodec->bits_per_coded_sample == 8
156  break;
157  case FLV_CODECID_AAC:
158  acodec->codec_id = AV_CODEC_ID_AAC;
159  break;
160  case FLV_CODECID_ADPCM:
162  break;
163  case FLV_CODECID_SPEEX:
164  acodec->codec_id = AV_CODEC_ID_SPEEX;
165  acodec->sample_rate = 16000;
166  break;
167  case FLV_CODECID_MP3:
168  acodec->codec_id = AV_CODEC_ID_MP3;
170  break;
172  // in case metadata does not otherwise declare samplerate
173  acodec->sample_rate = 8000;
175  break;
177  acodec->sample_rate = 16000;
179  break;
182  break;
184  acodec->sample_rate = 8000;
186  break;
188  acodec->sample_rate = 8000;
189  acodec->codec_id = AV_CODEC_ID_PCM_ALAW;
190  break;
191  default:
192  av_log(s, AV_LOG_INFO, "Unsupported audio codec (%x)\n",
193  flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
194  acodec->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
195  }
196 }
197 
198 static int flv_same_video_codec(AVCodecContext *vcodec, int flags)
199 {
200  int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
201 
202  if (!vcodec->codec_id && !vcodec->codec_tag)
203  return 1;
204 
205  switch (flv_codecid) {
206  case FLV_CODECID_H263:
207  return vcodec->codec_id == AV_CODEC_ID_FLV1;
208  case FLV_CODECID_SCREEN:
209  return vcodec->codec_id == AV_CODEC_ID_FLASHSV;
210  case FLV_CODECID_SCREEN2:
211  return vcodec->codec_id == AV_CODEC_ID_FLASHSV2;
212  case FLV_CODECID_VP6:
213  return vcodec->codec_id == AV_CODEC_ID_VP6F;
214  case FLV_CODECID_VP6A:
215  return vcodec->codec_id == AV_CODEC_ID_VP6A;
216  case FLV_CODECID_H264:
217  return vcodec->codec_id == AV_CODEC_ID_H264;
218  default:
219  return vcodec->codec_tag == flv_codecid;
220  }
221 }
222 
224  int flv_codecid, int read)
225 {
226  AVCodecContext *vcodec = vstream->codec;
227  switch (flv_codecid) {
228  case FLV_CODECID_H263:
229  vcodec->codec_id = AV_CODEC_ID_FLV1;
230  break;
231  case FLV_CODECID_SCREEN:
232  vcodec->codec_id = AV_CODEC_ID_FLASHSV;
233  break;
234  case FLV_CODECID_SCREEN2:
235  vcodec->codec_id = AV_CODEC_ID_FLASHSV2;
236  break;
237  case FLV_CODECID_VP6:
238  vcodec->codec_id = AV_CODEC_ID_VP6F;
239  case FLV_CODECID_VP6A:
240  if (flv_codecid == FLV_CODECID_VP6A)
241  vcodec->codec_id = AV_CODEC_ID_VP6A;
242  if (read) {
243  if (vcodec->extradata_size != 1) {
244  vcodec->extradata = av_malloc(1);
245  if (vcodec->extradata)
246  vcodec->extradata_size = 1;
247  }
248  if (vcodec->extradata)
249  vcodec->extradata[0] = avio_r8(s->pb);
250  else
251  avio_skip(s->pb, 1);
252  }
253  return 1; // 1 byte body size adjustment for flv_read_packet()
254  case FLV_CODECID_H264:
255  vcodec->codec_id = AV_CODEC_ID_H264;
256  return 3; // not 4, reading packet type will consume one byte
257  default:
258  av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid);
259  vcodec->codec_tag = flv_codecid;
260  }
261 
262  return 0;
263 }
264 
265 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
266 {
267  int length = avio_rb16(ioc);
268  if (length >= buffsize) {
269  avio_skip(ioc, length);
270  return -1;
271  }
272 
273  avio_read(ioc, buffer, length);
274 
275  buffer[length] = '\0';
276 
277  return length;
278 }
279 
281  AVStream *vstream, int64_t max_pos)
282 {
283  FLVContext *flv = s->priv_data;
284  unsigned int arraylen = 0, timeslen = 0, fileposlen = 0, i;
285  double num_val;
286  char str_val[256];
287  int64_t *times = NULL;
288  int64_t *filepositions = NULL;
289  int ret = AVERROR(ENOSYS);
290  int64_t initial_pos = avio_tell(ioc);
291 
292  if (s->flags & AVFMT_FLAG_IGNIDX)
293  return 0;
294 
295  while (avio_tell(ioc) < max_pos - 2 &&
296  amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
297  int64_t *current_array;
298 
299  // Expect array object in context
300  if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
301  break;
302 
303  arraylen = avio_rb32(ioc);
304  if (arraylen >> 28)
305  break;
306 
307  /* Expect only 'times' or 'filepositions' sub-arrays in other
308  * case refuse to use such metadata for indexing. */
309  if (!strcmp(KEYFRAMES_TIMESTAMP_TAG, str_val) && !times) {
310  if (!(times = av_mallocz(sizeof(*times) * arraylen))) {
311  ret = AVERROR(ENOMEM);
312  goto finish;
313  }
314  timeslen = arraylen;
315  current_array = times;
316  } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
317  !filepositions) {
318  if (!(filepositions = av_mallocz(sizeof(*filepositions) * arraylen))) {
319  ret = AVERROR(ENOMEM);
320  goto finish;
321  }
322  fileposlen = arraylen;
323  current_array = filepositions;
324  } else
325  // unexpected metatag inside keyframes, will not use such
326  // metadata for indexing
327  break;
328 
329  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
330  if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
331  goto finish;
332  num_val = av_int2double(avio_rb64(ioc));
333  current_array[i] = num_val;
334  }
335  if (times && filepositions) {
336  // All done, exiting at a position allowing amf_parse_object
337  // to finish parsing the object
338  ret = 0;
339  break;
340  }
341  }
342 
343  if (!ret && timeslen == fileposlen) {
344  for (i = 0; i < fileposlen; i++) {
345  av_add_index_entry(vstream, filepositions[i], times[i] * 1000,
346  0, 0, AVINDEX_KEYFRAME);
347  if (i < 2) {
348  flv->validate_index[i].pos = filepositions[i];
349  flv->validate_index[i].dts = times[i] * 1000;
350  flv->validate_count = i + 1;
351  }
352  }
353  } else
354  av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
355 
356 finish:
357  av_freep(&times);
358  av_freep(&filepositions);
359  // If we got unexpected data, but successfully reset back to
360  // the start pos, the caller can continue parsing
361  if (ret < 0 && avio_seek(ioc, initial_pos, SEEK_SET) > 0)
362  return 0;
363  return ret;
364 }
365 
366 static int amf_parse_object(AVFormatContext *s, AVStream *astream,
367  AVStream *vstream, const char *key,
368  int64_t max_pos, int depth)
369 {
370  AVCodecContext *acodec, *vcodec;
371  FLVContext *flv = s->priv_data;
372  AVIOContext *ioc;
373  AMFDataType amf_type;
374  char str_val[256];
375  double num_val;
376 
377  num_val = 0;
378  ioc = s->pb;
379  amf_type = avio_r8(ioc);
380 
381  switch (amf_type) {
383  num_val = av_int2double(avio_rb64(ioc));
384  break;
385  case AMF_DATA_TYPE_BOOL:
386  num_val = avio_r8(ioc);
387  break;
389  if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0)
390  return -1;
391  break;
393  if ((vstream || astream) && key &&
394  !strcmp(KEYFRAMES_TAG, key) && depth == 1)
395  if (parse_keyframes_index(s, ioc, vstream ? vstream : astream,
396  max_pos) < 0)
397  return -1;
398 
399  while (avio_tell(ioc) < max_pos - 2 &&
400  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
401  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
402  depth + 1) < 0)
403  return -1; // if we couldn't skip, bomb out.
404  if (avio_r8(ioc) != AMF_END_OF_OBJECT)
405  return -1;
406  break;
407  case AMF_DATA_TYPE_NULL:
410  break; // these take up no additional space
412  avio_skip(ioc, 4); // skip 32-bit max array index
413  while (avio_tell(ioc) < max_pos - 2 &&
414  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
415  // this is the only case in which we would want a nested
416  // parse to not skip over the object
417  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
418  depth + 1) < 0)
419  return -1;
420  if (avio_r8(ioc) != AMF_END_OF_OBJECT)
421  return -1;
422  break;
423  case AMF_DATA_TYPE_ARRAY:
424  {
425  unsigned int arraylen, i;
426 
427  arraylen = avio_rb32(ioc);
428  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
429  if (amf_parse_object(s, NULL, NULL, NULL, max_pos,
430  depth + 1) < 0)
431  return -1; // if we couldn't skip, bomb out.
432  }
433  break;
434  case AMF_DATA_TYPE_DATE:
435  avio_skip(ioc, 8 + 2); // timestamp (double) and UTC offset (int16)
436  break;
437  default: // unsupported type, we couldn't skip
438  return -1;
439  }
440 
441  // only look for metadata values when we are not nested and key != NULL
442  if (depth == 1 && key) {
443  acodec = astream ? astream->codec : NULL;
444  vcodec = vstream ? vstream->codec : NULL;
445 
446  if (amf_type == AMF_DATA_TYPE_NUMBER ||
447  amf_type == AMF_DATA_TYPE_BOOL) {
448  if (!strcmp(key, "duration"))
449  s->duration = num_val * AV_TIME_BASE;
450  else if (!strcmp(key, "videodatarate") && vcodec &&
451  0 <= (int)(num_val * 1024.0))
452  vcodec->bit_rate = num_val * 1024.0;
453  else if (!strcmp(key, "audiodatarate") && acodec &&
454  0 <= (int)(num_val * 1024.0))
455  acodec->bit_rate = num_val * 1024.0;
456  else if (!strcmp(key, "datastream")) {
458  if (!st)
459  return AVERROR(ENOMEM);
461  } else if (flv->trust_metadata) {
462  if (!strcmp(key, "videocodecid") && vcodec) {
463  flv_set_video_codec(s, vstream, num_val, 0);
464  } else if (!strcmp(key, "audiocodecid") && acodec) {
465  int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
466  flv_set_audio_codec(s, astream, acodec, id);
467  } else if (!strcmp(key, "audiosamplerate") && acodec) {
468  acodec->sample_rate = num_val;
469  } else if (!strcmp(key, "audiosamplesize") && acodec) {
470  acodec->bits_per_coded_sample = num_val;
471  } else if (!strcmp(key, "stereo") && acodec) {
472  acodec->channels = num_val + 1;
473  acodec->channel_layout = acodec->channels == 2 ?
476  } else if (!strcmp(key, "width") && vcodec) {
477  vcodec->width = num_val;
478  } else if (!strcmp(key, "height") && vcodec) {
479  vcodec->height = num_val;
480  }
481  }
482  }
483 
484  if (!strcmp(key, "duration") ||
485  !strcmp(key, "filesize") ||
486  !strcmp(key, "width") ||
487  !strcmp(key, "height") ||
488  !strcmp(key, "videodatarate") ||
489  !strcmp(key, "framerate") ||
490  !strcmp(key, "videocodecid") ||
491  !strcmp(key, "audiodatarate") ||
492  !strcmp(key, "audiosamplerate") ||
493  !strcmp(key, "audiosamplesize") ||
494  !strcmp(key, "stereo") ||
495  !strcmp(key, "audiocodecid") ||
496  !strcmp(key, "datastream"))
497  return 0;
498 
499  if (amf_type == AMF_DATA_TYPE_BOOL) {
500  av_strlcpy(str_val, num_val > 0 ? "true" : "false",
501  sizeof(str_val));
502  av_dict_set(&s->metadata, key, str_val, 0);
503  } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
504  snprintf(str_val, sizeof(str_val), "%.f", num_val);
505  av_dict_set(&s->metadata, key, str_val, 0);
506  } else if (amf_type == AMF_DATA_TYPE_STRING)
507  av_dict_set(&s->metadata, key, str_val, 0);
508  }
509 
510  return 0;
511 }
512 
513 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
514 {
515  AMFDataType type;
516  AVStream *stream, *astream, *vstream;
517  AVIOContext *ioc;
518  int i;
519  // only needs to hold the string "onMetaData".
520  // Anything longer is something we don't want.
521  char buffer[11];
522 
523  astream = NULL;
524  vstream = NULL;
525  ioc = s->pb;
526 
527  // first object needs to be "onMetaData" string
528  type = avio_r8(ioc);
529  if (type != AMF_DATA_TYPE_STRING ||
530  amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
531  return -1;
532 
533  if (!strcmp(buffer, "onTextData"))
534  return 1;
535 
536  if (strcmp(buffer, "onMetaData"))
537  return -1;
538 
539  // find the streams now so that amf_parse_object doesn't need to do
540  // the lookup every time it is called.
541  for (i = 0; i < s->nb_streams; i++) {
542  stream = s->streams[i];
543  if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO)
544  astream = stream;
545  else if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO)
546  vstream = stream;
547  }
548 
549  // parse the second object (we want a mixed array)
550  if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
551  return -1;
552 
553  return 0;
554 }
555 
557 {
558  int offset, flags;
559 
560  avio_skip(s->pb, 4);
561  flags = avio_r8(s->pb);
562  /* old flvtool cleared this field */
563  /* FIXME: better fix needed */
564  if (!flags) {
567  "Broken FLV file, which says no streams present, "
568  "this might fail\n");
569  }
570 
572 
573  if (flags & FLV_HEADER_FLAG_HASVIDEO)
575  return AVERROR(ENOMEM);
576  if (flags & FLV_HEADER_FLAG_HASAUDIO)
578  return AVERROR(ENOMEM);
579 
580  offset = avio_rb32(s->pb);
581  avio_seek(s->pb, offset, SEEK_SET);
582  avio_skip(s->pb, 4);
583 
584  s->start_time = 0;
585 
586  return 0;
587 }
588 
590 {
591  FLVContext *flv = s->priv_data;
592  av_freep(&flv->new_extradata[0]);
593  av_freep(&flv->new_extradata[1]);
594  return 0;
595 }
596 
598 {
599  av_free(st->codec->extradata);
601  if (!st->codec->extradata)
602  return AVERROR(ENOMEM);
603  st->codec->extradata_size = size;
605  return 0;
606 }
607 
608 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
609  int size)
610 {
611  av_free(flv->new_extradata[stream]);
612  flv->new_extradata[stream] = av_mallocz(size +
614  if (!flv->new_extradata[stream])
615  return AVERROR(ENOMEM);
616  flv->new_extradata_size[stream] = size;
617  avio_read(pb, flv->new_extradata[stream], size);
618  return 0;
619 }
620 
621 static void clear_index_entries(AVFormatContext *s, int64_t pos)
622 {
623  int i, j, out;
625  "Found invalid index entries, clearing the index.\n");
626  for (i = 0; i < s->nb_streams; i++) {
627  AVStream *st = s->streams[i];
628  /* Remove all index entries that point to >= pos */
629  out = 0;
630  for (j = 0; j < st->nb_index_entries; j++)
631  if (st->index_entries[j].pos < pos)
632  st->index_entries[out++] = st->index_entries[j];
633  st->nb_index_entries = out;
634  }
635 }
636 
637 static int amf_skip_tag(AVIOContext *pb, AMFDataType type)
638 {
639  int nb = -1, ret, parse_name = 1;
640 
641  switch (type) {
643  avio_skip(pb, 8);
644  break;
645  case AMF_DATA_TYPE_BOOL:
646  avio_skip(pb, 1);
647  break;
649  avio_skip(pb, avio_rb16(pb));
650  break;
651  case AMF_DATA_TYPE_ARRAY:
652  parse_name = 0;
654  nb = avio_rb32(pb);
656  while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
657  if (parse_name) {
658  int size = avio_rb16(pb);
659  if (!size) {
660  avio_skip(pb, 1);
661  break;
662  }
663  avio_skip(pb, size);
664  }
665  if ((ret = amf_skip_tag(pb, avio_r8(pb))) < 0)
666  return ret;
667  }
668  break;
669  case AMF_DATA_TYPE_NULL:
671  break;
672  default:
673  return AVERROR_INVALIDDATA;
674  }
675  return 0;
676 }
677 
679  int64_t dts, int64_t next)
680 {
681  AVIOContext *pb = s->pb;
682  AVStream *st = NULL;
683  char buf[20];
684  int ret = AVERROR_INVALIDDATA;
685  int i, length = -1;
686 
687  switch (avio_r8(pb)) {
689  avio_seek(pb, 4, SEEK_CUR);
691  break;
692  default:
693  goto skip;
694  }
695 
696  while ((ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
697  AMFDataType type = avio_r8(pb);
698  if (type == AMF_DATA_TYPE_STRING && !strcmp(buf, "text")) {
699  length = avio_rb16(pb);
700  ret = av_get_packet(pb, pkt, length);
701  if (ret < 0)
702  goto skip;
703  else
704  break;
705  } else {
706  if ((ret = amf_skip_tag(pb, type)) < 0)
707  goto skip;
708  }
709  }
710 
711  if (length < 0) {
712  ret = AVERROR_INVALIDDATA;
713  goto skip;
714  }
715 
716  for (i = 0; i < s->nb_streams; i++) {
717  st = s->streams[i];
718  if (st->codec->codec_type == AVMEDIA_TYPE_DATA)
719  break;
720  }
721 
722  if (i == s->nb_streams) {
724  if (!st)
725  return AVERROR_INVALIDDATA;
727  }
728 
729  pkt->dts = dts;
730  pkt->pts = dts;
731  pkt->size = ret;
732 
733  pkt->stream_index = st->index;
734  pkt->flags |= AV_PKT_FLAG_KEY;
735 
736 skip:
737  avio_seek(s->pb, next + 4, SEEK_SET);
738 
739  return ret;
740 }
741 
743 {
744  FLVContext *flv = s->priv_data;
745  int ret, i, type, size, flags, is_audio;
746  int64_t next, pos;
747  int64_t dts, pts = AV_NOPTS_VALUE;
748  int sample_rate = 0, channels = 0;
749  AVStream *st = NULL;
750 
751  /* pkt size is repeated at end. skip it */
752  for (;; avio_skip(s->pb, 4)) {
753  pos = avio_tell(s->pb);
754  type = avio_r8(s->pb);
755  size = avio_rb24(s->pb);
756  dts = avio_rb24(s->pb);
757  dts |= avio_r8(s->pb) << 24;
758  av_dlog(s, "type:%d, size:%d, dts:%"PRId64"\n", type, size, dts);
759  if (s->pb->eof_reached)
760  return AVERROR_EOF;
761  avio_skip(s->pb, 3); /* stream id, always 0 */
762  flags = 0;
763 
764  if (flv->validate_next < flv->validate_count) {
765  int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
766  if (pos == validate_pos) {
767  if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
769  flv->validate_next++;
770  } else {
771  clear_index_entries(s, validate_pos);
772  flv->validate_count = 0;
773  }
774  } else if (pos > validate_pos) {
775  clear_index_entries(s, validate_pos);
776  flv->validate_count = 0;
777  }
778  }
779 
780  if (size == 0)
781  continue;
782 
783  next = size + avio_tell(s->pb);
784 
785  if (type == FLV_TAG_TYPE_AUDIO) {
786  is_audio = 1;
787  flags = avio_r8(s->pb);
788  size--;
789  } else if (type == FLV_TAG_TYPE_VIDEO) {
790  is_audio = 0;
791  flags = avio_r8(s->pb);
792  size--;
793  if ((flags & 0xf0) == 0x50) /* video info / command frame */
794  goto skip;
795  } else {
796  if (type == FLV_TAG_TYPE_META && size > 13 + 1 + 4)
797  if (flv_read_metabody(s, next) > 0) {
798  return flv_data_packet(s, pkt, dts, next);
799  } else /* skip packet */
800  av_log(s, AV_LOG_DEBUG,
801  "skipping flv packet: type %d, size %d, flags %d\n",
802  type, size, flags);
803 
804 skip:
805  avio_seek(s->pb, next, SEEK_SET);
806  continue;
807  }
808 
809  /* skip empty data packets */
810  if (!size)
811  continue;
812 
813  /* now find stream */
814  for (i = 0; i < s->nb_streams; i++) {
815  st = s->streams[i];
816  if (is_audio && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
817  if (flv_same_audio_codec(st->codec, flags))
818  break;
819  } else if (!is_audio &&
821  if (flv_same_video_codec(st->codec, flags))
822  break;
823  }
824  }
825  if (i == s->nb_streams)
826  st = create_stream(s, is_audio ? AVMEDIA_TYPE_AUDIO
828  av_dlog(s, "%d %X %d \n", is_audio, flags, st->discard);
829  if ((st->discard >= AVDISCARD_NONKEY &&
830  !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio)) ||
831  (st->discard >= AVDISCARD_BIDIR &&
832  ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio)) ||
833  st->discard >= AVDISCARD_ALL) {
834  avio_seek(s->pb, next, SEEK_SET);
835  continue;
836  }
837  if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)
838  av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME);
839  break;
840  }
841 
842  // if not streamed and no duration from metadata then seek to end to find
843  // the duration from the timestamps
844  if (s->pb->seekable && (!s->duration || s->duration == AV_NOPTS_VALUE)) {
845  int size;
846  const int64_t pos = avio_tell(s->pb);
847  const int64_t fsize = avio_size(s->pb);
848  avio_seek(s->pb, fsize - 4, SEEK_SET);
849  size = avio_rb32(s->pb);
850  avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
851  if (size == avio_rb24(s->pb) + 11) {
852  uint32_t ts = avio_rb24(s->pb);
853  ts |= avio_r8(s->pb) << 24;
854  s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
855  }
856  avio_seek(s->pb, pos, SEEK_SET);
857  }
858 
859  if (is_audio) {
860  int bits_per_coded_sample;
861  channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
862  sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
864  bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
865  if (!st->codec->channels || !st->codec->sample_rate ||
867  st->codec->channels = channels;
868  st->codec->channel_layout = channels == 1
871  st->codec->sample_rate = sample_rate;
872  st->codec->bits_per_coded_sample = bits_per_coded_sample;
873  }
874  if (!st->codec->codec_id) {
875  flv_set_audio_codec(s, st, st->codec,
876  flags & FLV_AUDIO_CODECID_MASK);
877  flv->last_sample_rate =
878  sample_rate = st->codec->sample_rate;
879  flv->last_channels =
880  channels = st->codec->channels;
881  } else {
882  AVCodecContext ctx;
883  ctx.sample_rate = sample_rate;
884  flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK);
885  sample_rate = ctx.sample_rate;
886  }
887  } else {
888  size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1);
889  }
890 
891  if (st->codec->codec_id == AV_CODEC_ID_AAC ||
892  st->codec->codec_id == AV_CODEC_ID_H264) {
893  int type = avio_r8(s->pb);
894  size--;
895  if (st->codec->codec_id == AV_CODEC_ID_H264) {
896  // sign extension
897  int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
898  pts = dts + cts;
899  if (cts < 0) { // dts are wrong
900  flv->wrong_dts = 1;
902  "negative cts, previous timestamps might be wrong\n");
903  }
904  if (flv->wrong_dts)
905  dts = AV_NOPTS_VALUE;
906  }
907  if (type == 0) {
908  if (st->codec->extradata) {
909  if ((ret = flv_queue_extradata(flv, s->pb, is_audio, size)) < 0)
910  return ret;
911  ret = AVERROR(EAGAIN);
912  goto leave;
913  }
914  if ((ret = flv_get_extradata(s, st, size)) < 0)
915  return ret;
916  if (st->codec->codec_id == AV_CODEC_ID_AAC) {
917  MPEG4AudioConfig cfg;
918 
919  /* Workaround for buggy Omnia A/XE encoder */
920  AVDictionaryEntry *t = av_dict_get(s->metadata, "Encoder", NULL, 0);
921  if (t && !strcmp(t->value, "Omnia A/XE"))
922  st->codec->extradata_size = 2;
923 
925  st->codec->extradata_size * 8, 1);
926  st->codec->channels = cfg.channels;
927  st->codec->channel_layout = 0;
928  if (cfg.ext_sample_rate)
929  st->codec->sample_rate = cfg.ext_sample_rate;
930  else
931  st->codec->sample_rate = cfg.sample_rate;
932  av_dlog(s, "mp4a config channels %d sample rate %d\n",
933  st->codec->channels, st->codec->sample_rate);
934  }
935 
936  ret = AVERROR(EAGAIN);
937  goto leave;
938  }
939  }
940 
941  /* skip empty data packets */
942  if (!size) {
943  ret = AVERROR(EAGAIN);
944  goto leave;
945  }
946 
947  ret = av_get_packet(s->pb, pkt, size);
948  if (ret < 0)
949  return AVERROR(EIO);
950  /* note: we need to modify the packet size here to handle the last
951  * packet */
952  pkt->size = ret;
953  pkt->dts = dts;
954  pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
955  pkt->stream_index = st->index;
956  if (flv->new_extradata[is_audio]) {
958  flv->new_extradata_size[is_audio]);
959  if (side) {
960  memcpy(side, flv->new_extradata[is_audio],
961  flv->new_extradata_size[is_audio]);
962  av_freep(&flv->new_extradata[is_audio]);
963  flv->new_extradata_size[is_audio] = 0;
964  }
965  }
966  if (is_audio && (sample_rate != flv->last_sample_rate ||
967  channels != flv->last_channels)) {
968  flv->last_sample_rate = sample_rate;
969  flv->last_channels = channels;
970  ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
971  }
972 
973  if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))
974  pkt->flags |= AV_PKT_FLAG_KEY;
975 
976 leave:
977  avio_skip(s->pb, 4);
978  return ret;
979 }
980 
981 static int flv_read_seek(AVFormatContext *s, int stream_index,
982  int64_t ts, int flags)
983 {
984  FLVContext *flv = s->priv_data;
985  flv->validate_count = 0;
986  return avio_seek_time(s->pb, stream_index, ts, flags);
987 }
988 
989 #define OFFSET(x) offsetof(FLVContext, x)
990 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
991 static const AVOption options[] = {
992  { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VD },
993  { NULL }
994 };
995 
996 static const AVClass class = {
997  .class_name = "flvdec",
998  .item_name = av_default_item_name,
999  .option = options,
1001 };
1002 
1004  .name = "flv",
1005  .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1006  .priv_data_size = sizeof(FLVContext),
1007  .read_probe = flv_probe,
1012  .extensions = "flv",
1013  .priv_class = &class,
1014 };
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
discard all frames except keyframes
Definition: avcodec.h:545
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:241
int size
AVOption.
Definition: opt.h:233
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: utils.c:1312
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
static void clear_index_entries(AVFormatContext *s, int64_t pos)
Definition: flvdec.c:621
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:3208
int64_t pos
Definition: avformat.h:644
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
int index
stream index in AVFormatContext
Definition: avformat.h:684
int size
Definition: avcodec.h:974
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:186
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:827
static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, int64_t dts, int64_t next)
Definition: flvdec.c:678
enum AVMediaType codec_type
Definition: rtp.c:36
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
discard all
Definition: avcodec.h:546
static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream *vstream, int64_t max_pos)
Definition: flvdec.c:280
#define AV_CH_LAYOUT_STEREO
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: flvdec.c:742
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:574
uint8_t * new_extradata[2]
Definition: flvdec.c:50
int ctx_flags
Format-specific flags, see AVFMTCTX_xx.
Definition: avformat.h:916
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
#define OFFSET(x)
Definition: flvdec.c:989
static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags)
Definition: flvdec.c:981
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:198
Format I/O context.
Definition: avformat.h:871
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:38
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:976
Public dictionary API.
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition: intfloat.h:60
uint8_t
int validate_next
Definition: flvdec.c:58
#define VD
Definition: flvdec.c:990
Opaque data information usually continuous.
Definition: avutil.h:189
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:850
AVOptions.
#define FLV_AUDIO_CODECID_MASK
Definition: flv.h:42
int64_t pos
Definition: flvdec.c:56
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:589
int wrong_dts
wrong dts due to negative cts
Definition: flvdec.c:49
#define AV_RB32
Definition: intreadwrite.h:130
enum AVStreamParseType need_parsing
Definition: avformat.h:816
static const AVOption options[]
Definition: flvdec.c:991
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1162
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define FLV_VIDEO_CODECID_MASK
Definition: flv.h:44
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:935
#define VALIDATE_INDEX_TS_THRESH
Definition: flvdec.c:44
#define KEYFRAMES_BYTEOFFSET_TAG
Definition: flvdec.c:42
static int flags
Definition: log.c:44
#define AVERROR_EOF
End of file.
Definition: error.h:51
#define FLV_AUDIO_SAMPLERATE_OFFSET
Definition: flv.h:33
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:118
AMFDataType
Definition: flv.h:106
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:654
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
int trust_metadata
configure streams according onMetaData
Definition: flvdec.c:48
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2481
static float t
Definition: output.c:52
int validate_count
Definition: flvdec.c:59
#define FLV_AUDIO_SAMPLERATE_MASK
Definition: flv.h:41
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:446
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1023
#define AVINDEX_KEYFRAME
Definition: avformat.h:646
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1064
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
discard all bidirectional frames
Definition: avcodec.h:544
#define AVERROR(e)
Definition: error.h:43
static int flv_read_close(AVFormatContext *s)
Definition: flvdec.c:589
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
static int flv_read_header(AVFormatContext *s)
Definition: flvdec.c:556
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:369
int ff_add_param_change(AVPacket *pkt, int32_t channels, uint64_t channel_layout, int32_t sample_rate, int32_t width, int32_t height)
Add side data to a packet for changing parameters to the given values.
Definition: utils.c:3350
static AVStream * create_stream(AVFormatContext *s, int codec_type)
Definition: flvdec.c:77
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2662
enum AVCodecID codec_id
Definition: mov_chan.c:432
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:81
Definition: flv.h:62
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read)
Definition: flvdec.c:223
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1840
int64_t dts
Definition: flvdec.c:55
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:437
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:702
struct FLVContext::@103 validate_index[2]
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:390
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:509
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:923
#define FLV_AUDIO_CODECID_OFFSET
Definition: flv.h:34
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
int bit_rate
the average bitrate
Definition: avcodec.h:1112
audio channel layout utility functions
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:582
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:234
static int flv_same_video_codec(AVCodecContext *vcodec, int flags)
Definition: flvdec.c:198
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
int width
picture width / height.
Definition: avcodec.h:1217
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:210
int32_t
#define FFABS(a)
Definition: common.h:52
static char buffer[20]
Definition: seek-test.c:31
static int flv_probe(AVProbeData *p)
Definition: flvdec.c:62
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecContext *acodec, int flv_codecid)
Definition: flvdec.c:138
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:536
static int flv_same_audio_codec(AVCodecContext *acodec, int flags)
Definition: flvdec.c:87
Stream structure.
Definition: avformat.h:683
static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
Definition: flvdec.c:513
NULL
Definition: eval.c:55
#define AV_LOG_INFO
Standard information.
Definition: log.h:134
FLV common header.
enum AVMediaType codec_type
Definition: avcodec.h:1062
enum AVCodecID codec_id
Definition: avcodec.h:1065
int sample_rate
samples per second
Definition: avcodec.h:1779
AVIOContext * pb
I/O context.
Definition: avformat.h:913
av_default_item_name
Definition: dnxhdenc.c:45
main external API structure.
Definition: avcodec.h:1054
int new_extradata_size[2]
Definition: flvdec.c:51
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1080
int extradata_size
Definition: avcodec.h:1163
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
int last_sample_rate
Definition: flvdec.c:52
int nb_index_entries
Definition: avformat.h:829
Describe the class of an AVClass context structure.
Definition: log.h:33
int last_channels
Definition: flvdec.c:53
static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, int size)
Definition: flvdec.c:608
This structure contains the data a format has to probe a file.
Definition: avformat.h:388
#define FLV_AUDIO_CHANNEL_MASK
Definition: flv.h:39
#define FLV_AUDIO_SAMPLESIZE_MASK
Definition: flv.h:40
#define AMF_END_OF_OBJECT
Definition: flv.h:47
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
Definition: avformat.h:952
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:395
full parsing and repack
Definition: avformat.h:637
Main libavformat public API header.
#define KEYFRAMES_TAG
Definition: flvdec.c:40
raw UTF-8 text
Definition: avcodec.h:440
#define FLV_VIDEO_FRAMETYPE_MASK
Definition: flv.h:45
static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
Definition: flvdec.c:265
static const int32_t max_pos[4]
Definition: g723_1_data.h:534
AVInputFormat ff_flv_demuxer
Definition: flvdec.c:1003
int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bit_size, int sync_extension)
Parse MPEG-4 systems extradata to retrieve audio configuration.
Definition: mpeg4audio.c:79
static int amf_skip_tag(AVIOContext *pb, AMFDataType type)
Definition: flvdec.c:637
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:835
char * value
Definition: dict.h:76
int eof_reached
true if eof reached
Definition: avio.h:96
static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth)
Definition: flvdec.c:366
int channels
number of audio channels
Definition: avcodec.h:1780
void * priv_data
Format private data.
Definition: avformat.h:899
#define KEYFRAMES_TIMESTAMP_TAG
Definition: flvdec.c:41
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:972
static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
Definition: flvdec.c:597
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:962
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:516
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:261
int stream_index
Definition: avcodec.h:975
#define AV_CH_LAYOUT_MONO
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:740
This structure stores compressed data.
Definition: avcodec.h:950
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:205
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228