#include #include "MediaSource.h" #include "defines.h" #include "ImageShader.h" #include "ImageProcessingShader.h" #include "Resource.h" #include "Primitives.h" #include "MediaPlayer.h" #include "Visitor.h" #include "Log.h" MediaSource::MediaSource() : Source(), path_("") { // create media player mediaplayer_ = new MediaPlayer; // create media surface: // - textured with original texture from media player // - crop & repeat UV can be managed here // - additional custom shader can be associated mediasurface_ = new Surface(rendershader_); } MediaSource::~MediaSource() { // delete media surface & player delete mediasurface_; delete mediaplayer_; } void MediaSource::setPath(const std::string &p) { path_ = p; mediaplayer_->open(path_); mediaplayer_->play(true); Log::Notify("Opening %s", p.c_str()); } std::string MediaSource::path() const { return path_; } MediaPlayer *MediaSource::mediaplayer() const { return mediaplayer_; } bool MediaSource::failed() const { return mediaplayer_->failed(); } uint MediaSource::texture() const { return mediaplayer_->texture(); } void MediaSource::init() { if ( mediaplayer_->isOpen() ) { // update video mediaplayer_->update(); // once the texture of media player is created if (mediaplayer_->texture() != Resource::getTextureBlack()) { // get the texture index from media player, apply it to the media surface mediasurface_->setTextureIndex( mediaplayer_->texture() ); // create Frame buffer matching size of media player float height = float(mediaplayer()->width()) / mediaplayer()->aspectRatio(); FrameBuffer *renderbuffer = new FrameBuffer(mediaplayer()->width(), (uint)height, true); // set the renderbuffer of the source and attach rendering nodes attach(renderbuffer); // icon in mixing view if (mediaplayer_->duration() == GST_CLOCK_TIME_NONE) { overlays_[View::MIXING]->attach( new Icon(Icon::IMAGE, glm::vec3(0.8f, 0.8f, 0.01f)) ); overlays_[View::LAYER]->attach( new Icon(Icon::IMAGE, glm::vec3(0.8f, 0.8f, 0.01f)) ); } else { overlays_[View::MIXING]->attach( new Icon(Icon::VIDEO, glm::vec3(0.8f, 0.8f, 0.01f)) ); overlays_[View::LAYER]->attach( new Icon(Icon::VIDEO, glm::vec3(0.8f, 0.8f, 0.01f)) ); } // done init initialized_ = true; Log::Info("Source Media linked to Media %s.", mediaplayer()->uri().c_str()); // force update of activation mode active_ = true; touch(); } } } void MediaSource::setActive (bool on) { bool was_active = active_; Source::setActive(on); // change status of media player (only if status changed) if ( active_ != was_active ) { mediaplayer()->enable(active_); } } void MediaSource::update(float dt) { Source::update(dt); // update video mediaplayer_->update(); } void MediaSource::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(); mediasurface_->draw(glm::identity(), projection); renderbuffer_->end(); } } void MediaSource::accept(Visitor& v) { Source::accept(v); v.visit(*this); }