Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | |
| 17 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" | 16 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h" |
| 18 #include "media/base/bind_to_current_loop.h" | 17 #include "media/base/bind_to_current_loop.h" |
| 19 #include "media/base/bitstream_buffer.h" | 18 #include "media/base/bitstream_buffer.h" |
| 20 #include "media/base/test_data_util.h" | 19 #include "media/base/test_data_util.h" |
| 21 #include "media/filters/h264_parser.h" | 20 #include "media/filters/h264_parser.h" |
| 22 #include "media/video/video_encode_accelerator.h" | 21 #include "media/video/video_encode_accelerator.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 23 |
| 24 #if defined(USE_X11) | |
| 25 #include "ui/gfx/x/x11_types.h" | |
| 26 #endif | |
| 27 | |
| 28 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
| 29 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | |
|
wuchengli
2014/06/18 03:34:14
This should be the first include. Move this before
Pawel Osciak
2014/06/18 07:05:09
"Exception: sometimes, system-specific code needs
| |
| 30 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | |
| 31 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | |
| 32 #else | |
| 33 #error The VideoEncodeAcceleratorUnittest is not supported on this platform. | |
| 34 #endif | |
| 35 | |
| 25 using media::VideoEncodeAccelerator; | 36 using media::VideoEncodeAccelerator; |
| 26 | 37 |
| 27 namespace content { | 38 namespace content { |
| 28 namespace { | 39 namespace { |
| 29 | 40 |
| 30 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; | 41 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; |
| 31 | 42 |
| 32 // Arbitrarily chosen to add some depth to the pipeline. | 43 // Arbitrarily chosen to add some depth to the pipeline. |
| 33 const unsigned int kNumOutputBuffers = 4; | 44 const unsigned int kNumOutputBuffers = 4; |
| 34 const unsigned int kNumExtraInputFrames = 4; | 45 const unsigned int kNumExtraInputFrames = 4; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 seen_pps_(false), | 255 seen_pps_(false), |
| 245 seen_idr_(false) {} | 256 seen_idr_(false) {} |
| 246 | 257 |
| 247 void ProcessStreamBuffer(const uint8* stream, size_t size) OVERRIDE; | 258 void ProcessStreamBuffer(const uint8* stream, size_t size) OVERRIDE; |
| 248 | 259 |
| 249 private: | 260 private: |
| 250 // Set to true when encoder provides us with the corresponding NALU type. | 261 // Set to true when encoder provides us with the corresponding NALU type. |
| 251 bool seen_sps_; | 262 bool seen_sps_; |
| 252 bool seen_pps_; | 263 bool seen_pps_; |
| 253 bool seen_idr_; | 264 bool seen_idr_; |
| 265 | |
| 266 media::H264Parser h264_parser_; | |
| 254 }; | 267 }; |
| 255 | 268 |
| 256 void H264Validator::ProcessStreamBuffer(const uint8* stream, size_t size) { | 269 void H264Validator::ProcessStreamBuffer(const uint8* stream, size_t size) { |
| 257 media::H264Parser h264_parser; | 270 h264_parser_.SetStream(stream, size); |
| 258 h264_parser.SetStream(stream, size); | |
| 259 | 271 |
| 260 while (1) { | 272 while (1) { |
| 261 media::H264NALU nalu; | 273 media::H264NALU nalu; |
| 262 media::H264Parser::Result result; | 274 media::H264Parser::Result result; |
| 263 | 275 |
| 264 result = h264_parser.AdvanceToNextNALU(&nalu); | 276 result = h264_parser_.AdvanceToNextNALU(&nalu); |
| 265 if (result == media::H264Parser::kEOStream) | 277 if (result == media::H264Parser::kEOStream) |
| 266 break; | 278 break; |
| 267 | 279 |
| 268 ASSERT_EQ(result, media::H264Parser::kOk); | 280 ASSERT_EQ(result, media::H264Parser::kOk); |
| 269 | 281 |
| 270 bool keyframe = false; | 282 bool keyframe = false; |
| 271 | 283 |
| 272 switch (nalu.nal_unit_type) { | 284 switch (nalu.nal_unit_type) { |
| 273 case media::H264NALU::kIDRSlice: | 285 case media::H264NALU::kIDRSlice: |
| 274 ASSERT_TRUE(seen_sps_); | 286 ASSERT_TRUE(seen_sps_); |
| 275 ASSERT_TRUE(seen_pps_); | 287 ASSERT_TRUE(seen_pps_); |
| 276 seen_idr_ = keyframe = true; | 288 seen_idr_ = true; |
| 277 // fallthrough | 289 // fallthrough |
| 278 case media::H264NALU::kNonIDRSlice: | 290 case media::H264NALU::kNonIDRSlice: { |
| 279 ASSERT_TRUE(seen_idr_); | 291 ASSERT_TRUE(seen_idr_); |
| 292 | |
| 293 media::H264SliceHeader shdr; | |
| 294 ASSERT_EQ(h264_parser_.ParseSliceHeader(nalu, &shdr), | |
|
wuchengli
2014/06/18 03:34:13
The expectation (media::H264Parser::kOk) should be
Pawel Osciak
2014/06/18 07:05:09
Done.
| |
| 295 media::H264Parser::kOk); | |
| 296 keyframe = shdr.IsISlice() || shdr.IsSISlice(); | |
| 297 | |
| 280 if (!frame_cb_.Run(keyframe)) | 298 if (!frame_cb_.Run(keyframe)) |
| 281 return; | 299 return; |
| 282 break; | 300 break; |
| 301 } | |
| 283 | 302 |
| 284 case media::H264NALU::kSPS: | 303 case media::H264NALU::kSPS: { |
| 304 int sps_id; | |
| 305 ASSERT_EQ(h264_parser_.ParseSPS(&sps_id), media::H264Parser::kOk); | |
| 285 seen_sps_ = true; | 306 seen_sps_ = true; |
| 286 break; | 307 break; |
| 308 } | |
| 287 | 309 |
| 288 case media::H264NALU::kPPS: | 310 case media::H264NALU::kPPS: { |
| 289 ASSERT_TRUE(seen_sps_); | 311 ASSERT_TRUE(seen_sps_); |
| 312 int pps_id; | |
| 313 ASSERT_EQ(h264_parser_.ParsePPS(&pps_id), media::H264Parser::kOk); | |
| 290 seen_pps_ = true; | 314 seen_pps_ = true; |
| 291 break; | 315 break; |
| 316 } | |
| 292 | 317 |
| 293 default: | 318 default: |
| 294 break; | 319 break; |
| 295 } | 320 } |
| 296 } | 321 } |
| 297 } | 322 } |
| 298 | 323 |
| 299 class VP8Validator : public StreamValidator { | 324 class VP8Validator : public StreamValidator { |
| 300 public: | 325 public: |
| 301 explicit VP8Validator(const FrameFoundCallback& frame_cb) | 326 explicit VP8Validator(const FrameFoundCallback& frame_cb) |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 | 577 |
| 553 thread_checker_.DetachFromThread(); | 578 thread_checker_.DetachFromThread(); |
| 554 } | 579 } |
| 555 | 580 |
| 556 VEAClient::~VEAClient() { CHECK(!has_encoder()); } | 581 VEAClient::~VEAClient() { CHECK(!has_encoder()); } |
| 557 | 582 |
| 558 void VEAClient::CreateEncoder() { | 583 void VEAClient::CreateEncoder() { |
| 559 DCHECK(thread_checker_.CalledOnValidThread()); | 584 DCHECK(thread_checker_.CalledOnValidThread()); |
| 560 CHECK(!has_encoder()); | 585 CHECK(!has_encoder()); |
| 561 | 586 |
| 587 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) | |
| 562 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 588 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 563 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 589 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
| 590 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 591 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); | |
| 592 #endif | |
| 593 | |
| 564 SetState(CS_ENCODER_SET); | 594 SetState(CS_ENCODER_SET); |
| 565 | 595 |
| 566 DVLOG(1) << "Profile: " << test_stream_.requested_profile | 596 DVLOG(1) << "Profile: " << test_stream_.requested_profile |
| 567 << ", initial bitrate: " << test_stream_.requested_bitrate; | 597 << ", initial bitrate: " << test_stream_.requested_bitrate; |
| 568 if (!encoder_->Initialize(kInputFormat, | 598 if (!encoder_->Initialize(kInputFormat, |
| 569 test_stream_.size, | 599 test_stream_.size, |
| 570 test_stream_.requested_profile, | 600 test_stream_.requested_profile, |
| 571 test_stream_.requested_bitrate, | 601 test_stream_.requested_bitrate, |
| 572 this)) { | 602 this)) { |
| 573 DLOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | 603 DLOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1024 test_stream_data->assign(it->second.c_str()); | 1054 test_stream_data->assign(it->second.c_str()); |
| 1025 continue; | 1055 continue; |
| 1026 } | 1056 } |
| 1027 if (it->first == "v" || it->first == "vmodule") | 1057 if (it->first == "v" || it->first == "vmodule") |
| 1028 continue; | 1058 continue; |
| 1029 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 1059 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
| 1030 } | 1060 } |
| 1031 | 1061 |
| 1032 return RUN_ALL_TESTS(); | 1062 return RUN_ALL_TESTS(); |
| 1033 } | 1063 } |
| OLD | NEW |