OSDN Git Service

fix error when working with PMT having specific af mode.
[rec10/rec10-git.git] / jTsSplitter / trunk / src / jtssplitter / Tsfile.java
index 5394a86..941bb9a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * jTsSplitter - java based mpeg2ts splitter.
- * Copyright (C) 2009-2010 Yukikaze
+ * Copyright (C) 2009-2012 Yukikaze
  */
 
 package jtssplitter;
@@ -69,7 +69,9 @@ public class Tsfile {
                                 pats=m2tp2.getPAT();
                                 boolean containp_table=false;
                                 for (int iii=0;iii<pats.size();iii++){
-                                    if (pats.get(iii).Program_TABLE==p_table && csch!=0){
+                                    if (pats.get(iii).Program_TABLE==p_table){
+                                        containp_table=true;
+                                    }else if (csch > 0){
                                         containp_table=true;
                                     }
                                 }
@@ -103,7 +105,12 @@ public class Tsfile {
                                 //wbyte=wbytet;*/
                             }else if ((ii==pmt_pid)&&(readti>187)){
                                 wbyte=tb;
-                                ArrayList<PMTData> pmtss=m2tpp.readPMTglobal_byte(tb, pmt_pid);
+                                ArrayList<PMTData> pmtss;
+                                try{
+                                    pmtss=m2tpp.readPMTglobal_byte(tb, pmt_pid);
+                                }catch(NullPointerException e){
+                                    pmtss=new ArrayList<PMTData>();
+                                }
                                 if (pmtss.size()>0){
                                     int[] new_pids=new int[pmtss.size()+3];
                                     new_pids[pmtss.size()]=0;
@@ -245,6 +252,67 @@ public class Tsfile {
         }
         return pids;
     }
+    public Integer[] getProgramNum_byte(String fpath){
+            /**
+             * PIDを取得し、これと思われる必要なPIDを抜き出す。
+             * @return プログラム番号(return[0])とPIDのリスト(return[1-])
+             */
+            FileInputStream in = null;
+            ArrayList<Integer> retti = new ArrayList<Integer>();
+            byte[] tb = new byte[188];
+            ArrayList<PATData> pat = new ArrayList<PATData>();
+            ArrayList<PATData> pat_ok = new ArrayList<PATData>();
+            ArrayList<PMTData> pmt = new ArrayList<PMTData>();
+            try {
+            in = new FileInputStream(fpath);
+            int imax = 7000;
+            int mmax = 20000;
+            for (int i = 0; i < imax; i++) {
+                if (in.read(tb) == -1) {
+                    in.close();
+                    System.out.println("Program Table not found.");
+                    System.exit(1);
+                }
+                String last8;
+                Mpeg2TSPacket m2tp;
+                m2tp = new Mpeg2TSPacket();
+                m2tp.setPAT(pat);
+                m2tp.setPMT(pmt);
+                m2tp.readTS_byte(tb);
+                pat = m2tp.getPAT();
+                pmt = m2tp.getPMT();
+                ArrayList<PMTData> pmtt=m2tp.getPMT();
+                for (int i2=0;i2<pmtt.size();i2++){
+                    if (!(pmt.contains(pmtt.get(i2)))){
+                        pmt.add(pmtt.get(i2));
+                    }
+                }
+
+                if (i>imax-10 && pat_ok.size()==0 && i<mmax){
+                    imax=imax+100;
+                }
+                for (int i3=0;i3<pmt.size();i3++){
+                    if (pmt.get(i3).Stream_Type==0x02){
+                        for (int i4=0;i4<pat.size();i4++){
+                            if (pmt.get(i3).Program_Table==pat.get(i4).Program_TABLE && !(pat_ok.contains(pat.get(i4)))){
+                                pat_ok.add(pat.get(i4));
+                            }
+                        }
+                    }
+                }
+            }
+            for (int i5 = 0; i5 < pat_ok.size(); i5++) {
+                PATData patdd = pat_ok.get(i5);
+                if ((patdd.Program_TABLE != 0) &&(!(retti.contains(patdd.Program_TABLE)))){
+                    retti.add(patdd.Program_TABLE);
+                }
+            }
+        } catch (IOException ex) {
+            Logger.getLogger(Tsfile.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        Integer[] rt=retti.toArray(new Integer[retti.size()]);
+        return rt;
+    }
     private int getFirstP_Table_byte(String fpath){
         /**
          * PIDを取得し、これと思われる必要なPIDを抜き出す。