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 "color/color_producer.h"
\r
26 #include <common/memory/safe_ptr.h>
\r
28 namespace caspar { namespace core {
\r
30 std::vector<const producer_factory_t> g_factories;
\r
32 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer)
\r
34 if(producer == frame_producer::empty())
\r
35 return basic_frame::eof();
\r
37 auto frame = basic_frame::eof();
\r
40 frame = producer->receive();
\r
46 // Producer will be removed since frame == basic_frame::eof.
\r
47 CASPAR_LOG_CURRENT_EXCEPTION();
\r
48 CASPAR_LOG(warning) << producer->print() << " Failed to receive frame. Removing producer.";
\r
53 if(frame == basic_frame::eof())
\r
55 auto following = producer->get_following_producer();
\r
56 following->set_leading_producer(producer);
\r
57 producer = std::move(following);
\r
59 return receive_and_follow(producer);
\r
64 void register_producer_factory(const producer_factory_t& factory)
\r
66 g_factories.push_back(factory);
\r
69 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)
\r
72 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));
\r
74 auto producer = frame_producer::empty();
\r
75 std::any_of(g_factories.begin(), g_factories.end(), [&](const producer_factory_t& factory) -> bool
\r
79 producer = factory(my_frame_factory, params);
\r
83 CASPAR_LOG_CURRENT_EXCEPTION();
\r
85 return producer != frame_producer::empty();
\r
88 if(producer == frame_producer::empty())
\r
89 producer = create_color_producer(my_frame_factory, params);
\r
91 if(producer == frame_producer::empty())
\r
92 BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));
\r