Restore support for FFMPEG legacy channel_layout & channels fields, remove self-assignment in idSoundDecoder_Vorbis::Open()

(cherry picked from commit 22f9e5cc0e42a8d101f628df461ee7649acb3e01)
This commit is contained in:
Stephen Saunders 2022-12-22 21:24:50 -05:00
parent 21b021c3c0
commit 1340adb820
4 changed files with 37 additions and 6 deletions

View file

@ -738,11 +738,15 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping, n
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
#if LIBSWRESAMPLE_VERSION_INT >= AV_VERSION_INT(4,7,100)
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 );
}
#else
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 );
#endif
ret2 = swr_init( swr_ctx );
hasplanar = true;
}
@ -751,12 +755,19 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping, n
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->ch_layout.nb_channels, GetSampleFormat( dec_ctx2->sample_fmt ), hasplanar );
#if defined(_MSC_VER) && !defined(USE_OPENAL)
common->Printf( "Cinematic audio stream found: Sample Rate=%d Hz, Channels=%d, Format=%s, Planar=%d\n", dec_ctx2->sample_rate,
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,37,100)
dec_ctx2->ch_layout.nb_channels,
#else
dec_ctx2->channels,
#endif
GetSampleFormat( dec_ctx2->sample_fmt ), hasplanar );
#if defined(_MSC_VER) && !defined(USE_OPENAL)
cinematicAudio = new( TAG_AUDIO ) CinematicAudio_XAudio2;
#else
#else
cinematicAudio = new( TAG_AUDIO ) CinematicAudio_OpenAL;
#endif
#endif
cinematicAudio->InitAudio( dec_ctx2 );
}
//GK:End
@ -1484,7 +1495,11 @@ cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime, nvrhi::ICommandLis
else if( framePos + 1 == desiredFrame )
{
// SRS - Since destination sample format is packed (non-planar), returned bufflinesize equals num_bytes
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,37,100)
res = av_samples_alloc( &audioBuffer, &num_bytes, frame3->ch_layout.nb_channels, frame3->nb_samples, dst_smp, 0 );
#else
res = av_samples_alloc( &audioBuffer, &num_bytes, frame3->channels, frame3->nb_samples, dst_smp, 0 );
#endif
if( res < 0 || res != num_bytes )
{
common->Warning( "idCinematic: Failed to allocate audio buffer with result: %d\n", res );

View file

@ -66,19 +66,31 @@ void CinematicAudio_OpenAL::InitAudio( void* audioContext )
case AV_SAMPLE_FMT_U8:
case AV_SAMPLE_FMT_U8P:
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,37,100)
av_sample_cin = dec_ctx2->ch_layout.nb_channels == 2 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8;
#else
av_sample_cin = dec_ctx2->channels == 2 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8;
#endif
break;
}
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,37,100)
av_sample_cin = dec_ctx2->ch_layout.nb_channels == 2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
#else
av_sample_cin = dec_ctx2->channels == 2 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
#endif
break;
}
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
{
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,37,100)
av_sample_cin = dec_ctx2->ch_layout.nb_channels == 2 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
#else
av_sample_cin = dec_ctx2->channels == 2 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
#endif
break;
}
default:

View file

@ -108,7 +108,11 @@ void CinematicAudio_XAudio2::InitAudio( void* audioContext )
return;
}
}
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59,37,100)
voiceFormatcine.nChannels = dec_ctx2->ch_layout.nb_channels; //fixed
#else
voiceFormatcine.nChannels = dec_ctx2->channels; //fixed
#endif
voiceFormatcine.nSamplesPerSec = dec_ctx2->sample_rate; //fixed
#elif defined(USE_BINKDEC)
AudioInfo* binkInfo = ( AudioInfo* )audioContext;

View file

@ -330,7 +330,7 @@ bool idSoundDecoder_Vorbis::Open( const char* fileName )
return false;
}
this->sample = sample;
//this->sample = sample; // SRS - self assignment not needed here
return true;
}
}