comparison src/recpt1.c @ 161:ade99239f234

Enable change phisical channel by DLNA.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Wed, 12 Sep 2012 21:36:39 +0900
parents 38f79bcba50d
children 185ff17f89f7
comparison
equal deleted inserted replaced
160:ee69ddb11f93 161:ade99239f234
60 60
61 /* prototypes */ 61 /* prototypes */
62 int tune(char *channel, thread_data *tdata, char *device); 62 int tune(char *channel, thread_data *tdata, char *device);
63 int close_tuner(thread_data *tdata); 63 int close_tuner(thread_data *tdata);
64 static int get_device_id_by_name ( const char *name ); 64 static int get_device_id_by_name ( const char *name );
65 void calc_cn(int fd, int type);
65 66
66 static struct channel_info_list *open_list_file( 67 static struct channel_info_list *open_list_file(
67 char *type, 68 char *type,
68 struct channel_info_list *info_list) 69 struct channel_info_list *info_list)
69 { 70 {
541 splitbuf_t splitbuf; 542 splitbuf_t splitbuf;
542 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; 543 ARIB_STD_B25_BUFFER sbuf, dbuf, buf;
543 int code; 544 int code;
544 int split_select_finish = TSS_ERROR; 545 int split_select_finish = TSS_ERROR;
545 int old_sid = 0, new_sid = 0; 546 int old_sid = 0, new_sid = 0;
546 int old_tp = 0, new_tp = 0; 547 char *old_tp = NULL, *new_tp = NULL;
547 time_t split_start_time; 548 time_t split_start_time;
548 struct channel_info *channel_info = NULL;
549 549
550 time(&split_start_time); 550 time(&split_start_time);
551 551
552 buf.size = 0; 552 buf.size = 0;
553 buf.data = NULL; 553 buf.data = NULL;
650 * 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 650 * 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
651 */ 651 */
652 /* 652 /*
653 * DLNA $B$G$NJ*M}%A%c%s%M%k!&(BSID$BJQ99$N<BAu<B83(B 653 * DLNA $B$G$NJ*M}%A%c%s%M%k!&(BSID$BJQ99$N<BAu<B83(B
654 */ 654 */
655 if ( use_dlna && buf.size > 0 && 655 if ( use_dlna && buf.size > 0 ) {
656 strcmp("all", ut->request_channel)) {
657 if ( use_splitter ) { 656 if ( use_splitter ) {
658 if (ut->tp) 657 if (ut->tp) {
659 new_tp = atoi(ut->tp); 658 if (!old_tp)
659 old_tp = "0";
660 new_tp = ut->tp;
661 }
660 if (ut->sid) 662 if (ut->sid)
661 new_sid = atoi(ut->sid); 663 new_sid = atoi(ut->sid);
662 if (old_tp != new_tp) { 664 if ((new_tp) && (old_tp))
663 old_tp = new_tp; 665 if (strcmp(old_tp, new_tp)) {
664 // msgsnd() $B$r<+J,<+?H$KAw$l$k$N$J$i$=$NJ}$,NI$5$=$&$J5$$,$9$k(B 666 int current_type = data->table->type;
665 ioctl(data->tfd, STOP_REC, 0); 667 ISDB_T_FREQ_CONV_TABLE *table = searchrecoff(new_tp);
666 if(close_tuner(data) != 0) 668 if (table == NULL) {
667 break; 669 fprintf(stderr, "Invalid Channel: %s\n", new_tp);
668 pthread_mutex_lock(&data->queue->mutex); 670 break;
669 while(data->queue->num_used > 0) {
670 while(1) {
671 QUEUE_T *p_queue = data->queue;
672 if (p_queue->num_used == 0)
673 break;
674 free(p_queue->buffer[p_queue->out]);
675 p_queue->buffer[p_queue->out] = NULL;
676 p_queue->out++;
677 p_queue->out %= p_queue->size;
678
679 /* update counters */
680 p_queue->num_avail++;
681 p_queue->num_used--;
682 } 671 }
672 data->table = table;
673 old_tp = new_tp;
674
675 /* stop stream */
676 ioctl(data->tfd, STOP_REC, 0);
677 pthread_mutex_lock(&data->queue->mutex);
678 while(data->queue->num_used > 0) {
679 while(1) {
680 QUEUE_T *p_queue = data->queue;
681 if (p_queue->num_used == 0)
682 break;
683 free(p_queue->buffer[p_queue->out]);
684 p_queue->buffer[p_queue->out] = NULL;
685 p_queue->out++;
686 p_queue->out %= p_queue->size;
687
688 /* update counters */
689 p_queue->num_avail++;
690 p_queue->num_used--;
691 }
692 }
693 pthread_mutex_unlock(&data->queue->mutex);
694 if (data->table->type != current_type) {
695 /* re-open device */
696 if(close_tuner(data) != 0)
697 break;
698 tune(new_tp, data, NULL);
699 } else {
700 /* SET_CHANNEL only */
701 const FREQUENCY freq = {
702 .frequencyno = data->table->set_freq,
703 .slot = data->table->add_freq,
704 };
705 if(ioctl(data->tfd, SET_CHANNEL, &freq) < 0) {
706 fprintf(stderr, "Cannot tune to the specified channel\n");
707 data->ch = 0;
708 break;
709 }
710 data->ch = atoi(new_tp);
711 calc_cn(data->tfd, data->table->type);
712 }
713 if(ioctl(data->tfd, START_REC, 0) < 0) {
714 // $B$3$3$N07$$$I$3$m$,LB$&$H$3$m!#(Bexit $B$7$F$b$$$$5$$,$9$k(B
715 fprintf(stderr, "Tuner cannot start recording\n");
716 break;
717 }
718 time(&split_start_time);
683 } 719 }
684 pthread_mutex_unlock(&data->queue->mutex);
685 tune(ut->tp, data, NULL);
686 if(ioctl(data->tfd, START_REC, 0) < 0) {
687 // $B$3$3$N07$$$I$3$m$,LB$&$H$3$m!#(Bexit $B$7$F$b$$$$5$$,$9$k(B
688 fprintf(stderr, "Tuner cannot start recording\n");
689 break;
690 }
691 time(&split_start_time);
692 }
693 if ( old_sid != new_sid ) { 720 if ( old_sid != new_sid ) {
694 old_sid = new_sid; 721 old_sid = new_sid;
695 split_shutdown(splitter); 722 split_shutdown(splitter);
696 splitter = split_startup(ut->sid, NULL, NULL); 723 splitter = split_startup(ut->sid, NULL, NULL);
697 if ( splitter == NULL ) { 724 if ( splitter == NULL ) {
698 fprintf (stderr, "reader_func() splitter RESTART FAILED.\n", old_sid, new_sid); 725 fprintf (stderr, "reader_func() splitter RESTART FAILED.\n");
699 use_splitter = FALSE; 726 use_splitter = FALSE;
700 } 727 }
728 fprintf (stderr, "reader_func() splitter plit_select_finish set ERROR.\n");
701 split_select_finish = TSS_ERROR; 729 split_select_finish = TSS_ERROR;
702 free(qbuf); 730 free(qbuf);
703 qbuf = NULL; 731 qbuf = NULL;
704 732
705 pthread_mutex_lock(&data->stream_queue->mutex); 733 pthread_mutex_lock(&data->stream_queue->mutex);