AbstractAudioEncodeOutputPin.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Redistribution and use in source and binary forms, with or without
00005 //modification, are permitted provided that the following conditions
00006 //are met:
00007 //
00008 //- Redistributions of source code must retain the above copyright
00009 //  notice, this list of conditions and the following disclaimer.
00010 //
00011 //- Redistributions in binary form must reproduce the above copyright
00012 //  notice, this list of conditions and the following disclaimer in the
00013 //  documentation and/or other materials provided with the distribution.
00014 //
00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00016 //  may be used to endorse or promote products derived from this software 
00017 //  without specific prior written permission.
00018 //
00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00022 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 //===========================================================================
00031 
00032 #include "stdafx.h"
00033 #include "abstractaudioencodeoutputpin.h"
00034 
00035 
00036 
00037 AbstractAudioEncodeOutputPin::AbstractAudioEncodeOutputPin(AbstractAudioEncodeFilter* inParentFilter, CCritSec* inFilterLock, CHAR* inObjectName, LPCWSTR inPinDisplayName, CMediaType* inOutputMediaType)
00038         :       CBaseOutputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00039                 mParentFilter(inParentFilter)
00040 
00041         ,       mDataQueue(NULL)
00042 {
00043         mOutputMediaType = inOutputMediaType;
00044 }
00045 AbstractAudioEncodeOutputPin::~AbstractAudioEncodeOutputPin(void)
00046 {       
00047         
00048         delete mDataQueue;
00049         
00050 }
00051 STDMETHODIMP AbstractAudioEncodeOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00052         if (riid == IID_IMediaSeeking) {
00053                 *ppv = (IMediaSeeking*)this;
00054                 ((IUnknown*)*ppv)->AddRef();
00055                 return NOERROR;
00056         }
00057 
00058         return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv); 
00059 }
00060 
00061 HRESULT AbstractAudioEncodeOutputPin::DecideBufferSize(IMemAllocator* inAllocator, ALLOCATOR_PROPERTIES* inPropertyRequest) {
00062         
00063         
00064         //FIX::: Abstract this out properly     
00065 
00066         HRESULT locHR = S_OK;
00067 
00068         //Create the structures for setproperties to use
00069         ALLOCATOR_PROPERTIES locReqAlloc;
00070         ALLOCATOR_PROPERTIES locActualAlloc;
00071 
00072         const unsigned long MIN_BUFFER_SIZE = 1096;                     //What should this be ????
00073         const unsigned long DEFAULT_BUFFER_SIZE = 32192;
00074         const unsigned long MIN_NUM_BUFFERS = 3;
00075         const unsigned long DEFAULT_NUM_BUFFERS = 5;
00076 
00077         
00078         //Validate and change what we have been requested to do.
00079         //Allignment of data
00080         if (inPropertyRequest->cbAlign <= 0) {
00081                 locReqAlloc.cbAlign = 1;
00082         } else {
00083                 locReqAlloc.cbAlign = inPropertyRequest->cbAlign;
00084         }
00085 
00086         if (inPropertyRequest->cbBuffer < MIN_BUFFER_SIZE) {
00087                 locReqAlloc.cbBuffer = DEFAULT_BUFFER_SIZE;
00088         } else {
00089                 locReqAlloc.cbBuffer = inPropertyRequest->cbBuffer;
00090         }
00091 
00092         if (inPropertyRequest->cbPrefix < 0) {
00093                         locReqAlloc.cbPrefix = 0;
00094         } else {
00095                 locReqAlloc.cbPrefix = inPropertyRequest->cbPrefix;
00096         }
00097 
00098         if (inPropertyRequest->cBuffers < MIN_NUM_BUFFERS) {
00099                 locReqAlloc.cBuffers = DEFAULT_NUM_BUFFERS;
00100         } else {
00101 
00102                 locReqAlloc.cBuffers = inPropertyRequest->cBuffers;
00103         }
00104 
00105         locHR = inAllocator->SetProperties(&locReqAlloc, &locActualAlloc);
00106 
00107         if (locHR != S_OK)  {
00108                 return locHR;
00109         }
00110 
00111         
00112         locHR = inAllocator->Commit();
00113 
00114         return locHR;
00115 }
00116 HRESULT AbstractAudioEncodeOutputPin::CheckMediaType(const CMediaType *inMediaType) {
00117                 if      ( (inMediaType->majortype == MEDIATYPE_Audio) &&
00118                         (inMediaType->subtype == mOutputMediaType->subtype) && (inMediaType->formattype == mOutputMediaType->formattype)
00119                 )
00120         {
00121                 return S_OK;
00122         } else {
00123                 return S_FALSE;
00124         }
00125         
00126 }
00127 
00128 HRESULT AbstractAudioEncodeOutputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00129 
00130         if (inPosition < 0) {
00131                 return E_INVALIDARG;
00132         }
00133 
00134         BYTE* locFormatBuffer = NULL;
00135         switch (inPosition) {
00136                 case 0:
00137 
00138                         outMediaType->SetType(&MEDIATYPE_Audio);
00139                         outMediaType->SetSubtype(&(mOutputMediaType->subtype));
00140                         outMediaType->SetFormatType(&(mOutputMediaType->formattype));
00141                         //
00142                         locFormatBuffer = new BYTE[FormatBufferSize()];                 //Deleted below. Is this right ? What does set format do ?
00143                         FillFormatBuffer(locFormatBuffer);
00144                         outMediaType->SetFormat(locFormatBuffer, FormatBufferSize());
00145                         delete[] locFormatBuffer;
00146                         //
00147                         return S_OK;                    
00148                 default:
00149                         return VFW_S_NO_MORE_ITEMS;
00150         }
00151 }
00152 
00153 
00154 
00155 
00156 
00157 HRESULT AbstractAudioEncodeOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
00158 {
00159         //mPartialPacket = NULL;
00160         mDataQueue->NewSegment(tStart, tStop, dRate);
00161 
00162         return S_OK;
00163 }
00164 HRESULT AbstractAudioEncodeOutputPin::DeliverEndOfStream(void)
00165 {
00166         //mPartialPacket = NULL;
00167         mDataQueue->EOS();
00168     return S_OK;
00169 }
00170 
00171 HRESULT AbstractAudioEncodeOutputPin::DeliverEndFlush(void)
00172 {
00173         mDataQueue->EndFlush();
00174     return S_OK;
00175 }
00176 
00177 HRESULT AbstractAudioEncodeOutputPin::DeliverBeginFlush(void)
00178 {
00179         //mPartialPacket = NULL;
00180         mDataQueue->BeginFlush();
00181     return S_OK;
00182 }
00183 
00184 HRESULT AbstractAudioEncodeOutputPin::CompleteConnect (IPin *inReceivePin)
00185 {
00186         HRESULT locHR = S_OK;
00187         //DELETE in DEStructor
00188         mDataQueue = new COutputQueue (inReceivePin, &locHR, FALSE, TRUE, 1, TRUE, 10);
00189         if (FAILED(locHR)) {
00190                 locHR = locHR;
00191         }
00192         
00193         return CBaseOutputPin::CompleteConnect(inReceivePin);
00194 }

Generated on Tue Feb 15 14:54:17 2005 for oggdsf by  doxygen 1.3.9