comparison stream/tv.c @ 24246:0a82a3b7ac46

Move channels option parsing code into separate routine.
author voroshil
date Tue, 28 Aug 2007 14:36:13 +0000
parents 9e71e0345c35
children d31512f03462
comparison
equal deleted inserted replaced
24245:188964a48302 24246:0a82a3b7ac46
234 return *(int *)str; 234 return *(int *)str;
235 } 235 }
236 #endif 236 #endif
237 } 237 }
238 238
239 static void parse_channels(tvi_handle_t *tvh)
240 {
241 char** channels = tvh->tv_param->channels;
242
243 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_ChannelNamesDetected);
244 tv_channel_list = malloc(sizeof(tv_channels_t));
245 tv_channel_list->index=1;
246 tv_channel_list->next=NULL;
247 tv_channel_list->prev=NULL;
248 tv_channel_current = tv_channel_list;
249
250 while (*channels) {
251 char* tmp = *(channels++);
252 char* sep = strchr(tmp,'-');
253 int i;
254 struct CHANLIST cl;
255
256 if (!sep) continue; // Wrong syntax, but mplayer should not crash
257
258 av_strlcpy(tv_channel_current->name, sep + 1,
259 sizeof(tv_channel_current->name));
260 sep[0] = '\0';
261 strncpy(tv_channel_current->number, tmp, 5);
262 tv_channel_current->number[4]='\0';
263
264 while ((sep=strchr(tv_channel_current->name, '_')))
265 sep[0] = ' ';
266
267 // if channel number is a number and larger than 1000 threat it as frequency
268 // tmp still contain pointer to null-terminated string with channel number here
269 if (atoi(tmp)>1000){
270 tv_channel_current->freq=atoi(tmp);
271 }else{
272 tv_channel_current->freq = 0;
273 for (i = 0; i < chanlists[tvh->chanlist].count; i++) {
274 cl = tvh->chanlist_s[i];
275 if (!strcasecmp(cl.name, tv_channel_current->number)) {
276 tv_channel_current->freq=cl.freq;
277 break;
278 }
279 }
280 }
281 if (tv_channel_current->freq == 0)
282 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_NoFreqForChannel,
283 tv_channel_current->number, tv_channel_current->name);
284 else {
285 sep = strchr(tv_channel_current->name, '-');
286 if ( !sep ) sep = strchr(tv_channel_current->name, '+');
287
288 if ( sep ) {
289 i = atoi (sep+1);
290 if ( sep[0] == '+' ) tv_channel_current->freq += i * 100;
291 if ( sep[0] == '-' ) tv_channel_current->freq -= i * 100;
292 sep[0] = '\0';
293 }
294 }
295
296 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
297 tv_channel_current->number, tv_channel_current->name,
298 (float)tv_channel_current->freq/1000);*/
299
300 tv_channel_current->next = malloc(sizeof(tv_channels_t));
301 tv_channel_current->next->index = tv_channel_current->index + 1;
302 tv_channel_current->next->prev = tv_channel_current;
303 tv_channel_current->next->next = NULL;
304 tv_channel_current = tv_channel_current->next;
305 }
306 if (tv_channel_current->prev)
307 tv_channel_current->prev->next = NULL;
308 free(tv_channel_current);
309 }
239 static int open_tv(tvi_handle_t *tvh) 310 static int open_tv(tvi_handle_t *tvh)
240 { 311 {
241 int i; 312 int i;
242 tvi_functions_t *funcs = tvh->functions; 313 tvi_functions_t *funcs = tvh->functions;
243 int tv_fmt_list[] = { 314 int tv_fmt_list[] = {
383 goto done; 454 goto done;
384 } 455 }
385 456
386 /* Handle channel names */ 457 /* Handle channel names */
387 if (tvh->tv_param->channels) { 458 if (tvh->tv_param->channels) {
388 char** channels = tvh->tv_param->channels; 459 parse_channels(tvh);
389 mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_ChannelNamesDetected);
390 tv_channel_list = malloc(sizeof(tv_channels_t));
391 tv_channel_list->index=1;
392 tv_channel_list->next=NULL;
393 tv_channel_list->prev=NULL;
394 tv_channel_current = tv_channel_list;
395
396 while (*channels) {
397 char* tmp = *(channels++);
398 char* sep = strchr(tmp,'-');
399 int i;
400 struct CHANLIST cl;
401
402 if (!sep) continue; // Wrong syntax, but mplayer should not crash
403
404 av_strlcpy(tv_channel_current->name, sep + 1,
405 sizeof(tv_channel_current->name));
406 sep[0] = '\0';
407 strncpy(tv_channel_current->number, tmp, 5);
408 tv_channel_current->number[4]='\0';
409
410 while ((sep=strchr(tv_channel_current->name, '_')))
411 sep[0] = ' ';
412
413 // if channel number is a number and larger than 1000 threat it as frequency
414 // tmp still contain pointer to null-terminated string with channel number here
415 if (atoi(tmp)>1000){
416 tv_channel_current->freq=atoi(tmp);
417 }else{
418 tv_channel_current->freq = 0;
419 for (i = 0; i < chanlists[tvh->chanlist].count; i++) {
420 cl = tvh->chanlist_s[i];
421 if (!strcasecmp(cl.name, tv_channel_current->number)) {
422 tv_channel_current->freq=cl.freq;
423 break;
424 }
425 }
426 }
427 if (tv_channel_current->freq == 0)
428 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_NoFreqForChannel,
429 tv_channel_current->number, tv_channel_current->name);
430 else {
431 sep = strchr(tv_channel_current->name, '-');
432 if ( !sep ) sep = strchr(tv_channel_current->name, '+');
433
434 if ( sep ) {
435 i = atoi (sep+1);
436 if ( sep[0] == '+' ) tv_channel_current->freq += i * 100;
437 if ( sep[0] == '-' ) tv_channel_current->freq -= i * 100;
438 sep[0] = '\0';
439 }
440 }
441
442 /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
443 tv_channel_current->number, tv_channel_current->name,
444 (float)tv_channel_current->freq/1000);*/
445
446 tv_channel_current->next = malloc(sizeof(tv_channels_t));
447 tv_channel_current->next->index = tv_channel_current->index + 1;
448 tv_channel_current->next->prev = tv_channel_current;
449 tv_channel_current->next->next = NULL;
450 tv_channel_current = tv_channel_current->next;
451 }
452 if (tv_channel_current->prev)
453 tv_channel_current->prev->next = NULL;
454 free(tv_channel_current);
455 } else 460 } else
456 tv_channel_last_real = malloc(5); 461 tv_channel_last_real = malloc(5);
457 462
458 if (tv_channel_list) { 463 if (tv_channel_list) {
459 int i; 464 int i;