Change READY state of source

a source is ready after rendering one frame (which is after being initialized)
This commit is contained in:
Bruno
2021-05-01 00:34:58 +02:00
parent 058fde19ce
commit 381f68aaae
10 changed files with 42 additions and 21 deletions

View File

@@ -384,8 +384,12 @@ void DeviceSource::setDevice(const std::string &devicename)
pipeline << " ! videoconvert";
// open gstreamer
stream_->open( pipeline.str(), best.width, best.height);
stream_->play(true);
// will be ready after init and one frame rendered
ready_ = false;
}
else
Log::Warning("No such device '%s'", device_.c_str());

View File

@@ -25,11 +25,15 @@ MediaSource::~MediaSource()
void MediaSource::setPath(const std::string &p)
{
Log::Notify("Creating Source with media '%s'", p.c_str());
path_ = p;
Log::Notify("Creating Source with media '%s'", path_.c_str());
// open gstreamer
mediaplayer_->open(path_);
mediaplayer_->play(true);
// will be ready after init and one frame rendered
ready_ = false;
}
std::string MediaSource::path() const
@@ -126,15 +130,12 @@ void MediaSource::render()
if (!initialized_)
init();
else {
// blendingshader_->color.r = mediaplayer_->currentTimelineFading();
// blendingshader_->color.g = mediaplayer_->currentTimelineFading();
// blendingshader_->color.b = mediaplayer_->currentTimelineFading();
// render the media player into frame buffer
renderbuffer_->begin();
texturesurface_->shader()->color = glm::vec4( glm::vec3(mediaplayer_->currentTimelineFading()), 1.f);
texturesurface_->draw(glm::identity<glm::mat4>(), renderbuffer_->projection());
renderbuffer_->end();
ready_ = true;
}
}

View File

@@ -297,6 +297,9 @@ void NetworkSource::setConnection(const std::string &nameconnection)
// open network stream
networkStream()->connect( connection_name_ );
stream_->play(true);
// will be ready after init and one frame rendered
ready_ = false;
}

View File

@@ -145,8 +145,12 @@ void PatternSource::setPattern(uint type, glm::ivec2 resolution)
{
Log::Notify("Creating Source with pattern '%s'", Pattern::pattern_types[type].c_str());
// open gstreamer
pattern()->open( (uint) type, resolution );
stream_->play(true);
// will be ready after init and one frame rendered
ready_ = false;
}
void PatternSource::accept(Visitor& v)

View File

@@ -560,11 +560,14 @@ void SessionVisitor::visit (CloneSource& s)
void SessionVisitor::visit (PatternSource& s)
{
xmlCurrent_->SetAttribute("type", "PatternSource");
xmlCurrent_->SetAttribute("pattern", s.pattern()->type() );
XMLElement *resolution = xmlDoc_->NewElement("resolution");
resolution->InsertEndChild( XMLElementFromGLM(xmlDoc_, s.pattern()->resolution() ) );
xmlCurrent_->InsertEndChild(resolution);
if (s.pattern()) {
xmlCurrent_->SetAttribute("pattern", s.pattern()->type() );
XMLElement *resolution = xmlDoc_->NewElement("resolution");
resolution->InsertEndChild( XMLElementFromGLM(xmlDoc_, s.pattern()->resolution() ) );
xmlCurrent_->InsertEndChild(resolution);
}
}
void SessionVisitor::visit (DeviceSource& s)

View File

@@ -96,7 +96,8 @@ SourceCore& SourceCore::operator= (SourceCore const& other)
}
Source::Source(uint64_t id) : SourceCore(), id_(id), initialized_(false), symbol_(nullptr), active_(true), locked_(false), need_update_(true), workspace_(STAGE)
Source::Source(uint64_t id) : SourceCore(), id_(id), initialized_(false), ready_(false), symbol_(nullptr),
active_(true), locked_(false), need_update_(true), dt_(0), workspace_(STAGE)
{
// create unique id
if (id_ == 0)
@@ -420,6 +421,7 @@ void Source::render()
renderbuffer_->begin();
texturesurface_->draw(glm::identity<glm::mat4>(), renderbuffer_->projection());
renderbuffer_->end();
ready_ = true;
}
}
@@ -838,7 +840,7 @@ CloneSource *CloneSource::clone(uint64_t id)
void CloneSource::init()
{
if (origin_ && origin_->ready()) {
if (origin_ && origin_->initialized_) {
// get the texture index from framebuffer of view, apply it to the surface
texturesurface_->setTextureIndex( origin_->texture() );

View File

@@ -118,7 +118,7 @@ public:
inline void touch () { need_update_ = true; }
// informs if its ready (i.e. initialized)
inline bool ready () const { return initialized_; }
inline bool ready () const { return ready_; }
// a Source shall be updated before displayed (Mixing, Geometry and Layer)
virtual void update (float dt);
@@ -231,11 +231,11 @@ protected:
char initials_[3];
uint64_t id_;
// every Source shall be initialized on first draw
// every Source shall be initialized before first draw and ready after
bool initialized_;
bool ready_;
virtual void init() = 0;
// render() fills in the renderbuffer at every frame
// NB: rendershader_ is applied at render()
FrameBuffer *renderbuffer_;

View File

@@ -26,8 +26,12 @@ void GenericStreamSource::setDescription(const std::string &desc)
{
Log::Notify("Creating Source with Stream description '%s'", desc.c_str());
// open gstreamer
stream_->open(desc);
stream_->play(true);
// will be ready after init and one frame rendered
ready_ = false;
}
void GenericStreamSource::accept(Visitor& v)

View File

@@ -3557,7 +3557,7 @@ void Navigator::RenderMainPannel()
/// SOURCE PREVIEW
///
SourcePreview::SourcePreview() : source_(nullptr), label_(""), pre_frames_(0)
SourcePreview::SourcePreview() : source_(nullptr), label_(""), reset_(0)
{
}
@@ -3569,7 +3569,7 @@ void SourcePreview::setSource(Source *s, const string &label)
source_ = s;
label_ = label;
pre_frames_ = 2;
reset_ = true;
}
Source * SourcePreview::getSource()
@@ -3594,13 +3594,13 @@ void SourcePreview::Render(float width, bool controlbutton)
else
{
// render framebuffer
if ( pre_frames_ > 0 && source_->ready() ) {
if ( reset_ && source_->ready() ) {
// trick to ensure a minimum of 2 frames are rendered actively
source_->setActive(true);
source_->update( Mixer::manager().dt() );
source_->render();
source_->setActive(false);
--pre_frames_;
reset_ = false;
}
else {
// update source

View File

@@ -19,7 +19,7 @@ class SourcePreview {
Source *source_;
std::string label_;
int pre_frames_;
bool reset_;
public:
SourcePreview();