FFmpeg
flvdec.c
Go to the documentation of this file.
1 /*
2  * FLV demuxer
3  * Copyright (c) 2003 The FFmpeg Project
4  *
5  * This demuxer will generate a 1 byte extradata for VP6F content.
6  * It is composed of:
7  * - upper 4 bits: difference between encoded width and visible width
8  * - lower 4 bits: difference between encoded height and visible height
9  *
10  * This file is part of FFmpeg.
11  *
12  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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/avassert.h"
28 #include "libavutil/avstring.h"
30 #include "libavutil/dict.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/intfloat.h"
34 #include "libavutil/intreadwrite.h"
35 #include "libavutil/mathematics.h"
36 #include "avformat.h"
37 #include "demux.h"
38 #include "internal.h"
39 #include "flv.h"
40 
41 #define VALIDATE_INDEX_TS_THRESH 2500
42 
43 #define RESYNC_BUFFER_SIZE (1<<20)
44 
45 #define MAX_DEPTH 16 ///< arbitrary limit to prevent unbounded recursion
46 
47 typedef struct FLVContext {
48  const AVClass *class; ///< Class for private options.
49  int trust_metadata; ///< configure streams according onMetaData
50  int trust_datasize; ///< trust data size of FLVTag
51  int dump_full_metadata; ///< Dump full metadata of the onMetadata
52  int wrong_dts; ///< wrong dts due to negative cts
57  struct {
58  int64_t dts;
59  int64_t pos;
60  } validate_index[2];
64 
66 
69 
72  int64_t video_bit_rate;
73  int64_t audio_bit_rate;
74  int64_t *keyframe_times;
78  int64_t last_ts;
79  int64_t time_offset;
80  int64_t time_pos;
81 } FLVContext;
82 
83 /* AMF date type */
84 typedef struct amf_date {
85  double milliseconds;
86  int16_t timezone;
87 } amf_date;
88 
89 static int probe(const AVProbeData *p, int live)
90 {
91  const uint8_t *d = p->buf;
92  unsigned offset = AV_RB32(d + 5);
93 
94  if (d[0] == 'F' &&
95  d[1] == 'L' &&
96  d[2] == 'V' &&
97  d[3] < 5 && d[5] == 0 &&
98  offset + 100 < p->buf_size &&
99  offset > 8) {
100  int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
101 
102  if (live == is_live)
103  return AVPROBE_SCORE_MAX;
104  }
105  return 0;
106 }
107 
108 static int flv_probe(const AVProbeData *p)
109 {
110  return probe(p, 0);
111 }
112 
113 static int live_flv_probe(const AVProbeData *p)
114 {
115  return probe(p, 1);
116 }
117 
118 static int kux_probe(const AVProbeData *p)
119 {
120  const uint8_t *d = p->buf;
121 
122  if (d[0] == 'K' &&
123  d[1] == 'D' &&
124  d[2] == 'K' &&
125  d[3] == 0 &&
126  d[4] == 0) {
127  return AVPROBE_SCORE_EXTENSION + 1;
128  }
129  return 0;
130 }
131 
133 {
134  FLVContext *flv = s->priv_data;
135  AVStream *stream = NULL;
136  unsigned int i = 0;
137 
138  if (flv->last_keyframe_stream_index < 0) {
139  av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
140  return;
141  }
142 
143  av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
144  stream = s->streams[flv->last_keyframe_stream_index];
145 
146  if (ffstream(stream)->nb_index_entries == 0) {
147  for (i = 0; i < flv->keyframe_count; i++) {
148  av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
149  flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
151  flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME);
152  }
153  } else
154  av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
155 
156  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
157  av_freep(&flv->keyframe_times);
159  flv->keyframe_count = 0;
160  }
161 }
162 
164 {
165  FLVContext *flv = s->priv_data;
167  if (!st)
168  return NULL;
170  if (s->nb_streams>=3 ||( s->nb_streams==2
171  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
172  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
173  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
174  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
175  s->ctx_flags &= ~AVFMTCTX_NOHEADER;
177  st->codecpar->bit_rate = flv->audio_bit_rate;
179  }
181  st->codecpar->bit_rate = flv->video_bit_rate;
183  st->avg_frame_rate = flv->framerate;
184  }
185 
186 
187  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
188  flv->last_keyframe_stream_index = s->nb_streams - 1;
190  return st;
191 }
192 
194 {
195  int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
196  int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
197  int codec_id;
198 
199  if (!apar->codec_id && !apar->codec_tag)
200  return 1;
201 
202  if (apar->bits_per_coded_sample != bits_per_coded_sample)
203  return 0;
204 
205  switch (flv_codecid) {
206  // no distinction between S16 and S8 PCM codec flags
207  case FLV_CODECID_PCM:
208  codec_id = bits_per_coded_sample == 8
210 #if HAVE_BIGENDIAN
212 #else
214 #endif
215  return codec_id == apar->codec_id;
216  case FLV_CODECID_PCM_LE:
217  codec_id = bits_per_coded_sample == 8
220  return codec_id == apar->codec_id;
221  case FLV_CODECID_AAC:
222  return apar->codec_id == AV_CODEC_ID_AAC;
223  case FLV_CODECID_ADPCM:
224  return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
225  case FLV_CODECID_SPEEX:
226  return apar->codec_id == AV_CODEC_ID_SPEEX;
227  case FLV_CODECID_MP3:
228  return apar->codec_id == AV_CODEC_ID_MP3;
232  return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
234  return apar->sample_rate == 8000 &&
237  return apar->sample_rate == 8000 &&
239  default:
240  return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
241  }
242 }
243 
245  AVCodecParameters *apar, int flv_codecid)
246 {
247  switch (flv_codecid) {
248  // no distinction between S16 and S8 PCM codec flags
249  case FLV_CODECID_PCM:
250  apar->codec_id = apar->bits_per_coded_sample == 8
252 #if HAVE_BIGENDIAN
254 #else
256 #endif
257  break;
258  case FLV_CODECID_PCM_LE:
259  apar->codec_id = apar->bits_per_coded_sample == 8
262  break;
263  case FLV_CODECID_AAC:
264  apar->codec_id = AV_CODEC_ID_AAC;
265  break;
266  case FLV_CODECID_ADPCM:
268  break;
269  case FLV_CODECID_SPEEX:
270  apar->codec_id = AV_CODEC_ID_SPEEX;
271  apar->sample_rate = 16000;
272  break;
273  case FLV_CODECID_MP3:
274  apar->codec_id = AV_CODEC_ID_MP3;
276  break;
278  // in case metadata does not otherwise declare samplerate
279  apar->sample_rate = 8000;
281  break;
283  apar->sample_rate = 16000;
285  break;
288  break;
290  apar->sample_rate = 8000;
292  break;
294  apar->sample_rate = 8000;
296  break;
297  default:
298  avpriv_request_sample(s, "Audio codec (%x)",
299  flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
300  apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
301  }
302 }
303 
305 {
306  int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
307 
308  if (!vpar->codec_id && !vpar->codec_tag)
309  return 1;
310 
311  switch (flv_codecid) {
312  case FLV_CODECID_H263:
313  return vpar->codec_id == AV_CODEC_ID_FLV1;
314  case FLV_CODECID_SCREEN:
315  return vpar->codec_id == AV_CODEC_ID_FLASHSV;
316  case FLV_CODECID_SCREEN2:
317  return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
318  case FLV_CODECID_VP6:
319  return vpar->codec_id == AV_CODEC_ID_VP6F;
320  case FLV_CODECID_VP6A:
321  return vpar->codec_id == AV_CODEC_ID_VP6A;
322  case FLV_CODECID_H264:
323  return vpar->codec_id == AV_CODEC_ID_H264;
324  default:
325  return vpar->codec_tag == flv_codecid;
326  }
327 }
328 
330  int flv_codecid, int read)
331 {
332  FFStream *const vstreami = ffstream(vstream);
333  int ret = 0;
334  AVCodecParameters *par = vstream->codecpar;
335  enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
336  switch (flv_codecid) {
337  case FLV_CODECID_H263:
338  par->codec_id = AV_CODEC_ID_FLV1;
339  break;
341  par->codec_id = AV_CODEC_ID_H263;
342  break; // Really mean it this time
343  case FLV_CODECID_SCREEN:
345  break;
346  case FLV_CODECID_SCREEN2:
348  break;
349  case FLV_CODECID_VP6:
350  par->codec_id = AV_CODEC_ID_VP6F;
351  case FLV_CODECID_VP6A:
352  if (flv_codecid == FLV_CODECID_VP6A)
353  par->codec_id = AV_CODEC_ID_VP6A;
354  if (read) {
355  if (par->extradata_size != 1) {
356  ff_alloc_extradata(par, 1);
357  }
358  if (par->extradata)
359  par->extradata[0] = avio_r8(s->pb);
360  else
361  avio_skip(s->pb, 1);
362  }
363  ret = 1; // 1 byte body size adjustment for flv_read_packet()
364  break;
365  case FLV_CODECID_H264:
366  par->codec_id = AV_CODEC_ID_H264;
368  ret = 3; // not 4, reading packet type will consume one byte
369  break;
370  case FLV_CODECID_MPEG4:
372  ret = 3;
373  break;
374  default:
375  avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
376  par->codec_tag = flv_codecid;
377  }
378 
379  if (!vstreami->need_context_update && par->codec_id != old_codec_id) {
380  avpriv_request_sample(s, "Changing the codec id midstream");
381  return AVERROR_PATCHWELCOME;
382  }
383 
384  return ret;
385 }
386 
387 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
388 {
389  int ret;
390  int length = avio_rb16(ioc);
391  if (length >= buffsize) {
392  avio_skip(ioc, length);
393  return -1;
394  }
395 
396  ret = avio_read(ioc, buffer, length);
397  if (ret < 0)
398  return ret;
399  if (ret < length)
400  return AVERROR_INVALIDDATA;
401 
402  buffer[length] = '\0';
403 
404  return length;
405 }
406 
408 {
409  FLVContext *flv = s->priv_data;
410  unsigned int timeslen = 0, fileposlen = 0, i;
411  char str_val[256];
412  int64_t *times = NULL;
413  int64_t *filepositions = NULL;
414  int ret = AVERROR(ENOSYS);
415  int64_t initial_pos = avio_tell(ioc);
416 
417  if (flv->keyframe_count > 0) {
418  av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
419  return 0;
420  }
421  av_assert0(!flv->keyframe_times);
423 
424  if (s->flags & AVFMT_FLAG_IGNIDX)
425  return 0;
426 
427  while (avio_tell(ioc) < max_pos - 2 &&
428  amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
429  int64_t **current_array;
430  unsigned int arraylen;
431 
432  // Expect array object in context
433  if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
434  break;
435 
436  arraylen = avio_rb32(ioc);
437  if (arraylen>>28)
438  break;
439 
440  if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
441  current_array = &times;
442  timeslen = arraylen;
443  } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
444  !filepositions) {
445  current_array = &filepositions;
446  fileposlen = arraylen;
447  } else
448  // unexpected metatag inside keyframes, will not use such
449  // metadata for indexing
450  break;
451 
452  if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
453  ret = AVERROR(ENOMEM);
454  goto finish;
455  }
456 
457  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
458  double d;
459  if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
460  goto invalid;
461  d = av_int2double(avio_rb64(ioc));
462  if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
463  goto invalid;
464  if (current_array == &times && (d <= INT64_MIN / 1000 || d >= INT64_MAX / 1000))
465  goto invalid;
466  if (avio_feof(ioc))
467  goto invalid;
468  current_array[0][i] = d;
469  }
470  if (times && filepositions) {
471  // All done, exiting at a position allowing amf_parse_object
472  // to finish parsing the object
473  ret = 0;
474  break;
475  }
476  }
477 
478  if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
479  for (i = 0; i < FFMIN(2,fileposlen); i++) {
480  flv->validate_index[i].pos = filepositions[i];
481  flv->validate_index[i].dts = times[i] * 1000;
482  flv->validate_count = i + 1;
483  }
484  flv->keyframe_times = times;
485  flv->keyframe_filepositions = filepositions;
486  flv->keyframe_count = timeslen;
487  times = NULL;
488  filepositions = NULL;
489  } else {
490 invalid:
491  av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
492  }
493 
494 finish:
495  av_freep(&times);
496  av_freep(&filepositions);
497  avio_seek(ioc, initial_pos, SEEK_SET);
498  return ret;
499 }
500 
502  AVStream *vstream, const char *key,
503  int64_t max_pos, int depth)
504 {
505  AVCodecParameters *apar, *vpar;
506  FLVContext *flv = s->priv_data;
507  AVIOContext *ioc;
508  AMFDataType amf_type;
509  char str_val[1024];
510  double num_val;
511  amf_date date;
512 
513  if (depth > MAX_DEPTH)
514  return AVERROR_PATCHWELCOME;
515 
516  num_val = 0;
517  ioc = s->pb;
518  if (avio_feof(ioc))
519  return AVERROR_EOF;
520  amf_type = avio_r8(ioc);
521 
522  switch (amf_type) {
524  num_val = av_int2double(avio_rb64(ioc));
525  break;
526  case AMF_DATA_TYPE_BOOL:
527  num_val = avio_r8(ioc);
528  break;
530  if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
531  av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
532  return -1;
533  }
534  break;
536  if (key &&
537  (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
538  !strcmp(KEYFRAMES_TAG, key) && depth == 1)
539  if (parse_keyframes_index(s, ioc, max_pos) < 0)
540  av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
541  else
543  while (avio_tell(ioc) < max_pos - 2 &&
544  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
545  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
546  depth + 1) < 0)
547  return -1; // if we couldn't skip, bomb out.
548  if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
549  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
550  return -1;
551  }
552  break;
553  case AMF_DATA_TYPE_NULL:
556  break; // these take up no additional space
558  {
559  unsigned v;
560  avio_skip(ioc, 4); // skip 32-bit max array index
561  while (avio_tell(ioc) < max_pos - 2 &&
562  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
563  // this is the only case in which we would want a nested
564  // parse to not skip over the object
565  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
566  depth + 1) < 0)
567  return -1;
568  v = avio_r8(ioc);
569  if (v != AMF_END_OF_OBJECT) {
570  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
571  return -1;
572  }
573  break;
574  }
575  case AMF_DATA_TYPE_ARRAY:
576  {
577  unsigned int arraylen, i;
578 
579  arraylen = avio_rb32(ioc);
580  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
582  depth + 1) < 0)
583  return -1; // if we couldn't skip, bomb out.
584  }
585  break;
586  case AMF_DATA_TYPE_DATE:
587  // timestamp (double) and UTC offset (int16)
588  date.milliseconds = av_int2double(avio_rb64(ioc));
589  date.timezone = avio_rb16(ioc);
590  break;
591  default: // unsupported type, we couldn't skip
592  av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
593  return -1;
594  }
595 
596  if (key) {
597  apar = astream ? astream->codecpar : NULL;
598  vpar = vstream ? vstream->codecpar : NULL;
599 
600  // stream info doesn't live any deeper than the first object
601  if (depth == 1) {
602  if (amf_type == AMF_DATA_TYPE_NUMBER ||
603  amf_type == AMF_DATA_TYPE_BOOL) {
604  if (!strcmp(key, "duration"))
605  s->duration = num_val * AV_TIME_BASE;
606  else if (!strcmp(key, "videodatarate") &&
607  0 <= (int)(num_val * 1024.0))
608  flv->video_bit_rate = num_val * 1024.0;
609  else if (!strcmp(key, "audiodatarate") &&
610  0 <= (int)(num_val * 1024.0))
611  flv->audio_bit_rate = num_val * 1024.0;
612  else if (!strcmp(key, "datastream")) {
614  if (!st)
615  return AVERROR(ENOMEM);
617  } else if (!strcmp(key, "framerate")) {
618  flv->framerate = av_d2q(num_val, 1000);
619  if (vstream)
620  vstream->avg_frame_rate = flv->framerate;
621  } else if (flv->trust_metadata) {
622  if (!strcmp(key, "videocodecid") && vpar) {
623  int ret = flv_set_video_codec(s, vstream, num_val, 0);
624  if (ret < 0)
625  return ret;
626  } else if (!strcmp(key, "audiocodecid") && apar) {
627  int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
628  flv_set_audio_codec(s, astream, apar, id);
629  } else if (!strcmp(key, "audiosamplerate") && apar) {
630  apar->sample_rate = num_val;
631  } else if (!strcmp(key, "audiosamplesize") && apar) {
632  apar->bits_per_coded_sample = num_val;
633  } else if (!strcmp(key, "stereo") && apar) {
634  av_channel_layout_default(&apar->ch_layout, num_val + 1);
635  } else if (!strcmp(key, "width") && vpar) {
636  vpar->width = num_val;
637  } else if (!strcmp(key, "height") && vpar) {
638  vpar->height = num_val;
639  }
640  }
641  }
642  if (amf_type == AMF_DATA_TYPE_STRING) {
643  if (!strcmp(key, "encoder")) {
644  int version = -1;
645  if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
646  if (version > 0 && version <= 655)
647  flv->broken_sizes = 1;
648  }
649  } else if (!strcmp(key, "metadatacreator")) {
650  if ( !strcmp (str_val, "MEGA")
651  || !strncmp(str_val, "FlixEngine", 10))
652  flv->broken_sizes = 1;
653  }
654  }
655  }
656 
657  if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
658  ((!apar && !strcmp(key, "audiocodecid")) ||
659  (!vpar && !strcmp(key, "videocodecid"))))
660  s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
661 
662  if ((!strcmp(key, "duration") ||
663  !strcmp(key, "filesize") ||
664  !strcmp(key, "width") ||
665  !strcmp(key, "height") ||
666  !strcmp(key, "videodatarate") ||
667  !strcmp(key, "framerate") ||
668  !strcmp(key, "videocodecid") ||
669  !strcmp(key, "audiodatarate") ||
670  !strcmp(key, "audiosamplerate") ||
671  !strcmp(key, "audiosamplesize") ||
672  !strcmp(key, "stereo") ||
673  !strcmp(key, "audiocodecid") ||
674  !strcmp(key, "datastream")) && !flv->dump_full_metadata)
675  return 0;
676 
677  s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
678  if (amf_type == AMF_DATA_TYPE_BOOL) {
679  av_strlcpy(str_val, num_val > 0 ? "true" : "false",
680  sizeof(str_val));
681  av_dict_set(&s->metadata, key, str_val, 0);
682  } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
683  snprintf(str_val, sizeof(str_val), "%.f", num_val);
684  av_dict_set(&s->metadata, key, str_val, 0);
685  } else if (amf_type == AMF_DATA_TYPE_STRING) {
686  av_dict_set(&s->metadata, key, str_val, 0);
687  } else if ( amf_type == AMF_DATA_TYPE_DATE
688  && isfinite(date.milliseconds)
689  && date.milliseconds > INT64_MIN/1000
690  && date.milliseconds < INT64_MAX/1000
691  ) {
692  // timezone is ignored, since there is no easy way to offset the UTC
693  // timestamp into the specified timezone
694  avpriv_dict_set_timestamp(&s->metadata, key, 1000 * (int64_t)date.milliseconds);
695  }
696  }
697 
698  return 0;
699 }
700 
701 #define TYPE_ONTEXTDATA 1
702 #define TYPE_ONCAPTION 2
703 #define TYPE_ONCAPTIONINFO 3
704 #define TYPE_UNKNOWN 9
705 
706 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
707 {
708  FLVContext *flv = s->priv_data;
710  AVStream *stream, *astream, *vstream;
711  AVStream av_unused *dstream;
712  AVIOContext *ioc;
713  int i;
714  char buffer[32];
715 
716  astream = NULL;
717  vstream = NULL;
718  dstream = NULL;
719  ioc = s->pb;
720 
721  // first object needs to be "onMetaData" string
722  type = avio_r8(ioc);
723  if (type != AMF_DATA_TYPE_STRING ||
724  amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
725  return TYPE_UNKNOWN;
726 
727  if (!strcmp(buffer, "onTextData"))
728  return TYPE_ONTEXTDATA;
729 
730  if (!strcmp(buffer, "onCaption"))
731  return TYPE_ONCAPTION;
732 
733  if (!strcmp(buffer, "onCaptionInfo"))
734  return TYPE_ONCAPTIONINFO;
735 
736  if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint") && strcmp(buffer, "|RtmpSampleAccess")) {
737  av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
738  return TYPE_UNKNOWN;
739  }
740 
741  // find the streams now so that amf_parse_object doesn't need to do
742  // the lookup every time it is called.
743  for (i = 0; i < s->nb_streams; i++) {
744  stream = s->streams[i];
745  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
746  vstream = stream;
748  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
749  astream = stream;
750  if (flv->last_keyframe_stream_index == -1)
752  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
753  dstream = stream;
754  }
755 
756  // parse the second object (we want a mixed array)
757  if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
758  return -1;
759 
760  return 0;
761 }
762 
764 {
765  int flags;
766  FLVContext *flv = s->priv_data;
767  int offset;
768  int pre_tag_size = 0;
769 
770  /* Actual FLV data at 0xe40000 in KUX file */
771  if(!strcmp(s->iformat->name, "kux"))
772  avio_skip(s->pb, 0xe40000);
773 
774  avio_skip(s->pb, 4);
775  flags = avio_r8(s->pb);
776 
778 
779  s->ctx_flags |= AVFMTCTX_NOHEADER;
780 
781  offset = avio_rb32(s->pb);
782  avio_seek(s->pb, offset, SEEK_SET);
783 
784  /* Annex E. The FLV File Format
785  * E.3 TheFLVFileBody
786  * Field Type Comment
787  * PreviousTagSize0 UI32 Always 0
788  * */
789  pre_tag_size = avio_rb32(s->pb);
790  if (pre_tag_size) {
791  av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
792  }
793 
794  s->start_time = 0;
795  flv->sum_flv_tag_size = 0;
796  flv->last_keyframe_stream_index = -1;
797 
798  return 0;
799 }
800 
802 {
803  int i;
804  FLVContext *flv = s->priv_data;
805  for (i=0; i<FLV_STREAM_TYPE_NB; i++)
806  av_freep(&flv->new_extradata[i]);
807  av_freep(&flv->keyframe_times);
809  return 0;
810 }
811 
813 {
814  int ret;
815  if (!size)
816  return 0;
817 
818  if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
819  return ret;
820  ffstream(st)->need_context_update = 1;
821  return 0;
822 }
823 
824 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
825  int size)
826 {
827  if (!size)
828  return 0;
829 
830  av_free(flv->new_extradata[stream]);
831  flv->new_extradata[stream] = av_mallocz(size +
833  if (!flv->new_extradata[stream])
834  return AVERROR(ENOMEM);
835  flv->new_extradata_size[stream] = size;
836  avio_read(pb, flv->new_extradata[stream], size);
837  return 0;
838 }
839 
840 static void clear_index_entries(AVFormatContext *s, int64_t pos)
841 {
843  "Found invalid index entries, clearing the index.\n");
844  for (unsigned i = 0; i < s->nb_streams; i++) {
845  FFStream *const sti = ffstream(s->streams[i]);
846  int out = 0;
847  /* Remove all index entries that point to >= pos */
848  for (int j = 0; j < sti->nb_index_entries; j++)
849  if (sti->index_entries[j].pos < pos)
850  sti->index_entries[out++] = sti->index_entries[j];
851  sti->nb_index_entries = out;
852  }
853 }
854 
855 static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
856 {
857  int nb = -1, ret, parse_name = 1;
858 
859  if (depth > MAX_DEPTH)
860  return AVERROR_PATCHWELCOME;
861 
862  if (avio_feof(pb))
863  return AVERROR_EOF;
864 
865  switch (type) {
867  avio_skip(pb, 8);
868  break;
869  case AMF_DATA_TYPE_BOOL:
870  avio_skip(pb, 1);
871  break;
873  avio_skip(pb, avio_rb16(pb));
874  break;
875  case AMF_DATA_TYPE_ARRAY:
876  parse_name = 0;
878  nb = avio_rb32(pb);
879  if (nb < 0)
880  return AVERROR_INVALIDDATA;
882  while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
883  if (parse_name) {
884  int size = avio_rb16(pb);
885  if (!size) {
886  avio_skip(pb, 1);
887  break;
888  }
889  avio_skip(pb, size);
890  }
891  if ((ret = amf_skip_tag(pb, avio_r8(pb), depth + 1)) < 0)
892  return ret;
893  }
894  break;
895  case AMF_DATA_TYPE_NULL:
897  break;
898  default:
899  return AVERROR_INVALIDDATA;
900  }
901  return 0;
902 }
903 
905  int64_t dts, int64_t next)
906 {
907  AVIOContext *pb = s->pb;
908  AVStream *st = NULL;
909  char buf[20];
910  int ret = AVERROR_INVALIDDATA;
911  int i, length = -1;
912  int array = 0;
913 
914  switch (avio_r8(pb)) {
915  case AMF_DATA_TYPE_ARRAY:
916  array = 1;
918  avio_seek(pb, 4, SEEK_CUR);
920  break;
921  default:
922  goto skip;
923  }
924 
925  while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
926  AMFDataType type = avio_r8(pb);
927  if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
928  length = avio_rb16(pb);
929  ret = av_get_packet(pb, pkt, length);
930  if (ret < 0)
931  goto skip;
932  else
933  break;
934  } else {
935  if ((ret = amf_skip_tag(pb, type, 0)) < 0)
936  goto skip;
937  }
938  }
939 
940  if (length < 0) {
942  goto skip;
943  }
944 
945  for (i = 0; i < s->nb_streams; i++) {
946  st = s->streams[i];
948  break;
949  }
950 
951  if (i == s->nb_streams) {
953  if (!st)
954  return AVERROR(ENOMEM);
956  }
957 
958  pkt->dts = dts;
959  pkt->pts = dts;
960  pkt->size = ret;
961 
962  pkt->stream_index = st->index;
964 
965 skip:
966  avio_seek(s->pb, next + 4, SEEK_SET);
967 
968  return ret;
969 }
970 
972 {
973  FLVContext *flv = s->priv_data;
974  int64_t i;
975  int64_t pos = avio_tell(s->pb);
976 
977  for (i=0; !avio_feof(s->pb); i++) {
978  int j = i & (RESYNC_BUFFER_SIZE-1);
979  int j1 = j + RESYNC_BUFFER_SIZE;
980  flv->resync_buffer[j ] =
981  flv->resync_buffer[j1] = avio_r8(s->pb);
982 
983  if (i >= 8 && pos) {
984  uint8_t *d = flv->resync_buffer + j1 - 8;
985  if (d[0] == 'F' &&
986  d[1] == 'L' &&
987  d[2] == 'V' &&
988  d[3] < 5 && d[5] == 0) {
989  av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
990  flv->time_offset = flv->last_ts + 1;
991  flv->time_pos = avio_tell(s->pb);
992  }
993  }
994 
995  if (i > 22) {
996  unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
997  if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
998  unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
999  unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
1000  if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1001  unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
1002  if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
1003  avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
1004  return 1;
1005  }
1006  }
1007  }
1008  }
1009  }
1010  return AVERROR_EOF;
1011 }
1012 
1014 {
1015  FLVContext *flv = s->priv_data;
1016  int ret, i, size, flags;
1017  enum FlvTagType type;
1018  int stream_type=-1;
1019  int64_t next, pos, meta_pos;
1020  int64_t dts, pts = AV_NOPTS_VALUE;
1021  int av_uninit(channels);
1022  int av_uninit(sample_rate);
1023  AVStream *st = NULL;
1024  int last = -1;
1025  int orig_size;
1026 
1027 retry:
1028  /* pkt size is repeated at end. skip it */
1029  pos = avio_tell(s->pb);
1030  type = (avio_r8(s->pb) & 0x1F);
1031  orig_size =
1032  size = avio_rb24(s->pb);
1033  flv->sum_flv_tag_size += size + 11;
1034  dts = avio_rb24(s->pb);
1035  dts |= (unsigned)avio_r8(s->pb) << 24;
1036  av_log(s, AV_LOG_TRACE, "type:%d, size:%d, last:%d, dts:%"PRId64" pos:%"PRId64"\n", type, size, last, dts, avio_tell(s->pb));
1037  if (avio_feof(s->pb))
1038  return AVERROR_EOF;
1039  avio_skip(s->pb, 3); /* stream id, always 0 */
1040  flags = 0;
1041 
1042  if (flv->validate_next < flv->validate_count) {
1043  int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1044  if (pos == validate_pos) {
1045  if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1047  flv->validate_next++;
1048  } else {
1049  clear_index_entries(s, validate_pos);
1050  flv->validate_count = 0;
1051  }
1052  } else if (pos > validate_pos) {
1053  clear_index_entries(s, validate_pos);
1054  flv->validate_count = 0;
1055  }
1056  }
1057 
1058  if (size == 0) {
1059  ret = FFERROR_REDO;
1060  goto leave;
1061  }
1062 
1063  next = size + avio_tell(s->pb);
1064 
1065  if (type == FLV_TAG_TYPE_AUDIO) {
1066  stream_type = FLV_STREAM_TYPE_AUDIO;
1067  flags = avio_r8(s->pb);
1068  size--;
1069  } else if (type == FLV_TAG_TYPE_VIDEO) {
1070  stream_type = FLV_STREAM_TYPE_VIDEO;
1071  flags = avio_r8(s->pb);
1072  size--;
1074  goto skip;
1075  } else if (type == FLV_TAG_TYPE_META) {
1076  stream_type=FLV_STREAM_TYPE_SUBTITLE;
1077  if (size > 13 + 1 + 4) { // Header-type metadata stuff
1078  int type;
1079  meta_pos = avio_tell(s->pb);
1080  type = flv_read_metabody(s, next);
1081  if (type == 0 && dts == 0 || type < 0) {
1082  if (type < 0 && flv->validate_count &&
1083  flv->validate_index[0].pos > next &&
1084  flv->validate_index[0].pos - 4 < next) {
1085  av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1086  next = flv->validate_index[0].pos - 4;
1087  }
1088  goto skip;
1089  } else if (type == TYPE_ONTEXTDATA) {
1090  avpriv_request_sample(s, "OnTextData packet");
1091  return flv_data_packet(s, pkt, dts, next);
1092  } else if (type == TYPE_ONCAPTION) {
1093  return flv_data_packet(s, pkt, dts, next);
1094  } else if (type == TYPE_UNKNOWN) {
1095  stream_type = FLV_STREAM_TYPE_DATA;
1096  }
1097  avio_seek(s->pb, meta_pos, SEEK_SET);
1098  }
1099  } else {
1101  "Skipping flv packet: type %d, size %d, flags %d.\n",
1102  type, size, flags);
1103 skip:
1104  if (avio_seek(s->pb, next, SEEK_SET) != next) {
1105  // This can happen if flv_read_metabody above read past
1106  // next, on a non-seekable input, and the preceding data has
1107  // been flushed out from the IO buffer.
1108  av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1109  return AVERROR_INVALIDDATA;
1110  }
1111  ret = FFERROR_REDO;
1112  goto leave;
1113  }
1114 
1115  /* skip empty data packets */
1116  if (!size) {
1117  ret = FFERROR_REDO;
1118  goto leave;
1119  }
1120 
1121  /* now find stream */
1122  for (i = 0; i < s->nb_streams; i++) {
1123  st = s->streams[i];
1124  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1125  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1126  (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags)))
1127  break;
1128  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1129  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1130  (s->video_codec_id || flv_same_video_codec(st->codecpar, flags)))
1131  break;
1132  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1134  break;
1135  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1137  break;
1138  }
1139  }
1140  if (i == s->nb_streams) {
1142  st = create_stream(s, stream_types[stream_type]);
1143  if (!st)
1144  return AVERROR(ENOMEM);
1145  }
1146  av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1147 
1148  if (flv->time_pos <= pos) {
1149  dts += flv->time_offset;
1150  }
1151 
1152  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1154  stream_type == FLV_STREAM_TYPE_AUDIO))
1156 
1157  if ((st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || stream_type == FLV_STREAM_TYPE_AUDIO)) ||
1159  st->discard >= AVDISCARD_ALL) {
1160  avio_seek(s->pb, next, SEEK_SET);
1161  ret = FFERROR_REDO;
1162  goto leave;
1163  }
1164 
1165  // if not streamed and no duration from metadata then seek to end to find
1166  // the duration from the timestamps
1167  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1168  (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1169  !flv->searched_for_end) {
1170  int size;
1171  const int64_t pos = avio_tell(s->pb);
1172  // Read the last 4 bytes of the file, this should be the size of the
1173  // previous FLV tag. Use the timestamp of its payload as duration.
1174  int64_t fsize = avio_size(s->pb);
1175 retry_duration:
1176  avio_seek(s->pb, fsize - 4, SEEK_SET);
1177  size = avio_rb32(s->pb);
1178  if (size > 0 && size < fsize) {
1179  // Seek to the start of the last FLV tag at position (fsize - 4 - size)
1180  // but skip the byte indicating the type.
1181  avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
1182  if (size == avio_rb24(s->pb) + 11) {
1183  uint32_t ts = avio_rb24(s->pb);
1184  ts |= (unsigned)avio_r8(s->pb) << 24;
1185  if (ts)
1186  s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1187  else if (fsize >= 8 && fsize - 8 >= size) {
1188  fsize -= size+4;
1189  goto retry_duration;
1190  }
1191  }
1192  }
1193 
1194  avio_seek(s->pb, pos, SEEK_SET);
1195  flv->searched_for_end = 1;
1196  }
1197 
1198  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1199  int bits_per_coded_sample;
1201  sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1203  bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1205  !st->codecpar->sample_rate ||
1209  st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1210  }
1211  if (!st->codecpar->codec_id) {
1212  flv_set_audio_codec(s, st, st->codecpar,
1214  flv->last_sample_rate =
1216  flv->last_channels =
1218  } else {
1220  if (!par) {
1221  ret = AVERROR(ENOMEM);
1222  goto leave;
1223  }
1224  par->sample_rate = sample_rate;
1225  par->bits_per_coded_sample = bits_per_coded_sample;
1227  sample_rate = par->sample_rate;
1229  }
1230  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1232  if (ret < 0)
1233  return ret;
1234  size -= ret;
1235  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1237  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1238  st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1239  }
1240 
1241  if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1244  int type = avio_r8(s->pb);
1245  size--;
1246 
1247  if (size < 0) {
1249  goto leave;
1250  }
1251 
1253  // sign extension
1254  int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1255  pts = av_sat_add64(dts, cts);
1256  if (cts < 0) { // dts might be wrong
1257  if (!flv->wrong_dts)
1259  "Negative cts, previous timestamps might be wrong.\n");
1260  flv->wrong_dts = 1;
1261  } else if (FFABS(dts - pts) > 1000*60*15) {
1263  "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1264  dts = pts = AV_NOPTS_VALUE;
1265  }
1266  }
1267  if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1268  st->codecpar->codec_id == AV_CODEC_ID_H264)) {
1269  AVDictionaryEntry *t;
1270 
1271  if (st->codecpar->extradata) {
1272  if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
1273  return ret;
1274  ret = FFERROR_REDO;
1275  goto leave;
1276  }
1277  if ((ret = flv_get_extradata(s, st, size)) < 0)
1278  return ret;
1279 
1280  /* Workaround for buggy Omnia A/XE encoder */
1281  t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1282  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1283  st->codecpar->extradata_size = 2;
1284 
1285  ret = FFERROR_REDO;
1286  goto leave;
1287  }
1288  }
1289 
1290  /* skip empty data packets */
1291  if (!size) {
1292  ret = FFERROR_REDO;
1293  goto leave;
1294  }
1295 
1296  ret = av_get_packet(s->pb, pkt, size);
1297  if (ret < 0)
1298  return ret;
1299  pkt->dts = dts;
1300  pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1301  pkt->stream_index = st->index;
1302  pkt->pos = pos;
1303  if (flv->new_extradata[stream_type]) {
1305  flv->new_extradata[stream_type],
1306  flv->new_extradata_size[stream_type]);
1307  if (ret >= 0) {
1308  flv->new_extradata[stream_type] = NULL;
1309  flv->new_extradata_size[stream_type] = 0;
1310  }
1311  }
1312  if (stream_type == FLV_STREAM_TYPE_AUDIO &&
1313  (sample_rate != flv->last_sample_rate ||
1314  channels != flv->last_channels)) {
1316  flv->last_channels = channels;
1318  }
1319 
1320  if (stream_type == FLV_STREAM_TYPE_AUDIO ||
1322  stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1323  stream_type == FLV_STREAM_TYPE_DATA)
1325 
1326 leave:
1327  last = avio_rb32(s->pb);
1328  if (!flv->trust_datasize) {
1329  if (last != orig_size + 11 && last != orig_size + 10 &&
1330  !avio_feof(s->pb) &&
1331  (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1332  !flv->broken_sizes) {
1333  av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %d\n", last, orig_size + 11, flv->sum_flv_tag_size);
1334  avio_seek(s->pb, pos + 1, SEEK_SET);
1335  ret = resync(s);
1337  if (ret >= 0) {
1338  goto retry;
1339  }
1340  }
1341  }
1342 
1343  if (ret >= 0)
1344  flv->last_ts = pkt->dts;
1345 
1346  return ret;
1347 }
1348 
1349 static int flv_read_seek(AVFormatContext *s, int stream_index,
1350  int64_t ts, int flags)
1351 {
1352  FLVContext *flv = s->priv_data;
1353  flv->validate_count = 0;
1354  return avio_seek_time(s->pb, stream_index, ts, flags);
1355 }
1356 
1357 #define OFFSET(x) offsetof(FLVContext, x)
1358 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1359 static const AVOption options[] = {
1360  { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1361  { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1362  { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1363  { "missing_streams", "", OFFSET(missing_streams), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xFF, VD | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
1364  { NULL }
1365 };
1366 
1367 static const AVClass flv_kux_class = {
1368  .class_name = "(live) flv/kux demuxer",
1369  .item_name = av_default_item_name,
1370  .option = options,
1371  .version = LIBAVUTIL_VERSION_INT,
1372 };
1373 
1375  .name = "flv",
1376  .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1377  .priv_data_size = sizeof(FLVContext),
1378  .read_probe = flv_probe,
1383  .extensions = "flv",
1384  .priv_class = &flv_kux_class,
1385 };
1386 
1388  .name = "live_flv",
1389  .long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1390  .priv_data_size = sizeof(FLVContext),
1396  .extensions = "flv",
1397  .priv_class = &flv_kux_class,
1399 };
1400 
1402  .name = "kux",
1403  .long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1404  .priv_data_size = sizeof(FLVContext),
1405  .read_probe = kux_probe,
1410  .extensions = "kux",
1411  .priv_class = &flv_kux_class,
1412 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:318
FLVContext::audio_bit_rate
int64_t audio_bit_rate
Definition: flvdec.c:73
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
AMF_DATA_TYPE_OBJECT_END
@ AMF_DATA_TYPE_OBJECT_END
Definition: flv.h:132
AMF_END_OF_OBJECT
#define AMF_END_OF_OBJECT
Definition: flv.h:47
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_CODEC_ID_VP6F
@ AV_CODEC_ID_VP6F
Definition: codec_id.h:142
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:75
flv_same_video_codec
static int flv_same_video_codec(AVCodecParameters *vpar, int flags)
Definition: flvdec.c:304
FLV_TAG_TYPE_VIDEO
@ FLV_TAG_TYPE_VIDEO
Definition: flv.h:61
FLVContext::pos
int64_t pos
Definition: flvdec.c:59
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
AV_OPT_FLAG_READONLY
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:294
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
clear_index_entries
static void clear_index_entries(AVFormatContext *s, int64_t pos)
Definition: flvdec.c:840
FLVContext::validate_next
int validate_next
Definition: flvdec.c:61
out
FILE * out
Definition: movenc.c:54
FLV_CODECID_REALH263
@ FLV_CODECID_REALH263
Definition: flv.h:111
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:53
AVFMT_FLAG_IGNIDX
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1333
FLV_CODECID_VP6A
@ FLV_CODECID_VP6A
Definition: flv.h:108
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
av_int2double
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition: intfloat.h:60
TYPE_ONCAPTIONINFO
#define TYPE_ONCAPTIONINFO
Definition: flvdec.c:703
flv_data_packet
static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, int64_t dts, int64_t next)
Definition: flvdec.c:904
av_unused
#define av_unused
Definition: attributes.h:131
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
FLVContext::time_offset
int64_t time_offset
Definition: flvdec.c:79
FLVContext::trust_metadata
int trust_metadata
configure streams according onMetaData
Definition: flvdec.c:49
flv_read_packet
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: flvdec.c:1013
TYPE_ONCAPTION
#define TYPE_ONCAPTION
Definition: flvdec.c:702
AVOption
AVOption.
Definition: opt.h:251
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:1028
FLVContext::resync_buffer
uint8_t resync_buffer[2 *RESYNC_BUFFER_SIZE]
Definition: flvdec.c:65
amf_date
Definition: flvdec.c:84
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:63
FLV_STREAM_TYPE_DATA
@ FLV_STREAM_TYPE_DATA
Definition: flv.h:69
FLV_FRAME_KEY
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
Definition: flv.h:116
AMF_DATA_TYPE_UNDEFINED
@ AMF_DATA_TYPE_UNDEFINED
Definition: flv.h:129
AMF_DATA_TYPE_DATE
@ AMF_DATA_TYPE_DATE
Definition: flv.h:134
flv_set_audio_codec
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecParameters *apar, int flv_codecid)
Definition: flvdec.c:244
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:65
mathematics.h
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:456
FLV_CODECID_SCREEN
@ FLV_CODECID_SCREEN
Definition: flv.h:106
FLVContext::trust_datasize
int trust_datasize
trust data size of FLVTag
Definition: flvdec.c:50
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
intfloat.h
FLV_CODECID_AAC
@ FLV_CODECID_AAC
Definition: flv.h:100
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
AMF_DATA_TYPE_OBJECT
@ AMF_DATA_TYPE_OBJECT
Definition: flv.h:127
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:352
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
sample_rate
sample_rate
Definition: ffmpeg_filter.c:153
options
static const AVOption options[]
Definition: flvdec.c:1359
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:815
ff_get_extradata
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
Definition: demux_utils.c:355
FLV_STREAM_TYPE_VIDEO
@ FLV_STREAM_TYPE_VIDEO
Definition: flv.h:66
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:465
FLVContext::video_bit_rate
int64_t video_bit_rate
Definition: flvdec.c:72
FLVContext::searched_for_end
int searched_for_end
Definition: flvdec.c:63
FLVContext::keyframe_times
int64_t * keyframe_times
Definition: flvdec.c:74
FLVContext::keyframe_filepositions
int64_t * keyframe_filepositions
Definition: flvdec.c:75
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:697
FLV_STREAM_TYPE_NB
@ FLV_STREAM_TYPE_NB
Definition: flv.h:70
finish
static void finish(void)
Definition: movenc.c:342
OFFSET
#define OFFSET(x)
Definition: flvdec.c:1357
av_packet_add_side_data
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition: avpacket.c:196
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:462
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:407
FLVContext::last_ts
int64_t last_ts
Definition: flvdec.c:78
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:319
avio_seek_time
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:1336
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:151
av_add_index_entry
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: seek.c:118
TYPE_ONTEXTDATA
#define TYPE_ONTEXTDATA
Definition: flvdec.c:701
flv_read_seek
static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags)
Definition: flvdec.c:1349
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:143
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:505
ff_live_flv_demuxer
const AVInputFormat ff_live_flv_demuxer
Definition: flvdec.c:1387
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:654
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:428
FLV_CODECID_MPEG4
@ FLV_CODECID_MPEG4
Definition: flv.h:112
FLV_AUDIO_CODECID_OFFSET
#define FLV_AUDIO_CODECID_OFFSET
Definition: flv.h:34
VD
#define VD
Definition: flvdec.c:1358
avassert.h
AMFDataType
AMFDataType
Definition: flv.h:123
parse_keyframes_index
static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
Definition: flvdec.c:407
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:790
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVInputFormat
Definition: avformat.h:656
VALIDATE_INDEX_TS_THRESH
#define VALIDATE_INDEX_TS_THRESH
Definition: flvdec.c:41
FLVContext::sum_flv_tag_size
int sum_flv_tag_size
Definition: flvdec.c:68
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
FLVContext::new_extradata_size
int new_extradata_size[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:54
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
AMF_DATA_TYPE_UNSUPPORTED
@ AMF_DATA_TYPE_UNSUPPORTED
Definition: flv.h:136
ff_kux_demuxer
const AVInputFormat ff_kux_demuxer
Definition: flvdec.c:1401
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:455
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
create_stream
static AVStream * create_stream(AVFormatContext *s, int codec_type)
Definition: flvdec.c:163
FLVContext::dts
int64_t dts
Definition: flvdec.c:58
FLV_CODECID_PCM_MULAW
@ FLV_CODECID_PCM_MULAW
Definition: flv.h:99
amf_skip_tag
static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
Definition: flvdec.c:855
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
FLV_AUDIO_CHANNEL_MASK
#define FLV_AUDIO_CHANNEL_MASK
Definition: flv.h:39
FLV_CODECID_NELLYMOSER_16KHZ_MONO
@ FLV_CODECID_NELLYMOSER_16KHZ_MONO
Definition: flv.h:95
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
channels
channels
Definition: aptx.h:32
FLVContext::time_pos
int64_t time_pos
Definition: flvdec.c:80
isfinite
#define isfinite(x)
Definition: libm.h:359
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:324
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:371
live_flv_probe
static int live_flv_probe(const AVProbeData *p)
Definition: flvdec.c:113
KEYFRAMES_TIMESTAMP_TAG
#define KEYFRAMES_TIMESTAMP_TAG
Definition: flv.h:50
key
const char * key
Definition: hwcontext_opencl.c:174
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
FLV_VIDEO_FRAMETYPE_MASK
#define FLV_VIDEO_FRAMETYPE_MASK
Definition: flv.h:45
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: defs.h:51
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
TYPE_UNKNOWN
#define TYPE_UNKNOWN
Definition: flvdec.c:704
flv_set_video_codec
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read)
Definition: flvdec.c:329
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:380
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:325
flv_read_close
static int flv_read_close(AVFormatContext *s)
Definition: flvdec.c:801
AV_CODEC_ID_FLASHSV2
@ AV_CODEC_ID_FLASHSV2
Definition: codec_id.h:181
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:532
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
add_keyframes_index
static void add_keyframes_index(AVFormatContext *s)
Definition: flvdec.c:132
NULL
#define NULL
Definition: coverity.c:32
ff_flv_demuxer
const AVInputFormat ff_flv_demuxer
Definition: flvdec.c:1374
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
AVFMTCTX_NOHEADER
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:1164
AMF_DATA_TYPE_BOOL
@ AMF_DATA_TYPE_BOOL
Definition: flv.h:125
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
flv_read_header
static int flv_read_header(AVFormatContext *s)
Definition: flvdec.c:763
FLV_CODECID_ADPCM
@ FLV_CODECID_ADPCM
Definition: flv.h:92
isnan
#define isnan(x)
Definition: libm.h:340
flv_same_audio_codec
static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
Definition: flvdec.c:193
FLV_CODECID_NELLYMOSER_8KHZ_MONO
@ FLV_CODECID_NELLYMOSER_8KHZ_MONO
Definition: flv.h:96
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:937
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:254
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:453
FLVContext::validate_index
struct FLVContext::@261 validate_index[2]
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:960
flv.h
FLVContext::last_channels
int last_channels
Definition: flvdec.c:56
AMF_DATA_TYPE_ARRAY
@ AMF_DATA_TYPE_ARRAY
Definition: flv.h:133
AV_CODEC_ID_FLASHSV
@ AV_CODEC_ID_FLASHSV
Definition: codec_id.h:136
FLVContext::keyframe_count
int keyframe_count
Definition: flvdec.c:71
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:212
AV_CODEC_ID_VP6A
@ AV_CODEC_ID_VP6A
Definition: codec_id.h:156
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:463
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:177
FLVContext::missing_streams
int missing_streams
Definition: flvdec.c:76
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:79
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:429
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:53
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
avio_rb24
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:783
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
KEYFRAMES_BYTEOFFSET_TAG
#define KEYFRAMES_BYTEOFFSET_TAG
Definition: flv.h:51
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:263
FFStream
Definition: internal.h:197
FLV_CODECID_H263
@ FLV_CODECID_H263
Definition: flv.h:105
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:54
AV_CODEC_ID_ADPCM_SWF
@ AV_CODEC_ID_ADPCM_SWF
Definition: codec_id.h:370
size
int size
Definition: twinvq_data.h:10344
ff_add_param_change
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: demux_utils.c:151
FLVContext
Definition: flvdec.c:47
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
FLV_TAG_TYPE_AUDIO
@ FLV_TAG_TYPE_AUDIO
Definition: flv.h:60
MAX_DEPTH
#define MAX_DEPTH
arbitrary limit to prevent unbounded recursion
Definition: flvdec.c:45
amf_date::timezone
int16_t timezone
Definition: flvdec.c:86
KEYFRAMES_TAG
#define KEYFRAMES_TAG
Definition: flv.h:49
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
version
version
Definition: libkvazaar.c:313
FLV_FRAME_VIDEO_INFO_CMD
@ FLV_FRAME_VIDEO_INFO_CMD
video info/command frame
Definition: flv.h:120
FFERROR_REDO
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition: demux.h:62
kux_probe
static int kux_probe(const AVProbeData *p)
Definition: flvdec.c:118
FLV_CODECID_SPEEX
@ FLV_CODECID_SPEEX
Definition: flv.h:101
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
FLVContext::last_keyframe_stream_index
int last_keyframe_stream_index
Definition: flvdec.c:70
flv_read_metabody
static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
Definition: flvdec.c:706
internal.h
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:904
AVCodecParameters::height
int height
Definition: codec_par.h:128
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
resync
static int resync(AVFormatContext *s)
Definition: flvdec.c:971
FLVContext::framerate
AVRational framerate
Definition: flvdec.c:77
flv_probe
static int flv_probe(const AVProbeData *p)
Definition: flvdec.c:108
FLV_STREAM_TYPE_SUBTITLE
@ FLV_STREAM_TYPE_SUBTITLE
Definition: flv.h:68
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
FLV_CODECID_SCREEN2
@ FLV_CODECID_SCREEN2
Definition: flv.h:109
FLV_AUDIO_SAMPLERATE_OFFSET
#define FLV_AUDIO_SAMPLERATE_OFFSET
Definition: flv.h:33
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:53
demux.h
FLV_FRAME_DISP_INTER
@ FLV_FRAME_DISP_INTER
disposable inter frame (H.263 only)
Definition: flv.h:118
FLVContext::wrong_dts
int wrong_dts
wrong dts due to negative cts
Definition: flvdec.c:52
flv_queue_extradata
static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, int size)
Definition: flvdec.c:824
AMF_DATA_TYPE_MIXEDARRAY
@ AMF_DATA_TYPE_MIXEDARRAY
Definition: flv.h:131
av_get_packet
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:102
AMF_DATA_TYPE_STRING
@ AMF_DATA_TYPE_STRING
Definition: flv.h:126
FLVContext::new_extradata
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:53
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:111
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:948
probe
static int probe(const AVProbeData *p, int live)
Definition: flvdec.c:89
flv_kux_class
static const AVClass flv_kux_class
Definition: flvdec.c:1367
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
AVClass::class_name
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:71
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:775
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:799
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
FLV_CODECID_VP6
@ FLV_CODECID_VP6
Definition: flv.h:107
dict.h
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: codec_id.h:529
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
amf_get_string
static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
Definition: flvdec.c:387
av_sat_add64
#define av_sat_add64
Definition: common.h:137
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
FLV_CODECID_PCM
@ FLV_CODECID_PCM
Definition: flv.h:91
channel_layout.h
AV_OPT_FLAG_EXPORT
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition: opt.h:289
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
FLV_CODECID_NELLYMOSER
@ FLV_CODECID_NELLYMOSER
Definition: flv.h:97
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
FLV_TAG_TYPE_META
@ FLV_TAG_TYPE_META
Definition: flv.h:62
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:641
amf_parse_object
static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth)
Definition: flvdec.c:501
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:808
FLV_STEREO
@ FLV_STEREO
Definition: flv.h:75
AVIOContext::eof_reached
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:240
AVPacket::stream_index
int stream_index
Definition: packet.h:376
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:347
FLV_CODECID_MP3
@ FLV_CODECID_MP3
Definition: flv.h:93
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:252
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:103
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:483
FLV_CODECID_H264
@ FLV_CODECID_H264
Definition: flv.h:110
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:323
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
flv_get_extradata
static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
Definition: flvdec.c:812
AMF_DATA_TYPE_NUMBER
@ AMF_DATA_TYPE_NUMBER
Definition: flv.h:124
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:79
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FLV_CODECID_PCM_LE
@ FLV_CODECID_PCM_LE
Definition: flv.h:94
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
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:70
FLV_AUDIO_CODECID_MASK
#define FLV_AUDIO_CODECID_MASK
Definition: flv.h:42
FLV_CODECID_PCM_ALAW
@ FLV_CODECID_PCM_ALAW
Definition: flv.h:98
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:394
FLV_STREAM_TYPE_AUDIO
@ FLV_STREAM_TYPE_AUDIO
Definition: flv.h:67
FLV_AUDIO_SAMPLERATE_MASK
#define FLV_AUDIO_SAMPLERATE_MASK
Definition: flv.h:41
d
d
Definition: ffmpeg_filter.c:153
int32_t
int32_t
Definition: audioconvert.c:56
FLV_VIDEO_CODECID_MASK
#define FLV_VIDEO_CODECID_MASK
Definition: flv.h:44
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:798
FFStream::need_context_update
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
Definition: internal.h:241
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_strlcpy
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:86
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:90
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FLVContext::validate_count
int validate_count
Definition: flvdec.c:62
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FLV_AUDIO_SAMPLESIZE_MASK
#define FLV_AUDIO_SAMPLESIZE_MASK
Definition: flv.h:40
AVDictionaryEntry::value
char * value
Definition: dict.h:81
avstring.h
FlvTagType
FlvTagType
Definition: flv.h:59
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:71
amf_date::milliseconds
double milliseconds
Definition: flvdec.c:85
FLV_HEADER_FLAG_HASAUDIO
@ FLV_HEADER_FLAG_HASAUDIO
Definition: flv.h:56
AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:97
int
int
Definition: ffmpeg_filter.c:153
snprintf
#define snprintf
Definition: snprintf.h:34
FLVContext::dump_full_metadata
int dump_full_metadata
Dump full metadata of the onMetadata.
Definition: flvdec.c:51
avpriv_dict_set_timestamp
int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp)
Set a dictionary value to an ISO-8601 compliant timestamp string.
Definition: dict.c:258
FLVContext::last_sample_rate
int last_sample_rate
Definition: flvdec.c:55
max_pos
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
Definition: g723_1dec.c:98
FLV_HEADER_FLAG_HASVIDEO
@ FLV_HEADER_FLAG_HASVIDEO
Definition: flv.h:55
AMF_DATA_TYPE_NULL
@ AMF_DATA_TYPE_NULL
Definition: flv.h:128
AVFMT_EVENT_FLAG_METADATA_UPDATED
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
Definition: avformat.h:1530
RESYNC_BUFFER_SIZE
#define RESYNC_BUFFER_SIZE
Definition: flvdec.c:43
AV_CODEC_ID_NELLYMOSER
@ AV_CODEC_ID_NELLYMOSER
Definition: codec_id.h:460
FLVContext::broken_sizes
int broken_sizes
Definition: flvdec.c:67
ff_alloc_extradata
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition: utils.c:238
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:375