Properly delete cinematicAudio instances, eliminate use of new for ffmpeg error strings, vkCreateImageView FMT_DEPTH_STENCIL fix

This commit is contained in:
Stephen Saunders 2022-03-16 22:00:52 -04:00
parent 87271337c3
commit 78c5fd3a8c
3 changed files with 48 additions and 15 deletions

View file

@ -413,12 +413,27 @@ void idCinematic::Close()
}
// RB begin
/*
==============
idCinematic::IsPlaying
==============
*/
bool idCinematic::IsPlaying() const
{
return false;
}
// RB end
// SRS begin
/*
==============
CinematicAudio::~CinematicAudio
==============
*/
CinematicAudio::~CinematicAudio()
{
}
// SRS end
//===========================================
@ -565,6 +580,7 @@ idCinematicLocal::~idCinematicLocal()
//GK: Properly close local XAudio2 or OpenAL voice
cinematicAudio->ShutdownAudio();
delete cinematicAudio;
}
#if defined(USE_FFMPEG)
@ -619,6 +635,7 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping )
int ret;
int ret2;
int file_size;
char error[64];
looping = amilooping;
startTime = 0;
isRoQ = false;
@ -688,8 +705,7 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping )
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; // SRS - decoder timebase is set by avcodec_open2()
@ -698,8 +714,7 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping )
/* 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 +727,7 @@ bool idCinematicLocal::InitFromFFMPEGFile( const char* qpath, bool amilooping )
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; // SRS - decoder timebase is set by avcodec_open2()
@ -849,6 +863,11 @@ void idCinematicLocal::FFMPEGReset()
}
#endif
/*
==============
idCinematicLocal::InitFromBinkDecFile
==============
*/
#ifdef USE_BINKDEC
bool idCinematicLocal::InitFromBinkDecFile( const char* qpath, bool amilooping )
{
@ -925,6 +944,11 @@ bool idCinematicLocal::InitFromBinkDecFile( const char* qpath, bool amilooping )
return true;
}
/*
==============
idCinematicLocal::BinkDecReset
==============
*/
void idCinematicLocal::BinkDecReset()
{
framePos = -1;
@ -1175,6 +1199,11 @@ int idCinematicLocal::AnimationLength()
}
// RB begin
/*
==============
idCinematicLocal::IsPlaying
==============
*/
bool idCinematicLocal::IsPlaying() const
{
return ( status == FMV_PLAY );
@ -1349,6 +1378,7 @@ idCinematicLocal::ImageForTimeFFMPEG
cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
{
cinData_t cinData;
char error[64];
uint8_t* audioBuffer = NULL;
int num_bytes = 0;
@ -1440,8 +1470,7 @@ cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
// 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
@ -1449,8 +1478,7 @@ cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
frameFinished = avcodec_receive_frame( dec_ctx, frame );
if( frameFinished != 0 && frameFinished != AVERROR( EAGAIN ) )
{
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 );
}
}
@ -1461,8 +1489,7 @@ cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
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 );
}
//SRS - Separate frame finisher for audio since there can be multiple audio frames per video frame (e.g. at bik startup)
@ -1473,8 +1500,7 @@ cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
{
if( frameFinished1 != AVERROR( EAGAIN ) )
{
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 );
}
}
@ -1553,6 +1579,11 @@ cinData_t idCinematicLocal::ImageForTimeFFMPEG( int thisTime )
#endif
/*
==============
idCinematicLocal::ImageForTimeBinkDec
==============
*/
#ifdef USE_BINKDEC
cinData_t idCinematicLocal::ImageForTimeBinkDec( int thisTime )
{

View file

@ -590,7 +590,8 @@ void idImage::AllocImage()
viewCreateInfo.viewType = ( opts.textureType == TT_CUBIC ) ? VK_IMAGE_VIEW_TYPE_CUBE : VK_IMAGE_VIEW_TYPE_2D;
viewCreateInfo.format = internalFormat;
viewCreateInfo.components = VK_GetComponentMappingFromTextureFormat( opts.format, opts.colorFormat );
viewCreateInfo.subresourceRange.aspectMask = ( opts.format == FMT_DEPTH ) ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
// SRS - Added FMT_DEPTH_STENCIL case
viewCreateInfo.subresourceRange.aspectMask = ( opts.format == FMT_DEPTH || opts.format == FMT_DEPTH_STENCIL ) ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
viewCreateInfo.subresourceRange.levelCount = opts.numLevels;
viewCreateInfo.subresourceRange.layerCount = ( opts.textureType == TT_CUBIC ) ? 6 : 1;
viewCreateInfo.subresourceRange.baseMipLevel = 0;

View file

@ -28,6 +28,7 @@
class CinematicAudio
{
public:
virtual ~CinematicAudio();
virtual void InitAudio( void* audioContext ) = 0;
virtual void PlayAudio( uint8_t* data, int size ) = 0;
virtual void ResetAudio() = 0;