annotate loader/dshow/allocator.c @ 16651:6e45efe0e619

General cleanup: do not link -lm multiple times, use for...in loops instead of some if..elif constructs etc.
author reimar
date Mon, 03 Oct 2005 19:36:32 +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: 9967
diff changeset
1 /*
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 9967
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: 9967
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: 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;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
149 //if (pActual->cbBuffer == 2)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
150 // pActual->cbBuffer = 576;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
151
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
152 me->props = *pActual;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
153
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
154 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
155 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
156
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
157 static HRESULT STDCALL MemAllocator_GetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
158 /* [out] */ ALLOCATOR_PROPERTIES *pProps)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
159 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
160 Debug printf("MemAllocator_GetProperties(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
161 if (!pProps)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
162 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
163 if (((MemAllocator*)This)->props.cbBuffer<0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
164 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
165 *pProps=((MemAllocator*)This)->props;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
166
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
167 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
168 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
169
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
170 static HRESULT STDCALL MemAllocator_Commit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
171 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
172 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
173 int i;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
174 Debug printf("MemAllocator_Commit(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
175 if (((MemAllocator*)This)->props.cbBuffer < 0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
176 return E_FAIL;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
177 if (me->used_list || me->free_list)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
178 return E_INVALIDARG;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
179 for (i = 0; i < me->props.cBuffers; i++)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
180 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
181 CMediaSample* sample = CMediaSampleCreate((IMemAllocator*)me,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
182 me->props.cbBuffer);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
183 if (!sample)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
184 return E_OUTOFMEMORY;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
185 //printf("FREEEEEEEEEEEE ADDED %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
186 me->free_list = avm_list_add_tail(me->free_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
187 //avm_list_print(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
188 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
189
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
190 //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
191 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
192 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
193
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
194 static HRESULT STDCALL MemAllocator_Decommit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
195 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
196 MemAllocator* me=(MemAllocator*)This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
197 Debug printf("MemAllocator_Decommit(%p) called\n", This);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
198 //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
199 while (me->used_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
200 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
201 me->free_list = avm_list_add_tail(me->free_list,
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
202 (CMediaSample*) me->used_list->member);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
203 me->used_list = avm_list_del_head(me->used_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
204 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
205
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
206 while (me->free_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
207 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
208 CMediaSample* sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
209 //printf("****************** Decommiting FREE %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
210 //sample->vt->Release((IUnknown*)sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
211 CMediaSample_Destroy((CMediaSample*)sample);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
212 me->free_list = avm_list_del_head(me->free_list);
3056
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
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
215 return 0;
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 MemAllocator_GetBuffer(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
219 /* [out] */ IMediaSample **ppBuffer,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
220 /* [in] */ REFERENCE_TIME *pStartTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
221 /* [in] */ REFERENCE_TIME *pEndTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
222 /* [in] */ DWORD dwFlags)
168
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 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
225 CMediaSample* sample;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
226 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
227 avm_list_size(me->used_list), avm_list_size(me->free_list));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
228
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
229 if (!me->free_list)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
230 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
231 Debug printf("No samples available\n");
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
232 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
233 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
234
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
235 sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
236 me->free_list = avm_list_del_head(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
237 me->used_list = avm_list_add_tail(me->used_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
238
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
239 *ppBuffer = (IMediaSample*) sample;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
240 sample->vt->AddRef((IUnknown*) sample);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
241 if (me->new_pointer)
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
242 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
243 if (me->modified_sample)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
244 me->modified_sample->ResetPointer(me->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
245 sample->SetPointer(sample, me->new_pointer);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
246 me->modified_sample = sample;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
247 me->new_pointer = 0;
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
248 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
249 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
250 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
251
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
252 static HRESULT STDCALL MemAllocator_ReleaseBuffer(IMemAllocator* This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
253 /* [in] */ IMediaSample* pBuffer)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
254 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
255 avm_list_t* l;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
256 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
257 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
258 avm_list_size(me->used_list), avm_list_size(me->free_list));
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
259
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
260 l = avm_list_find(me->used_list, pBuffer);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
261 if (l)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
262 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
263 CMediaSample* sample = (CMediaSample*) l->member;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
264 if (me->modified_sample == sample)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
265 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
266 me->modified_sample->ResetPointer(me->modified_sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
267 me->modified_sample = 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
268 }
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
269 me->used_list = avm_list_del_head(me->used_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
270 me->free_list = avm_list_add_head(me->free_list, sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
271 //printf("****************** RELEASED OK %p %p\n", me->used_list, me->free_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
272 return 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
273 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
274 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
275 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
276 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
277
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 static void MemAllocator_SetPointer(MemAllocator* This, char* pointer)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
280 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
281 This->new_pointer = pointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
282 }
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_ResetPointer(MemAllocator* This)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
285 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
286 if (This->modified_sample)
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 This->modified_sample->ResetPointer(This->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
289 This->modified_sample = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
290 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
291 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
292
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
293 static void MemAllocator_Destroy(MemAllocator* This)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
294 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
295 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
296 #ifdef WIN32_LOADER
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
297 if (--AllocatorKeeper == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
298 UnregisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
299 #endif
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
300 free(This->vt);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
301 free(This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
302 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
303
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
304 IMPLEMENT_IUNKNOWN(MemAllocator)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
305
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
306 MemAllocator* MemAllocatorCreate()
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
307 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
308 MemAllocator* This = (MemAllocator*) malloc(sizeof(MemAllocator));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
309
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
310 if (!This)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
311 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
312
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
313 Debug printf("MemAllocatorCreate() called -> %p\n", This);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
314
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
315 This->refcount = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
316 This->props.cBuffers = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
317 This->props.cbBuffer = 65536; /* :/ */
9503
f47d484d8f28 cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents: 8292
diff changeset
318 This->props.cbAlign = 1;
f47d484d8f28 cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents: 8292
diff changeset
319 This->props.cbPrefix = 0;
3056
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->vt = (IMemAllocator_vt*) malloc(sizeof(IMemAllocator_vt));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
322
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
323 if (!This->vt)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
324 {
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
325 free(This);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
326 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
327 }
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
328
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
329 This->vt->QueryInterface = MemAllocator_QueryInterface;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
330 This->vt->AddRef = MemAllocator_AddRef;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
331 This->vt->Release = MemAllocator_Release;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
332 This->vt->SetProperties = MemAllocator_SetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
333 This->vt->GetProperties = MemAllocator_GetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
334 This->vt->Commit = MemAllocator_Commit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
335 This->vt->Decommit = MemAllocator_Decommit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
336 This->vt->GetBuffer = MemAllocator_GetBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
337 This->vt->ReleaseBuffer = MemAllocator_ReleaseBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
338
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
339 This->SetPointer = MemAllocator_SetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
340 This->ResetPointer = MemAllocator_ResetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
341
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
342 This->modified_sample = 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
343 This->new_pointer = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
344 This->used_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
345 This->free_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
346
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
347 This->interfaces[0]=IID_IUnknown;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
348 This->interfaces[1]=IID_IMemAllocator;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
349
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
350 #ifdef WIN32_LOADER
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
351 if (AllocatorKeeper++ == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
352 RegisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
353 #endif
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
354
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
355 return This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
356 }