67 lines
1.9 KiB
C++
Executable File
67 lines
1.9 KiB
C++
Executable File
#include "videocomponent.h"
|
|
|
|
#include <dtEntity/commandmessages.h>
|
|
#include <dtEntity/systemmessages.h>
|
|
#include <dtEntity/entity.h>
|
|
#include <dtEntity/stringid.h>
|
|
#include <dtEntityOSG/cameracomponent.h>
|
|
#include "windowcapturecallback.h"
|
|
|
|
namespace VCtrl
|
|
{
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
const dtEntity::StringId VideoSystem::TYPE(dtEntity::SID("Video"));
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
bool VideoSystem::StartVideoRecording(unsigned int contextid, const std::string &path, int w, int h, int framerate, int quality)
|
|
{
|
|
if (mWindowCaptureCallback.valid())
|
|
{
|
|
LOG_ERROR("Cannot start video recording, already started!");
|
|
return false;
|
|
}
|
|
StopVideoRecording(contextid);
|
|
|
|
dtEntityOSG::CameraSystem *cs;
|
|
GetEntityManager().GetES(cs);
|
|
|
|
dtEntity::EntityId camid = cs ? cs->GetCameraEntityByContextId(contextid) : 0;
|
|
|
|
dtEntityOSG::CameraComponent *camcomp;
|
|
if (camid == 0 || !GetEntityManager().GetComponent(camid, camcomp))
|
|
{
|
|
LOG_ERROR("Cannot set up video stream, camera not found");
|
|
return false;
|
|
}
|
|
|
|
mWindowCaptureCallback = new WindowCaptureCallback(GL_BACK, contextid, path, w, h, framerate, quality);
|
|
|
|
camcomp->GetCamera()->setFinalDrawCallback(mWindowCaptureCallback);
|
|
|
|
return true;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
bool VideoSystem::StopVideoRecording(unsigned int contextid)
|
|
{
|
|
if (mWindowCaptureCallback.valid())
|
|
{
|
|
dtEntityOSG::CameraSystem *camsys;
|
|
if (GetEntityManager().GetES(camsys))
|
|
{
|
|
dtEntity::EntityId camid = camsys->GetCameraEntityByContextId(contextid);
|
|
if (camid != 0)
|
|
{
|
|
dtEntityOSG::CameraComponent *cam;
|
|
if (GetEntityManager().GetComponent(camid, cam))
|
|
cam->GetCamera()->setFinalDrawCallback(nullptr);
|
|
}
|
|
}
|
|
mWindowCaptureCallback = nullptr;
|
|
}
|
|
return true;
|
|
}
|
|
}
|