1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 the VideoLAN team
7 * Authors: Eric Petit <titer@videolan.org>
8 * Paul Corke <paulc@datatote.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
37 #include <vlc_network.h>
39 #include <sys/types.h>
42 #include <linux/types.h>
43 #include <sys/ioctl.h>
44 #if defined(HAVE_LINUX_VIDEODEV2_H)
45 # include <linux/videodev2.h>
46 #elif defined(HAVE_SYS_VIDEOIO_H)
47 # include <sys/videoio.h>
49 # error "No Video4Linux2 headers found."
52 /*****************************************************************************
54 *****************************************************************************/
55 static int Open ( vlc_object_t
* );
56 static void Close( vlc_object_t
* );
58 #define DEVICE_TEXT N_( "Device" )
59 #define DEVICE_LONGTEXT N_( "PVR video device" )
61 #define RADIO_DEVICE_TEXT N_( "Radio device" )
62 #define RADIO_DEVICE_LONGTEXT N_( "PVR radio device" )
64 #define NORM_TEXT N_( "Norm" )
65 #define NORM_LONGTEXT N_( "Norm of the stream " \
66 "(Automatic, SECAM, PAL, or NTSC)." )
68 #define WIDTH_TEXT N_( "Width" )
69 #define WIDTH_LONGTEXT N_( "Width of the stream to capture " \
70 "(-1 for autodetection)." )
72 #define HEIGHT_TEXT N_( "Height" )
73 #define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \
74 "(-1 for autodetection)." )
76 #define FREQUENCY_TEXT N_( "Frequency" )
77 #define FREQUENCY_LONGTEXT N_( "Frequency to capture (in kHz), if applicable." )
79 #define FRAMERATE_TEXT N_( "Framerate" )
80 #define FRAMERATE_LONGTEXT N_( "Framerate to capture, if applicable " \
81 "(-1 for autodetect)." )
83 #define KEYINT_TEXT N_( "Key interval" )
84 #define KEYINT_LONGTEXT N_( "Interval between keyframes (-1 for autodetect)." )
86 #define BFRAMES_TEXT N_( "B Frames" )
87 #define BFRAMES_LONGTEXT N_("If this option is set, B-Frames will be used. " \
88 "Use this option to set the number of B-Frames.")
90 #define BITRATE_TEXT N_( "Bitrate" )
91 #define BITRATE_LONGTEXT N_( "Bitrate to use (-1 for default)." )
93 #define BITRATE_PEAK_TEXT N_( "Bitrate peak" )
94 #define BITRATE_PEAK_LONGTEXT N_( "Peak bitrate in VBR mode." )
96 #define BITRATE_MODE_TEXT N_( "Bitrate mode" )
97 #define BITRATE_MODE_LONGTEXT N_( "Bitrate mode to use (VBR or CBR)." )
99 #define BITMASK_TEXT N_( "Audio bitmask" )
100 #define BITMASK_LONGTEXT N_("Bitmask that will "\
101 "get used by the audio part of the card." )
103 #define VOLUME_TEXT N_( "Volume" )
104 #define VOLUME_LONGTEXT N_("Audio volume (0-65535)." )
106 #define CHAN_TEXT N_( "Channel" )
107 #define CHAN_LONGTEXT N_( "Channel of the card to use (Usually, 0 = tuner, " \
108 "1 = composite, 2 = svideo)" )
110 static const int i_norm_list
[] =
111 { V4L2_STD_UNKNOWN
, V4L2_STD_SECAM
, V4L2_STD_PAL
, V4L2_STD_NTSC
};
112 static const char *const psz_norm_list_text
[] =
113 { N_("Automatic"), N_("SECAM"), N_("PAL"), N_("NTSC") };
115 static const int i_bitrates
[] = { 0, 1 };
116 static const char *const psz_bitrates_list_text
[] = { N_("vbr"), N_("cbr") };
118 static const int pi_radio_range
[2] = { 65000, 108000 };
121 set_shortname( N_("PVR") )
122 set_description( N_("IVTV MPEG Encoding cards input") )
123 set_category( CAT_INPUT
)
124 set_subcategory( SUBCAT_INPUT_ACCESS
)
125 set_capability( "access", 0 )
126 add_shortcut( "pvr" )
128 add_string( "pvr-device", "/dev/video0", DEVICE_TEXT
,
129 DEVICE_LONGTEXT
, false )
130 add_string( "pvr-radio-device", "/dev/radio0", RADIO_DEVICE_TEXT
,
131 RADIO_DEVICE_LONGTEXT
, false )
132 add_integer( "pvr-norm", V4L2_STD_UNKNOWN
, NORM_TEXT
,
133 NORM_LONGTEXT
, false )
134 change_integer_list( i_norm_list
, psz_norm_list_text
)
135 add_integer( "pvr-width", -1, WIDTH_TEXT
, WIDTH_LONGTEXT
, true )
136 add_integer( "pvr-height", -1, HEIGHT_TEXT
, HEIGHT_LONGTEXT
,
138 add_integer( "pvr-frequency", -1, FREQUENCY_TEXT
, FREQUENCY_LONGTEXT
,
140 add_integer( "pvr-framerate", -1, FRAMERATE_TEXT
, FRAMERATE_LONGTEXT
,
142 add_integer( "pvr-keyint", -1, KEYINT_TEXT
, KEYINT_LONGTEXT
,
144 add_integer( "pvr-bframes", -1, FRAMERATE_TEXT
, FRAMERATE_LONGTEXT
,
146 add_integer( "pvr-bitrate", -1, BITRATE_TEXT
, BITRATE_LONGTEXT
,
148 add_integer( "pvr-bitrate-peak", -1, BITRATE_PEAK_TEXT
,
149 BITRATE_PEAK_LONGTEXT
, true )
150 add_integer( "pvr-bitrate-mode", -1, BITRATE_MODE_TEXT
,
151 BITRATE_MODE_LONGTEXT
, true )
152 change_integer_list( i_bitrates
, psz_bitrates_list_text
)
153 add_integer( "pvr-audio-bitmask", -1, BITMASK_TEXT
,
154 BITMASK_LONGTEXT
, true )
155 add_integer( "pvr-audio-volume", -1, VOLUME_TEXT
,
156 VOLUME_LONGTEXT
, true )
157 add_integer( "pvr-channel", -1, CHAN_TEXT
, CHAN_LONGTEXT
, true )
159 set_callbacks( Open
, Close
)
162 /*****************************************************************************
164 *****************************************************************************/
165 static ssize_t
Read ( access_t
*, uint8_t *, size_t );
166 static int Control( access_t
*, int, va_list );
170 /* file descriptor */
194 #define MAX_V4L2_CTRLS (6)
195 /*****************************************************************************
196 * AddV4L2Ctrl: adds a control to the v4l2 controls list
197 *****************************************************************************/
198 static void AddV4L2Ctrl( access_t
* p_access
,
199 struct v4l2_ext_controls
* p_controls
,
200 uint32_t i_id
, uint32_t i_value
)
202 if( p_controls
->count
>= MAX_V4L2_CTRLS
)
204 msg_Err( p_access
, "Tried to set too many v4l2 controls at once." );
208 p_controls
->controls
[p_controls
->count
].id
= i_id
;
209 p_controls
->controls
[p_controls
->count
].value
= i_value
;
213 /*****************************************************************************
214 * V4L2SampleRate: calculate v4l2 sample rate from pvr-audio-bitmask
215 *****************************************************************************/
216 static uint32_t V4L2SampleRate( uint32_t i_bitmask
)
218 switch( i_bitmask
& 0x0003 )
220 case 0x0001: return V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000
;
221 case 0x0002: return V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000
;
223 return V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100
;
226 /*****************************************************************************
227 * V4L2AudioEncoding: calculate v4l2 audio encoding level from pvr-audio-bitmask
228 *****************************************************************************/
229 static uint32_t V4L2AudioEncoding( uint32_t i_bitmask
)
231 switch( i_bitmask
& 0x000c )
233 case 0x0004: return V4L2_MPEG_AUDIO_ENCODING_LAYER_1
;
234 case 0x0008: return V4L2_MPEG_AUDIO_ENCODING_LAYER_2
;
239 /*****************************************************************************
240 * V4L2AudioL1Bitrate: calculate v4l2 audio bitrate for layer-1 audio from pvr-audio-bitmask
241 *****************************************************************************/
242 static uint32_t V4L2AudioL1Bitrate( uint32_t i_bitmask
)
244 switch( i_bitmask
& 0x00f0 )
246 case 0x0010: return V4L2_MPEG_AUDIO_L1_BITRATE_32K
;
247 case 0x0020: return V4L2_MPEG_AUDIO_L1_BITRATE_64K
;
248 case 0x0030: return V4L2_MPEG_AUDIO_L1_BITRATE_96K
;
249 case 0x0040: return V4L2_MPEG_AUDIO_L1_BITRATE_128K
;
250 case 0x0050: return V4L2_MPEG_AUDIO_L1_BITRATE_160K
;
251 case 0x0060: return V4L2_MPEG_AUDIO_L1_BITRATE_192K
;
252 case 0x0070: return V4L2_MPEG_AUDIO_L1_BITRATE_224K
;
253 case 0x0080: return V4L2_MPEG_AUDIO_L1_BITRATE_256K
;
254 case 0x0090: return V4L2_MPEG_AUDIO_L1_BITRATE_288K
;
255 case 0x00a0: return V4L2_MPEG_AUDIO_L1_BITRATE_320K
;
256 case 0x00b0: return V4L2_MPEG_AUDIO_L1_BITRATE_352K
;
257 case 0x00c0: return V4L2_MPEG_AUDIO_L1_BITRATE_384K
;
258 case 0x00d0: return V4L2_MPEG_AUDIO_L1_BITRATE_416K
;
259 case 0x00e0: return V4L2_MPEG_AUDIO_L1_BITRATE_448K
;
261 return V4L2_MPEG_AUDIO_L1_BITRATE_320K
;
264 /*****************************************************************************
265 * V4L2AudioL2Bitrate: calculate v4l2 audio bitrate for layer-1 audio from pvr-audio-bitmask
266 *****************************************************************************/
267 static uint32_t V4L2AudioL2Bitrate( uint32_t i_bitmask
)
269 switch( i_bitmask
& 0x00f0 )
271 case 0x0010: return V4L2_MPEG_AUDIO_L2_BITRATE_32K
;
272 case 0x0020: return V4L2_MPEG_AUDIO_L2_BITRATE_48K
;
273 case 0x0030: return V4L2_MPEG_AUDIO_L2_BITRATE_56K
;
274 case 0x0040: return V4L2_MPEG_AUDIO_L2_BITRATE_64K
;
275 case 0x0050: return V4L2_MPEG_AUDIO_L2_BITRATE_80K
;
276 case 0x0060: return V4L2_MPEG_AUDIO_L2_BITRATE_96K
;
277 case 0x0070: return V4L2_MPEG_AUDIO_L2_BITRATE_112K
;
278 case 0x0080: return V4L2_MPEG_AUDIO_L2_BITRATE_128K
;
279 case 0x0090: return V4L2_MPEG_AUDIO_L2_BITRATE_160K
;
280 case 0x00a0: return V4L2_MPEG_AUDIO_L2_BITRATE_192K
;
281 case 0x00b0: return V4L2_MPEG_AUDIO_L2_BITRATE_224K
;
282 case 0x00c0: return V4L2_MPEG_AUDIO_L2_BITRATE_256K
;
283 case 0x00d0: return V4L2_MPEG_AUDIO_L2_BITRATE_320K
;
284 case 0x00e0: return V4L2_MPEG_AUDIO_L2_BITRATE_384K
;
286 return V4L2_MPEG_AUDIO_L2_BITRATE_192K
;
289 /*****************************************************************************
290 * V4L2AudioMode: calculate v4l2 audio mode from pvr-audio-bitmask
291 *****************************************************************************/
292 static uint32_t V4L2AudioMode( uint32_t i_bitmask
)
294 switch( i_bitmask
& 0x0300 )
296 case 0x0100: return V4L2_MPEG_AUDIO_MODE_JOINT_STEREO
;
297 case 0x0200: return V4L2_MPEG_AUDIO_MODE_DUAL
;
298 case 0x0300: return V4L2_MPEG_AUDIO_MODE_MONO
;
300 return V4L2_MPEG_AUDIO_MODE_STEREO
;
303 /*****************************************************************************
304 * ConfigureV4L2: set up codec parameters using the new v4l2 api
305 *****************************************************************************/
306 static int ConfigureV4L2( access_t
* p_access
)
308 access_sys_t
*p_sys
= (access_sys_t
*) p_access
->p_sys
;
309 struct v4l2_ext_controls controls
;
312 memset( &controls
, 0, sizeof(struct v4l2_ext_controls
) );
313 controls
.ctrl_class
= V4L2_CTRL_CLASS_MPEG
;
314 controls
.error_idx
= 0;
315 controls
.reserved
[0] = 0;
316 controls
.reserved
[1] = 0;
318 controls
.controls
= calloc( MAX_V4L2_CTRLS
,
319 sizeof( struct v4l2_ext_control
) );
321 if( controls
.controls
== NULL
)
324 /* Note: Ignore frame rate. Doesn't look like it can be changed. */
325 if( p_sys
->i_bitrate
!= -1 )
327 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_VIDEO_BITRATE
,
329 msg_Dbg( p_access
, "Setting [%u] bitrate = %u",
330 controls
.count
- 1, p_sys
->i_bitrate
);
333 if( p_sys
->i_bitrate_peak
!= -1 )
335 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
,
336 p_sys
->i_bitrate_peak
);
337 msg_Dbg( p_access
, "Setting [%u] bitrate_peak = %u",
338 controls
.count
- 1, p_sys
->i_bitrate_peak
);
341 if( p_sys
->i_bitrate_mode
!= -1 )
343 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_VIDEO_BITRATE_MODE
,
344 p_sys
->i_bitrate_mode
);
345 msg_Dbg( p_access
, "Setting [%u] bitrate_mode = %u",
346 controls
.count
- 1, p_sys
->i_bitrate_mode
);
349 if( p_sys
->i_audio_bitmask
!= -1 )
352 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
353 V4L2SampleRate( p_sys
->i_audio_bitmask
) );
355 /* Encoding layer and bitrate */
356 switch( V4L2AudioEncoding( p_sys
->i_audio_bitmask
) )
358 case V4L2_MPEG_AUDIO_ENCODING_LAYER_1
:
359 AddV4L2Ctrl( p_access
, &controls
,
360 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
361 V4L2_MPEG_AUDIO_ENCODING_LAYER_1
);
362 AddV4L2Ctrl( p_access
, &controls
,
363 V4L2_CID_MPEG_AUDIO_L1_BITRATE
,
364 V4L2AudioL1Bitrate( p_sys
->i_audio_bitmask
) );
367 case V4L2_MPEG_AUDIO_ENCODING_LAYER_2
:
368 AddV4L2Ctrl( p_access
, &controls
,
369 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
,
370 V4L2_MPEG_AUDIO_ENCODING_LAYER_2
);
371 AddV4L2Ctrl( p_access
, &controls
,
372 V4L2_CID_MPEG_AUDIO_L2_BITRATE
,
373 V4L2AudioL2Bitrate( p_sys
->i_audio_bitmask
) );
377 /* Audio mode - stereo or mono */
378 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_AUDIO_MODE
,
379 V4L2AudioMode( p_sys
->i_audio_bitmask
) );
381 /* See if the user wants any other audio feature */
382 if( ( p_sys
->i_audio_bitmask
& 0x1ff00 ) != 0 )
384 /* It would be possible to support the bits that represent:
385 * V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
386 * V4L2_CID_MPEG_AUDIO_EMPHASIS
387 * V4L2_CID_MPEG_AUDIO_CRC
388 * but they are not currently used. Tell the user.
390 msg_Err( p_access
, "There were bits in pvr-audio-bitmask that were not used.");
392 msg_Dbg( p_access
, "Setting audio controls");
395 if( p_sys
->i_keyint
!= -1 )
397 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_VIDEO_GOP_SIZE
,
399 msg_Dbg( p_access
, "Setting [%u] keyint = %u",
400 controls
.count
- 1, p_sys
->i_keyint
);
403 if( p_sys
->i_bframes
!= -1 )
405 AddV4L2Ctrl( p_access
, &controls
, V4L2_CID_MPEG_VIDEO_B_FRAMES
,
407 msg_Dbg( p_access
, "Setting [%u] bframes = %u",
408 controls
.count
- 1, p_sys
->i_bframes
);
411 result
= ioctl( p_sys
->i_fd
, VIDIOC_S_EXT_CTRLS
, &controls
);
414 msg_Err( p_access
, "Failed to write %u new capture card settings.",
415 controls
.error_idx
);
417 free( controls
.controls
);
421 /*****************************************************************************
422 * Open: open the device
423 *****************************************************************************/
424 static int Open( vlc_object_t
* p_this
)
426 access_t
*p_access
= (access_t
*) p_this
;
427 access_sys_t
* p_sys
;
430 struct v4l2_capability device_capability
;
433 memset( &device_capability
, 0, sizeof(struct v4l2_capability
) );
435 access_InitFields( p_access
);
436 ACCESS_SET_CALLBACKS( Read
, NULL
, Control
, NULL
);
437 p_sys
= p_access
->p_sys
= calloc( 1, sizeof( access_sys_t
));
438 if( !p_sys
) return VLC_ENOMEM
;
440 /* defaults values */
441 p_sys
->psz_videodev
= var_InheritString( p_access
, "pvr-device" );
442 p_sys
->psz_radiodev
= var_InheritString( p_access
, "pvr-radio-device" );
443 p_sys
->i_standard
= var_InheritInteger( p_access
, "pvr-norm" );
444 p_sys
->i_width
= var_InheritInteger( p_access
, "pvr-width" );
445 p_sys
->i_height
= var_InheritInteger( p_access
, "pvr-height" );
446 p_sys
->i_frequency
= var_InheritInteger( p_access
, "pvr-frequency" );
447 p_sys
->i_framerate
= var_InheritInteger( p_access
, "pvr-framerate" );
448 p_sys
->i_keyint
= var_InheritInteger( p_access
, "pvr-keyint" );
449 p_sys
->i_bframes
= var_InheritInteger( p_access
, "pvr-bframes" );
450 p_sys
->i_bitrate
= var_InheritInteger( p_access
, "pvr-bitrate" );
451 p_sys
->i_bitrate_peak
= var_InheritInteger( p_access
, "pvr-bitrate-peak" );
452 p_sys
->i_bitrate_mode
= var_InheritInteger( p_access
, "pvr-bitrate-mode" );
453 p_sys
->i_audio_bitmask
= var_InheritInteger( p_access
, "pvr-audio-bitmask" );
454 p_sys
->i_volume
= var_InheritInteger( p_access
, "pvr-audio-volume" );
455 p_sys
->i_input
= var_InheritInteger( p_access
, "pvr-channel" );
457 /* parse command line options */
458 psz_tofree
= strdup( p_access
->psz_location
);
461 free( p_sys
->psz_radiodev
);
462 free( p_sys
->psz_videodev
);
467 psz_parser
= psz_tofree
;
470 /* Leading slash -> device path */
471 if( *psz_parser
== '/' )
473 free( p_sys
->psz_videodev
);
474 p_sys
->psz_videodev
= decode_URI_duplicate( psz_parser
);
478 /* Extract option name */
479 const char *optname
= psz_parser
;
480 psz_parser
= strchr( psz_parser
, '=' );
481 if( psz_parser
== NULL
)
483 *psz_parser
++ = '\0';
485 /* Extract option value */
486 char *optval
= psz_parser
;
487 while( memchr( ":,", *psz_parser
, 3 /* includes \0 */ ) == NULL
)
489 if( *psz_parser
) /* more options to come */
490 *psz_parser
++ = '\0'; /* skip , or : */
492 if ( !strcmp( optname
, "norm" ) )
494 if ( !strcmp( optval
, "secam" ) )
495 p_sys
->i_standard
= V4L2_STD_SECAM
;
496 else if ( !strcmp( optval
, "pal" ) )
497 p_sys
->i_standard
= V4L2_STD_PAL
;
498 else if ( !strcmp( optval
, "ntsc" ) )
499 p_sys
->i_standard
= V4L2_STD_NTSC
;
501 p_sys
->i_standard
= atoi( optval
);
503 else if( !strcmp( optname
, "channel" ) )
504 p_sys
->i_input
= atoi( optval
);
505 else if( !strcmp( optname
, "device" ) )
507 free( p_sys
->psz_videodev
);
508 if( asprintf( &p_sys
->psz_videodev
, "/dev/video%s", optval
) == -1)
509 p_sys
->psz_videodev
= NULL
;
511 else if( !strcmp( optname
, "frequency" ) )
512 p_sys
->i_frequency
= atoi( optval
);
513 else if( !strcmp( optname
, "framerate" ) )
514 p_sys
->i_framerate
= atoi( optval
);
515 else if( !strcmp( optname
, "keyint" ) )
516 p_sys
->i_keyint
= atoi( optval
);
517 else if( !strcmp( optname
, "bframes" ) )
518 p_sys
->i_bframes
= atoi( optval
);
519 else if( !strcmp( optname
, "width" ) )
520 p_sys
->i_width
= atoi( optval
);
521 else if( !strcmp( optname
, "height" ) )
522 p_sys
->i_height
= atoi( optval
);
523 else if( !strcmp( optname
, "audio" ) )
524 p_sys
->i_audio_bitmask
= atoi( optval
);
525 else if( !strcmp( optname
, "bitrate" ) )
526 p_sys
->i_bitrate
= atoi( optval
);
527 else if( !strcmp( optname
, "maxbitrate" ) )
528 p_sys
->i_bitrate_peak
= atoi( optval
);
529 else if( !strcmp( optname
, "bitratemode" ) )
531 if( !strcmp( optval
, "vbr" ) )
532 p_sys
->i_bitrate_mode
= 0;
533 else if( !strcmp( optval
, "cbr" ) )
534 p_sys
->i_bitrate_mode
= 1;
536 else if( !strcmp( optname
, "size" ) )
538 p_sys
->i_width
= strtol( optval
, &optval
, 0 );
539 p_sys
->i_height
= atoi( optval
);
544 /* open the device */
545 p_sys
->i_fd
= vlc_open( p_sys
->psz_videodev
, O_RDWR
);
546 if( p_sys
->i_fd
< 0 )
548 msg_Err( p_access
, "Cannot open device %s (%m).",
549 p_sys
->psz_videodev
);
550 Close( VLC_OBJECT(p_access
) );
553 msg_Dbg( p_access
, "Using video device: %s.", p_sys
->psz_videodev
);
555 /* See what version of ivtvdriver is running */
556 result
= ioctl( p_sys
->i_fd
, VIDIOC_QUERYCAP
, &device_capability
);
559 msg_Err( p_access
, "unknown ivtv/pvr driver version in use" );
560 Close( VLC_OBJECT(p_access
) );
564 msg_Dbg( p_access
, "%s driver (%s on %s) version %02x.%02x.%02x",
565 device_capability
.driver
,
566 device_capability
.card
,
567 device_capability
.bus_info
,
568 ( device_capability
.version
>> 16 ) & 0xff,
569 ( device_capability
.version
>> 8 ) & 0xff,
570 ( device_capability
.version
) & 0xff);
573 if ( p_sys
->i_input
!= -1 )
575 result
= ioctl( p_sys
->i_fd
, VIDIOC_S_INPUT
, &p_sys
->i_input
);
577 msg_Warn( p_access
, "Failed to select the requested input pin." );
579 msg_Dbg( p_access
, "input set to: %d", p_sys
->i_input
);
582 /* set the video standard */
583 if ( p_sys
->i_standard
!= V4L2_STD_UNKNOWN
)
585 result
= ioctl( p_sys
->i_fd
, VIDIOC_S_STD
, &p_sys
->i_standard
);
587 msg_Warn( p_access
, "Failed to set the requested video standard." );
589 msg_Dbg( p_access
, "video standard set to: %x",
593 /* set the picture size */
594 if ( (p_sys
->i_width
!= -1) || (p_sys
->i_height
!= -1) )
596 struct v4l2_format vfmt
;
598 memset( &vfmt
, 0, sizeof(struct v4l2_format
) );
599 vfmt
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
601 result
= ioctl( p_sys
->i_fd
, VIDIOC_G_FMT
, &vfmt
);
604 msg_Warn( p_access
, "Failed to read current picture size." );
608 if ( p_sys
->i_width
!= -1 )
610 vfmt
.fmt
.pix
.width
= p_sys
->i_width
;
613 if ( p_sys
->i_height
!= -1 )
615 vfmt
.fmt
.pix
.height
= p_sys
->i_height
;
618 result
= ioctl( p_sys
->i_fd
, VIDIOC_S_FMT
, &vfmt
);
621 msg_Warn( p_access
, "Failed to set requested picture size." );
625 msg_Dbg( p_access
, "picture size set to: %dx%d",
626 vfmt
.fmt
.pix
.width
, vfmt
.fmt
.pix
.height
);
631 /* set the frequency */
632 if ( p_sys
->i_frequency
!= -1 )
635 struct v4l2_tuner vt
;
637 /* TODO: let the user choose the tuner */
638 memset( &vt
, 0, sizeof(struct v4l2_tuner
) );
640 if ( (p_sys
->i_frequency
>= pi_radio_range
[0])
641 && (p_sys
->i_frequency
<= pi_radio_range
[1]) )
643 p_sys
->i_radio_fd
= vlc_open( p_sys
->psz_radiodev
, O_RDWR
);
644 if( p_sys
->i_radio_fd
< 0 )
646 msg_Err( p_access
, "Cannot open radio device (%m)." );
647 Close( VLC_OBJECT(p_access
) );
650 msg_Dbg( p_access
, "using radio device: %s",
651 p_sys
->psz_radiodev
);
652 i_fd
= p_sys
->i_radio_fd
;
657 p_sys
->i_radio_fd
= -1;
660 result
= ioctl( i_fd
, VIDIOC_G_TUNER
, &vt
);
663 msg_Warn( p_access
, "Failed to read tuner information (%m)." );
667 struct v4l2_frequency vf
;
669 memset( &vf
, 0, sizeof(struct v4l2_frequency
) );
672 result
= ioctl( i_fd
, VIDIOC_G_FREQUENCY
, &vf
);
675 msg_Warn( p_access
, "Failed to read tuner frequency (%m)." );
679 if( vt
.capability
& V4L2_TUNER_CAP_LOW
)
680 vf
.frequency
= p_sys
->i_frequency
* 16;
682 vf
.frequency
= (p_sys
->i_frequency
* 16 + 500) / 1000;
684 result
= ioctl( i_fd
, VIDIOC_S_FREQUENCY
, &vf
);
687 msg_Warn( p_access
, "Failed to set tuner frequency (%m)." );
691 msg_Dbg( p_access
, "tuner frequency set to: %d",
692 p_sys
->i_frequency
);
698 /* control parameters */
699 if ( p_sys
->i_volume
!= -1 )
701 struct v4l2_control ctrl
;
703 memset( &ctrl
, 0, sizeof(struct v4l2_control
) );
704 ctrl
.id
= V4L2_CID_AUDIO_VOLUME
;
705 ctrl
.value
= p_sys
->i_volume
;
707 result
= ioctl( p_sys
->i_fd
, VIDIOC_S_CTRL
, &ctrl
);
710 msg_Warn( p_access
, "Failed to set the volume." );
714 /* codec parameters */
715 if ( (p_sys
->i_framerate
!= -1)
716 || (p_sys
->i_bitrate_mode
!= -1)
717 || (p_sys
->i_bitrate_peak
!= -1)
718 || (p_sys
->i_keyint
!= -1)
719 || (p_sys
->i_bframes
!= -1)
720 || (p_sys
->i_bitrate
!= -1)
721 || (p_sys
->i_audio_bitmask
!= -1) )
723 result
= ConfigureV4L2( p_access
);
724 if( result
!= VLC_SUCCESS
)
726 Close( VLC_OBJECT(p_access
) );
734 /*****************************************************************************
735 * Close: close the device
736 *****************************************************************************/
737 static void Close( vlc_object_t
* p_this
)
739 access_t
*p_access
= (access_t
*) p_this
;
740 access_sys_t
*p_sys
= (access_sys_t
*) p_access
->p_sys
;
742 if ( p_sys
->i_fd
!= -1 )
743 close( p_sys
->i_fd
);
744 if ( p_sys
->i_radio_fd
!= -1 )
745 close( p_sys
->i_radio_fd
);
746 free( p_sys
->psz_videodev
);
747 free( p_sys
->psz_radiodev
);
751 /*****************************************************************************
753 *****************************************************************************/
754 static ssize_t
Read( access_t
* p_access
, uint8_t * p_buffer
, size_t i_len
)
756 access_sys_t
*p_sys
= (access_sys_t
*) p_access
->p_sys
;
759 if( p_access
->info
.b_eof
)
762 i_ret
= net_Read( p_access
, p_sys
->i_fd
, NULL
, p_buffer
, i_len
, false );
765 p_access
->info
.b_eof
= true;
769 p_access
->info
.i_pos
+= i_ret
;
775 /*****************************************************************************
777 *****************************************************************************/
778 static int Control( access_t
*p_access
, int i_query
, va_list args
)
786 case ACCESS_CAN_SEEK
:
787 case ACCESS_CAN_FASTSEEK
:
788 pb_bool
= (bool*)va_arg( args
, bool* );
791 case ACCESS_CAN_PAUSE
:
792 pb_bool
= (bool*)va_arg( args
, bool* );
795 case ACCESS_CAN_CONTROL_PACE
:
796 pb_bool
= (bool*)va_arg( args
, bool* );
801 case ACCESS_GET_PTS_DELAY
:
802 pi_64
= (int64_t*)va_arg( args
, int64_t * );
803 *pi_64
= INT64_C(1000)
804 * var_InheritInteger( p_access
, "live-caching" );
808 case ACCESS_SET_PAUSE_STATE
:
812 case ACCESS_GET_TITLE_INFO
:
813 case ACCESS_SET_TITLE
:
814 case ACCESS_SET_SEEKPOINT
:
815 case ACCESS_SET_PRIVATE_ID_STATE
:
816 case ACCESS_GET_CONTENT_TYPE
:
820 msg_Warn( p_access
, "Unimplemented query in control." );