Mercurial > pt1.oyama
comparison src/recpt1.c @ 152:30e91361506a
EXPERIMENTAL: Enable change phisical channel by DLNA.(ISDB-T only)
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Sun, 02 Sep 2012 01:59:27 +0900 |
parents | f7f594bf4e98 |
children | 578ebda88997 |
comparison
equal
deleted
inserted
replaced
151:f7f594bf4e98 | 152:30e91361506a |
---|---|
48 char mtext[MSGSZ]; | 48 char mtext[MSGSZ]; |
49 } pt1_message_buf; | 49 } pt1_message_buf; |
50 | 50 |
51 /* globals */ | 51 /* globals */ |
52 boolean f_exit = FALSE; | 52 boolean f_exit = FALSE; |
53 struct channel_info_list *channel_list = NULL; | |
53 extern struct ushare_t *ut; | 54 extern struct ushare_t *ut; |
54 | 55 |
55 /* prototypes */ | 56 /* prototypes */ |
56 int tune(char *channel, thread_data *tdata, char *device); | 57 int tune(char *channel, thread_data *tdata, char *device); |
57 int close_tuner(thread_data *tdata); | 58 int close_tuner(thread_data *tdata); |
58 static int get_device_id_by_name ( const char *name ); | 59 static int get_device_id_by_name ( const char *name ); |
60 | |
61 static struct channel_info_list *open_list_file(char *type) | |
62 { | |
63 char *buf = NULL; | |
64 char filename[PATH_MAX]; | |
65 char *home = NULL; | |
66 char *p = NULL; | |
67 struct channel_info *channel_info = NULL; | |
68 struct channel_info_list *channel_info_list = NULL; | |
69 FILE *f = NULL; | |
70 | |
71 home = getenv("HOME"); | |
72 snprintf(filename, PATH_MAX, "%s/.recpt1_%s", home, type); | |
73 f = fopen(filename, "r"); | |
74 if(!f) { | |
75 return channel_info_list; | |
76 } | |
77 channel_info_list = malloc(sizeof(*channel_info_list)); | |
78 if(!channel_info_list) | |
79 return NULL; | |
80 channel_info_list->nr_channel = 0; | |
81 while(1) { | |
82 buf = NULL; | |
83 buf = malloc(256); | |
84 if(!buf) | |
85 break; | |
86 if(!fgets(buf, 255, f)) { | |
87 free(buf); | |
88 buf = NULL; | |
89 break; | |
90 } | |
91 channel_info = NULL; | |
92 channel_info = malloc(sizeof(*channel_info)); | |
93 if(!channel_info) | |
94 break; | |
95 | |
96 channel_info->sid = NULL; | |
97 channel_info->tp = NULL; | |
98 channel_info->name = NULL; | |
99 | |
100 channel_info->sid = buf; | |
101 | |
102 p = strchr(buf, C_CHAR_COMMA); | |
103 if (p == NULL) { | |
104 /* FILE ERROR */ | |
105 free(channel_info); | |
106 channel_info = NULL; | |
107 continue; | |
108 } | |
109 *p = '\0'; | |
110 channel_info->tp = ++p; | |
111 | |
112 p = strchr(p, C_CHAR_COMMA); | |
113 if (p == NULL) { | |
114 /* FILE ERROR */ | |
115 free(channel_info); | |
116 channel_info = NULL; | |
117 continue; | |
118 } | |
119 *p = '\0'; | |
120 channel_info->name = ++p; | |
121 p = strchr(p, '\n'); | |
122 if (p) | |
123 *p = '\0'; | |
124 | |
125 if(channel_info_list->nr_channel < CHANNEL_MAX) { | |
126 channel_info_list->channel_info[channel_info_list->nr_channel] = channel_info; | |
127 channel_info_list->nr_channel += 1; | |
128 } | |
129 } | |
130 fclose(f); | |
131 return channel_info_list; | |
132 } | |
133 | |
134 static void close_list_file(struct channel_info_list *channel_info_list) | |
135 { | |
136 int i; | |
137 if (!channel_info_list) | |
138 return; | |
139 for (i=0; i < channel_info_list->nr_channel; i++) { | |
140 free(channel_info_list->channel_info[i]->sid); | |
141 channel_info_list->channel_info[i]->sid = NULL; | |
142 free(channel_info_list->channel_info[i]); | |
143 channel_info_list->channel_info[i] = NULL; | |
144 } | |
145 channel_info_list->nr_channel = 0; | |
146 free(channel_info_list); | |
147 channel_info_list = NULL; | |
148 return; | |
149 } | |
59 | 150 |
60 /* ipc message receive */ | 151 /* ipc message receive */ |
61 void * | 152 void * |
62 mq_recv(void *t) | 153 mq_recv(void *t) |
63 { | 154 { |
414 splitbuf_t splitbuf; | 505 splitbuf_t splitbuf; |
415 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; | 506 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; |
416 int code; | 507 int code; |
417 int split_select_finish = TSS_ERROR; | 508 int split_select_finish = TSS_ERROR; |
418 int old_sid = 0, new_sid = 0; | 509 int old_sid = 0, new_sid = 0; |
510 int old_tp = 0, new_tp = 0; | |
419 time_t split_start_time; | 511 time_t split_start_time; |
512 struct channel_info *channel_info = NULL; | |
420 | 513 |
421 time(&split_start_time); | 514 time(&split_start_time); |
422 | 515 |
423 buf.size = 0; | 516 buf.size = 0; |
424 buf.data = NULL; | 517 buf.data = NULL; |
519 * 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 | 612 * 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 |
520 * 2.2.3 tdata->stream_queue $B$K(B 2.2.1 $B$N%]%$%s%?$r(B enqueue() $B$9$k(B | 613 * 2.2.3 tdata->stream_queue $B$K(B 2.2.1 $B$N%]%$%s%?$r(B enqueue() $B$9$k(B |
521 * 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 | 614 * 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 |
522 */ | 615 */ |
523 /* | 616 /* |
524 * DLNA $B$G$N(BSID$BJQ99$N<BAu<B83(B | 617 * DLNA $B$G$NJ*M}%A%c%s%M%k!&(BSID$BJQ99$N<BAu<B83(B |
525 */ | 618 */ |
526 if ( use_dlna && buf.size > 0 && | 619 if ( use_dlna && buf.size > 0 && |
527 strcmp("all", ut->request_channel)) { | 620 strcmp("all", ut->request_channel)) { |
528 if ( use_splitter ) { | 621 if ( use_splitter ) { |
529 new_sid = atoi(ut->request_channel); | 622 if (ut->tp) |
623 new_tp = atoi(ut->tp); | |
624 if (ut->sid) | |
625 new_sid = atoi(ut->sid); | |
626 if (old_tp != new_tp) { | |
627 old_tp = new_tp; | |
628 // msgsnd() $B$r<+J,<+?H$KAw$l$k$N$J$i$=$NJ}$,NI$5$=$&$J5$$,$9$k(B | |
629 ioctl(data->tfd, STOP_REC, 0); | |
630 if(close_tuner(data) != 0) | |
631 break; | |
632 pthread_mutex_lock(&data->queue->mutex); | |
633 while(data->queue->num_used > 0) { | |
634 while(1) { | |
635 QUEUE_T *p_queue = data->queue; | |
636 if (p_queue->num_used == 0) | |
637 break; | |
638 free(p_queue->buffer[p_queue->out]); | |
639 p_queue->buffer[p_queue->out] = NULL; | |
640 p_queue->out++; | |
641 p_queue->out %= p_queue->size; | |
642 | |
643 /* update counters */ | |
644 p_queue->num_avail++; | |
645 p_queue->num_used--; | |
646 } | |
647 } | |
648 pthread_mutex_unlock(&data->queue->mutex); | |
649 tune(ut->tp, data, NULL); | |
650 if(ioctl(data->tfd, START_REC, 0) < 0) { | |
651 // $B$3$3$N07$$$I$3$m$,LB$&$H$3$m!#(Bexit $B$7$F$b$$$$5$$,$9$k(B | |
652 fprintf(stderr, "Tuner cannot start recording\n"); | |
653 break; | |
654 } | |
655 time(&split_start_time); | |
656 } | |
530 if ( old_sid != new_sid ) { | 657 if ( old_sid != new_sid ) { |
531 old_sid = new_sid; | 658 old_sid = new_sid; |
532 split_shutdown(splitter); | 659 split_shutdown(splitter); |
533 splitter = split_startup(ut->request_channel, NULL, NULL); | 660 splitter = split_startup(ut->sid, NULL, NULL); |
534 if ( splitter == NULL ) { | 661 if ( splitter == NULL ) { |
535 fprintf (stderr, "reader_func() splitter RESTART FAILED.\n", old_sid, new_sid); | 662 fprintf (stderr, "reader_func() splitter RESTART FAILED.\n", old_sid, new_sid); |
536 use_splitter = FALSE; | 663 use_splitter = FALSE; |
537 } | 664 } |
538 split_select_finish = TSS_ERROR; | 665 split_select_finish = TSS_ERROR; |
554 /* update counters */ | 681 /* update counters */ |
555 p_queue->num_avail++; | 682 p_queue->num_avail++; |
556 p_queue->num_used--; | 683 p_queue->num_used--; |
557 } | 684 } |
558 pthread_mutex_unlock(&data->stream_queue->mutex); | 685 pthread_mutex_unlock(&data->stream_queue->mutex); |
559 fprintf (stderr, "reader_func() free stream queue finish.\n"); | |
560 time(&split_start_time); | 686 time(&split_start_time); |
561 continue; | 687 continue; |
562 } | 688 } |
563 } | 689 } |
564 do { | 690 do { |
1390 } | 1516 } |
1391 | 1517 |
1392 /* initialize DLNA */ | 1518 /* initialize DLNA */ |
1393 if(use_dlna) { | 1519 if(use_dlna) { |
1394 do { | 1520 do { |
1521 if(use_splitter) | |
1522 channel_list = open_list_file("ISDB"); | |
1395 tdata.stream_queue = stream_queue; | 1523 tdata.stream_queue = stream_queue; |
1396 tdata.streamer = malloc(sizeof(streamer)); | 1524 tdata.streamer = malloc(sizeof(streamer)); |
1397 if ( tdata.streamer == NULL ) { | 1525 if ( tdata.streamer == NULL ) { |
1398 use_dlna = FALSE; | 1526 use_dlna = FALSE; |
1399 break; | 1527 break; |
1529 pthread_join(stream_thread, NULL); | 1657 pthread_join(stream_thread, NULL); |
1530 pthread_join(signal_thread, NULL); | 1658 pthread_join(signal_thread, NULL); |
1531 pthread_join(ipc_thread, NULL); | 1659 pthread_join(ipc_thread, NULL); |
1532 if ( use_dlna ) { | 1660 if ( use_dlna ) { |
1533 pthread_join(dlna_thread, NULL); | 1661 pthread_join(dlna_thread, NULL); |
1662 if ( channel_list ) | |
1663 close_list_file(channel_list); | |
1534 } | 1664 } |
1535 | 1665 |
1536 /* close tuner */ | 1666 /* close tuner */ |
1537 if(close_tuner(&tdata) != 0) | 1667 if(close_tuner(&tdata) != 0) |
1538 return 1; | 1668 return 1; |