📄 dvb.c
字号:
/* Set the frequency of the transponder, taking into account the local frequencies of the LNB */ hiband = (fep.frequency >= u_lnb_slof); if ((ret=ioctl_SetupSwitch (p_input, front, 0, b_polarisation, hiband))<0) { msg_Err(p_input, "DVB-S: Setup frontend switch failed (%d)", ret); return -1; } if (hiband) fep.frequency -= u_lnb_lof2; else fep.frequency -= u_lnb_lof1; /* Now send it all to the frontend device */ if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0) { close(front);# ifdef HAVE_ERRNO_H msg_Err(p_input, "DVB-S: setting frontend failed (%d) %s", ret, strerror(errno));# else msg_Err(p_input, "DVB-S: setting frontend failed (%d)", ret);# endif return -1; } ret = ioctl_CheckFrontend(p_input, front); /* Fixme: Return this instead of closing it. Close front end device */ close(front); return ret;}int ioctl_SetOFDMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, unsigned int u_adapter, unsigned int u_device ){ int ret; int front; char frontend[] = FRONTEND; int i_len; i_len = sizeof(FRONTEND); if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len) { msg_Err(p_input, "DVB-T FrontEnd snprintf() truncated string for FRONTEND" ); frontend[sizeof(FRONTEND)] = '\0'; } /* Open the frontend device */ msg_Dbg(p_input, "DVB-T: Opening frontend %s", frontend); if(( front = open(frontend,O_RDWR)) < 0) {# ifdef HAVE_ERRNO_H msg_Err(p_input, "DVB-T: failed to open frontend (%s)", strerror(errno));# else msg_Err(p_input, "DVB-T: failed to open frontend");# endif return -1; } /* Now send it all to the frontend device */ if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0) { close(front);# ifdef HAVE_ERRNO_H msg_Err(p_input, "DVB-T: setting frontend failed (%d) %s", ret, strerror(errno));# else msg_Err(p_input, "DVB-T: setting frontend failed (%d)", ret);# endif return -1; } ret = ioctl_CheckFrontend(p_input, front); /* Fixme: Return this instead of closing it. Close front end device */ close(front); return ret;}int ioctl_SetQAMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, unsigned int u_adapter, unsigned int u_device ){ int ret; int front; char frontend[] = FRONTEND; int i_len; i_len = sizeof(FRONTEND); if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len) { msg_Err(p_input, "DVB-C: FrontEnd snprintf() truncated string for FRONTEND" ); frontend[sizeof(FRONTEND)] = '\0'; } /* Open the frontend device */ msg_Dbg(p_input, "DVB-C: Opening frontend %s", frontend); if(( front = open(frontend,O_RDWR)) < 0) {# ifdef HAVE_ERRNO_H msg_Err(p_input, "DVB-C: failed to open frontend (%s)", strerror(errno));# else msg_Err(p_input, "DVB-C: failed to open frontend");# endif return -1; } /* Show more info on the tuning parameters used. */ msg_Dbg(p_input, "DVB-C: Tuning with the following paramters:"); msg_Dbg(p_input, "DVB-C: Frequency %d KHz", fep.frequency ); msg_Dbg(p_input, "DVB-C: Inversion/polarisation: %d",fep.inversion); msg_Dbg(p_input, "DVB-C: Symbolrate %d", fep.u.qam.symbol_rate); msg_Dbg(p_input, "DVB-C: FEC Inner %d", fep.u.qam.fec_inner); msg_Dbg(p_input, "DVB-C: Modulation %d", fep.u.qam.modulation); /* Now send it all to the frontend device */ if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0) { close(front);# ifdef HAVE_ERRNO_H msg_Err(p_input, "DVB-C: tuning channel failed (frontend returned %d:%s)", ret, strerror(errno));# else msg_Err(p_input, "DVB-C: tuning channel failed (frontend returned %d)", ret);# endif return -1; } /* Check Status of frontend */ ret = ioctl_CheckFrontend(p_input, front); /* Fixme: Return this instead of closing it. Close front end device */ close(front); return ret;}/****************************************************************** * Check completion of the frontend control sequence ******************************************************************/static int ioctl_CheckFrontend(input_thread_t * p_input, int front){ int i; int ret; struct pollfd pfd[1]; struct dvb_frontend_event event; /* poll for frontend event to check if tuning worked */ pfd[0].fd = front; pfd[0].events = POLLIN;#if 1 for (i=0; i<3; i++) { fe_status_t status; if ((ret=ioctl(front, FE_READ_STATUS, &status))<0) {# ifdef HAVE_ERRNO_H msg_Err(p_input, "reading frontend status failed (%d) %s", ret, strerror(errno));# else msg_Err(p_input, "reading frontend status failed (%d)", ret);# endif } if (status & FE_HAS_SIGNAL) /* found something above the noise level */ msg_Dbg(p_input, "check frontend ... has signal"); if (status & FE_HAS_CARRIER) /* found a DVB signal */ msg_Dbg(p_input, "check frontend ... has carrier"); if (status & FE_HAS_VITERBI) /* FEC is stable */ msg_Dbg(p_input, "check frontend ... has stable fec"); if (status & FE_HAS_SYNC) /* found sync bytes */ msg_Dbg(p_input, "check frontend ... has sync"); if (status & FE_HAS_LOCK) /* everything's working... */ { msg_Dbg(p_input, "check frontend ... has lock"); msg_Dbg(p_input, "check frontend ... tuning status == 0x%02x!!! ..." "tuning succeeded", status); return 0; } if (status & FE_TIMEDOUT) /* no lock within the last ~2 seconds */ { msg_Dbg(p_input, "check frontend ... tuning status == 0x%02x!!! ..." "tuning failed", status); msg_Err(p_input, "check frontend ... timed out"); return -2; } if (status & FE_REINIT) { /* frontend was reinitialized, */ /* application is recommned to reset */ /* DiSEqC, tone and parameters */ msg_Dbg(p_input, "DVB-S: tuning status == 0x%02x!!! ..." "tuning failed", status); msg_Err(p_input, "check frontend ... resend frontend parameters"); return -1; } usleep( 500000 ); }#else if (poll(pfd,1,3000)) { if (pfd[0].revents & POLLIN) { if ( (ret=ioctl(front, FE_GET_EVENT, &event)) < 0) {# ifdef HAVE_ERRNO_H msg_Err(p_input, "check frontend ... error occured (%d) %s", ret, strerror(errno));# else msg_Err(p_input, "check frontend ... error occured (%d)", ret);# endif return -5; } switch(event.status) { case FE_HAS_SIGNAL: /* found something above the noise level */ msg_Dbg(p_input, "check frontend ... has signal"); break; case FE_HAS_CARRIER: /* found a DVB signal */ msg_Dbg(p_input, "check frontend ... has carrier"); break; case FE_HAS_VITERBI: /* FEC is stable */ msg_Dbg(p_input, "check frontend ... has stable fec"); break; case FE_HAS_SYNC: /* found sync bytes */ msg_Dbg(p_input, "check frontend ... has sync"); break; case FE_HAS_LOCK: /* everything's working... */ msg_Dbg(p_input, "check frontend ... has lock"); return 0; case FE_TIMEDOUT: /* no lock within the last ~2 seconds */ msg_Err(p_input, "check frontend ... timed out"); return -2; case FE_REINIT: /* frontend was reinitialized, */ /* application is recommned to reset */ /* DiSEqC, tone and parameters */ msg_Err(p_input, "check frontend ... resend frontend parameters"); return -1; } } else { /* should come here */ msg_Err(p_input, "check frontend ... no event occured"); return -3; } } else {# ifdef HAVE_ERRNO_H msg_Err(p_input, "check frontend ... timeout when polling for event (%s)", strerror(errno));# else msg_Err(p_input, "check frontend ... timeout when polling for event ");# endif return -4; }#endif return -1;}/***************************************************************************** * ioctl_SetDMXFilter : controls the demux to add a filter *****************************************************************************/int ioctl_SetDMXFilter(input_thread_t * p_input, int i_pid, int * pi_fd , int i_type, unsigned int u_adapter, unsigned int u_device ){ struct dmx_pes_filter_params s_filter_params; char dmx[] = DMX; int i_len; int result; /* We first open the device */ i_len = sizeof(DMX); if (snprintf( dmx, sizeof(DMX), DMX, u_adapter, u_device) >= i_len) { msg_Err(p_input, "snprintf() truncated string for DMX" ); dmx[sizeof(DMX)] = '\0'; } msg_Dbg(p_input, "Opening demux device %s", dmx); if (( (*pi_fd) = open(dmx, O_RDWR|O_NONBLOCK)) < 0) {# ifdef HAVE_ERRNO_H msg_Err(p_input, "ioctl_SetDMXFilter: opening device failed (%s)", strerror(errno));# else msg_Err(p_input, "ioctl_SetDMXFilter: opening device failed");# endif return -1; } /* We fill the DEMUX structure : */ s_filter_params.pid = i_pid; s_filter_params.input = DMX_IN_FRONTEND; s_filter_params.output = DMX_OUT_TS_TAP; switch ( i_type ) { /* First device */ case 1: msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_VIDEO0 for PMT %d", i_pid); s_filter_params.pes_type = DMX_PES_VIDEO0; break; case 2: msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_AUDIO0 for PMT %d", i_pid); s_filter_params.pes_type = DMX_PES_AUDIO0; break; case 3: msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_TELETEXT0 for PMT %d", i_pid); s_filter_params.pes_type = DMX_PES_TELETEXT0; break; case 4: msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_SUBTITLE0 for PMT %d", i_pid); s_filter_params.pes_type = DMX_PES_SUBTITLE0; break; case 5: msg_Dbg(p_input, "ioctl_SetDMXFilter: DMX_PES_PCR0 for PMT %d", i_pid); s_filter_params.pes_type = DMX_PES_PCR0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -