|
29 | 29 |
|
30 | 30 | using namespace winrt;
|
31 | 31 |
|
32 |
| -template <typename TValueType> |
33 |
| -struct VideoDataVectorView : implements< |
34 |
| - VideoDataVectorView<TValueType>, |
35 |
| - Windows::Foundation::Collections::IVectorView<TValueType>, |
36 |
| - Windows::Foundation::Collections::IIterable<TValueType>>, |
37 |
| - winrt::vector_view_base<VideoDataVectorView<TValueType>, TValueType> |
38 |
| -{ |
39 |
| - VideoDataVectorView( |
40 |
| - const TValueType * const data, |
41 |
| - size_t size |
42 |
| - ) : container_(data, size) |
43 |
| - {} |
44 |
| - |
45 |
| - auto& get_container() const noexcept |
46 |
| - { |
47 |
| - return container_; |
48 |
| - } |
49 |
| - |
50 |
| - auto& get_container() noexcept |
51 |
| - { |
52 |
| - return container_; |
53 |
| - } |
54 |
| - |
55 |
| -private: |
56 |
| - |
57 |
| - struct Container |
58 |
| - { |
59 |
| - Container( |
60 |
| - const TValueType * const data, |
61 |
| - size_t size) : |
62 |
| - first_(data), |
63 |
| - last_(data + size) |
64 |
| - {} |
65 |
| - |
66 |
| - TValueType const* const first_; |
67 |
| - TValueType const* const last_; |
68 |
| - |
69 |
| - auto begin() const noexcept |
70 |
| - { |
71 |
| - return first_; |
72 |
| - } |
73 |
| - |
74 |
| - auto end() const noexcept |
75 |
| - { |
76 |
| - return last_; |
77 |
| - } |
78 |
| - }; |
79 |
| - |
80 |
| - Container container_; |
| 32 | +struct __declspec(uuid("5b0d3235-4dba-4d44-865e-8f1d0e4fd04d")) __declspec(novtable) IMemoryBufferByteAccess : ::IUnknown |
| 33 | +{ |
| 34 | + virtual HRESULT __stdcall GetBuffer(uint8_t** value, uint32_t* capacity) = 0; |
81 | 35 | };
|
82 | 36 |
|
83 |
| -typedef VideoDataVectorView<uint8_t> VideoData8BitVectorView; |
84 |
| -typedef VideoDataVectorView<uint16_t> VideoData16BitVectorView; |
85 |
| - |
86 | 37 | //------------------------------------------------------------------------------
|
87 | 38 | winrt::com_ptr< Org::WebRtc::implementation::VideoData > Org::WebRtc::implementation::VideoData::ToCppWinrtImpl(wrapper::org::webRtc::VideoDataPtr value)
|
88 | 39 | {
|
@@ -228,26 +179,57 @@ bool Org::WebRtc::implementation::VideoData::Is16BitColorSpace()
|
228 | 179 | }
|
229 | 180 |
|
230 | 181 | //------------------------------------------------------------------------------
|
231 |
| -Windows::Foundation::Collections::IVectorView< uint8_t > Org::WebRtc::implementation::VideoData::Data8bit() |
| 182 | +winrt::Windows::Foundation::IMemoryBuffer Org::WebRtc::implementation::VideoData::Data8bit() |
232 | 183 | {
|
233 |
| - if (!native_) { throw hresult_error(E_POINTER); } |
| 184 | + if (!native_) |
| 185 | + return {nullptr}; |
| 186 | + |
| 187 | + Windows::Foundation::MemoryBuffer memBuffer{ static_cast<uint32_t>(sizeof(uint8_t)*native_->get_size()) }; |
| 188 | + |
| 189 | + auto ref = memBuffer.CreateReference(); |
| 190 | + |
| 191 | + auto byteAccess = ref.as<IMemoryBufferByteAccess>(); |
| 192 | + if (!byteAccess) |
| 193 | + return {nullptr}; |
| 194 | + |
| 195 | + uint8_t* dest{}; |
| 196 | + uint32_t destSize {}; |
| 197 | + if (FAILED(byteAccess->GetBuffer(&dest, &destSize))) |
| 198 | + return {nullptr}; |
| 199 | + |
| 200 | + if (destSize != (sizeof(uint8_t)*native_->get_size())) |
| 201 | + return {nullptr}; |
234 | 202 |
|
235 |
| - auto data = native_->get_data8bit(); |
236 |
| - auto size = native_->get_size(); |
| 203 | + memcpy(dest, native_->get_data8bit(), destSize); |
237 | 204 |
|
238 |
| - return winrt::make<VideoData8BitVectorView>(data, size); |
| 205 | + return memBuffer; |
239 | 206 | }
|
240 | 207 |
|
241 | 208 | //------------------------------------------------------------------------------
|
242 |
| -Windows::Foundation::Collections::IVectorView< uint16_t > Org::WebRtc::implementation::VideoData::Data16bit() |
| 209 | +winrt::Windows::Foundation::IMemoryBuffer Org::WebRtc::implementation::VideoData::Data16bit() |
243 | 210 | {
|
244 |
| - if (!native_) { throw hresult_error(E_POINTER); } |
| 211 | + if (!native_) |
| 212 | + return {nullptr}; |
245 | 213 |
|
246 |
| - auto data = native_->get_data16bit(); |
247 |
| - auto size = native_->get_size(); |
| 214 | + Windows::Foundation::MemoryBuffer memBuffer{ static_cast<uint32_t>(sizeof(uint16_t)*native_->get_size()) }; |
248 | 215 |
|
249 |
| - return winrt::make<VideoData16BitVectorView>(data, size); |
250 |
| -} |
| 216 | + auto ref = memBuffer.CreateReference(); |
| 217 | + |
| 218 | + auto byteAccess = ref.as<IMemoryBufferByteAccess>(); |
| 219 | + if (!byteAccess) |
| 220 | + return {nullptr}; |
| 221 | + |
| 222 | + uint8_t* dest{}; |
| 223 | + uint32_t destSize {}; |
| 224 | + if (FAILED(byteAccess->GetBuffer(&dest, &destSize))) |
| 225 | + return {nullptr}; |
251 | 226 |
|
| 227 | + if (destSize != (sizeof(uint16_t)*native_->get_size())) |
| 228 | + return {nullptr}; |
| 229 | + |
| 230 | + memcpy(dest, native_->get_data16bit(), destSize); |
| 231 | + |
| 232 | + return memBuffer; |
| 233 | +} |
252 | 234 |
|
253 | 235 | #endif //ifndef CPPWINRT_USE_GENERATED_ORG_WEBRTC_VIDEODATA
|
0 commit comments