diff recpt1/recpt1.c @ 99:3a3f15b063e1

now recpt1 accepts single sid for terrestrial channels. technical summary: - mark pid to record instead of pid to drop - split after decoding for now
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 12 Feb 2010 21:40:21 +0900
parents 3fd15032fd3a
children aeba1988234f
line wrap: on
line diff
--- a/recpt1/recpt1.c	Wed Feb 10 15:02:25 2010 +0900
+++ b/recpt1/recpt1.c	Fri Feb 12 21:40:21 2010 +0900
@@ -301,11 +301,15 @@
     pthread_t signal_thread = data->signal_thread;
     struct sockaddr_in *addr = NULL;
     BUFSZ *qbuf;
-    BUFSZ splitbuf;
+    splitbuf_t splitbuf;
     ARIB_STD_B25_BUFFER sbuf, dbuf, buf;
     int code;
     int split_select_finish = TSS_ERROR;
 
+    buf.size = 0;
+    buf.data = NULL;
+    splitbuf.size = 0;
+
     if(wfd == -1)
         fileless = TRUE;
 
@@ -328,47 +332,6 @@
 
         buf = sbuf; /* default */
 
-        if ( use_splitter )
-        {
-            /* $BJ,N%BP>](BPID$B$NCj=P(B */
-            if ( split_select_finish != TSS_SUCCESS )
-            {
-                split_select_finish = split_select(splitter, &sbuf);
-                if ( split_select_finish == TSS_NULL )
-                {
-                    /* malloc$B%(%i!<H/@8(B */
-                    use_splitter = FALSE;
-                }
-                else if ( split_select_finish != TSS_SUCCESS )
-                {
-                    /* $BJ,N%BP>](BPID$B$,40A4$KCj=P$G$-$k$^$G=PNO$7$J$$(B
-                     * 1$BICDxEYM>M5$r8+$k$H$$$$$+$b(B
-                     */
-                    free(qbuf);
-                    qbuf = NULL;
-                    continue;
-                }
-            }
-            /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
-            code = split_ts(splitter, &sbuf, &splitbuf);
-            if ( code != TSS_SUCCESS )
-            {
-                free(qbuf);
-                qbuf = NULL;
-                continue;
-            }
-            /* $BJ,N%7k2L$,%<%m%P%$%H$G$"$k>l9g$K$O(Bb25$B$K2s$5$J$$(B */
-            if ( splitbuf.size == 0 )
-            {
-                free(qbuf);
-                qbuf = NULL;
-                continue;
-            }
-            sbuf.data = splitbuf.buffer;
-            sbuf.size = splitbuf.size;
-            buf = sbuf;
-        }
-
         if(use_b25) {
             code = b25_decode(dec, &sbuf, &dbuf);
             if(code < 0) {
@@ -379,12 +342,52 @@
                 buf = dbuf;
         }
 
+
+        if(use_splitter) {
+            splitbuf.size = 0;
+
+            while(buf.size) {
+                /* $BJ,N%BP>](BPID$B$NCj=P(B */
+                if(split_select_finish != TSS_SUCCESS) {
+                    split_select_finish = split_select(splitter, &buf);
+                    if(split_select_finish == TSS_NULL) {
+                        /* malloc$B%(%i!<H/@8(B */
+                        fprintf(stderr, "split_select malloc failed\n");
+                        use_splitter = FALSE;
+                        goto fin;
+                    }
+                    else if(split_select_finish != TSS_SUCCESS) {
+                        /* $BJ,N%BP>](BPID$B$,40A4$KCj=P$G$-$k$^$G=PNO$7$J$$(B
+                         * 1$BICDxEYM>M5$r8+$k$H$$$$$+$b(B
+                         */
+                        break;
+                    }
+                }
+                /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
+                code = split_ts(splitter, &buf, &splitbuf);
+                if(code != TSS_SUCCESS) {
+                    fprintf(stderr, "split_ts failed\n");
+                    break;
+                }
+
+                break;
+            } /* while */
+
+            buf.size = splitbuf.size;
+            buf.data = splitbuf.buffer;
+        fin:
+            ;
+        } /* if */
+
+
         if(!fileless) {
             /* write data to output file */
             int size_remain = buf.size;
             int offset = 0;
+
             while(size_remain > 0) {
                 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK;
+
                 wc = write(wfd, buf.data + offset, ws);
                 if(wc < 0) {
                     perror("write");
@@ -415,34 +418,14 @@
             }
         }
 
-        if ( qbuf != NULL ) {
-            free(qbuf);
-            qbuf = NULL;
-        }
+        free(qbuf);
+        qbuf = NULL;
 
         /* normal exit */
         if((f_exit && !p_queue->num_used) || file_err) {
 
             buf = sbuf; /* default */
 
-            if ( use_splitter )
-            {
-                /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
-                code = split_ts(splitter, &sbuf, &splitbuf);
-                if ( code != TSS_SUCCESS )
-                {
-                    break;
-                }
-                /* $BJ,N%7k2L$,%<%m%P%$%H$G$"$k>l9g$K$O(Bb25$B$K2s$5$J$$(B */
-                if ( splitbuf.size == 0 )
-                {
-                    break;
-                }
-                sbuf.data = splitbuf.buffer;
-                sbuf.size = splitbuf.size;
-                buf = sbuf;
-            }
-
             if(use_b25) {
                 code = b25_finish(dec, &sbuf, &dbuf);
                 if(code < 0)
@@ -451,6 +434,17 @@
                     buf = dbuf;
             }
 
+            if(use_splitter) {
+                /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */
+                code = split_ts(splitter, &buf, &splitbuf);
+                if(code != TSS_SUCCESS) {
+                    break;
+                }
+
+                buf.data = splitbuf.buffer;
+                buf.size = splitbuf.size;
+            }
+
             if(!fileless && !file_err) {
                 wc = write(wfd, buf.data, buf.size);
                 if(wc < 0) {