]> git.sesse.net Git - vlc/blob - modules/codec/dmo/buffer.c
* dmo: - fixed init of WAVEFORMATEX (cbSize is only the size of extra datas).
[vlc] / modules / codec / dmo / buffer.c
1 /*****************************************************************************
2  * buffer.c : DirectMedia Object decoder module for vlc
3  *****************************************************************************
4  * Copyright (C) 2002, 2003 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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/decoder.h>
33 #include <vlc/vout.h>
34
35 #define LOADER
36 #ifdef LOADER
37 #   include <wine/winerror.h>
38 #   include <dmo/dmo.h>
39 #   include <dmo/dmo_interfaces.h>
40 #   include <dmo/dmo_guids.h>
41 #   define _RECT32_
42 #   define _GUID_DEFINED
43 #   define _REFERENCE_TIME_
44 #   define _VIDEOINFOHEADER_
45 #else
46 #   include <objbase.h>
47 #endif
48 #include "codecs.h"
49 #include "dmo.h"
50
51 static long STDCALL QueryInterface( IUnknown *This,
52                                     const GUID *riid, void **ppv )
53 {
54     CMediaBuffer *p_mb = (CMediaBuffer *)This;
55     if( !memcmp( riid, &IID_IUnknown, sizeof(GUID) ) ||
56         !memcmp( riid, &IID_IMediaBuffer, sizeof(GUID) ) )
57     {
58         p_mb->i_ref++;
59         *ppv = (void *)This;
60         return NOERROR;
61     }
62     else
63     {
64         *ppv = NULL;
65         return E_NOINTERFACE;
66     }
67 }
68
69 static long STDCALL AddRef( IUnknown *This )
70 {
71     CMediaBuffer *p_mb = (CMediaBuffer *)This;
72     return p_mb->i_ref++;
73 }
74
75 static long STDCALL Release( IUnknown *This )
76 {
77     CMediaBuffer *p_mb = (CMediaBuffer *)This;
78     p_mb->i_ref--;
79
80     if( p_mb->i_ref == 0 )
81     {
82         if( p_mb->b_own ) block_Release( p_mb->p_block );
83         free( p_mb->vt );
84         free( p_mb );
85     }
86
87     return 0;
88 }
89
90 static long STDCALL SetLength( IMediaBuffer *This, uint32_t cbLength )
91 {
92     CMediaBuffer *p_mb = (CMediaBuffer *)This;
93     if( cbLength > p_mb->i_max_size ) return E_INVALIDARG;
94     p_mb->p_block->i_buffer = cbLength;
95     return S_OK;
96 }
97
98 static long STDCALL GetMaxLength( IMediaBuffer *This, uint32_t *pcbMaxLength )
99 {
100     CMediaBuffer *p_mb = (CMediaBuffer *)This;
101     if( !pcbMaxLength ) return E_POINTER;
102     *pcbMaxLength = p_mb->i_max_size;
103     return S_OK;
104 }
105
106 static long STDCALL GetBufferAndLength( IMediaBuffer *This,
107                                         char **ppBuffer, uint32_t *pcbLength )
108 {
109     CMediaBuffer *p_mb = (CMediaBuffer *)This;
110
111     if( !ppBuffer && !pcbLength ) return E_POINTER;
112     if( ppBuffer ) *ppBuffer = p_mb->p_block->p_buffer;
113     if( pcbLength ) *pcbLength = p_mb->p_block->i_buffer;
114     return S_OK;
115 }
116
117 CMediaBuffer *CMediaBufferCreate( block_t *p_block, int i_max_size,
118                                   vlc_bool_t b_own )
119 {
120     CMediaBuffer *p_mb = (CMediaBuffer *)malloc( sizeof(CMediaBuffer) );
121     if( !p_mb ) return NULL;
122
123     p_mb->vt = (IMediaBuffer_vt *)malloc( sizeof(IMediaBuffer_vt) );
124     if( !p_mb->vt )
125     {
126         free( p_mb );
127         return NULL;
128     }
129
130     p_mb->i_ref = 1;
131     p_mb->p_block = p_block;
132     p_mb->i_max_size = i_max_size;
133     p_mb->b_own = b_own;
134
135     p_mb->vt->QueryInterface = QueryInterface;
136     p_mb->vt->AddRef = AddRef;
137     p_mb->vt->Release = Release;
138
139     p_mb->vt->SetLength = SetLength;
140     p_mb->vt->GetMaxLength = GetMaxLength;
141     p_mb->vt->GetBufferAndLength = GetBufferAndLength;
142
143     return p_mb;
144 }