Skip to content

Commit

Permalink
Isolate new AVChannel Support
Browse files Browse the repository at this point in the history
Build it conditionaly.
  • Loading branch information
h4tr3d committed Aug 1, 2023
1 parent 03e3fb9 commit 6f33252
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/channellayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "channellayout.h"

#if API_NEW_CHANNEL_LAYOUT
namespace av {

static constexpr size_t BufferSize = 128;
Expand Down Expand Up @@ -214,5 +215,6 @@ void ChannelLayout::swap(ChannelLayout &other)
std::swap(m_layout, other.m_layout);
}


} // namespace av

#endif
5 changes: 4 additions & 1 deletion src/channellayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <string_view>
#include <bitset>

#include "avutils.h"

#if API_NEW_CHANNEL_LAYOUT
extern "C" {
#include <libavutil/channel_layout.h>
}
Expand Down Expand Up @@ -110,6 +113,6 @@ class ChannelLayout : public ChannelLayoutView

};


} // namespace av

#endif
2 changes: 2 additions & 0 deletions src/codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ std::deque<uint64_t> Codec::supportedChannelLayouts() const
return channelLayouts;
}

#if API_NEW_CHANNEL_LAYOUT
std::deque<ChannelLayoutView> Codec::supportedChannelLayouts2() const
{
deque<ChannelLayoutView> channelLayouts;
Expand All @@ -146,6 +147,7 @@ std::deque<ChannelLayoutView> Codec::supportedChannelLayouts2() const

return channelLayouts;
}
#endif

AVCodecID Codec::id() const
{
Expand Down
4 changes: 4 additions & 0 deletions src/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pixelformat.h"
#include "sampleformat.h"
#include "channellayout.h"
#include "avutils.h"

namespace av {

Expand All @@ -31,7 +32,10 @@ class Codec : public FFWrapperPtr<const AVCodec>
std::deque<int> supportedSamplerates() const;
std::deque<SampleFormat> supportedSampleFormats() const;
std::deque<uint64_t> supportedChannelLayouts() const;

#if API_NEW_CHANNEL_LAYOUT
std::deque<ChannelLayoutView> supportedChannelLayouts2() const;
#endif

AVCodecID id() const;
};
Expand Down
4 changes: 4 additions & 0 deletions src/codeccontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,14 @@ class AudioCodecContext : public CodecContextBase<Clazz, _direction, AVMEDIA_TYP
return codec_context::audio::get_channel_layout_mask(m_raw);
}

#if API_NEW_CHANNEL_LAYOUT
ChannelLayoutView channelLayout2() const noexcept
{
if (!isValid())
return ChannelLayoutView{};
return ChannelLayoutView{m_raw.ch_layout};
}
#endif

void setSampleRate(int sampleRate) noexcept
{
Expand Down Expand Up @@ -552,13 +554,15 @@ class AudioCodecContext : public CodecContextBase<Clazz, _direction, AVMEDIA_TYP
codec_context::audio::set_channel_layout_mask(m_raw, layout);
}

#if API_NEW_CHANNEL_LAYOUT
void setChannelLayout(ChannelLayout layout) noexcept
{
if (!isValid() || !layout.isValid())
return;
m_raw.ch_layout = *layout.raw();
layout.release(); // is controlled by the CodecContext
}
#endif

protected:
using Parent::moveOperator;
Expand Down

0 comments on commit 6f33252

Please sign in to comment.