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

Commit d288e13

Browse files
committed
Integrate libvpx rate controller with MSDK for VP9
1 parent 66bca74 commit d288e13

12 files changed

+523
-90
lines changed

talk/owt/sdk/base/mediautils.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ absl::optional<AV1Profile> StringToAV1Profile(const std::string& str) {
161161
return absl::nullopt;
162162
}
163163

164+
absl::optional<H265ProfileId> StringToH265Profile(const std::string& str) {
165+
const absl::optional<int> i = rtc::StringToNumber<int>(str);
166+
if (!i.has_value())
167+
return absl::nullopt;
168+
// See ISO/IEC-23008-2 section A.3.5. we use the general_profile_idc
169+
// as the profile-id per RFC 7798.
170+
switch (i.value()) {
171+
case 1:
172+
return H265ProfileId::kMain;
173+
case 2:
174+
return H265ProfileId::kMain10;
175+
case 3:
176+
return H265ProfileId::kMainStillPicture;
177+
case 4:
178+
return H265ProfileId::kMainRExt;
179+
#if (MFX_VERSION >= MFX_VERSION_NEXT)
180+
case 5:
181+
return H265ProfileId::kScc;
182+
#endif
183+
default:
184+
return absl::nullopt;
185+
}
186+
return absl::nullopt;
187+
}
188+
164189
absl::optional<AV1Profile> MediaUtils::ParseSdpForAV1Profile(
165190
const webrtc::SdpVideoFormat::Parameters& params) {
166191
const auto profile_it = params.find(kAV1FmtpProfileId);
@@ -170,5 +195,14 @@ absl::optional<AV1Profile> MediaUtils::ParseSdpForAV1Profile(
170195
return StringToAV1Profile(profile_str);
171196
}
172197

198+
absl::optional<H265ProfileId> MediaUtils::ParseSdpForH265Profile(
199+
const webrtc::SdpVideoFormat::Parameters& params) {
200+
const auto profile_it = params.find(kHEVCFmtpProfileId);
201+
if (profile_it == params.end())
202+
return H265ProfileId::kMain;
203+
const std::string& profile_str = profile_it->second;
204+
return StringToH265Profile(profile_str);
205+
}
206+
173207
} // namespace base
174208
} // namespace owt

talk/owt/sdk/base/mediautils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class MediaUtils {
180180
bool& is_idr);
181181
static absl::optional<AV1Profile> ParseSdpForAV1Profile(
182182
const webrtc::SdpVideoFormat::Parameters& params);
183+
static absl::optional<H265ProfileId> ParseSdpForH265Profile(
184+
const webrtc::SdpVideoFormat::Parameters& params);
183185
};
184186
}
185187
}

talk/owt/sdk/base/stream.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#if defined(WEBRTC_WIN)
1919
#include "talk/owt/sdk/base/desktopcapturer.h"
20-
#include "talk/owt/sdk/base/win/videorendererwin.h"
20+
#include "talk/owt/sdk/base/win/videorendererd3d11.h"
2121
#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
2222
#endif
2323
#if defined(WEBRTC_IOS)
@@ -82,6 +82,7 @@ Stream::Stream()
8282
renderer_impl_(nullptr),
8383
audio_renderer_impl_(nullptr),
8484
d3d9_renderer_impl_(nullptr),
85+
d3d11_renderer_impl_(nullptr),
8586
#ifdef OWT_ENABLE_QUIC
8687
source_(AudioSourceInfo::kUnknown,
8788
VideoSourceInfo::kUnknown,
@@ -96,6 +97,7 @@ Stream::Stream(const std::string& id)
9697
renderer_impl_(nullptr),
9798
audio_renderer_impl_(nullptr),
9899
d3d9_renderer_impl_(nullptr),
100+
d3d11_renderer_impl_(nullptr),
99101
#ifdef OWT_ENABLE_QUIC
100102
source_(AudioSourceInfo::kUnknown,
101103
VideoSourceInfo::kUnknown,
@@ -271,11 +273,11 @@ void Stream::AttachVideoRenderer(VideoRenderWindow& render_window) {
271273
<< "There are more than one video tracks, the first one "
272274
"will be attachecd to renderer.";
273275
}
274-
WebrtcVideoRendererD3D9Impl* old_renderer =
275-
d3d9_renderer_impl_ ? d3d9_renderer_impl_ : nullptr;
276-
d3d9_renderer_impl_ =
277-
new WebrtcVideoRendererD3D9Impl(render_window.GetWindowHandle());
278-
video_tracks[0]->AddOrUpdateSink(d3d9_renderer_impl_, rtc::VideoSinkWants());
276+
WebrtcVideoRendererD3D11Impl* old_renderer =
277+
d3d11_renderer_impl_ ? d3d11_renderer_impl_ : nullptr;
278+
d3d11_renderer_impl_ =
279+
new WebrtcVideoRendererD3D11Impl(render_window.GetWindowHandle());
280+
video_tracks[0]->AddOrUpdateSink(d3d11_renderer_impl_, rtc::VideoSinkWants());
279281
if (old_renderer)
280282
delete old_renderer;
281283
RTC_LOG(LS_INFO) << "Attached the stream to a renderer.";
@@ -285,7 +287,7 @@ void Stream::AttachVideoRenderer(VideoRenderWindow& render_window) {
285287
void Stream::DetachVideoRenderer() {
286288
#if defined(WEBRTC_WIN)
287289
if (media_stream_ == nullptr ||
288-
(renderer_impl_ == nullptr && d3d9_renderer_impl_ == nullptr))
290+
(renderer_impl_ == nullptr && d3d11_renderer_impl_ == nullptr))
289291
return;
290292
#elif defined(WEBRTC_LINUX)
291293
if (media_stream_ == nullptr ||
@@ -305,10 +307,10 @@ void Stream::DetachVideoRenderer() {
305307
renderer_impl_ = nullptr;
306308
}
307309
#if defined(WEBRTC_WIN)
308-
if (d3d9_renderer_impl_ != nullptr) {
309-
video_tracks[0]->RemoveSink(d3d9_renderer_impl_);
310-
delete d3d9_renderer_impl_;
311-
d3d9_renderer_impl_ = nullptr;
310+
if (d3d11_renderer_impl_ != nullptr) {
311+
video_tracks[0]->RemoveSink(d3d11_renderer_impl_);
312+
delete d3d11_renderer_impl_;
313+
d3d11_renderer_impl_ = nullptr;
312314
}
313315
#endif
314316
#if defined(WEBRTC_LINUX)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ bool MSDKFactory::LoadDecoderPlugin(uint32_t codec_id,
139139
}
140140
*plugin_id = MFX_PLUGINID_VP8D_HW;
141141
break;
142+
case MFX_CODEC_VP9:
143+
sts = MFXVideoUSER_Load(*session, &MFX_PLUGINID_VP9D_HW, 1);
144+
if (sts != MFX_ERR_NONE) {
145+
return false;
146+
}
147+
*plugin_id = MFX_PLUGINID_VP9D_HW;
148+
break;
142149
default:
143150
break;
144151
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ MSDKVideoDecoder::MSDKVideoDecoder()
4747
m_pInputSurfaces = nullptr;
4848
m_video_param_extracted = false;
4949
m_decBsOffset = 0;
50+
inited = false;
5051
surface_handle.reset(new D3D11ImageHandle());
5152
}
5253

@@ -147,7 +148,8 @@ int32_t MSDKVideoDecoder::InitDecodeOnCodecThread() {
147148
uint32_t codec_id = MFX_CODEC_AVC;
148149

149150
if (inited) {
150-
m_pmfxDEC->Close();
151+
if (m_pmfxDEC)
152+
m_pmfxDEC->Close();
151153
MSDK_SAFE_DELETE_ARRAY(m_pInputSurfaces);
152154

153155
if (m_pMFXAllocator) {
@@ -171,6 +173,10 @@ int32_t MSDKVideoDecoder::InitDecodeOnCodecThread() {
171173
codec_id = MFX_CODEC_AV1;
172174
}
173175

176+
if (!factory->LoadDecoderPlugin(codec_id, m_mfxSession, &m_pluginID)) {
177+
return WEBRTC_VIDEO_CODEC_ERROR;
178+
}
179+
174180
if (!CreateD3D11Device()) {
175181
return WEBRTC_VIDEO_CODEC_ERROR;
176182
}
@@ -194,15 +200,18 @@ int32_t MSDKVideoDecoder::InitDecodeOnCodecThread() {
194200
MSDK_ZERO_MEMORY(m_mfxBS);
195201
m_mfxBS.Data = new mfxU8[MSDK_BS_INIT_SIZE];
196202
m_mfxBS.MaxLength = MSDK_BS_INIT_SIZE;
203+
RTC_LOG(LS_ERROR) << "Creating underlying MSDK decoder.";
197204
m_pmfxDEC.reset(new MFXVideoDECODE(*m_mfxSession));
198205
if (m_pmfxDEC == nullptr) {
199206
return WEBRTC_VIDEO_CODEC_ERROR;
200207
}
201208
}
202209

203210
m_mfxVideoParams.mfx.CodecId = codec_id;
204-
211+
if (codec_id == MFX_CODEC_VP9)
212+
m_mfxVideoParams.mfx.EnableReallocRequest = MFX_CODINGOPTION_ON;
205213
inited = true;
214+
RTC_LOG(LS_ERROR) << "InitDecodeOnCodecThread --";
206215
return WEBRTC_VIDEO_CODEC_OK;
207216
}
208217

@@ -212,16 +221,19 @@ int32_t MSDKVideoDecoder::Decode(
212221
int64_t renderTimeMs) {
213222

214223
mfxStatus sts = MFX_ERR_NONE;
215-
HRESULT hr;
216-
bool device_opened = false;
217224
mfxFrameSurface1 *pOutputSurface = nullptr;
225+
218226
m_mfxVideoParams.IOPattern =
219227
MFX_IOPATTERN_OUT_VIDEO_MEMORY;
220-
m_mfxVideoParams.AsyncDepth = 1;
228+
m_mfxVideoParams.AsyncDepth = 4;
229+
221230
ReadFromInputStream(&m_mfxBS, inputImage.data(), inputImage.size());
222231

223232
dec_header:
224233
if (inited && !m_video_param_extracted) {
234+
if (!m_pmfxDEC.get()) {
235+
RTC_LOG(LS_ERROR) << "MSDK decoder not created.";
236+
}
225237
sts = m_pmfxDEC->DecodeHeader(&m_mfxBS, &m_mfxVideoParams);
226238
if (MFX_ERR_NONE == sts || MFX_WRN_PARTIAL_ACCELERATION == sts) {
227239
mfxU16 nSurfNum = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ std::unique_ptr<webrtc::VideoDecoder> MSDKVideoDecoderFactory::CreateVideoDecode
108108
std::vector<webrtc::SdpVideoFormat> MSDKVideoDecoderFactory::GetSupportedFormats()
109109
const {
110110
std::vector<webrtc::SdpVideoFormat> supported_codecs;
111-
supported_codecs.push_back(webrtc::SdpVideoFormat(cricket::kVp8CodecName));
111+
//supported_codecs.push_back(webrtc::SdpVideoFormat(cricket::kVp8CodecName));
112112
for (const webrtc::SdpVideoFormat& format : webrtc::SupportedVP9Codecs())
113113
supported_codecs.push_back(format);
114114
for (const webrtc::SdpVideoFormat& format : owt::base::CodecUtils::SupportedH264Codecs())

0 commit comments

Comments
 (0)