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.
+# devices section.
+# Here we use an enum to tell subdevsrc2 which camera to use.
[devices]
scanner=enum
property=camera-device
+# GStreaemer elements
[video-source]
element=subdevsrc2
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]
-presets=image-low,image-medium,image-high
-default=image-medium
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
-[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
+megapixels = 7
+aspectratio=16:9
-[image-medium]
+[image-medium-16:9]
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
+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
preview = 640x480
fps = 30
night = 10
+aspectratio=4:3
+resolution=VGA
[video-medium]
name=medium
preview = 848x480
fps = 30
night = 10
+aspectratio=16:9
+resolution=WVGA
[video-high]
name=high
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
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;
QObject(parent), d_ptr(new QtCamConfigPrivate) {
d_ptr->conf = new QSettings(configPath, QSettings::IniFormat, this);
-
- defaultImageSettings();
}
QtCamConfig::~QtCamConfig() {
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 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;
public:
QtCamImageModePrivate(QtCamDevicePrivate *dev) :
QtCamModePrivate(dev),
- settings(dev->conf->defaultImageSettings()) {
+ settings(dev->conf->imageSettings(dev->id)),
+ resolution(settings->defaultResolution()) {
}
~QtCamImageModePrivate() {
+ delete settings;
}
- QtCamImageSettings settings;
+ QtCamImageSettings *settings;
+ QtCamImageResolution resolution;
};
QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *dev, QObject *parent) :
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.
- 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");
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;
g_object_set(d_ptr->dev->cameraBin, "image-profile", profile, NULL);
}
+
+QtCamImageSettings *QtCamImageMode::settings() const {
+ return d->settings;
+}
class QtCamDevicePrivate;
class QtCamImageModePrivate;
+class QtCamImageResolution;
class QtCamImageSettings;
class QtCamImageMode : public QtCamMode {
bool capture(const QString& fileName);
- bool setSettings(const QtCamImageSettings& settings);
+ bool setResolution(const QtCamImageResolution& resolution);
void setProfile(GstEncodingProfile *profile);
+ QtCamImageSettings *settings() const;
+
protected:
virtual void start();
virtual void stop();
*/
#include "qtcamimagesettings.h"
+#include <QSharedData>
-class QtCamImageSettingsPrivate {
+class QtCamImageResolutionPrivate : public QSharedData {
public:
QString id;
QString name;
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->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;
}
-QString QtCamImageSettings::id() const {
+QtCamImageResolution::~QtCamImageResolution() {
+ // QSharedData will take care of reference counting.
+}
+
+QString QtCamImageResolution::id() const {
return d_ptr->id;
}
-QString QtCamImageSettings::name() const {
+QString QtCamImageResolution::name() const {
return d_ptr->name;
}
-QSize QtCamImageSettings::captureResolution() const {
+QSize QtCamImageResolution::captureResolution() const {
return d_ptr->capture;
}
-QSize QtCamImageSettings::viewfinderResolution() const {
+QSize QtCamImageResolution::viewfinderResolution() const {
return d_ptr->viewfinder;
}
-QSize QtCamImageSettings::previewResolution() const {
+QSize QtCamImageResolution::previewResolution() const {
return d_ptr->preview;
}
-int QtCamImageSettings::frameRate() const {
+int QtCamImageResolution::frameRate() const {
return d_ptr->fps;
}
-int QtCamImageSettings::nightFrameRate() const {
+int QtCamImageResolution::nightFrameRate() const {
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;
+}
#include <QSize>
#include <QPair>
#include <QString>
+#include <QSharedDataPointer>
+#include <QStringList>
class QtCamImageSettingsPrivate;
+class QtCamImageResolutionPrivate;
-class QtCamImageSettings {
+class QtCamImageResolution {
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;
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:
- QtCamImageSettingsPrivate *d_ptr;
+ QSharedDataPointer<QtCamImageSettingsPrivate> d_ptr;
};
#endif /* QT_CAM_IMAGE_SETTINGS_H */
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) {
}
}
- QtCamVideoSettings settings;
+ QtCamVideoSettings *settings;
+ QtCamVideoResolution resolution;
};
QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
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");
}
}
-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;
g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
}
+QtCamVideoSettings *QtCamVideoMode::settings() {
+ return d->settings;
+}
+
#include "moc_qtcamvideomode.cpp"
class QtCamDevicePrivate;
class QtCamVideoModePrivate;
+class QtCamVideoResolution;
class QtCamVideoSettings;
class QtCamVideoMode : public QtCamMode {
bool isRecording();
Q_INVOKABLE bool startRecording(const QString& fileName);
- bool setSettings(const QtCamVideoSettings& settings);
+ bool setResolution(const QtCamVideoResolution& resolution);
void setProfile(GstEncodingProfile *profile);
+ QtCamVideoSettings *settings();
+
public slots:
void stopRecording();
#include "qtcamvideosettings.h"
-class QtCamVideoSettingsPrivate {
+class QtCamVideoResolutionPrivate : public QSharedData {
public:
QString id;
QString name;
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->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;
}
-QString QtCamVideoSettings::id() const {
+QtCamVideoResolution::~QtCamVideoResolution() {
+ // QSharedData will take care of reference counting.
+}
+
+QString QtCamVideoResolution::id() const {
return d_ptr->id;
}
-QString QtCamVideoSettings::name() const {
+QString QtCamVideoResolution::name() const {
return d_ptr->name;
}
-QSize QtCamVideoSettings::captureResolution() const {
+QSize QtCamVideoResolution::captureResolution() const {
return d_ptr->capture;
}
-QSize QtCamVideoSettings::previewResolution() const {
+QSize QtCamVideoResolution::previewResolution() const {
return d_ptr->preview;
}
-int QtCamVideoSettings::frameRate() const {
+int QtCamVideoResolution::frameRate() const {
return d_ptr->fps;
}
-int QtCamVideoSettings::nightFrameRate() const {
+int QtCamVideoResolution::nightFrameRate() const {
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;
+}
#include <QSize>
#include <QPair>
#include <QString>
+#include <QSharedDataPointer>
+#include <QStringList>
class QtCamVideoSettingsPrivate;
+class QtCamVideoResolutionPrivate;
-class QtCamVideoSettings {
+class QtCamVideoResolution {
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;
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:
- QtCamVideoSettingsPrivate *d_ptr;
+ QSharedDataPointer<QtCamVideoSettingsPrivate> d_ptr;
};
#endif /* QT_CAM_VIDEO_SETTINGS_H */