From 91049febc4f59b875b8f77d124a7fcbbd0efa863 Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Sat, 8 Sep 2012 14:34:17 +0300 Subject: [PATCH] Changes to night mode handling: * 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. --- imports/mode.cpp | 12 ------- imports/mode.h | 5 --- lib/qtcamconfig.cpp | 17 +++------- lib/qtcamdevice_p.h | 1 + lib/qtcamimagemode.cpp | 14 ++++++-- lib/qtcamimagesettings.cpp | 35 ++++++++------------ lib/qtcamimagesettings.h | 6 ++-- lib/qtcammode.cpp | 13 -------- lib/qtcammode.h | 5 --- lib/qtcammode_p.h | 67 +++++++++++++++++++++++++++++++------- lib/qtcamvideomode.cpp | 13 +++++--- lib/qtcamvideosettings.cpp | 35 ++++++++------------ lib/qtcamvideosettings.h | 6 ++-- qml/ImagePage.qml | 1 - qml/VideoPage.qml | 1 - 15 files changed, 111 insertions(+), 120 deletions(-) diff --git a/imports/mode.cpp b/imports/mode.cpp index 8f3ae7a..298cdac 100644 --- a/imports/mode.cpp +++ b/imports/mode.cpp @@ -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; } diff --git a/imports/mode.h b/imports/mode.h index 87fbf36..c5edbf1 100644 --- a/imports/mode.h +++ b/imports/mode.h @@ -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: diff --git a/lib/qtcamconfig.cpp b/lib/qtcamconfig.cpp index bc47b04..55e224e 100644 --- a/lib/qtcamconfig.cpp +++ b/lib/qtcamconfig.cpp @@ -16,11 +16,6 @@ public: return QSize(parts[0].toInt(), parts[1].toInt()); } - QPair readFrameRate(const QString& key) { - QList parts = conf->value(key).toString().trimmed().split("/"); - return qMakePair(parts[0].toInt(), parts[1].toInt()); - } - QSettings *conf; QList imageSettings; @@ -99,15 +94,13 @@ QList QtCamConfig::imageSettings() { foreach (const QString& preset, presets) { d_ptr->conf->beginGroup(preset); - QPair fps = d_ptr->readFrameRate("fps"); - QPair 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 QtCamConfig::videoSettings() { foreach (const QString& preset, presets) { d_ptr->conf->beginGroup(preset); - QPair fps = d_ptr->readFrameRate("fps"); - QPair 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(); } diff --git a/lib/qtcamdevice_p.h b/lib/qtcamdevice_p.h index 5d694ef..35bfe17 100644 --- a/lib/qtcamdevice_p.h +++ b/lib/qtcamdevice_p.h @@ -43,6 +43,7 @@ public: } void createAndAddVideoSource() { + // TODO: rework this function GstElement *src, *wrapper; QString wrapperSrc = conf->wrapperVideoSource(); QString prop = conf->wrapperVideoSourceProperty(); diff --git a/lib/qtcamimagemode.cpp b/lib/qtcamimagemode.cpp index b5663c4..3935cee 100644 --- a/lib/qtcamimagemode.cpp +++ b/lib/qtcamimagemode.cpp @@ -43,14 +43,22 @@ bool QtCamImageMode::canCapture() { } void QtCamImageMode::applySettings() { - QPair 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() { diff --git a/lib/qtcamimagesettings.cpp b/lib/qtcamimagesettings.cpp index ed0c500..36db068 100644 --- a/lib/qtcamimagesettings.cpp +++ b/lib/qtcamimagesettings.cpp @@ -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 QtCamImageSettings::frameRate() const { - return qMakePair(d_ptr->numerator, d_ptr->denominator); +int QtCamImageSettings::frameRate() const { + return d_ptr->fps; } -QPair QtCamImageSettings::nightFrameRate() const { - return qMakePair(d_ptr->nightNumerator, d_ptr->nightDenominator); +int QtCamImageSettings::nightFrameRate() const { + return d_ptr->nightFps; } diff --git a/lib/qtcamimagesettings.h b/lib/qtcamimagesettings.h index 7d79871..cb70041 100644 --- a/lib/qtcamimagesettings.h +++ b/lib/qtcamimagesettings.h @@ -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 frameRate() const; - QPair nightFrameRate() const; + int frameRate() const; + int nightFrameRate() const; private: QtCamImageSettingsPrivate *d_ptr; diff --git a/lib/qtcammode.cpp b/lib/qtcammode.cpp index 099cb01..30a8be2 100644 --- a/lib/qtcammode.cpp +++ b/lib/qtcammode.cpp @@ -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; -} diff --git a/lib/qtcammode.h b/lib/qtcammode.h index 64dd9bd..e8a9e54 100644 --- a/lib/qtcammode.h +++ b/lib/qtcammode.h @@ -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; diff --git a/lib/qtcammode_p.h b/lib/qtcammode_p.h index fd31945..2b52452 100644 --- a/lib/qtcammode_p.h +++ b/lib/qtcammode_p.h @@ -8,15 +8,18 @@ #include #include +#ifndef GST_USE_UNSTABLE_API +#define GST_USE_UNSTABLE_API +#endif /* GST_USE_UNSTABLE_API */ +#include + 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 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 */ diff --git a/lib/qtcamvideomode.cpp b/lib/qtcamvideomode.cpp index 8cde40f..eb7bc67 100644 --- a/lib/qtcamvideomode.cpp +++ b/lib/qtcamvideomode.cpp @@ -53,15 +53,18 @@ bool QtCamVideoMode::canCapture() { } void QtCamVideoMode::applySettings() { - QPair 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() { diff --git a/lib/qtcamvideosettings.cpp b/lib/qtcamvideosettings.cpp index ff28ca7..3624915 100644 --- a/lib/qtcamvideosettings.cpp +++ b/lib/qtcamvideosettings.cpp @@ -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 QtCamVideoSettings::frameRate() const { - return qMakePair(d_ptr->numerator, d_ptr->denominator); +int QtCamVideoSettings::frameRate() const { + return d_ptr->fps; } -QPair QtCamVideoSettings::nightFrameRate() const { - return qMakePair(d_ptr->nightNumerator, d_ptr->nightDenominator); +int QtCamVideoSettings::nightFrameRate() const { + return d_ptr->nightFps; } diff --git a/lib/qtcamvideosettings.h b/lib/qtcamvideosettings.h index c829b54..06c3c85 100644 --- a/lib/qtcamvideosettings.h +++ b/lib/qtcamvideosettings.h @@ -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 frameRate() const; - QPair nightFrameRate() const; + int frameRate() const; + int nightFrameRate() const; private: QtCamVideoSettingsPrivate *d_ptr; diff --git a/qml/ImagePage.qml b/qml/ImagePage.qml index bbe14a3..9c1e669 100644 --- a/qml/ImagePage.qml +++ b/qml/ImagePage.qml @@ -26,7 +26,6 @@ CameraPage { id: imageMode camera: cam onPreviewAvailable: page.setPreview(preview); - nightMode: ready ? settings.imageSceneMode == Scene.Night : false } FlashButton { diff --git a/qml/VideoPage.qml b/qml/VideoPage.qml index fa15548..ab46692 100644 --- a/qml/VideoPage.qml +++ b/qml/VideoPage.qml @@ -36,7 +36,6 @@ CameraPage { id: videoMode camera: cam onPreviewAvailable: page.setPreview(preview); - nightMode: ready ? settings.videoSceneMode == Scene.Night : false } VideoTorchButton { -- 2.25.1