1 /*****************************************************************************
2 * dshow.cpp : DirectShow access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002, 2003 VideoLAN
7 * Author: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc/input.h>
38 /*****************************************************************************
39 * Access: local prototypes
40 *****************************************************************************/
41 static block_t *ReadCompressed( access_t * );
42 static int AccessControl ( access_t *, int, va_list );
44 static int Demux ( demux_t * );
45 static int DemuxControl( demux_t *, int, va_list );
47 static int OpenDevice( vlc_object_t *, access_sys_t *, string, vlc_bool_t );
48 static IBaseFilter *FindCaptureDevice( vlc_object_t *, string *,
49 list<string> *, vlc_bool_t );
50 static size_t EnumDeviceCaps( vlc_object_t *, IBaseFilter *,
51 int, int, int, int, int, int,
52 AM_MEDIA_TYPE *mt, size_t );
53 static bool ConnectFilters( vlc_object_t *, access_sys_t *,
54 IBaseFilter *, CaptureFilter * );
55 static int FindDevicesCallback( vlc_object_t *, char const *,
56 vlc_value_t, vlc_value_t, void * );
57 static int ConfigDevicesCallback( vlc_object_t *, char const *,
58 vlc_value_t, vlc_value_t, void * );
60 static void ShowPropertyPage( IUnknown * );
61 static void ShowDeviceProperties( vlc_object_t *, ICaptureGraphBuilder2 *,
62 IBaseFilter *, vlc_bool_t );
63 static void ShowTunerProperties( vlc_object_t *, ICaptureGraphBuilder2 *,
64 IBaseFilter *, vlc_bool_t );
66 /*****************************************************************************
68 *****************************************************************************/
69 static char *ppsz_vdev[] = { "", "none" };
70 static char *ppsz_vdev_text[] = { N_("Default"), N_("None") };
71 static char *ppsz_adev[] = { "", "none" };
72 static char *ppsz_adev_text[] = { N_("Default"), N_("None") };
74 #define CACHING_TEXT N_("Caching value in ms")
75 #define CACHING_LONGTEXT N_( \
76 "Allows you to modify the default caching value for DirectShow streams. " \
77 "This value should be set in milliseconds units." )
78 #define VDEV_TEXT N_("Video device name")
79 #define VDEV_LONGTEXT N_( \
80 "You can specify the name of the video device that will be used by the " \
81 "DirectShow plugin. If you don't specify anything, the default device " \
83 #define ADEV_TEXT N_("Audio device name")
84 #define ADEV_LONGTEXT N_( \
85 "You can specify the name of the audio device that will be used by the " \
86 "DirectShow plugin. If you don't specify anything, the default device " \
88 #define SIZE_TEXT N_("Video size")
89 #define SIZE_LONGTEXT N_( \
90 "You can specify the size of the video that will be displayed by the " \
91 "DirectShow plugin. If you don't specify anything the default size for " \
92 "your device will be used.")
93 #define CHROMA_TEXT N_("Video input chroma format")
94 #define CHROMA_LONGTEXT N_( \
95 "Force the DirectShow video input to use a specific chroma format " \
96 "(eg. I420 (default), RV24, etc.)")
97 #define CONFIG_TEXT N_("Device properties")
98 #define CONFIG_LONGTEXT N_( \
99 "Show the properties dialog of the selected device before starting the " \
101 #define TUNER_TEXT N_("Tuner properties")
102 #define TUNER_LONGTEXT N_( \
103 "Show the tuner properties [channel selection] page." )
105 static int CommonOpen ( vlc_object_t *, access_sys_t *, vlc_bool_t );
106 static void CommonClose( vlc_object_t *, access_sys_t * );
108 static int AccessOpen ( vlc_object_t * );
109 static void AccessClose( vlc_object_t * );
111 static int DemuxOpen ( vlc_object_t * );
112 static void DemuxClose ( vlc_object_t * );
115 set_shortname( _("DirectShow") );
116 set_description( _("DirectShow input") );
117 add_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,
118 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
120 add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, VLC_FALSE);
121 change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback );
122 change_action_add( FindDevicesCallback, N_("Refresh list") );
123 change_action_add( ConfigDevicesCallback, N_("Configure") );
125 add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE);
126 change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback );
127 change_action_add( FindDevicesCallback, N_("Refresh list") );
128 change_action_add( ConfigDevicesCallback, N_("Configure") );
130 add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE);
132 add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
135 add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,
138 add_bool( "dshow-tuner", VLC_FALSE, NULL, TUNER_TEXT, TUNER_LONGTEXT,
141 add_shortcut( "dshow" );
142 set_capability( "access_demux", 0 );
143 set_callbacks( DemuxOpen, DemuxClose );
146 set_description( _("DirectShow input") );
147 add_shortcut( "dshow" );
148 set_capability( "access2", 0 );
149 set_callbacks( AccessOpen, AccessClose );
153 /*****************************************************************************
154 * DirectShow elementary stream descriptor
155 *****************************************************************************/
156 typedef struct dshow_stream_t
159 IBaseFilter *p_device_filter;
160 CaptureFilter *p_capture_filter;
165 VIDEOINFOHEADER video;
177 /*****************************************************************************
178 * DirectShow utility functions
179 *****************************************************************************/
180 static void CreateDirectShowGraph( access_sys_t *p_sys )
182 p_sys->i_crossbar_route_depth = 0;
184 /* Create directshow filter graph */
185 if( SUCCEEDED( CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,
186 (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph) ) )
188 /* Create directshow capture graph builder if available */
189 if( SUCCEEDED( CoCreateInstance( CLSID_CaptureGraphBuilder2, 0,
190 CLSCTX_INPROC, (REFIID)IID_ICaptureGraphBuilder2,
191 (void **)&p_sys->p_capture_graph_builder2 ) ) )
193 p_sys->p_capture_graph_builder2->
194 SetFiltergraph((IGraphBuilder *)p_sys->p_graph);
197 p_sys->p_graph->QueryInterface( IID_IMediaControl,
198 (void **)&p_sys->p_control );
202 static void DeleteDirectShowGraph( access_sys_t *p_sys )
204 DeleteCrossbarRoutes( p_sys );
206 /* Remove filters from graph */
207 for( int i = 0; i < p_sys->i_streams; i++ )
209 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );
210 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );
211 p_sys->pp_streams[i]->p_capture_filter->Release();
212 p_sys->pp_streams[i]->p_device_filter->Release();
215 /* Release directshow objects */
216 if( p_sys->p_control )
218 p_sys->p_control->Release();
219 p_sys->p_control = NULL;
221 if( p_sys->p_capture_graph_builder2 )
223 p_sys->p_capture_graph_builder2->Release();
224 p_sys->p_capture_graph_builder2 = NULL;
229 p_sys->p_graph->Release();
230 p_sys->p_graph = NULL;
234 /*****************************************************************************
235 * CommonOpen: open direct show device
236 *****************************************************************************/
237 static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
238 vlc_bool_t b_access_demux )
243 /* Get/parse options and open device(s) */
244 string vdevname, adevname;
245 int i_width = 0, i_height = 0, i_chroma = 0;
246 vlc_bool_t b_audio = VLC_TRUE;
248 var_Create( p_this, "dshow-config", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
249 var_Create( p_this, "dshow-tuner", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
251 var_Create( p_this, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
252 var_Get( p_this, "dshow-vdev", &val );
253 if( val.psz_string ) vdevname = string( val.psz_string );
254 if( val.psz_string ) free( val.psz_string );
256 var_Create( p_this, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
257 var_Get( p_this, "dshow-adev", &val );
258 if( val.psz_string ) adevname = string( val.psz_string );
259 if( val.psz_string ) free( val.psz_string );
261 static struct {char *psz_size; int i_width; int i_height;} size_table[] =
262 { { "subqcif", 128, 96 }, { "qsif", 160, 120 }, { "qcif", 176, 144 },
263 { "sif", 320, 240 }, { "cif", 352, 288 }, { "cif", 640, 480 },
267 var_Create( p_this, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
268 var_Get( p_this, "dshow-size", &val );
269 if( val.psz_string && *val.psz_string )
271 for( i = 0; size_table[i].psz_size; i++ )
273 if( !strcmp( val.psz_string, size_table[i].psz_size ) )
275 i_width = size_table[i].i_width;
276 i_height = size_table[i].i_height;
280 if( !size_table[i].psz_size ) /* Try to parse "WidthxHeight" */
283 i_width = strtol( val.psz_string, &psz_parser, 0 );
284 if( *psz_parser == 'x' || *psz_parser == 'X')
286 i_height = strtol( psz_parser + 1, &psz_parser, 0 );
288 msg_Dbg( p_this, "Width x Height %dx%d", i_width, i_height );
291 if( val.psz_string ) free( val.psz_string );
293 var_Create( p_this, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
294 var_Get( p_this, "dshow-chroma", &val );
295 if( val.psz_string && strlen( val.psz_string ) >= 4 )
297 i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],
298 val.psz_string[2], val.psz_string[3] );
300 if( val.psz_string ) free( val.psz_string );
302 var_Create( p_this, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
304 /* Initialize OLE/COM */
307 /* Initialize some data */
308 p_sys->i_streams = 0;
309 p_sys->pp_streams = 0;
310 p_sys->i_width = i_width;
311 p_sys->i_height = i_height;
312 p_sys->i_chroma = i_chroma;
314 p_sys->p_graph = NULL;
315 p_sys->p_capture_graph_builder2 = NULL;
316 p_sys->p_control = NULL;
318 vlc_mutex_init( p_this, &p_sys->lock );
319 vlc_cond_init( p_this, &p_sys->wait );
321 /* Build directshow graph */
322 CreateDirectShowGraph( p_sys );
324 if( OpenDevice( p_this, p_sys, vdevname, 0 ) != VLC_SUCCESS )
326 msg_Err( p_this, "can't open video");
330 /* Check if we can handle the demuxing ourselves or need to spawn
331 * a demuxer module */
332 dshow_stream_t *p_stream = p_sys->pp_streams[p_sys->i_streams-1];
334 if( p_stream->mt.majortype == MEDIATYPE_Video )
336 if( /* Raw DV stream */
337 p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
338 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
339 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') ||
340 /* Raw MPEG video stream */
341 p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
347 /* Let the access (only) take care of that */
353 if( p_stream->mt.majortype == MEDIATYPE_Stream )
359 /* Let the access (only) take care of that */
365 if( b_audio && OpenDevice( p_this, p_sys, adevname, 1 ) != VLC_SUCCESS )
367 msg_Err( p_this, "can't open audio");
370 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
372 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
373 LONG VideoInputIndex = p_sys->crossbar_routes[i].VideoInputIndex;
374 LONG VideoOutputIndex = p_sys->crossbar_routes[i].VideoOutputIndex;
375 LONG AudioInputIndex = p_sys->crossbar_routes[i].AudioInputIndex;
376 LONG AudioOutputIndex = p_sys->crossbar_routes[i].AudioOutputIndex;
378 if( SUCCEEDED(pXbar->Route(VideoOutputIndex, VideoInputIndex)) )
380 msg_Dbg( p_this, "Crossbar at depth %d, Routed video "
381 "ouput %ld to video input %ld", i, VideoOutputIndex,
384 if( AudioOutputIndex != -1 && AudioInputIndex != -1 )
386 if( SUCCEEDED( pXbar->Route(AudioOutputIndex,
389 msg_Dbg(p_this, "Crossbar at depth %d, Routed audio "
390 "ouput %ld to audio input %ld", i,
391 AudioOutputIndex, AudioInputIndex );
398 ** Show properties pages from other filters in graph
400 var_Get( p_this, "dshow-config", &val );
403 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
405 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
408 if( SUCCEEDED( pXbar->QueryInterface( IID_IBaseFilter,
411 ShowPropertyPage( p_XF );
417 /* Initialize some data */
418 p_sys->i_current_stream = 0;
420 if( !p_sys->i_streams ) return VLC_EGENERIC;
425 /*****************************************************************************
426 * DemuxOpen: open direct show device as an access_demux module
427 *****************************************************************************/
428 static int DemuxOpen( vlc_object_t *p_this )
430 demux_t *p_demux = (demux_t *)p_this;
434 p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
435 memset( p_sys, 0, sizeof( access_sys_t ) );
436 p_demux->p_sys = (demux_sys_t *)p_sys;
438 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
440 CommonClose( p_this, p_sys );
444 /* Everything is ready. Let's rock baby */
445 msg_Dbg( p_this, "Playing...");
446 p_sys->p_control->Run();
448 p_demux->pf_demux = Demux;
449 p_demux->pf_control = DemuxControl;
450 p_demux->info.i_update = 0;
451 p_demux->info.i_title = 0;
452 p_demux->info.i_seekpoint = 0;
454 for( i = 0; i < p_sys->i_streams; i++ )
456 dshow_stream_t *p_stream = p_sys->pp_streams[i];
459 if( p_stream->mt.majortype == MEDIATYPE_Video )
461 es_format_Init( &fmt, VIDEO_ES, p_stream->i_fourcc );
463 fmt.video.i_width = p_stream->header.video.bmiHeader.biWidth;
464 fmt.video.i_height = p_stream->header.video.bmiHeader.biHeight;
465 fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
467 if( !p_stream->header.video.bmiHeader.biCompression )
469 /* RGB DIB are coded from bottom to top */
470 fmt.video.i_height = (unsigned int)(-(int)fmt.video.i_height);
473 /* Setup rgb mask for RGB formats */
474 if( p_stream->i_fourcc == VLC_FOURCC('R','V','2','4') )
476 /* This is in BGR format */
477 fmt.video.i_bmask = 0x00ff0000;
478 fmt.video.i_gmask = 0x0000ff00;
479 fmt.video.i_rmask = 0x000000ff;
482 else if( p_stream->mt.majortype == MEDIATYPE_Audio )
484 es_format_Init( &fmt, AUDIO_ES, p_stream->i_fourcc );
486 fmt.audio.i_channels = p_stream->header.audio.nChannels;
487 fmt.audio.i_rate = p_stream->header.audio.nSamplesPerSec;
488 fmt.audio.i_bitspersample = p_stream->header.audio.wBitsPerSample;
489 fmt.audio.i_blockalign = fmt.audio.i_channels *
490 fmt.audio.i_bitspersample / 8;
491 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
492 fmt.audio.i_bitspersample;
495 p_stream->p_es = es_out_Add( p_demux->out, &fmt );
501 /*****************************************************************************
502 * AccessOpen: open direct show device as an access module
503 *****************************************************************************/
504 static int AccessOpen( vlc_object_t *p_this )
506 access_t *p_access = (access_t*)p_this;
509 p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
510 memset( p_sys, 0, sizeof( access_sys_t ) );
512 if( CommonOpen( p_this, p_sys, VLC_FALSE ) != VLC_SUCCESS )
514 CommonClose( p_this, p_sys );
518 dshow_stream_t *p_stream = p_sys->pp_streams[0];
520 /* Check if we need to force demuxers */
521 if( !p_access->psz_demux || !*p_access->psz_demux )
523 if( p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
524 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
525 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') )
527 p_access->psz_demux = strdup( "rawdv" );
529 else if( p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
531 p_access->psz_demux = "mpgv";
536 p_access->pf_read = NULL;
537 p_access->pf_block = ReadCompressed;
538 p_access->pf_control = AccessControl;
539 p_access->pf_seek = NULL;
540 p_access->info.i_update = 0;
541 p_access->info.i_size = 0;
542 p_access->info.i_pos = 0;
543 p_access->info.b_eof = VLC_FALSE;
544 p_access->info.i_title = 0;
545 p_access->info.i_seekpoint = 0;
546 p_access->p_sys = p_sys;
548 /* Everything is ready. Let's rock baby */
549 msg_Dbg( p_this, "Playing...");
550 p_sys->p_control->Run();
555 /*****************************************************************************
556 * CommonClose: close device
557 *****************************************************************************/
558 static void CommonClose( vlc_object_t *p_this, access_sys_t *p_sys )
560 msg_Dbg( p_this, "Releasing DirectShow");
562 DeleteDirectShowGraph( p_sys );
564 /* Uninitialize OLE/COM */
567 /* Remove filters from graph */
568 for( int i = 0; i < p_sys->i_streams; i++ ) delete p_sys->pp_streams[i];
569 if( p_sys->i_streams ) free( p_sys->pp_streams );
571 vlc_mutex_destroy( &p_sys->lock );
572 vlc_cond_destroy( &p_sys->wait );
577 /*****************************************************************************
578 * AccessClose: close device
579 *****************************************************************************/
580 static void AccessClose( vlc_object_t *p_this )
582 access_t *p_access = (access_t *)p_this;
583 access_sys_t *p_sys = p_access->p_sys;
585 /* Stop capturing stuff */
586 p_sys->p_control->Stop();
588 CommonClose( p_this, p_sys );
591 /*****************************************************************************
592 * DemuxClose: close device
593 *****************************************************************************/
594 static void DemuxClose( vlc_object_t *p_this )
596 demux_t *p_demux = (demux_t *)p_this;
597 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
599 /* Stop capturing stuff */
600 p_sys->p_control->Stop();
602 CommonClose( p_this, p_sys );
605 /****************************************************************************
607 ****************************************************************************/
608 static bool ConnectFilters( vlc_object_t *p_this, access_sys_t *p_sys,
609 IBaseFilter *p_filter,
610 CaptureFilter *p_capture_filter )
612 CapturePin *p_input_pin = p_capture_filter->CustomGetPin();
614 AM_MEDIA_TYPE mediaType = p_input_pin->CustomGetMediaType();
616 if( p_sys->p_capture_graph_builder2 )
618 if( FAILED(p_sys->p_capture_graph_builder2->
619 RenderStream( &PIN_CATEGORY_CAPTURE, &mediaType.majortype,
620 p_filter, 0, (IBaseFilter *)p_capture_filter )) )
625 // Sort out all the possible video inputs
626 // The class needs to be given the capture filters ANALOGVIDEO input pin
628 if( ( mediaType.majortype == MEDIATYPE_Video ||
629 mediaType.majortype == MEDIATYPE_Stream ) &&
630 SUCCEEDED(p_filter->EnumPins(&pins)) )
636 IKsPropertySet *pKs=0;
640 while( !Found && ( S_OK == pins->Next(1, &pP, &n) ) )
642 if( S_OK == pP->QueryPinInfo(&pinInfo) )
644 // is this pin an ANALOGVIDEOIN input pin?
645 if( pinInfo.dir == PINDIR_INPUT &&
646 pP->QueryInterface( IID_IKsPropertySet,
647 (void **)&pKs ) == S_OK )
649 if( pKs->Get( AMPROPSETID_Pin,
650 AMPROPERTY_PIN_CATEGORY, NULL, 0,
651 &guid, sizeof(GUID), &dw ) == S_OK )
653 if( guid == PIN_CATEGORY_ANALOGVIDEOIN )
655 // recursively search crossbar routes
656 FindCrossbarRoutes( p_this, p_sys, pP, 0 );
663 pinInfo.pFilter->Release();
673 IEnumPins *p_enumpins;
676 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
678 while( S_OK == p_enumpins->Next( 1, &p_pin, NULL ) )
680 PIN_DIRECTION pin_dir;
681 p_pin->QueryDirection( &pin_dir );
683 if( pin_dir == PINDIR_OUTPUT &&
684 p_sys->p_graph->ConnectDirect( p_pin, (IPin *)p_input_pin,
688 p_enumpins->Release();
694 p_enumpins->Release();
700 * get fourcc priority from arbritary preference, the higher the better
702 static int GetFourCCPriority( int i_fourcc )
706 case VLC_FOURCC('I','4','2','0'):
707 case VLC_FOURCC('f','l','3','2'):
709 case VLC_FOURCC('Y','V','1','2'):
710 case VLC_FOURCC('a','r','a','w'):
712 case VLC_FOURCC('R','V','2','4'):
714 case VLC_FOURCC('Y','U','Y','2'):
715 case VLC_FOURCC('R','V','3','2'):
716 case VLC_FOURCC('R','G','B','A'):
723 #define MAX_MEDIA_TYPES 32
725 static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
726 string devicename, vlc_bool_t b_audio )
728 /* See if device is already opened */
729 for( int i = 0; i < p_sys->i_streams; i++ )
731 if( devicename.size() &&
732 p_sys->pp_streams[i]->devicename == devicename )
739 list<string> list_devices;
741 /* Enumerate devices and display their names */
742 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
744 if( !list_devices.size() )
747 list<string>::iterator iter;
748 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
749 msg_Dbg( p_this, "found device: %s", iter->c_str() );
751 /* If no device name was specified, pick the 1st one */
752 if( devicename.size() == 0 )
754 devicename = *list_devices.begin();
757 // Use the system device enumerator and class enumerator to find
758 // a capture/preview device, such as a desktop USB video camera.
759 IBaseFilter *p_device_filter =
760 FindCaptureDevice( p_this, &devicename, 0, b_audio );
761 if( p_device_filter )
762 msg_Dbg( p_this, "using device: %s", devicename.c_str() );
765 msg_Err( p_this, "can't use device: %s, unsupported device type",
766 devicename.c_str() );
770 // Retreive acceptable media types supported by device
771 AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
773 EnumDeviceCaps( p_this, p_device_filter, p_sys->i_chroma,
774 p_sys->i_width, p_sys->i_height,
775 0, 0, 0, media_types, MAX_MEDIA_TYPES );
777 /* Find out if the pin handles MEDIATYPE_Stream, in which case we
778 * won't add a prefered media type as this doesn't seem to work well
779 * -- to investigate. */
780 vlc_bool_t b_stream_type = VLC_FALSE;
781 for( size_t i = 0; i < media_count; i++ )
783 if( media_types[i].majortype == MEDIATYPE_Stream )
785 b_stream_type = VLC_TRUE;
791 AM_MEDIA_TYPE *mt = NULL;
793 if( !b_stream_type && !b_audio )
795 // Insert prefered video media type
799 mtr.majortype = MEDIATYPE_Video;
800 mtr.subtype = MEDIASUBTYPE_I420;
801 mtr.bFixedSizeSamples = TRUE;
802 mtr.bTemporalCompression = FALSE;
804 mtr.formattype = FORMAT_VideoInfo;
805 mtr.cbFormat = sizeof(vh);
806 mtr.pbFormat = (BYTE *)&vh;
808 memset(&vh, 0, sizeof(vh));
810 vh.bmiHeader.biSize = sizeof(vh.bmiHeader);
811 vh.bmiHeader.biWidth = p_sys->i_width > 0 ? p_sys->i_width : 320;
812 vh.bmiHeader.biHeight = p_sys->i_height > 0 ? p_sys->i_height : 240;
813 vh.bmiHeader.biPlanes = 3;
814 vh.bmiHeader.biBitCount = 12;
815 vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0');
816 vh.bmiHeader.biSizeImage = vh.bmiHeader.biWidth * 12 *
817 vh.bmiHeader.biHeight / 8;
818 mtr.lSampleSize = vh.bmiHeader.biSizeImage;
821 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
822 CopyMediaType(mt, &mtr);
824 else if( !b_stream_type )
826 // Insert prefered audio media type
830 mtr.majortype = MEDIATYPE_Audio;
831 mtr.subtype = MEDIASUBTYPE_PCM;
832 mtr.bFixedSizeSamples = TRUE;
833 mtr.bTemporalCompression = FALSE;
836 mtr.formattype = FORMAT_WaveFormatEx;
837 mtr.cbFormat = sizeof(wf);
838 mtr.pbFormat = (BYTE *)&wf;
840 memset(&wf, 0, sizeof(wf));
842 wf.wFormatTag = WAVE_FORMAT_PCM;
844 wf.nSamplesPerSec = 44100;
845 wf.wBitsPerSample = 16;
846 wf.nBlockAlign = wf.nSamplesPerSec * wf.wBitsPerSample / 8;
847 wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
851 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
852 CopyMediaType(mt, &mtr);
855 if( media_count > 0 )
857 mt = (AM_MEDIA_TYPE *)realloc( mt, sizeof(AM_MEDIA_TYPE) *
858 (mt_count + media_count) );
860 // Order and copy returned media types according to arbitrary
862 for( size_t c = 0; c < media_count; c++ )
865 GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
866 size_t slot_copy = c;
867 for( size_t d = c+1; d < media_count; d++ )
870 GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
871 if( priority > slot_priority )
873 slot_priority = priority;
879 mt[c+mt_count] = media_types[slot_copy];
880 media_types[slot_copy] = media_types[c];
884 mt[c+mt_count] = media_types[c];
887 mt_count += media_count;
890 /* Create and add our capture filter */
891 CaptureFilter *p_capture_filter =
892 new CaptureFilter( p_this, p_sys, mt, mt_count );
893 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
895 /* Add the device filter to the graph (seems necessary with VfW before
896 * accessing pin attributes). */
897 p_sys->p_graph->AddFilter( p_device_filter, 0 );
899 /* Attempt to connect one of this device's capture output pins */
900 msg_Dbg( p_this, "connecting filters" );
901 if( ConnectFilters( p_this, p_sys, p_device_filter, p_capture_filter ) )
904 msg_Dbg( p_this, "filters connected successfully !" );
906 dshow_stream_t dshow_stream;
907 dshow_stream.b_pts = VLC_FALSE;
908 dshow_stream.p_es = 0;
910 p_capture_filter->CustomGetPin()->CustomGetMediaType();
912 /* Show Device properties. Done here so the VLC stream is setup with
913 * the proper parameters. */
915 var_Get( p_this, "dshow-config", &val );
918 ShowDeviceProperties( p_this, p_sys->p_capture_graph_builder2,
919 p_device_filter, b_audio );
922 var_Get( p_this, "dshow-tuner", &val );
925 ShowTunerProperties( p_this, p_sys->p_capture_graph_builder2,
926 p_device_filter, b_audio );
930 p_capture_filter->CustomGetPin()->CustomGetMediaType();
932 dshow_stream.i_fourcc = GetFourCCFromMediaType( dshow_stream.mt );
933 if( dshow_stream.i_fourcc )
935 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
937 dshow_stream.header.video =
938 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
939 msg_Dbg( p_this, "MEDIATYPE_Video" );
940 msg_Dbg( p_this, "selected video pin accepts format: %4.4s",
941 (char *)&dshow_stream.i_fourcc);
943 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio )
945 dshow_stream.header.audio =
946 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
947 msg_Dbg( p_this, "MEDIATYPE_Audio" );
948 msg_Dbg( p_this, "selected audio pin accepts format: %4.4s",
949 (char *)&dshow_stream.i_fourcc);
951 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
953 msg_Dbg( p_this, "MEDIATYPE_Stream" );
954 msg_Dbg( p_this, "selected stream pin accepts format: %4.4s",
955 (char *)&dshow_stream.i_fourcc);
959 msg_Dbg( p_this, "unknown stream majortype" );
963 /* Add directshow elementary stream to our list */
964 dshow_stream.p_device_filter = p_device_filter;
965 dshow_stream.p_capture_filter = p_capture_filter;
967 p_sys->pp_streams = (dshow_stream_t **)realloc( p_sys->pp_streams,
968 sizeof(dshow_stream_t *) * (p_sys->i_streams + 1) );
969 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
970 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
977 /* Remove filters from graph */
978 p_sys->p_graph->RemoveFilter( p_device_filter );
979 p_sys->p_graph->RemoveFilter( p_capture_filter );
981 /* Release objects */
982 p_device_filter->Release();
983 p_capture_filter->Release();
989 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
990 list<string> *p_listdevices, vlc_bool_t b_audio )
992 IBaseFilter *p_base_filter = NULL;
993 IMoniker *p_moniker = NULL;
997 /* Create the system device enumerator */
998 ICreateDevEnum *p_dev_enum = NULL;
1000 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
1001 IID_ICreateDevEnum, (void **)&p_dev_enum );
1004 msg_Err( p_this, "failed to create the device enumerator (0x%lx)", hr);
1008 /* Create an enumerator for the video capture devices */
1009 IEnumMoniker *p_class_enum = NULL;
1011 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
1014 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
1016 p_dev_enum->Release();
1019 msg_Err( p_this, "failed to create the class enumerator (0x%lx)", hr );
1023 /* If there are no enumerators for the requested type, then
1024 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
1025 if( p_class_enum == NULL )
1027 msg_Err( p_this, "no capture device was detected" );
1031 /* Enumerate the devices */
1033 /* Note that if the Next() call succeeds but there are no monikers,
1034 * it will return S_FALSE (which is not a failure). Therefore, we check
1035 * that the return code is S_OK instead of using SUCCEEDED() macro. */
1037 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
1039 /* Getting the property page to get the device name */
1040 IPropertyBag *p_bag;
1041 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
1047 hr = p_bag->Read( L"FriendlyName", &var, NULL );
1051 int i_convert = ( lstrlenW( var.bstrVal ) + 1 ) * 2;
1052 char *p_buf = (char *)alloca( i_convert ); p_buf[0] = 0;
1053 WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, p_buf,
1054 i_convert, NULL, NULL );
1055 SysFreeString(var.bstrVal);
1057 if( p_listdevices ) p_listdevices->push_back( p_buf );
1059 if( p_devicename && *p_devicename == string(p_buf) )
1061 /* Bind Moniker to a filter object */
1062 hr = p_moniker->BindToObject( 0, 0, IID_IBaseFilter,
1063 (void **)&p_base_filter );
1066 msg_Err( p_this, "couldn't bind moniker to filter "
1067 "object (0x%lx)", hr );
1068 p_moniker->Release();
1069 p_class_enum->Release();
1072 p_moniker->Release();
1073 p_class_enum->Release();
1074 return p_base_filter;
1079 p_moniker->Release();
1082 p_class_enum->Release();
1086 static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
1087 int i_fourcc, int i_width, int i_height,
1088 int i_channels, int i_samplespersec,
1089 int i_bitspersample, AM_MEDIA_TYPE *mt,
1092 IEnumPins *p_enumpins;
1094 IEnumMediaTypes *p_enummt;
1095 size_t mt_count = 0;
1097 if( FAILED(p_filter->EnumPins( &p_enumpins )) )
1099 msg_Dbg( p_this, "EnumDeviceCaps failed: no pin enumeration !");
1103 while( S_OK == p_enumpins->Next( 1, &p_output_pin, NULL ) )
1107 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1109 msg_Dbg( p_this, "EnumDeviceCaps: %s pin: %S",
1110 info.dir == PINDIR_INPUT ? "input" : "output",
1112 if( info.pFilter ) info.pFilter->Release();
1115 p_output_pin->Release();
1118 p_enumpins->Reset();
1120 while( !mt_count && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
1124 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1126 if( info.pFilter ) info.pFilter->Release();
1127 if( info.dir == PINDIR_INPUT )
1129 p_output_pin->Release();
1132 msg_Dbg( p_this, "EnumDeviceCaps: trying pin %S", info.achName );
1136 if( !SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
1138 p_output_pin->Release();
1142 AM_MEDIA_TYPE *p_mt;
1143 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
1145 int i_current_fourcc = GetFourCCFromMediaType( *p_mt );
1146 if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Video )
1148 int i_current_width = p_mt->pbFormat ?
1149 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth :0;
1150 int i_current_height = p_mt->pbFormat ?
1151 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight :0;
1152 if( i_current_height < 0 )
1153 i_current_height = -i_current_height;
1155 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1156 "accepts chroma: %4.4s, width:%i, height:%i",
1157 (char *)&i_current_fourcc, i_current_width,
1160 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1161 ( !i_width || i_width == i_current_width ) &&
1162 ( !i_height || i_height == i_current_height ) &&
1166 mt[mt_count++] = *p_mt;
1168 else FreeMediaType( *p_mt );
1170 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Audio )
1172 int i_current_channels =
1173 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
1174 int i_current_samplespersec =
1175 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
1176 int i_current_bitspersample =
1177 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
1179 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1180 "accepts format: %4.4s, channels:%i, "
1181 "samples/sec:%i bits/sample:%i",
1182 (char *)&i_current_fourcc, i_current_channels,
1183 i_current_samplespersec, i_current_bitspersample);
1185 if( (!i_channels || i_channels == i_current_channels) &&
1186 (!i_samplespersec ||
1187 i_samplespersec == i_current_samplespersec) &&
1188 (!i_bitspersample ||
1189 i_bitspersample == i_current_bitspersample) &&
1193 mt[mt_count++] = *p_mt;
1195 /* Setup a few properties like the audio latency */
1196 IAMBufferNegotiation *p_ambuf;
1197 if( SUCCEEDED( p_output_pin->QueryInterface(
1198 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
1200 ALLOCATOR_PROPERTIES AllocProp;
1201 AllocProp.cbAlign = -1;
1203 /* 100 ms of latency */
1204 AllocProp.cbBuffer = i_current_channels *
1205 i_current_samplespersec *
1206 i_current_bitspersample / 8 / 10;
1208 AllocProp.cbPrefix = -1;
1209 AllocProp.cBuffers = -1;
1210 p_ambuf->SuggestAllocatorProperties( &AllocProp );
1214 else FreeMediaType( *p_mt );
1216 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Stream )
1218 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1219 "accepts stream format: %4.4s",
1220 (char *)&i_current_fourcc );
1222 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1226 mt[mt_count++] = *p_mt;
1227 i_fourcc = i_current_fourcc;
1229 else FreeMediaType( *p_mt );
1233 char *psz_type = "unknown";
1234 if( p_mt->majortype == MEDIATYPE_Video ) psz_type = "video";
1235 if( p_mt->majortype == MEDIATYPE_Audio ) psz_type = "audio";
1236 if( p_mt->majortype == MEDIATYPE_Stream ) psz_type = "stream";
1237 msg_Dbg( p_this, "EnumDeviceCaps: input pin: unknown format "
1238 "(%s %4.4s)", psz_type, (char *)&p_mt->subtype );
1239 FreeMediaType( *p_mt );
1241 CoTaskMemFree( (PVOID)p_mt );
1244 p_enummt->Release();
1245 p_output_pin->Release();
1248 p_enumpins->Release();
1252 /*****************************************************************************
1253 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1254 *****************************************************************************
1255 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1257 *****************************************************************************/
1258 static block_t *ReadCompressed( access_t *p_access )
1260 access_sys_t *p_sys = p_access->p_sys;
1261 dshow_stream_t *p_stream = NULL;
1262 VLCMediaSample sample;
1264 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1266 /* There must be only 1 elementary stream to produce a valid stream
1267 * of MPEG or DV data */
1268 p_stream = p_sys->pp_streams[0];
1272 if( p_access->b_die || p_access->b_error ) return 0;
1274 /* Get new sample/frame from the elementary stream (blocking). */
1275 vlc_mutex_lock( &p_sys->lock );
1277 if( p_stream->p_capture_filter->CustomGetPin()
1278 ->CustomGetSample( &sample ) != S_OK )
1280 /* No data available. Wait until some data has arrived */
1281 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1282 vlc_mutex_unlock( &p_sys->lock );
1286 vlc_mutex_unlock( &p_sys->lock );
1293 int i_data_size = sample.p_sample->GetActualDataLength();
1295 if( !i_data_size || !(p_block = block_New( p_access, i_data_size )) )
1297 sample.p_sample->Release();
1301 sample.p_sample->GetPointer( &p_data );
1302 p_access->p_vlc->pf_memcpy( p_block->p_buffer, p_data, i_data_size );
1303 sample.p_sample->Release();
1305 /* The caller got what he wanted */
1309 return 0; /* never reached */
1312 /****************************************************************************
1314 ****************************************************************************/
1315 static int Demux( demux_t *p_demux )
1317 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
1318 dshow_stream_t *p_stream = NULL;
1319 VLCMediaSample sample;
1320 int i_data_size, i_stream;
1324 vlc_mutex_lock( &p_sys->lock );
1326 /* Try to grab an audio sample (audio has a higher priority) */
1327 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1329 p_stream = p_sys->pp_streams[i_stream];
1330 if( p_stream->mt.majortype == MEDIATYPE_Audio &&
1331 p_stream->p_capture_filter &&
1332 p_stream->p_capture_filter->CustomGetPin()
1333 ->CustomGetSample( &sample ) == S_OK )
1338 /* Try to grab a video sample */
1339 if( i_stream == p_sys->i_streams )
1340 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1342 p_stream = p_sys->pp_streams[i_stream];
1343 if( p_stream->p_capture_filter &&
1344 p_stream->p_capture_filter->CustomGetPin()
1345 ->CustomGetSample( &sample ) == S_OK )
1351 vlc_mutex_unlock( &p_sys->lock );
1353 if( i_stream == p_sys->i_streams )
1355 /* Sleep so we do not consume all the cpu, 10ms seems
1356 * like a good value (100fps) */
1364 i_data_size = sample.p_sample->GetActualDataLength();
1365 sample.p_sample->GetPointer( &p_data );
1367 REFERENCE_TIME i_pts, i_end_date;
1368 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1369 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1373 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1375 /* Use our data timestamp */
1376 i_pts = sample.i_timestamp;
1377 p_stream->b_pts = VLC_TRUE;
1381 i_pts /= 10; /* Dshow works with 100 nano-seconds resolution */
1384 msg_Dbg( p_demux, "Read() stream: %i, size: %i, PTS: "I64Fd,
1385 i_stream, i_data_size, i_pts );
1388 p_block = block_New( p_demux, i_data_size );
1389 p_demux->p_vlc->pf_memcpy( p_block->p_buffer, p_data, i_data_size );
1390 p_block->i_pts = p_block->i_dts = i_pts;
1391 sample.p_sample->Release();
1393 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pts > 0 ? i_pts : 0 );
1394 es_out_Send( p_demux->out, p_stream->p_es, p_block );
1399 /*****************************************************************************
1401 *****************************************************************************/
1402 static int AccessControl( access_t *p_access, int i_query, va_list args )
1404 vlc_bool_t *pb_bool;
1411 case ACCESS_CAN_SEEK:
1412 case ACCESS_CAN_FASTSEEK:
1413 case ACCESS_CAN_PAUSE:
1414 case ACCESS_CAN_CONTROL_PACE:
1415 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
1416 *pb_bool = VLC_FALSE;
1420 case ACCESS_GET_MTU:
1421 pi_int = (int*)va_arg( args, int * );
1425 case ACCESS_GET_PTS_DELAY:
1426 pi_64 = (int64_t*)va_arg( args, int64_t * );
1427 *pi_64 = (int64_t)var_GetInteger( p_access, "dshow-caching" ) * 1000;
1431 case ACCESS_SET_PAUSE_STATE:
1432 case ACCESS_GET_TITLE_INFO:
1433 case ACCESS_SET_TITLE:
1434 case ACCESS_SET_SEEKPOINT:
1435 case ACCESS_SET_PRIVATE_ID_STATE:
1436 return VLC_EGENERIC;
1439 msg_Warn( p_access, "unimplemented query in control" );
1440 return VLC_EGENERIC;
1446 /****************************************************************************
1448 ****************************************************************************/
1449 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
1456 /* Special for access_demux */
1457 case DEMUX_CAN_PAUSE:
1458 case DEMUX_SET_PAUSE_STATE:
1459 case DEMUX_CAN_CONTROL_PACE:
1460 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
1464 case DEMUX_GET_PTS_DELAY:
1465 pi64 = (int64_t*)va_arg( args, int64_t * );
1466 *pi64 = (int64_t)var_GetInteger( p_demux, "dshow-caching" ) * 1000;
1469 case DEMUX_GET_TIME:
1470 pi64 = (int64_t*)va_arg( args, int64_t * );
1474 /* TODO implement others */
1476 return VLC_EGENERIC;
1479 return VLC_EGENERIC;
1482 /*****************************************************************************
1483 * config variable callback
1484 *****************************************************************************/
1485 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1486 vlc_value_t newval, vlc_value_t oldval, void * )
1488 module_config_t *p_item;
1489 vlc_bool_t b_audio = VLC_FALSE;
1492 p_item = config_FindConfig( p_this, psz_name );
1493 if( !p_item ) return VLC_SUCCESS;
1495 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1497 /* Clear-up the current list */
1498 if( p_item->i_list )
1500 /* Keep the 2 first entries */
1501 for( i = 2; i < p_item->i_list; i++ )
1503 free( p_item->ppsz_list[i] );
1504 free( p_item->ppsz_list_text[i] );
1506 /* TODO: Remove when no more needed */
1507 p_item->ppsz_list[i] = NULL;
1508 p_item->ppsz_list_text[i] = NULL;
1512 /* Find list of devices */
1513 list<string> list_devices;
1515 /* Initialize OLE/COM */
1518 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1520 /* Uninitialize OLE/COM */
1523 if( !list_devices.size() ) return VLC_SUCCESS;
1526 (char **)realloc( p_item->ppsz_list,
1527 (list_devices.size()+3) * sizeof(char *) );
1528 p_item->ppsz_list_text =
1529 (char **)realloc( p_item->ppsz_list_text,
1530 (list_devices.size()+3) * sizeof(char *) );
1532 list<string>::iterator iter;
1533 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1536 p_item->ppsz_list[i] = strdup( iter->c_str() );
1537 p_item->ppsz_list_text[i] = NULL;
1540 p_item->ppsz_list[i] = NULL;
1541 p_item->ppsz_list_text[i] = NULL;
1543 /* Signal change to the interface */
1544 p_item->b_dirty = VLC_TRUE;
1549 static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1550 vlc_value_t newval, vlc_value_t oldval, void * )
1552 module_config_t *p_item;
1553 vlc_bool_t b_audio = VLC_FALSE;
1555 /* Initialize OLE/COM */
1558 p_item = config_FindConfig( p_this, psz_name );
1559 if( !p_item ) return VLC_SUCCESS;
1561 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1565 if( newval.psz_string && *newval.psz_string )
1567 devicename = newval.psz_string;
1571 /* If no device name was specified, pick the 1st one */
1572 list<string> list_devices;
1574 /* Enumerate devices */
1575 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1576 if( !list_devices.size() ) return VLC_EGENERIC;
1577 devicename = *list_devices.begin();
1580 IBaseFilter *p_device_filter =
1581 FindCaptureDevice( p_this, &devicename, NULL, b_audio );
1582 if( p_device_filter )
1584 ShowPropertyPage( p_device_filter );
1588 /* Uninitialize OLE/COM */
1591 msg_Err( p_this, "didn't find device: %s", devicename.c_str() );
1592 return VLC_EGENERIC;
1595 /* Uninitialize OLE/COM */
1601 /*****************************************************************************
1603 *****************************************************************************/
1604 static void ShowPropertyPage( IUnknown *obj )
1606 ISpecifyPropertyPages *p_spec;
1609 HRESULT hr = obj->QueryInterface( IID_ISpecifyPropertyPages,
1611 if( FAILED(hr) ) return;
1613 if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
1615 if( cauuid.cElems > 0 )
1617 HWND hwnd_desktop = ::GetDesktopWindow();
1619 OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
1620 cauuid.cElems, cauuid.pElems, 0, 0, NULL );
1622 CoTaskMemFree( cauuid.pElems );
1628 static void ShowDeviceProperties( vlc_object_t *p_this,
1629 ICaptureGraphBuilder2 *p_capture_graph,
1630 IBaseFilter *p_device_filter,
1631 vlc_bool_t b_audio )
1634 msg_Dbg( p_this, "Configuring Device Properties" );
1637 * Video or audio capture filter page
1639 ShowPropertyPage( p_device_filter );
1644 if( p_capture_graph && b_audio )
1646 IAMStreamConfig *p_SC;
1648 msg_Dbg( p_this, "Showing WDM Audio Configuration Pages" );
1650 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1651 &MEDIATYPE_Audio, p_device_filter,
1652 IID_IAMStreamConfig,
1656 ShowPropertyPage(p_SC);
1664 HRESULT hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1665 &MEDIATYPE_Audio, p_device_filter,
1666 IID_IAMTVAudio, (void **)&p_TVA );
1669 ShowPropertyPage(p_TVA);
1677 if( p_capture_graph && !b_audio )
1679 IAMStreamConfig *p_SC;
1681 msg_Dbg( p_this, "Showing WDM Video Configuration Pages" );
1683 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1684 &MEDIATYPE_Interleaved,
1686 IID_IAMStreamConfig,
1690 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1693 IID_IAMStreamConfig,
1699 ShowPropertyPage(p_SC);
1705 static void ShowTunerProperties( vlc_object_t *p_this,
1706 ICaptureGraphBuilder2 *p_capture_graph,
1707 IBaseFilter *p_device_filter,
1708 vlc_bool_t b_audio )
1711 msg_Dbg( p_this, "Configuring Tuner Properties" );
1713 if( p_capture_graph && !b_audio )
1716 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1717 &MEDIATYPE_Interleaved,
1719 IID_IAMTVTuner, (void **)&p_TV );
1722 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1731 ShowPropertyPage(p_TV);