OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 | 14 |
15 #include "webrtc/video/loopback.h" | 15 #include "webrtc/video/loopback.h" |
16 | 16 |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
21 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
22 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 22 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
25 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 25 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
26 #include "webrtc/system_wrappers/interface/clock.h" | 26 #include "webrtc/system_wrappers/interface/clock.h" |
27 #include "webrtc/test/encoder_settings.h" | 27 #include "webrtc/test/encoder_settings.h" |
28 #include "webrtc/test/fake_encoder.h" | 28 #include "webrtc/test/fake_encoder.h" |
29 #include "webrtc/test/layer_filtering_transport.h" | 29 #include "webrtc/test/layer_filtering_transport.h" |
30 #include "webrtc/test/frame_generator.h" | |
30 #include "webrtc/test/run_loop.h" | 31 #include "webrtc/test/run_loop.h" |
31 #include "webrtc/test/testsupport/trace_to_stderr.h" | |
32 #include "webrtc/test/video_capturer.h" | 32 #include "webrtc/test/video_capturer.h" |
33 #include "webrtc/test/video_renderer.h" | 33 #include "webrtc/test/video_renderer.h" |
34 #include "webrtc/typedefs.h" | 34 #include "webrtc/typedefs.h" |
35 | 35 |
36 namespace webrtc { | 36 namespace webrtc { |
37 namespace test { | 37 namespace test { |
38 | 38 |
39 static const int kAbsSendTimeExtensionId = 7; | |
40 | |
41 static const uint32_t kSendSsrc = 0x654321; | |
42 static const uint32_t kSendRtxSsrc = 0x654322; | |
43 static const uint32_t kReceiverLocalSsrc = 0x123456; | |
44 | |
45 static const uint8_t kRtxVideoPayloadType = 96; | 39 static const uint8_t kRtxVideoPayloadType = 96; |
46 static const uint8_t kVideoPayloadTypeVP8 = 124; | 40 static const uint8_t kVideoPayloadTypeVP8 = 124; |
47 static const uint8_t kVideoPayloadTypeVP9 = 125; | 41 static const uint8_t kVideoPayloadTypeVP9 = 125; |
48 | 42 |
49 Loopback::Loopback(const Config& config) | 43 Loopback::Loopback(const Config& config) |
50 : config_(config), clock_(Clock::GetRealTimeClock()) { | 44 : config_(config), clock_(Clock::GetRealTimeClock()) { |
51 } | 45 } |
52 | 46 |
53 Loopback::~Loopback() { | 47 void Loopback::TestBody() { |
48 // Empty. Use Run() instead. | |
sprang_webrtc
2015/09/11 08:01:34
Should this ever be reached?
ivica
2015/09/14 17:12:55
Whoops, rebase error. This file should've been rem
| |
54 } | 49 } |
55 | 50 |
56 void Loopback::Run() { | 51 void Loopback::Run() { |
57 rtc::scoped_ptr<test::TraceToStderr> trace_to_stderr_; | 52 rtc::scoped_ptr<test::VideoRenderer> local_preview( |
58 if (config_.logs) | 53 test::VideoRenderer::Create("Local Preview", config_.shared.width, |
59 trace_to_stderr_.reset(new test::TraceToStderr); | 54 config_.shared.height)); |
55 rtc::scoped_ptr<test::VideoRenderer> loopback_video( | |
56 test::VideoRenderer::Create("Loopback Video", config_.shared.width, | |
57 config_.shared.height)); | |
60 | 58 |
61 rtc::scoped_ptr<test::VideoRenderer> local_preview( | 59 test::DirectTransport transport(config_.shared.pipe); |
62 test::VideoRenderer::Create("Local Preview", config_.width, | 60 Call::Config call_config(&transport); |
63 config_.height)); | |
64 rtc::scoped_ptr<test::VideoRenderer> loopback_video( | |
65 test::VideoRenderer::Create("Loopback Video", config_.width, | |
66 config_.height)); | |
67 | 61 |
68 Call::Config call_config; | |
69 call_config.bitrate_config.min_bitrate_bps = | 62 call_config.bitrate_config.min_bitrate_bps = |
70 static_cast<int>(config_.min_bitrate_kbps) * 1000; | 63 static_cast<int>(config_.shared.min_bitrate_bps); |
71 call_config.bitrate_config.start_bitrate_bps = | 64 call_config.bitrate_config.start_bitrate_bps = |
72 static_cast<int>(config_.start_bitrate_kbps) * 1000; | 65 static_cast<int>(config_.start_bitrate_bps); |
73 call_config.bitrate_config.max_bitrate_bps = | 66 call_config.bitrate_config.max_bitrate_bps = |
74 static_cast<int>(config_.max_bitrate_kbps) * 1000; | 67 static_cast<int>(config_.shared.max_bitrate_bps); |
75 rtc::scoped_ptr<Call> call(Call::Create(call_config)); | 68 rtc::scoped_ptr<Call> call(Call::Create(call_config)); |
76 | 69 |
77 FakeNetworkPipe::Config pipe_config; | 70 FakeNetworkPipe::Config pipe_config; |
78 pipe_config.loss_percent = config_.loss_percent; | 71 pipe_config.loss_percent = config_.loss_percent; |
79 pipe_config.link_capacity_kbps = config_.link_capacity_kbps; | 72 pipe_config.link_capacity_kbps = config_.link_capacity_kbps; |
80 pipe_config.queue_length_packets = config_.queue_size; | 73 pipe_config.queue_length_packets = config_.queue_size; |
81 pipe_config.queue_delay_ms = config_.avg_propagation_delay_ms; | 74 pipe_config.queue_delay_ms = config_.avg_propagation_delay_ms; |
82 pipe_config.delay_standard_deviation_ms = config_.std_propagation_delay_ms; | 75 pipe_config.delay_standard_deviation_ms = config_.std_propagation_delay_ms; |
83 LayerFilteringTransport send_transport( | 76 LayerFilteringTransport send_transport( |
84 pipe_config, kVideoPayloadTypeVP8, kVideoPayloadTypeVP9, | 77 pipe_config, kVideoPayloadTypeVP8, kVideoPayloadTypeVP9, |
85 static_cast<uint8_t>(config_.tl_discard_threshold), | 78 static_cast<uint8_t>(config_.tl_discard_threshold), |
86 static_cast<uint8_t>(config_.sl_discard_threshold)); | 79 static_cast<uint8_t>(config_.sl_discard_threshold)); |
87 | 80 |
88 // Loopback, call sends to itself. | 81 // Loopback, call sends to itself. |
89 send_transport.SetReceiver(call->Receiver()); | 82 send_transport.SetReceiver(call->Receiver()); |
90 | 83 |
91 VideoSendStream::Config send_config(&send_transport); | 84 rtc::scoped_ptr<VideoEncoder> encoder; |
92 send_config.rtp.ssrcs.push_back(kSendSsrc); | 85 SendConfigDefaultValues(&config_.shared); |
93 send_config.rtp.rtx.ssrcs.push_back(kSendRtxSsrc); | 86 SetupFromSharedConfig(config_.shared, &encoder); |
94 send_config.rtp.rtx.payload_type = kRtxVideoPayloadType; | 87 send_config_.local_renderer = local_preview.get(); |
95 send_config.rtp.nack.rtp_history_ms = 1000; | 88 send_config_.encoder_settings.payload_type = kVideoPayloadType; |
96 send_config.rtp.extensions.push_back( | 89 // VideoSendStream::Config send_config; |
97 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeExtensionId)); | 90 // send_config.rtp.ssrcs.push_back(kSendSsrc); // (!) |
91 // send_config.rtp.rtx.ssrcs.push_back(kSendRtxSsrc); // (!) | |
92 send_config_.rtp.rtx.payload_type = kRtxVideoPayloadType; // (!) | |
sprang_webrtc
2015/09/11 08:01:34
What's with the comments here?
ivica
2015/09/14 17:12:55
Same as above, file deleted.
| |
98 | 93 |
99 send_config.local_renderer = local_preview.get(); | 94 rtc::scoped_ptr<test::FrameGenerator> frame_generator; |
100 rtc::scoped_ptr<VideoEncoder> encoder; | 95 SetupScreenshare(config_.shared, &codec_settings_, &frame_generator); |
sprang_webrtc
2015/09/11 08:01:34
Is this only used with screenshare?
ivica
2015/09/14 17:12:55
Same as above, file deleted.
| |
101 if (config_.codec == "VP8") { | |
102 encoder.reset(VideoEncoder::Create(VideoEncoder::kVp8)); | |
103 } else if (config_.codec == "VP9") { | |
104 encoder.reset(VideoEncoder::Create(VideoEncoder::kVp9)); | |
105 } else { | |
106 // Codec not supported. | |
107 RTC_NOTREACHED() << "Codec not supported!"; | |
108 return; | |
109 } | |
110 const int payload_type = | |
111 config_.codec == "VP8" ? kVideoPayloadTypeVP8 : kVideoPayloadTypeVP9; | |
112 send_config.encoder_settings.encoder = encoder.get(); | |
113 send_config.encoder_settings.payload_name = config_.codec; | |
114 send_config.encoder_settings.payload_type = payload_type; | |
115 | |
116 VideoEncoderConfig encoder_config(CreateEncoderConfig()); | |
117 | 96 |
118 VideoSendStream* send_stream = | 97 VideoSendStream* send_stream = |
119 call->CreateVideoSendStream(send_config, encoder_config); | 98 call->CreateVideoSendStream(send_config_, encoder_config_); |
120 | 99 |
121 rtc::scoped_ptr<test::VideoCapturer> capturer(CreateCapturer(send_stream)); | 100 test::FrameGeneratorCapturer* capturer = new test::FrameGeneratorCapturer( |
101 clock_, send_stream->Input(), frame_generator.release(), | |
102 config_.shared.fps); | |
103 EXPECT_TRUE(capturer->Init()); | |
122 | 104 |
123 VideoReceiveStream::Config receive_config(&send_transport); | 105 receive_configs_[0].rtp.rtx[kVideoPayloadType].ssrc = kSendRtxSsrcs[0]; |
124 receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0]; | 106 receive_configs_[0].rtp.rtx[kVideoPayloadType].payload_type = |
125 receive_config.rtp.local_ssrc = kReceiverLocalSsrc; | 107 kRtxVideoPayloadType; |
126 receive_config.rtp.nack.rtp_history_ms = 1000; | 108 receive_configs_[0].rtp.extensions.push_back( |
127 receive_config.rtp.remb = true; | |
128 receive_config.rtp.rtx[payload_type].ssrc = kSendRtxSsrc; | |
129 receive_config.rtp.rtx[payload_type].payload_type = kRtxVideoPayloadType; | |
130 receive_config.rtp.extensions.push_back( | |
131 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeExtensionId)); | 109 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeExtensionId)); |
132 receive_config.renderer = loopback_video.get(); | 110 receive_configs_[0].renderer = loopback_video.get(); |
133 VideoReceiveStream::Decoder decoder = | |
134 test::CreateMatchingDecoder(send_config.encoder_settings); | |
135 receive_config.decoders.push_back(decoder); | |
136 | 111 |
137 VideoReceiveStream* receive_stream = | 112 VideoReceiveStream* receive_stream = |
138 call->CreateVideoReceiveStream(receive_config); | 113 call->CreateVideoReceiveStream(receive_configs_[0]); |
139 | 114 |
140 receive_stream->Start(); | 115 receive_stream->Start(); |
141 send_stream->Start(); | 116 send_stream->Start(); |
142 capturer->Start(); | 117 capturer->Start(); |
143 | 118 |
144 test::PressEnterToContinue(); | 119 test::PressEnterToContinue(); |
145 | 120 |
146 capturer->Stop(); | 121 capturer->Stop(); |
147 send_stream->Stop(); | 122 send_stream->Stop(); |
148 receive_stream->Stop(); | 123 receive_stream->Stop(); |
149 | 124 |
150 call->DestroyVideoReceiveStream(receive_stream); | 125 call->DestroyVideoReceiveStream(receive_stream); |
151 call->DestroyVideoSendStream(send_stream); | 126 call->DestroyVideoSendStream(send_stream); |
152 | 127 |
153 delete decoder.decoder; | 128 // delete decoder.decoder; |
sprang_webrtc
2015/09/11 08:01:34
Remove
ivica
2015/09/14 17:12:55
Same as above, file deleted.
| |
154 | 129 |
155 send_transport.StopSending(); | 130 send_transport.StopSending(); |
156 } | 131 } |
157 | 132 |
158 VideoEncoderConfig Loopback::CreateEncoderConfig() { | |
159 VideoEncoderConfig encoder_config; | |
160 encoder_config.streams = test::CreateVideoStreams(1); | |
161 VideoStream* stream = &encoder_config.streams[0]; | |
162 stream->width = config_.width; | |
163 stream->height = config_.height; | |
164 stream->min_bitrate_bps = static_cast<int>(config_.min_bitrate_kbps) * 1000; | |
165 stream->max_bitrate_bps = static_cast<int>(config_.max_bitrate_kbps) * 1000; | |
166 stream->target_bitrate_bps = | |
167 static_cast<int>(config_.max_bitrate_kbps) * 1000; | |
168 stream->max_framerate = config_.fps; | |
169 stream->max_qp = 56; | |
170 if (config_.num_temporal_layers != 0) { | |
171 stream->temporal_layer_thresholds_bps.resize(config_.num_temporal_layers - | |
172 1); | |
173 } | |
174 return encoder_config; | |
175 } | |
176 | |
177 test::VideoCapturer* Loopback::CreateCapturer(VideoSendStream* send_stream) { | |
178 return test::VideoCapturer::Create(send_stream->Input(), config_.width, | |
179 config_.height, config_.fps, clock_); | |
180 } | |
181 | |
182 } // namespace test | 133 } // namespace test |
183 } // namespace webrtc | 134 } // namespace webrtc |
OLD | NEW |