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

Side by Side Diff: content/common/gpu/media/video_encode_accelerator_unittest.cc

Issue 430583005: Make VEA test support videos with different coded size and visible size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: MemoryMappedFile starting address checking Created 6 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 | « no previous file | media/base/video_frame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/memory_mapped_file.h" 9 #include "base/files/memory_mapped_file.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 15 matching lines...) Expand all
26 #endif 26 #endif
27 27
28 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) 28 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
29 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" 29 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
30 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) 30 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
31 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" 31 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h"
32 #else 32 #else
33 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. 33 #error The VideoEncodeAcceleratorUnittest is not supported on this platform.
34 #endif 34 #endif
35 35
36 #define ALIGN_64_BYTES(x) (((x) + 63) & ~63)
Pawel Osciak 2014/09/05 07:21:32 Inline static function please.
henryhsu 2014/09/10 11:01:49 Done.
37
36 using media::VideoEncodeAccelerator; 38 using media::VideoEncodeAccelerator;
37 39
38 namespace content { 40 namespace content {
39 namespace { 41 namespace {
40 42
41 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; 43 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420;
42 44
43 // Arbitrarily chosen to add some depth to the pipeline. 45 // Arbitrarily chosen to add some depth to the pipeline.
44 const unsigned int kNumOutputBuffers = 4; 46 const unsigned int kNumOutputBuffers = 4;
45 const unsigned int kNumExtraInputFrames = 4; 47 const unsigned int kNumExtraInputFrames = 4;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 98
97 struct TestStream { 99 struct TestStream {
98 TestStream() 100 TestStream()
99 : requested_bitrate(0), 101 : requested_bitrate(0),
100 requested_framerate(0), 102 requested_framerate(0),
101 requested_subsequent_bitrate(0), 103 requested_subsequent_bitrate(0),
102 requested_subsequent_framerate(0) {} 104 requested_subsequent_framerate(0) {}
103 ~TestStream() {} 105 ~TestStream() {}
104 106
105 gfx::Size size; 107 gfx::Size size;
108
109 // Input file name and the file must be an I420 (YUV planar) raw stream.
110 std::string in_filename;
Pawel Osciak 2014/09/05 07:21:32 Please say that his is the original unaligned file
henryhsu 2014/09/10 11:01:49 Done.
111
112 // The memory mapped of |temp_file|
106 base::MemoryMappedFile input_file; 113 base::MemoryMappedFile input_file;
Pawel Osciak 2014/09/05 07:21:34 Please rename this and temp_file to (mapped_)align
henryhsu 2014/09/10 11:01:49 Done.
114
115 // A temporary file used to prepare input buffers.
Pawel Osciak 2014/09/05 07:21:32 Please say what it will contain and why.
henryhsu 2014/09/10 11:01:49 Done.
116 base::FilePath temp_file;
117
118 std::string out_filename;
107 media::VideoCodecProfile requested_profile; 119 media::VideoCodecProfile requested_profile;
108 std::string out_filename;
109 unsigned int requested_bitrate; 120 unsigned int requested_bitrate;
110 unsigned int requested_framerate; 121 unsigned int requested_framerate;
111 unsigned int requested_subsequent_bitrate; 122 unsigned int requested_subsequent_bitrate;
112 unsigned int requested_subsequent_framerate; 123 unsigned int requested_subsequent_framerate;
113 }; 124 };
125 TestStream *g_test_streams;
Pawel Osciak 2014/09/05 07:21:32 Could this be a property of the Environment impl?
henryhsu 2014/09/10 11:01:48 Done.
126 size_t g_test_streams_size;
127
128 static bool WriteFile(base::File *file,
Pawel Osciak 2014/09/05 07:21:33 Documentation please. Also star next to type name.
henryhsu 2014/09/10 11:01:50 Done.
129 const off_t offset,
130 const char* data,
Pawel Osciak 2014/09/05 07:21:34 Perhaps take uint8* and cast here in the method, n
henryhsu 2014/09/10 11:01:49 Done.
131 size_t size) {
132 size_t written_bytes = 0;
133 while (written_bytes < size) {
134 int bytes = file->Write(
135 offset + written_bytes, data + written_bytes, size - written_bytes);
136 if (bytes <= 0) return false;
137 written_bytes += bytes;
138 }
139 return true;
140 }
141
142 // ARM performs CPU cache management with CPU cache line granularity. We thus
143 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned).
144 // Otherwise newer kernels will refuse to accept them, and on older kernels
145 // we'll be treating ourselves to random corruption.
146 // Since we are just mmapping and passing chunks of the input file, to ensure
147 // alignment, if the starting virtual addresses of YUV planes of the frames
148 // in it were not 64 byte-aligned, we'd have to prepare a memory with 64
149 // byte-aligned starting address and make sure the addresses of YUV planes of
150 // each frame are 64 byte-aligned before sending to the encoder.
151 // Now we test resolutions different from coded size and prepare chunks before
Pawel Osciak 2014/09/05 07:21:33 "Now we test..." is not needed, we don't need to d
henryhsu 2014/09/10 11:01:48 Done.
152 // encoding to avoid performance impact.
153 // YUV data are copied to file directly. Use |visible_size| and |coded_size| to
154 // write YUV data from |in_filename| to |input_file|. Also calculate the byte
155 // size of an input frame and set it to |coded_buffer_size|. |temp_file| is used
156 // to prepare input buffers and will be deleted after test finished.
157 static void PrepareInputBuffers(const gfx::Size& visible_size,
Pawel Osciak 2014/09/05 07:21:33 The name is misleading. Please call it CreateAlign
henryhsu 2014/09/10 11:01:49 Done.
158 const gfx::Size& coded_size,
159 const std::string in_filename,
160 base::MemoryMappedFile* input_file,
161 base::FilePath* temp_file,
162 size_t* coded_buffer_size) {
Pawel Osciak 2014/09/05 07:21:32 Can we make coded_buffer_size a property of TestSt
henryhsu 2014/09/10 11:01:48 Done.
163 size_t input_num_planes = media::VideoFrame::NumPlanes(kInputFormat);
Pawel Osciak 2014/09/05 07:21:32 s/input_num_planes/num_planes/
henryhsu 2014/09/10 11:01:50 Done.
164 std::vector<size_t> padding_sizes(input_num_planes);
Pawel Osciak 2014/09/05 07:21:34 These require explanation.
henryhsu 2014/09/10 11:01:48 I think the below comments are enough to explain t
165 std::vector<size_t> coded_bpl(input_num_planes);
166 std::vector<size_t> visible_bpl(input_num_planes);
167 std::vector<size_t> visible_plane_rows(input_num_planes);
168
169 // YUV plane starting address should be 64 bytes alignment. Calculate padding
Pawel Osciak 2014/09/05 07:21:33 s/be 64 bytes alignment/aligned to 64 byte boundar
henryhsu 2014/09/10 11:01:49 Done.
170 // size for each plane, and frame allocation size for coded size. Also store
171 // bytes per line information of coded size and visible size.
Pawel Osciak 2014/09/05 07:21:33 Please in general don't comment describing what co
henryhsu 2014/09/10 11:01:49 Done.
172 *coded_buffer_size = 0;
Pawel Osciak 2014/09/05 07:21:33 aligned_buffer_size
henryhsu 2014/09/10 11:01:49 Done.
173 for (off_t i = 0; i < input_num_planes; i++) {
174 size_t size =
175 media::VideoFrame::PlaneAllocationSize(kInputFormat, i, coded_size);
176 size_t padding_bytes = ALIGN_64_BYTES(size) - size;
177 *coded_buffer_size += ALIGN_64_BYTES(size);
178
179 coded_bpl[i] =
180 media::VideoFrame::RowBytes(i, kInputFormat, coded_size.width());
181 visible_bpl[i] =
182 media::VideoFrame::RowBytes(i, kInputFormat, visible_size.width());
183 visible_plane_rows[i] =
184 media::VideoFrame::Rows(i, kInputFormat, visible_size.height());
185 size_t padding_rows =
186 media::VideoFrame::Rows(i, kInputFormat, coded_size.height()) -
187 visible_plane_rows[i];
188 padding_sizes[i] = padding_rows * coded_bpl[i] + padding_bytes;
Pawel Osciak 2014/09/05 07:21:33 Your destination buffer is coded_bpl[i] * coded_si
henryhsu 2014/09/10 11:01:49 coded_bpl[i] * coded_size.height() is exactly Plan
Pawel Osciak 2014/09/11 09:51:46 That's why I suggested ALIGN(coded_bpl[i] * coded_
189 }
190
191 // Test case may have many encoders and memory should be prepared once.
192 if (input_file->IsValid())
Pawel Osciak 2014/09/05 07:21:33 This should go at the beginning of the method.
henryhsu 2014/09/10 11:01:49 Because we should set coded_buffer_size for each e
Pawel Osciak 2014/09/11 09:51:46 Acknowledged.
193 return;
194
195 base::MemoryMappedFile src_file;
196 CHECK(base::CreateTemporaryFile(temp_file));
197 CHECK(src_file.Initialize(base::FilePath(in_filename)));
Pawel Osciak 2014/09/05 07:21:33 This should go one line up, or l195 should go one
henryhsu 2014/09/10 11:01:49 Done.
198
199 size_t visible_buffer_size =
200 media::VideoFrame::AllocationSize(kInputFormat, visible_size);
201 size_t num_frames = src_file.length() / visible_buffer_size;
Pawel Osciak 2014/09/05 07:21:34 The check that was here before should still be her
henryhsu 2014/09/10 11:01:49 Done.
202 uint32 flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
203 base::File::FLAG_READ;
204
205 // Create a temporary file with coded_size length.
206 base::File dest_file(*temp_file, flags);
207 dest_file.SetLength(*coded_buffer_size * num_frames);
208
209 off_t src_offset = 0, dest_offset = 0;
210 while (src_offset < static_cast<off_t>(src_file.length())) {
Pawel Osciak 2014/09/05 07:21:32 Iterate over num_frames?
henryhsu 2014/09/10 11:01:48 Done.
211 for (off_t i = 0; i < input_num_planes; i++) {
212 #if defined(ARCH_CPU_ARMEL)
Pawel Osciak 2014/09/05 07:21:32 We are now doing alignment for all platforms, so n
henryhsu 2014/09/10 11:01:50 Done.
213 // Assert that each plane of frame starts at 64-byte boundary.
214 ASSERT_EQ(dest_offset & 63, 0)
215 << "Planes of frame should be mapped at a 64 byte boundary";
216 #endif
217 for (off_t j = 0; j < visible_plane_rows[i]; j++) {
218 const char* src =
Pawel Osciak 2014/09/05 07:21:33 Perhaps keep a rolling pointer to the data, instea
henryhsu 2014/09/10 11:01:49 Done.
219 reinterpret_cast<const char*>(src_file.data() + src_offset);
220 CHECK(WriteFile(&dest_file, dest_offset, src, visible_bpl[i]));
221 src_offset += visible_bpl[i];
222 dest_offset += coded_bpl[i];
223 }
224 dest_offset += padding_sizes[i];
225 }
226 }
227 CHECK(input_file->Initialize(dest_file.Pass()));
228 #if defined(ARCH_CPU_ARMEL)
Pawel Osciak 2014/09/05 07:21:33 Please remove ifdef.
henryhsu 2014/09/10 11:01:49 Done.
229 // Assert that memory mapped of file starts at 64-byte boundary. So each
230 // plane of frames also start at 64-byte boundary.
231 ASSERT_EQ(reinterpret_cast<off_t>(input_file->data()) & 63, 0)
232 << "File should be mapped at a 64 byte boundary";
233 #endif
234 }
114 235
115 // Parse |data| into its constituent parts, set the various output fields 236 // Parse |data| into its constituent parts, set the various output fields
116 // accordingly, read in video stream, and store them to |test_streams|. 237 // accordingly, read in video stream, and store them to |test_streams|. Also
238 // store the size of |test_streams| to |test_streams_size|.
117 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, 239 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data,
118 ScopedVector<TestStream>* test_streams) { 240 TestStream** test_streams,
241 size_t* test_streams_size) {
119 // Split the string to individual test stream data. 242 // Split the string to individual test stream data.
120 std::vector<base::FilePath::StringType> test_streams_data; 243 std::vector<base::FilePath::StringType> test_streams_data;
121 base::SplitString(data, ';', &test_streams_data); 244 base::SplitString(data, ';', &test_streams_data);
122 CHECK_GE(test_streams_data.size(), 1U) << data; 245 CHECK_GE(test_streams_data.size(), 1U) << data;
123 246
247 *test_streams_size = test_streams_data.size();
248 *test_streams = new TestStream[*test_streams_size];
Pawel Osciak 2014/09/05 07:21:33 std::vector of TestStream instead?
henryhsu 2014/09/10 11:01:50 Static or global variables of class type are forbi
Pawel Osciak 2014/09/11 09:51:46 Acknowledged.
124 // Parse each test stream data and read the input file. 249 // Parse each test stream data and read the input file.
125 for (size_t index = 0; index < test_streams_data.size(); ++index) { 250 for (size_t index = 0; index < *test_streams_size; ++index) {
126 std::vector<base::FilePath::StringType> fields; 251 std::vector<base::FilePath::StringType> fields;
127 base::SplitString(test_streams_data[index], ':', &fields); 252 base::SplitString(test_streams_data[index], ':', &fields);
128 CHECK_GE(fields.size(), 4U) << data; 253 CHECK_GE(fields.size(), 4U) << data;
129 CHECK_LE(fields.size(), 9U) << data; 254 CHECK_LE(fields.size(), 9U) << data;
130 TestStream* test_stream = new TestStream(); 255 TestStream* test_stream = &*test_streams[index];
131 256
132 base::FilePath::StringType filename = fields[0]; 257 test_stream->in_filename = fields[0];
133 int width, height; 258 int width, height;
134 CHECK(base::StringToInt(fields[1], &width)); 259 CHECK(base::StringToInt(fields[1], &width));
135 CHECK(base::StringToInt(fields[2], &height)); 260 CHECK(base::StringToInt(fields[2], &height));
136 test_stream->size = gfx::Size(width, height); 261 test_stream->size = gfx::Size(width, height);
137 CHECK(!test_stream->size.IsEmpty()); 262 CHECK(!test_stream->size.IsEmpty());
138 int profile; 263 int profile;
139 CHECK(base::StringToInt(fields[3], &profile)); 264 CHECK(base::StringToInt(fields[3], &profile));
140 CHECK_GT(profile, media::VIDEO_CODEC_PROFILE_UNKNOWN); 265 CHECK_GT(profile, media::VIDEO_CODEC_PROFILE_UNKNOWN);
141 CHECK_LE(profile, media::VIDEO_CODEC_PROFILE_MAX); 266 CHECK_LE(profile, media::VIDEO_CODEC_PROFILE_MAX);
142 test_stream->requested_profile = 267 test_stream->requested_profile =
143 static_cast<media::VideoCodecProfile>(profile); 268 static_cast<media::VideoCodecProfile>(profile);
144 269
145 if (fields.size() >= 5 && !fields[4].empty()) 270 if (fields.size() >= 5 && !fields[4].empty())
146 test_stream->out_filename = fields[4]; 271 test_stream->out_filename = fields[4];
147 272
148 if (fields.size() >= 6 && !fields[5].empty()) 273 if (fields.size() >= 6 && !fields[5].empty())
149 CHECK(base::StringToUint(fields[5], &test_stream->requested_bitrate)); 274 CHECK(base::StringToUint(fields[5], &test_stream->requested_bitrate));
150 275
151 if (fields.size() >= 7 && !fields[6].empty()) 276 if (fields.size() >= 7 && !fields[6].empty())
152 CHECK(base::StringToUint(fields[6], &test_stream->requested_framerate)); 277 CHECK(base::StringToUint(fields[6], &test_stream->requested_framerate));
153 278
154 if (fields.size() >= 8 && !fields[7].empty()) { 279 if (fields.size() >= 8 && !fields[7].empty()) {
155 CHECK(base::StringToUint(fields[7], 280 CHECK(base::StringToUint(
156 &test_stream->requested_subsequent_bitrate)); 281 fields[7], &test_stream->requested_subsequent_bitrate));
157 } 282 }
158 283
159 if (fields.size() >= 9 && !fields[8].empty()) { 284 if (fields.size() >= 9 && !fields[8].empty()) {
160 CHECK(base::StringToUint(fields[8], 285 CHECK(base::StringToUint(
161 &test_stream->requested_subsequent_framerate)); 286 fields[8], &test_stream->requested_subsequent_framerate));
162 } 287 }
163
164 CHECK(test_stream->input_file.Initialize(base::FilePath(filename)));
165 test_streams->push_back(test_stream);
166 } 288 }
167 } 289 }
168 290
169 // Set default parameters of |test_streams| and update the parameters according
170 // to |mid_stream_bitrate_switch| and |mid_stream_framerate_switch|.
171 static void UpdateTestStreamData(bool mid_stream_bitrate_switch,
172 bool mid_stream_framerate_switch,
173 ScopedVector<TestStream>* test_streams) {
174 for (size_t i = 0; i < test_streams->size(); i++) {
175 TestStream* test_stream = (*test_streams)[i];
176 // Use defaults for bitrate/framerate if they are not provided.
177 if (test_stream->requested_bitrate == 0)
178 test_stream->requested_bitrate = kDefaultBitrate;
179
180 if (test_stream->requested_framerate == 0)
181 test_stream->requested_framerate = kDefaultFramerate;
182
183 // If bitrate/framerate switch is requested, use the subsequent values if
184 // provided, or, if not, calculate them from their initial values using
185 // the default ratios.
186 // Otherwise, if a switch is not requested, keep the initial values.
187 if (mid_stream_bitrate_switch) {
188 if (test_stream->requested_subsequent_bitrate == 0) {
189 test_stream->requested_subsequent_bitrate =
190 test_stream->requested_bitrate * kDefaultSubsequentBitrateRatio;
191 }
192 } else {
193 test_stream->requested_subsequent_bitrate =
194 test_stream->requested_bitrate;
195 }
196 if (test_stream->requested_subsequent_bitrate == 0)
197 test_stream->requested_subsequent_bitrate = 1;
198
199 if (mid_stream_framerate_switch) {
200 if (test_stream->requested_subsequent_framerate == 0) {
201 test_stream->requested_subsequent_framerate =
202 test_stream->requested_framerate * kDefaultSubsequentFramerateRatio;
203 }
204 } else {
205 test_stream->requested_subsequent_framerate =
206 test_stream->requested_framerate;
207 }
208 if (test_stream->requested_subsequent_framerate == 0)
209 test_stream->requested_subsequent_framerate = 1;
210 }
211 }
212
213 enum ClientState { 291 enum ClientState {
214 CS_CREATED, 292 CS_CREATED,
215 CS_ENCODER_SET, 293 CS_ENCODER_SET,
216 CS_INITIALIZED, 294 CS_INITIALIZED,
217 CS_ENCODING, 295 CS_ENCODING,
218 CS_FINISHED, 296 CS_FINISHED,
219 CS_ERROR, 297 CS_ERROR,
220 }; 298 };
221 299
222 // Performs basic, codec-specific sanity checks on the stream buffers passed 300 // Performs basic, codec-specific sanity checks on the stream buffers passed
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 validator.reset(new VP8Validator(frame_cb)); 439 validator.reset(new VP8Validator(frame_cb));
362 } else { 440 } else {
363 LOG(FATAL) << "Unsupported profile: " << profile; 441 LOG(FATAL) << "Unsupported profile: " << profile;
364 } 442 }
365 443
366 return validator.Pass(); 444 return validator.Pass();
367 } 445 }
368 446
369 class VEAClient : public VideoEncodeAccelerator::Client { 447 class VEAClient : public VideoEncodeAccelerator::Client {
370 public: 448 public:
371 VEAClient(const TestStream& test_stream, 449 VEAClient(TestStream& test_stream,
372 ClientStateNotification<ClientState>* note, 450 ClientStateNotification<ClientState>* note,
373 bool save_to_file, 451 bool save_to_file,
374 unsigned int keyframe_period, 452 unsigned int keyframe_period,
375 bool force_bitrate, 453 bool force_bitrate,
376 bool test_perf); 454 bool test_perf,
455 bool mid_stream_bitrate_switch,
456 bool mid_stream_framerate_switch);
377 virtual ~VEAClient(); 457 virtual ~VEAClient();
378 void CreateEncoder(); 458 void CreateEncoder();
379 void DestroyEncoder(); 459 void DestroyEncoder();
380 460
381 // Return the number of encoded frames per second. 461 // Return the number of encoded frames per second.
382 double frames_per_second(); 462 double frames_per_second();
383 463
384 // VideoDecodeAccelerator::Client implementation. 464 // VideoDecodeAccelerator::Client implementation.
385 virtual void RequireBitstreamBuffers(unsigned int input_count, 465 virtual void RequireBitstreamBuffers(unsigned int input_count,
386 const gfx::Size& input_coded_size, 466 const gfx::Size& input_coded_size,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 void VerifyStreamProperties(); 500 void VerifyStreamProperties();
421 501
422 // Test codec performance, failing the test if we are currently running 502 // Test codec performance, failing the test if we are currently running
423 // the performance test. 503 // the performance test.
424 void VerifyPerf(); 504 void VerifyPerf();
425 505
426 // Prepare and return a frame wrapping the data at |position| bytes in 506 // Prepare and return a frame wrapping the data at |position| bytes in
427 // the input stream, ready to be sent to encoder. 507 // the input stream, ready to be sent to encoder.
428 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); 508 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position);
429 509
510 // Update the parameters according to |mid_stream_bitrate_switch| and
511 // |mid_stream_framerate_switch|.
512 void UpdateTestStreamData(bool mid_stream_bitrate_switch,
513 bool mid_stream_framerate_switch);
514
430 ClientState state_; 515 ClientState state_;
431 scoped_ptr<VideoEncodeAccelerator> encoder_; 516 scoped_ptr<VideoEncodeAccelerator> encoder_;
432 517
433 const TestStream& test_stream_; 518 TestStream& test_stream_;
Pawel Osciak 2014/09/05 07:21:33 I think you can keep const here if you don't Updat
henryhsu 2014/09/10 11:01:49 We put input_buffer_size_ as a property of TestStr
Pawel Osciak 2014/09/11 09:51:46 Acknowledged.
434 // Used to notify another thread about the state. VEAClient does not own this. 519 // Used to notify another thread about the state. VEAClient does not own this.
435 ClientStateNotification<ClientState>* note_; 520 ClientStateNotification<ClientState>* note_;
436 521
437 // Ids assigned to VideoFrames (start at 1 for easy comparison with 522 // Ids assigned to VideoFrames (start at 1 for easy comparison with
438 // num_encoded_frames_). 523 // num_encoded_frames_).
439 std::set<int32> inputs_at_client_; 524 std::set<int32> inputs_at_client_;
440 int32 next_input_id_; 525 int32 next_input_id_;
441 526
442 // Ids for output BitstreamBuffers. 527 // Ids for output BitstreamBuffers.
443 typedef std::map<int32, base::SharedMemory*> IdToSHM; 528 typedef std::map<int32, base::SharedMemory*> IdToSHM;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 scoped_ptr<StreamValidator> validator_; 583 scoped_ptr<StreamValidator> validator_;
499 584
500 // The time when the encoding started. 585 // The time when the encoding started.
501 base::TimeTicks encode_start_time_; 586 base::TimeTicks encode_start_time_;
502 587
503 // The time when the last encoded frame is ready. 588 // The time when the last encoded frame is ready.
504 base::TimeTicks last_frame_ready_time_; 589 base::TimeTicks last_frame_ready_time_;
505 590
506 // All methods of this class should be run on the same thread. 591 // All methods of this class should be run on the same thread.
507 base::ThreadChecker thread_checker_; 592 base::ThreadChecker thread_checker_;
593
594 // Requested bitrate in bits per second.
595 unsigned int requested_bitrate_;
596
597 // Requested initial framerate.
598 unsigned int requested_framerate_;
599
600 // Bitrate to switch to in the middle of the stream.
601 unsigned int requested_subsequent_bitrate_;
602
603 // Framerate to switch to in the middle of the stream.
604 unsigned int requested_subsequent_framerate_;
508 }; 605 };
509 606
510 VEAClient::VEAClient(const TestStream& test_stream, 607 VEAClient::VEAClient(TestStream& test_stream,
511 ClientStateNotification<ClientState>* note, 608 ClientStateNotification<ClientState>* note,
512 bool save_to_file, 609 bool save_to_file,
513 unsigned int keyframe_period, 610 unsigned int keyframe_period,
514 bool force_bitrate, 611 bool force_bitrate,
515 bool test_perf) 612 bool test_perf,
613 bool mid_stream_bitrate_switch,
614 bool mid_stream_framerate_switch)
516 : state_(CS_CREATED), 615 : state_(CS_CREATED),
517 test_stream_(test_stream), 616 test_stream_(test_stream),
518 note_(note), 617 note_(note),
519 next_input_id_(1), 618 next_input_id_(1),
520 next_output_buffer_id_(0), 619 next_output_buffer_id_(0),
521 pos_in_input_stream_(0), 620 pos_in_input_stream_(0),
522 input_buffer_size_(0), 621 input_buffer_size_(0),
523 num_required_input_buffers_(0), 622 num_required_input_buffers_(0),
524 output_buffer_size_(0), 623 output_buffer_size_(0),
525 num_frames_in_stream_(0), 624 num_frames_in_stream_(0),
526 num_frames_to_encode_(0), 625 num_frames_to_encode_(0),
527 num_encoded_frames_(0), 626 num_encoded_frames_(0),
528 num_frames_since_last_check_(0), 627 num_frames_since_last_check_(0),
529 seen_keyframe_in_this_buffer_(false), 628 seen_keyframe_in_this_buffer_(false),
530 save_to_file_(save_to_file), 629 save_to_file_(save_to_file),
531 keyframe_period_(keyframe_period), 630 keyframe_period_(keyframe_period),
532 keyframe_requested_at_(kMaxFrameNum), 631 keyframe_requested_at_(kMaxFrameNum),
533 force_bitrate_(force_bitrate), 632 force_bitrate_(force_bitrate),
534 current_requested_bitrate_(0), 633 current_requested_bitrate_(0),
535 current_framerate_(0), 634 current_framerate_(0),
536 encoded_stream_size_since_last_check_(0), 635 encoded_stream_size_since_last_check_(0),
537 test_perf_(test_perf) { 636 test_perf_(test_perf),
637 requested_bitrate_(0),
638 requested_framerate_(0),
639 requested_subsequent_bitrate_(0),
640 requested_subsequent_framerate_(0) {
538 if (keyframe_period_) 641 if (keyframe_period_)
539 CHECK_LT(kMaxKeyframeDelay, keyframe_period_); 642 CHECK_LT(kMaxKeyframeDelay, keyframe_period_);
540 643
541 validator_ = StreamValidator::Create( 644 validator_ = StreamValidator::Create(
542 test_stream_.requested_profile, 645 test_stream_.requested_profile,
543 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 646 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
544 647
545 CHECK(validator_.get()); 648 CHECK(validator_.get());
546 649
547 if (save_to_file_) { 650 if (save_to_file_) {
548 CHECK(!test_stream_.out_filename.empty()); 651 CHECK(!test_stream_.out_filename.empty());
549 base::FilePath out_filename(test_stream_.out_filename); 652 base::FilePath out_filename(test_stream_.out_filename);
550 // This creates or truncates out_filename. 653 // This creates or truncates out_filename.
551 // Without it, AppendToFile() will not work. 654 // Without it, AppendToFile() will not work.
552 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); 655 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0));
553 } 656 }
554 657
555 input_buffer_size_ = 658 // Initialize the parameters of the test streams.
556 media::VideoFrame::AllocationSize(kInputFormat, test_stream.size); 659 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch);
557 CHECK_GT(input_buffer_size_, 0UL);
558
559 // Calculate the number of frames in the input stream by dividing its length
560 // in bytes by frame size in bytes.
561 CHECK_EQ(test_stream_.input_file.length() % input_buffer_size_, 0U)
562 << "Stream byte size is not a product of calculated frame byte size";
563 num_frames_in_stream_ = test_stream_.input_file.length() / input_buffer_size_;
564 CHECK_GT(num_frames_in_stream_, 0UL);
565 CHECK_LE(num_frames_in_stream_, kMaxFrameNum);
566
567 // We may need to loop over the stream more than once if more frames than
568 // provided is required for bitrate tests.
569 if (force_bitrate_ && num_frames_in_stream_ < kMinFramesForBitrateTests) {
570 DVLOG(1) << "Stream too short for bitrate test (" << num_frames_in_stream_
571 << " frames), will loop it to reach " << kMinFramesForBitrateTests
572 << " frames";
573 num_frames_to_encode_ = kMinFramesForBitrateTests;
574 } else {
575 num_frames_to_encode_ = num_frames_in_stream_;
576 }
577 660
578 thread_checker_.DetachFromThread(); 661 thread_checker_.DetachFromThread();
579 } 662 }
580 663
581 VEAClient::~VEAClient() { CHECK(!has_encoder()); } 664 VEAClient::~VEAClient() { CHECK(!has_encoder()); }
582 665
583 void VEAClient::CreateEncoder() { 666 void VEAClient::CreateEncoder() {
584 DCHECK(thread_checker_.CalledOnValidThread()); 667 DCHECK(thread_checker_.CalledOnValidThread());
585 CHECK(!has_encoder()); 668 CHECK(!has_encoder());
586 669
587 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) 670 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
588 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); 671 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
589 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); 672 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass()));
590 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) 673 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
591 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); 674 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay()));
592 #endif 675 #endif
593 676
594 SetState(CS_ENCODER_SET); 677 SetState(CS_ENCODER_SET);
595 678
596 DVLOG(1) << "Profile: " << test_stream_.requested_profile 679 DVLOG(1) << "Profile: " << test_stream_.requested_profile
597 << ", initial bitrate: " << test_stream_.requested_bitrate; 680 << ", initial bitrate: " << requested_bitrate_;
598 if (!encoder_->Initialize(kInputFormat, 681 if (!encoder_->Initialize(kInputFormat,
599 test_stream_.size, 682 test_stream_.size,
600 test_stream_.requested_profile, 683 test_stream_.requested_profile,
601 test_stream_.requested_bitrate, 684 requested_bitrate_,
602 this)) { 685 this)) {
603 DLOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; 686 DLOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed";
604 SetState(CS_ERROR); 687 SetState(CS_ERROR);
605 return; 688 return;
606 } 689 }
607 690
608 SetStreamParameters(test_stream_.requested_bitrate, 691 SetStreamParameters(requested_bitrate_, requested_framerate_);
609 test_stream_.requested_framerate);
610 SetState(CS_INITIALIZED); 692 SetState(CS_INITIALIZED);
611 } 693 }
612 694
613 void VEAClient::DestroyEncoder() { 695 void VEAClient::DestroyEncoder() {
614 DCHECK(thread_checker_.CalledOnValidThread()); 696 DCHECK(thread_checker_.CalledOnValidThread());
615 if (!has_encoder()) 697 if (!has_encoder())
616 return; 698 return;
617 encoder_.reset(); 699 encoder_.reset();
618 } 700 }
619 701
702 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch,
703 bool mid_stream_framerate_switch) {
704 // Use defaults for bitrate/framerate if they are not provided.
705 if (test_stream_.requested_bitrate == 0)
706 requested_bitrate_ = kDefaultBitrate;
707 else
708 requested_bitrate_ = test_stream_.requested_bitrate;
709
710 if (test_stream_.requested_framerate == 0)
711 requested_framerate_ = kDefaultFramerate;
712 else
713 requested_framerate_ = test_stream_.requested_framerate;
714
715 // If bitrate/framerate switch is requested, use the subsequent values if
716 // provided, or, if not, calculate them from their initial values using
717 // the default ratios.
718 // Otherwise, if a switch is not requested, keep the initial values.
719 if (mid_stream_bitrate_switch) {
720 if (test_stream_.requested_subsequent_bitrate == 0)
721 requested_subsequent_bitrate_ =
722 requested_bitrate_ * kDefaultSubsequentBitrateRatio;
723 else
724 requested_subsequent_bitrate_ = test_stream_.requested_subsequent_bitrate;
725 } else {
726 requested_subsequent_bitrate_ = requested_bitrate_;
727 }
728 if (requested_subsequent_bitrate_ == 0)
729 requested_subsequent_bitrate_ = 1;
730
731 if (mid_stream_framerate_switch) {
732 if (test_stream_.requested_subsequent_framerate == 0)
733 requested_subsequent_framerate_ =
734 requested_framerate_ * kDefaultSubsequentFramerateRatio;
735 else
736 requested_subsequent_framerate_ =
737 test_stream_.requested_subsequent_framerate;
738 } else {
739 requested_subsequent_framerate_ = requested_framerate_;
740 }
741 if (requested_subsequent_framerate_ == 0)
742 requested_subsequent_framerate_ = 1;
743 }
744
620 double VEAClient::frames_per_second() { 745 double VEAClient::frames_per_second() {
621 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_; 746 base::TimeDelta duration = last_frame_ready_time_ - encode_start_time_;
622 return num_encoded_frames_ / duration.InSecondsF(); 747 return num_encoded_frames_ / duration.InSecondsF();
623 } 748 }
624 749
625 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, 750 void VEAClient::RequireBitstreamBuffers(unsigned int input_count,
626 const gfx::Size& input_coded_size, 751 const gfx::Size& input_coded_size,
627 size_t output_size) { 752 size_t output_size) {
628 DCHECK(thread_checker_.CalledOnValidThread()); 753 DCHECK(thread_checker_.CalledOnValidThread());
629 ASSERT_EQ(state_, CS_INITIALIZED); 754 ASSERT_EQ(state_, CS_INITIALIZED);
630 SetState(CS_ENCODING); 755 SetState(CS_ENCODING);
631 756
632 // TODO(posciak): For now we only support input streams that meet encoder 757 PrepareInputBuffers(test_stream_.size,
Pawel Osciak 2014/09/05 07:21:32 Please just pass the test stream, instead of its m
henryhsu 2014/09/10 11:01:49 Done.
633 // size requirements exactly (i.e. coded size == visible size), so that we 758 input_coded_size,
634 // can simply mmap the stream file and feed the encoder directly with chunks 759 test_stream_.in_filename,
635 // of that, instead of memcpying from mmapped file into a separate set of 760 &test_stream_.input_file,
636 // input buffers that would meet the coded size and alignment requirements. 761 &test_stream_.temp_file,
637 // If/when this is changed, the ARM-specific alignment check below should be 762 &input_buffer_size_);
638 // redone as well. 763 CHECK_GT(input_buffer_size_, 0UL);
764
765 // Calculate the number of frames in the input stream by dividing its length
766 // in bytes by frame size in bytes.
767 CHECK_EQ(test_stream_.input_file.length() % input_buffer_size_, 0U)
768 << "Stream byte size is not a product of calculated frame byte size";
769 num_frames_in_stream_ = test_stream_.input_file.length() / input_buffer_size_;
Pawel Osciak 2014/09/05 07:21:32 This is already calculated in PrepareInputBuffers.
henryhsu 2014/09/10 11:01:49 We put input_buffer_size and num_frames into TestS
Pawel Osciak 2014/09/11 09:51:46 Acknowledged.
770 CHECK_GT(num_frames_in_stream_, 0UL);
771 CHECK_LE(num_frames_in_stream_, kMaxFrameNum);
772
773 // We may need to loop over the stream more than once if more frames than
774 // provided is required for bitrate tests.
775 if (force_bitrate_ && num_frames_in_stream_ < kMinFramesForBitrateTests) {
776 DVLOG(1) << "Stream too short for bitrate test (" << num_frames_in_stream_
777 << " frames), will loop it to reach " << kMinFramesForBitrateTests
778 << " frames";
779 num_frames_to_encode_ = kMinFramesForBitrateTests;
780 } else {
781 num_frames_to_encode_ = num_frames_in_stream_;
782 }
783
639 input_coded_size_ = input_coded_size; 784 input_coded_size_ = input_coded_size;
640 ASSERT_EQ(input_coded_size_, test_stream_.size);
641 #if defined(ARCH_CPU_ARMEL)
642 // ARM performs CPU cache management with CPU cache line granularity. We thus
643 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned).
644 // Otherwise newer kernels will refuse to accept them, and on older kernels
645 // we'll be treating ourselves to random corruption.
646 // Since we are just mmapping and passing chunks of the input file, to ensure
647 // alignment, if the starting virtual addresses of the frames in it were not
648 // 64 byte-aligned, we'd have to use a separate set of input buffers and copy
649 // the frames into them before sending to the encoder. It would have been an
650 // overkill here though, because, for now at least, we only test resolutions
651 // that result in proper alignment, and it would have also interfered with
652 // performance testing. So just assert that the frame size is a multiple of
653 // 64 bytes. This ensures all frames start at 64-byte boundary, because
654 // MemoryMappedFile should be mmapp()ed at virtual page start as well.
655 ASSERT_EQ(input_buffer_size_ & 63, 0u)
656 << "Frame size has to be a multiple of 64 bytes";
657 ASSERT_EQ(reinterpret_cast<off_t>(test_stream_.input_file.data()) & 63, 0)
658 << "Mapped file should be mapped at a 64 byte boundary";
659 #endif
660
661 num_required_input_buffers_ = input_count; 785 num_required_input_buffers_ = input_count;
662 ASSERT_GT(num_required_input_buffers_, 0UL); 786 ASSERT_GT(num_required_input_buffers_, 0UL);
663 787
664 output_buffer_size_ = output_size; 788 output_buffer_size_ = output_size;
665 ASSERT_GT(output_buffer_size_, 0UL); 789 ASSERT_GT(output_buffer_size_, 0UL);
666 790
667 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { 791 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) {
668 base::SharedMemory* shm = new base::SharedMemory(); 792 base::SharedMemory* shm = new base::SharedMemory();
669 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); 793 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_));
670 output_shms_.push_back(shm); 794 output_shms_.push_back(shm);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 860 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
737 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 861 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
738 ASSERT_NE(it, inputs_at_client_.end()); 862 ASSERT_NE(it, inputs_at_client_.end());
739 inputs_at_client_.erase(it); 863 inputs_at_client_.erase(it);
740 FeedEncoderWithInputs(); 864 FeedEncoderWithInputs();
741 } 865 }
742 866
743 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { 867 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) {
744 CHECK_LE(position + input_buffer_size_, test_stream_.input_file.length()); 868 CHECK_LE(position + input_buffer_size_, test_stream_.input_file.length());
745 869
746 uint8* frame_data = 870 uint8* frame_data_y =
747 const_cast<uint8*>(test_stream_.input_file.data() + position); 871 const_cast<uint8*>(test_stream_.input_file.data() + position);
872 uint8* frame_data_u =
Pawel Osciak 2014/09/05 07:21:32 It would be better to have these as the property o
henryhsu 2014/09/10 11:01:49 Done.
873 frame_data_y + ALIGN_64_BYTES(media::VideoFrame::PlaneAllocationSize(
874 kInputFormat, 0, input_coded_size_));
875 uint8* frame_data_v =
876 frame_data_u + ALIGN_64_BYTES(media::VideoFrame::PlaneAllocationSize(
877 kInputFormat, 1, input_coded_size_));
748 878
749 CHECK_GT(current_framerate_, 0U); 879 CHECK_GT(current_framerate_, 0U);
750 scoped_refptr<media::VideoFrame> frame = 880 scoped_refptr<media::VideoFrame> frame =
751 media::VideoFrame::WrapExternalYuvData( 881 media::VideoFrame::WrapExternalYuvData(
752 kInputFormat, 882 kInputFormat,
753 input_coded_size_, 883 input_coded_size_,
754 gfx::Rect(test_stream_.size), 884 gfx::Rect(test_stream_.size),
755 test_stream_.size, 885 test_stream_.size,
756 input_coded_size_.width(), 886 input_coded_size_.width(),
757 input_coded_size_.width() / 2, 887 input_coded_size_.width() / 2,
758 input_coded_size_.width() / 2, 888 input_coded_size_.width() / 2,
759 frame_data, 889 frame_data_y,
760 frame_data + input_coded_size_.GetArea(), 890 frame_data_u,
761 frame_data + (input_coded_size_.GetArea() * 5 / 4), 891 frame_data_v,
762 base::TimeDelta().FromMilliseconds( 892 base::TimeDelta().FromMilliseconds(
763 next_input_id_ * base::Time::kMillisecondsPerSecond / 893 next_input_id_ * base::Time::kMillisecondsPerSecond /
764 current_framerate_), 894 current_framerate_),
765 media::BindToCurrentLoop( 895 media::BindToCurrentLoop(
766 base::Bind(&VEAClient::InputNoLongerNeededCallback, 896 base::Bind(&VEAClient::InputNoLongerNeededCallback,
767 base::Unretained(this), 897 base::Unretained(this),
768 next_input_id_))); 898 next_input_id_)));
769 899
770 CHECK(inputs_at_client_.insert(next_input_id_).second); 900 CHECK(inputs_at_client_.insert(next_input_id_).second);
771 ++next_input_id_; 901 ++next_input_id_;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 // is asynchronous, i.e. not bound to any concrete frame, and because 977 // is asynchronous, i.e. not bound to any concrete frame, and because
848 // the pipeline can be deeper than one frame), at that frame, or after. 978 // the pipeline can be deeper than one frame), at that frame, or after.
849 // So the only constraints we put here is that we get a keyframe not 979 // So the only constraints we put here is that we get a keyframe not
850 // earlier than we requested one (in time), and not later than 980 // earlier than we requested one (in time), and not later than
851 // kMaxKeyframeDelay frames after the frame, for which we requested 981 // kMaxKeyframeDelay frames after the frame, for which we requested
852 // it, comes back encoded. 982 // it, comes back encoded.
853 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay); 983 EXPECT_LE(num_encoded_frames_, keyframe_requested_at_ + kMaxKeyframeDelay);
854 984
855 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { 985 if (num_encoded_frames_ == num_frames_to_encode_ / 2) {
856 VerifyStreamProperties(); 986 VerifyStreamProperties();
857 if (test_stream_.requested_subsequent_bitrate != 987 if (requested_subsequent_bitrate_ != current_requested_bitrate_ ||
Pawel Osciak 2014/09/05 07:21:32 Please keep those as a property of TestStream.
henryhsu 2014/09/10 11:01:50 Since TestStream is a property of environment obje
Pawel Osciak 2014/09/11 09:51:46 Acknowledged.
858 current_requested_bitrate_ || 988 requested_subsequent_framerate_ != current_framerate_) {
859 test_stream_.requested_subsequent_framerate != current_framerate_) { 989 SetStreamParameters(requested_subsequent_bitrate_,
860 SetStreamParameters(test_stream_.requested_subsequent_bitrate, 990 requested_subsequent_framerate_);
861 test_stream_.requested_subsequent_framerate);
862 } 991 }
863 } else if (num_encoded_frames_ == num_frames_to_encode_) { 992 } else if (num_encoded_frames_ == num_frames_to_encode_) {
864 VerifyPerf(); 993 VerifyPerf();
865 VerifyStreamProperties(); 994 VerifyStreamProperties();
866 SetState(CS_FINISHED); 995 SetState(CS_FINISHED);
867 return false; 996 return false;
868 } 997 }
869 998
870 return true; 999 return true;
871 } 1000 }
(...skipping 18 matching lines...) Expand all
890 num_frames_since_last_check_ = 0; 1019 num_frames_since_last_check_ = 0;
891 encoded_stream_size_since_last_check_ = 0; 1020 encoded_stream_size_since_last_check_ = 0;
892 1021
893 if (force_bitrate_) { 1022 if (force_bitrate_) {
894 EXPECT_NEAR(bitrate, 1023 EXPECT_NEAR(bitrate,
895 current_requested_bitrate_, 1024 current_requested_bitrate_,
896 kBitrateTolerance * current_requested_bitrate_); 1025 kBitrateTolerance * current_requested_bitrate_);
897 } 1026 }
898 } 1027 }
899 1028
1029 class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
Pawel Osciak 2014/09/05 07:21:33 Documentation please.
henryhsu 2014/09/10 11:01:49 Done.
1030 public:
1031 virtual void TearDown() {
1032 for (size_t i = 0; i < g_test_streams_size; i++)
1033 base::DeleteFile(g_test_streams[i].temp_file, false);
1034 delete[] g_test_streams;
1035 g_test_streams = NULL;
1036 }
1037 };
1038
900 // Test parameters: 1039 // Test parameters:
901 // - Number of concurrent encoders. 1040 // - Number of concurrent encoders.
902 // - If true, save output to file (provided an output filename was supplied). 1041 // - If true, save output to file (provided an output filename was supplied).
903 // - Force a keyframe every n frames. 1042 // - Force a keyframe every n frames.
904 // - Force bitrate; the actual required value is provided as a property 1043 // - Force bitrate; the actual required value is provided as a property
905 // of the input stream, because it depends on stream type/resolution/etc. 1044 // of the input stream, because it depends on stream type/resolution/etc.
906 // - If true, measure performance. 1045 // - If true, measure performance.
907 // - If true, switch bitrate mid-stream. 1046 // - If true, switch bitrate mid-stream.
908 // - If true, switch framerate mid-stream. 1047 // - If true, switch framerate mid-stream.
909 class VideoEncodeAcceleratorTest 1048 class VideoEncodeAcceleratorTest
910 : public ::testing::TestWithParam< 1049 : public ::testing::TestWithParam<
911 Tuple7<int, bool, int, bool, bool, bool, bool> > {}; 1050 Tuple7<int, bool, int, bool, bool, bool, bool> > {};
912 1051
913 TEST_P(VideoEncodeAcceleratorTest, TestSimpleEncode) { 1052 TEST_P(VideoEncodeAcceleratorTest, TestSimpleEncode) {
914 const size_t num_concurrent_encoders = GetParam().a; 1053 const size_t num_concurrent_encoders = GetParam().a;
915 const bool save_to_file = GetParam().b; 1054 const bool save_to_file = GetParam().b;
916 const unsigned int keyframe_period = GetParam().c; 1055 const unsigned int keyframe_period = GetParam().c;
917 const bool force_bitrate = GetParam().d; 1056 const bool force_bitrate = GetParam().d;
918 const bool test_perf = GetParam().e; 1057 const bool test_perf = GetParam().e;
919 const bool mid_stream_bitrate_switch = GetParam().f; 1058 const bool mid_stream_bitrate_switch = GetParam().f;
920 const bool mid_stream_framerate_switch = GetParam().g; 1059 const bool mid_stream_framerate_switch = GetParam().g;
921 1060
922 // Initialize the test streams.
923 ScopedVector<TestStream> test_streams;
924 ParseAndReadTestStreamData(*g_test_stream_data, &test_streams);
925 UpdateTestStreamData(
926 mid_stream_bitrate_switch, mid_stream_framerate_switch, &test_streams);
927
928 ScopedVector<ClientStateNotification<ClientState> > notes; 1061 ScopedVector<ClientStateNotification<ClientState> > notes;
929 ScopedVector<VEAClient> clients; 1062 ScopedVector<VEAClient> clients;
930 base::Thread encoder_thread("EncoderThread"); 1063 base::Thread encoder_thread("EncoderThread");
931 ASSERT_TRUE(encoder_thread.Start()); 1064 ASSERT_TRUE(encoder_thread.Start());
932 1065
933 // Create all encoders. 1066 // Create all encoders.
934 for (size_t i = 0; i < num_concurrent_encoders; i++) { 1067 for (size_t i = 0; i < num_concurrent_encoders; i++) {
935 size_t test_stream_index = i % test_streams.size(); 1068 size_t test_stream_index = i % g_test_streams_size;
936 // Disregard save_to_file if we didn't get an output filename. 1069 // Disregard save_to_file if we didn't get an output filename.
937 bool encoder_save_to_file = 1070 bool encoder_save_to_file =
938 (save_to_file && 1071 (save_to_file &&
939 !test_streams[test_stream_index]->out_filename.empty()); 1072 !g_test_streams[test_stream_index].out_filename.empty());
940 1073
941 notes.push_back(new ClientStateNotification<ClientState>()); 1074 notes.push_back(new ClientStateNotification<ClientState>());
942 clients.push_back(new VEAClient(*test_streams[test_stream_index], 1075 clients.push_back(new VEAClient(g_test_streams[test_stream_index],
943 notes.back(), 1076 notes.back(),
944 encoder_save_to_file, 1077 encoder_save_to_file,
945 keyframe_period, 1078 keyframe_period,
946 force_bitrate, 1079 force_bitrate,
947 test_perf)); 1080 test_perf,
1081 mid_stream_bitrate_switch,
Pawel Osciak 2014/09/05 07:21:34 Please update the streams from here like before, n
henryhsu 2014/09/10 11:01:50 requested_subsequent_bitrate and requested_subsequ
Pawel Osciak 2014/09/11 09:51:46 Acknowledged.
1082 mid_stream_framerate_switch));
948 1083
949 encoder_thread.message_loop()->PostTask( 1084 encoder_thread.message_loop()->PostTask(
950 FROM_HERE, 1085 FROM_HERE,
951 base::Bind(&VEAClient::CreateEncoder, 1086 base::Bind(&VEAClient::CreateEncoder,
952 base::Unretained(clients.back()))); 1087 base::Unretained(clients.back())));
953 } 1088 }
954 1089
955 // All encoders must pass through states in this order. 1090 // All encoders must pass through states in this order.
956 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED, 1091 enum ClientState state_transitions[] = {CS_ENCODER_SET, CS_INITIALIZED,
957 CS_ENCODING, CS_FINISHED}; 1092 CS_ENCODING, CS_FINISHED};
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 // TODO(posciak): more tests: 1156 // TODO(posciak): more tests:
1022 // - async FeedEncoderWithOutput 1157 // - async FeedEncoderWithOutput
1023 // - out-of-order return of outputs to encoder 1158 // - out-of-order return of outputs to encoder
1024 // - multiple encoders + decoders 1159 // - multiple encoders + decoders
1025 // - mid-stream encoder_->Destroy() 1160 // - mid-stream encoder_->Destroy()
1026 1161
1027 } // namespace 1162 } // namespace
1028 } // namespace content 1163 } // namespace content
1029 1164
1030 int main(int argc, char** argv) { 1165 int main(int argc, char** argv) {
1166 testing::AddGlobalTestEnvironment(
1167 new content::VideoEncodeAcceleratorTestEnvironment);
1031 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args. 1168 testing::InitGoogleTest(&argc, argv); // Removes gtest-specific args.
1032 base::CommandLine::Init(argc, argv); 1169 base::CommandLine::Init(argc, argv);
1033 1170
1034 base::ShadowingAtExitManager at_exit_manager; 1171 base::ShadowingAtExitManager at_exit_manager;
1035 scoped_ptr<base::FilePath::StringType> test_stream_data( 1172 scoped_ptr<base::FilePath::StringType> test_stream_data(
1036 new base::FilePath::StringType( 1173 new base::FilePath::StringType(
1037 media::GetTestDataFilePath(content::g_default_in_filename).value() + 1174 media::GetTestDataFilePath(content::g_default_in_filename).value() +
1038 content::g_default_in_parameters)); 1175 content::g_default_in_parameters));
1039 content::g_test_stream_data = test_stream_data.get(); 1176 content::g_test_stream_data = test_stream_data.get();
1040 1177
(...skipping 10 matching lines...) Expand all
1051 it != switches.end(); 1188 it != switches.end();
1052 ++it) { 1189 ++it) {
1053 if (it->first == "test_stream_data") { 1190 if (it->first == "test_stream_data") {
1054 test_stream_data->assign(it->second.c_str()); 1191 test_stream_data->assign(it->second.c_str());
1055 continue; 1192 continue;
1056 } 1193 }
1057 if (it->first == "v" || it->first == "vmodule") 1194 if (it->first == "v" || it->first == "vmodule")
1058 continue; 1195 continue;
1059 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 1196 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
1060 } 1197 }
1061 1198 content::ParseAndReadTestStreamData(*content::g_test_stream_data,
Pawel Osciak 2014/09/05 07:21:33 There is a Environment::SetUp() call, a counterpar
henryhsu 2014/09/10 11:01:49 Done.
1199 &content::g_test_streams,
1200 &content::g_test_streams_size);
1062 return RUN_ALL_TESTS(); 1201 return RUN_ALL_TESTS();
1063 } 1202 }
OLDNEW
« no previous file with comments | « no previous file | media/base/video_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698