]> git.sesse.net Git - vlc/blob - modules/codec/dmo/buffer.c
A bit of headers cleanup
[vlc] / modules / codec / dmo / buffer.c
1 /*****************************************************************************
2  * buffer.c : DirectMedia Object decoder module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002, 2003 the VideoLAN team
5  * $Id$
6  *
7  * Author: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc_codec.h>
33 #include <vlc_vout.h>
34
35 #ifndef WIN32
36 #    define LOADER
37 #else
38 #   include <objbase.h>
39 #endif
40
41 #ifdef LOADER
42 #   include <wine/winerror.h>
43 #   include <wine/windef.h>
44 #endif
45
46 #include <vlc_codecs.h>
47 #include "dmo.h"
48
49 static long STDCALL QueryInterface( IUnknown *This,
50                                     const GUID *riid, void **ppv )
51 {
52     CMediaBuffer *p_mb = (CMediaBuffer *)This;
53     if( !memcmp( riid, &IID_IUnknown, sizeof(GUID) ) ||
54         !memcmp( riid, &IID_IMediaBuffer, sizeof(GUID) ) )
55     {
56         p_mb->i_ref++;
57         *ppv = (void *)This;
58         return NOERROR;
59     }
60     else
61     {
62         *ppv = NULL;
63         return E_NOINTERFACE;
64     }
65 }
66
67 static long STDCALL AddRef( IUnknown *This )
68 {
69     CMediaBuffer *p_mb = (CMediaBuffer *)This;
70     return p_mb->i_ref++;
71 }
72
73 static long STDCALL Release( IUnknown *This )
74 {
75     CMediaBuffer *p_mb = (CMediaBuffer *)This;
76     p_mb->i_ref--;
77
78     if( p_mb->i_ref == 0 )
79     {
80         if( p_mb->b_own ) block_Release( p_mb->p_block );
81         free( p_mb->vt );
82         free( p_mb );
83     }
84
85     return 0;
86 }
87
88 static long STDCALL SetLength( IMediaBuffer *This, uint32_t cbLength )
89 {
90     CMediaBuffer *p_mb = (CMediaBuffer *)This;
91     if( cbLength > (uint32_t)p_mb->i_max_size ) return E_INVALIDARG;
92     p_mb->p_block->i_buffer = cbLength;
93     return S_OK;
94 }
95
96 static long STDCALL GetMaxLength( IMediaBuffer *This, uint32_t *pcbMaxLength )
97 {
98     CMediaBuffer *p_mb = (CMediaBuffer *)This;
99     if( !pcbMaxLength ) return E_POINTER;
100     *pcbMaxLength = p_mb->i_max_size;
101     return S_OK;
102 }
103
104 static long STDCALL GetBufferAndLength( IMediaBuffer *This,
105                                         char **ppBuffer, uint32_t *pcbLength )
106 {
107     CMediaBuffer *p_mb = (CMediaBuffer *)This;
108
109     if( !ppBuffer && !pcbLength ) return E_POINTER;
110     if( ppBuffer ) *ppBuffer = p_mb->p_block->p_buffer;
111     if( pcbLength ) *pcbLength = p_mb->p_block->i_buffer;
112     return S_OK;
113 }
114
115 CMediaBuffer *CMediaBufferCreate( block_t *p_block, int i_max_size,
116                                   vlc_bool_t b_own )
117 {
118     CMediaBuffer *p_mb = (CMediaBuffer *)malloc( sizeof(CMediaBuffer) );
119     if( !p_mb ) return NULL;
120
121     p_mb->vt = (IMediaBuffer_vt *)malloc( sizeof(IMediaBuffer_vt) );
122     if( !p_mb->vt )
123     {
124         free( p_mb );
125         return NULL;
126     }
127
128     p_mb->i_ref = 1;
129     p_mb->p_block = p_block;
130     p_mb->i_max_size = i_max_size;
131     p_mb->b_own = b_own;
132
133     p_mb->vt->QueryInterface = QueryInterface;
134     p_mb->vt->AddRef = AddRef;
135     p_mb->vt->Release = Release;
136
137     p_mb->vt->SetLength = SetLength;
138     p_mb->vt->GetMaxLength = GetMaxLength;
139     p_mb->vt->GetBufferAndLength = GetBufferAndLength;
140
141     return p_mb;
142 }