changeset 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
files src/recpt1.c
diffstat 1 files changed, 38 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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);
             }