CMMLSourcePin.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Copyright (C) 2003, 2004 Commonwealth Scientific and Industrial Research
00005 //   Organisation (CSIRO) Australia
00006 //
00007 //Redistribution and use in source and binary forms, with or without
00008 //modification, are permitted provided that the following conditions
00009 //are met:
00010 //
00011 //- Redistributions of source code must retain the above copyright
00012 //  notice, this list of conditions and the following disclaimer.
00013 //
00014 //- Redistributions in binary form must reproduce the above copyright
00015 //  notice, this list of conditions and the following disclaimer in the
00016 //  documentation and/or other materials provided with the distribution.
00017 //
00018 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00019 //  may be used to endorse or promote products derived from this software 
00020 //  without specific prior written permission.
00021 //
00022 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00026 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 //===========================================================================
00034 
00035 #include "stdafx.h"
00036 #include "cmmlsourcepin.h"
00037 
00038 CMMLSourcePin::CMMLSourcePin(   TCHAR* inObjectName, 
00039                                                                                 OggDemuxSourceFilter* inParentFilter,
00040                                                                                 CCritSec* inFilterLock,
00041                                                                                 StreamHeaders* inHeaderSource, 
00042                                                                                 CMediaType* inMediaType,
00043                                                                                 wstring inPinName,
00044                                                                                 unsigned long inNumBuffers,
00045                                                                                 unsigned long inBufferSize) 
00046                 :       OggDemuxSourcePin(inObjectName, inParentFilter, inFilterLock, inHeaderSource, inMediaType, inPinName, true, inNumBuffers, inBufferSize)
00047 {
00048         //debugLog.open("G:\\logs\\cmml_source_pin.log", ios_base::out);
00049 }
00050 
00051 CMMLSourcePin::~CMMLSourcePin(void)
00052 {
00053 }
00054 
00055 
00056 STDMETHODIMP CMMLSourcePin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00057 {
00058         if (riid == IID_IMediaSeeking) {
00059                 *ppv = (IMediaSeeking*)this;
00060                 ((IUnknown*)*ppv)->AddRef();
00061                 return NOERROR;
00062         }
00063 
00064         return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv); 
00065 }
00066 STDMETHODIMP CMMLSourcePin::Render(IPin* inOutputPin, IGraphBuilder* inGraphBuilder) {
00067         if (inOutputPin == NULL || inGraphBuilder == NULL) {
00068                 return E_POINTER;
00069         }
00070 
00071         
00072     IBaseFilter* locCMMLFilter = NULL;
00073 
00074 
00075 
00076     HRESULT locHR = S_OK;
00077         //locHR = inGraphBuilder->FindFilterByName(L"CMML Decode Filter", &locRenderer);
00078         if (locCMMLFilter == NULL) {
00079                 locHR= CoCreateInstance(CLSID_CMMLDecodeFilter, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&locCMMLFilter);
00080                 if (locHR != S_OK) {
00081                 return locHR;
00082             }
00083     
00084             locHR = inGraphBuilder->AddFilter(locCMMLFilter, L"CMML Decode Filter");
00085             if (locHR != S_OK) {
00086                         locCMMLFilter->Release();
00087                         return locHR;
00088                 }
00089         }
00090 
00091         IEnumPins* locEnumPins;
00092         IPin* locCMMLInputPin = NULL;
00093         locHR = locCMMLFilter->EnumPins(&locEnumPins);
00094 
00095         if (SUCCEEDED(locHR)) {
00096                 if (S_OK != locEnumPins->Next(1, &locCMMLInputPin, 0)) {
00097                         locHR = E_UNEXPECTED;
00098                 }
00099         }
00100 
00101         if (SUCCEEDED(locHR)) {
00102                 // CConnect VMR9 to the output of the theora decoder
00103                 //CMediaType* locMediaType = new CMediaType;
00104                 //
00105                 //FillMediaType(locMediaType);
00107                 //VIDEOINFOHEADER* locVideoFormat = (VIDEOINFOHEADER*)locMediaType->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
00108                 //FillVideoInfoHeader(locVideoFormat);
00109                 locHR = inGraphBuilder->ConnectDirect(inOutputPin, locCMMLInputPin, mMediaType);
00110                 locCMMLInputPin->Release();
00111         }
00112         if (FAILED(locHR)) 
00113         {
00114                 
00115                 inGraphBuilder->RemoveFilter(locCMMLFilter);
00116         }
00117         locCMMLFilter->Release();
00118         
00119     return locHR;
00120 
00121 
00122 }
00123 STDMETHODIMP CMMLSourcePin::Backout(IPin* inOutputPin, IGraphBuilder* inGraphBuilder) {
00124    //HRESULT locHR = S_OK;
00125    // if (m_Connected != NULL) // Pointer to the pin we're connected to.
00126    // {
00127    //     // Find the filter that owns the pin connected to us.
00128    //     FILTER_INFO fi;
00129    //     hr = m_Connected->QueryFilterInfo(&fi);
00130    //     if (SUCCEEDED(hr)) 
00131    //     {
00132    //         if (fi.pFilter != NULL) 
00133    //         {
00134    //             //  Disconnect the pins.
00135    //             pGraph->Disconnect(m_Connected);
00136    //             pGraph->Disconnect(pPin);
00137    //             // Remove the filter from the graph.
00138    //             pGraph->RemoveFilter(fi.pFilter);
00139    //             fi.pFilter->Release();
00140    //         } 
00141    //         else 
00142    //         {
00143    //             hr = E_UNEXPECTED;
00144    //         }
00145    //     }
00146    // }
00147    // return hr;
00148         return S_OK;
00149 }
00150 
00151 bool CMMLSourcePin::deliverOggPacket(StampedOggPacket* inPacket) {
00152 
00153         //Modified from the base class so that the times are multiplied by a scaling factor... curently 10000.
00154         //TODO::: When you properly save annodex header information, you need to account for other time schemes.
00155         //Probably issues for -1 gran pos here too.
00156         CAutoLock locStreamLock(mParentFilter->mStreamLock);
00157         IMediaSample* locSample = NULL;
00158         REFERENCE_TIME locStart = inPacket->endTime() * 10000;   //CMML Changes here.
00159         REFERENCE_TIME locStop = inPacket->endTime() * 10000;
00160         //debugLog<<"Start   : "<<locStart<<endl;
00161         //debugLog<<"End     : "<<locStop<<endl;
00162         DbgLog((LOG_TRACE, 2, "Getting Buffer in Source Pin..."));
00163         //DbgLog((LOG_TRACE, 2, ""));
00164 
00165         HRESULT locHR = GetDeliveryBuffer(&locSample, &locStart, &locStop, NULL);
00166         DbgLog((LOG_TRACE, 2, "* After get Buffer in Source Pin..."));
00167         //Error checks
00168         if (locHR != S_OK) {
00169                 DbgLog((LOG_TRACE, 2, "Getting Delivery Buff FAILED"));
00170                 //Stopping, fluching or error
00171                 //debugLog<<"Failure... No buffer"<<endl;
00172                 return false;
00173         }
00174 
00175         //More hacks so we can send a timebase after a seek, since granule pos in theora
00176         // is not convertible in both directions to time.
00177         
00178         //TIMESTAMP FIXING !
00179         locSample->SetTime(&locStart, &locStop);
00180         
00181         //Yes this is way dodgy !
00182         locSample->SetMediaTime(&mParentFilter->mSeekTimeBase, &mParentFilter->mSeekTimeBase);
00183         locSample->SetSyncPoint(TRUE);
00184         
00185 
00186         // Create a pointer for the samples buffer
00187         BYTE* locBuffer = NULL;
00188         locSample->GetPointer(&locBuffer);
00189 
00190         if (locSample->GetSize() >= inPacket->packetSize()) {
00191 
00192                 memcpy((void*)locBuffer, (const void*)inPacket->packetData(), inPacket->packetSize());
00193                 locSample->SetActualDataLength(inPacket->packetSize());
00194 
00195                 locHR = mDataQueue->Receive(locSample);
00196                 
00197                 if (locHR != S_OK) {
00198                         //debugLog << "Failure... Queue rejected sample..."<<endl;
00199                         //Stopping ??
00200                         return false;
00201                         
00202                 } else {
00203                         //debugLog<<"Delivery OK"<<endl;
00204                         return true;
00205                 }
00206         } else {
00207                 throw 0;
00208         }
00209 }

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