Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Unified Diff: media/capture/video/mac/video_capture_device_mac.mm

Issue 2129733004: ImageCapture: Implement takePhoto() for Mac AVFoundation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: General cleanup and added VideoCaptureDeviceTest::TakePhoto Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/capture/video/mac/video_capture_device_mac.mm
diff --git a/media/capture/video/mac/video_capture_device_mac.mm b/media/capture/video/mac/video_capture_device_mac.mm
index f032280d68e9a150dc54e94220a5323d7de32b38..8527800f12769262e46d8076468506b39b475321 100644
--- a/media/capture/video/mac/video_capture_device_mac.mm
+++ b/media/capture/video/mac/video_capture_device_mac.mm
@@ -389,6 +389,17 @@ void VideoCaptureDeviceMac::StopAndDeAllocate() {
state_ = kIdle;
}
+void VideoCaptureDeviceMac::TakePhoto(TakePhotoCallback callback) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(state_ == kCapturing) << state_;
+
+ if (photo_callback_) // Only one picture can be in flight at a time.
+ return;
+
+ photo_callback_.reset(new TakePhotoCallback(std::move(callback)));
+ [capture_device_ takePhoto];
+}
+
bool VideoCaptureDeviceMac::Init(
VideoCaptureDevice::Name::CaptureApiType capture_api_type) {
DCHECK(task_runner_->BelongsToCurrentThread());
@@ -413,8 +424,6 @@ void VideoCaptureDeviceMac::ReceiveFrame(const uint8_t* video_frame,
int aspect_numerator,
int aspect_denominator,
base::TimeDelta timestamp) {
- // This method is safe to call from a device capture thread, i.e. any thread
- // controlled by AVFoundation.
if (capture_format_.frame_size != frame_format.frame_size) {
ReceiveError(FROM_HERE,
"Captured resolution " + frame_format.frame_size.ToString() +
@@ -426,6 +435,25 @@ void VideoCaptureDeviceMac::ReceiveFrame(const uint8_t* video_frame,
0, base::TimeTicks::Now(), timestamp);
}
+void VideoCaptureDeviceMac::OnPhotoTaken(const uint8_t* image_data,
+ int image_length,
+ const std::string& mime_type) {
+ DCHECK(photo_callback_);
+ if (!image_data || !image_length) {
+ OnPhotoError();
+ return;
+ }
+ const std::vector<uint8_t> photo(image_data, image_data + image_length);
+ photo_callback_->Run(mojo::String::From(mime_type),
+ mojo::Array<uint8_t>::From(photo));
Robert Sesek 2016/07/08 19:31:04 Does this copy the data? Does it take an rvalue re
mcasas 2016/07/08 21:39:28 From() copies the data in this case [1], which is
Robert Sesek 2016/07/11 15:20:43 But this isn't being copied from the CoreMedia buf
mcasas 2016/07/11 23:29:59 Gotcha, done.
+ photo_callback_.reset();
+}
+
+void VideoCaptureDeviceMac::OnPhotoError() {
+ DLOG(ERROR) << __FUNCTION__ << " error taking picture";
+ photo_callback_.reset();
+}
+
void VideoCaptureDeviceMac::ReceiveError(
const tracked_objects::Location& from_here,
const std::string& reason) {

Powered by Google App Engine
This is Rietveld 408576698