 Chromium Code Reviews
 Chromium Code Reviews Issue 1754283002:
  Make ReconfigureVideoEncoder void.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1754283002:
  Make ReconfigureVideoEncoder void.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 } | 281 } | 
| 282 | 282 | 
| 283 RTC_DCHECK(config.encoder_settings.encoder != nullptr); | 283 RTC_DCHECK(config.encoder_settings.encoder != nullptr); | 
| 284 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); | 284 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); | 
| 285 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); | 285 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); | 
| 286 RTC_CHECK_EQ(0, vie_encoder_.RegisterExternalEncoder( | 286 RTC_CHECK_EQ(0, vie_encoder_.RegisterExternalEncoder( | 
| 287 config.encoder_settings.encoder, | 287 config.encoder_settings.encoder, | 
| 288 config.encoder_settings.payload_type, | 288 config.encoder_settings.payload_type, | 
| 289 config.encoder_settings.internal_source)); | 289 config.encoder_settings.internal_source)); | 
| 290 | 290 | 
| 291 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); | 291 ReconfigureVideoEncoder(encoder_config); | 
| 292 | 292 | 
| 293 vie_channel_.RegisterSendSideDelayObserver(&stats_proxy_); | 293 vie_channel_.RegisterSendSideDelayObserver(&stats_proxy_); | 
| 294 | 294 | 
| 295 if (config_.post_encode_callback) | 295 if (config_.post_encode_callback) | 
| 296 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_); | 296 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_); | 
| 297 | 297 | 
| 298 if (config_.suspend_below_min_bitrate) | 298 if (config_.suspend_below_min_bitrate) | 
| 299 vie_encoder_.SuspendBelowMinBitrate(); | 299 vie_encoder_.SuspendBelowMinBitrate(); | 
| 300 | 300 | 
| 301 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 301 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 344 } | 
| 345 | 345 | 
| 346 void VideoSendStream::Stop() { | 346 void VideoSendStream::Stop() { | 
| 347 if (!payload_router_.active()) | 347 if (!payload_router_.active()) | 
| 348 return; | 348 return; | 
| 349 // TODO(pbos): Make sure the encoder stops here. | 349 // TODO(pbos): Make sure the encoder stops here. | 
| 350 payload_router_.set_active(false); | 350 payload_router_.set_active(false); | 
| 351 vie_receiver_->StopReceive(); | 351 vie_receiver_->StopReceive(); | 
| 352 } | 352 } | 
| 353 | 353 | 
| 354 bool VideoSendStream::ReconfigureVideoEncoder( | 354 void VideoSendStream::ReconfigureVideoEncoder( | 
| 355 const VideoEncoderConfig& config) { | 355 const VideoEncoderConfig& config) { | 
| 356 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); | 356 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); | 
| 357 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); | 357 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); | 
| 358 const std::vector<VideoStream>& streams = config.streams; | 358 const std::vector<VideoStream>& streams = config.streams; | 
| 359 static const int kEncoderMinBitrate = 30; | |
| 
stefan-webrtc
2016/03/02 15:56:33
Kbps
 
pbos-webrtc
2016/03/02 15:57:56
Done.
 | |
| 359 RTC_DCHECK(!streams.empty()); | 360 RTC_DCHECK(!streams.empty()); | 
| 360 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size()); | 361 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size()); | 
| 361 | 362 | 
| 362 VideoCodec video_codec; | 363 VideoCodec video_codec; | 
| 363 memset(&video_codec, 0, sizeof(video_codec)); | 364 memset(&video_codec, 0, sizeof(video_codec)); | 
| 364 video_codec.codecType = | 365 video_codec.codecType = | 
| 365 PayloadNameToCodecType(config_.encoder_settings.payload_name); | 366 PayloadNameToCodecType(config_.encoder_settings.payload_name); | 
| 366 | 367 | 
| 367 switch (config.content_type) { | 368 switch (config.content_type) { | 
| 368 case VideoEncoderConfig::ContentType::kRealtimeVideo: | 369 case VideoEncoderConfig::ContentType::kRealtimeVideo: | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 421 } | 
| 421 | 422 | 
| 422 strncpy(video_codec.plName, | 423 strncpy(video_codec.plName, | 
| 423 config_.encoder_settings.payload_name.c_str(), | 424 config_.encoder_settings.payload_name.c_str(), | 
| 424 kPayloadNameSize - 1); | 425 kPayloadNameSize - 1); | 
| 425 video_codec.plName[kPayloadNameSize - 1] = '\0'; | 426 video_codec.plName[kPayloadNameSize - 1] = '\0'; | 
| 426 video_codec.plType = config_.encoder_settings.payload_type; | 427 video_codec.plType = config_.encoder_settings.payload_type; | 
| 427 video_codec.numberOfSimulcastStreams = | 428 video_codec.numberOfSimulcastStreams = | 
| 428 static_cast<unsigned char>(streams.size()); | 429 static_cast<unsigned char>(streams.size()); | 
| 429 video_codec.minBitrate = streams[0].min_bitrate_bps / 1000; | 430 video_codec.minBitrate = streams[0].min_bitrate_bps / 1000; | 
| 431 if (video_codec.minBitrate < kEncoderMinBitrate) | |
| 432 video_codec.minBitrate = kEncoderMinBitrate; | |
| 430 RTC_DCHECK_LE(streams.size(), static_cast<size_t>(kMaxSimulcastStreams)); | 433 RTC_DCHECK_LE(streams.size(), static_cast<size_t>(kMaxSimulcastStreams)); | 
| 431 if (video_codec.codecType == kVideoCodecVP9) { | 434 if (video_codec.codecType == kVideoCodecVP9) { | 
| 432 // If the vector is empty, bitrates will be configured automatically. | 435 // If the vector is empty, bitrates will be configured automatically. | 
| 433 RTC_DCHECK(config.spatial_layers.empty() || | 436 RTC_DCHECK(config.spatial_layers.empty() || | 
| 434 config.spatial_layers.size() == | 437 config.spatial_layers.size() == | 
| 435 video_codec.codecSpecific.VP9.numberOfSpatialLayers); | 438 video_codec.codecSpecific.VP9.numberOfSpatialLayers); | 
| 436 RTC_DCHECK_LE(video_codec.codecSpecific.VP9.numberOfSpatialLayers, | 439 RTC_DCHECK_LE(video_codec.codecSpecific.VP9.numberOfSpatialLayers, | 
| 437 kMaxSimulcastStreams); | 440 kMaxSimulcastStreams); | 
| 438 for (size_t i = 0; i < config.spatial_layers.size(); ++i) | 441 for (size_t i = 0; i < config.spatial_layers.size(); ++i) | 
| 439 video_codec.spatialLayers[i] = config.spatial_layers[i]; | 442 video_codec.spatialLayers[i] = config.spatial_layers[i]; | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 464 video_codec.height = std::max( | 467 video_codec.height = std::max( | 
| 465 video_codec.height, static_cast<uint16_t>(streams[i].height)); | 468 video_codec.height, static_cast<uint16_t>(streams[i].height)); | 
| 466 video_codec.minBitrate = | 469 video_codec.minBitrate = | 
| 467 std::min(static_cast<uint16_t>(video_codec.minBitrate), | 470 std::min(static_cast<uint16_t>(video_codec.minBitrate), | 
| 468 static_cast<uint16_t>(streams[i].min_bitrate_bps / 1000)); | 471 static_cast<uint16_t>(streams[i].min_bitrate_bps / 1000)); | 
| 469 video_codec.maxBitrate += streams[i].max_bitrate_bps / 1000; | 472 video_codec.maxBitrate += streams[i].max_bitrate_bps / 1000; | 
| 470 video_codec.qpMax = std::max(video_codec.qpMax, | 473 video_codec.qpMax = std::max(video_codec.qpMax, | 
| 471 static_cast<unsigned int>(streams[i].max_qp)); | 474 static_cast<unsigned int>(streams[i].max_qp)); | 
| 472 } | 475 } | 
| 473 | 476 | 
| 474 // Set to zero to not update the bitrate controller from ViEEncoder, as | 477 if (video_codec.maxBitrate == 0) { | 
| 475 // the bitrate controller is already set from Call. | 478 // Unset max bitrate -> cap to one bit per pixel. | 
| 476 video_codec.startBitrate = 0; | 479 video_codec.maxBitrate = | 
| 480 (video_codec.width * video_codec.height * video_codec.maxFramerate) / | |
| 481 1000; | |
| 482 } | |
| 483 if (video_codec.maxBitrate < kEncoderMinBitrate) | |
| 484 video_codec.maxBitrate = kEncoderMinBitrate; | |
| 477 | 485 | 
| 478 RTC_DCHECK_GT(streams[0].max_framerate, 0); | 486 RTC_DCHECK_GT(streams[0].max_framerate, 0); | 
| 479 video_codec.maxFramerate = streams[0].max_framerate; | 487 video_codec.maxFramerate = streams[0].max_framerate; | 
| 480 | 488 | 
| 481 if (!SetSendCodec(video_codec)) { | 489 vie_encoder_.SetEncoder(video_codec); | 
| 482 LOG(LS_WARNING) << "(Re)configureVideoEncoder: SetSendCodec failed " | 490 | 
| 483 "for config: " | |
| 484 << config.ToString(); | |
| 485 return false; | |
| 486 } | |
| 487 // Clear stats for disabled layers. | 491 // Clear stats for disabled layers. | 
| 488 for (size_t i = video_codec.numberOfSimulcastStreams; | 492 for (size_t i = video_codec.numberOfSimulcastStreams; | 
| 489 i < config_.rtp.ssrcs.size(); ++i) { | 493 i < config_.rtp.ssrcs.size(); ++i) { | 
| 490 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); | 494 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); | 
| 491 } | 495 } | 
| 492 | 496 | 
| 493 stats_proxy_.SetContentType(config.content_type); | 497 stats_proxy_.SetContentType(config.content_type); | 
| 494 | 498 | 
| 495 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); | 499 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); | 
| 496 vie_encoder_.SetMinTransmitBitrate(config.min_transmit_bitrate_bps / 1000); | 500 vie_encoder_.SetMinTransmitBitrate(config.min_transmit_bitrate_bps / 1000); | 
| 497 | |
| 498 return true; | |
| 499 } | 501 } | 
| 500 | 502 | 
| 501 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 503 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 
| 502 return vie_receiver_->DeliverRtcp(packet, length); | 504 return vie_receiver_->DeliverRtcp(packet, length); | 
| 503 } | 505 } | 
| 504 | 506 | 
| 505 VideoSendStream::Stats VideoSendStream::GetStats() { | 507 VideoSendStream::Stats VideoSendStream::GetStats() { | 
| 506 return stats_proxy_.GetStats(); | 508 return stats_proxy_.GetStats(); | 
| 507 } | 509 } | 
| 508 | 510 | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp); | 588 vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp); | 
| 587 if (state == kNetworkDown) { | 589 if (state == kNetworkDown) { | 
| 588 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 590 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 
| 589 rtp_rtcp->SetRTCPStatus(RtcpMode::kOff); | 591 rtp_rtcp->SetRTCPStatus(RtcpMode::kOff); | 
| 590 } | 592 } | 
| 591 } | 593 } | 
| 592 | 594 | 
| 593 int VideoSendStream::GetPaddingNeededBps() const { | 595 int VideoSendStream::GetPaddingNeededBps() const { | 
| 594 return vie_encoder_.GetPaddingNeededBps(); | 596 return vie_encoder_.GetPaddingNeededBps(); | 
| 595 } | 597 } | 
| 596 | |
| 597 bool VideoSendStream::SetSendCodec(VideoCodec video_codec) { | |
| 598 static const int kEncoderMinBitrate = 30; | |
| 599 if (video_codec.maxBitrate == 0) { | |
| 600 // Unset max bitrate -> cap to one bit per pixel. | |
| 601 video_codec.maxBitrate = | |
| 602 (video_codec.width * video_codec.height * video_codec.maxFramerate) / | |
| 603 1000; | |
| 604 } | |
| 605 | |
| 606 if (video_codec.minBitrate < kEncoderMinBitrate) | |
| 607 video_codec.minBitrate = kEncoderMinBitrate; | |
| 608 if (video_codec.maxBitrate < kEncoderMinBitrate) | |
| 609 video_codec.maxBitrate = kEncoderMinBitrate; | |
| 610 | |
| 611 // Stop the media flow while reconfiguring. | |
| 612 vie_encoder_.Pause(); | |
| 613 | |
| 614 if (vie_encoder_.SetEncoder(video_codec) != 0) { | |
| 615 LOG(LS_ERROR) << "Failed to set encoder."; | |
| 616 return false; | |
| 617 } | |
| 618 | |
| 619 size_t num_streams = video_codec.numberOfSimulcastStreams > 0 | |
| 620 ? video_codec.numberOfSimulcastStreams | |
| 621 : 1; | |
| 622 payload_router_.SetSendingRtpModules(num_streams); | |
| 623 | |
| 624 // Restart the media flow | |
| 625 vie_encoder_.Restart(); | |
| 626 | |
| 627 return true; | |
| 628 } | |
| 629 } // namespace internal | 598 } // namespace internal | 
| 630 } // namespace webrtc | 599 } // namespace webrtc | 
| OLD | NEW |