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
00052
00053
00054
00055
00056 };
00057
00058
00059 int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
00060
00061
00062
00063 CUnknown* WINAPI OggMuxFilter::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr)
00064 {
00065 OggMuxFilter *pNewObject = new OggMuxFilter();
00066 if (pNewObject == NULL) {
00067 *pHr = E_OUTOFMEMORY;
00068 }
00069 return pNewObject;
00070 }
00071
00072 void OggMuxFilter::NotifyComplete() {
00073 HRESULT locHR = NotifyEvent(EC_COMPLETE, S_OK, NULL);
00074
00075 }
00076
00077 STDMETHODIMP OggMuxFilter::NonDelegatingQueryInterface(REFIID riid, void **ppv)
00078 {
00079 if (riid == IID_IFileSinkFilter) {
00080 *ppv = (IFileSinkFilter*)this;
00081 ((IUnknown*)*ppv)->AddRef();
00082 return NOERROR;
00083 } else if (riid == IID_IAMFilterMiscFlags) {
00084 debugLog<<"Queried for IAMMiscFlags"<<endl;
00085 *ppv = (IAMFilterMiscFlags*)this;
00086 ((IUnknown*)*ppv)->AddRef();
00087 return NOERROR;
00088 } else if (riid == IID_IMediaSeeking) {
00089 debugLog<<"Queried for IMediaSeeking"<<endl;
00090 *ppv = (IMediaSeeking*)this;
00091 ((IUnknown*)*ppv)->AddRef();
00092 return NOERROR;
00093 } else if (riid == IID_IOggMuxProgress) {
00094 debugLog<<"Queried for IMediaSeeking"<<endl;
00095 *ppv = (IOggMuxProgress*)this;
00096 ((IUnknown*)*ppv)->AddRef();
00097 return NOERROR;
00098 } else if (riid == IID_IOggMuxSettings) {
00099 *ppv = (IOggMuxSettings*)this;
00100 ((IUnknown*)*ppv)->AddRef();
00101 return NOERROR;
00102 }
00103
00104
00105
00106
00107
00108
00109 return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
00110 }
00111
00112 STDMETHODIMP_(LONGLONG) OggMuxFilter::getProgressTime()
00113 {
00114 if (mInterleaver != NULL) {
00115 return mInterleaver->progressTime();
00116 } else {
00117 return -1;
00118 }
00119
00120 }
00121
00122 STDMETHODIMP_(LONGLONG) OggMuxFilter::getBytesWritten() {
00123 if (mInterleaver != NULL) {
00124 return mInterleaver->bytesWritten();
00125 } else {
00126 return -1;
00127 }
00128
00129 }
00130 ULONG OggMuxFilter::GetMiscFlags(void)
00131 {
00132 debugLog<<"GetMiscflags"<<endl;
00133 return AM_FILTER_MISC_FLAGS_IS_RENDERER;
00134 }
00135
00136
00137
00138 OggMuxFilter::OggMuxFilter()
00139 : CBaseFilter(NAME("OggMuxFilter"), NULL, m_pLock, CLSID_OggMuxFilter)
00140 , mInterleaver(NULL)
00141 {
00142 mInterleaver = new OggPageInterleaver(this, this);
00143
00144
00145 m_pLock = new CCritSec;
00146 mStreamLock = new CCritSec;
00147 mInputPins.push_back(new OggMuxInputPin(this, m_pLock, &mHR, mInterleaver->newStream()));
00148
00149 #ifdef OGGCODECS_LOGGING
00150 debugLog.open("g:\\logs\\muxer.log", ios_base::out);
00151 #endif
00152
00153
00154
00155
00156
00157
00158
00159 IMediaSeeking* locSeeker = (IMediaSeeking*)mInputPins[0];
00160 SetDelegate(locSeeker);
00161
00162 }
00163
00164 OggMuxFilter::OggMuxFilter(REFCLSID inFilterGUID)
00165 : CBaseFilter(NAME("OggMuxFilter"), NULL, m_pLock, inFilterGUID)
00166 , mInterleaver(NULL)
00167 {
00168
00169
00170
00171
00172 m_pLock = new CCritSec;
00173 mStreamLock = new CCritSec;
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 }
00188
00189 OggMuxFilter::~OggMuxFilter(void)
00190 {
00191
00192
00193
00194
00195
00196
00197 SetDelegate(NULL);
00198
00199 delete mInterleaver;
00200 for (size_t i = 0; i < mInputPins.size(); i++) {
00201 delete mInputPins[i];
00202 }
00203
00204
00205 delete m_pLock;
00206 delete mStreamLock;
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 }
00217
00218 HRESULT OggMuxFilter::addAnotherPin() {
00219 mInputPins.push_back(new OggMuxInputPin(this, m_pLock, &mHR, mInterleaver->newStream()));
00220 return S_OK;
00221 }
00222
00223
00224 HRESULT OggMuxFilter::SetFileName(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inMediaType) {
00225 CAutoLock locLock(m_pLock);
00226 mFileName = inFileName;
00227
00228 SetupOutput();
00229 return S_OK;
00230 }
00231 HRESULT OggMuxFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) {
00232
00233
00234
00235 LPOLESTR x = SysAllocString(mFileName.c_str());
00236 *outFileName = x;
00237
00238 return S_OK;
00239 }
00240
00241 bool OggMuxFilter::acceptOggPage(OggPage* inOggPage) {
00242
00243 unsigned char* locPageData = inOggPage->createRawPageData();
00244 mOutputFile.write((char*)locPageData, inOggPage->pageSize());
00245
00246 delete inOggPage;
00247 delete[] locPageData;
00248 return true;
00249 }
00250 bool OggMuxFilter::SetupOutput() {
00251 mOutputFile.open(StringHelper::toNarrowStr(mFileName).c_str(), ios_base::out | ios_base::binary);
00252 return mOutputFile.is_open();
00253 }
00254 bool OggMuxFilter::CloseOutput() {
00255 mOutputFile.close();
00256 return true;
00257
00258 }
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 int OggMuxFilter::GetPinCount() {
00280
00281 return (int)mInputPins.size();
00282 }
00283 CBasePin* OggMuxFilter::GetPin(int inPinNo) {
00284
00285 if ((inPinNo >= 0) && ((size_t)inPinNo < mInputPins.size()) ) {
00286 return mInputPins[inPinNo];
00287 } else {
00288 return NULL;
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
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 STDMETHODIMP OggMuxFilter::Run(REFERENCE_TIME tStart) {
00385
00386 CAutoLock locLock(m_pLock);
00387
00388 return CBaseFilter::Run(tStart);
00389
00390
00391 }
00392 STDMETHODIMP OggMuxFilter::Pause(void) {
00393 CAutoLock locLock(m_pLock);
00394
00395
00396
00397
00398
00399
00400
00401 HRESULT locHR = CBaseFilter::Pause();
00402
00403 return locHR;
00404
00405 }
00406 STDMETHODIMP OggMuxFilter::Stop(void) {
00407 CAutoLock locLock(m_pLock);
00408
00409
00410
00411
00412
00413 CloseOutput();
00414 return CBaseFilter::Stop();
00415 }
00416
00417 STDMETHODIMP OggMuxFilter::GetPositions(LONGLONG *pCurrent, LONGLONG *pStop) {
00418 HRESULT locHR = BasicSeekPassThrough::GetPositions(pCurrent, pStop);
00419 debugLog<<"GetPos Before : "<<*pCurrent<<" - "<<*pStop<<endl;
00420 *pCurrent = mInterleaver->progressTime();
00421 debugLog<<"GetPos After : "<<*pCurrent<<" - "<<*pStop<<endl;
00422 return locHR;
00423 }
00424
00425 STDMETHODIMP OggMuxFilter::GetCurrentPosition(LONGLONG *pCurrent) {
00426 *pCurrent = mInterleaver->progressTime();
00427 debugLog<<"GetCurrentPos : "<<*pCurrent<<endl;
00428 return S_OK;
00429 }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449 STDMETHODIMP_(bool) OggMuxFilter::setMaxPacketsPerPage(unsigned long inMaxPacketsPerPage) {
00450 for (std::vector<OggMuxInputPin*>::iterator locPinIterator = mInputPins.begin();
00451 locPinIterator != mInputPins.end();
00452 locPinIterator++) {
00453 OggMuxInputPin* locPin = *locPinIterator;
00454 locPin->SetPaginatorMaximumPacketsPerPage(inMaxPacketsPerPage);
00455 }
00456
00457 return true;
00458 }
00459
00460 STDMETHODIMP_(unsigned long) OggMuxFilter::maxPacketsPerPage() {
00461 unsigned long locCurrentMaximumPacketsPerPage = 0;
00462
00463 for (std::vector<OggMuxInputPin*>::iterator locPinIterator = mInputPins.begin();
00464 locPinIterator != mInputPins.end();
00465 locPinIterator++) {
00466
00467 OggMuxInputPin* locPin = *locPinIterator;
00468
00469 unsigned long locMaximumPacketsPerPageForThisPin =
00470 locPin->PaginatorMaximumPacketsPerPage();
00471
00472 if (locMaximumPacketsPerPageForThisPin > locCurrentMaximumPacketsPerPage) {
00473 locCurrentMaximumPacketsPerPage = locMaximumPacketsPerPageForThisPin;
00474 }
00475 }
00476
00477 return locCurrentMaximumPacketsPerPage;
00478 }