annotate loader/dshow/allocator.c @ 24182:8d6ad131c010

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