return 1;
}
-static int ea_probe(AVProbeData *p)
+static int ea_probe(const AVProbeData *p)
{
unsigned big_endian, size;
if (ea->num_channels <= 0 || ea->num_channels > 2) {
av_log(s, AV_LOG_WARNING,
"Unsupported number of channels: %d\n", ea->num_channels);
- ea->audio_codec = 0;
- return 1;
+ goto no_audio;
}
if (ea->sample_rate <= 0) {
av_log(s, AV_LOG_ERROR,
"Unsupported sample rate: %d\n", ea->sample_rate);
- ea->audio_codec = 0;
- return 1;
+ goto no_audio;
}
if (ea->bytes <= 0 || ea->bytes > 2) {
av_log(s, AV_LOG_ERROR,
"Invalid number of bytes per sample: %d\n", ea->bytes);
- ea->audio_codec = AV_CODEC_ID_NONE;
- return 1;
+ goto no_audio;
}
/* initialize the audio decoder stream */
st->codecpar->bits_per_coded_sample;
ea->audio_stream_index = st->index;
st->start_time = 0;
+ return 0;
}
+no_audio:
+ ea->audio_codec = AV_CODEC_ID_NONE;
- return 1;
+ if (!ea->video.codec)
+ return AVERROR_INVALIDDATA;
+ return 0;
}
static int ea_read_packet(AVFormatContext *s, AVPacket *pkt)
EaDemuxContext *ea = s->priv_data;
AVIOContext *pb = s->pb;
int partial_packet = 0;
+ int hit_end = 0;
unsigned int chunk_type, chunk_size;
int ret = 0, packet_read = 0, key = 0;
int av_uninit(num_samples);
- while (!packet_read || partial_packet) {
+ while ((!packet_read && !hit_end) || partial_packet) {
+ if (avio_feof(pb))
+ return AVERROR_EOF;
chunk_type = avio_rl32(pb);
chunk_size = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb);
if (chunk_size < 8)
break;
} else if (ea->audio_codec == AV_CODEC_ID_PCM_S16LE_PLANAR ||
ea->audio_codec == AV_CODEC_ID_MP3) {
+ if (chunk_size < 12)
+ return AVERROR_INVALIDDATA;
num_samples = avio_rl32(pb);
avio_skip(pb, 8);
chunk_size -= 12;
} else if (ea->audio_codec == AV_CODEC_ID_ADPCM_PSX) {
+ if (chunk_size < 8)
+ return AVERROR_INVALIDDATA;
avio_skip(pb, 8);
chunk_size -= 8;
}
case AV_CODEC_ID_ADPCM_EA_R3:
if (pkt->size < 4) {
av_log(s, AV_LOG_ERROR, "Packet is too short\n");
- av_packet_unref(pkt);
return AVERROR_INVALIDDATA;
}
if (ea->audio_codec == AV_CODEC_ID_ADPCM_EA_R3)
}
if (avio_feof(pb))
ret = AVERROR_EOF;
- packet_read = 1;
+ hit_end = 1;
break;
case MVIh_TAG:
case fVGT_TAG:
case MADm_TAG:
case MADe_TAG:
+ if (chunk_size > INT_MAX - 8)
+ return AVERROR_INVALIDDATA;
avio_seek(pb, -8, SEEK_CUR); // include chunk preamble
chunk_size += 8;
goto get_video_packet;
ret = av_get_packet(pb, pkt, chunk_size);
if (ret < 0) {
packet_read = 1;
+ partial_packet = 0;
break;
}
partial_packet = chunk_type == MVIh_TAG;
}
}
- if (ret < 0 && partial_packet)
- av_packet_unref(pkt);
+ if (ret >= 0 && hit_end && !packet_read)
+ return AVERROR(EAGAIN);
+
return ret;
}
-AVInputFormat ff_ea_demuxer = {
+const AVInputFormat ff_ea_demuxer = {
.name = "ea",
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia"),
.priv_data_size = sizeof(EaDemuxContext),