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

Side by Side Diff: media/cast/video_sender/external_video_encoder_unittest.cc

Issue 207593002: Cast: Enable use of VideoEncodeAccelerator for hardware video encoding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
11 #include "media/cast/cast_defines.h" 11 #include "media/cast/cast_defines.h"
12 #include "media/cast/cast_environment.h" 12 #include "media/cast/cast_environment.h"
13 #include "media/cast/test/fake_gpu_video_accelerator_factories.h"
14 #include "media/cast/test/fake_single_thread_task_runner.h" 13 #include "media/cast/test/fake_single_thread_task_runner.h"
15 #include "media/cast/test/fake_video_encode_accelerator.h" 14 #include "media/cast/test/fake_video_encode_accelerator.h"
16 #include "media/cast/test/utility/video_utility.h" 15 #include "media/cast/test/utility/video_utility.h"
17 #include "media/cast/video_sender/external_video_encoder.h" 16 #include "media/cast/video_sender/external_video_encoder.h"
18 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
19 18
20 namespace media { 19 namespace media {
21 namespace cast { 20 namespace cast {
22 21
23 using testing::_; 22 using testing::_;
24 23
25 namespace { 24 namespace {
25
26 void CreateVideoEncodeAccelerator(
27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
28 scoped_ptr<VideoEncodeAccelerator> fake_vea,
29 const base::Callback<void(scoped_refptr<base::SingleThreadTaskRunner>,
pwestin 2014/03/21 21:02:02 Use the proposed typedef
Alpha Left Google 2014/03/21 21:37:12 Done.
30 scoped_ptr<media::VideoEncodeAccelerator>)>&
31 callback) {
32 callback.Run(task_runner, fake_vea.Pass());
33 }
34
35 void CreateSharedMemory(
36 size_t size,
37 const base::Callback<void(scoped_ptr<base::SharedMemory>)>& callback) {
pwestin 2014/03/21 21:02:02 Use the proposed typedef
Alpha Left Google 2014/03/21 21:37:12 Done.
38 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
39 if (!shm->CreateAndMapAnonymous(size)) {
40 NOTREACHED();
41 return;
42 }
43 callback.Run(shm.Pass());
44 }
45
26 class TestVideoEncoderCallback 46 class TestVideoEncoderCallback
27 : public base::RefCountedThreadSafe<TestVideoEncoderCallback> { 47 : public base::RefCountedThreadSafe<TestVideoEncoderCallback> {
28 public: 48 public:
29 TestVideoEncoderCallback() {} 49 TestVideoEncoderCallback() {}
30 50
31 void SetExpectedResult(bool expected_key_frame, 51 void SetExpectedResult(bool expected_key_frame,
32 uint8 expected_frame_id, 52 uint8 expected_frame_id,
33 uint8 expected_last_referenced_frame_id, 53 uint8 expected_last_referenced_frame_id,
34 const base::TimeTicks& expected_capture_time) { 54 const base::TimeTicks& expected_capture_time) {
35 expected_key_frame_ = expected_key_frame; 55 expected_key_frame_ = expected_key_frame;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_); 110 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_);
91 cast_environment_ = 111 cast_environment_ =
92 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_).Pass(), 112 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_).Pass(),
93 task_runner_, 113 task_runner_,
94 task_runner_, 114 task_runner_,
95 task_runner_, 115 task_runner_,
96 task_runner_, 116 task_runner_,
97 task_runner_, 117 task_runner_,
98 task_runner_, 118 task_runner_,
99 GetDefaultCastSenderLoggingConfig()); 119 GetDefaultCastSenderLoggingConfig());
100 video_encoder_.reset(new ExternalVideoEncoder( 120 scoped_ptr<VideoEncodeAccelerator> fake_vea(
101 cast_environment_, 121 new test::FakeVideoEncodeAccelerator());
102 video_config_, 122 video_encoder_.reset(
103 new test::FakeGpuVideoAcceleratorFactories(task_runner_))); 123 new ExternalVideoEncoder(cast_environment_,
124 video_config_,
125 base::Bind(&CreateVideoEncodeAccelerator,
126 task_runner_,
127 base::Passed(&fake_vea)),
128 base::Bind(&CreateSharedMemory)));
104 } 129 }
105 130
106 virtual ~ExternalVideoEncoderTest() {} 131 virtual ~ExternalVideoEncoderTest() {}
107 132
108 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. 133 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
109 scoped_refptr<TestVideoEncoderCallback> test_video_encoder_callback_; 134 scoped_refptr<TestVideoEncoderCallback> test_video_encoder_callback_;
110 VideoSenderConfig video_config_; 135 VideoSenderConfig video_config_;
111 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 136 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
112 scoped_ptr<VideoEncoder> video_encoder_; 137 scoped_ptr<VideoEncoder> video_encoder_;
113 scoped_refptr<media::VideoFrame> video_frame_; 138 scoped_refptr<media::VideoFrame> video_frame_;
(...skipping 24 matching lines...) Expand all
138 video_frame_, capture_time, frame_encoded_callback)); 163 video_frame_, capture_time, frame_encoded_callback));
139 task_runner_->RunTasks(); 164 task_runner_->RunTasks();
140 } 165 }
141 // We need to run the task to cleanup the GPU instance. 166 // We need to run the task to cleanup the GPU instance.
142 video_encoder_.reset(NULL); 167 video_encoder_.reset(NULL);
143 task_runner_->RunTasks(); 168 task_runner_->RunTasks();
144 } 169 }
145 170
146 } // namespace cast 171 } // namespace cast
147 } // namespace media 172 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698