Skip to content

Commit 56f7574

Browse files
committed
VideoData now returns a MemoryBuffer instead of a vector view
1 parent 457dbbe commit 56f7574

File tree

3 files changed

+51
-71
lines changed

3 files changed

+51
-71
lines changed

windows/wrapper/override/cppwinrt/VideoData.cpp

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,60 +29,11 @@
2929

3030
using namespace winrt;
3131

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;
8135
};
8236

83-
typedef VideoDataVectorView<uint8_t> VideoData8BitVectorView;
84-
typedef VideoDataVectorView<uint16_t> VideoData16BitVectorView;
85-
8637
//------------------------------------------------------------------------------
8738
winrt::com_ptr< Org::WebRtc::implementation::VideoData > Org::WebRtc::implementation::VideoData::ToCppWinrtImpl(wrapper::org::webRtc::VideoDataPtr value)
8839
{
@@ -228,26 +179,57 @@ bool Org::WebRtc::implementation::VideoData::Is16BitColorSpace()
228179
}
229180

230181
//------------------------------------------------------------------------------
231-
Windows::Foundation::Collections::IVectorView< uint8_t > Org::WebRtc::implementation::VideoData::Data8bit()
182+
winrt::Windows::Foundation::IMemoryBuffer Org::WebRtc::implementation::VideoData::Data8bit()
232183
{
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};
234202

235-
auto data = native_->get_data8bit();
236-
auto size = native_->get_size();
203+
memcpy(dest, native_->get_data8bit(), destSize);
237204

238-
return winrt::make<VideoData8BitVectorView>(data, size);
205+
return memBuffer;
239206
}
240207

241208
//------------------------------------------------------------------------------
242-
Windows::Foundation::Collections::IVectorView< uint16_t > Org::WebRtc::implementation::VideoData::Data16bit()
209+
winrt::Windows::Foundation::IMemoryBuffer Org::WebRtc::implementation::VideoData::Data16bit()
243210
{
244-
if (!native_) { throw hresult_error(E_POINTER); }
211+
if (!native_)
212+
return {nullptr};
245213

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()) };
248215

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};
251226

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+
}
252234

253235
#endif //ifndef CPPWINRT_USE_GENERATED_ORG_WEBRTC_VIDEODATA

windows/wrapper/override/cppwinrt/VideoData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ namespace winrt {
6565
/// Gets or sets the video 8 bit color space data. <summary>
6666
/// </summary>
6767
/// </summary>
68-
Windows::Foundation::Collections::IVectorView< uint8_t > Data8bit();
68+
Windows::Foundation::IMemoryBuffer Data8bit();
6969
/// <summary>
7070
/// Gets or sets the video 16 bit color space data. <summary>
7171
/// </summary>
7272
/// </summary>
73-
Windows::Foundation::Collections::IVectorView< uint16_t > Data16bit();
73+
Windows::Foundation::IMemoryBuffer Data16bit();
7474

7575
};
7676

windows/wrapper/override/msidl/Org.WebRtc.VideoData.idl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ namespace Org
1818
Boolean Is16BitColorSpace { get; };
1919

2020
/// <summary>
21-
/// Gets or sets the video 8 bit color space data. <summary>
21+
/// Gets or sets the video 8 bit color space data.
2222
/// </summary>
23-
/// </summary>
24-
Windows.Foundation.Collections.IVectorView< UInt8 > Data8bit { get; };
23+
Windows.Foundation.IMemoryBuffer Data8bit { get; };
2524

2625
/// <summary>
27-
/// Gets or sets the video 16 bit color space data. <summary>
28-
/// </summary>
26+
/// Gets or sets the video 16 bit color space data (as 8 bit / 2 byte little endian).
2927
/// </summary>
30-
Windows.Foundation.Collections.IVectorView< UInt16 > Data16bit { get; };
28+
Windows.Foundation.IMemoryBuffer Data16bit { get; };
3129
};
3230

3331
runtimeclass VideoData : [default] IVideoData

0 commit comments

Comments
 (0)