annotate loader/dshow/allocator.c @ 14911:6a8b15582f64

store local keyframes too so faster seeking is possible
author michael
date Fri, 04 Mar 2005 03:16:40 +0000
parents b0d1b415320c
children f5537cc95b02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
1 #include "config.h"
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
2 #include "allocator.h"
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
3 #include "com.h"
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
4 #include "wine/winerror.h"
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
5 #include <stdio.h>
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
6 #include <stdlib.h>
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
7
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
8 static int AllocatorKeeper = 0;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
9
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
10 struct _avm_list_t
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
11 {
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
12 struct _avm_list_t* next;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
13 struct _avm_list_t* prev;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
14 void* member;
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
15 };
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
16
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
17 static inline int avm_list_size(avm_list_t* head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
18 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
19 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
20 int i = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
21 if (it)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
22 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
23 for (;;)
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 i++;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
26 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
27 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
28 break;
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 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
31 return i;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
32 }
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
33
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
34 static inline int avm_list_print(avm_list_t* head)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
35 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
36 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
37 int i = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
38 printf("Head: %p\n", head);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
39 if (it)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
40 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
41 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
42 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
43 i++;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
44 printf("%d: member: %p next: %p prev: %p\n",
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
45 i, it->member, it->next, it->prev);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
46 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
47 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
48 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
49 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
50 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
51 return i;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
52 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
53
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
54 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
55 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
56 avm_list_t* n = (avm_list_t*) malloc(sizeof(avm_list_t));
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
57 n->member = member;
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 if (!head)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
60 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
61 head = n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
62 head->prev = head;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
63 }
3056
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 n->prev = head->prev;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
66 head->prev = n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
67 n->next = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
68
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
69 return n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
70 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
71
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
72 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
73 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
74 avm_list_t* n = avm_list_add_head(head, member);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
75 return (!head) ? n : head;
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_del_head(avm_list_t* head)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
79 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
80 avm_list_t* n = 0;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
81
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
82 if (head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
83 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
84 if (head->next != head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
85 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
86 n = head->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
87 head->prev->next = head->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
88 head->next->prev = head->prev;
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 free(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 return n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
93 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
94
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
95 static inline avm_list_t* avm_list_find(avm_list_t* head, void* member)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
96 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
97 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
98 if (it)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
99 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
100 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
101 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
102 if (it->member == member)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
103 return it;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
104 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
105 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
106 break;
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 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
109 return NULL;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
110 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
111
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 3467
diff changeset
112 static long MemAllocator_CreateAllocator(GUID* clsid, const GUID* iid, void** ppv)
3056
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 IMemAllocator* p;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
115 int result;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
116 if (!ppv)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
117 return -1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
118 *ppv = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
119 if (memcmp(clsid, &CLSID_MemoryAllocator, sizeof(GUID)))
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
120 return -1;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
121
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
122 p = (IMemAllocator*) MemAllocatorCreate();
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
123 result = p->vt->QueryInterface((IUnknown*)p, iid, ppv);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
124 p->vt->Release((IUnknown*)p);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
125
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
126 return result;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
127 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
128
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
129 static HRESULT STDCALL MemAllocator_SetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
130 /* [in] */ ALLOCATOR_PROPERTIES *pRequest,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
131 /* [out] */ ALLOCATOR_PROPERTIES *pActual)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
132 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
133 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
134 Debug printf("MemAllocator_SetProperties(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
135 if (!pRequest || !pActual)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
136 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
137 if (pRequest->cBuffers<=0 || pRequest->cbBuffer<=0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
138 return E_FAIL;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
139 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
140 return E_FAIL;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
141
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
142 *pActual = *pRequest;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
143 //if (pActual->cbBuffer == 2)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
144 // pActual->cbBuffer = 576;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
145
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
146 me->props = *pActual;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
147
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
148 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
149 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
150
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
151 static HRESULT STDCALL MemAllocator_GetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
152 /* [out] */ ALLOCATOR_PROPERTIES *pProps)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
153 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
154 Debug printf("MemAllocator_GetProperties(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
155 if (!pProps)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
156 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
157 if (((MemAllocator*)This)->props.cbBuffer<0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
158 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
159 *pProps=((MemAllocator*)This)->props;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
160
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
161 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
162 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
163
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
164 static HRESULT STDCALL MemAllocator_Commit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
165 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
166 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
167 int i;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
168 Debug printf("MemAllocator_Commit(%p) called\n", This);
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;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
171 if (me->used_list || me->free_list)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
172 return E_INVALIDARG;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
173 for (i = 0; i < me->props.cBuffers; i++)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
174 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
175 CMediaSample* sample = CMediaSampleCreate((IMemAllocator*)me,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
176 me->props.cbBuffer);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
177 if (!sample)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
178 return E_OUTOFMEMORY;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
179 //printf("FREEEEEEEEEEEE ADDED %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
180 me->free_list = avm_list_add_tail(me->free_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
181 //avm_list_print(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
182 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
183
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
184 //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
185 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
186 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
187
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
188 static HRESULT STDCALL MemAllocator_Decommit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
189 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
190 MemAllocator* me=(MemAllocator*)This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
191 Debug printf("MemAllocator_Decommit(%p) called\n", This);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
192 //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
193 while (me->used_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
194 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
195 me->free_list = avm_list_add_tail(me->free_list,
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
196 (CMediaSample*) me->used_list->member);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
197 me->used_list = avm_list_del_head(me->used_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
198 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
199
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
200 while (me->free_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
201 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
202 CMediaSample* sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
203 //printf("****************** Decommiting FREE %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
204 //sample->vt->Release((IUnknown*)sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
205 CMediaSample_Destroy((CMediaSample*)sample);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
206 me->free_list = avm_list_del_head(me->free_list);
3056
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
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
209 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
210 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
211
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
212 static HRESULT STDCALL MemAllocator_GetBuffer(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
213 /* [out] */ IMediaSample **ppBuffer,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
214 /* [in] */ REFERENCE_TIME *pStartTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
215 /* [in] */ REFERENCE_TIME *pEndTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
216 /* [in] */ DWORD dwFlags)
168
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 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
219 CMediaSample* sample;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
220 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
221 avm_list_size(me->used_list), avm_list_size(me->free_list));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
222
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
223 if (!me->free_list)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
224 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
225 Debug printf("No samples available\n");
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
226 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
227 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
228
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
229 sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
230 me->free_list = avm_list_del_head(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
231 me->used_list = avm_list_add_tail(me->used_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
232
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
233 *ppBuffer = (IMediaSample*) sample;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
234 sample->vt->AddRef((IUnknown*) sample);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
235 if (me->new_pointer)
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
236 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
237 if (me->modified_sample)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
238 me->modified_sample->ResetPointer(me->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
239 sample->SetPointer(sample, me->new_pointer);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
240 me->modified_sample = sample;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
241 me->new_pointer = 0;
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
242 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
243 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
244 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
245
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
246 static HRESULT STDCALL MemAllocator_ReleaseBuffer(IMemAllocator* This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
247 /* [in] */ IMediaSample* pBuffer)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
248 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
249 avm_list_t* l;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
250 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
251 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
252 avm_list_size(me->used_list), avm_list_size(me->free_list));
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
253
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
254 l = avm_list_find(me->used_list, pBuffer);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
255 if (l)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
256 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
257 CMediaSample* sample = (CMediaSample*) l->member;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
258 if (me->modified_sample == sample)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
259 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
260 me->modified_sample->ResetPointer(me->modified_sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
261 me->modified_sample = 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
262 }
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
263 me->used_list = avm_list_del_head(me->used_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
264 me->free_list = avm_list_add_head(me->free_list, sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
265 //printf("****************** RELEASED OK %p %p\n", me->used_list, me->free_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
266 return 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
267 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
268 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
269 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
270 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
271
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
272
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
273 static void MemAllocator_SetPointer(MemAllocator* This, char* pointer)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
274 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
275 This->new_pointer = pointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
276 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
277
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
278 static void MemAllocator_ResetPointer(MemAllocator* This)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
279 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
280 if (This->modified_sample)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
281 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
282 This->modified_sample->ResetPointer(This->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
283 This->modified_sample = 0;
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 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
286
8292
9533c26c0806 avifile sync (mostly cosmetics)
arpi
parents: 7386
diff changeset
287 static void MemAllocator_Destroy(MemAllocator* This)
3056
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 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
290 #ifdef WIN32_LOADER
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
291 if (--AllocatorKeeper == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
292 UnregisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
293 #endif
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
294 free(This->vt);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
295 free(This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
296 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
297
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
298 IMPLEMENT_IUNKNOWN(MemAllocator)
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 MemAllocator* MemAllocatorCreate()
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
301 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
302 MemAllocator* This = (MemAllocator*) malloc(sizeof(MemAllocator));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
303
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
304 if (!This)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
305 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
306
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
307 Debug printf("MemAllocatorCreate() called -> %p\n", This);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
308
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
309 This->refcount = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
310 This->props.cBuffers = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
311 This->props.cbBuffer = 65536; /* :/ */
9503
f47d484d8f28 cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents: 8292
diff changeset
312 This->props.cbAlign = 1;
f47d484d8f28 cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents: 8292
diff changeset
313 This->props.cbPrefix = 0;
3056
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->vt = (IMemAllocator_vt*) malloc(sizeof(IMemAllocator_vt));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
316
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
317 if (!This->vt)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
318 {
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
319 free(This);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
320 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
321 }
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
322
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
323 This->vt->QueryInterface = MemAllocator_QueryInterface;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
324 This->vt->AddRef = MemAllocator_AddRef;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
325 This->vt->Release = MemAllocator_Release;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
326 This->vt->SetProperties = MemAllocator_SetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
327 This->vt->GetProperties = MemAllocator_GetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
328 This->vt->Commit = MemAllocator_Commit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
329 This->vt->Decommit = MemAllocator_Decommit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
330 This->vt->GetBuffer = MemAllocator_GetBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
331 This->vt->ReleaseBuffer = MemAllocator_ReleaseBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
332
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
333 This->SetPointer = MemAllocator_SetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
334 This->ResetPointer = MemAllocator_ResetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
335
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
336 This->modified_sample = 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
337 This->new_pointer = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
338 This->used_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
339 This->free_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
340
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
341 This->interfaces[0]=IID_IUnknown;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
342 This->interfaces[1]=IID_IMemAllocator;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
343
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
344 #ifdef WIN32_LOADER
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
345 if (AllocatorKeeper++ == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
346 RegisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
9967
b0d1b415320c cygwin support patch by Sascha Sommer and some fixes by me
alex
parents: 9503
diff changeset
347 #endif
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
348
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
349 return This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
350 }