CMMLRawSourcePin.cpp

Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include ".\cmmlrawsourcepin.h"
00003 
00004 CMMLRawSourcePin::CMMLRawSourcePin(CMMLRawSourceFilter* inParentFilter, CCritSec* inFilterLock)
00005         :       CBaseOutputPin(NAME("CMML Raw Source Pin"), inParentFilter, inFilterLock, &mFilterHR, L"CMML Source")
00006         ,       mDataQueue(NULL)
00007         ,       mLastTime(0)
00008 
00009 
00010 {
00011         mCMMLFormatBlock.granuleDenominator = 1;
00012         mCMMLFormatBlock.granuleNumerator = 1000;
00013 #ifdef OGGCODECS_LOGGING
00014         debugLog.open("G:\\logs\\cmmlrawsource.log", ios_base::out);
00015 #endif
00016 }
00017 
00018 CMMLRawSourcePin::~CMMLRawSourcePin(void)
00019 {
00020         debugLog.close();
00021 }
00022 
00023 STDMETHODIMP CMMLRawSourcePin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00024 {
00025         
00026         return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv); 
00027 }
00028 
00029 HRESULT CMMLRawSourcePin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
00030 {
00031         
00032         mDataQueue->NewSegment(tStart, tStop, dRate);
00033 
00034         return S_OK;
00035 }
00036 HRESULT CMMLRawSourcePin::DeliverEndOfStream(void)
00037 {
00038         
00039         mDataQueue->EOS();
00040     return S_OK;
00041 }
00042 
00043 HRESULT CMMLRawSourcePin::DeliverEndFlush(void)
00044 {
00045         CAutoLock locLock(m_pLock);
00046         mDataQueue->EndFlush();
00047     return S_OK;
00048 }
00049 
00050 HRESULT CMMLRawSourcePin::DeliverBeginFlush(void)
00051 {
00052         CAutoLock locLock(m_pLock);
00053         mDataQueue->BeginFlush();
00054     return S_OK;
00055 }
00056 
00057 HRESULT CMMLRawSourcePin::CompleteConnect (IPin *inReceivePin)
00058 {
00059         CAutoLock locLock(m_pLock);
00060         mFilterHR = S_OK;
00061         //Set the delegate for seeking
00062         //((BasicSeekable*)(inReceivePin))->SetDelegate(this);
00063         //This may cause issue if pins are disconnected and reconnected
00064         //DELETE in DEStructor
00065         mDataQueue = new COutputQueue (inReceivePin, &mFilterHR, FALSE, TRUE,1,TRUE, NUM_BUFFERS);
00066         if (FAILED(mFilterHR)) {
00067                 mFilterHR = mFilterHR;
00068         }
00069         
00070         return CBaseOutputPin::CompleteConnect(inReceivePin);
00071 }
00072 
00073 HRESULT CMMLRawSourcePin::BreakConnect(void) {
00074         CAutoLock locLock(m_pLock);
00075         delete mDataQueue;
00076         mDataQueue = NULL;
00077         return CBaseOutputPin::BreakConnect();
00078 }
00079 
00080         //CSourceStream virtuals
00081 HRESULT CMMLRawSourcePin::GetMediaType(int inPosition, CMediaType* outMediaType) {
00082         //Put it in from the info we got in the constructor.
00083         //NOTE::: May have missed some fields ????
00084         //NOTE::: May want to check for null pointers
00085         //outMediaType->SetFormat(mMediaType->Format(), mMediaType->FormatLength());
00086         if (inPosition == 0) {
00087                 CMediaType locMediaType;
00088 
00089                 locMediaType.majortype = MEDIATYPE_Text;
00090                 locMediaType.subtype = MEDIASUBTYPE_CMML;
00091                 locMediaType.formattype = FORMAT_CMML;
00092 
00093                 BYTE* locFB = locMediaType.AllocFormatBuffer(sizeof(sCMMLFormatBlock)); //0;//sizeof(sSpeexFormatBlock);
00094 
00095                 //locMediaType.pbFormat = (BYTE*)&mCMMLFormatBlock; //(BYTE*)locSpeexFormatInfo;
00096                 memcpy((void*)locFB, (const void*)&mCMMLFormatBlock, sizeof(sCMMLFormatBlock));
00097                 locMediaType.pUnk = NULL;
00098                 *outMediaType = locMediaType;
00099                 return S_OK;
00100         } else {
00101                 return VFW_S_NO_MORE_ITEMS;
00102         }
00103 }
00104 HRESULT CMMLRawSourcePin::CheckMediaType(const CMediaType* inMediaType) {
00105         if ((inMediaType->majortype == MEDIATYPE_Text) && (inMediaType->subtype == MEDIASUBTYPE_CMML) && (inMediaType->formattype == FORMAT_CMML)) {
00106                 return S_OK;
00107         } else {
00108                 return E_FAIL;
00109         }
00110 }
00111 HRESULT CMMLRawSourcePin::DecideBufferSize(IMemAllocator* inoutAllocator, ALLOCATOR_PROPERTIES* inoutInputRequest) {
00112 
00113         HRESULT locHR = S_OK;
00114 
00115         ALLOCATOR_PROPERTIES locReqAlloc;
00116         ALLOCATOR_PROPERTIES locActualAlloc;
00117 
00118 
00119         locReqAlloc.cbAlign = 1;
00120         locReqAlloc.cbBuffer = BUFFER_SIZE;
00121         locReqAlloc.cbPrefix = 0;
00122         locReqAlloc.cBuffers = NUM_BUFFERS;
00123 
00124         locHR = inoutAllocator->SetProperties(&locReqAlloc, &locActualAlloc);
00125 
00126         if (locHR != S_OK) {
00127                 return locHR;
00128         }
00129         
00130         locHR = inoutAllocator->Commit();
00131 
00132         return locHR;
00133 
00134 }
00135 
00136 
00137 HRESULT CMMLRawSourcePin::deliverTag(C_CMMLTag* inTag) {
00138 
00139         IMediaSample* locSample = NULL;
00140         REFERENCE_TIME locStart = 0;
00141         REFERENCE_TIME locStop = 0;
00142 
00143         HRESULT locHR = GetDeliveryBuffer(&locSample, NULL, NULL, NULL);
00144 
00145 
00146         if (locHR != S_OK) {
00147                 //debugLog<<"Failure... No buffer"<<endl;
00148                 return locHR;
00149         }
00150 
00151         BYTE* locOutBuffer = NULL;
00152         locHR = locSample->GetPointer(&locOutBuffer);
00153 
00154         if (locHR != S_OK) {
00155                 //debugLog<<"Failure... No buffer"<<endl;
00156                 return locHR;
00157         }
00158 
00159         wstring locStr = inTag->toString();
00160 
00161         
00162         //TODO::: For now, this narrowfies the string... to ascii, instead of sending
00163         // 2 byte chars.
00164 
00165         string locNarrowStr = StringHelper::toNarrowStr(locStr);
00166 
00167         memcpy((void*)locOutBuffer, (const void*)locNarrowStr.c_str(), locNarrowStr.size());
00168 
00169         if (inTag->tagType() == C_CMMLTag::CLIP) {
00170                 C_ClipTag* locClip = (C_ClipTag*)inTag;
00171                 C_TimeStamp locStartStamp;
00172                 locStartStamp.parseTimeStamp(StringHelper::toNarrowStr(locClip->start()));
00173                 //locStart = StringHelper::stringToNum(StringHelper::toNarrowStr(locClip->start())) * 1000ULL;
00174                 if ((ANX_VERSION_MAJOR == 2) && (ANX_VERSION_MINOR == 0)) {
00175                         locStart = locStartStamp.toHunNanos() / 10000;
00176                 } else if ((ANX_VERSION_MAJOR == 3) && (ANX_VERSION_MINOR == 0)) {
00177                         locStart = (mLastTime << 32) + ((locStartStamp.toHunNanos() - mLastTime) / 10000);
00178                         
00179                 } else {
00180                         //If you are here... you set the constants in the header file wrong
00181                         throw 0;
00182                 }
00183                 
00184                 
00185                 //TODO::: Do something better for handling of end times !!!!!!!!!!!!!!!!!!!!!!
00186 
00187                 C_TimeStamp locEndStamp;
00188                 locEndStamp.parseTimeStamp(StringHelper::toNarrowStr(locClip->start()));
00189                 if ((ANX_VERSION_MAJOR == 2) && (ANX_VERSION_MINOR == 0)) {
00190                         locStop = locEndStamp.toHunNanos() / 10000;
00191                 } else if ((ANX_VERSION_MAJOR == 3) && (ANX_VERSION_MINOR == 0)) {
00192                         locStop = (mLastTime << 32) + ((locEndStamp.toHunNanos() - mLastTime) / 10000);
00193                 } else {
00194                         //If you are here you set the constants in the header file wrong
00195                         throw 0;
00196                 }
00197 
00198                 mLastTime = locStartStamp.toHunNanos() / 10000;
00199                 //locStop = StringHelper::stringToNum(StringHelper::toNarrowStr(locClip->start())) * 1000ULL;
00200                 
00201 
00202         }
00203 
00204         debugLog<<"Tag time = "<<locStart<<" - "<<locStop<<endl;
00205         debugLog<<locNarrowStr<<endl<<endl;
00206         locSample->SetActualDataLength((long)locNarrowStr.size());
00207         locSample->SetTime(&locStart, &locStop);
00208         locSample->SetMediaTime(NULL, NULL);
00209         locSample->SetDiscontinuity(FALSE);
00210         locSample->SetSyncPoint(TRUE);
00211 
00212         locHR = Deliver(locSample);
00213 
00214         int x = locSample->Release();
00215         return locHR;
00216 
00217 
00218 }

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