From 08be895ad56325bb18277bcc55a658e9d6cd04bf Mon Sep 17 00:00:00 2001 From: Damien Fouilleul Date: Tue, 22 Jun 2004 09:13:51 +0000 Subject: [PATCH] - added last resort built-in mediatype for capture filter if card does not returns any (i.e Osprey cards) - miscelaneous clean ups --- modules/access/dshow/dshow.cpp | 157 ++++++++++++++------- modules/access/dshow/filter.cpp | 241 +++++++++++++++++++------------- modules/access/dshow/filter.h | 2 +- 3 files changed, 256 insertions(+), 144 deletions(-) diff --git a/modules/access/dshow/dshow.cpp b/modules/access/dshow/dshow.cpp index 46ce3a7891..926d3d8dd5 100644 --- a/modules/access/dshow/dshow.cpp +++ b/modules/access/dshow/dshow.cpp @@ -471,7 +471,7 @@ static int AccessOpen( vlc_object_t *p_this ) if( SUCCEEDED(pXbar->Route(VideoOutputIndex, VideoInputIndex)) ) { msg_Dbg( p_access, "Crossbar at depth %d, Routed video " - "ouput %d to video input %d", i, VideoOutputIndex, + "ouput %ld to video input %ld", i, VideoOutputIndex, VideoInputIndex ); if( AudioOutputIndex != -1 && AudioInputIndex != -1 ) @@ -480,7 +480,7 @@ static int AccessOpen( vlc_object_t *p_this ) AudioInputIndex)) ) { msg_Dbg(p_access, "Crossbar at depth %d, Routed audio " - "ouput %d to audio input %d", i, + "ouput %ld to audio input %ld", i, AudioOutputIndex, AudioInputIndex ); } } @@ -745,7 +745,7 @@ static HRESULT FindCrossbarRoutes( access_t *p_access, IPin *p_input_pin, p_sys->crossbar_routes[depth].AudioOutputIndex = outputPinIndexRelated; msg_Dbg( p_access, "Crossbar at depth %d, Found Route For " - "ouput %ld (type %ld) to input %d (type %ld)", depth, + "ouput %ld (type %ld) to input %ld (type %ld)", depth, outputPinIndex, outputPinPhysicalType, inputPinIndex, inputPinPhysicalType ); @@ -865,12 +865,13 @@ static int GetFourCCPriority(int i_fourcc) switch( i_fourcc ) { case VLC_FOURCC('I','4','2','0'): - case VLC_FOURCC('a','r','a','w'): + case VLC_FOURCC('f','l','3','2'): { return 9; } case VLC_FOURCC('Y','V','1','2'): + case VLC_FOURCC('a','r','a','w'): { return 8; } @@ -883,7 +884,6 @@ static int GetFourCCPriority(int i_fourcc) case VLC_FOURCC('Y','U','Y','2'): case VLC_FOURCC('R','V','3','2'): case VLC_FOURCC('R','G','B','A'): - case VLC_FOURCC('f','l','3','2'): { return 6; } @@ -940,6 +940,7 @@ static int OpenDevice( access_t *p_access, string devicename, return VLC_EGENERIC; } + AM_MEDIA_TYPE *mt; AM_MEDIA_TYPE media_types[MAX_MEDIA_TYPES]; size_t mt_count = EnumDeviceCaps( (vlc_object_t *)p_access, @@ -947,42 +948,101 @@ static int OpenDevice( access_t *p_access, string devicename, p_sys->i_width, p_sys->i_height, 0, 0, 0, media_types, MAX_MEDIA_TYPES ); - if( 0 == mt_count ) + if( mt_count > 0 ) { - msg_Err( p_access, "can't use device: %s, unsupported media types", + mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count ); + + // Order and copy returned media types according to arbitrary + // fourcc priority + for( size_t c=0; c slot_priority ) + { + slot_priority = priority; + slot_copy = d; + } + } + if( slot_copy != c ) + { + mt[c] = media_types[slot_copy]; + media_types[slot_copy] = media_types[c]; + } + else + { + mt[c] = media_types[c]; + } + } + } + else if( ! b_audio ) { + // Use default video media type + AM_MEDIA_TYPE mtr; + VIDEOINFOHEADER vh; + + mtr.majortype = MEDIATYPE_Video; + mtr.subtype = MEDIASUBTYPE_I420; + mtr.bFixedSizeSamples = TRUE; + mtr.bTemporalCompression = FALSE; + mtr.lSampleSize = 0; + mtr.pUnk = NULL; + mtr.formattype = FORMAT_VideoInfo; + mtr.cbFormat = sizeof(vh); + mtr.pbFormat = (BYTE *)&vh; + + memset(&vh, 0, sizeof(vh)); + + vh.bmiHeader.biSize = sizeof(vh.bmiHeader); + vh.bmiHeader.biWidth = p_sys->i_width > 0 ? p_sys->i_width: 320; + vh.bmiHeader.biHeight = p_sys->i_height > 0 ? p_sys->i_height : 240; + vh.bmiHeader.biPlanes = 1; + vh.bmiHeader.biBitCount = 24; + vh.bmiHeader.biCompression = VLC_FOURCC('I','4','2','0'); + vh.bmiHeader.biSizeImage = p_sys->i_width * 24 * p_sys->i_height / 8; + + msg_Warn( p_access, "device %s using built-in video media type", devicename.c_str() ); - return VLC_EGENERIC; + + mt_count = 1; + mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count ); + CopyMediaType(mt, &mtr); } - - AM_MEDIA_TYPE *mt = - (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count ); + else { + // Use default audio media type + AM_MEDIA_TYPE mtr; + WAVEFORMATEX wf; + + mtr.majortype = MEDIATYPE_Audio; + mtr.subtype = MEDIASUBTYPE_PCM; + mtr.bFixedSizeSamples = TRUE; + mtr.bTemporalCompression = FALSE; + mtr.lSampleSize = 0; + mtr.pUnk = NULL; + mtr.formattype = FORMAT_WaveFormatEx; + mtr.cbFormat = sizeof(wf); + mtr.pbFormat = (BYTE *)&wf; + + memset(&wf, 0, sizeof(wf)); + + wf.wFormatTag = WAVE_FORMAT_PCM; + wf.nChannels = 2; + wf.nSamplesPerSec = 44100; + wf.wBitsPerSample = 16; + wf.nBlockAlign = wf.nSamplesPerSec * wf.wBitsPerSample / 8; + wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign; + wf.cbSize = 0; + + msg_Warn( p_access, "device %s using built-in audio media type", + devicename.c_str() ); - // Order and copy returned media types according to arbitrary - // fourcc priority - for( size_t c=0; c slot_priority ) - { - slot_priority = priority; - slot_copy = d; - } - } - if( slot_copy != c ) - { - mt[c] = media_types[slot_copy]; - media_types[slot_copy] = media_types[c]; - } - else - { - mt[c] = media_types[c]; - } + mt_count = 1; + mt = (AM_MEDIA_TYPE *)malloc( sizeof(AM_MEDIA_TYPE)*mt_count ); + CopyMediaType(mt, &mtr); } /* Create and add our capture filter */ @@ -1026,8 +1086,6 @@ static int OpenDevice( access_t *p_access, string devicename, { if( dshow_stream.mt.majortype == MEDIATYPE_Video ) { - msg_Dbg( p_access, "MEDIATYPE_Video"); - dshow_stream.header.video = *(VIDEOINFOHEADER *)dshow_stream.mt.pbFormat; @@ -1087,13 +1145,11 @@ static int OpenDevice( access_t *p_access, string devicename, /* Greatly simplifies the reading routine */ int i_mtu = dshow_stream.header.video.bmiHeader.biWidth * i_height * 4; - p_sys->i_mtu = __MAX( p_sys->i_mtu, (unsigned int)i_mtu ); + p_sys->i_mtu = __MAX( p_sys->i_mtu, i_mtu ); } else if( dshow_stream.mt.majortype == MEDIATYPE_Audio ) { - msg_Dbg( p_access, "MEDIATYPE_Audio"); - dshow_stream.header.audio = *(WAVEFORMATEX *)dshow_stream.mt.pbFormat; @@ -1135,7 +1191,7 @@ static int OpenDevice( access_t *p_access, string devicename, dshow_stream.header.audio.wBitsPerSample / 8; } p_pin->Release(); - p_sys->i_mtu = __MAX( p_sys->i_mtu, (unsigned int)i_mtu ); + p_sys->i_mtu = __MAX( p_sys->i_mtu, i_mtu ); } else if( dshow_stream.mt.majortype == MEDIATYPE_Stream ) @@ -1200,7 +1256,7 @@ FindCaptureDevice( vlc_object_t *p_this, string *p_devicename, IID_ICreateDevEnum, (void **)&p_dev_enum ); if( FAILED(hr) ) { - msg_Err( p_this, "failed to create the device enumerator (0x%x)", hr); + msg_Err( p_this, "failed to create the device enumerator (0x%lx)", hr); return NULL; } @@ -1215,7 +1271,7 @@ FindCaptureDevice( vlc_object_t *p_this, string *p_devicename, p_dev_enum->Release(); if( FAILED(hr) ) { - msg_Err( p_this, "failed to create the class enumerator (0x%x)", hr ); + msg_Err( p_this, "failed to create the class enumerator (0x%lx)", hr ); return NULL; } @@ -1263,7 +1319,7 @@ FindCaptureDevice( vlc_object_t *p_this, string *p_devicename, if( FAILED(hr) ) { msg_Err( p_this, "couldn't bind moniker to filter " - "object (0x%x)", hr ); + "object (0x%lx)", hr ); p_moniker->Release(); p_class_enum->Release(); return NULL; @@ -1293,7 +1349,11 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter, IEnumMediaTypes *p_enummt; size_t mt_count = 0; - if( S_OK != p_filter->EnumPins( &p_enumpins ) ) return 0; + if( FAILED(p_filter->EnumPins( &p_enumpins )) ) + { + msg_Dbg( p_this, "EnumDeviceCaps failed: no pin enumeration !"); + return 0; + } while( S_OK == p_enumpins->Next( 1, &p_output_pin, NULL ) ) { @@ -1309,6 +1369,7 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter, p_output_pin->Release(); } + p_enumpins->Reset(); while( !mt_count && p_enumpins->Next( 1, &p_output_pin, NULL ) == S_OK ) @@ -1414,8 +1475,6 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter, } else if( p_mt->majortype == MEDIATYPE_Stream ) { - msg_Dbg( p_this, "EnumDeviceCaps: MEDIATYPE_Stream" ); - if( ( !i_fourcc || i_fourcc == i_current_fourcc ) && (mt_count < mt_max) ) { diff --git a/modules/access/dshow/filter.cpp b/modules/access/dshow/filter.cpp index 17b27663d7..24e535a99e 100644 --- a/modules/access/dshow/filter.cpp +++ b/modules/access/dshow/filter.cpp @@ -93,7 +93,9 @@ const GUID IID_IAMTVTuner = {0x211A8766, 0x03AC, 0x11d1, {0x8D, 0x13, 0x00, 0xAA const GUID IID_IKsPropertySet = {0x31EFAC30, 0x515C, 0x11d0, {0xA9, 0xAA, 0x00, 0xAA, 0x00, 0x61, 0xBE, 0x93}}; +/* Video Format */ +const GUID FORMAT_VideoInfo = {0x05589f80, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}}; /* * MEDIATYPEs and MEDIASUBTYPEs */ @@ -219,64 +221,69 @@ int GetFourCCFromMediaType(const AM_MEDIA_TYPE &media_type) if( media_type.majortype == MEDIATYPE_Video ) { - /* Packed RGB formats */ - if( media_type.subtype == MEDIASUBTYPE_RGB1 ) - i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' ); - else if( media_type.subtype == MEDIASUBTYPE_RGB4 ) - i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' ); - else if( media_type.subtype == MEDIASUBTYPE_RGB8 ) - i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' ); - else if( media_type.subtype == MEDIASUBTYPE_RGB555 ) - i_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' ); - else if( media_type.subtype == MEDIASUBTYPE_RGB565 ) - i_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' ); - else if( media_type.subtype == MEDIASUBTYPE_RGB24 ) - i_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' ); - else if( media_type.subtype == MEDIASUBTYPE_RGB32 ) - i_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' ); - else if( media_type.subtype == MEDIASUBTYPE_ARGB32 ) - i_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' ); - - /* Planar YUV formats */ - else if( media_type.subtype == MEDIASUBTYPE_I420 ) - i_fourcc = VLC_FOURCC( 'I', '4', '2', '0' ); - else if( media_type.subtype == MEDIASUBTYPE_Y41P ) - i_fourcc = VLC_FOURCC( 'I', '4', '1', '1' ); - else if( media_type.subtype == MEDIASUBTYPE_YV12 ) - i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' ); - else if( media_type.subtype == MEDIASUBTYPE_IYUV ) - i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' ); - else if( media_type.subtype == MEDIASUBTYPE_YVU9 ) - i_fourcc = VLC_FOURCC( 'Y', 'V', 'U', '9' ); - - /* Packed YUV formats */ - else if( media_type.subtype == MEDIASUBTYPE_YVYU ) - i_fourcc = VLC_FOURCC( 'Y', 'V', 'Y', 'U' ); - else if( media_type.subtype == MEDIASUBTYPE_YUYV ) - i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' ); - else if( media_type.subtype == MEDIASUBTYPE_Y411 ) - i_fourcc = VLC_FOURCC( 'I', '4', '1', 'N' ); - else if( media_type.subtype == MEDIASUBTYPE_Y211 ) - i_fourcc = VLC_FOURCC( 'Y', '2', '1', '1' ); - else if( media_type.subtype == MEDIASUBTYPE_YUY2 ) - i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' ); - else if( media_type.subtype == MEDIASUBTYPE_UYVY ) - i_fourcc = VLC_FOURCC( 'U', 'Y', 'V', 'Y' ); - - /* MPEG2 video elementary stream */ - else if( media_type.subtype == MEDIASUBTYPE_MPEG2_VIDEO ) - i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' ); - - /* DV formats */ - else if( media_type.subtype == MEDIASUBTYPE_dvsl ) - i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'l' ); - else if( media_type.subtype == MEDIASUBTYPE_dvsd ) - i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'd' ); - else if( media_type.subtype == MEDIASUBTYPE_dvhd ) - i_fourcc = VLC_FOURCC( 'd', 'v', 'h', 'd' ); + /* currently only support this type of video info format */ + if( media_type.formattype == FORMAT_VideoInfo ) + { + /* Packed RGB formats */ + if( media_type.subtype == MEDIASUBTYPE_RGB1 ) + i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '1' ); + else if( media_type.subtype == MEDIASUBTYPE_RGB4 ) + i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '4' ); + else if( media_type.subtype == MEDIASUBTYPE_RGB8 ) + i_fourcc = VLC_FOURCC( 'R', 'G', 'B', '8' ); + else if( media_type.subtype == MEDIASUBTYPE_RGB555 ) + i_fourcc = VLC_FOURCC( 'R', 'V', '1', '5' ); + else if( media_type.subtype == MEDIASUBTYPE_RGB565 ) + i_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' ); + else if( media_type.subtype == MEDIASUBTYPE_RGB24 ) + i_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' ); + else if( media_type.subtype == MEDIASUBTYPE_RGB32 ) + i_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' ); + else if( media_type.subtype == MEDIASUBTYPE_ARGB32 ) + i_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' ); + + /* Planar YUV formats */ + else if( media_type.subtype == MEDIASUBTYPE_I420 ) + i_fourcc = VLC_FOURCC( 'I', '4', '2', '0' ); + else if( media_type.subtype == MEDIASUBTYPE_Y41P ) + i_fourcc = VLC_FOURCC( 'I', '4', '1', '1' ); + else if( media_type.subtype == MEDIASUBTYPE_YV12 ) + i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' ); + else if( media_type.subtype == MEDIASUBTYPE_IYUV ) + i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' ); + else if( media_type.subtype == MEDIASUBTYPE_YVU9 ) + i_fourcc = VLC_FOURCC( 'Y', 'V', 'U', '9' ); + + /* Packed YUV formats */ + else if( media_type.subtype == MEDIASUBTYPE_YVYU ) + i_fourcc = VLC_FOURCC( 'Y', 'V', 'Y', 'U' ); + else if( media_type.subtype == MEDIASUBTYPE_YUYV ) + i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' ); + else if( media_type.subtype == MEDIASUBTYPE_Y411 ) + i_fourcc = VLC_FOURCC( 'I', '4', '1', 'N' ); + else if( media_type.subtype == MEDIASUBTYPE_Y211 ) + i_fourcc = VLC_FOURCC( 'Y', '2', '1', '1' ); + else if( media_type.subtype == MEDIASUBTYPE_YUY2 ) + i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' ); + else if( media_type.subtype == MEDIASUBTYPE_UYVY ) + i_fourcc = VLC_FOURCC( 'U', 'Y', 'V', 'Y' ); + + /* MPEG2 video elementary stream */ + else if( media_type.subtype == MEDIASUBTYPE_MPEG2_VIDEO ) + i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' ); + + /* DV formats */ + else if( media_type.subtype == MEDIASUBTYPE_dvsl ) + i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'l' ); + else if( media_type.subtype == MEDIASUBTYPE_dvsd ) + i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'd' ); + else if( media_type.subtype == MEDIASUBTYPE_dvhd ) + i_fourcc = VLC_FOURCC( 'd', 'v', 'h', 'd' ); + } } else if( media_type.majortype == MEDIATYPE_Audio ) { + /* currently only support this type of audio info format */ if( media_type.formattype == FORMAT_WaveFormatEx ) { if( media_type.subtype == MEDIASUBTYPE_PCM ) @@ -405,10 +412,7 @@ STDMETHODIMP_(ULONG) CapturePin::Release() STDMETHODIMP CapturePin::Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt ) { -#ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CapturePin::Connect" ); -#endif - if( State_Stopped == p_filter->state ) + if( State_Running != p_filter->state ) { if( ! p_connected_pin ) { @@ -416,46 +420,66 @@ STDMETHODIMP CapturePin::Connect( IPin * pReceivePin, return S_OK; if( (GUID_NULL != pmt->majortype) && (media_types[0].majortype != pmt->majortype) ) + msg_Dbg( p_input, "CapturePin::Connect [media major type mismatch]" ); return S_FALSE; if( (GUID_NULL != pmt->subtype) && (! GetFourCCFromMediaType(*pmt)) ) + msg_Dbg( p_input, "CapturePin::Connect [media subtype type not supported]" ); return S_FALSE; if( pmt->pbFormat ) { - if( pmt->majortype == MEDIATYPE_Video ) + if( pmt->majortype == MEDIATYPE_Video ) { if( (((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight == 0) ) + { + msg_Dbg( p_input, "CapturePin::Connect [video height == 0]" ); return S_FALSE; + } if( (((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth == 0) ) + { + msg_Dbg( p_input, "CapturePin::Connect [video width == 0]" ); return S_FALSE; - + } } } + msg_Dbg( p_input, "CapturePin::Connect [OK]" ); return S_OK; } + msg_Dbg( p_input, "CapturePin::Connect [already connected]" ); return VFW_E_ALREADY_CONNECTED; } + msg_Dbg( p_input, "CapturePin::Connect [not stopped]" ); return VFW_E_NOT_STOPPED; } STDMETHODIMP CapturePin::ReceiveConnection( IPin * pConnector, const AM_MEDIA_TYPE *pmt ) { -#ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CapturePin::ReceiveConnection" ); -#endif - if( State_Stopped != p_filter->state ) + { + msg_Dbg( p_input, "CapturePin::ReceiveConnection [not stopped]" ); return VFW_E_NOT_STOPPED; + } - if( ! pmt ) + if( !pConnector || !pmt ) + { + msg_Dbg( p_input, "CapturePin::ReceiveConnection [null pointer]" ); return E_POINTER; + } if( p_connected_pin ) + { + msg_Dbg( p_input, "CapturePin::ReceiveConnection [already connected]" ); return VFW_E_ALREADY_CONNECTED; + } if( S_OK != QueryAccept(pmt) ) + { + msg_Dbg( p_input, "CapturePin::ReceiveConnection [media type not accepted]" ); return VFW_E_TYPE_NOT_ACCEPTED; + } + + msg_Dbg( p_input, "CapturePin::ReceiveConnection [OK]" ); p_connected_pin = pConnector; p_connected_pin->AddRef(); @@ -465,11 +489,13 @@ STDMETHODIMP CapturePin::ReceiveConnection( IPin * pConnector, } STDMETHODIMP CapturePin::Disconnect() { -#ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CapturePin::Disconnect" ); -#endif + if( ! p_connected_pin ) + { + msg_Dbg( p_input, "CapturePin::Disconnect [not connected]" ); + return S_FALSE; + } - if( ! p_connected_pin ) return S_FALSE; + msg_Dbg( p_input, "CapturePin::Disconnect [OK]" ); #if 0 // FIXME: This does seem to create crashes sometimes VLCMediaSample vlc_sample; @@ -493,24 +519,26 @@ STDMETHODIMP CapturePin::Disconnect() } STDMETHODIMP CapturePin::ConnectedTo( IPin **pPin ) { -#ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CapturePin::ConnectedTo" ); -#endif - - if( !p_connected_pin ) return VFW_E_NOT_CONNECTED; + if( !p_connected_pin ) + { + msg_Dbg( p_input, "CapturePin::ConnectedTo [not connected]" ); + return VFW_E_NOT_CONNECTED; + } p_connected_pin->AddRef(); *pPin = p_connected_pin; + msg_Dbg( p_input, "CapturePin::ConnectedTo [OK]" ); + return S_OK; } STDMETHODIMP CapturePin::ConnectionMediaType( AM_MEDIA_TYPE *pmt ) { -#ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CapturePin::ConnectionMediaType" ); -#endif - - if( !p_connected_pin ) return VFW_E_NOT_CONNECTED; + if( !p_connected_pin ) + { + msg_Dbg( p_input, "CapturePin::ConnectionMediaType [not connected]" ); + return VFW_E_NOT_CONNECTED; + } return CopyMediaType( pmt, &cx_media_type ); } @@ -549,28 +577,54 @@ STDMETHODIMP CapturePin::QueryId( LPWSTR * Id ) } STDMETHODIMP CapturePin::QueryAccept( const AM_MEDIA_TYPE *pmt ) { -#ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CapturePin::QueryAccept" ); -#endif if( State_Stopped == p_filter->state ) { if( media_types[0].majortype == pmt->majortype ) { - if( GetFourCCFromMediaType(*pmt) ) + int i_chroma = GetFourCCFromMediaType(*pmt); + if( 0 != i_chroma ) { if( pmt->majortype == MEDIATYPE_Video ) + { if( pmt->pbFormat && ((((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight == 0) || (((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth == 0)) ) + { + msg_Dbg( p_input, "CapturePin::QueryAccept [video size wxh == 0]" ); return S_FALSE; - - if( !p_connected_pin ) - return S_OK; - - FreeMediaType( cx_media_type ); - return CopyMediaType( &cx_media_type, pmt ); + } + msg_Dbg( p_input, "CapturePin::QueryAccept [OK] (width=%ld, height=%ld, chroma=%4.4s)", + ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth, + ((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight, + (char *)&i_chroma + ); + } + else { + msg_Dbg( p_input, "CapturePin::QueryAccept [OK] (channels=%d, samples/sec=%lu, bits/samples=%d, format=%4.4s)", + ((WAVEFORMATEX *)pmt->pbFormat)->nChannels, + ((WAVEFORMATEX *)pmt->pbFormat)->nSamplesPerSec, + ((WAVEFORMATEX *)pmt->pbFormat)->wBitsPerSample, + (char *)&i_chroma + ); + } + + if( p_connected_pin ) + { + FreeMediaType( cx_media_type ); + CopyMediaType( &cx_media_type, pmt ); + } + return S_OK; } + else { + msg_Dbg( p_input, "CapturePin::QueryAccept [media type not supported]" ); + } } + else { + msg_Dbg( p_input, "CapturePin::QueryAccept [media type mismatch]" ); + } + } + else { + msg_Dbg( p_input, "CapturePin::QueryAccept [not stopped]" ); } return S_FALSE; } @@ -707,9 +761,8 @@ STDMETHODIMP CapturePin::ReceiveCanBlock( void ) ****************************************************************************/ CaptureFilter::CaptureFilter( access_t * _p_input, AM_MEDIA_TYPE *mt, size_t mt_count ) - : p_input( _p_input ), - p_pin( new CapturePin( _p_input, this, mt, mt_count ) ), - state( State_Stopped ), i_ref( 1 ) + : p_input( _p_input ), p_pin( new CapturePin( _p_input, this, mt, mt_count ) ), + state( State_Stopped ), i_ref( 1 ) { } @@ -1110,7 +1163,7 @@ STDMETHODIMP CaptureEnumMediaTypes::Next( ULONG cMediaTypes, ULONG * pcFetched ) { #ifdef DEBUG_DSHOW - msg_Dbg( p_input, "CaptureEnumMediaTypes::Next" ); + msg_Dbg( p_input, "CaptureEnumMediaTypes::Next " ); #endif ULONG count; diff --git a/modules/access/dshow/filter.h b/modules/access/dshow/filter.h index 442154a034..0eae2afbb5 100644 --- a/modules/access/dshow/filter.h +++ b/modules/access/dshow/filter.h @@ -209,7 +209,7 @@ class CaptureEnumMediaTypes : public IEnumMediaTypes access_t * p_input; CapturePin *p_pin; - int i_position; + size_t i_position; long i_ref; public: -- 2.39.5