Adding TODO items
[harmattan/cameraplus] / lib / qtcammode_p.h
1 // -*- c++ -*-
2
3 #ifndef QT_CAM_MODE_P_H
4 #define QT_CAM_MODE_P_H
5
6 #include <QSize>
7 #include "qtcamdevice_p.h"
8 #include <gst/pbutils/encoding-profile.h>
9 #include <gst/pbutils/encoding-target.h>
10
11 class QtCamDevicePrivate;
12 class PreviewImageHandler;
13 class DoneHandler;
14
15 #define CAPS "video/x-raw-yuv, width = (int) %1, height = (int) %2, framerate = (fraction) %3/%4"
16
17 class QtCamModePrivate {
18 public:
19   QtCamModePrivate(QtCamDevicePrivate *d) : id(-1), dev(d), night(false) {}
20   virtual ~QtCamModePrivate() {}
21
22   int modeId(const char *mode) {
23     if (!dev->cameraBin) {
24       return -1;
25     }
26
27     GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(dev->cameraBin),
28                                                      "mode");
29     if (!pspec) {
30       return -1;
31     }
32
33     if (!G_IS_PARAM_SPEC_ENUM(pspec)) {
34       return -1;
35     }
36
37     GParamSpecEnum *e = (GParamSpecEnum *)pspec;
38     GEnumClass *klass = e->enum_class;
39
40     for (unsigned x = 0; x < klass->n_values; x++) {
41       if (QLatin1String(mode) == QLatin1String(klass->values[x].value_nick)) {
42         return klass->values[x].value;
43       }
44     }
45
46     return -1;
47   }
48
49   GstEncodingProfile *loadProfile(const QString& path, const QString& name) {
50     GError *error = NULL;
51
52     GstEncodingTarget *target = gst_encoding_target_load_from_file(path.toUtf8().data(), &error);
53     if (!target) {
54       qCritical() << "Failed to load encoding target from" << path << error->message;
55       g_error_free(error);
56       return 0;
57     }
58
59     GstEncodingProfile *profile = gst_encoding_target_get_profile(target, name.toUtf8().data());
60     if (!profile) {
61       qCritical() << "Failed to load encoding profile from" << path;
62       gst_encoding_target_unref(target);
63       return 0;
64     }
65
66     gst_encoding_target_unref(target);
67
68     return profile;
69   }
70
71   void setCaps(const char *property, const QSize& resolution, const QPair<int, int> frameRate) {
72     if (!dev->cameraBin) {
73       return;
74     }
75
76     // TODO: allow proceeding without specifying a frame rate (maybe we can calculate it ?)
77     if (frameRate.first <= 0 || frameRate.second <= 0) {
78       return;
79     }
80
81     if (resolution.width() <= 0 || resolution.height() <= 0) {
82       return;
83     }
84
85     QString capsString = QString(CAPS)
86       .arg(resolution.width()).arg(resolution.height())
87       .arg(frameRate.first).arg(frameRate.second);
88
89     GstCaps *caps = gst_caps_from_string(capsString.toAscii());
90
91     g_object_set(dev->cameraBin, property, caps, NULL);
92
93     gst_caps_unref(caps);
94   }
95
96   int id;
97   QtCamDevicePrivate *dev;
98   PreviewImageHandler *previewImageHandler;
99   DoneHandler *doneHandler;
100   bool night;
101 };
102
103 #endif /* QT_CAM_MODE_P_H */