re-open should not change gl texture

rename 'ready' to 'opened' to avoid confusion
This commit is contained in:
Bruno
2021-05-01 15:35:36 +02:00
parent a05cd380fb
commit 5e0dd60adb
5 changed files with 37 additions and 39 deletions

View File

@@ -31,7 +31,7 @@ MediaPlayer::MediaPlayer()
uri_ = "undefined";
pipeline_ = nullptr;
ready_ = false;
opened_ = false;
enabled_ = true;
desired_state_ = GST_STATE_PAUSED;
@@ -65,6 +65,9 @@ MediaPlayer::~MediaPlayer()
if (textureindex_)
glDeleteTextures(1, &textureindex_);
// cleanup picture buffer
if (pbo_[0])
glDeleteBuffers(2, pbo_);
}
void MediaPlayer::accept(Visitor& v) {
@@ -401,7 +404,7 @@ void MediaPlayer::execute_open()
Log::Info("MediaPlayer %s Timeline [%ld %ld] %ld frames, %d gaps", std::to_string(id_).c_str(),
timeline_.begin(), timeline_.end(), timeline_.numFrames(), timeline_.numGaps());
ready_ = true;
opened_ = true;
// register media player
MediaPlayer::registered_.push_back(this);
@@ -409,7 +412,7 @@ void MediaPlayer::execute_open()
bool MediaPlayer::isOpen() const
{
return ready_;
return opened_;
}
bool MediaPlayer::failed() const
@@ -427,7 +430,7 @@ void MediaPlayer::Frame::unmap()
void MediaPlayer::close()
{
// not openned?
if (!ready_) {
if (!opened_) {
// wait for loading to finish
if (discoverer_.valid())
discoverer_.wait();
@@ -436,7 +439,7 @@ void MediaPlayer::close()
}
// un-ready the media player
ready_ = false;
opened_ = false;
// clean up GST
if (pipeline_ != nullptr) {
@@ -464,12 +467,6 @@ void MediaPlayer::close()
write_index_ = 0;
last_index_ = 0;
// cleanup picture buffer
if (pbo_[0])
glDeleteBuffers(2, pbo_);
pbo_size_ = 0;
pbo_index_ = 0;
pbo_next_index_ = 0;
#ifdef MEDIA_PLAYER_DEBUG
Log::Info("MediaPlayer %s closed", std::to_string(id_).c_str());
@@ -508,7 +505,7 @@ GstClockTime MediaPlayer::position()
void MediaPlayer::enable(bool on)
{
if ( !ready_ || pipeline_ == nullptr)
if ( !opened_ || pipeline_ == nullptr)
return;
if ( enabled_ != on ) {
@@ -832,7 +829,7 @@ void MediaPlayer::update()
return;
// not ready yet
if (!ready_) {
if (!opened_) {
if (discoverer_.valid()) {
// try to get info from discoverer
if (discoverer_.wait_for( std::chrono::milliseconds(4) ) == std::future_status::ready )
@@ -1156,7 +1153,7 @@ bool MediaPlayer::fill_frame(GstBuffer *buf, FrameStatus status)
void MediaPlayer::callback_end_of_stream (GstAppSink *, gpointer p)
{
MediaPlayer *m = static_cast<MediaPlayer *>(p);
if (m && m->ready_) {
if (m && m->opened_) {
m->fill_frame(NULL, MediaPlayer::EOS);
}
}
@@ -1173,7 +1170,7 @@ GstFlowReturn MediaPlayer::callback_new_preroll (GstAppSink *sink, gpointer p)
// send frames to media player only if ready
MediaPlayer *m = static_cast<MediaPlayer *>(p);
if (m && m->ready_) {
if (m && m->opened_) {
// get buffer from sample
GstBuffer *buf = gst_sample_get_buffer (sample);
@@ -1208,7 +1205,7 @@ GstFlowReturn MediaPlayer::callback_new_sample (GstAppSink *sink, gpointer p)
// send frames to media player only if ready
MediaPlayer *m = static_cast<MediaPlayer *>(p);
if (m && m->ready_) {
if (m && m->opened_) {
// get buffer from sample (valid until sample is released)
GstBuffer *buf = gst_sample_get_buffer (sample) ;

View File

@@ -285,7 +285,7 @@ private:
GstState desired_state_;
GstElement *pipeline_;
GstVideoInfo v_frame_video_info_;
std::atomic<bool> ready_;
std::atomic<bool> opened_;
std::atomic<bool> failed_;
bool seeking_;
bool enabled_;

View File

@@ -204,7 +204,7 @@ void NetworkStream::update()
{
Stream::update();
if ( !ready_ && !failed_ && received_config_)
if ( !opened_ && !failed_ && received_config_)
{
// only once
received_config_ = false;

View File

@@ -28,7 +28,7 @@ Stream::Stream()
description_ = "undefined";
pipeline_ = nullptr;
ready_ = false;
opened_ = false;
enabled_ = true;
desired_state_ = GST_STATE_PAUSED;
@@ -55,6 +55,14 @@ Stream::Stream()
Stream::~Stream()
{
close();
// cleanup opengl texture
if (textureindex_)
glDeleteTextures(1, &textureindex_);
// cleanup picture buffer
if (pbo_[0])
glDeleteBuffers(2, pbo_);
}
void Stream::accept(Visitor& v) {
@@ -94,7 +102,7 @@ std::string Stream::description() const
void Stream::execute_open()
{
// reset
ready_ = false;
opened_ = false;
// Add custom app sink to the gstreamer pipeline
string description = description_;
@@ -183,12 +191,12 @@ void Stream::execute_open()
// all good
Log::Info("Stream %s Opened '%s' (%d x %d)", std::to_string(id_).c_str(), description.c_str(), width_, height_);
ready_ = true;
opened_ = true;
}
bool Stream::isOpen() const
{
return ready_;
return opened_;
}
bool Stream::failed() const
@@ -206,13 +214,15 @@ void Stream::Frame::unmap()
void Stream::close()
{
// not openned?
if (!ready_) {
if (!opened_) {
// nothing else to change
return;
}
// un-ready
ready_ = false;
opened_ = false;
single_frame_ = false;
live_ = false;
// clean up GST
if (pipeline_ != nullptr) {
@@ -239,15 +249,6 @@ void Stream::close()
write_index_ = 0;
last_index_ = 0;
// cleanup opengl texture
if (textureindex_)
glDeleteTextures(1, &textureindex_);
textureindex_ = 0;
// cleanup picture buffer
if (pbo_[0])
glDeleteBuffers(2, pbo_);
pbo_size_ = 0;
}
@@ -268,7 +269,7 @@ float Stream::aspectRatio() const
void Stream::enable(bool on)
{
if ( !ready_ || pipeline_ == nullptr)
if ( !opened_ || pipeline_ == nullptr)
return;
if ( enabled_ != on ) {
@@ -483,7 +484,7 @@ void Stream::update()
return;
// not ready yet
if (!ready_){
if (!opened_){
// wait next frame to display
return;
}
@@ -636,7 +637,7 @@ bool Stream::fill_frame(GstBuffer *buf, FrameStatus status)
void Stream::callback_end_of_stream (GstAppSink *, gpointer p)
{
Stream *m = static_cast<Stream *>(p);
if (m && m->ready_) {
if (m && m->opened_) {
m->fill_frame(NULL, Stream::EOS);
}
}
@@ -652,7 +653,7 @@ GstFlowReturn Stream::callback_new_preroll (GstAppSink *sink, gpointer p)
if (sample != NULL) {
// send frames to media player only if ready
Stream *m = static_cast<Stream *>(p);
if (m && m->ready_) {
if (m && m->opened_) {
// get buffer from sample
GstBuffer *buf = gst_sample_get_buffer (sample);
@@ -686,7 +687,7 @@ GstFlowReturn Stream::callback_new_sample (GstAppSink *sink, gpointer p)
// send frames to media player only if ready
Stream *m = static_cast<Stream *>(p);
if (m && m->ready_) {
if (m && m->opened_) {
// get buffer from sample (valid until sample is released)
GstBuffer *buf = gst_sample_get_buffer (sample) ;

View File

@@ -129,7 +129,7 @@ protected:
GstState desired_state_;
GstElement *pipeline_;
GstVideoInfo v_frame_video_info_;
std::atomic<bool> ready_;
std::atomic<bool> opened_;
std::atomic<bool> failed_;
bool enabled_;