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/process/process.h" | 11 #include "base/process/process.h" |
12 #include "base/safe_numerics.h" | 12 #include "base/safe_numerics.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 "content/common/gpu/media/exynos_video_encode_accelerator.h" | 15 #include "content/common/gpu/media/exynos_video_encode_accelerator.h" |
16 #include "content/common/gpu/media/h264_parser.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" |
| 19 #include "media/filters/h264_parser.h" |
20 #include "media/video/video_encode_accelerator.h" | 20 #include "media/video/video_encode_accelerator.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using media::VideoEncodeAccelerator; | 23 using media::VideoEncodeAccelerator; |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Arbitrarily chosen to add some depth to the pipeline. | 28 // Arbitrarily chosen to add some depth to the pipeline. |
29 const unsigned int kNumOutputBuffers = 4; | 29 const unsigned int kNumOutputBuffers = 4; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 bool save_to_file_; | 174 bool save_to_file_; |
175 // Request a keyframe every keyframe_period_ frames. | 175 // Request a keyframe every keyframe_period_ frames. |
176 const unsigned int keyframe_period_; | 176 const unsigned int keyframe_period_; |
177 // Frame number for which we requested a keyframe. | 177 // Frame number for which we requested a keyframe. |
178 unsigned int keyframe_requested_at_; | 178 unsigned int keyframe_requested_at_; |
179 // True if we are asking encoder for a particular bitrate. | 179 // True if we are asking encoder for a particular bitrate. |
180 bool force_bitrate_; | 180 bool force_bitrate_; |
181 // Byte size of the encoded stream (for bitrate calculation). | 181 // Byte size of the encoded stream (for bitrate calculation). |
182 size_t encoded_stream_size_; | 182 size_t encoded_stream_size_; |
183 | 183 |
184 content::H264Parser h264_parser_; | 184 media::H264Parser h264_parser_; |
185 | 185 |
186 // All methods of this class should be run on the same thread. | 186 // All methods of this class should be run on the same thread. |
187 base::ThreadChecker thread_checker_; | 187 base::ThreadChecker thread_checker_; |
188 }; | 188 }; |
189 | 189 |
190 VEAClient::VEAClient(const TestStream& test_stream, | 190 VEAClient::VEAClient(const TestStream& test_stream, |
191 ClientStateNotification<ClientState>* note, | 191 ClientStateNotification<ClientState>* note, |
192 bool save_to_file, | 192 bool save_to_file, |
193 unsigned int keyframe_period, | 193 unsigned int keyframe_period, |
194 bool force_bitrate) | 194 bool force_bitrate) |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (state_ == CS_FINISHED) | 312 if (state_ == CS_FINISHED) |
313 return; | 313 return; |
314 | 314 |
315 encoded_stream_size_ += payload_size; | 315 encoded_stream_size_ += payload_size; |
316 | 316 |
317 h264_parser_.SetStream(static_cast<uint8*>(shm->memory()), payload_size); | 317 h264_parser_.SetStream(static_cast<uint8*>(shm->memory()), payload_size); |
318 | 318 |
319 bool seen_idr_in_this_buffer = false; | 319 bool seen_idr_in_this_buffer = false; |
320 | 320 |
321 while (1) { | 321 while (1) { |
322 content::H264NALU nalu; | 322 media::H264NALU nalu; |
323 content::H264Parser::Result result; | 323 media::H264Parser::Result result; |
324 | 324 |
325 result = h264_parser_.AdvanceToNextNALU(&nalu); | 325 result = h264_parser_.AdvanceToNextNALU(&nalu); |
326 if (result == content::H264Parser::kEOStream) | 326 if (result == media::H264Parser::kEOStream) |
327 break; | 327 break; |
328 | 328 |
329 ASSERT_EQ(result, content::H264Parser::kOk); | 329 ASSERT_EQ(result, media::H264Parser::kOk); |
330 | 330 |
331 switch (nalu.nal_unit_type) { | 331 switch (nalu.nal_unit_type) { |
332 case content::H264NALU::kIDRSlice: | 332 case media::H264NALU::kIDRSlice: |
333 ASSERT_TRUE(seen_sps_); | 333 ASSERT_TRUE(seen_sps_); |
334 ASSERT_TRUE(seen_pps_); | 334 ASSERT_TRUE(seen_pps_); |
335 seen_idr_ = seen_idr_in_this_buffer = true; | 335 seen_idr_ = seen_idr_in_this_buffer = true; |
336 // Got keyframe, reset keyframe detection regardless of whether we | 336 // Got keyframe, reset keyframe detection regardless of whether we |
337 // got a frame in time or not. | 337 // got a frame in time or not. |
338 keyframe_requested_at_ = kMaxFrameNum; | 338 keyframe_requested_at_ = kMaxFrameNum; |
339 // fallthrough | 339 // fallthrough |
340 case content::H264NALU::kNonIDRSlice: | 340 case media::H264NALU::kNonIDRSlice: |
341 ASSERT_TRUE(seen_idr_); | 341 ASSERT_TRUE(seen_idr_); |
342 ++num_encoded_slices_; | 342 ++num_encoded_slices_; |
343 | 343 |
344 // Because the keyframe behavior requirements are loose, we give | 344 // Because the keyframe behavior requirements are loose, we give |
345 // the encoder more freedom here. It could either deliver a keyframe | 345 // the encoder more freedom here. It could either deliver a keyframe |
346 // immediately after we requested it, which could be for a frame number | 346 // immediately after we requested it, which could be for a frame number |
347 // before the one we requested it for (if the keyframe request | 347 // before the one we requested it for (if the keyframe request |
348 // is asynchronous, i.e. not bound to any concrete frame, and because | 348 // is asynchronous, i.e. not bound to any concrete frame, and because |
349 // the pipeline can be deeper that one frame), at that frame, or after. | 349 // the pipeline can be deeper that one frame), at that frame, or after. |
350 // So the only constraints we put here is that we get a keyframe not | 350 // So the only constraints we put here is that we get a keyframe not |
351 // earlier than we requested one (in time), and not later than | 351 // earlier than we requested one (in time), and not later than |
352 // kMaxKeyframeDelay frames after the frame for which we requested | 352 // kMaxKeyframeDelay frames after the frame for which we requested |
353 // it comes back as encoded slice. | 353 // it comes back as encoded slice. |
354 EXPECT_LE(num_encoded_slices_, | 354 EXPECT_LE(num_encoded_slices_, |
355 keyframe_requested_at_ + kMaxKeyframeDelay); | 355 keyframe_requested_at_ + kMaxKeyframeDelay); |
356 break; | 356 break; |
357 case content::H264NALU::kSPS: | 357 case media::H264NALU::kSPS: |
358 seen_sps_ = true; | 358 seen_sps_ = true; |
359 break; | 359 break; |
360 case content::H264NALU::kPPS: | 360 case media::H264NALU::kPPS: |
361 ASSERT_TRUE(seen_sps_); | 361 ASSERT_TRUE(seen_sps_); |
362 seen_pps_ = true; | 362 seen_pps_ = true; |
363 break; | 363 break; |
364 default: | 364 default: |
365 break; | 365 break; |
366 } | 366 } |
367 | 367 |
368 if (num_encoded_slices_ == num_frames_in_stream_) { | 368 if (num_encoded_slices_ == num_frames_in_stream_) { |
369 ASSERT_EQ(state_, CS_FINISHING); | 369 ASSERT_EQ(state_, CS_FINISHING); |
370 ChecksAtFinish(); | 370 ChecksAtFinish(); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 592 } |
593 if (it->first == "v" || it->first == "vmodule") | 593 if (it->first == "v" || it->first == "vmodule") |
594 continue; | 594 continue; |
595 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; | 595 LOG(FATAL) << "Unexpected switch: " << it->first << ":" << it->second; |
596 } | 596 } |
597 | 597 |
598 base::ShadowingAtExitManager at_exit_manager; | 598 base::ShadowingAtExitManager at_exit_manager; |
599 | 599 |
600 return RUN_ALL_TESTS(); | 600 return RUN_ALL_TESTS(); |
601 } | 601 } |
OLD | NEW |