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: Helge Norberg, helge.norberg@svt.se
24 #include <common/memory.h>
26 #include <core/mixer/audio/audio_mixer.h>
28 #include <boost/noncopyable.hpp>
29 #include <boost/optional.hpp>
30 #include <boost/property_tree/ptree_fwd.hpp>
34 namespace caspar { namespace core {
36 struct audio_channel_layout final
40 std::vector<std::wstring> channel_order;
42 audio_channel_layout(int num_channels, std::wstring type, const std::wstring& channel_order);
43 std::vector<int> indexes_of(const std::wstring& channel_name) const;
44 std::wstring print() const;
45 static const audio_channel_layout& invalid();
47 audio_channel_layout();
50 bool operator==(const audio_channel_layout& lhs, const audio_channel_layout& rhs);
51 bool operator!=(const audio_channel_layout& lhs, const audio_channel_layout& rhs);
53 class audio_channel_layout_repository : boost::noncopyable
56 audio_channel_layout_repository();
57 void register_layout(std::wstring name, audio_channel_layout layout);
58 void register_all_layouts(const boost::property_tree::wptree& layouts);
59 boost::optional<audio_channel_layout> get_layout(const std::wstring& name) const;
60 static spl::shared_ptr<audio_channel_layout_repository> get_default();
63 spl::shared_ptr<impl> impl_;
66 class audio_mix_config_repository : boost::noncopyable
69 audio_mix_config_repository();
71 const std::wstring& from_type,
72 const std::vector<std::wstring>& to_types,
73 const std::wstring& mix_config);
74 void register_all_configs(const boost::property_tree::wptree& configs);
75 boost::optional<std::wstring> get_config(const std::wstring& from_type, const std::wstring& to_type) const;
76 static spl::shared_ptr<audio_mix_config_repository> get_default();
79 spl::shared_ptr<impl> impl_;
82 // Implementation in ffmpeg module.
83 class audio_channel_remapper : boost::noncopyable
86 audio_channel_remapper(
87 audio_channel_layout input_layout,
88 audio_channel_layout output_layout,
89 spl::shared_ptr<audio_mix_config_repository> mix_repo = audio_mix_config_repository::get_default());
92 * Perform downmix/upmix/rearranging of audio data if needed.
94 * @param input The input audio buffer.
96 * @return input if the input layout is the same as the output layout.
97 * otherwise the mixed buffer (valid until the next call).
99 audio_buffer mix_and_rearrange(audio_buffer input);
102 spl::shared_ptr<impl> impl_;