unified behavior stream and media player

This commit is contained in:
Bruno
2021-04-28 11:19:59 +02:00
parent 038fea3539
commit b0bc88e9c2
2 changed files with 51 additions and 41 deletions

View File

@@ -81,7 +81,6 @@ void Stream::open(const std::string &gstreamer_description, int w, int h)
if (isOpen()) if (isOpen())
close(); close();
execute_open();
} }
@@ -229,7 +228,6 @@ void Stream::close()
gst_object_unref (pipeline_); gst_object_unref (pipeline_);
pipeline_ = nullptr; pipeline_ = nullptr;
} }
desired_state_ = GST_STATE_PAUSED;
// cleanup eventual remaining frame memory // cleanup eventual remaining frame memory
for(guint i = 0; i < N_FRAME; ++i){ for(guint i = 0; i < N_FRAME; ++i){
@@ -312,7 +310,7 @@ bool Stream::live() const
void Stream::play(bool on) void Stream::play(bool on)
{ {
// ignore if disabled, and cannot play an image // ignore if disabled, and cannot play an image
if (!enabled_) if (!enabled_ || single_frame_)
return; return;
// request state // request state
@@ -353,6 +351,10 @@ void Stream::play(bool on)
bool Stream::isPlaying(bool testpipeline) const bool Stream::isPlaying(bool testpipeline) const
{ {
// image cannot play
if (single_frame_)
return false;
// if not ready yet, answer with requested state // if not ready yet, answer with requested state
if ( !testpipeline || pipeline_ == nullptr || !enabled_) if ( !testpipeline || pipeline_ == nullptr || !enabled_)
return desired_state_ == GST_STATE_PLAYING; return desired_state_ == GST_STATE_PLAYING;
@@ -378,6 +380,7 @@ void Stream::init_texture(guint index)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
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_) {
// set pbo image size // set pbo image size
pbo_size_ = height_ * width_ * 4; pbo_size_ = height_ * width_ * 4;
@@ -417,6 +420,8 @@ void Stream::init_texture(guint index)
#ifdef STREAM_DEBUG #ifdef STREAM_DEBUG
Log::Info("Stream %s Use Pixel Buffer Object texturing.", std::to_string(id_).c_str()); Log::Info("Stream %s Use Pixel Buffer Object texturing.", std::to_string(id_).c_str());
#endif #endif
}
glBindTexture(GL_TEXTURE_2D, 0);
} }
@@ -466,6 +471,7 @@ void Stream::fill_texture(guint index)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_,
GL_RGBA, GL_UNSIGNED_BYTE, frame_[index].vframe.data[0]); GL_RGBA, GL_UNSIGNED_BYTE, frame_[index].vframe.data[0]);
} }
glBindTexture(GL_TEXTURE_2D, 0);
} }
} }
@@ -476,12 +482,16 @@ void Stream::update()
return; return;
// not ready yet // not ready yet
if (!ready_) if (!ready_){
// open the stream
execute_open();
// wait next frame to display
return; return;
}
// // prevent unnecessary updates: disabled or already filled image // prevent unnecessary updates: already filled image
// if (!enabled_) if (single_frame_ && textureindex_>0)
// return; return;
// local variables before trying to update // local variables before trying to update
guint read_index = 0; guint read_index = 0;

View File

@@ -81,12 +81,12 @@ void StreamSource::init()
// set the renderbuffer of the source and attach rendering nodes // set the renderbuffer of the source and attach rendering nodes
attach(renderbuffer); attach(renderbuffer);
// deep update to reorder
++View::need_deep_update_;
// force update of activation mode // force update of activation mode
active_ = true; active_ = true;
// deep update to reorder
++View::need_deep_update_;
// done init // done init
initialized_ = true; initialized_ = true;
Log::Info("Source '%s' linked to Stream %s", name().c_str(), std::to_string(stream_->id()).c_str()); Log::Info("Source '%s' linked to Stream %s", name().c_str(), std::to_string(stream_->id()).c_str());