Merge lp:~uriboni/camera-app/switch-via-camera-position-api into lp:camera-app/staging

Proposed by Ugo Riboni
Status: Merged
Approved by: Florian Boucault
Approved revision: 652
Merged at revision: 689
Proposed branch: lp:~uriboni/camera-app/switch-via-camera-position-api
Merge into: lp:camera-app/staging
Diff against target: 300 lines (+48/-48)
5 files modified
CameraApp/advancedcamerasettings.cpp (+30/-26)
CameraApp/advancedcamerasettings.h (+4/-6)
ViewFinderGeometry.qml (+2/-2)
ViewFinderOverlay.qml (+10/-11)
ViewFinderView.qml (+2/-3)
To merge this branch: bzr merge lp:~uriboni/camera-app/switch-via-camera-position-api
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+286498@code.launchpad.net

Commit message

Set Camera.position to switch front/back cameras instead of AdvancedCameraSettings and hardcoded camera indexes

Description of the change

Set Camera.position to switch front/back cameras instead of AdvancedCameraSettings and hardcoded camera indexes

Note that https://code.launchpad.net/~uriboni/qtubuntu-camera/cameras-info/+merge/286283 is required for this to work

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

Merge changes from parent branch

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

Works well, thank you

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CameraApp/advancedcamerasettings.cpp'
2--- CameraApp/advancedcamerasettings.cpp 2016-01-28 09:52:25 +0000
3+++ CameraApp/advancedcamerasettings.cpp 2016-04-05 12:16:20 +0000
4@@ -36,7 +36,6 @@
5
6 AdvancedCameraSettings::AdvancedCameraSettings(QObject *parent) :
7 QObject(parent),
8- m_activeCameraIndex(0),
9 m_cameraObject(0),
10 m_camera(0),
11 m_deviceSelector(0),
12@@ -45,6 +44,7 @@
13 m_cameraExposureControl(0),
14 m_imageEncoderControl(0),
15 m_videoEncoderControl(0),
16+ m_cameraInfoControl(0),
17 m_hdrEnabled(false)
18 {
19 }
20@@ -183,16 +183,23 @@
21 return videoEncoderControl;
22 }
23
24+QCameraInfoControl* AdvancedCameraSettings::cameraInfoControlFromCamera(QCamera *camera) const
25+{
26+ QMediaControl *control = mediaControlFromCamera(camera, QCameraInfoControl_iid);
27+ QCameraInfoControl *infoControl = qobject_cast<QCameraInfoControl*>(control);
28+
29+ if (infoControl == 0) {
30+ qWarning() << "No info control support";
31+ }
32+
33+ return infoControl;
34+}
35+
36 QObject* AdvancedCameraSettings::camera() const
37 {
38 return m_cameraObject;
39 }
40
41-int AdvancedCameraSettings::activeCameraIndex() const
42-{
43- return m_activeCameraIndex;
44-}
45-
46 void AdvancedCameraSettings::setCamera(QObject *cameraObject)
47 {
48 if (cameraObject != m_cameraObject) {
49@@ -210,15 +217,25 @@
50
51 QVideoDeviceSelectorControl* selector = selectorFromCamera(m_camera);
52 m_deviceSelector = selector;
53- if (selector) {
54- m_deviceSelector->setSelectedDevice(m_activeCameraIndex);
55- }
56+ connect(m_deviceSelector, SIGNAL(selectedDeviceChanged(int)),
57+ this, SLOT(onSelectedDeviceChanged(int)));
58 }
59
60 Q_EMIT cameraChanged();
61 }
62 }
63
64+void AdvancedCameraSettings::onSelectedDeviceChanged(int index)
65+{
66+ Q_UNUSED(index);
67+
68+ Q_EMIT resolutionChanged();
69+ Q_EMIT maximumResolutionChanged();
70+ Q_EMIT fittingResolutionChanged();
71+ Q_EMIT hasFlashChanged();
72+ Q_EMIT videoSupportedResolutionsChanged();
73+}
74+
75 void AdvancedCameraSettings::readCapabilities()
76 {
77 m_viewFinderControl = viewfinderFromCamera(m_camera);
78@@ -249,6 +266,7 @@
79
80 m_imageEncoderControl = imageEncoderControlFromCamera(m_camera);
81 m_videoEncoderControl = videoEncoderControlFromCamera(m_camera);
82+ m_cameraInfoControl = cameraInfoControlFromCamera(m_camera);
83
84 Q_EMIT resolutionChanged();
85 Q_EMIT maximumResolutionChanged();
86@@ -267,22 +285,6 @@
87 }
88 }
89
90-void AdvancedCameraSettings::setActiveCameraIndex(int index)
91-{
92- if (index != m_activeCameraIndex) {
93- m_activeCameraIndex = index;
94- if (m_deviceSelector) {
95- m_deviceSelector->setSelectedDevice(m_activeCameraIndex);
96- }
97- Q_EMIT activeCameraIndexChanged();
98- Q_EMIT resolutionChanged();
99- Q_EMIT maximumResolutionChanged();
100- Q_EMIT fittingResolutionChanged();
101- Q_EMIT hasFlashChanged();
102- Q_EMIT videoSupportedResolutionsChanged();
103- }
104-}
105-
106 QSize AdvancedCameraSettings::resolution() const
107 {
108 if (m_viewFinderControl != 0) {
109@@ -417,7 +419,9 @@
110 // When using the front camera on krillin, using resolution 640x480 does
111 // not work properly and results in stretched videos. Remove it from
112 // the list of supported resolutions.
113- if (activeCameraIndex() == 1 && size.width() == 640 && size.height() == 480) {
114+ QString currentDeviceName = m_deviceSelector->deviceName(m_deviceSelector->selectedDevice());
115+ if (m_cameraInfoControl->cameraPosition(currentDeviceName) == QCamera::FrontFace &&
116+ size.width() == 640 && size.height() == 480) {
117 continue;
118 }
119 sizesAsStrings.append(QString("%1x%2").arg(size.width()).arg(size.height()));
120
121=== modified file 'CameraApp/advancedcamerasettings.h'
122--- CameraApp/advancedcamerasettings.h 2016-01-05 13:08:28 +0000
123+++ CameraApp/advancedcamerasettings.h 2016-04-05 12:16:20 +0000
124@@ -23,6 +23,7 @@
125 #include <QObject>
126 #include <QMultimedia>
127 #include <QtMultimedia/QCamera>
128+#include <QtMultimedia/QCameraInfoControl>
129 #include <QtMultimedia/QVideoDeviceSelectorControl>
130 #include <QtMultimedia/QCameraViewfinderSettingsControl>
131 #include <QtMultimedia/QCameraExposureControl>
132@@ -37,8 +38,6 @@
133 {
134 Q_OBJECT
135 Q_PROPERTY (QObject* camera READ camera WRITE setCamera NOTIFY cameraChanged)
136- Q_PROPERTY (int activeCameraIndex READ activeCameraIndex WRITE setActiveCameraIndex
137- NOTIFY activeCameraIndexChanged)
138 Q_PROPERTY (QSize resolution READ resolution NOTIFY resolutionChanged)
139 Q_PROPERTY (QSize imageCaptureResolution READ imageCaptureResolution)
140 Q_PROPERTY (QSize videoRecorderResolution READ videoRecorderResolution)
141@@ -53,9 +52,7 @@
142 public:
143 explicit AdvancedCameraSettings(QObject *parent = 0);
144 QObject* camera() const;
145- int activeCameraIndex() const;
146 void setCamera(QObject* camera);
147- void setActiveCameraIndex(int index);
148 QSize resolution() const;
149 QSize imageCaptureResolution() const;
150 QSize videoRecorderResolution() const;
151@@ -73,7 +70,6 @@
152
153 Q_SIGNALS:
154 void cameraChanged();
155- void activeCameraIndexChanged();
156 void resolutionChanged();
157 void maximumResolutionChanged();
158 void fittingResolutionChanged();
159@@ -86,6 +82,7 @@
160 private Q_SLOTS:
161 void onCameraStateChanged();
162 void onExposureValueChanged(int parameter);
163+ void onSelectedDeviceChanged(int index);
164
165 private:
166 QVideoDeviceSelectorControl* selectorFromCamera(QCamera *camera) const;
167@@ -97,17 +94,18 @@
168 QMediaControl* mediaControlFromCamera(QCamera *camera, const char* iid) const;
169 QImageEncoderControl* imageEncoderControlFromCamera(QCamera *camera) const;
170 QVideoEncoderSettingsControl* videoEncoderControlFromCamera(QCamera *camera) const;
171+ QCameraInfoControl* cameraInfoControlFromCamera(QCamera *camera) const;
172
173 QObject* m_cameraObject;
174 QCamera* m_camera;
175 QVideoDeviceSelectorControl* m_deviceSelector;
176- int m_activeCameraIndex;
177 QCameraViewfinderSettingsControl* m_viewFinderControl;
178 QCameraControl* m_cameraControl;
179 QCameraFlashControl* m_cameraFlashControl;
180 QCameraExposureControl* m_cameraExposureControl;
181 QImageEncoderControl* m_imageEncoderControl;
182 QVideoEncoderSettingsControl* m_videoEncoderControl;
183+ QCameraInfoControl* m_cameraInfoControl;
184 bool m_hdrEnabled;
185 };
186
187
188=== modified file 'ViewFinderGeometry.qml'
189--- ViewFinderGeometry.qml 2015-11-03 14:23:10 +0000
190+++ ViewFinderGeometry.qml 2016-04-05 12:16:20 +0000
191@@ -24,9 +24,9 @@
192 property int viewFinderWidth;
193 property int viewFinderOrientation;
194
195- property int __cameraWidth: Math.abs(viewFinderOrientation) == 90 ?
196+ property int __cameraWidth: Math.abs(viewFinderOrientation) == 90 || Math.abs(viewFinderOrientation) == 270 ?
197 cameraResolution.height : cameraResolution.width
198- property int __cameraHeight: Math.abs(viewFinderOrientation) == 90 ?
199+ property int __cameraHeight: Math.abs(viewFinderOrientation) == 90 || Math.abs(viewFinderOrientation) == 270 ?
200 cameraResolution.width : cameraResolution.height
201
202 property real widthScale: viewFinderWidth / __cameraWidth
203
204=== modified file 'ViewFinderOverlay.qml'
205--- ViewFinderOverlay.qml 2016-03-23 14:49:34 +0000
206+++ ViewFinderOverlay.qml 2016-04-05 12:16:20 +0000
207@@ -55,8 +55,7 @@
208 property bool playShutterSound: true
209 // FIXME: stores the resolution selected for 2 cameras. Instead it should:
210 // - support any number of cameras
211- // - not rely on the camera index but on Camera.deviceId
212- // Ref.: http://doc.qt.io/qt-5/qml-qtmultimedia-camera.html#deviceId-prop
213+ // - not assume that camera.deviceId is a string containing an integer
214 property string photoResolution0
215 property string photoResolution1
216
217@@ -99,7 +98,7 @@
218 Binding {
219 target: camera.imageCapture
220 property: "resolution"
221- value: settings["photoResolution" + camera.advanced.activeCameraIndex]
222+ value: settings["photoResolution" + camera.deviceId]
223 }
224
225 Connections {
226@@ -220,9 +219,9 @@
227 }
228
229 // If resolution setting is not supported select the resolution automatically
230- var photoResolution = settings["photoResolution" + camera.advanced.activeCameraIndex];
231+ var photoResolution = settings["photoResolution" + camera.deviceId];
232 if (!isResolutionAnOption(photoResolution)) {
233- settings["photoResolution" + camera.advanced.activeCameraIndex] = getAutomaticResolution();
234+ settings["photoResolution" + camera.deviceId] = getAutomaticResolution();
235 }
236 }
237
238@@ -261,18 +260,18 @@
239 }
240
241 Connections {
242- target: camera.advanced
243- onActiveCameraIndexChanged: {
244- var hasPhotoResolutionSetting = (settings["photoResolution" + camera.advanced.activeCameraIndex] != "")
245+ target: camera
246+ onDeviceIdChanged: {
247+ var hasPhotoResolutionSetting = (settings["photoResolution" + camera.deviceId] != "")
248 // FIXME: use camera.advanced.imageCaptureResolution instead of camera.imageCapture.resolution
249 // because the latter is not updated when the backend changes the resolution
250- settings["photoResolution" + camera.advanced.activeCameraIndex] = sizeToString(camera.advanced.imageCaptureResolution);
251+ settings["photoResolution" + camera.deviceId] = sizeToString(camera.advanced.imageCaptureResolution);
252 settings.videoResolution = sizeToString(camera.advanced.videoRecorderResolution);
253 updateResolutionOptions();
254
255 // If no resolution has ever been chosen, select one automatically
256 if (!hasPhotoResolutionSetting) {
257- settings["photoResolution" + camera.advanced.activeCameraIndex] = getAutomaticResolution();
258+ settings["photoResolution" + camera.deviceId] = getAutomaticResolution();
259 }
260 }
261 }
262@@ -558,7 +557,7 @@
263 ListModel {
264 id: photoResolutionOptionsModel
265
266- property string settingsProperty: "photoResolution" + camera.advanced.activeCameraIndex
267+ property string settingsProperty: "photoResolution" + camera.deviceId
268 property string icon: ""
269 property string label: sizeToAspectRatio(stringToSize(settings[settingsProperty]))
270 property bool isToggle: false
271
272=== modified file 'ViewFinderView.qml'
273--- ViewFinderView.qml 2016-03-23 14:49:34 +0000
274+++ ViewFinderView.qml 2016-04-05 12:16:20 +0000
275@@ -56,7 +56,7 @@
276 id: camera
277 captureMode: Camera.CaptureStillImage
278 cameraState: Camera.UnloadedState
279- StateSaver.properties: "captureMode"
280+ StateSaver.properties: "captureMode, position"
281 property bool failedToConnect: false
282
283 function manualFocus(x, y) {
284@@ -89,7 +89,6 @@
285 property AdvancedCameraSettings advanced: AdvancedCameraSettings {
286 id: advancedCamera
287 camera: camera
288- StateSaver.properties: "activeCameraIndex"
289 }
290
291 /* Use only digital zoom for now as it's what phone cameras mostly use.
292@@ -171,7 +170,7 @@
293 viewFinder.width = 1;
294 viewFinder.height = 1;
295 camera.cameraState = Camera.LoadedState;
296- camera.advanced.activeCameraIndex = (camera.advanced.activeCameraIndex === 0) ? 1 : 0;
297+ camera.position = (camera.position === Camera.FrontFace) ? Camera.BackFace : Camera.FrontFace;
298 decideCameraState();
299 viewFinderSwitcherRotation.angle = 180;
300 }

Subscribers

People subscribed via source and target branches