* 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.
this, SIGNAL(canCaptureChanged()));
QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
this, SIGNAL(canCaptureChanged()));
- QObject::disconnect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
preChangeMode();
}
this, SIGNAL(canCaptureChanged()));
QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
this, SIGNAL(canCaptureChanged()));
- QObject::connect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
postChangeMode();
}
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;
}
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:
bool canCapture();
- void setNightMode(bool night);
- bool inNightMode() const;
-
bool isReady() const;
signals:
void activeChanged();
void previewAvailable(const QString& preview, const QString& fileName);
void saved(const QString& fileName);
- void nightModeChanged();
void isReadyChanged();
private slots:
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;
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();
}
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();
}
}
void createAndAddVideoSource() {
+ // TODO: rework this function
GstElement *src, *wrapper;
QString wrapperSrc = conf->wrapperVideoSource();
QString prop = conf->wrapperVideoSourceProperty();
}
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() {
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;
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) :
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() {
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;
}
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;
}
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);
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;
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;
-}
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);
virtual void applySettings() = 0;
- void setNightMode(bool night);
- bool inNightMode() const;
-
public slots:
void activate();
void saved(const QString& fileName);
void canCaptureChanged();
void activeChanged();
- void nightModeChanged();
protected:
virtual void start() = 0;
#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) {
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;
}
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 */
}
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() {
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) :
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() {
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;
}
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;
}
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);
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;
id: imageMode
camera: cam
onPreviewAvailable: page.setPreview(preview);
- nightMode: ready ? settings.imageSceneMode == Scene.Night : false
}
FlashButton {
id: videoMode
camera: cam
onPreviewAvailable: page.setPreview(preview);
- nightMode: ready ? settings.videoSceneMode == Scene.Night : false
}
VideoTorchButton {