# HG changeset patch # User Naoya OYAMA # Date 1347453399 -32400 # Node ID ade99239f234b29cfd575de290293ca621be99c1 # Parent ee69ddb11f938fa13c860bdd45713650399437e8 Enable change phisical channel by DLNA. diff -r ee69ddb11f93 -r ade99239f234 src/recpt1.c --- a/src/recpt1.c Mon Sep 10 20:56:14 2012 +0900 +++ b/src/recpt1.c Wed Sep 12 21:36:39 2012 +0900 @@ -62,6 +62,7 @@ int tune(char *channel, thread_data *tdata, char *device); int close_tuner(thread_data *tdata); static int get_device_id_by_name ( const char *name ); +void calc_cn(int fd, int type); static struct channel_info_list *open_list_file( char *type, @@ -543,9 +544,8 @@ int code; int split_select_finish = TSS_ERROR; int old_sid = 0, new_sid = 0; - int old_tp = 0, new_tp = 0; + char *old_tp = NULL, *new_tp = NULL; time_t split_start_time; - struct channel_info *channel_info = NULL; time(&split_start_time); @@ -652,52 +652,80 @@ /* * DLNA での物理チャンネル・SID変更の実装実験 */ - if ( use_dlna && buf.size > 0 && - strcmp("all", ut->request_channel)) { + if ( use_dlna && buf.size > 0 ) { if ( use_splitter ) { - if (ut->tp) - new_tp = atoi(ut->tp); + if (ut->tp) { + if (!old_tp) + old_tp = "0"; + new_tp = ut->tp; + } if (ut->sid) new_sid = atoi(ut->sid); - if (old_tp != new_tp) { - old_tp = new_tp; - // msgsnd() を自分自身に送れるのならその方が良さそうな気がする - ioctl(data->tfd, STOP_REC, 0); - if(close_tuner(data) != 0) - break; - pthread_mutex_lock(&data->queue->mutex); - while(data->queue->num_used > 0) { - while(1) { - QUEUE_T *p_queue = data->queue; - if (p_queue->num_used == 0) - break; - free(p_queue->buffer[p_queue->out]); - p_queue->buffer[p_queue->out] = NULL; - p_queue->out++; - p_queue->out %= p_queue->size; + if ((new_tp) && (old_tp)) + if (strcmp(old_tp, new_tp)) { + int current_type = data->table->type; + ISDB_T_FREQ_CONV_TABLE *table = searchrecoff(new_tp); + if (table == NULL) { + fprintf(stderr, "Invalid Channel: %s\n", new_tp); + break; + } + data->table = table; + old_tp = new_tp; + + /* stop stream */ + ioctl(data->tfd, STOP_REC, 0); + pthread_mutex_lock(&data->queue->mutex); + while(data->queue->num_used > 0) { + while(1) { + QUEUE_T *p_queue = data->queue; + if (p_queue->num_used == 0) + break; + free(p_queue->buffer[p_queue->out]); + p_queue->buffer[p_queue->out] = NULL; + p_queue->out++; + p_queue->out %= p_queue->size; - /* update counters */ - p_queue->num_avail++; - p_queue->num_used--; + /* update counters */ + p_queue->num_avail++; + p_queue->num_used--; + } } + pthread_mutex_unlock(&data->queue->mutex); + if (data->table->type != current_type) { + /* re-open device */ + if(close_tuner(data) != 0) + break; + tune(new_tp, data, NULL); + } else { + /* SET_CHANNEL only */ + const FREQUENCY freq = { + .frequencyno = data->table->set_freq, + .slot = data->table->add_freq, + }; + if(ioctl(data->tfd, SET_CHANNEL, &freq) < 0) { + fprintf(stderr, "Cannot tune to the specified channel\n"); + data->ch = 0; + break; + } + data->ch = atoi(new_tp); + calc_cn(data->tfd, data->table->type); + } + if(ioctl(data->tfd, START_REC, 0) < 0) { + // ここの扱いどころが迷うところ。exit してもいい気がする + fprintf(stderr, "Tuner cannot start recording\n"); + break; + } + time(&split_start_time); } - pthread_mutex_unlock(&data->queue->mutex); - tune(ut->tp, data, NULL); - if(ioctl(data->tfd, START_REC, 0) < 0) { - // ここの扱いどころが迷うところ。exit してもいい気がする - fprintf(stderr, "Tuner cannot start recording\n"); - break; - } - time(&split_start_time); - } if ( old_sid != new_sid ) { old_sid = new_sid; split_shutdown(splitter); splitter = split_startup(ut->sid, NULL, NULL); if ( splitter == NULL ) { - fprintf (stderr, "reader_func() splitter RESTART FAILED.\n", old_sid, new_sid); + fprintf (stderr, "reader_func() splitter RESTART FAILED.\n"); use_splitter = FALSE; } + fprintf (stderr, "reader_func() splitter plit_select_finish set ERROR.\n"); split_select_finish = TSS_ERROR; free(qbuf); qbuf = NULL;