annotate loader/dshow/allocator.c @ 866:91087aaea5c7

using gcc -MM instead of makedepend, make OBJS from SRCS where possible
author arpi_esp
date Thu, 24 May 2001 21:09:13 +0000
parents 9355b2ae634e
children da26060c81ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
2 #include "allocator.h"
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
3 #include <com.h>
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
4 #define E_NOTIMPL 0x80004001
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
5 using namespace std;
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
6
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
7 class AllocatorKeeper
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
8 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
9 public:
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
10 AllocatorKeeper()
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
11 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
12 RegisterComClass(&CLSID_MemoryAllocator, MemAllocator::CreateAllocator);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
13 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
14 };
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
15 static AllocatorKeeper keeper;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
16 GUID MemAllocator::interfaces[]=
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
17 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
18 IID_IUnknown,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
19 IID_IMemAllocator,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
20 };
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
21 IMPLEMENT_IUNKNOWN(MemAllocator)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
22
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
23 MemAllocator::MemAllocator()
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
24 :refcount(1)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
25 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
26 Debug printf("MemAllocator::MemAllocator() called\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
27 vt=new IMemAllocator_vt;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
28 vt->QueryInterface = QueryInterface;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
29 vt->AddRef = AddRef;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
30 vt->Release = Release;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
31 vt->SetProperties = SetProperties;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
32 vt->GetProperties = GetProperties;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
33 vt->Commit = Commit;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
34 vt->Decommit = Decommit;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
35 vt->GetBuffer = GetBuffer;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
36 vt->ReleaseBuffer = ReleaseBuffer;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
37
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
38 props.cBuffers=1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
39 props.cbBuffer=65536;/* :/ */
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
40 props.cbAlign=props.cbPrefix=0;
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
41
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
42 new_pointer=0;
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
43 modified_sample=0;
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
44 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
45
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
46 long MemAllocator::CreateAllocator(GUID* clsid, GUID* iid, void** ppv)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
47 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
48 if(!ppv)return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
49 *ppv=0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
50 if(memcmp(clsid, &CLSID_MemoryAllocator, sizeof(GUID)))
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
51 return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
52
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
53 IMemAllocator* p=new MemAllocator;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
54 int result=p->vt->QueryInterface((IUnknown*)p, iid, ppv);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
55 p->vt->Release((IUnknown*)p);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
56 return result;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
57 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
58
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
59
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
60 /*
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
61 long cBuffers;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
62 long cbBuffer;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
63 long cbAlign;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
64 long cbPrefix;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
65 */
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
66 HRESULT STDCALL MemAllocator::SetProperties (
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
67 IMemAllocator * This,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
68 /* [in] */ ALLOCATOR_PROPERTIES *pRequest,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
69 /* [out] */ ALLOCATOR_PROPERTIES *pActual)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
70 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
71 Debug printf("MemAllocator::SetProperties() called\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
72 if(!pRequest)return 0x80004003;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
73 if(!pActual)return 0x80004003;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
74 if(pRequest->cBuffers<=0)return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
75 if(pRequest->cbBuffer<=0)return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
76 MemAllocator* me=(MemAllocator*)This;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
77 if(me->used_list.size() || me->free_list.size())return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
78 me->props=*pRequest;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
79 *pActual=*pRequest;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
80 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
81 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
82
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
83 HRESULT STDCALL MemAllocator::GetProperties (
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
84 IMemAllocator * This,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
85 /* [out] */ ALLOCATOR_PROPERTIES *pProps)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
86 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
87 Debug printf("MemAllocator::GetProperties() called\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
88 if(!pProps)return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
89 if(((MemAllocator*)This)->props.cbBuffer<0)return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
90 *pProps=((MemAllocator*)This)->props;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
91 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
92 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
93
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
94 HRESULT STDCALL MemAllocator::Commit (
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
95 IMemAllocator * This)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
96 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
97 Debug printf("MemAllocator::Commit() called\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
98 MemAllocator* me=(MemAllocator*)This;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
99 if(((MemAllocator*)This)->props.cbBuffer<0)return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
100 if(me->used_list.size() || me->free_list.size())return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
101 for(int i=0; i<me->props.cBuffers; i++)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
102 me->free_list.push_back(new CMediaSample(me, me->props.cbBuffer));
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
103 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
104 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
105
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
106 HRESULT STDCALL MemAllocator::Decommit (
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
107 IMemAllocator * This)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
108 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
109 Debug printf("MemAllocator::Decommit() called\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
110 MemAllocator* me=(MemAllocator*)This;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
111 list<CMediaSample*>::iterator it;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
112 for(it=me->free_list.begin(); it!=me->free_list.end(); it++)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
113 delete *it;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
114 for(it=me->used_list.begin(); it!=me->used_list.end(); it++)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
115 delete *it;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
116 me->free_list.clear();
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
117 me->used_list.clear();
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
118 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
119 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
120
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
121 HRESULT STDCALL MemAllocator::GetBuffer (
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
122 IMemAllocator * This,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
123 /* [out] */ IMediaSample **ppBuffer,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
124 /* [in] */ REFERENCE_TIME *pStartTime,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
125 /* [in] */ REFERENCE_TIME *pEndTime,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
126 /* [in] */ DWORD dwFlags)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
127 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
128 Debug printf("%x: MemAllocator::GetBuffer() called\n", This);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
129 MemAllocator* me=(MemAllocator*)This;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
130 if(me->free_list.size()==0)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
131 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
132 Debug printf("No samples available\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
133 return -1;//should block here if no samples are available
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
134 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
135 list<CMediaSample*>::iterator it=me->free_list.begin();
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
136 me->used_list.push_back(*it);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
137 *ppBuffer=*it;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
138 (*ppBuffer)->vt->AddRef((IUnknown*)*ppBuffer);
713
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
139 if(me->new_pointer)
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
140 {
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
141 if(me->modified_sample)
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
142 me->modified_sample->ResetPointer();
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
143 (*it)->SetPointer(me->new_pointer);
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
144 me->modified_sample=*it;
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
145 me->new_pointer=0;
9355b2ae634e avifile-0.6-CVS merge
arpi_esp
parents: 168
diff changeset
146 }
168
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
147 me->free_list.remove(*it);
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
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
151 HRESULT STDCALL MemAllocator::ReleaseBuffer (
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
152 IMemAllocator * This,
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
153 /* [in] */ IMediaSample *pBuffer)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
154 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
155 Debug printf("%x: MemAllocator::ReleaseBuffer() called\n", This);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
156 MemAllocator* me=(MemAllocator*)This;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
157 list<CMediaSample*>::iterator it;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
158 for(it=me->used_list.begin(); it!=me->used_list.end(); it++)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
159 if(*it==pBuffer)
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
160 {
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
161 me->used_list.erase(it);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
162 me->free_list.push_back((CMediaSample*)pBuffer);
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
163 return 0;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
164 }
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
165 Debug printf("Releasing unknown buffer\n");
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
166 return -1;
bdc4a8fc04d8 Initial revision
arpi_esp
parents:
diff changeset
167 }