Commit 465aa53f authored by Michael Niedermayer's avatar Michael Niedermayer

asfdec: move packet_obj_size to ASFStream

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent cb6d02df
...@@ -39,6 +39,7 @@ typedef struct ASFStream { ...@@ -39,6 +39,7 @@ typedef struct ASFStream {
/* use for reading */ /* use for reading */
AVPacket pkt; AVPacket pkt;
int frag_offset; int frag_offset;
int packet_obj_size;
int timestamp; int timestamp;
int64_t duration; int64_t duration;
......
...@@ -67,7 +67,6 @@ typedef struct { ...@@ -67,7 +67,6 @@ typedef struct {
unsigned int packet_frag_size; unsigned int packet_frag_size;
int64_t packet_frag_timestamp; int64_t packet_frag_timestamp;
int packet_multi_size; int packet_multi_size;
int packet_obj_size;
int packet_time_delta; int packet_time_delta;
int packet_time_start; int packet_time_start;
int64_t packet_pos; int64_t packet_pos;
...@@ -1006,10 +1005,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb) ...@@ -1006,10 +1005,10 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
if (asf->packet_replic_size >= 8) { if (asf->packet_replic_size >= 8) {
int64_t end = avio_tell(pb) + asf->packet_replic_size; int64_t end = avio_tell(pb) + asf->packet_replic_size;
AVRational aspect; AVRational aspect;
asf->packet_obj_size = avio_rl32(pb); asfst->packet_obj_size = avio_rl32(pb);
if (asf->packet_obj_size >= (1 << 24) || asf->packet_obj_size <= 0) { if (asfst->packet_obj_size >= (1 << 24) || asfst->packet_obj_size <= 0) {
av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n"); av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
asf->packet_obj_size = 0; asfst->packet_obj_size = 0;
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
asf->packet_frag_timestamp = avio_rl32(pb); // timestamp asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
...@@ -1157,37 +1156,37 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) ...@@ -1157,37 +1156,37 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
// frag_offset is here used as the beginning timestamp // frag_offset is here used as the beginning timestamp
asf->packet_frag_timestamp = asf->packet_time_start; asf->packet_frag_timestamp = asf->packet_time_start;
asf->packet_time_start += asf->packet_time_delta; asf->packet_time_start += asf->packet_time_delta;
asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb); asf_st->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
asf->packet_size_left--; asf->packet_size_left--;
asf->packet_multi_size--; asf->packet_multi_size--;
if (asf->packet_multi_size < asf->packet_obj_size) { if (asf->packet_multi_size < asf_st->packet_obj_size) {
asf->packet_time_start = 0; asf->packet_time_start = 0;
avio_skip(pb, asf->packet_multi_size); avio_skip(pb, asf->packet_multi_size);
asf->packet_size_left -= asf->packet_multi_size; asf->packet_size_left -= asf->packet_multi_size;
continue; continue;
} }
asf->packet_multi_size -= asf->packet_obj_size; asf->packet_multi_size -= asf_st->packet_obj_size;
} }
if (asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size && if (asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size &&
asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size) { asf_st->frag_offset + asf->packet_frag_size > asf_st->packet_obj_size) {
av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n", av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
asf_st->frag_offset, asf->packet_frag_size, asf_st->frag_offset, asf->packet_frag_size,
asf->packet_obj_size, asf_st->pkt.size); asf_st->packet_obj_size, asf_st->pkt.size);
asf->packet_obj_size = asf_st->pkt.size; asf_st->packet_obj_size = asf_st->pkt.size;
} }
if (asf_st->pkt.size != asf->packet_obj_size || if (asf_st->pkt.size != asf_st->packet_obj_size ||
// FIXME is this condition sufficient? // FIXME is this condition sufficient?
asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
if (asf_st->pkt.data) { if (asf_st->pkt.data) {
av_log(s, AV_LOG_INFO, av_log(s, AV_LOG_INFO,
"freeing incomplete packet size %d, new %d\n", "freeing incomplete packet size %d, new %d\n",
asf_st->pkt.size, asf->packet_obj_size); asf_st->pkt.size, asf_st->packet_obj_size);
asf_st->frag_offset = 0; asf_st->frag_offset = 0;
av_free_packet(&asf_st->pkt); av_free_packet(&asf_st->pkt);
} }
/* new packet */ /* new packet */
av_new_packet(&asf_st->pkt, asf->packet_obj_size); av_new_packet(&asf_st->pkt, asf_st->packet_obj_size);
asf_st->seq = asf->packet_seq; asf_st->seq = asf->packet_seq;
asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll; asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
asf_st->pkt.stream_index = asf->stream_index; asf_st->pkt.stream_index = asf->stream_index;
...@@ -1208,7 +1207,7 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) ...@@ -1208,7 +1207,7 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
asf->stream_index, asf->packet_key_frame, asf->stream_index, asf->packet_key_frame,
asf_st->pkt.flags & AV_PKT_FLAG_KEY, asf_st->pkt.flags & AV_PKT_FLAG_KEY,
s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO,
asf->packet_obj_size); asf_st->packet_obj_size);
if (s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO) if (s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
asf->packet_key_frame = 1; asf->packet_key_frame = 1;
if (asf->packet_key_frame) if (asf->packet_key_frame)
...@@ -1361,13 +1360,13 @@ static void asf_reset_header(AVFormatContext *s) ...@@ -1361,13 +1360,13 @@ static void asf_reset_header(AVFormatContext *s)
asf->packet_frag_size = 0; asf->packet_frag_size = 0;
asf->packet_frag_timestamp = 0; asf->packet_frag_timestamp = 0;
asf->packet_multi_size = 0; asf->packet_multi_size = 0;
asf->packet_obj_size = 0;
asf->packet_time_delta = 0; asf->packet_time_delta = 0;
asf->packet_time_start = 0; asf->packet_time_start = 0;
for (i = 0; i < 128; i++) { for (i = 0; i < 128; i++) {
asf_st = &asf->streams[i]; asf_st = &asf->streams[i];
av_free_packet(&asf_st->pkt); av_free_packet(&asf_st->pkt);
asf_st->packet_obj_size = 0;
asf_st->frag_offset = 0; asf_st->frag_offset = 0;
asf_st->seq = 0; asf_st->seq = 0;
} }
......
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