Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

buffer.c

00001 /*****************************************************************************
00002  * buffer.c : DirectMedia Object decoder module for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2002, 2003 the VideoLAN team
00005  * $Id: buffer.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Author: Gildas Bazin <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 
00031 #include <vlc/vlc.h>
00032 #include <vlc/decoder.h>
00033 #include <vlc/vout.h>
00034 
00035 #ifndef WIN32
00036 #    define LOADER
00037 #else
00038 #   include <objbase.h>
00039 #endif
00040 
00041 #ifdef LOADER
00042 #   include <wine/winerror.h>
00043 #   include <wine/windef.h>
00044 #endif
00045 
00046 #include "codecs.h"
00047 #include "dmo.h"
00048 
00049 static long STDCALL QueryInterface( IUnknown *This,
00050                                     const GUID *riid, void **ppv )
00051 {
00052     CMediaBuffer *p_mb = (CMediaBuffer *)This;
00053     if( !memcmp( riid, &IID_IUnknown, sizeof(GUID) ) ||
00054         !memcmp( riid, &IID_IMediaBuffer, sizeof(GUID) ) )
00055     {
00056         p_mb->i_ref++;
00057         *ppv = (void *)This;
00058         return NOERROR;
00059     }
00060     else
00061     {
00062         *ppv = NULL;
00063         return E_NOINTERFACE;
00064     }
00065 }
00066 
00067 static long STDCALL AddRef( IUnknown *This )
00068 {
00069     CMediaBuffer *p_mb = (CMediaBuffer *)This;
00070     return p_mb->i_ref++;
00071 }
00072 
00073 static long STDCALL Release( IUnknown *This )
00074 {
00075     CMediaBuffer *p_mb = (CMediaBuffer *)This;
00076     p_mb->i_ref--;
00077 
00078     if( p_mb->i_ref == 0 )
00079     {
00080         if( p_mb->b_own ) block_Release( p_mb->p_block );
00081         free( p_mb->vt );
00082         free( p_mb );
00083     }
00084 
00085     return 0;
00086 }
00087 
00088 static long STDCALL SetLength( IMediaBuffer *This, uint32_t cbLength )
00089 {
00090     CMediaBuffer *p_mb = (CMediaBuffer *)This;
00091     if( cbLength > (uint32_t)p_mb->i_max_size ) return E_INVALIDARG;
00092     p_mb->p_block->i_buffer = cbLength;
00093     return S_OK;
00094 }
00095 
00096 static long STDCALL GetMaxLength( IMediaBuffer *This, uint32_t *pcbMaxLength )
00097 {
00098     CMediaBuffer *p_mb = (CMediaBuffer *)This;
00099     if( !pcbMaxLength ) return E_POINTER;
00100     *pcbMaxLength = p_mb->i_max_size;
00101     return S_OK;
00102 }
00103 
00104 static long STDCALL GetBufferAndLength( IMediaBuffer *This,
00105                                         char **ppBuffer, uint32_t *pcbLength )
00106 {
00107     CMediaBuffer *p_mb = (CMediaBuffer *)This;
00108 
00109     if( !ppBuffer && !pcbLength ) return E_POINTER;
00110     if( ppBuffer ) *ppBuffer = p_mb->p_block->p_buffer;
00111     if( pcbLength ) *pcbLength = p_mb->p_block->i_buffer;
00112     return S_OK;
00113 }
00114 
00115 CMediaBuffer *CMediaBufferCreate( block_t *p_block, int i_max_size,
00116                                   vlc_bool_t b_own )
00117 {
00118     CMediaBuffer *p_mb = (CMediaBuffer *)malloc( sizeof(CMediaBuffer) );
00119     if( !p_mb ) return NULL;
00120 
00121     p_mb->vt = (IMediaBuffer_vt *)malloc( sizeof(IMediaBuffer_vt) );
00122     if( !p_mb->vt )
00123     {
00124         free( p_mb );
00125         return NULL;
00126     }
00127 
00128     p_mb->i_ref = 1;
00129     p_mb->p_block = p_block;
00130     p_mb->i_max_size = i_max_size;
00131     p_mb->b_own = b_own;
00132 
00133     p_mb->vt->QueryInterface = QueryInterface;
00134     p_mb->vt->AddRef = AddRef;
00135     p_mb->vt->Release = Release;
00136 
00137     p_mb->vt->SetLength = SetLength;
00138     p_mb->vt->GetMaxLength = GetMaxLength;
00139     p_mb->vt->GetBufferAndLength = GetBufferAndLength;
00140 
00141     return p_mb;
00142 }

Generated on Tue Dec 20 10:14:26 2005 for vlc-0.8.4a by  doxygen 1.4.2