X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Fframe_producer.h;h=cf7fb402ac8f6a7e4d42a70b50d9e13a850301c8;hb=f7b48279d43e30c270ef532f97d59f0582a73efc;hp=c19fec2118cc0df1ffcf3f5635c85c0f202cb414;hpb=2b27061fbf2ec4251c7689ccf6096893412e1d43;p=casparcg diff --git a/core/producer/frame_producer.h b/core/producer/frame_producer.h index c19fec211..cf7fb402a 100644 --- a/core/producer/frame_producer.h +++ b/core/producer/frame_producer.h @@ -1,91 +1,169 @@ -/* -* copyright (c) 2010 Sveriges Television AB -* -* This file is part of CasparCG. -* -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* CasparCG is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with CasparCG. If not, see . -* -*/ -#pragma once - -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace caspar { - -class executor; - -namespace core { - -class basic_frame; -struct frame_factory; - -struct frame_producer : boost::noncopyable -{ -public: - enum hints - { - NO_HINT = 0, - ALPHA_HINT = 1 - }; - - virtual ~frame_producer(){} - - virtual std::wstring print() const = 0; // nothrow - - virtual void param(const std::wstring&){} - - virtual safe_ptr get_following_producer() const {return frame_producer::empty();} // nothrow - virtual void set_leading_producer(const safe_ptr&) {} // nothrow - - virtual int64_t nb_frames() const {return std::numeric_limits::max();} - - virtual safe_ptr receive(int hints) = 0; - virtual safe_ptr last_frame() const = 0; - - static const safe_ptr& empty(); // nothrow -}; - -safe_ptr receive_and_follow(safe_ptr& producer, int hints); - -typedef std::function(const safe_ptr&, const std::vector&)> producer_factory_t; -void register_producer_factory(const producer_factory_t& factory); // Not thread-safe. -safe_ptr create_producer(const safe_ptr&, const std::vector& params); - -template -typename std::decay::type get_param(const std::wstring& name, const std::vector& params, T fail_value) -{ - auto it = std::find(params.begin(), params.end(), name); - if(it == params.end() || ++it == params.end()) - return fail_value; - - T value = fail_value; - try - { - value = boost::lexical_cast::type>(*it); - } - catch(boost::bad_lexical_cast&){} - - return value; -} - -}} +/* +* Copyright (c) 2011 Sveriges Television AB +* +* This file is part of CasparCG (www.casparcg.com). +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +* Author: Robert Nagy, ronag89@gmail.com +*/ + +#pragma once + +#include "../monitor/monitor.h" +#include "../fwd.h" +#include "../interaction/interaction_sink.h" +#include "../help/help_repository.h" +#include "binding.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +FORWARD1(caspar, class executor); + +namespace caspar { namespace core { + +class variable; + +struct constraints +{ + binding width; + binding height; + + constraints(double width, double height); + constraints(); +}; + +// Interface +class frame_producer : public interaction_sink +{ + frame_producer(const frame_producer&); + frame_producer& operator=(const frame_producer&); +public: + + // Static Members + + static const spl::shared_ptr& empty(); + + // Constructors + + frame_producer(){} + virtual ~frame_producer(){} + + // Methods + + virtual draw_frame receive() = 0; + virtual std::future call(const std::vector& params) = 0; + virtual variable& get_variable(const std::wstring& name) = 0; + virtual const std::vector& get_variables() const = 0; + + // monitor::observable + + virtual monitor::subject& monitor_output() = 0; + + // interaction_sink + virtual void on_interaction(const interaction_event::ptr& event) override { } + virtual bool collides(double x, double y) const override { return false; } + + // Properties + + + virtual void paused(bool value) = 0; + virtual std::wstring print() const = 0; + virtual std::wstring name() const = 0; + virtual boost::property_tree::wptree info() const = 0; + virtual uint32_t nb_frames() const = 0; + virtual uint32_t frame_number() const = 0; + virtual draw_frame last_frame() = 0; + virtual constraints& pixel_constraints() = 0; + virtual void leading_producer(const spl::shared_ptr&) {} +}; + +class frame_producer_base : public frame_producer +{ +public: + frame_producer_base(); + virtual ~frame_producer_base(){} + + // Methods + + virtual std::future call(const std::vector& params) override; + virtual variable& get_variable(const std::wstring& name) override; + virtual const std::vector& get_variables() const override; + + // monitor::observable + + // Properties + + void paused(bool value) override; + uint32_t nb_frames() const override; + uint32_t frame_number() const override; + virtual draw_frame last_frame() override; + +private: + virtual draw_frame receive() override; + virtual draw_frame receive_impl() = 0; + + struct impl; + friend struct impl; + std::shared_ptr impl_; +}; + +class frame_producer_registry; + +struct frame_producer_dependencies +{ + spl::shared_ptr frame_factory; + std::vector> channels; + video_format_desc format_desc; + spl::shared_ptr producer_registry; + + frame_producer_dependencies( + const spl::shared_ptr& frame_factory, + const std::vector>& channels, + const video_format_desc& format_desc, + const spl::shared_ptr producer_registry); +}; + +typedef std::function(const frame_producer_dependencies&, const std::vector&)> producer_factory_t; +typedef std::function thumbnail_producer_t; + +class frame_producer_registry : boost::noncopyable +{ +public: + frame_producer_registry(spl::shared_ptr help_repo); + void register_producer_factory(std::wstring name, const producer_factory_t& factory, const help_item_describer& describer); // Not thread-safe. + void register_thumbnail_producer(const thumbnail_producer_t& thumbnail_producer); // Not thread-safe. + spl::shared_ptr create_producer(const frame_producer_dependencies&, const std::vector& params) const; + spl::shared_ptr create_producer(const frame_producer_dependencies&, const std::wstring& params) const; + draw_frame create_thumbnail(const frame_producer_dependencies&, const std::wstring& media_file) const; +private: + struct impl; + spl::shared_ptr impl_; +}; + +spl::shared_ptr create_destroy_proxy(spl::shared_ptr producer); +void destroy_producers_synchronously(); + +}}