From b9866ebcc7d9891fb6b07cab70319fe1742a100a Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 22 Jan 2005 13:36:02 +0000 Subject: [PATCH] support discarding uninterresting packets Originally committed as revision 3860 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/asf.c | 5 +++-- libavformat/flvdec.c | 4 ++++ libavformat/matroska.c | 4 ++++ libavformat/mov.c | 2 +- libavformat/mpeg.c | 6 ++++-- libavformat/nut.c | 12 ++++++++++-- libavformat/rm.c | 7 ++++++- libavformat/utils.c | 2 +- 8 files changed, 33 insertions(+), 9 deletions(-) diff --git a/libavformat/asf.c b/libavformat/asf.c index 8450b53f94..d90e46b943 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -545,12 +545,13 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) asf->packet_size_left -= rsize; //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize); - if (asf->stream_index < 0) { + if (asf->stream_index < 0 || s->streams[asf->stream_index]->discard) { asf->packet_time_start = 0; /* unhandled packet (should not happen) */ url_fskip(pb, asf->packet_frag_size); asf->packet_size_left -= asf->packet_frag_size; - av_log(s, AV_LOG_ERROR, "ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f); + if(asf->stream_index < 0) + av_log(s, AV_LOG_ERROR, "ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f); continue; } asf->asf_st = s->streams[asf->stream_index]->priv_data; diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 3664f8a024..69257a5fc8 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -106,6 +106,10 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) st->codec.frame_rate_base= 1; st->codec.frame_rate= 1000; } + if(st->discard){ + url_fskip(&s->pb, size); + continue; + } break; } diff --git a/libavformat/matroska.c b/libavformat/matroska.c index 1e146d464a..47961fd81f 100644 --- a/libavformat/matroska.c +++ b/libavformat/matroska.c @@ -2364,6 +2364,10 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska, av_free(origdata); break; } + if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard){ + av_free(origdata); + break; + } /* time (relative to cluster time) */ time = ((data[0] << 8) | data[1]) * matroska->time_scale; diff --git a/libavformat/mov.c b/libavformat/mov.c index ff04be5f02..4ea401f95d 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1766,7 +1766,7 @@ again: } //av_log(NULL, AV_LOG_DEBUG, "chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset); - if(!sc->is_ff_stream) { + if(!sc->is_ff_stream || s->streams[sc->ffindex]->discard) { url_fskip(&s->pb, (offset - mov->next_chunk_offset)); mov->next_chunk_offset = offset; offset = 0x0FFFFFFFFFFFFFFFLL; diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index d7e94bb6db..e512752dc2 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -1533,6 +1533,8 @@ static int mpegps_read_packet(AVFormatContext *s, if (codec_id != CODEC_ID_PCM_S16BE) st->need_parsing = 1; found: + if(st->discard) + goto skip; if (startcode >= 0xa0 && startcode <= 0xbf) { int b1, freq; @@ -1555,8 +1557,8 @@ static int mpegps_read_packet(AVFormatContext *s, pkt->dts = dts; pkt->stream_index = st->index; #if 0 - av_log(s, AV_LOG_DEBUG, "%d: pts=%0.3f dts=%0.3f\n", - pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0); + av_log(s, AV_LOG_DEBUG, "%d: pts=%0.3f dts=%0.3f size=%d\n", + pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, pkt->size); #endif return 0; diff --git a/libavformat/nut.c b/libavformat/nut.c index 010e09c3bf..46fbee8aee 100644 --- a/libavformat/nut.c +++ b/libavformat/nut.c @@ -1229,6 +1229,11 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code, int fram if(size < 0) return -1; + if(s->streams[ stream_id ]->discard){ + url_fskip(bc, size); + return 1; + } + av_new_packet(pkt, size); get_buffer(bc, pkt->data, size); pkt->stream_index = stream_id; @@ -1243,7 +1248,7 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) { NUTContext *nut = s->priv_data; ByteIOContext *bc = &s->pb; - int i, frame_code=0; + int i, frame_code=0, ret; for(;;){ int64_t pos= url_ftell(bc); @@ -1281,8 +1286,11 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) reset(s, get_v(bc)); frame_code = get_byte(bc); case 0: - if(decode_frame(nut, pkt, frame_code, frame_type, pos)>=0) + ret= decode_frame(nut, pkt, frame_code, frame_type, pos); + if(ret==0) return 0; + else if(ret==1) //ok but discard packet + break; default: resync: av_log(s, AV_LOG_DEBUG, "syncing from %lld\n", nut->packet_start[2]+1); diff --git a/libavformat/rm.c b/libavformat/rm.c index f0529d0438..e6779a69a0 100644 --- a/libavformat/rm.c +++ b/libavformat/rm.c @@ -811,7 +811,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) st = s->streams[0]; } else { int seq=1; - +resync: len=sync(s, ×tamp, &flags, &i, &pos); if(len<0) return AVERROR_IO; @@ -841,6 +841,11 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) len=len2; rm->remaining_len-= len; } + + if(st->discard){ + url_fskip(pb, len); + goto resync; + } av_new_packet(pkt, len); pkt->stream_index = i; diff --git a/libavformat/utils.c b/libavformat/utils.c index a2d14fbb4b..bfc4ed366e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -821,7 +821,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) compute_pkt_fields(s, st, NULL, pkt); s->cur_st = NULL; return 0; - } else if (s->cur_len > 0) { + } else if (s->cur_len > 0 && !st->discard) { len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size, s->cur_ptr, s->cur_len, s->cur_pkt.pts, s->cur_pkt.dts);