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
21 #include "../StdAfx.h"
\r
23 #include "frame_producer.h"
\r
24 #include "frame/basic_frame.h"
\r
25 #include "frame/frame_transform.h"
\r
27 #include "color/color_producer.h"
\r
28 #include "separated/separated_producer.h"
\r
30 #include <common/memory/safe_ptr.h>
\r
31 #include <common/exception/exceptions.h>
\r
33 namespace caspar { namespace core {
\r
35 std::vector<const producer_factory_t> g_factories;
\r
37 const safe_ptr<frame_producer>& frame_producer::empty() // nothrow
\r
39 struct empty_frame_producer : public frame_producer
\r
41 virtual safe_ptr<basic_frame> receive(int){return basic_frame::empty();}
\r
42 virtual safe_ptr<basic_frame> last_frame() const{return basic_frame::empty();}
\r
43 virtual void set_frame_factory(const safe_ptr<frame_factory>&){}
\r
44 virtual int64_t nb_frames() const {return 0;}
\r
45 virtual std::wstring print() const { return L"empty";}
\r
47 static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();
\r
51 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer, int hints)
\r
53 auto frame = producer->receive(hints);
\r
54 if(frame == basic_frame::eof())
\r
56 CASPAR_LOG(info) << producer->print() << " End Of File.";
\r
57 auto following = producer->get_following_producer();
\r
58 following->set_leading_producer(producer);
\r
59 producer = std::move(following);
\r
61 if(producer == frame_producer::empty())
\r
62 return basic_frame::eof();
\r
64 return receive_and_follow(producer, hints);
\r
69 void register_producer_factory(const producer_factory_t& factory)
\r
71 g_factories.push_back(factory);
\r
74 safe_ptr<core::frame_producer> do_create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)
\r
77 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));
\r
79 auto producer = frame_producer::empty();
\r
80 std::any_of(g_factories.begin(), g_factories.end(), [&](const producer_factory_t& factory) -> bool
\r
84 producer = factory(my_frame_factory, params);
\r
88 CASPAR_LOG_CURRENT_EXCEPTION();
\r
90 return producer != frame_producer::empty();
\r
93 if(producer == frame_producer::empty())
\r
94 producer = create_color_producer(my_frame_factory, params);
\r
100 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)
\r
102 auto producer = do_create_producer(my_frame_factory, params);
\r
103 auto key_producer = frame_producer::empty();
\r
105 try // to find a key file.
\r
107 auto params_copy = params;
\r
108 if(params_copy.size() > 0)
\r
110 params_copy[0] += L"_A";
\r
111 key_producer = do_create_producer(my_frame_factory, params_copy);
\r
112 if(key_producer == frame_producer::empty())
\r
114 params_copy[0] += L"LPHA";
\r
115 key_producer = do_create_producer(my_frame_factory, params_copy);
\r
121 if(producer != frame_producer::empty() && key_producer != frame_producer::empty())
\r
122 producer = create_separated_producer(producer, key_producer);
\r
124 if(producer == frame_producer::empty())
\r
127 BOOST_FOREACH(auto& param, params)
\r
128 str += param + L" ";
\r
129 BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(narrow(str)));
\r