changeset 652:b47948262721 libavformat

support discarding uninterresting packets
author michael
date Sat, 22 Jan 2005 13:36:02 +0000
parents 6a5ba24b2c6b
children c61da0556426
files asf.c flvdec.c matroska.c mov.c mpeg.c nut.c rm.c utils.c
diffstat 8 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/asf.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/asf.c	Sat Jan 22 13:36:02 2005 +0000
@@ -545,12 +545,13 @@
 	    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;
--- a/flvdec.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/flvdec.c	Sat Jan 22 13:36:02 2005 +0000
@@ -106,6 +106,10 @@
         st->codec.frame_rate_base= 1;
         st->codec.frame_rate= 1000;
     }
+    if(st->discard){
+        url_fskip(&s->pb, size);
+        continue;
+    }
     break;
  }
 
--- a/matroska.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/matroska.c	Sat Jan 22 13:36:02 2005 +0000
@@ -2364,6 +2364,10 @@
                     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;
--- a/mov.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/mov.c	Sat Jan 22 13:36:02 2005 +0000
@@ -1766,7 +1766,7 @@
     }
 
 //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;
--- a/mpeg.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/mpeg.c	Sat Jan 22 13:36:02 2005 +0000
@@ -1533,6 +1533,8 @@
     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 @@
     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;
--- a/nut.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/nut.c	Sat Jan 22 13:36:02 2005 +0000
@@ -1229,6 +1229,11 @@
     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 @@
 {
     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 @@
             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);
--- a/rm.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/rm.c	Sat Jan 22 13:36:02 2005 +0000
@@ -811,7 +811,7 @@
         st = s->streams[0];
     } else {
         int seq=1;
-
+resync:
         len=sync(s, &timestamp, &flags, &i, &pos);
         if(len<0)
             return AVERROR_IO;
@@ -841,6 +841,11 @@
                 len=len2;
             rm->remaining_len-= len;
         }
+
+        if(st->discard){
+            url_fskip(pb, len);
+            goto resync;
+        }
         
         av_new_packet(pkt, len);
         pkt->stream_index = i;
--- a/utils.c	Sat Jan 22 02:30:45 2005 +0000
+++ b/utils.c	Sat Jan 22 13:36:02 2005 +0000
@@ -821,7 +821,7 @@
                 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);