annotate loader/dshow/allocator.c @ 7058:2e5c07262861

new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>: - multithreaded audio/video buffering (I know mplayer crew hates threads but it seems to me as the only way of doing reliable a/v capture) - a/v timebase synchronization (sample count vs. gettimeofday) - "immediate" mode support for mplayer - fixed colorspace stuff - RGB?? and YUY2 modes now work as expected - native ALSA audio capture - separated audio input layer
author arpi
date Wed, 21 Aug 2002 21:31:20 +0000
parents e3bbf44dbab2
children 174e2a58b4cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
1 #include "allocator.h"
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
2 #include "com.h"
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
3 #include "wine/winerror.h"
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
4 #include <stdio.h>
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
5
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
6 static int AllocatorKeeper = 0;
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 inline int avm_list_size(avm_list_t* head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
9 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
10 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
11 int i = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
12 if (it)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
13 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
14 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
15 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
16 i++;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
17 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
18 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
19 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
20 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
21 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
22 return i;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
23 }
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
24
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
25 static inline int avm_list_print(avm_list_t* head)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
26 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
27 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
28 int i = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
29 printf("Head: %p\n", head);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
30 if (it)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
31 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
32 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
33 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
34 i++;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
35 printf("%d: member: %p next: %p prev: %p\n",
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
36 i, it->member, it->next, it->prev);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
37 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
38 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
39 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
40 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
41 }
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
42 return i;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
43 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
44
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
45 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
46 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
47 avm_list_t* n = (avm_list_t*) malloc(sizeof(avm_list_t));
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
48 n->member = member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
49
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
50 if (!head)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
51 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
52 head = n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
53 head->prev = head;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
54 }
3056
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 n->prev = head->prev;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
57 head->prev = n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
58 n->next = head;
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 return n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
61 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
62
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
63 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
64 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
65 avm_list_t* n = avm_list_add_head(head, member);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
66 return (!head) ? n : head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
67 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
68
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
69 static inline avm_list_t* avm_list_del_head(avm_list_t* head)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
70 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
71 avm_list_t* n = 0;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
72
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
73 if (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 if (head->next != head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
76 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
77 n = head->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
78 head->prev->next = head->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
79 head->next->prev = head->prev;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
80 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
81 free(head);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
82 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
83 return n;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
84 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
85
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
86 static inline avm_list_t* avm_list_find(avm_list_t* head, void* member)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
87 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
88 avm_list_t* it = head;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
89 if (it)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
90 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
91 for (;;)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
92 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
93 if (it->member == member)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
94 return it;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
95 it = it->next;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
96 if (it == head)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
97 break;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
98 }
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 return NULL;
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
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
103 static long MemAllocator_CreateAllocator(GUID* clsid, GUID* iid, void** ppv)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
104 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
105 IMemAllocator* p;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
106 int result;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
107 if (!ppv)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
108 return -1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
109 *ppv = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
110 if (memcmp(clsid, &CLSID_MemoryAllocator, sizeof(GUID)))
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
111 return -1;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
112
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
113 p = (IMemAllocator*) MemAllocatorCreate();
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
114 result = p->vt->QueryInterface((IUnknown*)p, iid, ppv);
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
115 p->vt->Release((IUnknown*)p);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
116
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
117 return result;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
118 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
119
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
120 static HRESULT STDCALL MemAllocator_SetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
121 /* [in] */ ALLOCATOR_PROPERTIES *pRequest,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
122 /* [out] */ ALLOCATOR_PROPERTIES *pActual)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
123 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
124 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
125 Debug printf("MemAllocator_SetProperties(%p) called\n", This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
126 if (!pRequest || !pActual)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
127 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
128 if (pRequest->cBuffers<=0 || pRequest->cbBuffer<=0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
129 return E_FAIL;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
130 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
131 return E_FAIL;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
132
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
133 *pActual = *pRequest;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
134 //if (pActual->cbBuffer == 2)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
135 // pActual->cbBuffer = 576;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
136
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
137 me->props = *pActual;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
138
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
139 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
140 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
141
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
142 static HRESULT STDCALL MemAllocator_GetProperties(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
143 /* [out] */ ALLOCATOR_PROPERTIES *pProps)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
144 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
145 Debug printf("MemAllocator_GetProperties(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
146 if (!pProps)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
147 return E_INVALIDARG;
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
148 if (((MemAllocator*)This)->props.cbBuffer<0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
149 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
150 *pProps=((MemAllocator*)This)->props;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
151
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
152 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
153 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
154
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
155 static HRESULT STDCALL MemAllocator_Commit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
156 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
157 MemAllocator* me = (MemAllocator*)This;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
158 int i;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
159 Debug printf("MemAllocator_Commit(%p) called\n", This);
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
160 if (((MemAllocator*)This)->props.cbBuffer < 0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
161 return E_FAIL;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
162 if (me->used_list || me->free_list)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
163 return E_INVALIDARG;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
164 for (i = 0; i < me->props.cBuffers; i++)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
165 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
166 CMediaSample* sample = CMediaSampleCreate((IMemAllocator*)me,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
167 me->props.cbBuffer);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
168 if (!sample)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
169 return E_OUTOFMEMORY;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
170 //printf("FREEEEEEEEEEEE ADDED %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
171 me->free_list = avm_list_add_tail(me->free_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
172 //avm_list_print(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
173 }
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 //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
176 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
177 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
178
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
179 static HRESULT STDCALL MemAllocator_Decommit(IMemAllocator * This)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
180 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
181 MemAllocator* me=(MemAllocator*)This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
182 Debug printf("MemAllocator_Decommit(%p) called\n", This);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
183 //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
184 while (me->used_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
185 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
186 me->free_list = avm_list_add_tail(me->free_list,
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
187 (CMediaSample*) me->used_list->member);
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
188 me->used_list = avm_list_del_head(me->used_list);
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
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
191 while (me->free_list)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
192 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
193 CMediaSample* sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
194 //printf("****************** Decommiting FREE %p\n", sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
195 //sample->vt->Release((IUnknown*)sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
196 CMediaSample_Destroy((CMediaSample*)sample);
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
197 me->free_list = avm_list_del_head(me->free_list);
3056
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
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
200 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
201 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
202
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
203 static HRESULT STDCALL MemAllocator_GetBuffer(IMemAllocator * This,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
204 /* [out] */ IMediaSample **ppBuffer,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
205 /* [in] */ REFERENCE_TIME *pStartTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
206 /* [in] */ REFERENCE_TIME *pEndTime,
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
207 /* [in] */ DWORD dwFlags)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
208 {
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
209 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
210 CMediaSample* sample;
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
211 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
212 avm_list_size(me->used_list), avm_list_size(me->free_list));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
213
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
214 if (!me->free_list)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
215 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
216 Debug printf("No samples available\n");
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
217 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
218 }
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 sample = (CMediaSample*) me->free_list->member;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
221 me->free_list = avm_list_del_head(me->free_list);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
222 me->used_list = avm_list_add_tail(me->used_list, sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
223
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
224 *ppBuffer = (IMediaSample*) sample;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
225 sample->vt->AddRef((IUnknown*) sample);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
226 if (me->new_pointer)
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
227 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
228 if (me->modified_sample)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
229 me->modified_sample->ResetPointer(me->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
230 sample->SetPointer(sample, me->new_pointer);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
231 me->modified_sample = sample;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
232 me->new_pointer = 0;
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
233 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
234 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
235 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
236
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
237 static HRESULT STDCALL MemAllocator_ReleaseBuffer(IMemAllocator* This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
238 /* [in] */ IMediaSample* pBuffer)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
239 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
240 avm_list_t* l;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
241 MemAllocator* me = (MemAllocator*)This;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
242 Debug printf("MemAllocator_ReleaseBuffer(%p) called %d %d\n", This,
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
243 avm_list_size(me->used_list), avm_list_size(me->free_list));
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
244
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
245 l = avm_list_find(me->used_list, pBuffer);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
246 if (l)
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
247 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
248 CMediaSample* sample = (CMediaSample*) l->member;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
249 if (me->modified_sample == sample)
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
250 {
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
251 me->modified_sample->ResetPointer(me->modified_sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
252 me->modified_sample = 0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
253 }
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
254 me->used_list = avm_list_del_head(me->used_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
255 me->free_list = avm_list_add_head(me->free_list, sample);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
256 //printf("****************** RELEASED OK %p %p\n", me->used_list, me->free_list);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
257 return 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
258 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
259 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
260 return E_FAIL;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
261 }
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
262
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
263
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
264 static void MemAllocator_SetPointer(MemAllocator* This, char* pointer)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
265 {
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
266 This->new_pointer = pointer;
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
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
269 static void MemAllocator_ResetPointer(MemAllocator* This)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
270 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
271 if (This->modified_sample)
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 This->modified_sample->ResetPointer(This->modified_sample);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
274 This->modified_sample = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
275 }
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
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 void MemAllocator_Destroy(MemAllocator* This)
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_Destroy(%p) called (%d, %d)\n", This, This->refcount, AllocatorKeeper);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
281 if (--AllocatorKeeper == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
282 UnregisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
283 free(This->vt);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
284 free(This);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
285 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
286
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
287 IMPLEMENT_IUNKNOWN(MemAllocator)
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 MemAllocator* MemAllocatorCreate()
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
290 {
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
291 MemAllocator* This = (MemAllocator*) malloc(sizeof(MemAllocator));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
292
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
293 if (!This)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
294 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
295
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
296 Debug printf("MemAllocatorCreate() called -> %p\n", This);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
297
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
298 This->refcount = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
299 This->props.cBuffers = 1;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
300 This->props.cbBuffer = 65536; /* :/ */
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
301 This->props.cbAlign = This->props.cbPrefix = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
302
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
303 This->vt = (IMemAllocator_vt*) malloc(sizeof(IMemAllocator_vt));
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
304
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
305 if (!This->vt)
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
306 {
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
307 free(This);
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
308 return NULL;
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
309 }
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
310
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
311 This->vt->QueryInterface = MemAllocator_QueryInterface;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
312 This->vt->AddRef = MemAllocator_AddRef;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
313 This->vt->Release = MemAllocator_Release;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
314 This->vt->SetProperties = MemAllocator_SetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
315 This->vt->GetProperties = MemAllocator_GetProperties;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
316 This->vt->Commit = MemAllocator_Commit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
317 This->vt->Decommit = MemAllocator_Decommit;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
318 This->vt->GetBuffer = MemAllocator_GetBuffer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
319 This->vt->ReleaseBuffer = MemAllocator_ReleaseBuffer;
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->SetPointer = MemAllocator_SetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
322 This->ResetPointer = MemAllocator_ResetPointer;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
323
3467
e3bbf44dbab2 avifile sync
arpi
parents: 3056
diff changeset
324 This->modified_sample = 0;
3056
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
325 This->new_pointer = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
326 This->used_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
327 This->free_list = 0;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
328
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
329 This->interfaces[0]=IID_IUnknown;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
330 This->interfaces[1]=IID_IMemAllocator;
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
331
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
332 if (AllocatorKeeper++ == 0)
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
333 RegisterComClass(&CLSID_MemoryAllocator, MemAllocator_CreateAllocator);
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
334
213b35f84cf3 C++ -> C (import from avifile cvs)
arpi
parents: 2069
diff changeset
335 return This;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents: 713
diff changeset
336 }