Commit b9866ebc authored by Michael Niedermayer's avatar Michael Niedermayer

support discarding uninterresting packets

Originally committed as revision 3860 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent e19456e3
...@@ -545,11 +545,12 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -545,11 +545,12 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
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);
if (asf->stream_index < 0) { if (asf->stream_index < 0 || s->streams[asf->stream_index]->discard) {
asf->packet_time_start = 0; asf->packet_time_start = 0;
/* unhandled packet (should not happen) */ /* unhandled packet (should not happen) */
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)
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 %d\n", asf->packet_frag_size, num & 0x7f);
continue; continue;
} }
......
...@@ -106,6 +106,10 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -106,6 +106,10 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
st->codec.frame_rate_base= 1; st->codec.frame_rate_base= 1;
st->codec.frame_rate= 1000; st->codec.frame_rate= 1000;
} }
if(st->discard){
url_fskip(&s->pb, size);
continue;
}
break; break;
} }
......
...@@ -2364,6 +2364,10 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska, ...@@ -2364,6 +2364,10 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
av_free(origdata); av_free(origdata);
break; break;
} }
if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard){
av_free(origdata);
break;
}
/* time (relative to cluster time) */ /* time (relative to cluster time) */
time = ((data[0] << 8) | data[1]) * matroska->time_scale; time = ((data[0] << 8) | data[1]) * matroska->time_scale;
......
...@@ -1766,7 +1766,7 @@ again: ...@@ -1766,7 +1766,7 @@ again:
} }
//av_log(NULL, AV_LOG_DEBUG, "chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset); //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)); url_fskip(&s->pb, (offset - mov->next_chunk_offset));
mov->next_chunk_offset = offset; mov->next_chunk_offset = offset;
offset = 0x0FFFFFFFFFFFFFFFLL; offset = 0x0FFFFFFFFFFFFFFFLL;
......
...@@ -1533,6 +1533,8 @@ static int mpegps_read_packet(AVFormatContext *s, ...@@ -1533,6 +1533,8 @@ static int mpegps_read_packet(AVFormatContext *s,
if (codec_id != CODEC_ID_PCM_S16BE) if (codec_id != CODEC_ID_PCM_S16BE)
st->need_parsing = 1; st->need_parsing = 1;
found: found:
if(st->discard)
goto skip;
if (startcode >= 0xa0 && startcode <= 0xbf) { if (startcode >= 0xa0 && startcode <= 0xbf) {
int b1, freq; int b1, freq;
...@@ -1555,8 +1557,8 @@ static int mpegps_read_packet(AVFormatContext *s, ...@@ -1555,8 +1557,8 @@ static int mpegps_read_packet(AVFormatContext *s,
pkt->dts = dts; pkt->dts = dts;
pkt->stream_index = st->index; pkt->stream_index = st->index;
#if 0 #if 0
av_log(s, AV_LOG_DEBUG, "%d: pts=%0.3f dts=%0.3f\n", 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->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, pkt->size);
#endif #endif
return 0; return 0;
......
...@@ -1229,6 +1229,11 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code, int fram ...@@ -1229,6 +1229,11 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code, int fram
if(size < 0) if(size < 0)
return -1; return -1;
if(s->streams[ stream_id ]->discard){
url_fskip(bc, size);
return 1;
}
av_new_packet(pkt, size); av_new_packet(pkt, size);
get_buffer(bc, pkt->data, size); get_buffer(bc, pkt->data, size);
pkt->stream_index = stream_id; pkt->stream_index = stream_id;
...@@ -1243,7 +1248,7 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1243,7 +1248,7 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
ByteIOContext *bc = &s->pb; ByteIOContext *bc = &s->pb;
int i, frame_code=0; int i, frame_code=0, ret;
for(;;){ for(;;){
int64_t pos= url_ftell(bc); int64_t pos= url_ftell(bc);
...@@ -1281,8 +1286,11 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1281,8 +1286,11 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
reset(s, get_v(bc)); reset(s, get_v(bc));
frame_code = get_byte(bc); frame_code = get_byte(bc);
case 0: 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; return 0;
else if(ret==1) //ok but discard packet
break;
default: default:
resync: resync:
av_log(s, AV_LOG_DEBUG, "syncing from %lld\n", nut->packet_start[2]+1); av_log(s, AV_LOG_DEBUG, "syncing from %lld\n", nut->packet_start[2]+1);
......
...@@ -811,7 +811,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -811,7 +811,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
st = s->streams[0]; st = s->streams[0];
} else { } else {
int seq=1; int seq=1;
resync:
len=sync(s, &timestamp, &flags, &i, &pos); len=sync(s, &timestamp, &flags, &i, &pos);
if(len<0) if(len<0)
return AVERROR_IO; return AVERROR_IO;
...@@ -842,6 +842,11 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -842,6 +842,11 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
rm->remaining_len-= len; rm->remaining_len-= len;
} }
if(st->discard){
url_fskip(pb, len);
goto resync;
}
av_new_packet(pkt, len); av_new_packet(pkt, len);
pkt->stream_index = i; pkt->stream_index = i;
get_buffer(pb, pkt->data, len); get_buffer(pb, pkt->data, len);
......
...@@ -821,7 +821,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) ...@@ -821,7 +821,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
compute_pkt_fields(s, st, NULL, pkt); compute_pkt_fields(s, st, NULL, pkt);
s->cur_st = NULL; s->cur_st = NULL;
return 0; 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, len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size,
s->cur_ptr, s->cur_len, s->cur_ptr, s->cur_len,
s->cur_pkt.pts, s->cur_pkt.dts); s->cur_pkt.pts, s->cur_pkt.dts);
......
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