Mercurial > pt1.oyama
comparison src/recpt1.c @ 134:c4e0a5777363
add DLNA arg. (--dlna)
modify waits when stream_queue is empry.
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Mon, 18 Oct 2010 03:56:39 +0900 |
parents | 0db6ccf0fe31 |
children | 519a035533f6 |
comparison
equal
deleted
inserted
replaced
133:0db6ccf0fe31 | 134:c4e0a5777363 |
---|---|
220 void | 220 void |
221 enqueue(QUEUE_T *p_queue, BUFSZ *data) | 221 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
222 { | 222 { |
223 struct timeval now; | 223 struct timeval now; |
224 struct timespec spec; | 224 struct timespec spec; |
225 //fprintf (stderr, "enqueue() start.\n"); | |
226 | 225 |
227 gettimeofday(&now, NULL); | 226 gettimeofday(&now, NULL); |
228 spec.tv_sec = now.tv_sec + 1; | 227 spec.tv_sec = now.tv_sec + 1; |
229 spec.tv_nsec = now.tv_usec * 1000; | 228 spec.tv_nsec = now.tv_usec * 1000; |
230 | 229 |
231 //fprintf (stderr, "enqueue() mutex lock try. num_used[%d] num_avail[%d]\n", p_queue->num_used, p_queue->num_avail); | |
232 pthread_mutex_lock(&p_queue->mutex); | 230 pthread_mutex_lock(&p_queue->mutex); |
233 //fprintf (stderr, "enqueue() mutex lock success. num_used[%d] num_avail[%d]\n", p_queue->num_used, p_queue->num_avail); | |
234 /* entered critical section */ | 231 /* entered critical section */ |
235 | 232 |
236 /* wait while queue is full */ | 233 /* wait while queue is full */ |
237 while(p_queue->num_avail == 0) { | 234 while(p_queue->num_avail == 0) { |
238 pthread_cond_timedwait(&p_queue->cond_avail, | 235 pthread_cond_timedwait(&p_queue->cond_avail, |
252 /* update counters */ | 249 /* update counters */ |
253 p_queue->num_avail--; | 250 p_queue->num_avail--; |
254 p_queue->num_used++; | 251 p_queue->num_used++; |
255 | 252 |
256 /* leaving critical section */ | 253 /* leaving critical section */ |
257 //fprintf (stderr, "enqueue() mutex unlock. num_used[%d]\n", p_queue->num_used); | |
258 pthread_mutex_unlock(&p_queue->mutex); | 254 pthread_mutex_unlock(&p_queue->mutex); |
259 pthread_cond_signal(&p_queue->cond_used); | 255 pthread_cond_signal(&p_queue->cond_used); |
260 } | 256 } |
261 | 257 |
262 /* | 258 /* |
269 stream_enqueue(STREAM_QUEUE_T *p_queue, ARIB_STD_B25_BUFFER *data) | 265 stream_enqueue(STREAM_QUEUE_T *p_queue, ARIB_STD_B25_BUFFER *data) |
270 { | 266 { |
271 struct timeval now; | 267 struct timeval now; |
272 struct timespec spec; | 268 struct timespec spec; |
273 int i; | 269 int i; |
274 //fprintf (stderr, "stream_enqueue() start.\n"); | |
275 | 270 |
276 gettimeofday(&now, NULL); | 271 gettimeofday(&now, NULL); |
277 spec.tv_sec = now.tv_sec + 1; | 272 spec.tv_sec = now.tv_sec + 1; |
278 spec.tv_nsec = now.tv_usec * 1000; | 273 spec.tv_nsec = now.tv_usec * 1000; |
279 | 274 |
280 //fprintf (stderr, "stream_enqueue() mutex lock try. num_used[%d]\n", p_queue->num_used); | |
281 pthread_mutex_lock(&p_queue->mutex); | 275 pthread_mutex_lock(&p_queue->mutex); |
282 //fprintf (stderr, "stream_enqueue() mutex lock success. num_used[%d]\n", p_queue->num_used); | |
283 /* entered critical section */ | 276 /* entered critical section */ |
284 | 277 |
285 if (p_queue->num_avail == 0) { | 278 if (p_queue->num_avail == 0) { |
286 //fprintf (stderr, "stream_enqueue() num_used reach max[%d].\n", p_queue->num_used); | |
287 /* stream queue $B$O0lGU$K$J$C$?$i>C5n$7$F$7$^$&(B */ | 279 /* stream queue $B$O0lGU$K$J$C$?$i>C5n$7$F$7$^$&(B */ |
288 for ( i=0; i < p_queue->size; i++ ) { | 280 for ( i=0; i < p_queue->size; i++ ) { |
289 if ( p_queue->buffer[i] != NULL ) { | 281 if ( p_queue->buffer[i] != NULL ) { |
290 free(p_queue->buffer[i]->data); | 282 free(p_queue->buffer[i]->data); |
291 p_queue->buffer[i]->data = NULL; | 283 p_queue->buffer[i]->data = NULL; |
308 /* update counters */ | 300 /* update counters */ |
309 p_queue->num_avail--; | 301 p_queue->num_avail--; |
310 p_queue->num_used++; | 302 p_queue->num_used++; |
311 | 303 |
312 /* leaving critical section */ | 304 /* leaving critical section */ |
313 //fprintf (stderr, "stream_enqueue() mutex unlock.\n"); | |
314 pthread_mutex_unlock(&p_queue->mutex); | 305 pthread_mutex_unlock(&p_queue->mutex); |
315 pthread_cond_signal(&p_queue->cond_used); | 306 pthread_cond_signal(&p_queue->cond_used); |
316 } | 307 } |
317 | 308 |
318 /* dequeue data. this function will block if queue is empty. */ | 309 /* dequeue data. this function will block if queue is empty. */ |
321 { | 312 { |
322 struct timeval now; | 313 struct timeval now; |
323 struct timespec spec; | 314 struct timespec spec; |
324 BUFSZ *buffer; | 315 BUFSZ *buffer; |
325 | 316 |
326 //fprintf (stderr, "dequeue() start.\n"); | |
327 gettimeofday(&now, NULL); | 317 gettimeofday(&now, NULL); |
328 spec.tv_sec = now.tv_sec + 1; | 318 spec.tv_sec = now.tv_sec + 1; |
329 spec.tv_nsec = now.tv_usec * 1000; | 319 spec.tv_nsec = now.tv_usec * 1000; |
330 | 320 |
331 //fprintf (stderr, "dequeue() mutex lock try. num_used[%d]\n", p_queue->num_used); | |
332 pthread_mutex_lock(&p_queue->mutex); | 321 pthread_mutex_lock(&p_queue->mutex); |
333 //fprintf (stderr, "dequeue() mutex lock success. num_used[%d]\n", p_queue->num_used); | |
334 /* entered the critical section*/ | 322 /* entered the critical section*/ |
335 | 323 |
336 /* wait while queue is empty */ | 324 /* wait while queue is empty */ |
337 while(p_queue->num_used == 0) { | 325 while(p_queue->num_used == 0) { |
338 pthread_cond_timedwait(&p_queue->cond_used, | 326 pthread_cond_timedwait(&p_queue->cond_used, |
353 /* update counters */ | 341 /* update counters */ |
354 p_queue->num_avail++; | 342 p_queue->num_avail++; |
355 p_queue->num_used--; | 343 p_queue->num_used--; |
356 | 344 |
357 /* leaving the critical section */ | 345 /* leaving the critical section */ |
358 //fprintf (stderr, "dequeue() mutex unlock.\n"); | |
359 pthread_mutex_unlock(&p_queue->mutex); | 346 pthread_mutex_unlock(&p_queue->mutex); |
360 pthread_cond_signal(&p_queue->cond_avail); | 347 pthread_cond_signal(&p_queue->cond_avail); |
361 | 348 |
362 return buffer; | 349 return buffer; |
363 } | 350 } |
364 | 351 |
352 #define QUQUE_LOW_MIN (100) | |
353 #define QUEUE_LOW_USLEEP (800*1000) | |
365 ARIB_STD_B25_BUFFER * | 354 ARIB_STD_B25_BUFFER * |
366 stream_dequeue(STREAM_QUEUE_T *p_queue) | 355 stream_dequeue(STREAM_QUEUE_T *p_queue) |
367 { | 356 { |
368 struct timeval now; | 357 struct timeval now; |
369 struct timespec spec; | 358 struct timespec spec; |
370 ARIB_STD_B25_BUFFER *buffer; | 359 ARIB_STD_B25_BUFFER *buffer; |
371 | 360 |
372 //fprintf (stderr, "stream_dequeue() start.\n"); | |
373 gettimeofday(&now, NULL); | 361 gettimeofday(&now, NULL); |
374 spec.tv_sec = now.tv_sec + 1; | 362 spec.tv_sec = now.tv_sec + 1; |
375 spec.tv_nsec = now.tv_usec * 1000; | 363 spec.tv_nsec = now.tv_usec * 1000; |
376 | 364 |
377 //fprintf (stderr, "stream_dequeue() mutex lock try. num_used[%d]\n", p_queue->num_used); | |
378 pthread_mutex_lock(&p_queue->mutex); | 365 pthread_mutex_lock(&p_queue->mutex); |
379 //fprintf (stderr, "stream_dequeue() mutex lock success. num_used[%d]\n", p_queue->num_used); | |
380 /* entered the critical section*/ | 366 /* entered the critical section*/ |
381 | 367 |
382 /* wait while queue is empty */ | 368 /* wait while queue is empty */ |
383 while(p_queue->num_used == 0) { | 369 while(p_queue->num_used == 0) { |
384 pthread_cond_timedwait(&p_queue->cond_used, | 370 pthread_cond_timedwait(&p_queue->cond_used, |
400 p_queue->num_avail++; | 386 p_queue->num_avail++; |
401 p_queue->num_used--; | 387 p_queue->num_used--; |
402 | 388 |
403 /* leaving the critical section */ | 389 /* leaving the critical section */ |
404 pthread_mutex_unlock(&p_queue->mutex); | 390 pthread_mutex_unlock(&p_queue->mutex); |
405 //fprintf (stderr, "stream_dequeue() mutex unlock.\n"); | |
406 pthread_cond_signal(&p_queue->cond_avail); | 391 pthread_cond_signal(&p_queue->cond_avail); |
407 //fprintf (stderr, "dequeue() finish.\n"); | 392 |
408 | 393 if ( p_queue->num_used < QUQUE_LOW_MIN ) { |
394 /* force sleep 800msec */ | |
395 usleep(QUEUE_LOW_USLEEP); | |
396 } | |
409 return buffer; | 397 return buffer; |
410 } | 398 } |
411 | 399 |
412 /* this function will be reader thread */ | 400 /* this function will be reader thread */ |
413 void * | 401 void * |
420 int wfd = data->wfd; | 408 int wfd = data->wfd; |
421 boolean use_b25 = dec ? TRUE : FALSE; | 409 boolean use_b25 = dec ? TRUE : FALSE; |
422 boolean use_udp = data->sock_data ? TRUE : FALSE; | 410 boolean use_udp = data->sock_data ? TRUE : FALSE; |
423 boolean fileless = FALSE; | 411 boolean fileless = FALSE; |
424 boolean use_splitter = splitter ? TRUE : FALSE; | 412 boolean use_splitter = splitter ? TRUE : FALSE; |
425 boolean use_streaming = TRUE; // $BK\Ev$O0z?t$K$9$k$3$H(B | 413 boolean use_dlna = data->streamer ? TRUE : FALSE; |
426 int sfd = -1; | 414 int sfd = -1; |
427 pthread_t signal_thread = data->signal_thread; | 415 pthread_t signal_thread = data->signal_thread; |
428 struct sockaddr_in *addr = NULL; | 416 struct sockaddr_in *addr = NULL; |
429 BUFSZ *qbuf; | 417 BUFSZ *qbuf; |
430 ARIB_STD_B25_BUFFER *eqbuf; | 418 ARIB_STD_B25_BUFFER *eqbuf; |
444 sfd = data->sock_data->sfd; | 432 sfd = data->sock_data->sfd; |
445 addr = &data->sock_data->addr; | 433 addr = &data->sock_data->addr; |
446 } | 434 } |
447 | 435 |
448 while(1) { | 436 while(1) { |
449 // fprintf (stderr, "reader_func() while loop\n"); | |
450 ssize_t wc = 0; | 437 ssize_t wc = 0; |
451 int file_err = 0; | 438 int file_err = 0; |
452 //fprintf (stderr, "reader_func() dequeue() start.\n"); | |
453 qbuf = dequeue(p_queue); | 439 qbuf = dequeue(p_queue); |
454 //fprintf (stderr, "reader_func() dequeue() finish.\n"); | |
455 /* no entry in the queue */ | 440 /* no entry in the queue */ |
456 if(qbuf == NULL) { | 441 if(qbuf == NULL) { |
457 break; | 442 break; |
458 } | 443 } |
459 | 444 |
524 * 2.2.2 2.2.1$B$G(Balloc$B$7$?NN0h$K(B rader_func $B$,(B dequeue $B$7$?%9%H%j!<%`$J%G!<%?$r(Bmemcpy()$B$9$k(B | 509 * 2.2.2 2.2.1$B$G(Balloc$B$7$?NN0h$K(B rader_func $B$,(B dequeue $B$7$?%9%H%j!<%`$J%G!<%?$r(Bmemcpy()$B$9$k(B |
525 * 2.2.3 tdata->stream_queue $B$K(B 2.2.1 $B$N%]%$%s%?$r(B enqueue() $B$9$k(B | 510 * 2.2.3 tdata->stream_queue $B$K(B 2.2.1 $B$N%]%$%s%?$r(B enqueue() $B$9$k(B |
526 * 2.2.3.1 enqueue() $B$O(B tdata->stream_queue->mutex $B$r(B lock/unlock $B$7$F=q$-9~$_;~$NF1;~99?7$rKI;_$7$F$$$k(B | 511 * 2.2.3.1 enqueue() $B$O(B tdata->stream_queue->mutex $B$r(B lock/unlock $B$7$F=q$-9~$_;~$NF1;~99?7$rKI;_$7$F$$$k(B |
527 */ | 512 */ |
528 //fprintf (stderr, "reader_func() buf.size[%d]\n", buf.size); | 513 //fprintf (stderr, "reader_func() buf.size[%d]\n", buf.size); |
529 if ( use_streaming && buf.size > 0 ) { | 514 if ( use_dlna && buf.size > 0 ) { |
530 do { | 515 do { |
531 eqbuf = malloc(sizeof(ARIB_STD_B25_BUFFER)); | 516 eqbuf = malloc(sizeof(ARIB_STD_B25_BUFFER)); |
532 if ( eqbuf == NULL ) { | 517 if ( eqbuf == NULL ) { |
533 fprintf (stderr, "Cannot malloc eqbuf memory. streaming abort.\n"); | 518 fprintf (stderr, "Cannot malloc eqbuf memory. streaming abort.\n"); |
534 use_streaming = FALSE; | 519 use_dlna = FALSE; |
535 break; | 520 break; |
536 } | 521 } |
537 eqbuf->data = malloc(buf.size); | 522 eqbuf->data = malloc(buf.size); |
538 if ( eqbuf->data == NULL ) { | 523 if ( eqbuf->data == NULL ) { |
539 fprintf (stderr, "Cannot malloc eqbuf memory. streaming abort.\n"); | 524 fprintf (stderr, "Cannot malloc eqbuf memory. streaming abort.\n"); |
540 use_streaming = FALSE; | 525 use_dlna = FALSE; |
541 break; | 526 break; |
542 } | 527 } |
543 eqbuf->size = buf.size; | 528 eqbuf->size = buf.size; |
544 memcpy(eqbuf->data, buf.data, buf.size); | 529 memcpy(eqbuf->data, buf.data, buf.size); |
545 // $B$3$A$i$b0n$l$?$i>C5n$7$F$7$^$&(B stream_enqueue() $B$r;HMQ(B | 530 // $B$3$A$i$b0n$l$?$i>C5n$7$F$7$^$&(B stream_enqueue() $B$r;HMQ(B |
681 // 3.1 tdata->stream_queue $B$+$i(B dequeue $B$9$k(B | 666 // 3.1 tdata->stream_queue $B$+$i(B dequeue $B$9$k(B |
682 // dequeue $B$7$?%G!<%?$O(B ARIB_STD_B25_BUFFER | 667 // dequeue $B$7$?%G!<%?$O(B ARIB_STD_B25_BUFFER |
683 qbuf = stream_dequeue(p_queue); | 668 qbuf = stream_dequeue(p_queue); |
684 /* no entry in the queue */ | 669 /* no entry in the queue */ |
685 if(qbuf == NULL) { | 670 if(qbuf == NULL) { |
686 //fprintf (stderr, "stream_func(): dequeue() return NULL pointer. streaming abort.\n"); | |
687 continue; | 671 continue; |
688 } | 672 } |
689 data->streamer->total_byte += qbuf->size; | 673 data->streamer->total_byte += qbuf->size; |
690 // $B%/%j%F%#%+%k%;%/%7%g%sD9$$$N$J$s$H$+$7$?$$$J$!!D(B | 674 // $B%/%j%F%#%+%k%;%/%7%g%sD9$$$N$J$s$H$+$7$?$$$J$!!D(B |
691 // ToDo: memcpy $B$H$+%/%j%F%#%+%k%;%/%7%g%s$N30$K=P$9(B | 675 // ToDo: memcpy $B$H$+%/%j%F%#%+%k%;%/%7%g%s$N30$K=P$9(B |
692 // 3.2 tdata->streamer->mutex $B$r(B lock | 676 // 3.2 tdata->streamer->mutex $B$r(B lock |
693 //fprintf (stderr, "stream_func(): mutex lock try.\n"); | |
694 pthread_mutex_lock(&data->streamer->mutex); | 677 pthread_mutex_lock(&data->streamer->mutex); |
695 //fprintf (stderr, "stream_func(): mutex lock success.\n"); | |
696 // 3.3 $B0J2<$r(B tdata->streamer->stream_nr $B$N?t$@$1%k!<%W(B | 678 // 3.3 $B0J2<$r(B tdata->streamer->stream_nr $B$N?t$@$1%k!<%W(B |
697 for ( i=0; i < data->streamer->stream_nr; i++ ) { | 679 for ( i=0; i < data->streamer->stream_nr; i++ ) { |
698 // 3.3.1 tdata->streamer->stream_session[N]->is_valid $B$,M-8z$+3NG'(B | 680 // 3.3.1 tdata->streamer->stream_session[N]->is_valid $B$,M-8z$+3NG'(B |
699 if ( data->streamer->stream_session[i] != NULL ) { | 681 if ( data->streamer->stream_session[i] != NULL ) { |
700 if ( data->streamer->stream_session[i]->is_valid ) { | 682 if ( data->streamer->stream_session[i]->is_valid ) { |
722 } | 704 } |
723 // 3.4 tdata->streamer->mutex $B$r(B unlock | 705 // 3.4 tdata->streamer->mutex $B$r(B unlock |
724 pthread_mutex_unlock(&data->streamer->mutex); | 706 pthread_mutex_unlock(&data->streamer->mutex); |
725 free(qbuf->data); | 707 free(qbuf->data); |
726 free(qbuf); | 708 free(qbuf); |
727 //fprintf (stderr, "stream_func(): mutex unlock.\n"); | |
728 } | 709 } |
729 return NULL; | 710 return NULL; |
730 } | 711 } |
731 | 712 |
732 void | 713 void |
733 show_usage(char *cmd) | 714 show_usage(char *cmd) |
734 { | 715 { |
735 #ifdef HAVE_LIBARIB25 | 716 #ifdef HAVE_LIBARIB25 |
736 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] [--es filename_suffix] [--start_time YYYYMMDDHHMISS] channel rectime destfile\n", cmd); | 717 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] [--es filename_suffix] [--start_time YYYYMMDDHHMISS] [--dlna] channel rectime destfile\n", cmd); |
737 #else | 718 #else |
738 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] [--es filename_suffix] [--start_time YYYYMMDDHHMISS] channel rectime destfile\n", cmd); | 719 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] [--sid SID1,SID2] [--es filename_suffix] [--start_time YYYYMMDDHHMISS] [--dlna] channel rectime destfile\n", cmd); |
739 #endif | 720 #endif |
740 fprintf(stderr, "\n"); | 721 fprintf(stderr, "\n"); |
741 fprintf(stderr, "Remarks:\n"); | 722 fprintf(stderr, "Remarks:\n"); |
742 fprintf(stderr, "if rectime is '-', records indefinitely.\n"); | 723 fprintf(stderr, "if rectime is '-', records indefinitely.\n"); |
743 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); | 724 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); |
759 fprintf(stderr, "--device devicefile: Specify devicefile to use\n"); | 740 fprintf(stderr, "--device devicefile: Specify devicefile to use\n"); |
760 fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n"); | 741 fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n"); |
761 fprintf(stderr, "--sid SID1,SID2,...: Specify SID number in CSV format (101,102,...)\n"); | 742 fprintf(stderr, "--sid SID1,SID2,...: Specify SID number in CSV format (101,102,...)\n"); |
762 fprintf(stderr, " --es filename: Specify ES out filename prefix\n"); | 743 fprintf(stderr, " --es filename: Specify ES out filename prefix\n"); |
763 fprintf(stderr, " --start_time YYYYMMDDHHMISS: Specify record start datetime\n"); | 744 fprintf(stderr, " --start_time YYYYMMDDHHMISS: Specify record start datetime\n"); |
745 fprintf(stderr, "--dlna: Turn on DLNA DMS(Digital Media Server)\n"); | |
764 fprintf(stderr, "--help: Show this help\n"); | 746 fprintf(stderr, "--help: Show this help\n"); |
765 fprintf(stderr, "--version: Show version\n"); | 747 fprintf(stderr, "--version: Show version\n"); |
766 fprintf(stderr, "--list: Show channel list\n"); | 748 fprintf(stderr, "--list: Show channel list\n"); |
767 } | 749 } |
768 | 750 |
874 } | 856 } |
875 | 857 |
876 void | 858 void |
877 cleanup(thread_data *tdata) | 859 cleanup(thread_data *tdata) |
878 { | 860 { |
879 int use_dlna = TRUE; | 861 boolean use_dlna = tdata->streamer ? TRUE : FALSE; |
880 /* stop recording */ | 862 /* stop recording */ |
881 ioctl(tdata->tfd, STOP_REC, 0); | 863 ioctl(tdata->tfd, STOP_REC, 0); |
882 | 864 |
883 /* xxx need mutex? */ | 865 /* xxx need mutex? */ |
884 f_exit = TRUE; | 866 f_exit = TRUE; |
970 | 952 |
971 /* open tuner */ | 953 /* open tuner */ |
972 /* case 1: specified tuner device */ | 954 /* case 1: specified tuner device */ |
973 if(device) { | 955 if(device) { |
974 tdata->tfd = open(device, O_RDONLY); | 956 tdata->tfd = open(device, O_RDONLY); |
975 tdata->device_id = get_device_id_by_name(device); | 957 tdata->device_id = get_device_id_by_name(device); |
976 if(tdata->tfd < 0) { | 958 if(tdata->tfd < 0) { |
977 fprintf(stderr, "Cannot open tuner device: %s\n", device); | 959 fprintf(stderr, "Cannot open tuner device: %s\n", device); |
978 return 1; | 960 return 1; |
979 } | 961 } |
980 | 962 |
1161 { "sid", 1, NULL, 'i'}, | 1143 { "sid", 1, NULL, 'i'}, |
1162 { "SID", 1, NULL, 'i'}, | 1144 { "SID", 1, NULL, 'i'}, |
1163 { "es", 1, NULL, 'e'}, | 1145 { "es", 1, NULL, 'e'}, |
1164 { "ES", 1, NULL, 'e'}, | 1146 { "ES", 1, NULL, 'e'}, |
1165 { "start_time", 1, NULL, 'y'}, | 1147 { "start_time", 1, NULL, 'y'}, |
1148 { "dlna", 0, NULL, 'c'}, | |
1149 { "DLNA", 0, NULL, 'c'}, | |
1166 {0, 0, NULL, 0} /* terminate */ | 1150 {0, 0, NULL, 0} /* terminate */ |
1167 }; | 1151 }; |
1168 | 1152 |
1169 boolean use_b25 = FALSE; | 1153 boolean use_b25 = FALSE; |
1170 boolean use_udp = FALSE; | 1154 boolean use_udp = FALSE; |
1171 boolean fileless = FALSE; | 1155 boolean fileless = FALSE; |
1172 boolean use_stdout = FALSE; | 1156 boolean use_stdout = FALSE; |
1173 boolean use_splitter = FALSE; | 1157 boolean use_splitter = FALSE; |
1158 boolean use_esout = FALSE; | |
1159 boolean use_dlna = FALSE; | |
1174 char *host_to = NULL; | 1160 char *host_to = NULL; |
1175 int port_to = 1234; | 1161 int port_to = 1234; |
1176 sock_data *sockdata = NULL; | 1162 sock_data *sockdata = NULL; |
1177 char *device = NULL; | 1163 char *device = NULL; |
1178 int val; | 1164 int val; |
1179 char *voltage[] = {"0V", "11V", "15V"}; | 1165 char *voltage[] = {"0V", "11V", "15V"}; |
1180 char *sid_list = NULL; | 1166 char *sid_list = NULL; |
1181 char *es_name_prefix = NULL; | 1167 char *es_name_prefix = NULL; |
1182 char *start_time = NULL; | 1168 char *start_time = NULL; |
1183 | 1169 |
1184 while((result = getopt_long(argc, argv, "br:smn:ua:p:d:hvli:", | 1170 while((result = getopt_long(argc, argv, "br:smn:ua:p:d:hvli:y:c", |
1185 long_options, &option_index)) != -1) { | 1171 long_options, &option_index)) != -1) { |
1186 switch(result) { | 1172 switch(result) { |
1187 case 'b': | 1173 case 'b': |
1188 use_b25 = TRUE; | 1174 use_b25 = TRUE; |
1189 fprintf(stderr, "using B25...\n"); | 1175 fprintf(stderr, "using B25...\n"); |
1256 case 'i': | 1242 case 'i': |
1257 use_splitter = TRUE; | 1243 use_splitter = TRUE; |
1258 sid_list = optarg; | 1244 sid_list = optarg; |
1259 break; | 1245 break; |
1260 case 'e': | 1246 case 'e': |
1247 use_esout = TRUE; | |
1261 es_name_prefix = optarg; | 1248 es_name_prefix = optarg; |
1262 break; | 1249 break; |
1263 case 'y': | 1250 case 'y': |
1264 start_time = optarg; | 1251 start_time = optarg; |
1265 break; | 1252 break; |
1253 case 'c': | |
1254 use_dlna = TRUE; | |
1255 fprintf(stderr, "enable DLNA DMS(Digital Media Server)\n"); | |
1256 break; | |
1266 } | 1257 } |
1267 } | 1258 } |
1268 | 1259 |
1269 if(argc - optind < 3) { | 1260 if(argc - optind < 3) { |
1270 if(argc - optind == 2 && use_udp) { | 1261 if(argc - optind == 2 && |
1271 fprintf(stderr, "Fileless UDP broadcasting\n"); | 1262 (use_udp|use_dlna|use_esout) ) { |
1263 if ( use_udp ) { | |
1264 fprintf(stderr, "Fileless UDP broadcasting\n"); | |
1265 } | |
1266 else if ( use_dlna ) { | |
1267 fprintf(stderr, "Fileless DLNA broadcasting\n"); | |
1268 } | |
1269 else if ( use_esout ) { | |
1270 fprintf(stderr, "Fileless ES out\n"); | |
1271 } | |
1272 else { | |
1273 fprintf(stderr, "Fileless...not found...\n"); | |
1274 } | |
1272 fileless = TRUE; | 1275 fileless = TRUE; |
1273 tdata.wfd = -1; | 1276 tdata.wfd = -1; |
1274 } | 1277 } |
1275 else { | 1278 else { |
1276 fprintf(stderr, "Arguments are necessary!\n"); | 1279 fprintf(stderr, "Arguments are necessary!\n"); |
1330 fprintf(stderr, "Cannot start TS splitter\n"); | 1333 fprintf(stderr, "Cannot start TS splitter\n"); |
1331 return 1; | 1334 return 1; |
1332 } | 1335 } |
1333 } | 1336 } |
1334 | 1337 |
1335 boolean use_dlna = TRUE; | |
1336 /* initialize DLNA */ | 1338 /* initialize DLNA */ |
1337 if(use_dlna) { | 1339 if(use_dlna) { |
1338 do { | 1340 do { |
1339 tdata.stream_queue = stream_queue; | 1341 tdata.stream_queue = stream_queue; |
1340 tdata.streamer = malloc(sizeof(streamer)); | 1342 tdata.streamer = malloc(sizeof(streamer)); |
1343 break; | 1345 break; |
1344 } | 1346 } |
1345 tdata.streamer->stream_nr = 0; | 1347 tdata.streamer->stream_nr = 0; |
1346 tdata.streamer->stream_session[0] = NULL; | 1348 tdata.streamer->stream_session[0] = NULL; |
1347 pthread_mutex_init(&tdata.streamer->mutex, NULL); | 1349 pthread_mutex_init(&tdata.streamer->mutex, NULL); |
1350 | |
1351 pthread_create(&stream_thread, NULL, stream_func, &tdata); | |
1352 pthread_create(&dlna_thread, NULL, dlna_startup, NULL); | |
1348 } while(0); | 1353 } while(0); |
1354 } | |
1355 else { | |
1356 tdata.streamer = NULL; | |
1349 } | 1357 } |
1350 | 1358 |
1351 /* initialize udp connection */ | 1359 /* initialize udp connection */ |
1352 if(use_udp) { | 1360 if(use_udp) { |
1353 sockdata = calloc(1, sizeof(sock_data)); | 1361 sockdata = calloc(1, sizeof(sock_data)); |
1387 init_signal_handlers(&signal_thread, &tdata); | 1395 init_signal_handlers(&signal_thread, &tdata); |
1388 | 1396 |
1389 /* spawn reader thread */ | 1397 /* spawn reader thread */ |
1390 tdata.signal_thread = signal_thread; | 1398 tdata.signal_thread = signal_thread; |
1391 pthread_create(&reader_thread, NULL, reader_func, &tdata); | 1399 pthread_create(&reader_thread, NULL, reader_func, &tdata); |
1392 pthread_create(&stream_thread, NULL, stream_func, &tdata); | |
1393 pthread_create(&dlna_thread, NULL, dlna_startup, NULL); | |
1394 | 1400 |
1395 /* spawn ipc thread */ | 1401 /* spawn ipc thread */ |
1396 key_t key; | 1402 key_t key; |
1397 key = (key_t)getpid(); | 1403 key = (key_t)getpid(); |
1398 | 1404 |
1413 | 1419 |
1414 /* read from tuner */ | 1420 /* read from tuner */ |
1415 while(1) { | 1421 while(1) { |
1416 if(f_exit) | 1422 if(f_exit) |
1417 break; | 1423 break; |
1418 //fprintf (stderr, "main() while loop start.\n"); | |
1419 | 1424 |
1420 time(&cur_time); | 1425 time(&cur_time); |
1421 bufptr = malloc(sizeof(BUFSZ)); | 1426 bufptr = malloc(sizeof(BUFSZ)); |
1422 if(!bufptr) { | 1427 if(!bufptr) { |
1423 f_exit = TRUE; | 1428 f_exit = TRUE; |
1424 break; | 1429 break; |
1425 } | 1430 } |
1426 //fprintf (stderr, "main() loop#1.\n"); | |
1427 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); | 1431 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); |
1428 //fprintf (stderr, "main() loop#2.\n"); | |
1429 if(bufptr->size <= 0) { | 1432 if(bufptr->size <= 0) { |
1430 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { | 1433 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { |
1431 //fprintf (stderr, "main() loop#3.\n"); | |
1432 f_exit = TRUE; | 1434 f_exit = TRUE; |
1433 enqueue(p_queue, NULL); | 1435 enqueue(p_queue, NULL); |
1434 break; | 1436 break; |
1435 } | 1437 } |
1436 else { | 1438 else { |
1437 //fprintf (stderr, "main() loop#4.\n"); | |
1438 continue; | 1439 continue; |
1439 } | 1440 } |
1440 } | 1441 } |
1441 //fprintf (stderr, "main() loop#5.\n"); | |
1442 //fprintf (stderr, "PT1 enqueue start.\n"); | |
1443 enqueue(p_queue, bufptr); | 1442 enqueue(p_queue, bufptr); |
1444 //fprintf (stderr, "PT1 enqueue finish.\n"); | |
1445 | 1443 |
1446 /* stop recording */ | 1444 /* stop recording */ |
1447 time(&cur_time); | 1445 time(&cur_time); |
1448 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { | 1446 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { |
1449 ioctl(tdata.tfd, STOP_REC, 0); | 1447 ioctl(tdata.tfd, STOP_REC, 0); |
1475 /* wait for threads */ | 1473 /* wait for threads */ |
1476 pthread_join(reader_thread, NULL); | 1474 pthread_join(reader_thread, NULL); |
1477 pthread_join(stream_thread, NULL); | 1475 pthread_join(stream_thread, NULL); |
1478 pthread_join(signal_thread, NULL); | 1476 pthread_join(signal_thread, NULL); |
1479 pthread_join(ipc_thread, NULL); | 1477 pthread_join(ipc_thread, NULL); |
1480 // pthread_join(dlna_startup, NULL); | 1478 if ( use_dlna ) { |
1481 pthread_join(dlna_thread, NULL); | 1479 pthread_join(dlna_thread, NULL); |
1480 } | |
1482 | 1481 |
1483 /* close tuner */ | 1482 /* close tuner */ |
1484 if(close_tuner(&tdata) != 0) | 1483 if(close_tuner(&tdata) != 0) |
1485 return 1; | 1484 return 1; |
1486 | 1485 |