CMMLRawSourceFilter.cpp

Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include ".\cmmlrawsourcefilter.h"
00003 
00004 CFactoryTemplate g_Templates[] = 
00005 {
00006     { 
00007                 L"CMMLRawDemuxFilter",                                          // Name
00008             &CLSID_CMMLRawSourceFilter,            // CLSID
00009             CMMLRawSourceFilter::CreateInstance,        // Method to create an instance of MyComponent
00010         NULL,                                                                   // Initialization function
00011         NULL                                                                    // Set-up information (for filters)
00012     }
00013 
00014 };
00015 
00016 // Generic way of determining the number of items in the template
00017 int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); 
00018 
00019 
00020 CUnknown* WINAPI CMMLRawSourceFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 
00021 {
00022         CMMLRawSourceFilter *pNewObject = new CMMLRawSourceFilter();
00023     if (pNewObject == NULL) {
00024         *pHr = E_OUTOFMEMORY;
00025     }
00026     return pNewObject;
00027 } 
00028 
00029 STDMETHODIMP CMMLRawSourceFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00030 {
00031         if (riid == IID_IFileSourceFilter) {
00032                 *ppv = (IFileSourceFilter*)this;
00033                 ((IUnknown*)*ppv)->AddRef();
00034                 return NOERROR;
00035         }
00036         return CBaseFilter::NonDelegatingQueryInterface(riid, ppv); 
00037 }
00038 
00039 CMMLRawSourceFilter::CMMLRawSourceFilter(void)
00040         :       CBaseFilter(NAME("CMMLRawSourceFilter"), NULL, m_pLock, CLSID_CMMLRawSourceFilter)
00041         ,       mCMMLDoc(NULL)
00042         ,       mUptoTag(0)
00043 {
00044         m_pLock = new CCritSec;
00045         mCMMLSourcePin = new CMMLRawSourcePin(          this
00046                                                                                         ,       this->m_pLock);
00047 
00048 
00049 
00050 }
00051 
00052 CMMLRawSourceFilter::~CMMLRawSourceFilter(void)
00053 {
00054 
00055         delete mCMMLSourcePin;
00056         delete mCMMLDoc;
00057         delete m_pLock;
00058 }
00059 
00060 //BaseFilter Interface
00061 int CMMLRawSourceFilter::GetPinCount() {
00062         return 1;
00063 }
00064 CBasePin* CMMLRawSourceFilter::GetPin(int inPinNo) {
00065 
00066         if (inPinNo == 0) {
00067                 return mCMMLSourcePin;
00068         } else {
00069                 return NULL;
00070         }
00071 }
00072 
00073 //IAMFilterMiscFlags Interface
00074 ULONG CMMLRawSourceFilter::GetMiscFlags(void) {
00075         return AM_FILTER_MISC_FLAGS_IS_SOURCE;
00076 }
00077 
00078         //IFileSource Interface
00079 STDMETHODIMP CMMLRawSourceFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) {
00080         //Return the filename and mediatype of the raw data
00081 
00082          
00083         LPOLESTR x = SysAllocString(mFileName.c_str());
00084         *outFileName = x;
00085         
00086         return S_OK;
00087 }
00088 
00089 //ANX::: Seek table will need modifying to handle this.
00090 STDMETHODIMP CMMLRawSourceFilter::Load(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inMediaType) {
00091         //Initialise the file here and setup all the streams
00092         CAutoLock locLock(m_pLock);
00093         mFileName = inFileName;
00094 
00095         delete mCMMLDoc;
00096         mCMMLDoc = new C_CMMLDoc;
00097         bool retVal = mCMMLParser.parseDocFromFile(mFileName, mCMMLDoc);
00098 
00099         mUptoTag = -1;
00100 
00101         if (retVal) {
00102                 return S_OK;
00103         } else {
00104                 return S_FALSE;
00105         }
00106 
00107 
00108 }
00109 
00110 //CAMThread Stuff
00111 DWORD CMMLRawSourceFilter::ThreadProc(void) {
00112         //debugLog << "Thread Proc Called..."<<endl;
00113 
00114         while(true) {
00115                 DWORD locThreadCommand = GetRequest();
00116                 //debugLog << "Command = "<<locThreadCommand<<endl;
00117                 switch(locThreadCommand) {
00118                         case THREAD_EXIT:
00119                                 //debugLog << "EXIT ** "<<endl;
00120                                 Reply(S_OK);
00121                                 return S_OK;
00122 
00123                         case THREAD_RUN:
00124                                 //debugLog << "RUN ** "<<endl;
00125                                 Reply(S_OK);
00126                                 DataProcessLoop();
00127                                 break;
00128                 }
00129                 
00130         }
00131         return S_OK;
00132 }
00133 
00134 
00135 HRESULT CMMLRawSourceFilter::DataProcessLoop() 
00136 {
00137         C_ClipTag* locClip = NULL;
00138         DWORD locCommand = 0;
00139         while(true) {
00140                 if(CheckRequest(&locCommand) == TRUE) {
00141                         //debugLog<<"DataProcessLoop : Thread Command issued... leaving loop."<<endl;
00142                         return S_OK;
00143                 }
00144                 
00145                 if (mUptoTag == -1) {
00146                         //Deliver the head tag
00147                         mCMMLSourcePin->deliverTag(mCMMLDoc->root()->head());
00148                 } else if (mUptoTag < mCMMLDoc->root()->clipList()->numTags()) {
00149 
00150                         locClip = mCMMLDoc->root()->clipList()->getTag(mUptoTag);
00151 
00152                         wstring locTrackName = locClip->track();
00153 
00154                         if (locTrackName == L"") {
00155                                 locTrackName = L"default";
00156                         }
00157 
00158                         //Check if we have a pending end time in this track.
00159                         tTrackMap::iterator locIt = mTrackMap.find(locTrackName);
00160                         if (locIt != mTrackMap.end()) {
00161                                 //There's an entry for this track in the map.
00162                                 
00163                                 
00164                                 //__int64 locStartTime = StringHelper::stringToNum(StringHelper::toNarrowStr(locClip->start()));
00165                                 //Temporal URI Changes :::
00166                                 
00167                                 C_TimeStamp locStamp;
00168                                 locStamp.parseTimeStamp(StringHelper::toNarrowStr(locClip->start()));
00169                                 __int64 locStartTime = locStamp.toHunNanos();
00170                                 //
00171 
00172                                 if (locStartTime <= locIt->second) {
00173                                         //The start time of this clip is before the potential end time we saved.
00174                                         // This means the end time means nothing, and we can ignore it and remove from the map.
00175                                         mTrackMap.erase(locIt);
00176 
00177                                 } else {
00178                                         //The start time of this clip is after the saved end time...
00179                                         // We send an empty clip marked with the end time.
00180                                         C_ClipTag* locEndTag = new C_ClipTag;
00181                                         locEndTag->setStart(StringHelper::toWStr(StringHelper::numToString(locIt->second)));
00182                                         locEndTag->setTrack(locTrackName);
00183                                         mCMMLSourcePin->deliverTag(locEndTag);
00184 
00185                                         //Now remove it from the map.
00186                                         mTrackMap.erase(locIt);
00187                                 }
00188                         }
00189 
00190 
00191                         //If this clip has an end time we can add it's end time to the map
00192                         if (locClip->end() != L"") {
00193                                 //There's a specified end time on this clip, so hold on to it
00194                                 
00195                                 //Temporal changes...
00196                                 //__int64 locEndTime = StringHelper::stringToNum(StringHelper::toNarrowStr(locClip->end()));
00197                                 C_TimeStamp locStamp;
00198                                 locStamp.parseTimeStamp(StringHelper::toNarrowStr(locClip->end()));
00199                                 __int64 locEndTime = locStamp.toHunNanos();
00200                                 //
00201 
00202                                 mTrackMap.insert(tTrackMap::value_type(locTrackName, locEndTime));
00203                         }
00204                         
00205                         mCMMLSourcePin->deliverTag(locClip);
00206                 } else {
00207                         mCMMLSourcePin->DeliverEndOfStream();
00208                         return S_OK;
00209                 }
00210                 mUptoTag++;
00211 
00212         }
00213         return S_OK;
00214 
00215 }
00216 //IMEdiaStreaming
00217 STDMETHODIMP CMMLRawSourceFilter::Run(REFERENCE_TIME tStart) {
00218         CAutoLock locLock(m_pLock);
00219         return CBaseFilter::Run(tStart);
00220 }
00221 STDMETHODIMP CMMLRawSourceFilter::Pause(void) {
00222         CAutoLock locLock(m_pLock);
00223         if (m_State == State_Stopped) {
00224                 if (ThreadExists() == FALSE) {
00225                         Create();
00226                 }
00227                 CallWorker(THREAD_RUN);
00228         }
00229 
00230         HRESULT locHR = CBaseFilter::Pause();
00231         return locHR;
00232         
00233 }
00234 STDMETHODIMP CMMLRawSourceFilter::Stop(void) {
00235         CAutoLock locLock(m_pLock);
00236         CallWorker(THREAD_EXIT);
00237         Close();
00238         //mJustSeeked = true;
00239         //mSeekRequest = 0;
00240         mUptoTag = -1;
00241         mCMMLSourcePin->DeliverBeginFlush();
00242         mCMMLSourcePin->DeliverEndFlush();
00243         return CBaseFilter::Stop();
00244 }

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