@@ -16,6 +16,25 @@ constexpr char kVideoRecordedEvent[] = "video_recorded";
16
16
constexpr char kCameraClosingEvent [] = " camera_closing" ;
17
17
constexpr char kErrorEvent [] = " error" ;
18
18
19
+ // Camera error codes
20
+ constexpr char kCameraAccessDenied [] = " CameraAccessDenied" ;
21
+ constexpr char kCameraError [] = " camera_error" ;
22
+ constexpr char kPluginDisposed [] = " plugin_disposed" ;
23
+
24
+ std::string GetErrorCode (CameraResult result) {
25
+ assert (result != CameraResult::kSuccess );
26
+
27
+ switch (result) {
28
+ case CameraResult::kAccessDenied :
29
+ return kCameraAccessDenied ;
30
+
31
+ case CameraResult::kSuccess :
32
+ case CameraResult::kError :
33
+ default :
34
+ return kCameraError ;
35
+ }
36
+ }
37
+
19
38
CameraImpl::CameraImpl (const std::string& device_id)
20
39
: device_id_(device_id), Camera(device_id) {}
21
40
@@ -24,7 +43,7 @@ CameraImpl::~CameraImpl() {
24
43
OnCameraClosing ();
25
44
26
45
capture_controller_ = nullptr ;
27
- SendErrorForPendingResults (" plugin_disposed " ,
46
+ SendErrorForPendingResults (kPluginDisposed ,
28
47
" Plugin disposed before request was handled" );
29
48
}
30
49
@@ -121,11 +140,13 @@ void CameraImpl::OnCreateCaptureEngineSucceeded(int64_t texture_id) {
121
140
}
122
141
}
123
142
124
- void CameraImpl::OnCreateCaptureEngineFailed (const std::string& error) {
143
+ void CameraImpl::OnCreateCaptureEngineFailed (CameraResult result,
144
+ const std::string& error) {
125
145
auto pending_result =
126
146
GetPendingResultByType (PendingResultType::kCreateCamera );
127
147
if (pending_result) {
128
- pending_result->Error (" camera_error" , error);
148
+ std::string error_code = GetErrorCode (result);
149
+ pending_result->Error (error_code, error);
129
150
}
130
151
}
131
152
@@ -141,10 +162,12 @@ void CameraImpl::OnStartPreviewSucceeded(int32_t width, int32_t height) {
141
162
}
142
163
};
143
164
144
- void CameraImpl::OnStartPreviewFailed (const std::string& error) {
165
+ void CameraImpl::OnStartPreviewFailed (CameraResult result,
166
+ const std::string& error) {
145
167
auto pending_result = GetPendingResultByType (PendingResultType::kInitialize );
146
168
if (pending_result) {
147
- pending_result->Error (" camera_error" , error);
169
+ std::string error_code = GetErrorCode (result);
170
+ pending_result->Error (error_code, error);
148
171
}
149
172
};
150
173
@@ -156,11 +179,13 @@ void CameraImpl::OnResumePreviewSucceeded() {
156
179
}
157
180
}
158
181
159
- void CameraImpl::OnResumePreviewFailed (const std::string& error) {
182
+ void CameraImpl::OnResumePreviewFailed (CameraResult result,
183
+ const std::string& error) {
160
184
auto pending_result =
161
185
GetPendingResultByType (PendingResultType::kResumePreview );
162
186
if (pending_result) {
163
- pending_result->Error (" camera_error" , error);
187
+ std::string error_code = GetErrorCode (result);
188
+ pending_result->Error (error_code, error);
164
189
}
165
190
}
166
191
@@ -172,11 +197,13 @@ void CameraImpl::OnPausePreviewSucceeded() {
172
197
}
173
198
}
174
199
175
- void CameraImpl::OnPausePreviewFailed (const std::string& error) {
200
+ void CameraImpl::OnPausePreviewFailed (CameraResult result,
201
+ const std::string& error) {
176
202
auto pending_result =
177
203
GetPendingResultByType (PendingResultType::kPausePreview );
178
204
if (pending_result) {
179
- pending_result->Error (" camera_error" , error);
205
+ std::string error_code = GetErrorCode (result);
206
+ pending_result->Error (error_code, error);
180
207
}
181
208
}
182
209
@@ -187,10 +214,12 @@ void CameraImpl::OnStartRecordSucceeded() {
187
214
}
188
215
};
189
216
190
- void CameraImpl::OnStartRecordFailed (const std::string& error) {
217
+ void CameraImpl::OnStartRecordFailed (CameraResult result,
218
+ const std::string& error) {
191
219
auto pending_result = GetPendingResultByType (PendingResultType::kStartRecord );
192
220
if (pending_result) {
193
- pending_result->Error (" camera_error" , error);
221
+ std::string error_code = GetErrorCode (result);
222
+ pending_result->Error (error_code, error);
194
223
}
195
224
};
196
225
@@ -201,10 +230,12 @@ void CameraImpl::OnStopRecordSucceeded(const std::string& file_path) {
201
230
}
202
231
};
203
232
204
- void CameraImpl::OnStopRecordFailed (const std::string& error) {
233
+ void CameraImpl::OnStopRecordFailed (CameraResult result,
234
+ const std::string& error) {
205
235
auto pending_result = GetPendingResultByType (PendingResultType::kStopRecord );
206
236
if (pending_result) {
207
- pending_result->Error (" camera_error" , error);
237
+ std::string error_code = GetErrorCode (result);
238
+ pending_result->Error (error_code, error);
208
239
}
209
240
};
210
241
@@ -215,11 +246,13 @@ void CameraImpl::OnTakePictureSucceeded(const std::string& file_path) {
215
246
}
216
247
};
217
248
218
- void CameraImpl::OnTakePictureFailed (const std::string& error) {
249
+ void CameraImpl::OnTakePictureFailed (CameraResult result,
250
+ const std::string& error) {
219
251
auto pending_take_picture_result =
220
252
GetPendingResultByType (PendingResultType::kTakePicture );
221
253
if (pending_take_picture_result) {
222
- pending_take_picture_result->Error (" camera_error" , error);
254
+ std::string error_code = GetErrorCode (result);
255
+ pending_take_picture_result->Error (error_code, error);
223
256
}
224
257
};
225
258
@@ -238,9 +271,10 @@ void CameraImpl::OnVideoRecordSucceeded(const std::string& file_path,
238
271
}
239
272
}
240
273
241
- void CameraImpl::OnVideoRecordFailed (const std::string& error){};
274
+ void CameraImpl::OnVideoRecordFailed (CameraResult result,
275
+ const std::string& error){};
242
276
243
- void CameraImpl::OnCaptureError (const std::string& error) {
277
+ void CameraImpl::OnCaptureError (CameraResult result, const std::string& error) {
244
278
if (messenger_ && camera_id_ >= 0 ) {
245
279
auto channel = GetMethodChannel ();
246
280
@@ -250,7 +284,8 @@ void CameraImpl::OnCaptureError(const std::string& error) {
250
284
channel->InvokeMethod (kErrorEvent , std::move (message_data));
251
285
}
252
286
253
- SendErrorForPendingResults (" capture_error" , error);
287
+ std::string error_code = GetErrorCode (result);
288
+ SendErrorForPendingResults (error_code, error);
254
289
}
255
290
256
291
void CameraImpl::OnCameraClosing () {
0 commit comments