Bugfix: allow changing resolution of stream

This commit is contained in:
Bruno
2021-05-06 22:18:46 +02:00
parent e071ffe590
commit 250df8b651
2 changed files with 10 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ Stream::Stream()
// OpenGL texture // OpenGL texture
textureindex_ = 0; textureindex_ = 0;
textureinitialized_ = false;
} }
Stream::~Stream() Stream::~Stream()
@@ -80,6 +81,9 @@ guint Stream::texture() const
void Stream::open(const std::string &gstreamer_description, guint w, guint h) void Stream::open(const std::string &gstreamer_description, guint w, guint h)
{ {
if (w != width_ || h != height_ )
textureinitialized_ = false;
// set gstreamer pipeline source // set gstreamer pipeline source
description_ = gstreamer_description; description_ = gstreamer_description;
width_ = w; width_ = w;
@@ -372,6 +376,8 @@ bool Stream::isPlaying(bool testpipeline) const
void Stream::init_texture(guint index) void Stream::init_texture(guint index)
{ {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
if (textureindex_)
glDeleteTextures(1, &textureindex_);
glGenTextures(1, &textureindex_); glGenTextures(1, &textureindex_);
glBindTexture(GL_TEXTURE_2D, textureindex_); glBindTexture(GL_TEXTURE_2D, textureindex_);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width_, height_); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, width_, height_);
@@ -383,6 +389,7 @@ void Stream::init_texture(guint index)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (!single_frame_) { if (!single_frame_) {
// set pbo image size // set pbo image size
pbo_size_ = height_ * width_ * 4; pbo_size_ = height_ * width_ * 4;
@@ -425,13 +432,14 @@ void Stream::init_texture(guint index)
} }
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
textureinitialized_ = true;
} }
void Stream::fill_texture(guint index) void Stream::fill_texture(guint index)
{ {
// is this the first frame ? // is this the first frame ?
if (textureindex_ < 1) if ( !textureinitialized_ || textureindex_ < 1)
{ {
// initialize texture // initialize texture
init_texture(index); init_texture(index);

View File

@@ -185,6 +185,7 @@ protected:
virtual void execute_open(); virtual void execute_open();
// gst frame filling // gst frame filling
bool textureinitialized_;
void init_texture(guint index); void init_texture(guint index);
void fill_texture(guint index); void fill_texture(guint index);
bool fill_frame(GstBuffer *buf, FrameStatus status); bool fill_frame(GstBuffer *buf, FrameStatus status);