# HG changeset patch # User Naoya OYAMA # Date 1348487357 -32400 # Node ID 57eae2aec60dd73e33ff3e794125ec119cb3ee3a # Parent 185ff17f89f741aaea4252ce79415efa47ebb1a9 improve-channel-switching.patch.(https://gist.github.com/890635) diff -r 185ff17f89f7 -r 57eae2aec60d src/recpt1.c --- a/src/recpt1.c Wed Sep 12 21:49:16 2012 +0900 +++ b/src/recpt1.c Mon Sep 24 20:49:17 2012 +0900 @@ -63,6 +63,7 @@ int close_tuner(thread_data *tdata); static int get_device_id_by_name ( const char *name ); void calc_cn(int fd, int type); +ISDB_T_FREQ_CONV_TABLE *searchrecoff(char *channel); static struct channel_info_list *open_list_file( char *type, @@ -179,8 +180,6 @@ // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add); if(ch && tdata->ch != ch) { - /* stop stream */ - ioctl(tdata->tfd, STOP_REC, 0); #if 0 /* re-initialize decoder */ if(tdata->decoder) { @@ -193,17 +192,42 @@ } } #endif - /* tune to new channel */ - if(close_tuner(tdata) != 0) - return NULL; + int current_type = tdata->table->type; + ISDB_T_FREQ_CONV_TABLE *table = searchrecoff(channel); + if (table == NULL) { + fprintf(stderr, "Invalid Channel: %s\n", channel); + goto CHECK_TIME_TO_ADD; + } + tdata->table = table; + + /* stop stream */ + ioctl(tdata->tfd, STOP_REC, 0); /* wait for remainder */ while(tdata->queue->num_used > 0) { usleep(10000); } - tune(channel, tdata, NULL); - + if (tdata->table->type != current_type) { + /* re-open device */ + if(close_tuner(tdata) != 0) + return NULL; + + tune(channel, tdata, NULL); + } else { + /* SET_CHANNEL only */ + const FREQUENCY freq = { + .frequencyno = tdata->table->set_freq, + .slot = tdata->table->add_freq, + }; + if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) { + fprintf(stderr, "Cannot tune to the specified channel\n"); + tdata->ch = 0; + goto CHECK_TIME_TO_ADD; + } + tdata->ch = ch; + calc_cn(tdata->tfd, tdata->table->type); + } /* restart recording */ if(ioctl(tdata->tfd, START_REC, 0) < 0) { fprintf(stderr, "Tuner cannot start recording\n"); @@ -211,6 +235,7 @@ } } +CHECK_TIME_TO_ADD: if(time_to_add) { tdata->recsec += time_to_add; fprintf(stderr, "Extended %d sec\n", time_to_add); @@ -1685,6 +1710,8 @@ break; } else { + free(bufptr); + bufptr = NULL; continue; } } @@ -1706,6 +1733,10 @@ f_exit = TRUE; enqueue(p_queue, NULL); break; + } else { + free(bufptr); + bufptr = NULL; + break; } enqueue(p_queue, bufptr); }