Cinematic Video and Audio memory management fixes

(cherry picked from commit 40a9190283d30180a3b7e4ab9b77f3c3728dad4f)
This commit is contained in:
Stephen Saunders 2022-02-18 12:57:29 -05:00
parent 1f2df87be7
commit 922f9eddef
3 changed files with 9 additions and 7 deletions

View file

@ -790,7 +790,9 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping )
frameRate = av_q2d( fmt_ctx->streams[video_stream_index]->avg_frame_rate );
common->Printf( "Loaded FFMPEG file: '%s', looping=%d, %dx%d, %f FPS, %f sec\n", qpath, looping, CIN_WIDTH, CIN_HEIGHT, frameRate, durationSec );
image = ( byte* )Mem_Alloc( CIN_WIDTH * CIN_HEIGHT * 4 * 2, TAG_CINEMATIC );
// SRS - Get number of image bytes needed by querying with NULL first, then allocate image and fill with correct parameters
int img_bytes = av_image_fill_arrays( frame2->data, frame2->linesize, NULL, AV_PIX_FMT_BGR32, CIN_WIDTH, CIN_HEIGHT, 1 );
image = ( byte* )Mem_Alloc( img_bytes, TAG_CINEMATIC );
av_image_fill_arrays( frame2->data, frame2->linesize, image, AV_PIX_FMT_BGR32, CIN_WIDTH, CIN_HEIGHT, 1 ); //GK: Straight out of the FFMPEG source code
if( img_convert_ctx )
{
@ -1586,7 +1588,7 @@ cinData_t idCinematicLocal::ImageForTimeBinkDec( int thisTime )
if( audioTracks > 0 )
{
audioBuffer = ( int16_t* )malloc( binkInfo.idealBufferSize );
audioBuffer = ( int16_t* )Mem_Alloc( binkInfo.idealBufferSize, TAG_AUDIO );
num_bytes = Bink_GetAudioData( binkHandle, trackIndex, audioBuffer );
// SRS - If we have cinematic audio data, start playing it now
@ -1598,7 +1600,7 @@ cinData_t idCinematicLocal::ImageForTimeBinkDec( int thisTime )
else
{
// SRS - Even though we have no audio data to play, still need to free the audio buffer
free( audioBuffer );
Mem_Free( audioBuffer );
}
}

View file

@ -129,7 +129,7 @@ void CinematicAudio_OpenAL::PlayAudio( uint8_t* data, int size )
#if defined(USE_FFMPEG)
av_freep( &tempdata );
#elif defined(USE_BINKDEC)
free( tempdata );
Mem_Free( tempdata );
#endif
alSourceQueueBuffers( alMusicSourceVoicecin, 1, &bufid );
ALenum error = alGetError();
@ -149,7 +149,7 @@ void CinematicAudio_OpenAL::PlayAudio( uint8_t* data, int size )
#if defined(USE_FFMPEG)
av_freep( &data );
#elif defined(USE_BINKDEC)
free( data );
Mem_Free( data );
#endif
offset++;
if( offset == NUM_BUFFERS )
@ -221,7 +221,7 @@ void CinematicAudio_OpenAL::ShutdownAudio()
#if defined(USE_FFMPEG)
av_freep( &tempdata );
#elif defined(USE_BINKDEC)
free( tempdata );
Mem_Free( tempdata );
#endif
buffersize--;
}

View file

@ -52,7 +52,7 @@ public:
#if defined(USE_FFMPEG)
av_freep( &data );
#elif defined(USE_BINKDEC)
free( data );
Mem_Free( data );
#endif
}
//Unused methods are stubs