diff options
author | Joseph Wecker <jwecker@justin.tv> | 2011-08-26 17:39:11 -0700 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-09-07 02:38:13 +0200 |
commit | 4c050429780b0d4010b6dbd3bd50b2d36ba810b2 (patch) | |
tree | d3b0d25afc7e1ae00a30bf0d866afd01a49958e7 /libavformat | |
parent | c054f11606d76022e990891654ed40d63b863b06 (diff) | |
download | ffmpeg-4c050429780b0d4010b6dbd3bd50b2d36ba810b2.tar.gz |
flvdec: Properly decoding in-band metadata packets as data frames.
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/flvdec.c | 28 | ||||
-rw-r--r-- | libavformat/utils.c | 2 |
2 files changed, 17 insertions, 13 deletions
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index db3497a36d..3f72b9d429 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -284,13 +284,12 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) { AMFDataType type; - AVStream *stream, *astream, *vstream; + AVStream *stream, *astream, *vstream, *dstream; AVIOContext *ioc; int i; char buffer[11]; //only needs to hold the string "onMetaData". Anything longer is something we don't want. - astream = NULL; - vstream = NULL; + vstream = astream = dstream = NULL; ioc = s->pb; //first object needs to be "onMetaData" string @@ -301,8 +300,9 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) { //find the streams now so that amf_parse_object doesn't need to do the lookup every time it is called. for(i = 0; i < s->nb_streams; i++) { stream = s->streams[i]; - if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; - else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; + if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; + else if(stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; + else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) dstream = stream; } //parse the second object (we want a mixed array) @@ -322,6 +322,7 @@ static AVStream *create_stream(AVFormatContext *s, int stream_type){ case FLV_STREAM_TYPE_DATA: st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = CODEC_ID_NONE; // Going to rely on copy for now + av_log(s, AV_LOG_DEBUG, "Data stream created\n"); } av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ return st; @@ -379,7 +380,8 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) { FLVContext *flv = s->priv_data; - int ret, i, type, size, flags, stream_type; + int ret, i, type, size, flags; + int stream_type=-1; int64_t next, pos; int64_t dts, pts = AV_NOPTS_VALUE; AVStream *st = NULL; @@ -415,12 +417,10 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) if (size > 13+1+4 && dts == 0) { // Header-type metadata stuff flv_read_metabody(s, next); - } else if (dts != 0) { - // Script-data - stream_type=FLV_STREAM_TYPE_VIDEO; goto skip; - - // TODO: Parse / set stuff, etc. + } else if (dts != 0) { + // Script-data "special" metadata frames - don't skip + stream_type=FLV_STREAM_TYPE_DATA; } else { goto skip; } @@ -441,7 +441,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) break; } if(i == s->nb_streams){ - av_log(s, AV_LOG_ERROR, "invalid stream\n"); + av_log(s, AV_LOG_WARNING, "Stream discovered after head already parsed\n"); st= create_stream(s, stream_type); s->ctx_flags &= ~AVFMTCTX_NOHEADER; } @@ -540,7 +540,9 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts; pkt->stream_index = st->index; - if ((stream_type == FLV_STREAM_TYPE_AUDIO) || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)) + if ( stream_type == FLV_STREAM_TYPE_AUDIO || + (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || + stream_type == FLV_STREAM_TYPE_DATA) pkt->flags |= AV_PKT_FLAG_KEY; leave: diff --git a/libavformat/utils.c b/libavformat/utils.c index d7d78bf5a3..d3a0d4a0c2 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2119,6 +2119,8 @@ static int has_codec_parameters(AVCodecContext *avctx) case AVMEDIA_TYPE_VIDEO: val = avctx->width && avctx->pix_fmt != PIX_FMT_NONE; break; + case AVMEDIA_TYPE_DATA: + if(avctx->codec_id == CODEC_ID_NONE) return 1; default: val = 1; break; |