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

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

Issue 2338133003: Let ViEEncoder tell VideoSendStream about reconfigurations. (Closed)
Patch Set: Rebased Created 4 years, 3 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
« no previous file with comments | « webrtc/video/payload_router_unittest.cc ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "webrtc/video/video_send_stream.h" 10 #include "webrtc/video/video_send_stream.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 namespace { 195 namespace {
196 196
197 bool PayloadTypeSupportsSkippingFecPackets(const std::string& payload_name) { 197 bool PayloadTypeSupportsSkippingFecPackets(const std::string& payload_name) {
198 if (payload_name == "VP8" || payload_name == "VP9") 198 if (payload_name == "VP8" || payload_name == "VP9")
199 return true; 199 return true;
200 RTC_DCHECK(payload_name == "H264" || payload_name == "FAKE") 200 RTC_DCHECK(payload_name == "H264" || payload_name == "FAKE")
201 << "unknown payload_name " << payload_name; 201 << "unknown payload_name " << payload_name;
202 return false; 202 return false;
203 } 203 }
204 204
205 int CalculateMaxPadBitrateBps(const VideoEncoderConfig& config, 205 int CalculateMaxPadBitrateBps(std::vector<VideoStream> streams,
206 int min_transmit_bitrate_bps,
206 bool pad_to_min_bitrate) { 207 bool pad_to_min_bitrate) {
207 int pad_up_to_bitrate_bps = 0; 208 int pad_up_to_bitrate_bps = 0;
208 // Calculate max padding bitrate for a multi layer codec. 209 // Calculate max padding bitrate for a multi layer codec.
209 if (config.streams.size() > 1) { 210 if (streams.size() > 1) {
210 // Pad to min bitrate of the highest layer. 211 // Pad to min bitrate of the highest layer.
211 pad_up_to_bitrate_bps = 212 pad_up_to_bitrate_bps = streams[streams.size() - 1].min_bitrate_bps;
212 config.streams[config.streams.size() - 1].min_bitrate_bps;
213 // Add target_bitrate_bps of the lower layers. 213 // Add target_bitrate_bps of the lower layers.
214 for (size_t i = 0; i < config.streams.size() - 1; ++i) 214 for (size_t i = 0; i < streams.size() - 1; ++i)
215 pad_up_to_bitrate_bps += config.streams[i].target_bitrate_bps; 215 pad_up_to_bitrate_bps += streams[i].target_bitrate_bps;
216 } else if (pad_to_min_bitrate) { 216 } else if (pad_to_min_bitrate) {
217 pad_up_to_bitrate_bps = config.streams[0].min_bitrate_bps; 217 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps;
218 } 218 }
219 219
220 pad_up_to_bitrate_bps = 220 pad_up_to_bitrate_bps =
221 std::max(pad_up_to_bitrate_bps, config.min_transmit_bitrate_bps); 221 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps);
222 222
223 return pad_up_to_bitrate_bps; 223 return pad_up_to_bitrate_bps;
224 } 224 }
225 225
226 } // namespace 226 } // namespace
227 227
228 namespace internal { 228 namespace internal {
229 229
230 // VideoSendStreamImpl implements internal::VideoSendStream. 230 // VideoSendStreamImpl implements internal::VideoSendStream.
231 // It is created and destroyed on |worker_queue|. The intent is to decrease the 231 // It is created and destroyed on |worker_queue|. The intent is to decrease the
232 // need for locking and to ensure methods are called in sequence. 232 // need for locking and to ensure methods are called in sequence.
233 // Public methods except |DeliverRtcp| must be called on |worker_queue|. 233 // Public methods except |DeliverRtcp| must be called on |worker_queue|.
234 // DeliverRtcp is called on the libjingle worker thread or a network thread. 234 // DeliverRtcp is called on the libjingle worker thread or a network thread.
235 // An encoder may deliver frames through the EncodedImageCallback on an 235 // An encoder may deliver frames through the EncodedImageCallback on an
236 // arbitrary thread. 236 // arbitrary thread.
237 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, 237 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
238 public webrtc::VCMProtectionCallback, 238 public webrtc::VCMProtectionCallback,
239 public EncodedImageCallback { 239 public ViEEncoder::EncoderSink {
240 public: 240 public:
241 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, 241 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy,
242 rtc::TaskQueue* worker_queue, 242 rtc::TaskQueue* worker_queue,
243 CallStats* call_stats, 243 CallStats* call_stats,
244 CongestionController* congestion_controller, 244 CongestionController* congestion_controller,
245 BitrateAllocator* bitrate_allocator, 245 BitrateAllocator* bitrate_allocator,
246 SendDelayStats* send_delay_stats, 246 SendDelayStats* send_delay_stats,
247 VieRemb* remb, 247 VieRemb* remb,
248 ViEEncoder* vie_encoder, 248 ViEEncoder* vie_encoder,
249 RtcEventLog* event_log, 249 RtcEventLog* event_log,
250 const VideoSendStream::Config* config, 250 const VideoSendStream::Config* config,
251 int initial_encoder_max_bitrate,
251 std::map<uint32_t, RtpState> suspended_ssrcs); 252 std::map<uint32_t, RtpState> suspended_ssrcs);
252 ~VideoSendStreamImpl() override; 253 ~VideoSendStreamImpl() override;
253 254
254 // RegisterProcessThread register |module_process_thread| with those objects 255 // RegisterProcessThread register |module_process_thread| with those objects
255 // that use it. Registration has to happen on the thread were 256 // that use it. Registration has to happen on the thread were
256 // |module_process_thread| was created (libjingle's worker thread). 257 // |module_process_thread| was created (libjingle's worker thread).
257 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, 258 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue,
258 // maybe |worker_queue|. 259 // maybe |worker_queue|.
259 void RegisterProcessThread(ProcessThread* module_process_thread); 260 void RegisterProcessThread(ProcessThread* module_process_thread);
260 void DeRegisterProcessThread(); 261 void DeRegisterProcessThread();
261 262
262 void SignalNetworkState(NetworkState state); 263 void SignalNetworkState(NetworkState state);
263 bool DeliverRtcp(const uint8_t* packet, size_t length); 264 bool DeliverRtcp(const uint8_t* packet, size_t length);
264 void Start(); 265 void Start();
265 void Stop(); 266 void Stop();
266 267
267 void SignalEncoderConfigurationChanged(const VideoEncoderConfig& config);
268 VideoSendStream::RtpStateMap GetRtpStates() const; 268 VideoSendStream::RtpStateMap GetRtpStates() const;
269 269
270 private: 270 private:
271 class CheckEncoderActivityTask; 271 class CheckEncoderActivityTask;
272 class EncoderReconfiguredTask;
272 273
273 // Implements BitrateAllocatorObserver. 274 // Implements BitrateAllocatorObserver.
274 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, 275 uint32_t OnBitrateUpdated(uint32_t bitrate_bps,
275 uint8_t fraction_loss, 276 uint8_t fraction_loss,
276 int64_t rtt) override; 277 int64_t rtt) override;
277 278
278 // Implements webrtc::VCMProtectionCallback. 279 // Implements webrtc::VCMProtectionCallback.
279 int ProtectionRequest(const FecProtectionParams* delta_params, 280 int ProtectionRequest(const FecProtectionParams* delta_params,
280 const FecProtectionParams* key_params, 281 const FecProtectionParams* key_params,
281 uint32_t* sent_video_rate_bps, 282 uint32_t* sent_video_rate_bps,
282 uint32_t* sent_nack_rate_bps, 283 uint32_t* sent_nack_rate_bps,
283 uint32_t* sent_fec_rate_bps) override; 284 uint32_t* sent_fec_rate_bps) override;
284 285
286 void OnEncoderConfigurationChanged(std::vector<VideoStream> streams,
287 int min_transmit_bitrate_bps) override;
288
285 // Implements EncodedImageCallback. The implementation routes encoded frames 289 // Implements EncodedImageCallback. The implementation routes encoded frames
286 // to the |payload_router_| and |config.pre_encode_callback| if set. 290 // to the |payload_router_| and |config.pre_encode_callback| if set.
287 // Called on an arbitrary encoder callback thread. 291 // Called on an arbitrary encoder callback thread.
288 EncodedImageCallback::Result OnEncodedImage( 292 EncodedImageCallback::Result OnEncodedImage(
289 const EncodedImage& encoded_image, 293 const EncodedImage& encoded_image,
290 const CodecSpecificInfo* codec_specific_info, 294 const CodecSpecificInfo* codec_specific_info,
291 const RTPFragmentationHeader* fragmentation) override; 295 const RTPFragmentationHeader* fragmentation) override;
292 296
293 void ConfigureProtection(); 297 void ConfigureProtection();
294 void ConfigureSsrcs(); 298 void ConfigureSsrcs();
295 void SignalEncoderTimedOut(); 299 void SignalEncoderTimedOut();
296 void SignalEncoderActive(); 300 void SignalEncoderActive();
297 301
298 SendStatisticsProxy* const stats_proxy_; 302 SendStatisticsProxy* const stats_proxy_;
299 const VideoSendStream::Config* const config_; 303 const VideoSendStream::Config* const config_;
300 std::map<uint32_t, RtpState> suspended_ssrcs_; 304 std::map<uint32_t, RtpState> suspended_ssrcs_;
301 305
302 ProcessThread* module_process_thread_; 306 ProcessThread* module_process_thread_;
303 rtc::ThreadChecker module_process_thread_checker_; 307 rtc::ThreadChecker module_process_thread_checker_;
304 rtc::TaskQueue* const worker_queue_; 308 rtc::TaskQueue* const worker_queue_;
305 309
306 rtc::CriticalSection encoder_activity_crit_sect_; 310 rtc::CriticalSection encoder_activity_crit_sect_;
307 CheckEncoderActivityTask* check_encoder_activity_task_ 311 CheckEncoderActivityTask* check_encoder_activity_task_
308 GUARDED_BY(encoder_activity_crit_sect_); 312 GUARDED_BY(encoder_activity_crit_sect_);
313
309 CallStats* const call_stats_; 314 CallStats* const call_stats_;
310 CongestionController* const congestion_controller_; 315 CongestionController* const congestion_controller_;
311 BitrateAllocator* const bitrate_allocator_; 316 BitrateAllocator* const bitrate_allocator_;
312 VieRemb* const remb_; 317 VieRemb* const remb_;
313 318
314 static const bool kEnableFrameRecording = false; 319 static const bool kEnableFrameRecording = false;
315 static const int kMaxLayers = 3; 320 static const int kMaxLayers = 3;
316 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; 321 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers];
317 322
318 int max_padding_bitrate_; 323 int max_padding_bitrate_;
(...skipping 20 matching lines...) Expand all
339 SendStatisticsProxy* stats_proxy, 344 SendStatisticsProxy* stats_proxy,
340 ViEEncoder* vie_encoder, 345 ViEEncoder* vie_encoder,
341 ProcessThread* module_process_thread, 346 ProcessThread* module_process_thread,
342 CallStats* call_stats, 347 CallStats* call_stats,
343 CongestionController* congestion_controller, 348 CongestionController* congestion_controller,
344 BitrateAllocator* bitrate_allocator, 349 BitrateAllocator* bitrate_allocator,
345 SendDelayStats* send_delay_stats, 350 SendDelayStats* send_delay_stats,
346 VieRemb* remb, 351 VieRemb* remb,
347 RtcEventLog* event_log, 352 RtcEventLog* event_log,
348 const VideoSendStream::Config* config, 353 const VideoSendStream::Config* config,
354 int initial_encoder_max_bitrate,
349 const std::map<uint32_t, RtpState>& suspended_ssrcs) 355 const std::map<uint32_t, RtpState>& suspended_ssrcs)
350 : send_stream_(send_stream), 356 : send_stream_(send_stream),
351 done_event_(done_event), 357 done_event_(done_event),
352 stats_proxy_(stats_proxy), 358 stats_proxy_(stats_proxy),
353 vie_encoder_(vie_encoder), 359 vie_encoder_(vie_encoder),
354 call_stats_(call_stats), 360 call_stats_(call_stats),
355 congestion_controller_(congestion_controller), 361 congestion_controller_(congestion_controller),
356 bitrate_allocator_(bitrate_allocator), 362 bitrate_allocator_(bitrate_allocator),
357 send_delay_stats_(send_delay_stats), 363 send_delay_stats_(send_delay_stats),
358 remb_(remb), 364 remb_(remb),
359 event_log_(event_log), 365 event_log_(event_log),
360 config_(config), 366 config_(config),
367 initial_encoder_max_bitrate_(initial_encoder_max_bitrate),
361 suspended_ssrcs_(suspended_ssrcs) {} 368 suspended_ssrcs_(suspended_ssrcs) {}
362 369
363 ~ConstructionTask() override { done_event_->Set(); } 370 ~ConstructionTask() override { done_event_->Set(); }
364 371
365 private: 372 private:
366 bool Run() override { 373 bool Run() override {
367 send_stream_->reset(new VideoSendStreamImpl( 374 send_stream_->reset(new VideoSendStreamImpl(
368 stats_proxy_, rtc::TaskQueue::Current(), call_stats_, 375 stats_proxy_, rtc::TaskQueue::Current(), call_stats_,
369 congestion_controller_, bitrate_allocator_, send_delay_stats_, remb_, 376 congestion_controller_, bitrate_allocator_, send_delay_stats_, remb_,
370 vie_encoder_, event_log_, config_, std::move(suspended_ssrcs_))); 377 vie_encoder_, event_log_, config_, initial_encoder_max_bitrate_,
378 std::move(suspended_ssrcs_)));
371 return true; 379 return true;
372 } 380 }
373 381
374 std::unique_ptr<VideoSendStreamImpl>* const send_stream_; 382 std::unique_ptr<VideoSendStreamImpl>* const send_stream_;
375 rtc::Event* const done_event_; 383 rtc::Event* const done_event_;
376 SendStatisticsProxy* const stats_proxy_; 384 SendStatisticsProxy* const stats_proxy_;
377 ViEEncoder* const vie_encoder_; 385 ViEEncoder* const vie_encoder_;
378 CallStats* const call_stats_; 386 CallStats* const call_stats_;
379 CongestionController* const congestion_controller_; 387 CongestionController* const congestion_controller_;
380 BitrateAllocator* const bitrate_allocator_; 388 BitrateAllocator* const bitrate_allocator_;
381 SendDelayStats* const send_delay_stats_; 389 SendDelayStats* const send_delay_stats_;
382 VieRemb* const remb_; 390 VieRemb* const remb_;
383 RtcEventLog* const event_log_; 391 RtcEventLog* const event_log_;
384 const VideoSendStream::Config* config_; 392 const VideoSendStream::Config* config_;
393 int initial_encoder_max_bitrate_;
385 std::map<uint32_t, RtpState> suspended_ssrcs_; 394 std::map<uint32_t, RtpState> suspended_ssrcs_;
386 }; 395 };
387 396
388 class VideoSendStream::DestructAndGetRtpStateTask : public rtc::QueuedTask { 397 class VideoSendStream::DestructAndGetRtpStateTask : public rtc::QueuedTask {
389 public: 398 public:
390 DestructAndGetRtpStateTask(VideoSendStream::RtpStateMap* state_map, 399 DestructAndGetRtpStateTask(VideoSendStream::RtpStateMap* state_map,
391 std::unique_ptr<VideoSendStreamImpl> send_stream, 400 std::unique_ptr<VideoSendStreamImpl> send_stream,
392 rtc::Event* done_event) 401 rtc::Event* done_event)
393 : state_map_(state_map), 402 : state_map_(state_map),
394 send_stream_(std::move(send_stream)), 403 send_stream_(std::move(send_stream)),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // transferred to the task queue when PostDelayedTask was called. 463 // transferred to the task queue when PostDelayedTask was called.
455 return false; 464 return false;
456 } 465 }
457 volatile int activity_; 466 volatile int activity_;
458 467
459 rtc::SequencedTaskChecker task_checker_; 468 rtc::SequencedTaskChecker task_checker_;
460 VideoSendStreamImpl* send_stream_; 469 VideoSendStreamImpl* send_stream_;
461 bool timed_out_; 470 bool timed_out_;
462 }; 471 };
463 472
464 class ReconfigureVideoEncoderTask : public rtc::QueuedTask { 473 class VideoSendStreamImpl::EncoderReconfiguredTask : public rtc::QueuedTask {
465 public: 474 public:
466 ReconfigureVideoEncoderTask(VideoSendStreamImpl* send_stream, 475 EncoderReconfiguredTask(VideoSendStreamImpl* send_stream,
467 VideoEncoderConfig config) 476 std::vector<VideoStream> streams,
468 : send_stream_(send_stream), config_(std::move(config)) {} 477 int min_transmit_bitrate_bps)
478 : send_stream_(send_stream),
479 streams_(std::move(streams)),
480 min_transmit_bitrate_bps_(min_transmit_bitrate_bps) {}
469 481
470 private: 482 private:
471 bool Run() override { 483 bool Run() override {
472 send_stream_->SignalEncoderConfigurationChanged(std::move(config_)); 484 send_stream_->OnEncoderConfigurationChanged(std::move(streams_),
485 min_transmit_bitrate_bps_);
473 return true; 486 return true;
474 } 487 }
475 488
476 VideoSendStreamImpl* send_stream_; 489 VideoSendStreamImpl* send_stream_;
477 VideoEncoderConfig config_; 490 std::vector<VideoStream> streams_;
491 int min_transmit_bitrate_bps_;
478 }; 492 };
479 493
480 VideoSendStream::VideoSendStream( 494 VideoSendStream::VideoSendStream(
481 int num_cpu_cores, 495 int num_cpu_cores,
482 ProcessThread* module_process_thread, 496 ProcessThread* module_process_thread,
483 rtc::TaskQueue* worker_queue, 497 rtc::TaskQueue* worker_queue,
484 CallStats* call_stats, 498 CallStats* call_stats,
485 CongestionController* congestion_controller, 499 CongestionController* congestion_controller,
486 BitrateAllocator* bitrate_allocator, 500 BitrateAllocator* bitrate_allocator,
487 SendDelayStats* send_delay_stats, 501 SendDelayStats* send_delay_stats,
488 VieRemb* remb, 502 VieRemb* remb,
489 RtcEventLog* event_log, 503 RtcEventLog* event_log,
490 VideoSendStream::Config config, 504 VideoSendStream::Config config,
491 VideoEncoderConfig encoder_config, 505 VideoEncoderConfig encoder_config,
492 const std::map<uint32_t, RtpState>& suspended_ssrcs) 506 const std::map<uint32_t, RtpState>& suspended_ssrcs)
493 : worker_queue_(worker_queue), 507 : worker_queue_(worker_queue),
494 thread_sync_event_(false /* manual_reset */, false), 508 thread_sync_event_(false /* manual_reset */, false),
495 stats_proxy_(Clock::GetRealTimeClock(), 509 stats_proxy_(Clock::GetRealTimeClock(),
496 config, 510 config,
497 encoder_config.content_type), 511 encoder_config.content_type),
498 config_(std::move(config)) { 512 config_(std::move(config)) {
499 vie_encoder_.reset( 513 vie_encoder_.reset(
500 new ViEEncoder(num_cpu_cores, &stats_proxy_, config_.encoder_settings, 514 new ViEEncoder(num_cpu_cores, &stats_proxy_, config_.encoder_settings,
501 config_.pre_encode_callback, config_.overuse_callback, 515 config_.pre_encode_callback, config_.overuse_callback,
502 config_.post_encode_callback)); 516 config_.post_encode_callback));
503 517
518 // TODO(perkj): Remove vector<VideoStreams> from VideoEncoderConfig and
519 // replace with max_bitrate. The VideoStream should be created by ViEEncoder
520 // when the video resolution is known.
521 int initial_max_encoder_bitrate = 0;
522 for (const auto& stream : encoder_config.streams)
523 initial_max_encoder_bitrate += stream.max_bitrate_bps;
524
504 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask( 525 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new ConstructionTask(
505 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(), 526 &send_stream_, &thread_sync_event_, &stats_proxy_, vie_encoder_.get(),
506 module_process_thread, call_stats, congestion_controller, 527 module_process_thread, call_stats, congestion_controller,
507 bitrate_allocator, send_delay_stats, remb, event_log, &config_, 528 bitrate_allocator, send_delay_stats, remb, event_log, &config_,
508 suspended_ssrcs))); 529 initial_max_encoder_bitrate, suspended_ssrcs)));
509 530
510 // Wait for ConstructionTask to complete so that |send_stream_| can be used. 531 // Wait for ConstructionTask to complete so that |send_stream_| can be used.
511 // |module_process_thread| must be registered and deregistered on the thread 532 // |module_process_thread| must be registered and deregistered on the thread
512 // it was created on. 533 // it was created on.
513 thread_sync_event_.Wait(rtc::Event::kForever); 534 thread_sync_event_.Wait(rtc::Event::kForever);
514 send_stream_->RegisterProcessThread(module_process_thread); 535 send_stream_->RegisterProcessThread(module_process_thread);
515 536
516 vie_encoder_->RegisterProcessThread(module_process_thread); 537 vie_encoder_->RegisterProcessThread(module_process_thread);
517 538
518 ReconfigureVideoEncoder(std::move(encoder_config)); 539 ReconfigureVideoEncoder(std::move(encoder_config));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 vie_encoder_->SetSource(source); 572 vie_encoder_->SetSource(source);
552 } 573 }
553 574
554 void VideoSendStream::ReconfigureVideoEncoder(VideoEncoderConfig config) { 575 void VideoSendStream::ReconfigureVideoEncoder(VideoEncoderConfig config) {
555 // ReconfigureVideoEncoder will be called on the thread that deliverers video 576 // ReconfigureVideoEncoder will be called on the thread that deliverers video
556 // frames. We must change the encoder settings immediately so that 577 // frames. We must change the encoder settings immediately so that
557 // the codec settings matches the next frame. 578 // the codec settings matches the next frame.
558 // TODO(perkj): Move logic for reconfiguration the encoder due to frame size 579 // TODO(perkj): Move logic for reconfiguration the encoder due to frame size
559 // change from WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame to 580 // change from WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame to
560 // be internally handled by ViEEncoder. 581 // be internally handled by ViEEncoder.
561 vie_encoder_->ConfigureEncoder(config, config_.rtp.max_packet_size); 582 vie_encoder_->ConfigureEncoder(std::move(config),
562 583 config_.rtp.max_packet_size);
563 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(
564 new ReconfigureVideoEncoderTask(send_stream_.get(), std::move(config))));
565 } 584 }
566 585
567 VideoSendStream::Stats VideoSendStream::GetStats() { 586 VideoSendStream::Stats VideoSendStream::GetStats() {
568 // TODO(perkj, solenberg): Some test cases in EndToEndTest call GetStats from 587 // TODO(perkj, solenberg): Some test cases in EndToEndTest call GetStats from
569 // a network thread. See comment in Call::GetStats(). 588 // a network thread. See comment in Call::GetStats().
570 // RTC_DCHECK_RUN_ON(&thread_checker_); 589 // RTC_DCHECK_RUN_ON(&thread_checker_);
571 return stats_proxy_.GetStats(); 590 return stats_proxy_.GetStats();
572 } 591 }
573 592
574 void VideoSendStream::SignalNetworkState(NetworkState state) { 593 void VideoSendStream::SignalNetworkState(NetworkState state) {
(...skipping 25 matching lines...) Expand all
600 SendStatisticsProxy* stats_proxy, 619 SendStatisticsProxy* stats_proxy,
601 rtc::TaskQueue* worker_queue, 620 rtc::TaskQueue* worker_queue,
602 CallStats* call_stats, 621 CallStats* call_stats,
603 CongestionController* congestion_controller, 622 CongestionController* congestion_controller,
604 BitrateAllocator* bitrate_allocator, 623 BitrateAllocator* bitrate_allocator,
605 SendDelayStats* send_delay_stats, 624 SendDelayStats* send_delay_stats,
606 VieRemb* remb, 625 VieRemb* remb,
607 ViEEncoder* vie_encoder, 626 ViEEncoder* vie_encoder,
608 RtcEventLog* event_log, 627 RtcEventLog* event_log,
609 const VideoSendStream::Config* config, 628 const VideoSendStream::Config* config,
629 int initial_encoder_max_bitrate,
610 std::map<uint32_t, RtpState> suspended_ssrcs) 630 std::map<uint32_t, RtpState> suspended_ssrcs)
611 : stats_proxy_(stats_proxy), 631 : stats_proxy_(stats_proxy),
612 config_(config), 632 config_(config),
613 suspended_ssrcs_(std::move(suspended_ssrcs)), 633 suspended_ssrcs_(std::move(suspended_ssrcs)),
614 module_process_thread_(nullptr), 634 module_process_thread_(nullptr),
615 worker_queue_(worker_queue), 635 worker_queue_(worker_queue),
616 check_encoder_activity_task_(nullptr), 636 check_encoder_activity_task_(nullptr),
617 call_stats_(call_stats), 637 call_stats_(call_stats),
618 congestion_controller_(congestion_controller), 638 congestion_controller_(congestion_controller),
619 bitrate_allocator_(bitrate_allocator), 639 bitrate_allocator_(bitrate_allocator),
620 remb_(remb), 640 remb_(remb),
621 max_padding_bitrate_(0), 641 max_padding_bitrate_(0),
622 encoder_min_bitrate_bps_(0), 642 encoder_min_bitrate_bps_(0),
623 encoder_max_bitrate_bps_(0), 643 encoder_max_bitrate_bps_(initial_encoder_max_bitrate),
624 encoder_target_rate_bps_(0), 644 encoder_target_rate_bps_(0),
625 vie_encoder_(vie_encoder), 645 vie_encoder_(vie_encoder),
626 encoder_feedback_(Clock::GetRealTimeClock(), 646 encoder_feedback_(Clock::GetRealTimeClock(),
627 config_->rtp.ssrcs, 647 config_->rtp.ssrcs,
628 vie_encoder), 648 vie_encoder),
629 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this), 649 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this),
630 bandwidth_observer_(congestion_controller_->GetBitrateController() 650 bandwidth_observer_(congestion_controller_->GetBitrateController()
631 ->CreateRtcpBandwidthObserver()), 651 ->CreateRtcpBandwidthObserver()),
632 rtp_rtcp_modules_(CreateRtpRtcpModules( 652 rtp_rtcp_modules_(CreateRtpRtcpModules(
633 config_->send_transport, 653 config_->send_transport,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 814 }
795 815
796 void VideoSendStreamImpl::SignalEncoderActive() { 816 void VideoSendStreamImpl::SignalEncoderActive() {
797 RTC_DCHECK_RUN_ON(worker_queue_); 817 RTC_DCHECK_RUN_ON(worker_queue_);
798 LOG(LS_INFO) << "SignalEncoderActive, Encoder is active."; 818 LOG(LS_INFO) << "SignalEncoderActive, Encoder is active.";
799 bitrate_allocator_->AddObserver( 819 bitrate_allocator_->AddObserver(
800 this, encoder_min_bitrate_bps_, encoder_max_bitrate_bps_, 820 this, encoder_min_bitrate_bps_, encoder_max_bitrate_bps_,
801 max_padding_bitrate_, !config_->suspend_below_min_bitrate); 821 max_padding_bitrate_, !config_->suspend_below_min_bitrate);
802 } 822 }
803 823
804 void VideoSendStreamImpl::SignalEncoderConfigurationChanged( 824 void VideoSendStreamImpl::OnEncoderConfigurationChanged(
805 const VideoEncoderConfig& config) { 825 std::vector<VideoStream> streams,
806 RTC_DCHECK_GE(config_->rtp.ssrcs.size(), config.streams.size()); 826 int min_transmit_bitrate_bps) {
807 TRACE_EVENT0("webrtc", "VideoSendStream::SignalEncoderConfigurationChanged"); 827 if (!worker_queue_->IsCurrent()) {
808 LOG(LS_INFO) << "SignalEncoderConfigurationChanged: " << config.ToString(); 828 // TODO(perkj): Using |this| in post is safe for now since destruction of
809 RTC_DCHECK_GE(config_->rtp.ssrcs.size(), config.streams.size()); 829 // VideoSendStreamImpl is synchronized in
830 // VideoSendStream::StopPermanentlyAndGetRtpStates. But we should really
831 // use some kind of weak_ptr to guarantee that VideoSendStreamImpl is still
832 // alive when this task runs.
833 worker_queue_->PostTask(
834 std::unique_ptr<rtc::QueuedTask>(new EncoderReconfiguredTask(
835 this, std::move(streams), min_transmit_bitrate_bps)));
836 return;
837 }
838 RTC_DCHECK_GE(config_->rtp.ssrcs.size(), streams.size());
839 TRACE_EVENT0("webrtc", "VideoSendStream::OnEncoderConfigurationChanged");
840 RTC_DCHECK_GE(config_->rtp.ssrcs.size(), streams.size());
810 RTC_DCHECK_RUN_ON(worker_queue_); 841 RTC_DCHECK_RUN_ON(worker_queue_);
811 842
812 const int kEncoderMinBitrateBps = 30000; 843 const int kEncoderMinBitrateBps = 30000;
813 encoder_min_bitrate_bps_ = 844 encoder_min_bitrate_bps_ =
814 std::max(config.streams[0].min_bitrate_bps, kEncoderMinBitrateBps); 845 std::max(streams[0].min_bitrate_bps, kEncoderMinBitrateBps);
815 encoder_max_bitrate_bps_ = 0; 846 encoder_max_bitrate_bps_ = 0;
816 for (const auto& stream : config.streams) 847 for (const auto& stream : streams)
817 encoder_max_bitrate_bps_ += stream.max_bitrate_bps; 848 encoder_max_bitrate_bps_ += stream.max_bitrate_bps;
818 max_padding_bitrate_ = 849 max_padding_bitrate_ = CalculateMaxPadBitrateBps(
819 CalculateMaxPadBitrateBps(config, config_->suspend_below_min_bitrate); 850 streams, min_transmit_bitrate_bps, config_->suspend_below_min_bitrate);
820
821 payload_router_.SetSendStreams(config.streams);
822 851
823 // Clear stats for disabled layers. 852 // Clear stats for disabled layers.
824 for (size_t i = config.streams.size(); i < config_->rtp.ssrcs.size(); ++i) { 853 for (size_t i = streams.size(); i < config_->rtp.ssrcs.size(); ++i) {
825 stats_proxy_->OnInactiveSsrc(config_->rtp.ssrcs[i]); 854 stats_proxy_->OnInactiveSsrc(config_->rtp.ssrcs[i]);
826 } 855 }
827 856
828 size_t number_of_temporal_layers = 857 size_t number_of_temporal_layers =
829 config.streams.back().temporal_layer_thresholds_bps.size() + 1; 858 streams.back().temporal_layer_thresholds_bps.size() + 1;
830 protection_bitrate_calculator_.SetEncodingData( 859 protection_bitrate_calculator_.SetEncodingData(
831 config.streams[0].width, config.streams[0].height, 860 streams[0].width, streams[0].height, number_of_temporal_layers,
832 number_of_temporal_layers, config_->rtp.max_packet_size); 861 config_->rtp.max_packet_size);
833 862
834 if (payload_router_.active()) { 863 if (payload_router_.active()) {
835 // The send stream is started already. Update the allocator with new bitrate 864 // The send stream is started already. Update the allocator with new bitrate
836 // limits. 865 // limits.
837 bitrate_allocator_->AddObserver( 866 bitrate_allocator_->AddObserver(
838 this, encoder_min_bitrate_bps_, encoder_max_bitrate_bps_, 867 this, encoder_min_bitrate_bps_, encoder_max_bitrate_bps_,
839 max_padding_bitrate_, !config_->suspend_below_min_bitrate); 868 max_padding_bitrate_, !config_->suspend_below_min_bitrate);
840 } 869 }
841 } 870 }
842 871
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 &module_nack_rate); 1084 &module_nack_rate);
1056 *sent_video_rate_bps += module_video_rate; 1085 *sent_video_rate_bps += module_video_rate;
1057 *sent_nack_rate_bps += module_nack_rate; 1086 *sent_nack_rate_bps += module_nack_rate;
1058 *sent_fec_rate_bps += module_fec_rate; 1087 *sent_fec_rate_bps += module_fec_rate;
1059 } 1088 }
1060 return 0; 1089 return 0;
1061 } 1090 }
1062 1091
1063 } // namespace internal 1092 } // namespace internal
1064 } // namespace webrtc 1093 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/payload_router_unittest.cc ('k') | webrtc/video/vie_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698