| OLD | NEW | 
|     1 /* |     1 /* | 
|     2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |     2  *  Copyright (c) 2014 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   389   return GetSimulcastConfig( |   389   return GetSimulcastConfig( | 
|   390       num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, |   390       num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, | 
|   391       codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); |   391       codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); | 
|   392 } |   392 } | 
|   393  |   393  | 
|   394 std::vector<webrtc::VideoStream> |   394 std::vector<webrtc::VideoStream> | 
|   395 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( |   395 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( | 
|   396     const VideoCodec& codec, |   396     const VideoCodec& codec, | 
|   397     const VideoOptions& options, |   397     const VideoOptions& options, | 
|   398     int max_bitrate_bps, |   398     int max_bitrate_bps, | 
|   399     size_t num_streams) { |   399     size_t num_streams, | 
 |   400     bool encode_from_texture) { | 
|   400   int codec_max_bitrate_kbps; |   401   int codec_max_bitrate_kbps; | 
|   401   if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |   402   if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { | 
|   402     max_bitrate_bps = codec_max_bitrate_kbps * 1000; |   403     max_bitrate_bps = codec_max_bitrate_kbps * 1000; | 
|   403   } |   404   } | 
|   404   if (num_streams != 1) { |   405   if (num_streams != 1) { | 
|   405     return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, |   406     return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, | 
|   406                                        num_streams); |   407                                        num_streams); | 
|   407   } |   408   } | 
|   408  |   409  | 
|   409   // For unset max bitrates set default bitrate for non-simulcast. |   410   // For unset max bitrates set default bitrate for non-simulcast. | 
|   410   if (max_bitrate_bps <= 0) { |   411   if (max_bitrate_bps <= 0) { | 
|   411     max_bitrate_bps = |   412     max_bitrate_bps = | 
|   412         GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000; |   413         GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000; | 
|   413   } |   414   } | 
|   414  |   415  | 
|   415   webrtc::VideoStream stream; |   416   webrtc::VideoStream stream; | 
|   416   stream.width = codec.width; |   417   stream.width = codec.width; | 
|   417   stream.height = codec.height; |   418   stream.height = codec.height; | 
|   418   stream.max_framerate = |   419   stream.max_framerate = | 
|   419       codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; |   420       codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; | 
|   420  |   421  | 
|   421   stream.min_bitrate_bps = kMinVideoBitrate * 1000; |   422   stream.min_bitrate_bps = kMinVideoBitrate * 1000; | 
|   422   stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; |   423   stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; | 
|   423  |   424  | 
|   424   int max_qp = kDefaultQpMax; |   425   int max_qp = kDefaultQpMax; | 
|   425   codec.GetParam(kCodecParamMaxQuantization, &max_qp); |   426   codec.GetParam(kCodecParamMaxQuantization, &max_qp); | 
|   426   stream.max_qp = max_qp; |   427   stream.max_qp = max_qp; | 
 |   428   stream.encode_from_texture = encode_from_texture; | 
|   427   std::vector<webrtc::VideoStream> streams; |   429   std::vector<webrtc::VideoStream> streams; | 
|   428   streams.push_back(stream); |   430   streams.push_back(stream); | 
|   429   return streams; |   431   return streams; | 
|   430 } |   432 } | 
|   431  |   433  | 
|   432 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |   434 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( | 
|   433     const VideoCodec& codec) { |   435     const VideoCodec& codec) { | 
|   434   bool is_screencast = parameters_.options.is_screencast.value_or(false); |   436   bool is_screencast = parameters_.options.is_screencast.value_or(false); | 
|   435   // No automatic resizing when using simulcast or screencast. |   437   // No automatic resizing when using simulcast or screencast. | 
|   436   bool automatic_resize = |   438   bool automatic_resize = | 
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   741   } |   743   } | 
|   742  |   744  | 
|   743   if (!send_codec_ || supported_codecs.front() != *send_codec_) { |   745   if (!send_codec_ || supported_codecs.front() != *send_codec_) { | 
|   744     changed_params->codec = |   746     changed_params->codec = | 
|   745         rtc::Optional<VideoCodecSettings>(supported_codecs.front()); |   747         rtc::Optional<VideoCodecSettings>(supported_codecs.front()); | 
|   746   } |   748   } | 
|   747  |   749  | 
|   748   // Handle RTP header extensions. |   750   // Handle RTP header extensions. | 
|   749   std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( |   751   std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( | 
|   750       params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); |   752       params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); | 
|   751   if (send_rtp_extensions_ != filtered_extensions) { |   753   if (!send_rtp_extensions_ || (*send_rtp_extensions_ != filtered_extensions)) { | 
|   752     changed_params->rtp_header_extensions = |   754     changed_params->rtp_header_extensions = | 
|   753         rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); |   755         rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); | 
|   754   } |   756   } | 
|   755  |   757  | 
|   756   // Handle max bitrate. |   758   // Handle max bitrate. | 
|   757   if (params.max_bandwidth_bps != send_params_.max_bandwidth_bps && |   759   if (params.max_bandwidth_bps != send_params_.max_bandwidth_bps && | 
|   758       params.max_bandwidth_bps >= 0) { |   760       params.max_bandwidth_bps >= 0) { | 
|   759     // 0 uncaps max bitrate (-1). |   761     // 0 uncaps max bitrate (-1). | 
|   760     changed_params->max_bandwidth_bps = rtc::Optional<int>( |   762     changed_params->max_bandwidth_bps = rtc::Optional<int>( | 
|   761         params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps); |   763         params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps); | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|   789     return false; |   791     return false; | 
|   790   } |   792   } | 
|   791  |   793  | 
|   792   if (changed_params.codec) { |   794   if (changed_params.codec) { | 
|   793     const VideoCodecSettings& codec_settings = *changed_params.codec; |   795     const VideoCodecSettings& codec_settings = *changed_params.codec; | 
|   794     send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings); |   796     send_codec_ = rtc::Optional<VideoCodecSettings>(codec_settings); | 
|   795     LOG(LS_INFO) << "Using codec: " << codec_settings.codec.ToString(); |   797     LOG(LS_INFO) << "Using codec: " << codec_settings.codec.ToString(); | 
|   796   } |   798   } | 
|   797  |   799  | 
|   798   if (changed_params.rtp_header_extensions) { |   800   if (changed_params.rtp_header_extensions) { | 
|   799     send_rtp_extensions_ = *changed_params.rtp_header_extensions; |   801     send_rtp_extensions_ = changed_params.rtp_header_extensions; | 
|   800   } |   802   } | 
|   801  |   803  | 
|   802   if (changed_params.codec || changed_params.max_bandwidth_bps) { |   804   if (changed_params.codec || changed_params.max_bandwidth_bps) { | 
|   803     if (send_codec_) { |   805     if (send_codec_) { | 
|   804       // TODO(holmer): Changing the codec parameters shouldn't necessarily mean |   806       // TODO(holmer): Changing the codec parameters shouldn't necessarily mean | 
|   805       // that we change the min/max of bandwidth estimation. Reevaluate this. |   807       // that we change the min/max of bandwidth estimation. Reevaluate this. | 
|   806       bitrate_config_ = GetBitrateConfigForCodec(send_codec_->codec); |   808       bitrate_config_ = GetBitrateConfigForCodec(send_codec_->codec); | 
|   807       if (!changed_params.codec) { |   809       if (!changed_params.codec) { | 
|   808         // If the codec isn't changing, set the start bitrate to -1 which means |   810         // If the codec isn't changing, set the start bitrate to -1 which means | 
|   809         // "unchanged" so that BWE isn't affected. |   811         // "unchanged" so that BWE isn't affected. | 
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1513  |  1515  | 
|  1514 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |  1516 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 
|  1515     webrtc::Call* call, |  1517     webrtc::Call* call, | 
|  1516     const StreamParams& sp, |  1518     const StreamParams& sp, | 
|  1517     const webrtc::VideoSendStream::Config& config, |  1519     const webrtc::VideoSendStream::Config& config, | 
|  1518     const VideoOptions& options, |  1520     const VideoOptions& options, | 
|  1519     WebRtcVideoEncoderFactory* external_encoder_factory, |  1521     WebRtcVideoEncoderFactory* external_encoder_factory, | 
|  1520     bool enable_cpu_overuse_detection, |  1522     bool enable_cpu_overuse_detection, | 
|  1521     int max_bitrate_bps, |  1523     int max_bitrate_bps, | 
|  1522     const rtc::Optional<VideoCodecSettings>& codec_settings, |  1524     const rtc::Optional<VideoCodecSettings>& codec_settings, | 
|  1523     const std::vector<webrtc::RtpExtension>& rtp_extensions, |  1525     const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, | 
|  1524     // TODO(deadbeef): Don't duplicate information between send_params, |  1526     // TODO(deadbeef): Don't duplicate information between send_params, | 
|  1525     // rtp_extensions, options, etc. |  1527     // rtp_extensions, options, etc. | 
|  1526     const VideoSendParameters& send_params) |  1528     const VideoSendParameters& send_params) | 
|  1527     : worker_thread_(rtc::Thread::Current()), |  1529     : worker_thread_(rtc::Thread::Current()), | 
|  1528       ssrcs_(sp.ssrcs), |  1530       ssrcs_(sp.ssrcs), | 
|  1529       ssrc_groups_(sp.ssrc_groups), |  1531       ssrc_groups_(sp.ssrc_groups), | 
|  1530       call_(call), |  1532       call_(call), | 
|  1531       cpu_restricted_counter_(0), |  1533       cpu_restricted_counter_(0), | 
|  1532       number_of_cpu_adapt_changes_(0), |  1534       number_of_cpu_adapt_changes_(0), | 
|  1533       source_(nullptr), |  1535       source_(nullptr), | 
|  1534       external_encoder_factory_(external_encoder_factory), |  1536       external_encoder_factory_(external_encoder_factory), | 
|  1535       stream_(nullptr), |  1537       stream_(nullptr), | 
|  1536       parameters_(config, options, max_bitrate_bps, codec_settings), |  1538       parameters_(config, options, max_bitrate_bps, codec_settings), | 
|  1537       rtp_parameters_(CreateRtpParametersWithOneEncoding()), |  1539       rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 
|  1538       pending_encoder_reconfiguration_(false), |  1540       pending_encoder_reconfiguration_(false), | 
|  1539       allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), |  1541       allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 
|  1540       sending_(false), |  1542       sending_(false), | 
|  1541       last_frame_timestamp_ms_(0) { |  1543       last_frame_timestamp_ms_(0) { | 
|  1542   parameters_.config.rtp.max_packet_size = kVideoMtu; |  1544   parameters_.config.rtp.max_packet_size = kVideoMtu; | 
|  1543   parameters_.conference_mode = send_params.conference_mode; |  1545   parameters_.conference_mode = send_params.conference_mode; | 
|  1544  |  1546  | 
|  1545   sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |  1547   sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 
|  1546   sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |  1548   sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 
|  1547                  ¶meters_.config.rtp.rtx.ssrcs); |  1549                  ¶meters_.config.rtp.rtx.ssrcs); | 
|  1548   parameters_.config.rtp.c_name = sp.cname; |  1550   parameters_.config.rtp.c_name = sp.cname; | 
|  1549   parameters_.config.rtp.extensions = rtp_extensions; |  1551   if (rtp_extensions) { | 
 |  1552     parameters_.config.rtp.extensions = *rtp_extensions; | 
 |  1553   } | 
|  1550   parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size |  1554   parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size | 
|  1551                                          ? webrtc::RtcpMode::kReducedSize |  1555                                          ? webrtc::RtcpMode::kReducedSize | 
|  1552                                          : webrtc::RtcpMode::kCompound; |  1556                                          : webrtc::RtcpMode::kCompound; | 
|  1553   parameters_.config.overuse_callback = |  1557   parameters_.config.overuse_callback = | 
|  1554       enable_cpu_overuse_detection ? this : nullptr; |  1558       enable_cpu_overuse_detection ? this : nullptr; | 
|  1555  |  1559  | 
|  1556   sink_wants_.rotation_applied = !ContainsHeaderExtension( |  1560   sink_wants_.rotation_applied = | 
|  1557       rtp_extensions, webrtc::RtpExtension::kVideoRotationUri); |  1561       rtp_extensions && | 
 |  1562       !ContainsHeaderExtension(*rtp_extensions, | 
 |  1563                                webrtc::RtpExtension::kVideoRotationUri); | 
|  1558  |  1564  | 
|  1559   if (codec_settings) { |  1565   if (codec_settings) { | 
|  1560     SetCodec(*codec_settings); |  1566     SetCodec(*codec_settings); | 
|  1561   } |  1567   } | 
|  1562 } |  1568 } | 
|  1563  |  1569  | 
|  1564 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |  1570 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 
|  1565   DisconnectSource(); |  1571   DisconnectSource(); | 
|  1566   if (stream_ != NULL) { |  1572   if (stream_ != NULL) { | 
|  1567     call_->DestroyVideoSendStream(stream_); |  1573     call_->DestroyVideoSendStream(stream_); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  1586   frame.set_render_time_ms(render_time_ms_); |  1592   frame.set_render_time_ms(render_time_ms_); | 
|  1587   return frame; |  1593   return frame; | 
|  1588 } |  1594 } | 
|  1589  |  1595  | 
|  1590 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( |  1596 void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( | 
|  1591     const VideoFrame& frame) { |  1597     const VideoFrame& frame) { | 
|  1592   TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); |  1598   TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame"); | 
|  1593   webrtc::VideoFrame video_frame(frame.video_frame_buffer(), 0, 0, |  1599   webrtc::VideoFrame video_frame(frame.video_frame_buffer(), 0, 0, | 
|  1594                                  frame.rotation()); |  1600                                  frame.rotation()); | 
|  1595   rtc::CritScope cs(&lock_); |  1601   rtc::CritScope cs(&lock_); | 
 |  1602  | 
 |  1603   last_rotation_ = video_frame.rotation(); | 
 |  1604   last_frame_in_texture_ = | 
 |  1605       video_frame.video_frame_buffer()->native_handle() != NULL; | 
 |  1606   if (video_frame.width() != last_dimensions_.width || | 
 |  1607       video_frame.height() != last_dimensions_.height) { | 
 |  1608     last_dimensions_.width = video_frame.width(); | 
 |  1609     last_dimensions_.height = video_frame.height(); | 
 |  1610     pending_encoder_reconfiguration_ = true; | 
 |  1611     LOG(LS_INFO) << "Caching frame dimensions: " << last_dimensions_.width | 
 |  1612                  << "x" << last_dimensions_.height << ", r=" << last_rotation_ | 
 |  1613                  << ", texture=" << last_frame_in_texture_; | 
 |  1614   } | 
 |  1615  | 
|  1596   if (stream_ == NULL) { |  1616   if (stream_ == NULL) { | 
|  1597     // Frame input before send codecs are configured, dropping frame. |  1617     // Frame input before send codecs are configured, dropping frame. | 
|  1598     return; |  1618     return; | 
|  1599   } |  1619   } | 
|  1600  |  1620  | 
|  1601   int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; |  1621   int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; | 
|  1602  |  1622  | 
|  1603   // frame->GetTimeStamp() is essentially a delta, align to webrtc time |  1623   // frame->GetTimeStamp() is essentially a delta, align to webrtc time | 
|  1604   if (!first_frame_timestamp_ms_) { |  1624   if (!first_frame_timestamp_ms_) { | 
|  1605     first_frame_timestamp_ms_ = |  1625     first_frame_timestamp_ms_ = | 
|  1606         rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); |  1626         rtc::Optional<int64_t>(rtc::TimeMillis() - frame_delta_ms); | 
|  1607   } |  1627   } | 
|  1608  |  1628  | 
|  1609   last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms; |  1629   last_frame_timestamp_ms_ = *first_frame_timestamp_ms_ + frame_delta_ms; | 
|  1610  |  1630  | 
|  1611   video_frame.set_render_time_ms(last_frame_timestamp_ms_); |  1631   video_frame.set_render_time_ms(last_frame_timestamp_ms_); | 
|  1612   // Reconfigure codec if necessary. |  1632  | 
|  1613   SetDimensions(video_frame.width(), video_frame.height()); |  1633   ReconfigureEncoderIfNecessary(); | 
|  1614   last_rotation_ = video_frame.rotation(); |  | 
|  1615  |  1634  | 
|  1616   // Not sending, abort after reconfiguration. Reconfiguration should still |  1635   // Not sending, abort after reconfiguration. Reconfiguration should still | 
|  1617   // occur to permit sending this input as quickly as possible once we start |  1636   // occur to permit sending this input as quickly as possible once we start | 
|  1618   // sending (without having to reconfigure then). |  1637   // sending (without having to reconfigure then). | 
|  1619   if (!sending_) { |  1638   if (!sending_) { | 
|  1620     return; |  1639     return; | 
|  1621   } |  1640   } | 
|  1622  |  1641  | 
|  1623   stream_->Input()->IncomingCapturedFrame(video_frame); |  1642   stream_->Input()->IncomingCapturedFrame(video_frame); | 
|  1624 } |  1643 } | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1751 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |  1770 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( | 
|  1752     AllocatedEncoder* encoder) { |  1771     AllocatedEncoder* encoder) { | 
|  1753   if (encoder->external) { |  1772   if (encoder->external) { | 
|  1754     external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); |  1773     external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); | 
|  1755   } |  1774   } | 
|  1756   delete encoder->encoder; |  1775   delete encoder->encoder; | 
|  1757 } |  1776 } | 
|  1758  |  1777  | 
|  1759 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( |  1778 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( | 
|  1760     const VideoCodecSettings& codec_settings) { |  1779     const VideoCodecSettings& codec_settings) { | 
|  1761   parameters_.encoder_config = |  1780   parameters_.encoder_config = CreateVideoEncoderConfig( | 
|  1762       CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |  1781       last_dimensions_, last_frame_in_texture_, codec_settings.codec); | 
|  1763   RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |  1782   RTC_DCHECK(!parameters_.encoder_config.streams.empty()); | 
|  1764  |  1783  | 
|  1765   AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); |  1784   AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); | 
|  1766   parameters_.config.encoder_settings.encoder = new_encoder.encoder; |  1785   parameters_.config.encoder_settings.encoder = new_encoder.encoder; | 
|  1767   parameters_.config.encoder_settings.full_overuse_time = new_encoder.external; |  1786   parameters_.config.encoder_settings.full_overuse_time = new_encoder.external; | 
|  1768   parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; |  1787   parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; | 
|  1769   parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; |  1788   parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; | 
|  1770   if (new_encoder.external) { |  1789   if (new_encoder.external) { | 
|  1771     webrtc::VideoCodecType type = CodecTypeFromName(codec_settings.codec.name); |  1790     webrtc::VideoCodecType type = CodecTypeFromName(codec_settings.codec.name); | 
|  1772     parameters_.config.encoder_settings.internal_source = |  1791     parameters_.config.encoder_settings.internal_source = | 
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1892   } else { |  1911   } else { | 
|  1893     if (stream_ != nullptr) { |  1912     if (stream_ != nullptr) { | 
|  1894       stream_->Stop(); |  1913       stream_->Stop(); | 
|  1895     } |  1914     } | 
|  1896   } |  1915   } | 
|  1897 } |  1916 } | 
|  1898  |  1917  | 
|  1899 webrtc::VideoEncoderConfig |  1918 webrtc::VideoEncoderConfig | 
|  1900 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |  1919 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 
|  1901     const Dimensions& dimensions, |  1920     const Dimensions& dimensions, | 
 |  1921     bool encode_from_texture, | 
|  1902     const VideoCodec& codec) const { |  1922     const VideoCodec& codec) const { | 
|  1903   webrtc::VideoEncoderConfig encoder_config; |  1923   webrtc::VideoEncoderConfig encoder_config; | 
|  1904   bool is_screencast = parameters_.options.is_screencast.value_or(false); |  1924   bool is_screencast = parameters_.options.is_screencast.value_or(false); | 
|  1905   if (is_screencast) { |  1925   if (is_screencast) { | 
|  1906     encoder_config.min_transmit_bitrate_bps = |  1926     encoder_config.min_transmit_bitrate_bps = | 
|  1907         1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); |  1927         1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); | 
|  1908     encoder_config.content_type = |  1928     encoder_config.content_type = | 
|  1909         webrtc::VideoEncoderConfig::ContentType::kScreen; |  1929         webrtc::VideoEncoderConfig::ContentType::kScreen; | 
|  1910   } else { |  1930   } else { | 
|  1911     encoder_config.min_transmit_bitrate_bps = 0; |  1931     encoder_config.min_transmit_bitrate_bps = 0; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  1931   // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |  1951   // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 
|  1932   // or a screencast, only configure a single stream. |  1952   // or a screencast, only configure a single stream. | 
|  1933   size_t stream_count = parameters_.config.rtp.ssrcs.size(); |  1953   size_t stream_count = parameters_.config.rtp.ssrcs.size(); | 
|  1934   if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { |  1954   if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 
|  1935     stream_count = 1; |  1955     stream_count = 1; | 
|  1936   } |  1956   } | 
|  1937  |  1957  | 
|  1938   int stream_max_bitrate = |  1958   int stream_max_bitrate = | 
|  1939       MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, |  1959       MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, | 
|  1940                   parameters_.max_bitrate_bps); |  1960                   parameters_.max_bitrate_bps); | 
|  1941   encoder_config.streams = CreateVideoStreams( |  1961   encoder_config.streams = | 
|  1942       clamped_codec, parameters_.options, stream_max_bitrate, stream_count); |  1962       CreateVideoStreams(clamped_codec, parameters_.options, stream_max_bitrate, | 
 |  1963                          stream_count, encode_from_texture); | 
|  1943  |  1964  | 
|  1944   // Conference mode screencast uses 2 temporal layers split at 100kbit. |  1965   // Conference mode screencast uses 2 temporal layers split at 100kbit. | 
|  1945   if (parameters_.conference_mode && is_screencast && |  1966   if (parameters_.conference_mode && is_screencast && | 
|  1946       encoder_config.streams.size() == 1) { |  1967       encoder_config.streams.size() == 1) { | 
|  1947     ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |  1968     ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | 
|  1948  |  1969  | 
|  1949     // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked |  1970     // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked | 
|  1950     // on the VideoCodec struct as target and max bitrates, respectively. |  1971     // on the VideoCodec struct as target and max bitrates, respectively. | 
|  1951     // See eg. webrtc::VP8EncoderImpl::SetRates(). |  1972     // See eg. webrtc::VP8EncoderImpl::SetRates(). | 
|  1952     encoder_config.streams[0].target_bitrate_bps = |  1973     encoder_config.streams[0].target_bitrate_bps = | 
|  1953         config.tl0_bitrate_kbps * 1000; |  1974         config.tl0_bitrate_kbps * 1000; | 
|  1954     encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; |  1975     encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; | 
|  1955     encoder_config.streams[0].temporal_layer_thresholds_bps.clear(); |  1976     encoder_config.streams[0].temporal_layer_thresholds_bps.clear(); | 
|  1956     encoder_config.streams[0].temporal_layer_thresholds_bps.push_back( |  1977     encoder_config.streams[0].temporal_layer_thresholds_bps.push_back( | 
|  1957         config.tl0_bitrate_kbps * 1000); |  1978         config.tl0_bitrate_kbps * 1000); | 
|  1958   } |  1979   } | 
|  1959   if (CodecNamesEq(codec.name, kVp9CodecName) && !is_screencast && |  1980   if (CodecNamesEq(codec.name, kVp9CodecName) && !is_screencast && | 
|  1960       encoder_config.streams.size() == 1) { |  1981       encoder_config.streams.size() == 1) { | 
|  1961     encoder_config.streams[0].temporal_layer_thresholds_bps.resize( |  1982     encoder_config.streams[0].temporal_layer_thresholds_bps.resize( | 
|  1962         GetDefaultVp9TemporalLayers() - 1); |  1983         GetDefaultVp9TemporalLayers() - 1); | 
|  1963   } |  1984   } | 
|  1964   return encoder_config; |  1985   return encoder_config; | 
|  1965 } |  1986 } | 
|  1966  |  1987  | 
|  1967 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( |  1988 void WebRtcVideoChannel2::WebRtcVideoSendStream:: | 
|  1968     int width, |  1989     ReconfigureEncoderIfNecessary() { | 
|  1969     int height) { |  1990   if (!pending_encoder_reconfiguration_) { | 
|  1970   if (last_dimensions_.width == width && last_dimensions_.height == height && |  | 
|  1971       !pending_encoder_reconfiguration_) { |  | 
|  1972     // Configured using the same parameters, do not reconfigure. |  1991     // Configured using the same parameters, do not reconfigure. | 
|  1973     return; |  1992     return; | 
|  1974   } |  1993   } | 
|  1975  |  1994  | 
|  1976   last_dimensions_.width = width; |  | 
|  1977   last_dimensions_.height = height; |  | 
|  1978  |  | 
|  1979   RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |  1995   RTC_DCHECK(!parameters_.encoder_config.streams.empty()); | 
|  1980  |  1996  | 
|  1981   RTC_CHECK(parameters_.codec_settings); |  1997   RTC_CHECK(parameters_.codec_settings); | 
|  1982   VideoCodecSettings codec_settings = *parameters_.codec_settings; |  1998   VideoCodecSettings codec_settings = *parameters_.codec_settings; | 
|  1983  |  1999  | 
|  1984   webrtc::VideoEncoderConfig encoder_config = |  2000   webrtc::VideoEncoderConfig encoder_config = CreateVideoEncoderConfig( | 
|  1985       CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |  2001       last_dimensions_, last_frame_in_texture_, codec_settings.codec); | 
|  1986  |  2002  | 
|  1987   encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( |  2003   encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( | 
|  1988       codec_settings.codec); |  2004       codec_settings.codec); | 
|  1989  |  2005  | 
|  1990   stream_->ReconfigureVideoEncoder(encoder_config); |  2006   stream_->ReconfigureVideoEncoder(encoder_config); | 
|  1991  |  2007  | 
|  1992   encoder_config.encoder_specific_settings = NULL; |  2008   encoder_config.encoder_specific_settings = NULL; | 
|  1993   pending_encoder_reconfiguration_ = false; |  2009   pending_encoder_reconfiguration_ = false; | 
|  1994  |  2010  | 
|  1995   parameters_.encoder_config = encoder_config; |  2011   parameters_.encoder_config = encoder_config; | 
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2613         rtx_mapping[video_codecs[i].codec.id] != |  2629         rtx_mapping[video_codecs[i].codec.id] != | 
|  2614             fec_settings.red_payload_type) { |  2630             fec_settings.red_payload_type) { | 
|  2615       video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |  2631       video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 
|  2616     } |  2632     } | 
|  2617   } |  2633   } | 
|  2618  |  2634  | 
|  2619   return video_codecs; |  2635   return video_codecs; | 
|  2620 } |  2636 } | 
|  2621  |  2637  | 
|  2622 }  // namespace cricket |  2638 }  // namespace cricket | 
| OLD | NEW |