1 /*****************************************************************************
2 * dshow.cpp : DirectShow access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002, 2003 the VideoLAN team
7 * Author: Gildas Bazin <gbazin@videolan.org>
8 * Damien Fouilleul <damienf@videolan.org>
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 *****************************************************************************/
33 #define __STDC_FORMAT_MACROS 1
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_input.h>
39 #include <vlc_access.h>
40 #include <vlc_demux.h>
42 #include <vlc_dialog.h>
43 #include <vlc_charset.h>
48 /*****************************************************************************
49 * Access: local prototypes
50 *****************************************************************************/
51 static block_t *ReadCompressed( access_t * );
52 static int AccessControl ( access_t *, int, va_list );
54 static int Demux ( demux_t * );
55 static int DemuxControl( demux_t *, int, va_list );
57 static int OpenDevice( vlc_object_t *, access_sys_t *, string, bool );
58 static IBaseFilter *FindCaptureDevice( vlc_object_t *, string *,
59 list<string> *, bool );
60 static size_t EnumDeviceCaps( vlc_object_t *, IBaseFilter *,
61 int, int, int, int, int, int,
62 AM_MEDIA_TYPE *mt, size_t );
63 static bool ConnectFilters( vlc_object_t *, access_sys_t *,
64 IBaseFilter *, CaptureFilter * );
65 static int FindDevicesCallback( vlc_object_t *, char const *,
66 vlc_value_t, vlc_value_t, void * );
67 static int ConfigDevicesCallback( vlc_object_t *, char const *,
68 vlc_value_t, vlc_value_t, void * );
70 static void ShowPropertyPage( IUnknown * );
71 static void ShowDeviceProperties( vlc_object_t *, ICaptureGraphBuilder2 *,
72 IBaseFilter *, bool );
73 static void ShowTunerProperties( vlc_object_t *, ICaptureGraphBuilder2 *,
74 IBaseFilter *, bool );
75 static void ConfigTuner( vlc_object_t *, ICaptureGraphBuilder2 *,
78 /*****************************************************************************
80 *****************************************************************************/
81 static const char *const ppsz_vdev[] = { "", "none" };
82 static const char *const ppsz_vdev_text[] = { N_("Default"), N_("None") };
83 static const char *const ppsz_adev[] = { "", "none" };
84 static const char *const ppsz_adev_text[] = { N_("Default"), N_("None") };
85 static const int pi_tuner_input[] = { 0, 1, 2 };
86 static const char *const ppsz_tuner_input_text[] =
87 {N_("Default"), N_("Cable"), N_("Antenna")};
88 static const int pi_amtuner_mode[] = { AMTUNER_MODE_DEFAULT,
90 AMTUNER_MODE_FM_RADIO,
91 AMTUNER_MODE_AM_RADIO,
93 static const char *const ppsz_amtuner_mode_text[] = { N_("Default"),
99 #define CACHING_TEXT N_("Caching value in ms")
100 #define CACHING_LONGTEXT N_( \
101 "Caching value for DirectShow streams. " \
102 "This value should be set in milliseconds." )
103 #define VDEV_TEXT N_("Video device name")
104 #define VDEV_LONGTEXT N_( \
105 "Name of the video device that will be used by the " \
106 "DirectShow plugin. If you don't specify anything, the default device " \
108 #define ADEV_TEXT N_("Audio device name")
109 #define ADEV_LONGTEXT N_( \
110 "Name of the audio device that will be used by the " \
111 "DirectShow plugin. If you don't specify anything, the default device " \
113 #define SIZE_TEXT N_("Video size")
114 #define SIZE_LONGTEXT N_( \
115 "Size of the video that will be displayed by the " \
116 "DirectShow plugin. If you don't specify anything the default size for " \
117 "your device will be used. You can specify a standard size (cif, d1, ...) or <width>x<height>.")
118 #define CHROMA_TEXT N_("Video input chroma format")
119 #define CHROMA_LONGTEXT N_( \
120 "Force the DirectShow video input to use a specific chroma format " \
121 "(eg. I420 (default), RV24, etc.)")
122 #define FPS_TEXT N_("Video input frame rate")
123 #define FPS_LONGTEXT N_( \
124 "Force the DirectShow video input to use a specific frame rate" \
125 "(eg. 0 means default, 25, 29.97, 50, 59.94, etc.)")
126 #define CONFIG_TEXT N_("Device properties")
127 #define CONFIG_LONGTEXT N_( \
128 "Show the properties dialog of the selected device before starting the " \
130 #define TUNER_TEXT N_("Tuner properties")
131 #define TUNER_LONGTEXT N_( \
132 "Show the tuner properties [channel selection] page." )
133 #define CHANNEL_TEXT N_("Tuner TV Channel")
134 #define CHANNEL_LONGTEXT N_( \
135 "Set the TV channel the tuner will set to " \
136 "(0 means default)." )
137 #define COUNTRY_TEXT N_("Tuner country code")
138 #define COUNTRY_LONGTEXT N_( \
139 "Set the tuner country code that establishes the current " \
140 "channel-to-frequency mapping (0 means default)." )
141 #define TUNER_INPUT_TEXT N_("Tuner input type")
142 #define TUNER_INPUT_LONGTEXT N_( \
143 "Select the tuner input type (Cable/Antenna)." )
144 #define VIDEO_IN_TEXT N_("Video input pin")
145 #define VIDEO_IN_LONGTEXT N_( \
146 "Select the video input source, such as composite, s-video, " \
147 "or tuner. Since these settings are hardware-specific, you should find good " \
148 "settings in the \"Device config\" area, and use those numbers here. -1 " \
149 "means that settings will not be changed.")
150 #define AUDIO_IN_TEXT N_("Audio input pin")
151 #define AUDIO_IN_LONGTEXT N_( \
152 "Select the audio input source. See the \"video input\" option." )
153 #define VIDEO_OUT_TEXT N_("Video output pin")
154 #define VIDEO_OUT_LONGTEXT N_( \
155 "Select the video output type. See the \"video input\" option." )
156 #define AUDIO_OUT_TEXT N_("Audio output pin")
157 #define AUDIO_OUT_LONGTEXT N_( \
158 "Select the audio output type. See the \"video input\" option." )
160 #define AMTUNER_MODE_TEXT N_("AM Tuner mode")
161 #define AMTUNER_MODE_LONGTEXT N_( \
162 "AM Tuner mode. Can be one of Default (0), TV (1)," \
163 "AM Radio (2), FM Radio (3) or DSS (4).")
165 #define AUDIO_CHANNELS_TEXT N_("Number of audio channels")
166 #define AUDIO_CHANNELS_LONGTEXT N_( \
167 "Select audio input format with the given number of audio channels (if non 0)" )
169 #define AUDIO_SAMPLERATE_TEXT N_("Audio sample rate")
170 #define AUDIO_SAMPLERATE_LONGTEXT N_( \
171 "Select audio input format with the given sample rate (if non 0)" )
173 #define AUDIO_BITSPERSAMPLE_TEXT N_("Audio bits per sample")
174 #define AUDIO_BITSPERSAMPLE_LONGTEXT N_( \
175 "Select audio input format with the given bits/sample (if non 0)" )
177 static int CommonOpen ( vlc_object_t *, access_sys_t *, bool );
178 static void CommonClose( vlc_object_t *, access_sys_t * );
180 static int AccessOpen ( vlc_object_t * );
181 static void AccessClose( vlc_object_t * );
183 static int DemuxOpen ( vlc_object_t * );
184 static void DemuxClose ( vlc_object_t * );
187 set_shortname( N_("DirectShow") )
188 set_description( N_("DirectShow input") )
189 set_category( CAT_INPUT )
190 set_subcategory( SUBCAT_INPUT_ACCESS )
191 add_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,
192 CACHING_TEXT, CACHING_LONGTEXT, true )
194 add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, false)
195 change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback )
196 change_action_add( FindDevicesCallback, N_("Refresh list") )
197 change_action_add( ConfigDevicesCallback, N_("Configure") )
199 add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, false)
200 change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback )
201 change_action_add( FindDevicesCallback, N_("Refresh list") )
202 change_action_add( ConfigDevicesCallback, N_("Configure") )
204 add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, false)
206 add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true )
208 add_float( "dshow-fps", 0.0f, NULL, FPS_TEXT, FPS_LONGTEXT, true )
210 add_bool( "dshow-config", false, NULL, CONFIG_TEXT, CONFIG_LONGTEXT, true )
212 add_bool( "dshow-tuner", false, NULL, TUNER_TEXT, TUNER_LONGTEXT, true )
214 add_integer( "dshow-tuner-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,
217 add_integer( "dshow-tuner-country", 0, NULL, COUNTRY_TEXT, COUNTRY_LONGTEXT,
220 add_integer( "dshow-tuner-input", 0, NULL, TUNER_INPUT_TEXT,
221 TUNER_INPUT_LONGTEXT, true )
222 change_integer_list( pi_tuner_input, ppsz_tuner_input_text, NULL )
224 add_integer( "dshow-video-input", -1, NULL, VIDEO_IN_TEXT,
225 VIDEO_IN_LONGTEXT, true )
227 add_integer( "dshow-video-output", -1, NULL, VIDEO_OUT_TEXT,
228 VIDEO_OUT_LONGTEXT, true )
230 add_integer( "dshow-audio-input", -1, NULL, AUDIO_IN_TEXT,
231 AUDIO_IN_LONGTEXT, true )
233 add_integer( "dshow-audio-output", -1, NULL, AUDIO_OUT_TEXT,
234 AUDIO_OUT_LONGTEXT, true )
236 add_integer( "dshow-amtuner-mode", AMTUNER_MODE_TV, NULL,
237 AMTUNER_MODE_TEXT, AMTUNER_MODE_LONGTEXT, false)
238 change_integer_list( pi_amtuner_mode, ppsz_amtuner_mode_text, NULL )
240 add_integer( "dshow-audio-channels", 0, NULL, AUDIO_CHANNELS_TEXT,
241 AUDIO_CHANNELS_LONGTEXT, true )
242 add_integer( "dshow-audio-samplerate", 0, NULL, AUDIO_SAMPLERATE_TEXT,
243 AUDIO_SAMPLERATE_LONGTEXT, true )
244 add_integer( "dshow-audio-bitspersample", 0, NULL, AUDIO_BITSPERSAMPLE_TEXT,
245 AUDIO_BITSPERSAMPLE_LONGTEXT, true )
247 add_shortcut( "dshow" )
248 set_capability( "access_demux", 0 )
249 set_callbacks( DemuxOpen, DemuxClose )
252 set_description( N_("DirectShow input") )
253 set_capability( "access", 0 )
254 set_callbacks( AccessOpen, AccessClose )
258 /*****************************************************************************
259 * DirectShow elementary stream descriptor
260 *****************************************************************************/
261 typedef struct dshow_stream_t
264 IBaseFilter *p_device_filter;
265 CaptureFilter *p_capture_filter;
270 VIDEOINFOHEADER video;
280 deque<VLCMediaSample> samples_queue;
283 /*****************************************************************************
284 * DirectShow utility functions
285 *****************************************************************************/
286 static void CreateDirectShowGraph( access_sys_t *p_sys )
288 p_sys->i_crossbar_route_depth = 0;
290 /* Create directshow filter graph */
291 if( SUCCEEDED( CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,
292 (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph) ) )
294 /* Create directshow capture graph builder if available */
295 if( SUCCEEDED( CoCreateInstance( CLSID_CaptureGraphBuilder2, 0,
296 CLSCTX_INPROC, (REFIID)IID_ICaptureGraphBuilder2,
297 (void **)&p_sys->p_capture_graph_builder2 ) ) )
299 p_sys->p_capture_graph_builder2->
300 SetFiltergraph((IGraphBuilder *)p_sys->p_graph);
303 p_sys->p_graph->QueryInterface( IID_IMediaControl,
304 (void **)&p_sys->p_control );
308 static void DeleteDirectShowGraph( access_sys_t *p_sys )
310 DeleteCrossbarRoutes( p_sys );
312 /* Remove filters from graph */
313 for( int i = 0; i < p_sys->i_streams; i++ )
315 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );
316 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );
317 p_sys->pp_streams[i]->p_capture_filter->Release();
318 p_sys->pp_streams[i]->p_device_filter->Release();
321 /* Release directshow objects */
322 if( p_sys->p_control )
324 p_sys->p_control->Release();
325 p_sys->p_control = NULL;
327 if( p_sys->p_capture_graph_builder2 )
329 p_sys->p_capture_graph_builder2->Release();
330 p_sys->p_capture_graph_builder2 = NULL;
335 p_sys->p_graph->Release();
336 p_sys->p_graph = NULL;
340 /*****************************************************************************
341 * CommonOpen: open direct show device
342 *****************************************************************************/
343 static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
344 bool b_access_demux )
349 /* Get/parse options and open device(s) */
350 string vdevname, adevname;
351 int i_width = 0, i_height = 0, i_chroma = 0;
352 bool b_use_audio = true;
353 bool b_use_video = true;
355 /* Initialize OLE/COM */
358 var_Create( p_this, "dshow-config", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
359 var_Create( p_this, "dshow-tuner", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
360 var_Create( p_this, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
361 var_Get( p_this, "dshow-vdev", &val );
364 msg_Dbg( p_this, "dshow-vdev: %s", val.psz_string ) ;
365 /* skip none device */
366 if ( strncasecmp( val.psz_string, "none", 4 ) != 0 )
367 vdevname = string( val.psz_string );
369 b_use_video = false ;
371 free( val.psz_string );
373 var_Create( p_this, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
374 var_Get( p_this, "dshow-adev", &val );
377 msg_Dbg( p_this, "dshow-adev: %s", val.psz_string ) ;
378 /* skip none device */
379 if ( strncasecmp( val.psz_string, "none", 4 ) != 0 )
380 adevname = string( val.psz_string );
382 b_use_audio = false ;
384 free( val.psz_string );
386 static struct {const char *psz_size; int i_width; int i_height;} size_table[] =
387 { { "subqcif", 128, 96 }, { "qsif", 160, 120 }, { "qcif", 176, 144 },
388 { "sif", 320, 240 }, { "cif", 352, 288 }, { "d1", 640, 480 },
392 var_Create( p_this, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
393 var_Get( p_this, "dshow-size", &val );
394 if( val.psz_string && *val.psz_string )
396 for( i = 0; size_table[i].psz_size; i++ )
398 if( !strcmp( val.psz_string, size_table[i].psz_size ) )
400 i_width = size_table[i].i_width;
401 i_height = size_table[i].i_height;
405 if( !size_table[i].psz_size ) /* Try to parse "WidthxHeight" */
408 i_width = strtol( val.psz_string, &psz_parser, 0 );
409 if( *psz_parser == 'x' || *psz_parser == 'X')
411 i_height = strtol( psz_parser + 1, &psz_parser, 0 );
413 msg_Dbg( p_this, "width x height %dx%d", i_width, i_height );
416 free( val.psz_string );
418 p_sys->b_chroma = false;
419 var_Create( p_this, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
420 var_Get( p_this, "dshow-chroma", &val );
421 if( val.psz_string && strlen( val.psz_string ) >= 4 )
423 i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],
424 val.psz_string[2], val.psz_string[3] );
425 p_sys->b_chroma = true;
427 free( val.psz_string );
429 var_Create( p_this, "dshow-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
430 var_Create( p_this, "dshow-tuner-channel",
431 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
432 var_Create( p_this, "dshow-tuner-country",
433 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
434 var_Create( p_this, "dshow-tuner-input",
435 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
437 var_Create( p_this, "dshow-amtuner-mode",
438 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
440 var_Create( p_this, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
442 var_Create( p_this, "dshow-video-input", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
443 var_Create( p_this, "dshow-audio-input", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
444 var_Create( p_this, "dshow-video-output", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
445 var_Create( p_this, "dshow-audio-output", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
447 /* Initialize some data */
448 p_sys->i_streams = 0;
449 p_sys->pp_streams = NULL;
450 p_sys->i_width = i_width;
451 p_sys->i_height = i_height;
452 p_sys->i_chroma = i_chroma;
454 p_sys->p_graph = NULL;
455 p_sys->p_capture_graph_builder2 = NULL;
456 p_sys->p_control = NULL;
458 /* Build directshow graph */
459 CreateDirectShowGraph( p_sys );
461 vlc_mutex_init( &p_sys->lock );
462 vlc_cond_init( &p_sys->wait );
464 if( !b_use_video && !b_use_audio )
466 dialog_Fatal( p_this, _("Capture failed"),
467 _("No video or audio device selected.") );
468 return VLC_EGENERIC ;
472 msg_Dbg( p_this, "skipping video device" ) ;
473 bool b_err_video = false ;
475 if( b_use_video && OpenDevice( p_this, p_sys, vdevname, 0 ) != VLC_SUCCESS )
477 msg_Err( p_this, "can't open video device");
481 if ( b_use_video && !b_err_video )
483 /* Check if we can handle the demuxing ourselves or need to spawn
484 * a demuxer module */
485 dshow_stream_t *p_stream = p_sys->pp_streams[p_sys->i_streams-1];
487 if( p_stream->mt.majortype == MEDIATYPE_Video )
489 if( /* Raw DV stream */
490 p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
491 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
492 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') ||
493 /* Raw MPEG video stream */
494 p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
500 /* Let the access (only) take care of that */
506 if( p_stream->mt.majortype == MEDIATYPE_Stream )
512 /* Let the access (only) take care of that */
516 var_Get( p_this, "dshow-tuner", &val );
519 /* FIXME: we do MEDIATYPE_Stream here so we don't do
521 ShowTunerProperties( p_this, p_sys->p_capture_graph_builder2,
522 p_stream->p_device_filter, 0 );
528 msg_Dbg( p_this, "skipping audio device") ;
530 bool b_err_audio = false ;
532 if( b_use_audio && OpenDevice( p_this, p_sys, adevname, 1 ) != VLC_SUCCESS )
534 msg_Err( p_this, "can't open audio device");
538 if( ( b_use_video && b_err_video && b_use_audio && b_err_audio ) ||
539 ( !b_use_video && b_use_audio && b_err_audio ) ||
540 ( b_use_video && !b_use_audio && b_err_video ) )
542 msg_Err( p_this, "FATAL: could not open ANY device" ) ;
543 dialog_Fatal( p_this, _("Capture failed"),
544 _("VLC cannot open ANY capture device."
545 "Check the error log for details.") );
546 return VLC_EGENERIC ;
549 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
551 var_Get( p_this, "dshow-video-input", &val );
553 p_sys->crossbar_routes[i].VideoInputIndex=val.i_int;
554 var_Get( p_this, "dshow-video-output", &val );
556 p_sys->crossbar_routes[i].VideoOutputIndex=val.i_int;
557 var_Get( p_this, "dshow-audio-input", &val );
559 p_sys->crossbar_routes[i].AudioInputIndex=val.i_int;
560 var_Get( p_this, "dshow-audio-output", &val );
562 p_sys->crossbar_routes[i].AudioOutputIndex=val.i_int;
564 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
565 LONG VideoInputIndex = p_sys->crossbar_routes[i].VideoInputIndex;
566 LONG VideoOutputIndex = p_sys->crossbar_routes[i].VideoOutputIndex;
567 LONG AudioInputIndex = p_sys->crossbar_routes[i].AudioInputIndex;
568 LONG AudioOutputIndex = p_sys->crossbar_routes[i].AudioOutputIndex;
570 if( SUCCEEDED(pXbar->Route(VideoOutputIndex, VideoInputIndex)) )
572 msg_Dbg( p_this, "crossbar at depth %d, routed video "
573 "output %ld to video input %ld", i, VideoOutputIndex,
576 if( AudioOutputIndex != -1 && AudioInputIndex != -1 )
578 if( SUCCEEDED( pXbar->Route(AudioOutputIndex,
581 msg_Dbg(p_this, "crossbar at depth %d, routed audio "
582 "output %ld to audio input %ld", i,
583 AudioOutputIndex, AudioInputIndex );
588 msg_Err( p_this, "crossbar at depth %d could not route video "
589 "output %ld to input %ld", i, VideoOutputIndex, VideoInputIndex );
593 ** Show properties pages from other filters in graph
595 var_Get( p_this, "dshow-config", &val );
598 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
600 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
603 if( SUCCEEDED( pXbar->QueryInterface( IID_IBaseFilter,
606 ShowPropertyPage( p_XF );
612 /* Initialize some data */
613 p_sys->i_current_stream = 0;
615 if( !p_sys->i_streams ) return VLC_EGENERIC;
620 /*****************************************************************************
621 * DemuxOpen: open direct show device as an access_demux module
622 *****************************************************************************/
623 static int DemuxOpen( vlc_object_t *p_this )
625 demux_t *p_demux = (demux_t *)p_this;
629 p_sys = (access_sys_t*)calloc( 1, sizeof( access_sys_t ) );
632 p_demux->p_sys = (demux_sys_t *)p_sys;
634 if( CommonOpen( p_this, p_sys, true ) != VLC_SUCCESS )
636 CommonClose( p_this, p_sys );
640 /* Everything is ready. Let's rock baby */
641 msg_Dbg( p_this, "Playing...");
642 p_sys->p_control->Run();
644 p_demux->pf_demux = Demux;
645 p_demux->pf_control = DemuxControl;
646 p_demux->info.i_update = 0;
647 p_demux->info.i_title = 0;
648 p_demux->info.i_seekpoint = 0;
650 for( i = 0; i < p_sys->i_streams; i++ )
652 dshow_stream_t *p_stream = p_sys->pp_streams[i];
655 if( p_stream->mt.majortype == MEDIATYPE_Video )
657 es_format_Init( &fmt, VIDEO_ES, p_stream->i_fourcc );
659 fmt.video.i_width = p_stream->header.video.bmiHeader.biWidth;
660 fmt.video.i_height = p_stream->header.video.bmiHeader.biHeight;
661 fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
663 if( !p_stream->header.video.bmiHeader.biCompression )
665 /* RGB DIB are coded from bottom to top */
666 fmt.video.i_height = (unsigned int)(-(int)fmt.video.i_height);
669 /* Setup rgb mask for RGB formats */
670 if( p_stream->i_fourcc == VLC_FOURCC('R','V','2','4') )
672 /* This is in BGR format */
673 fmt.video.i_bmask = 0x00ff0000;
674 fmt.video.i_gmask = 0x0000ff00;
675 fmt.video.i_rmask = 0x000000ff;
678 if( p_stream->header.video.AvgTimePerFrame )
680 fmt.video.i_frame_rate = 10000000;
681 fmt.video.i_frame_rate_base =
682 p_stream->header.video.AvgTimePerFrame;
685 else if( p_stream->mt.majortype == MEDIATYPE_Audio )
687 es_format_Init( &fmt, AUDIO_ES, p_stream->i_fourcc );
689 fmt.audio.i_channels = p_stream->header.audio.nChannels;
690 fmt.audio.i_rate = p_stream->header.audio.nSamplesPerSec;
691 fmt.audio.i_bitspersample = p_stream->header.audio.wBitsPerSample;
692 fmt.audio.i_blockalign = fmt.audio.i_channels *
693 fmt.audio.i_bitspersample / 8;
694 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
695 fmt.audio.i_bitspersample;
698 p_stream->p_es = es_out_Add( p_demux->out, &fmt );
704 /*****************************************************************************
705 * AccessOpen: open direct show device as an access module
706 *****************************************************************************/
707 static int AccessOpen( vlc_object_t *p_this )
709 access_t *p_access = (access_t*)p_this;
712 p_access->p_sys = p_sys = (access_sys_t*)calloc( 1, sizeof( access_sys_t ) );
716 if( CommonOpen( p_this, p_sys, false ) != VLC_SUCCESS )
718 CommonClose( p_this, p_sys );
722 dshow_stream_t *p_stream = p_sys->pp_streams[0];
724 /* Check if we need to force demuxers */
725 if( !p_access->psz_demux || !*p_access->psz_demux )
727 if( p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
728 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
729 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') )
731 free( p_access->psz_demux );
732 p_access->psz_demux = strdup( "rawdv" );
734 else if( p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
736 free( p_access->psz_demux );
737 p_access->psz_demux = strdup( "mpgv" );
742 p_access->pf_read = NULL;
743 p_access->pf_block = ReadCompressed;
744 p_access->pf_control = AccessControl;
745 p_access->pf_seek = NULL;
746 p_access->info.i_update = 0;
747 p_access->info.i_size = 0;
748 p_access->info.i_pos = 0;
749 p_access->info.b_eof = false;
750 p_access->info.i_title = 0;
751 p_access->info.i_seekpoint = 0;
752 p_access->p_sys = p_sys;
754 /* Everything is ready. Let's rock baby */
755 msg_Dbg( p_this, "Playing...");
756 p_sys->p_control->Run();
761 /*****************************************************************************
762 * CommonClose: close device
763 *****************************************************************************/
764 static void CommonClose( vlc_object_t *p_this, access_sys_t *p_sys )
766 msg_Dbg( p_this, "releasing DirectShow");
768 DeleteDirectShowGraph( p_sys );
770 /* Uninitialize OLE/COM */
773 for( int i = 0; i < p_sys->i_streams; i++ ) delete p_sys->pp_streams[i];
774 if( p_sys->i_streams ) free( p_sys->pp_streams );
776 vlc_mutex_destroy( &p_sys->lock );
777 vlc_cond_destroy( &p_sys->wait );
782 /*****************************************************************************
783 * AccessClose: close device
784 *****************************************************************************/
785 static void AccessClose( vlc_object_t *p_this )
787 access_t *p_access = (access_t *)p_this;
788 access_sys_t *p_sys = p_access->p_sys;
790 /* Stop capturing stuff */
791 p_sys->p_control->Stop();
793 CommonClose( p_this, p_sys );
796 /*****************************************************************************
797 * DemuxClose: close device
798 *****************************************************************************/
799 static void DemuxClose( vlc_object_t *p_this )
801 demux_t *p_demux = (demux_t *)p_this;
802 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
804 /* Stop capturing stuff */
805 p_sys->p_control->Stop();
807 CommonClose( p_this, p_sys );
810 /****************************************************************************
812 ****************************************************************************/
813 static bool ConnectFilters( vlc_object_t *p_this, access_sys_t *p_sys,
814 IBaseFilter *p_filter,
815 CaptureFilter *p_capture_filter )
817 CapturePin *p_input_pin = p_capture_filter->CustomGetPin();
819 AM_MEDIA_TYPE mediaType = p_input_pin->CustomGetMediaType();
821 if( p_sys->p_capture_graph_builder2 )
823 if( FAILED(p_sys->p_capture_graph_builder2->
824 RenderStream( &PIN_CATEGORY_CAPTURE, &mediaType.majortype,
825 p_filter, 0, (IBaseFilter *)p_capture_filter )) )
830 // Sort out all the possible video inputs
831 // The class needs to be given the capture filters ANALOGVIDEO input pin
832 IEnumPins *pins = NULL;
833 if( ( mediaType.majortype == MEDIATYPE_Video ||
834 mediaType.majortype == MEDIATYPE_Stream ) &&
835 SUCCEEDED(p_filter->EnumPins(&pins)) )
841 IKsPropertySet *pKs = NULL;
845 while( !Found && ( S_OK == pins->Next(1, &pP, &n) ) )
847 if( S_OK == pP->QueryPinInfo(&pinInfo) )
849 // is this pin an ANALOGVIDEOIN input pin?
850 if( pinInfo.dir == PINDIR_INPUT &&
851 pP->QueryInterface( IID_IKsPropertySet,
852 (void **)&pKs ) == S_OK )
854 if( pKs->Get( AMPROPSETID_Pin,
855 AMPROPERTY_PIN_CATEGORY, NULL, 0,
856 &guid, sizeof(GUID), &dw ) == S_OK )
858 if( guid == PIN_CATEGORY_ANALOGVIDEOIN )
860 // recursively search crossbar routes
861 FindCrossbarRoutes( p_this, p_sys, pP, 0 );
868 pinInfo.pFilter->Release();
873 msg_Dbg( p_this, "ConnectFilters: graph_builder2 available.") ;
875 msg_Warn( p_this, "ConnectFilters: No crossBar routes found (incobatible pin types)" ) ;
881 IEnumPins *p_enumpins;
884 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
886 while( S_OK == p_enumpins->Next( 1, &p_pin, NULL ) )
888 PIN_DIRECTION pin_dir;
889 p_pin->QueryDirection( &pin_dir );
891 if( pin_dir == PINDIR_OUTPUT &&
892 p_sys->p_graph->ConnectDirect( p_pin, (IPin *)p_input_pin,
896 p_enumpins->Release();
902 p_enumpins->Release();
908 * get fourcc priority from arbritary preference, the higher the better
910 static int GetFourCCPriority( int i_fourcc )
914 case VLC_FOURCC('I','4','2','0'):
915 case VLC_FOURCC('f','l','3','2'):
917 case VLC_FOURCC('Y','V','1','2'):
918 case VLC_FOURCC('a','r','a','w'):
920 case VLC_FOURCC('R','V','2','4'):
922 case VLC_FOURCC('Y','U','Y','2'):
923 case VLC_FOURCC('R','V','3','2'):
924 case VLC_FOURCC('R','G','B','A'):
931 #define MAX_MEDIA_TYPES 32
933 static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
934 string devicename, bool b_audio )
936 /* See if device is already opened */
937 for( int i = 0; i < p_sys->i_streams; i++ )
939 if( devicename.size() &&
940 p_sys->pp_streams[i]->devicename == devicename )
947 list<string> list_devices;
949 /* Enumerate devices and display their names */
950 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
951 if( !list_devices.size() )
954 list<string>::iterator iter;
955 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
956 msg_Dbg( p_this, "found device: %s", iter->c_str() );
958 /* If no device name was specified, pick the 1st one */
959 if( devicename.size() == 0 )
961 /* When none selected */
962 devicename = *list_devices.begin();
963 msg_Dbg( p_this, "asking for default device: %s", devicename.c_str() ) ;
966 msg_Dbg( p_this, "asking for device: %s", devicename.c_str() ) ;
967 // Use the system device enumerator and class enumerator to find
968 // a capture/preview device, such as a desktop USB video camera.
969 IBaseFilter *p_device_filter =
970 FindCaptureDevice( p_this, &devicename, NULL, b_audio );
972 if( p_device_filter )
973 msg_Dbg( p_this, "using device: %s", devicename.c_str() );
976 msg_Err( p_this, "can't use device: %s, unsupported device type",
977 devicename.c_str() );
978 dialog_Fatal( p_this, _("Capture failed"),
979 _("VLC cannot use the device \"%s\", because its "
980 "type is not supported."), devicename.c_str() );
984 // Retreive acceptable media types supported by device
985 AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
987 EnumDeviceCaps( p_this, p_device_filter, b_audio ? 0 : p_sys->i_chroma,
988 p_sys->i_width, p_sys->i_height,
989 b_audio ? var_CreateGetInteger( p_this, "dshow-audio-channels" ) : 0,
990 b_audio ? var_CreateGetInteger( p_this, "dshow-audio-samplerate" ) : 0,
991 b_audio ? var_CreateGetInteger( p_this, "dshow-audio-bitspersample" ) : 0,
992 media_types, MAX_MEDIA_TYPES );
994 AM_MEDIA_TYPE *mt = NULL;
996 if( media_count > 0 )
998 mt = (AM_MEDIA_TYPE *)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * media_count);
1000 // Order and copy returned media types according to arbitrary
1002 for( size_t c = 0; c < media_count; c++ )
1005 GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
1006 size_t slot_copy = c;
1007 for( size_t d = c+1; d < media_count; d++ )
1010 GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
1011 if( priority > slot_priority )
1013 slot_priority = priority;
1017 if( slot_copy != c )
1019 mt[c] = media_types[slot_copy];
1020 media_types[slot_copy] = media_types[c];
1024 mt[c] = media_types[c];
1029 /* capture device */
1030 msg_Err( p_this, "capture device '%s' does not support required parameters !", devicename.c_str() );
1031 dialog_Fatal( p_this, _("Capture failed"),
1032 _("The capture device \"%s\" does not support the "
1033 "required parameters."), devicename.c_str() );
1034 p_device_filter->Release();
1035 return VLC_EGENERIC;
1038 /* Create and add our capture filter */
1039 CaptureFilter *p_capture_filter =
1040 new CaptureFilter( p_this, p_sys, mt, media_count );
1041 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
1043 /* Add the device filter to the graph (seems necessary with VfW before
1044 * accessing pin attributes). */
1045 p_sys->p_graph->AddFilter( p_device_filter, 0 );
1047 /* Attempt to connect one of this device's capture output pins */
1048 msg_Dbg( p_this, "connecting filters" );
1049 if( ConnectFilters( p_this, p_sys, p_device_filter, p_capture_filter ) )
1052 msg_Dbg( p_this, "filters connected successfully !" );
1054 dshow_stream_t dshow_stream;
1055 dshow_stream.b_pts = false;
1056 dshow_stream.p_es = 0;
1058 p_capture_filter->CustomGetPin()->CustomGetMediaType();
1060 /* Show Device properties. Done here so the VLC stream is setup with
1061 * the proper parameters. */
1063 var_Get( p_this, "dshow-config", &val );
1066 ShowDeviceProperties( p_this, p_sys->p_capture_graph_builder2,
1067 p_device_filter, b_audio );
1070 ConfigTuner( p_this, p_sys->p_capture_graph_builder2,
1073 var_Get( p_this, "dshow-tuner", &val );
1074 if( val.b_bool && dshow_stream.mt.majortype != MEDIATYPE_Stream )
1076 /* FIXME: we do MEDIATYPE_Stream later so we don't do it twice. */
1077 ShowTunerProperties( p_this, p_sys->p_capture_graph_builder2,
1078 p_device_filter, b_audio );
1082 p_capture_filter->CustomGetPin()->CustomGetMediaType();
1084 dshow_stream.i_fourcc = GetFourCCFromMediaType( dshow_stream.mt );
1085 if( dshow_stream.i_fourcc )
1087 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
1089 dshow_stream.header.video =
1090 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
1091 msg_Dbg( p_this, "MEDIATYPE_Video" );
1092 msg_Dbg( p_this, "selected video pin accepts format: %4.4s",
1093 (char *)&dshow_stream.i_fourcc);
1095 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio )
1097 dshow_stream.header.audio =
1098 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
1099 msg_Dbg( p_this, "MEDIATYPE_Audio" );
1100 msg_Dbg( p_this, "selected audio pin accepts format: %4.4s",
1101 (char *)&dshow_stream.i_fourcc);
1103 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
1105 msg_Dbg( p_this, "MEDIATYPE_Stream" );
1106 msg_Dbg( p_this, "selected stream pin accepts format: %4.4s",
1107 (char *)&dshow_stream.i_fourcc);
1111 msg_Dbg( p_this, "unknown stream majortype" );
1115 /* Add directshow elementary stream to our list */
1116 dshow_stream.p_device_filter = p_device_filter;
1117 dshow_stream.p_capture_filter = p_capture_filter;
1119 p_sys->pp_streams = (dshow_stream_t **)realloc( p_sys->pp_streams,
1120 sizeof(dshow_stream_t *) * (p_sys->i_streams + 1) );
1121 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
1122 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
1129 /* Remove filters from graph */
1130 p_sys->p_graph->RemoveFilter( p_device_filter );
1131 p_sys->p_graph->RemoveFilter( p_capture_filter );
1133 /* Release objects */
1134 p_device_filter->Release();
1135 p_capture_filter->Release();
1137 return VLC_EGENERIC;
1140 /* FindCaptureDevices:: This Function had two purposes :
1141 Returns the list of capture devices when p_listdevices != NULL
1142 Creates an IBaseFilter when p_devicename corresponds to an existing devname
1143 These actions *may* be requested whith a single call.
1145 static IBaseFilter *
1146 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
1147 list<string> *p_listdevices, bool b_audio )
1149 IBaseFilter *p_base_filter = NULL;
1150 IMoniker *p_moniker = NULL;
1153 list<string> devicelist;
1155 /* Create the system device enumerator */
1156 ICreateDevEnum *p_dev_enum = NULL;
1158 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
1159 IID_ICreateDevEnum, (void **)&p_dev_enum );
1162 msg_Err( p_this, "failed to create the device enumerator (0x%lx)", hr);
1166 /* Create an enumerator for the video capture devices */
1167 IEnumMoniker *p_class_enum = NULL;
1169 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
1172 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
1174 p_dev_enum->Release();
1177 msg_Err( p_this, "failed to create the class enumerator (0x%lx)", hr );
1181 /* If there are no enumerators for the requested type, then
1182 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
1183 if( p_class_enum == NULL )
1185 msg_Err( p_this, "no %s capture device was detected", ( b_audio ? "audio" : "video" ) );
1189 /* Enumerate the devices */
1191 /* Note that if the Next() call succeeds but there are no monikers,
1192 * it will return S_FALSE (which is not a failure). Therefore, we check
1193 * that the return code is S_OK instead of using SUCCEEDED() macro. */
1195 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
1197 /* Getting the property page to get the device name */
1198 IPropertyBag *p_bag;
1199 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
1205 hr = p_bag->Read( L"FriendlyName", &var, NULL );
1209 char *p_buf = FromWide( var.bstrVal );
1210 string devname = string(p_buf);
1214 /* find out if this name is already used by a previously found device */
1215 list<string>::const_iterator iter = devicelist.begin();
1216 list<string>::const_iterator end = devicelist.end();
1217 string ordevname = devname ;
1218 while ( iter != end )
1220 if( 0 == (*iter).compare( devname ) )
1221 { /* devname is on the list. Try another name with sequence
1222 number apended and then rescan until a unique entry is found*/
1224 snprintf(seq, 16, " #%d", ++dup);
1225 devname = ordevname + seq;
1226 iter = devicelist.begin();
1231 devicelist.push_back( devname );
1233 if( p_devicename && *p_devicename == devname )
1235 msg_Dbg( p_this, "asked for %s, binding to %s", p_devicename->c_str() , devname.c_str() ) ;
1236 /* NULL possibly means we don't need BindMoniker BindCtx ?? */
1237 hr = p_moniker->BindToObject( NULL, 0, IID_IBaseFilter,
1238 (void **)&p_base_filter );
1241 msg_Err( p_this, "couldn't bind moniker to filter "
1242 "object (0x%lx)", hr );
1243 p_moniker->Release();
1244 p_class_enum->Release();
1247 p_moniker->Release();
1248 p_class_enum->Release();
1249 return p_base_filter;
1254 p_moniker->Release();
1257 p_class_enum->Release();
1259 if( p_listdevices ) {
1261 *p_listdevices = devicelist;
1266 static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
1267 int i_fourcc, int i_width, int i_height,
1268 int i_channels, int i_samplespersec,
1269 int i_bitspersample, AM_MEDIA_TYPE *mt,
1272 IEnumPins *p_enumpins;
1274 IEnumMediaTypes *p_enummt;
1275 size_t mt_count = 0;
1277 LONGLONG i_AvgTimePerFrame = 0;
1278 float r_fps = var_GetFloat( p_this, "dshow-fps" );
1280 i_AvgTimePerFrame = 10000000000LL/(LONGLONG)(r_fps*1000.0f);
1282 if( FAILED(p_filter->EnumPins( &p_enumpins )) )
1284 msg_Dbg( p_this, "EnumDeviceCaps failed: no pin enumeration !");
1288 while( S_OK == p_enumpins->Next( 1, &p_output_pin, NULL ) )
1292 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1294 msg_Dbg( p_this, "EnumDeviceCaps: %s pin: %S",
1295 info.dir == PINDIR_INPUT ? "input" : "output",
1297 if( info.pFilter ) info.pFilter->Release();
1300 p_output_pin->Release();
1303 p_enumpins->Reset();
1305 while( !mt_count && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
1309 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1311 if( info.pFilter ) info.pFilter->Release();
1312 if( info.dir == PINDIR_INPUT )
1314 p_output_pin->Release();
1317 msg_Dbg( p_this, "EnumDeviceCaps: trying pin %S", info.achName );
1320 AM_MEDIA_TYPE *p_mt;
1323 ** Configure pin with a default compatible media if possible
1326 IAMStreamConfig *pSC;
1327 if( SUCCEEDED(p_output_pin->QueryInterface( IID_IAMStreamConfig,
1330 int piCount, piSize;
1331 if( SUCCEEDED(pSC->GetNumberOfCapabilities(&piCount, &piSize)) )
1333 BYTE *pSCC= (BYTE *)CoTaskMemAlloc(piSize);
1336 int i_priority = -1;
1337 for( int i=0; i<piCount; ++i )
1339 if( SUCCEEDED(pSC->GetStreamCaps(i, &p_mt, pSCC)) )
1341 int i_current_fourcc = GetFourCCFromMediaType( *p_mt );
1342 int i_current_priority = GetFourCCPriority(i_current_fourcc);
1344 if( (i_fourcc && (i_current_fourcc != i_fourcc))
1345 || (i_priority > i_current_priority) )
1347 // unwanted chroma, try next media type
1348 FreeMediaType( *p_mt );
1349 CoTaskMemFree( (PVOID)p_mt );
1353 if( MEDIATYPE_Video == p_mt->majortype
1354 && FORMAT_VideoInfo == p_mt->formattype )
1356 VIDEO_STREAM_CONFIG_CAPS *pVSCC = reinterpret_cast<VIDEO_STREAM_CONFIG_CAPS*>(pSCC);
1357 VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(p_mt->pbFormat);
1359 if( i_AvgTimePerFrame )
1361 if( pVSCC->MinFrameInterval > i_AvgTimePerFrame
1362 || i_AvgTimePerFrame > pVSCC->MaxFrameInterval )
1364 // required frame rate not compatible, try next media type
1365 FreeMediaType( *p_mt );
1366 CoTaskMemFree( (PVOID)p_mt );
1369 pVih->AvgTimePerFrame = i_AvgTimePerFrame;
1374 if(( !pVSCC->OutputGranularityX
1375 && i_width != pVSCC->MinOutputSize.cx
1376 && i_width != pVSCC->MaxOutputSize.cx)
1378 ( pVSCC->OutputGranularityX
1379 && ((i_width % pVSCC->OutputGranularityX)
1380 || pVSCC->MinOutputSize.cx > i_width
1381 || i_width > pVSCC->MaxOutputSize.cx )))
1383 // required width not compatible, try next media type
1384 FreeMediaType( *p_mt );
1385 CoTaskMemFree( (PVOID)p_mt );
1388 pVih->bmiHeader.biWidth = i_width;
1393 if(( !pVSCC->OutputGranularityY
1394 && i_height != pVSCC->MinOutputSize.cy
1395 && i_height != pVSCC->MaxOutputSize.cy)
1397 ( pVSCC->OutputGranularityY
1398 && ((i_height % pVSCC->OutputGranularityY)
1399 || pVSCC->MinOutputSize.cy > i_height
1400 || i_height > pVSCC->MaxOutputSize.cy )))
1402 // required height not compatible, try next media type
1403 FreeMediaType( *p_mt );
1404 CoTaskMemFree( (PVOID)p_mt );
1407 pVih->bmiHeader.biHeight = i_height;
1410 // Set the sample size and image size.
1411 // (Round the image width up to a DWORD boundary.)
1412 p_mt->lSampleSize = pVih->bmiHeader.biSizeImage =
1413 ((pVih->bmiHeader.biWidth + 3) & ~3) *
1414 pVih->bmiHeader.biHeight * (pVih->bmiHeader.biBitCount>>3);
1416 // no cropping, use full video input buffer
1417 memset(&(pVih->rcSource), 0, sizeof(RECT));
1418 memset(&(pVih->rcTarget), 0, sizeof(RECT));
1420 // select this format as default
1421 if( SUCCEEDED( pSC->SetFormat(p_mt) ) )
1423 i_priority = i_current_priority;
1425 // no need to check any more media types
1429 else if( p_mt->majortype == MEDIATYPE_Audio
1430 && p_mt->formattype == FORMAT_WaveFormatEx )
1432 AUDIO_STREAM_CONFIG_CAPS *pASCC = reinterpret_cast<AUDIO_STREAM_CONFIG_CAPS*>(pSCC);
1433 WAVEFORMATEX *pWfx = reinterpret_cast<WAVEFORMATEX*>(p_mt->pbFormat);
1435 if( i_current_fourcc && (WAVE_FORMAT_PCM == pWfx->wFormatTag) )
1437 int val = i_channels;
1441 if( ( !pASCC->ChannelsGranularity
1442 && (unsigned int)val != pASCC->MinimumChannels
1443 && (unsigned int)val != pASCC->MaximumChannels)
1445 ( pASCC->ChannelsGranularity
1446 && ((val % pASCC->ChannelsGranularity)
1447 || (unsigned int)val < pASCC->MinimumChannels
1448 || (unsigned int)val > pASCC->MaximumChannels)))
1450 // required number channels not available, try next media type
1451 FreeMediaType( *p_mt );
1452 CoTaskMemFree( (PVOID)p_mt );
1455 pWfx->nChannels = val;
1457 val = i_samplespersec;
1461 if( ( !pASCC->SampleFrequencyGranularity
1462 && (unsigned int)val != pASCC->MinimumSampleFrequency
1463 && (unsigned int)val != pASCC->MaximumSampleFrequency)
1465 ( pASCC->SampleFrequencyGranularity
1466 && ((val % pASCC->SampleFrequencyGranularity)
1467 || (unsigned int)val < pASCC->MinimumSampleFrequency
1468 || (unsigned int)val > pASCC->MaximumSampleFrequency )))
1470 // required sampling rate not available, try next media type
1471 FreeMediaType( *p_mt );
1472 CoTaskMemFree( (PVOID)p_mt );
1475 pWfx->nSamplesPerSec = val;
1477 val = i_bitspersample;
1480 if( VLC_FOURCC('f', 'l', '3', '2') == i_current_fourcc )
1486 if( ( !pASCC->BitsPerSampleGranularity
1487 && (unsigned int)val != pASCC->MinimumBitsPerSample
1488 && (unsigned int)val != pASCC->MaximumBitsPerSample )
1490 ( pASCC->BitsPerSampleGranularity
1491 && ((val % pASCC->BitsPerSampleGranularity)
1492 || (unsigned int)val < pASCC->MinimumBitsPerSample
1493 || (unsigned int)val > pASCC->MaximumBitsPerSample )))
1495 // required sample size not available, try next media type
1496 FreeMediaType( *p_mt );
1497 CoTaskMemFree( (PVOID)p_mt );
1501 pWfx->wBitsPerSample = val;
1502 pWfx->nBlockAlign = (pWfx->wBitsPerSample * pWfx->nChannels)/8;
1503 pWfx->nAvgBytesPerSec = pWfx->nSamplesPerSec * pWfx->nBlockAlign;
1505 // select this format as default
1506 if( SUCCEEDED( pSC->SetFormat(p_mt) ) )
1508 i_priority = i_current_priority;
1512 FreeMediaType( *p_mt );
1513 CoTaskMemFree( (PVOID)p_mt );
1516 CoTaskMemFree( (LPVOID)pSCC );
1517 if( i_priority >= 0 )
1518 msg_Dbg( p_this, "EnumDeviceCaps: input pin default format configured");
1525 ** Probe pin for available medias (may be a previously configured one)
1528 if( FAILED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
1530 p_output_pin->Release();
1534 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
1536 int i_current_fourcc = GetFourCCFromMediaType( *p_mt );
1537 if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Video
1538 && p_mt->formattype == FORMAT_VideoInfo )
1540 int i_current_width = ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth;
1541 int i_current_height = ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight;
1542 LONGLONG i_current_atpf = ((VIDEOINFOHEADER *)p_mt->pbFormat)->AvgTimePerFrame;
1544 if( i_current_height < 0 )
1545 i_current_height = -i_current_height;
1547 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1548 "accepts chroma: %4.4s, width:%i, height:%i, fps:%f",
1549 (char *)&i_current_fourcc, i_current_width,
1550 i_current_height, (10000000.0f/((float)i_current_atpf)) );
1552 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1553 ( !i_width || i_width == i_current_width ) &&
1554 ( !i_height || i_height == i_current_height ) &&
1555 ( !i_AvgTimePerFrame || i_AvgTimePerFrame == i_current_atpf ) &&
1559 mt[mt_count++] = *p_mt;
1561 else FreeMediaType( *p_mt );
1563 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Audio
1564 && p_mt->formattype == FORMAT_WaveFormatEx)
1566 int i_current_channels =
1567 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
1568 int i_current_samplespersec =
1569 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
1570 int i_current_bitspersample =
1571 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
1573 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1574 "accepts format: %4.4s, channels:%i, "
1575 "samples/sec:%i bits/sample:%i",
1576 (char *)&i_current_fourcc, i_current_channels,
1577 i_current_samplespersec, i_current_bitspersample);
1579 if( (!i_channels || i_channels == i_current_channels) &&
1580 (!i_samplespersec ||
1581 i_samplespersec == i_current_samplespersec) &&
1582 (!i_bitspersample ||
1583 i_bitspersample == i_current_bitspersample) &&
1587 mt[mt_count++] = *p_mt;
1589 /* Setup a few properties like the audio latency */
1590 IAMBufferNegotiation *p_ambuf;
1591 if( SUCCEEDED( p_output_pin->QueryInterface(
1592 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
1594 ALLOCATOR_PROPERTIES AllocProp;
1595 AllocProp.cbAlign = -1;
1597 /* 100 ms of latency */
1598 AllocProp.cbBuffer = i_current_channels *
1599 i_current_samplespersec *
1600 i_current_bitspersample / 8 / 10;
1602 AllocProp.cbPrefix = -1;
1603 AllocProp.cBuffers = -1;
1604 p_ambuf->SuggestAllocatorProperties( &AllocProp );
1608 else FreeMediaType( *p_mt );
1610 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Stream )
1612 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1613 "accepts stream format: %4.4s",
1614 (char *)&i_current_fourcc );
1616 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1620 mt[mt_count++] = *p_mt;
1621 i_fourcc = i_current_fourcc;
1623 else FreeMediaType( *p_mt );
1627 const char * psz_type = "unknown";
1628 if( p_mt->majortype == MEDIATYPE_Video ) psz_type = "video";
1629 if( p_mt->majortype == MEDIATYPE_Audio ) psz_type = "audio";
1630 if( p_mt->majortype == MEDIATYPE_Stream ) psz_type = "stream";
1631 msg_Dbg( p_this, "EnumDeviceCaps: input pin media: unsupported format "
1632 "(%s %4.4s)", psz_type, (char *)&p_mt->subtype );
1634 FreeMediaType( *p_mt );
1636 CoTaskMemFree( (PVOID)p_mt );
1639 if( !mt_count && p_enummt->Reset() == S_OK )
1641 // VLC did not find any supported MEDIATYPE for this output pin.
1642 // However the graph builder might insert converter filters in
1643 // the graph if we use a different codec in VLC filter input pin.
1644 // however, in order to avoid nasty surprises, make use of this
1645 // facility only for known unsupported codecs.
1647 while( !mt_count && p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
1649 // the first four bytes of subtype GUID contains the codec FOURCC
1650 const char *pfcc = (char *)&p_mt->subtype;
1651 int i_current_fourcc = VLC_FOURCC(pfcc[0], pfcc[1], pfcc[2], pfcc[3]);
1652 if( VLC_FOURCC('H','C','W','2') == i_current_fourcc
1653 && p_mt->majortype == MEDIATYPE_Video )
1655 // output format for 'Hauppauge WinTV PVR PCI II Capture'
1656 // try I420 as an input format
1657 i_current_fourcc = VLC_FOURCC('I','4','2','0');
1658 if( !i_fourcc || i_fourcc == i_current_fourcc )
1660 // return alternative media type
1664 mtr.majortype = MEDIATYPE_Video;
1665 mtr.subtype = MEDIASUBTYPE_I420;
1666 mtr.bFixedSizeSamples = TRUE;
1667 mtr.bTemporalCompression = FALSE;
1669 mtr.formattype = FORMAT_VideoInfo;
1670 mtr.cbFormat = sizeof(vh);
1671 mtr.pbFormat = (BYTE *)&vh;
1673 memset(&vh, 0, sizeof(vh));
1675 vh.bmiHeader.biSize = sizeof(vh.bmiHeader);
1676 vh.bmiHeader.biWidth = i_width > 0 ? i_width :
1677 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth;
1678 vh.bmiHeader.biHeight = i_height > 0 ? i_height :
1679 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight;
1680 vh.bmiHeader.biPlanes = 3;
1681 vh.bmiHeader.biBitCount = 12;
1682 vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0');
1683 vh.bmiHeader.biSizeImage = vh.bmiHeader.biWidth * 12 *
1684 vh.bmiHeader.biHeight / 8;
1685 mtr.lSampleSize = vh.bmiHeader.biSizeImage;
1687 msg_Dbg( p_this, "EnumDeviceCaps: input pin media: using 'I420' in place of unsupported format 'HCW2'");
1689 if( SUCCEEDED(CopyMediaType(mt+mt_count, &mtr)) )
1693 FreeMediaType( *p_mt );
1697 p_enummt->Release();
1698 p_output_pin->Release();
1701 p_enumpins->Release();
1705 /*****************************************************************************
1706 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1707 *****************************************************************************
1708 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1710 *****************************************************************************/
1711 static block_t *ReadCompressed( access_t *p_access )
1713 access_sys_t *p_sys = p_access->p_sys;
1714 dshow_stream_t *p_stream = NULL;
1715 VLCMediaSample sample;
1717 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1719 /* There must be only 1 elementary stream to produce a valid stream
1720 * of MPEG or DV data */
1721 p_stream = p_sys->pp_streams[0];
1725 if( !vlc_object_alive (p_access) || p_access->b_error ) return 0;
1727 /* Get new sample/frame from the elementary stream (blocking). */
1728 vlc_mutex_lock( &p_sys->lock );
1730 if( p_stream->p_capture_filter->CustomGetPin()
1731 ->CustomGetSample( &sample ) != S_OK )
1733 /* No data available. Wait until some data has arrived */
1734 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1735 vlc_mutex_unlock( &p_sys->lock );
1739 vlc_mutex_unlock( &p_sys->lock );
1746 int i_data_size = sample.p_sample->GetActualDataLength();
1748 if( !i_data_size || !(p_block = block_New( p_access, i_data_size )) )
1750 sample.p_sample->Release();
1754 sample.p_sample->GetPointer( &p_data );
1755 vlc_memcpy( p_block->p_buffer, p_data, i_data_size );
1756 sample.p_sample->Release();
1758 /* The caller got what he wanted */
1762 return NULL; /* never reached */
1765 /****************************************************************************
1767 ****************************************************************************/
1768 static int Demux( demux_t *p_demux )
1770 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
1772 int i_found_samples;
1774 i_found_samples = 0;
1775 vlc_mutex_lock( &p_sys->lock );
1777 while ( !i_found_samples )
1779 /* Try to grab samples from all streams */
1780 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1782 dshow_stream_t *p_stream = p_sys->pp_streams[i_stream];
1783 if( p_stream->p_capture_filter &&
1784 p_stream->p_capture_filter->CustomGetPin()
1785 ->CustomGetSamples( p_stream->samples_queue ) == S_OK )
1787 i_found_samples = 1;
1791 if ( !i_found_samples)
1793 /* Didn't find any audio nor video sample, just wait till the
1794 * dshow thread pushes some samples */
1795 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1796 /* Some DShow thread pushed data, or the OS broke the wait all
1797 * by itself. In all cases, it's *strongly* advised to test the
1798 * condition again, so let the loop do the test again */
1802 vlc_mutex_unlock( &p_sys->lock );
1804 for ( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1807 dshow_stream_t *p_stream = p_sys->pp_streams[i_stream];
1809 i_samples = p_stream->samples_queue.size();
1810 while ( i_samples > 0 )
1815 VLCMediaSample sample;
1817 sample = p_stream->samples_queue.front();
1818 p_stream->samples_queue.pop_front();
1820 i_data_size = sample.p_sample->GetActualDataLength();
1821 sample.p_sample->GetPointer( &p_data );
1823 REFERENCE_TIME i_pts, i_end_date;
1824 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1825 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1829 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1831 /* Use our data timestamp */
1832 i_pts = sample.i_timestamp;
1833 p_stream->b_pts = true;
1837 i_pts /= 10; /* Dshow works with 100 nano-seconds resolution */
1840 msg_Dbg( p_demux, "Read() stream: %i, size: %i, PTS: %"PRId64,
1841 i_stream, i_data_size, i_pts );
1844 p_block = block_New( p_demux, i_data_size );
1845 vlc_memcpy( p_block->p_buffer, p_data, i_data_size );
1846 p_block->i_pts = p_block->i_dts = i_pts;
1847 sample.p_sample->Release();
1849 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pts > 0 ? i_pts : 0 );
1850 es_out_Send( p_demux->out, p_stream->p_es, p_block );
1859 /*****************************************************************************
1861 *****************************************************************************/
1862 static int AccessControl( access_t *p_access, int i_query, va_list args )
1871 case ACCESS_CAN_SEEK:
1872 case ACCESS_CAN_FASTSEEK:
1873 case ACCESS_CAN_PAUSE:
1874 case ACCESS_CAN_CONTROL_PACE:
1875 pb_bool = (bool*)va_arg( args, bool* );
1880 case ACCESS_GET_PTS_DELAY:
1881 pi_64 = (int64_t*)va_arg( args, int64_t * );
1882 *pi_64 = (int64_t)var_GetInteger( p_access, "dshow-caching" ) * 1000;
1886 case ACCESS_SET_PAUSE_STATE:
1887 case ACCESS_GET_TITLE_INFO:
1888 case ACCESS_SET_TITLE:
1889 case ACCESS_SET_SEEKPOINT:
1890 case ACCESS_SET_PRIVATE_ID_STATE:
1891 return VLC_EGENERIC;
1894 msg_Warn( p_access, "unimplemented query in control" );
1895 return VLC_EGENERIC;
1901 /****************************************************************************
1903 ****************************************************************************/
1904 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
1911 /* Special for access_demux */
1912 case DEMUX_CAN_PAUSE:
1913 case DEMUX_CAN_SEEK:
1914 case DEMUX_SET_PAUSE_STATE:
1915 case DEMUX_CAN_CONTROL_PACE:
1916 pb = (bool*)va_arg( args, bool * );
1920 case DEMUX_GET_PTS_DELAY:
1921 pi64 = (int64_t*)va_arg( args, int64_t * );
1922 *pi64 = (int64_t)var_GetInteger( p_demux, "dshow-caching" ) * 1000;
1925 case DEMUX_GET_TIME:
1926 pi64 = (int64_t*)va_arg( args, int64_t * );
1930 /* TODO implement others */
1932 return VLC_EGENERIC;
1935 return VLC_EGENERIC;
1938 /*****************************************************************************
1939 * config variable callback
1940 *****************************************************************************/
1941 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1942 vlc_value_t newval, vlc_value_t oldval, void * )
1944 module_config_t *p_item;
1945 bool b_audio = false;
1948 p_item = config_FindConfig( p_this, psz_name );
1949 if( !p_item ) return VLC_SUCCESS;
1951 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = true;
1953 /* Clear-up the current list */
1954 if( p_item->i_list )
1956 /* Keep the 2 first entries */
1957 for( i = 2; i < p_item->i_list; i++ )
1959 free( const_cast<char *>(p_item->ppsz_list[i]) );
1960 free( const_cast<char *>(p_item->ppsz_list_text[i]) );
1962 /* TODO: Remove when no more needed */
1963 p_item->ppsz_list[i] = NULL;
1964 p_item->ppsz_list_text[i] = NULL;
1968 /* Find list of devices */
1969 list<string> list_devices;
1971 /* Initialize OLE/COM */
1974 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1976 /* Uninitialize OLE/COM */
1979 if( !list_devices.size() ) return VLC_SUCCESS;
1982 (char **)realloc( p_item->ppsz_list,
1983 (list_devices.size()+3) * sizeof(char *) );
1984 p_item->ppsz_list_text =
1985 (char **)realloc( p_item->ppsz_list_text,
1986 (list_devices.size()+3) * sizeof(char *) );
1988 list<string>::iterator iter;
1989 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1992 p_item->ppsz_list[i] = strdup( iter->c_str() );
1993 p_item->ppsz_list_text[i] = NULL;
1996 p_item->ppsz_list[i] = NULL;
1997 p_item->ppsz_list_text[i] = NULL;
1999 /* Signal change to the interface */
2000 p_item->b_dirty = true;
2005 static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
2006 vlc_value_t newval, vlc_value_t oldval, void * )
2008 module_config_t *p_item;
2009 bool b_audio = false;
2011 /* Initialize OLE/COM */
2014 p_item = config_FindConfig( p_this, psz_name );
2015 if( !p_item ) return VLC_SUCCESS;
2017 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = true;
2021 if( newval.psz_string && *newval.psz_string )
2023 devicename = newval.psz_string;
2027 /* If no device name was specified, pick the 1st one */
2028 list<string> list_devices;
2030 /* Enumerate devices */
2031 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
2032 if( !list_devices.size() ) return VLC_EGENERIC;
2033 devicename = *list_devices.begin();
2036 IBaseFilter *p_device_filter =
2037 FindCaptureDevice( p_this, &devicename, NULL, b_audio );
2038 if( p_device_filter )
2040 ShowPropertyPage( p_device_filter );
2041 p_device_filter->Release();
2045 /* Uninitialize OLE/COM */
2048 msg_Err( p_this, "didn't find device: %s", devicename.c_str() );
2049 return VLC_EGENERIC;
2052 /* Uninitialize OLE/COM */
2058 /*****************************************************************************
2060 *****************************************************************************/
2062 static void ShowPropertyPage( IUnknown *obj )
2064 ISpecifyPropertyPages *p_spec;
2067 HRESULT hr = obj->QueryInterface( IID_ISpecifyPropertyPages,
2069 if( FAILED(hr) ) return;
2071 if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
2073 if( cauuid.cElems > 0 )
2075 HWND hwnd_desktop = ::GetDesktopWindow();
2077 OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
2078 cauuid.cElems, cauuid.pElems, 0, 0, NULL );
2080 CoTaskMemFree( cauuid.pElems );
2086 static void ShowDeviceProperties( vlc_object_t *p_this,
2087 ICaptureGraphBuilder2 *p_graph,
2088 IBaseFilter *p_device_filter,
2092 msg_Dbg( p_this, "configuring Device Properties" );
2095 * Video or audio capture filter page
2097 ShowPropertyPage( p_device_filter );
2102 if( p_graph && b_audio )
2104 IAMStreamConfig *p_SC;
2106 msg_Dbg( p_this, "showing WDM Audio Configuration Pages" );
2108 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2109 &MEDIATYPE_Audio, p_device_filter,
2110 IID_IAMStreamConfig, (void **)&p_SC );
2113 ShowPropertyPage(p_SC);
2121 HRESULT hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2122 &MEDIATYPE_Audio, p_device_filter,
2123 IID_IAMTVAudio, (void **)&p_TVA );
2126 ShowPropertyPage(p_TVA);
2134 if( p_graph && !b_audio )
2136 IAMStreamConfig *p_SC;
2138 msg_Dbg( p_this, "showing WDM Video Configuration Pages" );
2140 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2141 &MEDIATYPE_Interleaved, p_device_filter,
2142 IID_IAMStreamConfig, (void **)&p_SC );
2145 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2146 &MEDIATYPE_Video, p_device_filter,
2147 IID_IAMStreamConfig, (void **)&p_SC );
2152 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2153 &MEDIATYPE_Stream, p_device_filter,
2154 IID_IAMStreamConfig, (void **)&p_SC );
2159 ShowPropertyPage(p_SC);
2165 static void ShowTunerProperties( vlc_object_t *p_this,
2166 ICaptureGraphBuilder2 *p_graph,
2167 IBaseFilter *p_device_filter,
2171 msg_Dbg( p_this, "configuring Tuner Properties" );
2173 if( !p_graph || b_audio ) return;
2176 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2177 &MEDIATYPE_Interleaved, p_device_filter,
2178 IID_IAMTVTuner, (void **)&p_TV );
2181 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2182 &MEDIATYPE_Video, p_device_filter,
2183 IID_IAMTVTuner, (void **)&p_TV );
2188 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
2189 &MEDIATYPE_Stream, p_device_filter,
2190 IID_IAMTVTuner, (void **)&p_TV );
2195 ShowPropertyPage(p_TV);
2200 static void ConfigTuner( vlc_object_t *p_this, ICaptureGraphBuilder2 *p_graph,
2201 IBaseFilter *p_device_filter )
2203 int i_channel, i_country, i_input, i_amtuner_mode;
2208 if( !p_graph ) return;
2210 i_channel = var_GetInteger( p_this, "dshow-tuner-channel" );
2211 i_country = var_GetInteger( p_this, "dshow-tuner-country" );
2212 i_input = var_GetInteger( p_this, "dshow-tuner-input" );
2213 i_amtuner_mode = var_GetInteger( p_this, "dshow-amtuner-mode" );
2215 if( !i_channel && !i_country && !i_input ) return; /* Nothing to do */
2217 msg_Dbg( p_this, "tuner config: channel %i, country %i, input type %i",
2218 i_channel, i_country, i_input );
2220 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Interleaved,
2221 p_device_filter, IID_IAMTVTuner,
2225 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
2226 p_device_filter, IID_IAMTVTuner,
2232 hr = p_graph->FindInterface( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Stream,
2233 p_device_filter, IID_IAMTVTuner,
2239 msg_Dbg( p_this, "couldn't find tuner interface" );
2243 hr = p_TV->GetAvailableModes( &l_modes );
2244 if( SUCCEEDED(hr) && (l_modes & i_amtuner_mode) )
2246 hr = p_TV->put_Mode( (AMTunerModeType)i_amtuner_mode );
2249 if( i_input == 1 ) p_TV->put_InputType( 0, TunerInputCable );
2250 else if( i_input == 2 ) p_TV->put_InputType( 0, TunerInputAntenna );
2252 p_TV->put_CountryCode( i_country );
2253 p_TV->put_Channel( i_channel, AMTUNER_SUBCHAN_NO_TUNE,
2254 AMTUNER_SUBCHAN_NO_TUNE );