1 /*****************************************************************************
2 * dshow.cpp : DirectShow access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002, 2003 VideoLAN
5 * $Id: dshow.cpp,v 1.25 2004/01/25 17:31:22 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 milliseconds 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_integer( "dshow-caching", (mtime_t)(0.2*CLOCK_FREQ) / 1000, NULL,
141 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
143 add_string( "dshow-vdev", NULL, NULL, VDEV_TEXT, VDEV_LONGTEXT, VLC_FALSE);
144 change_string_list( ppsz_vdev, ppsz_vdev_text, FindDevicesCallback );
146 add_string( "dshow-adev", NULL, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE);
147 change_string_list( ppsz_adev, ppsz_adev_text, FindDevicesCallback );
149 add_string( "dshow-size", NULL, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE);
151 add_string( "dshow-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
154 add_bool( "dshow-config", VLC_FALSE, NULL, CONFIG_TEXT, CONFIG_LONGTEXT,
157 add_shortcut( "dshow" );
158 set_capability( "access", 0 );
159 set_callbacks( AccessOpen, AccessClose );
162 set_description( _("DirectShow demuxer") );
163 add_shortcut( "dshow" );
164 set_capability( "demux", 200 );
165 set_callbacks( DemuxOpen, DemuxClose );
169 /****************************************************************************
170 * DirectShow elementary stream descriptor
171 ****************************************************************************/
172 typedef struct dshow_stream_t
175 IBaseFilter *p_device_filter;
176 CaptureFilter *p_capture_filter;
183 VIDEOINFOHEADER video;
192 /****************************************************************************
193 * Access descriptor declaration
194 ****************************************************************************/
200 IFilterGraph *p_graph;
201 IMediaControl *p_control;
208 /* list of elementary streams */
209 dshow_stream_t **pp_streams;
211 int i_current_stream;
213 /* misc properties */
220 /*****************************************************************************
221 * Open: open direct show device
222 *****************************************************************************/
223 static int AccessOpen( vlc_object_t *p_this )
225 input_thread_t *p_input = (input_thread_t *)p_this;
229 /* Get/parse options and open device(s) */
230 string vdevname, adevname;
231 int i_width = 0, i_height = 0, i_chroma = 0;
233 var_Create( p_input, "dshow-vdev", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
234 var_Get( p_input, "dshow-vdev", &val );
235 if( val.psz_string ) vdevname = string( val.psz_string );
236 if( val.psz_string ) free( val.psz_string );
238 var_Create( p_input, "dshow-adev", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
239 var_Get( p_input, "dshow-adev", &val );
240 if( val.psz_string ) adevname = string( val.psz_string );
241 if( val.psz_string ) free( val.psz_string );
243 var_Create( p_input, "dshow-size", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
244 var_Get( p_input, "dshow-size", &val );
245 if( val.psz_string && *val.psz_string )
247 if( !strcmp( val.psz_string, "subqcif" ) )
249 i_width = 128; i_height = 96;
251 else if( !strcmp( val.psz_string, "qsif" ) )
253 i_width = 160; i_height = 120;
255 else if( !strcmp( val.psz_string, "qcif" ) )
257 i_width = 176; i_height = 144;
259 else if( !strcmp( val.psz_string, "sif" ) )
261 i_width = 320; i_height = 240;
263 else if( !strcmp( val.psz_string, "cif" ) )
265 i_width = 352; i_height = 288;
267 else if( !strcmp( val.psz_string, "vga" ) )
269 i_width = 640; i_height = 480;
275 i_width = strtol( val.psz_string, &psz_parser, 0 );
276 if( *psz_parser == 'x' || *psz_parser == 'X')
278 i_height = strtol( psz_parser + 1, &psz_parser, 0 );
280 msg_Dbg( p_input, "Width x Height %dx%d", i_width, i_height );
283 if( val.psz_string ) free( val.psz_string );
285 var_Create( p_input, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
286 var_Get( p_input, "dshow-chroma", &val );
287 if( val.psz_string && strlen( val.psz_string ) >= 4 )
289 i_chroma = VLC_FOURCC( val.psz_string[0], val.psz_string[1],
290 val.psz_string[2], val.psz_string[3] );
292 if( val.psz_string ) free( val.psz_string );
294 p_input->pf_read = Read;
295 p_input->pf_seek = NULL;
296 p_input->pf_set_area = NULL;
297 p_input->pf_set_program = NULL;
299 vlc_mutex_lock( &p_input->stream.stream_lock );
300 p_input->stream.b_pace_control = 0;
301 p_input->stream.b_seekable = 0;
302 p_input->stream.p_selected_area->i_size = 0;
303 p_input->stream.p_selected_area->i_tell = 0;
304 p_input->stream.i_method = INPUT_METHOD_FILE;
305 vlc_mutex_unlock( &p_input->stream.stream_lock );
307 var_Create( p_input, "dshow-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
308 var_Get( p_input, "dshow-caching", &val );
309 p_input->i_pts_delay = val.i_int * 1000;
311 /* Initialize OLE/COM */
314 /* create access private data */
315 p_input->p_access_data = p_sys =
316 (access_sys_t *)malloc( sizeof( access_sys_t ) );
318 /* Initialize some data */
319 p_sys->i_streams = 0;
320 p_sys->pp_streams = (dshow_stream_t **)malloc( 1 );
321 p_sys->i_width = i_width;
322 p_sys->i_height = i_height;
323 p_sys->i_chroma = i_chroma;
324 p_sys->b_audio = VLC_TRUE;
327 p_sys->i_header_size = 8;
328 p_sys->p_header = (uint8_t *)malloc( p_sys->i_header_size );
329 memcpy( &p_sys->p_header[0], ".dsh", 4 );
330 SetDWBE( &p_sys->p_header[4], 1 );
331 p_sys->i_header_pos = p_sys->i_header_size;
333 /* Build directshow graph */
334 CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,
335 (REFIID)IID_IFilterGraph, (void **)&p_sys->p_graph );
337 p_sys->p_graph->QueryInterface( IID_IMediaControl,
338 (void **)&p_sys->p_control );
340 if( OpenDevice( p_input, vdevname, 0 ) != VLC_SUCCESS )
342 msg_Err( p_input, "can't open video");
345 if( p_sys->b_audio && OpenDevice( p_input, adevname, 1 ) != VLC_SUCCESS )
347 msg_Err( p_input, "can't open audio");
350 if( !p_sys->i_streams )
352 /* Release directshow objects */
353 if( p_sys->p_control ) p_sys->p_control->Release();
354 p_sys->p_graph->Release();
356 /* Uninitialize OLE/COM */
359 free( p_sys->p_header );
360 free( p_sys->pp_streams );
365 /* Initialize some data */
366 p_sys->i_current_stream = 0;
367 p_input->i_mtu += p_sys->i_header_size + 16 /* data header size */;
369 vlc_mutex_init( p_input, &p_sys->lock );
370 vlc_cond_init( p_input, &p_sys->wait );
372 /* Everything is ready. Let's rock baby */
373 p_sys->p_control->Run();
378 /*****************************************************************************
379 * AccessClose: close device
380 *****************************************************************************/
381 static void AccessClose( vlc_object_t *p_this )
383 input_thread_t *p_input = (input_thread_t *)p_this;
384 access_sys_t *p_sys = p_input->p_access_data;
386 /* Stop capturing stuff */
387 //p_sys->p_control->Stop(); /* FIXME?: we get stuck here sometimes */
388 p_sys->p_control->Release();
390 /* Remove filters from graph */
391 for( int i = 0; i < p_sys->i_streams; i++ )
393 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_capture_filter );
394 p_sys->p_graph->RemoveFilter( p_sys->pp_streams[i]->p_device_filter );
395 p_sys->pp_streams[i]->p_capture_filter->Release();
396 p_sys->pp_streams[i]->p_device_filter->Release();
398 p_sys->p_graph->Release();
400 /* Uninitialize OLE/COM */
403 free( p_sys->p_header );
404 for( int i = 0; i < p_sys->i_streams; i++ ) delete p_sys->pp_streams[i];
405 free( p_sys->pp_streams );
409 /****************************************************************************
411 ****************************************************************************/
412 static bool ConnectFilters( IFilterGraph *p_graph, IBaseFilter *p_filter,
415 IEnumPins *p_enumpins;
419 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return false;
421 while( S_OK == p_enumpins->Next( 1, &p_output_pin, &i_fetched ) )
423 if( S_OK == p_graph->ConnectDirect( p_output_pin, p_input_pin, 0 ) )
425 p_enumpins->Release();
430 p_enumpins->Release();
434 static int OpenDevice( input_thread_t *p_input, string devicename,
437 access_sys_t *p_sys = p_input->p_access_data;
438 list<string> list_devices;
440 /* Enumerate devices and display their names */
441 FindCaptureDevice( (vlc_object_t *)p_input, NULL, &list_devices, b_audio );
443 if( !list_devices.size() )
446 list<string>::iterator iter;
447 for( iter = list_devices.begin(); iter != list_devices.end(); iter++ )
448 msg_Dbg( p_input, "found device: %s", iter->c_str() );
450 /* If no device name was specified, pick the 1st one */
451 if( devicename.size() == 0 )
453 devicename = *list_devices.begin();
456 // Use the system device enumerator and class enumerator to find
457 // a capture/preview device, such as a desktop USB video camera.
458 IBaseFilter *p_device_filter =
459 FindCaptureDevice( (vlc_object_t *)p_input, &devicename,
461 if( p_device_filter )
462 msg_Dbg( p_input, "using device: %s", devicename.c_str() );
465 msg_Err( p_input, "can't use device: %s", devicename.c_str() );
469 AM_MEDIA_TYPE media_type =
470 EnumDeviceCaps( (vlc_object_t *)p_input, p_device_filter,
471 p_sys->i_chroma, p_sys->i_width, p_sys->i_height,
474 /* Create and add our capture filter */
475 CaptureFilter *p_capture_filter = new CaptureFilter( p_input, media_type );
476 p_sys->p_graph->AddFilter( p_capture_filter, 0 );
478 /* Add the device filter to the graph (seems necessary with VfW before
479 * accessing pin attributes). */
480 p_sys->p_graph->AddFilter( p_device_filter, 0 );
482 /* Attempt to connect one of this device's capture output pins */
483 msg_Dbg( p_input, "connecting filters" );
484 if( ConnectFilters( p_sys->p_graph, p_device_filter,
485 p_capture_filter->CustomGetPin() ) )
488 dshow_stream_t dshow_stream;
489 dshow_stream.b_invert = VLC_FALSE;
490 dshow_stream.b_pts = VLC_FALSE;
492 p_capture_filter->CustomGetPin()->CustomGetMediaType();
494 if( dshow_stream.mt.majortype == MEDIATYPE_Video )
496 msg_Dbg( p_input, "MEDIATYPE_Video");
498 /* Packed RGB formats */
499 if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB1 )
500 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' );
501 if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB4 )
502 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' );
503 if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB8 )
504 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' );
505 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB555 )
506 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' );
507 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB565 )
508 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' );
509 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB24 )
510 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' );
511 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_RGB32 )
512 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' );
513 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_ARGB32 )
514 dshow_stream.i_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' );
516 /* Packed YUV formats */
517 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YVYU )
518 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'V', 'Y', 'U' );
519 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YUYV )
520 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', 'V' );
521 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_Y411 )
522 dshow_stream.i_fourcc = VLC_FOURCC( 'I', '4', '1', 'N' );
523 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_Y211 )
524 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', '2', '1', '1' );
525 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YUY2 ||
526 dshow_stream.mt.subtype == MEDIASUBTYPE_UYVY )
527 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' );
529 /* Planar YUV formats */
530 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_I420 )
531 dshow_stream.i_fourcc = VLC_FOURCC( 'I', '4', '2', '0' );
532 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_Y41P )
533 dshow_stream.i_fourcc = VLC_FOURCC( 'I', '4', '1', '1' );
534 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YV12 ||
535 dshow_stream.mt.subtype == MEDIASUBTYPE_IYUV )
536 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' );
537 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_YVU9 )
538 dshow_stream.i_fourcc = VLC_FOURCC( 'Y', 'V', 'U', '9' );
541 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_dvsl )
542 dshow_stream.i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'l' );
543 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_dvsd )
544 dshow_stream.i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'd' );
545 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_dvhd )
546 dshow_stream.i_fourcc = VLC_FOURCC( 'd', 'v', 'h', 'd' );
548 /* MPEG video formats */
549 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_MPEG2_VIDEO )
550 dshow_stream.i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
554 dshow_stream.header.video =
555 *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat;
557 int i_height = dshow_stream.header.video.bmiHeader.biHeight;
559 /* Check if the image is inverted (bottom to top) */
560 if( dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', '1' ) ||
561 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', '4' ) ||
562 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', '8' ) ||
563 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '1', '5' ) ||
564 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '1', '6' ) ||
565 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '2', '4' ) ||
566 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'V', '3', '2' ) ||
567 dshow_stream.i_fourcc == VLC_FOURCC( 'R', 'G', 'B', 'A' ) )
569 if( i_height > 0 ) dshow_stream.b_invert = VLC_TRUE;
570 else i_height = - i_height;
573 /* Check if we are dealing with a DV stream */
574 if( dshow_stream.i_fourcc == VLC_FOURCC( 'd', 'v', 's', 'l' ) ||
575 dshow_stream.i_fourcc == VLC_FOURCC( 'd', 'v', 's', 'd' ) ||
576 dshow_stream.i_fourcc == VLC_FOURCC( 'd', 'v', 'h', 'd' ) )
578 p_input->pf_read = ReadCompressed;
579 if( !p_input->psz_demux || !*p_input->psz_demux )
581 p_input->psz_demux = "rawdv";
583 p_sys->b_audio = VLC_FALSE;
586 /* Check if we are dealing with an MPEG video stream */
587 if( dshow_stream.i_fourcc == VLC_FOURCC( 'm', 'p', '2', 'v' ) )
589 p_input->pf_read = ReadCompressed;
590 if( !p_input->psz_demux || !*p_input->psz_demux )
592 p_input->psz_demux = "mpgv";
594 p_sys->b_audio = VLC_FALSE;
597 /* Add video stream to header */
598 p_sys->i_header_size += 20;
599 p_sys->p_header = (uint8_t *)realloc( p_sys->p_header,
600 p_sys->i_header_size );
601 memcpy( &p_sys->p_header[p_sys->i_header_pos], "vids", 4 );
602 memcpy( &p_sys->p_header[p_sys->i_header_pos + 4],
603 &dshow_stream.i_fourcc, 4 );
604 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 8],
605 dshow_stream.header.video.bmiHeader.biWidth );
606 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 12], i_height );
607 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 16], 0 );
608 p_sys->i_header_pos = p_sys->i_header_size;
610 /* Greatly simplifies the reading routine */
611 int i_mtu = dshow_stream.header.video.bmiHeader.biWidth *
613 p_input->i_mtu = __MAX( p_input->i_mtu, (unsigned int)i_mtu );
616 else if( dshow_stream.mt.majortype == MEDIATYPE_Audio &&
617 dshow_stream.mt.formattype == FORMAT_WaveFormatEx )
619 msg_Dbg( p_input, "MEDIATYPE_Audio");
621 if( dshow_stream.mt.subtype == MEDIASUBTYPE_PCM )
622 dshow_stream.i_fourcc = VLC_FOURCC( 'a', 'r', 'a', 'w' );
623 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_IEEE_FLOAT )
624 dshow_stream.i_fourcc = VLC_FOURCC( 'f', 'l', '3', '2' );
627 dshow_stream.header.audio =
628 *(WAVEFORMATEX *)dshow_stream.mt.pbFormat;
630 /* Add audio stream to header */
631 p_sys->i_header_size += 20;
632 p_sys->p_header = (uint8_t *)realloc( p_sys->p_header,
633 p_sys->i_header_size );
634 memcpy( &p_sys->p_header[p_sys->i_header_pos], "auds", 4 );
635 memcpy( &p_sys->p_header[p_sys->i_header_pos + 4],
636 &dshow_stream.i_fourcc, 4 );
637 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 8],
638 dshow_stream.header.audio.nChannels );
639 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 12],
640 dshow_stream.header.audio.nSamplesPerSec );
641 SetDWBE( &p_sys->p_header[p_sys->i_header_pos + 16],
642 dshow_stream.header.audio.wBitsPerSample );
643 p_sys->i_header_pos = p_sys->i_header_size;
645 /* Greatly simplifies the reading routine */
646 IAMBufferNegotiation *p_ambuf;
650 p_capture_filter->CustomGetPin()->ConnectedTo( &p_pin );
651 if( SUCCEEDED( p_pin->QueryInterface(
652 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
654 ALLOCATOR_PROPERTIES AllocProp;
655 memset( &AllocProp, 0, sizeof( ALLOCATOR_PROPERTIES ) );
656 p_ambuf->GetAllocatorProperties( &AllocProp );
658 i_mtu = AllocProp.cbBuffer;
663 i_mtu = dshow_stream.header.audio.nSamplesPerSec *
664 dshow_stream.header.audio.nChannels *
665 dshow_stream.header.audio.wBitsPerSample / 8;
668 p_input->i_mtu = __MAX( p_input->i_mtu, (unsigned int)i_mtu );
671 else if( dshow_stream.mt.majortype == MEDIATYPE_Stream )
673 msg_Dbg( p_input, "MEDIATYPE_Stream" );
675 if( dshow_stream.mt.subtype == MEDIASUBTYPE_MPEG2_PROGRAM )
676 dshow_stream.i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'p' );
677 else if( dshow_stream.mt.subtype == MEDIASUBTYPE_MPEG2_TRANSPORT )
678 dshow_stream.i_fourcc = VLC_FOURCC( 'm', 'p', '2', 't' );
680 msg_Dbg( p_input, "selected stream pin accepts format: %4.4s",
681 (char *)&dshow_stream.i_fourcc);
683 p_sys->b_audio = VLC_FALSE;
684 p_sys->i_header_size = 0;
685 p_sys->i_header_pos = 0;
686 p_input->i_mtu = INPUT_DEFAULT_BUFSIZE;
688 p_input->pf_read = ReadCompressed;
689 p_input->pf_set_program = input_SetProgram;
694 msg_Dbg( p_input, "unknown stream majortype" );
698 /* Show properties */
700 var_Create( p_input, "dshow-config",
701 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
702 var_Get( p_input, "dshow-config", &val );
704 if(val.i_int) PropertiesPage( p_input, p_device_filter );
706 /* Add directshow elementary stream to our list */
707 dshow_stream.p_device_filter = p_device_filter;
708 dshow_stream.p_capture_filter = p_capture_filter;
711 (dshow_stream_t **)realloc( p_sys->pp_streams,
712 sizeof(dshow_stream_t *)
713 * (p_sys->i_streams + 1) );
714 p_sys->pp_streams[p_sys->i_streams] = new dshow_stream_t;
715 *p_sys->pp_streams[p_sys->i_streams++] = dshow_stream;
716 SetDWBE( &p_sys->p_header[4], (uint32_t)p_sys->i_streams );
722 /* Remove filters from graph */
723 p_sys->p_graph->RemoveFilter( p_device_filter );
724 p_sys->p_graph->RemoveFilter( p_capture_filter );
726 /* Release objects */
727 p_device_filter->Release();
728 p_capture_filter->Release();
734 FindCaptureDevice( vlc_object_t *p_this, string *p_devicename,
735 list<string> *p_listdevices, vlc_bool_t b_audio )
737 IBaseFilter *p_base_filter = NULL;
738 IMoniker *p_moniker = NULL;
742 /* Create the system device enumerator */
743 ICreateDevEnum *p_dev_enum = NULL;
745 hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
746 IID_ICreateDevEnum, (void **)&p_dev_enum );
749 msg_Err( p_this, "failed to create the device enumerator (0x%x)", hr);
753 /* Create an enumerator for the video capture devices */
754 IEnumMoniker *p_class_enum = NULL;
756 hr = p_dev_enum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory,
759 hr = p_dev_enum->CreateClassEnumerator( CLSID_AudioInputDeviceCategory,
761 p_dev_enum->Release();
764 msg_Err( p_this, "failed to create the class enumerator (0x%x)", hr );
768 /* If there are no enumerators for the requested type, then
769 * CreateClassEnumerator will succeed, but p_class_enum will be NULL */
770 if( p_class_enum == NULL )
772 msg_Err( p_this, "no capture device was detected." );
776 /* Enumerate the devices */
778 /* Note that if the Next() call succeeds but there are no monikers,
779 * it will return S_FALSE (which is not a failure). Therefore, we check
780 * that the return code is S_OK instead of using SUCCEEDED() macro. */
782 while( p_class_enum->Next( 1, &p_moniker, &i_fetched ) == S_OK )
784 /* Getting the property page to get the device name */
786 hr = p_moniker->BindToStorage( 0, 0, IID_IPropertyBag,
792 hr = p_bag->Read( L"FriendlyName", &var, NULL );
796 int i_convert = ( lstrlenW( var.bstrVal ) + 1 ) * 2;
797 char *p_buf = (char *)alloca( i_convert ); p_buf[0] = 0;
798 WideCharToMultiByte( CP_ACP, 0, var.bstrVal, -1, p_buf,
799 i_convert, NULL, NULL );
800 SysFreeString(var.bstrVal);
802 if( p_listdevices ) p_listdevices->push_back( p_buf );
804 if( p_devicename && *p_devicename == string(p_buf) )
806 /* Bind Moniker to a filter object */
807 hr = p_moniker->BindToObject( 0, 0, IID_IBaseFilter,
808 (void **)&p_base_filter );
811 msg_Err( p_this, "couldn't bind moniker to filter "
812 "object (0x%x)", hr );
813 p_moniker->Release();
814 p_class_enum->Release();
817 p_moniker->Release();
818 p_class_enum->Release();
819 return p_base_filter;
824 p_moniker->Release();
827 p_class_enum->Release();
831 static AM_MEDIA_TYPE EnumDeviceCaps( vlc_object_t *p_this,
832 IBaseFilter *p_filter,
833 int i_fourcc, int i_width, int i_height,
834 int i_channels, int i_samplespersec,
835 int i_bitspersample )
837 IEnumPins *p_enumpins;
839 IEnumMediaTypes *p_enummt;
840 int i_orig_fourcc = i_fourcc;
841 vlc_bool_t b_found = VLC_FALSE;
843 AM_MEDIA_TYPE media_type;
844 media_type.majortype = GUID_NULL;
845 media_type.subtype = GUID_NULL;
846 media_type.formattype = GUID_NULL;
847 media_type.pUnk = NULL;
848 media_type.cbFormat = 0;
849 media_type.pbFormat = NULL;
851 if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return media_type;
853 while( !b_found && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK )
857 if( S_OK == p_output_pin->QueryPinInfo( &info ) )
859 msg_Dbg( p_this, "EnumDeviceCaps: pin %S", info.achName );
860 if( info.pFilter ) info.pFilter->Release();
864 if( SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
867 while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
870 if( p_mt->majortype == MEDIATYPE_Video )
872 int i_current_fourcc = VLC_FOURCC(' ', ' ', ' ', ' ');
874 /* Packed RGB formats */
875 if( p_mt->subtype == MEDIASUBTYPE_RGB1 )
876 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' );
877 if( p_mt->subtype == MEDIASUBTYPE_RGB4 )
878 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' );
879 if( p_mt->subtype == MEDIASUBTYPE_RGB8 )
880 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' );
881 else if( p_mt->subtype == MEDIASUBTYPE_RGB555 )
882 i_current_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' );
883 else if( p_mt->subtype == MEDIASUBTYPE_RGB565 )
884 i_current_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' );
885 else if( p_mt->subtype == MEDIASUBTYPE_RGB24 )
886 i_current_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' );
887 else if( p_mt->subtype == MEDIASUBTYPE_RGB32 )
888 i_current_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' );
889 else if( p_mt->subtype == MEDIASUBTYPE_ARGB32 )
890 i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' );
892 /* MPEG2 video elementary stream */
893 else if( p_mt->subtype == MEDIASUBTYPE_MPEG2_VIDEO )
894 i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
896 /* hauppauge pvr video preview */
897 else if( p_mt->subtype == MEDIASUBTYPE_PREVIEW_VIDEO )
898 i_current_fourcc = VLC_FOURCC( 'P', 'V', 'R', 'V' );
900 else i_current_fourcc = *((int *)&p_mt->subtype);
902 int i_current_width = p_mt->pbFormat ?
903 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth : 0;
904 int i_current_height = p_mt->pbFormat ?
905 ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight : 0;
906 if( i_current_height < 0 )
907 i_current_height = -i_current_height;
909 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
910 "accepts chroma: %4.4s, width:%i, height:%i",
911 (char *)&i_current_fourcc, i_current_width,
914 if( ( !i_fourcc || i_fourcc == i_current_fourcc ||
915 ( !i_orig_fourcc && i_current_fourcc ==
916 VLC_FOURCC('I','4','2','0') ) ) &&
917 ( !i_width || i_width == i_current_width ) &&
918 ( !i_height || i_height == i_current_height ) )
920 /* Pick the 1st match */
922 i_fourcc = i_current_fourcc;
923 i_width = i_current_width;
924 i_height = i_current_height;
929 FreeMediaType( *p_mt );
932 else if( p_mt->majortype == MEDIATYPE_Audio )
934 int i_current_fourcc;
935 int i_current_channels =
936 ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
937 int i_current_samplespersec =
938 ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
939 int i_current_bitspersample =
940 ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
942 if( p_mt->subtype == MEDIASUBTYPE_PCM )
943 i_current_fourcc = VLC_FOURCC( 'p', 'c', 'm', ' ' );
944 else i_current_fourcc = *((int *)&p_mt->subtype);
946 msg_Dbg( p_this, "EnumDeviceCaps: input pin "
947 "accepts format: %4.4s, channels:%i, "
948 "samples/sec:%i bits/sample:%i",
949 (char *)&i_current_fourcc, i_current_channels,
950 i_current_samplespersec, i_current_bitspersample);
952 if( (!i_channels || i_channels == i_current_channels) &&
954 i_samplespersec == i_current_samplespersec) &&
956 i_bitspersample == i_current_bitspersample) )
958 /* Pick the 1st match */
960 i_channels = i_current_channels;
961 i_samplespersec = i_current_samplespersec;
962 i_bitspersample = i_current_bitspersample;
965 /* Setup a few properties like the audio latency */
966 IAMBufferNegotiation *p_ambuf;
968 if( SUCCEEDED( p_output_pin->QueryInterface(
969 IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
971 ALLOCATOR_PROPERTIES AllocProp;
972 AllocProp.cbAlign = -1;
973 AllocProp.cbBuffer = i_channels * i_samplespersec *
974 i_bitspersample / 8 / 10 ; /*100 ms of latency*/
975 AllocProp.cbPrefix = -1;
976 AllocProp.cBuffers = -1;
977 p_ambuf->SuggestAllocatorProperties( &AllocProp );
983 FreeMediaType( *p_mt );
986 else if( p_mt->majortype == MEDIATYPE_Stream )
988 msg_Dbg( p_this, "EnumDeviceCaps: MEDIATYPE_Stream" );
990 int i_current_fourcc = VLC_FOURCC(' ', ' ', ' ', ' ');
992 if( p_mt->subtype == MEDIASUBTYPE_MPEG2_PROGRAM )
993 i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 'p' );
994 else if( p_mt->subtype == MEDIASUBTYPE_MPEG2_TRANSPORT )
995 i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 't' );
997 if( ( !i_fourcc || i_fourcc == i_current_fourcc ) )
999 /* Pick the 1st match */
1001 i_fourcc = i_current_fourcc;
1006 FreeMediaType( *p_mt );
1012 "EnumDeviceCaps: input pin: unknown format" );
1013 FreeMediaType( *p_mt );
1016 CoTaskMemFree( (PVOID)p_mt );
1018 p_enummt->Release();
1021 p_output_pin->Release();
1024 p_enumpins->Release();
1028 /*****************************************************************************
1029 * Read: reads from the device into PES packets.
1030 *****************************************************************************
1031 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1033 *****************************************************************************/
1034 static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer,
1037 access_sys_t *p_sys = p_input->p_access_data;
1038 dshow_stream_t *p_stream = NULL;
1039 byte_t *p_buf_orig = p_buffer;
1040 VLCMediaSample sample;
1044 if( p_sys->i_header_pos )
1046 /* First header of the stream */
1047 memcpy( p_buffer, p_sys->p_header, p_sys->i_header_size );
1048 p_buffer += p_sys->i_header_size;
1049 p_sys->i_header_pos = 0;
1054 /* Get new sample/frame from next elementary stream.
1055 * We first loop through all the elementary streams and if all our
1056 * fifos are empty we block until we are signaled some new data has
1058 vlc_mutex_lock( &p_sys->lock );
1061 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1063 p_stream = p_sys->pp_streams[i_stream];
1064 if( p_stream->mt.majortype == MEDIATYPE_Audio &&
1065 p_stream->p_capture_filter &&
1066 p_stream->p_capture_filter->CustomGetPin()
1067 ->CustomGetSample( &sample ) == S_OK )
1072 if( i_stream == p_sys->i_streams )
1073 for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
1075 p_stream = p_sys->pp_streams[i_stream];
1076 if( p_stream->p_capture_filter &&
1077 p_stream->p_capture_filter->CustomGetPin()
1078 ->CustomGetSample( &sample ) == S_OK )
1083 if( i_stream == p_sys->i_streams )
1085 /* No data available. Wait until some data has arrived */
1086 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1087 vlc_mutex_unlock( &p_sys->lock );
1091 vlc_mutex_unlock( &p_sys->lock );
1096 i_data_size = sample.p_sample->GetActualDataLength();
1097 sample.p_sample->GetPointer( &p_data );
1099 REFERENCE_TIME i_pts, i_end_date;
1100 HRESULT hr = sample.p_sample->GetTime( &i_pts, &i_end_date );
1101 if( hr != VFW_S_NO_STOP_TIME && hr != S_OK ) i_pts = 0;
1105 if( p_stream->mt.majortype == MEDIATYPE_Video || !p_stream->b_pts )
1107 /* Use our data timestamp */
1108 i_pts = sample.i_timestamp;
1109 p_stream->b_pts = VLC_TRUE;
1114 msg_Dbg( p_input, "Read() stream: %i PTS: "I64Fd, i_stream, i_pts );
1117 /* Create pseudo header */
1118 SetDWBE( &p_sys->p_header[0], i_stream );
1119 SetDWBE( &p_sys->p_header[4], i_data_size );
1120 SetQWBE( &p_sys->p_header[8], i_pts * 9 / 1000 );
1123 msg_Info( p_input, "access read %i data_size %i", i_len, i_data_size );
1126 /* First copy header */
1127 memcpy( p_buffer, p_sys->p_header, 16 /* header size */ );
1128 p_buffer += 16 /* header size */;
1130 /* Then copy stream data if any */
1131 if( !p_stream->b_invert )
1133 p_input->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1134 p_buffer += i_data_size;
1138 int i_width = p_stream->header.video.bmiHeader.biWidth;
1139 int i_height = p_stream->header.video.bmiHeader.biHeight;
1140 if( i_height < 0 ) i_height = - i_height;
1142 switch( p_stream->i_fourcc )
1144 case VLC_FOURCC( 'R', 'V', '1', '5' ):
1145 case VLC_FOURCC( 'R', 'V', '1', '6' ):
1148 case VLC_FOURCC( 'R', 'V', '2', '4' ):
1151 case VLC_FOURCC( 'R', 'V', '3', '2' ):
1152 case VLC_FOURCC( 'R', 'G', 'B', 'A' ):
1157 for( int i = i_height - 1; i >= 0; i-- )
1159 p_input->p_vlc->pf_memcpy( p_buffer,
1160 &p_data[i * i_width], i_width );
1162 p_buffer += i_width;
1166 sample.p_sample->Release();
1168 /* The caller got what he wanted */
1169 return p_buffer - p_buf_orig;
1172 return 0; /* never reached */
1175 /*****************************************************************************
1176 * ReadCompressed: reads compressed (MPEG/DV) data from the device.
1177 *****************************************************************************
1178 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
1180 *****************************************************************************/
1181 static ssize_t ReadCompressed( input_thread_t * p_input, byte_t * p_buffer,
1184 access_sys_t *p_sys = p_input->p_access_data;
1185 dshow_stream_t *p_stream = NULL;
1186 VLCMediaSample sample;
1190 /* Read 1 DV/MPEG frame (they contain the video and audio data) */
1192 /* There must be only 1 elementary stream to produce a valid stream
1193 * of MPEG or DV data */
1194 p_stream = p_sys->pp_streams[0];
1198 if( p_input->b_die || p_input->b_error ) return 0;
1200 /* Get new sample/frame from the elementary stream (blocking). */
1201 vlc_mutex_lock( &p_sys->lock );
1203 if( p_stream->p_capture_filter->CustomGetPin()
1204 ->CustomGetSample( &sample ) != S_OK )
1206 /* No data available. Wait until some data has arrived */
1207 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
1208 vlc_mutex_unlock( &p_sys->lock );
1212 vlc_mutex_unlock( &p_sys->lock );
1217 i_data_size = sample.p_sample->GetActualDataLength();
1218 sample.p_sample->GetPointer( &p_data );
1221 msg_Info( p_input, "access read %i data_size %i", i_len, i_data_size );
1223 i_data_size = __MIN( i_data_size, (int)i_len );
1225 p_input->p_vlc->pf_memcpy( p_buffer, p_data, i_data_size );
1227 sample.p_sample->Release();
1229 /* The caller got what he wanted */
1233 return 0; /* never reached */
1236 /*****************************************************************************
1237 * Demux: local prototypes
1238 *****************************************************************************/
1245 static int Demux ( input_thread_t * );
1247 /****************************************************************************
1249 ****************************************************************************/
1250 static int DemuxOpen( vlc_object_t *p_this )
1252 input_thread_t *p_input = (input_thread_t *)p_this;
1259 /* a little test to see if it's a dshow stream */
1260 if( stream_Peek( p_input->s, &p_peek, 8 ) < 8 )
1262 msg_Warn( p_input, "dshow plugin discarded (cannot peek)" );
1263 return VLC_EGENERIC;
1266 if( memcmp( p_peek, ".dsh", 4 ) ||
1267 ( i_es = GetDWBE( &p_peek[4] ) ) <= 0 )
1269 msg_Warn( p_input, "dshow plugin discarded (not a valid stream)" );
1270 return VLC_EGENERIC;
1273 vlc_mutex_lock( &p_input->stream.stream_lock );
1274 if( input_InitStream( p_input, 0 ) == -1)
1276 vlc_mutex_unlock( &p_input->stream.stream_lock );
1277 msg_Err( p_input, "cannot init stream" );
1278 return VLC_EGENERIC;
1280 p_input->stream.i_mux_rate = 0 / 50;
1281 vlc_mutex_unlock( &p_input->stream.stream_lock );
1283 p_input->pf_demux = Demux;
1284 p_input->pf_demux_control = demux_vaControlDefault;
1285 p_input->p_demux_data = p_sys =
1286 (demux_sys_t *)malloc( sizeof( demux_sys_t ) );
1290 if( stream_Peek( p_input->s, &p_peek, 8 + 20 * i_es ) < 8 + 20 * i_es )
1292 msg_Err( p_input, "dshow plugin discarded (cannot peek)" );
1293 return VLC_EGENERIC;
1297 for( i = 0; i < i_es; i++ )
1301 if( !memcmp( p_peek, "auds", 4 ) )
1303 es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( p_peek[4], p_peek[5],
1304 p_peek[6], p_peek[7] ) );
1306 fmt.audio.i_channels = GetDWBE( &p_peek[8] );
1307 fmt.audio.i_rate = GetDWBE( &p_peek[12] );
1308 fmt.audio.i_bitspersample = GetDWBE( &p_peek[16] );
1309 fmt.audio.i_blockalign = fmt.audio.i_channels *
1310 fmt.audio.i_bitspersample / 8;
1311 fmt.i_bitrate = fmt.audio.i_channels *
1313 fmt.audio.i_bitspersample;
1315 msg_Dbg( p_input, "new audio es %d channels %dHz",
1316 fmt.audio.i_channels, fmt.audio.i_rate );
1318 TAB_APPEND( p_sys->i_es, p_sys->es,
1319 es_out_Add( p_input->p_es_out, &fmt ) );
1321 else if( !memcmp( p_peek, "vids", 4 ) )
1323 es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( p_peek[4], p_peek[5],
1324 p_peek[6], p_peek[7] ) );
1325 fmt.video.i_width = GetDWBE( &p_peek[8] );
1326 fmt.video.i_height = GetDWBE( &p_peek[12] );
1328 msg_Dbg( p_input, "added new video es %4.4s %dx%d",
1329 (char*)&fmt.i_codec,
1330 fmt.video.i_width, fmt.video.i_height );
1331 TAB_APPEND( p_sys->i_es, p_sys->es,
1332 es_out_Add( p_input->p_es_out, &fmt ) );
1339 stream_Read( p_input->s, NULL, 8 + 20 * i_es );
1344 /****************************************************************************
1346 ****************************************************************************/
1347 static void DemuxClose( vlc_object_t *p_this )
1349 input_thread_t *p_input = (input_thread_t *)p_this;
1350 demux_sys_t *p_sys = p_input->p_demux_data;
1352 if( p_sys->i_es > 0 )
1359 /****************************************************************************
1361 ****************************************************************************/
1362 static int Demux( input_thread_t *p_input )
1364 demux_sys_t *p_sys = p_input->p_demux_data;
1373 if( stream_Peek( p_input->s, &p_peek, 16 ) < 16 )
1375 msg_Warn( p_input, "cannot peek (EOF ?)" );
1379 i_es = GetDWBE( &p_peek[0] );
1380 if( i_es < 0 || i_es >= p_sys->i_es )
1382 msg_Err( p_input, "cannot find ES" );
1386 i_size = GetDWBE( &p_peek[4] );
1387 i_pcr = GetQWBE( &p_peek[8] );
1389 if( ( p_block = stream_Block( p_input->s, 16 + i_size ) ) == NULL )
1391 msg_Warn( p_input, "cannot read data" );
1395 p_block->p_buffer += 16;
1396 p_block->i_buffer -= 16;
1398 /* Call the pace control. */
1399 input_ClockManageRef( p_input, p_input->stream.p_selected_program, i_pcr );
1402 p_block->i_pts = i_pcr <= 0 ? 0 :
1403 input_ClockGetTS( p_input, p_input->stream.p_selected_program, i_pcr );
1405 es_out_Send( p_input->p_es_out, p_sys->es[i_es], p_block );
1411 /*****************************************************************************
1412 * config variable callback
1413 *****************************************************************************/
1414 static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
1415 vlc_value_t newval, vlc_value_t oldval, void * )
1417 module_config_t *p_item;
1418 vlc_bool_t b_audio = VLC_FALSE;
1421 p_item = config_FindConfig( p_this, psz_name );
1422 if( !p_item ) return VLC_SUCCESS;
1424 if( !strcmp( psz_name, "dshow-adev" ) ) b_audio = VLC_TRUE;
1426 /* Clear-up the current list */
1427 if( p_item->i_list )
1429 /* Keep the 2 first entries */
1430 for( i = 2; i < p_item->i_list; i++ )
1432 free( p_item->ppsz_list[i] );
1433 free( p_item->ppsz_list_text[i] );
1435 /* TODO: Remove when no more needed */
1436 p_item->ppsz_list[i] = NULL;
1437 p_item->ppsz_list_text[i] = NULL;
1441 /* Find list of devices */
1442 list<string> list_devices;
1444 FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
1446 if( !list_devices.size() ) return VLC_SUCCESS;
1449 (char **)realloc( p_item->ppsz_list,
1450 (list_devices.size()+3) * sizeof(char *) );
1451 p_item->ppsz_list_text =
1452 (char **)realloc( p_item->ppsz_list_text,
1453 (list_devices.size()+3) * sizeof(char *) );
1455 list<string>::iterator iter;
1456 for( iter = list_devices.begin(), i = 2; iter != list_devices.end();
1459 p_item->ppsz_list[i] = strdup( iter->c_str() );
1460 p_item->ppsz_list_text[i] = NULL;
1463 p_item->ppsz_list[i] = NULL;
1464 p_item->ppsz_list_text[i] = NULL;
1469 static void PropertiesPage( input_thread_t *p_input,
1470 IBaseFilter *p_device_filter )
1472 ISpecifyPropertyPages *p_spec;
1475 HRESULT hr = p_device_filter->QueryInterface( IID_ISpecifyPropertyPages,
1479 hr = p_spec->GetPages( &cauuid );
1482 HWND hwnd_desktop = ::GetDesktopWindow();
1484 hr = OleCreatePropertyFrame( hwnd_desktop, 30, 30, NULL, 1,
1485 (IUnknown **)&p_device_filter,
1487 (GUID *)cauuid.pElems, 0, 0, NULL );
1490 msg_Dbg( p_input, "made OleCreatePropertyFrame");
1493 CoTaskMemFree( cauuid.pElems );