comparison src/recpt1.c @ 163:57eae2aec60d

improve-channel-switching.patch.(https://gist.github.com/890635)
author Naoya OYAMA <naoya.oyama@gmail.com>
date Mon, 24 Sep 2012 20:49:17 +0900
parents 185ff17f89f7
children 7d8a5bb874ad
comparison
equal deleted inserted replaced
162:185ff17f89f7 163:57eae2aec60d
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 void calc_cn(int fd, int type);
66 ISDB_T_FREQ_CONV_TABLE *searchrecoff(char *channel);
66 67
67 static struct channel_info_list *open_list_file( 68 static struct channel_info_list *open_list_file(
68 char *type, 69 char *type,
69 struct channel_info_list *info_list) 70 struct channel_info_list *info_list)
70 { 71 {
177 sscanf(rbuf.mtext, "ch=%s t=%d e=%d", channel, &recsec, &time_to_add); 178 sscanf(rbuf.mtext, "ch=%s t=%d e=%d", channel, &recsec, &time_to_add);
178 ch = atoi(channel); 179 ch = atoi(channel);
179 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add); 180 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add);
180 181
181 if(ch && tdata->ch != ch) { 182 if(ch && tdata->ch != ch) {
182 /* stop stream */
183 ioctl(tdata->tfd, STOP_REC, 0);
184 #if 0 183 #if 0
185 /* re-initialize decoder */ 184 /* re-initialize decoder */
186 if(tdata->decoder) { 185 if(tdata->decoder) {
187 // b25_finish(tdata->decoder); 186 // b25_finish(tdata->decoder);
188 b25_shutdown(tdata->decoder); 187 b25_shutdown(tdata->decoder);
191 fprintf(stderr, "Cannot start b25 decoder\n"); 190 fprintf(stderr, "Cannot start b25 decoder\n");
192 fprintf(stderr, "Fall back to encrypted recording\n"); 191 fprintf(stderr, "Fall back to encrypted recording\n");
193 } 192 }
194 } 193 }
195 #endif 194 #endif
196 /* tune to new channel */ 195 int current_type = tdata->table->type;
197 if(close_tuner(tdata) != 0) 196 ISDB_T_FREQ_CONV_TABLE *table = searchrecoff(channel);
198 return NULL; 197 if (table == NULL) {
198 fprintf(stderr, "Invalid Channel: %s\n", channel);
199 goto CHECK_TIME_TO_ADD;
200 }
201 tdata->table = table;
202
203 /* stop stream */
204 ioctl(tdata->tfd, STOP_REC, 0);
199 205
200 /* wait for remainder */ 206 /* wait for remainder */
201 while(tdata->queue->num_used > 0) { 207 while(tdata->queue->num_used > 0) {
202 usleep(10000); 208 usleep(10000);
203 } 209 }
204 210
205 tune(channel, tdata, NULL); 211 if (tdata->table->type != current_type) {
206 212 /* re-open device */
213 if(close_tuner(tdata) != 0)
214 return NULL;
215
216 tune(channel, tdata, NULL);
217 } else {
218 /* SET_CHANNEL only */
219 const FREQUENCY freq = {
220 .frequencyno = tdata->table->set_freq,
221 .slot = tdata->table->add_freq,
222 };
223 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
224 fprintf(stderr, "Cannot tune to the specified channel\n");
225 tdata->ch = 0;
226 goto CHECK_TIME_TO_ADD;
227 }
228 tdata->ch = ch;
229 calc_cn(tdata->tfd, tdata->table->type);
230 }
207 /* restart recording */ 231 /* restart recording */
208 if(ioctl(tdata->tfd, START_REC, 0) < 0) { 232 if(ioctl(tdata->tfd, START_REC, 0) < 0) {
209 fprintf(stderr, "Tuner cannot start recording\n"); 233 fprintf(stderr, "Tuner cannot start recording\n");
210 return NULL; 234 return NULL;
211 } 235 }
212 } 236 }
213 237
238 CHECK_TIME_TO_ADD:
214 if(time_to_add) { 239 if(time_to_add) {
215 tdata->recsec += time_to_add; 240 tdata->recsec += time_to_add;
216 fprintf(stderr, "Extended %d sec\n", time_to_add); 241 fprintf(stderr, "Extended %d sec\n", time_to_add);
217 } 242 }
218 243
1683 f_exit = TRUE; 1708 f_exit = TRUE;
1684 enqueue(p_queue, NULL); 1709 enqueue(p_queue, NULL);
1685 break; 1710 break;
1686 } 1711 }
1687 else { 1712 else {
1713 free(bufptr);
1714 bufptr = NULL;
1688 continue; 1715 continue;
1689 } 1716 }
1690 } 1717 }
1691 enqueue(p_queue, bufptr); 1718 enqueue(p_queue, bufptr);
1692 1719
1704 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); 1731 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE);
1705 if(bufptr->size <= 0) { 1732 if(bufptr->size <= 0) {
1706 f_exit = TRUE; 1733 f_exit = TRUE;
1707 enqueue(p_queue, NULL); 1734 enqueue(p_queue, NULL);
1708 break; 1735 break;
1736 } else {
1737 free(bufptr);
1738 bufptr = NULL;
1739 break;
1709 } 1740 }
1710 enqueue(p_queue, bufptr); 1741 enqueue(p_queue, bufptr);
1711 } 1742 }
1712 break; 1743 break;
1713 } 1744 }