Mercurial > pt1.oyama
comparison recpt1/recpt1.c @ 88:59065b569eec
improve stability on changing channel
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 27 Jan 2010 14:36:47 +0900 |
parents | 0b00d22b0d1c |
children | d74bcf2d255d |
comparison
equal
deleted
inserted
replaced
87:0b00d22b0d1c | 88:59065b569eec |
---|---|
94 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add); | 94 // fprintf(stderr, "ch=%d time=%d extend=%d\n", ch, recsec, time_to_add); |
95 | 95 |
96 if(ch && tdata->ch != ch) { | 96 if(ch && tdata->ch != ch) { |
97 /* stop stream */ | 97 /* stop stream */ |
98 ioctl(tdata->tfd, STOP_REC, 0); | 98 ioctl(tdata->tfd, STOP_REC, 0); |
99 | |
100 /* flush remainder? */ | |
101 | |
102 #if 0 | 99 #if 0 |
103 /* re-initialize decoder */ | 100 /* re-initialize decoder */ |
104 if(tdata->decoder) { | 101 if(tdata->decoder) { |
105 // b25_finish(tdata->decoder); | 102 // b25_finish(tdata->decoder); |
106 b25_shutdown(tdata->decoder); | 103 b25_shutdown(tdata->decoder); |
112 } | 109 } |
113 #endif | 110 #endif |
114 /* tune to new channel */ | 111 /* tune to new channel */ |
115 if(close_tuner(tdata) != 0) | 112 if(close_tuner(tdata) != 0) |
116 return NULL; | 113 return NULL; |
114 | |
115 /* wait for remainder */ | |
116 while(tdata->queue->num_used > 0) { | |
117 usleep(10000); | |
118 } | |
119 | |
117 tune(channel, tdata, NULL); | 120 tune(channel, tdata, NULL); |
118 | 121 |
119 /* restart recording */ | 122 /* restart recording */ |
120 if(ioctl(tdata->tfd, START_REC, 0) < 0) { | 123 if(ioctl(tdata->tfd, START_REC, 0) < 0) { |
121 fprintf(stderr, "Tuner cannot start recording\n"); | 124 fprintf(stderr, "Tuner cannot start recording\n"); |
1035 if(f_exit) | 1038 if(f_exit) |
1036 break; | 1039 break; |
1037 | 1040 |
1038 time(&cur_time); | 1041 time(&cur_time); |
1039 bufptr = malloc(sizeof(BUFSZ)); | 1042 bufptr = malloc(sizeof(BUFSZ)); |
1043 if(!bufptr) { | |
1044 f_exit = TRUE; | |
1045 break; | |
1046 } | |
1040 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); | 1047 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); |
1041 if(bufptr->size <= 0) { | 1048 if(bufptr->size <= 0) { |
1042 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { | 1049 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { |
1043 f_exit = TRUE; | 1050 f_exit = TRUE; |
1044 enqueue(p_queue, NULL); | 1051 enqueue(p_queue, NULL); |
1055 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { | 1062 if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) { |
1056 ioctl(tdata.tfd, STOP_REC, 0); | 1063 ioctl(tdata.tfd, STOP_REC, 0); |
1057 /* read remaining data */ | 1064 /* read remaining data */ |
1058 while(1) { | 1065 while(1) { |
1059 bufptr = malloc(sizeof(BUFSZ)); | 1066 bufptr = malloc(sizeof(BUFSZ)); |
1067 if(!bufptr) { | |
1068 f_exit = TRUE; | |
1069 break; | |
1070 } | |
1060 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); | 1071 bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE); |
1061 if(bufptr->size <= 0) { | 1072 if(bufptr->size <= 0) { |
1062 f_exit = TRUE; | 1073 f_exit = TRUE; |
1063 enqueue(p_queue, NULL); | 1074 enqueue(p_queue, NULL); |
1064 break; | 1075 break; |