Reworked how resolution is being specified in the configuration.
authorMohammed Sameer <msameer@foolab.org>
Sat, 22 Sep 2012 00:01:47 +0000 (03:01 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 22 Sep 2012 00:01:47 +0000 (03:01 +0300)
Now resolution per camera device can be specified in the configuration.
QtCam*Settings classes hold the profile name and path, suffix and the list of the resolutions.

data/n9/qtcamera.ini
lib/qtcamconfig.cpp
lib/qtcamconfig.h
lib/qtcamimagemode.cpp
lib/qtcamimagemode.h
lib/qtcamimagesettings.cpp
lib/qtcamimagesettings.h
lib/qtcamvideomode.cpp
lib/qtcamvideomode.h
lib/qtcamvideosettings.cpp
lib/qtcamvideosettings.h

index 3db3a5a..b8b07c6 100644 (file)
@@ -1,7 +1,10 @@
+# devices section.
+# Here we use an enum to tell subdevsrc2 which camera to use.
 [devices]
 scanner=enum
 property=camera-device
 
 [devices]
 scanner=enum
 property=camera-device
 
+# GStreaemer elements
 [video-source]
 element=subdevsrc2
 
 [video-source]
 element=subdevsrc2
 
@@ -16,43 +19,124 @@ element=pulsesrc
 element=camsrcbin
 property=video-source
 
 element=camsrcbin
 property=video-source
 
+# caps for audio
+[audio-capture-caps]
+caps = "audio/x-raw-int, channels=(int)2, width=(int)16, depth=(int)16, rate=(int)48000"
+
+# Specifying resolutions and capture properties:
+# Generic sections are called [image] and [video]
+# A specific section per device can be created and named
+# [image-<camera id>] and [video-<camera id>]
+# Options from the device specific section override options from the generic section
+
+# Defaults
 [image]
 [image]
-presets=image-low,image-medium,image-high
-default=image-medium
 profile-name=image-profile
 profile-path=image.gep
 extension=jpg
 
 [video]
 profile-name=image-profile
 profile-path=image.gep
 extension=jpg
 
 [video]
-presets=video-low,video-medium,video-high
-default=video-high
 profile-name=video-profile
 profile-path=video.gep
 extension=mp4
 
 profile-name=video-profile
 profile-path=video.gep
 extension=mp4
 
-[image-low]
-name=low
-capture = 2304x1296
+# Primary camera
+[image-0]
+presets=image-high-16:9,image-medium-16:9,image-low-16:9,image-high-4:3,image-medium-4:3,image-low-4:3,image-high-3:2,image-medium-3:2,image-low-3:2
+
+[video-0]
+presets=video-low,video-medium,video-high
+
+# presets
+[image-high-16:9]
+name=high
+capture = 3552x2000
 preview = 912x514
 viewfinder = 848x480
 fps = 30
 night = 10
 preview = 912x514
 viewfinder = 848x480
 fps = 30
 night = 10
+megapixels = 7
+aspectratio=16:9
 
 
-[image-medium]
+[image-medium-16:9]
 name=medium
 capture = 3136x1760
 preview = 912x512
 viewfinder = 848x480
 fps = 30
 night = 10
 name=medium
 capture = 3136x1760
 preview = 912x512
 viewfinder = 848x480
 fps = 30
 night = 10
+megapixels = 6
+aspectratio=16:9
 
 
-[image-high]
-name=high
-capture = 3552x2000
+[image-low-16:9]
+name=low
+capture = 2304x1296
 preview = 912x514
 viewfinder = 848x480
 fps = 30
 night = 10
 preview = 912x514
 viewfinder = 848x480
 fps = 30
 night = 10
+megapixels = 3
+aspectratio=16:9
+
+[image-high-4:3]
+name=high
+capture = 3248x2448
+preview = 832x628
+viewfinder = 640x480
+fps = 30
+night = 10
+megapixels = 8
+aspectratio=4:3
+
+[image-medium-4:3]
+name=medium
+capture = 2720x2048
+preview = 832x626
+viewfinder = 640x480
+fps = 30
+night = 10
+megapixels = 6
+aspectratio=4:3
+
+[image-low-4:3]
+name=low
+capture = 2048x1536
+preview = 848x636
+viewfinder = 640x480
+fps = 30
+night = 10
+megapixels = 3
+aspectratio=4:3
+
+[image-high-3:2]
+name=high
+capture = 3248x2160
+preview = 944x628
+viewfinder = 720x480
+fps = 30
+night = 10
+megapixels = 7
+aspectratio=3:2
+
+[image-medium-3:2]
+name=medium
+capture = 2896x1920
+preview = 944x626
+viewfinder = 720x480
+fps = 30
+night = 10
+megapixels = 6
+aspectratio=3:2
+
+[image-low-3:2]
+name=low
+capture = 2160x1440
+preview = 944x630
+viewfinder = 720x480
+fps = 30
+night = 10
+megapixels = 3
+aspectratio=3:2
 
 [video-low]
 name=low
 
 [video-low]
 name=low
@@ -60,6 +144,8 @@ capture = 640x480
 preview = 640x480
 fps = 30
 night = 10
 preview = 640x480
 fps = 30
 night = 10
+aspectratio=4:3
+resolution=VGA
 
 [video-medium]
 name=medium
 
 [video-medium]
 name=medium
@@ -67,6 +153,8 @@ capture = 848x480
 preview = 848x480
 fps = 30
 night = 10
 preview = 848x480
 fps = 30
 night = 10
+aspectratio=16:9
+resolution=WVGA
 
 [video-high]
 name=high
 
 [video-high]
 name=high
@@ -74,6 +162,5 @@ capture = 1280x720
 preview = 1280x720
 fps = 30
 night = 10
 preview = 1280x720
 fps = 30
 night = 10
-
-[audio-capture-caps]
-caps = "audio/x-raw-int, channels=(int)2, width=(int)16, depth=(int)16, rate=(int)48000"
+aspectratio=16:9
+resolution=720p
index b4c1628..b94a1c0 100644 (file)
@@ -36,6 +36,15 @@ public:
     return QSize(parts[0].toInt(), parts[1].toInt());
   }
 
     return QSize(parts[0].toInt(), parts[1].toInt());
   }
 
+  QVariant readWithFallback(const QString& generic, const QString& specific, const QString& key) {
+    QString genericKey = QString("%1/%2").arg(generic).arg(key);
+    QString specificKey = QString("%1/%2").arg(specific).arg(key);
+
+    QVariant var = conf->value(genericKey);
+
+    return conf->value(specificKey, var);
+  }
+
   QSettings *conf;
 
   QList<QtCamImageSettings> imageSettings;
   QSettings *conf;
 
   QList<QtCamImageSettings> imageSettings;
@@ -52,8 +61,6 @@ QtCamConfig::QtCamConfig(const QString& configPath, QObject *parent) :
   QObject(parent), d_ptr(new QtCamConfigPrivate) {
 
   d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
   QObject(parent), d_ptr(new QtCamConfigPrivate) {
 
   d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
-
-  defaultImageSettings();
 }
 
 QtCamConfig::~QtCamConfig() {
 }
 
 QtCamConfig::~QtCamConfig() {
@@ -92,76 +99,69 @@ QString QtCamConfig::wrapperVideoSourceProperty() const {
   return d_ptr->conf->value("wrapper-video-source/property").toString();
 }
 
   return d_ptr->conf->value("wrapper-video-source/property").toString();
 }
 
-QtCamImageSettings QtCamConfig::defaultImageSettings() {
+QtCamImageSettings *QtCamConfig::imageSettings(const QVariant& id) {
+  QString generic = "image";
+  QString specific = QString("%1-%2").arg(generic).arg(id.toString());
 
 
-  QList<QtCamImageSettings> settings = imageSettings();
+  QString profileName = d_ptr->readWithFallback(generic, specific, "profile-name").toString();
+  QString profilePath = d_ptr->readWithFallback(generic, specific, "profile-path").toString();
+  QString suffix = d_ptr->readWithFallback(generic, specific, "extension").toString();
+  QStringList presets = d_ptr->readWithFallback(generic, specific, "presets").toStringList();
 
 
-  QString def = d_ptr->conf->value("image/default").toString();
-  foreach (const QtCamImageSettings& s, settings) {
-    if (s.id() == def) {
-      return s;
-    }
-  }
+  QList<QtCamImageResolution> resolutions;
 
 
-  // This will crash if no presets have been shipped but you deserve paying
-  // the price of shipping a broken configuration file.
-  return settings[0];
-}
+  foreach (const QString& preset, presets) {
+    d_ptr->conf->beginGroup(preset);
 
 
-QList<QtCamImageSettings> QtCamConfig::imageSettings() {
-  if (d_ptr->imageSettings.isEmpty()) {
-    QStringList presets = d_ptr->conf->value("image/presets").toStringList();
-    foreach (const QString& preset, presets) {
-      d_ptr->conf->beginGroup(preset);
+    QString id = preset;
+    QString name = d_ptr->conf->value("name").toString();
+    QSize capture = d_ptr->readResolution("capture");
+    QSize preview = d_ptr->readResolution("preview");
+    QSize viewfinder = d_ptr->readResolution("viewfinder");
+    int fps = d_ptr->conf->value("fps").toInt();
+    int nightFps = d_ptr->conf->value("night").toInt();
+    int megaPixels = d_ptr->conf->value("megapixels").toInt();
+    QString aspectRatio = d_ptr->conf->value("aspectratio").toString();
 
 
-      d_ptr->imageSettings <<
-       QtCamImageSettings(preset, d_ptr->conf->value("name").toString(),
-                          d_ptr->readResolution("capture"),
-                          d_ptr->readResolution("preview"),
-                          d_ptr->readResolution("viewfinder"),
-                          d_ptr->conf->value("fps").toInt(),
-                          d_ptr->conf->value("night").toInt());
+    d_ptr->conf->endGroup();
 
 
-      d_ptr->conf->endGroup();
-    }
+    resolutions << QtCamImageResolution(id, name, capture, preview, viewfinder,
+                                       fps, nightFps, megaPixels, aspectRatio);
   }
 
   }
 
-  return d_ptr->imageSettings;
+  return new QtCamImageSettings(id.toString(), suffix, profileName, profilePath, resolutions);
 }
 
 }
 
-QtCamVideoSettings QtCamConfig::defaultVideoSettings() {
-  QList<QtCamVideoSettings> settings = videoSettings();
+QtCamVideoSettings *QtCamConfig::videoSettings(const QVariant& id) {
+  QString generic = "video";
+  QString specific = QString("%1-%2").arg(generic).arg(id.toString());
 
 
-  QString def = d_ptr->conf->value("video/default").toString();
-  foreach (const QtCamVideoSettings& s, settings) {
-    if (s.id() == def) {
-      return s;
-    }
-  }
+  QString profileName = d_ptr->readWithFallback(generic, specific, "profile-name").toString();
+  QString profilePath = d_ptr->readWithFallback(generic, specific, "profile-path").toString();
+  QString suffix = d_ptr->readWithFallback(generic, specific, "extension").toString();
+  QStringList presets = d_ptr->readWithFallback(generic, specific, "presets").toStringList();
 
 
-  // This will crash if no presets have been shipped but you deserve paying
-  // the price of shipping a broken configuration file.
-  return settings[0];
-}
+  QList<QtCamVideoResolution> resolutions;
+
+  foreach (const QString& preset, presets) {
+    d_ptr->conf->beginGroup(preset);
 
 
-QList<QtCamVideoSettings> QtCamConfig::videoSettings() {
-  if (d_ptr->videoSettings.isEmpty()) {
-    QStringList presets = d_ptr->conf->value("video/presets").toStringList();
-    foreach (const QString& preset, presets) {
-      d_ptr->conf->beginGroup(preset);
+    QString id = preset;
+    QString name = d_ptr->conf->value("name").toString();
+    QSize capture = d_ptr->readResolution("capture");
+    QSize preview = d_ptr->readResolution("preview");
+    int fps = d_ptr->conf->value("fps").toInt();
+    int nightFps = d_ptr->conf->value("night").toInt();
+    QString aspectRatio = d_ptr->conf->value("aspectratio").toString();
+    QString resolution = d_ptr->conf->value("resolution").toString();
 
 
-      d_ptr->videoSettings <<
-       QtCamVideoSettings(preset, d_ptr->conf->value("name").toString(),
-                          d_ptr->readResolution("capture"),
-                          d_ptr->readResolution("preview"),
-                          d_ptr->conf->value("fps").toInt(),
-                          d_ptr->conf->value("night").toInt());
+    d_ptr->conf->endGroup();
 
 
-      d_ptr->conf->endGroup();
-    }
+    resolutions << QtCamVideoResolution(id, name, capture, preview,
+                                       fps, nightFps, aspectRatio, resolution);
   }
 
   }
 
-  return d_ptr->videoSettings;
+  return new QtCamVideoSettings(id.toString(), suffix, profileName, profilePath, resolutions);
 }
 
 QString QtCamConfig::imageEncodingProfileName() const {
 }
 
 QString QtCamConfig::imageEncodingProfileName() const {
index 8592225..7d06a82 100644 (file)
@@ -56,11 +56,8 @@ public:
   QString wrapperVideoSource() const;
   QString wrapperVideoSourceProperty() const;
 
   QString wrapperVideoSource() const;
   QString wrapperVideoSourceProperty() const;
 
-  QtCamImageSettings defaultImageSettings();
-  QList<QtCamImageSettings> imageSettings();
-
-  QtCamVideoSettings defaultVideoSettings();
-  QList<QtCamVideoSettings> videoSettings();
+  QtCamImageSettings *imageSettings(const QVariant& id);
+  QtCamVideoSettings *videoSettings(const QVariant& id);
 
   QString imageEncodingProfileName() const;
   QString imageEncodingProfilePath() const;
 
   QString imageEncodingProfileName() const;
   QString imageEncodingProfilePath() const;
index 1132fab..05a6d10 100644 (file)
@@ -28,14 +28,17 @@ class QtCamImageModePrivate : public QtCamModePrivate {
 public:
   QtCamImageModePrivate(QtCamDevicePrivate *dev) :
   QtCamModePrivate(dev),
 public:
   QtCamImageModePrivate(QtCamDevicePrivate *dev) :
   QtCamModePrivate(dev),
-  settings(dev->conf->defaultImageSettings()) {
+  settings(dev->conf->imageSettings(dev->id)),
+  resolution(settings->defaultResolution()) {
 
   }
 
   ~QtCamImageModePrivate() {
 
   }
 
   ~QtCamImageModePrivate() {
+    delete settings;
   }
 
   }
 
-  QtCamImageSettings settings;
+  QtCamImageSettings *settings;
+  QtCamImageResolution resolution;
 };
 
 QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *dev, QObject *parent) :
 };
 
 QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *dev, QObject *parent) :
@@ -65,17 +68,17 @@ bool QtCamImageMode::canCapture() {
 void QtCamImageMode::applySettings() {
   bool night = d_ptr->inNightMode();
 
 void QtCamImageMode::applySettings() {
   bool night = d_ptr->inNightMode();
 
-  int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
+  int fps = night ? d->resolution.nightFrameRate() : d->resolution.frameRate();
 
 
-  d_ptr->setCaps("viewfinder-caps", d->settings.viewfinderResolution(), fps);
+  d_ptr->setCaps("viewfinder-caps", d->resolution.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.
 
   // 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);
+  d_ptr->setCaps("image-capture-caps", d->resolution.captureResolution(), -1);
 
 
-  setPreviewSize(d->settings.previewResolution());
+  setPreviewSize(d->resolution.previewResolution());
 
   // TODO: ?
   // d_ptr->resetCaps("video-capture-caps");
 
   // TODO: ?
   // d_ptr->resetCaps("video-capture-caps");
@@ -106,8 +109,8 @@ bool QtCamImageMode::capture(const QString& fileName) {
   return true;
 }
 
   return true;
 }
 
-bool QtCamImageMode::setSettings(const QtCamImageSettings& settings) {
-  d->settings = settings;
+bool QtCamImageMode::setResolution(const QtCamImageResolution& resolution) {
+  d->resolution = resolution;
 
   if (!d_ptr->dev->q_ptr->isRunning() || !d_ptr->dev->q_ptr->isIdle()) {
     return false;
 
   if (!d_ptr->dev->q_ptr->isRunning() || !d_ptr->dev->q_ptr->isIdle()) {
     return false;
@@ -126,3 +129,7 @@ void QtCamImageMode::setProfile(GstEncodingProfile *profile) {
 
   g_object_set(d_ptr->dev->cameraBin, "image-profile", profile, NULL);
 }
 
   g_object_set(d_ptr->dev->cameraBin, "image-profile", profile, NULL);
 }
+
+QtCamImageSettings *QtCamImageMode::settings() const {
+  return d->settings;
+}
index 5a87cb1..480147b 100644 (file)
@@ -28,6 +28,7 @@
 
 class QtCamDevicePrivate;
 class QtCamImageModePrivate;
 
 class QtCamDevicePrivate;
 class QtCamImageModePrivate;
+class QtCamImageResolution;
 class QtCamImageSettings;
 
 class QtCamImageMode : public QtCamMode {
 class QtCamImageSettings;
 
 class QtCamImageMode : public QtCamMode {
@@ -42,10 +43,12 @@ public:
 
   bool capture(const QString& fileName);
 
 
   bool capture(const QString& fileName);
 
-  bool setSettings(const QtCamImageSettings& settings);
+  bool setResolution(const QtCamImageResolution& resolution);
 
   void setProfile(GstEncodingProfile *profile);
 
 
   void setProfile(GstEncodingProfile *profile);
 
+  QtCamImageSettings *settings() const;
+
 protected:
   virtual void start();
   virtual void stop();
 protected:
   virtual void start();
   virtual void stop();
index 0208fd1..1f95296 100644 (file)
@@ -19,8 +19,9 @@
  */
 
 #include "qtcamimagesettings.h"
  */
 
 #include "qtcamimagesettings.h"
+#include <QSharedData>
 
 
-class QtCamImageSettingsPrivate {
+class QtCamImageResolutionPrivate : public QSharedData {
 public:
   QString id;
   QString name;
 public:
   QString id;
   QString name;
@@ -29,14 +30,25 @@ public:
   QSize viewfinder;
   int fps;
   int nightFps;
   QSize viewfinder;
   int fps;
   int nightFps;
+  int megaPixels;
+  QString aspectRatio;
 };
 
 };
 
-QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& name,
-                                      const QSize& capture, const QSize& preview,
-                                      const QSize& viewfinder,
-                                      int fps, int nightFps) :
-  d_ptr(new QtCamImageSettingsPrivate) {
+class QtCamImageSettingsPrivate : public QSharedData {
+public:
+  QString id;
+  QString suffix;
+  QString profileName;
+  QString profilePath;
+  QList<QtCamImageResolution> resolutions;
+};
 
 
+
+QtCamImageResolution::QtCamImageResolution(const QString& id, const QString& name,
+                                          const QSize& capture, const QSize& preview,
+                                          const QSize& viewfinder, int fps, int nightFps,
+                                          int megaPixels, QString aspectRatio) :
+  d_ptr(new QtCamImageResolutionPrivate) {
   d_ptr->id = id;
   d_ptr->name = name;
   d_ptr->capture = capture;
   d_ptr->id = id;
   d_ptr->name = name;
   d_ptr->capture = capture;
@@ -44,61 +56,142 @@ QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& name,
   d_ptr->viewfinder = viewfinder;
   d_ptr->fps = fps;
   d_ptr->nightFps = nightFps;
   d_ptr->viewfinder = viewfinder;
   d_ptr->fps = fps;
   d_ptr->nightFps = nightFps;
+  d_ptr->megaPixels = megaPixels;
+  d_ptr->aspectRatio = aspectRatio;
 }
 
 }
 
-QtCamImageSettings::QtCamImageSettings(const QtCamImageSettings& other) :
-  d_ptr(new QtCamImageSettingsPrivate) {
-
-  d_ptr->id = other.d_ptr->id;
-  d_ptr->name = other.d_ptr->name;
-  d_ptr->capture = other.d_ptr->capture;
-  d_ptr->preview = other.d_ptr->preview;
-  d_ptr->viewfinder = other.d_ptr->viewfinder;
-  d_ptr->fps = other.d_ptr->fps;
-  d_ptr->nightFps = other.d_ptr->nightFps;
-}
+QtCamImageResolution::QtCamImageResolution(const QtCamImageResolution& other) :
+  d_ptr(other.d_ptr) {
 
 
-QtCamImageSettings::~QtCamImageSettings() {
-  delete d_ptr;
 }
 
 }
 
-QtCamImageSettings& QtCamImageSettings::operator=(const QtCamImageSettings&
-                                                               other) {
-  d_ptr->id = other.d_ptr->id;
-  d_ptr->name = other.d_ptr->name;
-  d_ptr->capture = other.d_ptr->capture;
-  d_ptr->preview = other.d_ptr->preview;
-  d_ptr->viewfinder = other.d_ptr->viewfinder;
-  d_ptr->fps = other.d_ptr->fps;
-  d_ptr->nightFps = other.d_ptr->nightFps;
+QtCamImageResolution& QtCamImageResolution::operator=(const QtCamImageResolution& other) {
+  d_ptr = other.d_ptr;
 
   return *this;
 }
 
 
   return *this;
 }
 
-QString QtCamImageSettings::id() const {
+QtCamImageResolution::~QtCamImageResolution() {
+  // QSharedData will take care of reference counting.
+}
+
+QString QtCamImageResolution::id() const {
   return d_ptr->id;
 }
 
   return d_ptr->id;
 }
 
-QString QtCamImageSettings::name() const {
+QString QtCamImageResolution::name() const {
   return d_ptr->name;
 }
 
   return d_ptr->name;
 }
 
-QSize QtCamImageSettings::captureResolution() const {
+QSize QtCamImageResolution::captureResolution() const {
   return d_ptr->capture;
 }
 
   return d_ptr->capture;
 }
 
-QSize QtCamImageSettings::viewfinderResolution() const {
+QSize QtCamImageResolution::viewfinderResolution() const {
   return d_ptr->viewfinder;
 }
 
   return d_ptr->viewfinder;
 }
 
-QSize QtCamImageSettings::previewResolution() const {
+QSize QtCamImageResolution::previewResolution() const {
   return d_ptr->preview;
 }
 
   return d_ptr->preview;
 }
 
-int QtCamImageSettings::frameRate() const {
+int QtCamImageResolution::frameRate() const {
   return d_ptr->fps;
 }
 
   return d_ptr->fps;
 }
 
-int QtCamImageSettings::nightFrameRate() const {
+int QtCamImageResolution::nightFrameRate() const {
   return d_ptr->nightFps;
 }
   return d_ptr->nightFps;
 }
+
+int QtCamImageResolution::megaPixels() const {
+  return d_ptr->megaPixels;
+}
+
+QString QtCamImageResolution::aspectRatio() const {
+  return d_ptr->aspectRatio;
+}
+
+QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& suffix,
+                                      const QString& profileName, const QString& profilePath,
+                                      const QList<QtCamImageResolution>& resolutions) :
+  d_ptr(new QtCamImageSettingsPrivate) {
+
+  d_ptr->id = id;
+  d_ptr->suffix = suffix;
+  d_ptr->profileName = profileName;
+  d_ptr->profilePath = profilePath;
+  d_ptr->resolutions = resolutions;
+}
+
+QtCamImageSettings::QtCamImageSettings(const QtCamImageSettings& other) :
+  d_ptr(other.d_ptr) {
+
+}
+
+QtCamImageSettings& QtCamImageSettings::operator=(const QtCamImageSettings& other) {
+  d_ptr = other.d_ptr;
+
+  return *this;
+}
+
+QtCamImageSettings::~QtCamImageSettings() {
+  // QSharedData will take care of reference counting.
+}
+
+QString QtCamImageSettings::id() const {
+  return d_ptr->id;
+}
+
+QString QtCamImageSettings::suffix() const {
+  return d_ptr->suffix;
+}
+
+QString QtCamImageSettings::profileName() const {
+  return d_ptr->profileName;
+}
+
+QString QtCamImageSettings::profilePath() const {
+  return d_ptr->profilePath;
+}
+
+QtCamImageResolution QtCamImageSettings::defaultResolution(const QString& aspectRatio) const {
+  if (aspectRatio.isEmpty()) {
+    return d_ptr->resolutions[0];
+  }
+
+  foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
+    if (r.aspectRatio() == aspectRatio) {
+      return r;
+    }
+  }
+
+  return d_ptr->resolutions[0];
+}
+
+QList<QtCamImageResolution> QtCamImageSettings::resolutions(const QString& aspectRatio) const {
+  if (aspectRatio.isEmpty()) {
+    return d_ptr->resolutions;
+  }
+
+  QList<QtCamImageResolution> res;
+
+  foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
+    if (r.aspectRatio() == aspectRatio) {
+      res << r;
+    }
+  }
+
+  return d_ptr->resolutions;
+}
+
+QStringList QtCamImageSettings::aspectRatios() const {
+  QStringList aspects;
+
+  foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
+    if (aspects.indexOf(r.aspectRatio()) == -1) {
+      aspects << r.aspectRatio();
+    }
+  }
+
+  return aspects;
+}
index f61e34a..9ea079b 100644 (file)
 #include <QSize>
 #include <QPair>
 #include <QString>
 #include <QSize>
 #include <QPair>
 #include <QString>
+#include <QSharedDataPointer>
+#include <QStringList>
 
 class QtCamImageSettingsPrivate;
 
 class QtCamImageSettingsPrivate;
+class QtCamImageResolutionPrivate;
 
 
-class QtCamImageSettings {
+class QtCamImageResolution {
 public:
 public:
-  QtCamImageSettings(const QString& id, const QString& name, const QSize& capture,
-                    const QSize& preview, const QSize& viewfinder,
-                    int fps, int nightFps);
+  QtCamImageResolution(const QString& id, const QString& name, const QSize& capture,
+                      const QSize& preview, const QSize& viewfinder,
+                      int fps, int nightFps, int megaPixels, QString aspectRatio);
+  QtCamImageResolution(const QtCamImageResolution& other);
 
 
-  QtCamImageSettings(const QtCamImageSettings& other);
+  QtCamImageResolution& operator=(const QtCamImageResolution& other);
 
 
-  ~QtCamImageSettings();
-
-  QtCamImageSettings& operator=(const QtCamImageSettings& other);
+  ~QtCamImageResolution();
 
   QString id() const;
   QString name() const;
 
   QString id() const;
   QString name() const;
@@ -48,9 +50,34 @@ public:
   QSize previewResolution() const;
   int frameRate() const;
   int nightFrameRate() const;
   QSize previewResolution() const;
   int frameRate() const;
   int nightFrameRate() const;
+  int megaPixels() const;
+  QString aspectRatio() const;
+
+private:
+  QSharedDataPointer<QtCamImageResolutionPrivate> d_ptr;
+};
+
+class QtCamImageSettings {
+public:
+  QtCamImageSettings(const QString& id, const QString& suffix, const QString& profileName,
+                    const QString& profilePath, const QList<QtCamImageResolution>& resolutions);
+  QtCamImageSettings(const QtCamImageSettings& other);
+
+  QtCamImageSettings& operator=(const QtCamImageSettings& other);
+
+  ~QtCamImageSettings();
+
+  QString id() const;
+  QString suffix() const;
+  QString profileName() const;
+  QString profilePath() const;
+
+  QtCamImageResolution defaultResolution(const QString& aspectRatio = QString()) const;
+  QList<QtCamImageResolution> resolutions(const QString& aspectRatio = QString()) const;
+  QStringList aspectRatios() const;
 
 private:
 
 private:
-  QtCamImageSettingsPrivate *d_ptr;
+  QSharedDataPointer<QtCamImageSettingsPrivate> d_ptr;
 };
 
 #endif /* QT_CAM_IMAGE_SETTINGS_H */
 };
 
 #endif /* QT_CAM_IMAGE_SETTINGS_H */
index 87177cf..d3d8885 100644 (file)
@@ -29,11 +29,14 @@ class QtCamVideoModePrivate : public QtCamModePrivate {
 public:
   QtCamVideoModePrivate(QtCamDevicePrivate *dev) :
   QtCamModePrivate(dev),
 public:
   QtCamVideoModePrivate(QtCamDevicePrivate *dev) :
   QtCamModePrivate(dev),
-  settings(dev->conf->defaultVideoSettings()) {
+  settings(dev->conf->videoSettings(dev->id)),
+  resolution(settings->defaultResolution()) {
 
   }
 
 
   }
 
-  ~QtCamVideoModePrivate() {}
+  ~QtCamVideoModePrivate() {
+    delete settings;
+  }
 
   void _d_idleStateChanged(bool isIdle) {
     if (isIdle && dev->active == dev->video) {
 
   void _d_idleStateChanged(bool isIdle) {
     if (isIdle && dev->active == dev->video) {
@@ -42,7 +45,8 @@ public:
     }
   }
 
     }
   }
 
-  QtCamVideoSettings settings;
+  QtCamVideoSettings *settings;
+  QtCamVideoResolution resolution;
 };
 
 QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
 };
 
 QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
@@ -75,13 +79,13 @@ bool QtCamVideoMode::canCapture() {
 void QtCamVideoMode::applySettings() {
   bool night = d_ptr->inNightMode();
 
 void QtCamVideoMode::applySettings() {
   bool night = d_ptr->inNightMode();
 
-  int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
+  int fps = night ? d->resolution.nightFrameRate() : d->resolution.frameRate();
 
 
-  d_ptr->setCaps("viewfinder-caps", d->settings.captureResolution(), fps);
+  d_ptr->setCaps("viewfinder-caps", d->resolution.captureResolution(), fps);
 
 
-  d_ptr->setCaps("video-capture-caps", d->settings.captureResolution(), fps);
+  d_ptr->setCaps("video-capture-caps", d->resolution.captureResolution(), fps);
 
 
-  setPreviewSize(d->settings.previewResolution());
+  setPreviewSize(d->resolution.previewResolution());
 
   // TODO:
   //  d_ptr->resetCaps("image-capture-caps");
 
   // TODO:
   //  d_ptr->resetCaps("image-capture-caps");
@@ -128,8 +132,8 @@ void QtCamVideoMode::stopRecording() {
   }
 }
 
   }
 }
 
-bool QtCamVideoMode::setSettings(const QtCamVideoSettings& settings) {
-  d->settings = settings;
+bool QtCamVideoMode::setResolution(const QtCamVideoResolution& resolution) {
+  d->resolution = resolution;
 
   if (!d_ptr->dev->q_ptr->isRunning() || isRecording()) {
     return false;
 
   if (!d_ptr->dev->q_ptr->isRunning() || isRecording()) {
     return false;
@@ -149,4 +153,8 @@ void QtCamVideoMode::setProfile(GstEncodingProfile *profile) {
   g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
 }
 
   g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
 }
 
+QtCamVideoSettings *QtCamVideoMode::settings() {
+  return d->settings;
+}
+
 #include "moc_qtcamvideomode.cpp"
 #include "moc_qtcamvideomode.cpp"
index d47f1f4..909403d 100644 (file)
@@ -28,6 +28,7 @@
 
 class QtCamDevicePrivate;
 class QtCamVideoModePrivate;
 
 class QtCamDevicePrivate;
 class QtCamVideoModePrivate;
+class QtCamVideoResolution;
 class QtCamVideoSettings;
 
 class QtCamVideoMode : public QtCamMode {
 class QtCamVideoSettings;
 
 class QtCamVideoMode : public QtCamMode {
@@ -45,10 +46,12 @@ public:
   bool isRecording();
   Q_INVOKABLE bool startRecording(const QString& fileName);
 
   bool isRecording();
   Q_INVOKABLE bool startRecording(const QString& fileName);
 
-  bool setSettings(const QtCamVideoSettings& settings);
+  bool setResolution(const QtCamVideoResolution& resolution);
 
   void setProfile(GstEncodingProfile *profile);
 
 
   void setProfile(GstEncodingProfile *profile);
 
+  QtCamVideoSettings *settings();
+
 public slots:
   void stopRecording();
 
 public slots:
   void stopRecording();
 
index 06f561d..5383c41 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "qtcamvideosettings.h"
 
 
 #include "qtcamvideosettings.h"
 
-class QtCamVideoSettingsPrivate {
+class QtCamVideoResolutionPrivate : public QSharedData {
 public:
   QString id;
   QString name;
 public:
   QString id;
   QString name;
@@ -28,68 +28,164 @@ public:
   QSize preview;
   int fps;
   int nightFps;
   QSize preview;
   int fps;
   int nightFps;
+  QString aspectRatio;
+  QString resolution;
 };
 
 };
 
-QtCamVideoSettings::QtCamVideoSettings(const QString& id, const QString& name,
-                                      const QSize& capture, const QSize& preview,
-                                      int fps, int nightFps) :
-  d_ptr(new QtCamVideoSettingsPrivate) {
+class QtCamVideoSettingsPrivate : public QSharedData {
+public:
+  QString id;
+  QString suffix;
+  QString profileName;
+  QString profilePath;
+  QList<QtCamVideoResolution> resolutions;
+};
 
 
+QtCamVideoResolution::QtCamVideoResolution(const QString& id, const QString& name,
+                                          const QSize& capture, const QSize& preview,
+                                          int fps, int nightFps,
+                                          const QString& aspectRatio,
+                                          const QString& resolution) :
+  d_ptr(new QtCamVideoResolutionPrivate) {
   d_ptr->id = id;
   d_ptr->name = name;
   d_ptr->capture = capture;
   d_ptr->preview = preview;
   d_ptr->fps = fps;
   d_ptr->nightFps = nightFps;
   d_ptr->id = id;
   d_ptr->name = name;
   d_ptr->capture = capture;
   d_ptr->preview = preview;
   d_ptr->fps = fps;
   d_ptr->nightFps = nightFps;
+  d_ptr->aspectRatio = aspectRatio;
+  d_ptr->resolution = resolution;
 }
 
 }
 
-QtCamVideoSettings::QtCamVideoSettings(const QtCamVideoSettings& other) :
-  d_ptr(new QtCamVideoSettingsPrivate) {
-
-  d_ptr->id = other.d_ptr->id;
-  d_ptr->name = other.d_ptr->name;
-  d_ptr->capture = other.d_ptr->capture;
-  d_ptr->preview = other.d_ptr->preview;
-  d_ptr->fps = other.d_ptr->fps;
-  d_ptr->nightFps = other.d_ptr->nightFps;
-}
+QtCamVideoResolution::QtCamVideoResolution(const QtCamVideoResolution& other) :
+  d_ptr(other.d_ptr) {
 
 
-QtCamVideoSettings::~QtCamVideoSettings() {
-  delete d_ptr;
 }
 
 }
 
-QtCamVideoSettings& QtCamVideoSettings::operator=(const QtCamVideoSettings&
-                                                               other) {
-  d_ptr->id = other.d_ptr->id;
-  d_ptr->name = other.d_ptr->name;
-  d_ptr->capture = other.d_ptr->capture;
-  d_ptr->preview = other.d_ptr->preview;
-  d_ptr->fps = other.d_ptr->fps;
-  d_ptr->nightFps = other.d_ptr->nightFps;
+QtCamVideoResolution& QtCamVideoResolution::operator=(const QtCamVideoResolution& other) {
+  d_ptr = other.d_ptr;
 
   return *this;
 }
 
 
   return *this;
 }
 
-QString QtCamVideoSettings::id() const {
+QtCamVideoResolution::~QtCamVideoResolution() {
+  // QSharedData will take care of reference counting.
+}
+
+QString QtCamVideoResolution::id() const {
   return d_ptr->id;
 }
 
   return d_ptr->id;
 }
 
-QString QtCamVideoSettings::name() const {
+QString QtCamVideoResolution::name() const {
   return d_ptr->name;
 }
 
   return d_ptr->name;
 }
 
-QSize QtCamVideoSettings::captureResolution() const {
+QSize QtCamVideoResolution::captureResolution() const {
   return d_ptr->capture;
 }
 
   return d_ptr->capture;
 }
 
-QSize QtCamVideoSettings::previewResolution() const {
+QSize QtCamVideoResolution::previewResolution() const {
   return d_ptr->preview;
 }
 
   return d_ptr->preview;
 }
 
-int QtCamVideoSettings::frameRate() const {
+int QtCamVideoResolution::frameRate() const {
   return d_ptr->fps;
 }
 
   return d_ptr->fps;
 }
 
-int QtCamVideoSettings::nightFrameRate() const {
+int QtCamVideoResolution::nightFrameRate() const {
   return d_ptr->nightFps;
 }
   return d_ptr->nightFps;
 }
+
+QString QtCamVideoResolution::aspectRatio() const {
+  return d_ptr->aspectRatio;
+}
+
+QString QtCamVideoResolution::resolution() const {
+  return d_ptr->resolution;
+}
+
+QtCamVideoSettings::QtCamVideoSettings(const QString& id, const QString& suffix,
+                                      const QString& profileName,
+                                      const QString& profilePath,
+                                      const QList<QtCamVideoResolution>& resolutions) :
+  d_ptr(new QtCamVideoSettingsPrivate) {
+
+  d_ptr->id = id;
+  d_ptr->suffix = suffix;
+  d_ptr->profileName = profileName;
+  d_ptr->profilePath = profilePath;
+  d_ptr->resolutions = resolutions;
+}
+
+QtCamVideoSettings::QtCamVideoSettings(const QtCamVideoSettings& other) :
+  d_ptr(other.d_ptr) {
+
+}
+
+QtCamVideoSettings& QtCamVideoSettings::operator=(const QtCamVideoSettings& other) {
+  d_ptr = other.d_ptr;
+
+  return *this;
+}
+
+QtCamVideoSettings::~QtCamVideoSettings() {
+  // QSharedData will take care of reference counting.
+}
+
+QString QtCamVideoSettings::id() const {
+  return d_ptr->id;
+}
+
+QString QtCamVideoSettings::suffix() const {
+  return d_ptr->suffix;
+}
+
+QString QtCamVideoSettings::profileName() const {
+  return d_ptr->profileName;
+}
+
+QString QtCamVideoSettings::profilePath() const {
+  return d_ptr->profilePath;
+}
+
+QtCamVideoResolution QtCamVideoSettings::defaultResolution(const QString& aspectRatio) const {
+  if (aspectRatio.isEmpty()) {
+    return d_ptr->resolutions[0];
+  }
+
+  foreach (const QtCamVideoResolution& r, d_ptr->resolutions) {
+    if (r.aspectRatio() == aspectRatio) {
+      return r;
+    }
+  }
+
+  return d_ptr->resolutions[0];
+}
+
+QList<QtCamVideoResolution> QtCamVideoSettings::resolutions(const QString& aspectRatio) const {
+  if (aspectRatio.isEmpty()) {
+    return d_ptr->resolutions;
+  }
+
+  QList<QtCamVideoResolution> res;
+
+  foreach (const QtCamVideoResolution& r, d_ptr->resolutions) {
+    if (r.aspectRatio() == aspectRatio) {
+      res << r;
+    }
+  }
+
+  return d_ptr->resolutions;
+}
+
+QStringList QtCamVideoSettings::aspectRatios() const {
+  QStringList aspects;
+
+  foreach (const QtCamVideoResolution& r, d_ptr->resolutions) {
+    if (aspects.indexOf(r.aspectRatio()) == -1) {
+      aspects << r.aspectRatio();
+    }
+  }
+
+  return aspects;
+}
index c3d3b60..0ab7044 100644 (file)
 #include <QSize>
 #include <QPair>
 #include <QString>
 #include <QSize>
 #include <QPair>
 #include <QString>
+#include <QSharedDataPointer>
+#include <QStringList>
 
 class QtCamVideoSettingsPrivate;
 
 class QtCamVideoSettingsPrivate;
+class QtCamVideoResolutionPrivate;
 
 
-class QtCamVideoSettings {
+class QtCamVideoResolution {
 public:
 public:
-  QtCamVideoSettings(const QString& id, const QString& name,
-                    const QSize& capture, const QSize& preview,
-                    int fps, int nightFps);
-
-  QtCamVideoSettings(const QtCamVideoSettings& other);
-
-  ~QtCamVideoSettings();
+  QtCamVideoResolution(const QString& id, const QString& name, const QSize& capture,
+                      const QSize& preview, int fps, int nightFps,
+                      const QString& aspectRatio, const QString& resolution);
+  QtCamVideoResolution(const QtCamVideoResolution& other);
+  QtCamVideoResolution& operator=(const QtCamVideoResolution& other);
 
 
-  QtCamVideoSettings& operator=(const QtCamVideoSettings& other);
+  ~QtCamVideoResolution();
 
   QString id() const;
   QString name() const;
 
   QString id() const;
   QString name() const;
@@ -47,9 +48,34 @@ public:
   QSize previewResolution() const;
   int frameRate() const;
   int nightFrameRate() const;
   QSize previewResolution() const;
   int frameRate() const;
   int nightFrameRate() const;
+  QString aspectRatio() const;
+  QString resolution() const;
+
+private:
+  QSharedDataPointer<QtCamVideoResolutionPrivate> d_ptr;
+};
+
+class QtCamVideoSettings {
+public:
+  QtCamVideoSettings(const QString& id, const QString& suffix, const QString& profileName,
+                    const QString& profilePath, const QList<QtCamVideoResolution>& resolutions);
+  QtCamVideoSettings(const QtCamVideoSettings& other);
+
+  QtCamVideoSettings& operator=(const QtCamVideoSettings& other);
+
+  ~QtCamVideoSettings();
+
+  QString id() const;
+  QString suffix() const;
+  QString profileName() const;
+  QString profilePath() const;
+
+  QtCamVideoResolution defaultResolution(const QString& aspectRatio = QString()) const;
+  QList<QtCamVideoResolution> resolutions(const QString& aspectRatio = QString()) const;
+  QStringList aspectRatios() const;
 
 private:
 
 private:
-  QtCamVideoSettingsPrivate *d_ptr;
+  QSharedDataPointer<QtCamVideoSettingsPrivate> d_ptr;
 };
 
 #endif /* QT_CAM_VIDEO_SETTINGS_H */
 };
 
 #endif /* QT_CAM_VIDEO_SETTINGS_H */