Code cleanup
authorMohammed Sameer <msameer@foolab.org>
Sun, 7 Oct 2012 21:30:23 +0000 (00:30 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sun, 7 Oct 2012 23:22:59 +0000 (02:22 +0300)
lib/qtcamdevice.cpp
lib/qtcamgstreamermessagelistener.cpp
lib/qtcamimagemode.cpp
lib/qtcammode.cpp
lib/qtcammode.h
lib/qtcammode_p.h
lib/qtcamvideomode.cpp
lib/qtcamzoom.cpp
qml/CameraPage.qml

index 793eefa..0009fff 100644 (file)
@@ -30,8 +30,6 @@
 #include "qtcamvideomode.h"
 #include "qtcamnotifications.h"
 
-// TODO: we want the ability to change the image and video gep from the app.
-
 QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name,
                         const QVariant& id, QObject *parent) :
   QObject(parent), d_ptr(new QtCamDevicePrivate) {
@@ -63,7 +61,6 @@ QtCamDevice::QtCamDevice(QtCamConfig *config, const QString& name,
   // TODO: audio bitrate
   // TODO: video bitrate
   // TODO: filters
-  // TODO: capabilities
   // TODO: custom properties for jifmux, mp4mux, audio encoder, video encoder, sink & video source
   d_ptr->listener = new QtCamGStreamerMessageListener(gst_element_get_bus(d_ptr->cameraBin),
                                                      d_ptr, this);
index 6254fd6..1168ba7 100644 (file)
@@ -119,7 +119,6 @@ public:
       break;
 
     default:
-      // TODO: other types
       break;
     }
   }
index 1a00712..8a913e5 100644 (file)
@@ -78,7 +78,7 @@ void QtCamImageMode::applySettings() {
   // we use. For now we will not set any FPS.
   d_ptr->setCaps("image-capture-caps", d->resolution.captureResolution(), -1);
 
-  setPreviewSize(d->resolution.previewResolution());
+  d_ptr->setPreviewSize(d->resolution.previewResolution());
 
   // If we don't reset the caps then: if we switch from video to image then we fail
   // the next time we restart the pipeline.
@@ -102,7 +102,7 @@ bool QtCamImageMode::capture(const QString& fileName) {
     return false;
   }
 
-  setFileName(fileName);
+  d_ptr->setFileName(fileName);
 
   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
index 3634cca..47c3978 100644 (file)
@@ -28,8 +28,6 @@
 #include <gst/video/video.h>
 #include <QImage>
 
-#define PREVIEW_CAPS "video/x-raw-rgb, width = (int) %1, height = (int) %2, bpp = (int) 32, depth = (int) 24, red_mask = (int) 65280, green_mask = (int) 16711680, blue_mask = (int) -16777216"
-
 class PreviewImageHandler : public QtCamGStreamerMessageHandler {
 public:
   PreviewImageHandler(QtCamMode *m, QObject *parent = 0) :
@@ -72,7 +70,7 @@ public:
 
     // We need to copy because GStreamer will free the buffer after we return
     // and since QImage doesn't copythe data by default we will end up with garbage.
-    // TODO: consider a QImage subclass that takes a GstBuffer reference
+    // There is no way to subclass QImage to prevent copying :|
     QImage cp = image.copy();
 
     QString fileName = QString::fromUtf8(file);
@@ -86,7 +84,7 @@ public:
 
 class DoneHandler : public QtCamGStreamerMessageHandler {
 public:
-  DoneHandler(QtCamMode *m, const char *done, QObject *parent = 0) :
+  DoneHandler(QtCamModePrivate *m, const char *done, QObject *parent = 0) :
     QtCamGStreamerMessageHandler(done, parent) {
     mode = m;
   }
@@ -96,23 +94,23 @@ public:
     if (gst_structure_has_field(s, "filename")) {
       const char *str = gst_structure_get_string(s, "filename");
       if (str) {
-       fileName = QString::fromUtf8(str);
+       mode->fileName = QString::fromUtf8(str);
       }
     }
 
-    QMetaObject::invokeMethod(mode, "saved", Q_ARG(QString, fileName));
+    QMetaObject::invokeMethod(mode->q_ptr, "saved", Q_ARG(QString, mode->fileName));
   }
 
-  QString fileName;
-  QtCamMode *mode;
+  QtCamModePrivate *mode;
 };
 
 QtCamMode::QtCamMode(QtCamModePrivate *d, const char *mode, const char *done, QObject *parent) :
   QObject(parent), d_ptr(d) {
 
+  d_ptr->q_ptr = this;
   d_ptr->id = d_ptr->modeId(mode);
   d_ptr->previewImageHandler = new PreviewImageHandler(this, this);
-  d_ptr->doneHandler = new DoneHandler(this, done, this);
+  d_ptr->doneHandler = new DoneHandler(d_ptr, done, this);
 }
 
 QtCamMode::~QtCamMode() {
@@ -137,9 +135,6 @@ void QtCamMode::activate() {
   // TODO: check that we can actually do it. Perhaps the pipeline is busy.
   g_object_set(d_ptr->dev->cameraBin, "mode", d_ptr->id, NULL);
 
-  // TODO: is that needed ?
-  //  d_ptr->dev->resetCapabilities();
-
   d_ptr->dev->listener->addHandler(d_ptr->previewImageHandler);
   d_ptr->dev->listener->addHandler(d_ptr->doneHandler);
 
@@ -181,29 +176,6 @@ bool QtCamMode::isActive() {
   return d_ptr->dev->active == this;
 }
 
-void QtCamMode::setPreviewSize(const QSize& size) {
-  if (!d_ptr->dev->cameraBin) {
-    return;
-  }
-
-  if (size.width() <= 0 && size.height() <= 0) {
-    g_object_set(d_ptr->dev->cameraBin, "preview-caps", NULL, "post-previews", FALSE, NULL);
-  }
-  else {
-    QString preview = QString(PREVIEW_CAPS).arg(size.width()).arg(size.height());
-
-    GstCaps *caps = gst_caps_from_string(preview.toAscii());
-
-    g_object_set(d_ptr->dev->cameraBin, "preview-caps", caps, "post-previews", TRUE, NULL);
-
-    gst_caps_unref(caps);
-  }
-}
-
-void QtCamMode::setFileName(const QString& fileName) {
-  d_ptr->doneHandler->fileName = fileName;
-}
-
 QtCamDevice *QtCamMode::device() const {
   return d_ptr->dev->q_ptr;
 }
index 2d7e0aa..ea4a238 100644 (file)
@@ -65,12 +65,6 @@ protected:
   virtual void start() = 0;
   virtual void stop() = 0;
 
-  // TODO: move this from here
-  void setPreviewSize(const QSize& size);
-
-  // TODO: move this from here
-  void setFileName(const QString& fileName);
-
   QtCamModePrivate *d_ptr;
 };
 
index f8095d0..e63390b 100644 (file)
@@ -33,6 +33,8 @@
 #endif /* GST_USE_UNSTABLE_API */
 #include <gst/interfaces/photography.h>
 
+#define PREVIEW_CAPS "video/x-raw-rgb, width = (int) %1, height = (int) %2, bpp = (int) 32, depth = (int) 24, red_mask = (int) 65280, green_mask = (int) 16711680, blue_mask = (int) -16777216"
+
 class QtCamDevicePrivate;
 class PreviewImageHandler;
 class DoneHandler;
@@ -57,7 +59,7 @@ public:
       return -1;
     }
 
-    GParamSpecEnum *e = (GParamSpecEnum *)pspec;
+    GParamSpecEnum *e = G_PARAM_SPEC_ENUM(pspec);
     GEnumClass *klass = e->enum_class;
 
     for (unsigned x = 0; x < klass->n_values; x++) {
@@ -155,10 +157,35 @@ public:
     }
   }
 
+  void setPreviewSize(const QSize& size) {
+    if (!dev->cameraBin) {
+      return;
+    }
+
+    if (size.width() <= 0 && size.height() <= 0) {
+      g_object_set(dev->cameraBin, "preview-caps", NULL, "post-previews", FALSE, NULL);
+    }
+    else {
+      QString preview = QString(PREVIEW_CAPS).arg(size.width()).arg(size.height());
+
+      GstCaps *caps = gst_caps_from_string(preview.toAscii());
+
+      g_object_set(dev->cameraBin, "preview-caps", caps, "post-previews", TRUE, NULL);
+
+      gst_caps_unref(caps);
+    }
+  }
+
+  void setFileName(const QString& file) {
+    fileName = file;
+  }
+
   int id;
+  QtCamMode *q_ptr;
   QtCamDevicePrivate *dev;
   PreviewImageHandler *previewImageHandler;
   DoneHandler *doneHandler;
+  QString fileName;
 };
 
 #endif /* QT_CAM_MODE_P_H */
index 46a5502..1f7121f 100644 (file)
@@ -65,7 +65,6 @@ QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
     }
   }
 
-  // TODO: Use signals from QtCamNotifications instead ?
   QObject::connect(d_ptr->dev->q_ptr, SIGNAL(idleStateChanged(bool)),
                   this, SLOT(_d_idleStateChanged(bool)));
 }
@@ -87,7 +86,7 @@ void QtCamVideoMode::applySettings() {
 
   d_ptr->setCaps("video-capture-caps", d->resolution.captureResolution(), fps);
 
-  setPreviewSize(d->resolution.previewResolution());
+  d_ptr->setPreviewSize(d->resolution.previewResolution());
 
   // Not sure this is needed but just in case.
   d_ptr->resetCaps("image-capture-caps");
@@ -116,7 +115,7 @@ bool QtCamVideoMode::startRecording(const QString& fileName) {
     return false;
   }
 
-  setFileName(fileName);
+  d_ptr->setFileName(fileName);
 
   QMetaObject::invokeMethod(d_ptr->dev->notifications, "videoRecordingStarted");
 
index 559f725..3411179 100644 (file)
@@ -98,7 +98,7 @@ public:
 QtCamZoom::QtCamZoom(QtCamDevice *dev, QObject *parent) :
   QtCamCapability(new QtCamZoomPrivate(dev, this), parent) {
 
-  ((QtCamZoomPrivate *) d_ptr)->init();
+  dynamic_cast<QtCamZoomPrivate *>(d_ptr)->init();
 }
 
 QtCamZoom::~QtCamZoom() {
@@ -106,11 +106,11 @@ QtCamZoom::~QtCamZoom() {
 }
 
 qreal QtCamZoom::value() {
-  return ((QtCamZoomPrivate *) d_ptr)->zoom();
+  return dynamic_cast<QtCamZoomPrivate *>(d_ptr)->zoom();
 }
 
 bool QtCamZoom::setValue(qreal zoom) {
-  if (((QtCamZoomPrivate *) d_ptr)->setZoom(zoom)) {
+  if (dynamic_cast<QtCamZoomPrivate *>(d_ptr)->setZoom(zoom)) {
     emit valueChanged();
     return true;
   }
@@ -119,9 +119,10 @@ bool QtCamZoom::setValue(qreal zoom) {
 }
 
 qreal QtCamZoom::minimumValue() {
+  // TODO: hardcoded
   return 1.0;
 }
 
 qreal QtCamZoom::maximumValue() {
-  return ((QtCamZoomPrivate *) d_ptr)->maxZoom();
+  return dynamic_cast<QtCamZoomPrivate *>(d_ptr)->maxZoom();
 }
index df75179..363d439 100644 (file)
@@ -113,9 +113,7 @@ Page {
         }
 
         Rectangle {
-                // TODO: color
                 // TODO: fade out transition
-                // TODO: there is a toolbar visible on the first startup
                 id: standby
                 color: "black"
                 anchors.fill: parent