CMedia更新至v1.4.3

CMedia更新至v1.4.3版本,新增了GetMediaProperty函数的属性,包括影片时长等,并提供了SetRate()等控制播放速率和位置的方法。此外还改进了窗口通知等功能。

//========================================================================
//TITLE:
// CMedia更新至v1.4.3
//AUTHOR:
// norains
//DATE:
// Friday 27-July-2007
//Environment:
// EVC4.0 + Windows CE 5.0 Standard SDK
//========================================================================

相对v1.2.0版本进行的改进:

1.增加GetMediaProperty函数获得的属性,增加如下属性:llDuration,llAvailableEarliest,llAvailableLatest.

2.增加如下函数:SetRate(),GetRate(),GetPositionCurrent(),SetPositionCurrent() ,GetDisplayMode()

3.改进之前一些函数的HRESULT值返回BOOL值的判定方法

4.增加SetVideoWindow()一个参数,以设置可以在窗口的任意位置为起点播放视频

5.改进SetDisplayMode()函数,当窗口句柄为空时,设置播放区域为0,并返回FALSE

6.改进SetNotifyWindow()函数,令其能够接收普通的窗口消息

7.Open()的参数改为const类型,更符合实际意义


v1.2.0版本及相关用法见:http://blog.youkuaiyun.com/norains/archive/2007/05/14/1609118.aspx


我们来看看具体更新了哪些功能:

1.MEDIAPROPERTY

增加了llDuration,llAvailableEarliest,llAvailableLatest属性,分别代表影片的时间长度,最早的可拖拽的时间位置,最早的可拖拽的时间位置.这个属性可以用在GetMediaProperty()函数中.



2.SetRate(),GetRate()

SetRate()设置当前的播放速率,"1"为正常速率,"2"即为两倍速,以此类推.

GetRate()获取当前播放的速率.



3.GetPositionCurrent(),SetPositionCurrent()

GetPositionCurrent():获取当前的时间位置,返回的时间值以100ns为基本单位.

SetPositionCurrent():设置播放的时间位置,该范围必须是llAvailableEarliest和llAvailableLatest之间的数值.



4.GetDisplayMode()

该函数用来获取当前的播放模式.




v1.4.3的完整代码如下:


///////////////////////////////////////////////////////////////////////
//Media.h:interfacefortheCMediaclass.
//
//Version:
//1.4.3
//Date:
//2007.07.19
//////////////////////////////////////////////////////////////////////
#ifndefMEDIA_H
#defineMEDIA_H


#include
<mmsystem.h>
#include
<streams.h>

//--------------------------------------------------------------------
//Macrodefine

//Thevolumevalue
#defineMAX_VOLUME0
#defineMIN_VOLUME-10000

//Thebalancevalue
#defineMAX_BALANCE10000
#defineMIN_BALANCE-10000

//Theflagmeansthattheareaisthewholewindow
constRECTRC_WHOLE_WINDOWN_AREA={0,0,0,0};

//--------------------------------------------------------------------
//Enumvalue

enumDISPLAYMODE
{
//Fittotheplaywindowsize.Howwide(height)thewindowis,how
//isthemove.Keepaspectratio.
DISP_FIT,

//Notsupport.Stretchtotheplaywindowsize.Don'tkeeptheaspectratio.
DISP_STRETCH,

//Fullscreenplay.
DISP_FULLSCREEN,

//Whenthesizeofvideoissmallerthantheplaywindow,itdisplayes
//asthevideosize.Ifit'sbigger,itjustliketheDISP_FITmode.
DISP_NATIVE
};
//--------------------------------------------------------------------

//Themediafileproperty
typedefstruct
{

//Thevolumerangeis–10,000to0.
//Divideby100togetequivalentdecibelvalue(forexample–10,000=–100dB).
LONGlVolume;


//Thevaluefrom–10,000to10,000indicatingthestereobalance
//AswiththeVolumeproperty,unitscorrespondto.01decibels(multipliedby–1whenplBalanceisapositivevalue).
//Forexample,avalueof1000indicates–10dBontherightchanneland–90dBontheleftchannel.
LONGlBalance;


//Widthofthevideo
LONGlWidth;


//Heightofthevideo
LONGlHeight;


//Approximatebitrate
LONGlBitRate;

//Thelengthoftimethatthemediastreamwillplay.
//Thedurationassumesnormalplaybackspeed,anditisthereforeunaffectedbytherate
LONGLONGllDuration;


//Earliesttimethatcanbeefficientlyseekedto.
LONGLONGllAvailableEarliest;

//Latesttimethatcanbeefficientlyseekedto
LONGLONGllAvailableLatest;

}MEDIAPROPERTY,
*PMEDIAPROPERTY;
//--------------------------------------------------------------------
classCMedia
{
public:
DISPLAYMODEGetDisplayMode();
BOOLSetPositionCurrent(LONGLONGllPos);
BOOLGetPositionCurrent(LONGLONG
*pllPos);
BOOLGetRate(
double*pdRate);
BOOLSetRate(
doubledRate);
BOOLGetEvent(LONG
*plEvCode,LONG*plParam1,LONG*plParam2);
BOOLSetNotifyWindow(HWNDhWnd,UINTwMsg,
longlInstanceData);
BOOLSetVolume(LONGlVolume,LONGlBalance
=0);
BOOLSetDisplayMode(DISPLAYMODEmode);
BOOLGetMediaProperty(PMEDIAPROPERTYpOutProperty);
staticCMedia*GetInstance();
voidClose();
BOOLCheckVisibility();
BOOLSetVideoWindow(HWNDhWndVideo,
constRECT&rcDisp=RC_WHOLE_WINDOWN_AREA);
BOOLOpen(
constTCHAR*pcszFileName);
BOOLStop();
BOOLPause();
BOOLPlay();
virtual~CMedia();

protected:


CMedia();

//Collectionofinterfaces
IGraphBuilder*m_pGB;
IMediaControl
*m_pMC;
IMediaEventEx
*m_pME;
IVideoWindow
*m_pVW;
IBasicAudio
*m_pBA;
IBasicVideo
*m_pBV;
IMediaSeeking
*m_pMS;

TCHARm_szFileName[MAX_PATH];
HWNDm_hWndVideo;
//Thewindowplayvideo
HWNDm_hWndNotify;//Thewindownotify
BOOLm_bExitThrd;
BOOLm_bThrdRunning;
staticCMedia*m_pInstance;
DISPLAYMODEm_DispMode;
DWORDm_dwCapability;
RECTm_rcDisp;
};

#endif//#ifndefMEDIA_H


///////////////////////////////////////////////////////////////////////
//Media.cpp:implementationoftheCMediaclass.
//
//////////////////////////////////////////////////////////////////////

#include
"stdafx.h"
#include
"Media.h"



//========================================================================================================
//Linkthe.lib
//Thelibalsoiscopyfrom"(InstallDir)WINCE500PUBLICDIRECTXSDKLIB"

#pragmacomment(lib,"Ole32.lib")

#ifdefCPU_X86EM
#pragmacomment(lib,"./lib/X86em/Strmiids.lib")
#pragmacomment(lib,"./lib/X86em/Strmbase.lib")
#endif

#ifdefCPU_MIPSII
#pragmacomment(lib,"./lib/MIPSII/Strmiids.lib")
#pragmacomment(lib,"./lib/MIPSII/Strmbase.lib")
#endif

#ifdefCPU_ARM4I
#pragmacomment(lib,"./lib/ARM4I/Strmiids.lib")
#pragmacomment(lib,"./lib/ARM4I/Strmbase.lib")
#endif
//========================================================================================================

//----------------------------------------------------------------------------------------------
//Macrodefine

//Defaultplaymode
#defineDEFAULT_DISPLAY_MODEDISP_NATIVE

//----------------------------------------------------------------------
//Initialize
CMedia*CMedia::m_pInstance=NULL;
//------------------------------------------------------------------------


//////////////////////////////////////////////////////////////////////
//Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMedia::CMedia():
m_pGB(NULL),
m_pMC(NULL),
m_pME(NULL),
m_pVW(NULL),
m_pBA(NULL),
m_pBV(NULL),
m_pMS(NULL),
m_hWndVideo(NULL),
m_bExitThrd(TRUE),
m_bThrdRunning(FALSE),
m_DispMode(DEFAULT_DISPLAY_MODE),
m_hWndNotify(NULL),
m_rcDisp(RC_WHOLE_WINDOWN_AREA)
{
memset(m_szFileName,
0,sizeof(m_szFileName));
}

CMedia::
~CMedia()
{
if(m_pInstance!=NULL)
{
deletem_pInstance;
m_pInstance
=NULL;
}

}




//------------------------------------------------------------
//Description:
//Playthemediafile
//Whenyoucallthefunction,youshouldcallOpen()before.
//
//-------------------------------------------------------------
BOOLCMedia::Play()
{
//Runthegraphtoplaythemediafile

if(m_pMC==NULL)
{
returnFALSE;
}




returnSUCCEEDED(m_pMC->Run());

}




//------------------------------------------------------------
//Description:
//Pause.
//Whenyoucallthefunction,youshouldcallOpen()before.
//
//-------------------------------------------------------------
BOOLCMedia::Pause()
{

if(m_pMC==NULL)
{
returnFALSE;
}

returnSUCCEEDED(m_pMC->Pause());


}




//------------------------------------------------------------
//Description:
//Stop.
//Whenyoucallthefunction,youshouldcallOpen()before.
//
//-------------------------------------------------------------
BOOLCMedia::Stop()
{

if(m_pMC==NULL||m_pMS==NULL)
{
returnFALSE;
}

HRESULThr;
hr
=m_pMC->Stop();
SetPositionCurrent(
0);

returnSUCCEEDED(hr);
}




//--------------------------------------------------------------------------
//Description:
//Openthemediafile.Whensucceedincallingthefunction,
//youshouldcalltheClose()toreleasetheresource
//
//-------------------------------------------------------------------------
BOOLCMedia::Open(constTCHAR*pcszFileName)
{
BOOLbResult
=FALSE;


if(_tcslen(pcszFileName)>=MAX_PATH)
{
gotoEND;
}
else
{
_tcscpy(m_szFileName,pcszFileName);

//Checkthefileexisting
HANDLEhdFile=CreateFile(m_szFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,NULL,NULL);
if(hdFile==INVALID_HANDLE_VALUE)
{
//Thefiledoesn'texist
gotoEND;
}
else
{
CloseHandle(hdFile);
}
}





//InitializeCOM
if(CoInitializeEx(NULL,COINIT_MULTITHREADED)!=S_OK)
{
gotoEND;
}

//GettheinterfaceforDirectShow'sGraphBuilder
if(CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void**)&m_pGB)!=S_OK)
{
gotoEND;
}


//Havethegraphconstructitstheappropriategraphautomatically
if(m_pGB->RenderFile(m_szFileName,NULL)!=NOERROR)
{
gotoEND;
}


//QueryInterfaceforDirectShowinterfaces
if(m_pGB->QueryInterface(IID_IMediaControl,(void**)&m_pMC)!=NOERROR)
{
gotoEND;
}
if(m_pGB->QueryInterface(IID_IMediaEventEx,(void**)&m_pME)!=NOERROR)
{
gotoEND;
}
if(m_pGB->QueryInterface(IID_IMediaSeeking,(void**)&m_pMS)!=NOERROR)
{
gotoEND;
}



//Queryforvideointerfaces,whichmaynotberelevantforaudiofiles
if(m_pGB->QueryInterface(IID_IVideoWindow,(void**)&m_pVW)!=NOERROR)
{
gotoEND;
}
if(m_pGB->QueryInterface(IID_IBasicVideo,(void**)&m_pBV)!=NOERROR)
{
gotoEND;
}

if(CheckVisibility()==FALSE)
{
//Itjustbetheaudiofile,anddon'tneedvideofilter.

//Relinquishownership(IMPORTANT!)afterhiding
if(m_pVW!=NULL)
{
m_pVW
->put_Visible(OAFALSE);
m_pVW
->put_Owner(NULL);
}

if(m_pBV!=NULL)
{
m_pBV
->Release();
m_pBV
=NULL;
}


if(m_pVW!=NULL)
{
m_pVW
->Release();
m_pVW
=NULL;
}
}


//Queryforaudiointerfaces,whichmaynotberelevantforvideo-onlyfiles
if(m_pGB->QueryInterface(IID_IBasicAudio,(void**)&m_pBA)!=NOERROR)
{
gotoEND;
}


//Setplaymode
SetDisplayMode(m_DispMode);

//Getthecapabilitiesofthemediafile.
m_pMS->GetCapabilities(&m_dwCapability);

bResult
=TRUE;

END:

if(bResult==FALSE)
{
//Releasetheresource
Close();
}

returnbResult;
}




//------------------------------------------------------------
//Description:
//Thismethodsetsanowningparentforthevideowindow.
//
//Parameters:
//hWnd:[in]Handleofnewownerwindow.
//rcDisp:[in]Thedisplayarea.Iftheparameterisnotset,
//itwillbesetasRC_WHOLE_WINDOWN_AREAwhichmeansthai
//thewholewindowisfordisplayingthevideo.
//
//----------------------------------------------------------
BOOLCMedia::SetVideoWindow(HWNDhWndVideo,constRECT&rcDisp)
{
m_hWndVideo
=hWndVideo;

m_rcDisp
=rcDisp;

if(m_pVW==NULL)
{
returnFALSE;
}

if(FAILED(m_pVW->put_Owner((OAHWND)hWndVideo)))
{
returnFALSE;
}

if(FAILED(m_pVW->put_WindowStyle(WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN)))
{
returnFALSE;
}

//Setplaymodeinordertonotifythedisplayedarea
returnSetDisplayMode(m_DispMode);
}



//------------------------------------------------------------
//Description:
//Checkthefilevisibility
//Whenyoucallthefunction,youshouldcallOpen()before.
//
//Parameters:
//TRUE:Video
//FALSE:It'snotthevideo
//
//------------------------------------------------------------
BOOLCMedia::CheckVisibility()
{


if(!m_pVW)
{
//NoVideoWindowinterface.Assumingaudio/MIDIfileorunsupportedvideocodec
returnFALSE;
}

if(!m_pBV)
{
//NoBasicVideointerface.Assumingaudio/MIDIfileorunsupportedvideocodec.
returnFALSE;
}


//Ifthisisanaudio-onlyclip,get_Visible()won'twork.
//
//Also,ifthisvideoisencodedwithanunsupportedcodec,
//wewon'tseeanyvideo,althoughtheaudiowillworkifitis
//ofasupportedformat.
longlVisible;
returnSUCCEEDED(m_pVW->get_Visible(&lVisible));

}




//------------------------------------------------------------
//Description:
//ReleasetheresourcewhichopenedintheOpen()
//
//------------------------------------------------------------
voidCMedia::Close()
{

//Relinquishownership(IMPORTANT!)afterhiding
if(m_pVW!=NULL)
{
m_pVW
->put_Visible(OAFALSE);
m_pVW
->put_Owner(NULL);
}

if(m_pMC!=NULL)
{
m_pMC
->Release();
m_pMC
=NULL;
}

if(m_pME!=NULL)
{
m_pME
->SetNotifyWindow(NULL,NULL,NULL);

m_pME
->Release();
m_pME
=NULL;
}

if(m_pMS!=NULL)
{
m_pMS
->Release();
m_pMS
=NULL;
}

if(m_pBV!=NULL)
{
m_pBV
->Release();
m_pBV
=NULL;
}

if(m_pBA!=NULL)
{
m_pBA
->Release();
m_pBA
=NULL;
}

if(m_pVW!=NULL)
{
m_pVW
->Release();
m_pVW
=NULL;
}

if(m_pGB!=NULL)
{
m_pGB
->Release();
m_pGB
=NULL;
}

//FinishedwithCOM
memset(m_szFileName,0,sizeof(m_szFileName));


CoUninitialize();
}


//------------------------------------------------------------
//Description:
//Gettheinstanceofobject
//
//------------------------------------------------------------
CMedia*CMedia::GetInstance()
{
if(m_pInstance==NULL)
{
m_pInstance
=newCMedia();
}

returnm_pInstance;
}




//------------------------------------------------------------
//Description:
//Getthemediafileproperty.
//Whenyoucallthefunction,youshouldcallOpen()before.
//
//------------------------------------------------------------
BOOLCMedia::GetMediaProperty(PMEDIAPROPERTYpOutProperty)
{

MEDIAPROPERTYprop
={0};

if(m_pBA==NULL&&m_pBV==NULL&&m_pMS==NULL)
{
returnFALSE;
}


//Gettheaudioproperty
if(m_pBA!=NULL)
{
m_pBA
->get_Volume(&prop.lVolume);
m_pBA
->get_Balance(&prop.lBalance);
}


//Getthevideoproperty
if(CheckVisibility()==TRUE&&m_pBV!=NULL)
{
m_pBV
->get_BitRate(&prop.lBitRate);
m_pBV
->GetVideoSize(&prop.lWidth,&prop.lHeight);
}


//Gettheseekingproperty
if(m_pMS!=NULL)
{
m_pMS
->GetDuration(&prop.llDuration);
m_pMS
->GetAvailable(&prop.llAvailableEarliest,&prop.llAvailableLatest);
}



*pOutProperty=prop;


returnTRUE;
}


//------------------------------------------------------------
//Description:
//Setthedisplaymode.
//Whenyoucallthefunction,youshouldcallSetVideoWindow()before.
//Iftheparentwindows(m_hWndVideo)isNULL,thedisplayareawouldbesettozero.
//
//------------------------------------------------------------
BOOLCMedia::SetDisplayMode(DISPLAYMODEmode)
{

if(m_pVW==NULL)
{
returnFALSE;
}

if(m_hWndVideo==NULL)
{
m_pVW
->put_Left(0);
m_pVW
->put_Top(0);
m_pVW
->put_Width(0);
m_pVW
->put_Height(0);

returnFALSE;
}

m_DispMode
=mode;

if(mode==DISP_FULLSCREEN)
{
m_pVW
->put_FullScreenMode(OATRUE);
}
else
{
//Restoretothenormalmode
m_pVW->put_FullScreenMode(OAFALSE);

RECTrcWnd
=m_rcDisp;
if(rcWnd.left==RC_WHOLE_WINDOWN_AREA.left&&
rcWnd.top
==RC_WHOLE_WINDOWN_AREA.top&&
rcWnd.right
==RC_WHOLE_WINDOWN_AREA.right&&
rcWnd.bottom
==RC_WHOLE_WINDOWN_AREA.bottom)
{
GetClientRect(m_hWndVideo,
&rcWnd);
}
LONGlWndWidth
=rcWnd.right-rcWnd.left;
LONGlWndHeight
=rcWnd.bottom-rcWnd.top;

MEDIAPROPERTYprop
={0};
GetMediaProperty(
&prop);


if(mode==DISP_FIT||mode==DISP_NATIVE)
{
LONGlDispLeft,lDispTop,lDispWidth,lDispHeight;

if(mode==DISP_NATIVE&&lWndWidth>=prop.lWidth&&lWndHeight>=prop.lHeight)
{
lDispLeft
=(lWndWidth-prop.lWidth)/2+rcWnd.left;
lDispTop
=(lWndHeight-prop.lHeight)/2+rcWnd.top;
lDispWidth
=prop.lWidth;
lDispHeight
=prop.lHeight;
}
else
{
if(prop.lWidth*lWndHeight>lWndWidth*prop.lHeight)
{
lDispWidth
=lWndWidth;
lDispHeight
=(LONG)((float)lDispWidth/(float)prop.lWidth*prop.lHeight);
lDispLeft
=rcWnd.left;
lDispTop
=(lWndHeight-lDispHeight)/2+rcWnd.top;
}
elseif(prop.lWidth*lWndHeight<lWndWidth*prop.lHeight)
{
lDispHeight
=lWndHeight;
lDispWidth
=(LONG)((float)lDispHeight/(float)prop.lHeight*prop.lWidth);
lDispLeft
=(lWndWidth-lDispWidth)/2+rcWnd.left;
lDispTop
=rcWnd.top;
}
else
{
lDispWidth
=lWndWidth;
lDispHeight
=lWndHeight;
lDispLeft
=rcWnd.left;
lDispTop
=rcWnd.top;
}
}





m_pVW
->put_Left(lDispLeft);
m_pVW
->put_Top(lDispTop);
m_pVW
->put_Width(lDispWidth);
m_pVW
->put_Height(lDispHeight);
}
elseif(mode==DISP_STRETCH)
{

m_pVW
->put_Left(rcWnd.left);
m_pVW
->put_Top(rcWnd.top);
m_pVW
->put_Width(lWndWidth);
m_pVW
->put_Height(lWndHeight);
}

}



returnTRUE;
}


//------------------------------------------------------------
//Description:
//Setthevolume.
//Whenyoucallthefunction,youshouldcallOpen()before.
//
//Parameters:
//lVolume:[in]Thevolume(amplitude)oftheaudiosignal.
//Rangeis–10,000to0.
//lBalance:[in]Thebalancefortheaudiosignal.Defaultvalueis0.
//Thevaluefrom–10,000to10,000indicatingthestereobalance.
//
//------------------------------------------------------------
BOOLCMedia::SetVolume(LONGlVolume,LONGlBalance)
{
if(m_pBA==NULL)
{
returnFALSE;
}

if(lVolume<MIN_VOLUME&&lVolume>MAX_VOLUME&&lBalance<MIN_BALANCE&&lBalance>MAX_BALANCE)
{
returnFALSE;
}

m_pBA
->put_Volume(lVolume);
m_pBA
->put_Balance(lBalance);

returnTRUE;
}




//----------------------------------------------------------------------
//Description:
//Registersawindowthatwillhandlethenotifiedmessagewhenaspecifiedeventoccursandsomewindowmessage
//
//Parameters:
//hWnd:[in]Handleofwindowtonotify.PassNULLtostopnotification.
//wMsg:[in]Windowmessagetobepassedasthenotification.
//lInstanceData:[in]Value(instancedata)tobepassedasthelParamparameterforthelMsgmessage.
//
//Remarks:
//WhenthenotifiedwindowreceivethewMsgasthenotification,youcouldgettheeventcode.
//Thefollowcodesshowthatprocess:
//
////"WM_GRAPHNOTIFY"istheuser-definenotifiedmessage
//caseWM_GRAPHNOTIFY:
//{
//LONGevCode,evParam1,evParam2;
//
////"m_pMedia"istheinstanceoftheCMedia
//if(m_pMedia->GetEvent(&evCode,&evParam1,&evParam2)==TRUE)
//{
////Checktheeventcode
//if(evCode==EC_COMPLETE)
//{
////Dosomething
//}
//}
//return0;
//}
//
//Theeventcodeisasfollow:
//EC_ACTIVATEAnaudioorvideorendererislosingorgainingactivation.
//EC_BUFFERING_DATAThebufferingstatusischanging.
//EC_CLOCK_CHANGEDThefiltergraphhaschangedfromonereferenceclocktoanother.
//EC_COMPLETEAlldatahasbeenrendered.
//EC_DRM_LEVELNotifieswhencontentprotectedbydigitalrightsmanagement(DRM)requestssomeformofanalogcontentprotection.
//EC_END_OF_SEGMENTNotifiesthatasegmentendhasbeenreached.
//EC_ERROR_STILLPLAYINGAtleastonecalltoRunfailedinanactivefiltergraph.
//Thecurrentstateofanyunderlyingfiltergraphorgraphsisindeterminate;theymightberunning,butsomearealmostcertainlynot.
//EC_ERRORABORTAnerrorforcedtheterminationofarequestedoperation.
//EC_FULLSCREEN_LOSTThevideorendererisswitchingoutoffull-screenmode.
//EC_NEED_RESTARTThecurrentgraphmustbestoppedandrestarted.
//EC_NOTIFY_WINDOWPassthewindowhandlearoundduringpinconnection.
//EC_OLE_EVENTAfilterispassingatextstringtotheapplication.
//EC_OPENING_FILETheopenfilestatusischanging.
//EC_PALETTE_CHANGEDThevideopalettehaschanged.
//EC_QUALITY_CHANGETheplaybackqualityhaschanged.
//EC_REPAINTArepaintisrequired.
//EC_SEGMENT_STARTEDNotifiesthatanewsegmenthasbeenstarted.
//EC_SHUTTING_DOWNThefiltergraphisstartingtoshutdown.
//DirectShowpassesthisnotificationtoanyplug-indistributorsthatsupporttheIMediaEventSinkinterface.
//EC_STARVATIONOneofthefilters(usuallyaparserorfilesourcefilter)isnotreceivingenoughdata.
//Bydefault,thefiltergraphmanagerwillpauseallrunningfiltersandthenreturntonormaloperationwhenenoughdataisavailable.
//EC_STREAM_CONTROL_STARTEDThestartingreferencetimefromanearliercalltoIAMStreamControl::StartAtpassed.
//EC_STREAM_CONTROL_STOPPEDThestoppingreferencetimefromanearliercalltoIAMStreamControl::StopAtpassed.
//EC_STREAM_ERROR_STILLPLAYINGThestreamisstillplaying,butshouldnotbeplaying.
//EC_STREAM_ERROR_STOPPEDThestreamhasstopped,butshouldnothavestopped.
//EC_TIMETherequestedreferencetimeoccurred.
//EC_USERABORTAuserhasforcedtheterminationofarequestedoperation.
//EC_VIDEO_SIZE_AR_CHANGEDThesizeoraspectratioofthenativevideohaschanged.
//EC_VIDEO_SIZE_CHANGEDThesizeofthenativevideohaschanged.
//EC_WINDOW_DESTROYEDThevideorenderer'sfilterisbeingremovedordestroyed.
//
//
//
//DirectShowpassesthefollowingmessagestothewindowspecifiedbythehWndparameter,
//ifandwhentheapplicationgeneratesthem:
//WM_KEYDOWN
//WM_KEYUP
//WM_LBUTTONDBLCLK
//WM_LBUTTONDOWN
//WM_LBUTTONUP
//WM_MBUTTONDBLCLK
//WM_MBUTTONDOWN
//WM_MBUTTONUP
//WM_MOUSEACTIVATE
//WM_MOUSEMOVE
//WM_RBUTTONDBLCLK
//WM_RBUTTONDOWN
//WM_RBUTTONUP
//-----------------------------------------------------------------------------
BOOLCMedia::SetNotifyWindow(HWNDhWnd,UINTwMsg,longlInstanceData)
{


if(m_pME==NULL)
{
returnFALSE;
}

HRESULThr;
hr
=m_pME->SetNotifyWindow((OAHWND)hWnd,wMsg,lInstanceData);
if(FAILED(hr))
{
returnFALSE;
}

if(CheckVisibility()==TRUE&&m_pVW!=NULL)
{
hr
=m_pVW->put_MessageDrain((OAHWND)hWnd);
}




returnSUCCEEDED(hr);
}


//----------------------------------------------------------------------
//Description:
//Thismethodretrievesthenotificationevent.
//
//-----------------------------------------------------------------------
BOOLCMedia::GetEvent(LONG*plEvCode,LONG*plParam1,LONG*plParam2)
{
if(m_pME==NULL)
{
returnFALSE;
}

LONGevCode,evParam1,evParam2;

if(SUCCEEDED(m_pME->GetEvent(&evCode,&evParam1,&evParam2,0))==TRUE)
{
*plEvCode=evCode;
*plParam1=evParam1;
*plParam2=evParam2;

//Spinthroughtheevents
m_pME->FreeEventParams(evCode,evParam1,evParam2);
}
else
{
returnFALSE;
}


returnTRUE;
}


//----------------------------------------------------------------------
//Description:
//Thismethodsetsanewplaybackrate.
//
//Parameters
//dRate:[in]Newrate,where1isthenormalrate,2istwiceasfast,andsoon.

//-----------------------------------------------------------------------
BOOLCMedia::SetRate(doubledRate)
{
if(m_pMS==NULL)
{
returnFALSE;
}
returnSUCCEEDED(m_pMS->SetRate(dRate));
}


//----------------------------------------------------------------------
//Description:
//Thismethodretrievesthecurrentrate.
//
//Parameters:
//pdRate:[out]Therate
//-----------------------------------------------------------------------
BOOLCMedia::GetRate(double*pdRate)
{
if(m_pMS==NULL)
{
returnFALSE;
}

returnSUCCEEDED(m_pMS->GetRate(pdRate));

}

//----------------------------------------------------------------------
//Description:
//Thismethodretrievesthecurrentpositionintermsofthetotallengthofthemediastream
//
//Parameters:
//pllPos:[out]Currentposition.
//-----------------------------------------------------------------------
BOOLCMedia::GetPositionCurrent(LONGLONG*pllPos)
{
if(m_pMS==NULL)
{
returnFALSE;
}

if(m_dwCapability&AM_SEEKING_CanGetCurrentPos==0)
{
returnFALSE;
}

returnSUCCEEDED(m_pMS->GetCurrentPosition(pllPos));
}

//----------------------------------------------------------------------
//Description:
//Thismethodsetscurrentpositions
//
//Parameters:
//llPos:[in]Startpositionifstopped,orpositionfromwhichtocontinueifpaused.
//-----------------------------------------------------------------------
BOOLCMedia::SetPositionCurrent(LONGLONGllPos)
{
if(m_pMS==NULL)
{
returnFALSE;
}

LONGLONGllCur
=0;
if(GetPositionCurrent(&llCur)==TRUE)
{
if((llCur>llPos)&&(m_dwCapability&AM_SEEKING_CanSeekBackwards==0))
{
returnFALSE;
}
elseif((llCur<llPos)&&(m_dwCapability&AM_SEEKING_CanSeekForwards==0))
{
returnFALSE;
}
elseif(llCur==llPos)
{
//It'sthecurrentpositon,needn'tset
returnTRUE;
}
}
elseif((m_dwCapability&AM_SEEKING_CanSeekBackwards==0)||(m_dwCapability&AM_SEEKING_CanSeekForwards==0))
{
returnFALSE;
}


returnSUCCEEDED(m_pMS->SetPositions(&llPos,AM_SEEKING_AbsolutePositioning,NULL,AM_SEEKING_NoPositioning));
}


//----------------------------------------------------------------------
//Description:
//Thismethodgetcurrentdisplaymode
//
//----------------------------------------------------------------------
DISPLAYMODECMedia::GetDisplayMode()
{
returnm_DispMode;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值