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

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

Issue 1056133009: Fix the validation of the keyframe requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | no next file » | 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/files/file_util.h" 8 #include "base/files/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 namespace { 45 namespace {
46 46
47 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420; 47 const media::VideoFrame::Format kInputFormat = media::VideoFrame::I420;
48 48
49 // Arbitrarily chosen to add some depth to the pipeline. 49 // Arbitrarily chosen to add some depth to the pipeline.
50 const unsigned int kNumOutputBuffers = 4; 50 const unsigned int kNumOutputBuffers = 4;
51 const unsigned int kNumExtraInputFrames = 4; 51 const unsigned int kNumExtraInputFrames = 4;
52 // Maximum delay between requesting a keyframe and receiving one, in frames. 52 // Maximum delay between requesting a keyframe and receiving one, in frames.
53 // Arbitrarily chosen as a reasonable requirement. 53 // Arbitrarily chosen as a reasonable requirement.
54 const unsigned int kMaxKeyframeDelay = 4; 54 const unsigned int kMaxKeyframeDelay = 4;
55 // Value to use as max frame number for keyframe detection.
56 const unsigned int kMaxFrameNum =
57 std::numeric_limits<unsigned int>::max() - kMaxKeyframeDelay;
58 // Default initial bitrate. 55 // Default initial bitrate.
59 const uint32 kDefaultBitrate = 2000000; 56 const uint32 kDefaultBitrate = 2000000;
60 // Default ratio of requested_subsequent_bitrate to initial_bitrate 57 // Default ratio of requested_subsequent_bitrate to initial_bitrate
61 // (see test parameters below) if one is not provided. 58 // (see test parameters below) if one is not provided.
62 const double kDefaultSubsequentBitrateRatio = 2.0; 59 const double kDefaultSubsequentBitrateRatio = 2.0;
63 // Default initial framerate. 60 // Default initial framerate.
64 const uint32 kDefaultFramerate = 30; 61 const uint32 kDefaultFramerate = 30;
65 // Default ratio of requested_subsequent_framerate to initial_framerate 62 // Default ratio of requested_subsequent_framerate to initial_framerate
66 // (see test parameters below) if one is not provided. 63 // (see test parameters below) if one is not provided.
67 const double kDefaultSubsequentFramerateRatio = 0.1; 64 const double kDefaultSubsequentFramerateRatio = 0.1;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 ASSERT_EQ( 291 ASSERT_EQ(
295 reinterpret_cast<off_t>(test_stream->mapped_aligned_in_file.data()) & 63, 292 reinterpret_cast<off_t>(test_stream->mapped_aligned_in_file.data()) & 63,
296 0) 293 0)
297 << "File should be mapped at a 64 byte boundary"; 294 << "File should be mapped at a 64 byte boundary";
298 295
299 CHECK_EQ(test_stream->mapped_aligned_in_file.length() % 296 CHECK_EQ(test_stream->mapped_aligned_in_file.length() %
300 test_stream->aligned_buffer_size, 297 test_stream->aligned_buffer_size,
301 0U) 298 0U)
302 << "Stream byte size is not a product of calculated frame byte size"; 299 << "Stream byte size is not a product of calculated frame byte size";
303 CHECK_GT(test_stream->num_frames, 0UL); 300 CHECK_GT(test_stream->num_frames, 0UL);
304 CHECK_LE(test_stream->num_frames, kMaxFrameNum);
305 } 301 }
306 302
307 // Parse |data| into its constituent parts, set the various output fields 303 // Parse |data| into its constituent parts, set the various output fields
308 // accordingly, read in video stream, and store them to |test_streams|. 304 // accordingly, read in video stream, and store them to |test_streams|.
309 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data, 305 static void ParseAndReadTestStreamData(const base::FilePath::StringType& data,
310 ScopedVector<TestStream>* test_streams) { 306 ScopedVector<TestStream>* test_streams) {
311 // Split the string to individual test stream data. 307 // Split the string to individual test stream data.
312 std::vector<base::FilePath::StringType> test_streams_data; 308 std::vector<base::FilePath::StringType> test_streams_data;
313 base::SplitString(data, ';', &test_streams_data); 309 base::SplitString(data, ';', &test_streams_data);
314 CHECK_GE(test_streams_data.size(), 1U) << data; 310 CHECK_GE(test_streams_data.size(), 1U) << data;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 pos_in_input_stream_(0), 698 pos_in_input_stream_(0),
703 num_required_input_buffers_(0), 699 num_required_input_buffers_(0),
704 output_buffer_size_(0), 700 output_buffer_size_(0),
705 num_frames_to_encode_(0), 701 num_frames_to_encode_(0),
706 num_encoded_frames_(0), 702 num_encoded_frames_(0),
707 num_frames_since_last_check_(0), 703 num_frames_since_last_check_(0),
708 seen_keyframe_in_this_buffer_(false), 704 seen_keyframe_in_this_buffer_(false),
709 save_to_file_(save_to_file), 705 save_to_file_(save_to_file),
710 keyframe_period_(keyframe_period), 706 keyframe_period_(keyframe_period),
711 num_keyframes_requested_(0), 707 num_keyframes_requested_(0),
712 next_keyframe_at_(kMaxFrameNum), 708 next_keyframe_at_(0),
713 force_bitrate_(force_bitrate), 709 force_bitrate_(force_bitrate),
714 current_requested_bitrate_(0), 710 current_requested_bitrate_(0),
715 current_framerate_(0), 711 current_framerate_(0),
716 encoded_stream_size_since_last_check_(0), 712 encoded_stream_size_since_last_check_(0),
717 test_perf_(test_perf), 713 test_perf_(test_perf),
718 requested_bitrate_(0), 714 requested_bitrate_(0),
719 requested_framerate_(0), 715 requested_framerate_(0),
720 requested_subsequent_bitrate_(0), 716 requested_subsequent_bitrate_(0),
721 requested_subsequent_framerate_(0), 717 requested_subsequent_framerate_(0),
722 run_at_fps_(run_at_fps) { 718 run_at_fps_(run_at_fps) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 // Because the keyframe behavior requirements are loose, we give 1090 // Because the keyframe behavior requirements are loose, we give
1095 // the encoder more freedom here. It could either deliver a keyframe 1091 // the encoder more freedom here. It could either deliver a keyframe
1096 // immediately after we requested it, which could be for a frame number 1092 // immediately after we requested it, which could be for a frame number
1097 // before the one we requested it for (if the keyframe request 1093 // before the one we requested it for (if the keyframe request
1098 // is asynchronous, i.e. not bound to any concrete frame, and because 1094 // is asynchronous, i.e. not bound to any concrete frame, and because
1099 // the pipeline can be deeper than one frame), at that frame, or after. 1095 // the pipeline can be deeper than one frame), at that frame, or after.
1100 // So the only constraints we put here is that we get a keyframe not 1096 // So the only constraints we put here is that we get a keyframe not
1101 // earlier than we requested one (in time), and not later than 1097 // earlier than we requested one (in time), and not later than
1102 // kMaxKeyframeDelay frames after the frame, for which we requested 1098 // kMaxKeyframeDelay frames after the frame, for which we requested
1103 // it, comes back encoded. 1099 // it, comes back encoded.
1104 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay);
1105
1106 if (keyframe) { 1100 if (keyframe) {
1107 if (num_keyframes_requested_ > 0) 1101 if (num_keyframes_requested_ > 0 &&
1102 num_encoded_frames_ > next_keyframe_at_) {
1108 --num_keyframes_requested_; 1103 --num_keyframes_requested_;
1109 next_keyframe_at_ += keyframe_period_; 1104 next_keyframe_at_ += keyframe_period_;
1105 }
1110 seen_keyframe_in_this_buffer_ = true; 1106 seen_keyframe_in_this_buffer_ = true;
1111 } 1107 }
1112 1108
1109 if (num_keyframes_requested_ > 0)
1110 EXPECT_LE(num_encoded_frames_, next_keyframe_at_ + kMaxKeyframeDelay);
1111
1113 if (num_encoded_frames_ == num_frames_to_encode_ / 2) { 1112 if (num_encoded_frames_ == num_frames_to_encode_ / 2) {
1114 VerifyStreamProperties(); 1113 VerifyStreamProperties();
1115 if (requested_subsequent_bitrate_ != current_requested_bitrate_ || 1114 if (requested_subsequent_bitrate_ != current_requested_bitrate_ ||
1116 requested_subsequent_framerate_ != current_framerate_) { 1115 requested_subsequent_framerate_ != current_framerate_) {
1117 SetStreamParameters(requested_subsequent_bitrate_, 1116 SetStreamParameters(requested_subsequent_bitrate_,
1118 requested_subsequent_framerate_); 1117 requested_subsequent_framerate_);
1119 if (run_at_fps_ && input_timer_) 1118 if (run_at_fps_ && input_timer_)
1120 input_timer_->Start( 1119 input_timer_->Start(
1121 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_, 1120 FROM_HERE, base::TimeDelta::FromSeconds(1) / current_framerate_,
1122 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); 1121 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 } 1407 }
1409 1408
1410 content::g_env = 1409 content::g_env =
1411 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>( 1410 reinterpret_cast<content::VideoEncodeAcceleratorTestEnvironment*>(
1412 testing::AddGlobalTestEnvironment( 1411 testing::AddGlobalTestEnvironment(
1413 new content::VideoEncodeAcceleratorTestEnvironment( 1412 new content::VideoEncodeAcceleratorTestEnvironment(
1414 test_stream_data.Pass(), run_at_fps))); 1413 test_stream_data.Pass(), run_at_fps)));
1415 1414
1416 return RUN_ALL_TESTS(); 1415 return RUN_ALL_TESTS();
1417 } 1416 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698