189 lines
5.0 KiB
C++
189 lines
5.0 KiB
C++
/*************************************************************************/
|
|
/* File : VideoSeek.cpp */
|
|
/* */
|
|
/* Author : Leïla AIT KACI */
|
|
/* Last Modification : 28/05/03 */
|
|
/*************************************************************************/
|
|
#include "CKAll.h"
|
|
#include "CKVideo.h"
|
|
#include "CKVideoManager.h"
|
|
|
|
CKObjectDeclaration* FillBehaviorVideoSeekDecl ();
|
|
CKERROR CreateVideoSeekProto (CKBehaviorPrototype **);
|
|
int VideoSeek (const CKBehaviorContext& BehContext);
|
|
CKERROR VideoSeekCB (const CKBehaviorContext& BehContext);
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Defines
|
|
//////////////////////////////////////////////////////////////////////
|
|
#define BB_NAME "Video Seek"
|
|
#define BB_DESC "Seek in a video."
|
|
#define BB_CAT "Video/Basic"
|
|
#define BB_VERSION 0x00010000
|
|
#define BB_TARGET CKCID_VIDEO
|
|
|
|
#define RETURN_IF_FAILED(res) \
|
|
if ( res != CK_OK ) { \
|
|
XString err = video->GetErrorDescrition(res); \
|
|
beh->SetOutputParameterValue(POUT_ERROR, err.Str(), err.Length() + 1 ); \
|
|
beh->ActivateOutput(OUT_ERROR); \
|
|
return CKBR_OK; \
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Enums for Parameter's Indexes
|
|
//////////////////////////////////////////////////////////////////////
|
|
enum BB_IN
|
|
{
|
|
IN_IN
|
|
};
|
|
|
|
enum BB_OUT
|
|
{
|
|
OUT_OUT,
|
|
OUT_ERROR
|
|
};
|
|
|
|
enum BB_LOC
|
|
{
|
|
SET_HOMOGENEOUS
|
|
};
|
|
|
|
enum BB_PIN
|
|
{
|
|
PIN_INTIME
|
|
};
|
|
|
|
enum BB_POUT
|
|
{
|
|
POUT_ERROR
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKObjectDeclaration *FillBehaviorVideoSeekDecl()
|
|
{
|
|
CKObjectDeclaration *od = CreateCKObjectDeclaration(BB_NAME);
|
|
od->SetType(CKDLL_BEHAVIORPROTOTYPE);
|
|
od->SetCompatibleClassId(BB_TARGET);
|
|
od->SetDescription(BB_DESC);
|
|
od->SetVersion(BB_VERSION);
|
|
od->SetCategory(BB_CAT);
|
|
od->SetAuthorName("Virtools");
|
|
od->SetAuthorGuid(VIRTOOLS_GUID);
|
|
od->SetGuid(CKGUID(0x10685f49,0xb370229));
|
|
od->SetCreationFunction(CreateVideoSeekProto);
|
|
|
|
return od;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKERROR CreateVideoSeekProto(CKBehaviorPrototype** pproto)
|
|
{
|
|
CKBehaviorPrototype *proto = CreateCKBehaviorPrototype(BB_NAME);
|
|
if(!proto) return CKERR_OUTOFMEMORY;
|
|
|
|
//--- Inputs declaration
|
|
proto->DeclareInput("In");
|
|
|
|
//--- Outputs declaration
|
|
proto->DeclareOutput("Out");
|
|
proto->DeclareOutput("Error");
|
|
|
|
//----- Input Parameters Declaration
|
|
proto->DeclareInParameter("Position", CKPGUID_TIME);
|
|
|
|
//--- Output Parameters Declaration
|
|
proto->DeclareOutParameter("Error", CKPGUID_STRING);
|
|
|
|
//---- Settings Declaration
|
|
proto->DeclareSetting("Homogeneous", CKPGUID_BOOL, "FALSE");
|
|
|
|
proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL);
|
|
proto->SetBehaviorFlags((CK_BEHAVIOR_FLAGS)(CKBEHAVIOR_TARGETABLE));
|
|
proto->SetBehaviorCallbackFct(VideoSeekCB, CKCB_BEHAVIORSETTINGSEDITED|CKCB_BEHAVIORCREATE, NULL);
|
|
proto->SetFunction(VideoSeek);
|
|
|
|
*pproto = proto;
|
|
return CK_OK;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
int VideoSeek(const CKBehaviorContext& BehContext)
|
|
{
|
|
CKContext* ctx = BehContext.Context;
|
|
CKBehavior* beh = BehContext.Behavior;
|
|
|
|
beh->ActivateInput(IN_IN, FALSE);
|
|
|
|
CKVideo* video = (CKVideo*) beh->GetTarget();
|
|
if ( !video ) {
|
|
XString err = "Invalid Video";
|
|
beh->SetOutputParameterValue(POUT_ERROR, err.Str(), err.Length() + 1 );
|
|
beh->ActivateOutput(OUT_ERROR);
|
|
return CKBR_OK;
|
|
}
|
|
|
|
CK_VIDEO_STATE State = video->GetState();
|
|
switch ( State )
|
|
{
|
|
////////////////////////
|
|
case CK_VIDEO_INVALID:
|
|
RETURN_IF_FAILED( CK_VIDEOERR_NOTLOADED );
|
|
break;
|
|
|
|
////////////////////////
|
|
case CK_VIDEO_LOADING:
|
|
RETURN_IF_FAILED( CK_VIDEOERR_LOADING );
|
|
break;
|
|
|
|
////////////////////////
|
|
case CK_VIDEO_UNLOADING:
|
|
RETURN_IF_FAILED( CK_VIDEOERR_UNLOADING );
|
|
break;
|
|
|
|
////////////////////////
|
|
case CK_VIDEO_STOPPED:
|
|
case CK_VIDEO_PLAYING:
|
|
case CK_VIDEO_PAUSED:
|
|
{
|
|
CKBOOL Homogeneous;
|
|
beh->GetLocalParameterValue(SET_HOMOGENEOUS, &Homogeneous);
|
|
|
|
float SeekTime = 0;
|
|
beh->GetInputParameterValue(PIN_INTIME, &SeekTime);
|
|
|
|
RETURN_IF_FAILED( video->Seek(SeekTime, Homogeneous) );
|
|
beh->SetOutputParameterValue(POUT_ERROR, "Success", 8);
|
|
beh->ActivateOutput(OUT_OUT);
|
|
}
|
|
break;
|
|
}
|
|
|
|
return CKBR_OK;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKERROR VideoSeekCB(const CKBehaviorContext& BehContext)
|
|
{
|
|
CKContext* ctx = BehContext.Context;
|
|
CKBehavior* beh = BehContext.Behavior;
|
|
|
|
// Get Settings
|
|
CKBOOL Homogeneous;
|
|
beh->GetLocalParameterValue(SET_HOMOGENEOUS, &Homogeneous);
|
|
|
|
// Change Pin Type
|
|
CKParameterIn* pin = beh->GetInputParameter(PIN_INTIME);
|
|
if ( Homogeneous )
|
|
pin->SetGUID(CKPGUID_PERCENTAGE);
|
|
else
|
|
pin->SetGUID(CKPGUID_TIME);
|
|
|
|
return CKBR_OK;
|
|
}
|