1 /*****************************************************************************
2 * dshow.cpp : DirectShow access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: dshow.cpp,v 1.21 2003/12/15 00:47:18 gbazin Exp $
7 * Author: Gildas Bazin <gbazin@netcourrier.com>
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>
37 /*****************************************************************************
38 * Access: local prototypes
39 *****************************************************************************/
40 static ssize_t Read ( input_thread_t *, byte_t *, size_t );
41 static ssize_t ReadCompressed( input_thread_t *, byte_t *, size_t );
43 static int OpenDevice( input_thread_t *, string, vlc_bool_t );
44 static IBaseFilter *FindCaptureDevice( vlc_object_t *, string *,
45 list<string> *, vlc_bool_t );
46 static AM_MEDIA_TYPE EnumDeviceCaps( vlc_object_t *, IBaseFilter *,
47 int, int, int, int, int, int );
48 static bool ConnectFilters( IFilterGraph *, IBaseFilter *, IPin * );
50 static int FindDevicesCallback( vlc_object_t *, char const *,
51 vlc_value_t, vlc_value_t, void * );
53 static void PropertiesPage( input_thread_t *, IBaseFilter * );
56 /* Debug only, use this to find out GUIDs */
58 UuidToString( (IID *)&IID_IAMBufferNegotiation, &p_st );
59 msg_Err( p_input, "BufferNegotiation: %s" , p_st );
83 static void SetDWBE( uint8_t *p, uint32_t dw )
85 p[0] = (dw >> 24)&0xff;
86 p[1] = (dw >> 16)&0xff;
87 p[2] = (dw >> 8)&0xff;
91 static void SetQWBE( uint8_t *p, uint64_t qw )
93 SetDWBE( p, (qw >> 32)&0xffffffff );
94 SetDWBE( &p[4], qw&0xffffffff );
97 /*****************************************************************************
99 *****************************************************************************/
100 static char *ppsz_vdev[] = { "", "none" };
101 static char *ppsz_vdev_text[] = { N_("Default"), N_("None") };
102 static char *ppsz_adev[] = { "", "none" };
103 static char *ppsz_adev_text[] = { N_("Default"), N_("None") };
105 #define CACHING_TEXT N_("Caching value in ms")
106 #define CACHING_LONGTEXT N_( \
107 "Allows you to modify the default caching value for directshow streams. " \
108 "This value should be set in miliseconds units." )
109 #define VDEV_TEXT N_("Video device name")
110 #define VDEV_LONGTEXT N_( \
111 "You can specify the name of the video device that will be used by the " \
112 "DirectShow plugin. If you don't specify anything, the default device " \
114 #define ADEV_TEXT N_("Audio device name")
115 #define ADEV_LONGTEXT N_( \
116 "You can specify the name of the audio device that will be used by the " \
117 "DirectShow plugin. If you don't specify anything, the default device " \
119 #define SIZE_TEXT N_("Video size")
120 #define SIZE_LONGTEXT N_( \
121 "You can specify the size of the video that will be displayed by the " \
122 "DirectShow plugin. If you don't specify anything the default size for " \
123 "your device will be used.")
124 #define CHROMA_TEXT N_("Video input chroma format")
125 #define CHROMA_LONGTEXT N_( \
126 "Force the DirectShow video input to use a specific chroma format " \
127 "(eg. I420 (default), RV24, etc.)")
128 #define CONFIG_TEXT N_("Device properties")
129 #define CONFIG_LONGTEXT N_( \
130 "Show the properties dialog of the selected device")
132 static int AccessOpen ( vlc_object_t * );
133 static void AccessClose( vlc_object_t * );
135 static int DemuxOpen ( vlc_object_t * );
136 static void DemuxClose ( vlc_object_t * );
139 set_description( _("DirectShow input") );
140 add_category_hint( N_("dshow"), NULL, VLC_TRUE );
141 add_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,
142 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
144 add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, VLC_FALSE);
145 change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback );
147 add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE);
148 change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback );
150 add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE);
152 add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
155 add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,
158 add_shortcut( "dshow" );
159 set_capability( "access", 0 );
160 set_callbacks( AccessOpen, AccessClose );
163 set_description( _("DirectShow demuxer") );
164 add_shortcut( "dshow" );
165 set_capability( "demux", 200 );
166 set_callbacks( DemuxOpen, DemuxClose );
170 /****************************************************************************
171 * DirectShow elementary stream descriptor
172 ****************************************************************************/
173 typedef struct dshow_stream_t
176 IBaseFilter *p_device_filter;
177 CaptureFilter *p_capture_filter;
184 VIDEOINFOHEADER video;
193 /****************************************************************************
194 * Access descriptor declaration
195 ****************************************************************************/
201 IFilterGraph *p_graph;
202 IMediaControl *p_control;
209 /* list of elementary streams */
210 dshow_stream_t **pp_streams;
212 int i_current_stream;
214 /* misc properties */
221 /*****************************************************************************
222 * Open: open direct show device
223 *****************************************************************************/
224 static int AccessOpen( vlc_object_t *p_this )
226 input_thread_t *p_input = (input_thread_t *)p_this;
230 /* Get/parse options and open device(s) */
231 string vdevname, adevname;
232 int i_width = 0, i_height = 0, i_chroma = 0;
234 var_Create( p_input, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
235 var_Get( p_input, "dshow-vdev", &val );
236 if( val.psz_string ) vdevname = string( val.psz_string );
237 if( val.psz_string ) free( val.psz_string );
239 var_Create( p_input, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
240 var_Get( p_input, "dshow-adev", &val );
241 if( val.psz_string ) adevname = string( val.psz_string );
242 if( val.psz_string ) free( val.psz_string );
244 var_Create( p_input, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
245 var_Get( p_input, "dshow-size", &val );
246 if( val.psz_string && *val.psz_string )
248 if( !strcmp( val.psz_string, "subqcif" ) )
250 i_width = 128; i_height = 96;
252 else if( !strcmp( val.psz_string, "qsif" ) )
254 i_width = 160; i_height = 120;
256 else if( !strcmp( val.psz_string, "qcif" ) )
258 i_width = 176; i_height = 144;
260 else if( !strcmp( val.psz_string, "sif" ) )
262 i_width = 320; i_height = 240;
264 else if( !strcmp( val.psz_string, "cif" ) )
266 i_width = 352; i_height = 288;
268 else if( !strcmp( val.psz_string, "vga" ) )
270 i_width = 640; i_height = 480;
276 i_width = strtol( val.psz_string, &psz_parser, 0 );
277 if( *psz_parser == 'x' || *psz_parser == 'X')
279 i_height = strtol( psz_parser + 1, &psz_parser, 0 );
281 msg_Dbg( p_input, "Width x Height %dx%d", i_width, i_height );
284 if( val.psz_string ) free( val.psz_string );
286 var_Create( p_input, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
287 var_Get( p_input, "dshow-chroma", &val );
288 if( val.psz_string && strlen( val.psz_string ) >= 4 )
290 i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],
291 val.psz_string[2], val.psz_string[3] );
293 if( val.psz_string ) free( val.psz_string );
295 p_input->pf_read = Read;
296 p_input->pf_seek = NULL;
297 p_input->pf_set_area = NULL;
298 p_input->pf_set_program = NULL;
300 vlc_mutex_lock( &p_input->stream.stream_lock );
301 p_input->stream.b_pace_control = 0;
302 p_input->stream.b_seekable = 0;
303 p_input->stream.p_selected_area->i_size = 0;
304 p_input->stream.p_selected_area->i_tell = 0;
305 p_input->stream.i_method = INPUT_METHOD_FILE;
306 vlc_mutex_unlock( &p_input->stream.stream_lock );
308 var_Create( p_input, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
309 var_Get( p_input, "dshow-caching", &val );
310 p_input->i_pts_delay = val.i_int * 1000;
312 /* Initialize OLE/COM */
315 /* create access private data */
316 p_input->p_access_data = p_sys =
317 (access_sys_t *)malloc( sizeof( access_sys_t ) );
319 /* Initialize some data */
320 p_sys->i_streams = 0;
321 p_sys->pp_streams = (dshow_stream_t **)malloc( 1 );
322 p_sys->i_width = i_width;
323 p_sys->i_height = i_height;
324 p_sys->i_chroma = i_chroma;
325 p_sys->b_audio = VLC_TRUE;
328 p_sys->i_header_size = 8;
329 p_sys->p_header = (uint8_t *)malloc( p_sys->i_header_size );
330 memcpy( &p_sys->p_header[0], ".dsh", 4 );
331 SetDWBE( &p_sys->p_header[4], 1 );
332 p_sys->i_header_pos = p_sys->i_header_size;
334 /* Build directshow graph */
335 CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,
336 (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph );
338 p_sys->p_graph->QueryInterface( IID_IMediaControl,
339 (void **)&p_sys->p_control );
341 if( OpenDevice( p_input, vdevname, 0 ) != VLC_SUCCESS )
343 msg_Err( p_input, "can't open video");
346 if( p_sys->b_audio && OpenDevice( p_input, adevname, 1 ) != VLC_SUCCESS )
348 msg_Err( p_input, "can't open audio");
351 if( !p_sys->i_streams )
353 /* Release directshow objects */
354 if( p_sys->p_control ) p_sys->p_control->Release();
355 p_sys->p_graph->Release();
357 /* Uninitialize OLE/COM */
360 free( p_sys->p_header );
361 free( p_sys->pp_streams );
366 /* Initialize some data */
367 p_sys->i_current_stream = 0;
368 p_input->i_mtu += p_sys->i_header_size + 16 /* data header size */;
370 vlc_mutex_init( p_input, &p_sys->lock );
371 vlc_cond_init( p_input, &p_sys->wait );
373 /* Everything is ready. Let's rock baby */
374 p_sys->p_control->Run();
379 /*****************************************************************************
380 * AccessClose: close device
381 *****************************************************************************/
382 static void AccessClose( vlc_object_t *p_this )
384 input_thread_t *p_input = (input_thread_t *)p_this;
385 access_sys_t *p_sys = p_input->p_access_data;
387 /* Stop capturing stuff */
388 //p_sys->p_control->Stop(); /* FIXME?: we get stuck here sometimes */
389 p_sys->p_control->Release();
391 /* Remove filters from graph */
392 for( int i = 0; i < p_sys->i_streams; i++ )
394 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );
395 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );
396 p_sys->pp_streams[i]->p_capture_filter->Release();
397 p_sys->pp_streams[i]->p_device_filter->Release();
399 p_sys->p_graph->Release();
401 /* Uninitialize OLE/COM */
404 free( p_sys->p_header );
405 for( int i = 0; i < p_sys->i_streams; i++ ) delete p_sys->pp_streams[i];
406 free( p_sys->pp_streams );
410 /****************************************************************************
412 ****************************************************************************/
413 static bool ConnectFilters( IFilterGraph *p_graph, IBaseFilter *p_filter,
416 IEnumPins *p_enumpins;
420 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
422 while( S_OK == p_enumpins->Next( 1, &p_output_pin, &i_fetched ) )
424 if( S_OK == p_graph->ConnectDirect( p_output_pin, p_input_pin, 0 ) )
426 p_enumpins->Release();
431 p_enumpins->Release();
435 static int OpenDevice( input_thread_t *p_input, string devicename,
438 access_sys_t *p_sys = p_input->p_access_data;
439 list<string> list_devices;
441 /* Enumerate devices and display their names */
442 FindCaptureDevice( (vlc_object_t *)p_input, NULL, &list_devices, b_audio );
444 if( !list_devices.size() )
447 list<string>::iterator iter;
448 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
449 msg_Dbg( p_input, "found device: %s", iter->c_str() );
451 /* If no device name was specified, pick the 1st one */
452 if( devicename.size() == 0 )
454 devicename = *list_devices.begin();
457 // Use the system device enumerator and class enumerator to find
458 // a capture/preview device, such as a desktop USB video camera.
459 IBaseFilter *p_device_filter =
460 FindCaptureDevice( (vlc_object_t *)p_input, &devicename,
462 if( p_device_filter )
463 msg_Dbg( p_input, "using device: %s", devicename.c_str() );
466 msg_Err( p_input, "can't use device: %s", devicename.c_str() );
470 AM_MEDIA_TYPE media_type =
471 EnumDeviceCaps( (vlc_object_t *)p_input, p_device_filter,
472 p_sys->i_chroma, p_sys->i_width, p_sys->i_height,
475 /* Create and add our capture filter */
476 CaptureFilter *p_capture_filter = new CaptureFilter( p_input, media_type );
477 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
479 /* Add the device filter to the graph (seems necessary with VfW before
480 * accessing pin attributes). */
481 p_sys->p_graph->AddFilter( p_device_filter, 0 );
483 /* Attempt to connect one of this device's capture output pins */
484 msg_Dbg( p_input, "connecting filters" );
485 if( ConnectFilters( p_sys->p_graph, p_device_filter,
486 p_capture_filter->CustomGetPin() ) )
489 dshow_stream_t dshow_stream;
490 dshow_stream.b_invert = VLC_FALSE;
491 dshow_stream.b_pts = VLC_FALSE;
493 p_capture_filter->CustomGetPin()->CustomGetMediaType();
495 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
497 msg_Dbg( p_input, "MEDIATYPE_Video");
499 /* Packed RGB formats */
500 if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB1 )
501 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' );
502 if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB4 )
503 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' );
504 if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB8 )
505 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' );
506 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB555 )
507 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' );
508 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB565 )
509 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' );
510 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB24 )
511 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' );
512 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB32 )
513 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' );
514 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_ARGB32 )
515 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' );
517 /* Packed YUV formats */
518 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YVYU )
519 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'V', 'Y', 'U' );
520 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YUYV )
521 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', 'V' );
522 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_Y411 )
523 dshow_stream.i_fourcc = VLC_FOURCC( 'I', '4', '1', 'N' );
524 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_Y211 )
525 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', '2', '1', '1' );
526 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YUY2 ||
527 dshow_stream.mt.subtype == MEDIASUBTYPE_UYVY )
528 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' );
530 /* Planar YUV formats */
531 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_I420 )
532 dshow_stream.i_fourcc = VLC_FOURCC( 'I', '4', '2', '0' );
533 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_Y41P )
534 dshow_stream.i_fourcc = VLC_FOURCC( 'I', '4', '1', '1' );
535 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YV12 ||
536 dshow_stream.mt.subtype == MEDIASUBTYPE_IYUV )
537 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' );
538 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YVU9 )
539 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'V', 'U', '9' );
542 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_dvsl )
543 dshow_stream.i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'l' );
544 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_dvsd )
545 dshow_stream.i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'd' );
546 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_dvhd )
547 dshow_stream.i_fourcc = VLC_FOURCC( 'd', 'v', 'h', 'd' );
549 /* MPEG video formats */
550 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_MPEG2_VIDEO )
551 dshow_stream.i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
555 dshow_stream.header.video =
556 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
558 int i_height = dshow_stream.header.video.bmiHeader.biHeight;
560 /* Check if the image is inverted (bottom to top) */
561 if( dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', '1' ) ||
562 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', '4' ) ||
563 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', '8' ) ||
564 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '1', '5' ) ||
565 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '1', '6' ) ||
566 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '2', '4' ) ||
567 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '3', '2' ) ||
568 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', 'A' ) )
570 if( i_height > 0 ) dshow_stream.b_invert = VLC_TRUE;
571 else i_height = - i_height;
574 /* Check if we are dealing with a DV stream */
575 if( dshow_stream.i_fourcc == VLC_FOURCC( 'd', 'v', 's', 'l' ) ||
576 dshow_stream.i_fourcc == VLC_FOURCC( 'd', 'v', 's', 'd' ) ||
577 dshow_stream.i_fourcc == VLC_FOURCC( 'd', 'v', 'h', 'd' ) )
579 p_input->pf_read = ReadCompressed;
580 if( !p_input->psz_demux || !*p_input->psz_demux )
582 p_input->psz_demux = "rawdv";
584 p_sys->b_audio = VLC_FALSE;
587 /* Check if we are dealing with an MPEG video stream */
588 if( dshow_stream.i_fourcc == VLC_FOURCC( 'm', 'p', '2', 'v' ) )
590 p_input->pf_read = ReadCompressed;
591 if( !p_input->psz_demux || !*p_input->psz_demux )
593 p_input->psz_demux = "mpgv";
595 p_sys->b_audio = VLC_FALSE;
598 /* Add video stream to header */
599 p_sys->i_header_size += 20;
600 p_sys->p_header = (uint8_t *)realloc( p_sys->p_header,
601 p_sys->i_header_size );
602 memcpy( &p_sys->p_header[p_sys->i_header_pos], "vids", 4 );
603 memcpy( &p_sys->p_header[p_sys->i_header_pos + 4],
604 &dshow_stream.i_fourcc, 4 );
605 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 8],
606 dshow_stream.header.video.bmiHeader.biWidth );
607 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 12], i_height );
608 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 16], 0 );
609 p_sys->i_header_pos = p_sys->i_header_size;
611 /* Greatly simplifies the reading routine */
612 int i_mtu = dshow_stream.header.video.bmiHeader.biWidth *
614 p_input->i_mtu = __MAX( p_input->i_mtu, (unsigned int)i_mtu );
617 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio &&
618 dshow_stream.mt.formattype == FORMAT_WaveFormatEx )
620 msg_Dbg( p_input, "MEDIATYPE_Audio");
622 if( dshow_stream.mt.subtype == MEDIASUBTYPE_PCM )
623 dshow_stream.i_fourcc = VLC_FOURCC( 'a', 'r', 'a', 'w' );
624 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_IEEE_FLOAT )
625 dshow_stream.i_fourcc = VLC_FOURCC( 'f', 'l', '3', '2' );
628 dshow_stream.header.audio =
629 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
631 /* Add audio stream to header */
632 p_sys->i_header_size += 20;
633 p_sys->p_header = (uint8_t *)realloc( p_sys->p_header,
634 p_sys->i_header_size );
635 memcpy( &p_sys->p_header[p_sys->i_header_pos], "auds", 4 );
636 memcpy( &p_sys->p_header[p_sys->i_header_pos + 4],
637 &dshow_stream.i_fourcc, 4 );
638 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 8],
639 dshow_stream.header.audio.nChannels );
640 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 12],
641 dshow_stream.header.audio.nSamplesPerSec );
642 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 16],
643 dshow_stream.header.audio.wBitsPerSample );
644 p_sys->i_header_pos = p_sys->i_header_size;
646 /* Greatly simplifies the reading routine */
647 IAMBufferNegotiation *p_ambuf;
651 p_capture_filter->CustomGetPin()->ConnectedTo( &p_pin );
652 if( SUCCEEDED( p_pin->QueryInterface(
653 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
655 ALLOCATOR_PROPERTIES AllocProp;
656 memset( &AllocProp, 0, sizeof( ALLOCATOR_PROPERTIES ) );
657 p_ambuf->GetAllocatorProperties( &AllocProp );
659 i_mtu = AllocProp.cbBuffer;
664 i_mtu = dshow_stream.header.audio.nSamplesPerSec *
665 dshow_stream.header.audio.nChannels *
666 dshow_stream.header.audio.wBitsPerSample / 8;
669 p_input->i_mtu = __MAX( p_input->i_mtu, (unsigned int)i_mtu );
672 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
674 msg_Dbg( p_input, "MEDIATYPE_Stream" );
676 if( dshow_stream.mt.subtype == MEDIASUBTYPE_MPEG2_PROGRAM )
677 dshow_stream.i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'p' );
678 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_MPEG2_TRANSPORT )
679 dshow_stream.i_fourcc = VLC_FOURCC( 'm', 'p', '2', 't' );
681 msg_Dbg( p_input, "selected stream pin accepts format: %4.4s",
682 (char *)&dshow_stream.i_fourcc);
684 p_sys->b_audio = VLC_FALSE;
685 p_sys->i_header_size = 0;
686 p_sys->i_header_pos = 0;
687 p_input->i_mtu = INPUT_DEFAULT_BUFSIZE;
689 p_input->pf_read = ReadCompressed;
690 p_input->pf_set_program = input_SetProgram;
695 msg_Dbg( p_input, "unknown stream majortype" );
699 /* Show properties */
701 var_Create( p_input, "dshow-config",
702 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
703 var_Get( p_input, "dshow-config", &val );
705 if(val.i_int) PropertiesPage( p_input, p_device_filter );
707 /* Add directshow elementary stream to our list */
708 dshow_stream.p_device_filter = p_device_filter;
709 dshow_stream.p_capture_filter = p_capture_filter;
712 (dshow_stream_t **)realloc( p_sys->pp_streams,
713 sizeof(dshow_stream_t *)
714 * (p_sys->i_streams + 1) );
715 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
716 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
717 SetDWBE( &p_sys->p_header[4], (uint32_t)p_sys->i_streams );
723 /* Remove filters from graph */
724 p_sys->p_graph->RemoveFilter( p_device_filter );
725 p_sys->p_graph->RemoveFilter( p_capture_filter );
727 /* Release objects */
728 p_device_filter->Release();
729 p_capture_filter->Release();
735 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
736 list<string> *p_listdevices, vlc_bool_t b_audio )
738 IBaseFilter *p_base_filter = NULL;
739 IMoniker *p_moniker = NULL;
743 /* Create the system device enumerator */
744 ICreateDevEnum *p_dev_enum = NULL;
746 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
747 IID_ICreateDevEnum, (void **)&p_dev_enum );
750 msg_Err( p_this, "failed to create the device enumerator (0x%x)", hr);
754 /* Create an enumerator for the video capture devices */
755 IEnumMoniker *p_class_enum = NULL;
757 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
760 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
762 p_dev_enum->Release();
765 msg_Err( p_this, "failed to create the class enumerator (0x%x)", hr );
769 /* If there are no enumerators for the requested type, then
770 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
771 if( p_class_enum == NULL )
773 msg_Err( p_this, "no capture device was detected." );
777 /* Enumerate the devices */
779 /* Note that if the Next() call succeeds but there are no monikers,
780 * it will return S_FALSE (which is not a failure). Therefore, we check
781 * that the return code is S_OK instead of using SUCCEEDED() macro. */
783 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
785 /* Getting the property page to get the device name */
787 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
793 hr = p_bag->Read( L"FriendlyName", &var, NULL );
797 int i_convert = ( lstrlenW( var.bstrVal ) + 1 ) * 2;
798 char *p_buf = (char *)alloca( i_convert ); p_buf[0] = 0;
799 WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, p_buf,
800 i_convert, NULL, NULL );
801 SysFreeString(var.bstrVal);
803 if( p_listdevices ) p_listdevices->push_back( p_buf );
805 if( p_devicename && *p_devicename == string(p_buf) )
807 /* Bind Moniker to a filter object */
808 hr = p_moniker->BindToObject( 0, 0, IID_IBaseFilter,
809 (void **)&p_base_filter );
812 msg_Err( p_this, "couldn't bind moniker to filter "
813 "object (0x%x)", hr );
814 p_moniker->Release();
815 p_class_enum->Release();
818 p_moniker->Release();
819 p_class_enum->Release();
820 return p_base_filter;
825 p_moniker->Release();
828 p_class_enum->Release();
832 static AM_MEDIA_TYPE EnumDeviceCaps( vlc_object_t *p_this,
833 IBaseFilter *p_filter,
834 int i_fourcc, int i_width, int i_height,
835 int i_channels, int i_samplespersec,
836 int i_bitspersample )
838 IEnumPins *p_enumpins;
840 IEnumMediaTypes *p_enummt;
841 int i_orig_fourcc = i_fourcc;
842 vlc_bool_t b_found = VLC_FALSE;
844 AM_MEDIA_TYPE media_type;
845 media_type.majortype = GUID_NULL;
846 media_type.subtype = GUID_NULL;
847 media_type.formattype = GUID_NULL;
848 media_type.pUnk = NULL;
849 media_type.cbFormat = 0;
850 media_type.pbFormat = NULL;
852 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return media_type;
854 while( !b_found && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
858 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
860 msg_Dbg( p_this, "EnumDeviceCaps: pin %S", info.achName );
861 if( info.pFilter ) info.pFilter->Release();
865 if( SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
868 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
871 if( p_mt->majortype == MEDIATYPE_Video )
873 int i_current_fourcc = VLC_FOURCC(' ', ' ', ' ', ' ');
875 /* Packed RGB formats */
876 if( p_mt->subtype == MEDIASUBTYPE_RGB1 )
877 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' );
878 if( p_mt->subtype == MEDIASUBTYPE_RGB4 )
879 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' );
880 if( p_mt->subtype == MEDIASUBTYPE_RGB8 )
881 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' );
882 else if( p_mt->subtype == MEDIASUBTYPE_RGB555 )
883 i_current_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' );
884 else if( p_mt->subtype == MEDIASUBTYPE_RGB565 )
885 i_current_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' );
886 else if( p_mt->subtype == MEDIASUBTYPE_RGB24 )
887 i_current_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' );
888 else if( p_mt->subtype == MEDIASUBTYPE_RGB32 )
889 i_current_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' );
890 else if( p_mt->subtype == MEDIASUBTYPE_ARGB32 )
891 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' );
893 /* MPEG2 video elementary stream */
894 else if( p_mt->subtype == MEDIASUBTYPE_MPEG2_VIDEO )
895 i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
897 /* hauppauge pvr video preview */
898 else if( p_mt->subtype == MEDIASUBTYPE_PREVIEW_VIDEO )
899 i_current_fourcc = VLC_FOURCC( 'P', 'V', 'R', 'V' );
901 else i_current_fourcc = *((int *)&p_mt->subtype);
903 int i_current_width = p_mt->pbFormat ?
904 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth : 0;
905 int i_current_height = p_mt->pbFormat ?
906 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight : 0;
907 if( i_current_height < 0 )
908 i_current_height = -i_current_height;
910 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
911 "accepts chroma: %4.4s, width:%i, height:%i",
912 (char *)&i_current_fourcc, i_current_width,
915 if( ( !i_fourcc || i_fourcc == i_current_fourcc ||
916 ( !i_orig_fourcc && i_current_fourcc ==
917 VLC_FOURCC('I','4','2','0') ) ) &&
918 ( !i_width || i_width == i_current_width ) &&
919 ( !i_height || i_height == i_current_height ) )
921 /* Pick the 1st match */
923 i_fourcc = i_current_fourcc;
924 i_width = i_current_width;
925 i_height = i_current_height;
930 FreeMediaType( *p_mt );
933 else if( p_mt->majortype == MEDIATYPE_Audio )
935 int i_current_fourcc;
936 int i_current_channels =
937 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
938 int i_current_samplespersec =
939 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
940 int i_current_bitspersample =
941 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
943 if( p_mt->subtype == MEDIASUBTYPE_PCM )
944 i_current_fourcc = VLC_FOURCC( 'p', 'c', 'm', ' ' );
945 else i_current_fourcc = *((int *)&p_mt->subtype);
947 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
948 "accepts format: %4.4s, channels:%i, "
949 "samples/sec:%i bits/sample:%i",
950 (char *)&i_current_fourcc, i_current_channels,
951 i_current_samplespersec, i_current_bitspersample);
953 if( (!i_channels || i_channels == i_current_channels) &&
955 i_samplespersec == i_current_samplespersec) &&
957 i_bitspersample == i_current_bitspersample) )
959 /* Pick the 1st match */
961 i_channels = i_current_channels;
962 i_samplespersec = i_current_samplespersec;
963 i_bitspersample = i_current_bitspersample;
966 /* Setup a few properties like the audio latency */
967 IAMBufferNegotiation *p_ambuf;
969 if( SUCCEEDED( p_output_pin->QueryInterface(
970 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
972 ALLOCATOR_PROPERTIES AllocProp;
973 AllocProp.cbAlign = -1;
974 AllocProp.cbBuffer = i_channels * i_samplespersec *
975 i_bitspersample / 8 / 10 ; /*100 ms of latency*/
976 AllocProp.cbPrefix = -1;
977 AllocProp.cBuffers = -1;
978 p_ambuf->SuggestAllocatorProperties( &AllocProp );
984 FreeMediaType( *p_mt );
987 else if( p_mt->majortype == MEDIATYPE_Stream )
989 msg_Dbg( p_this, "EnumDeviceCaps: MEDIATYPE_Stream" );
991 int i_current_fourcc = VLC_FOURCC(' ', ' ', ' ', ' ');
993 if( p_mt->subtype == MEDIASUBTYPE_MPEG2_PROGRAM )
994 i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 'p' );
995 else if( p_mt->subtype == MEDIASUBTYPE_MPEG2_TRANSPORT )
996 i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 't' );
998 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) )
1000 /* Pick the 1st match */
1002 i_fourcc = i_current_fourcc;
1007 FreeMediaType( *p_mt );
1013 "EnumDeviceCaps: input pin: unknown format" );
1014 FreeMediaType( *p_mt );
1017 CoTaskMemFree( (PVOID)p_mt );
1019 p_enummt->Release();
1022 p_output_pin->Release();
1025 p_enumpins->Release();
1029 /*****************************************************************************
1030 * Read: reads from the device into PES packets.
1031 *****************************************************************************
1032 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1034 *****************************************************************************/
1035 static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer,
1038 access_sys_t *p_sys = p_input->p_access_data;
1039 dshow_stream_t *p_stream = NULL;
1040 byte_t *p_buf_orig = p_buffer;
1041 VLCMediaSample sample;
1045 if( p_sys->i_header_pos )
1047 /* First header of the stream */
1048 memcpy( p_buffer, p_sys->p_header, p_sys->i_header_size );
1049 p_buffer += p_sys->i_header_size;
1050 p_sys->i_header_pos = 0;
1055 /* Get new sample/frame from next elementary stream.
1056 * We first loop through all the elementary streams and if all our
1057 * fifos are empty we block until we are signaled some new data has
1059 vlc_mutex_lock( &p_sys->lock );
1062 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1064 p_stream = p_sys->pp_streams[i_stream];
1065 if( p_stream->mt.majortype == MEDIATYPE_Audio &&
1066 p_stream->p_capture_filter &&
1067 p_stream->p_capture_filter->CustomGetPin()
1068 ->CustomGetSample( &sample ) == S_OK )
1073 if( i_stream == p_sys->i_streams )
1074 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1076 p_stream = p_sys->pp_streams[i_stream];
1077 if( p_stream->p_capture_filter &&
1078 p_stream->p_capture_filter->CustomGetPin()
1079 ->CustomGetSample( &sample ) == S_OK )
1084 if( i_stream == p_sys->i_streams )
1086 /* No data available. Wait until some data has arrived */
1087 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1088 vlc_mutex_unlock( &p_sys->lock );
1092 vlc_mutex_unlock( &p_sys->lock );
1097 i_data_size = sample.p_sample->GetActualDataLength();
1098 sample.p_sample->GetPointer( &p_data );
1100 REFERENCE_TIME i_pts, i_end_date;
1101 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1102 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1106 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1108 /* Use our data timestamp */
1109 i_pts = sample.i_timestamp;
1110 p_stream->b_pts = VLC_TRUE;
1115 msg_Dbg( p_input, "Read() stream: %i PTS: "I64Fd, i_stream, i_pts );
1118 /* Create pseudo header */
1119 SetDWBE( &p_sys->p_header[0], i_stream );
1120 SetDWBE( &p_sys->p_header[4], i_data_size );
1121 SetQWBE( &p_sys->p_header[8], i_pts * 9 / 1000 );
1124 msg_Info( p_input, "access read %i data_size %i", i_len, i_data_size );
1127 /* First copy header */
1128 memcpy( p_buffer, p_sys->p_header, 16 /* header size */ );
1129 p_buffer += 16 /* header size */;
1131 /* Then copy stream data if any */
1132 if( !p_stream->b_invert )
1134 p_input->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1135 p_buffer += i_data_size;
1139 int i_width = p_stream->header.video.bmiHeader.biWidth;
1140 int i_height = p_stream->header.video.bmiHeader.biHeight;
1141 if( i_height < 0 ) i_height = - i_height;
1143 switch( p_stream->i_fourcc )
1145 case VLC_FOURCC( 'R', 'V', '1', '5' ):
1146 case VLC_FOURCC( 'R', 'V', '1', '6' ):
1149 case VLC_FOURCC( 'R', 'V', '2', '4' ):
1152 case VLC_FOURCC( 'R', 'V', '3', '2' ):
1153 case VLC_FOURCC( 'R', 'G', 'B', 'A' ):
1158 for( int i = i_height - 1; i >= 0; i-- )
1160 p_input->p_vlc->pf_memcpy( p_buffer,
1161 &p_data[i * i_width], i_width );
1163 p_buffer += i_width;
1167 sample.p_sample->Release();
1169 /* The caller got what he wanted */
1170 return p_buffer - p_buf_orig;
1173 return 0; /* never reached */
1176 /*****************************************************************************
1177 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1178 *****************************************************************************
1179 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1181 *****************************************************************************/
1182 static ssize_t ReadCompressed( input_thread_t * p_input, byte_t * p_buffer,
1185 access_sys_t *p_sys = p_input->p_access_data;
1186 dshow_stream_t *p_stream = NULL;
1187 VLCMediaSample sample;
1191 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1193 /* There must be only 1 elementary stream to produce a valid stream
1194 * of MPEG or DV data */
1195 p_stream = p_sys->pp_streams[0];
1199 if( p_input->b_die || p_input->b_error ) return 0;
1201 /* Get new sample/frame from the elementary stream (blocking). */
1202 vlc_mutex_lock( &p_sys->lock );
1204 if( p_stream->p_capture_filter->CustomGetPin()
1205 ->CustomGetSample( &sample ) != S_OK )
1207 /* No data available. Wait until some data has arrived */
1208 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1209 vlc_mutex_unlock( &p_sys->lock );
1213 vlc_mutex_unlock( &p_sys->lock );
1218 i_data_size = sample.p_sample->GetActualDataLength();
1219 sample.p_sample->GetPointer( &p_data );
1222 msg_Info( p_input, "access read %i data_size %i", i_len, i_data_size );
1224 i_data_size = __MIN( i_data_size, (int)i_len );
1226 p_input->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1228 sample.p_sample->Release();
1230 /* The caller got what he wanted */
1234 return 0; /* never reached */
1237 /*****************************************************************************
1238 * Demux: local prototypes
1239 *****************************************************************************/
1246 static int Demux ( input_thread_t * );
1248 /****************************************************************************
1250 ****************************************************************************/
1251 static int DemuxOpen( vlc_object_t *p_this )
1253 input_thread_t *p_input = (input_thread_t *)p_this;
1260 /* a little test to see if it's a dshow stream */
1261 if( stream_Peek( p_input->s, &p_peek, 8 ) < 8 )
1263 msg_Warn( p_input, "dshow plugin discarded (cannot peek)" );
1264 return VLC_EGENERIC;
1267 if( memcmp( p_peek, ".dsh", 4 ) ||
1268 ( i_es = GetDWBE( &p_peek[4] ) ) <= 0 )
1270 msg_Warn( p_input, "dshow plugin discarded (not a valid stream)" );
1271 return VLC_EGENERIC;
1274 vlc_mutex_lock( &p_input->stream.stream_lock );
1275 if( input_InitStream( p_input, 0 ) == -1)
1277 vlc_mutex_unlock( &p_input->stream.stream_lock );
1278 msg_Err( p_input, "cannot init stream" );
1279 return VLC_EGENERIC;
1281 p_input->stream.i_mux_rate = 0 / 50;
1282 vlc_mutex_unlock( &p_input->stream.stream_lock );
1284 p_input->pf_demux = Demux;
1285 p_input->pf_demux_control = demux_vaControlDefault;
1286 p_input->p_demux_data = p_sys =
1287 (demux_sys_t *)malloc( sizeof( demux_sys_t ) );
1291 if( stream_Peek( p_input->s, &p_peek, 8 + 20 * i_es ) < 8 + 20 * i_es )
1293 msg_Err( p_input, "dshow plugin discarded (cannot peek)" );
1294 return VLC_EGENERIC;
1298 for( i = 0; i < i_es; i++ )
1302 if( !memcmp( p_peek, "auds", 4 ) )
1304 es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( p_peek[4], p_peek[5],
1305 p_peek[6], p_peek[7] ) );
1307 fmt.audio.i_channels = GetDWBE( &p_peek[8] );
1308 fmt.audio.i_rate = GetDWBE( &p_peek[12] );
1309 fmt.audio.i_bitspersample = GetDWBE( &p_peek[16] );
1310 fmt.audio.i_blockalign = fmt.audio.i_channels *
1311 fmt.audio.i_bitspersample / 8;
1312 fmt.i_bitrate = fmt.audio.i_channels *
1314 fmt.audio.i_bitspersample;
1316 msg_Dbg( p_input, "new audio es %d channels %dHz",
1317 fmt.audio.i_channels, fmt.audio.i_rate );
1319 TAB_APPEND( p_sys->i_es, p_sys->es,
1320 es_out_Add( p_input->p_es_out, &fmt ) );
1322 else if( !memcmp( p_peek, "vids", 4 ) )
1324 es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( p_peek[4], p_peek[5],
1325 p_peek[6], p_peek[7] ) );
1326 fmt.video.i_width = GetDWBE( &p_peek[8] );
1327 fmt.video.i_height = GetDWBE( &p_peek[12] );
1329 msg_Dbg( p_input, "added new video es %4.4s %dx%d",
1330 (char*)&fmt.i_codec,
1331 fmt.video.i_width, fmt.video.i_height );
1332 TAB_APPEND( p_sys->i_es, p_sys->es,
1333 es_out_Add( p_input->p_es_out, &fmt ) );
1340 stream_Read( p_input->s, NULL, 8 + 20 * i_es );
1345 /****************************************************************************
1347 ****************************************************************************/
1348 static void DemuxClose( vlc_object_t *p_this )
1350 input_thread_t *p_input = (input_thread_t *)p_this;
1351 demux_sys_t *p_sys = p_input->p_demux_data;
1353 if( p_sys->i_es > 0 )
1360 /****************************************************************************
1362 ****************************************************************************/
1363 static int Demux( input_thread_t *p_input )
1365 demux_sys_t *p_sys = p_input->p_demux_data;
1374 if( stream_Peek( p_input->s, &p_peek, 16 ) < 16 )
1376 msg_Warn( p_input, "cannot peek (EOF ?)" );
1380 i_es = GetDWBE( &p_peek[0] );
1381 if( i_es < 0 || i_es >= p_sys->i_es )
1383 msg_Err( p_input, "cannot find ES" );
1387 i_size = GetDWBE( &p_peek[4] );
1388 i_pcr = GetQWBE( &p_peek[8] );
1390 if( ( p_block = stream_Block( p_input->s, 16 + i_size ) ) == NULL )
1392 msg_Warn( p_input, "cannot read data" );
1396 p_block->p_buffer += 16;
1397 p_block->i_buffer -= 16;
1399 /* Call the pace control. */
1400 input_ClockManageRef( p_input, p_input->stream.p_selected_program, i_pcr );
1403 p_block->i_pts = i_pcr <= 0 ? 0 :
1404 input_ClockGetTS( p_input, p_input->stream.p_selected_program, i_pcr );
1406 es_out_Send( p_input->p_es_out, p_sys->es[i_es], p_block );
1412 /*****************************************************************************
1413 * config variable callback
1414 *****************************************************************************/
1415 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1416 vlc_value_t newval, vlc_value_t oldval, void * )
1418 module_config_t *p_item;
1419 vlc_bool_t b_audio = VLC_FALSE;
1422 p_item = config_FindConfig( p_this, psz_name );
1423 if( !p_item ) return VLC_SUCCESS;
1425 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1427 /* Clear-up the current list */
1428 if( p_item->i_list )
1430 /* Keep the 2 first entries */
1431 for( i = 2; i < p_item->i_list; i++ )
1433 free( p_item->ppsz_list[i] );
1434 free( p_item->ppsz_list_text[i] );
1436 /* TODO: Remove when no more needed */
1437 p_item->ppsz_list[i] = NULL;
1438 p_item->ppsz_list_text[i] = NULL;
1442 /* Find list of devices */
1443 list<string> list_devices;
1445 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1447 if( !list_devices.size() ) return VLC_SUCCESS;
1450 (char **)realloc( p_item->ppsz_list,
1451 (list_devices.size()+3) * sizeof(char *) );
1452 p_item->ppsz_list_text =
1453 (char **)realloc( p_item->ppsz_list_text,
1454 (list_devices.size()+3) * sizeof(char *) );
1456 list<string>::iterator iter;
1457 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1460 p_item->ppsz_list[i] = strdup( iter->c_str() );
1461 p_item->ppsz_list_text[i] = strdup( iter->c_str() );
1464 p_item->ppsz_list[i] = NULL;
1465 p_item->ppsz_list_text[i] = NULL;
1470 static void PropertiesPage( input_thread_t *p_input,
1471 IBaseFilter *p_device_filter )
1473 ISpecifyPropertyPages *p_spec;
1476 HRESULT hr = p_device_filter->QueryInterface( IID_ISpecifyPropertyPages,
1480 hr = p_spec->GetPages( &cauuid );
1483 HWND hwnd_desktop = ::GetDesktopWindow();
1485 hr = OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1,
1486 (IUnknown **)&p_device_filter,
1488 (GUID *)cauuid.pElems, 0, 0, NULL );
1491 msg_Dbg( p_input, "made OleCreatePropertyFrame");
1494 CoTaskMemFree( cauuid.pElems );