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