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

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 <queue>
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::queue<base::TimeDelta> frame_timestamps_;
992 }; 997 };
993 998
994 VEAClient::VEAClient(TestStream* test_stream, 999 VEAClient::VEAClient(TestStream* test_stream,
995 ClientStateNotification<ClientState>* note, 1000 ClientStateNotification<ClientState>* note,
996 bool save_to_file, 1001 bool save_to_file,
997 unsigned int keyframe_period, 1002 unsigned int keyframe_period,
998 bool force_bitrate, 1003 bool force_bitrate,
999 bool test_perf, 1004 bool test_perf,
1000 bool mid_stream_bitrate_switch, 1005 bool mid_stream_bitrate_switch,
1001 bool mid_stream_framerate_switch, 1006 bool mid_stream_framerate_switch,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this))); 1248 base::Bind(&VEAClient::OnInputTimer, base::Unretained(this)));
1244 } else { 1249 } else {
1245 while (inputs_at_client_.size() < 1250 while (inputs_at_client_.size() <
1246 num_required_input_buffers_ + kNumExtraInputFrames) 1251 num_required_input_buffers_ + kNumExtraInputFrames)
1247 FeedEncoderWithOneInput(); 1252 FeedEncoderWithOneInput();
1248 } 1253 }
1249 } 1254 }
1250 1255
1251 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, 1256 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id,
1252 size_t payload_size, 1257 size_t payload_size,
1253 bool key_frame) { 1258 bool key_frame,
1259 base::TimeDelta timestamp) {
1254 DCHECK(thread_checker_.CalledOnValidThread()); 1260 DCHECK(thread_checker_.CalledOnValidThread());
1255 ASSERT_LE(payload_size, output_buffer_size_); 1261 ASSERT_LE(payload_size, output_buffer_size_);
1256 1262
1257 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); 1263 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id);
1258 ASSERT_NE(it, output_buffers_at_client_.end()); 1264 ASSERT_NE(it, output_buffers_at_client_.end());
1259 base::SharedMemory* shm = it->second; 1265 base::SharedMemory* shm = it->second;
1260 output_buffers_at_client_.erase(it); 1266 output_buffers_at_client_.erase(it);
1261 1267
1262 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) 1268 if (state_ == CS_FINISHED || state_ == CS_VALIDATED)
1263 return; 1269 return;
1264 1270
1271 ASSERT_FALSE(frame_timestamps_.empty());
1272 ASSERT_EQ(timestamp, frame_timestamps_.front());
1273 frame_timestamps_.pop();
1274
1265 encoded_stream_size_since_last_check_ += payload_size; 1275 encoded_stream_size_since_last_check_ += payload_size;
1266 1276
1267 const uint8_t* stream_ptr = static_cast<const uint8_t*>(shm->memory()); 1277 const uint8_t* stream_ptr = static_cast<const uint8_t*>(shm->memory());
1268 if (payload_size > 0) { 1278 if (payload_size > 0) {
1269 if (stream_validator_) { 1279 if (stream_validator_) {
1270 stream_validator_->ProcessStreamBuffer(stream_ptr, payload_size); 1280 stream_validator_->ProcessStreamBuffer(stream_ptr, payload_size);
1271 } else { 1281 } else {
1272 HandleEncodedFrame(key_frame); 1282 HandleEncodedFrame(key_frame);
1273 } 1283 }
1274 1284
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 // we require for bitrate tests. 1403 // we require for bitrate tests.
1394 pos_in_input_stream_ = 0; 1404 pos_in_input_stream_ = 0;
1395 } 1405 }
1396 1406
1397 if (quality_validator_) 1407 if (quality_validator_)
1398 quality_validator_->AddOriginalFrame(CreateFrame(pos_in_input_stream_)); 1408 quality_validator_->AddOriginalFrame(CreateFrame(pos_in_input_stream_));
1399 1409
1400 int32_t input_id; 1410 int32_t input_id;
1401 scoped_refptr<media::VideoFrame> video_frame = 1411 scoped_refptr<media::VideoFrame> video_frame =
1402 PrepareInputFrame(pos_in_input_stream_, &input_id); 1412 PrepareInputFrame(pos_in_input_stream_, &input_id);
1413 frame_timestamps_.push(video_frame->timestamp());
1403 pos_in_input_stream_ += test_stream_->aligned_buffer_size; 1414 pos_in_input_stream_ += test_stream_->aligned_buffer_size;
1404 1415
1405 bool force_keyframe = false; 1416 bool force_keyframe = false;
1406 if (keyframe_period_ && input_id % keyframe_period_ == 0) { 1417 if (keyframe_period_ && input_id % keyframe_period_ == 0) {
1407 force_keyframe = true; 1418 force_keyframe = true;
1408 ++num_keyframes_requested_; 1419 ++num_keyframes_requested_;
1409 } 1420 }
1410 1421
1411 if (input_id == 0) { 1422 if (input_id == 0) {
1412 first_frame_start_time_ = base::TimeTicks::Now(); 1423 first_frame_start_time_ = base::TimeTicks::Now();
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 1827
1817 media::g_env = 1828 media::g_env =
1818 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 1829 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
1819 testing::AddGlobalTestEnvironment( 1830 testing::AddGlobalTestEnvironment(
1820 new media::VideoEncodeAcceleratorTestEnvironment( 1831 new media::VideoEncodeAcceleratorTestEnvironment(
1821 std::move(test_stream_data), log_path, run_at_fps, 1832 std::move(test_stream_data), log_path, run_at_fps,
1822 needs_encode_latency, verify_all_output))); 1833 needs_encode_latency, verify_all_output)));
1823 1834
1824 return RUN_ALL_TESTS(); 1835 return RUN_ALL_TESTS();
1825 } 1836 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698