]> git.sesse.net Git - vlc/blob - modules/codec/dmo/buffer.c
Remove stdio while we're at it.
[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
28 #include <vlc/vlc.h>
29 #include <vlc_codec.h>
30 #include <vlc_vout.h>
31
32 #ifndef WIN32
33 #    define LOADER
34 #else
35 #   include <objbase.h>
36 #endif
37
38 #ifdef LOADER
39 #   include <wine/winerror.h>
40 #   include <wine/windef.h>
41 #endif
42
43 #include <vlc_codecs.h>
44 #include "dmo.h"
45
46 static long STDCALL QueryInterface( IUnknown *This,
47                                     const GUID *riid, void **ppv )
48 {
49     CMediaBuffer *p_mb = (CMediaBuffer *)This;
50     if( !memcmp( riid, &IID_IUnknown, sizeof(GUID) ) ||
51         !memcmp( riid, &IID_IMediaBuffer, sizeof(GUID) ) )
52     {
53         p_mb->i_ref++;
54         *ppv = (void *)This;
55         return NOERROR;
56     }
57     else
58     {
59         *ppv = NULL;
60         return E_NOINTERFACE;
61     }
62 }
63
64 static long STDCALL AddRef( IUnknown *This )
65 {
66     CMediaBuffer *p_mb = (CMediaBuffer *)This;
67     return p_mb->i_ref++;
68 }
69
70 static long STDCALL Release( IUnknown *This )
71 {
72     CMediaBuffer *p_mb = (CMediaBuffer *)This;
73     p_mb->i_ref--;
74
75     if( p_mb->i_ref == 0 )
76     {
77         if( p_mb->b_own ) block_Release( p_mb->p_block );
78         free( p_mb->vt );
79         free( p_mb );
80     }
81
82     return 0;
83 }
84
85 static long STDCALL SetLength( IMediaBuffer *This, uint32_t cbLength )
86 {
87     CMediaBuffer *p_mb = (CMediaBuffer *)This;
88     if( cbLength > (uint32_t)p_mb->i_max_size ) return E_INVALIDARG;
89     p_mb->p_block->i_buffer = cbLength;
90     return S_OK;
91 }
92
93 static long STDCALL GetMaxLength( IMediaBuffer *This, uint32_t *pcbMaxLength )
94 {
95     CMediaBuffer *p_mb = (CMediaBuffer *)This;
96     if( !pcbMaxLength ) return E_POINTER;
97     *pcbMaxLength = p_mb->i_max_size;
98     return S_OK;
99 }
100
101 static long STDCALL GetBufferAndLength( IMediaBuffer *This,
102                                         char **ppBuffer, uint32_t *pcbLength )
103 {
104     CMediaBuffer *p_mb = (CMediaBuffer *)This;
105
106     if( !ppBuffer && !pcbLength ) return E_POINTER;
107     if( ppBuffer ) *ppBuffer = p_mb->p_block->p_buffer;
108     if( pcbLength ) *pcbLength = p_mb->p_block->i_buffer;
109     return S_OK;
110 }
111
112 CMediaBuffer *CMediaBufferCreate( block_t *p_block, int i_max_size,
113                                   vlc_bool_t b_own )
114 {
115     CMediaBuffer *p_mb = (CMediaBuffer *)malloc( sizeof(CMediaBuffer) );
116     if( !p_mb ) return NULL;
117
118     p_mb->vt = (IMediaBuffer_vt *)malloc( sizeof(IMediaBuffer_vt) );
119     if( !p_mb->vt )
120     {
121         free( p_mb );
122         return NULL;
123     }
124
125     p_mb->i_ref = 1;
126     p_mb->p_block = p_block;
127     p_mb->i_max_size = i_max_size;
128     p_mb->b_own = b_own;
129
130     p_mb->vt->QueryInterface = QueryInterface;
131     p_mb->vt->AddRef = AddRef;
132     p_mb->vt->Release = Release;
133
134     p_mb->vt->SetLength = SetLength;
135     p_mb->vt->GetMaxLength = GetMaxLength;
136     p_mb->vt->GetBufferAndLength = GetBufferAndLength;
137
138     return p_mb;
139 }