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

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

Issue 2427053002: Move video encode accelerator IPC messages to GPU IO thread (Closed)
Patch Set: posciak@ comments. Created 4 years, 1 month 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 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
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
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_for_io_;
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
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_for_io_(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
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_for_io_.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_for_io_.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 encoder_weak_factory_->InvalidateWeakPtrs();
1279 // |client_weak_factory_for_io_| is used only when
1280 // TryToSetupEncodeOnSeperateThread() returns true, in order to have weak
1281 // pointers to use when posting tasks on |io_thread_|. It is safe to
1282 // invalidate here because |encode_task_runner_| points to |io_thread_| in
1283 // this case. If not, it is safe to invalidate it on
1284 // |main_thread_task_runner_| as no weak pointers are used.
1285 client_weak_factory_for_io_.InvalidateWeakPtrs();
1286 }
1287
1219 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch, 1288 void VEAClient::UpdateTestStreamData(bool mid_stream_bitrate_switch,
1220 bool mid_stream_framerate_switch) { 1289 bool mid_stream_framerate_switch) {
1221 // Use defaults for bitrate/framerate if they are not provided. 1290 // Use defaults for bitrate/framerate if they are not provided.
1222 if (test_stream_->requested_bitrate == 0) 1291 if (test_stream_->requested_bitrate == 0)
1223 requested_bitrate_ = kDefaultBitrate; 1292 requested_bitrate_ = kDefaultBitrate;
1224 else 1293 else
1225 requested_bitrate_ = test_stream_->requested_bitrate; 1294 requested_bitrate_ = test_stream_->requested_bitrate;
1226 1295
1227 if (test_stream_->requested_framerate == 0) 1296 if (test_stream_->requested_framerate == 0)
1228 requested_framerate_ = kDefaultFramerate; 1297 requested_framerate_ = kDefaultFramerate;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 EXPECT_EQ(frame_timestamps_.front(), timestamp); 1398 EXPECT_EQ(frame_timestamps_.front(), timestamp);
1330 previous_timestamp_ = frame_timestamps_.front(); 1399 previous_timestamp_ = frame_timestamps_.front();
1331 frame_timestamps_.pop(); 1400 frame_timestamps_.pop();
1332 } 1401 }
1333 } 1402 }
1334 1403
1335 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id, 1404 void VEAClient::BitstreamBufferReady(int32_t bitstream_buffer_id,
1336 size_t payload_size, 1405 size_t payload_size,
1337 bool key_frame, 1406 bool key_frame,
1338 base::TimeDelta timestamp) { 1407 base::TimeDelta timestamp) {
1408 ASSERT_TRUE(encode_task_runner_->BelongsToCurrentThread());
1409 main_thread_task_runner_->PostTask(
1410 FROM_HERE, base::Bind(&VEAClient::BitstreamBufferReadyOnMainThread,
1411 base::Unretained(this), bitstream_buffer_id,
1412 payload_size, key_frame, timestamp));
1413 }
1414
1415 void VEAClient::NotifyError(VideoEncodeAccelerator::Error error) {
1339 DCHECK(thread_checker_.CalledOnValidThread()); 1416 DCHECK(thread_checker_.CalledOnValidThread());
1417 SetState(CS_ERROR);
1418 }
1419
1420 void VEAClient::BitstreamBufferReadyOnMainThread(int32_t bitstream_buffer_id,
1421 size_t payload_size,
1422 bool key_frame,
1423 base::TimeDelta timestamp) {
1424 DCHECK(thread_checker_.CalledOnValidThread());
1425
1340 ASSERT_LE(payload_size, output_buffer_size_); 1426 ASSERT_LE(payload_size, output_buffer_size_);
1341 1427
1342 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id); 1428 IdToSHM::iterator it = output_buffers_at_client_.find(bitstream_buffer_id);
1343 ASSERT_NE(it, output_buffers_at_client_.end()); 1429 ASSERT_NE(it, output_buffers_at_client_.end());
1344 base::SharedMemory* shm = it->second; 1430 base::SharedMemory* shm = it->second;
1345 output_buffers_at_client_.erase(it); 1431 output_buffers_at_client_.erase(it);
1346 1432
1347 if (state_ == CS_FINISHED || state_ == CS_VALIDATED) 1433 if (state_ == CS_FINISHED || state_ == CS_VALIDATED)
1348 return; 1434 return;
1349 1435
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 base::checked_cast<int>(payload_size))); 1467 base::checked_cast<int>(payload_size)));
1382 } 1468 }
1383 } 1469 }
1384 1470
1385 EXPECT_EQ(key_frame, seen_keyframe_in_this_buffer_); 1471 EXPECT_EQ(key_frame, seen_keyframe_in_this_buffer_);
1386 seen_keyframe_in_this_buffer_ = false; 1472 seen_keyframe_in_this_buffer_ = false;
1387 1473
1388 FeedEncoderWithOutput(shm); 1474 FeedEncoderWithOutput(shm);
1389 } 1475 }
1390 1476
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) { 1477 void VEAClient::SetState(ClientState new_state) {
1397 DVLOG(4) << "Changing state " << state_ << "->" << new_state; 1478 DVLOG(4) << "Changing state " << state_ << "->" << new_state;
1398 note_->Notify(new_state); 1479 note_->Notify(new_state);
1399 state_ = new_state; 1480 state_ = new_state;
1400 } 1481 }
1401 1482
1402 void VEAClient::SetStreamParameters(unsigned int bitrate, 1483 void VEAClient::SetStreamParameters(unsigned int bitrate,
1403 unsigned int framerate) { 1484 unsigned int framerate) {
1404 current_requested_bitrate_ = bitrate; 1485 current_requested_bitrate_ = bitrate;
1405 current_framerate_ = framerate; 1486 current_framerate_ = framerate;
1406 LOG_ASSERT(current_requested_bitrate_ > 0UL); 1487 LOG_ASSERT(current_requested_bitrate_ > 0UL);
1407 LOG_ASSERT(current_framerate_ > 0UL); 1488 LOG_ASSERT(current_framerate_ > 0UL);
1408 encoder_->RequestEncodingParametersChange(current_requested_bitrate_, 1489 encode_task_runner_->PostTask(
1409 current_framerate_); 1490 FROM_HERE,
1491 base::Bind(&VideoEncodeAccelerator::RequestEncodingParametersChange,
1492 encoder_weak_factory_->GetWeakPtr(), bitrate, framerate));
1410 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_ 1493 DVLOG(1) << "Switched parameters to " << current_requested_bitrate_
1411 << " bps @ " << current_framerate_ << " FPS"; 1494 << " bps @ " << current_framerate_ << " FPS";
1412 } 1495 }
1413 1496
1414 void VEAClient::InputNoLongerNeededCallback(int32_t input_id) { 1497 void VEAClient::InputNoLongerNeededCallback(int32_t input_id) {
1415 std::set<int32_t>::iterator it = inputs_at_client_.find(input_id); 1498 std::set<int32_t>::iterator it = inputs_at_client_.find(input_id);
1416 ASSERT_NE(it, inputs_at_client_.end()); 1499 ASSERT_NE(it, inputs_at_client_.end());
1417 inputs_at_client_.erase(it); 1500 inputs_at_client_.erase(it);
1418 if (!g_env->run_at_fps()) 1501 if (!g_env->run_at_fps())
1419 FeedEncoderWithOneInput(); 1502 FeedEncoderWithOneInput();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 } 1581 }
1499 1582
1500 if (input_id == 0) { 1583 if (input_id == 0) {
1501 first_frame_start_time_ = base::TimeTicks::Now(); 1584 first_frame_start_time_ = base::TimeTicks::Now();
1502 } 1585 }
1503 1586
1504 if (g_env->needs_encode_latency()) { 1587 if (g_env->needs_encode_latency()) {
1505 LOG_ASSERT(input_id == static_cast<int32_t>(encode_start_time_.size())); 1588 LOG_ASSERT(input_id == static_cast<int32_t>(encode_start_time_.size()));
1506 encode_start_time_.push_back(base::TimeTicks::Now()); 1589 encode_start_time_.push_back(base::TimeTicks::Now());
1507 } 1590 }
1508 encoder_->Encode(video_frame, force_keyframe); 1591
1592 encode_task_runner_->PostTask(
1593 FROM_HERE, base::Bind(&VideoEncodeAccelerator::Encode,
1594 encoder_weak_factory_->GetWeakPtr(), video_frame,
1595 force_keyframe));
1509 } 1596 }
1510 1597
1511 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) { 1598 void VEAClient::FeedEncoderWithOutput(base::SharedMemory* shm) {
1512 if (!has_encoder()) 1599 if (!has_encoder())
1513 return; 1600 return;
1514 1601
1515 if (state_ != CS_ENCODING) 1602 if (state_ != CS_ENCODING)
1516 return; 1603 return;
1517 1604
1518 base::SharedMemoryHandle dup_handle; 1605 base::SharedMemoryHandle dup_handle;
1519 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); 1606 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle));
1520 1607
1521 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, 1608 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle,
1522 output_buffer_size_); 1609 output_buffer_size_);
1523 LOG_ASSERT(output_buffers_at_client_ 1610 LOG_ASSERT(output_buffers_at_client_
1524 .insert(std::make_pair(bitstream_buffer.id(), shm)) 1611 .insert(std::make_pair(bitstream_buffer.id(), shm))
1525 .second); 1612 .second);
1526 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); 1613
1614 encode_task_runner_->PostTask(
1615 FROM_HERE,
1616 base::Bind(&VideoEncodeAccelerator::UseOutputBitstreamBuffer,
1617 encoder_weak_factory_->GetWeakPtr(), bitstream_buffer));
1527 } 1618 }
1528 1619
1529 bool VEAClient::HandleEncodedFrame(bool keyframe) { 1620 bool VEAClient::HandleEncodedFrame(bool keyframe) {
1530 // This would be a bug in the test, which should not ignore false 1621 // This would be a bug in the test, which should not ignore false
1531 // return value from this method. 1622 // return value from this method.
1532 LOG_ASSERT(num_encoded_frames_ <= num_frames_to_encode_); 1623 LOG_ASSERT(num_encoded_frames_ <= num_frames_to_encode_);
1533 1624
1534 last_frame_ready_time_ = base::TimeTicks::Now(); 1625 last_frame_ready_time_ = base::TimeTicks::Now();
1535 1626
1536 if (g_env->needs_encode_latency()) { 1627 if (g_env->needs_encode_latency()) {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 2032
1942 media::g_env = 2033 media::g_env =
1943 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( 2034 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>(
1944 testing::AddGlobalTestEnvironment( 2035 testing::AddGlobalTestEnvironment(
1945 new media::VideoEncodeAcceleratorTestEnvironment( 2036 new media::VideoEncodeAcceleratorTestEnvironment(
1946 std::move(test_stream_data), log_path, run_at_fps, 2037 std::move(test_stream_data), log_path, run_at_fps,
1947 needs_encode_latency, verify_all_output))); 2038 needs_encode_latency, verify_all_output)));
1948 2039
1949 return RUN_ALL_TESTS(); 2040 return RUN_ALL_TESTS();
1950 } 2041 }
OLDNEW
« no previous file with comments | « media/gpu/media_foundation_video_encode_accelerator_win.cc ('k') | media/video/video_encode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698