Unset camerabin viewfinder-sink property when we unset viewfinder
authorMohammed Sameer <msameer@foolab.org>
Sun, 14 Apr 2013 01:04:22 +0000 (04:04 +0300)
committerMohammed Sameer <msameer@foolab.org>
Fri, 2 Aug 2013 22:00:22 +0000 (01:00 +0300)
lib/qtcamdevice.cpp
lib/qtcamdevice_p.h

index a8e180c..d48bba2 100644 (file)
@@ -148,13 +148,14 @@ bool QtCamDevice::setViewfinder(QtCamViewfinder *viewfinder) {
   }
 
   if (!viewfinder) {
-    qWarning() << "QtCamDevice: viewfinder cannot be unset.";
-    return false;
-  }
+    if (d_ptr->cameraBin) {
+      g_object_set(d_ptr->cameraBin, "viewfinder-sink", NULL, NULL);
+    }
 
-  if (d_ptr->viewfinder) {
-    qWarning() << "QtCamDevice: viewfinder cannot be replaced.";
-    return false;
+    d_ptr->sink = 0;
+
+    d_ptr->viewfinder = 0;
+    return true;
   }
 
   if (!viewfinder->setDevice(this)) {
@@ -162,6 +163,7 @@ bool QtCamDevice::setViewfinder(QtCamViewfinder *viewfinder) {
   }
 
   d_ptr->viewfinder = viewfinder;
+  d_ptr->sink = 0;
 
   return true;
 }
index b0cb65d..c8c09fb 100644 (file)
@@ -43,6 +43,7 @@ public:
     cameraBin(0),
     videoSource(0),
     wrapperVideoSource(0),
+    sink(0),
     image(0),
     video(0),
     active(0),
@@ -116,11 +117,7 @@ public:
   }
 
   bool setViewfinderSink() {
-    GstElement *sink = 0;
-    g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
-
     if (sink) {
-      gst_object_unref(sink);
       return true;
     }
 
@@ -225,6 +222,7 @@ public:
   GstElement *cameraBin;
   GstElement *videoSource;
   GstElement *wrapperVideoSource;
+  GstElement *sink;
 
   QtCamImageMode *image;
   QtCamVideoMode *video;