mirror of
https://github.com/brunoherbelin/vimix.git
synced 2026-01-23 07:11:06 +01:00
Creation of the base class StreamSource. It is intended to become the
base class for all gstreamer pipeline. DeviceSource and PatternSource inherit from it. A generic stream source class is created for development tests and hack.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
#include "defines.h"
|
||||
#include "ImageShader.h"
|
||||
#include "ImageProcessingShader.h"
|
||||
#include "Resource.h"
|
||||
#include "Primitives.h"
|
||||
#include "Stream.h"
|
||||
@@ -118,7 +117,6 @@ void Pattern::open( uint pattern )
|
||||
std::ostringstream oss;
|
||||
oss << " kx2=" << (int)(aspectRatio() * 10.f) << " ky2=10 kt=4";
|
||||
gstreamer_pattern += oss.str(); // Zone plate
|
||||
single_frame_ = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -129,133 +127,129 @@ void Pattern::open( uint pattern )
|
||||
single_frame_ = type_ < 15;
|
||||
|
||||
// (private) open stream
|
||||
open(gstreamer_pattern);
|
||||
Stream::open(gstreamer_pattern);
|
||||
}
|
||||
|
||||
void Pattern::open(std::string gstreamer_pattern)
|
||||
{
|
||||
// set gstreamer pipeline source
|
||||
description_ = gstreamer_pattern;
|
||||
|
||||
// close before re-openning
|
||||
if (isOpen())
|
||||
close();
|
||||
|
||||
execute_open();
|
||||
}
|
||||
|
||||
|
||||
PatternSource::PatternSource(glm::ivec2 resolution) : Source()
|
||||
PatternSource::PatternSource(glm::ivec2 resolution) : StreamSource()
|
||||
{
|
||||
// create stream
|
||||
stream_ = new Pattern(resolution);
|
||||
stream_ = (Stream *) new Pattern(resolution);
|
||||
|
||||
// create surface
|
||||
patternsurface_ = new Surface(renderingshader_);
|
||||
}
|
||||
// // create surface
|
||||
// surface_ = new Surface(renderingshader_);
|
||||
|
||||
PatternSource::~PatternSource()
|
||||
{
|
||||
// delete media surface & stream
|
||||
delete patternsurface_;
|
||||
delete stream_;
|
||||
}
|
||||
|
||||
bool PatternSource::failed() const
|
||||
{
|
||||
return stream_->failed();
|
||||
}
|
||||
|
||||
uint PatternSource::texture() const
|
||||
{
|
||||
return stream_->texture();
|
||||
}
|
||||
|
||||
void PatternSource::replaceRenderingShader()
|
||||
{
|
||||
patternsurface_->replaceShader(renderingshader_);
|
||||
overlays_[View::MIXING]->attach( new Symbol(Symbol::PATTERN, glm::vec3(0.8f, 0.8f, 0.01f)) );
|
||||
overlays_[View::LAYER]->attach( new Symbol(Symbol::PATTERN, glm::vec3(0.8f, 0.8f, 0.01f)) );
|
||||
}
|
||||
|
||||
void PatternSource::setPattern(int id)
|
||||
{
|
||||
Log::Notify("Creating pattern %s", Pattern::pattern_types[id].c_str());
|
||||
|
||||
stream_->open(id);
|
||||
pattern()->open( (uint) id );
|
||||
stream_->play(true);
|
||||
}
|
||||
|
||||
|
||||
void PatternSource::init()
|
||||
{
|
||||
if ( stream_->isOpen() ) {
|
||||
|
||||
// update video
|
||||
stream_->update();
|
||||
|
||||
// once the texture of media player is created
|
||||
if (stream_->texture() != Resource::getTextureBlack()) {
|
||||
|
||||
// get the texture index from media player, apply it to the media surface
|
||||
patternsurface_->setTextureIndex( stream_->texture() );
|
||||
|
||||
// create Frame buffer matching size of media player
|
||||
float height = float(stream_->width()) / stream_->aspectRatio();
|
||||
FrameBuffer *renderbuffer = new FrameBuffer(stream_->width(), (uint)height, true);
|
||||
|
||||
// set the renderbuffer of the source and attach rendering nodes
|
||||
attach(renderbuffer);
|
||||
|
||||
// icon in mixing view
|
||||
overlays_[View::MIXING]->attach( new Symbol(Symbol::PATTERN, glm::vec3(0.8f, 0.8f, 0.01f)) );
|
||||
overlays_[View::LAYER]->attach( new Symbol(Symbol::PATTERN, glm::vec3(0.8f, 0.8f, 0.01f)) );
|
||||
|
||||
// done init
|
||||
initialized_ = true;
|
||||
Log::Info("Source Pattern linked to Stream %d.", stream_->description().c_str());
|
||||
|
||||
// force update of activation mode
|
||||
active_ = true;
|
||||
touch();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PatternSource::setActive (bool on)
|
||||
{
|
||||
bool was_active = active_;
|
||||
|
||||
Source::setActive(on);
|
||||
|
||||
// change status of media player (only if status changed)
|
||||
if ( active_ != was_active ) {
|
||||
stream_->enable(active_);
|
||||
}
|
||||
}
|
||||
|
||||
void PatternSource::update(float dt)
|
||||
{
|
||||
Source::update(dt);
|
||||
|
||||
// update stream
|
||||
stream_->update();
|
||||
}
|
||||
|
||||
void PatternSource::render()
|
||||
{
|
||||
if (!initialized_)
|
||||
init();
|
||||
else {
|
||||
// render the media player into frame buffer
|
||||
static glm::mat4 projection = glm::ortho(-1.f, 1.f, 1.f, -1.f, -1.f, 1.f);
|
||||
renderbuffer_->begin();
|
||||
patternsurface_->draw(glm::identity<glm::mat4>(), projection);
|
||||
renderbuffer_->end();
|
||||
}
|
||||
}
|
||||
|
||||
void PatternSource::accept(Visitor& v)
|
||||
{
|
||||
Source::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
Pattern *PatternSource::pattern() const
|
||||
{
|
||||
return dynamic_cast<Pattern *>(stream_);
|
||||
}
|
||||
|
||||
|
||||
//PatternSource::~PatternSource()
|
||||
//{
|
||||
// // delete media surface & stream
|
||||
// delete patternsurface_;
|
||||
// delete stream_;
|
||||
//}
|
||||
|
||||
//bool PatternSource::failed() const
|
||||
//{
|
||||
// return stream_->failed();
|
||||
//}
|
||||
|
||||
//uint PatternSource::texture() const
|
||||
//{
|
||||
// return stream_->texture();
|
||||
//}
|
||||
|
||||
//void PatternSource::replaceRenderingShader()
|
||||
//{
|
||||
// patternsurface_->replaceShader(renderingshader_);
|
||||
//}
|
||||
|
||||
|
||||
//void PatternSource::init()
|
||||
//{
|
||||
// if ( stream_->isOpen() ) {
|
||||
|
||||
// // update video
|
||||
// stream_->update();
|
||||
|
||||
// // once the texture of media player is created
|
||||
// if (stream_->texture() != Resource::getTextureBlack()) {
|
||||
|
||||
// // get the texture index from media player, apply it to the media surface
|
||||
// patternsurface_->setTextureIndex( stream_->texture() );
|
||||
|
||||
// // create Frame buffer matching size of media player
|
||||
// float height = float(stream_->width()) / stream_->aspectRatio();
|
||||
// FrameBuffer *renderbuffer = new FrameBuffer(stream_->width(), (uint)height, true);
|
||||
|
||||
// // set the renderbuffer of the source and attach rendering nodes
|
||||
// attach(renderbuffer);
|
||||
|
||||
// // icon in mixing view
|
||||
// overlays_[View::MIXING]->attach( new Symbol(Symbol::PATTERN, glm::vec3(0.8f, 0.8f, 0.01f)) );
|
||||
// overlays_[View::LAYER]->attach( new Symbol(Symbol::PATTERN, glm::vec3(0.8f, 0.8f, 0.01f)) );
|
||||
|
||||
// // done init
|
||||
// initialized_ = true;
|
||||
// Log::Info("Source Pattern linked to Stream %d.", stream_->description().c_str());
|
||||
|
||||
// // force update of activation mode
|
||||
// active_ = true;
|
||||
// touch();
|
||||
// }
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
//void PatternSource::setActive (bool on)
|
||||
//{
|
||||
// bool was_active = active_;
|
||||
|
||||
// Source::setActive(on);
|
||||
|
||||
// // change status of media player (only if status changed)
|
||||
// if ( active_ != was_active ) {
|
||||
// stream_->enable(active_);
|
||||
// }
|
||||
//}
|
||||
|
||||
//void PatternSource::update(float dt)
|
||||
//{
|
||||
// Source::update(dt);
|
||||
|
||||
// // update stream
|
||||
// stream_->update();
|
||||
//}
|
||||
|
||||
//void PatternSource::render()
|
||||
//{
|
||||
// if (!initialized_)
|
||||
// init();
|
||||
// else {
|
||||
// // render the media player into frame buffer
|
||||
// static glm::mat4 projection = glm::ortho(-1.f, 1.f, 1.f, -1.f, -1.f, 1.f);
|
||||
// renderbuffer_->begin();
|
||||
// patternsurface_->draw(glm::identity<glm::mat4>(), projection);
|
||||
// renderbuffer_->end();
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user