| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 graph_title_(graph_title), | 62 graph_title_(graph_title), |
| 63 ssrc_to_analyze_(ssrc_to_analyze), | 63 ssrc_to_analyze_(ssrc_to_analyze), |
| 64 frames_to_process_(duration_frames), | 64 frames_to_process_(duration_frames), |
| 65 frames_recorded_(0), | 65 frames_recorded_(0), |
| 66 frames_processed_(0), | 66 frames_processed_(0), |
| 67 dropped_frames_(0), | 67 dropped_frames_(0), |
| 68 last_render_time_(0), | 68 last_render_time_(0), |
| 69 rtp_timestamp_delta_(0), | 69 rtp_timestamp_delta_(0), |
| 70 avg_psnr_threshold_(avg_psnr_threshold), | 70 avg_psnr_threshold_(avg_psnr_threshold), |
| 71 avg_ssim_threshold_(avg_ssim_threshold), | 71 avg_ssim_threshold_(avg_ssim_threshold), |
| 72 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), |
| 72 comparison_available_event_(EventWrapper::Create()), | 73 comparison_available_event_(EventWrapper::Create()), |
| 73 done_(EventWrapper::Create()) { | 74 done_(EventWrapper::Create()) { |
| 74 // Create thread pool for CPU-expensive PSNR/SSIM calculations. | 75 // Create thread pool for CPU-expensive PSNR/SSIM calculations. |
| 75 | 76 |
| 76 // Try to use about as many threads as cores, but leave kMinCoresLeft alone, | 77 // Try to use about as many threads as cores, but leave kMinCoresLeft alone, |
| 77 // so that we don't accidentally starve "real" worker threads (codec etc). | 78 // so that we don't accidentally starve "real" worker threads (codec etc). |
| 78 // Also, don't allocate more than kMaxComparisonThreads, even if there are | 79 // Also, don't allocate more than kMaxComparisonThreads, even if there are |
| 79 // spare cores. | 80 // spare cores. |
| 80 | 81 |
| 81 uint32_t num_cores = CpuInfo::DetectNumberOfCores(); | 82 uint32_t num_cores = CpuInfo::DetectNumberOfCores(); |
| 82 RTC_DCHECK_GE(num_cores, 1u); | 83 RTC_DCHECK_GE(num_cores, 1u); |
| 83 static const uint32_t kMinCoresLeft = 4; | 84 static const uint32_t kMinCoresLeft = 4; |
| 84 static const uint32_t kMaxComparisonThreads = 8; | 85 static const uint32_t kMaxComparisonThreads = 8; |
| 85 | 86 |
| 86 if (num_cores <= kMinCoresLeft) { | 87 if (num_cores <= kMinCoresLeft) { |
| 87 num_cores = 1; | 88 num_cores = 1; |
| 88 } else { | 89 } else { |
| 89 num_cores -= kMinCoresLeft; | 90 num_cores -= kMinCoresLeft; |
| 90 num_cores = std::min(num_cores, kMaxComparisonThreads); | 91 num_cores = std::min(num_cores, kMaxComparisonThreads); |
| 91 } | 92 } |
| 92 | 93 |
| 93 for (uint32_t i = 0; i < num_cores; ++i) { | 94 for (uint32_t i = 0; i < num_cores; ++i) { |
| 94 rtc::scoped_ptr<PlatformThread> thread = PlatformThread::CreateThread( | 95 rtc::PlatformThread* thread = |
| 95 &FrameComparisonThread, this, "Analyzer"); | 96 new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer"); |
| 96 EXPECT_TRUE(thread->Start()); | 97 thread->Start(); |
| 97 comparison_thread_pool_.push_back(thread.release()); | 98 comparison_thread_pool_.push_back(thread); |
| 98 } | 99 } |
| 99 | 100 |
| 100 stats_polling_thread_ = | |
| 101 PlatformThread::CreateThread(&PollStatsThread, this, "StatsPoller"); | |
| 102 } | 101 } |
| 103 | 102 |
| 104 ~VideoAnalyzer() { | 103 ~VideoAnalyzer() { |
| 105 for (PlatformThread* thread : comparison_thread_pool_) { | 104 for (rtc::PlatformThread* thread : comparison_thread_pool_) { |
| 106 EXPECT_TRUE(thread->Stop()); | 105 thread->Stop(); |
| 107 delete thread; | 106 delete thread; |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; } | 110 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; } |
| 112 | 111 |
| 113 DeliveryStatus DeliverPacket(MediaType media_type, | 112 DeliveryStatus DeliverPacket(MediaType media_type, |
| 114 const uint8_t* packet, | 113 const uint8_t* packet, |
| 115 size_t length, | 114 size_t length, |
| 116 const PacketTime& packet_time) override { | 115 const PacketTime& packet_time) override { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 last_rendered_frame_ = video_frame; | 213 last_rendered_frame_ = video_frame; |
| 215 } | 214 } |
| 216 | 215 |
| 217 bool IsTextureSupported() const override { return false; } | 216 bool IsTextureSupported() const override { return false; } |
| 218 | 217 |
| 219 void Wait() { | 218 void Wait() { |
| 220 // Frame comparisons can be very expensive. Wait for test to be done, but | 219 // Frame comparisons can be very expensive. Wait for test to be done, but |
| 221 // at time-out check if frames_processed is going up. If so, give it more | 220 // at time-out check if frames_processed is going up. If so, give it more |
| 222 // time, otherwise fail. Hopefully this will reduce test flakiness. | 221 // time, otherwise fail. Hopefully this will reduce test flakiness. |
| 223 | 222 |
| 224 EXPECT_TRUE(stats_polling_thread_->Start()); | 223 stats_polling_thread_.Start(); |
| 225 | 224 |
| 226 int last_frames_processed = -1; | 225 int last_frames_processed = -1; |
| 227 EventTypeWrapper eventType; | 226 EventTypeWrapper eventType; |
| 228 int iteration = 0; | 227 int iteration = 0; |
| 229 while ((eventType = done_->Wait(VideoQualityTest::kDefaultTimeoutMs)) != | 228 while ((eventType = done_->Wait(VideoQualityTest::kDefaultTimeoutMs)) != |
| 230 kEventSignaled) { | 229 kEventSignaled) { |
| 231 int frames_processed; | 230 int frames_processed; |
| 232 { | 231 { |
| 233 rtc::CritScope crit(&comparison_lock_); | 232 rtc::CritScope crit(&comparison_lock_); |
| 234 frames_processed = frames_processed_; | 233 frames_processed = frames_processed_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 250 last_frames_processed = frames_processed; | 249 last_frames_processed = frames_processed; |
| 251 } | 250 } |
| 252 | 251 |
| 253 if (iteration > 0) | 252 if (iteration > 0) |
| 254 printf("- Farewell, sweet Concorde!\n"); | 253 printf("- Farewell, sweet Concorde!\n"); |
| 255 | 254 |
| 256 // Signal stats polling thread if that is still waiting and stop it now, | 255 // Signal stats polling thread if that is still waiting and stop it now, |
| 257 // since it uses the send_stream_ reference that might be reclaimed after | 256 // since it uses the send_stream_ reference that might be reclaimed after |
| 258 // returning from this method. | 257 // returning from this method. |
| 259 done_->Set(); | 258 done_->Set(); |
| 260 EXPECT_TRUE(stats_polling_thread_->Stop()); | 259 stats_polling_thread_.Stop(); |
| 261 } | 260 } |
| 262 | 261 |
| 263 VideoCaptureInput* input_; | 262 VideoCaptureInput* input_; |
| 264 test::LayerFilteringTransport* const transport_; | 263 test::LayerFilteringTransport* const transport_; |
| 265 PacketReceiver* receiver_; | 264 PacketReceiver* receiver_; |
| 266 VideoSendStream* send_stream_; | 265 VideoSendStream* send_stream_; |
| 267 | 266 |
| 268 private: | 267 private: |
| 269 struct FrameComparison { | 268 struct FrameComparison { |
| 270 FrameComparison() | 269 FrameComparison() |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 std::deque<VideoFrame> frames_ GUARDED_BY(crit_); | 594 std::deque<VideoFrame> frames_ GUARDED_BY(crit_); |
| 596 VideoFrame last_rendered_frame_ GUARDED_BY(crit_); | 595 VideoFrame last_rendered_frame_ GUARDED_BY(crit_); |
| 597 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_); | 596 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_); |
| 598 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_); | 597 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_); |
| 599 std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); | 598 std::map<uint32_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); |
| 600 VideoFrame first_send_frame_ GUARDED_BY(crit_); | 599 VideoFrame first_send_frame_ GUARDED_BY(crit_); |
| 601 const double avg_psnr_threshold_; | 600 const double avg_psnr_threshold_; |
| 602 const double avg_ssim_threshold_; | 601 const double avg_ssim_threshold_; |
| 603 | 602 |
| 604 rtc::CriticalSection comparison_lock_; | 603 rtc::CriticalSection comparison_lock_; |
| 605 std::vector<PlatformThread*> comparison_thread_pool_; | 604 std::vector<rtc::PlatformThread*> comparison_thread_pool_; |
| 606 rtc::scoped_ptr<PlatformThread> stats_polling_thread_; | 605 rtc::PlatformThread stats_polling_thread_; |
| 607 const rtc::scoped_ptr<EventWrapper> comparison_available_event_; | 606 const rtc::scoped_ptr<EventWrapper> comparison_available_event_; |
| 608 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_); | 607 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_); |
| 609 const rtc::scoped_ptr<EventWrapper> done_; | 608 const rtc::scoped_ptr<EventWrapper> done_; |
| 610 }; | 609 }; |
| 611 | 610 |
| 612 VideoQualityTest::VideoQualityTest() : clock_(Clock::GetRealTimeClock()) {} | 611 VideoQualityTest::VideoQualityTest() : clock_(Clock::GetRealTimeClock()) {} |
| 613 | 612 |
| 614 void VideoQualityTest::TestBody() {} | 613 void VideoQualityTest::TestBody() {} |
| 615 | 614 |
| 616 std::string VideoQualityTest::GenerateGraphTitle() const { | 615 std::string VideoQualityTest::GenerateGraphTitle() const { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 send_stream_->Stop(); | 1064 send_stream_->Stop(); |
| 1066 receive_stream->Stop(); | 1065 receive_stream->Stop(); |
| 1067 | 1066 |
| 1068 call->DestroyVideoReceiveStream(receive_stream); | 1067 call->DestroyVideoReceiveStream(receive_stream); |
| 1069 call->DestroyVideoSendStream(send_stream_); | 1068 call->DestroyVideoSendStream(send_stream_); |
| 1070 | 1069 |
| 1071 transport.StopSending(); | 1070 transport.StopSending(); |
| 1072 } | 1071 } |
| 1073 | 1072 |
| 1074 } // namespace webrtc | 1073 } // namespace webrtc |
| OLD | NEW |