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
00032
00033
00034 #include "stdafx.h"
00035 #include "dsplay.h"
00036
00037 #pragma managed
00038 namespace illiminable {
00039 namespace libDSPlayDotNET {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 DSPlay::DSPlay(void)
00053 : mGraphBuilder(NULL)
00054 , mMediaControl(NULL)
00055 , mMediaSeeking(NULL)
00056 , mMediaEvent(NULL)
00057 , mBasicAudio(NULL)
00058 , mEventHandle(INVALID_HANDLE_VALUE)
00059
00060 , mDNMediaEvent(NULL)
00061 , mCMMLAppControl(NULL)
00062 , mWindowHandle(NULL)
00063 , mVideoWindow(NULL)
00064 , mVideoRenderFilter(NULL)
00065 , mVMR7Window(NULL)
00066 , mVMR9Window(NULL)
00067 , mVideoFrameStep(NULL)
00068 , mLeft(0)
00069 , mTop(0)
00070 , mWidth(0)
00071 , mHeight(0)
00072 , mFileSize(0)
00073 , mVideoRenderType(VR_NONE)
00074
00075 , mAvgTimePerFrame(0)
00076 , mVideoWidth(0)
00077 , mVideoHeight(0)
00078
00079
00080
00081 {
00082 CoInitialize(NULL);
00083 mCMMLProxy = new CMMLCallbackProxy;
00084 debugLog = new fstream;
00085 #ifdef OGGCODECS_LOGGING
00086 debugLog->open("G:\\logs\\dsplay.log", ios_base::out | ios_base::app);
00087 #endif
00088 *debugLog<<"Starting new log"<<endl;
00089 }
00090
00091 DSPlay::DSPlay(IntPtr inWindowHandle, Int32 inLeft, Int32 inTop, Int32 inWidth, Int32 inHeight)
00092 : mGraphBuilder(NULL)
00093 , mMediaControl(NULL)
00094 , mMediaSeeking(NULL)
00095 , mMediaEvent(NULL)
00096 , mBasicAudio(NULL)
00097 , mEventHandle(INVALID_HANDLE_VALUE)
00098
00099 , mDNMediaEvent(NULL)
00100 , mCMMLAppControl(NULL)
00101 , mWindowHandle(inWindowHandle)
00102 , mVideoWindow(NULL)
00103 , mVideoRenderFilter(NULL)
00104 , mVMR7Window(NULL)
00105 , mVMR9Window(NULL)
00106 , mVideoFrameStep(NULL)
00107 , mLeft(inLeft)
00108 , mTop(inTop)
00109 , mWidth(inWidth)
00110 , mHeight(inHeight)
00111 , mFileSize(0)
00112 , mVideoRenderType(VR_NONE)
00113
00114 , mAvgTimePerFrame(0)
00115 , mVideoWidth(0)
00116 , mVideoHeight(0)
00117 {
00118 CoInitialize(NULL);
00119 mCMMLProxy = new CMMLCallbackProxy;
00120 debugLog = new fstream;
00121 debugLog->open("G:\\logs\\dsplay.log", ios_base::out | ios_base::app);
00122 *debugLog<<"Starting new log"<<endl;
00123 }
00124
00125 bool DSPlay::checkEvents() {
00126 const DWORD TIMEOUT_WAIT = 0;
00127 long locEventCode = 0;
00128 long locParam1 = 0;
00129 long locParam2 = 0;
00130 HRESULT locHR = S_OK;
00131
00132 if (WAIT_OBJECT_0 == WaitForSingleObject(mEventHandle, TIMEOUT_WAIT)) {
00133 while (locHR = mMediaEvent->GetEvent(&locEventCode, &locParam1, &locParam2, 0), SUCCEEDED(locHR))
00134 {
00135
00136
00137
00138
00139 if (mDNMediaEvent != NULL) {
00140 mDNMediaEvent->eventNotification(locEventCode, locParam1, locParam2);
00141 }
00142
00143 mMediaEvent->FreeEventParams(locEventCode, locParam1, locParam2);
00144 }
00145 }
00146 return true;
00147 }
00148
00149
00150 DSPlay::~DSPlay(void) {
00151 *debugLog<<"Killing DSPlay"<<endl;
00152 debugLog->close();
00153
00154 releaseInterfaces();
00155 delete debugLog;
00156 CoUninitialize();
00157 }
00158
00159
00160 void DSPlay::repaint()
00161 {
00162 if ((mVideoRenderType == VR_VMR9) && (mVMR9Window != NULL)) {
00163 HDC locHDC = GetDC(NULL);
00164
00165 mVMR9Window->RepaintVideo((HWND)((int)mWindowHandle), locHDC);
00166 }
00167 }
00168
00169
00170 long DSPlay::getVolume() {
00171 long retVolume = -10000;
00172 if (mBasicAudio != NULL) {
00173 HRESULT locHR = mBasicAudio->get_Volume(&retVolume);
00174 if (locHR != S_OK) {
00175 retVolume = -10000;
00176 }
00177 }
00178 return retVolume;
00179 }
00180
00181
00182 long DSPlay::getBalance() {
00183 long retBalance = 0;
00184 if (mBasicAudio != NULL) {
00185 HRESULT locHR = mBasicAudio->get_Balance(&retBalance);
00186 if (locHR != S_OK) {
00187 retBalance = 0;
00188 }
00189 }
00190 return retBalance;
00191 }
00192
00193
00194 bool DSPlay::setVolume(long inVolume) {
00195
00196 if (mBasicAudio != NULL) {
00197 HRESULT locHR = mBasicAudio->put_Volume(inVolume);
00198 if (locHR == S_OK) {
00199 return true;
00200 } else {
00201 return false;
00202 }
00203 } else {
00204 return false;
00205 }
00206 }
00207
00208
00209 bool DSPlay::setBalance(long inBalance) {
00210 if (mBasicAudio != NULL) {
00211 HRESULT locHR = mBasicAudio->put_Balance(inBalance);
00212 if (locHR == S_OK) {
00213 return true;
00214 } else {
00215 return false;
00216 }
00217 } else {
00218 return false;
00219 }
00220 }
00221 void DSPlay::releaseInterfaces() {
00222
00223 mVideoRenderType = VR_NONE;
00224 *debugLog<<"********* Releasing interfaces *********"<<endl;
00225 ULONG numRef = 0;
00226 if (mMediaControl != NULL) {
00227 numRef =
00228 mMediaControl->Release();
00229 *debugLog<<"Media Control count = "<<numRef<<endl;
00230 mMediaControl = NULL;
00231 }
00232
00233 if (mMediaSeeking != NULL) {
00234 numRef =
00235 mMediaSeeking->Release();
00236
00237 *debugLog<<"Media Seeking count = "<<numRef<<endl;
00238 mMediaSeeking = NULL;
00239 }
00240
00241 if (mMediaEvent != NULL) {
00242 numRef =
00243 mMediaEvent->Release();
00244
00245 *debugLog<<"Media Event count = "<<numRef<<endl;
00246 mMediaEvent = NULL;
00247 }
00248
00249 if (mBasicAudio != NULL) {
00250 numRef =
00251 mBasicAudio->Release();
00252
00253 *debugLog<<"BasicAudio count = "<<numRef<<endl;
00254 mBasicAudio = NULL;
00255 }
00256
00257
00258 if (mCMMLAppControl != NULL) {
00259 numRef =
00260 mCMMLAppControl->Release();
00261
00262 *debugLog<<"CMML App control count = "<<numRef<<endl;
00263 mCMMLAppControl = NULL;
00264 }
00265
00266 if(mVideoRenderFilter != NULL) {
00267 numRef =
00268 mVideoRenderFilter->Release();
00269
00270 *debugLog<<"Video Render Filter count = "<<numRef<<endl;
00271 mVideoRenderFilter = NULL;
00272 }
00273
00274
00275 if (mVideoWindow != NULL) {
00276 numRef =
00277 mVideoWindow->Release();
00278
00279 *debugLog<<"Video Window count = "<<numRef<<endl;
00280 mVideoWindow = NULL;
00281 }
00282
00283 if (mVideoFrameStep != NULL) {
00284 numRef =
00285 mVideoFrameStep->Release();
00286
00287 *debugLog<<"Video Frame Step count = "<<numRef<<endl;
00288 mVideoFrameStep = NULL;
00289 }
00290
00291 if (mVMR9Window != NULL) {
00292 numRef =
00293 mVMR9Window->Release();
00294
00295 *debugLog<<"Video Window VMR9 count = "<<numRef<<endl;
00296 mVMR9Window = NULL;
00297 }
00298
00299 if (mVMR7Window != NULL) {
00300 numRef =
00301 mVMR7Window->Release();
00302
00303 *debugLog<<"Video Window VMR7 count = "<<numRef<<endl;
00304 mVMR7Window = NULL;
00305 }
00306
00307 *debugLog<<"Before Graph release..."<<endl;
00308 if (mGraphBuilder != NULL) {
00309 numRef =
00310 mGraphBuilder->Release();
00311
00312 *debugLog<<"Graph Builder count = "<<numRef<<endl;
00313 mGraphBuilder = NULL;
00314 }
00315
00316
00317 *debugLog<<"****** After graph release ******"<<endl;
00318
00319 mIsLoaded = false;
00320
00321 }
00322
00323 void DSPlay::GetVideoInformation() {
00324
00325 if (mVideoRenderFilter != NULL) {
00326
00327 IEnumPins* locEnumPins = NULL;
00328 HRESULT locHR = mVideoRenderFilter->EnumPins(&locEnumPins);
00329 if (locHR == S_OK) {
00330
00331 IPin* locPin = NULL;
00332 ULONG locHowMany = 0;
00333 locHR = locEnumPins->Next(1, &locPin, &locHowMany);
00334 if (locHR == S_OK) {
00335
00336 AM_MEDIA_TYPE locMediaType;
00337 locHR = locPin->ConnectionMediaType(&locMediaType);
00338 if (locHR == S_OK) {
00339
00340 if (locMediaType.formattype == FORMAT_VideoInfo) {
00341 VIDEOINFOHEADER* locVideoInfo = (VIDEOINFOHEADER*)locMediaType.pbFormat;
00342
00343
00344 mAvgTimePerFrame = locVideoInfo->AvgTimePerFrame;
00345 mVideoWidth = locVideoInfo->bmiHeader.biWidth;
00346 mVideoHeight = locVideoInfo->bmiHeader.biHeight;
00347
00348 } else if (locMediaType.formattype == FORMAT_VideoInfo2) {
00349 VIDEOINFOHEADER2* locVideoInfo = (VIDEOINFOHEADER2*)locMediaType.pbFormat;
00350
00351 mAvgTimePerFrame = locVideoInfo->AvgTimePerFrame;
00352 mVideoWidth = locVideoInfo->bmiHeader.biWidth;
00353 mVideoHeight = locVideoInfo->bmiHeader.biHeight;
00354 } else {
00355 mAvgTimePerFrame = 0;
00356 mVideoWidth = 0;
00357 mVideoHeight = 0;
00358 }
00359
00360
00361 if ((locMediaType.cbFormat != 0) && (locMediaType.pbFormat != NULL)) {
00362 CoTaskMemFree(locMediaType.pbFormat);
00363 }
00364
00365 locPin->Release();
00366 locEnumPins->Release();
00367 return;
00368
00369 } else {
00370
00371 locPin->Release();
00372 locEnumPins->Release();
00373
00374 }
00375 } else {
00376
00377 locEnumPins->Release();
00378 }
00379 } else {
00380
00381 }
00382 } else {
00383
00384 }
00385
00386 mAvgTimePerFrame = 0;
00387 mVideoWidth = 0;
00388 mVideoHeight = 0;
00389
00390 }
00391
00392 bool DSPlay::loadFile(String* inFileName) {
00393
00394
00395 ULONG numRef = 0;
00396
00397
00398 if (!File::Exists(inFileName)) {
00399 return false;
00400 }
00401 FileInfo* locFileInfo = new FileInfo(inFileName);
00402 mFileSize = locFileInfo->Length;
00403
00404
00405
00406 releaseInterfaces();
00407 HRESULT locHR = S_OK;
00408
00409 char* locFileName = Wrappers::netStrToCStr(inFileName);
00410 *debugLog<<"File = "<<locFileName<<endl;
00411 wstring locWFileName = illiminable::libDSPlayDotNET::toWStr(locFileName);
00412
00413 Wrappers::releaseCStr(locFileName);
00414 locFileName = NULL;
00415
00416
00417
00418 IGraphBuilder* locGraphBuilder = NULL;
00419 locHR = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&locGraphBuilder);
00420 mGraphBuilder = locGraphBuilder;
00421
00422 if (locHR != S_OK) {
00423 mIsLoaded = false;
00424 return false;
00425 }
00426
00427
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 mVideoRenderType = VR_NONE;
00458
00459 IBaseFilter* locVMR9 = NULL;
00460
00461 *debugLog<<"Attempting VMR9 creation... making it !"<<endl;
00462 locHR= CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&locVMR9);
00463 if (locHR == S_OK) {
00464 locHR = mGraphBuilder->AddFilter(locVMR9, L"Video Mixing Renderer 9");
00465
00466
00467
00468 IVMRFilterConfig9* locVMR9Config = NULL;
00469 locHR = locVMR9->QueryInterface(IID_IVMRFilterConfig9, (void**)&locVMR9Config);
00470
00471 if (locHR == S_OK) {
00472 locVMR9Config->SetRenderingMode(VMRMode_Windowless);
00473 locVMR9Config->Release();
00474
00475
00476 IVMRWindowlessControl9* locVMR9Windowless = NULL;
00477 locHR = locVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void**)&locVMR9Windowless);
00478
00479 if (locHR == S_OK) {
00480 mVMR9Window = locVMR9Windowless;
00481 mVideoRenderType = VR_VMR9;
00482 *debugLog<<"We got our VMR9 window"<<endl;
00483 }
00484
00485 }
00486
00487
00488
00489
00490 mVideoRenderFilter = locVMR9;
00491 }
00492
00493 if (mVideoRenderType == VR_NONE) {
00494
00495 IBaseFilter* locVMR7 = NULL;
00496
00497 *debugLog<<"Attempting VMR7 creation... making it !"<<endl;
00498 locHR= CoCreateInstance(CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&locVMR7);
00499 if (locHR == S_OK) {
00500 locHR = mGraphBuilder->AddFilter(locVMR7, L"Video Mixing Renderer 7");
00501
00502
00503
00504 IVMRFilterConfig* locVMR7Config = NULL;
00505 locHR = locVMR7->QueryInterface(IID_IVMRFilterConfig, (void**)&locVMR7Config);
00506
00507 if (locHR == S_OK) {
00508 locVMR7Config->SetRenderingMode(VMRMode_Windowless);
00509 locVMR7Config->Release();
00510
00511
00512 IVMRWindowlessControl* locVMR7Windowless = NULL;
00513 locHR = locVMR7->QueryInterface(IID_IVMRWindowlessControl, (void**)&locVMR7Windowless);
00514
00515 if (locHR == S_OK) {
00516 mVMR7Window = locVMR7Windowless;
00517 mVideoRenderType = VR_VMR7;
00518 }
00519
00520 }
00521
00522
00523
00524
00525
00526 mVideoRenderFilter = locVMR7;
00527 }
00528 }
00529
00530 if (mWindowHandle != NULL) {
00531 *debugLog<<"Setting up video window pointer..."<<endl;
00532
00533 IVMRWindowlessControl9* locVMR9Window = NULL;
00534 IVMRWindowlessControl* locVMR7Window = NULL;
00535 IVideoWindow* locVideoWindow = NULL;
00536
00537 switch ((int)mVideoRenderType) {
00538 case VR_VMR9:
00539 *debugLog<<"Attemping to use VMR9 windowless"<<endl;
00540
00541
00542 locHR = locVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void**)&locVMR9Window);
00543
00544 if (locHR == S_OK) {
00545 *debugLog<<"Got VMR9 windowless interface"<<endl;
00546 mVMR9Window = locVMR9Window;
00547
00548 locHR = mVMR9Window->SetVideoClippingWindow( ((HWND)((int)mWindowHandle)));
00549 if (locHR == S_OK) {
00550 *debugLog<<"Clipping window set"<<endl;
00551 RECT locRect;
00552 locRect.left = mLeft;
00553 locRect.top = mTop;
00554 locRect.right = mLeft + mWidth;
00555 locRect.bottom = mTop + mHeight;
00556
00557 locHR = mVMR9Window->SetVideoPosition(NULL, &locRect);
00558 if (locHR == S_OK) {
00559 *debugLog<<"video pos set"<<endl;
00560 } else {
00561 *debugLog<<"video pos set FAILED"<<endl;
00562 }
00563 } else {
00564 *debugLog<<"Clipping window set FAILED"<<endl;
00565 }
00566 }
00567
00568
00569 break;
00570 case VR_VMR7:
00571 break;
00572 default:
00573
00574
00575 locHR = mGraphBuilder->QueryInterface(IID_IVideoWindow, (void**)&locVideoWindow);
00576
00577 if (locHR == S_OK) {
00578 mVideoWindow = locVideoWindow;
00579 mVideoWindow->put_Owner((int)mWindowHandle);
00580 mVideoWindow->SetWindowPosition(mLeft, mTop, mWidth, mHeight);
00581 mVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
00582 }
00583 break;
00584 }
00585 }
00586
00587
00588
00589
00590 *debugLog<<"About to call render on "<<endl;
00591
00592 locHR = mGraphBuilder->RenderFile(locWFileName.c_str(), NULL);
00593
00594 if (locHR != S_OK) {
00595 *debugLog<<"Render File FAILED !!"<<endl;
00596 mIsLoaded = false;
00597 return false;
00598 }
00599
00600
00601 GetVideoInformation();
00602
00603 *debugLog<<"Render must have been ok"<<endl;
00604 if (isFileAnnodex(inFileName)) {
00605 *debugLog<<"Is annodex"<<endl;
00606
00607 IBaseFilter* locCMMLFilter = NULL;
00608 locHR = mGraphBuilder->FindFilterByName(L"CMML Decode Filter", &locCMMLFilter);
00609
00610
00611 if (locCMMLFilter != NULL) {
00612 ICMMLAppControl* locCMMLAppControl = NULL;
00613
00614 locHR = locCMMLFilter->QueryInterface(X_IID_ICMMLAppControl, (void**)&locCMMLAppControl);
00615 if (locCMMLAppControl != NULL) {
00616 mCMMLAppControl = locCMMLAppControl;
00617 mCMMLAppControl->setCallbacks(mCMMLProxy);
00618 }
00619 numRef =
00620 locCMMLFilter->Release();
00621
00622 *debugLog<<"CMML Filter ref Count = "<<numRef<<endl;
00623 }
00624
00625 }
00626 *debugLog<<"After CMML Code..."<<endl;
00627
00628
00629 IMediaControl* locMediaControl = NULL;
00630 locHR = mGraphBuilder->QueryInterface(IID_IMediaControl, (void**)&locMediaControl);
00631 mMediaControl = locMediaControl;
00632
00633 if (locHR != S_OK) {
00634 mIsLoaded = false;
00635 return false;
00636 } else {
00637 mIsLoaded = true;
00638 }
00639
00640
00641 IMediaSeeking* locMediaSeeking = NULL;
00642 locHR = mGraphBuilder->QueryInterface(IID_IMediaSeeking, (void**)&locMediaSeeking);
00643 mMediaSeeking = locMediaSeeking;
00644
00645
00646 IMediaEvent* locMediaEvent = NULL;
00647 locHR = locGraphBuilder->QueryInterface(IID_IMediaEvent, (void**)&locMediaEvent);
00648
00649 if (locHR == S_OK) {
00650 mMediaEvent = locMediaEvent;
00651 HANDLE locEventHandle = INVALID_HANDLE_VALUE;
00652 locHR = locMediaEvent->GetEventHandle((OAEVENT*)&locEventHandle);
00653 mEventHandle = locEventHandle;
00654 }
00655
00656
00657 IBasicAudio* locBasicAudio = NULL;
00658 locHR = mGraphBuilder->QueryInterface(IID_IBasicAudio, (void**)&locBasicAudio);
00659 if (locHR == S_OK) {
00660 mBasicAudio = locBasicAudio;
00661 } else {
00662 mBasicAudio = NULL;
00663 }
00664
00665
00666 IVideoFrameStep* locVideoStep = NULL;
00667 locHR = mGraphBuilder->QueryInterface(IID_IVideoFrameStep, (void**)&locVideoStep);
00668 if (locHR == S_OK) {
00669 mVideoFrameStep = locVideoStep;
00670 } else {
00671 mVideoFrameStep = NULL;
00672 }
00673
00674
00675
00676
00677
00678 return true;
00679
00680
00681 }
00682
00683 System::Drawing::Bitmap* DSPlay::GetImage() {
00684 HRESULT locHR = S_OK;
00685 System::Drawing::Bitmap* locBitmap = NULL;
00686 BYTE* locBytes = NULL;
00687
00688 switch (mVideoRenderType) {
00689 case VR_VMR9:
00690 if (mVMR9Window != NULL) {
00691 locHR = mVMR9Window->GetCurrentImage(&locBytes);
00692 if (locHR == S_OK) {
00693 BITMAPINFOHEADER* locBMIH = (BITMAPINFOHEADER*) locBytes;
00694 *debugLog<<"BHIM : Bit count = "<<locBMIH->biBitCount<<endl;
00695 *debugLog<<"BHIM : Compresio = "<<locBMIH->biCompression<<endl;
00696 *debugLog<<"BHIM : Colours = "<<locBMIH->biClrUsed<<endl;
00697 *debugLog<<"BHIM : Width = "<<locBMIH->biWidth<<endl;
00698 *debugLog<<"BHIM : Height = "<<locBMIH->biHeight<<endl;
00699 *debugLog<<"BHIM : Size Img = "<<locBMIH->biSizeImage<<endl;
00700 *debugLog<<"BHIM : Size = "<<locBMIH->biSize<<endl;
00701 *debugLog<<"BHIM : Size BMIH = "<<sizeof(BITMAPINFOHEADER)<<endl;
00702 *debugLog<<"BHIM : Size BMI = "<<sizeof(BITMAPINFO)<<endl;
00703
00704
00705
00706
00707
00708
00709 if (locBMIH->biBitCount == 32) {
00710 unsigned char* locBuffer = new unsigned char[locBMIH->biSizeImage];
00711 memcpy((void*)locBuffer, (const void*)(locBytes + 44), locBMIH->biSizeImage);
00712 locBitmap = new System::Drawing::Bitmap(locBMIH->biWidth, locBMIH->biHeight, locBMIH->biWidth * 4, System::Drawing::Imaging::PixelFormat::Format32bppRgb, (System::IntPtr)(locBuffer));
00713 locBitmap->RotateFlip(System::Drawing::RotateFlipType::RotateNoneFlipY);
00714 }
00715
00716
00717
00718
00719 CoTaskMemFree(locBytes);
00720
00721
00722 }
00723
00724 }
00725
00726 default:
00727 break;
00728 };
00729
00730 return locBitmap;;
00731 }
00732
00733 bool DSPlay::setCMMLCallbacks(IDNCMMLCallbacks* inCMMLCallbacks) {
00734 return mCMMLProxy->setManagedDelegate(inCMMLCallbacks);
00735 }
00736
00737 bool DSPlay::isLoaded() {
00738 return mIsLoaded;
00739 }
00740 bool DSPlay::play() {
00741 if (mIsLoaded) {
00742 HRESULT locHR = mMediaControl->Run();
00743 if (SUCCEEDED(locHR)) {
00744 return true;
00745 } else {
00746 return false;
00747 }
00748 } else {
00749 return false;
00750 }
00751 }
00752
00753 bool DSPlay::pause() {
00754 if (mIsLoaded) {
00755 HRESULT locHR = mMediaControl->Pause();
00756 if (locHR != S_OK) {
00757 return false;
00758 } else {
00759 return true;
00760 }
00761 } else {
00762 return false;
00763 }
00764 }
00765
00766 bool DSPlay::stop() {
00767 if (mIsLoaded) {
00768 HRESULT locHR = mMediaControl->Stop();
00769 if (locHR != S_OK) {
00770 return false;
00771 } else {
00772 seek(0);
00773 return true;
00774 }
00775 } else {
00776 return false;
00777 }
00778 }
00779
00780 Int64 DSPlay::seek(Int64 inTime) {
00781 if (mIsLoaded && (mMediaSeeking != NULL)) {
00782 LONGLONG locCurrent = inTime;
00783 LONGLONG locStop = 0;
00784 HRESULT locHR = mMediaSeeking->SetPositions(&locCurrent, AM_SEEKING_AbsolutePositioning | AM_SEEKING_ReturnTime,
00785 &locStop, AM_SEEKING_NoPositioning);
00786
00787 if (SUCCEEDED(locHR)) {
00788 return locCurrent;
00789 } else {
00790 return -1;
00791 }
00792 } else {
00793 return -1;
00794 }
00795
00796 }
00797
00798 bool DSPlay::canStepFrame() {
00799 if (mVideoFrameStep != NULL) {
00800 HRESULT locHR = mVideoFrameStep->CanStep(0, NULL);
00801 if (locHR == S_OK) {
00802 return true;
00803 }
00804 }
00805 return false;
00806 }
00807
00808 bool DSPlay::stepFrame() {
00809 if (mVideoFrameStep != NULL) {
00810 HRESULT locHR = mVideoFrameStep->Step(1, NULL);
00811 if (locHR == S_OK) {
00812 return true;
00813 }
00814 }
00815 return false;
00816 }
00817
00818 Int64 DSPlay::seekStart() {
00819 return seek(0);
00820 }
00821
00822 Int64 DSPlay::queryPosition() {
00823 if (mIsLoaded && (mMediaSeeking != NULL)) {
00824 __int64 locStart = -1;
00825 __int64 locStop = -1;
00826 HRESULT locHR = mMediaSeeking->GetPositions(&locStart, &locStop);
00827 if (locHR == S_OK) {
00828 return locStart;
00829 } else {
00830 return -1;
00831 }
00832 } else {
00833 return -1;
00834 }
00835 }
00836
00837 Int64 DSPlay::fileSize() {
00838 if (mIsLoaded) {
00839 return mFileSize;
00840 } else {
00841 return -1;
00842 }
00843 }
00844 Int64 DSPlay::fileDuration() {
00845 if (mIsLoaded && (mMediaSeeking != NULL)) {
00846 LONGLONG locDuration = 0;
00847 HRESULT locHR = mMediaSeeking->GetDuration(&locDuration);
00848
00849 if (locHR != S_OK) {
00850 return -1;
00851 } else {
00852 return locDuration;
00853 }
00854 } else {
00855 return -1;
00856 }
00857 }
00858
00859 bool DSPlay::isFileAnnodex(String* inFilename)
00860 {
00861 String* locExt = (inFilename->Substring(inFilename->Length - 4, 4))->ToUpper();
00862 if (locExt->Equals(".ANX")) {
00863 return true;
00864 } else {
00865 return false;
00866 }
00867 }
00868
00869 bool DSPlay::setMediaEventCallback(IDNMediaEvent* inMediaEventCallback) {
00870 mDNMediaEvent = inMediaEventCallback;
00871 return true;
00872 }
00873 IDNMediaEvent* DSPlay::getMediaEventCallback() {
00874 return mDNMediaEvent;
00875 }
00876
00877
00879 Int64 DSPlay::averageTimePerFrame() {
00880 return mAvgTimePerFrame;
00881 }
00882
00884 Int64 DSPlay::averageFrameRate() {
00885
00886 if (mAvgTimePerFrame != 0) {
00887 Int64 locFrameRate = (10000000 * 100);
00888 locFrameRate /= mAvgTimePerFrame;
00889 return locFrameRate;
00890 } else {
00891 return 0;
00892 }
00893 }
00894
00896 Int32 DSPlay::videoWidth() {
00897 return mVideoWidth;
00898 }
00899
00901 Int32 DSPlay::videoHeight() {
00902 return mVideoHeight;
00903 }
00904
00905
00906 }
00907 }