Commit ae60a857 authored by Michael Niedermayer's avatar Michael Niedermayer

move frame header reading into its own function

Originally committed as revision 7649 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent b04d5d31
......@@ -530,45 +530,17 @@ static int asf_get_packet(AVFormatContext *s)
return 0;
}
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
{
/**
*
* @return <0 if error
*/
static int asf_read_frame_header(AVFormatContext *s){
ASFContext *asf = s->priv_data;
ASFStream *asf_st = 0;
ByteIOContext *pb = &s->pb;
//static int pc = 0;
for (;;) {
int rsize = 0;
if (asf->packet_size_left < FRAME_HEADER_SIZE
|| asf->packet_segments < 1) {
//asf->packet_size_left <= asf->packet_padsize) {
int ret = asf->packet_size_left + asf->packet_padsize;
//printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
assert(ret>=0);
/* fail safe */
url_fskip(pb, ret);
ret= (url_ftell(&s->pb) - s->data_offset) % asf->packet_size;
if(asf->hdr.max_pktsize == asf->hdr.min_pktsize && ret){
av_log(s, AV_LOG_ERROR, "packet end missaligned skiping %d\n", ret);
url_fskip(pb, asf->packet_size - ret);
}
asf->packet_pos= url_ftell(&s->pb);
if (asf->data_object_size != (uint64_t)-1 &&
(asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
return AVERROR_IO; /* Do not exceed the size of the data object */
ret = asf_get_packet(s);
//printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
if (ret < 0 || url_feof(pb))
return AVERROR_IO;
asf->packet_time_start = 0;
continue;
}
if (asf->packet_time_start == 0) {
/* read frame header */
int rsize = 1;
int num = get_byte(pb);
asf->packet_segments--;
rsize++;
asf->packet_key_frame = num >> 7;
asf->stream_index = asf->asfid2avid[num & 0x7f];
// sequence should be ignored!
......@@ -580,7 +552,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
asf->packet_obj_size = get_le32(pb);
if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
continue;
return -1;
}
asf->packet_frag_timestamp = get_le32(pb); // timestamp
url_fskip(pb, asf->packet_replic_size - 8);
......@@ -595,11 +567,10 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
rsize++;
}else if(asf->packet_replic_size!=0){
av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
continue;
return -1;
}
if (asf->packet_flags & 0x01) {
DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
#undef DO_2BITS
//printf("Fragsize %d\n", asf->packet_frag_size);
} else {
asf->packet_frag_size = asf->packet_size_left - rsize;
......@@ -607,14 +578,53 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
}
if (asf->packet_replic_size == 1) {
asf->packet_multi_size = asf->packet_frag_size;
if (asf->packet_multi_size > asf->packet_size_left) {
asf->packet_segments = 0;
continue;
}
if (asf->packet_multi_size > asf->packet_size_left)
return -1;
}
asf->packet_size_left -= rsize;
//printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
return 0;
}
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
{
ASFContext *asf = s->priv_data;
ASFStream *asf_st = 0;
ByteIOContext *pb = &s->pb;
//static int pc = 0;
for (;;) {
if (asf->packet_size_left < FRAME_HEADER_SIZE
|| asf->packet_segments < 1) {
//asf->packet_size_left <= asf->packet_padsize) {
int ret = asf->packet_size_left + asf->packet_padsize;
//printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
assert(ret>=0);
/* fail safe */
url_fskip(pb, ret);
ret= (url_ftell(&s->pb) - s->data_offset) % asf->packet_size;
if(asf->hdr.max_pktsize == asf->hdr.min_pktsize && ret){
av_log(s, AV_LOG_ERROR, "packet end missaligned skiping %d\n", ret);
url_fskip(pb, asf->packet_size - ret);
}
asf->packet_pos= url_ftell(&s->pb);
if (asf->data_object_size != (uint64_t)-1 &&
(asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
return AVERROR_IO; /* Do not exceed the size of the data object */
ret = asf_get_packet(s);
//printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
if (ret < 0 || url_feof(pb))
return AVERROR_IO;
asf->packet_time_start = 0;
continue;
}
if (asf->packet_time_start == 0) {
if(asf_read_frame_header(s) < 0){
asf->packet_segments= 0;
continue;
}
if (asf->stream_index < 0
|| s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
|| (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
......@@ -624,7 +634,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
url_fskip(pb, asf->packet_frag_size);
asf->packet_size_left -= asf->packet_frag_size;
if(asf->stream_index < 0)
av_log(s, AV_LOG_ERROR, "ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
continue;
}
asf->asf_st = s->streams[asf->stream_index]->priv_data;
......
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