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 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 codec.width = 320; | 137 codec.width = 320; |
138 codec.height = 180; | 138 codec.height = 180; |
139 codec.startBitrate = codec.minBitrate = codec.maxBitrate = | 139 codec.startBitrate = codec.minBitrate = codec.maxBitrate = |
140 Call::Config::kDefaultStartBitrateBps / 1000; | 140 Call::Config::kDefaultStartBitrateBps / 1000; |
141 | 141 |
142 return codec; | 142 return codec; |
143 } | 143 } |
144 } // namespace | 144 } // namespace |
145 | 145 |
146 namespace internal { | 146 namespace internal { |
147 | |
148 // Since an IncomingVideoStream instance will create a thread/queue, we don't | |
149 // instantiate one unless we know we're going to be delivering the frames | |
150 // to a renderer. | |
151 // | |
152 // TODO(tommi): Consider making the functionality provided by the | |
153 // IncomingVideoStream classes, tied to the Config class instead or even higher | |
154 // level. That will make it an optional feature that will be up to the | |
155 // application to use or not use. Right now, we have two classes available, | |
156 // they both have threads involved which uses WebRTC's threading classes and | |
157 // that might not suit what the application wants to do. If one of them or | |
158 // neither, suits, the app can get some code size back as well as more control. | |
159 std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> | |
160 MaybeCreateIncomingVideoStream(const VideoReceiveStream::Config& config, | |
161 rtc::VideoSinkInterface<VideoFrame>* callback) { | |
162 std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> ret; | |
163 if (config.renderer) { | |
164 if (config.disable_prerenderer_smoothing) { | |
165 ret.reset(new IncomingVideoStreamNoSmoothing(callback)); | |
166 } else { | |
167 ret.reset(new IncomingVideoStream(config.render_delay_ms, callback)); | |
168 } | |
169 } | |
170 return ret; | |
171 } | |
172 | |
173 VideoReceiveStream::VideoReceiveStream( | 147 VideoReceiveStream::VideoReceiveStream( |
174 int num_cpu_cores, | 148 int num_cpu_cores, |
175 CongestionController* congestion_controller, | 149 CongestionController* congestion_controller, |
176 VideoReceiveStream::Config config, | 150 VideoReceiveStream::Config config, |
177 webrtc::VoiceEngine* voice_engine, | 151 webrtc::VoiceEngine* voice_engine, |
178 ProcessThread* process_thread, | 152 ProcessThread* process_thread, |
179 CallStats* call_stats, | 153 CallStats* call_stats, |
180 VieRemb* remb) | 154 VieRemb* remb) |
181 : transport_adapter_(config.rtcp_send_transport), | 155 : transport_adapter_(config.rtcp_send_transport), |
182 config_(std::move(config)), | 156 config_(std::move(config)), |
183 process_thread_(process_thread), | 157 process_thread_(process_thread), |
184 clock_(Clock::GetRealTimeClock()), | 158 clock_(Clock::GetRealTimeClock()), |
185 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 159 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
186 congestion_controller_(congestion_controller), | 160 congestion_controller_(congestion_controller), |
187 call_stats_(call_stats), | 161 call_stats_(call_stats), |
188 video_receiver_(clock_, nullptr, this, this, this), | 162 video_receiver_(clock_, nullptr, this, this, this), |
| 163 incoming_video_stream_(config_.disable_prerenderer_smoothing), |
189 stats_proxy_(&config_, clock_), | 164 stats_proxy_(&config_, clock_), |
190 rtp_stream_receiver_(&video_receiver_, | 165 rtp_stream_receiver_(&video_receiver_, |
191 congestion_controller_->GetRemoteBitrateEstimator( | 166 congestion_controller_->GetRemoteBitrateEstimator( |
192 UseSendSideBwe(config_)), | 167 UseSendSideBwe(config_)), |
193 &transport_adapter_, | 168 &transport_adapter_, |
194 call_stats_->rtcp_rtt_stats(), | 169 call_stats_->rtcp_rtt_stats(), |
195 congestion_controller_->pacer(), | 170 congestion_controller_->pacer(), |
196 congestion_controller_->packet_router(), | 171 congestion_controller_->packet_router(), |
197 remb, | 172 remb, |
198 &config_, | 173 &config_, |
199 &stats_proxy_, | 174 &stats_proxy_, |
200 process_thread_), | 175 process_thread_), |
| 176 video_stream_decoder_(&video_receiver_, |
| 177 &rtp_stream_receiver_, |
| 178 &rtp_stream_receiver_, |
| 179 rtp_stream_receiver_.IsRetransmissionsEnabled(), |
| 180 rtp_stream_receiver_.IsFecEnabled(), |
| 181 &stats_proxy_, |
| 182 &incoming_video_stream_, |
| 183 config.pre_render_callback), |
201 vie_sync_(&video_receiver_) { | 184 vie_sync_(&video_receiver_) { |
202 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 185 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
203 | 186 |
204 RTC_DCHECK(process_thread_); | 187 RTC_DCHECK(process_thread_); |
205 RTC_DCHECK(congestion_controller_); | 188 RTC_DCHECK(congestion_controller_); |
206 RTC_DCHECK(call_stats_); | 189 RTC_DCHECK(call_stats_); |
207 | 190 |
| 191 // Register the channel to receive stats updates. |
| 192 call_stats_->RegisterStatsObserver(&video_stream_decoder_); |
| 193 |
208 RTC_DCHECK(!config_.decoders.empty()); | 194 RTC_DCHECK(!config_.decoders.empty()); |
209 std::set<int> decoder_payload_types; | 195 std::set<int> decoder_payload_types; |
210 for (const Decoder& decoder : config_.decoders) { | 196 for (const Decoder& decoder : config_.decoders) { |
211 RTC_CHECK(decoder.decoder); | 197 RTC_CHECK(decoder.decoder); |
212 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 198 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
213 decoder_payload_types.end()) | 199 decoder_payload_types.end()) |
214 << "Duplicate payload type (" << decoder.payload_type | 200 << "Duplicate payload type (" << decoder.payload_type |
215 << ") for different decoders."; | 201 << ") for different decoders."; |
216 decoder_payload_types.insert(decoder.payload_type); | 202 decoder_payload_types.insert(decoder.payload_type); |
217 video_receiver_.RegisterExternalDecoder(decoder.decoder, | 203 video_receiver_.RegisterExternalDecoder(decoder.decoder, |
218 decoder.payload_type); | 204 decoder.payload_type); |
219 | 205 |
220 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 206 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
221 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); | 207 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); |
222 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( | 208 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( |
223 &codec, num_cpu_cores, false)); | 209 &codec, num_cpu_cores, false)); |
224 } | 210 } |
225 | 211 |
226 video_receiver_.SetRenderDelay(config.render_delay_ms); | 212 video_receiver_.SetRenderDelay(config.render_delay_ms); |
| 213 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); |
| 214 incoming_video_stream_.SetExternalCallback(this); |
227 | 215 |
228 process_thread_->RegisterModule(&video_receiver_); | 216 process_thread_->RegisterModule(&video_receiver_); |
229 process_thread_->RegisterModule(&vie_sync_); | 217 process_thread_->RegisterModule(&vie_sync_); |
230 } | 218 } |
231 | 219 |
232 VideoReceiveStream::~VideoReceiveStream() { | 220 VideoReceiveStream::~VideoReceiveStream() { |
233 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 221 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
234 Stop(); | 222 Stop(); |
235 | 223 |
236 process_thread_->DeRegisterModule(&vie_sync_); | 224 process_thread_->DeRegisterModule(&vie_sync_); |
237 process_thread_->DeRegisterModule(&video_receiver_); | 225 process_thread_->DeRegisterModule(&video_receiver_); |
238 | 226 |
239 // Deregister external decoders so they are no longer running during | 227 // Deregister external decoders so they are no longer running during |
240 // destruction. This effectively stops the VCM since the decoder thread is | 228 // destruction. This effectively stops the VCM since the decoder thread is |
241 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 229 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
242 // running. | 230 // running. |
243 for (const Decoder& decoder : config_.decoders) | 231 for (const Decoder& decoder : config_.decoders) |
244 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 232 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
245 | 233 |
| 234 call_stats_->DeregisterStatsObserver(&video_stream_decoder_); |
| 235 |
246 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | 236 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) |
247 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); | 237 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); |
248 } | 238 } |
249 | 239 |
250 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 240 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
251 rtp_stream_receiver_.SignalNetworkState(state); | 241 rtp_stream_receiver_.SignalNetworkState(state); |
252 } | 242 } |
253 | 243 |
254 | 244 |
255 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 245 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
256 return rtp_stream_receiver_.DeliverRtcp(packet, length); | 246 return rtp_stream_receiver_.DeliverRtcp(packet, length); |
257 } | 247 } |
258 | 248 |
259 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, | 249 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, |
260 size_t length, | 250 size_t length, |
261 const PacketTime& packet_time) { | 251 const PacketTime& packet_time) { |
262 return rtp_stream_receiver_.DeliverRtp(packet, length, packet_time); | 252 return rtp_stream_receiver_.DeliverRtp(packet, length, packet_time); |
263 } | 253 } |
264 | 254 |
265 void VideoReceiveStream::Start() { | 255 void VideoReceiveStream::Start() { |
266 if (decode_thread_.IsRunning()) | 256 if (decode_thread_.IsRunning()) |
267 return; | 257 return; |
268 transport_adapter_.Enable(); | 258 transport_adapter_.Enable(); |
269 incoming_video_stream_ = MaybeCreateIncomingVideoStream(config_, this); | 259 incoming_video_stream_.Start(); |
270 video_stream_decoder_.reset(new VideoStreamDecoder( | |
271 &video_receiver_, &rtp_stream_receiver_, &rtp_stream_receiver_, | |
272 rtp_stream_receiver_.IsRetransmissionsEnabled(), | |
273 rtp_stream_receiver_.IsFecEnabled(), &stats_proxy_, | |
274 incoming_video_stream_.get(), config_.pre_render_callback)); | |
275 // Register the channel to receive stats updates. | |
276 call_stats_->RegisterStatsObserver(video_stream_decoder_.get()); | |
277 // Start the decode thread | 260 // Start the decode thread |
278 decode_thread_.Start(); | 261 decode_thread_.Start(); |
279 decode_thread_.SetPriority(rtc::kHighestPriority); | 262 decode_thread_.SetPriority(rtc::kHighestPriority); |
280 rtp_stream_receiver_.StartReceive(); | 263 rtp_stream_receiver_.StartReceive(); |
281 } | 264 } |
282 | 265 |
283 void VideoReceiveStream::Stop() { | 266 void VideoReceiveStream::Stop() { |
| 267 incoming_video_stream_.Stop(); |
284 rtp_stream_receiver_.StopReceive(); | 268 rtp_stream_receiver_.StopReceive(); |
285 video_receiver_.TriggerDecoderShutdown(); | 269 video_receiver_.TriggerDecoderShutdown(); |
286 decode_thread_.Stop(); | 270 decode_thread_.Stop(); |
287 call_stats_->DeregisterStatsObserver(video_stream_decoder_.get()); | |
288 video_stream_decoder_.reset(); | |
289 incoming_video_stream_.reset(); | |
290 transport_adapter_.Disable(); | 271 transport_adapter_.Disable(); |
291 } | 272 } |
292 | 273 |
293 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, | 274 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, |
294 int audio_channel_id) { | 275 int audio_channel_id) { |
295 if (voice_engine && audio_channel_id != -1) { | 276 if (voice_engine && audio_channel_id != -1) { |
296 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); | 277 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); |
297 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, | 278 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, |
298 rtp_stream_receiver_.rtp_rtcp(), | 279 rtp_stream_receiver_.rtp_rtcp(), |
299 rtp_stream_receiver_.GetRtpReceiver()); | 280 rtp_stream_receiver_.GetRtpReceiver()); |
300 voe_sync_interface->Release(); | 281 voe_sync_interface->Release(); |
301 } else { | 282 } else { |
302 vie_sync_.ConfigureSync(-1, nullptr, rtp_stream_receiver_.rtp_rtcp(), | 283 vie_sync_.ConfigureSync(-1, nullptr, rtp_stream_receiver_.rtp_rtcp(), |
303 rtp_stream_receiver_.GetRtpReceiver()); | 284 rtp_stream_receiver_.GetRtpReceiver()); |
304 } | 285 } |
305 } | 286 } |
306 | 287 |
307 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { | 288 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { |
308 return stats_proxy_.GetStats(); | 289 return stats_proxy_.GetStats(); |
309 } | 290 } |
310 | 291 |
311 // TODO(tommi): This method grabs a lock 6 times. | |
312 void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { | 292 void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { |
313 // TODO(tommi): OnDecodedFrame grabs a lock, incidentally the same lock | |
314 // that OnSyncOffsetUpdated() and OnRenderedFrame() below grab. | |
315 stats_proxy_.OnDecodedFrame(); | 293 stats_proxy_.OnDecodedFrame(); |
316 | 294 |
317 int64_t sync_offset_ms; | 295 int64_t sync_offset_ms; |
318 // TODO(tommi): GetStreamSyncOffsetInMs grabs three locks. One inside the | 296 if (vie_sync_.GetStreamSyncOffsetInMs(video_frame, &sync_offset_ms)) |
319 // function itself, another in GetChannel() and a third in | |
320 // GetPlayoutTimestamp. Seems excessive. Anyhow, I'm assuming the function | |
321 // succeeds most of the time, which leads to grabbing a fourth lock. | |
322 if (vie_sync_.GetStreamSyncOffsetInMs(video_frame, &sync_offset_ms)) { | |
323 // TODO(tommi): OnSyncOffsetUpdated grabs a lock. | |
324 stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms); | 297 stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms); |
325 } | |
326 | 298 |
327 // config_.renderer must never be null if we're getting this callback. | 299 if (config_.renderer) |
328 config_.renderer->OnFrame(video_frame); | 300 config_.renderer->OnFrame(video_frame); |
329 | 301 |
330 // TODO(tommi): OnRenderFrame grabs a lock too. | |
331 stats_proxy_.OnRenderedFrame(video_frame.width(), video_frame.height()); | 302 stats_proxy_.OnRenderedFrame(video_frame.width(), video_frame.height()); |
332 } | 303 } |
333 | 304 |
334 // TODO(asapersson): Consider moving callback from video_encoder.h or | 305 // TODO(asapersson): Consider moving callback from video_encoder.h or |
335 // creating a different callback. | 306 // creating a different callback. |
336 int32_t VideoReceiveStream::Encoded( | 307 int32_t VideoReceiveStream::Encoded( |
337 const EncodedImage& encoded_image, | 308 const EncodedImage& encoded_image, |
338 const CodecSpecificInfo* codec_specific_info, | 309 const CodecSpecificInfo* codec_specific_info, |
339 const RTPFragmentationHeader* fragmentation) { | 310 const RTPFragmentationHeader* fragmentation) { |
340 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); | 311 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 const std::vector<uint16_t>& sequence_numbers) { | 345 const std::vector<uint16_t>& sequence_numbers) { |
375 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); | 346 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); |
376 } | 347 } |
377 | 348 |
378 void VideoReceiveStream::RequestKeyFrame() { | 349 void VideoReceiveStream::RequestKeyFrame() { |
379 rtp_stream_receiver_.RequestKeyFrame(); | 350 rtp_stream_receiver_.RequestKeyFrame(); |
380 } | 351 } |
381 | 352 |
382 } // namespace internal | 353 } // namespace internal |
383 } // namespace webrtc | 354 } // namespace webrtc |
OLD | NEW |