2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
22 #include <common/memory/safe_ptr.h>
\r
24 #include <boost/noncopyable.hpp>
\r
26 #include <algorithm>
\r
27 #include <functional>
\r
33 #include <boost/thread/future.hpp>
\r
34 #include <boost/property_tree/ptree.hpp>
\r
43 struct frame_factory;
\r
45 struct frame_producer : boost::noncopyable
\r
54 virtual ~frame_producer(){}
\r
56 virtual std::wstring print() const = 0; // nothrow
\r
58 virtual boost::unique_future<std::wstring> call(const std::wstring&)
\r
60 boost::promise<std::wstring> promise;
\r
61 promise.set_value(L"");
\r
62 return promise.get_future();
\r
65 virtual boost::property_tree::wptree info() const
\r
67 boost::property_tree::wptree info;
\r
68 info.push_front(std::make_pair(L"producer", print()));
\r
72 virtual safe_ptr<frame_producer> get_following_producer() const {return frame_producer::empty();} // nothrow
\r
73 virtual void set_leading_producer(const safe_ptr<frame_producer>&) {} // nothrow
\r
75 virtual int64_t nb_frames() const {return std::numeric_limits<int>::max();}
\r
76 virtual int64_t file_nb_frames() const {return nb_frames();}
\r
78 virtual int64_t frame_number() const {return 0;}
\r
79 virtual int64_t file_frame_number() const {return frame_number();}
\r
81 virtual safe_ptr<basic_frame> receive(int hints) = 0;
\r
82 virtual safe_ptr<core::basic_frame> last_frame() const = 0;
\r
84 static const safe_ptr<frame_producer>& empty(); // nothrow
\r
87 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer, int hints);
\r
89 typedef std::function<safe_ptr<core::frame_producer>(const safe_ptr<frame_factory>&, const std::vector<std::wstring>&)> producer_factory_t;
\r
90 void register_producer_factory(const producer_factory_t& factory); // Not thread-safe.
\r
91 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>&, const std::vector<std::wstring>& params);
\r
92 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>&, const std::wstring& params);
\r
93 safe_ptr<core::frame_producer> create_producer_destroy_proxy(safe_ptr<core::frame_producer>&& producer);
\r
95 template<typename T>
\r
96 typename std::decay<T>::type get_param(const std::wstring& name, const std::vector<std::wstring>& params, T fail_value)
\r
98 auto it = std::find(params.begin(), params.end(), name);
\r
99 if(it == params.end() || ++it == params.end())
\r
102 T value = fail_value;
\r
105 value = boost::lexical_cast<std::decay<T>::type>(*it);
\r
107 catch(boost::bad_lexical_cast&){}
\r