2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "qtcamimagemode.h"
22 #include "qtcammode_p.h"
23 #include "qtcamdevice_p.h"
24 #include "qtcamimagesettings.h"
25 #include "qtcamdevice.h"
27 class QtCamImageModePrivate : public QtCamModePrivate {
29 QtCamImageModePrivate(QtCamDevicePrivate *dev) :
30 QtCamModePrivate(dev),
31 settings(dev->conf->imageSettings(dev->id)),
32 resolution(settings->defaultResolution()) {
36 ~QtCamImageModePrivate() {
40 QtCamImageSettings *settings;
41 QtCamImageResolution resolution;
44 QtCamImageMode::QtCamImageMode(QtCamDevicePrivate *dev, QObject *parent) :
45 QtCamMode(new QtCamImageModePrivate(dev), "mode-image", "image-done", parent) {
47 d = (QtCamImageModePrivate *)d_ptr;
49 QString name = d_ptr->dev->conf->imageEncodingProfileName();
50 QString path = d_ptr->dev->conf->imageEncodingProfilePath();
52 if (!name.isEmpty() && !path.isEmpty()) {
53 GstEncodingProfile *profile = d_ptr->loadProfile(path, name);
60 QtCamImageMode::~QtCamImageMode() {
64 bool QtCamImageMode::canCapture() {
65 return QtCamMode::canCapture() && d_ptr->dev->isWrapperReady();
68 void QtCamImageMode::applySettings() {
69 bool night = d_ptr->inNightMode();
71 int fps = night ? d->resolution.nightFrameRate() : d->resolution.frameRate();
73 d_ptr->setCaps("viewfinder-caps", d->resolution.viewfinderResolution(), fps);
76 // Ideally, we should query the image-capture-supported-caps and get a proper framerate
77 // as it seems that subdevsrc2 can only capture 15 FPS for at least the highest resolution
78 // we use. For now we will not set any FPS.
79 d_ptr->setCaps("image-capture-caps", d->resolution.captureResolution(), -1);
81 setPreviewSize(d->resolution.previewResolution());
84 // d_ptr->resetCaps("video-capture-caps");
87 void QtCamImageMode::start() {
91 void QtCamImageMode::stop() {
95 bool QtCamImageMode::capture(const QString& fileName) {
100 if (fileName.isEmpty()) {
104 setFileName(fileName);
106 g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
107 g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
112 bool QtCamImageMode::setResolution(const QtCamImageResolution& resolution) {
113 d->resolution = resolution;
115 if (!d_ptr->dev->q_ptr->isRunning()) {
116 // We will return true here because setting the resolution on a non-running pipeline
117 // doesn't make much sense (Probably the only use case is as a kind of optimization only).
118 // We will set it anyway when the pipeline gets started.
122 if (!d_ptr->dev->q_ptr->isIdle()) {
131 void QtCamImageMode::setProfile(GstEncodingProfile *profile) {
132 if (!d_ptr->dev->cameraBin) {
133 gst_encoding_profile_unref(profile);
137 g_object_set(d_ptr->dev->cameraBin, "image-profile", profile, NULL);
140 QtCamImageSettings *QtCamImageMode::settings() const {