]> git.sesse.net Git - casparcg/blobdiff - core/producer/frame_producer.h
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / core / producer / frame_producer.h
index f522322a59aacfd2b3f51061a410de418db5f39a..3cf7e50107fcc7ad38a2acf8de243e6569b9ac27 100644 (file)
 */\r
 #pragma once\r
 \r
-#include "../mixer/frame/draw_frame.h"\r
-#include "../mixer/frame_factory.h"\r
-\r
 #include <common/memory/safe_ptr.h>\r
 \r
 #include <boost/noncopyable.hpp>\r
 \r
+#include <algorithm>\r
+#include <functional>\r
 #include <string>\r
-#include <ostream>\r
+#include <vector>\r
+#include <stdint.h>\r
+#include <numeric>\r
+\r
+namespace caspar { \r
+       \r
+class executor;\r
+       \r
+namespace core {\r
 \r
-namespace caspar { namespace core {\r
+class basic_frame;\r
+struct frame_factory;\r
 \r
-class frame_producer : boost::noncopyable\r
+struct frame_producer : boost::noncopyable\r
 {\r
 public:\r
+       enum hints\r
+       {\r
+               NO_HINT = 0,\r
+               ALPHA_HINT = 1\r
+       };\r
+\r
        virtual ~frame_producer(){}     \r
 \r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       /// \fn virtual draw_frame :::receive() = 0;\r
-       ///\r
-       /// \brief      Renders a frame.\r
-       ///             \r
-       /// \note       This function is run in through the tbb task_schedular and shall be *non blocking*.\r
-       ///\r
-       /// \return     The frame. \r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       virtual safe_ptr<draw_frame> receive() = 0;\r
-\r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       /// \fn virtual std::shared_ptr<frame_producer> :::get_following_producer() const\r
-       ///\r
-       /// \brief      Gets the producer which will replace the current producer on EOF. \r
-       ///\r
-       /// \return     The following producer, or nullptr if there is no following producer. \r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
+       virtual std::wstring print() const = 0; // nothrow\r
+\r
+       virtual void param(const std::wstring&){}\r
+\r
        virtual safe_ptr<frame_producer> get_following_producer() const {return frame_producer::empty();}  // nothrow\r
+       virtual void set_leading_producer(const safe_ptr<frame_producer>&) {}  // nothrow\r
+               \r
+       virtual int64_t nb_frames() const {return std::numeric_limits<int>::max();}\r
        \r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       /// \fn virtual void :::set_leading_producer(const std::shared_ptr<frame_producer>& producer)\r
-       ///\r
-       /// \brief      Sets the producer which was run before the current producer. \r
-       ///\r
-       /// \param      producer        The leading producer.\r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       virtual void set_leading_producer(const safe_ptr<frame_producer>& /*producer*/) {}  // nothrow\r
-       \r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       /// \fn virtual void :::initialize(const safe_ptr<frame_factory>& frame_factory) = 0;\r
-       ///\r
-       /// \brief      Provides the frame frame_factory used to create frames and initializes the producer. \r
-       ///\r
-       /// \param      frame_factory   The frame frame_factory. \r
-       ////////////////////////////////////////////////////////////////////////////////////////////////////\r
-       virtual void initialize(const safe_ptr<frame_factory>& frame_factory) = 0;\r
-\r
-       static safe_ptr<frame_producer> empty()  // nothrow\r
-       {\r
-               struct empty_frame_producer : public frame_producer\r
-               {\r
-                       virtual safe_ptr<draw_frame> receive(){return draw_frame::empty();}\r
-                       virtual void initialize(const safe_ptr<frame_factory>&){}\r
-                       virtual std::wstring print() const { return L"empty";}\r
-               };\r
-               static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();\r
-               return producer;\r
-       }\r
+       virtual safe_ptr<basic_frame> receive(int hints) = 0;\r
+       virtual safe_ptr<core::basic_frame> last_frame() const = 0;\r
 \r
-       virtual std::wstring print() const = 0; // nothrow\r
+       static const safe_ptr<frame_producer>& empty(); // nothrow\r
 };\r
 \r
-inline std::wostream& operator<<(std::wostream& out, const frame_producer& producer)\r
-{\r
-       out << producer.print().c_str();\r
-       return out;\r
-}\r
+safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer, int hints);\r
 \r
-inline std::wostream& operator<<(std::wostream& out, const safe_ptr<const frame_producer>& producer)\r
-{\r
-       out << producer->print().c_str();\r
-       return out;\r
+typedef std::function<safe_ptr<core::frame_producer>(const safe_ptr<frame_factory>&, const std::vector<std::wstring>&)> producer_factory_t;\r
+void register_producer_factory(const producer_factory_t& factory); // Not thread-safe.\r
+safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>&, const std::vector<std::wstring>& params);\r
+\r
+safe_ptr<core::frame_producer> create_destroy_producer_proxy(executor& destroy_context, const safe_ptr<frame_producer>& producer);\r
+\r
+template<typename T>\r
+typename std::decay<T>::type get_param(const std::wstring& name, const std::vector<std::wstring>& params, T fail_value)\r
+{      \r
+       auto it = std::find(params.begin(), params.end(), name);\r
+       if(it == params.end() || ++it == params.end())  \r
+               return fail_value;\r
+       \r
+       T value = fail_value;\r
+       try\r
+       {\r
+               value = boost::lexical_cast<std::decay<T>::type>(*it);\r
+       }\r
+       catch(boost::bad_lexical_cast&){}\r
+\r
+       return value;\r
 }\r
 \r
 }}\r