Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when clicking audio insanely fast. #1424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/ffmpegaudio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reset here has the same meaning as the older thread = std::make_shared because the older code also ensure the existing one is deleted.

connect( this, &AudioService::cancelPlaying, thread.get(), &DecoderThread::cancel );
thread->start();
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ffmpegaudio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DecoderThread;
class AudioService: public QObject
{
Q_OBJECT
std::shared_ptr< DecoderThread > thread;
QScopedPointer< DecoderThread > thread;

public:
static AudioService & instance();
Expand Down
Loading