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

Side by Side Diff: webrtc/video/video_quality_test.cc

Issue 2998923002: Use SingleThreadedTaskQueue in DirectTransport (Closed)
Patch Set: . Created 3 years, 4 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 /* 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 "webrtc/video/video_quality_test.h" 10 #include "webrtc/video/video_quality_test.h"
(...skipping 19 matching lines...) Expand all
30 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 30 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
31 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" 31 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h"
32 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 32 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
33 #include "webrtc/rtc_base/checks.h" 33 #include "webrtc/rtc_base/checks.h"
34 #include "webrtc/rtc_base/cpu_time.h" 34 #include "webrtc/rtc_base/cpu_time.h"
35 #include "webrtc/rtc_base/event.h" 35 #include "webrtc/rtc_base/event.h"
36 #include "webrtc/rtc_base/format_macros.h" 36 #include "webrtc/rtc_base/format_macros.h"
37 #include "webrtc/rtc_base/memory_usage.h" 37 #include "webrtc/rtc_base/memory_usage.h"
38 #include "webrtc/rtc_base/optional.h" 38 #include "webrtc/rtc_base/optional.h"
39 #include "webrtc/rtc_base/platform_file.h" 39 #include "webrtc/rtc_base/platform_file.h"
40 #include "webrtc/rtc_base/ptr_util.h"
40 #include "webrtc/rtc_base/timeutils.h" 41 #include "webrtc/rtc_base/timeutils.h"
41 #include "webrtc/system_wrappers/include/cpu_info.h" 42 #include "webrtc/system_wrappers/include/cpu_info.h"
42 #include "webrtc/system_wrappers/include/field_trial.h" 43 #include "webrtc/system_wrappers/include/field_trial.h"
43 #include "webrtc/test/gtest.h" 44 #include "webrtc/test/gtest.h"
44 #include "webrtc/test/layer_filtering_transport.h" 45 #include "webrtc/test/layer_filtering_transport.h"
45 #include "webrtc/test/run_loop.h" 46 #include "webrtc/test/run_loop.h"
46 #include "webrtc/test/statistics.h" 47 #include "webrtc/test/statistics.h"
47 #include "webrtc/test/testsupport/fileutils.h" 48 #include "webrtc/test/testsupport/fileutils.h"
48 #include "webrtc/test/testsupport/frame_writer.h" 49 #include "webrtc/test/testsupport/frame_writer.h"
49 #include "webrtc/test/vcm_capturer.h" 50 #include "webrtc/test/vcm_capturer.h"
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 clock_)); 1763 clock_));
1763 ASSERT_TRUE(video_capturer_) << "Could not create capturer for " 1764 ASSERT_TRUE(video_capturer_) << "Could not create capturer for "
1764 << params_.video.clip_name 1765 << params_.video.clip_name
1765 << ".yuv. Is this resource file present?"; 1766 << ".yuv. Is this resource file present?";
1766 } 1767 }
1767 } 1768 }
1768 RTC_DCHECK(video_capturer_.get()); 1769 RTC_DCHECK(video_capturer_.get());
1769 } 1770 }
1770 1771
1771 void VideoQualityTest::RunWithAnalyzer(const Params& params) { 1772 void VideoQualityTest::RunWithAnalyzer(const Params& params) {
1773 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1774 std::unique_ptr<test::DirectTransport> recv_transport;
1775 FILE* graph_data_output_file = nullptr;
1776 std::unique_ptr<VideoAnalyzer> analyzer;
1777
1772 params_ = params; 1778 params_ = params;
1773 1779
1774 RTC_CHECK(!params_.audio.enabled); 1780 RTC_CHECK(!params_.audio.enabled);
1775 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to 1781 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1776 // differentiate between the analyzer and the renderer case. 1782 // differentiate between the analyzer and the renderer case.
1777 CheckParams(); 1783 CheckParams();
1778 1784
1779 FILE* graph_data_output_file = nullptr;
1780 if (!params_.analyzer.graph_data_output_filename.empty()) { 1785 if (!params_.analyzer.graph_data_output_filename.empty()) {
1781 graph_data_output_file = 1786 graph_data_output_file =
1782 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); 1787 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
1783 RTC_CHECK(graph_data_output_file) 1788 RTC_CHECK(graph_data_output_file)
1784 << "Can't open the file " << params_.analyzer.graph_data_output_filename 1789 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1785 << "!"; 1790 << "!";
1786 } 1791 }
1787 1792
1788 if (!params.logging.rtc_event_log_name.empty()) { 1793 if (!params.logging.rtc_event_log_name.empty()) {
1789 event_log_ = RtcEventLog::Create(clock_); 1794 event_log_ = RtcEventLog::Create(clock_);
1790 bool event_log_started = 1795 bool event_log_started =
1791 event_log_->StartLogging(params.logging.rtc_event_log_name, -1); 1796 event_log_->StartLogging(params.logging.rtc_event_log_name, -1);
1792 RTC_DCHECK(event_log_started); 1797 RTC_DCHECK(event_log_started);
1793 } 1798 }
1794 1799
1795 Call::Config call_config(event_log_.get()); 1800 Call::Config call_config(event_log_.get());
1796 call_config.bitrate_config = params.call.call_bitrate_config; 1801 call_config.bitrate_config = params.call.call_bitrate_config;
1797 CreateCalls(call_config, call_config);
1798 1802
1799 test::LayerFilteringTransport send_transport( 1803 task_queue_.SendTask([this, &call_config, &send_transport,
1800 params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, 1804 &recv_transport]() {
1801 params_.video.selected_tl, params_.ss.selected_sl, payload_type_map_); 1805 CreateCalls(call_config, call_config);
1802 1806
1803 test::DirectTransport recv_transport(params_.pipe, receiver_call_.get(), 1807 send_transport = rtc::MakeUnique<test::LayerFilteringTransport>(
1804 payload_type_map_); 1808 &task_queue_, params_.pipe, sender_call_.get(), kPayloadTypeVP8,
1809 kPayloadTypeVP9, params_.video.selected_tl, params_.ss.selected_sl,
1810 payload_type_map_);
1811
1812 recv_transport = rtc::MakeUnique<test::DirectTransport>(
1813 &task_queue_, params_.pipe, receiver_call_.get(), payload_type_map_);
1814 });
1805 1815
1806 std::string graph_title = params_.analyzer.graph_title; 1816 std::string graph_title = params_.analyzer.graph_title;
1807 if (graph_title.empty()) 1817 if (graph_title.empty())
1808 graph_title = VideoQualityTest::GenerateGraphTitle(); 1818 graph_title = VideoQualityTest::GenerateGraphTitle();
1809
1810 bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); 1819 bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest");
1811 VideoAnalyzer analyzer( 1820 analyzer = rtc::MakeUnique<VideoAnalyzer>(
1812 &send_transport, params_.analyzer.test_label, 1821 send_transport.get(), params_.analyzer.test_label,
1813 params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold, 1822 params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold,
1814 is_quick_test_enabled 1823 is_quick_test_enabled
1815 ? kFramesSentInQuickTest 1824 ? kFramesSentInQuickTest
1816 : params_.analyzer.test_durations_secs * params_.video.fps, 1825 : params_.analyzer.test_durations_secs * params_.video.fps,
1817 graph_data_output_file, graph_title, 1826 graph_data_output_file, graph_title,
1818 kVideoSendSsrcs[params_.ss.selected_stream], 1827 kVideoSendSsrcs[params_.ss.selected_stream],
1819 kSendRtxSsrcs[params_.ss.selected_stream], 1828 kSendRtxSsrcs[params_.ss.selected_stream],
1820 static_cast<size_t>(params_.ss.selected_stream), params.ss.selected_sl, 1829 static_cast<size_t>(params_.ss.selected_stream), params.ss.selected_sl,
1821 params_.video.selected_tl, is_quick_test_enabled, clock_, 1830 params_.video.selected_tl, is_quick_test_enabled, clock_,
1822 params_.logging.rtp_dump_name); 1831 params_.logging.rtp_dump_name);
1823 analyzer.SetCall(sender_call_.get());
1824 analyzer.SetReceiver(receiver_call_->Receiver());
1825 send_transport.SetReceiver(&analyzer);
1826 recv_transport.SetReceiver(sender_call_->Receiver());
1827 1832
1828 SetupVideo(&analyzer, &recv_transport); 1833 task_queue_.SendTask([&]() {
1829 SetupThumbnails(&analyzer, &recv_transport); 1834 analyzer->SetCall(sender_call_.get());
1830 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer; 1835 analyzer->SetReceiver(receiver_call_->Receiver());
1831 video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy(); 1836 send_transport->SetReceiver(analyzer.get());
1832 RTC_DCHECK(!video_send_config_.post_encode_callback); 1837 recv_transport->SetReceiver(sender_call_->Receiver());
1833 video_send_config_.post_encode_callback = analyzer.encode_timing_proxy();
1834 1838
1835 SetupScreenshareOrSVC(); 1839 SetupVideo(analyzer.get(), recv_transport.get());
1840 SetupThumbnails(analyzer.get(), recv_transport.get());
1841 video_receive_configs_[params_.ss.selected_stream].renderer =
1842 analyzer.get();
1843 video_send_config_.pre_encode_callback = analyzer->pre_encode_proxy();
1844 RTC_DCHECK(!video_send_config_.post_encode_callback);
1845 video_send_config_.post_encode_callback = analyzer->encode_timing_proxy();
1836 1846
1837 CreateFlexfecStreams(); 1847 SetupScreenshareOrSVC();
1838 CreateVideoStreams();
1839 analyzer.SetSendStream(video_send_stream_);
1840 if (video_receive_streams_.size() == 1)
1841 analyzer.SetReceiveStream(video_receive_streams_[0]);
1842 1848
1843 video_send_stream_->SetSource(analyzer.OutputInterface(), 1849 CreateFlexfecStreams();
1844 degradation_preference_); 1850 CreateVideoStreams();
1851 analyzer->SetSendStream(video_send_stream_);
1852 if (video_receive_streams_.size() == 1)
1853 analyzer->SetReceiveStream(video_receive_streams_[0]);
1845 1854
1846 SetupThumbnailCapturers(params_.call.num_thumbnails); 1855 video_send_stream_->SetSource(analyzer->OutputInterface(),
1847 for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) { 1856 degradation_preference_);
1848 thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(),
1849 degradation_preference_);
1850 }
1851 1857
1852 CreateCapturer(); 1858 SetupThumbnailCapturers(params_.call.num_thumbnails);
1859 for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) {
1860 thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(),
1861 degradation_preference_);
1862 }
1853 1863
1854 analyzer.SetSource(video_capturer_.get(), params_.ss.infer_streams); 1864 CreateCapturer();
1855 1865
1856 StartEncodedFrameLogs(video_send_stream_); 1866 analyzer->SetSource(video_capturer_.get(), params_.ss.infer_streams);
1857 StartEncodedFrameLogs(video_receive_streams_[params_.ss.selected_stream]);
1858 video_send_stream_->Start();
1859 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1860 thumbnail_send_stream->Start();
1861 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1862 receive_stream->Start();
1863 for (VideoReceiveStream* thumbnail_receive_stream :
1864 thumbnail_receive_streams_)
1865 thumbnail_receive_stream->Start();
1866 1867
1867 analyzer.StartMeasuringCpuProcessTime(); 1868 StartEncodedFrameLogs(video_send_stream_);
1869 StartEncodedFrameLogs(video_receive_streams_[params_.ss.selected_stream]);
1870 video_send_stream_->Start();
1871 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1872 thumbnail_send_stream->Start();
1873 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1874 receive_stream->Start();
1875 for (VideoReceiveStream* thumbnail_receive_stream :
1876 thumbnail_receive_streams_)
1877 thumbnail_receive_stream->Start();
1868 1878
1869 video_capturer_->Start(); 1879 analyzer->StartMeasuringCpuProcessTime();
1870 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
1871 thumbnail_capturers_) {
1872 video_caputurer->Start();
1873 }
1874 1880
1875 analyzer.Wait(); 1881 video_capturer_->Start();
1882 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
1883 thumbnail_capturers_) {
1884 video_caputurer->Start();
1885 }
1886 });
1876 1887
1877 send_transport.StopSending(); 1888 analyzer->Wait();
1878 recv_transport.StopSending();
1879 1889
1880 for (std::unique_ptr<test::VideoCapturer>& video_caputurer : 1890 task_queue_.SendTask([&]() {
1881 thumbnail_capturers_) 1891 send_transport.reset();
1882 video_caputurer->Stop(); 1892 recv_transport.reset();
1883 video_capturer_->Stop();
1884 for (VideoReceiveStream* thumbnail_receive_stream :
1885 thumbnail_receive_streams_)
1886 thumbnail_receive_stream->Stop();
1887 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1888 receive_stream->Stop();
1889 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1890 thumbnail_send_stream->Stop();
1891 video_send_stream_->Stop();
1892 1893
1893 DestroyStreams(); 1894 for (std::unique_ptr<test::VideoCapturer>& video_caputurer :
1894 DestroyThumbnailStreams(); 1895 thumbnail_capturers_)
1896 video_caputurer->Stop();
1897 video_capturer_->Stop();
1898 for (VideoReceiveStream* thumbnail_receive_stream :
1899 thumbnail_receive_streams_)
1900 thumbnail_receive_stream->Stop();
1901 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1902 receive_stream->Stop();
1903 for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_)
1904 thumbnail_send_stream->Stop();
1905 video_send_stream_->Stop();
1895 1906
1896 event_log_->StopLogging(); 1907 DestroyStreams();
1897 if (graph_data_output_file) 1908 DestroyThumbnailStreams();
1898 fclose(graph_data_output_file); 1909
1910 event_log_->StopLogging();
1911 if (graph_data_output_file)
1912 fclose(graph_data_output_file);
1913
1914 DestroyCalls();
1915 });
1899 } 1916 }
1900 1917
1901 void VideoQualityTest::SetupAudio(int send_channel_id, 1918 void VideoQualityTest::SetupAudio(int send_channel_id,
1902 int receive_channel_id, 1919 int receive_channel_id,
1903 Transport* transport, 1920 Transport* transport,
1904 AudioReceiveStream** audio_receive_stream) { 1921 AudioReceiveStream** audio_receive_stream) {
1905 audio_send_config_ = AudioSendStream::Config(transport); 1922 audio_send_config_ = AudioSendStream::Config(transport);
1906 audio_send_config_.voe_channel_id = send_channel_id; 1923 audio_send_config_.voe_channel_id = send_channel_id;
1907 audio_send_config_.rtp.ssrc = kAudioSendSsrc; 1924 audio_send_config_.rtp.ssrc = kAudioSendSsrc;
1908 1925
(...skipping 26 matching lines...) Expand all
1935 audio_config.decoder_factory = decoder_factory_; 1952 audio_config.decoder_factory = decoder_factory_;
1936 audio_config.decoder_map = {{kAudioSendPayloadType, {"OPUS", 48000, 2}}}; 1953 audio_config.decoder_map = {{kAudioSendPayloadType, {"OPUS", 48000, 2}}};
1937 if (params_.video.enabled && params_.audio.sync_video) 1954 if (params_.video.enabled && params_.audio.sync_video)
1938 audio_config.sync_group = kSyncGroup; 1955 audio_config.sync_group = kSyncGroup;
1939 1956
1940 *audio_receive_stream = 1957 *audio_receive_stream =
1941 receiver_call_->CreateAudioReceiveStream(audio_config); 1958 receiver_call_->CreateAudioReceiveStream(audio_config);
1942 } 1959 }
1943 1960
1944 void VideoQualityTest::RunWithRenderers(const Params& params) { 1961 void VideoQualityTest::RunWithRenderers(const Params& params) {
1945 params_ = params; 1962 std::unique_ptr<test::LayerFilteringTransport> send_transport;
1946 CheckParams(); 1963 std::unique_ptr<test::DirectTransport> recv_transport;
1964 ::VoiceEngineState voe;
1965 std::unique_ptr<test::VideoRenderer> local_preview;
1966 std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers;
1967 AudioReceiveStream* audio_receive_stream = nullptr;
1947 1968
1948 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to 1969 task_queue_.SendTask([&]() {
1949 // match the full stack tests. 1970 params_ = params;
1950 Call::Config call_config(event_log_.get()); 1971 CheckParams();
1951 call_config.bitrate_config = params_.call.call_bitrate_config;
1952 1972
1953 ::VoiceEngineState voe; 1973 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1954 rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing( 1974 // match the full stack tests.
1955 webrtc::AudioProcessing::Create()); 1975 Call::Config call_config(event_log_.get());
1976 call_config.bitrate_config = params_.call.call_bitrate_config;
1956 1977
1957 if (params_.audio.enabled) { 1978 rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing(
1958 CreateVoiceEngine(&voe, audio_processing.get(), decoder_factory_); 1979 webrtc::AudioProcessing::Create());
1959 AudioState::Config audio_state_config;
1960 audio_state_config.voice_engine = voe.voice_engine;
1961 audio_state_config.audio_mixer = AudioMixerImpl::Create();
1962 audio_state_config.audio_processing = audio_processing;
1963 call_config.audio_state = AudioState::Create(audio_state_config);
1964 }
1965 1980
1966 CreateCalls(call_config, call_config); 1981 if (params_.audio.enabled) {
1967 1982 CreateVoiceEngine(&voe, audio_processing.get(), decoder_factory_);
1968 // TODO(minyue): consider if this is a good transport even for audio only 1983 AudioState::Config audio_state_config;
1969 // calls. 1984 audio_state_config.voice_engine = voe.voice_engine;
1970 test::LayerFilteringTransport send_transport( 1985 audio_state_config.audio_mixer = AudioMixerImpl::Create();
1971 params.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, 1986 audio_state_config.audio_processing = audio_processing;
1972 params.video.selected_tl, params_.ss.selected_sl, payload_type_map_); 1987 call_config.audio_state = AudioState::Create(audio_state_config);
1973
1974 test::DirectTransport recv_transport(params_.pipe, receiver_call_.get(),
1975 payload_type_map_);
1976
1977 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1978 // least share as much code as possible. That way this test would also match
1979 // the full stack tests better.
1980 send_transport.SetReceiver(receiver_call_->Receiver());
1981 recv_transport.SetReceiver(sender_call_->Receiver());
1982
1983 std::unique_ptr<test::VideoRenderer> local_preview;
1984 std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers_;
1985 if (params_.video.enabled) {
1986 // Create video renderers.
1987 local_preview.reset(test::VideoRenderer::Create(
1988 "Local Preview", params_.video.width, params_.video.height));
1989
1990 const size_t selected_stream_id = params_.ss.selected_stream;
1991 const size_t num_streams = params_.ss.streams.size();
1992
1993 if (selected_stream_id == num_streams) {
1994 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) {
1995 std::ostringstream oss;
1996 oss << "Loopback Video - Stream #" << static_cast<int>(stream_id);
1997 loopback_renderers_.emplace_back(test::VideoRenderer::Create(
1998 oss.str().c_str(), params_.ss.streams[stream_id].width,
1999 params_.ss.streams[stream_id].height));
2000 }
2001 } else {
2002 loopback_renderers_.emplace_back(test::VideoRenderer::Create(
2003 "Loopback Video", params_.ss.streams[selected_stream_id].width,
2004 params_.ss.streams[selected_stream_id].height));
2005 } 1988 }
2006 1989
2007 SetupVideo(&send_transport, &recv_transport); 1990 CreateCalls(call_config, call_config);
2008 1991
2009 video_send_config_.pre_encode_callback = local_preview.get(); 1992 // TODO(minyue): consider if this is a good transport even for audio only
2010 if (selected_stream_id == num_streams) { 1993 // calls.
2011 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) { 1994 send_transport = rtc::MakeUnique<test::LayerFilteringTransport>(
2012 video_receive_configs_[stream_id].renderer = 1995 &task_queue_, params.pipe, sender_call_.get(), kPayloadTypeVP8,
2013 loopback_renderers_[stream_id].get(); 1996 kPayloadTypeVP9, params.video.selected_tl, params_.ss.selected_sl,
1997 payload_type_map_);
1998
1999 recv_transport = rtc::MakeUnique<test::DirectTransport>(
2000 &task_queue_, params_.pipe, receiver_call_.get(), payload_type_map_);
2001
2002 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
2003 // least share as much code as possible. That way this test would also match
2004 // the full stack tests better.
2005 send_transport->SetReceiver(receiver_call_->Receiver());
2006 recv_transport->SetReceiver(sender_call_->Receiver());
2007
2008 if (params_.video.enabled) {
2009 // Create video renderers.
2010 local_preview.reset(test::VideoRenderer::Create(
2011 "Local Preview", params_.video.width, params_.video.height));
2012
2013 const size_t selected_stream_id = params_.ss.selected_stream;
2014 const size_t num_streams = params_.ss.streams.size();
2015
2016 if (selected_stream_id == num_streams) {
2017 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) {
2018 std::ostringstream oss;
2019 oss << "Loopback Video - Stream #" << static_cast<int>(stream_id);
2020 loopback_renderers.emplace_back(test::VideoRenderer::Create(
2021 oss.str().c_str(), params_.ss.streams[stream_id].width,
2022 params_.ss.streams[stream_id].height));
2023 }
2024 } else {
2025 loopback_renderers.emplace_back(test::VideoRenderer::Create(
2026 "Loopback Video", params_.ss.streams[selected_stream_id].width,
2027 params_.ss.streams[selected_stream_id].height));
2028 }
2029
2030 SetupVideo(send_transport.get(), recv_transport.get());
2031
2032 video_send_config_.pre_encode_callback = local_preview.get();
2033 if (selected_stream_id == num_streams) {
2034 for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) {
2035 video_receive_configs_[stream_id].renderer =
2036 loopback_renderers[stream_id].get();
2037 if (params_.audio.enabled && params_.audio.sync_video)
2038 video_receive_configs_[stream_id].sync_group = kSyncGroup;
2039 }
2040 } else {
2041 video_receive_configs_[selected_stream_id].renderer =
2042 loopback_renderers.back().get();
2014 if (params_.audio.enabled && params_.audio.sync_video) 2043 if (params_.audio.enabled && params_.audio.sync_video)
2015 video_receive_configs_[stream_id].sync_group = kSyncGroup; 2044 video_receive_configs_[selected_stream_id].sync_group = kSyncGroup;
2016 } 2045 }
2017 } else { 2046
2018 video_receive_configs_[selected_stream_id].renderer = 2047 if (params_.screenshare.enabled)
2019 loopback_renderers_.back().get(); 2048 SetupScreenshareOrSVC();
2020 if (params_.audio.enabled && params_.audio.sync_video) 2049
2021 video_receive_configs_[selected_stream_id].sync_group = kSyncGroup; 2050 CreateFlexfecStreams();
2051 CreateVideoStreams();
2052
2053 CreateCapturer();
2054 video_send_stream_->SetSource(video_capturer_.get(),
2055 degradation_preference_);
2022 } 2056 }
2023 2057
2024 if (params_.screenshare.enabled) 2058 if (params_.audio.enabled) {
2025 SetupScreenshareOrSVC(); 2059 SetupAudio(voe.send_channel_id, voe.receive_channel_id,
2060 send_transport.get(), &audio_receive_stream);
2061 }
2026 2062
2027 CreateFlexfecStreams(); 2063 for (VideoReceiveStream* receive_stream : video_receive_streams_)
2028 CreateVideoStreams(); 2064 StartEncodedFrameLogs(receive_stream);
2065 StartEncodedFrameLogs(video_send_stream_);
2029 2066
2030 CreateCapturer(); 2067 // Start sending and receiving video.
2031 video_send_stream_->SetSource(video_capturer_.get(), 2068 if (params_.video.enabled) {
2032 degradation_preference_); 2069 for (VideoReceiveStream* video_receive_stream : video_receive_streams_)
2033 } 2070 video_receive_stream->Start();
2034 2071
2035 AudioReceiveStream* audio_receive_stream = nullptr; 2072 video_send_stream_->Start();
2036 if (params_.audio.enabled) { 2073 video_capturer_->Start();
2037 SetupAudio(voe.send_channel_id, voe.receive_channel_id, &send_transport, 2074 }
2038 &audio_receive_stream);
2039 }
2040 2075
2041 for (VideoReceiveStream* receive_stream : video_receive_streams_) 2076 if (params_.audio.enabled) {
2042 StartEncodedFrameLogs(receive_stream); 2077 // Start receiving audio.
2043 StartEncodedFrameLogs(video_send_stream_); 2078 audio_receive_stream->Start();
2079 EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id));
2044 2080
2045 // Start sending and receiving video. 2081 // Start sending audio.
2046 if (params_.video.enabled) { 2082 audio_send_stream_->Start();
2047 for (VideoReceiveStream* video_receive_stream : video_receive_streams_) 2083 EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id));
2048 video_receive_stream->Start(); 2084 }
2049 2085 });
2050 video_send_stream_->Start();
2051 video_capturer_->Start();
2052 }
2053
2054 if (params_.audio.enabled) {
2055 // Start receiving audio.
2056 audio_receive_stream->Start();
2057 EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id));
2058
2059 // Start sending audio.
2060 audio_send_stream_->Start();
2061 EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id));
2062 }
2063 2086
2064 test::PressEnterToContinue(); 2087 test::PressEnterToContinue();
2065 2088
2066 if (params_.audio.enabled) { 2089 task_queue_.SendTask([&]() {
2067 // Stop sending audio. 2090 if (params_.audio.enabled) {
2068 EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id)); 2091 // Stop sending audio.
2069 audio_send_stream_->Stop(); 2092 EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id));
2093 audio_send_stream_->Stop();
2070 2094
2071 // Stop receiving audio. 2095 // Stop receiving audio.
2072 EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id)); 2096 EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id));
2073 audio_receive_stream->Stop(); 2097 audio_receive_stream->Stop();
2074 sender_call_->DestroyAudioSendStream(audio_send_stream_); 2098 sender_call_->DestroyAudioSendStream(audio_send_stream_);
2075 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); 2099 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream);
2076 } 2100 }
2077 2101
2078 // Stop receiving and sending video. 2102 // Stop receiving and sending video.
2079 if (params_.video.enabled) { 2103 if (params_.video.enabled) {
2080 video_capturer_->Stop(); 2104 video_capturer_->Stop();
2081 video_send_stream_->Stop(); 2105 video_send_stream_->Stop();
2082 for (FlexfecReceiveStream* flexfec_receive_stream : 2106 for (FlexfecReceiveStream* flexfec_receive_stream :
2083 flexfec_receive_streams_) { 2107 flexfec_receive_streams_) {
2084 for (VideoReceiveStream* video_receive_stream : video_receive_streams_) { 2108 for (VideoReceiveStream* video_receive_stream :
2085 video_receive_stream->RemoveSecondarySink(flexfec_receive_stream); 2109 video_receive_streams_) {
2110 video_receive_stream->RemoveSecondarySink(flexfec_receive_stream);
2111 }
2112 receiver_call_->DestroyFlexfecReceiveStream(flexfec_receive_stream);
2086 } 2113 }
2087 receiver_call_->DestroyFlexfecReceiveStream(flexfec_receive_stream); 2114 for (VideoReceiveStream* receive_stream : video_receive_streams_) {
2115 receive_stream->Stop();
2116 receiver_call_->DestroyVideoReceiveStream(receive_stream);
2117 }
2118 sender_call_->DestroyVideoSendStream(video_send_stream_);
2088 } 2119 }
2089 for (VideoReceiveStream* receive_stream : video_receive_streams_) {
2090 receive_stream->Stop();
2091 receiver_call_->DestroyVideoReceiveStream(receive_stream);
2092 }
2093 sender_call_->DestroyVideoSendStream(video_send_stream_);
2094 }
2095 2120
2096 send_transport.StopSending(); 2121 send_transport.reset();
2097 recv_transport.StopSending(); 2122 recv_transport.reset();
2098 2123
2099 if (params_.audio.enabled) 2124 if (params_.audio.enabled)
2100 DestroyVoiceEngine(&voe); 2125 DestroyVoiceEngine(&voe);
2126
2127 recv_transport.reset();
2128 send_transport.reset();
2129 local_preview.reset();
2130 loopback_renderers.clear();
2131
2132 DestroyCalls();
2133 });
2101 } 2134 }
2102 2135
2103 void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) { 2136 void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) {
2104 if (!params_.logging.encoded_frame_base_path.empty()) { 2137 if (!params_.logging.encoded_frame_base_path.empty()) {
2105 std::ostringstream str; 2138 std::ostringstream str;
2106 str << send_logs_++; 2139 str << send_logs_++;
2107 std::string prefix = 2140 std::string prefix =
2108 params_.logging.encoded_frame_base_path + "." + str.str() + ".send."; 2141 params_.logging.encoded_frame_base_path + "." + str.str() + ".send.";
2109 stream->EnableEncodedFrameRecording( 2142 stream->EnableEncodedFrameRecording(
2110 std::vector<rtc::PlatformFile>( 2143 std::vector<rtc::PlatformFile>(
2111 {rtc::CreatePlatformFile(prefix + "1.ivf"), 2144 {rtc::CreatePlatformFile(prefix + "1.ivf"),
2112 rtc::CreatePlatformFile(prefix + "2.ivf"), 2145 rtc::CreatePlatformFile(prefix + "2.ivf"),
2113 rtc::CreatePlatformFile(prefix + "3.ivf")}), 2146 rtc::CreatePlatformFile(prefix + "3.ivf")}),
2114 100000000); 2147 100000000);
2115 } 2148 }
2116 } 2149 }
2117 2150
2118 void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) { 2151 void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) {
2119 if (!params_.logging.encoded_frame_base_path.empty()) { 2152 if (!params_.logging.encoded_frame_base_path.empty()) {
2120 std::ostringstream str; 2153 std::ostringstream str;
2121 str << receive_logs_++; 2154 str << receive_logs_++;
2122 std::string path = 2155 std::string path =
2123 params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; 2156 params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
2124 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), 2157 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path),
2125 100000000); 2158 100000000);
2126 } 2159 }
2127 } 2160 }
2128 } // namespace webrtc 2161 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698