1 /*****************************************************************************
2 * dvb.c: linux-dvb input for DVBlast
3 *****************************************************************************
4 * Copyright (C) 2008-2010, 2015 VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
24 #ifdef HAVE_DVB_SUPPORT
32 #include <sys/types.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
44 /* DVB Card Drivers */
45 #include <linux/dvb/version.h>
46 #include <linux/dvb/dmx.h>
47 #include <linux/dvb/frontend.h>
48 #include <linux/dvb/ca.h>
52 #if DVBAPI_VERSION < 508
53 #define DTV_STREAM_ID 42
54 #define FE_CAN_MULTISTREAM 0x4000000
55 #define FE_CAN_TURBO_FEC 0x8000000
58 #define MAX_DELIVERY_SYSTEMS 20
64 #include <bitstream/common.h>
66 /*****************************************************************************
68 *****************************************************************************/
69 #define DVR_READ_TIMEOUT 30000000 /* 30 s */
70 #define MAX_READ_ONCE 50
71 #define DVR_BUFFER_SIZE 40*188*1024 /* bytes */
73 int i_dvr_buffer_size
= DVR_BUFFER_SIZE
;
75 static int i_frontend
, i_dvr
;
76 static struct ev_io frontend_watcher
, dvr_watcher
;
77 static struct ev_timer lock_watcher
, mute_watcher
, print_watcher
;
78 static fe_status_t i_last_status
;
79 static block_t
*p_freelist
= NULL
;
81 /*****************************************************************************
83 *****************************************************************************/
84 static void DVRRead(struct ev_loop
*loop
, struct ev_io
*w
, int revents
);
85 static void DVRMuteCb(struct ev_loop
*loop
, struct ev_timer
*w
, int revents
);
86 static void FrontendRead(struct ev_loop
*loop
, struct ev_io
*w
, int revents
);
87 static void FrontendLockCb(struct ev_loop
*loop
, struct ev_timer
*w
, int revents
);
88 static void FrontendSet( bool b_reset
);
90 /*****************************************************************************
92 *****************************************************************************/
97 msg_Dbg( NULL
, "compiled with DVB API version %d.%d", DVB_API_VERSION
, DVB_API_VERSION_MINOR
);
101 sprintf( psz_tmp
, "/dev/dvb/adapter%d/frontend%d", i_adapter
, i_fenum
);
102 if( (i_frontend
= open(psz_tmp
, O_RDWR
| O_NONBLOCK
)) < 0 )
104 msg_Err( NULL
, "opening device %s failed (%s)", psz_tmp
,
116 sprintf( psz_tmp
, "/dev/dvb/adapter%d/dvr%d", i_adapter
, i_fenum
);
118 if( (i_dvr
= open(psz_tmp
, O_RDONLY
| O_NONBLOCK
)) < 0 )
120 msg_Err( NULL
, "opening device %s failed (%s)", psz_tmp
,
125 if ( ioctl( i_dvr
, DMX_SET_BUFFER_SIZE
, i_dvr_buffer_size
) < 0 )
127 msg_Warn( NULL
, "couldn't set %s buffer size (%s)", psz_tmp
,
131 ev_io_init(&dvr_watcher
, DVRRead
, i_dvr
, EV_READ
);
132 ev_io_start(event_loop
, &dvr_watcher
);
134 if ( i_frontend
!= -1 )
136 ev_io_init(&frontend_watcher
, FrontendRead
, i_frontend
, EV_READ
);
137 ev_io_start(event_loop
, &frontend_watcher
);
140 ev_timer_init(&lock_watcher
, FrontendLockCb
,
141 i_frontend_timeout_duration
/ 1000000.,
142 i_frontend_timeout_duration
/ 1000000.);
143 ev_timer_init(&mute_watcher
, DVRMuteCb
,
144 DVR_READ_TIMEOUT
/ 1000000.,
145 DVR_READ_TIMEOUT
/ 1000000.);
150 /*****************************************************************************
152 *****************************************************************************/
153 void dvb_Reset( void )
159 /*****************************************************************************
161 *****************************************************************************/
162 static void DVRRead(struct ev_loop
*loop
, struct ev_io
*w
, int revents
)
165 block_t
*p_ts
= p_freelist
, **pp_current
= &p_ts
;
166 struct iovec p_iov
[MAX_READ_ONCE
];
168 for ( i
= 0; i
< MAX_READ_ONCE
; i
++ )
170 if ( (*pp_current
) == NULL
) *pp_current
= block_New();
171 p_iov
[i
].iov_base
= (*pp_current
)->p_ts
;
172 p_iov
[i
].iov_len
= TS_SIZE
;
173 pp_current
= &(*pp_current
)->p_next
;
176 if ( (i_len
= readv(i_dvr
, p_iov
, MAX_READ_ONCE
)) < 0 )
178 msg_Err( NULL
, "couldn't read from DVR device (%s)",
185 ev_timer_again(loop
, &mute_watcher
);
188 while ( i_len
&& *pp_current
)
190 pp_current
= &(*pp_current
)->p_next
;
194 p_freelist
= *pp_current
;
200 static void DVRMuteCb(struct ev_loop
*loop
, struct ev_timer
*w
, int revents
)
202 msg_Warn( NULL
, "no DVR output, resetting" );
203 ev_timer_stop(loop
, w
);
205 switch (i_print_type
) {
207 fprintf(print_fh
, "<EVENT type=\"reset\" cause=\"dvr\" />\n");
210 fprintf(print_fh
, "reset cause: dvr\n");
225 /*****************************************************************************
226 * dvb_SetFilter : controls the demux to add a filter
227 *****************************************************************************/
228 int dvb_SetFilter( uint16_t i_pid
)
230 struct dmx_pes_filter_params s_filter_params
;
234 sprintf( psz_tmp
, "/dev/dvb/adapter%d/demux%d", i_adapter
, i_fenum
);
235 if( (i_fd
= open(psz_tmp
, O_RDWR
)) < 0 )
237 msg_Err( NULL
, "DMXSetFilter: opening device failed (%s)",
242 s_filter_params
.pid
= i_pid
;
243 s_filter_params
.input
= DMX_IN_FRONTEND
;
244 s_filter_params
.output
= DMX_OUT_TS_TAP
;
245 s_filter_params
.flags
= DMX_IMMEDIATE_START
;
246 s_filter_params
.pes_type
= DMX_PES_OTHER
;
248 if ( ioctl( i_fd
, DMX_SET_PES_FILTER
, &s_filter_params
) < 0 )
250 msg_Err( NULL
, "failed setting filter on %d (%s)", i_pid
,
256 msg_Dbg( NULL
, "setting filter on PID %d", i_pid
);
261 /*****************************************************************************
262 * dvb_UnsetFilter : removes a filter
263 *****************************************************************************/
264 void dvb_UnsetFilter( int i_fd
, uint16_t i_pid
)
266 if ( ioctl( i_fd
, DMX_STOP
) < 0 )
267 msg_Err( NULL
, "DMX_STOP failed (%s)", strerror(errno
) );
269 msg_Dbg( NULL
, "unsetting filter on PID %d", i_pid
);
279 /*****************************************************************************
281 *****************************************************************************/
282 static void PrintCb( struct ev_loop
*loop
, struct ev_timer
*w
, int revents
)
285 uint16_t i_strength
= 0, i_snr
= 0;
286 uint32_t i_uncorrected
= 0;
288 ioctl(i_frontend
, FE_READ_BER
, &i_ber
);
289 ioctl(i_frontend
, FE_READ_SIGNAL_STRENGTH
, &i_strength
);
290 ioctl(i_frontend
, FE_READ_SNR
, &i_snr
);
291 ioctl(i_frontend
, FE_READ_UNCORRECTED_BLOCKS
, &i_uncorrected
);
293 switch (i_print_type
)
297 "<STATUS type=\"frontend\" ber=\"%"PRIu32
"\" strength=\"%"PRIu16
"\" snr=\"%"PRIu16
"\" uncorrected=\"%"PRIu32
"\" />\n",
298 i_ber
, i_strength
, i_snr
, i_uncorrected
);
301 fprintf(print_fh
, "frontend ber: %"PRIu32
" strength: %"PRIu16
" snr: %"PRIu16
" uncorrected: %"PRIu32
"\n",
302 i_ber
, i_strength
, i_snr
, i_uncorrected
);
309 /*****************************************************************************
311 *****************************************************************************/
312 static void FrontendRead(struct ev_loop
*loop
, struct ev_io
*w
, int revents
)
314 struct dvb_frontend_event event
;
315 fe_status_t i_status
, i_diff
;
319 int i_ret
= ioctl( i_frontend
, FE_GET_EVENT
, &event
);
323 if( errno
== EWOULDBLOCK
)
324 return; /* no more events */
326 msg_Err( NULL
, "reading frontend event failed (%d) %s",
327 i_ret
, strerror(errno
) );
331 i_status
= event
.status
;
332 i_diff
= i_status
^ i_last_status
;
333 i_last_status
= i_status
;
338 if ( i_diff & (x) ) \
340 if ( i_status & (x) )
342 IF_UP( FE_HAS_SIGNAL
)
343 msg_Dbg( NULL
, "frontend has acquired signal" );
345 msg_Dbg( NULL
, "frontend has lost signal" );
347 IF_UP( FE_HAS_CARRIER
)
348 msg_Dbg( NULL
, "frontend has acquired carrier" );
350 msg_Dbg( NULL
, "frontend has lost carrier" );
352 IF_UP( FE_HAS_VITERBI
)
353 msg_Dbg( NULL
, "frontend has acquired stable FEC" );
355 msg_Dbg( NULL
, "frontend has lost FEC" );
358 msg_Dbg( NULL
, "frontend has acquired sync" );
360 msg_Dbg( NULL
, "frontend has lost sync" );
365 msg_Info( NULL
, "frontend has acquired lock" );
366 switch (i_print_type
) {
368 fprintf(print_fh
, "<STATUS type=\"lock\" status=\"1\" />\n");
371 fprintf(print_fh
, "lock status: 1\n");
377 ev_timer_stop(loop
, &lock_watcher
);
378 ev_timer_again(loop
, &mute_watcher
);
380 /* Read some statistics */
381 if( ioctl( i_frontend
, FE_READ_BER
, &i_value
) >= 0 )
382 msg_Dbg( NULL
, "- Bit error rate: %d", i_value
);
383 if( ioctl( i_frontend
, FE_READ_SIGNAL_STRENGTH
, &i_value
) >= 0 )
384 msg_Dbg( NULL
, "- Signal strength: %d", i_value
);
385 if( ioctl( i_frontend
, FE_READ_SNR
, &i_value
) >= 0 )
386 msg_Dbg( NULL
, "- SNR: %d", i_value
);
390 ev_timer_init( &print_watcher
, PrintCb
,
391 i_print_period
/ 1000000.,
392 i_print_period
/ 1000000. );
393 ev_timer_start( event_loop
, &print_watcher
);
398 msg_Dbg( NULL
, "frontend has lost lock" );
399 switch (i_print_type
) {
401 fprintf(print_fh
, "<STATUS type=\"lock\" status=\"0\"/>\n");
404 fprintf(print_fh
, "lock status: 0\n");
410 if (i_frontend_timeout_duration
)
412 ev_timer_stop(event_loop
, &lock_watcher
);
413 ev_timer_again(loop
, &mute_watcher
);
417 ev_timer_stop(event_loop
, &print_watcher
);
422 /* The frontend was reinited. */
423 msg_Warn( NULL
, "reiniting frontend");
432 static void FrontendLockCb(struct ev_loop
*loop
, struct ev_timer
*w
, int revents
)
434 if ( i_quit_timeout_duration
)
436 msg_Err( NULL
, "no lock" );
437 ev_break(loop
, EVBREAK_ALL
);
441 msg_Warn( NULL
, "no lock, tuning again" );
442 ev_timer_stop(loop
, w
);
444 switch (i_print_type
) {
446 fprintf(print_fh
, "<EVENT type=\"reset\" cause=\"nolock\" />\n");
449 fprintf(print_fh
, "reset cause: nolock\n");
458 static int FrontendDoDiseqc(void)
460 fe_sec_voltage_t fe_voltage
;
461 fe_sec_tone_mode_t fe_tone
;
466 case 0: fe_voltage
= SEC_VOLTAGE_OFF
; break;
468 case 13: fe_voltage
= SEC_VOLTAGE_13
; break;
469 case 18: fe_voltage
= SEC_VOLTAGE_18
; break;
472 fe_tone
= b_tone
? SEC_TONE_ON
: SEC_TONE_OFF
;
474 if ( strcmp( psz_lnb_type
, "universal" ) == 0 )
476 /* Automatic mode. */
477 if ( i_frequency
>= 950000 && i_frequency
<= 2150000 )
479 msg_Dbg( NULL
, "frequency %d is in IF-band", i_frequency
);
480 bis_frequency
= i_frequency
;
482 else if ( i_frequency
>= 2500000 && i_frequency
<= 2700000 )
484 msg_Dbg( NULL
, "frequency %d is in S-band", i_frequency
);
485 bis_frequency
= 3650000 - i_frequency
;
487 else if ( i_frequency
>= 3400000 && i_frequency
<= 4200000 )
489 msg_Dbg( NULL
, "frequency %d is in C-band (lower)", i_frequency
);
490 bis_frequency
= 5150000 - i_frequency
;
492 else if ( i_frequency
>= 4500000 && i_frequency
<= 4800000 )
494 msg_Dbg( NULL
, "frequency %d is in C-band (higher)", i_frequency
);
495 bis_frequency
= 5950000 - i_frequency
;
497 else if ( i_frequency
>= 10700000 && i_frequency
< 11700000 )
499 msg_Dbg( NULL
, "frequency %d is in Ku-band (lower)",
501 bis_frequency
= i_frequency
- 9750000;
503 else if ( i_frequency
>= 11700000 && i_frequency
<= 13250000 )
505 msg_Dbg( NULL
, "frequency %d is in Ku-band (higher)",
507 bis_frequency
= i_frequency
- 10600000;
508 fe_tone
= SEC_TONE_ON
;
512 msg_Err( NULL
, "frequency %d is out of any known band",
517 else if ( strcmp( psz_lnb_type
, "old-sky" ) == 0 )
519 if ( i_frequency
>= 11700000 && i_frequency
<= 13250000 )
521 msg_Dbg( NULL
, "frequency %d is in Ku-band (higher)",
523 bis_frequency
= i_frequency
- 11300000;
524 fe_tone
= SEC_TONE_ON
;
528 msg_Err( NULL
, "frequency %d is out of any known band",
535 msg_Err( NULL
, "lnb-type '%s' is not known. Valid type: universal old-sky",
540 /* Switch off continuous tone. */
541 if ( ioctl( i_frontend
, FE_SET_TONE
, SEC_TONE_OFF
) < 0 )
543 msg_Err( NULL
, "FE_SET_TONE failed (%s)", strerror(errno
) );
547 /* Configure LNB voltage. */
548 if ( ioctl( i_frontend
, FE_SET_VOLTAGE
, fe_voltage
) < 0 )
550 msg_Err( NULL
, "FE_SET_VOLTAGE failed (%s)", strerror(errno
) );
554 /* Wait for at least 15 ms. Currently 100 ms because of broken drivers. */
558 if ( i_satnum
> 0 && i_satnum
< 5 )
560 /* digital satellite equipment control,
561 * specification is available from http://www.eutelsat.com/
565 struct dvb_diseqc_master_cmd uncmd
=
566 { {0xe0, 0x10, 0x39, 0xf0, 0x00, 0x00}, 4};
569 struct dvb_diseqc_master_cmd cmd
=
570 { {0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4};
572 cmd
.msg
[3] = 0xf0 /* reset bits */
573 | ((i_satnum
- 1) << 2)
574 | (fe_voltage
== SEC_VOLTAGE_13
? 0 : 2)
575 | (fe_tone
== SEC_TONE_ON
? 1 : 0);
577 if ( i_uncommitted
> 0 && i_uncommitted
< 17 )
579 uncmd
.msg
[3] = 0xf0 /* reset bits */
580 | (i_uncommitted
- 1);
581 if( ioctl( i_frontend
, FE_DISEQC_SEND_MASTER_CMD
, &uncmd
) < 0 )
583 msg_Err( NULL
, "ioctl FE_SEND_MASTER_CMD failed (%s)",
587 /* Repeat uncommitted command */
588 uncmd
.msg
[0] = 0xe1; /* framing: master, no reply, repeated TX */
589 if( ioctl( i_frontend
, FE_DISEQC_SEND_MASTER_CMD
, &uncmd
) < 0 )
591 msg_Err( NULL
, "ioctl FE_SEND_MASTER_CMD failed (%s)",
595 /* Pause 125 ms between uncommitted & committed diseqc commands. */
599 if( ioctl( i_frontend
, FE_DISEQC_SEND_MASTER_CMD
, &cmd
) < 0 )
601 msg_Err( NULL
, "ioctl FE_SEND_MASTER_CMD failed (%s)",
605 msleep(100000); /* Should be 15 ms. */
607 /* Do it again just to be sure. */
608 cmd
.msg
[0] = 0xe1; /* framing: master, no reply, repeated TX */
609 if( ioctl( i_frontend
, FE_DISEQC_SEND_MASTER_CMD
, &cmd
) < 0 )
611 msg_Err( NULL
, "ioctl FE_SEND_MASTER_CMD failed (%s)",
615 msleep(100000); /* Again, should be 15 ms */
617 else if ( i_satnum
== 0xA || i_satnum
== 0xB )
619 /* A or B simple diseqc ("diseqc-compatible") */
620 if( ioctl( i_frontend
, FE_DISEQC_SEND_BURST
,
621 i_satnum
== 0xB ? SEC_MINI_B
: SEC_MINI_A
) < 0 )
623 msg_Err( NULL
, "ioctl FE_SEND_BURST failed (%s)", strerror(errno
) );
626 msleep(100000); /* ... */
629 if ( ioctl( i_frontend
, FE_SET_TONE
, fe_tone
) < 0 )
631 msg_Err( NULL
, "FE_SET_TONE failed (%s)", strerror(errno
) );
635 msleep(100000); /* ... */
637 msg_Dbg( NULL
, "configuring LNB to v=%d p=%d satnum=%x uncommitted=%x lnb-type=%s bis_frequency=%d",
638 i_voltage
, b_tone
, i_satnum
, i_uncommitted
, psz_lnb_type
, bis_frequency
);
639 return bis_frequency
;
642 #if DVB_API_VERSION >= 5
644 #if DVBAPI_VERSION < 505
645 #warning Your linux-dvb headers are old, you should consider upgrading your kernel and/or compiling against different kernel headers
648 /*****************************************************************************
649 * Helper functions for S2API
650 *****************************************************************************/
651 static fe_spectral_inversion_t
GetInversion(void)
653 switch ( i_inversion
)
655 case 0: return INVERSION_OFF
;
656 case 1: return INVERSION_ON
;
658 msg_Warn( NULL
, "invalid inversion %d", i_inversion
);
659 case -1: return INVERSION_AUTO
;
663 static fe_code_rate_t
GetFEC(fe_caps_t fe_caps
, int i_fec_value
)
665 #define GET_FEC_INNER(fec, val) \
666 if ( (fe_caps & FE_CAN_##fec) && (i_fec_value == val) ) \
669 GET_FEC_INNER(FEC_AUTO
, 999);
670 GET_FEC_INNER(FEC_AUTO
, -1);
671 if (i_fec_value
== 0)
673 GET_FEC_INNER(FEC_1_2
, 12);
674 GET_FEC_INNER(FEC_2_3
, 23);
675 GET_FEC_INNER(FEC_3_4
, 34);
676 if (i_fec_value
== 35)
678 GET_FEC_INNER(FEC_4_5
, 45);
679 GET_FEC_INNER(FEC_5_6
, 56);
680 GET_FEC_INNER(FEC_6_7
, 67);
681 GET_FEC_INNER(FEC_7_8
, 78);
682 GET_FEC_INNER(FEC_8_9
, 89);
683 if (i_fec_value
== 910)
687 msg_Warn(NULL
, "invalid FEC %d", i_fec_value
);
691 #define GetFECInner(caps) GetFEC(caps, i_fec)
692 #define GetFECLP(caps) GetFEC(caps, i_fec_lp)
694 static fe_modulation_t
GetModulation(void)
696 #define GET_MODULATION( mod ) \
697 if ( !strcasecmp( psz_modulation, #mod ) ) \
700 GET_MODULATION(QPSK
);
701 GET_MODULATION(QAM_16
);
702 GET_MODULATION(QAM_32
);
703 GET_MODULATION(QAM_64
);
704 GET_MODULATION(QAM_128
);
705 GET_MODULATION(QAM_256
);
706 GET_MODULATION(QAM_AUTO
);
707 GET_MODULATION(VSB_8
);
708 GET_MODULATION(VSB_16
);
709 GET_MODULATION(PSK_8
);
710 GET_MODULATION(APSK_16
);
711 GET_MODULATION(APSK_32
);
712 GET_MODULATION(DQPSK
);
714 #undef GET_MODULATION
715 msg_Err( NULL
, "invalid modulation %s", psz_modulation
);
719 static fe_pilot_t
GetPilot(void)
723 case 0: return PILOT_OFF
;
724 case 1: return PILOT_ON
;
726 msg_Warn( NULL
, "invalid pilot %d", i_pilot
);
727 case -1: return PILOT_AUTO
;
731 static fe_rolloff_t
GetRollOff(void)
736 case 0: return ROLLOFF_AUTO
;
737 case 20: return ROLLOFF_20
;
738 case 25: return ROLLOFF_25
;
740 msg_Warn( NULL
, "invalid rolloff %d", i_rolloff
);
741 case 35: return ROLLOFF_35
;
745 static fe_guard_interval_t
GetGuard(void)
749 case 32: return GUARD_INTERVAL_1_32
;
750 case 16: return GUARD_INTERVAL_1_16
;
751 case 8: return GUARD_INTERVAL_1_8
;
752 case 4: return GUARD_INTERVAL_1_4
;
754 msg_Warn( NULL
, "invalid guard interval %d", i_guard
);
756 case 0: return GUARD_INTERVAL_AUTO
;
760 static fe_transmit_mode_t
GetTransmission(void)
762 switch ( i_transmission
)
764 case 2: return TRANSMISSION_MODE_2K
;
765 case 8: return TRANSMISSION_MODE_8K
;
766 #ifdef TRANSMISSION_MODE_4K
767 case 4: return TRANSMISSION_MODE_4K
;
770 msg_Warn( NULL
, "invalid tranmission mode %d", i_transmission
);
772 case 0: return TRANSMISSION_MODE_AUTO
;
776 static fe_hierarchy_t
GetHierarchy(void)
778 switch ( i_hierarchy
)
780 case 0: return HIERARCHY_NONE
;
781 case 1: return HIERARCHY_1
;
782 case 2: return HIERARCHY_2
;
783 case 4: return HIERARCHY_4
;
785 msg_Warn( NULL
, "invalid intramission mode %d", i_transmission
);
786 case -1: return HIERARCHY_AUTO
;
790 /*****************************************************************************
791 * FrontendInfo : Print frontend info
792 *****************************************************************************/
793 static void FrontendInfo( struct dvb_frontend_info
*info
, uint32_t version
,
794 fe_delivery_system_t
*p_systems
, int i_systems
)
796 msg_Dbg( NULL
, "using DVB API version %d.%d", version
/ 256, version
% 256 );
797 msg_Dbg( NULL
, "Frontend \"%s\" supports:", info
->name
);
798 msg_Dbg( NULL
, " frequency min: %d, max: %d, stepsize: %d, tolerance: %d",
799 info
->frequency_min
, info
->frequency_max
,
800 info
->frequency_stepsize
, info
->frequency_tolerance
);
801 msg_Dbg( NULL
, " symbolrate min: %d, max: %d, tolerance: %d",
802 info
->symbol_rate_min
, info
->symbol_rate_max
, info
->symbol_rate_tolerance
);
803 msg_Dbg( NULL
, " capabilities:" );
805 #define FRONTEND_INFO(caps,val,msg) \
807 msg_Dbg( NULL, " %s", msg );
809 FRONTEND_INFO( info
->caps
, FE_IS_STUPID
, "FE_IS_STUPID" )
810 FRONTEND_INFO( info
->caps
, FE_CAN_INVERSION_AUTO
, "INVERSION_AUTO" )
811 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_1_2
, "FEC_1_2" )
812 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_2_3
, "FEC_2_3" )
813 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_3_4
, "FEC_3_4" )
814 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_4_5
, "FEC_4_5" )
815 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_5_6
, "FEC_5_6" )
816 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_6_7
, "FEC_6_7" )
817 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_7_8
, "FEC_7_8" )
818 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_8_9
, "FEC_8_9" )
819 FRONTEND_INFO( info
->caps
, FE_CAN_FEC_AUTO
,"FEC_AUTO")
820 FRONTEND_INFO( info
->caps
, FE_CAN_QPSK
, "QPSK" )
821 FRONTEND_INFO( info
->caps
, FE_CAN_QAM_16
, "QAM_16" )
822 FRONTEND_INFO( info
->caps
, FE_CAN_QAM_32
, "QAM_32" )
823 FRONTEND_INFO( info
->caps
, FE_CAN_QAM_64
, "QAM_64" )
824 FRONTEND_INFO( info
->caps
, FE_CAN_QAM_128
,"QAM_128")
825 FRONTEND_INFO( info
->caps
, FE_CAN_QAM_256
,"QAM_256")
826 FRONTEND_INFO( info
->caps
, FE_CAN_QAM_AUTO
,"QAM_AUTO" )
827 FRONTEND_INFO( info
->caps
, FE_CAN_TRANSMISSION_MODE_AUTO
, "TRANSMISSION_MODE_AUTO" )
828 FRONTEND_INFO( info
->caps
, FE_CAN_BANDWIDTH_AUTO
, "BANDWIDTH_AUTO" )
829 FRONTEND_INFO( info
->caps
, FE_CAN_GUARD_INTERVAL_AUTO
, "GUARD_INTERVAL_AUTO" )
830 FRONTEND_INFO( info
->caps
, FE_CAN_HIERARCHY_AUTO
, "HIERARCHY_AUTO" )
831 FRONTEND_INFO( info
->caps
, FE_CAN_8VSB
, "8VSB" )
832 FRONTEND_INFO( info
->caps
, FE_CAN_16VSB
,"16VSB" )
833 FRONTEND_INFO( info
->caps
, FE_HAS_EXTENDED_CAPS
, "EXTENDED_CAPS" )
834 #if DVBAPI_VERSION >= 501
835 FRONTEND_INFO( info
->caps
, FE_CAN_2G_MODULATION
, "2G_MODULATION" )
837 FRONTEND_INFO( info
->caps
, FE_CAN_MULTISTREAM
, "MULTISTREAM" )
838 FRONTEND_INFO( info
->caps
, FE_CAN_TURBO_FEC
, "TURBO_FEC" )
839 FRONTEND_INFO( info
->caps
, FE_NEEDS_BENDING
, "NEEDS_BENDING" )
840 FRONTEND_INFO( info
->caps
, FE_CAN_RECOVER
, "FE_CAN_RECOVER" )
841 FRONTEND_INFO( info
->caps
, FE_CAN_MUTE_TS
, "FE_CAN_MUTE_TS" )
844 msg_Dbg( NULL
, " delivery systems:" );
846 for ( i
= 0; i
< i_systems
; i
++ )
848 switch ( p_systems
[i
] )
850 #define DELSYS_INFO(delsys, msg) \
851 case delsys: msg_Dbg( NULL, " %s", msg); break;
852 DELSYS_INFO( SYS_ATSC
, "ATSC" )
853 DELSYS_INFO( SYS_ATSCMH
, "ATSCMH" )
854 DELSYS_INFO( SYS_CMMB
, "CMBB" )
855 DELSYS_INFO( SYS_DAB
, "DAB" )
856 DELSYS_INFO( SYS_DSS
, "DSS" )
857 DELSYS_INFO( SYS_DVBC_ANNEX_B
, "DVBC_ANNEX_B" )
858 DELSYS_INFO( SYS_DVBH
, "DVBH" )
859 DELSYS_INFO( SYS_DVBS
, "DVBS" )
860 DELSYS_INFO( SYS_DVBS2
, "DVBS2" )
861 DELSYS_INFO( SYS_DVBT
, "DVBT" )
862 DELSYS_INFO( SYS_ISDBC
, "ISDBC" )
863 DELSYS_INFO( SYS_ISDBS
, "ISDBS" )
864 DELSYS_INFO( SYS_ISDBT
, "ISDBT" )
865 DELSYS_INFO( SYS_UNDEFINED
, "UNDEFINED" )
866 #if DVBAPI_VERSION >= 505
867 DELSYS_INFO( SYS_DVBC_ANNEX_A
, "DVBC_ANNEX_A" )
868 DELSYS_INFO( SYS_DVBC_ANNEX_C
, "DVBC_ANNEX_C" )
869 DELSYS_INFO( SYS_DVBT2
, "DVBT2" )
870 DELSYS_INFO( SYS_TURBO
, "TURBO" )
872 DELSYS_INFO( SYS_DVBC_ANNEX_AC
, "DVBC_ANNEX_AC" )
874 #if DVBAPI_VERSION >= 507
875 DELSYS_INFO( SYS_DTMB
, "DTMB" )
877 DELSYS_INFO( SYS_DMBTH
, "DMBTH" )
879 default: msg_Dbg( NULL
, " Unknown delivery system %u", p_systems
[i
]);
885 /*****************************************************************************
887 *****************************************************************************/
889 #if DVBAPI_VERSION >= 505
890 static struct dtv_property info_cmdargs
[] = {
891 { .cmd
= DTV_API_VERSION
, .u
.data
= 0 },
893 static struct dtv_properties info_cmdseq
= {
894 .num
= sizeof(info_cmdargs
)/sizeof(struct dtv_property
),
895 .props
= info_cmdargs
898 static struct dtv_property enum_cmdargs
[] = {
899 { .cmd
= DTV_ENUM_DELSYS
, .u
.data
= 0 },
901 static struct dtv_properties enum_cmdseq
= {
902 .num
= sizeof(enum_cmdargs
)/sizeof(struct dtv_property
),
903 .props
= enum_cmdargs
907 static struct dtv_property dvbs_cmdargs
[] = {
908 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_DVBS
},
909 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
910 { .cmd
= DTV_MODULATION
, .u
.data
= QPSK
},
911 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
912 { .cmd
= DTV_SYMBOL_RATE
, .u
.data
= 27500000 },
913 { .cmd
= DTV_INNER_FEC
, .u
.data
= FEC_AUTO
},
916 static struct dtv_properties dvbs_cmdseq
= {
917 .num
= sizeof(dvbs_cmdargs
)/sizeof(struct dtv_property
),
918 .props
= dvbs_cmdargs
921 #define IDX_DVBS2_PILOT 6
922 #define IDX_DVBS2_ROLLOFF 7
923 #define IDX_DVBS2_STREAM_ID 8
925 /* Commands 0..5 are the same as dvbs_cmdargs */
926 /* Commands 6..8 are special for DVB-S2 */
927 static struct dtv_property dvbs2_cmdargs
[] = {
928 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_DVBS2
},
929 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
930 { .cmd
= DTV_MODULATION
, .u
.data
= PSK_8
},
931 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
932 { .cmd
= DTV_SYMBOL_RATE
, .u
.data
= 27500000 },
933 { .cmd
= DTV_INNER_FEC
, .u
.data
= FEC_AUTO
},
934 { .cmd
= DTV_PILOT
, .u
.data
= PILOT_AUTO
}, /* idx: 6 */
935 { .cmd
= DTV_ROLLOFF
, .u
.data
= ROLLOFF_AUTO
}, /* idx: 7 */
936 { .cmd
= DTV_STREAM_ID
, .u
.data
= 0 }, /* idx: 8 */
939 static struct dtv_properties dvbs2_cmdseq
= {
940 .num
= sizeof(dvbs2_cmdargs
)/sizeof(struct dtv_property
),
941 .props
= dvbs2_cmdargs
944 static struct dtv_property dvbc_cmdargs
[] = {
945 #if DVBAPI_VERSION >= 505
946 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_DVBC_ANNEX_A
},
948 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_DVBC_ANNEX_AC
},
950 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
951 { .cmd
= DTV_MODULATION
, .u
.data
= QAM_AUTO
},
952 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
953 { .cmd
= DTV_SYMBOL_RATE
, .u
.data
= 27500000 },
956 static struct dtv_properties dvbc_cmdseq
= {
957 .num
= sizeof(dvbc_cmdargs
)/sizeof(struct dtv_property
),
958 .props
= dvbc_cmdargs
961 static struct dtv_property dvbt_cmdargs
[] = {
962 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_DVBT
},
963 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
964 { .cmd
= DTV_MODULATION
, .u
.data
= QAM_AUTO
},
965 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
966 { .cmd
= DTV_BANDWIDTH_HZ
, .u
.data
= 8000000 },
967 { .cmd
= DTV_CODE_RATE_HP
, .u
.data
= FEC_AUTO
},
968 { .cmd
= DTV_CODE_RATE_LP
, .u
.data
= FEC_AUTO
},
969 { .cmd
= DTV_GUARD_INTERVAL
, .u
.data
= GUARD_INTERVAL_AUTO
},
970 { .cmd
= DTV_TRANSMISSION_MODE
,.u
.data
= TRANSMISSION_MODE_AUTO
},
971 { .cmd
= DTV_HIERARCHY
, .u
.data
= HIERARCHY_AUTO
},
975 static struct dtv_property dvbt2_cmdargs
[] = {
976 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_DVBT2
},
977 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
978 { .cmd
= DTV_MODULATION
, .u
.data
= QAM_AUTO
},
979 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
980 { .cmd
= DTV_BANDWIDTH_HZ
, .u
.data
= 8000000 },
981 { .cmd
= DTV_CODE_RATE_HP
, .u
.data
= FEC_AUTO
},
982 { .cmd
= DTV_CODE_RATE_LP
, .u
.data
= FEC_AUTO
},
983 { .cmd
= DTV_GUARD_INTERVAL
, .u
.data
= GUARD_INTERVAL_AUTO
},
984 { .cmd
= DTV_TRANSMISSION_MODE
,.u
.data
= TRANSMISSION_MODE_AUTO
},
985 { .cmd
= DTV_HIERARCHY
, .u
.data
= HIERARCHY_AUTO
},
986 { .cmd
= DTV_STREAM_ID
, .u
.data
= 0 },
990 static struct dtv_properties dvbt2_cmdseq
= {
991 .num
= sizeof(dvbt2_cmdargs
)/sizeof(struct dtv_property
),
992 .props
= dvbt2_cmdargs
995 static struct dtv_properties dvbt_cmdseq
= {
996 .num
= sizeof(dvbt_cmdargs
)/sizeof(struct dtv_property
),
997 .props
= dvbt_cmdargs
1000 /* ATSC + DVB-C annex B */
1001 static struct dtv_property atsc_cmdargs
[] = {
1002 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_ATSC
},
1003 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
1004 { .cmd
= DTV_MODULATION
, .u
.data
= QAM_AUTO
},
1005 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
1006 { .cmd
= DTV_TUNE
},
1008 static struct dtv_properties atsc_cmdseq
= {
1009 .num
= sizeof(atsc_cmdargs
)/sizeof(struct dtv_property
),
1010 .props
= atsc_cmdargs
1013 static struct dtv_property isdbt_cmdargs
[] = {
1014 { .cmd
= DTV_DELIVERY_SYSTEM
, .u
.data
= SYS_ISDBT
},
1015 { .cmd
= DTV_FREQUENCY
, .u
.data
= 0 },
1016 { .cmd
= DTV_BANDWIDTH_HZ
, .u
.data
= 6000000 },
1017 { .cmd
= DTV_INVERSION
, .u
.data
= INVERSION_AUTO
},
1018 { .cmd
= DTV_ISDBT_LAYERA_FEC
, .u
.data
= FEC_AUTO
},
1019 { .cmd
= DTV_ISDBT_LAYERA_MODULATION
, .u
.data
= QAM_AUTO
},
1020 { .cmd
= DTV_ISDBT_LAYERA_SEGMENT_COUNT
, .u
.data
= 0 },
1021 { .cmd
= DTV_ISDBT_LAYERA_TIME_INTERLEAVING
,.u
.data
= 0 },
1022 { .cmd
= DTV_ISDBT_LAYERB_FEC
, .u
.data
= FEC_AUTO
},
1023 { .cmd
= DTV_ISDBT_LAYERB_MODULATION
, .u
.data
= QAM_AUTO
},
1024 { .cmd
= DTV_ISDBT_LAYERB_SEGMENT_COUNT
, .u
.data
= 0 },
1025 { .cmd
= DTV_ISDBT_LAYERB_TIME_INTERLEAVING
,.u
.data
= 0 },
1026 { .cmd
= DTV_ISDBT_LAYERC_FEC
, .u
.data
= FEC_AUTO
},
1027 { .cmd
= DTV_ISDBT_LAYERC_MODULATION
, .u
.data
= QAM_AUTO
},
1028 { .cmd
= DTV_ISDBT_LAYERC_SEGMENT_COUNT
, .u
.data
= 0 },
1029 { .cmd
= DTV_ISDBT_LAYERC_TIME_INTERLEAVING
,.u
.data
= 0 },
1030 { .cmd
= DTV_TUNE
},
1033 static struct dtv_properties isdbt_cmdseq
= {
1034 .num
= sizeof(isdbt_cmdargs
)/sizeof(struct dtv_property
),
1035 .props
= isdbt_cmdargs
1040 #define MODULATION 2
1042 #define SYMBOL_RATE 4
1047 #define TRANSMISSION 8
1053 #define ISDBT_BANDWIDTH 2
1054 #define ISDBT_LAYERA_FEC 4
1055 #define ISDBT_LAYERA_MODULATION 5
1056 #define ISDBT_LAYERA_SEGMENT_COUNT 6
1057 #define ISDBT_LAYERA_TIME_INTERLEAVING 7
1058 #define ISDBT_LAYERB_FEC 8
1059 #define ISDBT_LAYERB_MODULATION 9
1060 #define ISDBT_LAYERB_SEGMENT_COUNT 10
1061 #define ISDBT_LAYERB_TIME_INTERLEAVING 11
1062 #define ISDBT_LAYERC_FEC 12
1063 #define ISDBT_LAYERC_MODULATION 13
1064 #define ISDBT_LAYERC_SEGMENT_COUNT 14
1065 #define ISDBT_LAYERC_TIME_INTERLEAVING 15
1067 struct dtv_property pclear
[] = {
1068 { .cmd
= DTV_CLEAR
},
1071 struct dtv_properties cmdclear
= {
1076 static fe_delivery_system_t
1077 FrontendGuessSystem( fe_delivery_system_t
*p_systems
, int i_systems
)
1079 if ( psz_delsys
!= NULL
)
1081 if ( !strcasecmp( psz_delsys
, "DVBS" ) )
1083 if ( !strcasecmp( psz_delsys
, "DVBS2" ) )
1085 if ( !strcasecmp( psz_delsys
, "DVBC_ANNEX_A" ) )
1086 #if DVBAPI_VERSION >= 505
1087 return SYS_DVBC_ANNEX_A
;
1089 return SYS_DVBC_ANNEX_AC
;
1091 if ( !strcasecmp( psz_delsys
, "DVBC_ANNEX_B" ) )
1092 return SYS_DVBC_ANNEX_B
;
1093 if ( !strcasecmp( psz_delsys
, "DVBT" ) )
1095 if ( !strcasecmp( psz_delsys
, "DVBT2" ) )
1097 if ( !strcasecmp( psz_delsys
, "ATSC" ) )
1099 if ( !strcasecmp( psz_delsys
, "ISDBT" ) )
1101 msg_Err( NULL
, "unknown delivery system %s", psz_delsys
);
1105 if ( i_systems
== 1 )
1106 return p_systems
[0];
1109 for ( i
= 0; i
< i_systems
; i
++ )
1111 switch ( p_systems
[i
] )
1114 if ( i_frequency
< 50000000 )
1117 #if DVBAPI_VERSION >= 505
1118 case SYS_DVBC_ANNEX_A
:
1119 if ( i_frequency
> 50000000 || i_srate
!= 27500000 ||
1120 psz_modulation
!= NULL
)
1121 return SYS_DVBC_ANNEX_A
;
1124 case SYS_DVBC_ANNEX_AC
:
1125 if ( i_frequency
> 50000000 || i_srate
!= 27500000 ||
1126 psz_modulation
!= NULL
)
1127 return SYS_DVBC_ANNEX_AC
;
1131 if ( i_frequency
> 50000000 )
1135 if ( i_frequency
> 50000000 && (dvb_plp_id
) )
1143 msg_Warn( NULL
, "couldn't guess delivery system, use --delsys" );
1144 return p_systems
[0];
1147 static void FrontendSet( bool b_init
)
1149 struct dvb_frontend_info info
;
1150 struct dtv_properties
*p
;
1151 fe_delivery_system_t p_systems
[MAX_DELIVERY_SYSTEMS
] = { 0 };
1154 if ( ioctl( i_frontend
, FE_GET_INFO
, &info
) < 0 )
1156 msg_Err( NULL
, "FE_GET_INFO failed (%s)", strerror(errno
) );
1160 uint32_t version
= 0x300;
1161 #if DVBAPI_VERSION >= 505
1162 if ( ioctl( i_frontend
, FE_GET_PROPERTY
, &info_cmdseq
) < 0 )
1166 switch ( info
.type
)
1169 p_systems
[i_systems
++] = SYS_DVBT
;
1170 #if DVBAPI_VERSION >= 505
1171 if ( info
.caps
& FE_CAN_2G_MODULATION
)
1172 p_systems
[i_systems
++] = SYS_DVBT2
;
1176 #if DVBAPI_VERSION >= 505
1177 p_systems
[i_systems
++] = SYS_DVBC_ANNEX_A
;
1179 p_systems
[i_systems
++] = SYS_DVBC_ANNEX_AC
;
1183 p_systems
[i_systems
++] = SYS_DVBS
;
1184 if ( info
.caps
& FE_CAN_2G_MODULATION
)
1185 p_systems
[i_systems
++] = SYS_DVBS2
;
1188 if ( info
.caps
& (FE_CAN_8VSB
| FE_CAN_16VSB
) )
1189 p_systems
[i_systems
++] = SYS_ATSC
;
1190 if ( info
.caps
& (FE_CAN_QAM_64
| FE_CAN_QAM_256
| FE_CAN_QAM_AUTO
) )
1191 p_systems
[i_systems
++] = SYS_DVBC_ANNEX_B
;
1194 msg_Err( NULL
, "unknown frontend type %d", info
.type
);
1197 #if DVBAPI_VERSION >= 505
1201 version
= info_cmdargs
[0].u
.data
;
1202 if ( ioctl( i_frontend
, FE_GET_PROPERTY
, &enum_cmdseq
) < 0 )
1204 msg_Err( NULL
, "unable to query frontend" );
1207 i_systems
= enum_cmdargs
[0].u
.buffer
.len
;
1208 if ( i_systems
< 1 )
1210 msg_Err( NULL
, "no available delivery system" );
1215 for ( i
= 0; i
< i_systems
; i
++ )
1216 p_systems
[i
] = enum_cmdargs
[0].u
.buffer
.data
[i
];
1221 FrontendInfo( &info
, version
, p_systems
, i_systems
);
1223 /* Clear frontend commands */
1224 if ( ioctl( i_frontend
, FE_SET_PROPERTY
, &cmdclear
) < 0 )
1226 msg_Err( NULL
, "Unable to clear frontend" );
1230 fe_delivery_system_t system
= FrontendGuessSystem( p_systems
, i_systems
);
1235 p
->props
[DELSYS
].u
.data
= system
;
1236 p
->props
[FREQUENCY
].u
.data
= i_frequency
;
1237 p
->props
[INVERSION
].u
.data
= GetInversion();
1238 if ( psz_modulation
!= NULL
)
1239 p
->props
[MODULATION
].u
.data
= GetModulation();
1240 p
->props
[BANDWIDTH
].u
.data
= i_bandwidth
* 1000000;
1241 p
->props
[FEC_INNER
].u
.data
= GetFECInner(info
.caps
);
1242 p
->props
[FEC_LP
].u
.data
= GetFECLP(info
.caps
);
1243 p
->props
[GUARD
].u
.data
= GetGuard();
1244 p
->props
[TRANSMISSION
].u
.data
= GetTransmission();
1245 p
->props
[HIERARCHY
].u
.data
= GetHierarchy();
1247 msg_Dbg( NULL
, "tuning DVB-T frontend to f=%d bandwidth=%d inversion=%d fec_hp=%d fec_lp=%d hierarchy=%d modulation=%s guard=%d transmission=%d",
1248 i_frequency
, i_bandwidth
, i_inversion
, i_fec
, i_fec_lp
,
1250 psz_modulation
== NULL
? "qam_auto" : psz_modulation
,
1251 i_guard
, i_transmission
);
1255 p
->props
[DELSYS
].u
.data
= system
;
1256 p
->props
[FREQUENCY
].u
.data
= i_frequency
;
1257 p
->props
[INVERSION
].u
.data
= GetInversion();
1258 if ( psz_modulation
!= NULL
)
1259 p
->props
[MODULATION
].u
.data
= GetModulation();
1260 p
->props
[BANDWIDTH
].u
.data
= i_bandwidth
* 1000000;
1261 p
->props
[FEC_INNER
].u
.data
= GetFECInner(info
.caps
);
1262 p
->props
[FEC_LP
].u
.data
= GetFECLP(info
.caps
);
1263 p
->props
[GUARD
].u
.data
= GetGuard();
1264 p
->props
[TRANSMISSION
].u
.data
= GetTransmission();
1265 p
->props
[HIERARCHY
].u
.data
= GetHierarchy();
1266 p
->props
[PLP_ID
].u
.data
= dvb_plp_id
;
1268 msg_Dbg( NULL
, "tuning DVB-T2 frontend to f=%d bandwidth=%d inversion=%d fec_hp=%d fec_lp=%d hierarchy=%d modulation=%s guard=%d transmission=%d PLP_ID=%d ",
1269 i_frequency
, i_bandwidth
, i_inversion
, i_fec
, i_fec_lp
,
1271 psz_modulation
== NULL
? "qam_auto" : psz_modulation
,
1272 i_guard
, i_transmission
, p
->props
[PLP_ID
].u
.data
);
1274 #if DVBAPI_VERSION >= 505
1275 case SYS_DVBC_ANNEX_A
:
1277 case SYS_DVBC_ANNEX_AC
:
1280 p
->props
[FREQUENCY
].u
.data
= i_frequency
;
1281 p
->props
[INVERSION
].u
.data
= GetInversion();
1282 if ( psz_modulation
!= NULL
)
1283 p
->props
[MODULATION
].u
.data
= GetModulation();
1284 p
->props
[SYMBOL_RATE
].u
.data
= i_srate
;
1286 msg_Dbg( NULL
, "tuning DVB-C frontend to f=%d srate=%d inversion=%d modulation=%s",
1287 i_frequency
, i_srate
, i_inversion
,
1288 psz_modulation
== NULL
? "qam_auto" : psz_modulation
);
1291 case SYS_DVBC_ANNEX_B
:
1293 p
->props
[DELSYS
].u
.data
= system
;
1294 p
->props
[FREQUENCY
].u
.data
= i_frequency
;
1295 p
->props
[INVERSION
].u
.data
= GetInversion();
1296 if ( psz_modulation
!= NULL
)
1297 p
->props
[MODULATION
].u
.data
= GetModulation();
1299 msg_Dbg( NULL
, "tuning ATSC cable frontend to f=%d inversion=%d modulation=%s",
1300 i_frequency
, i_inversion
,
1301 psz_modulation
== NULL
? "qam_auto" : psz_modulation
);
1306 if ( psz_modulation
!= NULL
)
1309 p
->props
[MODULATION
].u
.data
= GetModulation();
1310 p
->props
[IDX_DVBS2_PILOT
].u
.data
= GetPilot();
1311 p
->props
[IDX_DVBS2_ROLLOFF
].u
.data
= GetRollOff();
1312 p
->props
[IDX_DVBS2_STREAM_ID
].u
.data
= i_mis
;
1317 p
->props
[INVERSION
].u
.data
= GetInversion();
1318 p
->props
[SYMBOL_RATE
].u
.data
= i_srate
;
1319 p
->props
[FEC_INNER
].u
.data
= GetFECInner(info
.caps
);
1320 p
->props
[FREQUENCY
].u
.data
= FrontendDoDiseqc();
1322 msg_Dbg( NULL
, "tuning DVB-S frontend to f=%d srate=%d inversion=%d fec=%d rolloff=%d modulation=%s pilot=%d mis=%d /pls-mode: %s (%d) pls-code: %d is-id: %d /",
1323 i_frequency
, i_srate
, i_inversion
, i_fec
, i_rolloff
,
1324 psz_modulation
== NULL
? "legacy" : psz_modulation
, i_pilot
,
1325 i_mis
, psz_mis_pls_mode
, i_mis_pls_mode
, i_mis_pls_code
, i_mis_is_id
);
1330 p
->props
[FREQUENCY
].u
.data
= i_frequency
;
1331 p
->props
[INVERSION
].u
.data
= GetInversion();
1332 if ( psz_modulation
!= NULL
)
1333 p
->props
[MODULATION
].u
.data
= GetModulation();
1335 msg_Dbg( NULL
, "tuning ATSC frontend to f=%d inversion=%d modulation=%s",
1336 i_frequency
, i_inversion
,
1337 psz_modulation
== NULL
? "qam_auto" : psz_modulation
);
1341 p
->props
[DELSYS
].u
.data
= system
;
1342 p
->props
[FREQUENCY
].u
.data
= i_frequency
;
1343 p
->props
[ISDBT_BANDWIDTH
].u
.data
= i_bandwidth
* 1000000;
1344 p
->props
[INVERSION
].u
.data
= GetInversion();
1345 p
->props
[ISDBT_LAYERA_FEC
].u
.data
= FEC_AUTO
;
1346 p
->props
[ISDBT_LAYERA_MODULATION
].u
.data
= QAM_AUTO
;
1347 p
->props
[ISDBT_LAYERA_SEGMENT_COUNT
].u
.data
= 0;
1348 p
->props
[ISDBT_LAYERA_TIME_INTERLEAVING
].u
.data
= 0;
1349 p
->props
[ISDBT_LAYERB_FEC
].u
.data
= FEC_AUTO
;
1350 p
->props
[ISDBT_LAYERB_MODULATION
].u
.data
= QAM_AUTO
;
1351 p
->props
[ISDBT_LAYERB_SEGMENT_COUNT
].u
.data
= 0;
1352 p
->props
[ISDBT_LAYERB_TIME_INTERLEAVING
].u
.data
= 0;
1353 p
->props
[ISDBT_LAYERC_FEC
].u
.data
= FEC_AUTO
;
1354 p
->props
[ISDBT_LAYERC_MODULATION
].u
.data
= QAM_AUTO
;
1355 p
->props
[ISDBT_LAYERC_SEGMENT_COUNT
].u
.data
= 0;
1356 p
->props
[ISDBT_LAYERC_TIME_INTERLEAVING
].u
.data
= 0;
1358 msg_Dbg( NULL
, "tuning ISDB-T frontend to f=%d bandwidth=%d ",
1359 i_frequency
, i_bandwidth
);
1363 msg_Err( NULL
, "unknown frontend type %d", info
.type
);
1367 /* Empty the event queue */
1370 struct dvb_frontend_event event
;
1371 if ( ioctl( i_frontend
, FE_GET_EVENT
, &event
) < 0
1372 && errno
== EWOULDBLOCK
)
1376 /* Now send it all to the frontend device */
1377 if ( ioctl( i_frontend
, FE_SET_PROPERTY
, p
) < 0 )
1379 msg_Err( NULL
, "setting frontend failed (%s)", strerror(errno
) );
1385 if (i_frontend_timeout_duration
)
1386 ev_timer_again(event_loop
, &lock_watcher
);
1391 #warning "You are trying to compile DVBlast with an outdated linux-dvb interface."
1392 #warning "DVBlast will be very limited and some options will have no effect."
1394 static void FrontendSet( bool b_init
)
1396 struct dvb_frontend_info info
;
1397 struct dvb_frontend_parameters fep
;
1399 if ( ioctl( i_frontend
, FE_GET_INFO
, &info
) < 0 )
1401 msg_Err( NULL
, "FE_GET_INFO failed (%s)", strerror(errno
) );
1405 switch ( info
.type
)
1408 fep
.frequency
= i_frequency
;
1409 fep
.inversion
= INVERSION_AUTO
;
1411 switch ( i_bandwidth
)
1413 case 6: fep
.u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
; break;
1414 case 7: fep
.u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
; break;
1416 case 8: fep
.u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
; break;
1419 fep
.u
.ofdm
.code_rate_HP
= FEC_AUTO
;
1420 fep
.u
.ofdm
.code_rate_LP
= FEC_AUTO
;
1421 fep
.u
.ofdm
.constellation
= QAM_AUTO
;
1422 fep
.u
.ofdm
.transmission_mode
= TRANSMISSION_MODE_AUTO
;
1423 fep
.u
.ofdm
.guard_interval
= GUARD_INTERVAL_AUTO
;
1424 fep
.u
.ofdm
.hierarchy_information
= HIERARCHY_AUTO
;
1426 msg_Dbg( NULL
, "tuning OFDM frontend to f=%d, bandwidth=%d",
1427 i_frequency
, i_bandwidth
);
1431 fep
.frequency
= i_frequency
;
1432 fep
.inversion
= INVERSION_AUTO
;
1433 fep
.u
.qam
.symbol_rate
= i_srate
;
1434 fep
.u
.qam
.fec_inner
= FEC_AUTO
;
1435 fep
.u
.qam
.modulation
= QAM_AUTO
;
1437 msg_Dbg( NULL
, "tuning QAM frontend to f=%d, srate=%d",
1438 i_frequency
, i_srate
);
1442 fep
.inversion
= INVERSION_AUTO
;
1443 fep
.u
.qpsk
.symbol_rate
= i_srate
;
1444 fep
.u
.qpsk
.fec_inner
= FEC_AUTO
;
1445 fep
.frequency
= FrontendDoDiseqc();
1447 msg_Dbg( NULL
, "tuning QPSK frontend to f=%d, srate=%d",
1448 i_frequency
, i_srate
);
1451 #if DVBAPI_VERSION >= 301
1453 fep
.frequency
= i_frequency
;
1455 fep
.u
.vsb
.modulation
= QAM_AUTO
;
1457 msg_Dbg( NULL
, "tuning ATSC frontend to f=%d", i_frequency
);
1462 msg_Err( NULL
, "unknown frontend type %d", info
.type
);
1466 /* Empty the event queue */
1469 struct dvb_frontend_event event
;
1470 if ( ioctl( i_frontend
, FE_GET_EVENT
, &event
) < 0
1471 && errno
== EWOULDBLOCK
)
1475 /* Now send it all to the frontend device */
1476 if ( ioctl( i_frontend
, FE_SET_FRONTEND
, &fep
) < 0 )
1478 msg_Err( NULL
, "setting frontend failed (%s)", strerror(errno
) );
1484 if (i_frontend_timeout_duration
)
1485 ev_timer_again(event_loop
, &lock_watcher
);
1490 /*****************************************************************************
1491 * dvb_FrontendStatus
1492 *****************************************************************************/
1493 uint8_t dvb_FrontendStatus( uint8_t *p_answer
, ssize_t
*pi_size
)
1495 struct ret_frontend_status
*p_ret
= (struct ret_frontend_status
*)p_answer
;
1497 if ( ioctl( i_frontend
, FE_GET_INFO
, &p_ret
->info
) < 0 )
1499 msg_Err( NULL
, "ioctl FE_GET_INFO failed (%s)", strerror(errno
) );
1503 if ( ioctl( i_frontend
, FE_READ_STATUS
, &p_ret
->i_status
) < 0 )
1505 msg_Err( NULL
, "ioctl FE_READ_STATUS failed (%s)", strerror(errno
) );
1509 if ( p_ret
->i_status
& FE_HAS_LOCK
)
1511 if ( ioctl( i_frontend
, FE_READ_BER
, &p_ret
->i_ber
) < 0 )
1512 msg_Err( NULL
, "ioctl FE_READ_BER failed (%s)", strerror(errno
) );
1514 if ( ioctl( i_frontend
, FE_READ_SIGNAL_STRENGTH
, &p_ret
->i_strength
)
1516 msg_Err( NULL
, "ioctl FE_READ_SIGNAL_STRENGTH failed (%s)",
1519 if ( ioctl( i_frontend
, FE_READ_SNR
, &p_ret
->i_snr
) < 0 )
1520 msg_Err( NULL
, "ioctl FE_READ_SNR failed (%s)", strerror(errno
) );
1523 *pi_size
= sizeof(struct ret_frontend_status
);
1524 return RET_FRONTEND_STATUS
;