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