Files
oak-editor/app/render/backend/opengl/openglexporter.cpp
T
itsmattkc 3a7b3ffac6 implemented audio exporting
The encoder was moved to its own thread and will transcode the PCM from the
audio renderer into the chosen codec while the video frames are still
received. The implementation isn't perfect and could use some cleaning up, but
it is functional at the moment.
2019-12-23 01:45:27 +11:00

84 lines
2.2 KiB
C++

#include "openglexporter.h"
#include "render/backend/opengl/functions.h"
#include "render/pixelservice.h"
OpenGLExporter::OpenGLExporter(ViewerOutput* viewer, const VideoRenderingParams& video_params, const AudioRenderingParams &audio_params, const QMatrix4x4 &transform, ColorProcessorPtr color_processor, Encoder *encoder, QObject* parent) :
Exporter(viewer, video_params, audio_params, transform, color_processor, encoder, parent)
{
}
OpenGLExporter::~OpenGLExporter()
{
}
bool OpenGLExporter::Initialize()
{
QOpenGLContext* ctx = QOpenGLContext::currentContext();
// Create rendering backends
video_backend_ = new OpenGLBackend();
audio_backend_ = new AudioBackend();
// Create blitting framebuffer and texture
buffer_.Create(ctx);
texture_ = std::make_shared<OpenGLTexture>();
texture_->Create(ctx, video_params_.effective_width(), video_params_.effective_height(), video_params_.format());
pipeline_ = OpenGLShader::CreateDefault();
return true;
}
void OpenGLExporter::Cleanup()
{
texture_->Destroy();
buffer_.Destroy();
}
FramePtr OpenGLExporter::TextureToFrame(const QVariant& texture)
{
FramePtr frame = Frame::Create();
frame->set_width(video_params_.width());
frame->set_height(video_params_.height());
frame->set_format(video_params_.format());
frame->allocate();
// Blit for transform if the width/height are different
OpenGLTexturePtr input_tex = texture.value<OpenGLTexturePtr>();
if (input_tex) {
QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
f->glViewport(0, 0, texture_->width(), texture_->height());
buffer_.Attach(texture_);
buffer_.Bind();
input_tex->Bind();
olive::gl::Blit(pipeline_, false, transform_);
input_tex->Release();
buffer_.Release();
buffer_.Detach();
// Perform OpenGL read
buffer_.Attach(texture_);
buffer_.Bind();
PixelFormatInfo format_info = PixelService::GetPixelFormatInfo(video_params_.format());
f->glReadPixels(0,
0,
texture_->width(),
texture_->height(),
format_info.pixel_format,
format_info.gl_pixel_type,
frame->data());
buffer_.Release();
buffer_.Detach();
}
return frame;
}