Initial implementation
[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("video-capture-caps", d_ptr->settings.captureResolution(),
47           d_ptr->settings.frameRate());
48   setCaps("viewfinder-caps", d_ptr->settings.captureResolution(),
49           d_ptr->settings.frameRate());
50   setPreviewSize(d_ptr->settings.previewResolution());
51 }
52
53 void QtCamVideoMode::start() {
54   // Nothing
55 }
56
57 void QtCamVideoMode::stop() {
58   if (isRecording()) {
59     stopRecording();
60   }
61 }
62
63 bool QtCamVideoMode::isRecording() {
64   return !d_ptr->dev->q_ptr->isIdle();
65 }
66
67 bool QtCamVideoMode::startRecording(const QString& fileName) {
68   if (!canCapture() || isRecording()) {
69     return false;
70   }
71
72   setFileName(fileName);
73
74   g_object_set(d_ptr->dev->cameraBin, "location", fileName.toUtf8().data(), NULL);
75   g_signal_emit_by_name(d_ptr->dev->cameraBin, "start-capture", NULL);
76
77   return true;
78 }
79
80 bool QtCamVideoMode::stopRecording() {
81   if (isRecording()) {
82     g_signal_emit_by_name(d_ptr->dev->cameraBin, "stop-capture", NULL);
83   }
84
85   return true;
86 }
87
88 bool QtCamVideoMode::setSettings(const QtCamVideoSettings& settings) {
89   d_ptr->settings = settings;
90
91   if (isRecording()) {
92     return false;
93   }
94
95   applySettings();
96
97   return true;
98 }
99
100
101 void QtCamVideoMode::setProfile(GstEncodingProfile *profile) {
102   if (!d_ptr->dev->cameraBin) {
103     gst_encoding_profile_unref(profile);
104     return;
105   }
106
107   g_object_set(d_ptr->dev->cameraBin, "video-profile", profile, NULL);
108 }