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