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/audio_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 if(producer == frame_producer::empty())
\r
54 return basic_frame::eof();
\r
56 auto frame = basic_frame::eof();
\r
59 frame = producer->receive(hints);
\r
65 // Producer will be removed since frame == basic_frame::eof.
\r
66 CASPAR_LOG_CURRENT_EXCEPTION();
\r
67 CASPAR_LOG(warning) << producer->print() << " Failed to receive frame. Removing producer.";
\r
72 if(frame == basic_frame::eof())
\r
74 CASPAR_LOG(info) << producer->print() << " End Of File.";
\r
75 auto following = producer->get_following_producer();
\r
76 following->set_leading_producer(producer);
\r
77 producer = std::move(following);
\r
79 return receive_and_follow(producer, hints);
\r
84 void register_producer_factory(const producer_factory_t& factory)
\r
86 g_factories.push_back(factory);
\r
89 safe_ptr<core::frame_producer> do_create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)
\r
92 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));
\r
94 auto producer = frame_producer::empty();
\r
95 std::any_of(g_factories.begin(), g_factories.end(), [&](const producer_factory_t& factory) -> bool
\r
99 producer = factory(my_frame_factory, params);
\r
103 CASPAR_LOG_CURRENT_EXCEPTION();
\r
105 return producer != frame_producer::empty();
\r
108 if(producer == frame_producer::empty())
\r
109 producer = create_color_producer(my_frame_factory, params);
\r
111 if(producer == frame_producer::empty())
\r
114 BOOST_FOREACH(auto& param, params)
\r
115 str += param + L" ";
\r
116 BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(narrow(str)));
\r
123 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)
\r
125 auto producer = do_create_producer(my_frame_factory, params);
\r
126 auto key_producer = frame_producer::empty();
\r
128 try // to find a key file.
\r
130 auto params_copy = params;
\r
131 if(params_copy.size() > 0)
\r
133 params_copy[0] += L"_A";
\r
134 key_producer = do_create_producer(my_frame_factory, params_copy);
\r
139 if(key_producer != frame_producer::empty())
\r
140 return create_separated_producer(producer, key_producer);
\r