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

Side by Side Diff: media/capture/video/fake_video_capture_device.cc

Issue 2673373003: getUserMeida: report device starting states (Closed)
Patch Set: address comments on PS#4 and revise unittests Created 3 years, 10 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
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/fake_video_capture_device.h" 5 #include "media/capture/video/fake_video_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 void DrawPacman(base::TimeDelta elapsed_time, uint8_t* target_buffer); 90 void DrawPacman(base::TimeDelta elapsed_time, uint8_t* target_buffer);
91 91
92 const VideoPixelFormat pixel_format_; 92 const VideoPixelFormat pixel_format_;
93 const FakeDeviceState* fake_device_state_ = nullptr; 93 const FakeDeviceState* fake_device_state_ = nullptr;
94 }; 94 };
95 95
96 // Paints and delivers frames to a client, which is set via Initialize(). 96 // Paints and delivers frames to a client, which is set via Initialize().
97 class FrameDeliverer { 97 class FrameDeliverer {
98 public: 98 public:
99 FrameDeliverer(std::unique_ptr<PacmanFramePainter> frame_painter) 99 FrameDeliverer(std::unique_ptr<PacmanFramePainter> frame_painter)
100 : frame_painter_(std::move(frame_painter)) {} 100 : frame_painter_(std::move(frame_painter)), capture_(false) {}
101 virtual ~FrameDeliverer() {} 101 virtual ~FrameDeliverer() {}
102 virtual void Initialize(VideoPixelFormat pixel_format, 102 virtual void Initialize(VideoPixelFormat pixel_format,
103 std::unique_ptr<VideoCaptureDevice::Client> client, 103 std::unique_ptr<VideoCaptureDevice::Client> client,
104 const FakeDeviceState* device_state) = 0; 104 const FakeDeviceState* device_state) = 0;
105 virtual void Uninitialize() = 0; 105 virtual void Uninitialize() = 0;
106 virtual void PaintAndDeliverNextFrame(base::TimeDelta timestamp_to_paint) = 0; 106 virtual void PaintAndDeliverNextFrame(base::TimeDelta timestamp_to_paint) = 0;
107 107
108 protected: 108 protected:
109 base::TimeDelta CalculateTimeSinceFirstInvocation(base::TimeTicks now) { 109 base::TimeDelta CalculateTimeSinceFirstInvocation(base::TimeTicks now) {
110 if (first_ref_time_.is_null()) 110 if (first_ref_time_.is_null())
111 first_ref_time_ = now; 111 first_ref_time_ = now;
112 return now - first_ref_time_; 112 return now - first_ref_time_;
113 } 113 }
114 114
115 const std::unique_ptr<PacmanFramePainter> frame_painter_; 115 const std::unique_ptr<PacmanFramePainter> frame_painter_;
116 const FakeDeviceState* device_state_ = nullptr; 116 const FakeDeviceState* device_state_ = nullptr;
117 std::unique_ptr<VideoCaptureDevice::Client> client_; 117 std::unique_ptr<VideoCaptureDevice::Client> client_;
118 bool capture_;
118 119
119 private: 120 private:
120 base::TimeTicks first_ref_time_; 121 base::TimeTicks first_ref_time_;
121 }; 122 };
122 123
123 // Delivers frames using its own buffers via OnIncomingCapturedData(). 124 // Delivers frames using its own buffers via OnIncomingCapturedData().
124 class OwnBufferFrameDeliverer : public FrameDeliverer { 125 class OwnBufferFrameDeliverer : public FrameDeliverer {
125 public: 126 public:
126 OwnBufferFrameDeliverer(std::unique_ptr<PacmanFramePainter> frame_painter); 127 OwnBufferFrameDeliverer(std::unique_ptr<PacmanFramePainter> frame_painter);
127 ~OwnBufferFrameDeliverer() override; 128 ~OwnBufferFrameDeliverer() override;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 OwnBufferFrameDeliverer::~OwnBufferFrameDeliverer() = default; 522 OwnBufferFrameDeliverer::~OwnBufferFrameDeliverer() = default;
522 523
523 void OwnBufferFrameDeliverer::Initialize( 524 void OwnBufferFrameDeliverer::Initialize(
524 VideoPixelFormat pixel_format, 525 VideoPixelFormat pixel_format,
525 std::unique_ptr<VideoCaptureDevice::Client> client, 526 std::unique_ptr<VideoCaptureDevice::Client> client,
526 const FakeDeviceState* device_state) { 527 const FakeDeviceState* device_state) {
527 client_ = std::move(client); 528 client_ = std::move(client);
528 device_state_ = device_state; 529 device_state_ = device_state;
529 buffer_.reset(new uint8_t[VideoFrame::AllocationSize( 530 buffer_.reset(new uint8_t[VideoFrame::AllocationSize(
530 pixel_format, device_state_->format.frame_size)]); 531 pixel_format, device_state_->format.frame_size)]);
532 client_->OnStarted();
533 capture_ = true;
531 } 534 }
532 535
533 void OwnBufferFrameDeliverer::Uninitialize() { 536 void OwnBufferFrameDeliverer::Uninitialize() {
537 capture_ = false;
534 client_.reset(); 538 client_.reset();
535 device_state_ = nullptr; 539 device_state_ = nullptr;
536 buffer_.reset(); 540 buffer_.reset();
537 } 541 }
538 542
539 void OwnBufferFrameDeliverer::PaintAndDeliverNextFrame( 543 void OwnBufferFrameDeliverer::PaintAndDeliverNextFrame(
540 base::TimeDelta timestamp_to_paint) { 544 base::TimeDelta timestamp_to_paint) {
541 if (!client_) 545 if (!client_ || !capture_)
542 return; 546 return;
543 const size_t frame_size = device_state_->format.ImageAllocationSize(); 547 const size_t frame_size = device_state_->format.ImageAllocationSize();
544 memset(buffer_.get(), 0, frame_size); 548 memset(buffer_.get(), 0, frame_size);
545 frame_painter_->PaintFrame(timestamp_to_paint, buffer_.get()); 549 frame_painter_->PaintFrame(timestamp_to_paint, buffer_.get());
546 base::TimeTicks now = base::TimeTicks::Now(); 550 base::TimeTicks now = base::TimeTicks::Now();
547 client_->OnIncomingCapturedData(buffer_.get(), frame_size, 551 client_->OnIncomingCapturedData(buffer_.get(), frame_size,
548 device_state_->format, 0 /* rotation */, now, 552 device_state_->format, 0 /* rotation */, now,
549 CalculateTimeSinceFirstInvocation(now)); 553 CalculateTimeSinceFirstInvocation(now));
550 } 554 }
551 555
552 ClientBufferFrameDeliverer::ClientBufferFrameDeliverer( 556 ClientBufferFrameDeliverer::ClientBufferFrameDeliverer(
553 std::unique_ptr<PacmanFramePainter> frame_painter) 557 std::unique_ptr<PacmanFramePainter> frame_painter)
554 : FrameDeliverer(std::move(frame_painter)) {} 558 : FrameDeliverer(std::move(frame_painter)) {}
555 559
556 ClientBufferFrameDeliverer::~ClientBufferFrameDeliverer() = default; 560 ClientBufferFrameDeliverer::~ClientBufferFrameDeliverer() = default;
557 561
558 void ClientBufferFrameDeliverer::Initialize( 562 void ClientBufferFrameDeliverer::Initialize(
559 VideoPixelFormat, 563 VideoPixelFormat,
560 std::unique_ptr<VideoCaptureDevice::Client> client, 564 std::unique_ptr<VideoCaptureDevice::Client> client,
561 const FakeDeviceState* device_state) { 565 const FakeDeviceState* device_state) {
562 client_ = std::move(client); 566 client_ = std::move(client);
563 device_state_ = device_state; 567 device_state_ = device_state;
568 client_->OnStarted();
564 } 569 }
565 570
566 void ClientBufferFrameDeliverer::Uninitialize() { 571 void ClientBufferFrameDeliverer::Uninitialize() {
567 client_.reset(); 572 client_.reset();
568 device_state_ = nullptr; 573 device_state_ = nullptr;
569 } 574 }
570 575
571 void ClientBufferFrameDeliverer::PaintAndDeliverNextFrame( 576 void ClientBufferFrameDeliverer::PaintAndDeliverNextFrame(
572 base::TimeDelta timestamp_to_paint) { 577 base::TimeDelta timestamp_to_paint) {
573 if (client_ == nullptr) 578 if (client_ == nullptr)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 int session_id) { 635 int session_id) {
631 DCHECK(thread_checker_.CalledOnValidThread()); 636 DCHECK(thread_checker_.CalledOnValidThread());
632 if (session_id != current_session_id_) 637 if (session_id != current_session_id_)
633 return; 638 return;
634 639
635 frame_deliverer_->PaintAndDeliverNextFrame(elapsed_time_); 640 frame_deliverer_->PaintAndDeliverNextFrame(elapsed_time_);
636 BeepAndScheduleNextCapture(expected_execution_time); 641 BeepAndScheduleNextCapture(expected_execution_time);
637 } 642 }
638 643
639 } // namespace media 644 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698