Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit baa7449

Browse files
committed
Add diffsrv for screen sharing.
1 parent 579c3f1 commit baa7449

File tree

8 files changed

+94
-12
lines changed

8 files changed

+94
-12
lines changed

talk/owt/sdk/base/globalconfiguration.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ int GlobalConfiguration::screen_max_ = 0;
3030
int GlobalConfiguration::data_min_ = 0;
3131
int GlobalConfiguration::data_max_ = 0;
3232
bool GlobalConfiguration::pre_decode_dump_enabled_ = false;
33+
bool GlobalConfiguration::post_encode_dump_enabled_ = false;
3334
} // namespace base
3435
}

talk/owt/sdk/base/peerconnectiondependencyfactory.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ void PeerConnectionDependencyFactory::
115115
field_trial_ += "WebRTC-DecoderDataDumpDirectory/./";
116116
}
117117

118+
bool post_encode_dump = GlobalConfiguration::GetPostEncodeDumpEnabled();
119+
if (post_encode_dump) {
120+
field_trial_ += "WebRTC-EncoderDataDumpDirectory/./";
121+
}
122+
118123
// Set H.264 temporal layers. Ideally it should be set via RtpSenderParam
119124
int h264_temporal_layers = GlobalConfiguration::GetH264TemporalLayers();
120125
field_trial_ +=

talk/owt/sdk/base/sdputils.cc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ std::string SdpUtils::SetPreferAudioCodecs(const std::string& original_sdp,
4242
return cur_sdp;
4343
}
4444
std::string SdpUtils::SetPreferVideoCodecs(const std::string& original_sdp,
45-
std::vector<VideoCodec>& codec) {
45+
std::vector<VideoCodec>& codec, bool set_quality) {
4646
std::string cur_sdp(original_sdp);
4747
if (codec.size() == 0)
4848
return cur_sdp;
@@ -56,7 +56,7 @@ std::string SdpUtils::SetPreferVideoCodecs(const std::string& original_sdp,
5656
}
5757
codec_names.push_back(codec_it->second);
5858
}
59-
cur_sdp = SdpUtils::SetPreferCodecs(cur_sdp, codec_names, false);
59+
cur_sdp = SdpUtils::SetPreferCodecs(cur_sdp, codec_names, false, set_quality);
6060
return cur_sdp;
6161
}
6262
std::vector<std::string> SdpUtils::GetCodecValues(const std::string& sdp,
@@ -81,7 +81,7 @@ std::vector<std::string> SdpUtils::GetCodecValues(const std::string& sdp,
8181
// TODO: unify to std::regex impl for Linux builds.
8282
std::string SdpUtils::SetPreferCodecs(const std::string& sdp,
8383
std::vector<std::string>& codec_names,
84-
bool is_audio) {
84+
bool is_audio, bool set_quality) {
8585
// Search all rtx maps in the sdp.
8686
std::regex reg_fmtp_apt(
8787
"a=fmtp:(\\d+) apt=(\\d+)(?=[\r]?[\n]?)",
@@ -193,9 +193,28 @@ std::string SdpUtils::SetPreferCodecs(const std::string& sdp,
193193
for (auto& codec_value : kept_codec_values) {
194194
m_line_stream << " " << codec_value;
195195
}
196+
196197
RTC_LOG(LS_INFO) << "New m-line: " << m_line_stream.str();
197198
std::string before_strip = std::regex_replace(sdp, reg_m_line, m_line_stream.str());
198199
std::string after_strip = before_strip;
200+
201+
if (!is_audio && set_quality) {
202+
// Search for c-line and add a=priority line after it.
203+
std::regex reg_c_line("c=IN .*\\r\\n");
204+
std::smatch c_line_match;
205+
auto cline_search_result =
206+
std::regex_search(after_strip, c_line_match, reg_c_line);
207+
if (!cline_search_result || c_line_match.size() == 0) {
208+
RTC_LOG(LS_WARNING) << "c-line is not found. SDP: " << sdp;
209+
return sdp;
210+
}
211+
std::string c_line(c_line_match[0]);
212+
std::stringstream c_line_stream(c_line);
213+
std::string new_cline = c_line_stream.str() + "a=quality:10\r\n";
214+
215+
after_strip = std::regex_replace(before_strip, reg_c_line, new_cline);
216+
before_strip = after_strip;
217+
}
199218
// Remove all a=fmtp:xx, a=rtpmap:xx and a=rtcp-fb:xx where xx is not in m-line,
200219
// this includes the a=fmtp:xx apt:yy lines for rtx.
201220
for (size_t i = 3, m_line_vector_size = m_line_vector.size(); i < m_line_vector_size; i++) {

talk/owt/sdk/base/sdputils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SdpUtils {
1414
static std::string SetPreferAudioCodecs(const std::string& sdp,
1515
std::vector<AudioCodec>& codec);
1616
static std::string SetPreferVideoCodecs(const std::string& sdp,
17-
std::vector<VideoCodec>& codec);
17+
std::vector<VideoCodec>& codec, bool set_quality = false);
1818
private:
1919
/**
2020
@brief Replace SDP for preferred codec.
@@ -24,7 +24,7 @@ class SdpUtils {
2424
*/
2525
static std::string SetPreferCodecs(const std::string& sdp,
2626
std::vector<std::string>& codec_name,
27-
bool is_audio);
27+
bool is_audio, bool set_quality = false);
2828
static std::vector<std::string> GetCodecValues(const std::string& sdp,
2929
std::string& codec_name,
3030
bool is_audio);

talk/owt/sdk/base/win/msdkvideoencoder.cc

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66
#include <vector>
77
#include "libyuv/convert_from.h"
88
#include "mfxcommon.h"
9+
#include "absl/algorithm/container.h"
910
#include "talk/owt/sdk/base/mediautils.h"
1011
#include "talk/owt/sdk/base/win/d3d_allocator.h"
1112
#include "talk/owt/sdk/base/win/msdkvideobase.h"
1213
#include "talk/owt/sdk/base/win/msdkvideoencoder.h"
1314
#include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h"
14-
#include "webrtc/rtc_base/bind.h"
15-
#include "webrtc/rtc_base/checks.h"
16-
#include "webrtc/rtc_base/logging.h"
17-
#include "webrtc/rtc_base/thread.h"
18-
#include "webrtc/media/base/vp9_profile.h"
1915
#include "webrtc/common_video/h264/h264_common.h"
2016
#ifndef DISABLE_H265
2117
#include "webrtc/common_video/h265/h265_common.h"
2218
#endif
19+
#include "webrtc/media/base/vp9_profile.h"
20+
#include "webrtc/rtc_base/bind.h"
21+
#include "webrtc/rtc_base/checks.h"
22+
#include "webrtc/rtc_base/system/file_wrapper.h"
23+
#include "webrtc/rtc_base/logging.h"
24+
#include "webrtc/rtc_base/thread.h"
25+
#include "webrtc/system_wrappers/include/field_trial.h"
2326
#include "vp9/ratectrl_rtc.h"
2427

2528
using namespace rtc;
@@ -95,6 +98,26 @@ MSDKVideoEncoder::MSDKVideoEncoder(const cricket::VideoCodec& format)
9598
gof.SetGofInfoVP9(webrtc::TemporalStructureMode::kTemporalStructureMode1);
9699
gof_idx = 0;
97100
rtp_codec_parameters = format;
101+
102+
encoder_dump_file_name =
103+
webrtc::field_trial::FindFullName("WebRTC-EncoderDataDumpDirectory");
104+
// Because '/' can't be used inside a field trial parameter, we use ';'
105+
// instead.
106+
// This is only relevant to WebRTC-EncoderDataDumpDirectory
107+
// field trial. ';' is chosen arbitrary. Even though it's a legal character
108+
// in some file systems, we can sacrifice ability to use it in the path to
109+
// dumped video, since it's developers-only feature for debugging.
110+
absl::c_replace(encoder_dump_file_name, ';', '/');
111+
if (!encoder_dump_file_name.empty()) {
112+
enable_bitstream_dump = true;
113+
char filename_buffer[256];
114+
rtc::SimpleStringBuilder ssb(filename_buffer);
115+
ssb << encoder_dump_file_name << "/webrtc_send_stream_"
116+
<< rtc::TimeMicros() << ".ivf";
117+
dump_writer =
118+
webrtc::IvfFileWriter::Wrap(webrtc::FileWrapper::OpenWriteOnly(
119+
ssb.str()), /* byte_limit= */ 100000000);
120+
}
98121
}
99122

100123
MSDKVideoEncoder::~MSDKVideoEncoder() {
@@ -400,7 +423,7 @@ int MSDKVideoEncoder::InitEncodeOnEncoderThread(
400423
vp9_rate_ctrl = VP9RateControl::Create(vp9_rc_config);
401424
memset(&frame_params, 0, sizeof(frame_params));
402425

403-
// MSDK is using ExtAvcTemporalLayers for HEVC as well. This should be fixed.
426+
// TODO: MSDK is using ExtAvcTemporalLayers for HEVC as well. This should be fixed.
404427
if ((codec_id == MFX_CODEC_AVC || codec_id == MFX_CODEC_HEVC) && num_temporal_layers > 1) {
405428
mfxExtAvcTemporalLayers extAvcTemporalLayers;
406429
MSDK_ZERO_MEMORY(extAvcTemporalLayers);
@@ -823,6 +846,11 @@ int MSDKVideoEncoder::Encode(
823846
bs.DataOffset = 0;
824847
return WEBRTC_VIDEO_CODEC_ERROR;
825848
}
849+
850+
if (enable_bitstream_dump && dump_writer.get()) {
851+
dump_writer->WriteFrame(encodedFrame, codec_type);
852+
}
853+
826854
if (pbsData != nullptr) {
827855
delete[] pbsData;
828856
pbsData = nullptr;

talk/owt/sdk/base/win/msdkvideoencoder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mfxvideo++.h"
1515
#include "mfxvideo.h"
1616
#include "sysmem_allocator.h"
17+
#include "modules/video_coding/utility/ivf_file_writer.h"
1718
#include "webrtc/api/video_codecs/video_codec.h"
1819
#include "webrtc/api/video_codecs/video_encoder.h"
1920
#include "webrtc/media/base/codec.h"
@@ -113,6 +114,9 @@ class MSDKVideoEncoder : public webrtc::VideoEncoder {
113114
// Gof related information for VP9 codec specific info.
114115
uint8_t gof_idx;
115116
webrtc::GofInfoVP9 gof;
117+
std::unique_ptr<webrtc::IvfFileWriter> dump_writer;
118+
bool enable_bitstream_dump = false;
119+
std::string encoder_dump_file_name;
116120
};
117121
} // namespace base
118122
} // namespace owt

talk/owt/sdk/conference/conferencepeerconnectionchannel.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,13 @@ void ConferencePeerConnectionChannel::OnCreateSessionDescriptionSuccess(
307307
for (auto& video_enc_param : configuration_.video) {
308308
video_codecs.push_back(video_enc_param.codec.name);
309309
}
310-
sdp_string = SdpUtils::SetPreferVideoCodecs(sdp_string, video_codecs);
310+
bool is_screen = published_stream_.get() ? (published_stream_->Source().video ==
311+
owt::base::VideoSourceInfo::kScreenCast)
312+
: (subscribed_stream_.get()
313+
? (subscribed_stream_->Source().video ==
314+
owt::base::VideoSourceInfo::kScreenCast)
315+
: false);
316+
sdp_string = SdpUtils::SetPreferVideoCodecs(sdp_string, video_codecs, is_screen);
311317
webrtc::SessionDescriptionInterface* new_desc(
312318
webrtc::CreateSessionDescription(desc->type(), sdp_string, nullptr));
313319
peer_connection_->SetLocalDescription(observer, new_desc);

talk/owt/sdk/include/cpp/owt/base/globalconfiguration.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class GlobalConfiguration {
110110
pre_decode_dump_enabled_ = enabled;
111111
}
112112

113+
/**
114+
@brief This function enables stream dump after encoder.
115+
*/
116+
static void SetPostEncodeDumpEnabled(bool enabled) {
117+
post_encode_dump_enabled_ = enabled;
118+
}
113119
/**
114120
@brief This function sets the temporal layers for H.264.
115121
@@ -235,11 +241,24 @@ class GlobalConfiguration {
235241
static int data_min_;
236242
static int data_max_;
237243

244+
/**
245+
@brief This function enables dumping of bitstream before decoding.
246+
*/
238247
static bool GetPreDecodeDumpEnabled() {
239248
return pre_decode_dump_enabled_;
240249
}
241250

242251
static bool pre_decode_dump_enabled_;
252+
253+
/**
254+
@brief This function enables dumping of bitstream after encoding.
255+
*/
256+
static bool GetPostEncodeDumpEnabled() {
257+
return post_encode_dump_enabled_;
258+
}
259+
260+
static bool post_encode_dump_enabled_;
261+
243262
/**
244263
@brief This function gets whether auto echo cancellation is enabled or not.
245264
@return true or false.

0 commit comments

Comments
 (0)