1545
|
1 #include "cmediasample.h"
|
|
2 #include <wine/winerror.h>
|
168
|
3 #include <stdio.h>
|
|
4 #include <string.h>
|
1545
|
5
|
|
6 static long STDCALL CMediaSample_QueryInterface(IUnknown * This,
|
|
7 /* [in] */ IID* iid,
|
|
8 /* [iid_is][out] */ void **ppv)
|
168
|
9 {
|
1545
|
10 Debug printf("CMediaSample_QueryInterface() called\n");
|
|
11 if (!ppv)
|
|
12 return E_INVALIDARG;
|
|
13 if (!memcmp(iid, &IID_IUnknown, 16))
|
168
|
14 {
|
|
15 *ppv=(void*)This;
|
|
16 This->vt->AddRef(This);
|
|
17 return 0;
|
|
18 }
|
1545
|
19 if (!memcmp(iid, &IID_IMediaSample, 16))
|
168
|
20 {
|
|
21 *ppv=(void*)This;
|
|
22 This->vt->AddRef(This);
|
|
23 return 0;
|
|
24 }
|
1545
|
25 return E_NOINTERFACE;
|
168
|
26 }
|
|
27
|
1545
|
28 static long STDCALL CMediaSample_AddRef(IUnknown* This)
|
168
|
29 {
|
1545
|
30 Debug printf("CMediaSample_AddRef() called\n");
|
168
|
31 ((CMediaSample*)This)->refcount++;
|
|
32 return 0;
|
|
33 }
|
1545
|
34
|
|
35 static long STDCALL CMediaSample_Release(IUnknown* This)
|
168
|
36 {
|
1545
|
37 Debug printf("%p: CMediaSample_Release() called, new refcount %d\n",
|
|
38 This, ((CMediaSample*)This)->refcount-1);
|
168
|
39 CMediaSample* parent=(CMediaSample*)This;
|
1545
|
40 if (--((CMediaSample*)This)->refcount==0)
|
|
41 parent->all->vt->ReleaseBuffer((IMemAllocator*)(parent->all),
|
|
42 (IMediaSample*)This);
|
168
|
43 return 0;
|
|
44 }
|
1545
|
45
|
|
46 static HRESULT STDCALL CMediaSample_GetPointer(IMediaSample * This,
|
|
47 /* [out] */ BYTE **ppBuffer)
|
168
|
48 {
|
1545
|
49 Debug printf("%p: CMediaSample_GetPointer() called\n", This);
|
|
50 if (!ppBuffer)
|
|
51 return E_INVALIDARG;
|
168
|
52 *ppBuffer=(BYTE *)((CMediaSample*)This)->block;
|
|
53 return 0;
|
|
54 }
|
|
55
|
1545
|
56 static long STDCALL CMediaSample_GetSize(IMediaSample * This)
|
168
|
57 {
|
1545
|
58 Debug printf("%p: CMediaSample_GetSize() called -> %d\n",
|
|
59 This, ((CMediaSample*)This)->size);
|
168
|
60 return ((CMediaSample*)This)->size;
|
|
61 }
|
|
62
|
1545
|
63 static HRESULT STDCALL CMediaSample_GetTime(IMediaSample * This,
|
|
64 /* [out] */ REFERENCE_TIME *pTimeStart,
|
|
65 /* [out] */ REFERENCE_TIME *pTimeEnd)
|
168
|
66 {
|
1545
|
67 Debug printf("%p: CMediaSample_GetTime() called\n", This);
|
168
|
68 return E_NOTIMPL;
|
|
69 }
|
|
70
|
1545
|
71 static HRESULT STDCALL CMediaSample_SetTime(IMediaSample * This,
|
|
72 /* [in] */ REFERENCE_TIME *pTimeStart,
|
|
73 /* [in] */ REFERENCE_TIME *pTimeEnd)
|
168
|
74 {
|
1545
|
75 Debug printf("%p: CMediaSample_SetTime() called\n", This);
|
168
|
76 return E_NOTIMPL;
|
|
77 }
|
|
78
|
1545
|
79 static HRESULT STDCALL CMediaSample_IsSyncPoint(IMediaSample * This)
|
168
|
80 {
|
1545
|
81 Debug printf("%p: CMediaSample_IsSyncPoint() called\n", This);
|
|
82 if (((CMediaSample*)This)->isSyncPoint)
|
|
83 return 0;
|
168
|
84 return 1;
|
|
85 }
|
|
86
|
1545
|
87 static HRESULT STDCALL CMediaSample_SetSyncPoint(IMediaSample * This,
|
|
88 long bIsSyncPoint)
|
168
|
89 {
|
1545
|
90 Debug printf("%p: CMediaSample_SetSyncPoint() called\n", This);
|
168
|
91 ((CMediaSample*)This)->isSyncPoint=bIsSyncPoint;
|
|
92 return 0;
|
|
93 }
|
|
94
|
1545
|
95 static HRESULT STDCALL CMediaSample_IsPreroll(IMediaSample * This)
|
168
|
96 {
|
1545
|
97 Debug printf("%p: CMediaSample_IsPreroll() called\n", This);
|
|
98
|
|
99 if (((CMediaSample*)This)->isPreroll)
|
168
|
100 return 0;//S_OK
|
1545
|
101
|
|
102 return 1;//S_FALSE
|
168
|
103 }
|
|
104
|
1545
|
105 static HRESULT STDCALL CMediaSample_SetPreroll(IMediaSample * This,
|
|
106 long bIsPreroll)
|
168
|
107 {
|
1545
|
108 Debug printf("%p: CMediaSample_SetPreroll() called\n", This);
|
168
|
109 ((CMediaSample*)This)->isPreroll=bIsPreroll;
|
|
110 return 0;
|
|
111 }
|
|
112
|
1545
|
113 static long STDCALL CMediaSample_GetActualDataLength(IMediaSample * This)
|
168
|
114 {
|
1545
|
115 Debug printf("%p: CMediaSample_GetActualDataLength() called -> %d\n", This, ((CMediaSample*)This)->actual_size);
|
168
|
116 return ((CMediaSample*)This)->actual_size;
|
|
117 }
|
|
118
|
1545
|
119 static HRESULT STDCALL CMediaSample_SetActualDataLength(IMediaSample * This,
|
|
120 long __MIDL_0010)
|
168
|
121 {
|
1545
|
122 Debug printf("%p: CMediaSample_SetActualDataLength(%ld) called\n", This, __MIDL_0010);
|
|
123 if (__MIDL_0010 > ((CMediaSample*)This)->size)
|
168
|
124 {
|
1545
|
125 printf("%p: ERROR: CMediaSample buffer overflow\n", This);
|
168
|
126 }
|
|
127 ((CMediaSample*)This)->actual_size=__MIDL_0010;
|
|
128 return 0;
|
|
129 }
|
|
130
|
1545
|
131 static HRESULT STDCALL CMediaSample_GetMediaType(IMediaSample * This,
|
|
132 AM_MEDIA_TYPE **ppMediaType)
|
168
|
133 {
|
1545
|
134 Debug printf("%p: CMediaSample_GetMediaType() called\n", This);
|
168
|
135 if(!ppMediaType)
|
1545
|
136 return E_INVALIDARG;
|
168
|
137 if(!((CMediaSample*)This)->type_valid)
|
|
138 {
|
|
139 *ppMediaType=0;
|
|
140 return 1;
|
|
141 }
|
|
142 AM_MEDIA_TYPE& t=((CMediaSample*)This)->media_type;
|
|
143 // if(t.pbFormat)CoTaskMemFree(t.pbFormat);
|
|
144 (*ppMediaType)=(AM_MEDIA_TYPE*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
|
|
145 memcpy(*ppMediaType, &t, sizeof(AM_MEDIA_TYPE));
|
|
146 (*ppMediaType)->pbFormat=(char*)CoTaskMemAlloc(t.cbFormat);
|
1545
|
147 memcpy((*ppMediaType)->pbFormat, t.pbFormat, t.cbFormat);
|
168
|
148 // *ppMediaType=0; //media type was not changed
|
1545
|
149 return 0;
|
168
|
150 }
|
|
151
|
1545
|
152 static HRESULT STDCALL CMediaSample_SetMediaType(IMediaSample * This,
|
|
153 AM_MEDIA_TYPE *pMediaType)
|
168
|
154 {
|
1545
|
155 Debug printf("%p: CMediaSample_SetMediaType() called\n", This);
|
|
156 if (!pMediaType)
|
|
157 return E_INVALIDARG;
|
|
158 AM_MEDIA_TYPE& t = ((CMediaSample*)This)->media_type;
|
|
159 if (t.pbFormat)
|
|
160 CoTaskMemFree(t.pbFormat);
|
|
161 t = *pMediaType;
|
|
162 t.pbFormat = (char*)CoTaskMemAlloc(t.cbFormat);
|
|
163 memcpy(t.pbFormat, pMediaType->pbFormat, t.cbFormat);
|
168
|
164 ((CMediaSample*)This)->type_valid=1;
|
1545
|
165
|
168
|
166 return 0;
|
|
167 }
|
|
168
|
1545
|
169 static HRESULT STDCALL CMediaSample_IsDiscontinuity(IMediaSample * This)
|
168
|
170 {
|
1545
|
171 Debug printf("%p: CMediaSample_IsDiscontinuity() called\n", This);
|
168
|
172 return 1;
|
|
173 }
|
|
174
|
1545
|
175 static HRESULT STDCALL CMediaSample_SetDiscontinuity(IMediaSample * This,
|
|
176 long bDiscontinuity)
|
168
|
177 {
|
1545
|
178 Debug printf("%p: CMediaSample_SetDiscontinuity() called\n", This);
|
|
179 return E_NOTIMPL;
|
|
180 }
|
|
181
|
|
182 static HRESULT STDCALL CMediaSample_GetMediaTime(IMediaSample * This,
|
|
183 /* [out] */ LONGLONG *pTimeStart,
|
|
184 /* [out] */ LONGLONG *pTimeEnd)
|
|
185 {
|
|
186 Debug printf("%p: CMediaSample_GetMediaTime() called\n", This);
|
|
187 return E_NOTIMPL;
|
|
188 }
|
|
189
|
|
190 static HRESULT STDCALL CMediaSample_SetMediaTime(IMediaSample * This,
|
|
191 /* [in] */ LONGLONG *pTimeStart,
|
|
192 /* [in] */ LONGLONG *pTimeEnd)
|
|
193 {
|
|
194 Debug printf("%p: CMediaSample_SetMediaTime() called\n", This);
|
168
|
195 return E_NOTIMPL;
|
|
196 }
|
|
197
|
1545
|
198 CMediaSample::CMediaSample(IMemAllocator* allocator, long _size)
|
168
|
199 {
|
1545
|
200 vt = new IMediaSample_vt;
|
|
201
|
|
202 vt->QueryInterface = CMediaSample_QueryInterface;
|
|
203 vt->AddRef = CMediaSample_AddRef;
|
|
204 vt->Release = CMediaSample_Release;
|
|
205 vt->GetPointer = CMediaSample_GetPointer;
|
|
206 vt->GetSize = CMediaSample_GetSize;
|
|
207 vt->GetTime = CMediaSample_GetTime;
|
|
208 vt->SetTime = CMediaSample_SetTime;
|
|
209 vt->IsSyncPoint = CMediaSample_IsSyncPoint;
|
|
210 vt->SetSyncPoint = CMediaSample_SetSyncPoint;
|
|
211 vt->IsPreroll = CMediaSample_IsPreroll;
|
|
212 vt->SetPreroll = CMediaSample_SetPreroll;
|
|
213 vt->GetActualDataLength = CMediaSample_GetActualDataLength;
|
|
214 vt->SetActualDataLength = CMediaSample_SetActualDataLength;
|
|
215 vt->GetMediaType = CMediaSample_GetMediaType;
|
|
216 vt->SetMediaType = CMediaSample_SetMediaType;
|
|
217 vt->IsDiscontinuity = CMediaSample_IsDiscontinuity;
|
|
218 vt->SetDiscontinuity = CMediaSample_SetDiscontinuity;
|
|
219 vt->GetMediaTime = CMediaSample_GetMediaTime;
|
|
220 vt->SetMediaTime = CMediaSample_SetMediaTime;
|
|
221
|
|
222 all = allocator;
|
|
223 size = _size;
|
|
224 refcount = 0;
|
|
225 actual_size = 0;
|
|
226 media_type.pbFormat = 0;
|
|
227 isPreroll = 0;
|
|
228 type_valid = 0;
|
|
229 own_block = new char[size];
|
|
230 block = own_block;
|
|
231 Debug printf("%p: Creating media sample with size %ld, buffer %p\n",
|
|
232 this, _size, block);
|
168
|
233 }
|
|
234
|
1545
|
235 CMediaSample::~CMediaSample()
|
168
|
236 {
|
1545
|
237 Debug printf("%p: CMediaSample::~CMediaSample() called\n", this);
|
|
238 if (!vt)
|
|
239 printf("Second delete of CMediaSample()!!|\n");
|
|
240 delete vt;
|
|
241 delete own_block;
|
|
242 if (media_type.pbFormat)
|
|
243 CoTaskMemFree(media_type.pbFormat);
|
168
|
244 }
|