1#include "VideoCaptureSystem.h"
3#include "VideoCaptureRenderer.h"
4#include "IVideoEncoder.h"
7#include "Components/Core/CameraComponent.h"
8#include "Renderer/RenderResources.h"
9#include "Renderer/RenderTexture.h"
10#include "Systems/Core/CameraSystem.h"
11#include "Resources/Texture.h"
13#include "Rendering/IContext.h"
15#include "Foundation/Platform/Timer.h"
16#include "Foundation/Logging/Logger.h"
47 if (!context->videoEncoderContext)
return;
48 for (
auto & capComp : pool) {
49 auto & capData = getData(&capComp);
50 if (!capData.encoder || capComp.endOfStream)
continue;
51 if(capComp.updateTimestamp)
52 capComp.timestamp = Timer::currentTimeMicroseconds();
58 if (!context->videoEncoderContext)
return;
59 for (
auto & capComp : pool) {
67 int64_t now = Timer::currentTimeMilliseconds();
69 if (capComp.restart) {
70 capComp.endOfStream =
false;
73 if (((!capData.encoder && (capData.nextRestartTime < now)) || capComp.restart || capComp.reconfig) && !capComp.endOfStream) {
74 if(capData.encoder && capComp.restart) {
75 context->videoEncoderContext->destroyVideoEncoder(capData.encoder);
79 desc.codec = capComp.codec;
80 desc.encodeWidth = capComp.width;
81 desc.encodeHeight = capComp.height;
82 desc.darWidth = desc.encodeWidth;
83 desc.darHeight = desc.encodeHeight;
84 desc.maxWidth = capComp.maxWidth;
85 desc.maxHeight = capComp.maxHeight;
86 desc.bitrate = capComp.bitrate;
87 desc.maxBitrate = capComp.maxBitrate;
88 desc.bFrameCount = capComp.bFrameCount;
89 desc.bFrameReference = (uint32_t)capComp.bFrameReference;
90 desc.frameRate = 1000.0f / capComp.frameInterval;
91 desc.lookahead = capComp.lookahead;
92 desc.recordToDisk = capComp.recordToDisk;
93 desc.recordPath = capComp.recordPath;
94 desc.callback = capComp.callback;
95 desc.useMSAA = capComp.useMSAA;
97 if(!capData.encoder || capComp.restart) {
98 capData.encoder = context->videoEncoderContext->createVideoEncoder(desc);
100 if (!capData.encoder) {
103 capData.nextRestartTime = now + 3000;
106 capData.nextRestartTime = 0;
110 capData.encoder->reconfigure(desc,
false,
true);
112 capComp.width = desc.encodeWidth;
113 capComp.height = desc.encodeHeight;
114 capComp.maxWidth = desc.maxWidth;
115 capComp.maxHeight = desc.maxHeight;
116 capComp.bFrameCount = desc.bFrameCount;
117 capComp.restart =
false;
118 capComp.reconfig =
false;
122 if (!capData.encoder || capComp.endOfStream) {
125 camComp->
resolveTarget = capData.encoder->getNextInputBuffer();
134void Cogs::Core::VideoCaptureSystem::postRender(
Context * context)
136 if (!context->videoEncoderContext) {
139 for (
auto& capComp : pool) {
151 auto & capData = getData(&capComp);
152 if (!capData.encoder) {
155 if (capComp.endOfStream) {
156 if (capData.encoder) {
157 context->videoEncoderContext->destroyVideoEncoder(capData.encoder);
158 capData.encoder =
nullptr;
162 int64_t now = Timer::currentTimeMilliseconds();
164 if (capData.nextEncodeTime < now) {
165 capData.nextEncodeTime = now + capComp.frameInterval;
170 input.timestamp = capComp.timestamp;
171 input.duration = capComp.duration;
172 input.forceIntra = capComp.forceIntra;
173 input.forceIDR = capComp.forceIDR;
174 input.outputSPSPPS = capComp.outputSPSPPS;
176 capData.encoder->encode(input);
177 capComp.forceIntra =
false;
178 capComp.forceIDR =
false;
179 capComp.outputSPSPPS =
false;
186 if (context->videoEncoderContext){
200 context->videoEncoderContext->destroyVideoEncoder(capData.encoder);
201 capData.encoder =
nullptr;
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
ComponentType * getComponent() const
CameraFlags flags
Camera behavior flags.
glm::vec2 viewportSize
Size of the viewport covered by this instance, given in pixels.
TextureHandle resolveTarget
The texture to which the rendered output will be resolved. (Needs an offscreen renderTexture for this...
TextureHandle renderTexture
The render texture to output the rendered scene from the camera to.
virtual void cleanup(Context *)
Provided for custom cleanup logic in derived systems.
Context * context
Pointer to the Context instance the system lives in.
virtual void initialize(Context *context)
Initialize the system.
virtual void destroyComponent(ComponentHandle)
Destroy the component held by the given handle.
void update()
Updates the system state to that of the current frame.
void preUpdate()
Run the pre-update method of the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
class IRenderer * renderer
Renderer.
virtual void registerExtension(IRendererExtension *extension)=0
Register an extension with the renderer.
virtual void unregisterExtension(IRendererExtension *extension)=0
Unregister an extension with the renderer.
void destroyComponent(ComponentHandle component) override
void initialize(Context *context) override
Initialize the system.
void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ EnableRender
Renderable.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Handle to a Component instance.
ComponentType * resolveComponent() const