changeset 2134:16cf48c9af53 libavformat

dont rescan for information on each pid, but rather do it just once by opening 1 filter for each at the same time
author michael
date Mon, 04 Jun 2007 14:17:43 +0000
parents 2b2f5fc314e0
children 9387d2dce86f
files mpegts.c
diffstat 1 files changed, 14 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mpegts.c	Mon Jun 04 14:11:54 2007 +0000
+++ b/mpegts.c	Mon Jun 04 14:17:43 2007 +0000
@@ -110,8 +110,6 @@
     /** list of PMTs in the last PAT seen                    */
     MpegTSService **services;
 
-    /** MPEG program number of stream we want to decode      */
-    int req_sid;
 
     /** filters for various streams specified by PMT + for the PAT and PMT */
     MpegTSFilter *pids[NB_PID_MAX];
@@ -441,7 +439,7 @@
     av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x sec_num=%d/%d\n",
            h->id, h->sec_num, h->last_sec_num);
 #endif
-    if (h->tid != PMT_TID || (ts->req_sid >= 0 && h->id != ts->req_sid) )
+    if (h->tid != PMT_TID)
         return;
 
     pcr_pid = get16(&p, p_end) & 0x1fff;
@@ -538,10 +536,16 @@
         case STREAM_TYPE_AUDIO_AC3:
         case STREAM_TYPE_AUDIO_DTS:
         case STREAM_TYPE_SUBTITLE_DVB:
+            if(ts->pids[pid]){
+                assert(ts->pids[pid].type == MPEGTS_PES);
+                pes= ts->pids[pid]->u.pes_filter.opaque;
+                st= pes->st;
+            }else{
             pes = add_pes_stream(ts, pid, stream_type);
             if (pes)
                 st = new_pes_av_stream(pes, 0);
             break;
+            }
         default:
             /* we ignore the other streams */
             break;
@@ -561,7 +565,7 @@
         }
     }
     /* all parameters are there */
-    ts->stop_parse=1;
+    ts->stop_parse++;
     mpegts_close_filter(ts, filter);
 }
 
@@ -596,17 +600,14 @@
         if (sid == 0x0000) {
             /* NIT info */
         } else {
-            if (ts->req_sid == sid) {
+            ts->stop_parse--;
                 mpegts_open_section_filter(ts, pmt_pid,
                                                             pmt_cb, ts, 1);
-                goto found;
-            }
         }
     }
     /* not found */
-    ts->stop_parse=1;
+    ts->stop_parse++;
 
- found:
     mpegts_close_filter(ts, filter);
 }
 
@@ -651,9 +652,8 @@
     mpegts_close_filter(ts, filter);
 }
 
-static void mpegts_set_service(MpegTSContext *ts, int sid)
+static void mpegts_set_service(MpegTSContext *ts)
 {
-    ts->req_sid = sid;
     mpegts_open_section_filter(ts, PAT_PID,
                                                 pat_cb, ts, 1);
 }
@@ -1098,7 +1098,7 @@
     ts->stop_parse = 0;
     packet_num = 0;
     for(;;) {
-        if (ts->stop_parse)
+        if (ts->stop_parse>0)
             break;
         packet_num++;
         if (nb_packets != 0 && packet_num >= nb_packets)
@@ -1218,22 +1218,10 @@
             goto do_pcr;
         }
 
-        /* tune to first service found */
-        for(i=0; i<ts->nb_services; i++){
-            service = ts->services[i];
-            sid = service->sid;
-#ifdef DEBUG_SI
-            av_log(ts->stream, AV_LOG_DEBUG, "tuning to '%s'\n", service->name);
-#endif
-
-            /* now find the info for the first service if we found any,
-            otherwise try to filter all PATs */
-
             url_fseek(pb, pos, SEEK_SET);
-            mpegts_set_service(ts, sid);
+            mpegts_set_service(ts);
 
             handle_packets(ts, s->probesize);
-        }
         /* if could not find service, enable auto_guess */
 
         ts->auto_guess = 1;
@@ -1464,7 +1452,7 @@
     ts->pkt = pkt;
     ts->stop_parse = 0;
     for(;;) {
-        if (ts->stop_parse)
+        if (ts->stop_parse>0)
             break;
         if (len < TS_PACKET_SIZE)
             return -1;