]> git.sesse.net Git - casparcg/blob - core/frame/audio_channel_layout.h
[framerate_producer] Fixed frame repeat issue that caused the first frame to be empty...
[casparcg] / core / frame / audio_channel_layout.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #pragma once
23
24 #include <common/memory.h>
25
26 #include <core/mixer/audio/audio_mixer.h>
27
28 #include <boost/noncopyable.hpp>
29 #include <boost/optional.hpp>
30 #include <boost/property_tree/ptree_fwd.hpp>
31
32 #include <string>
33
34 namespace caspar { namespace core {
35
36 struct audio_channel_layout final
37 {
38         int                                                     num_channels;
39         std::wstring                            type;
40         std::vector<std::wstring>       channel_order;
41
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();
46 private:
47         audio_channel_layout();
48 };
49
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);
52
53 class audio_channel_layout_repository : boost::noncopyable
54 {
55 public:
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();
61 private:
62         struct impl;
63         spl::shared_ptr<impl> impl_;
64 };
65
66 class audio_mix_config_repository : boost::noncopyable
67 {
68 public:
69         audio_mix_config_repository();
70         void register_config(
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();
77 private:
78         struct impl;
79         spl::shared_ptr<impl> impl_;
80 };
81
82 // Implementation in ffmpeg module.
83 class audio_channel_remapper : boost::noncopyable
84 {
85 public:
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());
90
91         /**
92          * Perform downmix/upmix/rearranging of audio data if needed.
93          *
94          * @param input The input audio buffer.
95          *
96          * @return input if the input layout is the same as the output layout.
97          *         otherwise the mixed buffer (valid until the next call).
98          */
99         audio_buffer mix_and_rearrange(audio_buffer input);
100 private:
101         struct impl;
102         spl::shared_ptr<impl> impl_;
103 };
104
105 }}