From b16f1a06988f9f8c776a82425702389f4530b17a Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 16 Nov 2011 19:55:22 +0000 Subject: [PATCH] Use scoped_ptr to store the worker thread in DirectSoundPlayer2 Originally committed to SVN as r5855. --- aegisub/src/audio_player_dsound2.cpp | 24 ++++++------------------ aegisub/src/audio_player_dsound2.h | 4 +++- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/aegisub/src/audio_player_dsound2.cpp b/aegisub/src/audio_player_dsound2.cpp index 10df13ec2..e2b1b241e 100644 --- a/aegisub/src/audio_player_dsound2.cpp +++ b/aegisub/src/audio_player_dsound2.cpp @@ -808,8 +808,6 @@ bool DirectSoundPlayer2Thread::IsDead() DirectSoundPlayer2::DirectSoundPlayer2() { - thread = 0; - // The buffer will hold BufferLength times WantedLatency milliseconds of audio WantedLatency = OPT_GET("Player/Audio/DirectSound/Buffer Latency")->GetInt(); BufferLength = OPT_GET("Player/Audio/DirectSound/Buffer Length")->GetInt(); @@ -823,21 +821,16 @@ DirectSoundPlayer2::DirectSoundPlayer2() DirectSoundPlayer2::~DirectSoundPlayer2() { - CloseStream(); } bool DirectSoundPlayer2::IsThreadAlive() { - if (!thread) return false; - - if (thread->IsDead()) + if (thread && thread->IsDead()) { - delete thread; - thread = 0; - return false; + thread.reset(); } - return true; + return thread; } void DirectSoundPlayer2::OpenStream() @@ -846,21 +839,17 @@ void DirectSoundPlayer2::OpenStream() try { - thread = new DirectSoundPlayer2Thread(GetProvider(), WantedLatency, BufferLength); + thread.reset(new DirectSoundPlayer2Thread(GetProvider(), WantedLatency, BufferLength)); } catch (const char *msg) { LOG_E("audio/player/dsound") << msg; - thread = 0; } } void DirectSoundPlayer2::CloseStream() { - if (!IsThreadAlive()) return; - - delete thread; - thread = 0; + thread.reset(); } void DirectSoundPlayer2::SetProvider(AudioProvider *provider) @@ -869,8 +858,7 @@ void DirectSoundPlayer2::SetProvider(AudioProvider *provider) { if (IsThreadAlive() && provider != GetProvider()) { - delete thread; - thread = new DirectSoundPlayer2Thread(provider, WantedLatency, BufferLength); + thread.reset(new DirectSoundPlayer2Thread(provider, WantedLatency, BufferLength)); } AudioPlayer::SetProvider(provider); diff --git a/aegisub/src/audio_player_dsound2.h b/aegisub/src/audio_player_dsound2.h index f3b4fe901..7a73403d6 100644 --- a/aegisub/src/audio_player_dsound2.h +++ b/aegisub/src/audio_player_dsound2.h @@ -38,6 +38,8 @@ #include "include/aegisub/audio_player.h" +#include + class DirectSoundPlayer2Thread; /// @class DirectSoundPlayer2 @@ -48,7 +50,7 @@ class DirectSoundPlayer2Thread; /// send commands to the playback thread. class DirectSoundPlayer2 : public AudioPlayer { /// The playback thread - DirectSoundPlayer2Thread *thread; + agi::scoped_ptr thread; /// Desired length in milliseconds to write ahead of the playback cursor int WantedLatency;