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

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

Issue 1996453003: RTC Video Encoder: Use capturer timestamp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 <inttypes.h> 5 #include <inttypes.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <queue> 11 #include <queue>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector>
14 15
15 #include "base/at_exit.h" 16 #include "base/at_exit.h"
16 #include "base/bind.h" 17 #include "base/bind.h"
17 #include "base/command_line.h" 18 #include "base/command_line.h"
18 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
19 #include "base/files/memory_mapped_file.h" 20 #include "base/files/memory_mapped_file.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "base/memory/scoped_vector.h" 22 #include "base/memory/scoped_vector.h"
22 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
23 #include "base/numerics/safe_conversions.h" 24 #include "base/numerics/safe_conversions.h"
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 ~VEAClient() override; 802 ~VEAClient() override;
802 void CreateEncoder(); 803 void CreateEncoder();
803 void DestroyEncoder(); 804 void DestroyEncoder();
804 805
805 // VideoDecodeAccelerator::Client implementation. 806 // VideoDecodeAccelerator::Client implementation.
806 void RequireBitstreamBuffers(unsigned int input_count, 807 void RequireBitstreamBuffers(unsigned int input_count,
807 const gfx::Size& input_coded_size, 808 const gfx::Size& input_coded_size,
808 size_t output_buffer_size) override; 809 size_t output_buffer_size) override;
809 void BitstreamBufferReady(int32_t bitstream_buffer_id, 810 void BitstreamBufferReady(int32_t bitstream_buffer_id,
810 size_t payload_size, 811 size_t payload_size,
811 bool key_frame) override; 812 bool key_frame,
813 base::TimeDelta timestamp) override;
812 void NotifyError(VideoEncodeAccelerator::Error error) override; 814 void NotifyError(VideoEncodeAccelerator::Error error) override;
813 815
814 private: 816 private:
815 bool has_encoder() { return encoder_.get(); } 817 bool has_encoder() { return encoder_.get(); }
816 818
817 // Return the number of encoded frames per second. 819 // Return the number of encoded frames per second.
818 double frames_per_second(); 820 double frames_per_second();
819 821
820 std::unique_ptr<media::VideoEncodeAccelerator> CreateFakeVEA(); 822 std::unique_ptr<media::VideoEncodeAccelerator> CreateFakeVEA();
821 std::unique_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); 823 std::unique_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 unsigned int requested_framerate_; 984 unsigned int requested_framerate_;
983 985
984 // Bitrate to switch to in the middle of the stream. 986 // Bitrate to switch to in the middle of the stream.
985 unsigned int requested_subsequent_bitrate_; 987 unsigned int requested_subsequent_bitrate_;
986 988
987 // Framerate to switch to in the middle of the stream. 989 // Framerate to switch to in the middle of the stream.
988 unsigned int requested_subsequent_framerate_; 990 unsigned int requested_subsequent_framerate_;
989 991
990 // The timer used to feed the encoder with the input frames. 992 // The timer used to feed the encoder with the input frames.
991 std::unique_ptr<base::RepeatingTimer> input_timer_; 993 std::unique_ptr<base::RepeatingTimer> input_timer_;
994
995 // The timestamps for each frame in the order of CreateFrame() invocation.
996 std::vector<base::TimeDelta> frame_timestamps_;
997
998 // The counter to keep track of which timestamp in |frame_timestamps| we are
999 // checking now.
1000 unsigned int output_frame_count_;
Pawel Osciak 2016/05/26 07:39:23 Perhaps we could use a queue for frame_timestamps_
shenghao 2016/05/26 10:38:20 Done.
992 }; 1001 };
993 1002
994 VEAClient::VEAClient(TestStream* test_stream, 1003 VEAClient::VEAClient(TestStream* test_stream,
995 ClientStateNotification<ClientState>* note, 1004 ClientStateNotification<ClientState>* note,
996 bool save_to_file, 1005 bool save_to_file,
997 unsigned int keyframe_period, 1006 unsigned int keyframe_period,
998 bool force_bitrate, 1007 bool force_bitrate,
999 bool test_perf, 1008 bool test_perf,
1000 bool mid_stream_bitrate_switch, 1009 bool mid_stream_bitrate_switch,
1001 bool mid_stream_framerate_switch, 1010 bool mid_stream_framerate_switch,
(...skipping 16 matching lines...) Expand all
1018 next_keyframe_at_(0), 1027 next_keyframe_at_(0),
1019 force_bitrate_(force_bitrate), 1028 force_bitrate_(force_bitrate),
1020 current_requested_bitrate_(0), 1029 current_requested_bitrate_(0),
1021 current_framerate_(0), 1030 current_framerate_(0),
1022 encoded_stream_size_since_last_check_(0), 1031 encoded_stream_size_since_last_check_(0),
1023 test_perf_(test_perf), 1032 test_perf_(test_perf),
1024 verify_output_(verify_output), 1033 verify_output_(verify_output),
1025 requested_bitrate_(0), 1034 requested_bitrate_(0),
1026 requested_framerate_(0), 1035 requested_framerate_(0),
1027 requested_subsequent_bitrate_(0), 1036 requested_subsequent_bitrate_(0),
1028 requested_subsequent_framerate_(0) { 1037 requested_subsequent_framerate_(0),
1038 output_frame_count_(0) {
1029 if (keyframe_period_) 1039 if (keyframe_period_)
1030 LOG_ASSERT(kMaxKeyframeDelay < keyframe_period_); 1040 LOG_ASSERT(kMaxKeyframeDelay < keyframe_period_);
1031 1041
1032 // Fake encoder produces an invalid stream, so skip validating it. 1042 // Fake encoder produces an invalid stream, so skip validating it.
1033 if (!g_fake_encoder) { 1043 if (!g_fake_encoder) {
1034 stream_validator_ = StreamValidator::Create( 1044 stream_validator_ = StreamValidator::Create(
1035 test_stream_->requested_profile, 1045 test_stream_->requested_profile,
1036 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); 1046 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this)));
1037 CHECK(stream_validator_); 1047 CHECK(stream_validator_);
1038 } 1048 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); 1253 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
1244 } else { 1254 } else {
1245 while (inputs_at_client_.size() < 1255 while (inputs_at_client_.size() <
1246 num_required_input_buffers_ + kNumExtraInputFrames) 1256 num_required_input_buffers_ + kNumExtraInputFrames)
1247 FeedEncoderWithOneInput(); 1257 FeedEncoderWithOneInput();
1248 } 1258 }
1249 } 1259 }
1250 1260
1251 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, 1261 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id,
1252 size_t payload_size, 1262 size_t payload_size,
1253 bool key_frame) { 1263 bool key_frame,
1264 base::TimeDelta timestamp) {
1254 DCHECK(thread_checker_.CalledOnValidThread()); 1265 DCHECK(thread_checker_.CalledOnValidThread());
1255 ASSERT_LE(payload_size, output_buffer_size_); 1266 ASSERT_LE(payload_size, output_buffer_size_);
1256 1267
1257 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); 1268 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id);
1258 ASSERT_NE(it, output_buffers_at_client_.end()); 1269 ASSERT_NE(it, output_buffers_at_client_.end());
1259 base::SharedMemory* shm = it->second; 1270 base::SharedMemory* shm = it->second;
1260 output_buffers_at_client_.erase(it); 1271 output_buffers_at_client_.erase(it);
1261 1272
1262 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) 1273 if (state_ == CS_FINISHED || state_ == CS_VALIDATED)
1263 return; 1274 return;
1264 1275
1276 ASSERT_GT(frame_timestamps_.size(), output_frame_count_);
1277 ASSERT_EQ(timestamp, frame_timestamps_[output_frame_count_]);
1278 ++output_frame_count_;
1279
1265 encoded_stream_size_since_last_check_ += payload_size; 1280 encoded_stream_size_since_last_check_ += payload_size;
1266 1281
1267 const uint8_t* stream_ptr = static_cast<const uint8_t*>(shm->memory()); 1282 const uint8_t* stream_ptr = static_cast<const uint8_t*>(shm->memory());
1268 if (payload_size > 0) { 1283 if (payload_size > 0) {
1269 if (stream_validator_) { 1284 if (stream_validator_) {
1270 stream_validator_->ProcessStreamBuffer(stream_ptr, payload_size); 1285 stream_validator_->ProcessStreamBuffer(stream_ptr, payload_size);
1271 } else { 1286 } else {
1272 HandleEncodedFrame(key_frame); 1287 HandleEncodedFrame(key_frame);
1273 } 1288 }
1274 1289
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 // we require for bitrate tests. 1408 // we require for bitrate tests.
1394 pos_in_input_stream_ = 0; 1409 pos_in_input_stream_ = 0;
1395 } 1410 }
1396 1411
1397 if (quality_validator_) 1412 if (quality_validator_)
1398 quality_validator_->AddOriginalFrame(CreateFrame(pos_in_input_stream_)); 1413 quality_validator_->AddOriginalFrame(CreateFrame(pos_in_input_stream_));
1399 1414
1400 int32_t input_id; 1415 int32_t input_id;
1401 scoped_refptr<media::VideoFrame> video_frame = 1416 scoped_refptr<media::VideoFrame> video_frame =
1402 PrepareInputFrame(pos_in_input_stream_, &input_id); 1417 PrepareInputFrame(pos_in_input_stream_, &input_id);
1418 frame_timestamps_.push_back(video_frame->timestamp());
1403 pos_in_input_stream_ += test_stream_->aligned_buffer_size; 1419 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1404 1420
1405 bool force_keyframe = false; 1421 bool force_keyframe = false;
1406 if (keyframe_period_ && input_id % keyframe_period_ == 0) { 1422 if (keyframe_period_ && input_id % keyframe_period_ == 0) {
1407 force_keyframe = true; 1423 force_keyframe = true;
1408 ++num_keyframes_requested_; 1424 ++num_keyframes_requested_;
1409 } 1425 }
1410 1426
1411 if (input_id == 0) { 1427 if (input_id == 0) {
1412 first_frame_start_time_ = base::TimeTicks::Now(); 1428 first_frame_start_time_ = base::TimeTicks::Now();
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 1832
1817 media::g_env = 1833 media::g_env =
1818 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 1834 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
1819 testing::AddGlobalTestEnvironment( 1835 testing::AddGlobalTestEnvironment(
1820 new media::VideoEncodeAcceleratorTestEnvironment( 1836 new media::VideoEncodeAcceleratorTestEnvironment(
1821 std::move(test_stream_data), log_path, run_at_fps, 1837 std::move(test_stream_data), log_path, run_at_fps,
1822 needs_encode_latency, verify_all_output))); 1838 needs_encode_latency, verify_all_output)));
1823 1839
1824 return RUN_ALL_TESTS(); 1840 return RUN_ALL_TESTS();
1825 } 1841 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698