Skip to content

Commit

Permalink
added some property setting and getting
Browse files Browse the repository at this point in the history
(cherry picked from commit 75fcedf)
  • Loading branch information
ilya-lavrenov authored and asmorkalov committed Oct 26, 2015
1 parent 9a3e53e commit 56654ae
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions modules/highgui/src/cap_gstreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class CvCapture_GStreamer : public CvCapture
gpointer data);
GstElement* pipeline;
GstElement* uridecodebin;
GstElement* v4l2src;
GstElement* color;
GstElement* sink;
#if GST_VERSION_MAJOR > 0
Expand All @@ -168,6 +169,7 @@ void CvCapture_GStreamer::init()
{
pipeline = NULL;
uridecodebin = NULL;
v4l2src = NULL;
color = NULL;
sink = NULL;
#if GST_VERSION_MAJOR > 0
Expand Down Expand Up @@ -707,14 +709,18 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
if (strstr(name, "opencvsink") != NULL || strstr(name, "appsink") != NULL)
{
sink = GST_ELEMENT ( gst_object_ref (element) );
done = sink && color;
}
else if (strstr(name, COLOR_ELEM_NAME) != NULL)
{
color = GST_ELEMENT ( gst_object_ref (element) );
done = sink && color;
}
else if (strstr(name, "v4l") != NULL)
{
v4l2src = GST_ELEMENT ( gst_object_ref (element) );
}
g_free(name);

done = sink && color && v4l2src;
}
#if GST_VERSION_MAJOR > 0
g_value_unset (&value);
Expand Down Expand Up @@ -884,7 +890,7 @@ double CvCapture_GStreamer::getProperty( int propId )

if(!pipeline) {
CV_WARN("GStreamer: no pipeline");
return false;
return 0;
}

switch(propId) {
Expand All @@ -893,23 +899,23 @@ double CvCapture_GStreamer::getProperty( int propId )
status = gst_element_query_position(sink, FORMAT, &value);
if(!status) {
CV_WARN("GStreamer: unable to query position of stream");
return false;
return 0;
}
return value * 1e-6; // nano seconds to milli seconds
case CV_CAP_PROP_POS_FRAMES:
format = GST_FORMAT_DEFAULT;
status = gst_element_query_position(sink, FORMAT, &value);
if(!status) {
CV_WARN("GStreamer: unable to query position of stream");
return false;
return 0;
}
return value;
case CV_CAP_PROP_POS_AVI_RATIO:
format = GST_FORMAT_PERCENT;
status = gst_element_query_position(sink, FORMAT, &value);
if(!status) {
CV_WARN("GStreamer: unable to query position of stream");
return false;
return 0;
}
return ((double) value) / GST_FORMAT_PERCENT_MAX;
case CV_CAP_PROP_FRAME_WIDTH:
Expand All @@ -928,6 +934,21 @@ double CvCapture_GStreamer::getProperty( int propId )
case CV_CAP_PROP_CONTRAST:
case CV_CAP_PROP_SATURATION:
case CV_CAP_PROP_HUE:
if (v4l2src)
{
const gchar * propName =
propId == CV_CAP_PROP_BRIGHTNESS ? "brightness" :
propId == CV_CAP_PROP_CONTRAST ? "contrast" :
propId == CV_CAP_PROP_SATURATION ? "saturation" :
propId == CV_CAP_PROP_HUE ? "hue" : NULL;

if (propName)
{
gint32 value32 = 0;
g_object_get(G_OBJECT(v4l2src), propName, &value32, NULL);
return value32;
}
}
case CV_CAP_PROP_GAIN:
case CV_CAP_PROP_CONVERT_RGB:
break;
Expand All @@ -944,7 +965,7 @@ double CvCapture_GStreamer::getProperty( int propId )

#undef FORMAT

return false;
return 0;
}

/*!
Expand Down Expand Up @@ -1023,6 +1044,21 @@ bool CvCapture_GStreamer::setProperty( int propId, double value )
case CV_CAP_PROP_CONTRAST:
case CV_CAP_PROP_SATURATION:
case CV_CAP_PROP_HUE:
if (v4l2src)
{
const gchar * propName =
propId == CV_CAP_PROP_BRIGHTNESS ? "brightness" :
propId == CV_CAP_PROP_CONTRAST ? "contrast" :
propId == CV_CAP_PROP_SATURATION ? "saturation" :
propId == CV_CAP_PROP_HUE ? "hue" : NULL;

if (propName)
{
gint32 value32 = cv::saturate_cast<gint32>(value);
g_object_set(G_OBJECT(v4l2src), propName, &value32, NULL);
return true;
}
}
case CV_CAP_PROP_GAIN:
case CV_CAP_PROP_CONVERT_RGB:
break;
Expand Down

0 comments on commit 56654ae

Please sign in to comment.