comparison recpt1/recpt1.c @ 133:b14397800eae

imported eagletmt-san's reuse device patch for fast channel selection in recpt1ctl. The original patch can be obtained at https://gist.github.com/890635/57c3fd93e181b3eb3f6e5ebeae22ad7b5f1f4ec1
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 27 Jun 2012 06:56:33 +0900
parents 8e0f7191b92e
children 2b057f249811
comparison
equal deleted inserted replaced
132:9783d247d1c9 133:b14397800eae
73 73
74 /* globals */ 74 /* globals */
75 boolean f_exit = FALSE; 75 boolean f_exit = FALSE;
76 76
77 /* prototypes */ 77 /* prototypes */
78 ISDB_T_FREQ_CONV_TABLE *searchrecoff(char *channel);
79 void calc_cn(int fd, int type);
78 int tune(char *channel, thread_data *tdata, char *device); 80 int tune(char *channel, thread_data *tdata, char *device);
79 int close_tuner(thread_data *tdata); 81 int close_tuner(thread_data *tdata);
80 82
81 83
82 /* ipc message receive */ 84 /* ipc message receive */
96 sscanf(rbuf.mtext, "ch=%s t=%d e=%d", channel, &recsec, &time_to_add); 98 sscanf(rbuf.mtext, "ch=%s t=%d e=%d", channel, &recsec, &time_to_add);
97 ch = atoi(channel); 99 ch = atoi(channel);
98 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add); 100 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add);
99 101
100 if(ch && tdata->ch != ch) { 102 if(ch && tdata->ch != ch) {
101 /* stop stream */
102 ioctl(tdata->tfd, STOP_REC, 0);
103 #if 0 103 #if 0
104 /* re-initialize decoder */ 104 /* re-initialize decoder */
105 if(tdata->decoder) { 105 if(tdata->decoder) {
106 // b25_finish(tdata->decoder); 106 // b25_finish(tdata->decoder);
107 b25_shutdown(tdata->decoder); 107 b25_shutdown(tdata->decoder);
110 fprintf(stderr, "Cannot start b25 decoder\n"); 110 fprintf(stderr, "Cannot start b25 decoder\n");
111 fprintf(stderr, "Fall back to encrypted recording\n"); 111 fprintf(stderr, "Fall back to encrypted recording\n");
112 } 112 }
113 } 113 }
114 #endif 114 #endif
115 /* tune to new channel */ 115 int current_type = tdata->table->type;
116 if(close_tuner(tdata) != 0) 116 ISDB_T_FREQ_CONV_TABLE *table = searchrecoff(channel);
117 return NULL; 117 if (table == NULL) {
118 fprintf(stderr, "Invalid Channel: %s\n", channel);
119 goto CHECK_TIME_TO_ADD;
120 }
121 tdata->table = table;
122
123 /* stop stream */
124 ioctl(tdata->tfd, STOP_REC, 0);
118 125
119 /* wait for remainder */ 126 /* wait for remainder */
120 while(tdata->queue->num_used > 0) { 127 while(tdata->queue->num_used > 0) {
121 usleep(10000); 128 usleep(10000);
122 } 129 }
123 130
124 tune(channel, tdata, NULL); 131 if (tdata->table->type != current_type) {
125 132 /* re-open device */
133 if(close_tuner(tdata) != 0)
134 return NULL;
135
136 tune(channel, tdata, NULL);
137 } else {
138 /* SET_CHANNEL only */
139 const FREQUENCY freq = {
140 .frequencyno = tdata->table->set_freq,
141 .slot = tdata->table->add_freq,
142 };
143 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
144 fprintf(stderr, "Cannot tune to the specified channel\n");
145 tdata->ch = 0;
146 goto CHECK_TIME_TO_ADD;
147 }
148 tdata->ch = ch;
149 calc_cn(tdata->tfd, tdata->table->type);
150 }
126 /* restart recording */ 151 /* restart recording */
127 if(ioctl(tdata->tfd, START_REC, 0) < 0) { 152 if(ioctl(tdata->tfd, START_REC, 0) < 0) {
128 fprintf(stderr, "Tuner cannot start recording\n"); 153 fprintf(stderr, "Tuner cannot start recording\n");
129 return NULL; 154 return NULL;
130 } 155 }
131 } 156 }
132 157
158 CHECK_TIME_TO_ADD:
133 if(time_to_add) { 159 if(time_to_add) {
134 tdata->recsec += time_to_add; 160 tdata->recsec += time_to_add;
135 fprintf(stderr, "Extended %d sec\n", time_to_add); 161 fprintf(stderr, "Extended %d sec\n", time_to_add);
136 } 162 }
137 163
1157 f_exit = TRUE; 1183 f_exit = TRUE;
1158 enqueue(p_queue, NULL); 1184 enqueue(p_queue, NULL);
1159 break; 1185 break;
1160 } 1186 }
1161 else { 1187 else {
1188 free(bufptr);
1162 continue; 1189 continue;
1163 } 1190 }
1164 } 1191 }
1165 enqueue(p_queue, bufptr); 1192 enqueue(p_queue, bufptr);
1166 1193