Commit a2517fca authored by Peter Ross's avatar Peter Ross Committed by Michael Niedermayer

electronicarts: move video stream properties into dedicated structure

This is required for the alpha stream demux patch.
Signed-off-by: 's avatarPeter Ross <pross@xvid.org>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 1bcdac2d
...@@ -63,14 +63,18 @@ ...@@ -63,14 +63,18 @@
#define MVIf_TAG MKTAG('M', 'V', 'I', 'f') /* CMV I-frame */ #define MVIf_TAG MKTAG('M', 'V', 'I', 'f') /* CMV I-frame */
#define AVP6_TAG MKTAG('A', 'V', 'P', '6') #define AVP6_TAG MKTAG('A', 'V', 'P', '6')
typedef struct EaDemuxContext { typedef struct VideoProperties {
int big_endian; enum AVCodecID codec;
enum AVCodecID video_codec;
AVRational time_base; AVRational time_base;
int width, height; int width, height;
int nb_frames; int nb_frames;
int video_stream_index; int stream_index;
} VideoProperties;
typedef struct EaDemuxContext {
int big_endian;
VideoProperties video;
enum AVCodecID audio_codec; enum AVCodecID audio_codec;
int audio_stream_index; int audio_stream_index;
...@@ -302,46 +306,43 @@ static void process_audio_header_sead(AVFormatContext *s) ...@@ -302,46 +306,43 @@ static void process_audio_header_sead(AVFormatContext *s)
ea->audio_codec = AV_CODEC_ID_ADPCM_IMA_EA_SEAD; ea->audio_codec = AV_CODEC_ID_ADPCM_IMA_EA_SEAD;
} }
static void process_video_header_mdec(AVFormatContext *s) static void process_video_header_mdec(AVFormatContext *s, VideoProperties *video)
{ {
EaDemuxContext *ea = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
avio_skip(pb, 4); avio_skip(pb, 4);
ea->width = avio_rl16(pb); video->width = avio_rl16(pb);
ea->height = avio_rl16(pb); video->height = avio_rl16(pb);
ea->time_base = (AVRational) { 1, 15 }; video->time_base = (AVRational) { 1, 15 };
ea->video_codec = AV_CODEC_ID_MDEC; video->codec = AV_CODEC_ID_MDEC;
} }
static int process_video_header_vp6(AVFormatContext *s) static int process_video_header_vp6(AVFormatContext *s, VideoProperties *video)
{ {
EaDemuxContext *ea = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
avio_skip(pb, 8); avio_skip(pb, 8);
ea->nb_frames = avio_rl32(pb); video->nb_frames = avio_rl32(pb);
avio_skip(pb, 4); avio_skip(pb, 4);
ea->time_base.den = avio_rl32(pb); video->time_base.den = avio_rl32(pb);
ea->time_base.num = avio_rl32(pb); video->time_base.num = avio_rl32(pb);
if (ea->time_base.den <= 0 || ea->time_base.num <= 0) { if (video->time_base.den <= 0 || video->time_base.num <= 0) {
av_log(s, AV_LOG_ERROR, "Timebase is invalid\n"); av_log(s, AV_LOG_ERROR, "Timebase is invalid\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
ea->video_codec = AV_CODEC_ID_VP6; video->codec = AV_CODEC_ID_VP6;
return 1; return 1;
} }
static void process_video_header_cmv(AVFormatContext *s) static void process_video_header_cmv(AVFormatContext *s, VideoProperties *video)
{ {
EaDemuxContext *ea = s->priv_data;
int fps; int fps;
avio_skip(s->pb, 10); avio_skip(s->pb, 10);
fps = avio_rl16(s->pb); fps = avio_rl16(s->pb);
if (fps) if (fps)
ea->time_base = (AVRational) { 1, fps }; video->time_base = (AVRational) { 1, fps };
ea->video_codec = AV_CODEC_ID_CMV; video->codec = AV_CODEC_ID_CMV;
} }
/* Process EA file header. /* Process EA file header.
...@@ -353,7 +354,7 @@ static int process_ea_header(AVFormatContext *s) ...@@ -353,7 +354,7 @@ static int process_ea_header(AVFormatContext *s)
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
int i; int i;
for (i = 0; i < 5 && (!ea->audio_codec || !ea->video_codec); i++) { for (i = 0; i < 5 && (!ea->audio_codec || !ea->video.codec); i++) {
uint64_t startpos = avio_tell(pb); uint64_t startpos = avio_tell(pb);
int err = 0; int err = 0;
...@@ -395,40 +396,40 @@ static int process_ea_header(AVFormatContext *s) ...@@ -395,40 +396,40 @@ static int process_ea_header(AVFormatContext *s)
break; break;
case MVIh_TAG: case MVIh_TAG:
process_video_header_cmv(s); process_video_header_cmv(s, &ea->video);
break; break;
case kVGT_TAG: case kVGT_TAG:
ea->video_codec = AV_CODEC_ID_TGV; ea->video.codec = AV_CODEC_ID_TGV;
break; break;
case mTCD_TAG: case mTCD_TAG:
process_video_header_mdec(s); process_video_header_mdec(s, &ea->video);
break; break;
case MPCh_TAG: case MPCh_TAG:
ea->video_codec = AV_CODEC_ID_MPEG2VIDEO; ea->video.codec = AV_CODEC_ID_MPEG2VIDEO;
break; break;
case pQGT_TAG: case pQGT_TAG:
case TGQs_TAG: case TGQs_TAG:
ea->video_codec = AV_CODEC_ID_TGQ; ea->video.codec = AV_CODEC_ID_TGQ;
ea->time_base = (AVRational) { 1, 15 }; ea->video.time_base = (AVRational) { 1, 15 };
break; break;
case pIQT_TAG: case pIQT_TAG:
ea->video_codec = AV_CODEC_ID_TQI; ea->video.codec = AV_CODEC_ID_TQI;
ea->time_base = (AVRational) { 1, 15 }; ea->video.time_base = (AVRational) { 1, 15 };
break; break;
case MADk_TAG: case MADk_TAG:
ea->video_codec = AV_CODEC_ID_MAD; ea->video.codec = AV_CODEC_ID_MAD;
avio_skip(pb, 6); avio_skip(pb, 6);
ea->time_base = (AVRational) { avio_rl16(pb), 1000 }; ea->video.time_base = (AVRational) { avio_rl16(pb), 1000 };
break; break;
case MVhd_TAG: case MVhd_TAG:
err = process_video_header_vp6(s); err = process_video_header_vp6(s, &ea->video);
break; break;
} }
...@@ -474,34 +475,44 @@ static int ea_probe(AVProbeData *p) ...@@ -474,34 +475,44 @@ static int ea_probe(AVProbeData *p)
return AVPROBE_SCORE_MAX; return AVPROBE_SCORE_MAX;
} }
static int ea_read_header(AVFormatContext *s) static int init_video_stream(AVFormatContext *s, VideoProperties *video)
{ {
EaDemuxContext *ea = s->priv_data;
AVStream *st; AVStream *st;
if (process_ea_header(s)<=0) if (!video->codec)
return AVERROR(EIO); return 0;
if (ea->video_codec) {
/* initialize the video decoder stream */ /* initialize the video decoder stream */
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) if (!st)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ea->video_stream_index = st->index; video->stream_index = st->index;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = ea->video_codec; st->codec->codec_id = video->codec;
// parsing is necessary to make FFmpeg generate correct timestamps // parsing is necessary to make FFmpeg generate correct timestamps
if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO)
st->need_parsing = AVSTREAM_PARSE_HEADERS; st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->codec->codec_tag = 0; /* no fourcc */ st->codec->codec_tag = 0; /* no fourcc */
st->codec->width = ea->width; st->codec->width = video->width;
st->codec->height = ea->height; st->codec->height = video->height;
st->duration = st->nb_frames = ea->nb_frames; st->duration = st->nb_frames = video->nb_frames;
if (ea->time_base.num) if (video->time_base.num)
avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den); avpriv_set_pts_info(st, 64, video->time_base.num, video->time_base.den);
st->r_frame_rate = st->r_frame_rate =
st->avg_frame_rate = av_inv_q(ea->time_base); st->avg_frame_rate = av_inv_q(video->time_base);
} return 0;
}
static int ea_read_header(AVFormatContext *s)
{
EaDemuxContext *ea = s->priv_data;
AVStream *st;
if (process_ea_header(s)<=0)
return AVERROR(EIO);
if (init_video_stream(s, &ea->video))
return AVERROR(ENOMEM);
if (ea->audio_codec) { if (ea->audio_codec) {
if (ea->num_channels <= 0 || ea->num_channels > 2) { if (ea->num_channels <= 0 || ea->num_channels > 2) {
...@@ -678,7 +689,7 @@ get_video_packet: ...@@ -678,7 +689,7 @@ get_video_packet:
break; break;
} }
partial_packet = chunk_type == MVIh_TAG; partial_packet = chunk_type == MVIh_TAG;
pkt->stream_index = ea->video_stream_index; pkt->stream_index = ea->video.stream_index;
pkt->flags |= key; pkt->flags |= key;
packet_read = 1; packet_read = 1;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment