|
35 | 35 | #include <winrt/windows.devices.enumeration.h>
|
36 | 36 | #include <winrt/windows.system.profile.h>
|
37 | 37 |
|
| 38 | +#include <mfapi.h> |
| 39 | + |
38 | 40 | using zsLib::String;
|
39 | 41 | using zsLib::Time;
|
40 | 42 | using zsLib::Seconds;
|
@@ -1097,8 +1099,54 @@ namespace webrtc
|
1097 | 1099 |
|
1098 | 1100 | OnFrame(captureFrame, captureFrame.width(), captureFrame.height());
|
1099 | 1101 |
|
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 | + |
1102 | 1150 | subscriptions_.delegate()->onVideoFrameReceived(VideoCapturerPtr(), sample);
|
1103 | 1151 | }
|
1104 | 1152 |
|
|
0 commit comments