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 <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 | 14 |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bits.h" | 17 #include "base/bits.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/aligned_memory.h" | 21 #include "base/memory/aligned_memory.h" |
22 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
23 #include "base/memory/weak_ptr.h" | |
23 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
24 #include "base/numerics/safe_conversions.h" | 25 #include "base/numerics/safe_conversions.h" |
25 #include "base/process/process_handle.h" | 26 #include "base/process/process_handle.h" |
26 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
27 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
28 #include "base/strings/string_split.h" | 29 #include "base/strings/string_split.h" |
29 #include "base/strings/stringprintf.h" | 30 #include "base/strings/stringprintf.h" |
30 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
31 #include "base/threading/thread.h" | 32 #include "base/threading/thread.h" |
32 #include "base/threading/thread_checker.h" | 33 #include "base/threading/thread_checker.h" |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
838 bool force_bitrate, | 839 bool force_bitrate, |
839 bool test_perf, | 840 bool test_perf, |
840 bool mid_stream_bitrate_switch, | 841 bool mid_stream_bitrate_switch, |
841 bool mid_stream_framerate_switch, | 842 bool mid_stream_framerate_switch, |
842 bool verify_output, | 843 bool verify_output, |
843 bool verify_output_timestamp); | 844 bool verify_output_timestamp); |
844 ~VEAClient() override; | 845 ~VEAClient() override; |
845 void CreateEncoder(); | 846 void CreateEncoder(); |
846 void DestroyEncoder(); | 847 void DestroyEncoder(); |
847 | 848 |
849 void TryToSetupEncodeOnSeperateThread(); | |
850 void DestroyEncodeOnSeperateThread(); | |
851 | |
848 // VideoDecodeAccelerator::Client implementation. | 852 // VideoDecodeAccelerator::Client implementation. |
849 void RequireBitstreamBuffers(unsigned int input_count, | 853 void RequireBitstreamBuffers(unsigned int input_count, |
850 const gfx::Size& input_coded_size, | 854 const gfx::Size& input_coded_size, |
851 size_t output_buffer_size) override; | 855 size_t output_buffer_size) override; |
852 void BitstreamBufferReady(int32_t bitstream_buffer_id, | 856 void BitstreamBufferReady(int32_t bitstream_buffer_id, |
853 size_t payload_size, | 857 size_t payload_size, |
854 bool key_frame, | 858 bool key_frame, |
855 base::TimeDelta timestamp) override; | 859 base::TimeDelta timestamp) override; |
856 void NotifyError(VideoEncodeAccelerator::Error error) override; | 860 void NotifyError(VideoEncodeAccelerator::Error error) override; |
857 | 861 |
858 private: | 862 private: |
863 void BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id, | |
864 size_t payload_size, | |
865 bool key_frame, | |
866 base::TimeDelta timestamp); | |
859 bool has_encoder() { return encoder_.get(); } | 867 bool has_encoder() { return encoder_.get(); } |
860 | 868 |
861 // Return the number of encoded frames per second. | 869 // Return the number of encoded frames per second. |
862 double frames_per_second(); | 870 double frames_per_second(); |
863 | 871 |
864 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); | 872 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); |
865 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); | 873 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); |
866 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); | 874 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); |
867 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); | 875 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); |
868 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA(); | 876 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1039 unsigned int requested_subsequent_framerate_; | 1047 unsigned int requested_subsequent_framerate_; |
1040 | 1048 |
1041 // The timer used to feed the encoder with the input frames. | 1049 // The timer used to feed the encoder with the input frames. |
1042 std::unique_ptr<base::RepeatingTimer> input_timer_; | 1050 std::unique_ptr<base::RepeatingTimer> input_timer_; |
1043 | 1051 |
1044 // The timestamps for each frame in the order of CreateFrame() invocation. | 1052 // The timestamps for each frame in the order of CreateFrame() invocation. |
1045 std::queue<base::TimeDelta> frame_timestamps_; | 1053 std::queue<base::TimeDelta> frame_timestamps_; |
1046 | 1054 |
1047 // The last timestamp popped from |frame_timestamps_|. | 1055 // The last timestamp popped from |frame_timestamps_|. |
1048 base::TimeDelta previous_timestamp_; | 1056 base::TimeDelta previous_timestamp_; |
1057 | |
1058 // Dummy thread used to redirect encode tasks, represents GPU IO thread. | |
1059 base::Thread io_thread_; | |
1060 | |
1061 // Task runner on which |encoder_| is created. | |
1062 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
1063 | |
1064 // Task runner used for posting encode tasks. If | |
1065 // TryToSetupEncodeOnSeperateThread() is true, |io_thread|'s task runner is | |
1066 // used, otherwise |main_thread_task_runner_|. | |
1067 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | |
1068 | |
1069 // Weak factory used for posting tasks on |encode_task_runner_|. | |
1070 std::unique_ptr<base::WeakPtrFactory<VideoEncodeAccelerator>> | |
1071 encoder_weak_factory_; | |
1072 | |
1073 // Weak factory used for TryToSetupEncodeOnSeperateThread(). | |
1074 base::WeakPtrFactory<VEAClient> client_weak_factory_; | |
1049 }; | 1075 }; |
1050 | 1076 |
1051 VEAClient::VEAClient(TestStream* test_stream, | 1077 VEAClient::VEAClient(TestStream* test_stream, |
1052 ClientStateNotification<ClientState>* note, | 1078 ClientStateNotification<ClientState>* note, |
1053 bool save_to_file, | 1079 bool save_to_file, |
1054 unsigned int keyframe_period, | 1080 unsigned int keyframe_period, |
1055 bool force_bitrate, | 1081 bool force_bitrate, |
1056 bool test_perf, | 1082 bool test_perf, |
1057 bool mid_stream_bitrate_switch, | 1083 bool mid_stream_bitrate_switch, |
1058 bool mid_stream_framerate_switch, | 1084 bool mid_stream_framerate_switch, |
(...skipping 18 matching lines...) Expand all Loading... | |
1077 force_bitrate_(force_bitrate), | 1103 force_bitrate_(force_bitrate), |
1078 current_requested_bitrate_(0), | 1104 current_requested_bitrate_(0), |
1079 current_framerate_(0), | 1105 current_framerate_(0), |
1080 encoded_stream_size_since_last_check_(0), | 1106 encoded_stream_size_since_last_check_(0), |
1081 test_perf_(test_perf), | 1107 test_perf_(test_perf), |
1082 verify_output_(verify_output), | 1108 verify_output_(verify_output), |
1083 verify_output_timestamp_(verify_output_timestamp), | 1109 verify_output_timestamp_(verify_output_timestamp), |
1084 requested_bitrate_(0), | 1110 requested_bitrate_(0), |
1085 requested_framerate_(0), | 1111 requested_framerate_(0), |
1086 requested_subsequent_bitrate_(0), | 1112 requested_subsequent_bitrate_(0), |
1087 requested_subsequent_framerate_(0) { | 1113 requested_subsequent_framerate_(0), |
1114 io_thread_("IOThread"), | |
1115 client_weak_factory_(this) { | |
1088 if (keyframe_period_) | 1116 if (keyframe_period_) |
1089 LOG_ASSERT(kMaxKeyframeDelay < keyframe_period_); | 1117 LOG_ASSERT(kMaxKeyframeDelay < keyframe_period_); |
1090 | 1118 |
1091 // Fake encoder produces an invalid stream, so skip validating it. | 1119 // Fake encoder produces an invalid stream, so skip validating it. |
1092 if (!g_fake_encoder) { | 1120 if (!g_fake_encoder) { |
1093 stream_validator_ = StreamValidator::Create( | 1121 stream_validator_ = StreamValidator::Create( |
1094 test_stream_->requested_profile, | 1122 test_stream_->requested_profile, |
1095 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 1123 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
1096 CHECK(stream_validator_); | 1124 CHECK(stream_validator_); |
1097 } | 1125 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); | 1188 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); |
1161 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); | 1189 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); |
1162 #endif | 1190 #endif |
1163 return encoder; | 1191 return encoder; |
1164 } | 1192 } |
1165 | 1193 |
1166 void VEAClient::CreateEncoder() { | 1194 void VEAClient::CreateEncoder() { |
1167 DCHECK(thread_checker_.CalledOnValidThread()); | 1195 DCHECK(thread_checker_.CalledOnValidThread()); |
1168 LOG_ASSERT(!has_encoder()); | 1196 LOG_ASSERT(!has_encoder()); |
1169 | 1197 |
1198 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
1199 encode_task_runner_ = main_thread_task_runner_; | |
1200 | |
1170 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1201 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
1171 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | 1202 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
1172 CreateMFVEA()}; | 1203 CreateMFVEA()}; |
1173 | 1204 |
1174 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 1205 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
1175 << ", initial bitrate: " << requested_bitrate_; | 1206 << ", initial bitrate: " << requested_bitrate_; |
1176 | 1207 |
1177 for (size_t i = 0; i < arraysize(encoders); ++i) { | 1208 for (size_t i = 0; i < arraysize(encoders); ++i) { |
1178 if (!encoders[i]) | 1209 if (!encoders[i]) |
1179 continue; | 1210 continue; |
1180 encoder_ = std::move(encoders[i]); | 1211 encoder_ = std::move(encoders[i]); |
1181 SetState(CS_ENCODER_SET); | 1212 SetState(CS_ENCODER_SET); |
1182 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, | 1213 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, |
1183 test_stream_->requested_profile, | 1214 test_stream_->requested_profile, |
1184 requested_bitrate_, this)) { | 1215 requested_bitrate_, this)) { |
1216 encoder_weak_factory_.reset( | |
1217 new base::WeakPtrFactory<VideoEncodeAccelerator>(encoder_.get())); | |
1218 TryToSetupEncodeOnSeperateThread(); | |
1185 SetStreamParameters(requested_bitrate_, requested_framerate_); | 1219 SetStreamParameters(requested_bitrate_, requested_framerate_); |
1186 SetState(CS_INITIALIZED); | 1220 SetState(CS_INITIALIZED); |
1187 | 1221 |
1188 if (verify_output_ && !g_fake_encoder) | 1222 if (verify_output_ && !g_fake_encoder) |
1189 quality_validator_.reset(new VideoFrameQualityValidator( | 1223 quality_validator_.reset(new VideoFrameQualityValidator( |
1190 test_stream_->requested_profile, | 1224 test_stream_->requested_profile, |
1191 base::Bind(&VEAClient::DecodeCompleted, base::Unretained(this)), | 1225 base::Bind(&VEAClient::DecodeCompleted, base::Unretained(this)), |
1192 base::Bind(&VEAClient::DecodeFailed, base::Unretained(this)))); | 1226 base::Bind(&VEAClient::DecodeFailed, base::Unretained(this)))); |
1193 return; | 1227 return; |
1194 } | 1228 } |
1195 } | 1229 } |
1196 encoder_.reset(); | 1230 encoder_.reset(); |
1197 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | 1231 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
1198 SetState(CS_ERROR); | 1232 SetState(CS_ERROR); |
1199 } | 1233 } |
1200 | 1234 |
1201 void VEAClient::DecodeCompleted() { | 1235 void VEAClient::DecodeCompleted() { |
1202 SetState(CS_VALIDATED); | 1236 SetState(CS_VALIDATED); |
1203 } | 1237 } |
1204 | 1238 |
1239 void VEAClient::TryToSetupEncodeOnSeperateThread() { | |
1240 // Start dummy thread if not started already. | |
1241 if (!io_thread_.IsRunning()) | |
1242 ASSERT_TRUE(io_thread_.Start()); | |
1243 | |
1244 if (!encoder_->TryToSetupEncodeOnSeparateThread( | |
1245 client_weak_factory_.GetWeakPtr(), io_thread_.task_runner())) { | |
1246 io_thread_.Stop(); | |
1247 return; | |
1248 } | |
1249 | |
1250 encode_task_runner_ = io_thread_.task_runner(); | |
1251 } | |
1252 | |
1205 void VEAClient::DecodeFailed() { | 1253 void VEAClient::DecodeFailed() { |
1206 SetState(CS_ERROR); | 1254 SetState(CS_ERROR); |
1207 } | 1255 } |
1208 | 1256 |
1209 void VEAClient::DestroyEncoder() { | 1257 void VEAClient::DestroyEncoder() { |
1210 DCHECK(thread_checker_.CalledOnValidThread()); | 1258 DCHECK(thread_checker_.CalledOnValidThread()); |
1211 if (!has_encoder()) | 1259 if (!has_encoder()) |
1212 return; | 1260 return; |
1261 | |
1262 if (io_thread_.IsRunning()) { | |
1263 encode_task_runner_->PostTask( | |
1264 FROM_HERE, base::Bind(&VEAClient::DestroyEncodeOnSeperateThread, | |
1265 client_weak_factory_.GetWeakPtr())); | |
1266 io_thread_.Stop(); | |
1267 } else { | |
1268 DestroyEncodeOnSeperateThread(); | |
1269 } | |
1270 | |
1213 // Clear the objects that should be destroyed on the same thread as creation. | 1271 // Clear the objects that should be destroyed on the same thread as creation. |
1214 encoder_.reset(); | 1272 encoder_.reset(); |
1215 input_timer_.reset(); | 1273 input_timer_.reset(); |
1216 quality_validator_.reset(); | 1274 quality_validator_.reset(); |
1217 } | 1275 } |
1218 | 1276 |
1277 void VEAClient::DestroyEncodeOnSeperateThread() { | |
1278 client_weak_factory_.InvalidateWeakPtrs(); | |
Pawel Osciak
2016/11/07 02:00:36
I think this should be run on main?
emircan
2016/11/07 19:35:29
|client_weak_factory_| is used only when TryToSetu
| |
1279 encoder_weak_factory_->InvalidateWeakPtrs(); | |
1280 } | |
1281 | |
1219 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, | 1282 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, |
1220 bool mid_stream_framerate_switch) { | 1283 bool mid_stream_framerate_switch) { |
1221 // Use defaults for bitrate/framerate if they are not provided. | 1284 // Use defaults for bitrate/framerate if they are not provided. |
1222 if (test_stream_->requested_bitrate == 0) | 1285 if (test_stream_->requested_bitrate == 0) |
1223 requested_bitrate_ = kDefaultBitrate; | 1286 requested_bitrate_ = kDefaultBitrate; |
1224 else | 1287 else |
1225 requested_bitrate_ = test_stream_->requested_bitrate; | 1288 requested_bitrate_ = test_stream_->requested_bitrate; |
1226 | 1289 |
1227 if (test_stream_->requested_framerate == 0) | 1290 if (test_stream_->requested_framerate == 0) |
1228 requested_framerate_ = kDefaultFramerate; | 1291 requested_framerate_ = kDefaultFramerate; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1329 EXPECT_EQ(frame_timestamps_.front(), timestamp); | 1392 EXPECT_EQ(frame_timestamps_.front(), timestamp); |
1330 previous_timestamp_ = frame_timestamps_.front(); | 1393 previous_timestamp_ = frame_timestamps_.front(); |
1331 frame_timestamps_.pop(); | 1394 frame_timestamps_.pop(); |
1332 } | 1395 } |
1333 } | 1396 } |
1334 | 1397 |
1335 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, | 1398 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, |
1336 size_t payload_size, | 1399 size_t payload_size, |
1337 bool key_frame, | 1400 bool key_frame, |
1338 base::TimeDelta timestamp) { | 1401 base::TimeDelta timestamp) { |
1402 ASSERT_TRUE(encode_task_runner_->BelongsToCurrentThread()); | |
1403 main_thread_task_runner_->PostTask( | |
1404 FROM_HERE, base::Bind(&VEAClient::BitstreamBufferReadyOnMainThread, | |
1405 base::Unretained(this), bitstream_buffer_id, | |
1406 payload_size, key_frame, timestamp)); | |
1407 } | |
1408 | |
1409 void VEAClient::NotifyError(VideoEncodeAccelerator::Error error) { | |
1339 DCHECK(thread_checker_.CalledOnValidThread()); | 1410 DCHECK(thread_checker_.CalledOnValidThread()); |
1411 SetState(CS_ERROR); | |
1412 } | |
1413 | |
1414 void VEAClient::BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id, | |
1415 size_t payload_size, | |
1416 bool key_frame, | |
1417 base::TimeDelta timestamp) { | |
1418 DCHECK(thread_checker_.CalledOnValidThread()); | |
1419 | |
1340 ASSERT_LE(payload_size, output_buffer_size_); | 1420 ASSERT_LE(payload_size, output_buffer_size_); |
1341 | 1421 |
1342 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); | 1422 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); |
1343 ASSERT_NE(it, output_buffers_at_client_.end()); | 1423 ASSERT_NE(it, output_buffers_at_client_.end()); |
1344 base::SharedMemory* shm = it->second; | 1424 base::SharedMemory* shm = it->second; |
1345 output_buffers_at_client_.erase(it); | 1425 output_buffers_at_client_.erase(it); |
1346 | 1426 |
1347 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) | 1427 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) |
1348 return; | 1428 return; |
1349 | 1429 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 base::checked_cast<int>(payload_size))); | 1461 base::checked_cast<int>(payload_size))); |
1382 } | 1462 } |
1383 } | 1463 } |
1384 | 1464 |
1385 EXPECT_EQ(key_frame, seen_keyframe_in_this_buffer_); | 1465 EXPECT_EQ(key_frame, seen_keyframe_in_this_buffer_); |
1386 seen_keyframe_in_this_buffer_ = false; | 1466 seen_keyframe_in_this_buffer_ = false; |
1387 | 1467 |
1388 FeedEncoderWithOutput(shm); | 1468 FeedEncoderWithOutput(shm); |
1389 } | 1469 } |
1390 | 1470 |
1391 void VEAClient::NotifyError(VideoEncodeAccelerator::Error error) { | |
1392 DCHECK(thread_checker_.CalledOnValidThread()); | |
1393 SetState(CS_ERROR); | |
1394 } | |
1395 | |
1396 void VEAClient::SetState(ClientState new_state) { | 1471 void VEAClient::SetState(ClientState new_state) { |
1397 DVLOG(4) << "Changing state " << state_ << "->" << new_state; | 1472 DVLOG(4) << "Changing state " << state_ << "->" << new_state; |
1398 note_->Notify(new_state); | 1473 note_->Notify(new_state); |
1399 state_ = new_state; | 1474 state_ = new_state; |
1400 } | 1475 } |
1401 | 1476 |
1402 void VEAClient::SetStreamParameters(unsigned int bitrate, | 1477 void VEAClient::SetStreamParameters(unsigned int bitrate, |
1403 unsigned int framerate) { | 1478 unsigned int framerate) { |
1404 current_requested_bitrate_ = bitrate; | 1479 current_requested_bitrate_ = bitrate; |
1405 current_framerate_ = framerate; | 1480 current_framerate_ = framerate; |
1406 LOG_ASSERT(current_requested_bitrate_ > 0UL); | 1481 LOG_ASSERT(current_requested_bitrate_ > 0UL); |
1407 LOG_ASSERT(current_framerate_ > 0UL); | 1482 LOG_ASSERT(current_framerate_ > 0UL); |
1408 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, | 1483 encode_task_runner_->PostTask( |
1409 current_framerate_); | 1484 FROM_HERE, |
1485 base::Bind(&VideoEncodeAccelerator::RequestEncodingParametersChange, | |
1486 encoder_weak_factory_->GetWeakPtr(), bitrate, framerate)); | |
1410 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ | 1487 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ |
1411 << " bps @ " << current_framerate_ << " FPS"; | 1488 << " bps @ " << current_framerate_ << " FPS"; |
1412 } | 1489 } |
1413 | 1490 |
1414 void VEAClient::InputNoLongerNeededCallback(int32_t input_id) { | 1491 void VEAClient::InputNoLongerNeededCallback(int32_t input_id) { |
1415 std::set<int32_t>::iterator it = inputs_at_client_.find(input_id); | 1492 std::set<int32_t>::iterator it = inputs_at_client_.find(input_id); |
1416 ASSERT_NE(it, inputs_at_client_.end()); | 1493 ASSERT_NE(it, inputs_at_client_.end()); |
1417 inputs_at_client_.erase(it); | 1494 inputs_at_client_.erase(it); |
1418 if (!g_env->run_at_fps()) | 1495 if (!g_env->run_at_fps()) |
1419 FeedEncoderWithOneInput(); | 1496 FeedEncoderWithOneInput(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1498 } | 1575 } |
1499 | 1576 |
1500 if (input_id == 0) { | 1577 if (input_id == 0) { |
1501 first_frame_start_time_ = base::TimeTicks::Now(); | 1578 first_frame_start_time_ = base::TimeTicks::Now(); |
1502 } | 1579 } |
1503 | 1580 |
1504 if (g_env->needs_encode_latency()) { | 1581 if (g_env->needs_encode_latency()) { |
1505 LOG_ASSERT(input_id == static_cast<int32_t>(encode_start_time_.size())); | 1582 LOG_ASSERT(input_id == static_cast<int32_t>(encode_start_time_.size())); |
1506 encode_start_time_.push_back(base::TimeTicks::Now()); | 1583 encode_start_time_.push_back(base::TimeTicks::Now()); |
1507 } | 1584 } |
1508 encoder_->Encode(video_frame, force_keyframe); | 1585 |
1586 encode_task_runner_->PostTask( | |
1587 FROM_HERE, base::Bind(&VideoEncodeAccelerator::Encode, | |
1588 encoder_weak_factory_->GetWeakPtr(), video_frame, | |
1589 force_keyframe)); | |
1509 } | 1590 } |
1510 | 1591 |
1511 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 1592 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
1512 if (!has_encoder()) | 1593 if (!has_encoder()) |
1513 return; | 1594 return; |
1514 | 1595 |
1515 if (state_ != CS_ENCODING) | 1596 if (state_ != CS_ENCODING) |
1516 return; | 1597 return; |
1517 | 1598 |
1518 base::SharedMemoryHandle dup_handle; | 1599 base::SharedMemoryHandle dup_handle; |
1519 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | 1600 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); |
1520 | 1601 |
1521 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, | 1602 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, |
1522 output_buffer_size_); | 1603 output_buffer_size_); |
1523 LOG_ASSERT(output_buffers_at_client_ | 1604 LOG_ASSERT(output_buffers_at_client_ |
1524 .insert(std::make_pair(bitstream_buffer.id(), shm)) | 1605 .insert(std::make_pair(bitstream_buffer.id(), shm)) |
1525 .second); | 1606 .second); |
1526 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | 1607 |
1608 encode_task_runner_->PostTask( | |
1609 FROM_HERE, | |
1610 base::Bind(&VideoEncodeAccelerator::UseOutputBitstreamBuffer, | |
1611 encoder_weak_factory_->GetWeakPtr(), bitstream_buffer)); | |
1527 } | 1612 } |
1528 | 1613 |
1529 bool VEAClient::HandleEncodedFrame(bool keyframe) { | 1614 bool VEAClient::HandleEncodedFrame(bool keyframe) { |
1530 // This would be a bug in the test, which should not ignore false | 1615 // This would be a bug in the test, which should not ignore false |
1531 // return value from this method. | 1616 // return value from this method. |
1532 LOG_ASSERT(num_encoded_frames_ <= num_frames_to_encode_); | 1617 LOG_ASSERT(num_encoded_frames_ <= num_frames_to_encode_); |
1533 | 1618 |
1534 last_frame_ready_time_ = base::TimeTicks::Now(); | 1619 last_frame_ready_time_ = base::TimeTicks::Now(); |
1535 | 1620 |
1536 if (g_env->needs_encode_latency()) { | 1621 if (g_env->needs_encode_latency()) { |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1941 | 2026 |
1942 media::g_env = | 2027 media::g_env = |
1943 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2028 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
1944 testing::AddGlobalTestEnvironment( | 2029 testing::AddGlobalTestEnvironment( |
1945 new media::VideoEncodeAcceleratorTestEnvironment( | 2030 new media::VideoEncodeAcceleratorTestEnvironment( |
1946 std::move(test_stream_data), log_path, run_at_fps, | 2031 std::move(test_stream_data), log_path, run_at_fps, |
1947 needs_encode_latency, verify_all_output))); | 2032 needs_encode_latency, verify_all_output))); |
1948 | 2033 |
1949 return RUN_ALL_TESTS(); | 2034 return RUN_ALL_TESTS(); |
1950 } | 2035 } |
OLD | NEW |