Mercurial > pt1.oyama
diff recpt1/recpt1.c @ 96:52f8e081763d
add an option to specify the necessary service IDs.
patch by Naoya OYAMA <naoya.oyama@gmail.com>, based on the code of tssplitter_lite by querulous.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 10 Feb 2010 14:33:32 +0900 |
parents | 2b55985bbb4c |
children | 4d201756c593 |
line wrap: on
line diff
--- a/recpt1/recpt1.c Tue Feb 09 06:27:01 2010 +0900 +++ b/recpt1/recpt1.c Wed Feb 10 14:33:32 2010 +0900 @@ -30,6 +30,8 @@ #include <sys/ipc.h> #include <sys/msg.h> +#include "pt1_dev.h" +#include "tssplitter_lite.h" /* maximum write length at once */ #define SIZE_CHANK 1316 @@ -60,6 +62,7 @@ time_t start_time; boolean indefinite; int msqid; + splitter *splitter; } thread_data; typedef struct msgbuf { @@ -288,16 +291,20 @@ thread_data *data = (thread_data *)p; QUEUE_T *p_queue = data->queue; decoder *dec = data->decoder; + splitter *splitter = data->splitter; int wfd = data->wfd; boolean use_b25 = dec ? TRUE : FALSE; boolean use_udp = data->sock_data ? TRUE : FALSE; boolean fileless = FALSE; + boolean use_splitter = splitter ? TRUE : FALSE; int sfd = -1; pthread_t signal_thread = data->signal_thread; struct sockaddr_in *addr = NULL; BUFSZ *qbuf; + BUFSZ splitbuf; ARIB_STD_B25_BUFFER sbuf, dbuf, buf; int code; + int split_select_finish = TSS_ERROR; if(wfd == -1) fileless = TRUE; @@ -321,6 +328,47 @@ 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) { @@ -367,13 +415,34 @@ } } - free(qbuf); + if ( 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) @@ -416,9 +485,9 @@ show_usage(char *cmd) { #ifdef HAVE_LIBARIB25 - fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] channel rectime destfile\n", cmd); + fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--split SID1,SID2] channel rectime destfile\n", cmd); #else - fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] channel rectime destfile\n", cmd); + fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--split SID1,SID2] channel rectime destfile\n", cmd); #endif fprintf(stderr, "\n"); fprintf(stderr, "Remarks:\n"); @@ -441,6 +510,7 @@ fprintf(stderr, " --port portnumber: Port number to connect\n"); fprintf(stderr, "--device devicefile: Specify devicefile to use\n"); fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n"); + fprintf(stderr, "--split SID1,SID2...,SIDN: Specify SID number in CSV format(100,101,102,...)\n"); fprintf(stderr, "--help: Show this help\n"); fprintf(stderr, "--version: Show version\n"); fprintf(stderr, "--list: Show channel list\n"); @@ -795,6 +865,7 @@ QUEUE_T *p_queue = create_queue(MAX_QUEUE); BUFSZ *bufptr; decoder *dec = NULL; + splitter *splitter = NULL; static thread_data tdata; decoder_options dopt = { 4, /* round */ @@ -824,6 +895,7 @@ { "help", 0, NULL, 'h'}, { "version", 0, NULL, 'v'}, { "list", 0, NULL, 'l'}, + { "split", 1, NULL, 'i'}, {0, 0, NULL, 0} /* terminate */ }; @@ -831,12 +903,14 @@ boolean use_udp = FALSE; boolean fileless = FALSE; boolean use_stdout = FALSE; + boolean use_splitter = FALSE; char *host_to = NULL; int port_to = 1234; sock_data *sockdata = NULL; char *device = NULL; int val; char *voltage[] = {"0V", "11V", "15V"}; + char *sid_list = NULL; while((result = getopt_long(argc, argv, "br:smn:ua:p:d:hvl", long_options, &option_index)) != -1) { @@ -910,6 +984,10 @@ device = optarg; fprintf(stderr, "using device: %s\n", device); break; + case 'i': + use_splitter = TRUE; + sid_list = optarg; + break; } } @@ -970,6 +1048,16 @@ use_b25 = 0; } } + /* initialize splitter */ + if(use_splitter) + { + splitter = split_startup(sid_list); + if ( splitter->sid_list == NULL ) + { + fprintf(stderr, "Cannot start TS splitter\n"); + return(1); + } + } /* initialize udp connection */ if(use_udp) { @@ -1003,6 +1091,7 @@ /* prepare thread data */ tdata.queue = p_queue; tdata.decoder = dec; + tdata.splitter = splitter; tdata.sock_data = sockdata; /* spawn signal handler thread */ @@ -1109,6 +1198,9 @@ if(use_b25) { b25_shutdown(dec); } + if(use_splitter) { + split_shutdown(splitter); + } return 0; }