Merge pull request #1424 from shenlebantongying/fix/insanly-click-audio-crash

fix: crash when clicking audio insanely fast.
This commit is contained in:
xiaoyifang 2024-03-20 13:20:38 +08:00 committed by GitHub
commit 52c07b9291
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -52,11 +52,12 @@ AudioService::~AudioService()
void AudioService::playMemory( const char * ptr, int size )
{
emit cancelPlaying( false );
if ( !thread.isNull() ) {
thread->wait();
}
QByteArray audioData( ptr, size );
thread = std::make_shared< DecoderThread >( audioData, this );
connect( this, &AudioService::cancelPlaying, thread.get(), [ this ]( bool waitFinished ) {
thread->cancel( waitFinished );
} );
thread.reset( new DecoderThread( audioData, this ) );
connect( this, &AudioService::cancelPlaying, thread.get(), &DecoderThread::cancel );
thread->start();
}
@ -263,6 +264,11 @@ bool DecoderContext::openOutputDevice( QString & errorString )
}
#endif
if ( audioOutput == nullptr ) {
errorString += QStringLiteral( "Failed to create audioOutput." );
return false;
}
audioOutput->setAudioFormat( 44100, codecContext_->channels );
return true;
}

View file

@ -29,7 +29,7 @@ class DecoderThread;
class AudioService: public QObject
{
Q_OBJECT
std::shared_ptr< DecoderThread > thread;
QScopedPointer< DecoderThread > thread;
public:
static AudioService & instance();