Commit 286eb78a authored by michael's avatar michael

move frame header reading into its own function


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@7649 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 5023a475
...@@ -530,45 +530,17 @@ static int asf_get_packet(AVFormatContext *s) ...@@ -530,45 +530,17 @@ static int asf_get_packet(AVFormatContext *s)
return 0; 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; ASFContext *asf = s->priv_data;
ASFStream *asf_st = 0;
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
//static int pc = 0; int rsize = 1;
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 num = get_byte(pb); int num = get_byte(pb);
asf->packet_segments--; asf->packet_segments--;
rsize++;
asf->packet_key_frame = num >> 7; asf->packet_key_frame = num >> 7;
asf->stream_index = asf->asfid2avid[num & 0x7f]; asf->stream_index = asf->asfid2avid[num & 0x7f];
// sequence should be ignored! // sequence should be ignored!
...@@ -580,7 +552,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -580,7 +552,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
asf->packet_obj_size = get_le32(pb); asf->packet_obj_size = get_le32(pb);
if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){ if(asf->packet_obj_size >= (1<<24) || asf->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");
continue; return -1;
} }
asf->packet_frag_timestamp = get_le32(pb); // timestamp asf->packet_frag_timestamp = get_le32(pb); // timestamp
url_fskip(pb, asf->packet_replic_size - 8); url_fskip(pb, asf->packet_replic_size - 8);
...@@ -595,11 +567,10 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -595,11 +567,10 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
rsize++; rsize++;
}else if(asf->packet_replic_size!=0){ }else if(asf->packet_replic_size!=0){
av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size); 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) { if (asf->packet_flags & 0x01) {
DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal 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); //printf("Fragsize %d\n", asf->packet_frag_size);
} else { } else {
asf->packet_frag_size = asf->packet_size_left - rsize; asf->packet_frag_size = asf->packet_size_left - rsize;
...@@ -607,14 +578,53 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -607,14 +578,53 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
} }
if (asf->packet_replic_size == 1) { if (asf->packet_replic_size == 1) {
asf->packet_multi_size = asf->packet_frag_size; asf->packet_multi_size = asf->packet_frag_size;
if (asf->packet_multi_size > asf->packet_size_left) { if (asf->packet_multi_size > asf->packet_size_left)
asf->packet_segments = 0; return -1;
continue;
}
} }
asf->packet_size_left -= rsize; asf->packet_size_left -= rsize;
//printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, 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 if (asf->stream_index < 0
|| s->streams[asf->stream_index]->discard >= AVDISCARD_ALL || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
|| (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY) || (!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) ...@@ -624,7 +634,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
url_fskip(pb, asf->packet_frag_size); url_fskip(pb, asf->packet_frag_size);
asf->packet_size_left -= asf->packet_frag_size; asf->packet_size_left -= asf->packet_frag_size;
if(asf->stream_index < 0) 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; continue;
} }
asf->asf_st = s->streams[asf->stream_index]->priv_data; 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