00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "stdafx.h"
00032 #include "oggmuxfilter.h"
00033
00034
00035
00036
00037
00038 CFactoryTemplate g_Templates[] =
00039 {
00040 {
00041 L"OggMuxFilter",
00042 &CLSID_OggMuxFilter,
00043 OggMuxFilter::CreateInstance,
00044 NULL,
00045 NULL
00046 }
00047
00048 };
00049
00050
00051 int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
00052
00053
00054
00055 CUnknown* WINAPI OggMuxFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr)
00056 {
00057 OggMuxFilter *pNewObject = new OggMuxFilter();
00058 if (pNewObject == NULL) {
00059 *pHr = E_OUTOFMEMORY;
00060 }
00061 return pNewObject;
00062 }
00063
00064 void OggMuxFilter::NotifyComplete() {
00065 HRESULT locHR = NotifyEvent(EC_COMPLETE, S_OK, NULL);
00066
00067 }
00068
00069 STDMETHODIMP OggMuxFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00070 {
00071 if (riid == IID_IFileSinkFilter) {
00072 *ppv = (IFileSinkFilter*)this;
00073 ((IUnknown*)*ppv)->AddRef();
00074 return NOERROR;
00075 } else if (riid == IID_IAMFilterMiscFlags) {
00076 debugLog<<"Queried for IAMMiscFlags"<<endl;
00077 *ppv = (IAMFilterMiscFlags*)this;
00078 ((IUnknown*)*ppv)->AddRef();
00079 return NOERROR;
00080 } else if (riid == IID_IMediaSeeking) {
00081 debugLog<<"Queried for IMediaSeeking"<<endl;
00082 *ppv = (IMediaSeeking*)this;
00083 ((IUnknown*)*ppv)->AddRef();
00084 return NOERROR;
00085 } else if (riid == IID_IOggMuxProgress) {
00086 debugLog<<"Queried for IMediaSeeking"<<endl;
00087 *ppv = (IOggMuxProgress*)this;
00088 ((IUnknown*)*ppv)->AddRef();
00089 return NOERROR;
00090 }
00091 return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
00092 }
00093
00094 STDMETHODIMP_(LONGLONG) OggMuxFilter::getProgressTime()
00095 {
00096 if (mInterleaver != NULL) {
00097 return mInterleaver->progressTime();
00098 } else {
00099 return -1;
00100 }
00101
00102 }
00103
00104 STDMETHODIMP_(LONGLONG) OggMuxFilter::getBytesWritten() {
00105 if (mInterleaver != NULL) {
00106 return mInterleaver->bytesWritten();
00107 } else {
00108 return -1;
00109 }
00110
00111 }
00112 ULONG OggMuxFilter::GetMiscFlags(void)
00113 {
00114 debugLog<<"GetMiscflags"<<endl;
00115 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
00116 }
00117
00118
00119
00120 OggMuxFilter::OggMuxFilter()
00121 : CBaseFilter(NAME("OggMuxFilter"), NULL, m_pLock, CLSID_OggMuxFilter)
00122 , mInterleaver(NULL)
00123 {
00124 mInterleaver = new OggPageInterleaver(this, this);
00125
00126
00127 m_pLock = new CCritSec;
00128 mStreamLock = new CCritSec;
00129 mInputPins.push_back(new OggMuxInputPin(this, m_pLock, &mHR, mInterleaver->newStream()));
00130
00131 #ifdef OGGCODECS_LOGGING
00132 debugLog.open("g:\\logs\\muxer.log", ios_base::out);
00133 #endif
00134
00135
00136
00137
00138
00139
00140
00141 IMediaSeeking* locSeeker = (IMediaSeeking*)mInputPins[0];
00142 SetDelegate(locSeeker);
00143
00144 }
00145
00146 OggMuxFilter::OggMuxFilter(REFCLSID inFilterGUID)
00147 : CBaseFilter(NAME("OggMuxFilter"), NULL, m_pLock, inFilterGUID)
00148 , mInterleaver(NULL)
00149 {
00150
00151
00152
00153
00154 m_pLock = new CCritSec;
00155 mStreamLock = new CCritSec;
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 }
00170
00171 OggMuxFilter::~OggMuxFilter(void)
00172 {
00173
00174
00175
00176
00177
00178
00179 SetDelegate(NULL);
00180
00181 delete mInterleaver;
00182 for (size_t i = 0; i < mInputPins.size(); i++) {
00183 delete mInputPins[i];
00184 }
00185
00186
00187 delete m_pLock;
00188 delete mStreamLock;
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 }
00199
00200 HRESULT OggMuxFilter::addAnotherPin() {
00201 mInputPins.push_back(new OggMuxInputPin(this, m_pLock, &mHR, mInterleaver->newStream()));
00202 return S_OK;
00203 }
00204
00205
00206 HRESULT OggMuxFilter::SetFileName(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inMediaType) {
00207 CAutoLock locLock(m_pLock);
00208 mFileName = inFileName;
00209
00210 SetupOutput();
00211 return S_OK;
00212 }
00213 HRESULT OggMuxFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) {
00214
00215
00216
00217 LPOLESTR x = SysAllocString(mFileName.c_str());
00218 *outFileName = x;
00219
00220 return S_OK;
00221 }
00222
00223 bool OggMuxFilter::acceptOggPage(OggPage* inOggPage) {
00224
00225 unsigned char* locPageData = inOggPage->createRawPageData();
00226 mOutputFile.write((char*)locPageData, inOggPage->pageSize());
00227
00228 delete inOggPage;
00229 delete[] locPageData;
00230 return true;
00231 }
00232 bool OggMuxFilter::SetupOutput() {
00233 mOutputFile.open(StringHelper::toNarrowStr(mFileName).c_str(), ios_base::out | ios_base::binary);
00234 return mOutputFile.is_open();
00235 }
00236 bool OggMuxFilter::CloseOutput() {
00237 mOutputFile.close();
00238 return true;
00239
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 int OggMuxFilter::GetPinCount() {
00262
00263 return (int)mInputPins.size();
00264 }
00265 CBasePin* OggMuxFilter::GetPin(int inPinNo) {
00266
00267 if ((inPinNo >= 0) && ((size_t)inPinNo < mInputPins.size()) ) {
00268 return mInputPins[inPinNo];
00269 } else {
00270 return NULL;
00271 }
00272
00273
00274
00275
00276
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 STDMETHODIMP OggMuxFilter::Run(REFERENCE_TIME tStart) {
00367
00368 CAutoLock locLock(m_pLock);
00369
00370 return CBaseFilter::Run(tStart);
00371
00372
00373 }
00374 STDMETHODIMP OggMuxFilter::Pause(void) {
00375 CAutoLock locLock(m_pLock);
00376
00377
00378
00379
00380
00381
00382
00383 HRESULT locHR = CBaseFilter::Pause();
00384
00385 return locHR;
00386
00387 }
00388 STDMETHODIMP OggMuxFilter::Stop(void) {
00389 CAutoLock locLock(m_pLock);
00390
00391
00392
00393
00394
00395 CloseOutput();
00396 return CBaseFilter::Stop();
00397 }
00398
00399 STDMETHODIMP OggMuxFilter::GetPositions(LONGLONG *pCurrent, LONGLONG *pStop) {
00400 HRESULT locHR = BasicSeekPassThrough::GetPositions(pCurrent, pStop);
00401 debugLog<<"GetPos Before : "<<*pCurrent<<" - "<<*pStop<<endl;
00402 *pCurrent = mInterleaver->progressTime();
00403 debugLog<<"GetPos After : "<<*pCurrent<<" - "<<*pStop<<endl;
00404 return locHR;
00405 }
00406
00407 STDMETHODIMP OggMuxFilter::GetCurrentPosition(LONGLONG *pCurrent) {
00408 *pCurrent = mInterleaver->progressTime();
00409 debugLog<<"GetCurrentPos : "<<*pCurrent<<endl;
00410 return S_OK;
00411 }