AbstractVideoDecodeOutputPin.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 "abstractVideodecodeoutputpin.h"
00034 
00035 AbstractVideoDecodeOutputPin::AbstractVideoDecodeOutputPin(AbstractVideoDecodeFilter* inParentFilter, CCritSec* inFilterLock, CHAR* inObjectName, LPCWSTR inPinDisplayName)
00036         :       CBaseOutputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00037                 mParentFilter(inParentFilter)
00038         ,       mDataQueue(NULL)
00039 {
00040         //debugLog.open("g:\\logs\\absvidlog.log", ios_base::out|ios_base::binary);
00041 }
00042 AbstractVideoDecodeOutputPin::~AbstractVideoDecodeOutputPin(void)
00043 {
00044         //debugLog.close();
00045         
00046         delete mDataQueue;
00047         mDataQueue = NULL;
00048 }
00049 
00050 STDMETHODIMP AbstractVideoDecodeOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00051         //debugLog<<"QueryInterface : {"<<riid.Data1<<"-"<<riid.Data2<<"-"<<riid.Data3<<"-"<<riid.Data4<<"}"<<endl;
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 HRESULT AbstractVideoDecodeOutputPin::DecideBufferSize(IMemAllocator* inAllocator, ALLOCATOR_PROPERTIES* inPropertyRequest) {
00061         
00062         //debugLog<<endl;
00063         
00064         
00065         //FIX::: Abstract this out properly     
00066 
00067         //debugLog<<"Allocator is "<<(unsigned long)inAllocator<<endl;
00068         //Our error variable
00069         HRESULT locHR = S_OK;
00070 
00071         //Create the structures for setproperties to use
00072         ALLOCATOR_PROPERTIES locReqAlloc;
00073         ALLOCATOR_PROPERTIES locActualAlloc;
00074 
00075         //debugLog<<"DecideBufferSize : Requested :"<<endl;
00076         //debugLog<<"DecideBufferSize : Align     : "<<inPropertyRequest->cbAlign<<endl;
00077         //debugLog<<"DecideBufferSize : BuffSize  : "<<inPropertyRequest->cbBuffer<<endl;
00078         //debugLog<<"DecideBufferSize : Prefix    : "<<inPropertyRequest->cbPrefix<<endl;
00079         //debugLog<<"DecideBufferSize : NumBuffs  : "<<inPropertyRequest->cBuffers<<endl;
00080 
00081 
00082         const unsigned long MIN_BUFFER_SIZE = 16*16;                    //What should this be ????
00083         const unsigned long DEFAULT_BUFFER_SIZE = 1024*1024;
00084         const unsigned long MIN_NUM_BUFFERS = 1;
00085         const unsigned long DEFAULT_NUM_BUFFERS = 1;
00086 
00087         
00088         //Validate and change what we have been requested to do.
00089         //Allignment of data
00090         if (inPropertyRequest->cbAlign <= 0) {
00091                 locReqAlloc.cbAlign = 1;
00092         } else {
00093                 locReqAlloc.cbAlign = inPropertyRequest->cbAlign;
00094         }
00095 
00096         //Size of each buffer
00097         if (inPropertyRequest->cbBuffer < MIN_BUFFER_SIZE) {
00098                 locReqAlloc.cbBuffer = DEFAULT_BUFFER_SIZE;
00099         } else {
00100                 locReqAlloc.cbBuffer = inPropertyRequest->cbBuffer;
00101         }
00102 
00103         //How many prefeixed bytes
00104         if (inPropertyRequest->cbPrefix < 0) {
00105                         locReqAlloc.cbPrefix = 0;
00106         } else {
00107                 locReqAlloc.cbPrefix = inPropertyRequest->cbPrefix;
00108         }
00109 
00110         //Number of buffers in the allcoator
00111         if (inPropertyRequest->cBuffers < MIN_NUM_BUFFERS) {
00112                 locReqAlloc.cBuffers = DEFAULT_NUM_BUFFERS;
00113         } else {
00114 
00115                 locReqAlloc.cBuffers = inPropertyRequest->cBuffers;
00116         }
00117 
00118         //debugLog<<"DecideBufferSize : Modified Request :"<<endl;
00119         //debugLog<<"DecideBufferSize : Align     : "<<locReqAlloc.cbAlign<<endl;
00120         //debugLog<<"DecideBufferSize : BuffSize  : "<<locReqAlloc.cbBuffer<<endl;
00121         //debugLog<<"DecideBufferSize : Prefix    : "<<locReqAlloc.cbPrefix<<endl;
00122         //debugLog<<"DecideBufferSize : NumBuffs  : "<<locReqAlloc.cBuffers<<endl;
00123 
00124 
00125         //Set the properties in the allocator
00126         locHR = inAllocator->SetProperties(&locReqAlloc, &locActualAlloc);
00127 
00128         //debugLog<<"DecideBufferSize : SetProperties returns "<<locHR<<endl;
00129         //debugLog<<"DecideBufferSize : Actual Params :"<<endl;
00130         //debugLog<<"DecideBufferSize : Align     : "<<locActualAlloc.cbAlign<<endl;
00131         //debugLog<<"DecideBufferSize : BuffSize  : "<<locActualAlloc.cbBuffer<<endl;
00132         //debugLog<<"DecideBufferSize : Prefix    : "<<locActualAlloc.cbPrefix<<endl;
00133         //debugLog<<"DecideBufferSize : NumBuffs  : "<<locActualAlloc.cBuffers<<endl;
00134 
00135         //Check the response
00136         switch (locHR) {
00137                 case E_POINTER:
00138                         //debugLog<<"DecideBufferSize : SetProperties - NULL POINTER"<<endl;
00139                         return locHR;
00140                         
00141 
00142                 case VFW_E_ALREADY_COMMITTED:
00143                         //debugLog<<"DecideBufferSize : SetProperties - Already COMMITED"<<endl;
00144                         return locHR;
00145                         
00146                 case VFW_E_BADALIGN:
00147                         //debugLog<<"DecideBufferSize : SetProperties - Bad ALIGN"<<endl;
00148                         return locHR;
00149                         
00150                 case VFW_E_BUFFERS_OUTSTANDING:
00151                         //debugLog<<"DecideBufferSize : SetProperties - BUFFS OUTSTANDING"<<endl;
00152                         return locHR;
00153                         
00154 
00155                 case S_OK:
00156 
00157                         break;
00158                 default:
00159                         //debugLog<<"DecideBufferSize : SetProperties - UNKNOWN ERROR"<<endl;
00160                         break;
00161 
00162         }
00163 
00164         
00165         //TO DO::: Do we commit ?
00166         //RESOLVED ::: Yep !
00167         
00168         locHR = inAllocator->Commit();
00169         //debugLog<<"DecideBufferSize : Commit Returned "<<locHR<<endl;
00170 
00171 
00172         switch (locHR) {
00173                 case E_FAIL:
00174                         //debugLog<<"DecideBufferSize : Commit - FAILED "<<endl;
00175                         return locHR;
00176                 case E_POINTER:
00177                         //debugLog<<"DecideBufferSize : Commit - NULL POINTER "<<endl;
00178                         return locHR;
00179                 case E_INVALIDARG:
00180                         //debugLog<<"DecideBufferSize : Commit - INVALID ARG "<<endl;
00181                         return locHR;
00182                 case E_NOTIMPL:
00183                         //debugLog<<"DecideBufferSize : Commit - NOT IMPL"<<endl;
00184                         return locHR;
00185                 case S_OK:
00186                         //debugLog<<"DecideBufferSize : Commit - ** SUCCESS **"<<endl;
00187                         break;
00188                 default:
00189                         //debugLog<<"DecideBufferSize : Commit - UNKNOWN ERROR "<<endl;
00190                         return locHR;
00191         }
00192 
00193 
00194         return S_OK;
00195 }
00196 HRESULT AbstractVideoDecodeOutputPin::CheckMediaType(const CMediaType *inMediaType) {
00197         //debugLog<<"CheckMediaType : "<<endl;
00198         if ((inMediaType->majortype == MEDIATYPE_Video) && (inMediaType->subtype == MEDIASUBTYPE_YV12) && (inMediaType->formattype == FORMAT_VideoInfo)) {
00199                 
00200                 //FIX::: SHould this stuff be in a check routine ??? Shouldn't it be in set mediatype ?
00201 
00202                 //debugLog << "CheckMediaType : Accepting..."<<endl;
00203         
00204                 VIDEOINFOHEADER* locVideoHeader = (VIDEOINFOHEADER*)inMediaType->Format();
00205                 //debugLog << "CheckMediaType : Height = " << locVideoHeader->bmiHeader.biHeight<<endl;
00206                 //debugLog << "CheckMediaType : Width  = " << locVideoHeader->bmiHeader.biWidth<<endl;
00207                 //debugLog << "CheckMediaType : Size = "<<locVideoHeader->bmiHeader.biSizeImage<<endl<<endl;
00208                 //debugLog << "CheckMediaType : mHeight was = " << mParentFilter->mInputPin->mHeight<<endl;
00209                 //debugLog << "CheckMediaType : mWidth  was = " << mParentFilter->mInputPin->mWidth<<endl<<endl;
00210                 //debugLog<<"CheckMediaType : Size was = "<<mParentFilter->mInputPin->mFrameSize<<endl<<endl;
00211                 mParentFilter->mInputPin->mHeight = (unsigned long)abs(locVideoHeader->bmiHeader.biHeight);
00212                 mParentFilter->mInputPin->mWidth = (unsigned long)abs(locVideoHeader->bmiHeader.biWidth);
00213                 mParentFilter->mInputPin->mFrameSize = (unsigned long)locVideoHeader->bmiHeader.biSizeImage;
00214                 //debugLog<<"CheckMediaType : SUCCESS"<<endl;
00215                 
00216                 return S_OK;
00217         } else {
00218                 //debugLog<<"CheckMediaType : FAILURE"<<endl;
00219                 return S_FALSE;
00220         }
00221         
00222 }
00223 
00224 void AbstractVideoDecodeOutputPin::FillMediaType(CMediaType* outMediaType) {
00225         outMediaType->SetType(&MEDIATYPE_Video);
00226         outMediaType->SetSubtype(&MEDIASUBTYPE_YV12);
00227         outMediaType->SetFormatType(&FORMAT_VideoInfo);
00228         outMediaType->SetTemporalCompression(FALSE);
00229         outMediaType->SetSampleSize(0);         
00230 
00231 }
00232 HRESULT AbstractVideoDecodeOutputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00233         
00234         if (inPosition < 0) {
00235                 return E_INVALIDARG;
00236         }
00237         
00238         if (inPosition == 0) {
00239                 FillMediaType(outMediaType);
00240                 VIDEOINFOHEADER* locVideoFormat = (VIDEOINFOHEADER*)outMediaType->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
00241                 FillVideoInfoHeader(locVideoFormat);
00242                 
00243                 //debugLog<<"Vid format size "<<locVideoFormat->bmiHeader.biSizeImage<<endl;
00244                 outMediaType->SetSampleSize(locVideoFormat->bmiHeader.biSizeImage);
00245                 //debugLog<<"Returning from GetMediaType"<<endl;
00246                 return S_OK;
00247         } else {
00248                 return VFW_S_NO_MORE_ITEMS;
00249         }
00250 }
00251 
00252 
00253 //Overriden for a data queue
00254 HRESULT AbstractVideoDecodeOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
00255 {
00256         //mPartialPacket = NULL;
00257         //debugLog << "DeliverNewSegment: start"<<endl;
00258         CBasePin::NewSegment(tStart, tStop, dRate);
00259         mDataQueue->NewSegment(tStart, tStop, dRate);
00260         //debugLog << "DeliverNewSegment: end"<<endl;
00261 
00262         return S_OK;
00263 }
00264 HRESULT AbstractVideoDecodeOutputPin::DeliverEndOfStream(void)
00265 {
00266         //debugLog << "DeliverEndOfStream: executed" << endl;
00267         //mPartialPacket = NULL;
00268         mDataQueue->EOS();
00269     return S_OK;
00270 }
00271 
00272 HRESULT AbstractVideoDecodeOutputPin::DeliverEndFlush(void)
00273 {
00274         //debugLog << "DeliverEndFlush" << endl;
00275         mDataQueue->EndFlush();
00276     return S_OK;
00277 }
00278 
00279 HRESULT AbstractVideoDecodeOutputPin::DeliverBeginFlush(void)
00280 {
00281         //mPartialPacket = NULL;
00282         //debugLog << "DeliverBeginFlush"<<endl;
00283         mDataQueue->BeginFlush();
00284     return S_OK;
00285 }
00286 
00287 HRESULT AbstractVideoDecodeOutputPin::CompleteConnect (IPin *inReceivePin)
00288 {
00289         //debugLog<<"ComlpeteConnect"<<endl;
00290         HRESULT locHR = S_OK;
00291 
00292         //Here when another pin connects to us, we internally connect the seek delegate
00293         // from this output pin onto the input pin... and we release it on breakconnect.
00294         //
00295         IMediaSeeking* locSeeker = NULL;
00296         mParentFilter->mInputPin->NonDelegatingQueryInterface(IID_IMediaSeeking, (void**)&locSeeker);
00297         SetDelegate(locSeeker);
00298         //
00299         //This may cause issue if pins are disconnected and reconnected
00300         //DELETE in DEStructor
00301         mDataQueue = new COutputQueue (inReceivePin, &locHR, FALSE, TRUE, 1, TRUE, 15);                 //deleted in destructor
00302         if (FAILED(locHR)) {
00303                 //debugLog<<"Creating Output Q failed."<<endl;
00304                 locHR = locHR;
00305         }
00306         
00307         return CBaseOutputPin::CompleteConnect(inReceivePin);
00308 }
00309 
00310 HRESULT AbstractVideoDecodeOutputPin::BreakConnect(void) {
00311         //debugLog<<"Break Connect"<<endl;
00312         //CAutoLock locLock(mFilterLock);
00313         HRESULT locHR = CBaseOutputPin::BreakConnect();
00314         //debugLog<<"Base BreakConnect returns "<<locHR<<endl;
00315         ReleaseDelegate();
00316         delete mDataQueue;
00317         mDataQueue = NULL;
00318         return locHR;
00319 }
00320 
00321 //Testing
00322 HRESULT AbstractVideoDecodeOutputPin::InitAllocator(IMemAllocator **ppAlloc) {
00323         //debugLog<<"InitAllocator Called"<<endl;
00324         HRESULT locHR = CBaseOutputPin::InitAllocator(ppAlloc);
00325         //debugLog<<"Base InitAlloc returns "<<locHR<<endl;
00326         return locHR;
00327 }
00328 
00329 HRESULT AbstractVideoDecodeOutputPin::SetMediaType(const CMediaType *pmt) {
00330         //debugLog<<"SETTING MEDIA TYPE"<<endl;
00331         HRESULT locHR = CBaseOutputPin::SetMediaType(pmt);
00332         //debugLog<<"ase SetMedia Type returns "<<locHR<<endl;
00333         return locHR;
00334 }

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