OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 | |
13 #include <map> | |
14 | |
15 #include "webrtc/video/loopback.h" | |
16 | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
19 #include "webrtc/base/checks.h" | |
20 #include "webrtc/base/scoped_ptr.h" | |
21 #include "webrtc/call.h" | |
22 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | |
23 #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" | |
24 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | |
25 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | |
26 #include "webrtc/system_wrappers/interface/clock.h" | |
27 #include "webrtc/test/encoder_settings.h" | |
28 #include "webrtc/test/fake_encoder.h" | |
29 #include "webrtc/test/layer_filtering_transport.h" | |
30 #include "webrtc/test/run_loop.h" | |
31 #include "webrtc/test/testsupport/trace_to_stderr.h" | |
32 #include "webrtc/test/video_capturer.h" | |
33 #include "webrtc/test/video_renderer.h" | |
34 #include "webrtc/typedefs.h" | |
35 | |
36 namespace webrtc { | |
37 namespace test { | |
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; | |
46 static const uint8_t kVideoPayloadTypeVP8 = 124; | |
47 static const uint8_t kVideoPayloadTypeVP9 = 125; | |
48 | |
49 Loopback::Loopback(const Config& config) | |
50 : config_(config), clock_(Clock::GetRealTimeClock()) { | |
51 } | |
52 | |
53 Loopback::~Loopback() { | |
54 } | |
55 | |
56 void Loopback::Run() { | |
57 rtc::scoped_ptr<test::TraceToStderr> trace_to_stderr_; | |
58 if (config_.logs) | |
59 trace_to_stderr_.reset(new test::TraceToStderr); | |
60 | |
61 rtc::scoped_ptr<test::VideoRenderer> local_preview( | |
62 test::VideoRenderer::Create("Local Preview", config_.width, | |
63 config_.height)); | |
64 rtc::scoped_ptr<test::VideoRenderer> loopback_video( | |
65 test::VideoRenderer::Create("Loopback Video", config_.width, | |
66 config_.height)); | |
67 | |
68 Call::Config call_config; | |
69 call_config.bitrate_config.min_bitrate_bps = | |
70 static_cast<int>(config_.min_bitrate_kbps) * 1000; | |
71 call_config.bitrate_config.start_bitrate_bps = | |
72 static_cast<int>(config_.start_bitrate_kbps) * 1000; | |
73 call_config.bitrate_config.max_bitrate_bps = | |
74 static_cast<int>(config_.max_bitrate_kbps) * 1000; | |
75 rtc::scoped_ptr<Call> call(Call::Create(call_config)); | |
76 | |
77 FakeNetworkPipe::Config pipe_config; | |
78 pipe_config.loss_percent = config_.loss_percent; | |
79 pipe_config.link_capacity_kbps = config_.link_capacity_kbps; | |
80 pipe_config.queue_length_packets = config_.queue_size; | |
81 pipe_config.queue_delay_ms = config_.avg_propagation_delay_ms; | |
82 pipe_config.delay_standard_deviation_ms = config_.std_propagation_delay_ms; | |
83 LayerFilteringTransport send_transport( | |
84 pipe_config, kVideoPayloadTypeVP8, kVideoPayloadTypeVP9, | |
85 static_cast<uint8_t>(config_.tl_discard_threshold), | |
86 static_cast<uint8_t>(config_.sl_discard_threshold)); | |
87 | |
88 // Loopback, call sends to itself. | |
89 send_transport.SetReceiver(call->Receiver()); | |
90 | |
91 VideoSendStream::Config send_config(&send_transport); | |
92 send_config.rtp.ssrcs.push_back(kSendSsrc); | |
93 send_config.rtp.rtx.ssrcs.push_back(kSendRtxSsrc); | |
94 send_config.rtp.rtx.payload_type = kRtxVideoPayloadType; | |
95 send_config.rtp.nack.rtp_history_ms = 1000; | |
96 send_config.rtp.extensions.push_back( | |
97 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeExtensionId)); | |
98 | |
99 send_config.local_renderer = local_preview.get(); | |
100 rtc::scoped_ptr<VideoEncoder> encoder; | |
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 | |
118 VideoSendStream* send_stream = | |
119 call->CreateVideoSendStream(send_config, encoder_config); | |
120 | |
121 rtc::scoped_ptr<test::VideoCapturer> capturer(CreateCapturer(send_stream)); | |
122 | |
123 VideoReceiveStream::Config receive_config(&send_transport); | |
124 receive_config.rtp.remote_ssrc = send_config.rtp.ssrcs[0]; | |
125 receive_config.rtp.local_ssrc = kReceiverLocalSsrc; | |
126 receive_config.rtp.nack.rtp_history_ms = 1000; | |
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)); | |
132 receive_config.renderer = loopback_video.get(); | |
133 VideoReceiveStream::Decoder decoder = | |
134 test::CreateMatchingDecoder(send_config.encoder_settings); | |
135 receive_config.decoders.push_back(decoder); | |
136 | |
137 VideoReceiveStream* receive_stream = | |
138 call->CreateVideoReceiveStream(receive_config); | |
139 | |
140 receive_stream->Start(); | |
141 send_stream->Start(); | |
142 capturer->Start(); | |
143 | |
144 test::PressEnterToContinue(); | |
145 | |
146 capturer->Stop(); | |
147 send_stream->Stop(); | |
148 receive_stream->Stop(); | |
149 | |
150 call->DestroyVideoReceiveStream(receive_stream); | |
151 call->DestroyVideoSendStream(send_stream); | |
152 | |
153 delete decoder.decoder; | |
154 | |
155 send_transport.StopSending(); | |
156 } | |
157 | |
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 | |
183 } // namespace webrtc | |
OLD | NEW |