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

Side by Side Diff: media/capture/video/win/video_capture_device_win.cc

Issue 2354783002: ImageCapture: Implement takePhoto() for Windows (Closed)
Patch Set: xianglu@ comments Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « media/capture/video/win/video_capture_device_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/video/win/video_capture_device_win.h" 5 #include "media/capture/video/win/video_capture_device_win.h"
6 6
7 #include <ks.h> 7 #include <ks.h>
8 #include <ksmedia.h> 8 #include <ksmedia.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <list> 11 #include <list>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
16 #include "base/win/scoped_co_mem.h" 16 #include "base/win/scoped_co_mem.h"
17 #include "base/win/scoped_variant.h" 17 #include "base/win/scoped_variant.h"
18 #include "media/base/timestamp_constants.h" 18 #include "media/base/timestamp_constants.h"
19 #include "media/capture/video/blob_utils.h"
19 20
20 using base::win::ScopedCoMem; 21 using base::win::ScopedCoMem;
21 using base::win::ScopedComPtr; 22 using base::win::ScopedComPtr;
22 using base::win::ScopedVariant; 23 using base::win::ScopedVariant;
23 24
24 namespace media { 25 namespace media {
25 26
26 // Check if a Pin matches a category. 27 // Check if a Pin matches a category.
27 bool PinMatchesCategory(IPin* pin, REFGUID category) { 28 bool PinMatchesCategory(IPin* pin, REFGUID category) {
28 DCHECK(pin); 29 DCHECK(pin);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 return; 444 return;
444 } 445 }
445 446
446 graph_builder_->Disconnect(output_capture_pin_.get()); 447 graph_builder_->Disconnect(output_capture_pin_.get());
447 graph_builder_->Disconnect(input_sink_pin_.get()); 448 graph_builder_->Disconnect(input_sink_pin_.get());
448 449
449 client_.reset(); 450 client_.reset();
450 state_ = kIdle; 451 state_ = kIdle;
451 } 452 }
452 453
454 void VideoCaptureDeviceWin::TakePhoto(TakePhotoCallback callback) {
455 DCHECK(thread_checker_.CalledOnValidThread());
456 // DirectShow has other means of capturing still pictures, e.g. connecting a
457 // SampleGrabber filter to a PIN_CATEGORY_STILL of |capture_filter_|. This
458 // way, however, is not widespread and proves too cumbersome, so we just grab
459 // the next captured frame instead.
460 take_photo_callbacks_.push(std::move(callback));
461 }
462
453 // Implements SinkFilterObserver::SinkFilterObserver. 463 // Implements SinkFilterObserver::SinkFilterObserver.
454 void VideoCaptureDeviceWin::FrameReceived(const uint8_t* buffer, 464 void VideoCaptureDeviceWin::FrameReceived(const uint8_t* buffer,
455 int length, 465 int length,
456 base::TimeDelta timestamp) { 466 base::TimeDelta timestamp) {
457 if (first_ref_time_.is_null()) 467 if (first_ref_time_.is_null())
458 first_ref_time_ = base::TimeTicks::Now(); 468 first_ref_time_ = base::TimeTicks::Now();
459 469
460 // There is a chance that the platform does not provide us with the timestamp, 470 // There is a chance that the platform does not provide us with the timestamp,
461 // in which case, we use reference time to calculate a timestamp. 471 // in which case, we use reference time to calculate a timestamp.
462 if (timestamp == media::kNoTimestamp) 472 if (timestamp == media::kNoTimestamp)
463 timestamp = base::TimeTicks::Now() - first_ref_time_; 473 timestamp = base::TimeTicks::Now() - first_ref_time_;
464 474
465 client_->OnIncomingCapturedData(buffer, length, capture_format_, 0, 475 client_->OnIncomingCapturedData(buffer, length, capture_format_, 0,
466 base::TimeTicks::Now(), timestamp); 476 base::TimeTicks::Now(), timestamp);
477
478 while (!take_photo_callbacks_.empty()) {
479 TakePhotoCallback cb = std::move(take_photo_callbacks_.front());
480 take_photo_callbacks_.pop();
481
482 mojom::BlobPtr blob = Blobify(buffer, length, capture_format_);
483 if (blob)
484 cb.Run(std::move(blob));
485 }
467 } 486 }
468 487
469 bool VideoCaptureDeviceWin::CreateCapabilityMap() { 488 bool VideoCaptureDeviceWin::CreateCapabilityMap() {
470 DCHECK(thread_checker_.CalledOnValidThread()); 489 DCHECK(thread_checker_.CalledOnValidThread());
471 ScopedComPtr<IAMStreamConfig> stream_config; 490 ScopedComPtr<IAMStreamConfig> stream_config;
472 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); 491 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive());
473 if (FAILED(hr)) { 492 if (FAILED(hr)) {
474 DPLOG(ERROR) << "Failed to get IAMStreamConfig interface from " 493 DPLOG(ERROR) << "Failed to get IAMStreamConfig interface from "
475 "capture device: " << logging::SystemErrorCodeToString(hr); 494 "capture device: " << logging::SystemErrorCodeToString(hr);
476 return false; 495 return false;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 604 }
586 605
587 void VideoCaptureDeviceWin::SetErrorState( 606 void VideoCaptureDeviceWin::SetErrorState(
588 const tracked_objects::Location& from_here, 607 const tracked_objects::Location& from_here,
589 const std::string& reason) { 608 const std::string& reason) {
590 DCHECK(thread_checker_.CalledOnValidThread()); 609 DCHECK(thread_checker_.CalledOnValidThread());
591 state_ = kError; 610 state_ = kError;
592 client_->OnError(from_here, reason); 611 client_->OnError(from_here, reason);
593 } 612 }
594 } // namespace media 613 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/win/video_capture_device_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698