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