deargui-vpl/ref/virtools/Samples/Behaviors/Video/Sources/Video Capture.cpp

164 lines
4.4 KiB
C++

/*************************************************************************/
/* File : VideoCapture.cpp */
/* */
/* Author : Leïla AIT KACI */
/* Last Modification : 28/05/03 */
/*************************************************************************/
#include "CKAll.h"
#include "CKVideo.h"
#include "CKVideoManager.h"
CKObjectDeclaration* FillBehaviorVideoCaptureDecl ();
CKERROR CreateVideoCaptureProto (CKBehaviorPrototype **);
int VideoCapture (const CKBehaviorContext& BehContext);
//////////////////////////////////////////////////////////////////////
// Defines
//////////////////////////////////////////////////////////////////////
#define BB_NAME "Video Capture"
#define BB_DESC "Capture the current image of 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
{
};
enum BB_PIN
{
PIN_TARGET_TEXTURE
};
enum BB_POUT
{
POUT_ERROR
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
CKObjectDeclaration *FillBehaviorVideoCaptureDecl()
{
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(0x1470206b,0x5b087f1f));
od->SetCreationFunction(CreateVideoCaptureProto);
return od;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
CKERROR CreateVideoCaptureProto(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("Target", CKPGUID_TEXTURE);
//--- Output Parameters Declaration
proto->DeclareOutParameter("Error", CKPGUID_STRING);
//---- Settings Declaration
proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL);
proto->SetBehaviorFlags((CK_BEHAVIOR_FLAGS)(CKBEHAVIOR_TARGETABLE));
proto->SetFunction(VideoCapture);
*pproto = proto;
return CK_OK;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
int VideoCapture(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;
}
CKTexture* target = (CKTexture*) beh->GetInputParameterObject(PIN_TARGET_TEXTURE);
if ( !target ) {
XString err = "Invalid Texture";
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:
RETURN_IF_FAILED( video->CaptureImage(target) );
beh->SetOutputParameterValue(POUT_ERROR, "Success", 8);
beh->ActivateOutput(OUT_OUT);
break;
}
return CKBR_OK;
}