AbstractVideoEncodeOutputPin.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 #include "stdafx.h"
00032 #include "abstractvideoencodeoutputpin.h"
00033 
00034 AbstractVideoEncodeOutputPin::AbstractVideoEncodeOutputPin(AbstractVideoEncodeFilter* inParentFilter, CCritSec* inFilterLock, CHAR* inObjectName, LPCWSTR inPinDisplayName, CMediaType* inOutputMediaType)
00035         :       CBaseOutputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00036                 mParentFilter(inParentFilter)
00037 
00038         ,       mDataQueue(NULL)
00039 {
00040         mOutputMediaType = inOutputMediaType;
00041 }
00042 AbstractVideoEncodeOutputPin::~AbstractVideoEncodeOutputPin(void)
00043 {       
00044         
00045         delete mDataQueue;
00046         
00047 }
00048 
00049 STDMETHODIMP AbstractVideoEncodeOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00050         if (riid == IID_IMediaSeeking) {
00051                 *ppv = (IMediaSeeking*)this;
00052                 ((IUnknown*)*ppv)->AddRef();
00053                 return NOERROR;
00054         }
00055 
00056         return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv); 
00057 }
00058 
00059 HRESULT AbstractVideoEncodeOutputPin::DecideBufferSize(IMemAllocator* inAllocator, ALLOCATOR_PROPERTIES* inPropertyRequest) {
00060         
00061         
00062         //FIX::: Abstract this out properly     
00063 
00064         HRESULT locHR = S_OK;
00065 
00066         //Create the structures for setproperties to use
00067         ALLOCATOR_PROPERTIES locReqAlloc;
00068         ALLOCATOR_PROPERTIES locActualAlloc;
00069 
00070         const unsigned long MIN_BUFFER_SIZE = 65536;                    //What should this be ????
00071         const unsigned long DEFAULT_BUFFER_SIZE = 1024*1024;
00072         const unsigned long MIN_NUM_BUFFERS = 3;
00073         const unsigned long DEFAULT_NUM_BUFFERS = 5;
00074 
00075         
00076         //Validate and change what we have been requested to do.
00077         //Allignment of data
00078         if (inPropertyRequest->cbAlign <= 0) {
00079                 locReqAlloc.cbAlign = 1;
00080         } else {
00081                 locReqAlloc.cbAlign = inPropertyRequest->cbAlign;
00082         }
00083 
00084         if (inPropertyRequest->cbBuffer < MIN_BUFFER_SIZE) {
00085                 locReqAlloc.cbBuffer = DEFAULT_BUFFER_SIZE;
00086         } else {
00087                 locReqAlloc.cbBuffer = inPropertyRequest->cbBuffer;
00088         }
00089 
00090         if (inPropertyRequest->cbPrefix < 0) {
00091                         locReqAlloc.cbPrefix = 0;
00092         } else {
00093                 locReqAlloc.cbPrefix = inPropertyRequest->cbPrefix;
00094         }
00095 
00096         if (inPropertyRequest->cBuffers < MIN_NUM_BUFFERS) {
00097                 locReqAlloc.cBuffers = DEFAULT_NUM_BUFFERS;
00098         } else {
00099 
00100                 locReqAlloc.cBuffers = inPropertyRequest->cBuffers;
00101         }
00102 
00103         locHR = inAllocator->SetProperties(&locReqAlloc, &locActualAlloc);
00104 
00105         if (locHR != S_OK)  {
00106                 return locHR;
00107         }
00108 
00109         
00110         locHR = inAllocator->Commit();
00111 
00112         return locHR;
00113 }
00114 HRESULT AbstractVideoEncodeOutputPin::CheckMediaType(const CMediaType *inMediaType) {
00115                 if      ( (inMediaType->majortype == MEDIATYPE_Video) &&
00116                         (inMediaType->subtype == mOutputMediaType->subtype) && (inMediaType->formattype == mOutputMediaType->formattype)
00117                 )
00118         {
00119                 return S_OK;
00120         } else {
00121                 return S_FALSE;
00122         }
00123         
00124 }
00125 
00126 HRESULT AbstractVideoEncodeOutputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00127 
00128         
00129         if (inPosition < 0) {
00130                 return E_INVALIDARG;
00131         }
00132 
00133         BYTE* locFormatBuffer = NULL;
00134         switch (inPosition) {
00135                 case 0:
00136 
00137                         outMediaType->SetType(&MEDIATYPE_Video);
00138                         outMediaType->SetSubtype(&(mOutputMediaType->subtype));
00139                         outMediaType->SetFormatType(&(mOutputMediaType->formattype));
00140                         //FillFormatBuffer(outMediaType->pbformat);
00141                         //
00142                         locFormatBuffer = new BYTE[FormatBufferSize()];
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 AbstractVideoEncodeOutputPin::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 AbstractVideoEncodeOutputPin::DeliverEndOfStream(void)
00165 {
00166         //mPartialPacket = NULL;
00167         mDataQueue->EOS();
00168     return S_OK;
00169 }
00170 
00171 HRESULT AbstractVideoEncodeOutputPin::DeliverEndFlush(void)
00172 {
00173         mDataQueue->EndFlush();
00174     return S_OK;
00175 }
00176 
00177 HRESULT AbstractVideoEncodeOutputPin::DeliverBeginFlush(void)
00178 {
00179         //mPartialPacket = NULL;
00180         mDataQueue->BeginFlush();
00181     return S_OK;
00182 }
00183 
00184 HRESULT AbstractVideoEncodeOutputPin::CompleteConnect (IPin *inReceivePin)
00185 {
00186         HRESULT locHR = S_OK;
00187         //DELETE in DEStructor
00188         mDataQueue = new COutputQueue (inReceivePin, &locHR, FALSE, TRUE, 1, TRUE, 25);
00189         if (FAILED(locHR)) {
00190                 locHR = locHR;
00191         }
00192         
00193         return CBaseOutputPin::CompleteConnect(inReceivePin);
00194 }

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