demux_avi: remove pointless checks
[mplayer.git] / loader / dmo / buffer.c
blob78428e249f7eb428808a04e1f5f46c1060bcb57a
1 #include "DMO_Filter.h"
3 #include "loader/wine/winerror.h"
4 #include "loader/wine/windef.h"
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdlib.h>
10 struct CMediaBuffer
12 IMediaBuffer_vt* vt;
13 DECLARE_IUNKNOWN();
14 GUID interfaces[2];
15 void* mem;
16 unsigned long len;
17 unsigned long maxlen;
18 int freemem;
21 static HRESULT STDCALL CMediaBuffer_SetLength(IMediaBuffer* This,
22 unsigned long cbLength)
24 CMediaBuffer* cmb = (CMediaBuffer*) This;
25 Debug printf("CMediaBuffer_SetLength(%p) called (%ld, %ld)\n", This, cbLength, cmb->maxlen);
26 if (cbLength > cmb->maxlen)
27 return E_INVALIDARG;
28 cmb->len = cbLength;
29 return S_OK;
32 static HRESULT STDCALL CMediaBuffer_GetMaxLength(IMediaBuffer* This,
33 /* [out] */ unsigned long *pcbMaxLength)
35 CMediaBuffer* cmb = (CMediaBuffer*) This;
36 Debug printf("CMediaBuffer_GetMaxLength(%p) called -> %ld\n", This, cmb->maxlen);
37 if (!pcbMaxLength)
38 return E_POINTER;
39 *pcbMaxLength = cmb->maxlen;
40 return S_OK;
43 static HRESULT STDCALL CMediaBuffer_GetBufferAndLength(IMediaBuffer* This,
44 /* [out] */ char** ppBuffer,
45 /* [out] */ unsigned long* pcbLength)
47 CMediaBuffer* cmb = (CMediaBuffer*) This;
48 Debug printf("CMediaBuffer_GetBufferAndLength(%p) called -> %p %ld\n", This, cmb->mem, cmb->len);
49 if (!ppBuffer && !pcbLength)
50 return E_POINTER;
51 if (ppBuffer)
52 *ppBuffer = cmb->mem;
53 if (pcbLength)
54 *pcbLength = cmb->len;
55 return S_OK;
58 static void CMediaBuffer_Destroy(CMediaBuffer* This)
60 Debug printf("CMediaBuffer_Destroy(%p) called\n", This);
61 if (This->freemem)
62 free(This->mem);
63 free(This->vt);
64 free(This);
67 IMPLEMENT_IUNKNOWN(CMediaBuffer)
69 CMediaBuffer* CMediaBufferCreate(unsigned long maxlen, void* mem,
70 unsigned long len, int copy)
72 CMediaBuffer* This = malloc(sizeof(CMediaBuffer));
74 if (!This)
75 return NULL;
77 This->vt = malloc(sizeof(IMediaBuffer_vt));
78 if (!This->vt)
80 CMediaBuffer_Destroy(This);
81 return NULL;
84 This->refcount = 1;
85 This->len = len;
86 This->maxlen = maxlen;
87 This->freemem = 0;
88 This->mem = mem;
89 if (copy)
90 /* make a private copy of data */
91 This->mem = 0;
92 if (This->mem == NULL)
94 if (This->maxlen)
96 This->mem = malloc(This->maxlen);
97 if (!This->mem)
99 CMediaBuffer_Destroy(This);
100 return NULL;
102 This->freemem = 1;
103 if (copy)
104 memcpy(This->mem, mem, This->len);
107 This->vt->QueryInterface = CMediaBuffer_QueryInterface;
108 This->vt->AddRef = CMediaBuffer_AddRef;
109 This->vt->Release = CMediaBuffer_Release;
111 This->vt->SetLength = CMediaBuffer_SetLength;
112 This->vt->GetMaxLength = CMediaBuffer_GetMaxLength;
113 This->vt->GetBufferAndLength = CMediaBuffer_GetBufferAndLength;
115 This->interfaces[0] = IID_IUnknown;
116 This->interfaces[1] = IID_IMediaBuffer;
118 return This;