comparison stream/stream_dvb.c @ 29263:0f1b5b68af32

whitespace cosmetics: Remove all trailing whitespace.
author diego
date Wed, 13 May 2009 02:58:57 +0000
parents 9e739bdb049c
children b5e34617a096
comparison
equal deleted inserted replaced
29262:7d545a6b8aff 29263:0f1b5b68af32
130 char tmp_lcr[256], tmp_hier[256], inv[256], bw[256], cr[256], mod[256], transm[256], gi[256], vpid_str[256], apid_str[256]; 130 char tmp_lcr[256], tmp_hier[256], inv[256], bw[256], cr[256], mod[256], transm[256], gi[256], vpid_str[256], apid_str[256];
131 const char *cbl_conf = "%d:%255[^:]:%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n"; 131 const char *cbl_conf = "%d:%255[^:]:%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n";
132 const char *sat_conf = "%d:%c:%d:%d:%255[^:]:%255[^:]\n"; 132 const char *sat_conf = "%d:%c:%d:%d:%255[^:]:%255[^:]\n";
133 const char *ter_conf = "%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n"; 133 const char *ter_conf = "%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n";
134 const char *atsc_conf = "%d:%255[^:]:%255[^:]:%255[^:]\n"; 134 const char *atsc_conf = "%d:%255[^:]:%255[^:]:%255[^:]\n";
135 135
136 mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type); 136 mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type);
137 if((f=fopen(filename, "r"))==NULL) 137 if((f=fopen(filename, "r"))==NULL)
138 { 138 {
139 mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename); 139 mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename);
140 return NULL; 140 return NULL;
231 { 231 {
232 ptr->pids_cnt = pcnt; 232 ptr->pids_cnt = pcnt;
233 fields++; 233 fields++;
234 } 234 }
235 } 235 }
236 236
237 if(apid_str[0]) 237 if(apid_str[0])
238 { 238 {
239 cnt = ptr->pids_cnt; 239 cnt = ptr->pids_cnt;
240 pcnt = sscanf(apid_str, "%d+%d+%d+%d+%d+%d+%d+%d", &ptr->pids[cnt], &ptr->pids[cnt+1], &ptr->pids[cnt+2], 240 pcnt = sscanf(apid_str, "%d+%d+%d+%d+%d+%d+%d+%d", &ptr->pids[cnt], &ptr->pids[cnt+1], &ptr->pids[cnt+2],
241 &ptr->pids[cnt+3], &ptr->pids[cnt+4], &ptr->pids[cnt+5], &ptr->pids[cnt+6], &ptr->pids[cnt+7]); 241 &ptr->pids[cnt+3], &ptr->pids[cnt+4], &ptr->pids[cnt+5], &ptr->pids[cnt+6], &ptr->pids[cnt+7]);
269 } 269 }
270 mp_msg(MSGT_DEMUX, MSGL_V, " PIDS: "); 270 mp_msg(MSGT_DEMUX, MSGL_V, " PIDS: ");
271 for(cnt = 0; cnt < ptr->pids_cnt; cnt++) 271 for(cnt = 0; cnt < ptr->pids_cnt; cnt++)
272 mp_msg(MSGT_DEMUX, MSGL_V, " %d ", ptr->pids[cnt]); 272 mp_msg(MSGT_DEMUX, MSGL_V, " %d ", ptr->pids[cnt]);
273 mp_msg(MSGT_DEMUX, MSGL_V, "\n"); 273 mp_msg(MSGT_DEMUX, MSGL_V, "\n");
274 274
275 if((type == TUNER_TER) || (type == TUNER_CBL)) 275 if((type == TUNER_TER) || (type == TUNER_CBL))
276 { 276 {
277 if(! strcmp(inv, "INVERSION_ON")) 277 if(! strcmp(inv, "INVERSION_ON"))
278 ptr->inv = INVERSION_ON; 278 ptr->inv = INVERSION_ON;
279 else if(! strcmp(inv, "INVERSION_OFF")) 279 else if(! strcmp(inv, "INVERSION_OFF"))
302 ptr->cr =FEC_7_8; 302 ptr->cr =FEC_7_8;
303 else if(! strcmp(cr, "FEC_NONE")) 303 else if(! strcmp(cr, "FEC_NONE"))
304 ptr->cr =FEC_NONE; 304 ptr->cr =FEC_NONE;
305 else ptr->cr =FEC_AUTO; 305 else ptr->cr =FEC_AUTO;
306 } 306 }
307 307
308 308
309 if((type == TUNER_TER) || (type == TUNER_CBL) || (type == TUNER_ATSC)) 309 if((type == TUNER_TER) || (type == TUNER_CBL) || (type == TUNER_ATSC))
310 { 310 {
311 if(! strcmp(mod, "QAM_128")) 311 if(! strcmp(mod, "QAM_128"))
312 ptr->mod = QAM_128; 312 ptr->mod = QAM_128;
316 ptr->mod = QAM_64; 316 ptr->mod = QAM_64;
317 else if(! strcmp(mod, "QAM_32")) 317 else if(! strcmp(mod, "QAM_32"))
318 ptr->mod = QAM_32; 318 ptr->mod = QAM_32;
319 else if(! strcmp(mod, "QAM_16")) 319 else if(! strcmp(mod, "QAM_16"))
320 ptr->mod = QAM_16; 320 ptr->mod = QAM_16;
321 #ifdef DVB_ATSC 321 #ifdef DVB_ATSC
322 else if(! strcmp(mod, "VSB_8") || ! strcmp(mod, "8VSB")) 322 else if(! strcmp(mod, "VSB_8") || ! strcmp(mod, "8VSB"))
323 ptr->mod = VSB_8; 323 ptr->mod = VSB_8;
324 else if(! strcmp(mod, "VSB_16") || !strcmp(mod, "16VSB")) 324 else if(! strcmp(mod, "VSB_16") || !strcmp(mod, "16VSB"))
325 ptr->mod = VSB_16; 325 ptr->mod = VSB_16;
326 326
349 else if(! strcmp(gi, "GUARD_INTERVAL_1_16")) 349 else if(! strcmp(gi, "GUARD_INTERVAL_1_16"))
350 ptr->gi = GUARD_INTERVAL_1_16; 350 ptr->gi = GUARD_INTERVAL_1_16;
351 else if(! strcmp(gi, "GUARD_INTERVAL_1_8")) 351 else if(! strcmp(gi, "GUARD_INTERVAL_1_8"))
352 ptr->gi = GUARD_INTERVAL_1_8; 352 ptr->gi = GUARD_INTERVAL_1_8;
353 else ptr->gi = GUARD_INTERVAL_1_4; 353 else ptr->gi = GUARD_INTERVAL_1_4;
354 354
355 if(! strcmp(tmp_lcr, "FEC_1_2")) 355 if(! strcmp(tmp_lcr, "FEC_1_2"))
356 ptr->cr_lp =FEC_1_2; 356 ptr->cr_lp =FEC_1_2;
357 else if(! strcmp(tmp_lcr, "FEC_2_3")) 357 else if(! strcmp(tmp_lcr, "FEC_2_3"))
358 ptr->cr_lp =FEC_2_3; 358 ptr->cr_lp =FEC_2_3;
359 else if(! strcmp(tmp_lcr, "FEC_3_4")) 359 else if(! strcmp(tmp_lcr, "FEC_3_4"))
371 else if(! strcmp(tmp_lcr, "FEC_7_8")) 371 else if(! strcmp(tmp_lcr, "FEC_7_8"))
372 ptr->cr_lp =FEC_7_8; 372 ptr->cr_lp =FEC_7_8;
373 else if(! strcmp(tmp_lcr, "FEC_NONE")) 373 else if(! strcmp(tmp_lcr, "FEC_NONE"))
374 ptr->cr_lp =FEC_NONE; 374 ptr->cr_lp =FEC_NONE;
375 else ptr->cr_lp =FEC_AUTO; 375 else ptr->cr_lp =FEC_AUTO;
376 376
377 377
378 if(! strcmp(tmp_hier, "HIERARCHY_1")) 378 if(! strcmp(tmp_hier, "HIERARCHY_1"))
379 ptr->hier = HIERARCHY_1; 379 ptr->hier = HIERARCHY_1;
380 else if(! strcmp(tmp_hier, "HIERARCHY_2")) 380 else if(! strcmp(tmp_hier, "HIERARCHY_2"))
381 ptr->hier = HIERARCHY_2; 381 ptr->hier = HIERARCHY_2;
382 else if(! strcmp(tmp_hier, "HIERARCHY_4")) 382 else if(! strcmp(tmp_hier, "HIERARCHY_4"))
417 417
418 void dvb_free_config(dvb_config_t *config) 418 void dvb_free_config(dvb_config_t *config)
419 { 419 {
420 int i, j; 420 int i, j;
421 421
422 for(i=0; i<config->count; i++) 422 for(i=0; i<config->count; i++)
423 { 423 {
424 if(config->cards[i].name) 424 if(config->cards[i].name)
425 free(config->cards[i].name); 425 free(config->cards[i].name);
426 if(!config->cards[i].list) 426 if(!config->cards[i].list)
427 continue; 427 continue;
433 free(config->cards[i].list->channels[j].name); 433 free(config->cards[i].list->channels[j].name);
434 } 434 }
435 free(config->cards[i].list->channels); 435 free(config->cards[i].list->channels);
436 } 436 }
437 free(config->cards[i].list); 437 free(config->cards[i].list);
438 } 438 }
439 free(config); 439 free(config);
440 } 440 }
441 441
442 static int dvb_streaming_read(stream_t *stream, char *buffer, int size) 442 static int dvb_streaming_read(stream_t *stream, char *buffer, int size)
443 { 443 {
446 dvb_priv_t *priv = (dvb_priv_t *) stream->priv; 446 dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
447 447
448 mp_msg(MSGT_DEMUX, MSGL_DBG3, "dvb_streaming_read(%d)\n", size); 448 mp_msg(MSGT_DEMUX, MSGL_DBG3, "dvb_streaming_read(%d)\n", size);
449 449
450 tries = priv->retry + 1; 450 tries = priv->retry + 1;
451 451
452 fd = stream->fd; 452 fd = stream->fd;
453 while(pos < size) 453 while(pos < size)
454 { 454 {
455 pfds[0].fd = fd; 455 pfds[0].fd = fd;
456 pfds[0].events = POLLIN | POLLPRI; 456 pfds[0].events = POLLIN | POLLPRI;
469 { 469 {
470 pos += rk; 470 pos += rk;
471 mp_msg(MSGT_DEMUX, MSGL_DBG3, "ret (%d) bytes\n", pos); 471 mp_msg(MSGT_DEMUX, MSGL_DBG3, "ret (%d) bytes\n", pos);
472 } 472 }
473 } 473 }
474 474
475 475
476 if(! pos) 476 if(! pos)
477 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, return %d bytes\n", pos); 477 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, return %d bytes\n", pos);
478 478
479 return pos; 479 return pos;
494 if((card < 0) || (card > conf->count)) 494 if((card < 0) || (card > conf->count))
495 { 495 {
496 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CARD NUMBER: %d vs %d, abort\n", card, conf->count); 496 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CARD NUMBER: %d vs %d, abort\n", card, conf->count);
497 return 0; 497 return 0;
498 } 498 }
499 499
500 devno = conf->cards[card].devno; 500 devno = conf->cards[card].devno;
501 new_list = conf->cards[card].list; 501 new_list = conf->cards[card].list;
502 if((n > new_list->NUM_CHANNELS) || (n < 0)) 502 if((n > new_list->NUM_CHANNELS) || (n < 0))
503 { 503 {
504 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, for card %d, abort\n", n, card); 504 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, for card %d, abort\n", n, card);
505 return 0; 505 return 0;
506 } 506 }
507 channel = &(new_list->channels[n]); 507 channel = &(new_list->channels[n]);
508 508
509 if(priv->is_on) //the fds are already open and we have to stop the demuxers 509 if(priv->is_on) //the fds are already open and we have to stop the demuxers
510 { 510 {
511 for(i = 0; i < priv->demux_fds_cnt; i++) 511 for(i = 0; i < priv->demux_fds_cnt; i++)
512 dvb_demux_stop(priv->demux_fds[i]); 512 dvb_demux_stop(priv->demux_fds[i]);
513 513
514 priv->retry = 0; 514 priv->retry = 0;
515 while(dvb_streaming_read(stream, buf, 4096) > 0); //empty both the stream's and driver's buffer 515 while(dvb_streaming_read(stream, buf, 4096) > 0); //empty both the stream's and driver's buffer
516 if(priv->card != card) 516 if(priv->card != card)
517 { 517 {
518 dvbin_close(stream); 518 dvbin_close(stream);
521 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB_SET_CHANNEL, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card); 521 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB_SET_CHANNEL, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card);
522 return 0; 522 return 0;
523 } 523 }
524 } 524 }
525 else //close all demux_fds with pos > pids required for the new channel or open other demux_fds if we have too few 525 else //close all demux_fds with pos > pids required for the new channel or open other demux_fds if we have too few
526 { 526 {
527 if(! dvb_fix_demuxes(priv, channel->pids_cnt)) 527 if(! dvb_fix_demuxes(priv, channel->pids_cnt))
528 return 0; 528 return 0;
529 } 529 }
530 } 530 }
531 else 531 else
560 for(i = 0; i < channel->pids_cnt; i++) 560 for(i = 0; i < channel->pids_cnt; i++)
561 { 561 {
562 if(! dvb_set_ts_filt(priv->demux_fds[i], channel->pids[i], DMX_PES_OTHER)) 562 if(! dvb_set_ts_filt(priv->demux_fds[i], channel->pids[i], DMX_PES_OTHER))
563 return 0; 563 return 0;
564 } 564 }
565 565
566 return 1; 566 return 1;
567 } 567 }
568 568
569 569
570 570
710 free(priv); 710 free(priv);
711 mp_msg(MSGT_DEMUX, MSGL_ERR, "NO CONFIGURATION FOUND FOR CARD N. %d, exit\n", p->card); 711 mp_msg(MSGT_DEMUX, MSGL_ERR, "NO CONFIGURATION FOUND FOR CARD N. %d, exit\n", p->card);
712 return STREAM_ERROR; 712 return STREAM_ERROR;
713 } 713 }
714 priv->timeout = p->timeout; 714 priv->timeout = p->timeout;
715 715
716 tuner_type = priv->config->cards[priv->card].type; 716 tuner_type = priv->config->cards[priv->card].type;
717 717
718 if(tuner_type == 0) 718 if(tuner_type == 0)
719 { 719 {
720 free(priv); 720 free(priv);
727 727
728 mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: prog=%s, card=%d, type=%d\n", 728 mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: prog=%s, card=%d, type=%d\n",
729 p->prog, priv->card+1, priv->tuner_type); 729 p->prog, priv->card+1, priv->tuner_type);
730 730
731 priv->list = priv->config->cards[priv->card].list; 731 priv->list = priv->config->cards[priv->card].list;
732 732
733 if((! strcmp(p->prog, "")) && (priv->list != NULL)) 733 if((! strcmp(p->prog, "")) && (priv->list != NULL))
734 progname = priv->list->channels[0].name; 734 progname = priv->list->channels[0].name;
735 else 735 else
736 progname = p->prog; 736 progname = p->prog;
737 737
745 745
746 stream->type = STREAMTYPE_DVB; 746 stream->type = STREAMTYPE_DVB;
747 stream->fill_buffer = dvb_streaming_read; 747 stream->fill_buffer = dvb_streaming_read;
748 stream->close = dvbin_close; 748 stream->close = dvbin_close;
749 m_struct_free(&stream_opts, opts); 749 m_struct_free(&stream_opts, opts);
750 750
751 *file_format = DEMUXER_TYPE_MPEG_TS; 751 *file_format = DEMUXER_TYPE_MPEG_TS;
752 752
753 return STREAM_OK; 753 return STREAM_OK;
754 } 754 }
755 755
759 int i, fd, type, size; 759 int i, fd, type, size;
760 char filename[30], *conf_file, *name; 760 char filename[30], *conf_file, *name;
761 dvb_channels_list *list; 761 dvb_channels_list *list;
762 dvb_card_config_t *cards = NULL, *tmp; 762 dvb_card_config_t *cards = NULL, *tmp;
763 dvb_config_t *conf = NULL; 763 dvb_config_t *conf = NULL;
764 764
765 765
766 conf = malloc(sizeof(dvb_config_t)); 766 conf = malloc(sizeof(dvb_config_t));
767 if(conf == NULL) 767 if(conf == NULL)
768 return NULL; 768 return NULL;
769 769
770 conf->priv = NULL; 770 conf->priv = NULL;
771 conf->count = 0; 771 conf->count = 0;
772 conf->cards = NULL; 772 conf->cards = NULL;
773 for(i=0; i<MAX_CARDS; i++) 773 for(i=0; i<MAX_CARDS; i++)
774 { 774 {
775 snprintf(filename, sizeof(filename), "/dev/dvb/adapter%d/frontend0", i); 775 snprintf(filename, sizeof(filename), "/dev/dvb/adapter%d/frontend0", i);
777 if(fd < 0) 777 if(fd < 0)
778 { 778 {
779 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't open device %s, skipping\n", filename); 779 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't open device %s, skipping\n", filename);
780 continue; 780 continue;
781 } 781 }
782 782
783 type = dvb_get_tuner_type(fd); 783 type = dvb_get_tuner_type(fd);
784 close(fd); 784 close(fd);
785 if(type != TUNER_SAT && type != TUNER_TER && type != TUNER_CBL && type != TUNER_ATSC) 785 if(type != TUNER_SAT && type != TUNER_TER && type != TUNER_CBL && type != TUNER_ATSC)
786 { 786 {
787 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't detect tuner type of card %d, skipping\n", i); 787 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't detect tuner type of card %d, skipping\n", i);
788 continue; 788 continue;
789 } 789 }
790 790
791 switch(type) 791 switch(type)
792 { 792 {
793 case TUNER_TER: 793 case TUNER_TER:
794 conf_file = get_path("channels.conf.ter"); 794 conf_file = get_path("channels.conf.ter");
795 break; 795 break;
801 break; 801 break;
802 case TUNER_ATSC: 802 case TUNER_ATSC:
803 conf_file = get_path("channels.conf.atsc"); 803 conf_file = get_path("channels.conf.atsc");
804 break; 804 break;
805 } 805 }
806 806
807 if((access(conf_file, F_OK | R_OK) != 0)) 807 if((access(conf_file, F_OK | R_OK) != 0))
808 { 808 {
809 if(conf_file) 809 if(conf_file)
810 free(conf_file); 810 free(conf_file);
811 conf_file = get_path("channels.conf"); 811 conf_file = get_path("channels.conf");
820 list = dvb_get_channels(conf_file, type); 820 list = dvb_get_channels(conf_file, type);
821 if(conf_file) 821 if(conf_file)
822 free(conf_file); 822 free(conf_file);
823 if(list == NULL) 823 if(list == NULL)
824 continue; 824 continue;
825 825
826 size = sizeof(dvb_card_config_t) * (conf->count + 1); 826 size = sizeof(dvb_card_config_t) * (conf->count + 1);
827 tmp = realloc(conf->cards, size); 827 tmp = realloc(conf->cards, size);
828 828
829 if(tmp == NULL) 829 if(tmp == NULL)
830 { 830 {
863 const stream_info_t stream_info_dvb = { 863 const stream_info_t stream_info_dvb = {
864 "Dvb Input", 864 "Dvb Input",
865 "dvbin", 865 "dvbin",
866 "Nico", 866 "Nico",
867 "based on the code from ??? (probably Arpi)", 867 "based on the code from ??? (probably Arpi)",
868 dvb_open, 868 dvb_open,
869 { "dvb", NULL }, 869 { "dvb", NULL },
870 &stream_opts, 870 &stream_opts,
871 1 // Urls are an option string 871 1 // Urls are an option string
872 }; 872 };