Chromium Code Reviews| 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 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 unsigned int requested_subsequent_framerate_; | 1043 unsigned int requested_subsequent_framerate_; |
| 1040 | 1044 |
| 1041 // The timer used to feed the encoder with the input frames. | 1045 // The timer used to feed the encoder with the input frames. |
| 1042 std::unique_ptr<base::RepeatingTimer> input_timer_; | 1046 std::unique_ptr<base::RepeatingTimer> input_timer_; |
| 1043 | 1047 |
| 1044 // The timestamps for each frame in the order of CreateFrame() invocation. | 1048 // The timestamps for each frame in the order of CreateFrame() invocation. |
| 1045 std::queue<base::TimeDelta> frame_timestamps_; | 1049 std::queue<base::TimeDelta> frame_timestamps_; |
| 1046 | 1050 |
| 1047 // The last timestamp popped from |frame_timestamps_|. | 1051 // The last timestamp popped from |frame_timestamps_|. |
| 1048 base::TimeDelta previous_timestamp_; | 1052 base::TimeDelta previous_timestamp_; |
| 1053 | |
| 1054 // Indicates if encode is setup on on |io_thread_|. | |
| 1055 bool encode_setup_on_io_thread_; | |
| 1056 | |
| 1057 // Dummy thread used to redirect encode tasks, represents GPU IO thread. | |
| 1058 base::Thread io_thread_; | |
| 1059 | |
| 1060 // Task runner used for TryToSetupEncodeOnSeperateThread(). | |
| 1061 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; | |
| 1062 | |
| 1063 // Task runner used for trampolining from |io_thread_|. | |
| 1064 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
| 1065 | |
| 1066 // Weak factories to use for TryToSetupEncodeOnSeperateThread() on | |
| 1067 // |io_thread_|. | |
| 1068 std::unique_ptr<base::WeakPtrFactory<VideoEncodeAccelerator>> | |
| 1069 encoder_weak_factory_; | |
| 1070 base::WeakPtrFactory<VEAClient> client_weak_factory_; | |
| 1049 }; | 1071 }; |
| 1050 | 1072 |
| 1051 VEAClient::VEAClient(TestStream* test_stream, | 1073 VEAClient::VEAClient(TestStream* test_stream, |
| 1052 ClientStateNotification<ClientState>* note, | 1074 ClientStateNotification<ClientState>* note, |
| 1053 bool save_to_file, | 1075 bool save_to_file, |
| 1054 unsigned int keyframe_period, | 1076 unsigned int keyframe_period, |
| 1055 bool force_bitrate, | 1077 bool force_bitrate, |
| 1056 bool test_perf, | 1078 bool test_perf, |
| 1057 bool mid_stream_bitrate_switch, | 1079 bool mid_stream_bitrate_switch, |
| 1058 bool mid_stream_framerate_switch, | 1080 bool mid_stream_framerate_switch, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1077 force_bitrate_(force_bitrate), | 1099 force_bitrate_(force_bitrate), |
| 1078 current_requested_bitrate_(0), | 1100 current_requested_bitrate_(0), |
| 1079 current_framerate_(0), | 1101 current_framerate_(0), |
| 1080 encoded_stream_size_since_last_check_(0), | 1102 encoded_stream_size_since_last_check_(0), |
| 1081 test_perf_(test_perf), | 1103 test_perf_(test_perf), |
| 1082 verify_output_(verify_output), | 1104 verify_output_(verify_output), |
| 1083 verify_output_timestamp_(verify_output_timestamp), | 1105 verify_output_timestamp_(verify_output_timestamp), |
| 1084 requested_bitrate_(0), | 1106 requested_bitrate_(0), |
| 1085 requested_framerate_(0), | 1107 requested_framerate_(0), |
| 1086 requested_subsequent_bitrate_(0), | 1108 requested_subsequent_bitrate_(0), |
| 1087 requested_subsequent_framerate_(0) { | 1109 requested_subsequent_framerate_(0), |
| 1110 encode_setup_on_io_thread_(false), | |
| 1111 io_thread_("IOThread"), | |
| 1112 client_weak_factory_(this) { | |
| 1088 if (keyframe_period_) | 1113 if (keyframe_period_) |
| 1089 LOG_ASSERT(kMaxKeyframeDelay < keyframe_period_); | 1114 LOG_ASSERT(kMaxKeyframeDelay < keyframe_period_); |
| 1090 | 1115 |
| 1091 // Fake encoder produces an invalid stream, so skip validating it. | 1116 // Fake encoder produces an invalid stream, so skip validating it. |
| 1092 if (!g_fake_encoder) { | 1117 if (!g_fake_encoder) { |
| 1093 stream_validator_ = StreamValidator::Create( | 1118 stream_validator_ = StreamValidator::Create( |
| 1094 test_stream_->requested_profile, | 1119 test_stream_->requested_profile, |
| 1095 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); | 1120 base::Bind(&VEAClient::HandleEncodedFrame, base::Unretained(this))); |
| 1096 CHECK(stream_validator_); | 1121 CHECK(stream_validator_); |
| 1097 } | 1122 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1160 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); | 1185 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); |
| 1161 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); | 1186 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); |
| 1162 #endif | 1187 #endif |
| 1163 return encoder; | 1188 return encoder; |
| 1164 } | 1189 } |
| 1165 | 1190 |
| 1166 void VEAClient::CreateEncoder() { | 1191 void VEAClient::CreateEncoder() { |
| 1167 DCHECK(thread_checker_.CalledOnValidThread()); | 1192 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1168 LOG_ASSERT(!has_encoder()); | 1193 LOG_ASSERT(!has_encoder()); |
| 1169 | 1194 |
| 1195 main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
| 1196 | |
| 1170 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1197 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
| 1171 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | 1198 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
| 1172 CreateMFVEA()}; | 1199 CreateMFVEA()}; |
| 1173 | 1200 |
| 1174 DVLOG(1) << "Profile: " << test_stream_->requested_profile | 1201 DVLOG(1) << "Profile: " << test_stream_->requested_profile |
| 1175 << ", initial bitrate: " << requested_bitrate_; | 1202 << ", initial bitrate: " << requested_bitrate_; |
| 1176 | 1203 |
| 1177 for (size_t i = 0; i < arraysize(encoders); ++i) { | 1204 for (size_t i = 0; i < arraysize(encoders); ++i) { |
| 1178 if (!encoders[i]) | 1205 if (!encoders[i]) |
| 1179 continue; | 1206 continue; |
| 1180 encoder_ = std::move(encoders[i]); | 1207 encoder_ = std::move(encoders[i]); |
| 1181 SetState(CS_ENCODER_SET); | 1208 SetState(CS_ENCODER_SET); |
| 1182 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, | 1209 if (encoder_->Initialize(kInputFormat, test_stream_->visible_size, |
| 1183 test_stream_->requested_profile, | 1210 test_stream_->requested_profile, |
| 1184 requested_bitrate_, this)) { | 1211 requested_bitrate_, this)) { |
| 1212 TryToSetupEncodeOnSeperateThread(); | |
| 1185 SetStreamParameters(requested_bitrate_, requested_framerate_); | 1213 SetStreamParameters(requested_bitrate_, requested_framerate_); |
| 1186 SetState(CS_INITIALIZED); | 1214 SetState(CS_INITIALIZED); |
| 1187 | 1215 |
| 1188 if (verify_output_ && !g_fake_encoder) | 1216 if (verify_output_ && !g_fake_encoder) |
| 1189 quality_validator_.reset(new VideoFrameQualityValidator( | 1217 quality_validator_.reset(new VideoFrameQualityValidator( |
| 1190 test_stream_->requested_profile, | 1218 test_stream_->requested_profile, |
| 1191 base::Bind(&VEAClient::DecodeCompleted, base::Unretained(this)), | 1219 base::Bind(&VEAClient::DecodeCompleted, base::Unretained(this)), |
| 1192 base::Bind(&VEAClient::DecodeFailed, base::Unretained(this)))); | 1220 base::Bind(&VEAClient::DecodeFailed, base::Unretained(this)))); |
| 1193 return; | 1221 return; |
| 1194 } | 1222 } |
| 1195 } | 1223 } |
| 1196 encoder_.reset(); | 1224 encoder_.reset(); |
| 1197 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | 1225 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
| 1198 SetState(CS_ERROR); | 1226 SetState(CS_ERROR); |
| 1199 } | 1227 } |
| 1200 | 1228 |
| 1201 void VEAClient::DecodeCompleted() { | 1229 void VEAClient::DecodeCompleted() { |
| 1202 SetState(CS_VALIDATED); | 1230 SetState(CS_VALIDATED); |
| 1203 } | 1231 } |
| 1204 | 1232 |
| 1233 void VEAClient::TryToSetupEncodeOnSeperateThread() { | |
| 1234 // Start dummy thread if not started. | |
| 1235 if (!io_thread_.IsRunning()) { | |
| 1236 ASSERT_TRUE(io_thread_.Start()); | |
| 1237 io_thread_task_runner_ = io_thread_.task_runner(); | |
| 1238 } | |
| 1239 | |
| 1240 if (!encoder_->TryToSetupEncodeOnSeparateThread( | |
| 1241 client_weak_factory_.GetWeakPtr(), io_thread_task_runner_)) { | |
| 1242 io_thread_.Stop(); | |
| 1243 encode_setup_on_io_thread_ = false; | |
| 1244 return; | |
| 1245 } | |
| 1246 | |
| 1247 encoder_weak_factory_.reset( | |
| 1248 new base::WeakPtrFactory<VideoEncodeAccelerator>(encoder_.get())); | |
| 1249 encode_setup_on_io_thread_ = true; | |
| 1250 } | |
| 1251 | |
| 1205 void VEAClient::DecodeFailed() { | 1252 void VEAClient::DecodeFailed() { |
| 1206 SetState(CS_ERROR); | 1253 SetState(CS_ERROR); |
| 1207 } | 1254 } |
| 1208 | 1255 |
| 1209 void VEAClient::DestroyEncoder() { | 1256 void VEAClient::DestroyEncoder() { |
| 1210 DCHECK(thread_checker_.CalledOnValidThread()); | 1257 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1211 if (!has_encoder()) | 1258 if (!has_encoder()) |
| 1212 return; | 1259 return; |
| 1260 | |
| 1261 if (encode_setup_on_io_thread_) { | |
| 1262 io_thread_task_runner_->PostTask( | |
| 1263 FROM_HERE, base::Bind(&VEAClient::DestroyEncodeOnSeperateThread, | |
| 1264 client_weak_factory_.GetWeakPtr())); | |
| 1265 io_thread_.Stop(); | |
| 1266 } | |
| 1267 | |
| 1213 // Clear the objects that should be destroyed on the same thread as creation. | 1268 // Clear the objects that should be destroyed on the same thread as creation. |
| 1214 encoder_.reset(); | 1269 encoder_.reset(); |
| 1215 input_timer_.reset(); | 1270 input_timer_.reset(); |
| 1216 quality_validator_.reset(); | 1271 quality_validator_.reset(); |
| 1217 } | 1272 } |
| 1218 | 1273 |
| 1274 void VEAClient::DestroyEncodeOnSeperateThread() { | |
| 1275 client_weak_factory_.InvalidateWeakPtrs(); | |
| 1276 encoder_weak_factory_->InvalidateWeakPtrs(); | |
| 1277 } | |
| 1278 | |
| 1219 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, | 1279 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, |
| 1220 bool mid_stream_framerate_switch) { | 1280 bool mid_stream_framerate_switch) { |
| 1221 // Use defaults for bitrate/framerate if they are not provided. | 1281 // Use defaults for bitrate/framerate if they are not provided. |
| 1222 if (test_stream_->requested_bitrate == 0) | 1282 if (test_stream_->requested_bitrate == 0) |
| 1223 requested_bitrate_ = kDefaultBitrate; | 1283 requested_bitrate_ = kDefaultBitrate; |
| 1224 else | 1284 else |
| 1225 requested_bitrate_ = test_stream_->requested_bitrate; | 1285 requested_bitrate_ = test_stream_->requested_bitrate; |
| 1226 | 1286 |
| 1227 if (test_stream_->requested_framerate == 0) | 1287 if (test_stream_->requested_framerate == 0) |
| 1228 requested_framerate_ = kDefaultFramerate; | 1288 requested_framerate_ = kDefaultFramerate; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1329 EXPECT_EQ(frame_timestamps_.front(), timestamp); | 1389 EXPECT_EQ(frame_timestamps_.front(), timestamp); |
| 1330 previous_timestamp_ = frame_timestamps_.front(); | 1390 previous_timestamp_ = frame_timestamps_.front(); |
| 1331 frame_timestamps_.pop(); | 1391 frame_timestamps_.pop(); |
| 1332 } | 1392 } |
| 1333 } | 1393 } |
| 1334 | 1394 |
| 1335 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, | 1395 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, |
| 1336 size_t payload_size, | 1396 size_t payload_size, |
| 1337 bool key_frame, | 1397 bool key_frame, |
| 1338 base::TimeDelta timestamp) { | 1398 base::TimeDelta timestamp) { |
| 1399 if (encode_setup_on_io_thread_ && | |
|
Pawel Osciak
2016/10/31 07:40:22
If you'd accept my suggestion below, we could ASSE
emircan
2016/10/31 19:45:08
Done.
| |
| 1400 io_thread_task_runner_->BelongsToCurrentThread()) { | |
| 1401 main_thread_task_runner_->PostTask( | |
| 1402 FROM_HERE, | |
| 1403 base::Bind(&VEAClient::BitstreamBufferReady, base::Unretained(this), | |
| 1404 bitstream_buffer_id, payload_size, key_frame, timestamp)); | |
| 1405 return; | |
| 1406 } | |
| 1339 DCHECK(thread_checker_.CalledOnValidThread()); | 1407 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1408 | |
| 1340 ASSERT_LE(payload_size, output_buffer_size_); | 1409 ASSERT_LE(payload_size, output_buffer_size_); |
| 1341 | 1410 |
| 1342 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); | 1411 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); |
| 1343 ASSERT_NE(it, output_buffers_at_client_.end()); | 1412 ASSERT_NE(it, output_buffers_at_client_.end()); |
| 1344 base::SharedMemory* shm = it->second; | 1413 base::SharedMemory* shm = it->second; |
| 1345 output_buffers_at_client_.erase(it); | 1414 output_buffers_at_client_.erase(it); |
| 1346 | 1415 |
| 1347 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) | 1416 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) |
| 1348 return; | 1417 return; |
| 1349 | 1418 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 note_->Notify(new_state); | 1467 note_->Notify(new_state); |
| 1399 state_ = new_state; | 1468 state_ = new_state; |
| 1400 } | 1469 } |
| 1401 | 1470 |
| 1402 void VEAClient::SetStreamParameters(unsigned int bitrate, | 1471 void VEAClient::SetStreamParameters(unsigned int bitrate, |
| 1403 unsigned int framerate) { | 1472 unsigned int framerate) { |
| 1404 current_requested_bitrate_ = bitrate; | 1473 current_requested_bitrate_ = bitrate; |
| 1405 current_framerate_ = framerate; | 1474 current_framerate_ = framerate; |
| 1406 LOG_ASSERT(current_requested_bitrate_ > 0UL); | 1475 LOG_ASSERT(current_requested_bitrate_ > 0UL); |
| 1407 LOG_ASSERT(current_framerate_ > 0UL); | 1476 LOG_ASSERT(current_framerate_ > 0UL); |
| 1408 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, | 1477 if (encode_setup_on_io_thread_) { |
| 1409 current_framerate_); | 1478 io_thread_task_runner_->PostTask( |
| 1479 FROM_HERE, | |
| 1480 base::Bind(&VideoEncodeAccelerator::RequestEncodingParametersChange, | |
| 1481 encoder_weak_factory_->GetWeakPtr(), bitrate, framerate)); | |
| 1482 } else { | |
| 1483 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, | |
| 1484 current_framerate_); | |
| 1485 } | |
| 1410 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ | 1486 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ |
| 1411 << " bps @ " << current_framerate_ << " FPS"; | 1487 << " bps @ " << current_framerate_ << " FPS"; |
| 1412 } | 1488 } |
| 1413 | 1489 |
| 1414 void VEAClient::InputNoLongerNeededCallback(int32_t input_id) { | 1490 void VEAClient::InputNoLongerNeededCallback(int32_t input_id) { |
| 1415 std::set<int32_t>::iterator it = inputs_at_client_.find(input_id); | 1491 std::set<int32_t>::iterator it = inputs_at_client_.find(input_id); |
| 1416 ASSERT_NE(it, inputs_at_client_.end()); | 1492 ASSERT_NE(it, inputs_at_client_.end()); |
| 1417 inputs_at_client_.erase(it); | 1493 inputs_at_client_.erase(it); |
| 1418 if (!g_env->run_at_fps()) | 1494 if (!g_env->run_at_fps()) |
| 1419 FeedEncoderWithOneInput(); | 1495 FeedEncoderWithOneInput(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1498 } | 1574 } |
| 1499 | 1575 |
| 1500 if (input_id == 0) { | 1576 if (input_id == 0) { |
| 1501 first_frame_start_time_ = base::TimeTicks::Now(); | 1577 first_frame_start_time_ = base::TimeTicks::Now(); |
| 1502 } | 1578 } |
| 1503 | 1579 |
| 1504 if (g_env->needs_encode_latency()) { | 1580 if (g_env->needs_encode_latency()) { |
| 1505 LOG_ASSERT(input_id == static_cast<int32_t>(encode_start_time_.size())); | 1581 LOG_ASSERT(input_id == static_cast<int32_t>(encode_start_time_.size())); |
| 1506 encode_start_time_.push_back(base::TimeTicks::Now()); | 1582 encode_start_time_.push_back(base::TimeTicks::Now()); |
| 1507 } | 1583 } |
| 1508 encoder_->Encode(video_frame, force_keyframe); | 1584 |
| 1585 if (encode_setup_on_io_thread_) { | |
|
Pawel Osciak
2016/10/31 07:40:21
Perhaps we could remove encode_setup_on_io_thread_
emircan
2016/10/31 19:45:08
Done.
| |
| 1586 io_thread_task_runner_->PostTask( | |
| 1587 FROM_HERE, base::Bind(&VideoEncodeAccelerator::Encode, | |
| 1588 encoder_weak_factory_->GetWeakPtr(), video_frame, | |
| 1589 force_keyframe)); | |
| 1590 } else { | |
| 1591 encoder_->Encode(video_frame, force_keyframe); | |
| 1592 } | |
| 1509 } | 1593 } |
| 1510 | 1594 |
| 1511 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { | 1595 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { |
| 1512 if (!has_encoder()) | 1596 if (!has_encoder()) |
| 1513 return; | 1597 return; |
| 1514 | 1598 |
| 1515 if (state_ != CS_ENCODING) | 1599 if (state_ != CS_ENCODING) |
| 1516 return; | 1600 return; |
| 1517 | 1601 |
| 1518 base::SharedMemoryHandle dup_handle; | 1602 base::SharedMemoryHandle dup_handle; |
| 1519 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | 1603 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); |
| 1520 | 1604 |
| 1521 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, | 1605 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, |
| 1522 output_buffer_size_); | 1606 output_buffer_size_); |
| 1523 LOG_ASSERT(output_buffers_at_client_ | 1607 LOG_ASSERT(output_buffers_at_client_ |
| 1524 .insert(std::make_pair(bitstream_buffer.id(), shm)) | 1608 .insert(std::make_pair(bitstream_buffer.id(), shm)) |
| 1525 .second); | 1609 .second); |
| 1526 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | 1610 |
| 1611 if (encode_setup_on_io_thread_) { | |
| 1612 io_thread_task_runner_->PostTask( | |
| 1613 FROM_HERE, | |
| 1614 base::Bind(&VideoEncodeAccelerator::UseOutputBitstreamBuffer, | |
| 1615 encoder_weak_factory_->GetWeakPtr(), bitstream_buffer)); | |
| 1616 } else { | |
| 1617 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | |
| 1618 } | |
| 1527 } | 1619 } |
| 1528 | 1620 |
| 1529 bool VEAClient::HandleEncodedFrame(bool keyframe) { | 1621 bool VEAClient::HandleEncodedFrame(bool keyframe) { |
| 1530 // This would be a bug in the test, which should not ignore false | 1622 // This would be a bug in the test, which should not ignore false |
| 1531 // return value from this method. | 1623 // return value from this method. |
| 1532 LOG_ASSERT(num_encoded_frames_ <= num_frames_to_encode_); | 1624 LOG_ASSERT(num_encoded_frames_ <= num_frames_to_encode_); |
| 1533 | 1625 |
| 1534 last_frame_ready_time_ = base::TimeTicks::Now(); | 1626 last_frame_ready_time_ = base::TimeTicks::Now(); |
| 1535 | 1627 |
| 1536 if (g_env->needs_encode_latency()) { | 1628 if (g_env->needs_encode_latency()) { |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1941 | 2033 |
| 1942 media::g_env = | 2034 media::g_env = |
| 1943 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2035 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
| 1944 testing::AddGlobalTestEnvironment( | 2036 testing::AddGlobalTestEnvironment( |
| 1945 new media::VideoEncodeAcceleratorTestEnvironment( | 2037 new media::VideoEncodeAcceleratorTestEnvironment( |
| 1946 std::move(test_stream_data), log_path, run_at_fps, | 2038 std::move(test_stream_data), log_path, run_at_fps, |
| 1947 needs_encode_latency, verify_all_output))); | 2039 needs_encode_latency, verify_all_output))); |
| 1948 | 2040 |
| 1949 return RUN_ALL_TESTS(); | 2041 return RUN_ALL_TESTS(); |
| 1950 } | 2042 } |
| OLD | NEW |