27 #include "libavutil/avstring.h"
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intfloat.h"
32 #include "libavutil/mathematics.h"
40 #define VALIDATE_INDEX_TS_THRESH 2500
67 d[3] < 5 && d[5] == 0 &&
101 switch (flv_codecid) {
104 codec_id = bits_per_coded_sample == 8
111 return codec_id == acodec->
codec_id;
113 codec_id = bits_per_coded_sample == 8
116 return codec_id == acodec->
codec_id;
143 switch (flv_codecid) {
207 switch (flv_codecid) {
226 int flv_codecid,
int read)
229 switch (flv_codecid) {
274 if (length >= buffsize) {
290 unsigned int timeslen = 0, fileposlen = 0, i;
292 int64_t *times = NULL;
293 int64_t *filepositions = NULL;
307 int64_t **current_array;
308 unsigned int arraylen;
319 current_array = ×
323 current_array = &filepositions;
324 fileposlen = arraylen;
330 if (!(*current_array =
av_mallocz(
sizeof(**current_array) * arraylen))) {
335 for (i = 0; i < arraylen &&
avio_tell(ioc) < max_pos - 1; i++) {
340 if (times && filepositions) {
348 if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
349 for (i = 0; i < fileposlen; i++) {
397 if ((vstream || astream) && key &&
430 unsigned int arraylen, i;
433 for (i = 0; i < arraylen &&
avio_tell(ioc) < max_pos - 1; i++)
447 if (depth == 1 && key) {
448 acodec = astream ? astream->
codec : NULL;
449 vcodec = vstream ? vstream->
codec : NULL;
453 if (!strcmp(key,
"duration"))
455 else if (!strcmp(key,
"videodatarate") && vcodec &&
456 0 <= (
int)(num_val * 1024.0))
457 vcodec->
bit_rate = num_val * 1024.0;
458 else if (!strcmp(key,
"audiodatarate") && acodec &&
459 0 <= (
int)(num_val * 1024.0))
460 acodec->
bit_rate = num_val * 1024.0;
461 else if (!strcmp(key,
"datastream")) {
467 if (!strcmp(key,
"videocodecid") && vcodec) {
469 }
else if (!strcmp(key,
"audiocodecid") && acodec) {
472 }
else if (!strcmp(key,
"audiosamplerate") && acodec) {
474 }
else if (!strcmp(key,
"audiosamplesize") && acodec) {
476 }
else if (!strcmp(key,
"stereo") && acodec) {
481 }
else if (!strcmp(key,
"width") && vcodec) {
482 vcodec->
width = num_val;
483 }
else if (!strcmp(key,
"height") && vcodec) {
490 ((!acodec && !strcmp(key,
"audiocodecid")) ||
491 (!vcodec && !strcmp(key,
"videocodecid"))))
494 if (!strcmp(key,
"duration") ||
495 !strcmp(key,
"filesize") ||
496 !strcmp(key,
"width") ||
497 !strcmp(key,
"height") ||
498 !strcmp(key,
"videodatarate") ||
499 !strcmp(key,
"framerate") ||
500 !strcmp(key,
"videocodecid") ||
501 !strcmp(key,
"audiodatarate") ||
502 !strcmp(key,
"audiosamplerate") ||
503 !strcmp(key,
"audiosamplesize") ||
504 !strcmp(key,
"stereo") ||
505 !strcmp(key,
"audiocodecid") ||
506 !strcmp(key,
"datastream"))
510 av_strlcpy(str_val, num_val > 0 ?
"true" :
"false",
514 snprintf(str_val,
sizeof(str_val),
"%.f", num_val);
526 AVStream *stream, *astream, *vstream;
545 if (!strcmp(buffer,
"onTextData"))
548 if (strcmp(buffer,
"onMetaData"))
581 "Broken FLV file, which says no streams present, "
582 "this might fail\n");
640 "Found invalid index entries, clearing the index.\n");
654 int nb = -1,
ret, parse_name = 1;
694 int64_t dts, int64_t next)
762 int64_t next, pos, meta_pos;
775 av_dlog(s,
"type:%d, size:%d, dts:%"PRId64
"\n", type, size, dts);
783 if (pos == validate_pos) {
791 }
else if (pos > validate_pos) {
814 if (size > 13 + 1 + 4 && dts == 0) {
823 "skipping flv packet: type %d, size %d, flags %d\n",
886 else if (fsize >= 8 && fsize - 8 >= size) {
897 int bits_per_coded_sample;
940 "negative cts, previous timestamps might be wrong\n");
964 av_dlog(s,
"mp4a config channels %d sample rate %d\n",
1015 int64_t ts,
int flags)
1022 #define OFFSET(x) offsetof(FLVContext, x)
1023 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1025 {
"flv_metadata",
"Allocate streams according to the onMetaData array",
OFFSET(trust_metadata),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
VD },
1045 .extensions =
"flv",
1046 .priv_class = &flv_class,
discard all frames except keyframes
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
AVCodecContext * codec
Codec context associated with this stream.
int index
stream index in AVFormatContext
enum AVMediaType codec_type
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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)
#define AV_CH_LAYOUT_STEREO
int ctx_flags
Format-specific flags, see AVFMTCTX_xx.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const char * av_default_item_name(void *ctx)
Return the context 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...
int wrong_dts
wrong dts due to negative cts
static const uint8_t offset[511][2]
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
static av_cold int read_close(AVFormatContext *ctx)
int trust_metadata
configure streams according onMetaData
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
const OptionDef options[]
enum AVCodecID video_codec_id
Forced video codec_id.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void * priv_data
Format private data.
discard all bidirectional frames
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
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.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
int flags
A combination of AV_PKT_FLAG values.
uint64_t channel_layout
Audio channel layout.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int nb_streams
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
Opaque data information usually continuous.
#define AV_TIME_BASE
Internal time base represented as integer.
enum AVCodecID audio_codec_id
Forced audio codec_id.
int width
picture width / height.
int new_extradata_size[FLV_STREAM_TYPE_NB]
struct FLVContext::@145 validate_index[2]
static int read_header(FFV1Context *f)
enum AVMediaType codec_type
int sample_rate
samples per second
main external API structure.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
AVIOContext * pb
I/O context.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
This structure contains the data a format has to probe a file.
int64_t start_time
Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds...
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
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.
#define AVERROR_INVALIDDATA
int eof_reached
true if eof reached
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){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));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);ff_audio_convert_init_arm(ac);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
int channels
number of audio channels
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
#define AV_CH_LAYOUT_MONO
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...