DSPlay.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2004 Zentaro Kavanagh
00003 //
00004 //Copyright (C) 2004 Commonwealth Scientific and Industrial Research
00005 // Orgainisation (CSIRO) Australia
00006 //
00007 //Redistribution and use in source and binary forms, with or without
00008 //modification, are permitted provided that the following conditions
00009 //are met:
00010 //
00011 //- Redistributions of source code must retain the above copyright
00012 //  notice, this list of conditions and the following disclaimer.
00013 //
00014 //- Redistributions in binary form must reproduce the above copyright
00015 //  notice, this list of conditions and the following disclaimer in the
00016 //  documentation and/or other materials provided with the distribution.
00017 //
00018 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00019 //  may be used to endorse or promote products derived from this software 
00020 //  without specific prior written permission.
00021 //
00022 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00026 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 //===========================================================================
00034 #include "stdafx.h"
00035 #include "dsplay.h"
00036 
00037 #pragma managed
00038 namespace illiminable {
00039 namespace libDSPlayDotNET {
00040         //class __gc DSPlayer {
00041         //      public:
00042         //              bool loadFile(String inFileName);
00043         //              bool play();
00044         //              bool pause();
00045         //              bool stop();
00046         //              bool seek(Int64 inTime);
00047         //              Int64 queryPosition();
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         //,     mDNCMMLCallbacks(NULL)
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;                     //Need to delete this !
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         //,     mDNCMMLCallbacks(NULL)
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;                     //Need to delete this !
00120         debugLog = new fstream;
00121 #ifdef OGGCODECS_LOGGING
00122         debugLog->open("G:\\logs\\dsplay.log", ios_base::out | ios_base::app);
00123 #endif
00124         *debugLog<<"Starting new log"<<endl;
00125 }
00126 
00127 bool DSPlay::checkEvents() {
00128         const DWORD TIMEOUT_WAIT = 0;  //Wait this many ms for handle
00129         long locEventCode = 0;
00130         long locParam1 = 0;
00131         long locParam2 = 0;
00132         HRESULT locHR = S_OK;
00133 
00134         if (WAIT_OBJECT_0 == WaitForSingleObject(mEventHandle, TIMEOUT_WAIT))   { 
00135                         while (locHR = mMediaEvent->GetEvent(&locEventCode, &locParam1, &locParam2, 0), SUCCEEDED(locHR)) 
00136                         {
00137                     
00138                                 //cout<<"Event : "<<evCode<<" Params : "<<param1<<", "<<param2<<endl;
00139                                 
00140                                 //This is dodgy ! param1 and 2 are actually pointers !!
00141                                 if (mDNMediaEvent != NULL) {
00142                                         mDNMediaEvent->eventNotification(locEventCode, locParam1, locParam2);
00143                                 }
00144 
00145                                 mMediaEvent->FreeEventParams(locEventCode, locParam1, locParam2);
00146                         }
00147         }
00148         return true;
00149 }
00150 
00151 
00152 DSPlay::~DSPlay(void) {
00153         *debugLog<<"Killing DSPlay"<<endl;
00154         debugLog->close();
00155         
00156         releaseInterfaces();
00157         delete debugLog;
00158         CoUninitialize();
00159 }
00160 
00161 
00162 void DSPlay::repaint() 
00163 {
00164         if ((mVideoRenderType == VR_VMR9) && (mVMR9Window != NULL)) {
00165                 HDC locHDC = GetDC(NULL);
00166 
00167                 mVMR9Window->RepaintVideo((HWND)((int)mWindowHandle), locHDC);
00168         }
00169 }
00170 
00171 
00172 long DSPlay::getVolume() {
00173         long retVolume = -10000;
00174         if (mBasicAudio != NULL) {
00175                 HRESULT locHR = mBasicAudio->get_Volume(&retVolume);
00176                 if (locHR != S_OK) {
00177                         retVolume = -10000;
00178                 }
00179         }
00180         return retVolume;
00181 }
00182 
00183 
00184 long DSPlay::getBalance() {
00185         long retBalance = 0;
00186         if (mBasicAudio != NULL) {
00187                 HRESULT locHR = mBasicAudio->get_Balance(&retBalance);
00188                 if (locHR != S_OK) {
00189                         retBalance = 0;
00190                 }
00191         }
00192         return retBalance;
00193 }
00194 
00195 
00196 bool DSPlay::setVolume(long inVolume) {
00197 
00198         if (mBasicAudio != NULL) {
00199                 HRESULT locHR = mBasicAudio->put_Volume(inVolume);
00200                 if (locHR == S_OK) {
00201                         return true;
00202                 } else {
00203                         return false;
00204                 }
00205         } else {
00206                 return false;
00207         }
00208 }
00209 
00210 
00211 bool DSPlay::setBalance(long inBalance) {
00212         if (mBasicAudio != NULL) {
00213                 HRESULT locHR = mBasicAudio->put_Balance(inBalance);
00214                 if (locHR == S_OK) {
00215                         return true;
00216                 } else {
00217                         return false;
00218                 }
00219         } else {
00220                 return false;
00221         }
00222 }
00223 void DSPlay::releaseInterfaces() {
00224 
00225         mVideoRenderType = VR_NONE;
00226         *debugLog<<"********* Releasing interfaces *********"<<endl;
00227         ULONG numRef = 0;
00228         if (mMediaControl != NULL) {
00229                 numRef = 
00230                         mMediaControl->Release();
00231                 *debugLog<<"Media Control count = "<<numRef<<endl;
00232                 mMediaControl = NULL;
00233         }
00234 
00235         if (mMediaSeeking != NULL) {
00236                 numRef = 
00237                         mMediaSeeking->Release();
00238 
00239                 *debugLog<<"Media Seeking count = "<<numRef<<endl;
00240                 mMediaSeeking = NULL;
00241         }
00242 
00243         if (mMediaEvent != NULL) {
00244                 numRef = 
00245                         mMediaEvent->Release();
00246 
00247                 *debugLog<<"Media Event count = "<<numRef<<endl;
00248                 mMediaEvent = NULL;
00249         }
00250 
00251         if (mBasicAudio != NULL) {
00252                 numRef = 
00253                         mBasicAudio->Release();
00254 
00255                 *debugLog<<"BasicAudio count = "<<numRef<<endl;
00256                 mBasicAudio = NULL;
00257         }
00258 
00259 
00260         if (mCMMLAppControl != NULL) {
00261                 numRef = 
00262                         mCMMLAppControl->Release();
00263 
00264                 *debugLog<<"CMML App control count = "<<numRef<<endl;
00265                 mCMMLAppControl = NULL;
00266         }
00267 
00268         if(mVideoRenderFilter != NULL) {
00269                 numRef =
00270             mVideoRenderFilter->Release();
00271 
00272                 *debugLog<<"Video Render Filter count = "<<numRef<<endl;
00273                 mVideoRenderFilter = NULL;
00274         }
00275 
00276 
00277         if (mVideoWindow != NULL) {
00278                 numRef =
00279             mVideoWindow->Release();
00280 
00281                 *debugLog<<"Video Window count = "<<numRef<<endl;
00282                 mVideoWindow = NULL;
00283         }
00284 
00285         if (mVideoFrameStep != NULL) {
00286                 numRef =
00287             mVideoFrameStep->Release();
00288 
00289                 *debugLog<<"Video Frame Step count = "<<numRef<<endl;
00290                 mVideoFrameStep = NULL;
00291         }
00292 
00293         if (mVMR9Window != NULL) {
00294                 numRef =
00295             mVMR9Window->Release();
00296 
00297                 *debugLog<<"Video Window VMR9 count = "<<numRef<<endl;
00298                 mVMR9Window = NULL;
00299         }
00300 
00301         if (mVMR7Window != NULL) {
00302                 numRef =
00303             mVMR7Window->Release();
00304 
00305                 *debugLog<<"Video Window VMR7 count = "<<numRef<<endl;
00306                 mVMR7Window = NULL;
00307         }
00308 
00309                 *debugLog<<"Before Graph release..."<<endl;
00310         if (mGraphBuilder != NULL) {
00311                 numRef =
00312             mGraphBuilder->Release();
00313 
00314                 *debugLog<<"Graph Builder count = "<<numRef<<endl;
00315                 mGraphBuilder = NULL;
00316         }
00317 
00318 
00319         *debugLog<<"****** After graph release ******"<<endl;
00320 
00321         mIsLoaded = false;
00322         //TODO::: Release everything !
00323 }
00324 
00325 void DSPlay::GetVideoInformation() {
00326         //Check there's even a video renderer.
00327         if (mVideoRenderFilter != NULL) {
00328                 //Get an enumerator for the pins
00329                 IEnumPins* locEnumPins = NULL;
00330                 HRESULT locHR = mVideoRenderFilter->EnumPins(&locEnumPins);
00331                 if (locHR == S_OK) {
00332                         //Get the first pin
00333                         IPin* locPin = NULL;
00334                         ULONG locHowMany = 0;
00335                         locHR = locEnumPins->Next(1, &locPin, &locHowMany);
00336                         if (locHR == S_OK) {
00337                                 //Get the media type for the connection
00338                                 AM_MEDIA_TYPE locMediaType;
00339                                 locHR = locPin->ConnectionMediaType(&locMediaType);
00340                                 if (locHR == S_OK) {
00341                                         //Make sure it's video
00342                                         if (locMediaType.formattype == FORMAT_VideoInfo) {
00343                                                 VIDEOINFOHEADER* locVideoInfo = (VIDEOINFOHEADER*)locMediaType.pbFormat;
00344 
00345                                                 //Get the info we need
00346                                                 mAvgTimePerFrame = locVideoInfo->AvgTimePerFrame;
00347                                                 mVideoWidth = locVideoInfo->bmiHeader.biWidth;
00348                                                 mVideoHeight = locVideoInfo->bmiHeader.biHeight;
00349 
00350                                         } else if (locMediaType.formattype == FORMAT_VideoInfo2) {
00351                                                 VIDEOINFOHEADER2* locVideoInfo = (VIDEOINFOHEADER2*)locMediaType.pbFormat;
00352                                                 //Get the info we need
00353                                                 mAvgTimePerFrame = locVideoInfo->AvgTimePerFrame;
00354                                                 mVideoWidth = locVideoInfo->bmiHeader.biWidth;
00355                                                 mVideoHeight = locVideoInfo->bmiHeader.biHeight;
00356                                         } else {
00357                                                 mAvgTimePerFrame = 0;
00358                                                 mVideoWidth = 0;
00359                                                 mVideoHeight = 0;
00360                                         }
00361 
00362                                         //Free the format block
00363                                         if ((locMediaType.cbFormat != 0) && (locMediaType.pbFormat != NULL)) {
00364                                                 CoTaskMemFree(locMediaType.pbFormat);
00365                                         }
00366 
00367                                         locPin->Release();
00368                                         locEnumPins->Release();
00369                                         return;
00370 
00371                                 } else {
00372                                         //Failed to get media type or not conencted
00373                                         locPin->Release();
00374                                         locEnumPins->Release();
00375                                         
00376                                 }
00377                         } else {
00378                                 //Failed to get pin
00379                                 locEnumPins->Release();
00380                         }
00381                 } else {
00382                         //Failed to get enumerator
00383                 }
00384         } else {
00385                 //There is no video renderer
00386         }
00387 
00388         mAvgTimePerFrame = 0;
00389         mVideoWidth = 0;
00390         mVideoHeight = 0;
00391 
00392 }
00393 
00394 bool DSPlay::loadFile(String* inFileName) {
00395 
00396         //Debugging only
00397         ULONG numRef = 0;
00398         //
00399 
00400         if (!File::Exists(inFileName)) {
00401                 return false;
00402         }
00403         FileInfo* locFileInfo = new FileInfo(inFileName);
00404         mFileSize = locFileInfo->Length;
00405 
00406 
00407 
00408         releaseInterfaces();
00409         HRESULT locHR = S_OK;
00410 
00411         char* locFileName = Wrappers::netStrToCStr(inFileName);
00412         *debugLog<<"File = "<<locFileName<<endl;
00413         wstring locWFileName = illiminable::libDSPlayDotNET::toWStr(locFileName);
00414         
00415         Wrappers::releaseCStr(locFileName);
00416         locFileName = NULL;
00417 
00418         //Have to use a local pointer or taking the adress of a member function makes the second level
00419         // of indirection a __gc pointer.
00420         IGraphBuilder* locGraphBuilder = NULL;
00421         locHR = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&locGraphBuilder);
00422         mGraphBuilder = locGraphBuilder;
00423         
00424         if (locHR != S_OK) {
00425                 mIsLoaded = false;
00426                 return false;
00427         }
00428         
00429         
00430 
00431         mVideoRenderType = VR_NONE;
00432         //Attempt to use VMR9
00433         IBaseFilter* locVMR9 = NULL;
00434 
00435         *debugLog<<"Attempting VMR9 creation... making it !"<<endl;
00436         locHR= CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&locVMR9);
00437         if (locHR == S_OK) {
00438                 locHR = mGraphBuilder->AddFilter(locVMR9, L"Video Mixing Renderer 9");
00439                 
00440                 //TODO::: Need an error check ?
00441 
00442                 IVMRFilterConfig9* locVMR9Config = NULL;
00443                 locHR = locVMR9->QueryInterface(IID_IVMRFilterConfig9, (void**)&locVMR9Config);
00444 
00445                 if (locHR == S_OK) {
00446                         locVMR9Config->SetRenderingMode(VMRMode_Windowless);
00447                         locVMR9Config->Release();
00448 
00449                         //Get the windowless control
00450                         IVMRWindowlessControl9* locVMR9Windowless = NULL;
00451                         locHR = locVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void**)&locVMR9Windowless);
00452 
00453                         if (locHR == S_OK) {
00454                                 mVMR9Window = locVMR9Windowless;
00455                                 mVideoRenderType = VR_VMR9;
00456                                 *debugLog<<"We got our VMR9 window"<<endl;
00457                         }
00458 
00459                 }
00460                 
00461                 numRef = locVMR9->Release();
00462                 //*debugLog<<"VMR9 ref count = "<<numRef<<endl;
00463                 mVideoRenderFilter = locVMR9;
00464         }
00465 
00466         if (mVideoRenderType == VR_NONE) {
00467                 //Attempt to use VMR7
00468                 IBaseFilter* locVMR7 = NULL;
00469 
00470                 *debugLog<<"Attempting VMR7 creation... making it !"<<endl;
00471                 locHR= CoCreateInstance(CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&locVMR7);
00472                 if (locHR == S_OK) {
00473                         locHR = mGraphBuilder->AddFilter(locVMR7, L"Video Mixing Renderer 7");
00474                         
00475                         //TODO::: Need an error check ?
00476 
00477                         IVMRFilterConfig* locVMR7Config = NULL;
00478                         locHR = locVMR7->QueryInterface(IID_IVMRFilterConfig, (void**)&locVMR7Config);
00479 
00480                         if (locHR == S_OK) {
00481                                 locVMR7Config->SetRenderingMode(VMRMode_Windowless);
00482                                 locVMR7Config->Release();
00483 
00484                                 //Get the windowless control
00485                                 IVMRWindowlessControl* locVMR7Windowless = NULL;
00486                                 locHR = locVMR7->QueryInterface(IID_IVMRWindowlessControl, (void**)&locVMR7Windowless);
00487 
00488                                 if (locHR == S_OK) {
00489                                         mVMR7Window = locVMR7Windowless;
00490                                         mVideoRenderType = VR_VMR7;
00491                                 }
00492 
00493                         }
00494                         
00495                         numRef = locVMR7->Release();
00496                         //*debugLog<<"VMR7 ref count = "<<numRef<<endl;
00497 
00498                         mVideoRenderFilter = locVMR7;
00499                 }
00500         }
00501 
00502         if (mWindowHandle != NULL) {
00503                 *debugLog<<"Setting up video window pointer..."<<endl;
00504 
00505                 IVMRWindowlessControl9* locVMR9Window = NULL;
00506                 IVMRWindowlessControl* locVMR7Window = NULL;
00507                 IVideoWindow* locVideoWindow = NULL;
00508 
00509                 switch ((int)mVideoRenderType) {
00510                         case VR_VMR9:
00511                                 *debugLog<<"Attemping to use VMR9 windowless"<<endl;
00512                                 //Get the IVMRWindowlessControl9 interface.
00513                                 
00514                                 locHR = locVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void**)&locVMR9Window);
00515         
00516                                 if (locHR == S_OK) {
00517                                         *debugLog<<"Got VMR9 windowless interface"<<endl;
00518                                         mVMR9Window = locVMR9Window;
00519                                         
00520                                         locHR = mVMR9Window->SetVideoClippingWindow(  ((HWND)((int)mWindowHandle)));
00521                                         if (locHR == S_OK) {
00522                                                 *debugLog<<"Clipping window set"<<endl;
00523                                                 RECT locRect;
00524                                                 locRect.left = mLeft;
00525                                                 locRect.top = mTop;
00526                                                 locRect.right = mLeft + mWidth;
00527                                                 locRect.bottom = mTop + mHeight;
00528         
00529                                                 locHR = mVMR9Window->SetVideoPosition(NULL, &locRect);
00530                                                 if (locHR == S_OK) {
00531                                                         *debugLog<<"video pos set"<<endl;
00532                                                 } else {
00533                                                         *debugLog<<"video pos set FAILED"<<endl;
00534                                                 }
00535                                         } else {
00536                                                 *debugLog<<"Clipping window set FAILED"<<endl;
00537                                         }
00538                                 }
00539                                 
00540 
00541                                 break;
00542                         case VR_VMR7:
00543                                 break;
00544                         default:
00545                                 //Get the IVideoWindow interface.
00546 
00547                                 locHR = mGraphBuilder->QueryInterface(IID_IVideoWindow, (void**)&locVideoWindow);
00548         
00549                                 if (locHR == S_OK) {
00550                                         mVideoWindow = locVideoWindow;
00551                                         mVideoWindow->put_Owner((int)mWindowHandle);
00552                                         mVideoWindow->SetWindowPosition(mLeft, mTop, mWidth, mHeight);
00553                                         mVideoWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
00554                                 }
00555                                 break;
00556                 }
00557         }
00558 
00559 
00560 
00561 
00562         *debugLog<<"About to call render on "<<endl;
00563         //Build the graph
00564         locHR = mGraphBuilder->RenderFile(locWFileName.c_str(), NULL);
00565 
00566         if (locHR != S_OK) {
00567                 *debugLog<<"Render File FAILED !!"<<endl;
00568                 mIsLoaded = false;
00569                 return false;
00570         }
00571 
00572         //CHANGES::: Use this to get information about the video, once it's been rendered.
00573         GetVideoInformation();
00574 
00575         *debugLog<<"Render must have been ok"<<endl;
00576         if (isFileAnnodex(inFileName)) {
00577                 *debugLog<<"Is annodex"<<endl;
00578                 //Get the app control interface for CMML.
00579                 IBaseFilter* locCMMLFilter = NULL;
00580                 locHR = mGraphBuilder->FindFilterByName(L"CMML Decode Filter", &locCMMLFilter);
00581                 
00582 
00583                 if (locCMMLFilter != NULL) {
00584                         ICMMLAppControl* locCMMLAppControl = NULL;
00585                         
00586                         locHR = locCMMLFilter->QueryInterface(X_IID_ICMMLAppControl, (void**)&locCMMLAppControl);
00587                         if (locCMMLAppControl != NULL) {
00588                                 mCMMLAppControl = locCMMLAppControl;
00589                                 mCMMLAppControl->setCallbacks(mCMMLProxy);
00590                         }
00591                         numRef = 
00592                 locCMMLFilter->Release();
00593 
00594                         *debugLog<<"CMML Filter ref Count = "<<numRef<<endl;
00595                 }
00596 
00597         }
00598         *debugLog<<"After CMML Code..."<<endl;
00599 
00600         //Get the media control interface
00601         IMediaControl* locMediaControl = NULL;
00602         locHR = mGraphBuilder->QueryInterface(IID_IMediaControl, (void**)&locMediaControl);
00603         mMediaControl = locMediaControl;
00604 
00605         if (locHR != S_OK) {
00606                 mIsLoaded = false;
00607                 return false;
00608         } else {
00609                 mIsLoaded = true;
00610         }
00611 
00612         //get the media seeking interface if its available.
00613         IMediaSeeking* locMediaSeeking = NULL;
00614         locHR = mGraphBuilder->QueryInterface(IID_IMediaSeeking, (void**)&locMediaSeeking);
00615         mMediaSeeking = locMediaSeeking;
00616 
00617         //Get the media event interface
00618         IMediaEvent* locMediaEvent = NULL;
00619         locHR = locGraphBuilder->QueryInterface(IID_IMediaEvent, (void**)&locMediaEvent);
00620 
00621         if (locHR == S_OK) {
00622                 mMediaEvent = locMediaEvent;
00623                 HANDLE locEventHandle = INVALID_HANDLE_VALUE;
00624                 locHR = locMediaEvent->GetEventHandle((OAEVENT*)&locEventHandle);
00625                 mEventHandle = locEventHandle;
00626         }
00627 
00628         //Get the IBasicAudio Interface
00629         IBasicAudio* locBasicAudio = NULL;
00630         locHR = mGraphBuilder->QueryInterface(IID_IBasicAudio, (void**)&locBasicAudio);
00631         if (locHR == S_OK) {
00632                 mBasicAudio = locBasicAudio;
00633         } else {
00634                 mBasicAudio = NULL;
00635         }
00636 
00637         //Get the IVideFrameStep if ity exists
00638         IVideoFrameStep* locVideoStep = NULL;
00639         locHR = mGraphBuilder->QueryInterface(IID_IVideoFrameStep, (void**)&locVideoStep);
00640         if (locHR == S_OK) {
00641                 mVideoFrameStep = locVideoStep;
00642         } else {
00643                 mVideoFrameStep = NULL;
00644         }
00645 
00646 
00647 
00648 //      if (FAILED(hr))
00649 
00650         return true;
00651 
00652 
00653 }
00654 
00655 System::Drawing::Bitmap* DSPlay::GetImage() {
00656         HRESULT locHR = S_OK;
00657         System::Drawing::Bitmap* locBitmap = NULL;
00658         BYTE* locBytes = NULL;
00659 
00660         switch (mVideoRenderType) {
00661                 case VR_VMR9:
00662                         if (mVMR9Window != NULL) {
00663                                 locHR = mVMR9Window->GetCurrentImage(&locBytes);
00664                                 if (locHR == S_OK) {
00665                                         BITMAPINFOHEADER* locBMIH = (BITMAPINFOHEADER*) locBytes;
00666                                         *debugLog<<"BHIM : Bit count = "<<locBMIH->biBitCount<<endl;
00667                                         *debugLog<<"BHIM : Compresio = "<<locBMIH->biCompression<<endl;
00668                                         *debugLog<<"BHIM : Colours   = "<<locBMIH->biClrUsed<<endl;
00669                                         *debugLog<<"BHIM : Width     = "<<locBMIH->biWidth<<endl;
00670                                         *debugLog<<"BHIM : Height    = "<<locBMIH->biHeight<<endl;
00671                                         *debugLog<<"BHIM : Size Img  = "<<locBMIH->biSizeImage<<endl;
00672                                         *debugLog<<"BHIM : Size      = "<<locBMIH->biSize<<endl;
00673                                         *debugLog<<"BHIM : Size BMIH = "<<sizeof(BITMAPINFOHEADER)<<endl;
00674                                         *debugLog<<"BHIM : Size BMI  = "<<sizeof(BITMAPINFO)<<endl;
00675 
00676                                         
00677 
00678                                         
00679 
00680 
00681                                         if (locBMIH->biBitCount == 32) {
00682                                                 unsigned char* locBuffer = new unsigned char[locBMIH->biSizeImage];
00683                                                 memcpy((void*)locBuffer, (const void*)(locBytes + 44), locBMIH->biSizeImage);
00684                                                 locBitmap = new System::Drawing::Bitmap(locBMIH->biWidth, locBMIH->biHeight, locBMIH->biWidth * 4, System::Drawing::Imaging::PixelFormat::Format32bppRgb, (System::IntPtr)(locBuffer));
00685                                                 locBitmap->RotateFlip(System::Drawing::RotateFlipType::RotateNoneFlipY);
00686                                         }
00687 
00688                                         /* .... */
00689                                         
00690                                         
00691                                         CoTaskMemFree(locBytes);
00692                                         
00693 
00694                                 }
00695 
00696                         }
00697 
00698                 default:
00699                         break;
00700         };
00701 
00702         return locBitmap;;
00703 }
00704 
00705 bool DSPlay::setCMMLCallbacks(IDNCMMLCallbacks* inCMMLCallbacks) {
00706         return mCMMLProxy->setManagedDelegate(inCMMLCallbacks);
00707 }
00708 
00709 bool DSPlay::isLoaded() {
00710         return mIsLoaded;
00711 }
00712 bool DSPlay::play() {
00713         if (mIsLoaded) {
00714                 HRESULT locHR = mMediaControl->Run();
00715                 if (SUCCEEDED(locHR)) {
00716                         return true;
00717                 } else {
00718                         return false;
00719                 }
00720         } else {
00721                 return false;
00722         }
00723 }
00724 
00725 bool DSPlay::pause() {
00726         if (mIsLoaded) {
00727                 HRESULT locHR = mMediaControl->Pause();
00728                 if (locHR != S_OK) {
00729                         return false;
00730                 } else {
00731                         return true;
00732                 }
00733         } else {
00734                 return false;
00735         }
00736 }
00737 
00738 bool DSPlay::stop() {
00739         if (mIsLoaded) {
00740                 HRESULT locHR = mMediaControl->Stop();
00741                 if (locHR != S_OK) {
00742                         return false;
00743                 } else {
00744                         seek(0);
00745                         return true;
00746                 }
00747         } else {
00748                 return false;
00749         }
00750 }
00751 
00752 Int64 DSPlay::seek(Int64 inTime) {
00753         if (mIsLoaded && (mMediaSeeking != NULL)) {
00754                 LONGLONG locCurrent = inTime;
00755                 LONGLONG locStop = 0;
00756                 HRESULT locHR = mMediaSeeking->SetPositions(&locCurrent, AM_SEEKING_AbsolutePositioning | AM_SEEKING_ReturnTime, 
00757                                                                                                         &locStop, AM_SEEKING_NoPositioning);
00758                 
00759                 if (SUCCEEDED(locHR)) {
00760                         return locCurrent;
00761                 } else {
00762                         return -1;
00763                 }
00764         } else {
00765                 return -1;
00766         }
00767         
00768 }
00769 
00770 bool DSPlay::canStepFrame() {
00771         if (mVideoFrameStep != NULL) {
00772                 HRESULT locHR = mVideoFrameStep->CanStep(0, NULL);
00773                 if (locHR == S_OK) {
00774                         return true;
00775                 }
00776         }
00777         return false;
00778 }
00779 
00780 bool DSPlay::stepFrame() {
00781         if (mVideoFrameStep != NULL) {
00782                 HRESULT locHR = mVideoFrameStep->Step(1, NULL);
00783                 if (locHR == S_OK) {
00784                         return true;
00785                 }
00786         }
00787         return false;
00788 }
00789 
00790 Int64 DSPlay::seekStart() {
00791         return seek(0);
00792 }
00793 
00794 Int64 DSPlay::queryPosition() {
00795         if (mIsLoaded && (mMediaSeeking != NULL)) {
00796                 __int64 locStart = -1;
00797                 __int64 locStop = -1;
00798                 HRESULT locHR = mMediaSeeking->GetPositions(&locStart, &locStop);
00799                 if (locHR == S_OK) {
00800                         return locStart;
00801                 } else {
00802                         return -1;
00803                 }
00804         } else {
00805                 return -1;      
00806         }
00807 }
00808 
00809 Int64 DSPlay::fileSize() {
00810         if (mIsLoaded) {
00811                 return mFileSize;       
00812         } else {
00813                 return -1;
00814         }
00815 }
00816 Int64 DSPlay::fileDuration() {
00817         if (mIsLoaded && (mMediaSeeking != NULL)) {
00818                 LONGLONG locDuration = 0;
00819                 HRESULT locHR = mMediaSeeking->GetDuration(&locDuration);
00820 
00821                 if (locHR != S_OK) {
00822                         return -1;
00823                 } else {
00824                         return locDuration;
00825                 }
00826         } else {
00827                 return -1;
00828         }
00829 }
00830 
00831 bool DSPlay::isFileAnnodex(String* inFilename)
00832 {
00833         String* locExt = (inFilename->Substring(inFilename->Length - 4, 4))->ToUpper();
00834         if (locExt->Equals(".ANX")) {
00835                 return true;
00836         } else {
00837                 return false;
00838         }
00839 }
00840 
00841 bool DSPlay::setMediaEventCallback(IDNMediaEvent* inMediaEventCallback) {
00842         mDNMediaEvent = inMediaEventCallback;
00843         return true;
00844 }
00845 IDNMediaEvent* DSPlay::getMediaEventCallback() {
00846         return mDNMediaEvent;
00847 }
00848 
00849 
00851 Int64 DSPlay::averageTimePerFrame() {
00852         return mAvgTimePerFrame;
00853 }
00854 
00856 Int64 DSPlay::averageFrameRate() {
00857 
00858         if (mAvgTimePerFrame != 0) {
00859                 Int64 locFrameRate = (10000000 * 100);
00860                 locFrameRate /= mAvgTimePerFrame;
00861                 return locFrameRate;
00862         } else {
00863                 return 0;
00864         }
00865 }
00866 
00868 Int32 DSPlay::videoWidth() {
00869         return mVideoWidth;
00870 }
00871 
00873 Int32 DSPlay::videoHeight() {
00874         return mVideoHeight;
00875 }
00876 
00877 
00878 } //end namespace libDSPlayDotNET
00879 } //end namespace illiminable

Generated on Thu Feb 16 23:48:18 2006 for oggdsf by  doxygen 1.3.9