Skip to content

Commit

Permalink
avcodec: add a define to test for AVCodecContext.ch_layout availability
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Lhomme <[email protected]>
  • Loading branch information
fcartegnie and robUx4 committed Jun 29, 2024
1 parent bece856 commit 3abf937
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions modules/codec/avcodec/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <libavcodec/avcodec.h>
#include <libavutil/mem.h>

#define API_CHANNEL_LAYOUT_STRUCT (LIBAVCODEC_VERSION_CHECK(59, 24, 100)) // AVCodecContext.ch_layout

#include <libavutil/channel_layout.h>


Expand Down Expand Up @@ -138,7 +140,7 @@ static int OpenAudioCodec( decoder_t *p_dec )
}

ctx->sample_rate = p_dec->fmt_in->audio.i_rate;
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100) && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
av_channel_layout_default( &ctx->ch_layout, p_dec->fmt_in->audio.i_channels );
#else
ctx->channels = p_dec->fmt_in->audio.i_channels;
Expand Down Expand Up @@ -598,7 +600,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
p_dec->fmt_out.audio.i_rate = p_sys->p_context->sample_rate;

/* */
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT
if( p_sys->i_previous_channels == p_sys->p_context->ch_layout.nb_channels &&
p_sys->i_previous_layout == p_sys->p_context->ch_layout.u.mask )
return;
Expand All @@ -621,7 +623,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
uint32_t pi_order_src[AOUT_CHAN_MAX] = { 0 };

int i_channels_src = 0;
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT
uint64_t channel_layout_mask = p_sys->p_context->ch_layout.u.mask;
int channel_count = p_sys->p_context->ch_layout.nb_channels;
#else
Expand Down
12 changes: 7 additions & 5 deletions modules/codec/avcodec/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "avcodec.h"
#include "avcommon.h"

#define API_CHANNEL_LAYOUT_STRUCT (LIBAVCODEC_VERSION_CHECK(59, 24, 100)) // AVCodecContext.ch_layout

#define HURRY_UP_GUARD1 VLC_TICK_FROM_MS(450)
#define HURRY_UP_GUARD2 VLC_TICK_FROM_MS(300)
#define HURRY_UP_GUARD3 VLC_TICK_FROM_MS(100)
Expand Down Expand Up @@ -172,7 +174,7 @@ static const uint64_t pi_channels_map[][2] =
{ AV_CH_STEREO_RIGHT, 0 },
};

#if !LIBAVCODEC_VERSION_CHECK(59, 24, 100)
#if !API_CHANNEL_LAYOUT_STRUCT
static const uint32_t channel_mask[][2] = {
{0,0},
{AOUT_CHAN_CENTER, AV_CH_LAYOUT_MONO},
Expand Down Expand Up @@ -778,7 +780,7 @@ int InitVideoEnc( vlc_object_t *p_this )
int i_channels_src = 0;

msg_Dbg( p_enc, "Creating channel order for reordering");
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100) && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
av_channel_layout_default( &p_context->ch_layout, p_enc->fmt_out.audio.i_channels );
uint64_t channel_mask = p_context->ch_layout.u.mask;
#else
Expand Down Expand Up @@ -933,7 +935,7 @@ int InitVideoEnc( vlc_object_t *p_this )

if( p_enc->fmt_out.audio.i_channels > 2 )
{
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100) && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
av_channel_layout_default( &p_context->ch_layout, 2 );
#else
p_context->channels = 2;
Expand Down Expand Up @@ -1298,7 +1300,7 @@ static block_t *handle_delay_buffer( encoder_t *p_enc, encoder_sys_t *p_sys, uns
av_frame_unref( p_sys->frame );
p_sys->frame->format = p_sys->p_context->sample_fmt;
p_sys->frame->nb_samples = leftover_samples + p_sys->i_samples_delay;
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100) && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
#else
p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
Expand Down Expand Up @@ -1432,7 +1434,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
else
p_sys->frame->nb_samples = p_sys->i_frame_size;
p_sys->frame->format = p_sys->p_context->sample_fmt;
#if LIBAVCODEC_VERSION_CHECK(59, 24, 100) && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
#if API_CHANNEL_LAYOUT_STRUCT && LIBAVUTIL_VERSION_CHECK(57, 24, 100)
av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
#else
p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
Expand Down

0 comments on commit 3abf937

Please sign in to comment.