2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
22 #include "../stdafx.h"
24 #include "reroute_producer.h"
25 #include "layer_producer.h"
26 #include "channel_producer.h"
28 #include <core/producer/frame_producer.h>
29 #include <core/video_channel.h>
31 #include <boost/algorithm/string.hpp>
32 #include <boost/range/algorithm/find_if.hpp>
34 namespace caspar { namespace reroute {
36 spl::shared_ptr<core::frame_producer> create_producer(
37 const core::frame_producer_dependencies& dependencies,
38 const std::vector<std::wstring>& params)
40 static const std::wstring PREFIX = L"route://";
43 !boost::starts_with(params.at(0), PREFIX) ||
44 boost::ends_with(params.at(0), L"_A") ||
45 boost::ends_with(params.at(0), L"_ALPHA"))
47 return core::frame_producer::empty();
50 auto& url = params.at(0);
51 auto channel_layer_spec = url.substr(PREFIX.length());
52 auto dash = channel_layer_spec.find(L"-");
53 bool has_layer_spec = dash != std::wstring::npos;
57 channel_id = boost::lexical_cast<int>(channel_layer_spec.substr(0, dash));
59 channel_id = boost::lexical_cast<int>(channel_layer_spec);
61 auto found_channel = boost::find_if(dependencies.channels, [=](spl::shared_ptr<core::video_channel> ch) { return ch->index() == channel_id; });
63 if (found_channel == dependencies.channels.end())
64 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(L"No channel with id " + channel_id));
68 auto layer = boost::lexical_cast<int>(channel_layer_spec.substr(dash + 1));
70 return create_layer_producer(*found_channel, layer);
74 return create_channel_producer(dependencies, *found_channel);