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 ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
55 static int SatelliteSetArea ( input_thread_t *, input_area_t * );
56 static int SatelliteSetProgram ( input_thread_t *, pgrm_descriptor_t * );
57 static void SatelliteSeek ( input_thread_t *, off_t );
59 /*****************************************************************************
60 * Open: open the dvr device
61 *****************************************************************************/
62 int E_(Open) ( vlc_object_t *p_this )
64 input_thread_t * p_input = (input_thread_t *)p_this;
65 input_socket_t * p_satellite;
79 /* parse the options passed in command line : */
81 psz_parser = strdup( p_input->psz_name );
88 p_input->pf_read = SatelliteRead;
89 p_input->pf_set_program = SatelliteSetProgram;
90 p_input->pf_set_area = SatelliteSetArea;
91 p_input->pf_seek = SatelliteSeek;
93 i_freq = (int)strtol( psz_parser, &psz_next, 10 );
97 psz_parser = psz_next + 1;
98 b_pol = (vlc_bool_t)strtol( psz_parser, &psz_next, 10 );
101 psz_parser = psz_next + 1;
102 i_fec = (int)strtol( psz_parser, &psz_next, 10 );
105 psz_parser = psz_next + 1;
106 i_srate = (int)strtol( psz_parser, &psz_next, 10 );
112 if( i_freq > 12999 || i_freq < 10000 )
114 msg_Warn( p_input, "invalid frequency, using default one" );
115 i_freq = config_GetInt( p_input, "frequency" );
116 if( i_freq > 12999 || i_freq < 10000 )
118 msg_Err( p_input, "invalid default frequency" );
123 if( i_srate > 30000 || i_srate < 1000 )
125 msg_Warn( p_input, "invalid symbol rate, using default one" );
126 i_srate = config_GetInt( p_input, "symbol-rate" );
127 if( i_srate > 30000 || i_srate < 1000 )
129 msg_Err( p_input, "invalid default symbol rate" );
134 if( b_pol && b_pol != 1 )
136 msg_Warn( p_input, "invalid polarization, using default one" );
137 b_pol = config_GetInt( p_input, "polarization" );
138 if( b_pol && b_pol != 1 )
140 msg_Err( p_input, "invalid default polarization" );
145 if( i_fec > 7 || i_fec < 1 )
147 msg_Warn( p_input, "invalid FEC, using default one" );
148 i_fec = config_GetInt( p_input, "fec" );
149 if( i_fec > 7 || i_fec < 1 )
151 msg_Err( p_input, "invalid default FEC" );
185 /* Initialise structure */
186 p_satellite = malloc( sizeof( input_socket_t ) );
188 if( p_satellite == NULL )
190 msg_Err( p_input, "out of memory" );
194 p_input->p_access_data = (void *)p_satellite;
196 /* Open the DVR device */
197 msg_Dbg( p_input, "opening DVR device `%s'", DVR );
199 if( (p_satellite->i_handle = open( DVR,
200 /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
202 msg_Warn( p_input, "cannot open `%s' (%s)", DVR, strerror(errno) );
208 /* Get antenna configuration options */
209 b_diseqc = config_GetInt( p_input, "diseqc" );
210 i_lnb_lof1 = config_GetInt( p_input, "lnb-lof1" );
211 i_lnb_lof2 = config_GetInt( p_input, "lnb-lof2" );
212 i_lnb_slof = config_GetInt( p_input, "lnb-slof" );
214 /* Initialize the Satellite Card */
216 msg_Dbg( p_input, "initializing Sat Card with Freq: %d, Pol: %d, "
217 "FEC: %03f, Srate: %d", i_freq, b_pol, f_fec, i_srate );
219 if ( ioctl_SECControl( i_freq * 1000, b_pol, i_lnb_slof * 1000,
222 msg_Err( p_input, "an error occured when controling SEC" );
223 close( p_satellite->i_handle );
228 msg_Dbg( p_input, "initializing frontend device" );
229 switch (ioctl_SetQPSKFrontend ( i_freq * 1000, i_srate* 1000, f_fec,
230 i_lnb_lof1 * 1000, i_lnb_lof2 * 1000, i_lnb_slof * 1000))
233 msg_Err( p_input, "frontend returned an unexpected event" );
234 close( p_satellite->i_handle );
239 msg_Err( p_input, "frontend returned no event" );
240 close( p_satellite->i_handle );
245 msg_Err( p_input, "frontend: timeout when polling for event" );
246 close( p_satellite->i_handle );
251 msg_Err( p_input, "an error occured when polling frontend device" );
252 close( p_satellite->i_handle );
257 msg_Err( p_input, "frontend returned a failure event" );
258 close( p_satellite->i_handle );
266 msg_Dbg( p_input, "setting filter on PAT" );
268 if ( ioctl_SetDMXFilter( 0, &i_fd, 3 ) < 0 )
270 msg_Err( p_input, "an error occured when setting filter on PAT" );
271 close( p_satellite->i_handle );
276 if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
278 msg_Err( p_input, "could not initialize stream structure" );
279 close( p_satellite->i_handle );
284 vlc_mutex_lock( &p_input->stream.stream_lock );
286 p_input->stream.b_pace_control = 1;
287 p_input->stream.b_seekable = 0;
288 p_input->stream.p_selected_area->i_tell = 0;
290 vlc_mutex_unlock( &p_input->stream.stream_lock );
292 p_input->i_mtu = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
293 p_input->stream.i_method = INPUT_METHOD_SATELLITE;
298 /*****************************************************************************
299 * Close : Close the device
300 *****************************************************************************/
301 void E_(Close) ( vlc_object_t *p_this )
303 input_thread_t * p_input = (input_thread_t *)p_this;
304 input_socket_t * p_satellite;
307 if ( p_input->stream.p_selected_program )
309 for ( i_es_index = 1 ;
310 i_es_index < p_input->stream.p_selected_program->
314 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
315 if ( p_es->p_decoder_fifo )
317 ioctl_UnsetDMXFilter( p_es->i_demux_fd );
323 p_satellite = (input_socket_t *)p_input;
324 close( p_satellite->i_handle );
328 /*****************************************************************************
329 * SatelliteRead: reads data from the satellite card
330 *****************************************************************************/
331 static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
336 /* if not set, set filters to the PMTs */
337 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
339 if ( p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd == 0 )
341 msg_Dbg( p_input, "setting filter on pmt pid %d",
342 p_input->stream.pp_programs[i]->pp_es[0]->i_id );
343 ioctl_SetDMXFilter( p_input->stream.pp_programs[i]->pp_es[0]->i_id,
344 &p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd,
349 return input_FDRead( p_input, p_buffer, i_len );
355 /*****************************************************************************
356 * SatelliteSetArea : Does nothing
357 *****************************************************************************/
358 static int SatelliteSetArea( input_thread_t * p_input, input_area_t * p_area )
363 /*****************************************************************************
364 * SatelliteSetProgram : Sets the card filters according to the
366 * and makes the appropriate changes to stream structure.
367 *****************************************************************************/
368 int SatelliteSetProgram( input_thread_t * p_input,
369 pgrm_descriptor_t * p_new_prg )
373 if ( p_input->stream.p_selected_program )
375 for ( i_es_index = 1 ; /* 0 should be the PMT */
376 i_es_index < p_input->stream.p_selected_program->
380 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
381 if ( p_es->p_decoder_fifo )
383 input_UnselectES( p_input , p_es );
385 if ( p_es->i_demux_fd )
387 ioctl_UnsetDMXFilter( p_es->i_demux_fd );
388 p_es->i_demux_fd = 0;
394 for (i_es_index = 1 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
396 #define p_es p_new_prg->pp_es[i_es_index]
397 switch( p_es->i_cat )
401 if ( config_GetInt( p_input, "video" ) )
403 ioctl_SetDMXFilter( p_es->i_id, &p_es->i_demux_fd, 1);
404 input_SelectES( p_input , p_es );
409 if ( config_GetInt( p_input, "audio" ) )
411 ioctl_SetDMXFilter( p_es->i_id, &p_es->i_demux_fd, 2);
412 input_SelectES( p_input , p_es );
416 ioctl_SetDMXFilter( p_es->i_id, &p_es->i_demux_fd, 3);
417 input_SelectES( p_input , p_es );
423 p_input->stream.p_selected_program = p_new_prg;
428 /*****************************************************************************
429 * SatelliteSeek: does nothing (not a seekable stream
430 *****************************************************************************/
431 static void SatelliteSeek( input_thread_t * p_input, off_t i_off )