annotate loader/dshow/cmediasample.c @ 15214:47027be213b2

mention the generic ratecontrol options (lmin,lmax,vqcomp,vratetol)
author lorenm
date Mon, 18 Apr 2005 20:13:43 +0000
parents f5537cc95b02
children 0783dd397f74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15166
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9964
diff changeset
1 /*
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9964
diff changeset
2 * Modified for use with MPlayer, detailed CVS changelog at
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9964
diff changeset
3 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9964
diff changeset
4 * $Id$
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9964
diff changeset
5 */
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9964
diff changeset
6
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
7 #include "cmediasample.h"
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
8 #include "wine/winerror.h"
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
9 #include <stdio.h>
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
10 #include <string.h>
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
11 #include <stdlib.h>
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
12
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
13 /*
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
14 * currently hack to make some extra room for DS Acel codec which
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
15 * seems to overwrite allocated memory - FIXME better later
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
16 * check the buffer allocation
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
17 */
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
18 static const int SAFETY_ACEL = 1024;
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
19
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
20 static long STDCALL CMediaSample_QueryInterface(IUnknown* This,
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
21 /* [in] */ const GUID* iid,
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
22 /* [iid_is][out] */ void **ppv)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
23 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
24 Debug printf("CMediaSample_QueryInterface(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
25 if (!ppv)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
26 return E_INVALIDARG;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
27 if (memcmp(iid, &IID_IUnknown, sizeof(*iid)) == 0)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
28 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
29 *ppv = (void*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
30 ((IMediaSample*) This)->vt->AddRef(This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
31 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
32 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
33 if (memcmp(iid, &IID_IMediaSample, sizeof(*iid)) == 0)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
34 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
35 *ppv = (void*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
36 ((IMediaSample*) This)->vt->AddRef(This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
37 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
38 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
39 return E_NOINTERFACE;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
40 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
41
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
42 static long STDCALL CMediaSample_AddRef(IUnknown* This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
43 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
44 Debug printf("CMediaSample_AddRef(%p) called\n", This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
45 ((CMediaSample*)This)->refcount++;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
46 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
47 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
48
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
49 void CMediaSample_Destroy(CMediaSample* This)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
50 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
51
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
52 Debug printf("CMediaSample_Destroy(%p) called (ref:%d)\n", This, This->refcount);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
53 free(This->vt);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
54 free(This->own_block);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
55 if (This->media_type.pbFormat)
9964
6454a2ba2e33 CoTaskMemAlloc/Free vs malloc/free cleanup
alex
parents: 8292
diff changeset
56 free(This->media_type.pbFormat);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
57 free(This);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
58 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
59
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
60 static long STDCALL CMediaSample_Release(IUnknown* This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
61 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
62 CMediaSample* parent = (CMediaSample*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
63 Debug printf("CMediaSample_Release(%p) called (new ref:%d)\n",
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
64 This, ((CMediaSample*)This)->refcount-1);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
65
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
66 if (--((CMediaSample*) This)->refcount == 0)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
67 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
68 parent->all->vt->ReleaseBuffer((IMemAllocator*)(parent->all),
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
69 (IMediaSample*)This);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
70 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
71 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
72 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
73
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
74 static HRESULT STDCALL CMediaSample_GetPointer(IMediaSample* This,
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
75 /* [out] */ BYTE** ppBuffer)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
76 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
77 Debug printf("CMediaSample_GetPointer(%p) called -> %p, size: %d %d\n", This, ((CMediaSample*) This)->block, ((CMediaSample*)This)->actual_size, ((CMediaSample*)This)->size);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
78 if (!ppBuffer)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
79 return E_INVALIDARG;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
80 *ppBuffer = (BYTE*) ((CMediaSample*) This)->block;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
81 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
82 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
83
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
84 static long STDCALL CMediaSample_GetSize(IMediaSample * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
85 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
86 Debug printf("CMediaSample_GetSize(%p) called -> %d\n", This, ((CMediaSample*) This)->size);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
87 return ((CMediaSample*) This)->size;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
88 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
89
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
90 static HRESULT STDCALL CMediaSample_GetTime(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
91 /* [out] */ REFERENCE_TIME *pTimeStart,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
92 /* [out] */ REFERENCE_TIME *pTimeEnd)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
93 {
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
94 Debug printf("CMediaSample_GetTime(%p) called (UNIMPLEMENTED)\n", This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
95 return E_NOTIMPL;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
96 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
97
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
98 static HRESULT STDCALL CMediaSample_SetTime(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
99 /* [in] */ REFERENCE_TIME *pTimeStart,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
100 /* [in] */ REFERENCE_TIME *pTimeEnd)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
101 {
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
102 Debug printf("CMediaSample_SetTime(%p) called (UNIMPLEMENTED)\n", This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
103 return E_NOTIMPL;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
104 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
105
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
106 static HRESULT STDCALL CMediaSample_IsSyncPoint(IMediaSample * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
107 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
108 Debug printf("CMediaSample_IsSyncPoint(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
109 if (((CMediaSample*)This)->isSyncPoint)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
110 return 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
111 return 1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
112 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
113
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
114 static HRESULT STDCALL CMediaSample_SetSyncPoint(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
115 long bIsSyncPoint)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
116 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
117 Debug printf("CMediaSample_SetSyncPoint(%p) called\n", This);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
118 ((CMediaSample*)This)->isSyncPoint = bIsSyncPoint;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
119 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
120 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
121
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
122 static HRESULT STDCALL CMediaSample_IsPreroll(IMediaSample * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
123 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
124 Debug printf("CMediaSample_IsPreroll(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
125
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
126 if (((CMediaSample*)This)->isPreroll)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
127 return 0;//S_OK
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
128
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
129 return 1;//S_FALSE
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
130 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
131
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
132 static HRESULT STDCALL CMediaSample_SetPreroll(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
133 long bIsPreroll)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
134 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
135 Debug printf("CMediaSample_SetPreroll(%p) called\n", This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
136 ((CMediaSample*)This)->isPreroll=bIsPreroll;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
137 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
138 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
139
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
140 static long STDCALL CMediaSample_GetActualDataLength(IMediaSample* This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
141 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
142 Debug printf("CMediaSample_GetActualDataLength(%p) called -> %d\n", This, ((CMediaSample*)This)->actual_size);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
143 return ((CMediaSample*)This)->actual_size;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
144 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
145
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
146 static HRESULT STDCALL CMediaSample_SetActualDataLength(IMediaSample* This,
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
147 long __MIDL_0010)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
148 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
149 CMediaSample* cms = (CMediaSample*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
150 Debug printf("CMediaSample_SetActualDataLength(%p, %ld) called\n", This, __MIDL_0010);
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
151
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
152 if (__MIDL_0010 > cms->size)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
153 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
154 char* c = cms->own_block;
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
155 Debug printf("CMediaSample - buffer overflow %ld %d %p %p\n",
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
156 __MIDL_0010, ((CMediaSample*)This)->size, cms->own_block, cms->block);
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
157 cms->own_block = (char*) realloc(cms->own_block, (size_t) __MIDL_0010 + SAFETY_ACEL);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
158 if (c == cms->block)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
159 cms->block = cms->own_block;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
160 cms->size = __MIDL_0010;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
161 }
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
162 cms->actual_size = __MIDL_0010;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
163 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
164 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
165
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
166 static HRESULT STDCALL CMediaSample_GetMediaType(IMediaSample* This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
167 AM_MEDIA_TYPE** ppMediaType)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
168 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
169 AM_MEDIA_TYPE* t;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
170 Debug printf("CMediaSample_GetMediaType(%p) called\n", This);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
171 if(!ppMediaType)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
172 return E_INVALIDARG;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
173 if(!((CMediaSample*)This)->type_valid)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
174 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
175 *ppMediaType=0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
176 return 1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
177 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
178
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
179 t = &((CMediaSample*)This)->media_type;
9964
6454a2ba2e33 CoTaskMemAlloc/Free vs malloc/free cleanup
alex
parents: 8292
diff changeset
180 // if(t.pbFormat)free(t.pbFormat);
6454a2ba2e33 CoTaskMemAlloc/Free vs malloc/free cleanup
alex
parents: 8292
diff changeset
181 (*ppMediaType) = (AM_MEDIA_TYPE*)malloc(sizeof(AM_MEDIA_TYPE));
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
182 **ppMediaType = *t;
9964
6454a2ba2e33 CoTaskMemAlloc/Free vs malloc/free cleanup
alex
parents: 8292
diff changeset
183 (*ppMediaType)->pbFormat = (char*)malloc(t->cbFormat);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
184 memcpy((*ppMediaType)->pbFormat, t->pbFormat, t->cbFormat);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
185 // *ppMediaType=0; //media type was not changed
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
186 return 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
187 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
188
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
189 static HRESULT STDCALL CMediaSample_SetMediaType(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
190 AM_MEDIA_TYPE *pMediaType)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
191 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
192 AM_MEDIA_TYPE* t;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
193 Debug printf("CMediaSample_SetMediaType(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
194 if (!pMediaType)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
195 return E_INVALIDARG;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
196 t = &((CMediaSample*)This)->media_type;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
197 if (t->pbFormat)
9964
6454a2ba2e33 CoTaskMemAlloc/Free vs malloc/free cleanup
alex
parents: 8292
diff changeset
198 free(t->pbFormat);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
199 t = pMediaType;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
200 if (t->cbFormat)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
201 {
9964
6454a2ba2e33 CoTaskMemAlloc/Free vs malloc/free cleanup
alex
parents: 8292
diff changeset
202 t->pbFormat = (char*)malloc(t->cbFormat);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
203 memcpy(t->pbFormat, pMediaType->pbFormat, t->cbFormat);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
204 }
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
205 else
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
206 t->pbFormat = 0;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
207 ((CMediaSample*) This)->type_valid=1;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
208
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
209 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
210 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
211
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
212 static HRESULT STDCALL CMediaSample_IsDiscontinuity(IMediaSample * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
213 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
214 Debug printf("CMediaSample_IsDiscontinuity(%p) called\n", This);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
215 return ((CMediaSample*) This)->isDiscontinuity;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
216 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
217
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
218 static HRESULT STDCALL CMediaSample_SetDiscontinuity(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
219 long bDiscontinuity)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
220 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
221 Debug printf("CMediaSample_SetDiscontinuity(%p) called (%ld)\n", This, bDiscontinuity);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
222 ((CMediaSample*) This)->isDiscontinuity = bDiscontinuity;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
223 return 0;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
224 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
225
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
226 static HRESULT STDCALL CMediaSample_GetMediaTime(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
227 /* [out] */ LONGLONG *pTimeStart,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
228 /* [out] */ LONGLONG *pTimeEnd)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
229 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
230 Debug printf("CMediaSample_GetMediaTime(%p) called\n", This);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
231 if (pTimeStart)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
232 *pTimeStart = ((CMediaSample*) This)->time_start;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
233 if (pTimeEnd)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
234 *pTimeEnd = ((CMediaSample*) This)->time_end;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
235 return 0;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
236 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
237
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
238 static HRESULT STDCALL CMediaSample_SetMediaTime(IMediaSample * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
239 /* [in] */ LONGLONG *pTimeStart,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
240 /* [in] */ LONGLONG *pTimeEnd)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
241 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
242 Debug printf("CMediaSample_SetMediaTime(%p) called\n", This);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
243 if (pTimeStart)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
244 ((CMediaSample*) This)->time_start = *pTimeStart;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
245 if (pTimeEnd)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
246 ((CMediaSample*) This)->time_end = *pTimeEnd;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
247 return 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
248 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
249
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
250 // extension for direct memory write or decompressed data
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
251 static void CMediaSample_SetPointer(CMediaSample* This, char* pointer)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
252 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
253 Debug printf("CMediaSample_SetPointer(%p) called -> %p\n", This, pointer);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
254 if (pointer)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
255 This->block = pointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
256 else
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
257 This->block = This->own_block;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
258 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
259
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
260 static void CMediaSample_ResetPointer(CMediaSample* This)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
261 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
262 Debug printf("CMediaSample_ResetPointer(%p) called\n", This);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
263 This->block = This->own_block;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
264 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
265
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
266 CMediaSample* CMediaSampleCreate(IMemAllocator* allocator, int _size)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
267 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
268 CMediaSample* This = (CMediaSample*) malloc(sizeof(CMediaSample));
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
269 if (!This)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
270 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
271
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
272 // some hack here!
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
273 // it looks like Acelp decoder is actually accessing
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
274 // the allocated memory before it sets the new size for it ???
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
275 // -- maybe it's being initialized with wrong parameters
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
276 // anyway this is fixes the problem somehow with some reserves
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
277 //
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
278 // using different trick for now - in DS_Audio modify sample size
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
279 //if (_size < 0x1000)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
280 // _size = (_size + 0xfff) & ~0xfff;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
281
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
282 This->vt = (IMediaSample_vt*) malloc(sizeof(IMediaSample_vt));
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
283 This->own_block = (char*) malloc((size_t)_size + SAFETY_ACEL);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
284 This->media_type.pbFormat = 0;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
285
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
286 if (!This->vt || !This->own_block)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
287 {
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
288 CMediaSample_Destroy(This);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
289 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
290 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
291
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
292 This->vt->QueryInterface = CMediaSample_QueryInterface;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
293 This->vt->AddRef = CMediaSample_AddRef;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
294 This->vt->Release = CMediaSample_Release;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
295 This->vt->GetPointer = CMediaSample_GetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
296 This->vt->GetSize = CMediaSample_GetSize;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
297 This->vt->GetTime = CMediaSample_GetTime;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
298 This->vt->SetTime = CMediaSample_SetTime;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
299 This->vt->IsSyncPoint = CMediaSample_IsSyncPoint;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
300 This->vt->SetSyncPoint = CMediaSample_SetSyncPoint;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
301 This->vt->IsPreroll = CMediaSample_IsPreroll;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
302 This->vt->SetPreroll = CMediaSample_SetPreroll;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
303 This->vt->GetActualDataLength = CMediaSample_GetActualDataLength;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
304 This->vt->SetActualDataLength = CMediaSample_SetActualDataLength;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
305 This->vt->GetMediaType = CMediaSample_GetMediaType;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
306 This->vt->SetMediaType = CMediaSample_SetMediaType;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
307 This->vt->IsDiscontinuity = CMediaSample_IsDiscontinuity;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
308 This->vt->SetDiscontinuity = CMediaSample_SetDiscontinuity;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
309 This->vt->GetMediaTime = CMediaSample_GetMediaTime;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
310 This->vt->SetMediaTime = CMediaSample_SetMediaTime;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
311
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
312 This->all = allocator;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
313 This->size = _size;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
314 This->refcount = 0; // increased by MemAllocator
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
315 This->actual_size = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
316 This->isPreroll = 0;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
317 This->isDiscontinuity = 1;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
318 This->time_start = 0;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
319 This->time_end = 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
320 This->type_valid = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
321 This->block = This->own_block;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
322
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
323 This->SetPointer = CMediaSample_SetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
324 This->ResetPointer = CMediaSample_ResetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
325
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
326 Debug printf("CMediaSample_Create(%p) called - sample size %d, buffer %p\n",
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
327 This, This->size, This->block);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
328
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
329 return This;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
330 }