Changeset 1817
- Timestamp:
- 03/10/10 13:51:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-dvbapi.c
r1807 r1817 32 32 33 33 static int listenfd = -1; 34 int global_support_pip = 0;35 int global_merged_capmt = 0;36 34 37 35 typedef struct ECMPIDS … … 56 54 FILTERTYPE demux_fd[MAX_FILTER]; 57 55 unsigned short cadev_index; 58 unsigned short ca_fd;59 unsigned short active;56 int ca_fd; 57 int socket_fd; 60 58 unsigned short ECMpidcount; 61 59 ECMPIDSTYPE ECMpids[ECM_PIDS]; … … 376 374 demux[demux_id].demux_index=-1; 377 375 demux[demux_id].program_number=0; 376 demux[demux_id].socket_fd=0; 378 377 379 378 dvbapi_stop_filter(demux_id, 0); … … 485 484 void dvbapi_resort_ecmpids(int demux_index) { 486 485 ECMPIDSTYPE tmppids[ECM_PIDS],tmppids2[ECM_PIDS]; 487 int tmppidcount=0,tmppid2count=0,n,i,k ,j;486 int tmppidcount=0,tmppid2count=0,n,i,k=0,j; 488 487 489 488 for (i=0;i<MAX_CAID;i++) 490 489 global_caid_list[i]=0; 491 490 492 k=0;493 491 for (i=0;i<CS_MAXREADER;i++) { 494 492 for (j=0;j<16;j++) { 495 493 if (reader[i].caid[j] != 0) { 496 494 if (k+1>=MAX_CAID) break; 497 global_caid_list[k]=reader[i].caid[j]; 498 k++; 495 global_caid_list[k++]=reader[i].caid[j]; 499 496 } 500 497 } … … 505 502 } else if (dvbapi_check_array(global_caid_list, MAX_CAID, demux[demux_index].ECMpids[n].CA_System_ID)>=0) { 506 503 cs_debug("-> caid list %04x", demux[demux_index].ECMpids[n].CA_System_ID); 507 tmppids[tmppidcount]=demux[demux_index].ECMpids[n]; 508 tmppidcount++; 504 tmppids[tmppidcount++]=demux[demux_index].ECMpids[n]; 509 505 } else if (dvbapi_check_array(prioritytab.caid, CS_MAXCAIDTAB, demux[demux_index].ECMpids[n].CA_System_ID)>=0) { 510 506 cs_debug("-> priority %04x", demux[demux_index].ECMpids[n].CA_System_ID); 511 tmppids[tmppidcount]=demux[demux_index].ECMpids[n]; 512 tmppidcount++; 507 tmppids[tmppidcount++]=demux[demux_index].ECMpids[n]; 513 508 } else { 514 tmppids2[tmppid2count]=demux[demux_index].ECMpids[n]; 515 tmppid2count++; 516 } 517 } 518 519 for (n=0;n<tmppid2count;n++) { 520 tmppids[tmppidcount]=tmppids2[n]; 521 tmppidcount++; 522 } 523 524 for (n=0; n<tmppidcount; n++) { 509 tmppids2[tmppid2count++]=demux[demux_index].ECMpids[n]; 510 } 511 } 512 513 for (n=0;n<tmppid2count;n++) 514 tmppids[tmppidcount++]=tmppids2[n]; 515 516 for (n=0; n<tmppidcount; n++) 525 517 demux[demux_index].ECMpids[n]=tmppids[n]; 526 }527 518 528 519 demux[demux_index].ECMpidcount=tmppidcount; … … 553 544 demux[demux_id].ECMpids[demux[demux_id].ECMpidcount].CA_PID=descriptor_ca_pid; 554 545 demux[demux_id].ECMpids[demux[demux_id].ECMpidcount].CA_System_ID=descriptor_ca_system_id; 555 demux[demux_id].ECMpids[demux[demux_id].ECMpidcount].EMM_PID=0; 556 demux[demux_id].ECMpidcount++; 546 demux[demux_id].ECMpids[demux[demux_id].ECMpidcount++].EMM_PID=0; 557 547 } 558 548 } … … 561 551 562 552 // from tuxbox camd 563 int dvbapi_parse_capmt(unsigned char *buffer, unsigned int length ) {564 unsigned short i , u;553 int dvbapi_parse_capmt(unsigned char *buffer, unsigned int length, int connfd) { 554 unsigned short i; 565 555 unsigned short ca_mask=0x01, demux_index2=0x00; 566 556 … … 585 575 } 586 576 */ 577 587 578 if (buffer[17]==0x82 && buffer[18]==0x02) { 588 579 //enigma2 589 580 ca_mask = buffer[19]; 590 581 demux_index2 = buffer[20]; 591 } else {592 //neutrino workaround593 //dvbapi_stop_descrambling_all(0);594 }595 596 for (i=0;i<MAX_DEMUX;i++) {597 if (demux[i].demux_index==demux_index2 && demux[i].program_number==((buffer[1] << 8) | buffer[2])) { // already descrambling prog on this device598 global_support_pip=1;599 if (demux[i].active==1) {600 //remove any inactive program601 for (u=0;u<MAX_DEMUX;u++) {602 if (demux[u].demux_index==demux_index2 && demux[u].active==0)603 dvbapi_stop_descrambling(u);604 demux[u].active=0;605 }606 } else607 demux[i].active=1;608 return 0;609 }610 }611 612 if (global_support_pip != 1 && global_merged_capmt != 1) {613 dvbapi_stop_descrambling_all(demux_index2);614 582 } 615 583 … … 636 604 demux[demux_id].ECMpidcount=0; 637 605 demux[demux_id].STREAMpidcount=0; 638 demux[demux_id].active=1;639 606 demux[demux_id].cadev_index=demux_index2; 607 demux[demux_id].socket_fd=connfd; 640 608 641 609 for (i=0;i<8;i++) { … … 692 660 693 661 694 void dvbapi_handlesockmsg (unsigned char *buffer, unsigned int len ) {662 void dvbapi_handlesockmsg (unsigned char *buffer, unsigned int len, int connfd) { 695 663 unsigned int val=0, size=0, i, k; 696 664 … … 702 670 } 703 671 704 global_merged_capmt=0; 705 if (k>0) global_merged_capmt=1; 672 if (k>0) { 673 cs_log("dvbapi: Unsupported capmt. Please report"); 674 cs_dump(buffer, len, "capmt:"); 675 } 706 676 707 677 if (buffer[3+k] & 0x80) { … … 717 687 switch(buffer[2+k]) { 718 688 case 0x32: 719 dvbapi_parse_capmt(buffer + size + 3 + k, val );689 dvbapi_parse_capmt(buffer + size + 3 + k, val, connfd); 720 690 break; 721 691 case 0x3f: 722 692 //9F 80 3f 04 83 02 00 <demux index> 723 693 cs_ddump(buffer, len, "capmt 3f:"); 724 int demux_index=buffer[7+k];725 dvbapi_stop_descrambling_all(demux_index);694 //int demux_index=buffer[7+k]; 695 //dvbapi_stop_descrambling_all(demux_index); 726 696 break; 727 697 default: … … 757 727 void *thread_check_zap(void *arg) { 758 728 struct sockaddr_un servaddr; 759 ssize_t len; 760 int connfd,clilen; 729 ssize_t len=0; 730 int connfd,clilen,rc,pfdcount,i,j; 731 struct pollfd pfd2[MAX_DEMUX+1]; 732 733 pfd2[0].fd=listenfd; 734 pfd2[0].events = (POLLIN | POLLPRI); 761 735 762 736 while(1) { 763 737 //cs_debug("dvbapi: check zap"); 764 765 connfd = accept(listenfd, (struct sockaddr *)&servaddr, (socklen_t *)&clilen); 766 767 if (connfd <= 0) { //socket not available 768 cs_debug("dvbapi: socket not available"); 769 break; 770 } 771 772 len = read(connfd, mbuf, sizeof(mbuf)); 773 774 if (len < 3) { 775 cs_debug("dvbapi: camd.socket: too short message received"); 776 continue; 777 } 778 779 // if message begins with an apdu_tag and is longer than three bytes 780 if ((mbuf[0] == 0x9F) && ((mbuf[1] >> 7) == 0x01) && ((mbuf[2] >> 7) == 0x00)) { 781 dvbapi_handlesockmsg(mbuf, len); 782 } else { 783 cs_debug("dvbapi: invaild capmt"); 784 } 785 786 close(connfd); 787 cs_sleepms(500); 738 pfdcount=1; 739 740 for (i=0;i<MAX_DEMUX;i++) { 741 if (demux[i].socket_fd>0) { 742 pfd2[pfdcount].fd=demux[i].socket_fd; 743 pfd2[pfdcount++].events = (POLLIN | POLLPRI | POLLHUP); 744 } 745 } 746 747 rc = poll(pfd2, pfdcount, -1); 748 749 for (i = 0; i < pfdcount; i++) { 750 cs_debug("dvbapi: Event %d on socket", pfd2[i].revents); 751 if (pfd2[i].revents & (POLLHUP | POLLNVAL)) { 752 for (j=0;j<MAX_DEMUX;j++) { 753 if (demux[j].socket_fd==pfd2[i].fd) 754 cs_debug("dvbapi: closing socket (demux_index: %d)", j); 755 dvbapi_stop_descrambling(j); 756 757 } 758 close(pfd2[i].fd); 759 continue; 760 } 761 if (pfd2[i].revents & (POLLIN | POLLPRI)) { 762 if (pfd2[i].fd==listenfd) { 763 cs_debug("dvbapi: new socket connection"); 764 connfd = accept(listenfd, (struct sockaddr *)&servaddr, (socklen_t *)&clilen); 765 766 if (connfd <= 0) { //socket not available 767 cs_debug("dvbapi: socket not available"); 768 continue; 769 } 770 771 len = read(connfd, mbuf, sizeof(mbuf)); 772 773 if (len < 3) { 774 cs_debug("dvbapi: camd.socket: too short message received"); 775 continue; 776 } 777 778 // if message begins with an apdu_tag and is longer than three bytes 779 if ((mbuf[0] == 0x9F) && ((mbuf[1] >> 7) == 0x01) && ((mbuf[2] >> 7) == 0x00)) 780 dvbapi_handlesockmsg(mbuf, len, connfd); 781 else 782 cs_debug("dvbapi: invaild capmt"); 783 } else { 784 cs_log("dvbapi: New capmt on old socket. Please report."); 785 cs_dump(mbuf, len, "capmt:"); 786 } 787 } 788 789 } 788 790 } 789 791 … … 806 808 { 807 809 ctab->caid[i]=caid; 808 ctab->mask[i]=prov; 809 i++; 810 ctab->mask[i++]=prov; 810 811 } 811 812 } … … 839 840 demux[i].ca_fd=0; 840 841 demux[i].demux_index=-1; 842 demux[i].socket_fd=0; 841 843 memset(demux[i].buffer_cache_dmx, 0, CS_ECMSTORESIZE); 842 844 for (rc=0;rc<MAX_FILTER;rc++) demux[i].demux_fd[rc].fd=0; … … 882 884 pfd2[pfdcount].events = (POLLIN | POLLPRI); 883 885 ids[pfdcount]=i; 884 fdn[pfdcount]=g; 885 pfdcount++; 886 fdn[pfdcount++]=g; 886 887 } 887 888 }
Note:
See TracChangeset
for help on using the changeset viewer.