1 /*****************************************************************************
2 * input_satellite.c: Satellite card input
3 *****************************************************************************
4 * Copyright (C) 1998-2002 VideoLAN
6 * Authors: Johan Bilien <jobi@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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc/input.h>
38 #include <sys/types.h>
42 #ifdef STRNCASECMP_IN_STRINGS_H
46 #include "satellite_tools.h"
48 #define SATELLITE_READ_ONCE 3
50 /*****************************************************************************
52 *****************************************************************************/
53 static int SatelliteOpen ( input_thread_t * );
54 static void SatelliteClose ( input_thread_t * );
55 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
57 static int SatelliteSetArea ( input_thread_t *, input_area_t * );
58 static int SatelliteSetProgram ( input_thread_t *, pgrm_descriptor_t * );
59 static void SatelliteSeek ( input_thread_t *, off_t );
61 /*****************************************************************************
62 * Functions exported as capabilities. They are declared as static so that
63 * we don't pollute the namespace too much.
64 *****************************************************************************/
65 void _M( access_getfunctions )( function_list_t * p_function_list )
67 #define access p_function_list->functions.access
68 access.pf_open = SatelliteOpen;
69 access.pf_close = SatelliteClose;
70 access.pf_read = SatelliteRead;
71 access.pf_set_area = SatelliteSetArea;
72 access.pf_set_program = SatelliteSetProgram;
73 access.pf_seek = SatelliteSeek;
77 /*****************************************************************************
78 * SatelliteOpen : open the dvr device
79 *****************************************************************************/
80 static int SatelliteOpen( input_thread_t * p_input )
82 input_socket_t * p_satellite;
96 /* parse the options passed in command line : */
98 psz_parser = strdup( p_input->psz_name );
105 i_freq = (int)strtol( psz_parser, &psz_next, 10 );
109 psz_parser = psz_next + 1;
110 b_pol = (vlc_bool_t)strtol( psz_parser, &psz_next, 10 );
113 psz_parser = psz_next + 1;
114 i_fec = (int)strtol( psz_parser, &psz_next, 10 );
117 psz_parser = psz_next + 1;
118 i_srate = (int)strtol( psz_parser, &psz_next, 10 );
124 if( i_freq > 12999 || i_freq < 10000 )
126 msg_Warn( p_input, "invalid frequency, using default one" );
127 i_freq = config_GetInt( p_input, "frequency" );
128 if( i_freq > 12999 || i_freq < 10000 )
130 msg_Err( p_input, "invalid default frequency" );
135 if( i_srate > 30000 || i_srate < 1000 )
137 msg_Warn( p_input, "invalid symbol rate, using default one" );
138 i_srate = config_GetInt( p_input, "symbol-rate" );
139 if( i_srate > 30000 || i_srate < 1000 )
141 msg_Err( p_input, "invalid default symbol rate" );
146 if( b_pol && b_pol != 1 )
148 msg_Warn( p_input, "invalid polarization, using default one" );
149 b_pol = config_GetInt( p_input, "polarization" );
150 if( b_pol && b_pol != 1 )
152 msg_Err( p_input, "invalid default polarization" );
157 if( i_fec > 7 || i_fec < 1 )
159 msg_Warn( p_input, "invalid FEC, using default one" );
160 i_fec = config_GetInt( p_input, "fec" );
161 if( i_fec > 7 || i_fec < 1 )
163 msg_Err( p_input, "invalid default FEC" );
197 /* Initialise structure */
198 p_satellite = malloc( sizeof( input_socket_t ) );
200 if( p_satellite == NULL )
202 msg_Err( p_input, "out of memory" );
206 p_input->p_access_data = (void *)p_satellite;
208 /* Open the DVR device */
209 msg_Dbg( p_input, "opening DVR device `%s'", DVR );
211 if( (p_satellite->i_handle = open( DVR,
212 /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
214 msg_Warn( p_input, "cannot open `%s' (%s)", DVR, strerror(errno) );
220 /* Get antenna configuration options */
221 b_diseqc = config_GetInt( p_input, "diseqc" );
222 i_lnb_lof1 = config_GetInt( p_input, "lnb-lof1" );
223 i_lnb_lof2 = config_GetInt( p_input, "lnb-lof2" );
224 i_lnb_slof = config_GetInt( p_input, "lnb-slof" );
226 /* Initialize the Satellite Card */
228 msg_Dbg( p_input, "initializing Sat Card with Freq: %d, Pol: %d, "
229 "FEC: %03f, Srate: %d", i_freq, b_pol, f_fec, i_srate );
231 if ( ioctl_SECControl( i_freq * 1000, b_pol, i_lnb_slof * 1000,
234 msg_Err( p_input, "an error occured when controling SEC" );
235 close( p_satellite->i_handle );
240 msg_Dbg( p_input, "initializing frontend device" );
241 switch (ioctl_SetQPSKFrontend ( i_freq * 1000, i_srate* 1000, f_fec,
242 i_lnb_lof1 * 1000, i_lnb_lof2 * 1000, i_lnb_slof * 1000))
245 msg_Err( p_input, "frontend returned an unexpected event" );
246 close( p_satellite->i_handle );
251 msg_Err( p_input, "frontend returned no event" );
252 close( p_satellite->i_handle );
257 msg_Err( p_input, "frontend: timeout when polling for event" );
258 close( p_satellite->i_handle );
263 msg_Err( p_input, "an error occured when polling frontend device" );
264 close( p_satellite->i_handle );
269 msg_Err( p_input, "frontend returned a failure event" );
270 close( p_satellite->i_handle );
278 msg_Dbg( p_input, "setting filter on PAT" );
280 if ( ioctl_SetDMXFilter( 0, &i_fd, 3 ) < 0 )
282 msg_Err( p_input, "an error occured when setting filter on PAT" );
283 close( p_satellite->i_handle );
288 if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
290 msg_Err( p_input, "could not initialize stream structure" );
291 close( p_satellite->i_handle );
296 vlc_mutex_lock( &p_input->stream.stream_lock );
298 p_input->stream.b_pace_control = 1;
299 p_input->stream.b_seekable = 0;
300 p_input->stream.p_selected_area->i_tell = 0;
302 vlc_mutex_unlock( &p_input->stream.stream_lock );
304 p_input->i_mtu = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
305 p_input->stream.i_method = INPUT_METHOD_SATELLITE;
310 /*****************************************************************************
311 * SatelliteClose : Closes the device
312 *****************************************************************************/
313 static void SatelliteClose( input_thread_t * p_input )
315 input_socket_t * p_satellite;
318 if ( p_input->stream.p_selected_program )
320 for ( i_es_index = 1 ;
321 i_es_index < p_input->stream.p_selected_program->
325 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
326 if ( p_es->p_decoder_fifo )
328 ioctl_UnsetDMXFilter( p_es->i_demux_fd );
334 p_satellite = (input_socket_t *)p_input;
335 close( p_satellite->i_handle );
339 /*****************************************************************************
340 * SatelliteRead: reads data from the satellite card
341 *****************************************************************************/
342 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
347 /* if not set, set filters to the PMTs */
348 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
350 if ( p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd == 0 )
352 msg_Dbg( p_input, "setting filter on pmt pid %d",
353 p_input->stream.pp_programs[i]->pp_es[0]->i_id );
354 ioctl_SetDMXFilter( p_input->stream.pp_programs[i]->pp_es[0]->i_id,
355 &p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd,
360 return input_FDRead( p_input, p_buffer, i_len );
366 /*****************************************************************************
367 * SatelliteSetArea : Does nothing
368 *****************************************************************************/
369 static int SatelliteSetArea( input_thread_t * p_input, input_area_t * p_area )
374 /*****************************************************************************
375 * SatelliteSetProgram : Sets the card filters according to the
377 * and makes the appropriate changes to stream structure.
378 *****************************************************************************/
379 int SatelliteSetProgram( input_thread_t * p_input,
380 pgrm_descriptor_t * p_new_prg )
384 if ( p_input->stream.p_selected_program )
386 for ( i_es_index = 1 ; /* 0 should be the PMT */
387 i_es_index < p_input->stream.p_selected_program->
391 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
392 if ( p_es->p_decoder_fifo )
394 input_UnselectES( p_input , p_es );
396 if ( p_es->i_demux_fd )
398 ioctl_UnsetDMXFilter( p_es->i_demux_fd );
399 p_es->i_demux_fd = 0;
405 for (i_es_index = 1 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
407 #define p_es p_new_prg->pp_es[i_es_index]
408 switch( p_es->i_cat )
412 if ( !config_GetInt( p_input, "novideo" ) )
414 ioctl_SetDMXFilter( p_es->i_id, &p_es->i_demux_fd, 1);
415 input_SelectES( p_input , p_es );
420 if ( !config_GetInt( p_input, "noaudio" ) )
422 ioctl_SetDMXFilter( p_es->i_id, &p_es->i_demux_fd, 2);
423 input_SelectES( p_input , p_es );
427 ioctl_SetDMXFilter( p_es->i_id, &p_es->i_demux_fd, 3);
428 input_SelectES( p_input , p_es );
434 p_input->stream.p_selected_program = p_new_prg;
439 /*****************************************************************************
440 * SatelliteSeek: does nothing (not a seekable stream
441 *****************************************************************************/
442 static void SatelliteSeek( input_thread_t * p_input, off_t i_off )