dshowvideosrc: converts code to C++

This commit is contained in:
Julien Isorce 2009-07-22 11:01:49 +02:00
parent 5e6edd7e7b
commit 779ac0d98e
2 changed files with 73 additions and 90 deletions

View file

@ -181,12 +181,14 @@ gst_dshowvideosrc_class_init (GstDshowVideoSrcClass * klass)
g_object_class_install_property g_object_class_install_property
(gobject_class, PROP_DEVICE, (gobject_class, PROP_DEVICE,
g_param_spec_string ("device", "Device", g_param_spec_string ("device", "Device",
"Directshow device path (@..classID/name)", NULL, G_PARAM_READWRITE)); "Directshow device path (@..classID/name)", NULL,
static_cast<GParamFlags>(G_PARAM_READWRITE)));
g_object_class_install_property g_object_class_install_property
(gobject_class, PROP_DEVICE_NAME, (gobject_class, PROP_DEVICE_NAME,
g_param_spec_string ("device-name", "Device name", g_param_spec_string ("device-name", "Device name",
"Human-readable name of the sound device", NULL, G_PARAM_READWRITE)); "Human-readable name of the sound device", NULL,
static_cast<GParamFlags>(G_PARAM_READWRITE)));
GST_DEBUG_CATEGORY_INIT (dshowvideosrc_debug, "dshowvideosrc", 0, GST_DEBUG_CATEGORY_INIT (dshowvideosrc_debug, "dshowvideosrc", 0,
"Directshow video source"); "Directshow video source");
@ -243,7 +245,7 @@ gst_dshowvideosrc_dispose (GObject * gobject)
/* clean dshow */ /* clean dshow */
if (src->video_cap_filter) { if (src->video_cap_filter) {
IBaseFilter_Release (src->video_cap_filter); src->video_cap_filter->Release();
src->video_cap_filter = NULL; src->video_cap_filter = NULL;
} }
@ -327,8 +329,8 @@ gst_dshowvideosrc_get_device_name_values (GstDshowVideoSrc * src)
g_value_init (&value, G_TYPE_STRING); g_value_init (&value, G_TYPE_STRING);
hres = CoCreateInstance (&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, hres = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
&IID_ICreateDevEnum, (void **) &devices_enum); IID_ICreateDevEnum, (LPVOID *) &devices_enum);
if (hres != S_OK) { if (hres != S_OK) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't create an instance of the system device enumerator (error=%d)", "Can't create an instance of the system device enumerator (error=%d)",
@ -337,9 +339,8 @@ gst_dshowvideosrc_get_device_name_values (GstDshowVideoSrc * src)
goto clean; goto clean;
} }
hres = hres = devices_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
ICreateDevEnum_CreateClassEnumerator (devices_enum, &moniker_enum, 0);
&CLSID_VideoInputDeviceCategory, &moniker_enum, 0);
if (hres != S_OK || !moniker_enum) { if (hres != S_OK || !moniker_enum) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't get enumeration of video devices (error=%d)", hres); "Can't get enumeration of video devices (error=%d)", hres);
@ -347,22 +348,20 @@ gst_dshowvideosrc_get_device_name_values (GstDshowVideoSrc * src)
goto clean; goto clean;
} }
IEnumMoniker_Reset (moniker_enum); moniker_enum->Reset();
while (hres = IEnumMoniker_Next (moniker_enum, 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 =
IMoniker_BindToStorage (moniker, NULL, NULL, &IID_IPropertyBag, moniker->BindToStorage(NULL, NULL, IID_IPropertyBag,
(void **) &property_bag); (LPVOID *) &property_bag);
if (SUCCEEDED (hres) && property_bag) { if (SUCCEEDED (hres) && property_bag) {
VARIANT varFriendlyName; VARIANT varFriendlyName;
VariantInit (&varFriendlyName); VariantInit (&varFriendlyName);
hres = hres = property_bag->Read(L"FriendlyName", &varFriendlyName, NULL);
IPropertyBag_Read (property_bag, L"FriendlyName", &varFriendlyName,
NULL);
if (hres == S_OK && varFriendlyName.bstrVal) { if (hres == S_OK && varFriendlyName.bstrVal) {
gchar *friendly_name = gchar *friendly_name =
g_utf16_to_utf8 ((const gunichar2 *) varFriendlyName.bstrVal, g_utf16_to_utf8 ((const gunichar2 *) varFriendlyName.bstrVal,
@ -374,19 +373,17 @@ gst_dshowvideosrc_get_device_name_values (GstDshowVideoSrc * src)
g_free (friendly_name); g_free (friendly_name);
SysFreeString (varFriendlyName.bstrVal); SysFreeString (varFriendlyName.bstrVal);
} }
IPropertyBag_Release (property_bag); property_bag->Release();
} }
IMoniker_Release (moniker); moniker->Release();
} }
clean: clean:
if (moniker_enum) { if (moniker_enum)
IEnumMoniker_Release (moniker_enum); moniker_enum->Release();
}
if (devices_enum) { if (devices_enum)
ICreateDevEnum_Release (devices_enum); devices_enum->Release();
}
return array; return array;
} }
@ -480,14 +477,13 @@ 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, unidevice, &dwEaten, &videom); hres = MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &videom);
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
hres = hres = videom->BindToObject(lpbc, NULL, IID_IBaseFilter,
IMoniker_BindToObject (videom, lpbc, NULL, &IID_IBaseFilter, (LPVOID *) &src->video_cap_filter);
&src->video_cap_filter); videom->Release();
IMoniker_Release (videom);
} }
IBindCtx_Release (lpbc); lpbc->Release();
} }
} }
@ -501,21 +497,18 @@ gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc)
IEnumPins *enumpins = NULL; IEnumPins *enumpins = NULL;
HRESULT hres; HRESULT hres;
hres = IBaseFilter_EnumPins (src->video_cap_filter, &enumpins); hres = src->video_cap_filter->EnumPins(&enumpins);
if (SUCCEEDED (hres)) { if (SUCCEEDED (hres)) {
while (IEnumPins_Next (enumpins, 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 =
IPin_QueryInterface (capture_pin, &IID_IKsPropertySet,
(void **) &pKs);
if (SUCCEEDED (hres) && pKs) { if (SUCCEEDED (hres) && pKs) {
DWORD cbReturned; DWORD cbReturned;
GUID pin_category; GUID pin_category;
RPC_STATUS rpcstatus; RPC_STATUS rpcstatus;
hres = hres =
IKsPropertySet_Get (pKs, &AMPROPSETID_Pin, pKs->Get(AMPROPSETID_Pin,
AMPROPERTY_PIN_CATEGORY, NULL, 0, &pin_category, sizeof (GUID), AMPROPERTY_PIN_CATEGORY, NULL, 0, &pin_category, sizeof (GUID),
&cbReturned); &cbReturned);
@ -524,8 +517,8 @@ gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc)
&rpcstatus) == 0) { &rpcstatus) == 0) {
IAMStreamConfig *streamcaps = NULL; IAMStreamConfig *streamcaps = NULL;
if (SUCCEEDED (IPin_QueryInterface (capture_pin, if (SUCCEEDED (capture_pin->QueryInterface(
&IID_IAMStreamConfig, (void **) &streamcaps))) { IID_IAMStreamConfig, (LPVOID *) &streamcaps))) {
GstCaps *caps = GstCaps *caps =
gst_dshowvideosrc_getcaps_from_streamcaps (src, capture_pin, gst_dshowvideosrc_getcaps_from_streamcaps (src, capture_pin,
streamcaps); streamcaps);
@ -533,16 +526,16 @@ gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc)
if (caps) { if (caps) {
gst_caps_append (src->caps, caps); gst_caps_append (src->caps, caps);
} }
IAMStreamConfig_Release (streamcaps); streamcaps->Release();
} }
} }
IKsPropertySet_Release (pKs); pKs->Release();
} }
IPin_Release (capture_pin); capture_pin->Release();
} }
IEnumPins_Release (enumpins); enumpins->Release();
} }
} }
@ -573,7 +566,7 @@ gst_dshowvideosrc_change_state (GstElement * element, GstStateChange transition)
break; break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING: case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
if (src->media_filter) if (src->media_filter)
hres = IMediaFilter_Run (src->media_filter, 0); hres = src->media_filter->Run(0);
if (hres != S_OK) { if (hres != S_OK) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't RUN the directshow capture graph (error=%d)", hres); "Can't RUN the directshow capture graph (error=%d)", hres);
@ -582,7 +575,7 @@ gst_dshowvideosrc_change_state (GstElement * element, GstStateChange transition)
break; break;
case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
if (src->media_filter) if (src->media_filter)
hres = IMediaFilter_Stop (src->media_filter); hres = src->media_filter->Stop();
if (hres != S_OK) { if (hres != S_OK) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't STOP the directshow capture graph (error=%d)", hres); "Can't STOP the directshow capture graph (error=%d)", hres);
@ -604,16 +597,16 @@ gst_dshowvideosrc_start (GstBaseSrc * bsrc)
HRESULT hres = S_FALSE; HRESULT hres = S_FALSE;
GstDshowVideoSrc *src = GST_DSHOWVIDEOSRC (bsrc); GstDshowVideoSrc *src = GST_DSHOWVIDEOSRC (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_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't create an instance of the dshow graph manager (error=%d)", hres); "Can't create an instance of the dshow graph manager (error=%d)", hres);
goto error; goto error;
} }
hres = IFilterGraph_QueryInterface (src->filter_graph, &IID_IMediaFilter, hres = src->filter_graph->QueryInterface(IID_IMediaFilter,
(void **) &src->media_filter); (LPVOID *) &src->media_filter);
if (hres != S_OK || !src->media_filter) { if (hres != S_OK || !src->media_filter) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't get IMediacontrol interface from the graph manager (error=%d)", "Can't get IMediacontrol interface from the graph manager (error=%d)",
@ -621,8 +614,8 @@ gst_dshowvideosrc_start (GstBaseSrc * bsrc)
goto error; goto error;
} }
hres = CoCreateInstance (&CLSID_DshowFakeSink, NULL, CLSCTX_INPROC, hres = CoCreateInstance (CLSID_DshowFakeSink, NULL, CLSCTX_INPROC,
&IID_IBaseFilter, (LPVOID *) & src->dshow_fakesink); IID_IBaseFilter, (LPVOID *) & src->dshow_fakesink);
if (hres != S_OK || !src->dshow_fakesink) { if (hres != S_OK || !src->dshow_fakesink) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't create an instance of our dshow fakesink filter (error=0x%x)", "Can't create an instance of our dshow fakesink filter (error=0x%x)",
@ -630,17 +623,14 @@ gst_dshowvideosrc_start (GstBaseSrc * bsrc)
goto error; goto error;
} }
hres = hres = src->filter_graph->AddFilter(src->video_cap_filter, L"capture");
IFilterGraph_AddFilter (src->filter_graph, src->video_cap_filter,
L"capture");
if (hres != S_OK) { if (hres != S_OK) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't add video capture filter to the graph (error=%d)", hres); "Can't add video capture filter to the graph (error=%d)", hres);
goto error; goto error;
} }
hres = hres = src->filter_graph->AddFilter(src->dshow_fakesink, L"sink");
IFilterGraph_AddFilter (src->filter_graph, src->dshow_fakesink, L"sink");
if (hres != S_OK) { if (hres != S_OK) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
"Can't add our fakesink filter to the graph (error=%d)", hres); "Can't add our fakesink filter to the graph (error=%d)", hres);
@ -651,16 +641,16 @@ gst_dshowvideosrc_start (GstBaseSrc * bsrc)
error: error:
if (src->dshow_fakesink) { if (src->dshow_fakesink) {
IBaseFilter_Release (src->dshow_fakesink); src->dshow_fakesink->Release();
src->dshow_fakesink = NULL; src->dshow_fakesink = NULL;
} }
if (src->media_filter) { if (src->media_filter) {
IMediaFilter_Release (src->media_filter); src->media_filter->Release();
src->media_filter = NULL; src->media_filter = NULL;
} }
if (src->filter_graph) { if (src->filter_graph) {
IFilterGraph_Release (src->filter_graph); src->filter_graph->Release();
src->filter_graph = NULL; src->filter_graph = NULL;
} }
@ -699,9 +689,8 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
if (type) { if (type) {
pin_mediatype = (GstCapturePinMediaType *) type->data; pin_mediatype = (GstCapturePinMediaType *) type->data;
hres = hres = src->dshow_fakesink->QueryInterface(
IBaseFilter_QueryInterface (src->dshow_fakesink, IID_IGstDshowInterface, (LPVOID *) &srcinterface);
&IID_IGstDshowInterface, (void **) &srcinterface);
if (hres != S_OK || !srcinterface) { if (hres != S_OK || !srcinterface) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
@ -710,14 +699,12 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
goto error; goto error;
} }
IGstDshowInterface_gst_set_media_type (srcinterface, srcinterface->gst_set_media_type(pin_mediatype->mediatype);
pin_mediatype->mediatype); srcinterface->gst_set_buffer_callback(
IGstDshowInterface_gst_set_buffer_callback (srcinterface, (push_buffer_func) gst_dshowvideosrc_push_buffer, (byte *) src);
(byte *) gst_dshowvideosrc_push_buffer, (byte *) src);
if (srcinterface) { if (srcinterface)
IGstDshowInterface_Release (srcinterface); srcinterface->Release();
}
gst_dshow_get_pin_from_filter (src->dshow_fakesink, PINDIR_INPUT, gst_dshow_get_pin_from_filter (src->dshow_fakesink, PINDIR_INPUT,
&input_pin); &input_pin);
@ -727,10 +714,9 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
goto error; goto error;
} }
hres = hres = src->filter_graph->ConnectDirect(pin_mediatype->capture_pin,
IFilterGraph_ConnectDirect (src->filter_graph, input_pin, NULL);
pin_mediatype->capture_pin, input_pin, NULL); input_pin->Release();
IPin_Release (input_pin);
if (hres != S_OK) { if (hres != S_OK) {
GST_CAT_ERROR (dshowvideosrc_debug, GST_CAT_ERROR (dshowvideosrc_debug,
@ -760,9 +746,8 @@ gst_dshowvideosrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
return TRUE; return TRUE;
error: error:
if (srcinterface) { if (srcinterface)
IGstDshowInterface_Release (srcinterface); srcinterface->Release();
}
return FALSE; return FALSE;
} }
@ -781,30 +766,30 @@ gst_dshowvideosrc_stop (GstBaseSrc * bsrc)
gst_dshow_get_pin_from_filter (src->video_cap_filter, PINDIR_OUTPUT, gst_dshow_get_pin_from_filter (src->video_cap_filter, PINDIR_OUTPUT,
&output_pin); &output_pin);
if (output_pin) { if (output_pin) {
hres = IFilterGraph_Disconnect (src->filter_graph, output_pin); hres = src->filter_graph->Disconnect(output_pin);
IPin_Release (output_pin); output_pin->Release();
} }
gst_dshow_get_pin_from_filter (src->dshow_fakesink, PINDIR_INPUT, &input_pin); gst_dshow_get_pin_from_filter (src->dshow_fakesink, PINDIR_INPUT, &input_pin);
if (input_pin) { if (input_pin) {
hres = IFilterGraph_Disconnect (src->filter_graph, input_pin); hres = src->filter_graph->Disconnect(input_pin);
IPin_Release (input_pin); input_pin->Release();
} }
/*remove filters from the graph */ /*remove filters from the graph */
IFilterGraph_RemoveFilter (src->filter_graph, src->video_cap_filter); src->filter_graph->RemoveFilter(src->video_cap_filter);
IFilterGraph_RemoveFilter (src->filter_graph, src->dshow_fakesink); src->filter_graph->RemoveFilter(src->dshow_fakesink);
/*release our gstreamer dshow sink */ /*release our gstreamer dshow sink */
IBaseFilter_Release (src->dshow_fakesink); src->dshow_fakesink->Release();
src->dshow_fakesink = NULL; src->dshow_fakesink = NULL;
/*release media filter interface */ /*release media filter interface */
IMediaFilter_Release (src->media_filter); src->media_filter->Release();
src->media_filter = NULL; src->media_filter = NULL;
/*release the filter graph manager */ /*release the filter graph manager */
IFilterGraph_Release (src->filter_graph); src->filter_graph->Release();
src->filter_graph = NULL; src->filter_graph = NULL;
return TRUE; return TRUE;
@ -876,7 +861,7 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin,
if (!streamcaps) if (!streamcaps)
return NULL; return NULL;
IAMStreamConfig_GetNumberOfCapabilities (streamcaps, &icount, &isize); streamcaps->GetNumberOfCapabilities(&icount, &isize);
if (isize != sizeof (vscc)) if (isize != sizeof (vscc))
return NULL; return NULL;
@ -884,12 +869,10 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin,
for (; i < icount; i++) { for (; i < icount; i++) {
GstCapturePinMediaType *pin_mediatype = g_new0 (GstCapturePinMediaType, 1); GstCapturePinMediaType *pin_mediatype = g_new0 (GstCapturePinMediaType, 1);
IPin_AddRef (pin); pin->AddRef();
pin_mediatype->capture_pin = pin; pin_mediatype->capture_pin = pin;
hres = hres = streamcaps->GetStreamCaps(i, &pin_mediatype->mediatype, (BYTE *) & vscc);
IAMStreamConfig_GetStreamCaps (streamcaps, i, &pin_mediatype->mediatype,
(BYTE *) & vscc);
if (hres == S_OK && pin_mediatype->mediatype) { if (hres == S_OK && pin_mediatype->mediatype) {
VIDEOINFOHEADER *video_info; VIDEOINFOHEADER *video_info;
GstCaps *mediacaps = NULL; GstCaps *mediacaps = NULL;

View file

@ -236,7 +236,7 @@
> >
</File> </File>
<File <File
RelativePath="..\..\sys\dshowsrcwrapper\gstdshowvideosrc.c" RelativePath="..\..\sys\dshowsrcwrapper\gstdshowvideosrc.cpp"
> >
</File> </File>
<File <File