Merge lp:~uriboni/qtubuntu-camera/cameras-info into lp:qtubuntu-camera/staging

Proposed by Ugo Riboni
Status: Merged
Approved by: Florian Boucault
Approved revision: 188
Merged at revision: 181
Proposed branch: lp:~uriboni/qtubuntu-camera/cameras-info
Merge into: lp:qtubuntu-camera/staging
Diff against target: 586 lines (+328/-34)
13 files modified
src/aalcamerainfocontrol.cpp (+33/-0)
src/aalcamerainfocontrol.h (+32/-0)
src/aalcameraservice.cpp (+17/-12)
src/aalcameraservice.h (+3/-0)
src/aalcameraserviceplugin.cpp (+71/-5)
src/aalcameraserviceplugin.h (+5/-1)
src/aalvideodeviceselectorcontrol.cpp (+4/-14)
src/src.pro (+2/-0)
unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro (+6/-2)
unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp (+5/-0)
unittests/stubs/qcamerainfo_stub.cpp (+81/-0)
unittests/stubs/qcamerainfodata.cpp (+30/-0)
unittests/stubs/qcamerainfodata.h (+39/-0)
To merge this branch: bzr merge lp:~uriboni/qtubuntu-camera/cameras-info
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Florian Boucault (community) Needs Fixing
Review via email: mp+286283@code.launchpad.net

Commit message

Implement qtmultimedia APIs to query the system for available cameras, their orientation and facing and replace some hardcoded logic to calls to these APIs.

Description of the change

Implement qtmultimedia APIs to query the system for available cameras, their orientation and facing and replace some hardcoded logic to calls to these APIs.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
184. By Ugo Riboni

Fix unit tests

185. By Ugo Riboni

Add useful info the human readable device description

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
186. By Ugo Riboni

Remove debug

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Florian Boucault (fboucault) wrote :

src/aalcameraservice.cpp
control returned by android_camera_connect_by_id() is not kept

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

src/aalcameraserviceplugin.cpp
    return (result != 0) ? QCamera::UnspecifiedPosition :
                           (facing == BACK_FACING_CAMERA_TYPE ? QCamera::BackFace :
                                                                QCamera::FrontFace);

how about using some if blocks to help readability?

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

src/aalcameraserviceplugin.cpp

    if (!ok) return 0;
[...]
    if (!ok) return QCamera::UnspecifiedPosition;

syntax rule is to always use {} for any block, even for 1 liners

review: Needs Fixing
187. By Ugo Riboni

Save the AndroidControl in case there is only one camera.Style fixes

188. By Ugo Riboni

Style fixes

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Terry (mterry) wrote :

I tested this branch and got crashes with the code samples from bug 1514253 or bug 1514250.

Ran like so: "qmlscene test.qml --desktop_file_hint=dialer-app.desktop"

#0 0xb30193a8 in ?? () from /lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
#1 0xb3016ec4 in OPENSSL_cpuid_setup ()
   from /lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
#2 0xb6fe280c in ?? () from /lib/ld-linux-armhf.so.3
#3 0x000243b0 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Revision history for this message
Michael Terry (mterry) wrote :

Oh, and this was the phone:

current build number: 267
device name: mako
channel: ubuntu-touch/rc-proposed/bq-aquaris.en
last update: 2016-03-19 11:53:04
version version: 267
version ubuntu: 20160318
version device: 20160315
version custom: 20160201-5-vivid

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'src/aalcamerainfocontrol.cpp'
--- src/aalcamerainfocontrol.cpp 1970-01-01 00:00:00 +0000
+++ src/aalcamerainfocontrol.cpp 2016-02-24 14:33:23 +0000
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "aalcamerainfocontrol.h"
18
19#include <QCameraInfo>
20
21AalCameraInfoControl::AalCameraInfoControl(QObject *parent) : QCameraInfoControl(parent)
22{
23}
24
25QCamera::Position AalCameraInfoControl::cameraPosition(const QString &deviceName) const
26{
27 return QCameraInfo(deviceName.toLatin1()).position();
28}
29
30int AalCameraInfoControl::cameraOrientation(const QString &deviceName) const
31{
32 return QCameraInfo(deviceName.toLatin1()).orientation();
33}
034
=== added file 'src/aalcamerainfocontrol.h'
--- src/aalcamerainfocontrol.h 1970-01-01 00:00:00 +0000
+++ src/aalcamerainfocontrol.h 2016-02-24 14:33:23 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef AALCAMERAINFOCONTROL_H
18#define AALCAMERAINFOCONTROL_H
19
20#include <QCameraInfoControl>
21
22class AalCameraInfoControl : public QCameraInfoControl
23{
24 Q_OBJECT
25public:
26 AalCameraInfoControl(QObject *parent = 0);
27
28 QCamera::Position cameraPosition(const QString &deviceName) const;
29 int cameraOrientation(const QString &deviceName) const;
30};
31
32#endif // AALCAMERAINFOCONTROL_H
033
=== modified file 'src/aalcameraservice.cpp'
--- src/aalcameraservice.cpp 2016-01-12 12:04:31 +0000
+++ src/aalcameraservice.cpp 2016-02-24 14:33:23 +0000
@@ -27,6 +27,7 @@
27#include "aalvideoencodersettingscontrol.h"27#include "aalvideoencodersettingscontrol.h"
28#include "aalvideorenderercontrol.h"28#include "aalvideorenderercontrol.h"
29#include "aalviewfindersettingscontrol.h"29#include "aalviewfindersettingscontrol.h"
30#include "aalcamerainfocontrol.h"
30#include "storagemanager.h"31#include "storagemanager.h"
31#include "aalcameraexposurecontrol.h"32#include "aalcameraexposurecontrol.h"
3233
@@ -60,6 +61,7 @@
60 m_videoOutput = new AalVideoRendererControl(this);61 m_videoOutput = new AalVideoRendererControl(this);
61 m_viewfinderControl = new AalViewfinderSettingsControl(this);62 m_viewfinderControl = new AalViewfinderSettingsControl(this);
62 m_exposureControl = new AalCameraExposureControl(this);63 m_exposureControl = new AalCameraExposureControl(this);
64 m_infoControl = new AalCameraInfoControl(this);
6365
64 QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance());66 QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance());
65 m_previousApplicationState = application->applicationState();67 m_previousApplicationState = application->applicationState();
@@ -84,6 +86,7 @@
84 delete m_videoOutput;86 delete m_videoOutput;
85 delete m_viewfinderControl;87 delete m_viewfinderControl;
86 delete m_exposureControl;88 delete m_exposureControl;
89 delete m_infoControl;
87 if (m_androidControl)90 if (m_androidControl)
88 android_camera_delete(m_androidControl);91 android_camera_delete(m_androidControl);
89 delete m_storageManager;92 delete m_storageManager;
@@ -130,6 +133,9 @@
130 if (qstrcmp(name, QCameraExposureControl_iid) == 0)133 if (qstrcmp(name, QCameraExposureControl_iid) == 0)
131 return m_exposureControl;134 return m_exposureControl;
132135
136 if (qstrcmp(name, QCameraInfoControl_iid) == 0)
137 return m_infoControl;
138
133 return 0;139 return 0;
134}140}
135141
@@ -153,21 +159,18 @@
153 if (m_androidControl)159 if (m_androidControl)
154 return true;160 return true;
155161
156 CameraType device = BACK_FACING_CAMERA_TYPE;
157 if (!isBackCameraUsed())
158 device = FRONT_FACING_CAMERA_TYPE;
159
160 m_androidListener = new CameraControlListener;162 m_androidListener = new CameraControlListener;
161 memset(m_androidListener, 0, sizeof(*m_androidListener));163 memset(m_androidListener, 0, sizeof(*m_androidListener));
162164
163 m_androidControl = android_camera_connect_to(device, m_androidListener);165 // if there is only one camera fallback directly to the ID of whatever device we have
164166 if (m_deviceSelectControl->deviceCount() == 1) {
165 // fallback if there is only one camera167 m_androidControl = android_camera_connect_by_id(m_deviceSelectControl->selectedDevice(), m_androidListener);
166 if (!m_androidControl && m_deviceSelectControl->deviceCount() == 1) {168 } else {
167 if (device == BACK_FACING_CAMERA_TYPE)169 CameraType device = BACK_FACING_CAMERA_TYPE;
170 if (!isBackCameraUsed()) {
168 device = FRONT_FACING_CAMERA_TYPE;171 device = FRONT_FACING_CAMERA_TYPE;
169 else172 }
170 device = BACK_FACING_CAMERA_TYPE;173
171 m_androidControl = android_camera_connect_to(device, m_androidListener);174 m_androidControl = android_camera_connect_to(device, m_androidListener);
172 }175 }
173176
@@ -232,7 +235,9 @@
232235
233bool AalCameraService::isBackCameraUsed() const236bool AalCameraService::isBackCameraUsed() const
234{237{
235 return m_deviceSelectControl->selectedDevice() == 0;238 int deviceIndex = m_deviceSelectControl->selectedDevice();
239 QString deviceName = m_deviceSelectControl->deviceName(deviceIndex);
240 return m_infoControl->cameraPosition(deviceName) == QCamera::BackFace;
236}241}
237242
238/*!243/*!
239244
=== modified file 'src/aalcameraservice.h'
--- src/aalcameraservice.h 2015-12-16 11:22:04 +0000
+++ src/aalcameraservice.h 2016-02-24 14:33:23 +0000
@@ -34,6 +34,7 @@
34class AalVideoRendererControl;34class AalVideoRendererControl;
35class AalViewfinderSettingsControl;35class AalViewfinderSettingsControl;
36class AalCameraExposureControl;36class AalCameraExposureControl;
37class AalCameraInfoControl;
37class QCameraControl;38class QCameraControl;
3839
39struct CameraControl;40struct CameraControl;
@@ -64,6 +65,7 @@
64 AalVideoRendererControl *videoOutputControl() const { return m_videoOutput; }65 AalVideoRendererControl *videoOutputControl() const { return m_videoOutput; }
65 AalViewfinderSettingsControl *viewfinderControl() const { return m_viewfinderControl; }66 AalViewfinderSettingsControl *viewfinderControl() const { return m_viewfinderControl; }
66 AalCameraExposureControl *exposureControl() const { return m_exposureControl; }67 AalCameraExposureControl *exposureControl() const { return m_exposureControl; }
68 AalCameraInfoControl *infoControl() const { return m_infoControl; }
6769
68 CameraControl *androidControl();70 CameraControl *androidControl();
6971
@@ -110,6 +112,7 @@
110 AalVideoRendererControl *m_videoOutput;112 AalVideoRendererControl *m_videoOutput;
111 AalViewfinderSettingsControl *m_viewfinderControl;113 AalViewfinderSettingsControl *m_viewfinderControl;
112 AalCameraExposureControl *m_exposureControl;114 AalCameraExposureControl *m_exposureControl;
115 AalCameraInfoControl *m_infoControl;
113116
114 CameraControl *m_androidControl;117 CameraControl *m_androidControl;
115 CameraControlListener *m_androidListener;118 CameraControlListener *m_androidListener;
116119
=== modified file 'src/aalcameraserviceplugin.cpp'
--- src/aalcameraserviceplugin.cpp 2013-03-12 16:17:37 +0000
+++ src/aalcameraserviceplugin.cpp 2016-02-24 14:33:23 +0000
@@ -21,6 +21,10 @@
21#include <QMetaType>21#include <QMetaType>
22#include <qgl.h>22#include <qgl.h>
2323
24#include <hybris/camera/camera_compatibility_layer.h>
25#include <hybris/camera/camera_compatibility_layer_capabilities.h>
26
27
24AalServicePlugin::AalServicePlugin()28AalServicePlugin::AalServicePlugin()
25{29{
26}30}
@@ -42,13 +46,75 @@
4246
43QList<QByteArray> AalServicePlugin::devices(const QByteArray &service) const47QList<QByteArray> AalServicePlugin::devices(const QByteArray &service) const
44{48{
45 Q_UNUSED(service);49 QList<QByteArray> deviceList;
46 return QList<QByteArray>();50
51 if (QString::fromLatin1(service) != QLatin1String(Q_MEDIASERVICE_CAMERA)) {
52 return deviceList;
53 }
54
55 // Devices are identified in android only by their index, so we do the same
56 int cameras = android_camera_get_number_of_devices();
57 for (int deviceId = 0; deviceId < cameras; deviceId++) {
58 QString camera("%1");
59 camera = camera.arg(deviceId);
60 deviceList.append(camera.toLatin1());
61 }
62
63 return deviceList;
47}64}
4865
49QString AalServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)66QString AalServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
50{67{
51 Q_UNUSED(service);68 if (QString::fromLatin1(service) != QLatin1String(Q_MEDIASERVICE_CAMERA)) {
52 Q_UNUSED(device);69 return QString();
53 return QString();70 }
71
72 // Android does not provice a descriptive identifier for devices, so we just
73 // send back the index plus some useful human readable information about position.
74 bool ok;
75 int deviceID = device.toInt(&ok, 10);
76 if (!ok || deviceID >= android_camera_get_number_of_devices()) {
77 qWarning() << "Requested description for invalid device ID:" << device;
78 return QString();
79 } else {
80 QCamera::Position position = cameraPosition(device);
81 return QString("Camera %1%2").arg(QLatin1String(device))
82 .arg(position == QCamera::FrontFace ? " Front facing" :
83 (position == QCamera::BackFace ? " Back facing" : ""));
84 }
85}
86
87int AalServicePlugin::cameraOrientation(const QByteArray & device) const
88{
89 int facing;
90 int orientation;
91
92 bool ok;
93 int deviceID = device.toInt(&ok, 10);
94 if (!ok) {
95 return 0;
96 }
97
98 int result = android_camera_get_device_info(deviceID, &facing, &orientation);
99 return (result != 0) ? 0 : orientation;
100}
101
102QCamera::Position AalServicePlugin::cameraPosition(const QByteArray & device) const
103{
104 int facing;
105 int orientation;
106
107 bool ok;
108 int deviceID = device.toInt(&ok, 10);
109 if (!ok) {
110 return QCamera::UnspecifiedPosition;
111 }
112
113 int result = android_camera_get_device_info(deviceID, &facing, &orientation);
114 if (result != 0) {
115 return QCamera::UnspecifiedPosition;
116 } else {
117 return facing == BACK_FACING_CAMERA_TYPE ? QCamera::BackFace :
118 QCamera::FrontFace;
119 }
54}120}
55121
=== modified file 'src/aalcameraserviceplugin.h'
--- src/aalcameraserviceplugin.h 2013-02-11 15:56:21 +0000
+++ src/aalcameraserviceplugin.h 2016-02-24 14:33:23 +0000
@@ -20,10 +20,12 @@
20#include <QMediaServiceProviderPlugin>20#include <QMediaServiceProviderPlugin>
2121
22class AalServicePlugin : public QMediaServiceProviderPlugin,22class AalServicePlugin : public QMediaServiceProviderPlugin,
23 public QMediaServiceSupportedDevicesInterface23 public QMediaServiceSupportedDevicesInterface,
24 public QMediaServiceCameraInfoInterface
24{25{
25 Q_OBJECT26 Q_OBJECT
26 Q_INTERFACES(QMediaServiceSupportedDevicesInterface)27 Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
28 Q_INTERFACES(QMediaServiceCameraInfoInterface)
27 Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "aalcamera.json")29 Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "aalcamera.json")
2830
29public:31public:
@@ -34,6 +36,8 @@
3436
35 QList<QByteArray> devices(const QByteArray &service) const;37 QList<QByteArray> devices(const QByteArray &service) const;
36 QString deviceDescription(const QByteArray &service, const QByteArray &device);38 QString deviceDescription(const QByteArray &service, const QByteArray &device);
39 int cameraOrientation(const QByteArray & device) const;
40 QCamera::Position cameraPosition(const QByteArray & device) const;
37};41};
3842
39#endif43#endif
4044
=== modified file 'src/aalvideodeviceselectorcontrol.cpp'
--- src/aalvideodeviceselectorcontrol.cpp 2015-12-07 15:16:51 +0000
+++ src/aalvideodeviceselectorcontrol.cpp 2016-02-24 14:33:23 +0000
@@ -23,6 +23,7 @@
2323
24#include <QDebug>24#include <QDebug>
25#include <QtMultimedia/QCamera>25#include <QtMultimedia/QCamera>
26#include <QtMultimedia/QCameraInfo>
2627
27#include <hybris/camera/camera_compatibility_layer_capabilities.h>28#include <hybris/camera/camera_compatibility_layer_capabilities.h>
2829
@@ -41,28 +42,17 @@
4142
42int AalVideoDeviceSelectorControl::deviceCount() const43int AalVideoDeviceSelectorControl::deviceCount() const
43{44{
44 if (m_numberOfCameras < 0)45 return QCameraInfo::availableCameras().count();
45 m_numberOfCameras = android_camera_get_number_of_devices();
46
47 return m_numberOfCameras;
48}46}
4947
50QString AalVideoDeviceSelectorControl::deviceDescription(int index) const48QString AalVideoDeviceSelectorControl::deviceDescription(int index) const
51{49{
52 switch (index) {50 return QCameraInfo::availableCameras().value(index).description();
53 case 0: return QLatin1String("Back camera");
54 case 1: return QLatin1String("Front camera");
55 default: return QLatin1String("");
56 }
57}51}
5852
59QString AalVideoDeviceSelectorControl::deviceName(int index) const53QString AalVideoDeviceSelectorControl::deviceName(int index) const
60{54{
61 switch (index) {55 return QCameraInfo::availableCameras().value(index).deviceName();
62 case 0: return QLatin1String("Back");
63 case 1: return QLatin1String("Front");
64 default: return QLatin1String("");
65 }
66}56}
6757
68int AalVideoDeviceSelectorControl::selectedDevice() const58int AalVideoDeviceSelectorControl::selectedDevice() const
6959
=== modified file 'src/src.pro'
--- src/src.pro 2015-11-12 10:32:24 +0000
+++ src/src.pro 2016-02-24 14:33:23 +0000
@@ -29,6 +29,7 @@
29 aalvideoencodersettingscontrol.h \29 aalvideoencodersettingscontrol.h \
30 aalvideorenderercontrol.h \30 aalvideorenderercontrol.h \
31 aalviewfindersettingscontrol.h \31 aalviewfindersettingscontrol.h \
32 aalcamerainfocontrol.h \
32 audiocapture.h \33 audiocapture.h \
33 aalcameraexposurecontrol.h \34 aalcameraexposurecontrol.h \
34 storagemanager.h35 storagemanager.h
@@ -48,6 +49,7 @@
48 aalvideoencodersettingscontrol.cpp \49 aalvideoencodersettingscontrol.cpp \
49 aalvideorenderercontrol.cpp \50 aalvideorenderercontrol.cpp \
50 aalviewfindersettingscontrol.cpp \51 aalviewfindersettingscontrol.cpp \
52 aalcamerainfocontrol.cpp \
51 audiocapture.cpp \53 audiocapture.cpp \
52 aalcameraexposurecontrol.cpp \54 aalcameraexposurecontrol.cpp \
53 storagemanager.cpp55 storagemanager.cpp
5456
=== modified file 'unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro'
--- unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro 2015-12-18 15:16:06 +0000
+++ unittests/aalvideodeviceselectorcontrol/aalvideodeviceselectorcontrol.pro 2016-02-24 14:33:23 +0000
@@ -7,11 +7,13 @@
7LIBS += -L../mocks/aal -laal7LIBS += -L../mocks/aal -laal
8INCLUDEPATH += ../../src8INCLUDEPATH += ../../src
9INCLUDEPATH += ../mocks/aal9INCLUDEPATH += ../mocks/aal
10INCLUDEPATH += ../stubs/
1011
11HEADERS += ../../src/aalvideodeviceselectorcontrol.h \12HEADERS += ../../src/aalvideodeviceselectorcontrol.h \
12 ../../src/aalcameracontrol.h \13 ../../src/aalcameracontrol.h \
13 ../../src/aalcameraservice.h \14 ../../src/aalcameraservice.h \
14 ../../src/aalvideoencodersettingscontrol.h15 ../../src/aalvideoencodersettingscontrol.h \
16 ../stubs/qcamerainfodata.h
1517
16SOURCES += tst_aalvideodeviceselectorcontrol.cpp \18SOURCES += tst_aalvideodeviceselectorcontrol.cpp \
17 ../../src/aalvideodeviceselectorcontrol.cpp \19 ../../src/aalvideodeviceselectorcontrol.cpp \
@@ -19,7 +21,9 @@
19 aalimageencodercontrol.cpp \21 aalimageencodercontrol.cpp \
20 aalviewfindersettingscontrol.cpp \22 aalviewfindersettingscontrol.cpp \
21 ../stubs/aalcameracontrol_stub.cpp \23 ../stubs/aalcameracontrol_stub.cpp \
22 ../stubs/aalvideoencodersettingscontrol_stub.cpp24 ../stubs/aalvideoencodersettingscontrol_stub.cpp \
25 ../stubs/qcamerainfo_stub.cpp \
26 ../stubs/qcamerainfodata.cpp
2327
24check.depends = $${TARGET}28check.depends = $${TARGET}
25check.commands = ./$${TARGET}29check.commands = ./$${TARGET}
2630
=== modified file 'unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp'
--- unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp 2014-07-31 16:44:03 +0000
+++ unittests/aalvideodeviceselectorcontrol/tst_aalvideodeviceselectorcontrol.cpp 2016-02-24 14:33:23 +0000
@@ -21,6 +21,7 @@
2121
22#define private public22#define private public
23#include "aalvideodeviceselectorcontrol.h"23#include "aalvideodeviceselectorcontrol.h"
24#include "qcamerainfodata.h"
2425
25class tst_AalVideoDeviceSelectorControl : public QObject26class tst_AalVideoDeviceSelectorControl : public QObject
26{27{
@@ -53,6 +54,10 @@
53 QSignalSpy spy(m_selectControl, SIGNAL(selectedDeviceChanged(int)));54 QSignalSpy spy(m_selectControl, SIGNAL(selectedDeviceChanged(int)));
54 QSignalSpy spy2(m_selectControl, SIGNAL(selectedDeviceChanged(QString)));55 QSignalSpy spy2(m_selectControl, SIGNAL(selectedDeviceChanged(QString)));
5556
57 QCameraInfoData::availableDevices.clear();
58 QCameraInfoData::availableDevices.append(CameraInfo("0", "Camera 0"));
59 QCameraInfoData::availableDevices.append(CameraInfo("1", "Camera 1"));
60
56 m_selectControl->setSelectedDevice(1);61 m_selectControl->setSelectedDevice(1);
5762
58 QCOMPARE(m_selectControl->selectedDevice(), 1);63 QCOMPARE(m_selectControl->selectedDevice(), 1);
5964
=== added file 'unittests/stubs/qcamerainfo_stub.cpp'
--- unittests/stubs/qcamerainfo_stub.cpp 1970-01-01 00:00:00 +0000
+++ unittests/stubs/qcamerainfo_stub.cpp 2016-02-24 14:33:23 +0000
@@ -0,0 +1,81 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <QtMultimedia/QCameraInfo>
18#include "qcamerainfodata.h"
19
20class QCameraInfoPrivate {
21public:
22 QString deviceID;
23 QString description;
24 int orientation;
25 QCamera::Position position;
26};
27
28QCameraInfo::QCameraInfo(const QByteArray &name) : d(new QCameraInfoPrivate())
29{
30 QStringList info = QString::fromLatin1(name).split('|');
31 d->deviceID = info.at(0);
32 d->description = info.at(1);
33 d->orientation = info.at(2).toInt();
34 d->position = QCamera::Position(info.at(3).toInt());
35}
36
37QCameraInfo::QCameraInfo(const QCamera &camera) : d(new QCameraInfoPrivate()) {
38 Q_UNUSED(camera);
39}
40
41QCameraInfo::QCameraInfo(const QCameraInfo& other) : d(new QCameraInfoPrivate())
42{
43 d->deviceID = other.deviceName();
44 d->description = other.description();
45 d->orientation = other.orientation();
46 d->position = other.position();
47}
48QCameraInfo::~QCameraInfo() { }
49
50QCameraInfo& QCameraInfo::operator=(const QCameraInfo& other) {
51 if (this != &other) {
52 d->deviceID = other.deviceName();
53 d->description = other.description();
54 d->orientation = other.orientation();
55 d->position = other.position();
56 }
57 return *this;
58}
59bool QCameraInfo::operator==(const QCameraInfo &other) const { Q_UNUSED(other); return false; }
60
61bool QCameraInfo::isNull() const { return false; }
62
63QString QCameraInfo::deviceName() const { return d->deviceID; }
64QString QCameraInfo::description() const { return d->description; }
65QCamera::Position QCameraInfo::position() const { return d->position; }
66int QCameraInfo::orientation() const { return d->orientation; }
67
68QCameraInfo QCameraInfo::defaultCamera() { return QCameraInfo(); }
69QList<QCameraInfo> QCameraInfo::availableCameras(QCamera::Position position) {
70 Q_UNUSED(position);
71
72 QList<QCameraInfo> list;
73 Q_FOREACH(CameraInfo info, QCameraInfoData::availableDevices) {
74 QString infoString = QString("%1|%2|%3|%4").arg(info.deviceID).arg(info.description)
75 .arg(info.orientation).arg(info.position);
76 QCameraInfo camera(infoString.toLatin1());
77 list.append(camera);
78 }
79
80 return list;
81}
082
=== added file 'unittests/stubs/qcamerainfodata.cpp'
--- unittests/stubs/qcamerainfodata.cpp 1970-01-01 00:00:00 +0000
+++ unittests/stubs/qcamerainfodata.cpp 2016-02-24 14:33:23 +0000
@@ -0,0 +1,30 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "qcamerainfodata.h"
18
19QList<CameraInfo> QCameraInfoData::availableDevices = QList<CameraInfo>();
20
21CameraInfo::CameraInfo(QString deviceID, QString description,
22 int orientation, QCamera::Position position) :
23 deviceID(deviceID),
24 description(description),
25 orientation(orientation),
26 position(position)
27{
28}
29
30
031
=== added file 'unittests/stubs/qcamerainfodata.h'
--- unittests/stubs/qcamerainfodata.h 1970-01-01 00:00:00 +0000
+++ unittests/stubs/qcamerainfodata.h 2016-02-24 14:33:23 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef QCAMERAINFODATA_H
18#define QCAMERAINFODATA_H
19
20#include <QCamera>
21
22class CameraInfo {
23public:
24 CameraInfo(QString deviceID = QString(), QString description = QString(),
25 int orientation = 0, QCamera::Position position = QCamera::UnspecifiedPosition);
26
27 QString deviceID;
28 QString description;
29 int orientation;
30 QCamera::Position position;
31};
32
33class QCameraInfoData
34{
35public:
36 static QList<CameraInfo> availableDevices;
37};
38
39#endif // QCAMERAINFODATA_H

Subscribers

People subscribed via source and target branches