- if( info.pFilter ) info.pFilter->Release();
- if( info.dir == PINDIR_INPUT )
- {
- p_output_pin->Release();
- continue;
- }
- msg_Dbg( p_this, "EnumDeviceCaps: trying pin %S", info.achName );
- }
-
- /* Probe pin */
- if( SUCCEEDED( p_output_pin->EnumMediaTypes( &p_enummt ) ) )
- {
- AM_MEDIA_TYPE *p_mt;
- while( p_enummt->Next( 1, &p_mt, NULL ) == S_OK )
- {
-
- if( p_mt->majortype == MEDIATYPE_Video )
- {
- int i_current_fourcc = VLC_FOURCC(' ', ' ', ' ', ' ');
-
- /* Packed RGB formats */
- if( p_mt->subtype == MEDIASUBTYPE_RGB1 )
- i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' );
- if( p_mt->subtype == MEDIASUBTYPE_RGB4 )
- i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' );
- if( p_mt->subtype == MEDIASUBTYPE_RGB8 )
- i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' );
- else if( p_mt->subtype == MEDIASUBTYPE_RGB555 )
- i_current_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' );
- else if( p_mt->subtype == MEDIASUBTYPE_RGB565 )
- i_current_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' );
- else if( p_mt->subtype == MEDIASUBTYPE_RGB24 )
- i_current_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' );
- else if( p_mt->subtype == MEDIASUBTYPE_RGB32 )
- i_current_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' );
- else if( p_mt->subtype == MEDIASUBTYPE_ARGB32 )
- i_current_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' );
-
- /* MPEG2 video elementary stream */
- else if( p_mt->subtype == MEDIASUBTYPE_MPEG2_VIDEO )
- i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
-
- /* hauppauge pvr video preview */
- else if( p_mt->subtype == MEDIASUBTYPE_PREVIEW_VIDEO )
- i_current_fourcc = VLC_FOURCC( 'P', 'V', 'R', 'V' );
-
- else i_current_fourcc = *((int *)&p_mt->subtype);
-
- int i_current_width = p_mt->pbFormat ?
- ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biWidth : 0;
- int i_current_height = p_mt->pbFormat ?
- ((VIDEOINFOHEADER *)p_mt->pbFormat)->bmiHeader.biHeight : 0;
- if( i_current_height < 0 )
- i_current_height = -i_current_height;
-
- msg_Dbg( p_this, "EnumDeviceCaps: input pin "
- "accepts chroma: %4.4s, width:%i, height:%i",
- (char *)&i_current_fourcc, i_current_width,
- i_current_height );
-
- if( ( !i_fourcc || i_fourcc == i_current_fourcc ||
- ( !i_orig_fourcc && i_current_fourcc ==
- VLC_FOURCC('I','4','2','0') ) ) &&
- ( !i_width || i_width == i_current_width ) &&
- ( !i_height || i_height == i_current_height ) )
- {
- /* Pick the 1st match */
- media_type = *p_mt;
- i_fourcc = i_current_fourcc;
- i_width = i_current_width;
- i_height = i_current_height;
- b_found = VLC_TRUE;
- }
- else
- {
- FreeMediaType( *p_mt );
- }
- }
- else if( p_mt->majortype == MEDIATYPE_Audio )
- {
- int i_current_fourcc;
- int i_current_channels =
- ((WAVEFORMATEX *)p_mt->pbFormat)->nChannels;
- int i_current_samplespersec =
- ((WAVEFORMATEX *)p_mt->pbFormat)->nSamplesPerSec;
- int i_current_bitspersample =
- ((WAVEFORMATEX *)p_mt->pbFormat)->wBitsPerSample;
-
- if( p_mt->subtype == MEDIASUBTYPE_PCM )
- i_current_fourcc = VLC_FOURCC( 'p', 'c', 'm', ' ' );
- else i_current_fourcc = *((int *)&p_mt->subtype);
-
- msg_Dbg( p_this, "EnumDeviceCaps: input pin "
- "accepts format: %4.4s, channels:%i, "
- "samples/sec:%i bits/sample:%i",
- (char *)&i_current_fourcc, i_current_channels,
- i_current_samplespersec, i_current_bitspersample);
-
- if( (!i_channels || i_channels == i_current_channels) &&
- (!i_samplespersec ||
- i_samplespersec == i_current_samplespersec) &&
- (!i_bitspersample ||
- i_bitspersample == i_current_bitspersample) )
- {
- /* Pick the 1st match */
- media_type = *p_mt;
- i_channels = i_current_channels;
- i_samplespersec = i_current_samplespersec;
- i_bitspersample = i_current_bitspersample;
- b_found = VLC_TRUE;
-
- /* Setup a few properties like the audio latency */
- IAMBufferNegotiation *p_ambuf;
-
- if( SUCCEEDED( p_output_pin->QueryInterface(
- IID_IAMBufferNegotiation, (void **)&p_ambuf ) ) )
- {
- ALLOCATOR_PROPERTIES AllocProp;
- AllocProp.cbAlign = -1;
- AllocProp.cbBuffer = i_channels * i_samplespersec *
- i_bitspersample / 8 / 10 ; /*100 ms of latency*/
- AllocProp.cbPrefix = -1;
- AllocProp.cBuffers = -1;
- p_ambuf->SuggestAllocatorProperties( &AllocProp );
- p_ambuf->Release();
- }
- }
- else
- {
- FreeMediaType( *p_mt );
- }
- }
- else if( p_mt->majortype == MEDIATYPE_Stream )
- {
- msg_Dbg( p_this, "EnumDeviceCaps: MEDIATYPE_Stream" );
-
- int i_current_fourcc = VLC_FOURCC(' ', ' ', ' ', ' ');
-
- if( p_mt->subtype == MEDIASUBTYPE_MPEG2_PROGRAM )
- i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 'p' );
- else if( p_mt->subtype == MEDIASUBTYPE_MPEG2_TRANSPORT )
- i_current_fourcc = VLC_FOURCC( 'm', 'p', '2', 't' );
-
- if( ( !i_fourcc || i_fourcc == i_current_fourcc ) )
- {
- /* Pick the 1st match */
- media_type = *p_mt;
- i_fourcc = i_current_fourcc;
- b_found = VLC_TRUE;
- }
- else
- {
- FreeMediaType( *p_mt );
- }
- }
- else
- {
- msg_Dbg( p_this,
- "EnumDeviceCaps: input pin: unknown format" );
- FreeMediaType( *p_mt );
- }
-
- CoTaskMemFree( (PVOID)p_mt );
- }
- p_enummt->Release();
- }
-
- p_output_pin->Release();
- }
-
- p_enumpins->Release();
- return media_type;
-}
-
-/*****************************************************************************
- * Read: reads from the device into PES packets.
- *****************************************************************************
- * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
- * bytes.
- *****************************************************************************/
-static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer,
- size_t i_len )
-{
- access_sys_t *p_sys = p_input->p_access_data;
- dshow_stream_t *p_stream = NULL;
- byte_t *p_buf_orig = p_buffer;
- VLCMediaSample sample;
- int i_data_size;
- uint8_t *p_data;
-
- if( p_sys->i_header_pos )
- {
- /* First header of the stream */
- memcpy( p_buffer, p_sys->p_header, p_sys->i_header_size );
- p_buffer += p_sys->i_header_size;
- p_sys->i_header_pos = 0;
- }
-
- while( 1 )
- {
- /* Get new sample/frame from next elementary stream.
- * We first loop through all the elementary streams and if all our
- * fifos are empty we block until we are signaled some new data has
- * arrived. */
- vlc_mutex_lock( &p_sys->lock );
-
- int i_stream;
- for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
- {
- p_stream = p_sys->pp_streams[i_stream];
- if( p_stream->mt.majortype == MEDIATYPE_Audio &&
- p_stream->p_capture_filter &&
- p_stream->p_capture_filter->CustomGetPin()
- ->CustomGetSample( &sample ) == S_OK )
- {
- break;
- }
- }
- if( i_stream == p_sys->i_streams )
- for( i_stream = 0; i_stream < p_sys->i_streams; i_stream++ )
- {
- p_stream = p_sys->pp_streams[i_stream];
- if( p_stream->p_capture_filter &&
- p_stream->p_capture_filter->CustomGetPin()
- ->CustomGetSample( &sample ) == S_OK )
- {
- break;
- }
- }
- if( i_stream == p_sys->i_streams )
- {
- /* No data available. Wait until some data has arrived */
- vlc_cond_wait( &p_sys->wait, &p_sys->lock );
- vlc_mutex_unlock( &p_sys->lock );
- continue;