dshowsrcwrapper: indent

This commit is contained in:
Julien Isorce 2009-09-07 10:59:53 +02:00
parent 9844d73b37
commit 0518509f0a
8 changed files with 367 additions and 296 deletions

View file

@ -62,7 +62,8 @@ gst_dshow_new_pin_mediatype (IPin *pin, gint id, IAMStreamConfig * streamcaps)
{ {
GstCapturePinMediaType *pin_mediatype = g_new0 (GstCapturePinMediaType, 1); GstCapturePinMediaType *pin_mediatype = g_new0 (GstCapturePinMediaType, 1);
HRESULT hres = streamcaps->GetStreamCaps(id, &pin_mediatype->mediatype, (BYTE *) & pin_mediatype->vscc); HRESULT hres = streamcaps->GetStreamCaps (id, &pin_mediatype->mediatype,
(BYTE *) & pin_mediatype->vscc);
if (FAILED (hres) || !pin_mediatype->mediatype) { if (FAILED (hres) || !pin_mediatype->mediatype) {
gst_dshow_free_pin_mediatype (pin_mediatype); gst_dshow_free_pin_mediatype (pin_mediatype);
return NULL; return NULL;
@ -102,7 +103,8 @@ gst_dshow_check_mediatype (AM_MEDIA_TYPE *media_type, const GUID sub_type,
} }
gboolean gboolean
gst_dshow_get_pin_from_filter (IBaseFilter *filter, PIN_DIRECTION pindir, IPin **pin) gst_dshow_get_pin_from_filter (IBaseFilter * filter, PIN_DIRECTION pindir,
IPin ** pin)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
IEnumPins *enumpins = NULL; IEnumPins *enumpins = NULL;
@ -115,8 +117,7 @@ gst_dshow_get_pin_from_filter (IBaseFilter *filter, PIN_DIRECTION pindir, IPin *
return ret; return ret;
} }
while (enumpins->Next (1, &pintmp, NULL) == S_OK) while (enumpins->Next (1, &pintmp, NULL) == S_OK) {
{
PIN_DIRECTION pindirtmp; PIN_DIRECTION pindirtmp;
hres = pintmp->QueryDirection (&pindirtmp); hres = pintmp->QueryDirection (&pindirtmp);
if (hres == S_OK && pindir == pindirtmp) { if (hres == S_OK && pindir == pindirtmp) {
@ -131,7 +132,8 @@ gst_dshow_get_pin_from_filter (IBaseFilter *filter, PIN_DIRECTION pindir, IPin *
return ret; return ret;
} }
gboolean gst_dshow_find_filter(CLSID input_majortype, CLSID input_subtype, gboolean
gst_dshow_find_filter (CLSID input_majortype, CLSID input_subtype,
CLSID output_majortype, CLSID output_subtype, CLSID output_majortype, CLSID output_subtype,
gchar * prefered_filter_name, IBaseFilter ** filter) gchar * prefered_filter_name, IBaseFilter ** filter)
{ {
@ -166,9 +168,10 @@ gboolean gst_dshow_find_filter(CLSID input_majortype, CLSID input_subtype,
memcpy (&arrayOutTypes[0], &output_majortype, sizeof (CLSID)); memcpy (&arrayOutTypes[0], &output_majortype, sizeof (CLSID));
memcpy (&arrayOutTypes[1], &output_subtype, sizeof (CLSID)); memcpy (&arrayOutTypes[1], &output_subtype, sizeof (CLSID));
hres = mapper->EnumMatchingFilters (&enum_moniker, 0, FALSE, MERIT_DO_NOT_USE+1, hres =
TRUE, 1, arrayInTypes, NULL, NULL, FALSE, mapper->EnumMatchingFilters (&enum_moniker, 0, FALSE,
TRUE, 1, arrayOutTypes, NULL, NULL); MERIT_DO_NOT_USE + 1, TRUE, 1, arrayInTypes, NULL, NULL, FALSE, TRUE, 1,
arrayOutTypes, NULL, NULL);
if (FAILED (hres)) if (FAILED (hres))
goto clean; goto clean;
@ -180,14 +183,17 @@ gboolean gst_dshow_find_filter(CLSID input_majortype, CLSID input_subtype,
IPropertyBag *property_bag = NULL; IPropertyBag *property_bag = NULL;
gchar *friendly_name = NULL; gchar *friendly_name = NULL;
hres = moniker->BindToStorage (NULL, NULL, IID_IPropertyBag, (void **)&property_bag); hres =
moniker->BindToStorage (NULL, NULL, IID_IPropertyBag,
(void **) &property_bag);
if (SUCCEEDED (hres) && property_bag) { if (SUCCEEDED (hres) && property_bag) {
VARIANT varFriendlyName; VARIANT varFriendlyName;
VariantInit (&varFriendlyName); VariantInit (&varFriendlyName);
hres = property_bag->Read (L"FriendlyName", &varFriendlyName, NULL); hres = property_bag->Read (L"FriendlyName", &varFriendlyName, NULL);
if (hres == S_OK && varFriendlyName.bstrVal) { if (hres == S_OK && varFriendlyName.bstrVal) {
friendly_name = g_utf16_to_utf8((const gunichar2*)varFriendlyName.bstrVal, friendly_name =
g_utf16_to_utf8 ((const gunichar2 *) varFriendlyName.bstrVal,
wcslen (varFriendlyName.bstrVal), NULL, NULL, NULL); wcslen (varFriendlyName.bstrVal), NULL, NULL, NULL);
if (friendly_name) if (friendly_name)
_strupr (friendly_name); _strupr (friendly_name);
@ -196,7 +202,9 @@ gboolean gst_dshow_find_filter(CLSID input_majortype, CLSID input_subtype,
property_bag->Release (); property_bag->Release ();
} }
hres = moniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&filter_temp); hres =
moniker->BindToObject (NULL, NULL, IID_IBaseFilter,
(void **) &filter_temp);
if (SUCCEEDED (hres) && filter_temp) { if (SUCCEEDED (hres) && filter_temp) {
ret = TRUE; ret = TRUE;
if (filter) { if (filter) {
@ -238,7 +246,8 @@ clean:
gchar * gchar *
gst_dshow_getdevice_from_devicename (const GUID *device_category, gchar **device_name) gst_dshow_getdevice_from_devicename (const GUID * device_category,
gchar ** device_name)
{ {
gchar *ret = NULL; gchar *ret = NULL;
ICreateDevEnum *devices_enum = NULL; ICreateDevEnum *devices_enum = NULL;
@ -267,14 +276,17 @@ gst_dshow_getdevice_from_devicename (const GUID *device_category, gchar **devic
while (hres = enum_moniker->Next (1, &moniker, &fetched), hres == S_OK while (hres = enum_moniker->Next (1, &moniker, &fetched), hres == S_OK
&& !bfound) { && !bfound) {
IPropertyBag *property_bag = NULL; IPropertyBag *property_bag = NULL;
hres = moniker->BindToStorage(NULL, NULL, IID_IPropertyBag, (void **)&property_bag); hres =
moniker->BindToStorage (NULL, NULL, IID_IPropertyBag,
(void **) &property_bag);
if (SUCCEEDED (hres) && property_bag) { if (SUCCEEDED (hres) && property_bag) {
VARIANT varFriendlyName; VARIANT varFriendlyName;
VariantInit (&varFriendlyName); VariantInit (&varFriendlyName);
hres = property_bag->Read (L"FriendlyName", &varFriendlyName, NULL); hres = property_bag->Read (L"FriendlyName", &varFriendlyName, NULL);
if (hres == S_OK && varFriendlyName.bstrVal) { if (hres == S_OK && varFriendlyName.bstrVal) {
gchar * friendly_name = g_utf16_to_utf8((const gunichar2*)varFriendlyName.bstrVal, gchar *friendly_name =
g_utf16_to_utf8 ((const gunichar2 *) varFriendlyName.bstrVal,
wcslen (varFriendlyName.bstrVal), NULL, NULL, NULL); wcslen (varFriendlyName.bstrVal), NULL, NULL, NULL);
if (!*device_name) { if (!*device_name) {
@ -315,9 +327,9 @@ gst_dshow_show_propertypage (IBaseFilter *base_filter)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
ISpecifyPropertyPages *pProp = NULL; ISpecifyPropertyPages *pProp = NULL;
HRESULT hres = base_filter->QueryInterface (IID_ISpecifyPropertyPages, (void **)&pProp); HRESULT hres =
if (SUCCEEDED(hres)) base_filter->QueryInterface (IID_ISpecifyPropertyPages, (void **) &pProp);
{ if (SUCCEEDED (hres)) {
/* Get the filter's name and IUnknown pointer. */ /* Get the filter's name and IUnknown pointer. */
FILTER_INFO FilterInfo; FILTER_INFO FilterInfo;
CAUUID caGUID; CAUUID caGUID;
@ -338,12 +350,14 @@ gst_dshow_show_propertypage (IBaseFilter *base_filter)
return ret; return ret;
} }
GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar* name, GstCaps *
gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar * name,
GstCapturePinMediaType * pin_mediatype) GstCapturePinMediaType * pin_mediatype)
{ {
GstCaps *video_caps = NULL; GstCaps *video_caps = NULL;
GstStructure *video_structure = NULL; GstStructure *video_structure = NULL;
VIDEOINFOHEADER *video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat; VIDEOINFOHEADER *video_info =
(VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat;
pin_mediatype->defaultWidth = video_info->bmiHeader.biWidth; pin_mediatype->defaultWidth = video_info->bmiHeader.biWidth;
pin_mediatype->defaultHeight = video_info->bmiHeader.biHeight; pin_mediatype->defaultHeight = video_info->bmiHeader.biHeight;
@ -392,12 +406,13 @@ GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar* nam
/* value that the filter supports" as it said in the VIDEO_STREAM_CONFIG_CAPS dshwo doc */ /* value that the filter supports" as it said in the VIDEO_STREAM_CONFIG_CAPS dshwo doc */
gst_structure_set (video_structure, gst_structure_set (video_structure,
"width", GST_TYPE_INT_RANGE, pin_mediatype->vscc.MinOutputSize.cx, pin_mediatype->vscc.MaxOutputSize.cx, "width", GST_TYPE_INT_RANGE, pin_mediatype->vscc.MinOutputSize.cx,
"height", GST_TYPE_INT_RANGE, pin_mediatype->vscc.MinOutputSize.cy, pin_mediatype->vscc.MaxOutputSize.cy, pin_mediatype->vscc.MaxOutputSize.cx, "height", GST_TYPE_INT_RANGE,
"framerate", GST_TYPE_FRACTION_RANGE, pin_mediatype->vscc.MinOutputSize.cy,
pin_mediatype->vscc.MaxOutputSize.cy, "framerate",
GST_TYPE_FRACTION_RANGE,
(gint) (10000000 / pin_mediatype->vscc.MaxFrameInterval), 1, (gint) (10000000 / pin_mediatype->vscc.MaxFrameInterval), 1,
(gint) (10000000 / pin_mediatype->vscc.MinFrameInterval), 1, (gint) (10000000 / pin_mediatype->vscc.MinFrameInterval), 1, NULL);
NULL);
return video_caps; return video_caps;
} }

View file

@ -54,16 +54,19 @@ void gst_dshow_free_pin_mediatype (gpointer pt);
void gst_dshow_free_mediatype (AM_MEDIA_TYPE * pmt); void gst_dshow_free_mediatype (AM_MEDIA_TYPE * pmt);
/* create a new capture media type that handles dshow video caps of a capture pin */ /* create a new capture media type that handles dshow video caps of a capture pin */
GstCapturePinMediaType *gst_dshow_new_pin_mediatype (IPin *pin, gint id, IAMStreamConfig * streamcaps); GstCapturePinMediaType *gst_dshow_new_pin_mediatype (IPin * pin, gint id,
IAMStreamConfig * streamcaps);
/* free the memory of all mediatypes of the input list if pin mediatype */ /* free the memory of all mediatypes of the input list if pin mediatype */
void gst_dshow_free_pins_mediatypes (GList * mediatypes); void gst_dshow_free_pins_mediatypes (GList * mediatypes);
/* allow to know what kind of media type we have */ /* allow to know what kind of media type we have */
gboolean gst_dshow_check_mediatype (AM_MEDIA_TYPE *media_type, const GUID sub_type, const GUID format_type); gboolean gst_dshow_check_mediatype (AM_MEDIA_TYPE * media_type,
const GUID sub_type, const GUID format_type);
/* get a pin from directshow filter */ /* get a pin from directshow filter */
gboolean gst_dshow_get_pin_from_filter (IBaseFilter *filter, PIN_DIRECTION pindir, IPin **pin); gboolean gst_dshow_get_pin_from_filter (IBaseFilter * filter,
PIN_DIRECTION pindir, IPin ** pin);
/* find and return a filter according to the input and output types */ /* find and return a filter according to the input and output types */
gboolean gst_dshow_find_filter (CLSID input_majortype, CLSID input_subtype, gboolean gst_dshow_find_filter (CLSID input_majortype, CLSID input_subtype,
@ -72,13 +75,14 @@ gboolean gst_dshow_find_filter(CLSID input_majortype, CLSID input_subtype,
/* get the dshow device path from device friendly name. /* get the dshow device path from device friendly name.
If friendly name is not set, it will return the first available device */ If friendly name is not set, it will return the first available device */
gchar *gst_dshow_getdevice_from_devicename (const GUID *device_category, gchar **device_name); gchar *gst_dshow_getdevice_from_devicename (const GUID * device_category,
gchar ** device_name);
/* show the capture filter property page (generally used to setup the device). the page is modal*/ /* show the capture filter property page (generally used to setup the device). the page is modal*/
gboolean gst_dshow_show_propertypage (IBaseFilter * base_filter); gboolean gst_dshow_show_propertypage (IBaseFilter * base_filter);
/* transform a dshow video caps to a gstreamer video caps */ /* transform a dshow video caps to a gstreamer video caps */
GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar* name, GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format,
GstCapturePinMediaType *pin_mediatype); const gchar * name, GstCapturePinMediaType * pin_mediatype);
#endif /* _GSTDSHOW_ */ #endif /* _GSTDSHOW_ */

View file

@ -273,7 +273,9 @@ gst_dshowaudiosrc_get_device_name_values (GstDshowAudioSrc * src)
hres = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, hres = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (LPVOID *) & devices_enum); IID_ICreateDevEnum, (LPVOID *) & devices_enum);
if (hres != S_OK) { if (hres != S_OK) {
GST_ERROR ("Can't create an instance of the system device enumerator (error=0x%x)", hres); GST_ERROR
("Can't create an instance of the system device enumerator (error=0x%x)",
hres);
array = NULL; array = NULL;
goto clean; goto clean;
} }
@ -288,8 +290,7 @@ gst_dshowaudiosrc_get_device_name_values (GstDshowAudioSrc * src)
moniker_enum->Reset (); moniker_enum->Reset ();
while (hres = moniker_enum->Next(1, &moniker, &fetched), while (hres = moniker_enum->Next (1, &moniker, &fetched), hres == S_OK) {
hres == S_OK) {
IPropertyBag *property_bag = NULL; IPropertyBag *property_bag = NULL;
hres = moniker->BindToStorage (NULL, NULL, IID_IPropertyBag, hres = moniker->BindToStorage (NULL, NULL, IID_IPropertyBag,
@ -416,7 +417,8 @@ gst_dshowaudiosrc_get_caps (GstBaseSrc * basesrc)
if (!src->audio_cap_filter) { if (!src->audio_cap_filter) {
hres = CreateBindCtx (0, &lpbc); hres = CreateBindCtx (0, &lpbc);
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
hres = MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &audiom); hres =
MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &audiom);
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
hres = audiom->BindToObject (lpbc, NULL, IID_IBaseFilter, hres = audiom->BindToObject (lpbc, NULL, IID_IBaseFilter,
(LPVOID *) & src->audio_cap_filter); (LPVOID *) & src->audio_cap_filter);
@ -437,7 +439,8 @@ gst_dshowaudiosrc_get_caps (GstBaseSrc * basesrc)
while (enumpins->Next (1, &capture_pin, NULL) == S_OK) { while (enumpins->Next (1, &capture_pin, NULL) == S_OK) {
IKsPropertySet *pKs = NULL; IKsPropertySet *pKs = NULL;
hres = capture_pin->QueryInterface(IID_IKsPropertySet, (LPVOID *) &pKs); hres =
capture_pin->QueryInterface (IID_IKsPropertySet, (LPVOID *) & pKs);
if (SUCCEEDED (hres) && pKs) { if (SUCCEEDED (hres) && pKs) {
DWORD cbReturned; DWORD cbReturned;
GUID pin_category; GUID pin_category;
@ -453,7 +456,8 @@ gst_dshowaudiosrc_get_caps (GstBaseSrc * basesrc)
&rpcstatus) == 0) { &rpcstatus) == 0) {
IAMStreamConfig *streamcaps = NULL; IAMStreamConfig *streamcaps = NULL;
if (SUCCEEDED (capture_pin->QueryInterface(IID_IAMStreamConfig, (LPVOID *) &streamcaps))) { if (SUCCEEDED (capture_pin->QueryInterface (IID_IAMStreamConfig,
(LPVOID *) & streamcaps))) {
src->caps = src->caps =
gst_dshowaudiosrc_getcaps_from_streamcaps (src, capture_pin, gst_dshowaudiosrc_getcaps_from_streamcaps (src, capture_pin,
streamcaps); streamcaps);
@ -505,7 +509,8 @@ gst_dshowaudiosrc_change_state (GstElement * element, GstStateChange transition)
if (src->media_filter) if (src->media_filter)
hres = src->media_filter->Stop (); hres = src->media_filter->Stop ();
if (hres != S_OK) { if (hres != S_OK) {
GST_ERROR ("Can't STOP the directshow capture graph (error=0x%x)", hres); GST_ERROR ("Can't STOP the directshow capture graph (error=0x%x)",
hres);
return GST_STATE_CHANGE_FAILURE; return GST_STATE_CHANGE_FAILURE;
} }
src->is_running = FALSE; src->is_running = FALSE;
@ -531,13 +536,19 @@ gst_dshowaudiosrc_open (GstAudioSrc * asrc)
hres = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC, hres = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IFilterGraph, (LPVOID *) & src->filter_graph); IID_IFilterGraph, (LPVOID *) & src->filter_graph);
if (hres != S_OK || !src->filter_graph) { if (hres != S_OK || !src->filter_graph) {
GST_ERROR ("Can't create an instance of the directshow graph manager (error=0x%x)", hres); GST_ERROR
("Can't create an instance of the directshow graph manager (error=0x%x)",
hres);
goto error; goto error;
} }
hres = src->filter_graph->QueryInterface(IID_IMediaFilter, (LPVOID *) &src->media_filter); hres =
src->filter_graph->QueryInterface (IID_IMediaFilter,
(LPVOID *) & src->media_filter);
if (hres != S_OK || !src->media_filter) { if (hres != S_OK || !src->media_filter) {
GST_ERROR ("Can't get IMediacontrol interface from the graph manager (error=0x%x)", hres); GST_ERROR
("Can't get IMediacontrol interface from the graph manager (error=0x%x)",
hres);
goto error; goto error;
} }
@ -546,7 +557,9 @@ gst_dshowaudiosrc_open (GstAudioSrc * asrc)
hres = src->filter_graph->AddFilter (src->audio_cap_filter, L"capture"); hres = src->filter_graph->AddFilter (src->audio_cap_filter, L"capture");
if (hres != S_OK) { if (hres != S_OK) {
GST_ERROR ("Can't add the directshow capture filter to the graph (error=0x%x)", hres); GST_ERROR
("Can't add the directshow capture filter to the graph (error=0x%x)",
hres);
goto error; goto error;
} }
@ -621,7 +634,9 @@ gst_dshowaudiosrc_prepare (GstAudioSrc * asrc, GstRingBufferSpec * spec)
input_pin->Release (); input_pin->Release ();
if (hres != S_OK) { if (hres != S_OK) {
GST_ERROR ("Can't connect capture filter with fakesink filter (error=0x%x)", hres); GST_ERROR
("Can't connect capture filter with fakesink filter (error=0x%x)",
hres);
goto error; goto error;
} }
@ -779,7 +794,8 @@ gst_dshowaudiosrc_getcaps_from_streamcaps (GstDshowAudioSrc * src, IPin * pin,
if (!caps) if (!caps)
caps = gst_caps_new_empty (); caps = gst_caps_new_empty ();
if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_PCM, FORMAT_WaveFormatEx)) { if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_PCM,
FORMAT_WaveFormatEx)) {
WAVEFORMATEX *wavformat = WAVEFORMATEX *wavformat =
(WAVEFORMATEX *) pin_mediatype->mediatype->pbFormat; (WAVEFORMATEX *) pin_mediatype->mediatype->pbFormat;
mediacaps = mediacaps =

View file

@ -35,7 +35,9 @@ STDMETHODIMP CDshowFakeSink::gst_set_media_type (AM_MEDIA_TYPE *pmt)
return S_OK; return S_OK;
} }
STDMETHODIMP CDshowFakeSink::gst_set_buffer_callback (push_buffer_func push, gpointer data) STDMETHODIMP
CDshowFakeSink::gst_set_buffer_callback (push_buffer_func push,
gpointer data)
{ {
m_callback = push; m_callback = push;
m_data = data; m_data = data;
@ -54,12 +56,14 @@ HRESULT CDshowFakeSink::CheckMediaType(const CMediaType *pmt)
HRESULT CDshowFakeSink::DoRenderSample (IMediaSample * pMediaSample) HRESULT CDshowFakeSink::DoRenderSample (IMediaSample * pMediaSample)
{ {
if(pMediaSample && m_callback) if (pMediaSample && m_callback) {
{ BYTE *
BYTE *pBuffer = NULL; pBuffer = NULL;
LONGLONG lStart = 0, lStop = 0; LONGLONG
lStart = 0, lStop = 0;
pMediaSample->GetPointer (&pBuffer); pMediaSample->GetPointer (&pBuffer);
long size = pMediaSample->GetActualDataLength(); long
size = pMediaSample->GetActualDataLength ();
pMediaSample->GetTime (&lStart, &lStop); pMediaSample->GetTime (&lStart, &lStop);
lStart *= 100; lStart *= 100;
lStop *= 100; lStop *= 100;

View file

@ -26,15 +26,20 @@
//{6A780808-9725-4d0b-8695-A4DD8D210773} //{6A780808-9725-4d0b-8695-A4DD8D210773}
static const GUID CLSID_DshowFakeSink = static const GUID CLSID_DshowFakeSink =
{ 0x6a780808, 0x9725, 0x4d0b, { 0x86, 0x95, 0xa4, 0xdd, 0x8d, 0x21, 0x7, 0x73 } }; { 0x6a780808, 0x9725, 0x4d0b, {0x86, 0x95, 0xa4, 0xdd, 0x8d, 0x21, 0x7,
0x73}
};
typedef bool (*push_buffer_func) (byte *buffer, long size, gpointer src_object, UINT64 start, UINT64 stop); typedef bool (*push_buffer_func) (byte * buffer, long size, gpointer src_object,
UINT64 start, UINT64 stop);
class CDshowFakeSink:public CBaseRenderer class CDshowFakeSink:public CBaseRenderer
{ {
public: public:
CDshowFakeSink (); CDshowFakeSink ();
virtual ~CDshowFakeSink () {} virtual ~ CDshowFakeSink ()
{
}
virtual HRESULT CheckMediaType (const CMediaType * pmt); virtual HRESULT CheckMediaType (const CMediaType * pmt);
virtual HRESULT DoRenderSample (IMediaSample * pMediaSample); virtual HRESULT DoRenderSample (IMediaSample * pMediaSample);

View file

@ -45,17 +45,14 @@ const GUID MEDIASUBTYPE_I420
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ( GST_STATIC_CAPS (GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_BGR ";"
GST_VIDEO_CAPS_YUV ("{ I420 }") ";" GST_VIDEO_CAPS_YUV ("{ I420 }") ";"
"video/x-dv," "video/x-dv,"
"systemstream = (boolean) FALSE," "systemstream = (boolean) FALSE,"
"width = (int) [ 1, MAX ]," "width = (int) [ 1, MAX ],"
"height = (int) [ 1, MAX ]," "height = (int) [ 1, MAX ],"
"framerate = (fraction) [ 0, MAX ]," "framerate = (fraction) [ 0, MAX ],"
"format = (fourcc) dvsd;" "format = (fourcc) dvsd;" "video/x-dv," "systemstream = (boolean) TRUE")
"video/x-dv,"
"systemstream = (boolean) TRUE")
); );
static void gst_dshowvideosrc_init_interfaces (GType type); static void gst_dshowvideosrc_init_interfaces (GType type);
@ -238,10 +235,14 @@ gst_dshowvideosrc_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
if (res != -1) { if (res != -1) {
GList *type_pin_mediatype = g_list_nth (src->pins_mediatypes, res); GList *type_pin_mediatype = g_list_nth (src->pins_mediatypes, res);
if (type_pin_mediatype) { if (type_pin_mediatype) {
GstCapturePinMediaType *pin_mediatype = (GstCapturePinMediaType *) type_pin_mediatype->data; GstCapturePinMediaType *pin_mediatype =
gst_structure_fixate_field_nearest_int (structure, "width", pin_mediatype->defaultWidth); (GstCapturePinMediaType *) type_pin_mediatype->data;
gst_structure_fixate_field_nearest_int (structure, "height", pin_mediatype->defaultHeight); gst_structure_fixate_field_nearest_int (structure, "width",
gst_structure_fixate_field_nearest_fraction (structure, "framerate", pin_mediatype->defaultFPS, 1); pin_mediatype->defaultWidth);
gst_structure_fixate_field_nearest_int (structure, "height",
pin_mediatype->defaultHeight);
gst_structure_fixate_field_nearest_fraction (structure, "framerate",
pin_mediatype->defaultFPS, 1);
} }
} }
} }
@ -371,8 +372,7 @@ gst_dshowvideosrc_get_device_name_values (GstDshowVideoSrc * src)
moniker_enum->Reset (); moniker_enum->Reset ();
while (hres = moniker_enum->Next(1, &moniker, &fetched), while (hres = moniker_enum->Next (1, &moniker, &fetched), hres == S_OK) {
hres == S_OK) {
IPropertyBag *property_bag = NULL; IPropertyBag *property_bag = NULL;
hres = hres =
@ -500,7 +500,8 @@ gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc)
if (!src->video_cap_filter) { if (!src->video_cap_filter) {
hres = CreateBindCtx (0, &lpbc); hres = CreateBindCtx (0, &lpbc);
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
hres = MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &videom); hres =
MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &videom);
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
hres = videom->BindToObject (lpbc, NULL, IID_IBaseFilter, hres = videom->BindToObject (lpbc, NULL, IID_IBaseFilter,
(LPVOID *) & src->video_cap_filter); (LPVOID *) & src->video_cap_filter);
@ -524,7 +525,8 @@ gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc)
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
while (enumpins->Next (1, &capture_pin, NULL) == S_OK) { while (enumpins->Next (1, &capture_pin, NULL) == S_OK) {
IKsPropertySet *pKs = NULL; IKsPropertySet *pKs = NULL;
hres = capture_pin->QueryInterface(IID_IKsPropertySet, (LPVOID *) &pKs); hres =
capture_pin->QueryInterface (IID_IKsPropertySet, (LPVOID *) & pKs);
if (SUCCEEDED (hres) && pKs) { if (SUCCEEDED (hres) && pKs) {
DWORD cbReturned; DWORD cbReturned;
GUID pin_category; GUID pin_category;
@ -540,8 +542,8 @@ gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc)
&rpcstatus) == 0) { &rpcstatus) == 0) {
IAMStreamConfig *streamcaps = NULL; IAMStreamConfig *streamcaps = NULL;
if (SUCCEEDED (capture_pin->QueryInterface( if (SUCCEEDED (capture_pin->QueryInterface (IID_IAMStreamConfig,
IID_IAMStreamConfig, (LPVOID *) &streamcaps))) { (LPVOID *) & streamcaps))) {
GstCaps *caps = GstCaps *caps =
gst_dshowvideosrc_getcaps_from_streamcaps (src, capture_pin, gst_dshowvideosrc_getcaps_from_streamcaps (src, capture_pin,
streamcaps); streamcaps);
@ -618,14 +620,18 @@ gst_dshowvideosrc_start (GstBaseSrc * bsrc)
hres = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC, hres = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IFilterGraph, (LPVOID *) & src->filter_graph); IID_IFilterGraph, (LPVOID *) & src->filter_graph);
if (hres != S_OK || !src->filter_graph) { if (hres != S_OK || !src->filter_graph) {
GST_ERROR ("Can't create an instance of the dshow graph manager (error=0x%x)", hres); GST_ERROR
("Can't create an instance of the dshow graph manager (error=0x%x)",
hres);
goto error; goto error;
} }
hres = src->filter_graph->QueryInterface (IID_IMediaFilter, hres = src->filter_graph->QueryInterface (IID_IMediaFilter,
(LPVOID *) & src->media_filter); (LPVOID *) & src->media_filter);
if (hres != S_OK || !src->media_filter) { if (hres != S_OK || !src->media_filter) {
GST_ERROR ("Can't get IMediacontrol interface from the graph manager (error=0x%x)", hres); GST_ERROR
("Can't get IMediacontrol interface from the graph manager (error=0x%x)",
hres);
goto error; goto error;
} }
@ -634,7 +640,8 @@ gst_dshowvideosrc_start (GstBaseSrc * bsrc)
hres = src->filter_graph->AddFilter (src->video_cap_filter, L"capture"); hres = src->filter_graph->AddFilter (src->video_cap_filter, L"capture");
if (hres != S_OK) { if (hres != S_OK) {
GST_ERROR ("Can't add video capture filter to the graph (error=0x%x)", hres); GST_ERROR ("Can't add video capture filter to the graph (error=0x%x)",
hres);
goto error; goto error;
} }
@ -691,7 +698,8 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
GList *type_pin_mediatype = g_list_nth (src->pins_mediatypes, res); GList *type_pin_mediatype = g_list_nth (src->pins_mediatypes, res);
if (type_pin_mediatype) { if (type_pin_mediatype) {
GstCapturePinMediaType *pin_mediatype = (GstCapturePinMediaType *) type_pin_mediatype->data; GstCapturePinMediaType *pin_mediatype =
(GstCapturePinMediaType *) type_pin_mediatype->data;
gchar *caps_string = NULL; gchar *caps_string = NULL;
gchar *src_caps_string = NULL; gchar *src_caps_string = NULL;
@ -708,16 +716,21 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
/* check if the desired video size is valid about granularity */ /* check if the desired video size is valid about granularity */
/* This check will be removed when GST_TYPE_INT_RANGE_STEP exits */ /* This check will be removed when GST_TYPE_INT_RANGE_STEP exits */
/* See remarks in gst_dshowvideosrc_getcaps_from_streamcaps function */ /* See remarks in gst_dshowvideosrc_getcaps_from_streamcaps function */
if (pin_mediatype->granularityWidth != 0 && width % pin_mediatype->granularityWidth != 0) if (pin_mediatype->granularityWidth != 0
g_warning ("your desired video size is not valid : %d mod %d !=0\n", width, pin_mediatype->granularityWidth) ; && width % pin_mediatype->granularityWidth != 0)
if (pin_mediatype->granularityHeight !=0 && height % pin_mediatype->granularityHeight != 0) g_warning ("your desired video size is not valid : %d mod %d !=0\n",
g_warning ("your desired video size is not valid : %d mod %d !=0\n", height, pin_mediatype->granularityHeight) ; width, pin_mediatype->granularityWidth);
if (pin_mediatype->granularityHeight != 0
&& height % pin_mediatype->granularityHeight != 0)
g_warning ("your desired video size is not valid : %d mod %d !=0\n",
height, pin_mediatype->granularityHeight);
/* update mediatype */ /* update mediatype */
video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat; video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat;
video_info->bmiHeader.biWidth = width; video_info->bmiHeader.biWidth = width;
video_info->bmiHeader.biHeight = height; video_info->bmiHeader.biHeight = height;
video_info->AvgTimePerFrame = (LONGLONG) (10000000 * denominator / (double)numerator); video_info->AvgTimePerFrame =
(LONGLONG) (10000000 * denominator / (double) numerator);
video_info->bmiHeader.biSizeImage = DIBSIZE (video_info->bmiHeader); video_info->bmiHeader.biSizeImage = DIBSIZE (video_info->bmiHeader);
pin_mediatype->mediatype->lSampleSize = DIBSIZE (video_info->bmiHeader); pin_mediatype->mediatype->lSampleSize = DIBSIZE (video_info->bmiHeader);
@ -737,7 +750,9 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
input_pin->Release (); input_pin->Release ();
if (hres != S_OK) { if (hres != S_OK) {
GST_ERROR ("Can't connect capture filter with fakesink filter (error=0x%x)", hres); GST_ERROR
("Can't connect capture filter with fakesink filter (error=0x%x)",
hres);
goto error; goto error;
} }
@ -888,20 +903,30 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin,
GstCaps *mediacaps = NULL; GstCaps *mediacaps = NULL;
if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_I420, FORMAT_VideoInfo)) { if (gst_dshow_check_mediatype (pin_mediatype->mediatype,
mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_I420, NULL, pin_mediatype); MEDIASUBTYPE_I420, FORMAT_VideoInfo)) {
mediacaps =
} else if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_RGB24, FORMAT_VideoInfo)) { gst_dshow_new_video_caps (GST_VIDEO_FORMAT_I420, NULL,
mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_BGR, NULL, pin_mediatype);
} else if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_dvsd, FORMAT_VideoInfo)) {
mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_UNKNOWN, "video/x-dv, systemstream=FALSE",
pin_mediatype); pin_mediatype);
} else if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_dvsd, FORMAT_DvInfo)) { } else if (gst_dshow_check_mediatype (pin_mediatype->mediatype,
mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_UNKNOWN, "video/x-dv, systemstream=TRUE", MEDIASUBTYPE_RGB24, FORMAT_VideoInfo)) {
mediacaps =
gst_dshow_new_video_caps (GST_VIDEO_FORMAT_BGR, NULL,
pin_mediatype); pin_mediatype);
} else if (gst_dshow_check_mediatype (pin_mediatype->mediatype,
MEDIASUBTYPE_dvsd, FORMAT_VideoInfo)) {
mediacaps =
gst_dshow_new_video_caps (GST_VIDEO_FORMAT_UNKNOWN,
"video/x-dv, systemstream=FALSE", pin_mediatype);
} else if (gst_dshow_check_mediatype (pin_mediatype->mediatype,
MEDIASUBTYPE_dvsd, FORMAT_DvInfo)) {
mediacaps =
gst_dshow_new_video_caps (GST_VIDEO_FORMAT_UNKNOWN,
"video/x-dv, systemstream=TRUE", pin_mediatype);
pin_mediatype->granularityWidth = 0; pin_mediatype->granularityWidth = 0;
pin_mediatype->granularityHeight = 0; pin_mediatype->granularityHeight = 0;
} }
@ -964,8 +989,9 @@ gst_dshowvideosrc_push_buffer (byte * buffer, long size, gpointer src_object,
memcpy (GST_BUFFER_DATA (buf), buffer, size); memcpy (GST_BUFFER_DATA (buf), buffer, size);
} }
GST_DEBUG ("push_buffer => pts %" GST_TIME_FORMAT "duration %" GST_TIME_FORMAT, GST_DEBUG ("push_buffer => pts %" GST_TIME_FORMAT "duration %"
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (stop - start)); GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
GST_TIME_ARGS (stop - start));
/* the negotiate() method already set caps on the source pad */ /* the negotiate() method already set caps on the source pad */
gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (src))); gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (src)));

View file

@ -31,7 +31,8 @@
#include "gstdshowfakesink.h" #include "gstdshowfakesink.h"
// 30323449-0000-0010-8000-00AA00389B71 MEDIASUBTYPE_I420 // 30323449-0000-0010-8000-00AA00389B71 MEDIASUBTYPE_I420
DEFINE_GUID(MEDIASUBTYPE_I420, 0x30323449, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71); DEFINE_GUID (MEDIASUBTYPE_I420, 0x30323449, 0x0000, 0x0010, 0x80, 0x00, 0x00,
0xAA, 0x00, 0x38, 0x9B, 0x71);
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_DSHOWVIDEOSRC (gst_dshowvideosrc_get_type()) #define GST_TYPE_DSHOWVIDEOSRC (gst_dshowvideosrc_get_type())