Changes to night mode handling:
authorMohammed Sameer <msameer@foolab.org>
Sat, 8 Sep 2012 11:34:17 +0000 (14:34 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 8 Sep 2012 11:37:54 +0000 (14:37 +0300)
* FPS is now a numerator only and we ask camerabin for ranges instead of exact fps.
* We set the image capture caps without any FPS for now.
* Dropped the night property for the modes. We will handle it automatically.

15 files changed:
imports/mode.cpp
imports/mode.h
lib/qtcamconfig.cpp
lib/qtcamdevice_p.h
lib/qtcamimagemode.cpp
lib/qtcamimagesettings.cpp
lib/qtcamimagesettings.h
lib/qtcammode.cpp
lib/qtcammode.h
lib/qtcammode_p.h
lib/qtcamvideomode.cpp
lib/qtcamvideosettings.cpp
lib/qtcamvideosettings.h
qml/ImagePage.qml
qml/VideoPage.qml

index 8f3ae7a..298cdac 100644 (file)
@@ -66,7 +66,6 @@ void Mode::deviceChanged() {
                        this, SIGNAL(canCaptureChanged()));
     QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
                        this, SIGNAL(canCaptureChanged()));
-    QObject::disconnect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
 
     preChangeMode();
   }
@@ -88,7 +87,6 @@ void Mode::deviceChanged() {
                     this, SIGNAL(canCaptureChanged()));
     QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
                     this, SIGNAL(canCaptureChanged()));
-    QObject::connect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
 
     postChangeMode();
   }
@@ -107,16 +105,6 @@ void Mode::gotPreview(const QImage& image, const QString& fileName) {
   emit previewAvailable(url, fileName);
 }
 
-void Mode::setNightMode(bool night) {
-  if (m_mode) {
-    m_mode->setNightMode(night);
-  }
-}
-
-bool Mode::inNightMode() const {
-  return m_mode ? m_mode->inNightMode() : false;
-}
-
 bool Mode::isReady() const {
   return m_mode;
 }
index 87fbf36..c5edbf1 100644 (file)
@@ -15,7 +15,6 @@ class Mode : public QObject {
   Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged);
   Q_PROPERTY(bool canCapture READ canCapture NOTIFY canCaptureChanged);
   Q_PROPERTY(bool active READ isActive NOTIFY activeChanged);
-  Q_PROPERTY(bool nightMode READ inNightMode WRITE setNightMode NOTIFY nightModeChanged);
   Q_PROPERTY(bool ready READ isReady NOTIFY isReadyChanged);
 
 public:
@@ -29,9 +28,6 @@ public:
 
   bool canCapture();
 
-  void setNightMode(bool night);
-  bool inNightMode() const;
-
   bool isReady() const;
 
 signals:
@@ -40,7 +36,6 @@ signals:
   void activeChanged();
   void previewAvailable(const QString& preview, const QString& fileName);
   void saved(const QString& fileName);
-  void nightModeChanged();
   void isReadyChanged();
 
 private slots:
index bc47b04..55e224e 100644 (file)
@@ -16,11 +16,6 @@ public:
     return QSize(parts[0].toInt(), parts[1].toInt());
   }
 
-  QPair<int, int> readFrameRate(const QString& key) {
-    QList<QString> parts = conf->value(key).toString().trimmed().split("/");
-    return qMakePair<int, int>(parts[0].toInt(), parts[1].toInt());
-  }
-
   QSettings *conf;
 
   QList<QtCamImageSettings> imageSettings;
@@ -99,15 +94,13 @@ QList<QtCamImageSettings> QtCamConfig::imageSettings() {
     foreach (const QString& preset, presets) {
       d_ptr->conf->beginGroup(preset);
 
-      QPair<int, int> fps = d_ptr->readFrameRate("fps");
-      QPair<int, int> night = d_ptr->readFrameRate("night");
-
       d_ptr->imageSettings <<
        QtCamImageSettings(preset, d_ptr->conf->value("name").toString(),
                           d_ptr->readResolution("capture"),
                           d_ptr->readResolution("preview"),
                           d_ptr->readResolution("viewfinder"),
-                          fps.first, fps.second, night.first, night.second);
+                          d_ptr->conf->value("fps").toInt(),
+                          d_ptr->conf->value("night").toInt());
 
       d_ptr->conf->endGroup();
     }
@@ -137,14 +130,12 @@ QList<QtCamVideoSettings> QtCamConfig::videoSettings() {
     foreach (const QString& preset, presets) {
       d_ptr->conf->beginGroup(preset);
 
-      QPair<int, int> fps = d_ptr->readFrameRate("fps");
-      QPair<int, int> night = d_ptr->readFrameRate("night");
-
       d_ptr->videoSettings <<
        QtCamVideoSettings(preset, d_ptr->conf->value("name").toString(),
                           d_ptr->readResolution("capture"),
                           d_ptr->readResolution("preview"),
-                          fps.first, fps.second, night.first, night.second);
+                          d_ptr->conf->value("fps").toInt(),
+                          d_ptr->conf->value("night").toInt());
 
       d_ptr->conf->endGroup();
     }
index 5d694ef..35bfe17 100644 (file)
@@ -43,6 +43,7 @@ public:
   }
 
   void createAndAddVideoSource() {
+    // TODO: rework this function
     GstElement *src, *wrapper;
     QString wrapperSrc = conf->wrapperVideoSource();
     QString prop = conf->wrapperVideoSourceProperty();
index b5663c4..3935cee 100644 (file)
@@ -43,14 +43,22 @@ bool QtCamImageMode::canCapture() {
 }
 
 void QtCamImageMode::applySettings() {
-  QPair<int, int> fps = d_ptr->night ? d->settings.nightFrameRate() : d->settings.frameRate();
+  bool night = d_ptr->inNightMode();
 
-  d_ptr->setCaps("image-capture-caps", d->settings.captureResolution(),
-                d->settings.frameRate());
+  int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
 
   d_ptr->setCaps("viewfinder-caps", d->settings.viewfinderResolution(), fps);
 
+  // FIXME:
+  // Ideally, we should query the image-capture-supported-caps and get a proper framerate
+  // as it seems that subdevsrc2 can only capture 15 FPS for at least the highest resolution
+  // we use. For now we will not set any FPS.
+  d_ptr->setCaps("image-capture-caps", d->settings.captureResolution(), -1);
+
   setPreviewSize(d->settings.previewResolution());
+
+  // TODO: ?
+  // d_ptr->resetCaps("video-capture-caps");
 }
 
 void QtCamImageMode::start() {
index ed0c500..36db068 100644 (file)
@@ -7,17 +7,14 @@ public:
   QSize capture;
   QSize preview;
   QSize viewfinder;
-  int numerator;
-  int denominator;
-  int nightNumerator;
-  int nightDenominator;
+  int fps;
+  int nightFps;
 };
 
 QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& name,
                                       const QSize& capture, const QSize& preview,
                                       const QSize& viewfinder,
-                                      int numerator, int denominator,
-                                      int nightNumerator, int nightDenominator) :
+                                      int fps, int nightFps) :
   d_ptr(new QtCamImageSettingsPrivate) {
 
   d_ptr->id = id;
@@ -25,10 +22,8 @@ QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& name,
   d_ptr->capture = capture;
   d_ptr->preview = preview;
   d_ptr->viewfinder = viewfinder;
-  d_ptr->numerator = numerator;
-  d_ptr->denominator = denominator;
-  d_ptr->nightNumerator = nightNumerator;
-  d_ptr->nightDenominator = nightDenominator;
+  d_ptr->fps = fps;
+  d_ptr->nightFps = nightFps;
 }
 
 QtCamImageSettings::QtCamImageSettings(const QtCamImageSettings& other) :
@@ -39,10 +34,8 @@ QtCamImageSettings::QtCamImageSettings(const QtCamImageSettings& other) :
   d_ptr->capture = other.d_ptr->capture;
   d_ptr->preview = other.d_ptr->preview;
   d_ptr->viewfinder = other.d_ptr->viewfinder;
-  d_ptr->numerator = other.d_ptr->numerator;
-  d_ptr->denominator = other.d_ptr->denominator;
-  d_ptr->nightNumerator = other.d_ptr->nightNumerator;
-  d_ptr->nightDenominator = other.d_ptr->nightDenominator;
+  d_ptr->fps = other.d_ptr->fps;
+  d_ptr->nightFps = other.d_ptr->nightFps;
 }
 
 QtCamImageSettings::~QtCamImageSettings() {
@@ -56,10 +49,8 @@ QtCamImageSettings& QtCamImageSettings::operator=(const QtCamImageSettings&
   d_ptr->capture = other.d_ptr->capture;
   d_ptr->preview = other.d_ptr->preview;
   d_ptr->viewfinder = other.d_ptr->viewfinder;
-  d_ptr->numerator = other.d_ptr->numerator;
-  d_ptr->denominator = other.d_ptr->denominator;
-  d_ptr->nightNumerator = other.d_ptr->nightNumerator;
-  d_ptr->nightDenominator = other.d_ptr->nightDenominator;
+  d_ptr->fps = other.d_ptr->fps;
+  d_ptr->nightFps = other.d_ptr->nightFps;
 
   return *this;
 }
@@ -84,10 +75,10 @@ QSize QtCamImageSettings::previewResolution() const {
   return d_ptr->preview;
 }
 
-QPair<int, int> QtCamImageSettings::frameRate() const {
-  return qMakePair<int, int>(d_ptr->numerator, d_ptr->denominator);
+int QtCamImageSettings::frameRate() const {
+  return d_ptr->fps;
 }
 
-QPair<int, int> QtCamImageSettings::nightFrameRate() const {
-  return qMakePair<int, int>(d_ptr->nightNumerator, d_ptr->nightDenominator);
+int QtCamImageSettings::nightFrameRate() const {
+  return d_ptr->nightFps;
 }
index 7d79871..cb70041 100644 (file)
@@ -13,7 +13,7 @@ class QtCamImageSettings {
 public:
   QtCamImageSettings(const QString& id, const QString& name, const QSize& capture,
                     const QSize& preview, const QSize& viewfinder,
-                    int numerator, int denominator, int nightNumerator, int nightDenominator);
+                    int fps, int nightFps);
 
   QtCamImageSettings(const QtCamImageSettings& other);
 
@@ -26,8 +26,8 @@ public:
   QSize captureResolution() const;
   QSize viewfinderResolution() const;
   QSize previewResolution() const;
-  QPair<int, int> frameRate() const;
-  QPair<int, int> nightFrameRate() const;
+  int frameRate() const;
+  int nightFrameRate() const;
 
 private:
   QtCamImageSettingsPrivate *d_ptr;
index 099cb01..30a8be2 100644 (file)
@@ -182,16 +182,3 @@ void QtCamMode::setPreviewSize(const QSize& size) {
 void QtCamMode::setFileName(const QString& fileName) {
   d_ptr->doneHandler->fileName = fileName;
 }
-
-void QtCamMode::setNightMode(bool night) {
-  if (d_ptr->night != night) {
-    d_ptr->night = night;
-    applySettings();
-
-    emit nightModeChanged();
-  }
-}
-
-bool QtCamMode::inNightMode() const {
-  return d_ptr->night;
-}
index 64dd9bd..e8a9e54 100644 (file)
@@ -16,7 +16,6 @@ class QtCamMode : public QObject {
 
   Q_PROPERTY(bool canCapture READ canCapture NOTIFY canCaptureChanged);
   Q_PROPERTY(bool active READ isActive NOTIFY activeChanged);
-  Q_PROPERTY(bool nightMode READ inNightMode WRITE setNightMode NOTIFY nightModeChanged);
 
 public:
   QtCamMode(QtCamModePrivate *d, const char *mode, const char *done, QObject *parent = 0);
@@ -30,9 +29,6 @@ public:
 
   virtual void applySettings() = 0;
 
-  void setNightMode(bool night);
-  bool inNightMode() const;
-
 public slots:
   void activate();
 
@@ -41,7 +37,6 @@ signals:
   void saved(const QString& fileName);
   void canCaptureChanged();
   void activeChanged();
-  void nightModeChanged();
 
 protected:
   virtual void start() = 0;
index fd31945..2b52452 100644 (file)
@@ -8,15 +8,18 @@
 #include <gst/pbutils/encoding-profile.h>
 #include <gst/pbutils/encoding-target.h>
 
+#ifndef GST_USE_UNSTABLE_API
+#define GST_USE_UNSTABLE_API
+#endif /* GST_USE_UNSTABLE_API */
+#include <gst/interfaces/photography.h>
+
 class QtCamDevicePrivate;
 class PreviewImageHandler;
 class DoneHandler;
 
-#define CAPS "video/x-raw-yuv, width = (int) %1, height = (int) %2, framerate = (fraction) %3/%4"
-
 class QtCamModePrivate {
 public:
-  QtCamModePrivate(QtCamDevicePrivate *d) : id(-1), dev(d), night(false) {}
+  QtCamModePrivate(QtCamDevicePrivate *d) : id(-1), dev(d) {}
   virtual ~QtCamModePrivate() {}
 
   int modeId(const char *mode) {
@@ -68,13 +71,28 @@ public:
     return profile;
   }
 
-  void setCaps(const char *property, const QSize& resolution, const QPair<int, int> frameRate) {
+  void resetCaps(const char *property) {
     if (!dev->cameraBin) {
       return;
     }
 
-    // TODO: allow proceeding without specifying a frame rate (maybe we can calculate it ?)
-    if (frameRate.first <= 0 || frameRate.second <= 0) {
+    g_object_set(dev->cameraBin, property, NULL, NULL);
+  }
+
+  bool inNightMode() {
+    if (!dev->cameraBin) {
+      return false;
+    }
+
+    int val = 0;
+
+    g_object_get(dev->videoSource, "scene-mode", &val, NULL);
+
+    return val == GST_PHOTOGRAPHY_SCENE_MODE_NIGHT;
+  }
+
+  void setCaps(const char *property, const QSize& resolution, int fps) {
+    if (!dev->cameraBin) {
       return;
     }
 
@@ -82,22 +100,47 @@ public:
       return;
     }
 
-    QString capsString = QString(CAPS)
-      .arg(resolution.width()).arg(resolution.height())
-      .arg(frameRate.first).arg(frameRate.second);
+    GstCaps *caps = 0;
+
+    if (fps <= 0) {
+      caps = gst_caps_new_simple("video/x-raw-yuv",
+                                "width", G_TYPE_INT, resolution.width(),
+                                "height", G_TYPE_INT, resolution.height(),
+                                NULL);
+    }
+    else {
+      caps = gst_caps_new_simple("video/x-raw-yuv",
+                                "width", G_TYPE_INT, resolution.width(),
+                                "height", G_TYPE_INT, resolution.height(),
+                                "framerate",
+                                GST_TYPE_FRACTION_RANGE, fps - 1, 1, fps + 1, 1,
+                                NULL);
+    }
+
+    GstCaps *old = 0;
+
+    g_object_get(dev->cameraBin, property, &old, NULL);
 
-    GstCaps *caps = gst_caps_from_string(capsString.toAscii());
+    if (gst_caps_is_equal(caps, old)) {
+      gst_caps_unref(old);
+      gst_caps_unref(caps);
+
+      return;
+    }
+
+    qDebug() << "Setting caps" << property << gst_caps_to_string(caps);
 
     g_object_set(dev->cameraBin, property, caps, NULL);
 
-    gst_caps_unref(caps);
+    if (old) {
+      gst_caps_unref(old);
+    }
   }
 
   int id;
   QtCamDevicePrivate *dev;
   PreviewImageHandler *previewImageHandler;
   DoneHandler *doneHandler;
-  bool night;
 };
 
 #endif /* QT_CAM_MODE_P_H */
index 8cde40f..eb7bc67 100644 (file)
@@ -53,15 +53,18 @@ bool QtCamVideoMode::canCapture() {
 }
 
 void QtCamVideoMode::applySettings() {
-  QPair<int, int> fps = d_ptr->night ? d->settings.nightFrameRate() : d->settings.frameRate();
+  bool night = d_ptr->inNightMode();
 
-  d_ptr->setCaps("viewfinder-caps", d->settings.captureResolution(),
-                fps);
+  int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
 
-  d_ptr->setCaps("video-capture-caps", d->settings.captureResolution(),
-                fps);
+  d_ptr->setCaps("viewfinder-caps", d->settings.captureResolution(), fps);
+
+  d_ptr->setCaps("video-capture-caps", d->settings.captureResolution(), fps);
 
   setPreviewSize(d->settings.previewResolution());
+
+  // TODO:
+  //  d_ptr->resetCaps("image-capture-caps");
 }
 
 void QtCamVideoMode::start() {
index ff28ca7..3624915 100644 (file)
@@ -6,26 +6,21 @@ public:
   QString name;
   QSize capture;
   QSize preview;
-  int numerator;
-  int denominator;
-  int nightNumerator;
-  int nightDenominator;
+  int fps;
+  int nightFps;
 };
 
 QtCamVideoSettings::QtCamVideoSettings(const QString& id, const QString& name,
                                       const QSize& capture, const QSize& preview,
-                                      int numerator, int denominator,
-                                      int nightNumerator, int nightDenominator) :
+                                      int fps, int nightFps) :
   d_ptr(new QtCamVideoSettingsPrivate) {
 
   d_ptr->id = id;
   d_ptr->name = name;
   d_ptr->capture = capture;
   d_ptr->preview = preview;
-  d_ptr->numerator = numerator;
-  d_ptr->denominator = denominator;
-  d_ptr->nightNumerator = nightNumerator;
-  d_ptr->nightDenominator = nightDenominator;
+  d_ptr->fps = fps;
+  d_ptr->nightFps = nightFps;
 }
 
 QtCamVideoSettings::QtCamVideoSettings(const QtCamVideoSettings& other) :
@@ -35,10 +30,8 @@ QtCamVideoSettings::QtCamVideoSettings(const QtCamVideoSettings& other) :
   d_ptr->name = other.d_ptr->name;
   d_ptr->capture = other.d_ptr->capture;
   d_ptr->preview = other.d_ptr->preview;
-  d_ptr->numerator = other.d_ptr->numerator;
-  d_ptr->denominator = other.d_ptr->denominator;
-  d_ptr->nightNumerator = other.d_ptr->nightNumerator;
-  d_ptr->nightDenominator = other.d_ptr->nightDenominator;
+  d_ptr->fps = other.d_ptr->fps;
+  d_ptr->nightFps = other.d_ptr->nightFps;
 }
 
 QtCamVideoSettings::~QtCamVideoSettings() {
@@ -51,10 +44,8 @@ QtCamVideoSettings& QtCamVideoSettings::operator=(const QtCamVideoSettings&
   d_ptr->name = other.d_ptr->name;
   d_ptr->capture = other.d_ptr->capture;
   d_ptr->preview = other.d_ptr->preview;
-  d_ptr->numerator = other.d_ptr->numerator;
-  d_ptr->denominator = other.d_ptr->denominator;
-  d_ptr->nightNumerator = other.d_ptr->nightNumerator;
-  d_ptr->nightDenominator = other.d_ptr->nightDenominator;
+  d_ptr->fps = other.d_ptr->fps;
+  d_ptr->nightFps = other.d_ptr->nightFps;
 
   return *this;
 }
@@ -75,10 +66,10 @@ QSize QtCamVideoSettings::previewResolution() const {
   return d_ptr->preview;
 }
 
-QPair<int, int> QtCamVideoSettings::frameRate() const {
-  return qMakePair<int, int>(d_ptr->numerator, d_ptr->denominator);
+int QtCamVideoSettings::frameRate() const {
+  return d_ptr->fps;
 }
 
-QPair<int, int> QtCamVideoSettings::nightFrameRate() const {
-  return qMakePair<int, int>(d_ptr->nightNumerator, d_ptr->nightDenominator);
+int QtCamVideoSettings::nightFrameRate() const {
+  return d_ptr->nightFps;
 }
index c829b54..06c3c85 100644 (file)
@@ -13,7 +13,7 @@ class QtCamVideoSettings {
 public:
   QtCamVideoSettings(const QString& id, const QString& name,
                     const QSize& capture, const QSize& preview,
-                    int numerator, int denominator, int nightNumerator, int nightDenominator);
+                    int fps, int nightFps);
 
   QtCamVideoSettings(const QtCamVideoSettings& other);
 
@@ -25,8 +25,8 @@ public:
   QString name() const;
   QSize captureResolution() const;
   QSize previewResolution() const;
-  QPair<int, int> frameRate() const;
-  QPair<int, int> nightFrameRate() const;
+  int frameRate() const;
+  int nightFrameRate() const;
 
 private:
   QtCamVideoSettingsPrivate *d_ptr;
index bbe14a3..9c1e669 100644 (file)
@@ -26,7 +26,6 @@ CameraPage {
                 id: imageMode
                 camera: cam
                 onPreviewAvailable: page.setPreview(preview);
-                nightMode: ready ? settings.imageSceneMode == Scene.Night : false
         }
 
         FlashButton {
index fa15548..ab46692 100644 (file)
@@ -36,7 +36,6 @@ CameraPage {
                 id: videoMode
                 camera: cam
                 onPreviewAvailable: page.setPreview(preview);
-                nightMode: ready ? settings.videoSceneMode == Scene.Night : false
         }
 
         VideoTorchButton {