WebRTC清晰度和流畅度

WebRTC清晰度和流畅度

flyfish

WebRTC提供了4种模式DISABLED,MAINTAIN_FRAMERATE,MAINTAIN_RESOLUTION,BALANCED

cpp 复制代码
// Based on the spec in
// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
// These options are enforced on a best-effort basis. For instance, all of
// these options may suffer some frame drops in order to avoid queuing.
// TODO(sprang): Look into possibility of more strictly enforcing the
// maintain-framerate option.
// TODO(deadbeef): Default to "balanced", as the spec indicates?
enum class DegradationPreference {
  // Don't take any actions based on over-utilization signals. Not part of the
  // web API.
  DISABLED,
  // On over-use, request lower resolution, possibly causing down-scaling.
  MAINTAIN_FRAMERATE,
  // On over-use, request lower frame rate, possibly causing frame drops.
  MAINTAIN_RESOLUTION,
  // Try to strike a "pleasing" balance between frame rate or resolution.
  BALANCED,
};

接口是

cpp 复制代码
  // See https://crbug.com/653531 and https://w3c.github.io/mst-content-hint.
  enum class ContentHint { kNone, kFluid, kDetailed, kText };

根据源码 接口这里不是一一对应的kDetailed和kText是类似的

cpp 复制代码
webrtc::DegradationPreference
WebRtcVideoChannel::WebRtcVideoSendStream::GetDegradationPreference() const {
  // Do not adapt resolution for screen content as this will likely
  // result in blurry and unreadable text.
  // `this` acts like a VideoSource to make sure SinkWants are handled on the
  // correct thread.
  if (!enable_cpu_overuse_detection_) {
    return webrtc::DegradationPreference::DISABLED;
  }

  webrtc::DegradationPreference degradation_preference;
  if (rtp_parameters_.degradation_preference.has_value()) {
    degradation_preference = *rtp_parameters_.degradation_preference;
  } else {
    if (parameters_.options.content_hint ==
        webrtc::VideoTrackInterface::ContentHint::kFluid) {
      degradation_preference =
          webrtc::DegradationPreference::MAINTAIN_FRAMERATE;
    } else if (parameters_.options.is_screencast.value_or(false) ||
               parameters_.options.content_hint ==
                   webrtc::VideoTrackInterface::ContentHint::kDetailed ||
               parameters_.options.content_hint ==
                   webrtc::VideoTrackInterface::ContentHint::kText) {
      degradation_preference =
          webrtc::DegradationPreference::MAINTAIN_RESOLUTION;
    } else if (IsEnabled(call_->trials(), "WebRTC-Video-BalancedDegradation")) {
      // Standard wants balanced by default, but it needs to be tuned first.
      degradation_preference = webrtc::DegradationPreference::BALANCED;
    } else {
      // Keep MAINTAIN_FRAMERATE by default until BALANCED has been tuned for
      // all codecs and launched.
      degradation_preference =
          webrtc::DegradationPreference::MAINTAIN_FRAMERATE;
    }
  }

  return degradation_preference;
}

使用方法

cpp 复制代码
// create a new webrtc stream
{
	std::lock_guard<std::mutex> mlock(m_streamMapMutex);
	std::map<std::string, std::pair<rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>, rtc::scoped_refptr<webrtc::AudioSourceInterface>>>::iterator it = m_stream_map.find(streamLabel);
	if (it != m_stream_map.end())
	{
			std::pair<rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>, rtc::scoped_refptr<webrtc::AudioSourceInterface>> pair = it->second;
			rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> videoSource(pair.first);
			if (!videoSource)
			{
				RTC_LOG(LS_ERROR) << "Cannot create capturer video:" << videourl;
			}
			else
			{
				rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track = m_peer_connection_factory->CreateVideoTrack(streamLabel + "_video", videoSource.get());
									
				if ((video_track) && (!peer_connection->AddTrack(video_track, {streamLabel}).ok()))
				{
					RTC_LOG(LS_ERROR) << "Adding VideoTrack to MediaStream failed";
				}
				else
				{
	
					RTC_LOG(LS_INFO) << "VideoTrack added to PeerConnection";
					ret = true;
				}					
			}

上述代码video_track创建好之后,调用

cpp 复制代码
video_track->set_content_hint(webrtc::VideoTrackInterface::ContentHint::kDetailed);

参考

https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference

https://crbug.com/653531 and https://w3c.github.io/mst-content-hint

相关推荐
Black蜡笔小新24 分钟前
WebRTC嵌入式视频通话SDK:EasyRTC从免插件到轻量级带来的音视频通话技术
音视频·webrtc·sdk·rtc·webp2p
EasyNVR26 分钟前
EasyRTC:开启智能硬件与全平台互动新时代
网络·音视频·webrtc·p2p·智能硬件·视频监控
EasyGBS27 分钟前
从开发到部署:EasyRTC嵌入式视频通话SDK如何简化实时音视频通信的集成与应用
音视频·webrtc·实时音视频·视频监控
EasyNVR13 小时前
智能硬件新时代,EasyRTC开启物联音视频新纪元
运维·服务器·音视频·webrtc·p2p·智能硬件·视频监控
科技小E15 小时前
EasyRTC:智能硬件适配,实现多端音视频互动新突破
网络协议·安全·小程序·音视频·webrtc·p2p·视频监控
EasyNVR3 天前
EasyRTC智能硬件:小体积,大能量,开启音视频互动新体验
前端·安全·音视频·webrtc·sdk·p2p·智能硬件
科技小E4 天前
WebRTC与EasyRTC:开启智能硬件音视频通讯的全新旅程
网络·网络协议·音视频·webrtc·p2p·视频监控
cyw89984 天前
vue3读取webrtc-stream 视频流
webrtc
Likeadust5 天前
WebP2P+自研回音消除:视频通话SDK嵌入式EasyRTC构建高交互性音视频应用
音视频·webrtc·p2p·webp2p
EasyGBS6 天前
EasyRTC嵌入式WebRTC视频通话SDK支持Web浏览器、Linux、ARM、Android、iOS
arm开发·音视频·webrtc·webp2p