/*****************************************************************************
* filter.c : DirectShow access module for vlc
*****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002 the VideoLAN team
* $Id$
*
* Author: Gildas Bazin <gbazin@videolan.org>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/vout.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_fourcc.h>
#ifndef _MSC_VER
/* Work-around a bug in w32api-2.5 */
/*****************************************************************************
* DirectShow GUIDs.
- * Easier to define them hear as mingw doesn't provide them all.
+ * Easier to define them here as mingw doesn't provide them all.
*****************************************************************************/
const GUID CLSID_SystemDeviceEnum = {0x62be5d10, 0x60eb, 0x11d0, {0xbd, 0x3b, 0x00, 0xa0, 0xc9, 0x11, 0xce, 0x86}};
const GUID CLSID_VideoInputDeviceCategory = {0x860BB310,0x5D01,0x11d0,{0xBD,0x3B,0x00,0xA0,0xC9,0x11,0xCE,0x86}};
const GUID MEDIASUBTYPE_YUY2 = {0x32595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
const GUID MEDIASUBTYPE_YVYU = {0x55595659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
const GUID MEDIASUBTYPE_UYVY = {0x59565955, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+const GUID MEDIASUBTYPE_HDYC = {0x43594448, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
/* Planar YUV formats */
const GUID MEDIASUBTYPE_YVU9 = {0x39555659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
const GUID MEDIASUBTYPE_MPEG2_TRANSPORT = {0xe06d8023, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
const GUID FORMAT_MPEG2Video = {0xe06d80e3, 0xdb46, 0x11cf, {0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea}};
+/* MJPG format */
+const GUID MEDIASUBTYPE_MJPG = {0x47504A4D, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+
+/* DivX formats */
+const GUID MEDIASUBTYPE_DIVX = {0x58564944, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+
/* Analog Video */
const GUID FORMAT_AnalogVideo = {0x482dde0, 0x7817, 0x11cf, {0x8a, 0x3, 0x0, 0xaa, 0x0, 0x6e, 0xcb, 0x65}};
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' );
+ i_fourcc = VLC_CODEC_RGB15;
else if( media_type.subtype == MEDIASUBTYPE_RGB565 )
- i_fourcc = VLC_FOURCC( 'R', 'V', '1', '6' );
+ i_fourcc = VLC_CODEC_RGB16;
else if( media_type.subtype == MEDIASUBTYPE_RGB24 )
- i_fourcc = VLC_FOURCC( 'R', 'V', '2', '4' );
+ i_fourcc = VLC_CODEC_RGB24;
else if( media_type.subtype == MEDIASUBTYPE_RGB32 )
- i_fourcc = VLC_FOURCC( 'R', 'V', '3', '2' );
+ i_fourcc = VLC_CODEC_RGB32;
else if( media_type.subtype == MEDIASUBTYPE_ARGB32 )
- i_fourcc = VLC_FOURCC( 'R', 'G', 'B', 'A' );
+ i_fourcc = VLC_CODEC_RGBA;
/* Planar YUV formats */
else if( media_type.subtype == MEDIASUBTYPE_I420 )
- i_fourcc = VLC_FOURCC( 'I', '4', '2', '0' );
+ i_fourcc = VLC_CODEC_I420;
else if( media_type.subtype == MEDIASUBTYPE_Y41P )
- i_fourcc = VLC_FOURCC( 'I', '4', '1', '1' );
+ i_fourcc = VLC_CODEC_I411;
else if( media_type.subtype == MEDIASUBTYPE_YV12 )
- i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' );
+ i_fourcc = VLC_CODEC_YV12;
else if( media_type.subtype == MEDIASUBTYPE_IYUV )
- i_fourcc = VLC_FOURCC( 'Y', 'V', '1', '2' );
+ i_fourcc = VLC_CODEC_YV12;
else if( media_type.subtype == MEDIASUBTYPE_YVU9 )
- i_fourcc = VLC_FOURCC( 'Y', 'V', 'U', '9' );
+ i_fourcc = VLC_CODEC_I410;
/* Packed YUV formats */
else if( media_type.subtype == MEDIASUBTYPE_YVYU )
- i_fourcc = VLC_FOURCC( 'Y', 'V', 'Y', 'U' );
+ i_fourcc = VLC_CODEC_YVYU;
else if( media_type.subtype == MEDIASUBTYPE_YUYV )
- i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' );
+ i_fourcc = VLC_CODEC_YUYV;
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' );
+ i_fourcc = VLC_CODEC_Y211;
else if( media_type.subtype == MEDIASUBTYPE_YUY2 )
- i_fourcc = VLC_FOURCC( 'Y', 'U', 'Y', '2' );
+ i_fourcc = VLC_CODEC_YUYV;
else if( media_type.subtype == MEDIASUBTYPE_UYVY )
- i_fourcc = VLC_FOURCC( 'U', 'Y', 'V', 'Y' );
+ i_fourcc = VLC_CODEC_UYVY;
+ /* HDYC uses UYVY sample positions but Rec709 colourimetry */
+ /* FIXME: When VLC understands colourspace, something will need
+ * to be added / changed here. Until then, just make it behave
+ * like UYVY */
+ else if( media_type.subtype == MEDIASUBTYPE_HDYC )
+ i_fourcc = VLC_CODEC_UYVY;
/* MPEG2 video elementary stream */
else if( media_type.subtype == MEDIASUBTYPE_MPEG2_VIDEO )
- i_fourcc = VLC_FOURCC( 'm', 'p', '2', 'v' );
+ i_fourcc = VLC_CODEC_MPGV;
+
+ /* DivX video */
+ else if( media_type.subtype == MEDIASUBTYPE_DIVX )
+ i_fourcc = VLC_CODEC_MP4V;
/* DV formats */
else if( media_type.subtype == MEDIASUBTYPE_dvsl )
- i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'l' );
+ i_fourcc = VLC_CODEC_DV;
else if( media_type.subtype == MEDIASUBTYPE_dvsd )
- i_fourcc = VLC_FOURCC( 'd', 'v', 's', 'd' );
+ i_fourcc = VLC_CODEC_DV;
else if( media_type.subtype == MEDIASUBTYPE_dvhd )
- i_fourcc = VLC_FOURCC( 'd', 'v', 'h', 'd' );
+ i_fourcc = VLC_CODEC_DV;
+
+ /* MJPEG format */
+ else if( media_type.subtype == MEDIASUBTYPE_MJPG )
+ i_fourcc = VLC_CODEC_MJPG;
+
}
}
else if( media_type.majortype == MEDIATYPE_Audio )
if( media_type.subtype == MEDIASUBTYPE_PCM )
i_fourcc = VLC_FOURCC( 'a', 'r', 'a', 'w' );
else if( media_type.subtype == MEDIASUBTYPE_IEEE_FLOAT )
- i_fourcc = VLC_FOURCC( 'f', 'l', '3', '2' );
+ i_fourcc = VLC_CODEC_FL32;
}
}
else if( media_type.majortype == MEDIATYPE_Stream )
FreeMediaType(cx_media_type);
}
+/**
+ * Returns the complete queue of samples that have been received so far.
+ * Lock the p_sys->lock before calling this function.
+ * @param samples_queue [out] Empty queue that will get all elements from
+ * the pin queue.
+ * @return S_OK if a sample was available, S_FALSE if no sample was
+ * available
+ */
+HRESULT CapturePin::CustomGetSamples( deque<VLCMediaSample> &external_queue )
+{
+#if 0 //def DEBUG_DSHOW
+ msg_Dbg( p_input, "CapturePin::CustomGetSamples: %d samples in the queue", samples_queue.size());
+#endif
+
+ if( !samples_queue.empty() )
+ {
+ external_queue.swap(samples_queue);
+ return S_OK;
+ }
+ return S_FALSE;
+}
+
+/**
+ * Returns a sample from its sample queue. Proper locking must be done prior
+ * to this call. Current dshow code protects the access to any sample queue
+ * (audio and video) with the p_sys->lock
+ * @param vlc_sample [out] Address of a sample if sucessfull. Undefined
+ * otherwise.
+ * @return S_OK if a sample was available, S_FALSE if no sample was
+ * available
+ */
HRESULT CapturePin::CustomGetSample( VLCMediaSample *vlc_sample )
{
#if 0 //def DEBUG_DSHOW
msg_Dbg( p_input, "CapturePin::CustomGetSample" );
#endif
- vlc_mutex_lock( &p_sys->lock );
if( samples_queue.size() )
{
*vlc_sample = samples_queue.back();
samples_queue.pop_back();
- vlc_mutex_unlock( &p_sys->lock );
return S_OK;
}
- vlc_mutex_unlock( &p_sys->lock );
return S_FALSE;
}
}
if( !pmt ) return S_OK;
-
+
if( GUID_NULL != pmt->majortype &&
media_types[0].majortype != pmt->majortype )
{
msg_Dbg( p_input, "CapturePin::Disconnect [OK]" );
-#if 0 // FIXME: This does seem to create crashes sometimes
- VLCMediaSample vlc_sample;
-
- vlc_mutex_lock( &p_sys->lock );
- while( samples_queue.size() )
- {
- vlc_sample = samples_queue.back();
- samples_queue.pop_back();
- vlc_sample.p_sample->Release();
- }
- vlc_mutex_unlock( &p_sys->lock );
-#endif
+ /* samples_queue was already flushed in EndFlush() */
p_connected_pin->Release();
p_connected_pin = NULL;
int i_fourcc = GetFourCCFromMediaType(*pmt);
if( !i_fourcc )
- {
+ {
msg_Dbg( p_input, "CapturePin::QueryAccept "
"[media type not supported]" );
return S_FALSE;
}
msg_Dbg( p_input, "CapturePin::QueryAccept [OK] "
- "(width=%ld, height=%ld, chroma=%4.4s)",
+ "(width=%ld, height=%ld, chroma=%4.4s, fps=%f)",
((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biWidth,
((VIDEOINFOHEADER *)pmt->pbFormat)->bmiHeader.biHeight,
- (char *)&i_fourcc );
+ (char *)&i_fourcc,
+ 10000000.0f/((float)((VIDEOINFOHEADER *)pmt->pbFormat)->AvgTimePerFrame) );
}
else if( pmt->majortype == MEDIATYPE_Audio )
{
((WAVEFORMATEX *)pmt->pbFormat)->nSamplesPerSec,
((WAVEFORMATEX *)pmt->pbFormat)->wBitsPerSample,
(char *)&i_fourcc );
- }
+ }
else
{
msg_Dbg( p_input, "CapturePin::QueryAccept [OK] (stream format=%4.4s)",
#ifdef DEBUG_DSHOW
msg_Dbg( p_input, "CapturePin::EndFlush" );
#endif
+
+ VLCMediaSample vlc_sample;
+
+ vlc_mutex_lock( &p_sys->lock );
+ while( samples_queue.size() )
+ {
+ vlc_sample = samples_queue.back();
+ samples_queue.pop_back();
+ vlc_sample.p_sample->Release();
+ }
+ vlc_mutex_unlock( &p_sys->lock );
+
return S_OK;
}
STDMETHODIMP CapturePin::NewSegment( REFERENCE_TIME tStart,
AM_MEDIA_TYPE *mt, size_t mt_count )
: p_input( _p_input ),
p_pin( new CapturePin( _p_input, p_sys, this, mt, mt_count ) ),
- state( State_Stopped ), i_ref( 1 )
+ state( State_Stopped ), i_ref( 1 )
{
}
msg_Dbg( p_input, "CaptureFilter::Stop" );
#endif
+ p_pin->EndFlush();
+
state = State_Stopped;
return S_OK;
};
/* Are we creating a new enumerator */
if( pEnumMediaTypes == NULL )
{
- CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
+ CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
i_position = 0;
}
else
{
- CopyMediaType(&cx_media_type, &pEnumMediaTypes->cx_media_type);
+ CopyMediaType(&cx_media_type, &pEnumMediaTypes->cx_media_type);
i_position = pEnumMediaTypes->i_position;
}
}
ULONG offset = 0;
ULONG max = p_pin->media_type_count;
- if( ! ppMediaTypes )
+ if( ! ppMediaTypes )
return E_POINTER;
if( (! pcFetched) && (cMediaTypes > 1) )
(AM_MEDIA_TYPE *)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
if( CopyMediaType(ppMediaTypes[copied], &cx_media_type) != S_OK )
return E_OUTOFMEMORY;
- ++i_position;
+ ++i_position;
++copied;
}
}
return E_OUTOFMEMORY;
++copied;
- ++i_position;
+ ++i_position;
}
if( pcFetched ) *pcFetched = copied;
#endif
FreeMediaType(cx_media_type);
- CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
+ CopyMediaType(&cx_media_type, &p_pin->cx_media_type);
i_position = 0;
return S_OK;
};