--- vlc-3.0.20/modules/codec/avcodec/audio.c.orig 2024-04-11 22:04:48.840481336 +0100 +++ vlc-3.0.20/modules/codec/avcodec/audio.c 2024-04-11 22:56:54.658799280 +0100 @@ -65,7 +65,7 @@ bool b_extract; int pi_extraction[AOUT_CHAN_MAX]; int i_previous_channels; - uint64_t i_previous_layout; + AVChannelLayout i_previous_layout; }; #define BLOCK_FLAG_PRIVATE_REALLOCATED (1 << BLOCK_FLAG_PRIVATE_SHIFT) @@ -139,7 +139,7 @@ } ctx->sample_rate = p_dec->fmt_in.audio.i_rate; - ctx->channels = p_dec->fmt_in.audio.i_channels; + ctx->ch_layout.nb_channels = p_dec->fmt_in.audio.i_channels; ctx->block_align = p_dec->fmt_in.audio.i_blockalign; ctx->bit_rate = p_dec->fmt_in.i_bitrate; ctx->bits_per_coded_sample = p_dec->fmt_in.audio.i_bitspersample; @@ -245,7 +245,7 @@ p_sys->i_reject_count = 0; p_sys->b_extract = false; p_sys->i_previous_channels = 0; - p_sys->i_previous_layout = 0; + p_sys->i_previous_layout = (AVChannelLayout){0}; /* */ /* Try to set as much information as possible but do not trust it */ @@ -396,11 +396,11 @@ if( ret == 0 ) { /* checks and init from first decoded frame */ - if( ctx->channels <= 0 || ctx->channels > INPUT_CHAN_MAX + if( ctx->ch_layout.nb_channels <= 0 || ctx->ch_layout.nb_channels > INPUT_CHAN_MAX || ctx->sample_rate <= 0 ) { msg_Warn( p_dec, "invalid audio properties channels count %d, sample rate %d", - ctx->channels, ctx->sample_rate ); + ctx->ch_layout.nb_channels, ctx->sample_rate ); goto drop; } else if( p_dec->fmt_out.audio.i_rate != (unsigned int)ctx->sample_rate ) @@ -484,15 +484,15 @@ /* Interleave audio if required */ if( av_sample_fmt_is_planar( ctx->sample_fmt ) ) { - p_block = block_Alloc(frame->linesize[0] * ctx->channels); + p_block = block_Alloc(frame->linesize[0] * ctx->ch_layout.nb_channels); if ( likely(p_block) ) { - const void *planes[ctx->channels]; - for (int i = 0; i < ctx->channels; i++) + const void *planes[ctx->ch_layout.nb_channels]; + for (int i = 0; i < ctx->ch_layout.nb_channels; i++) planes[i] = frame->extended_data[i]; aout_Interleave(p_block->p_buffer, planes, frame->nb_samples, - ctx->channels, p_dec->fmt_out.audio.i_format); + ctx->ch_layout.nb_channels, p_dec->fmt_out.audio.i_format); p_block->i_nb_samples = frame->nb_samples; } av_frame_free(&frame); @@ -511,7 +511,7 @@ { aout_ChannelExtract( p_buffer->p_buffer, p_dec->fmt_out.audio.i_channels, - p_block->p_buffer, ctx->channels, + p_block->p_buffer, ctx->ch_layout.nb_channels, p_block->i_nb_samples, p_sys->pi_extraction, p_dec->fmt_out.audio.i_bitspersample ); p_buffer->i_nb_samples = p_block->i_nb_samples; @@ -580,33 +580,36 @@ p_dec->fmt_out.audio.i_rate = p_sys->p_context->sample_rate; /* */ - if( p_sys->i_previous_channels == p_sys->p_context->channels && - p_sys->i_previous_layout == p_sys->p_context->channel_layout ) + if( p_sys->i_previous_channels == p_sys->p_context->ch_layout.nb_channels && + av_channel_layout_compare(&p_sys->i_previous_layout,&p_sys->p_context->ch_layout) == 0 ) return; if( b_trust ) { - p_sys->i_previous_channels = p_sys->p_context->channels; - p_sys->i_previous_layout = p_sys->p_context->channel_layout; + p_sys->i_previous_channels = p_sys->p_context->ch_layout.nb_channels; + av_channel_layout_copy(&p_sys->i_previous_layout, &p_sys->p_context->ch_layout); } const unsigned i_order_max = sizeof(pi_channels_map)/sizeof(*pi_channels_map); uint32_t pi_order_src[i_order_max]; int i_channels_src = 0; - int64_t channel_layout = - p_sys->p_context->channel_layout ? p_sys->p_context->channel_layout : - av_get_default_channel_layout( p_sys->p_context->channels ); + AVChannelLayout channel_layout; + if(p_sys->p_context->ch_layout.u.mask) { + av_channel_layout_copy(&channel_layout, &p_sys->p_context->ch_layout); + } else { + av_channel_layout_default(&channel_layout, p_sys->p_context->ch_layout.nb_channels ); + } - if( channel_layout ) + if(av_channel_layout_check(&channel_layout)) { for( unsigned i = 0; i < i_order_max - && i_channels_src < p_sys->p_context->channels; i++ ) + && i_channels_src < p_sys->p_context->ch_layout.nb_channels; i++ ) { - if( channel_layout & pi_channels_map[i][0] ) + if( channel_layout.u.mask & pi_channels_map[i][0] ) pi_order_src[i_channels_src++] = pi_channels_map[i][1]; } - if( i_channels_src != p_sys->p_context->channels && b_trust ) + if( i_channels_src != p_sys->p_context->ch_layout.nb_channels && b_trust ) msg_Err( p_dec, "Channel layout not understood" ); /* Detect special dual mono case */ @@ -638,7 +641,7 @@ { msg_Warn( p_dec, "no channel layout found"); p_dec->fmt_out.audio.i_physical_channels = 0; - p_dec->fmt_out.audio.i_channels = p_sys->p_context->channels; + p_dec->fmt_out.audio.i_channels = p_sys->p_context->ch_layout.nb_channels; } aout_FormatPrepare( &p_dec->fmt_out.audio ); --- vlc-3.0.20/modules/codec/avcodec/fourcc.c.orig 2024-04-11 23:18:24.472481862 +0100 +++ vlc-3.0.20/modules/codec/avcodec/fourcc.c 2024-04-11 23:17:13.105163354 +0100 @@ -182,7 +182,7 @@ /* AV_CODEC_ID_V210X */ { VLC_CODEC_TMV, AV_CODEC_ID_TMV }, { VLC_CODEC_V210, AV_CODEC_ID_V210 }, -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 50, 100 ) && LIBAVCODEC_VERSION_MICRO >= 100 +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 50, 100 ) && LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_MAJOR < 61 { VLC_CODEC_VUYA, AV_CODEC_ID_AYUV }, #endif /* AV_CODEC_ID_DPX */ --- vlc-3.0.20/modules/codec/avcodec/encoder.c.orig 2024-04-11 23:16:32.476696552 +0100 +++ vlc-3.0.20/modules/codec/avcodec/encoder.c 2024-04-12 00:05:54.128425226 +0100 @@ -739,9 +739,10 @@ date_Set( &p_sys->buffer_date, AV_NOPTS_VALUE ); p_context->time_base.num = 1; p_context->time_base.den = p_context->sample_rate; - p_context->channels = p_enc->fmt_out.audio.i_channels; + p_context->ch_layout.order = AV_CHANNEL_ORDER_NATIVE; + p_context->ch_layout.nb_channels = p_enc->fmt_out.audio.i_channels; #if LIBAVUTIL_VERSION_CHECK( 52, 2, 6, 0, 0) - p_context->channel_layout = channel_mask[p_context->channels][1]; + p_context->ch_layout.u.mask = channel_mask[p_context->ch_layout.nb_channels][1]; /* Setup Channel ordering for multichannel audio * as VLC channel order isn't same as libavcodec expects @@ -752,17 +753,17 @@ /* Specified order * Copied from audio.c */ - const unsigned i_order_max = 8 * sizeof(p_context->channel_layout); + const unsigned i_order_max = 8 * sizeof(p_context->ch_layout.u.mask); uint32_t pi_order_dst[AOUT_CHAN_MAX] = { }; uint32_t order_mask = 0; int i_channels_src = 0; - if( p_context->channel_layout ) + if( p_context->ch_layout.u.mask ) { msg_Dbg( p_enc, "Creating channel order for reordering"); for( unsigned i = 0; i < sizeof(pi_channels_map)/sizeof(*pi_channels_map); i++ ) { - if( p_context->channel_layout & pi_channels_map[i][0] ) + if( p_context->ch_layout.u.mask & pi_channels_map[i][0] ) { msg_Dbg( p_enc, "%d %"PRIx64" mapped to %"PRIx64"", i_channels_src, pi_channels_map[i][0], pi_channels_map[i][1]); pi_order_dst[i_channels_src++] = pi_channels_map[i][1]; @@ -774,7 +775,7 @@ { msg_Dbg( p_enc, "Creating default channel order for reordering"); /* Create default order */ - for( unsigned int i = 0; i < __MIN( i_order_max, (unsigned)p_sys->p_context->channels ); i++ ) + for( unsigned int i = 0; i < __MIN( i_order_max, (unsigned)p_sys->p_context->ch_layout.nb_channels ); i++ ) { if( i < sizeof(pi_channels_map)/sizeof(*pi_channels_map) ) { @@ -784,7 +785,7 @@ } } } - if( i_channels_src != p_context->channels ) + if( i_channels_src != p_context->ch_layout.nb_channels ) msg_Err( p_enc, "Channel layout not understood" ); p_sys->i_channels_to_reorder = @@ -891,7 +892,7 @@ if( ret ) { if( p_enc->fmt_in.i_cat != AUDIO_ES || - (p_context->channels <= 2 && i_codec_id != AV_CODEC_ID_MP2 + (p_context->ch_layout.nb_channels <= 2 && i_codec_id != AV_CODEC_ID_MP2 && i_codec_id != AV_CODEC_ID_MP3) ) errmsg: { @@ -916,10 +917,10 @@ goto error; } - if( p_context->channels > 2 ) + if( p_context->ch_layout.nb_channels > 2 ) { - p_context->channels = 2; - p_context->channel_layout = channel_mask[p_context->channels][1]; + p_context->ch_layout.nb_channels = 2; + p_context->ch_layout.u.mask = channel_mask[p_context->ch_layout.nb_channels][1]; /* Change fmt_in in order to ask for a channels conversion */ p_enc->fmt_in.audio.i_channels = @@ -1022,7 +1023,7 @@ p_context->frame_size : AV_INPUT_BUFFER_MIN_SIZE; p_sys->i_buffer_out = av_samples_get_buffer_size(NULL, - p_sys->p_context->channels, p_sys->i_frame_size, + p_sys->p_context->ch_layout.nb_channels, p_sys->i_frame_size, p_sys->p_context->sample_fmt, DEFAULT_ALIGN); p_sys->p_buffer = av_malloc( p_sys->i_buffer_out ); if ( unlikely( p_sys->p_buffer == NULL ) ) @@ -1272,13 +1273,12 @@ { block_t *p_block = NULL; //How much we need to copy from new packet - const size_t leftover = leftover_samples * p_sys->p_context->channels * p_sys->i_sample_bytes; + const size_t leftover = leftover_samples * p_sys->p_context->ch_layout.nb_channels * p_sys->i_sample_bytes; 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; - p_sys->frame->channel_layout = p_sys->p_context->channel_layout; - p_sys->frame->channels = p_sys->p_context->channels; + av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout); p_sys->frame->pts = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den / CLOCK_FREQ / p_sys->p_context->time_base.num; @@ -1295,7 +1295,7 @@ // We need to deinterleave from p_aout_buf to p_buffer the leftover bytes if( p_sys->b_planar ) aout_Deinterleave( p_sys->p_interleave_buf, p_sys->p_buffer, - p_sys->i_frame_size, p_sys->p_context->channels, p_enc->fmt_in.i_codec ); + p_sys->i_frame_size, p_sys->p_context->ch_layout.nb_channels, p_enc->fmt_in.i_codec ); else memcpy( p_sys->p_buffer + buffer_delay, p_aout_buf->p_buffer, leftover); @@ -1313,7 +1313,7 @@ memset( p_sys->p_buffer + (leftover+buffer_delay), 0, padding_size ); buffer_delay += padding_size; } - if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->channels, + if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->ch_layout.nb_channels, p_sys->p_context->sample_fmt, p_sys->b_planar ? p_sys->p_interleave_buf : p_sys->p_buffer, p_sys->i_buffer_out, DEFAULT_ALIGN) < 0 ) @@ -1343,7 +1343,7 @@ //i_bytes_left is amount of bytes we get i_samples_left = p_aout_buf ? p_aout_buf->i_nb_samples : 0; - buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_sys->p_context->channels; + buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_sys->p_context->ch_layout.nb_channels; //p_sys->i_buffer_out = p_sys->i_frame_size * chan * p_sys->i_sample_bytes //Calculate how many bytes we would need from current buffer to fill frame @@ -1408,16 +1408,15 @@ p_sys->frame->pts = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den / CLOCK_FREQ / p_sys->p_context->time_base.num; - p_sys->frame->channel_layout = p_sys->p_context->channel_layout; - p_sys->frame->channels = p_sys->p_context->channels; + av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout); const int in_bytes = p_sys->frame->nb_samples * - p_sys->p_context->channels * p_sys->i_sample_bytes; + p_sys->p_context->ch_layout.nb_channels * p_sys->i_sample_bytes; if( p_sys->b_planar ) { aout_Deinterleave( p_sys->p_buffer, p_aout_buf->p_buffer, - p_sys->frame->nb_samples, p_sys->p_context->channels, p_enc->fmt_in.i_codec ); + p_sys->frame->nb_samples, p_sys->p_context->ch_layout.nb_channels, p_enc->fmt_in.i_codec ); } else @@ -1425,7 +1424,7 @@ memcpy(p_sys->p_buffer, p_aout_buf->p_buffer, in_bytes); } - if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->channels, + if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->ch_layout.nb_channels, p_sys->p_context->sample_fmt, p_sys->p_buffer, p_sys->i_buffer_out, @@ -1451,7 +1450,7 @@ if( p_aout_buf->i_nb_samples > 0 ) { memcpy( p_sys->p_buffer + buffer_delay, p_aout_buf->p_buffer, - p_aout_buf->i_nb_samples * p_sys->i_sample_bytes * p_sys->p_context->channels); + p_aout_buf->i_nb_samples * p_sys->i_sample_bytes * p_sys->p_context->ch_layout.nb_channels); p_sys->i_samples_delay += p_aout_buf->i_nb_samples; } --- vlc-3.0.20/modules/demux/avformat/mux.c.orig 2024-04-12 09:43:14.176674968 +0100 +++ vlc-3.0.20/modules/demux/avformat/mux.c 2024-04-12 09:46:15.032487553 +0100 @@ -74,10 +74,10 @@ static void DelStream( sout_mux_t *, sout_input_t * ); static int Mux ( sout_mux_t * ); -static int IOWrite( void *opaque, uint8_t *buf, int buf_size ); +static int IOWrite( void *opaque, const uint8_t *buf, int buf_size ); static int64_t IOSeek( void *opaque, int64_t offset, int whence ); #if LIBAVFORMAT_VERSION_CHECK( 57, 7, 0, 40, 100 ) -static int IOWriteTyped(void *opaque, uint8_t *buf, int buf_size, +static int IOWriteTyped(void *opaque, const uint8_t *buf, int buf_size, enum AVIODataMarkerType type, int64_t time); #endif @@ -267,7 +267,7 @@ { case AUDIO_ES: codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - codecpar->channels = fmt->audio.i_channels; + codecpar->ch_layout.nb_channels = fmt->audio.i_channels; codecpar->sample_rate = fmt->audio.i_rate; stream->time_base = (AVRational){1, codecpar->sample_rate}; if (fmt->i_bitrate == 0) { @@ -407,7 +407,7 @@ } #if LIBAVFORMAT_VERSION_CHECK( 57, 7, 0, 40, 100 ) -int IOWriteTyped(void *opaque, uint8_t *buf, int buf_size, +int IOWriteTyped(void *opaque, const uint8_t *buf, int buf_size, enum AVIODataMarkerType type, int64_t time) { VLC_UNUSED(time); @@ -508,7 +508,7 @@ /***************************************************************************** * I/O wrappers for libavformat *****************************************************************************/ -static int IOWrite( void *opaque, uint8_t *buf, int buf_size ) +static int IOWrite( void *opaque, const uint8_t *buf, int buf_size ) { sout_mux_t *p_mux = opaque; sout_mux_sys_t *p_sys = p_mux->p_sys; --- vlc-3.0.20/modules/demux/avformat/demux.c.orig 2024-04-12 09:43:02.724067453 +0100 +++ vlc-3.0.20/modules/demux/avformat/demux.c 2024-04-12 09:46:46.224422142 +0100 @@ -401,7 +401,7 @@ es_format_Init( &es_fmt, AUDIO_ES, fcc ); es_fmt.i_original_fourcc = CodecTagToFourcc( cp->codec_tag ); es_fmt.i_bitrate = cp->bit_rate; - es_fmt.audio.i_channels = cp->channels; + es_fmt.audio.i_channels = cp->ch_layout.nb_channels; es_fmt.audio.i_rate = cp->sample_rate; es_fmt.audio.i_bitspersample = cp->bits_per_coded_sample; es_fmt.audio.i_blockalign = cp->block_align;