]> git.sesse.net Git - casparcg/blobdiff - core/consumer/frame_consumer.h
Created a consumer that provides sync to a channel based on the pace of another chann...
[casparcg] / core / consumer / frame_consumer.h
index a5fe5d4e4a4e03141a340c823e1d4a7202969d65..58ffeb61b62168581d4f2d91c4f2ea5d068c9897 100644 (file)
-/*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
-*\r
-*  This file is part of CasparCG.\r
-*\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
-*\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-*/\r
-#pragma once\r
-\r
-#include <common/memory/safe_ptr.h>\r
-\r
-#include <boost/noncopyable.hpp>\r
-\r
-#include <functional>\r
-#include <string>\r
-#include <vector>\r
-\r
-namespace caspar { namespace core {\r
-       \r
-class read_frame;\r
-struct video_format_desc;\r
-\r
-struct frame_consumer : boost::noncopyable\r
-{\r
-       virtual ~frame_consumer() {}\r
-       \r
-       virtual void send(const safe_ptr<const read_frame>& frame) = 0;\r
-       virtual size_t buffer_depth() const = 0;\r
-       virtual void initialize(const video_format_desc& format_desc) = 0;\r
-       virtual std::wstring print() const = 0;\r
-\r
-       static const safe_ptr<frame_consumer>& empty()\r
-       {\r
-               struct empty_frame_consumer : public frame_consumer\r
-               {\r
-                       virtual void send(const safe_ptr<const read_frame>&){}\r
-                       virtual size_t buffer_depth() const{return 0;}\r
-                       virtual void initialize(const video_format_desc&){}\r
-                       virtual std::wstring print() const {return L"empty";}\r
-               };\r
-               static safe_ptr<frame_consumer> consumer = make_safe<empty_frame_consumer>();\r
-               return consumer;\r
-       }\r
-};\r
-\r
-typedef std::function<safe_ptr<core::frame_consumer>(const std::vector<std::wstring>&)> consumer_factory_t;\r
-\r
-void register_consumer_factory(const consumer_factory_t& factory);\r
-safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params);\r
-\r
-}}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#pragma once
+
+#include "../monitor/monitor.h"
+#include "../fwd.h"
+#include "../help/help_repository.h"
+
+#include <common/memory.h>
+#include <common/future_fwd.h>
+
+#include <boost/property_tree/ptree_fwd.hpp>
+
+#include <functional>
+#include <string>
+#include <vector>
+
+namespace caspar { namespace core {
+
+// Interface
+class frame_consumer
+{
+       frame_consumer(const frame_consumer&);
+       frame_consumer& operator=(const frame_consumer&);
+public:
+
+       // Static Members
+
+       static const spl::shared_ptr<frame_consumer>& empty();
+
+       // Constructors
+
+       frame_consumer(){}
+       virtual ~frame_consumer() {}
+
+       // Methods
+
+       virtual std::future<bool>                               send(const_frame frame) = 0;
+       virtual void                                                    initialize(const video_format_desc& format_desc, const audio_channel_layout& channel_layout, int channel_index) = 0;
+
+       // monitor::observable
+
+       virtual monitor::subject& monitor_output() = 0;
+
+       // Properties
+
+       virtual std::wstring                                    print() const = 0;
+       virtual std::wstring                                    name() const = 0;
+       virtual boost::property_tree::wptree    info() const = 0;
+       virtual bool                                                    has_synchronization_clock() const {return true;}
+       virtual int                                                             buffer_depth() const = 0; // -1 to not participate in frame presentation synchronization
+       virtual int                                                             index() const = 0;
+       virtual int64_t                                                 presentation_frame_age_millis() const = 0;
+       virtual const frame_consumer*                   unwrapped() const { return this; }
+};
+
+typedef std::function<spl::shared_ptr<frame_consumer>(
+               const std::vector<std::wstring>&,
+               interaction_sink* sink,
+               std::vector<spl::shared_ptr<video_channel>> channels)> consumer_factory_t;
+typedef std::function<spl::shared_ptr<frame_consumer>(
+               const boost::property_tree::wptree& element,
+               interaction_sink* sink,
+               std::vector<spl::shared_ptr<video_channel>> channels)> preconfigured_consumer_factory_t;
+
+class frame_consumer_registry : boost::noncopyable
+{
+public:
+       frame_consumer_registry(spl::shared_ptr<help_repository> help_repo);
+       void register_consumer_factory(const std::wstring& name, const consumer_factory_t& factory, const help_item_describer& describer);
+       void register_preconfigured_consumer_factory(
+                       const std::wstring& element_name,
+                       const preconfigured_consumer_factory_t& factory);
+       spl::shared_ptr<frame_consumer> create_consumer(
+                       const std::vector<std::wstring>& params,
+                       interaction_sink* sink,
+                       std::vector<spl::shared_ptr<video_channel>> channels) const;
+       spl::shared_ptr<frame_consumer> create_consumer(
+                       const std::wstring& element_name,
+                       const boost::property_tree::wptree& element,
+                       interaction_sink* sink,
+                       std::vector<spl::shared_ptr<video_channel>> channels) const;
+private:
+       struct impl;
+       spl::shared_ptr<impl> impl_;
+};
+
+void destroy_consumers_synchronously();
+
+}}