Skip to content

Commit 986ec17

Browse files
committed
make a duplicate of the MF sample to send to the connected thread
1 parent df84a07 commit 986ec17

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

windows/wrapper/impl_webrtc_VideoCapturer.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include <winrt/windows.devices.enumeration.h>
3636
#include <winrt/windows.system.profile.h>
3737

38+
#include <mfapi.h>
39+
3840
using zsLib::String;
3941
using zsLib::Time;
4042
using zsLib::Seconds;
@@ -1097,8 +1099,54 @@ namespace webrtc
10971099

10981100
OnFrame(captureFrame, captureFrame.width(), captureFrame.height());
10991101

1100-
wrapper::org::webRtc::MediaSamplePtr sample =
1101-
wrapper::impl::org::webRtc::MediaSample::toWrapper(spMediaSample);
1102+
if (subscriptions_.size() < 1)
1103+
return;
1104+
1105+
winrt::com_ptr<IMFMediaBuffer> spSampleBuffer;
1106+
DWORD cbCurrentLength {};
1107+
DWORD cbMaxLength {};
1108+
1109+
winrt::com_ptr<IMFSample> spSampleCopy;
1110+
winrt::com_ptr<IMFMediaBuffer> spSampleBufferCopy;
1111+
1112+
if (!SUCCEEDED(spMediaSample->GetBufferByIndex(0, spSampleBuffer.put()))) {
1113+
RTC_LOG(LS_ERROR) << "Failed to get MF media buffer by index.";
1114+
return;
1115+
}
1116+
1117+
if (!SUCCEEDED(spSampleBuffer->GetCurrentLength(&cbCurrentLength))) {
1118+
RTC_LOG(LS_ERROR) << "Failed to get MF media buffer length.";
1119+
return;
1120+
}
1121+
1122+
if (!SUCCEEDED(spSampleBuffer->GetMaxLength(&cbMaxLength))) {
1123+
RTC_LOG(LS_ERROR) << "Failed to get MF media buffer length.";
1124+
return;
1125+
}
1126+
1127+
if (!SUCCEEDED(MFCreateMemoryBuffer(cbMaxLength, spSampleBufferCopy.put()))) {
1128+
RTC_LOG(LS_ERROR) << "Failed to create MF media sample buffer.";
1129+
return;
1130+
}
1131+
1132+
if (!SUCCEEDED(spMediaSample->CopyToBuffer(spSampleBufferCopy.get()))) {
1133+
RTC_LOG(LS_ERROR) << "Failed to copy MF media sample buffer from source.";
1134+
return;
1135+
}
1136+
1137+
if (!SUCCEEDED(MFCreateSample(spSampleCopy.put()))) {
1138+
RTC_LOG(LS_ERROR) << "Failed to create MF media sample.";
1139+
return;
1140+
}
1141+
1142+
if (!SUCCEEDED(spSampleCopy->AddBuffer(spSampleBufferCopy.get()))) {
1143+
RTC_LOG(LS_ERROR) << "Failed to add MF media buffer to sample copy.";
1144+
return;
1145+
}
1146+
1147+
wrapper::org::webRtc::MediaSamplePtr sample =
1148+
wrapper::impl::org::webRtc::MediaSample::toWrapper(spSampleCopy);
1149+
11021150
subscriptions_.delegate()->onVideoFrameReceived(VideoCapturerPtr(), sample);
11031151
}
11041152

0 commit comments

Comments
 (0)