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

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: address review comments of patch set 12 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
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)
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // stream. 91 // stream.
90 // - |requested_subsequent_framerate| framerate to switch to in the middle 92 // - |requested_subsequent_framerate| framerate to switch to in the middle
91 // of the stream. 93 // of the stream.
92 // Bitrate is only forced for tests that test bitrate. 94 // Bitrate is only forced for tests that test bitrate.
93 const char* g_default_in_filename = "bear_320x192_40frames.yuv"; 95 const char* g_default_in_filename = "bear_320x192_40frames.yuv";
94 const char* g_default_in_parameters = ":320:192:1:out.h264:200000"; 96 const char* g_default_in_parameters = ":320:192:1:out.h264:200000";
95 base::FilePath::StringType* g_test_stream_data; 97 base::FilePath::StringType* g_test_stream_data;
96 98
97 struct TestStream { 99 struct TestStream {
98 TestStream() 100 TestStream()
99 : requested_bitrate(0), 101 : input_file(NULL),
102 requested_bitrate(0),
100 requested_framerate(0), 103 requested_framerate(0),
101 requested_subsequent_bitrate(0), 104 requested_subsequent_bitrate(0),
102 requested_subsequent_framerate(0) {} 105 requested_subsequent_framerate(0) {}
103 ~TestStream() {} 106 ~TestStream() {}
104 107
105 gfx::Size size; 108 gfx::Size size;
106 base::MemoryMappedFile input_file; 109
110 // Input file name and the file must be an I420 (YUV planar) raw stream.
111 std::string in_filename;
112
113 // The memory mapped of |temp_file|
114 base::MemoryMappedFile* input_file;
wuchengli 2014/09/01 08:20:42 Use scoped_ptr to indicate ownership.
henryhsu 2014/09/01 08:57:36 Done.
115
116 // A temporary file used to prepare input buffers.
117 base::FilePath temp_file;
118
119 std::string out_filename;
107 media::VideoCodecProfile requested_profile; 120 media::VideoCodecProfile requested_profile;
108 std::string out_filename;
109 unsigned int requested_bitrate; 121 unsigned int requested_bitrate;
110 unsigned int requested_framerate; 122 unsigned int requested_framerate;
111 unsigned int requested_subsequent_bitrate; 123 unsigned int requested_subsequent_bitrate;
112 unsigned int requested_subsequent_framerate; 124 unsigned int requested_subsequent_framerate;
113 }; 125 };
114 126
127 // ARM performs CPU cache management with CPU cache line granularity. We thus
128 // need to ensure our buffers are CPU cache line-aligned (64 byte-aligned).
129 // Otherwise newer kernels will refuse to accept them, and on older kernels
130 // we'll be treating ourselves to random corruption.
131 // Since we are just mmapping and passing chunks of the input file, to ensure
132 // alignment, if the starting virtual addresses of YUV planes of the frames
133 // in it were not 64 byte-aligned, we'd have to prepare a memory with 64
134 // byte-aligned starting address and make sure the addresses of YUV planes of
135 // each frame are 64 byte-aligned before sending to the encoder.
136 // Now we test resolutions different from coded size and prepare chunks before
137 // encoding to avoid performance impact.
138 // Use |visible_size| and |coded_size| to copy YUV data into memory from
139 // |in_filename|. The copied result will be saved in |input_file|. Also
140 // calculate the byte size of an input frame and set it to |coded_buffer_size|.
141 // |temp_file| is used to prepare input buffers and will be deleted after test
142 // finished.
143 static void PrepareInputBuffers(const gfx::Size& visible_size,
144 const gfx::Size& coded_size,
145 const std::string in_filename,
146 base::MemoryMappedFile* input_file,
147 base::FilePath* temp_file,
148 size_t* coded_buffer_size) {
149 size_t input_num_planes = media::VideoFrame::NumPlanes(kInputFormat);
150 std::vector<size_t> padding_sizes(input_num_planes);
151 std::vector<size_t> coded_bpl(input_num_planes);
152 std::vector<size_t> visible_bpl(input_num_planes);
153 std::vector<size_t> visible_plane_rows(input_num_planes);
154
155 // YUV plane starting address should be 64 bytes alignment. Calculate padding
156 // size for each plane, and frame allocation size for coded size. Also store
157 // bytes per line information of coded size and visible size.
158 *coded_buffer_size = 0;
159 for (off_t i = 0; i < input_num_planes; i++) {
160 size_t size =
161 media::VideoFrame::PlaneAllocationSize(kInputFormat, i, coded_size);
162 size_t padding_bytes = ALIGN_64_BYTES(size) - size;
163 *coded_buffer_size += ALIGN_64_BYTES(size);
164
165 coded_bpl[i] =
166 media::VideoFrame::RowBytes(i, kInputFormat, coded_size.width());
167 visible_bpl[i] =
168 media::VideoFrame::RowBytes(i, kInputFormat, visible_size.width());
169 visible_plane_rows[i] =
170 media::VideoFrame::Rows(i, kInputFormat, visible_size.height());
171 size_t padding_rows =
172 media::VideoFrame::Rows(i, kInputFormat, coded_size.height()) -
173 visible_plane_rows[i];
174 padding_sizes[i] = padding_rows * coded_bpl[i] + padding_bytes;
175 }
176
177 // Test case may have many encoders and memory should be prepared once.
178 if (input_file && input_file->IsValid())
179 return;
180
181 base::MemoryMappedFile src_file;
182 CHECK(base::CreateTemporaryFile(temp_file));
183 CHECK(src_file.Initialize(base::FilePath(in_filename)));
184
185 size_t visible_buffer_size =
186 media::VideoFrame::AllocationSize(kInputFormat, visible_size);
187 size_t num_frames = src_file.length() / visible_buffer_size;
188 uint32 flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
189 base::File::FLAG_READ;
190
191 // Create a temporary file with coded_size length.
192 base::File file(*temp_file, flags);
193 file.SetLength(*coded_buffer_size * num_frames);
194 CHECK(input_file->Initialize(file.Pass(), true));
195
196 off_t src_offset = 0, dest_offset = 0;
197 while (src_offset < static_cast<off_t>(src_file.length())) {
198 for (off_t i = 0; i < input_num_planes; i++) {
199 #if defined(ARCH_CPU_ARMEL)
200 // Assert that each plane of frame starts at 64-byte boundary.
201 const uint8* ptr = input_file->data() + dest_offset;
202 ASSERT_EQ(reinterpret_cast<off_t>(ptr) & 63, 0)
203 << "Planes of frame should be mapped at a 64 byte boundary";
204 #endif
205 for (off_t j = 0; j < visible_plane_rows[i]; j++) {
206 const uint8* src = src_file.data() + src_offset;
207 uint8* dest = input_file->data() + dest_offset;
208 memcpy(dest, src, visible_bpl[i]);
209 src_offset += visible_bpl[i];
210 dest_offset += coded_bpl[i];
211 }
212 dest_offset += padding_sizes[i];
213 }
214 }
215 }
216
115 // Parse |data| into its constituent parts, set the various output fields 217 // Parse |data| into its constituent parts, set the various output fields
116 // accordingly, read in video stream, and store them to |test_streams|. 218 // accordingly, read in video stream, and store them to |test_streams|.
117 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, 219 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data,
118 ScopedVector<TestStream>* test_streams) { 220 ScopedVector<TestStream>* test_streams) {
119 // Split the string to individual test stream data. 221 // Split the string to individual test stream data.
120 std::vector<base::FilePath::StringType> test_streams_data; 222 std::vector<base::FilePath::StringType> test_streams_data;
121 base::SplitString(data, ';', &test_streams_data); 223 base::SplitString(data, ';', &test_streams_data);
122 CHECK_GE(test_streams_data.size(), 1U) << data; 224 CHECK_GE(test_streams_data.size(), 1U) << data;
123 225
124 // Parse each test stream data and read the input file. 226 // Parse each test stream data and read the input file.
125 for (size_t index = 0; index < test_streams_data.size(); ++index) { 227 for (size_t index = 0; index < test_streams_data.size(); ++index) {
126 std::vector<base::FilePath::StringType> fields; 228 std::vector<base::FilePath::StringType> fields;
127 base::SplitString(test_streams_data[index], ':', &fields); 229 base::SplitString(test_streams_data[index], ':', &fields);
128 CHECK_GE(fields.size(), 4U) << data; 230 CHECK_GE(fields.size(), 4U) << data;
129 CHECK_LE(fields.size(), 9U) << data; 231 CHECK_LE(fields.size(), 9U) << data;
130 TestStream* test_stream = new TestStream(); 232 TestStream* test_stream = new TestStream();
233 test_stream->input_file = new base::MemoryMappedFile();
131 234
132 base::FilePath::StringType filename = fields[0]; 235 test_stream->in_filename = fields[0];
133 int width, height; 236 int width, height;
134 CHECK(base::StringToInt(fields[1], &width)); 237 CHECK(base::StringToInt(fields[1], &width));
135 CHECK(base::StringToInt(fields[2], &height)); 238 CHECK(base::StringToInt(fields[2], &height));
136 test_stream->size = gfx::Size(width, height); 239 test_stream->size = gfx::Size(width, height);
137 CHECK(!test_stream->size.IsEmpty()); 240 CHECK(!test_stream->size.IsEmpty());
138 int profile; 241 int profile;
139 CHECK(base::StringToInt(fields[3], &profile)); 242 CHECK(base::StringToInt(fields[3], &profile));
140 CHECK_GT(profile, media::VIDEO_CODEC_PROFILE_UNKNOWN); 243 CHECK_GT(profile, media::VIDEO_CODEC_PROFILE_UNKNOWN);
141 CHECK_LE(profile, media::VIDEO_CODEC_PROFILE_MAX); 244 CHECK_LE(profile, media::VIDEO_CODEC_PROFILE_MAX);
142 test_stream->requested_profile = 245 test_stream->requested_profile =
(...skipping 11 matching lines...) Expand all
154 if (fields.size() >= 8 && !fields[7].empty()) { 257 if (fields.size() >= 8 && !fields[7].empty()) {
155 CHECK(base::StringToUint(fields[7], 258 CHECK(base::StringToUint(fields[7],
156 &test_stream->requested_subsequent_bitrate)); 259 &test_stream->requested_subsequent_bitrate));
157 } 260 }
158 261
159 if (fields.size() >= 9 && !fields[8].empty()) { 262 if (fields.size() >= 9 && !fields[8].empty()) {
160 CHECK(base::StringToUint(fields[8], 263 CHECK(base::StringToUint(fields[8],
161 &test_stream->requested_subsequent_framerate)); 264 &test_stream->requested_subsequent_framerate));
162 } 265 }
163 266
164 CHECK(test_stream->input_file.Initialize(base::FilePath(filename)));
165 test_streams->push_back(test_stream); 267 test_streams->push_back(test_stream);
166 } 268 }
167 } 269 }
168 270
169 // Set default parameters of |test_streams| and update the parameters according 271 // Set default parameters of |test_streams| and update the parameters according
170 // to |mid_stream_bitrate_switch| and |mid_stream_framerate_switch|. 272 // to |mid_stream_bitrate_switch| and |mid_stream_framerate_switch|.
171 static void UpdateTestStreamData(bool mid_stream_bitrate_switch, 273 static void UpdateTestStreamData(bool mid_stream_bitrate_switch,
172 bool mid_stream_framerate_switch, 274 bool mid_stream_framerate_switch,
173 ScopedVector<TestStream>* test_streams) { 275 ScopedVector<TestStream>* test_streams) {
174 for (size_t i = 0; i < test_streams->size(); i++) { 276 for (size_t i = 0; i < test_streams->size(); i++) {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 validator.reset(new VP8Validator(frame_cb)); 463 validator.reset(new VP8Validator(frame_cb));
362 } else { 464 } else {
363 LOG(FATAL) << "Unsupported profile: " << profile; 465 LOG(FATAL) << "Unsupported profile: " << profile;
364 } 466 }
365 467
366 return validator.Pass(); 468 return validator.Pass();
367 } 469 }
368 470
369 class VEAClient : public VideoEncodeAccelerator::Client { 471 class VEAClient : public VideoEncodeAccelerator::Client {
370 public: 472 public:
371 VEAClient(const TestStream& test_stream, 473 VEAClient(TestStream& test_stream,
372 ClientStateNotification<ClientState>* note, 474 ClientStateNotification<ClientState>* note,
373 bool save_to_file, 475 bool save_to_file,
374 unsigned int keyframe_period, 476 unsigned int keyframe_period,
375 bool force_bitrate, 477 bool force_bitrate,
376 bool test_perf); 478 bool test_perf);
377 virtual ~VEAClient(); 479 virtual ~VEAClient();
378 void CreateEncoder(); 480 void CreateEncoder();
379 void DestroyEncoder(); 481 void DestroyEncoder();
380 482
381 // Return the number of encoded frames per second. 483 // Return the number of encoded frames per second.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // the performance test. 525 // the performance test.
424 void VerifyPerf(); 526 void VerifyPerf();
425 527
426 // Prepare and return a frame wrapping the data at |position| bytes in 528 // Prepare and return a frame wrapping the data at |position| bytes in
427 // the input stream, ready to be sent to encoder. 529 // the input stream, ready to be sent to encoder.
428 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position); 530 scoped_refptr<media::VideoFrame> PrepareInputFrame(off_t position);
429 531
430 ClientState state_; 532 ClientState state_;
431 scoped_ptr<VideoEncodeAccelerator> encoder_; 533 scoped_ptr<VideoEncodeAccelerator> encoder_;
432 534
433 const TestStream& test_stream_; 535 TestStream& test_stream_;
434 // Used to notify another thread about the state. VEAClient does not own this. 536 // Used to notify another thread about the state. VEAClient does not own this.
435 ClientStateNotification<ClientState>* note_; 537 ClientStateNotification<ClientState>* note_;
436 538
437 // Ids assigned to VideoFrames (start at 1 for easy comparison with 539 // Ids assigned to VideoFrames (start at 1 for easy comparison with
438 // num_encoded_frames_). 540 // num_encoded_frames_).
439 std::set<int32> inputs_at_client_; 541 std::set<int32> inputs_at_client_;
440 int32 next_input_id_; 542 int32 next_input_id_;
441 543
442 // Ids for output BitstreamBuffers. 544 // Ids for output BitstreamBuffers.
443 typedef std::map<int32, base::SharedMemory*> IdToSHM; 545 typedef std::map<int32, base::SharedMemory*> IdToSHM;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 // The time when the encoding started. 602 // The time when the encoding started.
501 base::TimeTicks encode_start_time_; 603 base::TimeTicks encode_start_time_;
502 604
503 // The time when the last encoded frame is ready. 605 // The time when the last encoded frame is ready.
504 base::TimeTicks last_frame_ready_time_; 606 base::TimeTicks last_frame_ready_time_;
505 607
506 // All methods of this class should be run on the same thread. 608 // All methods of this class should be run on the same thread.
507 base::ThreadChecker thread_checker_; 609 base::ThreadChecker thread_checker_;
508 }; 610 };
509 611
510 VEAClient::VEAClient(const TestStream& test_stream, 612 VEAClient::VEAClient(TestStream& test_stream,
511 ClientStateNotification<ClientState>* note, 613 ClientStateNotification<ClientState>* note,
512 bool save_to_file, 614 bool save_to_file,
513 unsigned int keyframe_period, 615 unsigned int keyframe_period,
514 bool force_bitrate, 616 bool force_bitrate,
515 bool test_perf) 617 bool test_perf)
516 : state_(CS_CREATED), 618 : state_(CS_CREATED),
517 test_stream_(test_stream), 619 test_stream_(test_stream),
518 note_(note), 620 note_(note),
519 next_input_id_(1), 621 next_input_id_(1),
520 next_output_buffer_id_(0), 622 next_output_buffer_id_(0),
(...skipping 24 matching lines...) Expand all
545 CHECK(validator_.get()); 647 CHECK(validator_.get());
546 648
547 if (save_to_file_) { 649 if (save_to_file_) {
548 CHECK(!test_stream_.out_filename.empty()); 650 CHECK(!test_stream_.out_filename.empty());
549 base::FilePath out_filename(test_stream_.out_filename); 651 base::FilePath out_filename(test_stream_.out_filename);
550 // This creates or truncates out_filename. 652 // This creates or truncates out_filename.
551 // Without it, AppendToFile() will not work. 653 // Without it, AppendToFile() will not work.
552 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); 654 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0));
553 } 655 }
554 656
555 input_buffer_size_ =
556 media::VideoFrame::AllocationSize(kInputFormat, test_stream.size);
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
578 thread_checker_.DetachFromThread(); 657 thread_checker_.DetachFromThread();
579 } 658 }
580 659
581 VEAClient::~VEAClient() { CHECK(!has_encoder()); } 660 VEAClient::~VEAClient() { CHECK(!has_encoder()); }
582 661
583 void VEAClient::CreateEncoder() { 662 void VEAClient::CreateEncoder() {
584 DCHECK(thread_checker_.CalledOnValidThread()); 663 DCHECK(thread_checker_.CalledOnValidThread());
585 CHECK(!has_encoder()); 664 CHECK(!has_encoder());
586 665
587 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) 666 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 return num_encoded_frames_ / duration.InSecondsF(); 701 return num_encoded_frames_ / duration.InSecondsF();
623 } 702 }
624 703
625 void VEAClient::RequireBitstreamBuffers(unsigned int input_count, 704 void VEAClient::RequireBitstreamBuffers(unsigned int input_count,
626 const gfx::Size& input_coded_size, 705 const gfx::Size& input_coded_size,
627 size_t output_size) { 706 size_t output_size) {
628 DCHECK(thread_checker_.CalledOnValidThread()); 707 DCHECK(thread_checker_.CalledOnValidThread());
629 ASSERT_EQ(state_, CS_INITIALIZED); 708 ASSERT_EQ(state_, CS_INITIALIZED);
630 SetState(CS_ENCODING); 709 SetState(CS_ENCODING);
631 710
632 // TODO(posciak): For now we only support input streams that meet encoder 711 PrepareInputBuffers(test_stream_.size,
633 // size requirements exactly (i.e. coded size == visible size), so that we 712 input_coded_size,
634 // can simply mmap the stream file and feed the encoder directly with chunks 713 test_stream_.in_filename,
635 // of that, instead of memcpying from mmapped file into a separate set of 714 test_stream_.input_file,
636 // input buffers that would meet the coded size and alignment requirements. 715 &test_stream_.temp_file,
637 // If/when this is changed, the ARM-specific alignment check below should be 716 &input_buffer_size_);
638 // redone as well. 717 CHECK_GT(input_buffer_size_, 0UL);
718
719 // Calculate the number of frames in the input stream by dividing its length
720 // in bytes by frame size in bytes.
721 CHECK_EQ(test_stream_.input_file->length() % input_buffer_size_, 0U)
722 << "Stream byte size is not a product of calculated frame byte size";
723 num_frames_in_stream_ =
724 test_stream_.input_file->length() / input_buffer_size_;
725 CHECK_GT(num_frames_in_stream_, 0UL);
726 CHECK_LE(num_frames_in_stream_, kMaxFrameNum);
727
728 // We may need to loop over the stream more than once if more frames than
729 // provided is required for bitrate tests.
730 if (force_bitrate_ && num_frames_in_stream_ < kMinFramesForBitrateTests) {
731 DVLOG(1) << "Stream too short for bitrate test (" << num_frames_in_stream_
732 << " frames), will loop it to reach " << kMinFramesForBitrateTests
733 << " frames";
734 num_frames_to_encode_ = kMinFramesForBitrateTests;
735 } else {
736 num_frames_to_encode_ = num_frames_in_stream_;
737 }
738
639 input_coded_size_ = input_coded_size; 739 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; 740 num_required_input_buffers_ = input_count;
662 ASSERT_GT(num_required_input_buffers_, 0UL); 741 ASSERT_GT(num_required_input_buffers_, 0UL);
663 742
664 output_buffer_size_ = output_size; 743 output_buffer_size_ = output_size;
665 ASSERT_GT(output_buffer_size_, 0UL); 744 ASSERT_GT(output_buffer_size_, 0UL);
666 745
667 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { 746 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) {
668 base::SharedMemory* shm = new base::SharedMemory(); 747 base::SharedMemory* shm = new base::SharedMemory();
669 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_)); 748 CHECK(shm->CreateAndMapAnonymous(output_buffer_size_));
670 output_shms_.push_back(shm); 749 output_shms_.push_back(shm);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 } 813 }
735 814
736 void VEAClient::InputNoLongerNeededCallback(int32 input_id) { 815 void VEAClient::InputNoLongerNeededCallback(int32 input_id) {
737 std::set<int32>::iterator it = inputs_at_client_.find(input_id); 816 std::set<int32>::iterator it = inputs_at_client_.find(input_id);
738 ASSERT_NE(it, inputs_at_client_.end()); 817 ASSERT_NE(it, inputs_at_client_.end());
739 inputs_at_client_.erase(it); 818 inputs_at_client_.erase(it);
740 FeedEncoderWithInputs(); 819 FeedEncoderWithInputs();
741 } 820 }
742 821
743 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) { 822 scoped_refptr<media::VideoFrame> VEAClient::PrepareInputFrame(off_t position) {
744 CHECK_LE(position + input_buffer_size_, test_stream_.input_file.length()); 823 CHECK_LE(position + input_buffer_size_, test_stream_.input_file->length());
745 824
746 uint8* frame_data = 825 uint8* frame_data_y =
747 const_cast<uint8*>(test_stream_.input_file.data() + position); 826 const_cast<uint8*>(test_stream_.input_file->data() + position);
827 uint8* frame_data_u =
828 frame_data_y + ALIGN_64_BYTES(media::VideoFrame::PlaneAllocationSize(
829 kInputFormat, 0, input_coded_size_));
830 uint8* frame_data_v =
831 frame_data_u + ALIGN_64_BYTES(media::VideoFrame::PlaneAllocationSize(
832 kInputFormat, 1, input_coded_size_));
748 833
749 CHECK_GT(current_framerate_, 0U); 834 CHECK_GT(current_framerate_, 0U);
750 scoped_refptr<media::VideoFrame> frame = 835 scoped_refptr<media::VideoFrame> frame =
751 media::VideoFrame::WrapExternalYuvData( 836 media::VideoFrame::WrapExternalYuvData(
752 kInputFormat, 837 kInputFormat,
753 input_coded_size_, 838 input_coded_size_,
754 gfx::Rect(test_stream_.size), 839 gfx::Rect(test_stream_.size),
755 test_stream_.size, 840 test_stream_.size,
756 input_coded_size_.width(), 841 input_coded_size_.width(),
757 input_coded_size_.width() / 2, 842 input_coded_size_.width() / 2,
758 input_coded_size_.width() / 2, 843 input_coded_size_.width() / 2,
759 frame_data, 844 frame_data_y,
760 frame_data + input_coded_size_.GetArea(), 845 frame_data_u,
761 frame_data + (input_coded_size_.GetArea() * 5 / 4), 846 frame_data_v,
762 base::TimeDelta().FromMilliseconds( 847 base::TimeDelta().FromMilliseconds(
763 next_input_id_ * base::Time::kMillisecondsPerSecond / 848 next_input_id_ * base::Time::kMillisecondsPerSecond /
764 current_framerate_), 849 current_framerate_),
765 media::BindToCurrentLoop( 850 media::BindToCurrentLoop(
766 base::Bind(&VEAClient::InputNoLongerNeededCallback, 851 base::Bind(&VEAClient::InputNoLongerNeededCallback,
767 base::Unretained(this), 852 base::Unretained(this),
768 next_input_id_))); 853 next_input_id_)));
769 854
770 CHECK(inputs_at_client_.insert(next_input_id_).second); 855 CHECK(inputs_at_client_.insert(next_input_id_).second);
771 ++next_input_id_; 856 ++next_input_id_;
772 857
773 return frame; 858 return frame;
774 } 859 }
775 860
776 void VEAClient::FeedEncoderWithInputs() { 861 void VEAClient::FeedEncoderWithInputs() {
777 if (!has_encoder()) 862 if (!has_encoder())
778 return; 863 return;
779 864
780 if (state_ != CS_ENCODING) 865 if (state_ != CS_ENCODING)
781 return; 866 return;
782 867
783 while (inputs_at_client_.size() < 868 while (inputs_at_client_.size() <
784 num_required_input_buffers_ + kNumExtraInputFrames) { 869 num_required_input_buffers_ + kNumExtraInputFrames) {
785 size_t bytes_left = test_stream_.input_file.length() - pos_in_input_stream_; 870 size_t bytes_left =
871 test_stream_.input_file->length() - pos_in_input_stream_;
786 if (bytes_left < input_buffer_size_) { 872 if (bytes_left < input_buffer_size_) {
787 DCHECK_EQ(bytes_left, 0UL); 873 DCHECK_EQ(bytes_left, 0UL);
788 // Rewind if at the end of stream and we are still encoding. 874 // Rewind if at the end of stream and we are still encoding.
789 // This is to flush the encoder with additional frames from the beginning 875 // This is to flush the encoder with additional frames from the beginning
790 // of the stream, or if the stream is shorter that the number of frames 876 // of the stream, or if the stream is shorter that the number of frames
791 // we require for bitrate tests. 877 // we require for bitrate tests.
792 pos_in_input_stream_ = 0; 878 pos_in_input_stream_ = 0;
793 continue; 879 continue;
794 } 880 }
795 881
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 ASSERT_EQ(notes[i]->Wait(), state_transitions[state_no]); 1054 ASSERT_EQ(notes[i]->Wait(), state_transitions[state_no]);
969 1055
970 for (size_t i = 0; i < num_concurrent_encoders; ++i) { 1056 for (size_t i = 0; i < num_concurrent_encoders; ++i) {
971 encoder_thread.message_loop()->PostTask( 1057 encoder_thread.message_loop()->PostTask(
972 FROM_HERE, 1058 FROM_HERE,
973 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i]))); 1059 base::Bind(&VEAClient::DestroyEncoder, base::Unretained(clients[i])));
974 } 1060 }
975 1061
976 // This ensures all tasks have finished. 1062 // This ensures all tasks have finished.
977 encoder_thread.Stop(); 1063 encoder_thread.Stop();
1064
1065 for (size_t i = 0; i < test_streams.size(); i++) {
1066 delete test_streams[i]->input_file;
1067 base::DeleteFile(test_streams[i]->temp_file, false);
1068 }
978 } 1069 }
979 1070
980 INSTANTIATE_TEST_CASE_P( 1071 INSTANTIATE_TEST_CASE_P(
981 SimpleEncode, 1072 SimpleEncode,
982 VideoEncodeAcceleratorTest, 1073 VideoEncodeAcceleratorTest,
983 ::testing::Values(MakeTuple(1, true, 0, false, false, false, false))); 1074 ::testing::Values(MakeTuple(1, true, 0, false, false, false, false)));
984 1075
985 INSTANTIATE_TEST_CASE_P( 1076 INSTANTIATE_TEST_CASE_P(
986 EncoderPerf, 1077 EncoderPerf,
987 VideoEncodeAcceleratorTest, 1078 VideoEncodeAcceleratorTest,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 test_stream_data->assign(it->second.c_str()); 1145 test_stream_data->assign(it->second.c_str());
1055 continue; 1146 continue;
1056 } 1147 }
1057 if (it->first == "v" || it->first == "vmodule") 1148 if (it->first == "v" || it->first == "vmodule")
1058 continue; 1149 continue;
1059 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; 1150 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second;
1060 } 1151 }
1061 1152
1062 return RUN_ALL_TESTS(); 1153 return RUN_ALL_TESTS();
1063 } 1154 }
OLDNEW
« no previous file with comments | « components/translate/content/renderer/data_file_renderer_cld_data_provider.cc ('k') | media/base/video_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698