Dear Maintainer,

Please find in attachment a patch that you can drop in the
debian/patches/ directory to fix the build with ffmpeg 7

Best regards,
Sébastien
Description: fix build with ffmpeg 7
Forwarded: Committed upstream
cherry picked from:
 - 78c5fd3a8c13fdb720875fd3051097e4acd018b6
 - 21b021c3c01d9951f7996bd551de2869c3368c77
--- a/neo/renderer/Cinematic.cpp
+++ b/neo/renderer/Cinematic.cpp
@@ -619,6 +619,7 @@ bool idCinematicLocal::InitFromFFMPEGFil
 	int ret;
 	int ret2;
 	int file_size;
+	char error[64];
 	looping = amilooping;
 	startTime = 0;
 	isRoQ = false;
@@ -688,8 +689,7 @@ bool idCinematicLocal::InitFromFFMPEGFil
 	dec_ctx = avcodec_alloc_context3( dec );
 	if( ( ret = avcodec_parameters_to_context( dec_ctx, fmt_ctx->streams[video_stream_index]->codecpar ) ) < 0 )
 	{
-		char* error = new char[256];
-		av_strerror( ret, error, 256 );
+		av_strerror( ret, error, sizeof( error ) );
 		common->Warning( "idCinematic: Failed to create video codec context from codec parameters with error: %s\n", error );
 	}
 	dec_ctx->time_base = fmt_ctx->streams[video_stream_index]->time_base;
@@ -698,8 +698,7 @@ bool idCinematicLocal::InitFromFFMPEGFil
 	/* init the video decoder */
 	if( ( ret = avcodec_open2( dec_ctx, dec, NULL ) ) < 0 )
 	{
-		char* error = new char[256];
-		av_strerror( ret, error, 256 );
+		av_strerror( ret, error, sizeof( error ) );
 		common->Warning( "idCinematic: Cannot open video decoder for: '%s', %d, with error: %s\n", qpath, looping, error );
 		return false;
 	}
@@ -712,8 +711,7 @@ bool idCinematicLocal::InitFromFFMPEGFil
 		dec_ctx2 = avcodec_alloc_context3( dec2 );
 		if( ( ret2 = avcodec_parameters_to_context( dec_ctx2, fmt_ctx->streams[audio_stream_index]->codecpar ) ) < 0 )
 		{
-			char* error = new char[256];
-			av_strerror( ret2, error, 256 );
+			av_strerror( ret2, error, sizeof( error ) );
 			common->Warning( "idCinematic: Failed to create audio codec context from codec parameters with error: %s\n", error );
 		}
 		dec_ctx2->time_base = fmt_ctx->streams[audio_stream_index]->time_base;
@@ -727,8 +725,12 @@ bool idCinematicLocal::InitFromFFMPEGFil
 		if( dec_ctx2->sample_fmt >= AV_SAMPLE_FMT_U8P )											// SRS - Planar formats start at AV_SAMPLE_FMT_U8P
 		{
 			dst_smp = static_cast<AVSampleFormat>( dec_ctx2->sample_fmt - AV_SAMPLE_FMT_U8P );	// SRS - Setup context to convert from planar to packed
-			swr_ctx = swr_alloc_set_opts( NULL, dec_ctx2->channel_layout, dst_smp, dec_ctx2->sample_rate, dec_ctx2->channel_layout, dec_ctx2->sample_fmt, dec_ctx2->sample_rate, 0, NULL );
-			int res = swr_init( swr_ctx );
+			if( ( ret2 = swr_alloc_set_opts2( &swr_ctx, &dec_ctx2->ch_layout, dst_smp, dec_ctx2->sample_rate, &dec_ctx2->ch_layout, dec_ctx2->sample_fmt, dec_ctx2->sample_rate, 0, NULL ) ) < 0 )
+			{
+				av_strerror( ret2, error, sizeof( error ) );
+				common->Warning( "idCinematic: Failed to create audio resample context with error: %s\n", error );
+			}
+			ret2 = swr_init( swr_ctx );
 			hasplanar = true;
 		}
 		else
@@ -736,7 +738,7 @@ bool idCinematicLocal::InitFromFFMPEGFil
 			dst_smp = dec_ctx2->sample_fmt;														// SRS - Must always define the destination format
 			hasplanar = false;
 		}
-		common->Printf( "Cinematic audio stream found: Sample Rate=%d Hz, Channels=%d, Format=%s, Planar=%d\n", dec_ctx2->sample_rate, dec_ctx2->channels, GetSampleFormat( dec_ctx2->sample_fmt ), hasplanar );
+		common->Printf( "Cinematic audio stream found: Sample Rate=%d Hz, Channels=%d, Format=%s, Planar=%d\n", dec_ctx2->sample_rate, dec_ctx2->ch_layout.nb_channels, GetSampleFormat( dec_ctx2->sample_fmt ), hasplanar );
 		cinematicAudio->InitAudio( dec_ctx2 );
 	}
 	else
@@ -1310,6 +1312,7 @@ idCinematicLocal::ImageForTimeFFMPEG
 cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
 {
 	cinData_t	cinData;
+	char		error[64];
 	uint8_t*	audioBuffer = NULL;
 	int			num_bytes = 0;
 
@@ -1404,16 +1407,14 @@ cinData_t idCinematicLocal::ImageForTime
 				// Decode video frame
 				if( ( res = avcodec_send_packet( dec_ctx, &packet ) ) != 0 )
 				{
-					char* error = new char[256];
-					av_strerror( res, error, 256 );
+					av_strerror( res, error, sizeof( error ) );
 					common->Warning( "idCinematic: Failed to send video packet for decoding with error: %s\n", error );
 				}
 				else
 				{
 					if( ( frameFinished = avcodec_receive_frame( dec_ctx, frame ) ) != 0 )
 					{
-						char* error = new char[256];
-						av_strerror( frameFinished, error, 256 );
+						av_strerror( frameFinished, error, sizeof( error ) );
 						common->Warning( "idCinematic: Failed to receive video frame from decoding with error: %s\n", error );
 					}
 				}
@@ -1424,22 +1425,20 @@ cinData_t idCinematicLocal::ImageForTime
 				res = avcodec_send_packet( dec_ctx2, &packet );
 				if( res != 0 && res != AVERROR( EAGAIN ) )
 				{
-					char* error = new char[256];
-					av_strerror( res, error, 256 );
+					av_strerror( res, error, sizeof( error ) );
 					common->Warning( "idCinematic: Failed to send audio packet for decoding with error: %s\n", error );
 				}
 				else
 				{
 					if( ( frameFinished1 = avcodec_receive_frame( dec_ctx2, frame3 ) ) != 0 )
 					{
-						char* error = new char[256];
-						av_strerror( frameFinished1, error, 256 );
+						av_strerror( frameFinished1, error, sizeof( error ) );
 						common->Warning( "idCinematic: Failed to receive audio frame from decoding with error: %s\n", error );
 					}
 					else
 					{
 						// SRS - Since destination sample format is packed (non-planar), returned bufflinesize equals num_bytes
-						res = av_samples_alloc( &audioBuffer, &num_bytes, frame3->channels, frame3->nb_samples, dst_smp, 0 );
+						res = av_samples_alloc( &audioBuffer, &num_bytes, frame3->ch_layout.nb_channels, frame3->nb_samples, dst_smp, 0 );
 						if( res < 0 || res != num_bytes )
 						{
 							common->Warning( "idCinematic: Failed to allocate audio buffer with result: %d\n", res );
--- a/neo/sound/OpenAL/AL_CinematicAudio.cpp
+++ b/neo/sound/OpenAL/AL_CinematicAudio.cpp
@@ -66,19 +66,19 @@ void CinematicAudio_OpenAL::InitAudio( void* audioContext )
 		case AV_SAMPLE_FMT_U8:
 		case AV_SAMPLE_FMT_U8P:
 		{
-			av_sample_cin = dec_ctx2->channels == 2 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8;
+			av_sample_cin = dec_ctx2->ch_layout.nb_channels == 2 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8;
 			break;
 		}
 		case AV_SAMPLE_FMT_S16:
 		case AV_SAMPLE_FMT_S16P:
 		{
-			av_sample_cin = dec_ctx2->channels == 2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
+			av_sample_cin = dec_ctx2->ch_layout.nb_channels == 2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
 			break;
 		}
 		case AV_SAMPLE_FMT_FLT:
 		case AV_SAMPLE_FMT_FLTP:
 		{
-			av_sample_cin = dec_ctx2->channels == 2 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
+			av_sample_cin = dec_ctx2->ch_layout.nb_channels == 2 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
 			break;
 		}
 		default:
--- a/neo/sound/XAudio2/XA2_CinematicAudio.cpp
+++ b/neo/sound/XAudio2/XA2_CinematicAudio.cpp
@@ -107,7 +107,7 @@ void CinematicAudio_XAudio2::InitAudio( void* audioContext )
 			return;
 		}
 	}
-	voiceFormatcine.nChannels = dec_ctx2->channels; //fixed
+	voiceFormatcine.nChannels = dec_ctx2->ch_layout.nb_channels; //fixed
 	voiceFormatcine.nSamplesPerSec = dec_ctx2->sample_rate; //fixed
 #elif defined(USE_BINKDEC)
 	AudioInfo* binkInfo = ( AudioInfo* )audioContext;

Reply via email to