annotate loader/dshow/allocator.c @ 36964:5cac4cf2ef94

Temporarily disable balance start value (skin default). Setting the balance for ac3 audio causes a crash in the filter "format" automatically added by the mixer.
author ib
date Mon, 24 Mar 2014 17:00:26 +0000
parents c121d03db8b9
children
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: 9967
diff changeset
1 /*
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 15166
diff changeset
2 * Modified for use with MPlayer, detailed changelog at
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 15166
diff changeset
3 * http://svn.mplayerhq.hu/mplayer/trunk/
15166
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9967
diff changeset
4 */
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9967
diff changeset
5
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
6 #include "config.h"
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
7 #include "allocator.h"
30170
008338d7679f Drop -Iloader from CPPFLAGS for the loader subdirectory.
diego
parents: 29263
diff changeset
8 #include "loader/com.h"
008338d7679f Drop -Iloader from CPPFLAGS for the loader subdirectory.
diego
parents: 29263
diff changeset
9 #include "loader/wine/winerror.h"
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
10 #include <stdio.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
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
13 static int AllocatorKeeper = 0;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
14
25794
2c8cdb9123b8 Fix a ton of illegal identifiers. Identifiers starting with __ or _ and a
diego
parents: 22304
diff changeset
15 struct avm_list_t
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
16 {
25794
2c8cdb9123b8 Fix a ton of illegal identifiers. Identifiers starting with __ or _ and a
diego
parents: 22304
diff changeset
17 struct avm_list_t* next;
2c8cdb9123b8 Fix a ton of illegal identifiers. Identifiers starting with __ or _ and a
diego
parents: 22304
diff changeset
18 struct avm_list_t* prev;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
19 void* member;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
20 };
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
21
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
22 static inline int avm_list_size(avm_list_t* head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
23 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
24 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
25 int i = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
26 if (it)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
27 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
28 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
29 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
30 i++;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
31 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
32 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
33 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
34 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
35 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
36 return i;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
37 }
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
38
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
39 static inline int avm_list_print(avm_list_t* head)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
40 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
41 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
42 int i = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
43 printf("Head: %p\n", head);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
44 if (it)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
45 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
46 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
47 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
48 i++;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
49 printf("%d: member: %p next: %p prev: %p\n",
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
50 i, it->member, it->next, it->prev);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
51 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
52 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
53 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
54 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
55 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
56 return i;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
57 }
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 static inline avm_list_t* avm_list_add_head(avm_list_t* head, void* member)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
60 {
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30170
diff changeset
61 avm_list_t* n = malloc(sizeof(avm_list_t));
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
62 n->member = member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
63
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
64 if (!head)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
65 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
66 head = n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
67 head->prev = head;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
68 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
69
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
70 n->prev = head->prev;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
71 head->prev = n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
72 n->next = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
73
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
74 return n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
75 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
76
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
77 static inline avm_list_t* avm_list_add_tail(avm_list_t* head, void* member)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
78 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
79 avm_list_t* n = avm_list_add_head(head, member);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
80 return (!head) ? n : head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
81 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
82
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
83 static inline avm_list_t* avm_list_del_head(avm_list_t* head)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
84 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
85 avm_list_t* n = 0;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
86
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
87 if (head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
88 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
89 if (head->next != head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
90 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
91 n = head->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
92 head->prev->next = head->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
93 head->next->prev = head->prev;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
94 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
95 free(head);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
96 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
97 return n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
98 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
99
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
100 static inline avm_list_t* avm_list_find(avm_list_t* head, void* member)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
101 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
102 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
103 if (it)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
104 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
105 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
106 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
107 if (it->member == member)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
108 return it;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
109 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
110 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
111 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
112 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
113 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
114 return NULL;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
115 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
116
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
117 static long MemAllocator_CreateAllocator(GUID* clsid, const GUID* iid, void** ppv)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
118 {
30824
c121d03db8b9 Implement DirectShow filter graph.
sesse
parents: 30702
diff changeset
119 IUnknown* p;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
120 int result;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
121 if (!ppv)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
122 return -1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
123 *ppv = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
124 if (memcmp(clsid, &CLSID_MemoryAllocator, sizeof(GUID)))
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
125 return -1;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
126
30824
c121d03db8b9 Implement DirectShow filter graph.
sesse
parents: 30702
diff changeset
127 p = (IUnknown*) MemAllocatorCreate();
c121d03db8b9 Implement DirectShow filter graph.
sesse
parents: 30702
diff changeset
128 result = p->vt->QueryInterface(p, iid, ppv);
c121d03db8b9 Implement DirectShow filter graph.
sesse
parents: 30702
diff changeset
129 p->vt->Release(p);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
130
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
131 return result;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
132 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
133
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
134 static HRESULT STDCALL MemAllocator_SetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
135 /* [in] */ ALLOCATOR_PROPERTIES *pRequest,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
136 /* [out] */ ALLOCATOR_PROPERTIES *pActual)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
137 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
138 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
139 Debug printf("MemAllocator_SetProperties(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
140 if (!pRequest || !pActual)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
141 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
142 if (pRequest->cBuffers<=0 || pRequest->cbBuffer<=0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
143 return E_FAIL;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
144 if (me->used_list != 0 || me->free_list != 0)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
145 return E_FAIL;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
146
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
147 *pActual = *pRequest;
22304
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
148 /*
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
149 DirectShow DOCS ("Negotiating Allocators" chapter) says that allocator might not
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25849
diff changeset
150 honor the requested properties. Thus, since WMSP audio codecs requests bufer with two
22304
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
151 bytes length for unknown reason, we should correct requested value. Otherwise above
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
152 codec don't want to load.
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
153 */
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
154 if (pActual->cbBuffer == 2)
254733f57707 Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents: 18783
diff changeset
155 pActual->cbBuffer = 10240; //Enough for WMSP codec
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
156
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
157 me->props = *pActual;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
158
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
159 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
160 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
161
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
162 static HRESULT STDCALL MemAllocator_GetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
163 /* [out] */ ALLOCATOR_PROPERTIES *pProps)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
164 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
165 Debug printf("MemAllocator_GetProperties(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
166 if (!pProps)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
167 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
168 if (((MemAllocator*)This)->props.cbBuffer<0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
169 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
170 *pProps=((MemAllocator*)This)->props;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
171
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
172 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
173 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
174
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
175 static HRESULT STDCALL MemAllocator_Commit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
176 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
177 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
178 int i;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
179 Debug printf("MemAllocator_Commit(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
180 if (((MemAllocator*)This)->props.cbBuffer < 0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
181 return E_FAIL;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
182 if (me->used_list || me->free_list)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
183 return E_INVALIDARG;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
184 for (i = 0; i < me->props.cBuffers; i++)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
185 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
186 CMediaSample* sample = CMediaSampleCreate((IMemAllocator*)me,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
187 me->props.cbBuffer);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
188 if (!sample)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
189 return E_OUTOFMEMORY;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
190 //printf("FREEEEEEEEEEEE ADDED %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
191 me->free_list = avm_list_add_tail(me->free_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
192 //avm_list_print(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
193 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
194
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
195 //printf("Added mem %p: lsz: %d %d size: %d\n", me, avm_list_size(me->free_list), me->props.cBuffers, me->props.cbBuffer);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
196 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
197 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
198
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
199 static HRESULT STDCALL MemAllocator_Decommit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
200 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
201 MemAllocator* me=(MemAllocator*)This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
202 Debug printf("MemAllocator_Decommit(%p) called\n", This);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
203 //printf("Deleted mem %p: %d %d\n", me, me->free_list.size(), me->used_list.size());
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
204 while (me->used_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
205 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
206 me->free_list = avm_list_add_tail(me->free_list,
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
207 (CMediaSample*) me->used_list->member);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
208 me->used_list = avm_list_del_head(me->used_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
209 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
210
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
211 while (me->free_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
212 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
213 CMediaSample* sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
214 //printf("****************** Decommiting FREE %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
215 //sample->vt->Release((IUnknown*)sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
216 CMediaSample_Destroy((CMediaSample*)sample);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
217 me->free_list = avm_list_del_head(me->free_list);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
218 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
219
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
220 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
221 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
222
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
223 static HRESULT STDCALL MemAllocator_GetBuffer(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
224 /* [out] */ IMediaSample **ppBuffer,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
225 /* [in] */ REFERENCE_TIME *pStartTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
226 /* [in] */ REFERENCE_TIME *pEndTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
227 /* [in] */ DWORD dwFlags)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
228 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
229 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
230 CMediaSample* sample;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
231 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
232 avm_list_size(me->used_list), avm_list_size(me->free_list));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
233
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
234 if (!me->free_list)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
235 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
236 Debug printf("No samples available\n");
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
237 return E_FAIL;//should block here if no samples are available
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
238 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
239
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
240 sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
241 me->free_list = avm_list_del_head(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
242 me->used_list = avm_list_add_tail(me->used_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
243
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
244 *ppBuffer = (IMediaSample*) sample;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
245 sample->vt->AddRef((IUnknown*) sample);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
246 if (me->new_pointer)
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
247 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
248 if (me->modified_sample)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
249 me->modified_sample->ResetPointer(me->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
250 sample->SetPointer(sample, me->new_pointer);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
251 me->modified_sample = sample;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
252 me->new_pointer = 0;
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
253 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
254 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
255 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
256
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
257 static HRESULT STDCALL MemAllocator_ReleaseBuffer(IMemAllocator* This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
258 /* [in] */ IMediaSample* pBuffer)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
259 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
260 avm_list_t* l;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
261 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
262 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
263 avm_list_size(me->used_list), avm_list_size(me->free_list));
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
264
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
265 l = avm_list_find(me->used_list, pBuffer);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
266 if (l)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
267 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
268 CMediaSample* sample = (CMediaSample*) l->member;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
269 if (me->modified_sample == sample)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
270 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
271 me->modified_sample->ResetPointer(me->modified_sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
272 me->modified_sample = 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
273 }
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
274 me->used_list = avm_list_del_head(me->used_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
275 me->free_list = avm_list_add_head(me->free_list, sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
276 //printf("****************** RELEASED OK %p %p\n", me->used_list, me->free_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
277 return 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
278 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
279 Debug printf("MemAllocator_ReleaseBuffer(%p) releasing unknown buffer!!!! %p\n", This, pBuffer);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
280 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
281 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
282
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
283
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
284 static void MemAllocator_SetPointer(MemAllocator* This, char* pointer)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
285 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
286 This->new_pointer = pointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
287 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
288
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
289 static void MemAllocator_ResetPointer(MemAllocator* This)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
290 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
291 if (This->modified_sample)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
292 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
293 This->modified_sample->ResetPointer(This->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
294 This->modified_sample = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
295 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
296 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
297
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
298 static void MemAllocator_Destroy(MemAllocator* This)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
299 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
300 Debug printf("MemAllocator_Destroy(%p) called (%d, %d)\n", This, This->refcount, AllocatorKeeper);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
301 #ifdef WIN32_LOADER
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
302 if (--AllocatorKeeper == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
303 UnregisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
304 #endif
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
305 free(This->vt);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
306 free(This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
307 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
308
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
309 IMPLEMENT_IUNKNOWN(MemAllocator)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
310
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
311 MemAllocator* MemAllocatorCreate()
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
312 {
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30170
diff changeset
313 MemAllocator* This = malloc(sizeof(MemAllocator));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
314
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
315 if (!This)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
316 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
317
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
318 Debug printf("MemAllocatorCreate() called -> %p\n", This);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
319
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
320 This->refcount = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
321 This->props.cBuffers = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
322 This->props.cbBuffer = 65536; /* :/ */
9503
f47d484d8f28 cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents: 8292
diff changeset
323 This->props.cbAlign = 1;
f47d484d8f28 cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents: 8292
diff changeset
324 This->props.cbPrefix = 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
325
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30170
diff changeset
326 This->vt = malloc(sizeof(IMemAllocator_vt));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
327
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
328 if (!This->vt)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
329 {
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
330 free(This);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
331 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
332 }
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
333
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
334 This->vt->QueryInterface = MemAllocator_QueryInterface;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
335 This->vt->AddRef = MemAllocator_AddRef;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
336 This->vt->Release = MemAllocator_Release;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
337 This->vt->SetProperties = MemAllocator_SetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
338 This->vt->GetProperties = MemAllocator_GetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
339 This->vt->Commit = MemAllocator_Commit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
340 This->vt->Decommit = MemAllocator_Decommit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
341 This->vt->GetBuffer = MemAllocator_GetBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
342 This->vt->ReleaseBuffer = MemAllocator_ReleaseBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
343
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
344 This->SetPointer = MemAllocator_SetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
345 This->ResetPointer = MemAllocator_ResetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
346
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
347 This->modified_sample = 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
348 This->new_pointer = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
349 This->used_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
350 This->free_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
351
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
352 This->interfaces[0]=IID_IUnknown;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
353 This->interfaces[1]=IID_IMemAllocator;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
354
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
355 #ifdef WIN32_LOADER
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
356 if (AllocatorKeeper++ == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
357 RegisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
358 #endif
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
359
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
360 return This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
361 }