X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fidroqdec.c;h=fffee9d76e027ed05b63b413d0ebefc7878ae0be;hb=ee4d43ef7a89626de8eaf02bec5a7ca44d96edbf;hp=5cc32d2b47f1b3c1993986462ccdbfd9bc51e1e3;hpb=5271b857ebc7ddcfa2d0dc6604f55ef43d2bc49e;p=ffmpeg diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 5cc32d2b47f..fffee9d76e0 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -29,6 +29,8 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" +#include "internal.h" +#include "avio_internal.h" #define RoQ_MAGIC_NUMBER 0x1084 #define RoQ_CHUNK_PREAMBLE_SIZE 8 @@ -43,6 +45,7 @@ typedef struct RoqDemuxContext { + int frame_rate; int width; int height; int audio_channels; @@ -69,29 +72,21 @@ static int roq_read_header(AVFormatContext *s, { RoqDemuxContext *roq = s->priv_data; AVIOContext *pb = s->pb; - int framerate; - AVStream *st; unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; /* get the main header */ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); - framerate = AV_RL16(&preamble[6]); + roq->frame_rate = AV_RL16(&preamble[6]); /* init private context parameters */ roq->width = roq->height = roq->audio_channels = roq->video_pts = roq->audio_frame_count = 0; roq->audio_stream_index = -1; + roq->video_stream_index = -1; - st = av_new_stream(s, 0); - if (!st) - return AVERROR(ENOMEM); - av_set_pts_info(st, 63, 1, framerate); - roq->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_ROQ; - st->codec->codec_tag = 0; /* no fourcc */ + s->ctx_flags |= AVFMTCTX_NOHEADER; return 0; } @@ -124,11 +119,21 @@ static int roq_read_packet(AVFormatContext *s, if(chunk_size > INT_MAX) return AVERROR_INVALIDDATA; + chunk_size = ffio_limit(pb, chunk_size); + switch (chunk_type) { case RoQ_INFO: - if (!roq->width || !roq->height) { - AVStream *st = s->streams[roq->video_stream_index]; + if (roq->video_stream_index == -1) { + AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + avpriv_set_pts_info(st, 63, 1, roq->frame_rate); + roq->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_ROQ; + st->codec->codec_tag = 0; /* no fourcc */ + if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); st->codec->width = roq->width = AV_RL16(preamble); @@ -166,10 +171,10 @@ static int roq_read_packet(AVFormatContext *s, case RoQ_SOUND_MONO: case RoQ_SOUND_STEREO: if (roq->audio_stream_index == -1) { - AVStream *st = av_new_stream(s, 1); + AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - av_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); + avpriv_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); roq->audio_stream_index = st->index; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ROQ_DPCM;