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 "qtcamvideomode.h"
22 #include "qtcammode_p.h"
24 #include "qtcamdevice_p.h"
25 #include "qtcamdevice.h"
26 #include "qtcamvideosettings.h"
27 #include "qtcamnotifications.h"
29 class QtCamVideoModePrivate : public QtCamModePrivate {
31 QtCamVideoModePrivate(QtCamDevicePrivate *dev) :
32 QtCamModePrivate(dev),
33 settings(dev->conf->videoSettings(dev->id)),
34 resolution(settings->defaultResolution()) {
38 ~QtCamVideoModePrivate() {
42 void _d_idleStateChanged(bool isIdle) {
43 if (isIdle && dev->active == dev->video) {
44 QMetaObject::invokeMethod(dev->video, "recordingStateChanged");
45 QMetaObject::invokeMethod(dev->video, "canCaptureChanged");
49 QtCamVideoSettings *settings;
50 QtCamVideoResolution resolution;
53 QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
54 QtCamMode(new QtCamVideoModePrivate(dev), "mode-video", "video-done", parent) {
56 d = (QtCamVideoModePrivate *)QtCamMode::d_ptr;
58 QString name = d_ptr->dev->conf->videoEncodingProfileName();
59 QString path = d_ptr->dev->conf->videoEncodingProfilePath();
61 if (!name.isEmpty() && !path.isEmpty()) {
62 GstEncodingProfile *profile = d_ptr->loadProfile(path, name);
68 // TODO: Use signals from QtCamNotifications instead ?
69 QObject::connect(d_ptr->dev->q_ptr, SIGNAL(idleStateChanged(bool)),
70 this, SLOT(_d_idleStateChanged(bool)));
73 QtCamVideoMode::~QtCamVideoMode() {
77 bool QtCamVideoMode::canCapture() {
78 return QtCamMode::canCapture() && d_ptr->dev->q_ptr->isIdle();
81 void QtCamVideoMode::applySettings() {
82 bool night = d_ptr->inNightMode();
84 int fps = night ? d->resolution.nightFrameRate() : d->resolution.frameRate();
86 d_ptr->setCaps("viewfinder-caps", d->resolution.captureResolution(), fps);
88 d_ptr->setCaps("video-capture-caps", d->resolution.captureResolution(), fps);
90 setPreviewSize(d->resolution.previewResolution());
92 // Not sure this is needed but just in case.
93 d_ptr->resetCaps("image-capture-caps");
96 void QtCamVideoMode::start() {
100 void QtCamVideoMode::stop() {
106 bool QtCamVideoMode::isRecording() {
107 return !d_ptr->dev->q_ptr->isIdle();
110 bool QtCamVideoMode::startRecording(const QString& fileName) {
111 if (!canCapture() || isRecording()) {
115 if (fileName.isEmpty()) {
119 setFileName(fileName);
121 QMetaObject::invokeMethod(d_ptr->dev->notifications, "videoRecordingStarted");
123 g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
124 g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
126 emit recordingStateChanged();
128 emit canCaptureChanged();
133 void QtCamVideoMode::stopRecording() {
135 g_signal_emit_by_name(d_ptr->dev->cameraBin, "stop-capture", NULL);
139 bool QtCamVideoMode::setResolution(const QtCamVideoResolution& resolution) {
140 d->resolution = resolution;
142 if (!d_ptr->dev->q_ptr->isRunning()) {
143 // We will return true here because setting the resolution on a non-running pipeline
144 // doesn't make much sense (Probably the only use case is as a kind of optimization only).
145 // We will set it anyway when the pipeline gets started.
158 void QtCamVideoMode::setProfile(GstEncodingProfile *profile) {
159 if (!d_ptr->dev->cameraBin) {
160 gst_encoding_profile_unref(profile);
164 g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
167 QtCamVideoSettings *QtCamVideoMode::settings() {
171 #include "moc_qtcamvideomode.cpp"