Set viewfinder-caps before video-capture-caps otherwise we get an error while subdevs...
[harmattan/cameraplus] / lib / qtcamvideomode.cpp
1 #include "qtcamvideomode.h"
2 #include "qtcammode_p.h"
3 #include <QDebug>
4 #include "qtcamdevice_p.h"
5 #include "qtcamdevice.h"
6 #include "qtcamvideosettings.h"
7
8 class QtCamVideoModePrivate : public QtCamModePrivate {
9 public:
10   QtCamVideoModePrivate(QtCamDevicePrivate *dev) :
11   QtCamModePrivate(dev),
12   settings(dev->conf->defaultVideoSettings()) {
13
14   }
15
16   ~QtCamVideoModePrivate() {}
17
18   QtCamVideoSettings settings;
19 };
20
21 QtCamVideoMode::QtCamVideoMode(QtCamDevicePrivate *d, QObject *parent) :
22   QtCamMode(new QtCamVideoModePrivate(d), "mode-video", "video-done", parent) {
23
24   d_ptr = (QtCamVideoModePrivate *)QtCamMode::d_ptr;
25
26   QString name = d_ptr->dev->conf->videoEncodingProfileName();
27   QString path = d_ptr->dev->conf->videoEncodingProfilePath();
28
29   if (!name.isEmpty() && !path.isEmpty()) {
30     GstEncodingProfile *profile = d_ptr->loadProfile(path, name);
31     if (profile) {
32       setProfile(profile);
33     }
34   }
35 }
36
37 QtCamVideoMode::~QtCamVideoMode() {
38
39 }
40
41 bool QtCamVideoMode::canCapture() {
42   return d_ptr->dev->q_ptr->isIdle();
43 }
44
45 void QtCamVideoMode::applySettings() {
46   setCaps("viewfinder-caps", d_ptr->settings.captureResolution(),
47           d_ptr->settings.frameRate());
48
49   setCaps("video-capture-caps", d_ptr->settings.captureResolution(),
50           d_ptr->settings.frameRate());
51
52   setPreviewSize(d_ptr->settings.previewResolution());
53 }
54
55 void QtCamVideoMode::start() {
56   // Nothing
57 }
58
59 void QtCamVideoMode::stop() {
60   if (isRecording()) {
61     stopRecording();
62   }
63 }
64
65 bool QtCamVideoMode::isRecording() {
66   return !d_ptr->dev->q_ptr->isIdle();
67 }
68
69 bool QtCamVideoMode::startRecording(const QString& fileName) {
70   if (!canCapture() || isRecording()) {
71     return false;
72   }
73
74   setFileName(fileName);
75
76   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
77   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
78
79   return true;
80 }
81
82 bool QtCamVideoMode::stopRecording() {
83   if (isRecording()) {
84     g_signal_emit_by_name(d_ptr->dev->cameraBin, "stop-capture", NULL);
85   }
86
87   return true;
88 }
89
90 bool QtCamVideoMode::setSettings(const QtCamVideoSettings& settings) {
91   d_ptr->settings = settings;
92
93   if (isRecording()) {
94     return false;
95   }
96
97   applySettings();
98
99   return true;
100 }
101
102
103 void QtCamVideoMode::setProfile(GstEncodingProfile *profile) {
104   if (!d_ptr->dev->cameraBin) {
105     gst_encoding_profile_unref(profile);
106     return;
107   }
108
109   g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
110 }