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 );
64 /*****************************************************************************
66 *****************************************************************************/
67 static char *ppsz_vdev[] = { "", "none" };
68 static char *ppsz_vdev_text[] = { N_("Default"), N_("None") };
69 static char *ppsz_adev[] = { "", "none" };
70 static char *ppsz_adev_text[] = { N_("Default"), N_("None") };
72 #define CACHING_TEXT N_("Caching value in ms")
73 #define CACHING_LONGTEXT N_( \
74 "Allows you to modify the default caching value for DirectShow streams. " \
75 "This value should be set in milliseconds units." )
76 #define VDEV_TEXT N_("Video device name")
77 #define VDEV_LONGTEXT N_( \
78 "You can specify the name of the video device that will be used by the " \
79 "DirectShow plugin. If you don't specify anything, the default device " \
81 #define ADEV_TEXT N_("Audio device name")
82 #define ADEV_LONGTEXT N_( \
83 "You can specify the name of the audio device that will be used by the " \
84 "DirectShow plugin. If you don't specify anything, the default device " \
86 #define SIZE_TEXT N_("Video size")
87 #define SIZE_LONGTEXT N_( \
88 "You can specify the size of the video that will be displayed by the " \
89 "DirectShow plugin. If you don't specify anything the default size for " \
90 "your device will be used.")
91 #define CHROMA_TEXT N_("Video input chroma format")
92 #define CHROMA_LONGTEXT N_( \
93 "Force the DirectShow video input to use a specific chroma format " \
94 "(eg. I420 (default), RV24, etc.)")
95 #define CONFIG_TEXT N_("Device properties")
96 #define CONFIG_LONGTEXT N_( \
97 "Show the properties dialog of the selected device before starting the " \
100 static int CommonOpen ( vlc_object_t *, access_sys_t *, vlc_bool_t );
101 static void CommonClose( vlc_object_t *, access_sys_t * );
103 static int AccessOpen ( vlc_object_t * );
104 static void AccessClose( vlc_object_t * );
106 static int DemuxOpen ( vlc_object_t * );
107 static void DemuxClose ( vlc_object_t * );
110 set_shortname( _("DirectShow") );
111 set_description( _("DirectShow input") );
112 add_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,
113 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
115 add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, VLC_FALSE);
116 change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback );
117 change_action_add( FindDevicesCallback, N_("Refresh list") );
118 change_action_add( ConfigDevicesCallback, N_("Configure") );
120 add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE);
121 change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback );
122 change_action_add( FindDevicesCallback, N_("Refresh list") );
123 change_action_add( ConfigDevicesCallback, N_("Configure") );
125 add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE);
127 add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
130 add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,
133 add_shortcut( "dshow" );
134 set_capability( "access_demux", 0 );
135 set_callbacks( DemuxOpen, DemuxClose );
138 set_description( _("DirectShow input") );
139 add_shortcut( "dshow" );
140 set_capability( "access2", 0 );
141 set_callbacks( AccessOpen, AccessClose );
145 /*****************************************************************************
146 * DirectShow elementary stream descriptor
147 *****************************************************************************/
148 typedef struct dshow_stream_t
151 IBaseFilter *p_device_filter;
152 CaptureFilter *p_capture_filter;
157 VIDEOINFOHEADER video;
169 /*****************************************************************************
170 * DirectShow utility functions
171 *****************************************************************************/
172 static void CreateDirectShowGraph( access_sys_t *p_sys )
174 p_sys->i_crossbar_route_depth = 0;
176 /* Create directshow filter graph */
177 if( SUCCEEDED( CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,
178 (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph) ) )
180 /* Create directshow capture graph builder if available */
181 if( SUCCEEDED( CoCreateInstance( CLSID_CaptureGraphBuilder2, 0,
182 CLSCTX_INPROC, (REFIID)IID_ICaptureGraphBuilder2,
183 (void **)&p_sys->p_capture_graph_builder2 ) ) )
185 p_sys->p_capture_graph_builder2->
186 SetFiltergraph((IGraphBuilder *)p_sys->p_graph);
189 p_sys->p_graph->QueryInterface( IID_IMediaControl,
190 (void **)&p_sys->p_control );
194 static void DeleteDirectShowGraph( access_sys_t *p_sys )
196 DeleteCrossbarRoutes( p_sys );
198 /* Remove filters from graph */
199 for( int i = 0; i < p_sys->i_streams; i++ )
201 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );
202 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );
203 p_sys->pp_streams[i]->p_capture_filter->Release();
204 p_sys->pp_streams[i]->p_device_filter->Release();
207 /* Release directshow objects */
208 if( p_sys->p_control )
210 p_sys->p_control->Release();
211 p_sys->p_control = NULL;
213 if( p_sys->p_capture_graph_builder2 )
215 p_sys->p_capture_graph_builder2->Release();
216 p_sys->p_capture_graph_builder2 = NULL;
221 p_sys->p_graph->Release();
222 p_sys->p_graph = NULL;
226 /*****************************************************************************
227 * CommonOpen: open direct show device
228 *****************************************************************************/
229 static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
230 vlc_bool_t b_access_demux )
235 /* Get/parse options and open device(s) */
236 string vdevname, adevname;
237 int i_width = 0, i_height = 0, i_chroma = 0;
238 vlc_bool_t b_audio = VLC_TRUE;
240 var_Create( p_this, "dshow-config", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
242 var_Create( p_this, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
243 var_Get( p_this, "dshow-vdev", &val );
244 if( val.psz_string ) vdevname = string( val.psz_string );
245 if( val.psz_string ) free( val.psz_string );
247 var_Create( p_this, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
248 var_Get( p_this, "dshow-adev", &val );
249 if( val.psz_string ) adevname = string( val.psz_string );
250 if( val.psz_string ) free( val.psz_string );
252 static struct {char *psz_size; int i_width; int i_height;} size_table[] =
253 { { "subqcif", 128, 96 }, { "qsif", 160, 120 }, { "qcif", 176, 144 },
254 { "sif", 320, 240 }, { "cif", 352, 288 }, { "cif", 640, 480 },
258 var_Create( p_this, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
259 var_Get( p_this, "dshow-size", &val );
260 if( val.psz_string && *val.psz_string )
262 for( i = 0; size_table[i].psz_size; i++ )
264 if( !strcmp( val.psz_string, size_table[i].psz_size ) )
266 i_width = size_table[i].i_width;
267 i_height = size_table[i].i_height;
271 if( !size_table[i].psz_size ) /* Try to parse "WidthxHeight" */
274 i_width = strtol( val.psz_string, &psz_parser, 0 );
275 if( *psz_parser == 'x' || *psz_parser == 'X')
277 i_height = strtol( psz_parser + 1, &psz_parser, 0 );
279 msg_Dbg( p_this, "Width x Height %dx%d", i_width, i_height );
282 if( val.psz_string ) free( val.psz_string );
284 var_Create( p_this, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
285 var_Get( p_this, "dshow-chroma", &val );
286 if( val.psz_string && strlen( val.psz_string ) >= 4 )
288 i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],
289 val.psz_string[2], val.psz_string[3] );
291 if( val.psz_string ) free( val.psz_string );
293 var_Create( p_this, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
295 /* Initialize OLE/COM */
298 /* Initialize some data */
299 p_sys->i_streams = 0;
300 p_sys->pp_streams = (dshow_stream_t **)malloc( 1 );
301 p_sys->i_width = i_width;
302 p_sys->i_height = i_height;
303 p_sys->i_chroma = i_chroma;
305 p_sys->p_graph = NULL;
306 p_sys->p_capture_graph_builder2 = NULL;
307 p_sys->p_control = NULL;
309 /* Build directshow graph */
310 CreateDirectShowGraph( p_sys );
312 if( OpenDevice( p_this, p_sys, vdevname, 0 ) != VLC_SUCCESS )
314 msg_Err( p_this, "can't open video");
318 /* Check if we can handle the demuxing ourselves or need to spawn
319 * a demuxer module */
320 dshow_stream_t *p_stream = p_sys->pp_streams[p_sys->i_streams-1];
322 if( p_stream->mt.majortype == MEDIATYPE_Video )
324 if( /* Raw DV stream */
325 p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
326 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
327 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') ||
328 /* Raw MPEG video stream */
329 p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
335 if( p_stream->mt.majortype == MEDIATYPE_Stream ) b_audio = VLC_FALSE;
338 if( b_audio && OpenDevice( p_this, p_sys, adevname, 1 ) != VLC_SUCCESS )
340 msg_Err( p_this, "can't open audio");
343 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
345 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
346 LONG VideoInputIndex = p_sys->crossbar_routes[i].VideoInputIndex;
347 LONG VideoOutputIndex = p_sys->crossbar_routes[i].VideoOutputIndex;
348 LONG AudioInputIndex = p_sys->crossbar_routes[i].AudioInputIndex;
349 LONG AudioOutputIndex = p_sys->crossbar_routes[i].AudioOutputIndex;
351 if( SUCCEEDED(pXbar->Route(VideoOutputIndex, VideoInputIndex)) )
353 msg_Dbg( p_this, "Crossbar at depth %d, Routed video "
354 "ouput %ld to video input %ld", i, VideoOutputIndex,
357 if( AudioOutputIndex != -1 && AudioInputIndex != -1 )
359 if( SUCCEEDED( pXbar->Route(AudioOutputIndex,
362 msg_Dbg(p_this, "Crossbar at depth %d, Routed audio "
363 "ouput %ld to audio input %ld", i,
364 AudioOutputIndex, AudioInputIndex );
371 ** Show properties pages from other filters in graph
373 var_Get( p_this, "dshow-config", &val );
376 for( i = p_sys->i_crossbar_route_depth-1; i >= 0 ; --i )
378 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
381 if( SUCCEEDED( pXbar->QueryInterface( IID_IBaseFilter,
384 ShowPropertyPage( p_XF );
390 /* Initialize some data */
391 p_sys->i_current_stream = 0;
392 vlc_mutex_init( p_this, &p_sys->lock );
393 vlc_cond_init( p_this, &p_sys->wait );
395 if( !p_sys->i_streams ) return VLC_EGENERIC;
400 /*****************************************************************************
401 * DemuxOpen: open direct show device as an access_demux module
402 *****************************************************************************/
403 static int DemuxOpen( vlc_object_t *p_this )
405 demux_t *p_demux = (demux_t *)p_this;
409 p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
410 memset( p_sys, 0, sizeof( access_sys_t ) );
411 p_demux->p_sys = (demux_sys_t *)p_sys;
413 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
415 CommonClose( p_this, p_sys );
419 /* Everything is ready. Let's rock baby */
420 msg_Dbg( p_this, "Playing...");
421 p_sys->p_control->Run();
423 p_demux->pf_demux = Demux;
424 p_demux->pf_control = DemuxControl;
425 p_demux->info.i_update = 0;
426 p_demux->info.i_title = 0;
427 p_demux->info.i_seekpoint = 0;
429 for( i = 0; i < p_sys->i_streams; i++ )
431 dshow_stream_t *p_stream = p_sys->pp_streams[i];
434 if( p_stream->mt.majortype == MEDIATYPE_Video )
436 es_format_Init( &fmt, VIDEO_ES, p_stream->i_fourcc );
438 fmt.video.i_width = p_stream->header.video.bmiHeader.biWidth;
439 fmt.video.i_height = p_stream->header.video.bmiHeader.biHeight;
440 fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
442 if( !p_stream->header.video.bmiHeader.biCompression )
444 /* RGB DIB are coded from bottom to top */
445 fmt.video.i_height = (unsigned int)(-(int)fmt.video.i_height);
448 /* Setup rgb mask for RGB formats */
449 if( p_stream->i_fourcc == VLC_FOURCC('R','V','2','4') )
451 /* This is in BGR format */
452 fmt.video.i_bmask = 0x00ff0000;
453 fmt.video.i_gmask = 0x0000ff00;
454 fmt.video.i_rmask = 0x000000ff;
457 else if( p_stream->mt.majortype == MEDIATYPE_Audio )
459 es_format_Init( &fmt, AUDIO_ES, p_stream->i_fourcc );
461 fmt.audio.i_channels = p_stream->header.audio.nChannels;
462 fmt.audio.i_rate = p_stream->header.audio.nSamplesPerSec;
463 fmt.audio.i_bitspersample = p_stream->header.audio.wBitsPerSample;
464 fmt.audio.i_blockalign = fmt.audio.i_channels *
465 fmt.audio.i_bitspersample / 8;
466 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
467 fmt.audio.i_bitspersample;
470 p_stream->p_es = es_out_Add( p_demux->out, &fmt );
476 /*****************************************************************************
477 * AccessOpen: open direct show device as an access module
478 *****************************************************************************/
479 static int AccessOpen( vlc_object_t *p_this )
481 access_t *p_access = (access_t*)p_this;
484 p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
485 memset( p_sys, 0, sizeof( access_sys_t ) );
487 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
489 CommonClose( p_this, p_sys );
493 dshow_stream_t *p_stream = p_sys->pp_streams[0];
495 /* Check if we need to force demuxers */
496 if( !p_access->psz_demux || !*p_access->psz_demux )
498 if( p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
499 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
500 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') )
502 p_access->psz_demux = strdup( "rawdv" );
504 else if( p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
506 p_access->psz_demux = "mpgv";
511 p_access->pf_read = ReadCompressed;
512 p_access->pf_block = NULL;
513 p_access->pf_control = AccessControl;
514 p_access->pf_seek = NULL;
515 p_access->info.i_update = 0;
516 p_access->info.i_size = 0;
517 p_access->info.i_pos = 0;
518 p_access->info.b_eof = VLC_FALSE;
519 p_access->info.i_title = 0;
520 p_access->info.i_seekpoint = 0;
521 p_access->p_sys = p_sys;
523 /* Everything is ready. Let's rock baby */
524 msg_Dbg( p_this, "Playing...");
525 p_sys->p_control->Run();
530 /*****************************************************************************
531 * CommonClose: close device
532 *****************************************************************************/
533 static void CommonClose( vlc_object_t *p_this, access_sys_t *p_sys )
535 msg_Dbg( p_this, "Releasing DirectShow");
537 DeleteDirectShowGraph( p_sys );
539 /* Uninitialize OLE/COM */
542 /* Remove filters from graph */
543 for( int i = 0; i < p_sys->i_streams; i++ )
545 delete p_sys->pp_streams[i];
547 free( p_sys->pp_streams );
549 vlc_mutex_destroy( &p_sys->lock );
550 vlc_cond_destroy( &p_sys->wait );
555 /*****************************************************************************
556 * AccessClose: close device
557 *****************************************************************************/
558 static void AccessClose( vlc_object_t *p_this )
560 access_t *p_access = (access_t *)p_this;
561 access_sys_t *p_sys = p_access->p_sys;
563 /* Stop capturing stuff */
564 p_sys->p_control->Stop();
566 CommonClose( p_this, p_sys );
569 /*****************************************************************************
570 * DemuxClose: close device
571 *****************************************************************************/
572 static void DemuxClose( vlc_object_t *p_this )
574 demux_t *p_demux = (demux_t *)p_this;
575 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
577 /* Stop capturing stuff */
578 p_sys->p_control->Stop();
580 CommonClose( p_this, p_sys );
583 /****************************************************************************
585 ****************************************************************************/
586 static bool ConnectFilters( vlc_object_t *p_this, access_sys_t *p_sys,
587 IBaseFilter *p_filter,
588 CaptureFilter *p_capture_filter )
590 CapturePin *p_input_pin = p_capture_filter->CustomGetPin();
592 AM_MEDIA_TYPE mediaType = p_input_pin->CustomGetMediaType();
594 if( p_sys->p_capture_graph_builder2 )
596 if( FAILED(p_sys->p_capture_graph_builder2->
597 RenderStream( &PIN_CATEGORY_CAPTURE, &mediaType.majortype,
598 p_filter, 0, (IBaseFilter *)p_capture_filter )) )
603 // Sort out all the possible video inputs
604 // The class needs to be given the capture filters ANALOGVIDEO input pin
606 if( mediaType.majortype == MEDIATYPE_Video &&
607 SUCCEEDED(p_filter->EnumPins(&pins)) )
613 IKsPropertySet *pKs=0;
617 while( !Found && ( S_OK == pins->Next(1, &pP, &n) ) )
619 if( S_OK == pP->QueryPinInfo(&pinInfo) )
621 // is this pin an ANALOGVIDEOIN input pin?
622 if( pinInfo.dir == PINDIR_INPUT &&
623 pP->QueryInterface( IID_IKsPropertySet,
624 (void **)&pKs ) == S_OK )
626 if( pKs->Get( AMPROPSETID_Pin,
627 AMPROPERTY_PIN_CATEGORY, NULL, 0,
628 &guid, sizeof(GUID), &dw ) == S_OK )
630 if( guid == PIN_CATEGORY_ANALOGVIDEOIN )
632 // recursively search crossbar routes
633 FindCrossbarRoutes( p_this, p_sys, pP, 0 );
640 pinInfo.pFilter->Release();
650 IEnumPins *p_enumpins;
653 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
655 while( S_OK == p_enumpins->Next( 1, &p_pin, NULL ) )
657 PIN_DIRECTION pin_dir;
658 p_pin->QueryDirection( &pin_dir );
660 if( pin_dir == PINDIR_OUTPUT &&
661 p_sys->p_graph->ConnectDirect( p_pin, (IPin *)p_input_pin,
665 p_enumpins->Release();
671 p_enumpins->Release();
677 * get fourcc priority from arbritary preference, the higher the better
679 static int GetFourCCPriority( int i_fourcc )
683 case VLC_FOURCC('I','4','2','0'):
684 case VLC_FOURCC('f','l','3','2'):
686 case VLC_FOURCC('Y','V','1','2'):
687 case VLC_FOURCC('a','r','a','w'):
689 case VLC_FOURCC('R','V','2','4'):
691 case VLC_FOURCC('Y','U','Y','2'):
692 case VLC_FOURCC('R','V','3','2'):
693 case VLC_FOURCC('R','G','B','A'):
700 #define MAX_MEDIA_TYPES 32
702 static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
703 string devicename, vlc_bool_t b_audio )
705 /* See if device is already opened */
706 for( int i = 0; i < p_sys->i_streams; i++ )
708 if( devicename.size() &&
709 p_sys->pp_streams[i]->devicename == devicename )
716 list<string> list_devices;
718 /* Enumerate devices and display their names */
719 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
721 if( !list_devices.size() )
724 list<string>::iterator iter;
725 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
726 msg_Dbg( p_this, "found device: %s", iter->c_str() );
728 /* If no device name was specified, pick the 1st one */
729 if( devicename.size() == 0 )
731 devicename = *list_devices.begin();
734 // Use the system device enumerator and class enumerator to find
735 // a capture/preview device, such as a desktop USB video camera.
736 IBaseFilter *p_device_filter =
737 FindCaptureDevice( p_this, &devicename, 0, b_audio );
738 if( p_device_filter )
739 msg_Dbg( p_this, "using device: %s", devicename.c_str() );
742 msg_Err( p_this, "can't use device: %s, unsupported device type",
743 devicename.c_str() );
748 AM_MEDIA_TYPE *mt = NULL;
752 // Insert prefered video media type
756 mtr.majortype = MEDIATYPE_Video;
757 mtr.subtype = MEDIASUBTYPE_I420;
758 mtr.bFixedSizeSamples = TRUE;
759 mtr.bTemporalCompression = FALSE;
761 mtr.formattype = FORMAT_VideoInfo;
762 mtr.cbFormat = sizeof(vh);
763 mtr.pbFormat = (BYTE *)&vh;
765 memset(&vh, 0, sizeof(vh));
767 vh.bmiHeader.biSize = sizeof(vh.bmiHeader);
768 vh.bmiHeader.biWidth = p_sys->i_width > 0 ? p_sys->i_width : 320;
769 vh.bmiHeader.biHeight = p_sys->i_height > 0 ? p_sys->i_height : 240;
770 vh.bmiHeader.biPlanes = 3;
771 vh.bmiHeader.biBitCount = 12;
772 vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0');
773 vh.bmiHeader.biSizeImage = vh.bmiHeader.biWidth * 12 *
774 vh.bmiHeader.biHeight / 8;
775 mtr.lSampleSize = vh.bmiHeader.biSizeImage;
778 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
779 CopyMediaType(mt, &mtr);
783 // Insert prefered audio media type
787 mtr.majortype = MEDIATYPE_Audio;
788 mtr.subtype = MEDIASUBTYPE_PCM;
789 mtr.bFixedSizeSamples = TRUE;
790 mtr.bTemporalCompression = FALSE;
793 mtr.formattype = FORMAT_WaveFormatEx;
794 mtr.cbFormat = sizeof(wf);
795 mtr.pbFormat = (BYTE *)&wf;
797 memset(&wf, 0, sizeof(wf));
799 wf.wFormatTag = WAVE_FORMAT_PCM;
801 wf.nSamplesPerSec = 44100;
802 wf.wBitsPerSample = 16;
803 wf.nBlockAlign = wf.nSamplesPerSec * wf.wBitsPerSample / 8;
804 wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
808 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
809 CopyMediaType(mt, &mtr);
812 // Retreive acceptable media types supported by device
813 AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
815 EnumDeviceCaps( p_this, p_device_filter, p_sys->i_chroma,
816 p_sys->i_width, p_sys->i_height,
817 0, 0, 0, media_types, MAX_MEDIA_TYPES );
819 if( media_count > 0 )
821 mt = (AM_MEDIA_TYPE *)realloc( mt, sizeof(AM_MEDIA_TYPE) *
822 (mt_count + media_count) );
824 // Order and copy returned media types according to arbitrary
826 for( size_t c = 0; c < media_count; c++ )
829 GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
830 size_t slot_copy = c;
831 for( size_t d = c+1; d < media_count; d++ )
834 GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
835 if( priority > slot_priority )
837 slot_priority = priority;
843 mt[c+mt_count] = media_types[slot_copy];
844 media_types[slot_copy] = media_types[c];
848 mt[c+mt_count] = media_types[c];
851 mt_count += media_count;
854 /* Create and add our capture filter */
855 CaptureFilter *p_capture_filter =
856 new CaptureFilter( p_this, p_sys, mt, mt_count );
857 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
859 /* Add the device filter to the graph (seems necessary with VfW before
860 * accessing pin attributes). */
861 p_sys->p_graph->AddFilter( p_device_filter, 0 );
863 /* Attempt to connect one of this device's capture output pins */
864 msg_Dbg( p_this, "connecting filters" );
865 if( ConnectFilters( p_this, p_sys, p_device_filter, p_capture_filter ) )
868 msg_Dbg( p_this, "filters connected successfully !" );
870 dshow_stream_t dshow_stream;
871 dshow_stream.b_pts = VLC_FALSE;
872 dshow_stream.p_es = 0;
874 p_capture_filter->CustomGetPin()->CustomGetMediaType();
876 /* Show Device properties. Done here so the VLC stream is setup with
877 * the proper parameters. */
879 var_Get( p_this, "dshow-config", &val );
882 ShowDeviceProperties( p_this, p_sys->p_capture_graph_builder2,
883 p_device_filter, b_audio );
887 p_capture_filter->CustomGetPin()->CustomGetMediaType();
889 dshow_stream.i_fourcc = GetFourCCFromMediaType( dshow_stream.mt );
890 if( dshow_stream.i_fourcc )
892 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
894 dshow_stream.header.video =
895 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
896 msg_Dbg( p_this, "MEDIATYPE_Video" );
897 msg_Dbg( p_this, "selected video pin accepts format: %4.4s",
898 (char *)&dshow_stream.i_fourcc);
900 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio )
902 dshow_stream.header.audio =
903 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
904 msg_Dbg( p_this, "MEDIATYPE_Audio" );
905 msg_Dbg( p_this, "selected audio pin accepts format: %4.4s",
906 (char *)&dshow_stream.i_fourcc);
908 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
910 msg_Dbg( p_this, "MEDIATYPE_Stream" );
911 msg_Dbg( p_this, "selected stream pin accepts format: %4.4s",
912 (char *)&dshow_stream.i_fourcc);
916 msg_Dbg( p_this, "unknown stream majortype" );
920 /* Add directshow elementary stream to our list */
921 dshow_stream.p_device_filter = p_device_filter;
922 dshow_stream.p_capture_filter = p_capture_filter;
924 p_sys->pp_streams = (dshow_stream_t **)realloc( p_sys->pp_streams,
925 sizeof(dshow_stream_t *) * (p_sys->i_streams + 1) );
926 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
927 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
934 /* Remove filters from graph */
935 p_sys->p_graph->RemoveFilter( p_device_filter );
936 p_sys->p_graph->RemoveFilter( p_capture_filter );
938 /* Release objects */
939 p_device_filter->Release();
940 p_capture_filter->Release();
946 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
947 list<string> *p_listdevices, vlc_bool_t b_audio )
949 IBaseFilter *p_base_filter = NULL;
950 IMoniker *p_moniker = NULL;
954 /* Create the system device enumerator */
955 ICreateDevEnum *p_dev_enum = NULL;
957 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
958 IID_ICreateDevEnum, (void **)&p_dev_enum );
961 msg_Err( p_this, "failed to create the device enumerator (0x%lx)", hr);
965 /* Create an enumerator for the video capture devices */
966 IEnumMoniker *p_class_enum = NULL;
968 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
971 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
973 p_dev_enum->Release();
976 msg_Err( p_this, "failed to create the class enumerator (0x%lx)", hr );
980 /* If there are no enumerators for the requested type, then
981 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
982 if( p_class_enum == NULL )
984 msg_Err( p_this, "no capture device was detected" );
988 /* Enumerate the devices */
990 /* Note that if the Next() call succeeds but there are no monikers,
991 * it will return S_FALSE (which is not a failure). Therefore, we check
992 * that the return code is S_OK instead of using SUCCEEDED() macro. */
994 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
996 /* Getting the property page to get the device name */
998 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
1004 hr = p_bag->Read( L"FriendlyName", &var, NULL );
1008 int i_convert = ( lstrlenW( var.bstrVal ) + 1 ) * 2;
1009 char *p_buf = (char *)alloca( i_convert ); p_buf[0] = 0;
1010 WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, p_buf,
1011 i_convert, NULL, NULL );
1012 SysFreeString(var.bstrVal);
1014 if( p_listdevices ) p_listdevices->push_back( p_buf );
1016 if( p_devicename && *p_devicename == string(p_buf) )
1018 /* Bind Moniker to a filter object */
1019 hr = p_moniker->BindToObject( 0, 0, IID_IBaseFilter,
1020 (void **)&p_base_filter );
1023 msg_Err( p_this, "couldn't bind moniker to filter "
1024 "object (0x%lx)", hr );
1025 p_moniker->Release();
1026 p_class_enum->Release();
1029 p_moniker->Release();
1030 p_class_enum->Release();
1031 return p_base_filter;
1036 p_moniker->Release();
1039 p_class_enum->Release();
1043 static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
1044 int i_fourcc, int i_width, int i_height,
1045 int i_channels, int i_samplespersec,
1046 int i_bitspersample, AM_MEDIA_TYPE *mt,
1049 IEnumPins *p_enumpins;
1051 IEnumMediaTypes *p_enummt;
1052 size_t mt_count = 0;
1054 if( FAILED(p_filter->EnumPins( &p_enumpins )) )
1056 msg_Dbg( p_this, "EnumDeviceCaps failed: no pin enumeration !");
1060 while( S_OK == p_enumpins->Next( 1, &p_output_pin, NULL ) )
1064 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1066 msg_Dbg( p_this, "EnumDeviceCaps: %s pin: %S",
1067 info.dir == PINDIR_INPUT ? "input" : "output",
1069 if( info.pFilter ) info.pFilter->Release();
1072 p_output_pin->Release();
1075 p_enumpins->Reset();
1077 while( !mt_count && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
1081 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1083 if( info.pFilter ) info.pFilter->Release();
1084 if( info.dir == PINDIR_INPUT )
1086 p_output_pin->Release();
1089 msg_Dbg( p_this, "EnumDeviceCaps: trying pin %S", info.achName );
1093 if( !SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
1095 p_output_pin->Release();
1099 AM_MEDIA_TYPE *p_mt;
1100 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
1102 int i_current_fourcc = GetFourCCFromMediaType(*p_mt);
1103 if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Video )
1105 int i_current_width = p_mt->pbFormat ?
1106 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth :0;
1107 int i_current_height = p_mt->pbFormat ?
1108 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight :0;
1109 if( i_current_height < 0 )
1110 i_current_height = -i_current_height;
1112 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1113 "accepts chroma: %4.4s, width:%i, height:%i",
1114 (char *)&i_current_fourcc, i_current_width,
1117 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1118 ( !i_width || i_width == i_current_width ) &&
1119 ( !i_height || i_height == i_current_height ) &&
1123 mt[mt_count++] = *p_mt;
1125 else FreeMediaType( *p_mt );
1127 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Audio )
1129 int i_current_channels =
1130 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
1131 int i_current_samplespersec =
1132 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
1133 int i_current_bitspersample =
1134 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
1136 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1137 "accepts format: %4.4s, channels:%i, "
1138 "samples/sec:%i bits/sample:%i",
1139 (char *)&i_current_fourcc, i_current_channels,
1140 i_current_samplespersec, i_current_bitspersample);
1142 if( (!i_channels || i_channels == i_current_channels) &&
1143 (!i_samplespersec ||
1144 i_samplespersec == i_current_samplespersec) &&
1145 (!i_bitspersample ||
1146 i_bitspersample == i_current_bitspersample) &&
1150 mt[mt_count++] = *p_mt;
1152 /* Setup a few properties like the audio latency */
1153 IAMBufferNegotiation *p_ambuf;
1154 if( SUCCEEDED( p_output_pin->QueryInterface(
1155 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
1157 ALLOCATOR_PROPERTIES AllocProp;
1158 AllocProp.cbAlign = -1;
1160 /* 100 ms of latency */
1161 AllocProp.cbBuffer = i_current_channels *
1162 i_current_samplespersec *
1163 i_current_bitspersample / 8 / 10;
1165 AllocProp.cbPrefix = -1;
1166 AllocProp.cBuffers = -1;
1167 p_ambuf->SuggestAllocatorProperties( &AllocProp );
1171 else FreeMediaType( *p_mt );
1173 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Stream )
1175 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1179 mt[mt_count++] = *p_mt;
1180 i_fourcc = i_current_fourcc;
1182 else FreeMediaType( *p_mt );
1186 msg_Dbg( p_this, "EnumDeviceCaps: input pin: unknown format" );
1187 FreeMediaType( *p_mt );
1189 CoTaskMemFree( (PVOID)p_mt );
1192 p_enummt->Release();
1193 p_output_pin->Release();
1196 p_enumpins->Release();
1200 /*****************************************************************************
1201 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1202 *****************************************************************************
1203 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1205 *****************************************************************************/
1206 static int ReadCompressed( access_t *p_access, uint8_t *p_buffer, int i_len )
1208 access_sys_t *p_sys = p_access->p_sys;
1209 dshow_stream_t *p_stream = NULL;
1210 VLCMediaSample sample;
1214 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1216 /* There must be only 1 elementary stream to produce a valid stream
1217 * of MPEG or DV data */
1218 p_stream = p_sys->pp_streams[0];
1222 if( p_access->b_die || p_access->b_error ) return 0;
1224 /* Get new sample/frame from the elementary stream (blocking). */
1225 vlc_mutex_lock( &p_sys->lock );
1227 if( p_stream->p_capture_filter->CustomGetPin()
1228 ->CustomGetSample( &sample ) != S_OK )
1230 /* No data available. Wait until some data has arrived */
1231 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1232 vlc_mutex_unlock( &p_sys->lock );
1236 vlc_mutex_unlock( &p_sys->lock );
1241 i_data_size = sample.p_sample->GetActualDataLength();
1242 sample.p_sample->GetPointer( &p_data );
1245 msg_Info( p_access, "access read %i data_size %i", i_len, i_data_size );
1247 i_data_size = __MIN( i_data_size, (int)i_len );
1249 p_access->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1251 sample.p_sample->Release();
1253 /* The caller got what he wanted */
1257 return 0; /* never reached */
1260 /****************************************************************************
1262 ****************************************************************************/
1263 static int Demux( demux_t *p_demux )
1265 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
1266 dshow_stream_t *p_stream = NULL;
1267 VLCMediaSample sample;
1268 int i_data_size, i_stream;
1272 vlc_mutex_lock( &p_sys->lock );
1274 /* Try to grab an audio sample (audio has a higher priority) */
1275 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1277 p_stream = p_sys->pp_streams[i_stream];
1278 if( p_stream->mt.majortype == MEDIATYPE_Audio &&
1279 p_stream->p_capture_filter &&
1280 p_stream->p_capture_filter->CustomGetPin()
1281 ->CustomGetSample( &sample ) == S_OK )
1286 /* Try to grab a video sample */
1287 if( i_stream == p_sys->i_streams )
1288 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1290 p_stream = p_sys->pp_streams[i_stream];
1291 if( p_stream->p_capture_filter &&
1292 p_stream->p_capture_filter->CustomGetPin()
1293 ->CustomGetSample( &sample ) == S_OK )
1299 vlc_mutex_unlock( &p_sys->lock );
1301 if( i_stream == p_sys->i_streams )
1303 /* Sleep so we do not consume all the cpu, 10ms seems
1304 * like a good value (100fps) */
1312 i_data_size = sample.p_sample->GetActualDataLength();
1313 sample.p_sample->GetPointer( &p_data );
1315 REFERENCE_TIME i_pts, i_end_date;
1316 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1317 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1321 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1323 /* Use our data timestamp */
1324 i_pts = sample.i_timestamp;
1325 p_stream->b_pts = VLC_TRUE;
1329 i_pts /= 10; /* Dshow works with 100 nano-seconds resolution */
1332 msg_Dbg( p_demux, "Read() stream: %i, size: %i, PTS: "I64Fd,
1333 i_stream, i_data_size, i_pts );
1336 p_block = block_New( p_demux, i_data_size );
1337 p_demux->p_vlc->pf_memcpy( p_block->p_buffer, p_data, i_data_size );
1338 p_block->i_pts = p_block->i_dts = i_pts;
1339 sample.p_sample->Release();
1341 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pts > 0 ? i_pts : 0 );
1342 es_out_Send( p_demux->out, p_stream->p_es, p_block );
1347 /*****************************************************************************
1349 *****************************************************************************/
1350 static int AccessControl( access_t *p_access, int i_query, va_list args )
1352 vlc_bool_t *pb_bool;
1359 case ACCESS_CAN_SEEK:
1360 case ACCESS_CAN_FASTSEEK:
1361 case ACCESS_CAN_PAUSE:
1362 case ACCESS_CAN_CONTROL_PACE:
1363 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
1364 *pb_bool = VLC_FALSE;
1368 case ACCESS_GET_MTU:
1369 pi_int = (int*)va_arg( args, int * );
1373 case ACCESS_GET_PTS_DELAY:
1374 pi_64 = (int64_t*)va_arg( args, int64_t * );
1375 *pi_64 = (int64_t)var_GetInteger( p_access, "dshow-caching" ) * 1000;
1379 case ACCESS_SET_PAUSE_STATE:
1380 case ACCESS_GET_TITLE_INFO:
1381 case ACCESS_SET_TITLE:
1382 case ACCESS_SET_SEEKPOINT:
1383 case ACCESS_SET_PRIVATE_ID_STATE:
1384 return VLC_EGENERIC;
1387 msg_Warn( p_access, "unimplemented query in control" );
1388 return VLC_EGENERIC;
1394 /****************************************************************************
1396 ****************************************************************************/
1397 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
1404 /* Special for access_demux */
1405 case DEMUX_CAN_PAUSE:
1406 case DEMUX_SET_PAUSE_STATE:
1407 case DEMUX_CAN_CONTROL_PACE:
1408 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
1412 case DEMUX_GET_PTS_DELAY:
1413 pi64 = (int64_t*)va_arg( args, int64_t * );
1414 *pi64 = (int64_t)var_GetInteger( p_demux, "dshow-caching" ) * 1000;
1417 case DEMUX_GET_TIME:
1418 pi64 = (int64_t*)va_arg( args, int64_t * );
1422 /* TODO implement others */
1424 return VLC_EGENERIC;
1427 return VLC_EGENERIC;
1430 /*****************************************************************************
1431 * config variable callback
1432 *****************************************************************************/
1433 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1434 vlc_value_t newval, vlc_value_t oldval, void * )
1436 module_config_t *p_item;
1437 vlc_bool_t b_audio = VLC_FALSE;
1440 p_item = config_FindConfig( p_this, psz_name );
1441 if( !p_item ) return VLC_SUCCESS;
1443 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1445 /* Clear-up the current list */
1446 if( p_item->i_list )
1448 /* Keep the 2 first entries */
1449 for( i = 2; i < p_item->i_list; i++ )
1451 free( p_item->ppsz_list[i] );
1452 free( p_item->ppsz_list_text[i] );
1454 /* TODO: Remove when no more needed */
1455 p_item->ppsz_list[i] = NULL;
1456 p_item->ppsz_list_text[i] = NULL;
1460 /* Find list of devices */
1461 list<string> list_devices;
1463 /* Initialize OLE/COM */
1466 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1468 /* Uninitialize OLE/COM */
1471 if( !list_devices.size() ) return VLC_SUCCESS;
1474 (char **)realloc( p_item->ppsz_list,
1475 (list_devices.size()+3) * sizeof(char *) );
1476 p_item->ppsz_list_text =
1477 (char **)realloc( p_item->ppsz_list_text,
1478 (list_devices.size()+3) * sizeof(char *) );
1480 list<string>::iterator iter;
1481 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1484 p_item->ppsz_list[i] = strdup( iter->c_str() );
1485 p_item->ppsz_list_text[i] = NULL;
1488 p_item->ppsz_list[i] = NULL;
1489 p_item->ppsz_list_text[i] = NULL;
1491 /* Signal change to the interface */
1492 p_item->b_dirty = VLC_TRUE;
1497 static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1498 vlc_value_t newval, vlc_value_t oldval, void * )
1500 module_config_t *p_item;
1501 vlc_bool_t b_audio = VLC_FALSE;
1503 /* Initialize OLE/COM */
1506 p_item = config_FindConfig( p_this, psz_name );
1507 if( !p_item ) return VLC_SUCCESS;
1509 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1513 if( newval.psz_string && *newval.psz_string )
1515 devicename = newval.psz_string;
1519 /* If no device name was specified, pick the 1st one */
1520 list<string> list_devices;
1522 /* Enumerate devices */
1523 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1524 if( !list_devices.size() ) return VLC_EGENERIC;
1525 devicename = *list_devices.begin();
1528 IBaseFilter *p_device_filter =
1529 FindCaptureDevice( p_this, &devicename, NULL, b_audio );
1530 if( p_device_filter )
1532 ShowPropertyPage( p_device_filter );
1536 /* Uninitialize OLE/COM */
1539 msg_Err( p_this, "didn't find device: %s", devicename.c_str() );
1540 return VLC_EGENERIC;
1543 /* Uninitialize OLE/COM */
1549 /*****************************************************************************
1551 *****************************************************************************/
1552 static void ShowPropertyPage( IUnknown *obj )
1554 ISpecifyPropertyPages *p_spec;
1557 HRESULT hr = obj->QueryInterface( IID_ISpecifyPropertyPages,
1559 if( FAILED(hr) ) return;
1561 if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
1563 if( cauuid.cElems > 0 )
1565 HWND hwnd_desktop = ::GetDesktopWindow();
1567 OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
1568 cauuid.cElems, cauuid.pElems, 0, 0, NULL );
1570 CoTaskMemFree( cauuid.pElems );
1576 static void ShowDeviceProperties( vlc_object_t *p_this,
1577 ICaptureGraphBuilder2 *p_capture_graph,
1578 IBaseFilter *p_device_filter,
1579 vlc_bool_t b_audio )
1582 msg_Dbg( p_this, "Configuring Device Properties" );
1585 * Video or audio capture filter page
1587 ShowPropertyPage( p_device_filter );
1592 if( p_capture_graph && b_audio )
1594 IAMStreamConfig *p_SC;
1596 msg_Dbg( p_this, "Showing WDM Audio Configuration Pages" );
1598 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1599 &MEDIATYPE_Audio, p_device_filter,
1600 IID_IAMStreamConfig,
1604 ShowPropertyPage(p_SC);
1612 HRESULT hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1613 &MEDIATYPE_Audio, p_device_filter,
1614 IID_IAMTVAudio, (void **)&p_TVA );
1617 ShowPropertyPage(p_TVA);
1625 if( p_capture_graph && !b_audio )
1627 IAMStreamConfig *p_SC;
1629 msg_Dbg( p_this, "Showing WDM Video Configuration Pages" );
1631 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1632 &MEDIATYPE_Interleaved,
1634 IID_IAMStreamConfig,
1638 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1641 IID_IAMStreamConfig,
1647 ShowPropertyPage(p_SC);
1656 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1657 &MEDIATYPE_Interleaved,
1659 IID_IAMTVTuner, (void **)&p_TV );
1662 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1671 ShowPropertyPage(p_TV);