1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/*****************************************************************************
* buffer.c : DirectMedia Object decoder module for vlc
*****************************************************************************
* Copyright (C) 2002, 2003 VLC authors and VideoLAN
* $Id$
*
* Author: Gildas Bazin <gbazin@videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_codec.h>
#ifndef _WIN32
# define LOADER
#else
# include <objbase.h>
#endif
#ifdef LOADER
# include <wine/winerror.h>
# include <wine/windef.h>
#endif
#include <vlc_codecs.h>
#include "dmo.h"
static long STDCALL QueryInterface( IUnknown *This,
const GUID *riid, void **ppv )
{
CMediaBuffer *p_mb = (CMediaBuffer *)This;
if( !memcmp( riid, &IID_IUnknown, sizeof(GUID) ) ||
!memcmp( riid, &IID_IMediaBuffer, sizeof(GUID) ) )
{
p_mb->i_ref++;
*ppv = (void *)This;
return NOERROR;
}
else
{
*ppv = NULL;
return E_NOINTERFACE;
}
}
static long STDCALL AddRef( IUnknown *This )
{
CMediaBuffer *p_mb = (CMediaBuffer *)This;
return p_mb->i_ref++;
}
static long STDCALL Release( IUnknown *This )
{
CMediaBuffer *p_mb = (CMediaBuffer *)This;
p_mb->i_ref--;
if( p_mb->i_ref == 0 )
{
if( p_mb->b_own ) block_Release( p_mb->p_block );
free( p_mb->vt );
free( p_mb );
}
return 0;
}
static long STDCALL SetLength( IMediaBuffer *This, uint32_t cbLength )
{
CMediaBuffer *p_mb = (CMediaBuffer *)This;
if( cbLength > (uint32_t)p_mb->i_max_size ) return E_INVALIDARG;
p_mb->p_block->i_buffer = cbLength;
return S_OK;
}
static long STDCALL GetMaxLength( IMediaBuffer *This, uint32_t *pcbMaxLength )
{
CMediaBuffer *p_mb = (CMediaBuffer *)This;
if( !pcbMaxLength ) return E_POINTER;
*pcbMaxLength = p_mb->i_max_size;
return S_OK;
}
static long STDCALL GetBufferAndLength( IMediaBuffer *This,
char **ppBuffer, uint32_t *pcbLength )
{
CMediaBuffer *p_mb = (CMediaBuffer *)This;
if( !ppBuffer && !pcbLength ) return E_POINTER;
if( ppBuffer ) *ppBuffer = (char*)p_mb->p_block->p_buffer;
if( pcbLength ) *pcbLength = p_mb->p_block->i_buffer;
return S_OK;
}
CMediaBuffer *CMediaBufferCreate( block_t *p_block, int i_max_size,
bool b_own )
{
CMediaBuffer *p_mb = (CMediaBuffer *)malloc( sizeof(CMediaBuffer) );
if( !p_mb ) return NULL;
p_mb->vt = (IMediaBuffer_vt *)malloc( sizeof(IMediaBuffer_vt) );
if( !p_mb->vt )
{
free( p_mb );
return NULL;
}
p_mb->i_ref = 1;
p_mb->p_block = p_block;
p_mb->i_max_size = i_max_size;
p_mb->b_own = b_own;
p_mb->vt->QueryInterface = QueryInterface;
p_mb->vt->AddRef = AddRef;
p_mb->vt->Release = Release;
p_mb->vt->SetLength = SetLength;
p_mb->vt->GetMaxLength = GetMaxLength;
p_mb->vt->GetBufferAndLength = GetBufferAndLength;
return p_mb;
}
|