174 lines
4.9 KiB
C++
174 lines
4.9 KiB
C++
/*************************************************************************/
|
|
/* File : InputFormats.cpp */
|
|
/* */
|
|
/* Author : Leïla AIT KACI */
|
|
/* Last Modification : 28/05/03 */
|
|
/*************************************************************************/
|
|
#include "CKAll.h"
|
|
#include "CKVideo.h"
|
|
#include "CKVideoManager.h"
|
|
|
|
CKObjectDeclaration* FillBehaviorInputFormatsDecl ();
|
|
CKERROR CreateInputFormatsProto (CKBehaviorPrototype **);
|
|
int InputFormats (const CKBehaviorContext& BehContext);
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Defines
|
|
//////////////////////////////////////////////////////////////////////
|
|
#define BB_NAME "Get Video Input Formats"
|
|
#define BB_DESC "Get the available input formats descriptions for the given capture ID"
|
|
#define BB_CAT "Video/Controls"
|
|
#define BB_VERSION 0x00010000
|
|
#define BB_TARGET CKCID_BEOBJECT
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Enums for Parameter's Indexes
|
|
//////////////////////////////////////////////////////////////////////
|
|
enum BB_IN
|
|
{
|
|
IN_IN,
|
|
IN_LOOPIN
|
|
};
|
|
|
|
enum BB_OUT
|
|
{
|
|
OUT_OUT,
|
|
OUT_LOOPOUT
|
|
};
|
|
|
|
enum BB_LOC
|
|
{
|
|
};
|
|
|
|
enum BB_PIN
|
|
{
|
|
PIN_CAPTUREID
|
|
};
|
|
|
|
enum BB_POUT
|
|
{
|
|
POUT_COUNT,
|
|
POUT_ID,
|
|
POUT_NAME,
|
|
POUT_SIZE,
|
|
POUT_FREQUENCY
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKObjectDeclaration *FillBehaviorInputFormatsDecl()
|
|
{
|
|
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(0x416b4dc8,0x496d0e81));
|
|
od->SetCreationFunction(CreateInputFormatsProto);
|
|
|
|
return od;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
CKERROR CreateInputFormatsProto(CKBehaviorPrototype** pproto)
|
|
{
|
|
CKBehaviorPrototype *proto = CreateCKBehaviorPrototype(BB_NAME);
|
|
if(!proto) return CKERR_OUTOFMEMORY;
|
|
|
|
//--- Inputs declaration
|
|
proto->DeclareInput("In");
|
|
proto->DeclareInput("Loop In");
|
|
|
|
//--- Outputs declaration
|
|
proto->DeclareOutput("Out");
|
|
proto->DeclareOutput("Loop Out");
|
|
|
|
//----- Input Parameters Declaration
|
|
proto->DeclareInParameter("Capture ID", CKPGUID_VIDEOCAPTURE, "0");
|
|
|
|
//--- Output Parameters Declaration
|
|
proto->DeclareOutParameter("Count", CKPGUID_INT );
|
|
proto->DeclareOutParameter("ID", CKPGUID_INT );
|
|
proto->DeclareOutParameter("Name", CKPGUID_STRING );
|
|
proto->DeclareOutParameter("Size", CKPGUID_2DVECTOR );
|
|
proto->DeclareOutParameter("Frequency", CKPGUID_2DVECTOR );
|
|
|
|
//---- Settings Declaration
|
|
proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL);
|
|
proto->SetBehaviorFlags(CKBEHAVIOR_NONE);
|
|
proto->SetFunction(InputFormats);
|
|
|
|
*pproto = proto;
|
|
return CK_OK;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
int InputFormats(const CKBehaviorContext& BehContext)
|
|
{
|
|
CKContext* ctx = BehContext.Context;
|
|
CKBehavior* beh = BehContext.Behavior;
|
|
|
|
int Count = -1;
|
|
int CurrentID = -1;
|
|
|
|
// Then, we get the manager and return if failed
|
|
CKVideoManager* vm = (CKVideoManager*) ctx->GetManagerByGuid(CKVideoManager::GetGUID());
|
|
if ( !vm )
|
|
return CKBR_GENERICERROR;
|
|
|
|
// Get the capture ID
|
|
int CaptureID = 0;
|
|
beh->GetInputParameterValue(PIN_CAPTUREID, &CaptureID);
|
|
|
|
// Start Iteration
|
|
if ( beh->IsInputActive(IN_IN) )
|
|
{
|
|
beh->ActivateInput(IN_IN, FALSE);
|
|
|
|
// Get the available format count
|
|
Count = vm->GetVideoInputFormatCount(CaptureID);
|
|
beh->SetOutputParameterValue(POUT_COUNT, &Count);
|
|
|
|
// And reset the current index (ID) to start iteration
|
|
beh->SetOutputParameterValue(POUT_ID, &CurrentID);
|
|
|
|
// Don't return to start the iteration
|
|
}
|
|
else
|
|
beh->ActivateInput(IN_LOOPIN, FALSE);
|
|
|
|
// Get current count, if <0, no iteration is possible.
|
|
beh->GetOutputParameterValue(POUT_COUNT, &Count);
|
|
if ( Count < 0 ) {
|
|
beh->ActivateOutput(OUT_OUT);
|
|
return CKBR_OK;
|
|
}
|
|
|
|
// Get next description ID
|
|
beh->GetOutputParameterValue(POUT_ID, &CurrentID);
|
|
CurrentID++;
|
|
if ( CurrentID >= Count ) {
|
|
beh->ActivateOutput(OUT_OUT);
|
|
return CKBR_OK;
|
|
}
|
|
|
|
// Get the format description and update outputs
|
|
const CKVideoInputFormatDesc* desc = vm->GetVideoInputFormatDesc(CaptureID, CurrentID);
|
|
XString name = desc->m_Format;
|
|
beh->SetOutputParameterValue(POUT_NAME, name.Str(), name.Length()+1 );
|
|
beh->SetOutputParameterValue(POUT_ID, &CurrentID );
|
|
beh->SetOutputParameterValue(POUT_SIZE, &desc->m_Size );
|
|
beh->SetOutputParameterValue(POUT_FREQUENCY, &desc->m_Frequency );
|
|
|
|
// And return
|
|
beh->ActivateOutput(OUT_LOOPOUT);
|
|
return CKBR_OK;
|
|
}
|