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 int ReadCompressed( access_t *, byte_t *, int );
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 = (dshow_stream_t **)malloc( 1 );
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 /* Build directshow graph */
319 CreateDirectShowGraph( p_sys );
321 if( OpenDevice( p_this, p_sys, vdevname, 0 ) != VLC_SUCCESS )
323 msg_Err( p_this, "can't open video");
327 /* Check if we can handle the demuxing ourselves or need to spawn
328 * a demuxer module */
329 dshow_stream_t *p_stream = p_sys->pp_streams[p_sys->i_streams-1];
331 if( p_stream->mt.majortype == MEDIATYPE_Video )
333 if( /* Raw DV stream */
334 p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
335 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
336 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') ||
337 /* Raw MPEG video stream */
338 p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
344 if( p_stream->mt.majortype == MEDIATYPE_Stream ) b_audio = VLC_FALSE;
347 if( b_audio && OpenDevice( p_this, p_sys, adevname, 1 ) != VLC_SUCCESS )
349 msg_Err( p_this, "can't open audio");
352 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
354 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
355 LONG VideoInputIndex = p_sys->crossbar_routes[i].VideoInputIndex;
356 LONG VideoOutputIndex = p_sys->crossbar_routes[i].VideoOutputIndex;
357 LONG AudioInputIndex = p_sys->crossbar_routes[i].AudioInputIndex;
358 LONG AudioOutputIndex = p_sys->crossbar_routes[i].AudioOutputIndex;
360 if( SUCCEEDED(pXbar->Route(VideoOutputIndex, VideoInputIndex)) )
362 msg_Dbg( p_this, "Crossbar at depth %d, Routed video "
363 "ouput %ld to video input %ld", i, VideoOutputIndex,
366 if( AudioOutputIndex != -1 && AudioInputIndex != -1 )
368 if( SUCCEEDED( pXbar->Route(AudioOutputIndex,
371 msg_Dbg(p_this, "Crossbar at depth %d, Routed audio "
372 "ouput %ld to audio input %ld", i,
373 AudioOutputIndex, AudioInputIndex );
380 ** Show properties pages from other filters in graph
382 var_Get( p_this, "dshow-config", &val );
385 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
387 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
390 if( SUCCEEDED( pXbar->QueryInterface( IID_IBaseFilter,
393 ShowPropertyPage( p_XF );
399 /* Initialize some data */
400 p_sys->i_current_stream = 0;
401 vlc_mutex_init( p_this, &p_sys->lock );
402 vlc_cond_init( p_this, &p_sys->wait );
404 if( !p_sys->i_streams ) return VLC_EGENERIC;
409 /*****************************************************************************
410 * DemuxOpen: open direct show device as an access_demux module
411 *****************************************************************************/
412 static int DemuxOpen( vlc_object_t *p_this )
414 demux_t *p_demux = (demux_t *)p_this;
418 p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
419 memset( p_sys, 0, sizeof( access_sys_t ) );
420 p_demux->p_sys = (demux_sys_t *)p_sys;
422 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
424 CommonClose( p_this, p_sys );
428 /* Everything is ready. Let's rock baby */
429 msg_Dbg( p_this, "Playing...");
430 p_sys->p_control->Run();
432 p_demux->pf_demux = Demux;
433 p_demux->pf_control = DemuxControl;
434 p_demux->info.i_update = 0;
435 p_demux->info.i_title = 0;
436 p_demux->info.i_seekpoint = 0;
438 for( i = 0; i < p_sys->i_streams; i++ )
440 dshow_stream_t *p_stream = p_sys->pp_streams[i];
443 if( p_stream->mt.majortype == MEDIATYPE_Video )
445 es_format_Init( &fmt, VIDEO_ES, p_stream->i_fourcc );
447 fmt.video.i_width = p_stream->header.video.bmiHeader.biWidth;
448 fmt.video.i_height = p_stream->header.video.bmiHeader.biHeight;
449 fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
451 if( !p_stream->header.video.bmiHeader.biCompression )
453 /* RGB DIB are coded from bottom to top */
454 fmt.video.i_height = (unsigned int)(-(int)fmt.video.i_height);
457 /* Setup rgb mask for RGB formats */
458 if( p_stream->i_fourcc == VLC_FOURCC('R','V','2','4') )
460 /* This is in BGR format */
461 fmt.video.i_bmask = 0x00ff0000;
462 fmt.video.i_gmask = 0x0000ff00;
463 fmt.video.i_rmask = 0x000000ff;
466 else if( p_stream->mt.majortype == MEDIATYPE_Audio )
468 es_format_Init( &fmt, AUDIO_ES, p_stream->i_fourcc );
470 fmt.audio.i_channels = p_stream->header.audio.nChannels;
471 fmt.audio.i_rate = p_stream->header.audio.nSamplesPerSec;
472 fmt.audio.i_bitspersample = p_stream->header.audio.wBitsPerSample;
473 fmt.audio.i_blockalign = fmt.audio.i_channels *
474 fmt.audio.i_bitspersample / 8;
475 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
476 fmt.audio.i_bitspersample;
479 p_stream->p_es = es_out_Add( p_demux->out, &fmt );
485 /*****************************************************************************
486 * AccessOpen: open direct show device as an access module
487 *****************************************************************************/
488 static int AccessOpen( vlc_object_t *p_this )
490 access_t *p_access = (access_t*)p_this;
493 p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
494 memset( p_sys, 0, sizeof( access_sys_t ) );
496 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
498 CommonClose( p_this, p_sys );
502 dshow_stream_t *p_stream = p_sys->pp_streams[0];
504 /* Check if we need to force demuxers */
505 if( !p_access->psz_demux || !*p_access->psz_demux )
507 if( p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
508 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
509 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') )
511 p_access->psz_demux = strdup( "rawdv" );
513 else if( p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
515 p_access->psz_demux = "mpgv";
520 p_access->pf_read = ReadCompressed;
521 p_access->pf_block = NULL;
522 p_access->pf_control = AccessControl;
523 p_access->pf_seek = NULL;
524 p_access->info.i_update = 0;
525 p_access->info.i_size = 0;
526 p_access->info.i_pos = 0;
527 p_access->info.b_eof = VLC_FALSE;
528 p_access->info.i_title = 0;
529 p_access->info.i_seekpoint = 0;
530 p_access->p_sys = p_sys;
532 /* Everything is ready. Let's rock baby */
533 msg_Dbg( p_this, "Playing...");
534 p_sys->p_control->Run();
539 /*****************************************************************************
540 * CommonClose: close device
541 *****************************************************************************/
542 static void CommonClose( vlc_object_t *p_this, access_sys_t *p_sys )
544 msg_Dbg( p_this, "Releasing DirectShow");
546 DeleteDirectShowGraph( p_sys );
548 /* Uninitialize OLE/COM */
551 /* Remove filters from graph */
552 for( int i = 0; i < p_sys->i_streams; i++ )
554 delete p_sys->pp_streams[i];
556 free( p_sys->pp_streams );
558 vlc_mutex_destroy( &p_sys->lock );
559 vlc_cond_destroy( &p_sys->wait );
564 /*****************************************************************************
565 * AccessClose: close device
566 *****************************************************************************/
567 static void AccessClose( vlc_object_t *p_this )
569 access_t *p_access = (access_t *)p_this;
570 access_sys_t *p_sys = p_access->p_sys;
572 /* Stop capturing stuff */
573 p_sys->p_control->Stop();
575 CommonClose( p_this, p_sys );
578 /*****************************************************************************
579 * DemuxClose: close device
580 *****************************************************************************/
581 static void DemuxClose( vlc_object_t *p_this )
583 demux_t *p_demux = (demux_t *)p_this;
584 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
586 /* Stop capturing stuff */
587 p_sys->p_control->Stop();
589 CommonClose( p_this, p_sys );
592 /****************************************************************************
594 ****************************************************************************/
595 static bool ConnectFilters( vlc_object_t *p_this, access_sys_t *p_sys,
596 IBaseFilter *p_filter,
597 CaptureFilter *p_capture_filter )
599 CapturePin *p_input_pin = p_capture_filter->CustomGetPin();
601 AM_MEDIA_TYPE mediaType = p_input_pin->CustomGetMediaType();
603 if( p_sys->p_capture_graph_builder2 )
605 if( FAILED(p_sys->p_capture_graph_builder2->
606 RenderStream( &PIN_CATEGORY_CAPTURE, &mediaType.majortype,
607 p_filter, 0, (IBaseFilter *)p_capture_filter )) )
612 // Sort out all the possible video inputs
613 // The class needs to be given the capture filters ANALOGVIDEO input pin
615 if( mediaType.majortype == MEDIATYPE_Video &&
616 SUCCEEDED(p_filter->EnumPins(&pins)) )
622 IKsPropertySet *pKs=0;
626 while( !Found && ( S_OK == pins->Next(1, &pP, &n) ) )
628 if( S_OK == pP->QueryPinInfo(&pinInfo) )
630 // is this pin an ANALOGVIDEOIN input pin?
631 if( pinInfo.dir == PINDIR_INPUT &&
632 pP->QueryInterface( IID_IKsPropertySet,
633 (void **)&pKs ) == S_OK )
635 if( pKs->Get( AMPROPSETID_Pin,
636 AMPROPERTY_PIN_CATEGORY, NULL, 0,
637 &guid, sizeof(GUID), &dw ) == S_OK )
639 if( guid == PIN_CATEGORY_ANALOGVIDEOIN )
641 // recursively search crossbar routes
642 FindCrossbarRoutes( p_this, p_sys, pP, 0 );
649 pinInfo.pFilter->Release();
659 IEnumPins *p_enumpins;
662 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
664 while( S_OK == p_enumpins->Next( 1, &p_pin, NULL ) )
666 PIN_DIRECTION pin_dir;
667 p_pin->QueryDirection( &pin_dir );
669 if( pin_dir == PINDIR_OUTPUT &&
670 p_sys->p_graph->ConnectDirect( p_pin, (IPin *)p_input_pin,
674 p_enumpins->Release();
680 p_enumpins->Release();
686 * get fourcc priority from arbritary preference, the higher the better
688 static int GetFourCCPriority( int i_fourcc )
692 case VLC_FOURCC('I','4','2','0'):
693 case VLC_FOURCC('f','l','3','2'):
695 case VLC_FOURCC('Y','V','1','2'):
696 case VLC_FOURCC('a','r','a','w'):
698 case VLC_FOURCC('R','V','2','4'):
700 case VLC_FOURCC('Y','U','Y','2'):
701 case VLC_FOURCC('R','V','3','2'):
702 case VLC_FOURCC('R','G','B','A'):
709 #define MAX_MEDIA_TYPES 32
711 static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
712 string devicename, vlc_bool_t b_audio )
714 /* See if device is already opened */
715 for( int i = 0; i < p_sys->i_streams; i++ )
717 if( devicename.size() &&
718 p_sys->pp_streams[i]->devicename == devicename )
725 list<string> list_devices;
727 /* Enumerate devices and display their names */
728 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
730 if( !list_devices.size() )
733 list<string>::iterator iter;
734 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
735 msg_Dbg( p_this, "found device: %s", iter->c_str() );
737 /* If no device name was specified, pick the 1st one */
738 if( devicename.size() == 0 )
740 devicename = *list_devices.begin();
743 // Use the system device enumerator and class enumerator to find
744 // a capture/preview device, such as a desktop USB video camera.
745 IBaseFilter *p_device_filter =
746 FindCaptureDevice( p_this, &devicename, 0, b_audio );
747 if( p_device_filter )
748 msg_Dbg( p_this, "using device: %s", devicename.c_str() );
751 msg_Err( p_this, "can't use device: %s, unsupported device type",
752 devicename.c_str() );
757 AM_MEDIA_TYPE *mt = NULL;
761 // Insert prefered video media type
765 mtr.majortype = MEDIATYPE_Video;
766 mtr.subtype = MEDIASUBTYPE_I420;
767 mtr.bFixedSizeSamples = TRUE;
768 mtr.bTemporalCompression = FALSE;
770 mtr.formattype = FORMAT_VideoInfo;
771 mtr.cbFormat = sizeof(vh);
772 mtr.pbFormat = (BYTE *)&vh;
774 memset(&vh, 0, sizeof(vh));
776 vh.bmiHeader.biSize = sizeof(vh.bmiHeader);
777 vh.bmiHeader.biWidth = p_sys->i_width > 0 ? p_sys->i_width : 320;
778 vh.bmiHeader.biHeight = p_sys->i_height > 0 ? p_sys->i_height : 240;
779 vh.bmiHeader.biPlanes = 3;
780 vh.bmiHeader.biBitCount = 12;
781 vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0');
782 vh.bmiHeader.biSizeImage = vh.bmiHeader.biWidth * 12 *
783 vh.bmiHeader.biHeight / 8;
784 mtr.lSampleSize = vh.bmiHeader.biSizeImage;
787 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
788 CopyMediaType(mt, &mtr);
792 // Insert prefered audio media type
796 mtr.majortype = MEDIATYPE_Audio;
797 mtr.subtype = MEDIASUBTYPE_PCM;
798 mtr.bFixedSizeSamples = TRUE;
799 mtr.bTemporalCompression = FALSE;
802 mtr.formattype = FORMAT_WaveFormatEx;
803 mtr.cbFormat = sizeof(wf);
804 mtr.pbFormat = (BYTE *)&wf;
806 memset(&wf, 0, sizeof(wf));
808 wf.wFormatTag = WAVE_FORMAT_PCM;
810 wf.nSamplesPerSec = 44100;
811 wf.wBitsPerSample = 16;
812 wf.nBlockAlign = wf.nSamplesPerSec * wf.wBitsPerSample / 8;
813 wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
817 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
818 CopyMediaType(mt, &mtr);
821 // Retreive acceptable media types supported by device
822 AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
824 EnumDeviceCaps( p_this, p_device_filter, p_sys->i_chroma,
825 p_sys->i_width, p_sys->i_height,
826 0, 0, 0, media_types, MAX_MEDIA_TYPES );
828 if( media_count > 0 )
830 mt = (AM_MEDIA_TYPE *)realloc( mt, sizeof(AM_MEDIA_TYPE) *
831 (mt_count + media_count) );
833 // Order and copy returned media types according to arbitrary
835 for( size_t c = 0; c < media_count; c++ )
838 GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
839 size_t slot_copy = c;
840 for( size_t d = c+1; d < media_count; d++ )
843 GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
844 if( priority > slot_priority )
846 slot_priority = priority;
852 mt[c+mt_count] = media_types[slot_copy];
853 media_types[slot_copy] = media_types[c];
857 mt[c+mt_count] = media_types[c];
860 mt_count += media_count;
863 /* Create and add our capture filter */
864 CaptureFilter *p_capture_filter =
865 new CaptureFilter( p_this, p_sys, mt, mt_count );
866 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
868 /* Add the device filter to the graph (seems necessary with VfW before
869 * accessing pin attributes). */
870 p_sys->p_graph->AddFilter( p_device_filter, 0 );
872 /* Attempt to connect one of this device's capture output pins */
873 msg_Dbg( p_this, "connecting filters" );
874 if( ConnectFilters( p_this, p_sys, p_device_filter, p_capture_filter ) )
877 msg_Dbg( p_this, "filters connected successfully !" );
879 dshow_stream_t dshow_stream;
880 dshow_stream.b_pts = VLC_FALSE;
881 dshow_stream.p_es = 0;
883 p_capture_filter->CustomGetPin()->CustomGetMediaType();
885 /* Show Device properties. Done here so the VLC stream is setup with
886 * the proper parameters. */
888 var_Get( p_this, "dshow-config", &val );
891 ShowDeviceProperties( p_this, p_sys->p_capture_graph_builder2,
892 p_device_filter, b_audio );
895 var_Get( p_this, "dshow-tuner", &val );
898 ShowTunerProperties( p_this, p_sys->p_capture_graph_builder2,
899 p_device_filter, b_audio );
903 p_capture_filter->CustomGetPin()->CustomGetMediaType();
905 dshow_stream.i_fourcc = GetFourCCFromMediaType( dshow_stream.mt );
906 if( dshow_stream.i_fourcc )
908 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
910 dshow_stream.header.video =
911 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
912 msg_Dbg( p_this, "MEDIATYPE_Video" );
913 msg_Dbg( p_this, "selected video pin accepts format: %4.4s",
914 (char *)&dshow_stream.i_fourcc);
916 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio )
918 dshow_stream.header.audio =
919 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
920 msg_Dbg( p_this, "MEDIATYPE_Audio" );
921 msg_Dbg( p_this, "selected audio pin accepts format: %4.4s",
922 (char *)&dshow_stream.i_fourcc);
924 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
926 msg_Dbg( p_this, "MEDIATYPE_Stream" );
927 msg_Dbg( p_this, "selected stream pin accepts format: %4.4s",
928 (char *)&dshow_stream.i_fourcc);
932 msg_Dbg( p_this, "unknown stream majortype" );
936 /* Add directshow elementary stream to our list */
937 dshow_stream.p_device_filter = p_device_filter;
938 dshow_stream.p_capture_filter = p_capture_filter;
940 p_sys->pp_streams = (dshow_stream_t **)realloc( p_sys->pp_streams,
941 sizeof(dshow_stream_t *) * (p_sys->i_streams + 1) );
942 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
943 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
950 /* Remove filters from graph */
951 p_sys->p_graph->RemoveFilter( p_device_filter );
952 p_sys->p_graph->RemoveFilter( p_capture_filter );
954 /* Release objects */
955 p_device_filter->Release();
956 p_capture_filter->Release();
962 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
963 list<string> *p_listdevices, vlc_bool_t b_audio )
965 IBaseFilter *p_base_filter = NULL;
966 IMoniker *p_moniker = NULL;
970 /* Create the system device enumerator */
971 ICreateDevEnum *p_dev_enum = NULL;
973 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
974 IID_ICreateDevEnum, (void **)&p_dev_enum );
977 msg_Err( p_this, "failed to create the device enumerator (0x%lx)", hr);
981 /* Create an enumerator for the video capture devices */
982 IEnumMoniker *p_class_enum = NULL;
984 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
987 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
989 p_dev_enum->Release();
992 msg_Err( p_this, "failed to create the class enumerator (0x%lx)", hr );
996 /* If there are no enumerators for the requested type, then
997 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
998 if( p_class_enum == NULL )
1000 msg_Err( p_this, "no capture device was detected" );
1004 /* Enumerate the devices */
1006 /* Note that if the Next() call succeeds but there are no monikers,
1007 * it will return S_FALSE (which is not a failure). Therefore, we check
1008 * that the return code is S_OK instead of using SUCCEEDED() macro. */
1010 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
1012 /* Getting the property page to get the device name */
1013 IPropertyBag *p_bag;
1014 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
1020 hr = p_bag->Read( L"FriendlyName", &var, NULL );
1024 int i_convert = ( lstrlenW( var.bstrVal ) + 1 ) * 2;
1025 char *p_buf = (char *)alloca( i_convert ); p_buf[0] = 0;
1026 WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, p_buf,
1027 i_convert, NULL, NULL );
1028 SysFreeString(var.bstrVal);
1030 if( p_listdevices ) p_listdevices->push_back( p_buf );
1032 if( p_devicename && *p_devicename == string(p_buf) )
1034 /* Bind Moniker to a filter object */
1035 hr = p_moniker->BindToObject( 0, 0, IID_IBaseFilter,
1036 (void **)&p_base_filter );
1039 msg_Err( p_this, "couldn't bind moniker to filter "
1040 "object (0x%lx)", hr );
1041 p_moniker->Release();
1042 p_class_enum->Release();
1045 p_moniker->Release();
1046 p_class_enum->Release();
1047 return p_base_filter;
1052 p_moniker->Release();
1055 p_class_enum->Release();
1059 static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
1060 int i_fourcc, int i_width, int i_height,
1061 int i_channels, int i_samplespersec,
1062 int i_bitspersample, AM_MEDIA_TYPE *mt,
1065 IEnumPins *p_enumpins;
1067 IEnumMediaTypes *p_enummt;
1068 size_t mt_count = 0;
1070 if( FAILED(p_filter->EnumPins( &p_enumpins )) )
1072 msg_Dbg( p_this, "EnumDeviceCaps failed: no pin enumeration !");
1076 while( S_OK == p_enumpins->Next( 1, &p_output_pin, NULL ) )
1080 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1082 msg_Dbg( p_this, "EnumDeviceCaps: %s pin: %S",
1083 info.dir == PINDIR_INPUT ? "input" : "output",
1085 if( info.pFilter ) info.pFilter->Release();
1088 p_output_pin->Release();
1091 p_enumpins->Reset();
1093 while( !mt_count && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
1097 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1099 if( info.pFilter ) info.pFilter->Release();
1100 if( info.dir == PINDIR_INPUT )
1102 p_output_pin->Release();
1105 msg_Dbg( p_this, "EnumDeviceCaps: trying pin %S", info.achName );
1109 if( !SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
1111 p_output_pin->Release();
1115 AM_MEDIA_TYPE *p_mt;
1116 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
1118 int i_current_fourcc = GetFourCCFromMediaType( *p_mt );
1119 if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Video )
1121 int i_current_width = p_mt->pbFormat ?
1122 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth :0;
1123 int i_current_height = p_mt->pbFormat ?
1124 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight :0;
1125 if( i_current_height < 0 )
1126 i_current_height = -i_current_height;
1128 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1129 "accepts chroma: %4.4s, width:%i, height:%i",
1130 (char *)&i_current_fourcc, i_current_width,
1133 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1134 ( !i_width || i_width == i_current_width ) &&
1135 ( !i_height || i_height == i_current_height ) &&
1139 mt[mt_count++] = *p_mt;
1141 else FreeMediaType( *p_mt );
1143 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Audio )
1145 int i_current_channels =
1146 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
1147 int i_current_samplespersec =
1148 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
1149 int i_current_bitspersample =
1150 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
1152 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1153 "accepts format: %4.4s, channels:%i, "
1154 "samples/sec:%i bits/sample:%i",
1155 (char *)&i_current_fourcc, i_current_channels,
1156 i_current_samplespersec, i_current_bitspersample);
1158 if( (!i_channels || i_channels == i_current_channels) &&
1159 (!i_samplespersec ||
1160 i_samplespersec == i_current_samplespersec) &&
1161 (!i_bitspersample ||
1162 i_bitspersample == i_current_bitspersample) &&
1166 mt[mt_count++] = *p_mt;
1168 /* Setup a few properties like the audio latency */
1169 IAMBufferNegotiation *p_ambuf;
1170 if( SUCCEEDED( p_output_pin->QueryInterface(
1171 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
1173 ALLOCATOR_PROPERTIES AllocProp;
1174 AllocProp.cbAlign = -1;
1176 /* 100 ms of latency */
1177 AllocProp.cbBuffer = i_current_channels *
1178 i_current_samplespersec *
1179 i_current_bitspersample / 8 / 10;
1181 AllocProp.cbPrefix = -1;
1182 AllocProp.cBuffers = -1;
1183 p_ambuf->SuggestAllocatorProperties( &AllocProp );
1187 else FreeMediaType( *p_mt );
1189 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Stream )
1191 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1192 "accepts stream format: %4.4s",
1193 (char *)&i_current_fourcc );
1195 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1199 mt[mt_count++] = *p_mt;
1200 i_fourcc = i_current_fourcc;
1202 else FreeMediaType( *p_mt );
1206 char *psz_type = "unknown";
1207 if( p_mt->majortype == MEDIATYPE_Video ) psz_type = "video";
1208 if( p_mt->majortype == MEDIATYPE_Audio ) psz_type = "audio";
1209 if( p_mt->majortype == MEDIATYPE_Stream ) psz_type = "stream";
1210 msg_Dbg( p_this, "EnumDeviceCaps: input pin: unknown format "
1211 "(%s %4.4s)", psz_type, (char *)&p_mt->subtype );
1212 FreeMediaType( *p_mt );
1214 CoTaskMemFree( (PVOID)p_mt );
1217 p_enummt->Release();
1218 p_output_pin->Release();
1221 p_enumpins->Release();
1225 /*****************************************************************************
1226 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1227 *****************************************************************************
1228 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1230 *****************************************************************************/
1231 static int ReadCompressed( access_t *p_access, uint8_t *p_buffer, int i_len )
1233 access_sys_t *p_sys = p_access->p_sys;
1234 dshow_stream_t *p_stream = NULL;
1235 VLCMediaSample sample;
1239 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1241 /* There must be only 1 elementary stream to produce a valid stream
1242 * of MPEG or DV data */
1243 p_stream = p_sys->pp_streams[0];
1247 if( p_access->b_die || p_access->b_error ) return 0;
1249 /* Get new sample/frame from the elementary stream (blocking). */
1250 vlc_mutex_lock( &p_sys->lock );
1252 if( p_stream->p_capture_filter->CustomGetPin()
1253 ->CustomGetSample( &sample ) != S_OK )
1255 /* No data available. Wait until some data has arrived */
1256 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1257 vlc_mutex_unlock( &p_sys->lock );
1261 vlc_mutex_unlock( &p_sys->lock );
1266 i_data_size = sample.p_sample->GetActualDataLength();
1267 sample.p_sample->GetPointer( &p_data );
1270 msg_Info( p_access, "access read %i data_size %i", i_len, i_data_size );
1272 i_data_size = __MIN( i_data_size, (int)i_len );
1274 p_access->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1276 sample.p_sample->Release();
1278 /* The caller got what he wanted */
1282 return 0; /* never reached */
1285 /****************************************************************************
1287 ****************************************************************************/
1288 static int Demux( demux_t *p_demux )
1290 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
1291 dshow_stream_t *p_stream = NULL;
1292 VLCMediaSample sample;
1293 int i_data_size, i_stream;
1297 vlc_mutex_lock( &p_sys->lock );
1299 /* Try to grab an audio sample (audio has a higher priority) */
1300 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1302 p_stream = p_sys->pp_streams[i_stream];
1303 if( p_stream->mt.majortype == MEDIATYPE_Audio &&
1304 p_stream->p_capture_filter &&
1305 p_stream->p_capture_filter->CustomGetPin()
1306 ->CustomGetSample( &sample ) == S_OK )
1311 /* Try to grab a video sample */
1312 if( i_stream == p_sys->i_streams )
1313 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1315 p_stream = p_sys->pp_streams[i_stream];
1316 if( p_stream->p_capture_filter &&
1317 p_stream->p_capture_filter->CustomGetPin()
1318 ->CustomGetSample( &sample ) == S_OK )
1324 vlc_mutex_unlock( &p_sys->lock );
1326 if( i_stream == p_sys->i_streams )
1328 /* Sleep so we do not consume all the cpu, 10ms seems
1329 * like a good value (100fps) */
1337 i_data_size = sample.p_sample->GetActualDataLength();
1338 sample.p_sample->GetPointer( &p_data );
1340 REFERENCE_TIME i_pts, i_end_date;
1341 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1342 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1346 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1348 /* Use our data timestamp */
1349 i_pts = sample.i_timestamp;
1350 p_stream->b_pts = VLC_TRUE;
1354 i_pts /= 10; /* Dshow works with 100 nano-seconds resolution */
1357 msg_Dbg( p_demux, "Read() stream: %i, size: %i, PTS: "I64Fd,
1358 i_stream, i_data_size, i_pts );
1361 p_block = block_New( p_demux, i_data_size );
1362 p_demux->p_vlc->pf_memcpy( p_block->p_buffer, p_data, i_data_size );
1363 p_block->i_pts = p_block->i_dts = i_pts;
1364 sample.p_sample->Release();
1366 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pts > 0 ? i_pts : 0 );
1367 es_out_Send( p_demux->out, p_stream->p_es, p_block );
1372 /*****************************************************************************
1374 *****************************************************************************/
1375 static int AccessControl( access_t *p_access, int i_query, va_list args )
1377 vlc_bool_t *pb_bool;
1384 case ACCESS_CAN_SEEK:
1385 case ACCESS_CAN_FASTSEEK:
1386 case ACCESS_CAN_PAUSE:
1387 case ACCESS_CAN_CONTROL_PACE:
1388 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
1389 *pb_bool = VLC_FALSE;
1393 case ACCESS_GET_MTU:
1394 pi_int = (int*)va_arg( args, int * );
1398 case ACCESS_GET_PTS_DELAY:
1399 pi_64 = (int64_t*)va_arg( args, int64_t * );
1400 *pi_64 = (int64_t)var_GetInteger( p_access, "dshow-caching" ) * 1000;
1404 case ACCESS_SET_PAUSE_STATE:
1405 case ACCESS_GET_TITLE_INFO:
1406 case ACCESS_SET_TITLE:
1407 case ACCESS_SET_SEEKPOINT:
1408 case ACCESS_SET_PRIVATE_ID_STATE:
1409 return VLC_EGENERIC;
1412 msg_Warn( p_access, "unimplemented query in control" );
1413 return VLC_EGENERIC;
1419 /****************************************************************************
1421 ****************************************************************************/
1422 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
1429 /* Special for access_demux */
1430 case DEMUX_CAN_PAUSE:
1431 case DEMUX_SET_PAUSE_STATE:
1432 case DEMUX_CAN_CONTROL_PACE:
1433 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
1437 case DEMUX_GET_PTS_DELAY:
1438 pi64 = (int64_t*)va_arg( args, int64_t * );
1439 *pi64 = (int64_t)var_GetInteger( p_demux, "dshow-caching" ) * 1000;
1442 case DEMUX_GET_TIME:
1443 pi64 = (int64_t*)va_arg( args, int64_t * );
1447 /* TODO implement others */
1449 return VLC_EGENERIC;
1452 return VLC_EGENERIC;
1455 /*****************************************************************************
1456 * config variable callback
1457 *****************************************************************************/
1458 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1459 vlc_value_t newval, vlc_value_t oldval, void * )
1461 module_config_t *p_item;
1462 vlc_bool_t b_audio = VLC_FALSE;
1465 p_item = config_FindConfig( p_this, psz_name );
1466 if( !p_item ) return VLC_SUCCESS;
1468 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1470 /* Clear-up the current list */
1471 if( p_item->i_list )
1473 /* Keep the 2 first entries */
1474 for( i = 2; i < p_item->i_list; i++ )
1476 free( p_item->ppsz_list[i] );
1477 free( p_item->ppsz_list_text[i] );
1479 /* TODO: Remove when no more needed */
1480 p_item->ppsz_list[i] = NULL;
1481 p_item->ppsz_list_text[i] = NULL;
1485 /* Find list of devices */
1486 list<string> list_devices;
1488 /* Initialize OLE/COM */
1491 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1493 /* Uninitialize OLE/COM */
1496 if( !list_devices.size() ) return VLC_SUCCESS;
1499 (char **)realloc( p_item->ppsz_list,
1500 (list_devices.size()+3) * sizeof(char *) );
1501 p_item->ppsz_list_text =
1502 (char **)realloc( p_item->ppsz_list_text,
1503 (list_devices.size()+3) * sizeof(char *) );
1505 list<string>::iterator iter;
1506 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1509 p_item->ppsz_list[i] = strdup( iter->c_str() );
1510 p_item->ppsz_list_text[i] = NULL;
1513 p_item->ppsz_list[i] = NULL;
1514 p_item->ppsz_list_text[i] = NULL;
1516 /* Signal change to the interface */
1517 p_item->b_dirty = VLC_TRUE;
1522 static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1523 vlc_value_t newval, vlc_value_t oldval, void * )
1525 module_config_t *p_item;
1526 vlc_bool_t b_audio = VLC_FALSE;
1528 /* Initialize OLE/COM */
1531 p_item = config_FindConfig( p_this, psz_name );
1532 if( !p_item ) return VLC_SUCCESS;
1534 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1538 if( newval.psz_string && *newval.psz_string )
1540 devicename = newval.psz_string;
1544 /* If no device name was specified, pick the 1st one */
1545 list<string> list_devices;
1547 /* Enumerate devices */
1548 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1549 if( !list_devices.size() ) return VLC_EGENERIC;
1550 devicename = *list_devices.begin();
1553 IBaseFilter *p_device_filter =
1554 FindCaptureDevice( p_this, &devicename, NULL, b_audio );
1555 if( p_device_filter )
1557 ShowPropertyPage( p_device_filter );
1561 /* Uninitialize OLE/COM */
1564 msg_Err( p_this, "didn't find device: %s", devicename.c_str() );
1565 return VLC_EGENERIC;
1568 /* Uninitialize OLE/COM */
1574 /*****************************************************************************
1576 *****************************************************************************/
1577 static void ShowPropertyPage( IUnknown *obj )
1579 ISpecifyPropertyPages *p_spec;
1582 HRESULT hr = obj->QueryInterface( IID_ISpecifyPropertyPages,
1584 if( FAILED(hr) ) return;
1586 if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
1588 if( cauuid.cElems > 0 )
1590 HWND hwnd_desktop = ::GetDesktopWindow();
1592 OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
1593 cauuid.cElems, cauuid.pElems, 0, 0, NULL );
1595 CoTaskMemFree( cauuid.pElems );
1601 static void ShowDeviceProperties( vlc_object_t *p_this,
1602 ICaptureGraphBuilder2 *p_capture_graph,
1603 IBaseFilter *p_device_filter,
1604 vlc_bool_t b_audio )
1607 msg_Dbg( p_this, "Configuring Device Properties" );
1610 * Video or audio capture filter page
1612 ShowPropertyPage( p_device_filter );
1617 if( p_capture_graph && b_audio )
1619 IAMStreamConfig *p_SC;
1621 msg_Dbg( p_this, "Showing WDM Audio Configuration Pages" );
1623 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1624 &MEDIATYPE_Audio, p_device_filter,
1625 IID_IAMStreamConfig,
1629 ShowPropertyPage(p_SC);
1637 HRESULT hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1638 &MEDIATYPE_Audio, p_device_filter,
1639 IID_IAMTVAudio, (void **)&p_TVA );
1642 ShowPropertyPage(p_TVA);
1650 if( p_capture_graph && !b_audio )
1652 IAMStreamConfig *p_SC;
1654 msg_Dbg( p_this, "Showing WDM Video Configuration Pages" );
1656 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1657 &MEDIATYPE_Interleaved,
1659 IID_IAMStreamConfig,
1663 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1666 IID_IAMStreamConfig,
1672 ShowPropertyPage(p_SC);
1678 static void ShowTunerProperties( vlc_object_t *p_this,
1679 ICaptureGraphBuilder2 *p_capture_graph,
1680 IBaseFilter *p_device_filter,
1681 vlc_bool_t b_audio )
1684 msg_Dbg( p_this, "Configuring Tuner Properties" );
1686 if( p_capture_graph && !b_audio )
1689 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1690 &MEDIATYPE_Interleaved,
1692 IID_IAMTVTuner, (void **)&p_TV );
1695 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1704 ShowPropertyPage(p_TV);