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 PropertiesPage( vlc_object_t *, IBaseFilter *,
61 ICaptureGraphBuilder2 *, vlc_bool_t );
63 /*****************************************************************************
65 *****************************************************************************/
66 static char *ppsz_vdev[] = { "", "none" };
67 static char *ppsz_vdev_text[] = { N_("Default"), N_("None") };
68 static char *ppsz_adev[] = { "", "none" };
69 static char *ppsz_adev_text[] = { N_("Default"), N_("None") };
71 #define CACHING_TEXT N_("Caching value in ms")
72 #define CACHING_LONGTEXT N_( \
73 "Allows you to modify the default caching value for DirectShow streams. " \
74 "This value should be set in milliseconds units." )
75 #define VDEV_TEXT N_("Video device name")
76 #define VDEV_LONGTEXT N_( \
77 "You can specify the name of the video device that will be used by the " \
78 "DirectShow plugin. If you don't specify anything, the default device " \
80 #define ADEV_TEXT N_("Audio device name")
81 #define ADEV_LONGTEXT N_( \
82 "You can specify the name of the audio device that will be used by the " \
83 "DirectShow plugin. If you don't specify anything, the default device " \
85 #define SIZE_TEXT N_("Video size")
86 #define SIZE_LONGTEXT N_( \
87 "You can specify the size of the video that will be displayed by the " \
88 "DirectShow plugin. If you don't specify anything the default size for " \
89 "your device will be used.")
90 #define CHROMA_TEXT N_("Video input chroma format")
91 #define CHROMA_LONGTEXT N_( \
92 "Force the DirectShow video input to use a specific chroma format " \
93 "(eg. I420 (default), RV24, etc.)")
94 #define CONFIG_TEXT N_("Device properties")
95 #define CONFIG_LONGTEXT N_( \
96 "Show the properties dialog of the selected device before starting the " \
99 static int CommonOpen ( vlc_object_t *, access_sys_t *, vlc_bool_t );
100 static void CommonClose( vlc_object_t *, access_sys_t * );
102 static int AccessOpen ( vlc_object_t * );
103 static void AccessClose( vlc_object_t * );
105 static int DemuxOpen ( vlc_object_t * );
106 static void DemuxClose ( vlc_object_t * );
109 set_shortname( _("DirectShow") );
110 set_description( _("DirectShow input") );
111 add_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,
112 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
114 add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, VLC_FALSE);
115 change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback );
116 change_action_add( FindDevicesCallback, N_("Refresh list") );
117 change_action_add( ConfigDevicesCallback, N_("Configure") );
119 add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE);
120 change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback );
121 change_action_add( FindDevicesCallback, N_("Refresh list") );
122 change_action_add( ConfigDevicesCallback, N_("Configure") );
124 add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE);
126 add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
129 add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,
132 add_shortcut( "dshow" );
133 set_capability( "access_demux", 0 );
134 set_callbacks( DemuxOpen, DemuxClose );
137 set_description( _("DirectShow input") );
138 add_shortcut( "dshow" );
139 set_capability( "access2", 0 );
140 set_callbacks( AccessOpen, AccessClose );
144 /*****************************************************************************
145 * DirectShow elementary stream descriptor
146 *****************************************************************************/
147 typedef struct dshow_stream_t
150 IBaseFilter *p_device_filter;
151 CaptureFilter *p_capture_filter;
156 VIDEOINFOHEADER video;
168 /*****************************************************************************
169 * DirectShow utility functions
170 *****************************************************************************/
171 static void CreateDirectShowGraph( access_sys_t *p_sys )
173 p_sys->i_crossbar_route_depth = 0;
175 /* Create directshow filter graph */
176 if( SUCCEEDED( CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,
177 (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph) ) )
179 /* Create directshow capture graph builder if available */
180 if( SUCCEEDED( CoCreateInstance( CLSID_CaptureGraphBuilder2, 0,
181 CLSCTX_INPROC, (REFIID)IID_ICaptureGraphBuilder2,
182 (void **)&p_sys->p_capture_graph_builder2 ) ) )
184 p_sys->p_capture_graph_builder2->
185 SetFiltergraph((IGraphBuilder *)p_sys->p_graph);
188 p_sys->p_graph->QueryInterface( IID_IMediaControl,
189 (void **)&p_sys->p_control );
193 static void DeleteDirectShowGraph( access_sys_t *p_sys )
195 DeleteCrossbarRoutes( p_sys );
197 /* Remove filters from graph */
198 for( int i = 0; i < p_sys->i_streams; i++ )
200 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );
201 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );
202 p_sys->pp_streams[i]->p_capture_filter->Release();
203 p_sys->pp_streams[i]->p_device_filter->Release();
206 /* Release directshow objects */
207 if( p_sys->p_control )
209 p_sys->p_control->Release();
210 p_sys->p_control = NULL;
212 if( p_sys->p_capture_graph_builder2 )
214 p_sys->p_capture_graph_builder2->Release();
215 p_sys->p_capture_graph_builder2 = NULL;
220 p_sys->p_graph->Release();
221 p_sys->p_graph = NULL;
225 /*****************************************************************************
226 * CommonOpen: open direct show device
227 *****************************************************************************/
228 static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys,
229 vlc_bool_t b_access_demux )
234 /* Get/parse options and open device(s) */
235 string vdevname, adevname;
236 int i_width = 0, i_height = 0, i_chroma = 0;
237 vlc_bool_t b_audio = VLC_TRUE;
239 var_Create( p_this, "dshow-config", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
241 var_Create( p_this, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
242 var_Get( p_this, "dshow-vdev", &val );
243 if( val.psz_string ) vdevname = string( val.psz_string );
244 if( val.psz_string ) free( val.psz_string );
246 var_Create( p_this, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
247 var_Get( p_this, "dshow-adev", &val );
248 if( val.psz_string ) adevname = string( val.psz_string );
249 if( val.psz_string ) free( val.psz_string );
251 static struct {char *psz_size; int i_width; int i_height;} size_table[] =
252 { { "subqcif", 128, 96 }, { "qsif", 160, 120 }, { "qcif", 176, 144 },
253 { "sif", 320, 240 }, { "cif", 352, 288 }, { "cif", 640, 480 },
257 var_Create( p_this, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
258 var_Get( p_this, "dshow-size", &val );
259 if( val.psz_string && *val.psz_string )
261 for( i = 0; size_table[i].psz_size; i++ )
263 if( !strcmp( val.psz_string, size_table[i].psz_size ) )
265 i_width = size_table[i].i_width;
266 i_height = size_table[i].i_height;
270 if( !size_table[i].psz_size ) /* Try to parse "WidthxHeight" */
273 i_width = strtol( val.psz_string, &psz_parser, 0 );
274 if( *psz_parser == 'x' || *psz_parser == 'X')
276 i_height = strtol( psz_parser + 1, &psz_parser, 0 );
278 msg_Dbg( p_this, "Width x Height %dx%d", i_width, i_height );
281 if( val.psz_string ) free( val.psz_string );
283 var_Create( p_this, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
284 var_Get( p_this, "dshow-chroma", &val );
285 if( val.psz_string && strlen( val.psz_string ) >= 4 )
287 i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],
288 val.psz_string[2], val.psz_string[3] );
290 if( val.psz_string ) free( val.psz_string );
292 var_Create( p_this, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
294 /* Initialize OLE/COM */
297 /* Initialize some data */
298 p_sys->i_streams = 0;
299 p_sys->pp_streams = (dshow_stream_t **)malloc( 1 );
300 p_sys->i_width = i_width;
301 p_sys->i_height = i_height;
302 p_sys->i_chroma = i_chroma;
304 p_sys->p_graph = NULL;
305 p_sys->p_capture_graph_builder2 = NULL;
306 p_sys->p_control = NULL;
308 /* Build directshow graph */
309 CreateDirectShowGraph( p_sys );
311 if( OpenDevice( p_this, p_sys, vdevname, 0 ) != VLC_SUCCESS )
313 msg_Err( p_this, "can't open video");
317 /* Check if we can handle the demuxing ourselves or need to spawn
318 * a demuxer module */
319 dshow_stream_t *p_stream = p_sys->pp_streams[p_sys->i_streams-1];
321 if( p_stream->mt.majortype == MEDIATYPE_Video )
323 if( /* Raw DV stream */
324 p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
325 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
326 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') ||
327 /* Raw MPEG video stream */
328 p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
334 if( p_stream->mt.majortype == MEDIATYPE_Stream ) b_audio = VLC_FALSE;
337 if( b_audio && OpenDevice( p_this, p_sys, adevname, 1 ) != VLC_SUCCESS )
339 msg_Err( p_this, "can't open audio");
342 for( i = 0; i < p_sys->i_crossbar_route_depth; i++ )
344 IAMCrossbar *pXbar = p_sys->crossbar_routes[i].pXbar;
345 LONG VideoInputIndex = p_sys->crossbar_routes[i].VideoInputIndex;
346 LONG VideoOutputIndex = p_sys->crossbar_routes[i].VideoOutputIndex;
347 LONG AudioInputIndex = p_sys->crossbar_routes[i].AudioInputIndex;
348 LONG AudioOutputIndex = p_sys->crossbar_routes[i].AudioOutputIndex;
350 if( SUCCEEDED(pXbar->Route(VideoOutputIndex, VideoInputIndex)) )
352 msg_Dbg( p_this, "Crossbar at depth %d, Routed video "
353 "ouput %ld to video input %ld", i, VideoOutputIndex,
356 if( AudioOutputIndex != -1 && AudioInputIndex != -1 )
358 if( SUCCEEDED( pXbar->Route(AudioOutputIndex,
361 msg_Dbg(p_this, "Crossbar at depth %d, Routed audio "
362 "ouput %ld to audio input %ld", i,
363 AudioOutputIndex, AudioInputIndex );
369 /* Initialize some data */
370 p_sys->i_current_stream = 0;
371 vlc_mutex_init( p_this, &p_sys->lock );
372 vlc_cond_init( p_this, &p_sys->wait );
374 if( !p_sys->i_streams ) return VLC_EGENERIC;
379 /*****************************************************************************
380 * DemuxOpen: open direct show device as an access_demux module
381 *****************************************************************************/
382 static int DemuxOpen( vlc_object_t *p_this )
384 demux_t *p_demux = (demux_t *)p_this;
388 p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
389 memset( p_sys, 0, sizeof( access_sys_t ) );
390 p_demux->p_sys = (demux_sys_t *)p_sys;
392 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
394 CommonClose( p_this, p_sys );
398 /* Everything is ready. Let's rock baby */
399 msg_Dbg( p_this, "Playing...");
400 p_sys->p_control->Run();
402 p_demux->pf_demux = Demux;
403 p_demux->pf_control = DemuxControl;
404 p_demux->info.i_update = 0;
405 p_demux->info.i_title = 0;
406 p_demux->info.i_seekpoint = 0;
408 for( i = 0; i < p_sys->i_streams; i++ )
410 dshow_stream_t *p_stream = p_sys->pp_streams[i];
413 if( p_stream->mt.majortype == MEDIATYPE_Video )
415 es_format_Init( &fmt, VIDEO_ES, p_stream->i_fourcc );
417 fmt.video.i_width = p_stream->header.video.bmiHeader.biWidth;
418 fmt.video.i_height = p_stream->header.video.bmiHeader.biHeight;
419 fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
421 if( !p_stream->header.video.bmiHeader.biCompression )
423 /* RGB DIB are coded from bottom to top */
424 fmt.video.i_height = (unsigned int)(-(int)fmt.video.i_height);
427 /* Setup rgb mask for RGB formats */
428 if( p_stream->i_fourcc == VLC_FOURCC('R','V','2','4') )
430 /* This is in BGR format */
431 fmt.video.i_bmask = 0x00ff0000;
432 fmt.video.i_gmask = 0x0000ff00;
433 fmt.video.i_rmask = 0x000000ff;
436 else if( p_stream->mt.majortype == MEDIATYPE_Audio )
438 es_format_Init( &fmt, AUDIO_ES, p_stream->i_fourcc );
440 fmt.audio.i_channels = p_stream->header.audio.nChannels;
441 fmt.audio.i_rate = p_stream->header.audio.nSamplesPerSec;
442 fmt.audio.i_bitspersample = p_stream->header.audio.wBitsPerSample;
443 fmt.audio.i_blockalign = fmt.audio.i_channels *
444 fmt.audio.i_bitspersample / 8;
445 fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
446 fmt.audio.i_bitspersample;
449 p_stream->p_es = es_out_Add( p_demux->out, &fmt );
455 /*****************************************************************************
456 * AccessOpen: open direct show device as an access module
457 *****************************************************************************/
458 static int AccessOpen( vlc_object_t *p_this )
460 access_t *p_access = (access_t*)p_this;
463 p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
464 memset( p_sys, 0, sizeof( access_sys_t ) );
466 if( CommonOpen( p_this, p_sys, VLC_TRUE ) != VLC_SUCCESS )
468 CommonClose( p_this, p_sys );
472 dshow_stream_t *p_stream = p_sys->pp_streams[0];
474 /* Check if we need to force demuxers */
475 if( !p_access->psz_demux || !*p_access->psz_demux )
477 if( p_stream->i_fourcc == VLC_FOURCC('d','v','s','l') ||
478 p_stream->i_fourcc == VLC_FOURCC('d','v','s','d') ||
479 p_stream->i_fourcc == VLC_FOURCC('d','v','h','d') )
481 p_access->psz_demux = strdup( "rawdv" );
483 else if( p_stream->i_fourcc == VLC_FOURCC('m','p','2','v') )
485 p_access->psz_demux = "mpgv";
490 p_access->pf_read = ReadCompressed;
491 p_access->pf_block = NULL;
492 p_access->pf_control = AccessControl;
493 p_access->pf_seek = NULL;
494 p_access->info.i_update = 0;
495 p_access->info.i_size = 0;
496 p_access->info.i_pos = 0;
497 p_access->info.b_eof = VLC_FALSE;
498 p_access->info.i_title = 0;
499 p_access->info.i_seekpoint = 0;
500 p_access->p_sys = p_sys;
502 /* Everything is ready. Let's rock baby */
503 msg_Dbg( p_this, "Playing...");
504 p_sys->p_control->Run();
509 /*****************************************************************************
510 * CommonClose: close device
511 *****************************************************************************/
512 static void CommonClose( vlc_object_t *p_this, access_sys_t *p_sys )
514 msg_Dbg( p_this, "Releasing DirectShow");
516 DeleteDirectShowGraph( p_sys );
518 /* Uninitialize OLE/COM */
521 /* Remove filters from graph */
522 for( int i = 0; i < p_sys->i_streams; i++ )
524 delete p_sys->pp_streams[i];
526 free( p_sys->pp_streams );
528 vlc_mutex_destroy( &p_sys->lock );
529 vlc_cond_destroy( &p_sys->wait );
534 /*****************************************************************************
535 * AccessClose: close device
536 *****************************************************************************/
537 static void AccessClose( vlc_object_t *p_this )
539 access_t *p_access = (access_t *)p_this;
540 access_sys_t *p_sys = p_access->p_sys;
542 /* Stop capturing stuff */
543 p_sys->p_control->Stop();
545 CommonClose( p_this, p_sys );
548 /*****************************************************************************
549 * DemuxClose: close device
550 *****************************************************************************/
551 static void DemuxClose( vlc_object_t *p_this )
553 demux_t *p_demux = (demux_t *)p_this;
554 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
556 /* Stop capturing stuff */
557 p_sys->p_control->Stop();
559 CommonClose( p_this, p_sys );
562 /****************************************************************************
564 ****************************************************************************/
565 static bool ConnectFilters( vlc_object_t *p_this, access_sys_t *p_sys,
566 IBaseFilter *p_filter,
567 CaptureFilter *p_capture_filter )
569 CapturePin *p_input_pin = p_capture_filter->CustomGetPin();
571 AM_MEDIA_TYPE mediaType = p_input_pin->CustomGetMediaType();
573 if( p_sys->p_capture_graph_builder2 )
575 if( FAILED(p_sys->p_capture_graph_builder2->
576 RenderStream( &PIN_CATEGORY_CAPTURE, &mediaType.majortype,
577 p_filter, 0, (IBaseFilter *)p_capture_filter )) )
582 // Sort out all the possible video inputs
583 // The class needs to be given the capture filters ANALOGVIDEO input pin
585 if( mediaType.majortype == MEDIATYPE_Video &&
586 SUCCEEDED(p_filter->EnumPins(&pins)) )
592 IKsPropertySet *pKs=0;
596 while( !Found && ( S_OK == pins->Next(1, &pP, &n) ) )
598 if( S_OK == pP->QueryPinInfo(&pinInfo) )
600 // is this pin an ANALOGVIDEOIN input pin?
601 if( pinInfo.dir == PINDIR_INPUT &&
602 pP->QueryInterface( IID_IKsPropertySet,
603 (void **)&pKs ) == S_OK )
605 if( pKs->Get( AMPROPSETID_Pin,
606 AMPROPERTY_PIN_CATEGORY, NULL, 0,
607 &guid, sizeof(GUID), &dw ) == S_OK )
609 if( guid == PIN_CATEGORY_ANALOGVIDEOIN )
611 // recursively search crossbar routes
612 FindCrossbarRoutes( p_this, p_sys, pP,
613 PhysConn_Video_Tuner );
620 pinInfo.pFilter->Release();
630 IEnumPins *p_enumpins;
633 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
635 while( S_OK == p_enumpins->Next( 1, &p_pin, NULL ) )
637 PIN_DIRECTION pin_dir;
638 p_pin->QueryDirection( &pin_dir );
640 if( pin_dir == PINDIR_OUTPUT &&
641 p_sys->p_graph->ConnectDirect( p_pin, (IPin *)p_input_pin,
645 p_enumpins->Release();
651 p_enumpins->Release();
657 * get fourcc priority from arbritary preference, the higher the better
659 static int GetFourCCPriority( int i_fourcc )
663 case VLC_FOURCC('I','4','2','0'):
664 case VLC_FOURCC('f','l','3','2'):
666 case VLC_FOURCC('Y','V','1','2'):
667 case VLC_FOURCC('a','r','a','w'):
669 case VLC_FOURCC('R','V','2','4'):
671 case VLC_FOURCC('Y','U','Y','2'):
672 case VLC_FOURCC('R','V','3','2'):
673 case VLC_FOURCC('R','G','B','A'):
680 #define MAX_MEDIA_TYPES 32
682 static int OpenDevice( vlc_object_t *p_this, access_sys_t *p_sys,
683 string devicename, vlc_bool_t b_audio )
685 /* See if device is already opened */
686 for( int i = 0; i < p_sys->i_streams; i++ )
688 if( devicename.size() &&
689 p_sys->pp_streams[i]->devicename == devicename )
696 list<string> list_devices;
698 /* Enumerate devices and display their names */
699 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
701 if( !list_devices.size() )
704 list<string>::iterator iter;
705 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
706 msg_Dbg( p_this, "found device: %s", iter->c_str() );
708 /* If no device name was specified, pick the 1st one */
709 if( devicename.size() == 0 )
711 devicename = *list_devices.begin();
714 // Use the system device enumerator and class enumerator to find
715 // a capture/preview device, such as a desktop USB video camera.
716 IBaseFilter *p_device_filter =
717 FindCaptureDevice( p_this, &devicename, 0, b_audio );
718 if( p_device_filter )
719 msg_Dbg( p_this, "using device: %s", devicename.c_str() );
722 msg_Err( p_this, "can't use device: %s, unsupported device type",
723 devicename.c_str() );
728 AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES];
730 size_t mt_count = EnumDeviceCaps( p_this, p_device_filter, p_sys->i_chroma,
731 p_sys->i_width, p_sys->i_height,
732 0, 0, 0, media_types, MAX_MEDIA_TYPES );
736 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
738 // Order and copy returned media types according to arbitrary
740 for( size_t c = 0; c < mt_count; c++ )
743 GetFourCCPriority(GetFourCCFromMediaType(media_types[c]));
744 size_t slot_copy = c;
745 for( size_t d = c+1; d < mt_count; d++ )
748 GetFourCCPriority(GetFourCCFromMediaType(media_types[d]));
749 if( priority > slot_priority )
751 slot_priority = priority;
757 mt[c] = media_types[slot_copy];
758 media_types[slot_copy] = media_types[c];
762 mt[c] = media_types[c];
768 // Use default video media type
772 mtr.majortype = MEDIATYPE_Video;
773 mtr.subtype = MEDIASUBTYPE_I420;
774 mtr.bFixedSizeSamples = TRUE;
775 mtr.bTemporalCompression = FALSE;
778 mtr.formattype = FORMAT_VideoInfo;
779 mtr.cbFormat = sizeof(vh);
780 mtr.pbFormat = (BYTE *)&vh;
782 memset(&vh, 0, sizeof(vh));
784 vh.bmiHeader.biSize = sizeof(vh.bmiHeader);
785 vh.bmiHeader.biWidth = p_sys->i_width > 0 ? p_sys->i_width: 320;
786 vh.bmiHeader.biHeight = p_sys->i_height > 0 ? p_sys->i_height : 240;
787 vh.bmiHeader.biPlanes = 1;
788 vh.bmiHeader.biBitCount = 12;
789 vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0');
790 vh.bmiHeader.biSizeImage = p_sys->i_width * 12 * p_sys->i_height / 8;
792 msg_Warn( p_this, "device %s using built-in video media type",
793 devicename.c_str() );
796 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
797 CopyMediaType(mt, &mtr);
801 // Use default audio media type
805 mtr.majortype = MEDIATYPE_Audio;
806 mtr.subtype = MEDIASUBTYPE_PCM;
807 mtr.bFixedSizeSamples = TRUE;
808 mtr.bTemporalCompression = FALSE;
811 mtr.formattype = FORMAT_WaveFormatEx;
812 mtr.cbFormat = sizeof(wf);
813 mtr.pbFormat = (BYTE *)&wf;
815 memset(&wf, 0, sizeof(wf));
817 wf.wFormatTag = WAVE_FORMAT_PCM;
819 wf.nSamplesPerSec = 44100;
820 wf.wBitsPerSample = 16;
821 wf.nBlockAlign = wf.nSamplesPerSec * wf.wBitsPerSample / 8;
822 wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
825 msg_Warn( p_this, "device %s using built-in audio media type",
826 devicename.c_str() );
829 mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count );
830 CopyMediaType(mt, &mtr);
833 /* Create and add our capture filter */
834 CaptureFilter *p_capture_filter =
835 new CaptureFilter( p_this, p_sys, mt, mt_count );
836 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
838 /* Add the device filter to the graph (seems necessary with VfW before
839 * accessing pin attributes). */
840 p_sys->p_graph->AddFilter( p_device_filter, 0 );
842 /* Attempt to connect one of this device's capture output pins */
843 msg_Dbg( p_this, "connecting filters" );
844 if( ConnectFilters( p_this, p_sys, p_device_filter, p_capture_filter ) )
847 msg_Dbg( p_this, "filters connected successfully !" );
849 dshow_stream_t dshow_stream;
850 dshow_stream.b_pts = VLC_FALSE;
851 dshow_stream.p_es = 0;
853 p_capture_filter->CustomGetPin()->CustomGetMediaType();
855 /* Show properties. Done here so the VLC stream is setup with the
856 * proper parameters. */
858 var_Get( p_this, "dshow-config", &val );
861 PropertiesPage( p_this, p_device_filter,
862 p_sys->p_capture_graph_builder2,
863 dshow_stream.mt.majortype == MEDIATYPE_Audio );
867 p_capture_filter->CustomGetPin()->CustomGetMediaType();
869 dshow_stream.i_fourcc = GetFourCCFromMediaType( dshow_stream.mt );
870 if( dshow_stream.i_fourcc )
872 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
874 dshow_stream.header.video =
875 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
876 msg_Dbg( p_this, "MEDIATYPE_Video" );
877 msg_Dbg( p_this, "selected video pin accepts format: %4.4s",
878 (char *)&dshow_stream.i_fourcc);
880 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio )
882 dshow_stream.header.audio =
883 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
884 msg_Dbg( p_this, "MEDIATYPE_Audio" );
885 msg_Dbg( p_this, "selected audio pin accepts format: %4.4s",
886 (char *)&dshow_stream.i_fourcc);
888 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
890 msg_Dbg( p_this, "MEDIATYPE_Stream" );
891 msg_Dbg( p_this, "selected stream pin accepts format: %4.4s",
892 (char *)&dshow_stream.i_fourcc);
896 msg_Dbg( p_this, "unknown stream majortype" );
900 /* Add directshow elementary stream to our list */
901 dshow_stream.p_device_filter = p_device_filter;
902 dshow_stream.p_capture_filter = p_capture_filter;
904 p_sys->pp_streams = (dshow_stream_t **)realloc( p_sys->pp_streams,
905 sizeof(dshow_stream_t *) * (p_sys->i_streams + 1) );
906 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
907 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
914 /* Remove filters from graph */
915 p_sys->p_graph->RemoveFilter( p_device_filter );
916 p_sys->p_graph->RemoveFilter( p_capture_filter );
918 /* Release objects */
919 p_device_filter->Release();
920 p_capture_filter->Release();
926 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
927 list<string> *p_listdevices, vlc_bool_t b_audio )
929 IBaseFilter *p_base_filter = NULL;
930 IMoniker *p_moniker = NULL;
934 /* Create the system device enumerator */
935 ICreateDevEnum *p_dev_enum = NULL;
937 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
938 IID_ICreateDevEnum, (void **)&p_dev_enum );
941 msg_Err( p_this, "failed to create the device enumerator (0x%lx)", hr);
945 /* Create an enumerator for the video capture devices */
946 IEnumMoniker *p_class_enum = NULL;
948 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
951 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
953 p_dev_enum->Release();
956 msg_Err( p_this, "failed to create the class enumerator (0x%lx)", hr );
960 /* If there are no enumerators for the requested type, then
961 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
962 if( p_class_enum == NULL )
964 msg_Err( p_this, "no capture device was detected" );
968 /* Enumerate the devices */
970 /* Note that if the Next() call succeeds but there are no monikers,
971 * it will return S_FALSE (which is not a failure). Therefore, we check
972 * that the return code is S_OK instead of using SUCCEEDED() macro. */
974 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
976 /* Getting the property page to get the device name */
978 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
984 hr = p_bag->Read( L"FriendlyName", &var, NULL );
988 int i_convert = ( lstrlenW( var.bstrVal ) + 1 ) * 2;
989 char *p_buf = (char *)alloca( i_convert ); p_buf[0] = 0;
990 WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, p_buf,
991 i_convert, NULL, NULL );
992 SysFreeString(var.bstrVal);
994 if( p_listdevices ) p_listdevices->push_back( p_buf );
996 if( p_devicename && *p_devicename == string(p_buf) )
998 /* Bind Moniker to a filter object */
999 hr = p_moniker->BindToObject( 0, 0, IID_IBaseFilter,
1000 (void **)&p_base_filter );
1003 msg_Err( p_this, "couldn't bind moniker to filter "
1004 "object (0x%lx)", hr );
1005 p_moniker->Release();
1006 p_class_enum->Release();
1009 p_moniker->Release();
1010 p_class_enum->Release();
1011 return p_base_filter;
1016 p_moniker->Release();
1019 p_class_enum->Release();
1023 static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
1024 int i_fourcc, int i_width, int i_height,
1025 int i_channels, int i_samplespersec,
1026 int i_bitspersample, AM_MEDIA_TYPE *mt,
1029 IEnumPins *p_enumpins;
1031 IEnumMediaTypes *p_enummt;
1032 size_t mt_count = 0;
1034 if( FAILED(p_filter->EnumPins( &p_enumpins )) )
1036 msg_Dbg( p_this, "EnumDeviceCaps failed: no pin enumeration !");
1040 while( S_OK == p_enumpins->Next( 1, &p_output_pin, NULL ) )
1044 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1046 msg_Dbg( p_this, "EnumDeviceCaps: %s pin: %S",
1047 info.dir == PINDIR_INPUT ? "input" : "output",
1049 if( info.pFilter ) info.pFilter->Release();
1052 p_output_pin->Release();
1055 p_enumpins->Reset();
1057 while( !mt_count && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
1061 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
1063 if( info.pFilter ) info.pFilter->Release();
1064 if( info.dir == PINDIR_INPUT )
1066 p_output_pin->Release();
1069 msg_Dbg( p_this, "EnumDeviceCaps: trying pin %S", info.achName );
1073 if( !SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
1075 p_output_pin->Release();
1079 AM_MEDIA_TYPE *p_mt;
1080 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
1082 int i_current_fourcc = GetFourCCFromMediaType(*p_mt);
1083 if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Video )
1085 int i_current_width = p_mt->pbFormat ?
1086 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth :0;
1087 int i_current_height = p_mt->pbFormat ?
1088 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight :0;
1089 if( i_current_height < 0 )
1090 i_current_height = -i_current_height;
1092 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1093 "accepts chroma: %4.4s, width:%i, height:%i",
1094 (char *)&i_current_fourcc, i_current_width,
1097 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1098 ( !i_width || i_width == i_current_width ) &&
1099 ( !i_height || i_height == i_current_height ) &&
1103 mt[mt_count++] = *p_mt;
1105 else FreeMediaType( *p_mt );
1107 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Audio )
1109 int i_current_channels =
1110 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
1111 int i_current_samplespersec =
1112 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
1113 int i_current_bitspersample =
1114 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
1116 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
1117 "accepts format: %4.4s, channels:%i, "
1118 "samples/sec:%i bits/sample:%i",
1119 (char *)&i_current_fourcc, i_current_channels,
1120 i_current_samplespersec, i_current_bitspersample);
1122 if( (!i_channels || i_channels == i_current_channels) &&
1123 (!i_samplespersec ||
1124 i_samplespersec == i_current_samplespersec) &&
1125 (!i_bitspersample ||
1126 i_bitspersample == i_current_bitspersample) &&
1130 mt[mt_count++] = *p_mt;
1132 /* Setup a few properties like the audio latency */
1133 IAMBufferNegotiation *p_ambuf;
1134 if( SUCCEEDED( p_output_pin->QueryInterface(
1135 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
1137 ALLOCATOR_PROPERTIES AllocProp;
1138 AllocProp.cbAlign = -1;
1140 /* 100 ms of latency */
1141 AllocProp.cbBuffer = i_current_channels *
1142 i_current_samplespersec *
1143 i_current_bitspersample / 8 / 10;
1145 AllocProp.cbPrefix = -1;
1146 AllocProp.cBuffers = -1;
1147 p_ambuf->SuggestAllocatorProperties( &AllocProp );
1151 else FreeMediaType( *p_mt );
1153 else if( i_current_fourcc && p_mt->majortype == MEDIATYPE_Stream )
1155 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) &&
1159 mt[mt_count++] = *p_mt;
1160 i_fourcc = i_current_fourcc;
1162 else FreeMediaType( *p_mt );
1166 msg_Dbg( p_this, "EnumDeviceCaps: input pin: unknown format" );
1167 FreeMediaType( *p_mt );
1169 CoTaskMemFree( (PVOID)p_mt );
1172 p_enummt->Release();
1173 p_output_pin->Release();
1176 p_enumpins->Release();
1180 /*****************************************************************************
1181 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1182 *****************************************************************************
1183 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1185 *****************************************************************************/
1186 static int ReadCompressed( access_t *p_access, uint8_t *p_buffer, int i_len )
1188 access_sys_t *p_sys = p_access->p_sys;
1189 dshow_stream_t *p_stream = NULL;
1190 VLCMediaSample sample;
1194 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1196 /* There must be only 1 elementary stream to produce a valid stream
1197 * of MPEG or DV data */
1198 p_stream = p_sys->pp_streams[0];
1202 if( p_access->b_die || p_access->b_error ) return 0;
1204 /* Get new sample/frame from the elementary stream (blocking). */
1205 vlc_mutex_lock( &p_sys->lock );
1207 if( p_stream->p_capture_filter->CustomGetPin()
1208 ->CustomGetSample( &sample ) != S_OK )
1210 /* No data available. Wait until some data has arrived */
1211 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1212 vlc_mutex_unlock( &p_sys->lock );
1216 vlc_mutex_unlock( &p_sys->lock );
1221 i_data_size = sample.p_sample->GetActualDataLength();
1222 sample.p_sample->GetPointer( &p_data );
1225 msg_Info( p_access, "access read %i data_size %i", i_len, i_data_size );
1227 i_data_size = __MIN( i_data_size, (int)i_len );
1229 p_access->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1231 sample.p_sample->Release();
1233 /* The caller got what he wanted */
1237 return 0; /* never reached */
1240 /****************************************************************************
1242 ****************************************************************************/
1243 static int Demux( demux_t *p_demux )
1245 access_sys_t *p_sys = (access_sys_t *)p_demux->p_sys;
1246 dshow_stream_t *p_stream = NULL;
1247 VLCMediaSample sample;
1248 int i_data_size, i_stream;
1252 vlc_mutex_lock( &p_sys->lock );
1254 /* Try to grab an audio sample (audio has a higher priority) */
1255 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1257 p_stream = p_sys->pp_streams[i_stream];
1258 if( p_stream->mt.majortype == MEDIATYPE_Audio &&
1259 p_stream->p_capture_filter &&
1260 p_stream->p_capture_filter->CustomGetPin()
1261 ->CustomGetSample( &sample ) == S_OK )
1266 /* Try to grab a video sample */
1267 if( i_stream == p_sys->i_streams )
1268 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1270 p_stream = p_sys->pp_streams[i_stream];
1271 if( p_stream->p_capture_filter &&
1272 p_stream->p_capture_filter->CustomGetPin()
1273 ->CustomGetSample( &sample ) == S_OK )
1279 vlc_mutex_unlock( &p_sys->lock );
1281 if( i_stream == p_sys->i_streams )
1283 /* Sleep so we do not consume all the cpu, 10ms seems
1284 * like a good value (100fps) */
1292 i_data_size = sample.p_sample->GetActualDataLength();
1293 sample.p_sample->GetPointer( &p_data );
1295 REFERENCE_TIME i_pts, i_end_date;
1296 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1297 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1301 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1303 /* Use our data timestamp */
1304 i_pts = sample.i_timestamp;
1305 p_stream->b_pts = VLC_TRUE;
1309 i_pts /= 10; /* Dshow works with 100 nano-seconds resolution */
1312 msg_Dbg( p_demux, "Read() stream: %i, size: %i, PTS: "I64Fd,
1313 i_stream, i_data_size, i_pts );
1316 p_block = block_New( p_demux, i_data_size );
1317 p_demux->p_vlc->pf_memcpy( p_block->p_buffer, p_data, i_data_size );
1318 p_block->i_pts = p_block->i_dts = i_pts;
1319 sample.p_sample->Release();
1321 es_out_Control( p_demux->out, ES_OUT_SET_PCR, i_pts > 0 ? i_pts : 0 );
1322 es_out_Send( p_demux->out, p_stream->p_es, p_block );
1327 /*****************************************************************************
1329 *****************************************************************************/
1330 static int AccessControl( access_t *p_access, int i_query, va_list args )
1332 vlc_bool_t *pb_bool;
1339 case ACCESS_CAN_SEEK:
1340 case ACCESS_CAN_FASTSEEK:
1341 case ACCESS_CAN_PAUSE:
1342 case ACCESS_CAN_CONTROL_PACE:
1343 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
1344 *pb_bool = VLC_FALSE;
1348 case ACCESS_GET_MTU:
1349 pi_int = (int*)va_arg( args, int * );
1353 case ACCESS_GET_PTS_DELAY:
1354 pi_64 = (int64_t*)va_arg( args, int64_t * );
1355 *pi_64 = (int64_t)var_GetInteger( p_access, "dshow-caching" ) * 1000;
1359 case ACCESS_SET_PAUSE_STATE:
1360 case ACCESS_GET_TITLE_INFO:
1361 case ACCESS_SET_TITLE:
1362 case ACCESS_SET_SEEKPOINT:
1363 case ACCESS_SET_PRIVATE_ID_STATE:
1364 return VLC_EGENERIC;
1367 msg_Warn( p_access, "unimplemented query in control" );
1368 return VLC_EGENERIC;
1374 /****************************************************************************
1376 ****************************************************************************/
1377 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
1384 /* Special for access_demux */
1385 case DEMUX_CAN_PAUSE:
1386 case DEMUX_SET_PAUSE_STATE:
1387 case DEMUX_CAN_CONTROL_PACE:
1388 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
1392 case DEMUX_GET_PTS_DELAY:
1393 pi64 = (int64_t*)va_arg( args, int64_t * );
1394 *pi64 = (int64_t)var_GetInteger( p_demux, "dshow-caching" ) * 1000;
1397 case DEMUX_GET_TIME:
1398 pi64 = (int64_t*)va_arg( args, int64_t * );
1402 /* TODO implement others */
1404 return VLC_EGENERIC;
1407 return VLC_EGENERIC;
1410 /*****************************************************************************
1411 * config variable callback
1412 *****************************************************************************/
1413 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1414 vlc_value_t newval, vlc_value_t oldval, void * )
1416 module_config_t *p_item;
1417 vlc_bool_t b_audio = VLC_FALSE;
1420 p_item = config_FindConfig( p_this, psz_name );
1421 if( !p_item ) return VLC_SUCCESS;
1423 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1425 /* Clear-up the current list */
1426 if( p_item->i_list )
1428 /* Keep the 2 first entries */
1429 for( i = 2; i < p_item->i_list; i++ )
1431 free( p_item->ppsz_list[i] );
1432 free( p_item->ppsz_list_text[i] );
1434 /* TODO: Remove when no more needed */
1435 p_item->ppsz_list[i] = NULL;
1436 p_item->ppsz_list_text[i] = NULL;
1440 /* Find list of devices */
1441 list<string> list_devices;
1443 /* Initialize OLE/COM */
1446 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1448 /* Uninitialize OLE/COM */
1451 if( !list_devices.size() ) return VLC_SUCCESS;
1454 (char **)realloc( p_item->ppsz_list,
1455 (list_devices.size()+3) * sizeof(char *) );
1456 p_item->ppsz_list_text =
1457 (char **)realloc( p_item->ppsz_list_text,
1458 (list_devices.size()+3) * sizeof(char *) );
1460 list<string>::iterator iter;
1461 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1464 p_item->ppsz_list[i] = strdup( iter->c_str() );
1465 p_item->ppsz_list_text[i] = NULL;
1468 p_item->ppsz_list[i] = NULL;
1469 p_item->ppsz_list_text[i] = NULL;
1471 /* Signal change to the interface */
1472 p_item->b_dirty = VLC_TRUE;
1477 static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1478 vlc_value_t newval, vlc_value_t oldval, void * )
1480 module_config_t *p_item;
1481 vlc_bool_t b_audio = VLC_FALSE;
1483 /* Initialize OLE/COM */
1486 p_item = config_FindConfig( p_this, psz_name );
1487 if( !p_item ) return VLC_SUCCESS;
1489 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1493 if( newval.psz_string && *newval.psz_string )
1495 devicename = newval.psz_string;
1499 /* If no device name was specified, pick the 1st one */
1500 list<string> list_devices;
1502 /* Enumerate devices */
1503 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1504 if( !list_devices.size() ) return VLC_EGENERIC;
1505 devicename = *list_devices.begin();
1508 IBaseFilter *p_device_filter =
1509 FindCaptureDevice( p_this, &devicename, NULL, b_audio );
1510 if( p_device_filter )
1512 PropertiesPage( p_this, p_device_filter, NULL, b_audio );
1516 /* Uninitialize OLE/COM */
1519 msg_Err( p_this, "didn't find device: %s", devicename.c_str() );
1520 return VLC_EGENERIC;
1523 /* Uninitialize OLE/COM */
1529 static void ShowPropertyPage( IUnknown *obj, CAUUID *cauuid )
1531 if( cauuid->cElems > 0 )
1533 HWND hwnd_desktop = ::GetDesktopWindow();
1535 OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1, &obj,
1536 cauuid->cElems, cauuid->pElems, 0, 0, NULL );
1538 CoTaskMemFree( cauuid->pElems );
1542 static void PropertiesPage( vlc_object_t *p_this, IBaseFilter *p_device_filter,
1543 ICaptureGraphBuilder2 *p_capture_graph,
1544 vlc_bool_t b_audio )
1548 msg_Dbg( p_this, "Configuring Device Properties" );
1551 * Video or audio capture filter page
1553 ISpecifyPropertyPages *p_spec;
1555 HRESULT hr = p_device_filter->QueryInterface( IID_ISpecifyPropertyPages,
1559 if( SUCCEEDED(p_spec->GetPages( &cauuid )) )
1561 ShowPropertyPage( p_device_filter, &cauuid );
1566 msg_Dbg( p_this, "looking for WDM Configuration Pages" );
1568 if( p_capture_graph )
1569 msg_Dbg( p_this, "got capture graph for WDM Configuration Pages" );
1574 if( p_capture_graph && b_audio )
1576 IAMStreamConfig *p_SC;
1578 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1579 &MEDIATYPE_Audio, p_device_filter,
1580 IID_IAMStreamConfig,
1584 hr = p_SC->QueryInterface( IID_ISpecifyPropertyPages,
1588 hr = p_spec->GetPages( &cauuid );
1591 for( unsigned int c = 0; c < cauuid.cElems; c++ )
1593 ShowPropertyPage( p_SC, &cauuid );
1595 CoTaskMemFree( cauuid.pElems );
1606 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1607 &MEDIATYPE_Audio, p_device_filter,
1608 IID_IAMTVAudio, (void **)&p_TVA );
1611 hr = p_TVA->QueryInterface( IID_ISpecifyPropertyPages,
1615 if( SUCCEEDED( p_spec->GetPages( &cauuid ) ) )
1616 ShowPropertyPage(p_TVA, &cauuid);
1627 if( p_capture_graph && !b_audio )
1629 IAMStreamConfig *p_SC;
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 hr = p_SC->QueryInterface( IID_ISpecifyPropertyPages,
1651 if( SUCCEEDED( p_spec->GetPages(&cauuid) ) )
1653 ShowPropertyPage(p_SC, &cauuid);
1661 * Video crossbar, and a possible second crossbar
1663 IAMCrossbar *p_X, *p_X2;
1666 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1667 &MEDIATYPE_Interleaved,
1669 IID_IAMCrossbar, (void **)&p_X );
1672 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1681 hr = p_X->QueryInterface( IID_IBaseFilter, (void **)&p_XF );
1684 hr = p_X->QueryInterface( IID_ISpecifyPropertyPages,
1688 hr = p_spec->GetPages(&cauuid);
1689 if( hr == S_OK && cauuid.cElems > 0 )
1691 ShowPropertyPage( p_X, &cauuid );
1696 hr = p_capture_graph->FindInterface( &LOOK_UPSTREAM_ONLY, NULL,
1697 p_XF, IID_IAMCrossbar,
1701 hr = p_X2->QueryInterface( IID_ISpecifyPropertyPages,
1705 hr = p_spec->GetPages( &cauuid );
1708 ShowPropertyPage( p_X2, &cauuid );
1725 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1726 &MEDIATYPE_Interleaved,
1728 IID_IAMTVTuner, (void **)&p_TV );
1731 hr = p_capture_graph->FindInterface( &PIN_CATEGORY_CAPTURE,
1740 hr = p_TV->QueryInterface( IID_ISpecifyPropertyPages,
1744 hr = p_spec->GetPages(&cauuid);
1747 ShowPropertyPage(p_TV, &cauuid);