avcpp 3.2.1
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
channellayout.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <string>
11#include <string_view>
12#include <bitset>
13
14#include "avcompat.h"
15#include "avutils.h"
16
17#if AVCPP_API_NEW_CHANNEL_LAYOUT
18extern "C" {
19#include <libavutil/channel_layout.h>
20}
21
22namespace av {
23
31std::string channel_name(AVChannel channel);
39std::string channel_description(AVChannel channel);
47AVChannel channel_from_string(const std::string &name);
55AVChannel channel_from_string(const char *name);
56
57class ChannelLayout;
58
68{
69public:
74 // implicit by design
83 ChannelLayoutView(const AVChannelLayout &layout) noexcept;
84
85 // ???
86 //+ const AVChannelLayout *av_channel_layout_standard(void **opaque);
95 template<typename Callable>
96 static void iterate(Callable callable) {
97 void *iter = nullptr;
98 const AVChannelLayout *playout;
99 while ((playout = av_channel_layout_standard(&iter))) {
100 if (callable(ChannelLayoutView(*playout)))
101 break;
102 }
103 }
104
108 static void dumpLayouts();
109
110 //+ int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size);
111 //+ int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel);
112 //+ int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout, const char *name);
113 //+ enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx);
114 //+ enum AVChannel av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout, const char *name);
115 //+ uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, uint64_t mask);
116 //+ int av_channel_layout_check(const AVChannelLayout *channel_layout);
117 //+ int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1);
118
124 AVChannelLayout *raw();
130 const AVChannelLayout *raw() const;
131
137 int channels() const noexcept;
144 uint64_t layout() const noexcept;
152 uint64_t subset(uint64_t mask) const noexcept;
158 bool isValid() const noexcept;
164 std::string describe() const;
170 void describe(std::string &desc) const;
171
179 int index(AVChannel channel) const;
187 int index(const char *name) const;
188
197 AVChannel channel(unsigned int index) const;
206 AVChannel channel(const char *name) const;
207
215 bool operator==(const ChannelLayoutView &other) const noexcept;
216
223
224protected:
226 AVChannelLayout m_layout{};
227};
228
229
230
240{
241public:
245 ChannelLayout() = default;
246 //explicit ChannelLayout(ChannelLayoutView &&view);
252 explicit ChannelLayout(const ChannelLayoutView &view);
253
255
270
285
290
291 //+ void av_channel_layout_uninit(AVChannelLayout *channel_layout);
292 //
293 //+ int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask);
294 //+ int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str);
295 //+ void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels);
296 //+ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src);
297
298 //explicit ChannelLayout(uint64_t mask);
304 explicit ChannelLayout(std::bitset<64> mask);
311 explicit ChannelLayout(const char *str);
317 explicit ChannelLayout(int channels);
318
319 // Stop control AVChannelLayout
326 void release();
327
328private:
334 void swap(ChannelLayout &other);
335
336};
337
338} // namespace av
339
340#endif
FFmpeg version and API compatibility switches.
Common helpers: comparisons, value lookup, non-copyable base, string utilities.
uint64_t layout() const noexcept
The layout as a bit mask when it can be expressed as one.
ChannelLayout clone() const
Deep copy of the layout.
std::string describe() const
Text description of the layout.
int index(AVChannel channel) const
Position of a speaker in the layout.
AVChannelLayout * raw()
The underlying FFmpeg layout, mutable.
const AVChannelLayout * raw() const
The underlying FFmpeg layout, read-only.
AVChannel channel(unsigned int index) const
Speaker at a position.
uint64_t subset(uint64_t mask) const noexcept
Intersection of the layout with a mask.
ChannelLayoutView() noexcept
Create an empty, invalid view.
bool isValid() const noexcept
Whether the view refers to a usable layout.
AVChannelLayout m_layout
The viewed layout; for the view it is a shallow copy of the descriptor.
Definition channellayout.h:226
int channels() const noexcept
Number of channels in the layout.
static void iterate(Callable callable)
Iterate the standard layouts FFmpeg knows about.
Definition channellayout.h:96
static void dumpLayouts()
Print every standard layout through the FFmpeg log system.
Owning channel layout.
Definition channellayout.h:240
void release()
Give up control of the owned description.
ChannelLayout(const ChannelLayoutView &view)
Copy a view into an owning layout.
ChannelLayout()=default
Create an empty layout that owns nothing.
ChannelLayoutView() noexcept
Create an empty, invalid view.
ChannelLayout(const char *str)
Build a layout from its textual form.
ChannelLayout & operator=(const ChannelLayout &other)
Deep copy assignment; the previous contents are released.
ChannelLayout(std::bitset< 64 > mask)
Build a layout from a bit mask.
~ChannelLayout()
Release the owned description.
ChannelLayout(ChannelLayout &&other)
Move a layout.
ChannelLayout(int channels)
Build the default layout for a channel count.
ChannelLayout(const ChannelLayout &other)
Deep copy of a layout.
ChannelLayout & operator=(ChannelLayout &&other)
Move assignment; the previous contents are released.
Root namespace of the library.
Definition audioresampler.h:19
AVChannel channel_from_string(const std::string &name)
Look a speaker position up by name.
std::string channel_name(AVChannel channel)
Name of a speaker position.
std::string channel_description(AVChannel channel)
Human-readable description of a speaker position.
STL namespace.