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"
28 class QtCamVideoModePrivate : public QtCamModePrivate {
30 QtCamVideoModePrivate(QtCamDevicePrivate *dev) :
31 QtCamModePrivate(dev),
32 settings(dev->conf->defaultVideoSettings()) {
36 ~QtCamVideoModePrivate() {}
38 void _d_idleStateChanged(bool isIdle) {
39 if (isIdle && dev->active == dev->video) {
40 QMetaObject::invokeMethod(dev->video, "recordingStateChanged");
41 QMetaObject::invokeMethod(dev->video, "canCaptureChanged");
45 QtCamVideoSettings settings;
48 QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *dev, QObject *parent) :
49 QtCamMode(new QtCamVideoModePrivate(dev), "mode-video", "video-done", parent) {
51 d = (QtCamVideoModePrivate *)QtCamMode::d_ptr;
53 QString name = d_ptr->dev->conf->videoEncodingProfileName();
54 QString path = d_ptr->dev->conf->videoEncodingProfilePath();
56 if (!name.isEmpty() && !path.isEmpty()) {
57 GstEncodingProfile *profile = d_ptr->loadProfile(path, name);
63 QObject::connect(d_ptr->dev->q_ptr, SIGNAL(idleStateChanged(bool)),
64 this, SLOT(_d_idleStateChanged(bool)));
67 QtCamVideoMode::~QtCamVideoMode() {
71 bool QtCamVideoMode::canCapture() {
72 return QtCamMode::canCapture() && d_ptr->dev->q_ptr->isIdle();
75 void QtCamVideoMode::applySettings() {
76 bool night = d_ptr->inNightMode();
78 int fps = night ? d->settings.nightFrameRate() : d->settings.frameRate();
80 d_ptr->setCaps("viewfinder-caps", d->settings.captureResolution(), fps);
82 d_ptr->setCaps("video-capture-caps", d->settings.captureResolution(), fps);
84 setPreviewSize(d->settings.previewResolution());
87 // d_ptr->resetCaps("image-capture-caps");
90 void QtCamVideoMode::start() {
94 void QtCamVideoMode::stop() {
100 bool QtCamVideoMode::isRecording() {
101 return !d_ptr->dev->q_ptr->isIdle();
104 bool QtCamVideoMode::startRecording(const QString& fileName) {
105 if (!canCapture() || isRecording()) {
109 if (fileName.isEmpty()) {
113 setFileName(fileName);
115 g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
116 g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
118 emit recordingStateChanged();
120 emit canCaptureChanged();
125 void QtCamVideoMode::stopRecording() {
127 g_signal_emit_by_name(d_ptr->dev->cameraBin, "stop-capture", NULL);
131 bool QtCamVideoMode::setSettings(const QtCamVideoSettings& settings) {
132 d->settings = settings;
134 if (!d_ptr->dev->q_ptr->isRunning() || isRecording()) {
143 void QtCamVideoMode::setProfile(GstEncodingProfile *profile) {
144 if (!d_ptr->dev->cameraBin) {
145 gst_encoding_profile_unref(profile);
149 g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
152 #include "moc_qtcamvideomode.cpp"