/** * @brief Open filters for the pids in asked_pid. This function update the asked_pid array and * can be called more than one time if new pids are added (typical case autoconf) * Ie it asks the card for the pid list by calling set_ts_filt * @param asked_pid the array of asked pids * @param fds the structure with the file descriptors */ void set_filters(uint8_t *asked_pid, fds_t *fds) { int curr_pid = 0; for(curr_pid=0;curr_pid<8193;curr_pid++) if ((asked_pid[curr_pid] == PID_ASKED) ) { set_ts_filt (fds->fd_demuxer[curr_pid], curr_pid); asked_pid[curr_pid] = PID_FILTERED; } }
int main(int argc, char *argv[]) { // filedescriptors for video, audio and dvr-device int fda,fdv; int fd_dvr; // pids for video and audio stream uint16_t vpid = 0; uint16_t apid = 0; struct sockaddr_in si; int socketIn; char *ip = "224.0.1.2"; int port = 5004; // process command-line arguments static struct option long_options[]={ {"group", required_argument, NULL, 'g'}, {"port", required_argument, NULL, 'p'}, {"vpid", required_argument, NULL, 'v'}, {"apid", required_argument, NULL, 'a'}, {"help", no_argument, NULL, 'h'}, {0} }; int c; int option_index = 0; fprintf(stderr,"*** rtpfeed 0.1 ***\n"); while((c = getopt_long(argc, argv, "g:p:v:a:h",long_options, &option_index))!=-1) { switch(c) { case 'g': ip = optarg; break; case 'p': port = atoi(optarg); break; case 'v': vpid = atoi(optarg); break; case 'a': apid = atoi(optarg); break; case 'h': fprintf(stderr,"Usage: %s [-g group] [-p port] [-v video PID] [-a audio PID] \n",argv[0]); exit(1); }// end switch }// end while // open dvr device for output if((fd_dvr = open("/dev/ost/dvr",O_WRONLY)) < 0){ perror("DVR DEVICE: "); return -1; } // open video device, set filters if(vpid!=0){ if((fdv = open("/dev/ost/demux",O_RDWR|O_NONBLOCK)) < 0){ perror("DEMUX DEVICE: "); return -1; }// end if set_ts_filt(fdv, vpid, 1); }// end if // open audio device, set filters if(apid!=0){ if((fda = open("/dev/ost/demux",O_RDWR|O_NONBLOCK)) < 0){ perror("DEMUX DEVICE: "); return -1; }// end if set_ts_filt(fda, apid, 2); }// end if socketIn = makeclientsocket(ip,port,2,&si); dumprtp(socketIn, fd_dvr); close(socketIn); return(0); }
int process_telnet() { char cmd[1024]; int cmd_i=0; int i; char* ch; dmx_pes_type_t pestype; unsigned long freq=0; unsigned long srate=0; /* Open a new telnet session if a client is trying to connect */ if (ns==-1) { if ((ns = accept(socketIn, (struct sockaddr *)&fsin, &fromlen)) > 0) { make_nonblock(ns); cmd_i=0; cmd[0]=0; printf("Opened connection\n"); writes(ns,"220-DVBSTREAM - "); writes(ns,hostname); writes(ns,"\r\nDONE\r\n"); connectionOpen=1; } } /* If a telnet session is open, receive and process any input */ if (connectionOpen) { /* Read in at most a line of text - any ctrl character ends the line */ while (read(ns,&in_ch,1)>0) { if (in_ch < 32) break; /* Prevent buffer overflows */ if (cmd_i < 1024-1) { cmd[cmd_i++]=in_ch; cmd[cmd_i]=0; } } if (in_ch > 0) { if (cmd_i > 0) { printf("CMD: \"%s\"\n",cmd); if (strcasecmp(cmd,"QUIT")==0) { writes(ns,"DONE\r\n"); close(ns); ns=-1; connectionOpen=0; printf("Closed connection\n"); } else if (strcasecmp(cmd,"STOP")==0) { writes(ns,"STOP\n"); for (i=0;i<npids;i++) { if (ioctl(fd[i], DMX_STOP) < 0) { perror("DMX_STOP"); } } for (i=0;i<8192;i++) { hi_mappids[i]=(i >> 8); lo_mappids[i]=(i&0xff); } writes(ns,"DONE\r\n"); } else if (strncasecmp(cmd,"ADD",3)==0) { i=4; if ((cmd[3]=='V') || (cmd[3]=='v')) pestype=DMX_PES_VIDEO; else if ((cmd[3]=='A') || (cmd[3]=='a')) pestype=DMX_PES_AUDIO; else if ((cmd[3]=='T') || (cmd[3]=='t')) pestype=DMX_PES_TELETEXT; else { pestype=DMX_PES_OTHER; i=3; } while (cmd[i]==' ') i++; if ((ch=(char*)strstr(&cmd[i],":"))!=NULL) { pid2=atoi(&ch[1]); ch[0]=0; } else { pid2=-1; } pid=atoi(&cmd[i]); if (pid) { if (npids == MAX_CHANNELS) { fprintf(stderr,"\nsorry, you can only set up to 8 filters.\n\n"); return(-1); } else { pestypes[npids]=pestype; pestype=DMX_PES_OTHER; pids[npids]=pid; if (pid2!=-1) { hi_mappids[pid]=pid2>>8; lo_mappids[pid]=pid2&0xff; fprintf(stderr,"Mapping %d to %d\n",pid,pid2); } if((fd[npids] = open(demuxdev[card],O_RDWR|O_NONBLOCK)) < 0){ fprintf(stderr,"FD %i: ",i); perror("DEMUX DEVICE: "); } else { set_ts_filt(fd[npids],pids[npids],pestypes[npids]); npids++; } } }