mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 10:49:59 +01:00
Clone Source loading fixed and simplified
Fixed loading order. Removed the option of origin selection for Clone: not meaningful anymore with chain of clones.
This commit is contained in:
@@ -31,11 +31,9 @@
|
|||||||
|
|
||||||
#include "CloneSource.h"
|
#include "CloneSource.h"
|
||||||
|
|
||||||
const char* CloneSource::cloning_provenance_label[2] = { "Original texture", "Post-processed image" };
|
|
||||||
|
|
||||||
|
|
||||||
CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin), cloningsurface_(nullptr),
|
CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin), cloningsurface_(nullptr),
|
||||||
garbage_image_(nullptr), delay_(0.0), paused_(false), provenance_(CLONE_TEXTURE)
|
garbage_image_(nullptr), delay_(0.0), paused_(false)
|
||||||
{
|
{
|
||||||
// initial name copies the origin name: diplucates are namanged in session
|
// initial name copies the origin name: diplucates are namanged in session
|
||||||
name_ = origin->name();
|
name_ = origin->name();
|
||||||
@@ -72,22 +70,9 @@ CloneSource::~CloneSource()
|
|||||||
g_free(timer_);
|
g_free(timer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CloneSource *CloneSource::clone(uint64_t id)
|
|
||||||
{
|
|
||||||
// do not clone a clone : clone the original instead
|
|
||||||
if (origin_)
|
|
||||||
return origin_->clone(id);
|
|
||||||
else
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CloneSource::init()
|
void CloneSource::init()
|
||||||
{
|
{
|
||||||
if (origin_ && origin_->mode_ > Source::UNINITIALIZED) {
|
if (origin_ && origin_->mode_ > Source::UNINITIALIZED && origin_->renderbuffer_) {
|
||||||
|
|
||||||
// internal surface to draw the original texture
|
|
||||||
cloningsurface_ = new Surface;
|
|
||||||
cloningsurface_->setTextureIndex( origin()->texture() );
|
|
||||||
|
|
||||||
// frame buffers where to draw frames from the origin source
|
// frame buffers where to draw frames from the origin source
|
||||||
glm::vec3 res = origin_->frame()->resolution();
|
glm::vec3 res = origin_->frame()->resolution();
|
||||||
@@ -102,7 +87,7 @@ void CloneSource::init()
|
|||||||
texturesurface_->setTextureIndex( images_.front()->texture() );
|
texturesurface_->setTextureIndex( images_.front()->texture() );
|
||||||
|
|
||||||
// create render Frame buffer matching size of images
|
// create render Frame buffer matching size of images
|
||||||
FrameBuffer *renderbuffer = new FrameBuffer( res, true);
|
FrameBuffer *renderbuffer = new FrameBuffer( res, true );
|
||||||
|
|
||||||
// set the renderbuffer of the source and attach rendering nodes
|
// set the renderbuffer of the source and attach rendering nodes
|
||||||
attach(renderbuffer);
|
attach(renderbuffer);
|
||||||
@@ -149,7 +134,7 @@ void CloneSource::update(float dt)
|
|||||||
|
|
||||||
if (origin_) {
|
if (origin_) {
|
||||||
|
|
||||||
if (!paused_ && cloningsurface_ != nullptr) {
|
if (!paused_) {
|
||||||
|
|
||||||
// if temporary FBO was pending to be deleted, delete it now
|
// if temporary FBO was pending to be deleted, delete it now
|
||||||
if (garbage_image_ != nullptr) {
|
if (garbage_image_ != nullptr) {
|
||||||
@@ -192,15 +177,8 @@ void CloneSource::update(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CLONE_RENDER : blit rendered framebuffer in the newest image (back)
|
// blit rendered framebuffer in the newest image (back)
|
||||||
if (provenance_ == CLONE_RENDER)
|
origin_->frame()->blit(images_.back());
|
||||||
origin_->frame()->blit(images_.back());
|
|
||||||
// CLONE_TEXTURE : render origin texture in the the newest image (back)
|
|
||||||
else {
|
|
||||||
images_.back()->begin();
|
|
||||||
cloningsurface_->draw(glm::identity<glm::mat4>(), images_.back()->projection());
|
|
||||||
images_.back()->end();
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the source surface to be rendered with the oldest image (front)
|
// update the source surface to be rendered with the oldest image (front)
|
||||||
texturesurface_->setTextureIndex( images_.front()->texture() );
|
texturesurface_->setTextureIndex( images_.front()->texture() );
|
||||||
@@ -242,7 +220,6 @@ void CloneSource::replay()
|
|||||||
{
|
{
|
||||||
// clear to_delete_ FBO if pending
|
// clear to_delete_ FBO if pending
|
||||||
if (garbage_image_ != nullptr) {
|
if (garbage_image_ != nullptr) {
|
||||||
g_printerr(" REPLAY delete garbage %d \n", garbage_image_->opengl_id());
|
|
||||||
delete garbage_image_;
|
delete garbage_image_;
|
||||||
garbage_image_ = nullptr;
|
garbage_image_ = nullptr;
|
||||||
}
|
}
|
||||||
@@ -279,10 +256,10 @@ guint64 CloneSource::playtime () const
|
|||||||
|
|
||||||
uint CloneSource::texture() const
|
uint CloneSource::texture() const
|
||||||
{
|
{
|
||||||
if (cloningsurface_ != nullptr && !images_.empty())
|
if (!images_.empty())
|
||||||
return images_.front()->texture();
|
return images_.front()->texture();
|
||||||
else
|
else
|
||||||
return Resource::getTextureTransparent();
|
return Resource::getTextureBlack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloneSource::accept(Visitor& v)
|
void CloneSource::accept(Visitor& v)
|
||||||
|
|||||||
@@ -25,20 +25,10 @@ public:
|
|||||||
void accept (Visitor& v) override;
|
void accept (Visitor& v) override;
|
||||||
|
|
||||||
// implementation of cloning mechanism
|
// implementation of cloning mechanism
|
||||||
CloneSource *clone(uint64_t id = 0) override;
|
|
||||||
inline void detach() { origin_ = nullptr; }
|
inline void detach() { origin_ = nullptr; }
|
||||||
inline Source *origin() const { return origin_; }
|
inline Source *origin() const { return origin_; }
|
||||||
|
|
||||||
// Clone properties
|
// Clone properties
|
||||||
typedef enum {
|
|
||||||
CLONE_TEXTURE = 0,
|
|
||||||
CLONE_RENDER
|
|
||||||
} CloneSourceProvenance;
|
|
||||||
static const char* cloning_provenance_label[2];
|
|
||||||
|
|
||||||
void setCloningProvenance(CloneSourceProvenance m) { provenance_ = m; }
|
|
||||||
CloneSourceProvenance cloningProvenance() const { return provenance_; }
|
|
||||||
|
|
||||||
void setDelay(double second);
|
void setDelay(double second);
|
||||||
double delay() const { return delay_; }
|
double delay() const { return delay_; }
|
||||||
|
|
||||||
@@ -65,7 +55,6 @@ protected:
|
|||||||
|
|
||||||
// control
|
// control
|
||||||
bool paused_;
|
bool paused_;
|
||||||
CloneSourceProvenance provenance_;
|
|
||||||
|
|
||||||
// connecting line
|
// connecting line
|
||||||
class DotLine *connection_;
|
class DotLine *connection_;
|
||||||
|
|||||||
@@ -270,8 +270,12 @@ void FrameBuffer::release()
|
|||||||
|
|
||||||
void FrameBuffer::readPixels(uint8_t *target_data)
|
void FrameBuffer::readPixels(uint8_t *target_data)
|
||||||
{
|
{
|
||||||
if (!framebufferid_)
|
if (!framebufferid_) {
|
||||||
|
#ifdef FRAMEBUFFER_DEBUG
|
||||||
|
g_printerr("FrameBuffer readPixels failed\n");
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (use_multi_sampling_)
|
if (use_multi_sampling_)
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, intermediate_framebufferid_);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, intermediate_framebufferid_);
|
||||||
@@ -289,8 +293,12 @@ void FrameBuffer::readPixels(uint8_t *target_data)
|
|||||||
|
|
||||||
bool FrameBuffer::blit(FrameBuffer *destination)
|
bool FrameBuffer::blit(FrameBuffer *destination)
|
||||||
{
|
{
|
||||||
if (!framebufferid_ || !destination || (use_alpha_ != destination->use_alpha_) )
|
if (!framebufferid_ || !destination || (use_alpha_ != destination->use_alpha_) ){
|
||||||
|
#ifdef FRAMEBUFFER_DEBUG
|
||||||
|
g_printerr("FrameBuffer blit failed\n");
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!destination->framebufferid_)
|
if (!destination->framebufferid_)
|
||||||
destination->init();
|
destination->init();
|
||||||
|
|||||||
@@ -763,20 +763,26 @@ void ImGuiVisitor::visit (CloneSource& s)
|
|||||||
UserInterface::manager().showSourceEditor(&s);
|
UserInterface::manager().showSourceEditor(&s);
|
||||||
ImGui::SetCursorPos(pos);
|
ImGui::SetCursorPos(pos);
|
||||||
|
|
||||||
if ( ImGui::Button(s.origin()->name().c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0)) )
|
std::string label = std::string(s.origin()->initials()) + " - " + s.origin()->name();
|
||||||
|
if ( ImGui::Button(label.c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0)) )
|
||||||
Mixer::manager().setCurrentSource(s.origin());
|
Mixer::manager().setCurrentSource(s.origin());
|
||||||
ImGui::SameLine(0, IMGUI_SAME_LINE);
|
ImGui::SameLine(0, IMGUI_SAME_LINE);
|
||||||
ImGui::Text("Origin");
|
ImGui::Text("Origin");
|
||||||
|
|
||||||
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
if (ImGuiToolkit::IconButton(10, 15)) {
|
||||||
int m = (int) s.cloningProvenance();
|
s.setDelay(0.f);
|
||||||
if (ImGui::Combo("Render", &m, CloneSource::cloning_provenance_label, IM_ARRAYSIZE(CloneSource::cloning_provenance_label)) )
|
Action::manager().store("Delay None");
|
||||||
s.setCloningProvenance((CloneSource::CloneSourceProvenance)m);
|
}
|
||||||
|
ImGui::SameLine(0, IMGUI_SAME_LINE);
|
||||||
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
||||||
float d = s.delay();
|
float d = s.delay();
|
||||||
if (ImGui::SliderFloat("Delay", &d, 0.f, 2.f, d < 0.01f ? "None" : "%.2f s"))
|
if (ImGui::SliderFloat("Delay", &d, 0.f, 2.f, d < 0.01f ? "None" : "%.2f s"))
|
||||||
s.setDelay(d);
|
s.setDelay(d);
|
||||||
|
if (ImGui::IsItemDeactivatedAfterEdit()) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Delay " << std::setprecision(3) << d << " s";
|
||||||
|
Action::manager().store(oss.str());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -235,8 +235,7 @@ void InfoVisitor::visit (CloneSource& s)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (s.origin())
|
if (s.origin())
|
||||||
oss << "Clone of '" << s.origin()->name() << "' ";
|
oss << "Clone of '" << s.origin()->name() << "' " << std::endl;
|
||||||
oss << CloneSource::cloning_provenance_label[s.cloningProvenance()] << std::endl;
|
|
||||||
oss << (s.frame()->use_alpha() ? "RGBA, " : "RGB, ");
|
oss << (s.frame()->use_alpha() ? "RGBA, " : "RGB, ");
|
||||||
oss << (int)(s.delay()*1000.0) << " ms delay " << std::endl;
|
oss << (int)(s.delay()*1000.0) << " ms delay " << std::endl;
|
||||||
oss << s.frame()->width() << " x " << s.frame()->height();
|
oss << s.frame()->width() << " x " << s.frame()->height();
|
||||||
|
|||||||
@@ -375,6 +375,10 @@ void SessionLoader::load(XMLElement *sessionNode)
|
|||||||
sessionNode->QueryFloatAttribute("activationThreshold", &t);
|
sessionNode->QueryFloatAttribute("activationThreshold", &t);
|
||||||
session_->setActivationThreshold(t);
|
session_->setActivationThreshold(t);
|
||||||
|
|
||||||
|
|
||||||
|
std::list<XMLElement*> cloneNodesToAdd;
|
||||||
|
std::list<uint64_t> possible_xml_ids;
|
||||||
|
|
||||||
//
|
//
|
||||||
// source lists
|
// source lists
|
||||||
//
|
//
|
||||||
@@ -389,6 +393,7 @@ void SessionLoader::load(XMLElement *sessionNode)
|
|||||||
// check if a source with the given id exists in the session
|
// check if a source with the given id exists in the session
|
||||||
uint64_t id_xml_ = 0;
|
uint64_t id_xml_ = 0;
|
||||||
xmlCurrent_->QueryUnsigned64Attribute("id", &id_xml_);
|
xmlCurrent_->QueryUnsigned64Attribute("id", &id_xml_);
|
||||||
|
possible_xml_ids.push_front(id_xml_);
|
||||||
SourceList::iterator sit = session_->find(id_xml_);
|
SourceList::iterator sit = session_->find(id_xml_);
|
||||||
|
|
||||||
// no source with this id exists
|
// no source with this id exists
|
||||||
@@ -427,7 +432,10 @@ void SessionLoader::load(XMLElement *sessionNode)
|
|||||||
else if ( std::string(pType) == "SrtReceiverSource") {
|
else if ( std::string(pType) == "SrtReceiverSource") {
|
||||||
load_source = new SrtReceiverSource(id_xml_);
|
load_source = new SrtReceiverSource(id_xml_);
|
||||||
}
|
}
|
||||||
else if ( std::string(pType) != "CloneSource") {
|
else if ( std::string(pType) == "CloneSource") {
|
||||||
|
cloneNodesToAdd.push_front(xmlCurrent_);
|
||||||
|
}
|
||||||
|
else {
|
||||||
Log::Info("Unknown source type '%s' ignored.", pType);
|
Log::Info("Unknown source type '%s' ignored.", pType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,54 +458,60 @@ void SessionLoader::load(XMLElement *sessionNode)
|
|||||||
sources_id_[id_xml_] = load_source;
|
sources_id_[id_xml_] = load_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create clones after all sources, to be able to clone a source created above
|
// take all node elements for Clones to add
|
||||||
sourceNode = sessionNode->FirstChildElement("Source");
|
while ( !cloneNodesToAdd.empty() ) {
|
||||||
for( ; sourceNode ; sourceNode = sourceNode->NextSiblingElement())
|
|
||||||
{
|
|
||||||
xmlCurrent_ = sourceNode;
|
|
||||||
|
|
||||||
// verify type of node
|
// take out Clone's XML element
|
||||||
const char *pType = xmlCurrent_->Attribute("type");
|
xmlCurrent_ = cloneNodesToAdd.front();
|
||||||
if ( pType && std::string(pType) == "CloneSource") {
|
cloneNodesToAdd.pop_front();
|
||||||
|
|
||||||
// check if a source with same id exists
|
// check if a clone source with same id exists
|
||||||
uint64_t id_xml_ = 0;
|
uint64_t id_xml_ = 0;
|
||||||
xmlCurrent_->QueryUnsigned64Attribute("id", &id_xml_);
|
xmlCurrent_->QueryUnsigned64Attribute("id", &id_xml_);
|
||||||
SourceList::iterator sit = session_->find(id_xml_);
|
SourceList::iterator sit = session_->find(id_xml_);
|
||||||
|
|
||||||
// no source clone with this id exists
|
// no source clone with this id exists
|
||||||
if ( sit == session_->end() ) {
|
if ( sit == session_->end() ) {
|
||||||
|
|
||||||
// clone from given origin
|
// try to get clone from given origin
|
||||||
XMLElement* originNode = xmlCurrent_->FirstChildElement("origin");
|
XMLElement* originNode = xmlCurrent_->FirstChildElement("origin");
|
||||||
if (originNode) {
|
if (originNode) {
|
||||||
uint64_t id_origin_ = 0;
|
|
||||||
originNode->QueryUnsigned64Attribute("id", &id_origin_);
|
|
||||||
SourceList::iterator origin;
|
|
||||||
if (id_origin_ > 0)
|
|
||||||
origin = session_->find(id_origin_);
|
|
||||||
else {
|
|
||||||
const char *text = originNode->GetText();
|
|
||||||
if (text)
|
|
||||||
origin = session_->find( std::string(text) );
|
|
||||||
else
|
|
||||||
origin = session_->end();
|
|
||||||
}
|
|
||||||
// found the orign source
|
|
||||||
if (origin != session_->end()) {
|
|
||||||
// create a new source of type Clone
|
|
||||||
CloneSource *clone_source = (*origin)->clone(id_xml_);
|
|
||||||
|
|
||||||
// add source to session
|
// find origin by id
|
||||||
session_->addSource(clone_source);
|
uint64_t id_origin_ = 0;
|
||||||
|
originNode->QueryUnsigned64Attribute("id", &id_origin_);
|
||||||
|
SourceList::iterator origin;
|
||||||
|
if (id_origin_ > 0)
|
||||||
|
origin = session_->find(id_origin_);
|
||||||
|
// legacy: find origin by name
|
||||||
|
else {
|
||||||
|
const char *text = originNode->GetText();
|
||||||
|
if (text)
|
||||||
|
origin = session_->find( std::string(text) );
|
||||||
|
else
|
||||||
|
origin = session_->end();
|
||||||
|
}
|
||||||
|
|
||||||
// apply config to source
|
// found the orign source!
|
||||||
clone_source->accept(*this);
|
if (origin != session_->end()) {
|
||||||
clone_source->touch();
|
// create a new source of type Clone
|
||||||
|
CloneSource *clone_source = (*origin)->clone(id_xml_);
|
||||||
|
|
||||||
// remember
|
// add clone source to session
|
||||||
sources_id_[id_xml_] = clone_source;
|
session_->addSource(clone_source);
|
||||||
}
|
|
||||||
|
// apply config to clone source
|
||||||
|
clone_source->accept(*this);
|
||||||
|
clone_source->touch();
|
||||||
|
|
||||||
|
// remember
|
||||||
|
sources_id_[id_xml_] = clone_source;
|
||||||
|
}
|
||||||
|
// origin not found, retry later
|
||||||
|
else {
|
||||||
|
// sanity check: only retry later if the id is possible.
|
||||||
|
if ( std::find(possible_xml_ids.begin(), possible_xml_ids.end(),id_origin_) != possible_xml_ids.end() )
|
||||||
|
cloneNodesToAdd.push_back(xmlCurrent_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1200,11 +1214,6 @@ void SessionLoader::visit (SrtReceiverSource& s)
|
|||||||
|
|
||||||
void SessionLoader::visit (CloneSource& s)
|
void SessionLoader::visit (CloneSource& s)
|
||||||
{
|
{
|
||||||
// set attributes
|
|
||||||
int p = 0;
|
|
||||||
xmlCurrent_->QueryIntAttribute("provenance", &p);
|
|
||||||
s.setCloningProvenance((CloneSource::CloneSourceProvenance)p);
|
|
||||||
|
|
||||||
double d = 0.0;
|
double d = 0.0;
|
||||||
xmlCurrent_->QueryDoubleAttribute("delay", &d);
|
xmlCurrent_->QueryDoubleAttribute("delay", &d);
|
||||||
s.setDelay(d);
|
s.setDelay(d);
|
||||||
|
|||||||
@@ -687,7 +687,6 @@ void SessionVisitor::visit (CloneSource& s)
|
|||||||
xmlCurrent_->SetAttribute("type", "CloneSource");
|
xmlCurrent_->SetAttribute("type", "CloneSource");
|
||||||
|
|
||||||
if (s.origin()) {
|
if (s.origin()) {
|
||||||
xmlCurrent_->SetAttribute("provenance", (int) s.cloningProvenance());
|
|
||||||
xmlCurrent_->SetAttribute("delay", (double) s.delay());
|
xmlCurrent_->SetAttribute("delay", (double) s.delay());
|
||||||
|
|
||||||
XMLElement *origin = xmlDoc_->NewElement("origin");
|
XMLElement *origin = xmlDoc_->NewElement("origin");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#define APP_TITLE "Video Live Mixer"
|
#define APP_TITLE "Video Live Mixer"
|
||||||
#define APP_SETTINGS "vimix.xml"
|
#define APP_SETTINGS "vimix.xml"
|
||||||
#define XML_VERSION_MAJOR 0
|
#define XML_VERSION_MAJOR 0
|
||||||
#define XML_VERSION_MINOR 2
|
#define XML_VERSION_MINOR 3
|
||||||
#define MAX_RECENT_HISTORY 20
|
#define MAX_RECENT_HISTORY 20
|
||||||
#define MAX_SESSION_LEVEL 3
|
#define MAX_SESSION_LEVEL 3
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user