forked from mia/Aegisub
Use scoped_ptr to store the worker thread in DirectSoundPlayer2
Originally committed to SVN as r5855.
This commit is contained in:
parent
f45d9f8e2d
commit
b16f1a0698
2 changed files with 9 additions and 19 deletions
|
@ -808,8 +808,6 @@ bool DirectSoundPlayer2Thread::IsDead()
|
||||||
|
|
||||||
DirectSoundPlayer2::DirectSoundPlayer2()
|
DirectSoundPlayer2::DirectSoundPlayer2()
|
||||||
{
|
{
|
||||||
thread = 0;
|
|
||||||
|
|
||||||
// The buffer will hold BufferLength times WantedLatency milliseconds of audio
|
// The buffer will hold BufferLength times WantedLatency milliseconds of audio
|
||||||
WantedLatency = OPT_GET("Player/Audio/DirectSound/Buffer Latency")->GetInt();
|
WantedLatency = OPT_GET("Player/Audio/DirectSound/Buffer Latency")->GetInt();
|
||||||
BufferLength = OPT_GET("Player/Audio/DirectSound/Buffer Length")->GetInt();
|
BufferLength = OPT_GET("Player/Audio/DirectSound/Buffer Length")->GetInt();
|
||||||
|
@ -823,21 +821,16 @@ DirectSoundPlayer2::DirectSoundPlayer2()
|
||||||
|
|
||||||
DirectSoundPlayer2::~DirectSoundPlayer2()
|
DirectSoundPlayer2::~DirectSoundPlayer2()
|
||||||
{
|
{
|
||||||
CloseStream();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectSoundPlayer2::IsThreadAlive()
|
bool DirectSoundPlayer2::IsThreadAlive()
|
||||||
{
|
{
|
||||||
if (!thread) return false;
|
if (thread && thread->IsDead())
|
||||||
|
|
||||||
if (thread->IsDead())
|
|
||||||
{
|
{
|
||||||
delete thread;
|
thread.reset();
|
||||||
thread = 0;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectSoundPlayer2::OpenStream()
|
void DirectSoundPlayer2::OpenStream()
|
||||||
|
@ -846,21 +839,17 @@ void DirectSoundPlayer2::OpenStream()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
thread = new DirectSoundPlayer2Thread(GetProvider(), WantedLatency, BufferLength);
|
thread.reset(new DirectSoundPlayer2Thread(GetProvider(), WantedLatency, BufferLength));
|
||||||
}
|
}
|
||||||
catch (const char *msg)
|
catch (const char *msg)
|
||||||
{
|
{
|
||||||
LOG_E("audio/player/dsound") << msg;
|
LOG_E("audio/player/dsound") << msg;
|
||||||
thread = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectSoundPlayer2::CloseStream()
|
void DirectSoundPlayer2::CloseStream()
|
||||||
{
|
{
|
||||||
if (!IsThreadAlive()) return;
|
thread.reset();
|
||||||
|
|
||||||
delete thread;
|
|
||||||
thread = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
|
void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
|
||||||
|
@ -869,8 +858,7 @@ void DirectSoundPlayer2::SetProvider(AudioProvider *provider)
|
||||||
{
|
{
|
||||||
if (IsThreadAlive() && provider != GetProvider())
|
if (IsThreadAlive() && provider != GetProvider())
|
||||||
{
|
{
|
||||||
delete thread;
|
thread.reset(new DirectSoundPlayer2Thread(provider, WantedLatency, BufferLength));
|
||||||
thread = new DirectSoundPlayer2Thread(provider, WantedLatency, BufferLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioPlayer::SetProvider(provider);
|
AudioPlayer::SetProvider(provider);
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
|
|
||||||
#include "include/aegisub/audio_player.h"
|
#include "include/aegisub/audio_player.h"
|
||||||
|
|
||||||
|
#include <libaegisub/scoped_ptr.h>
|
||||||
|
|
||||||
class DirectSoundPlayer2Thread;
|
class DirectSoundPlayer2Thread;
|
||||||
|
|
||||||
/// @class DirectSoundPlayer2
|
/// @class DirectSoundPlayer2
|
||||||
|
@ -48,7 +50,7 @@ class DirectSoundPlayer2Thread;
|
||||||
/// send commands to the playback thread.
|
/// send commands to the playback thread.
|
||||||
class DirectSoundPlayer2 : public AudioPlayer {
|
class DirectSoundPlayer2 : public AudioPlayer {
|
||||||
/// The playback thread
|
/// The playback thread
|
||||||
DirectSoundPlayer2Thread *thread;
|
agi::scoped_ptr<DirectSoundPlayer2Thread> thread;
|
||||||
|
|
||||||
/// Desired length in milliseconds to write ahead of the playback cursor
|
/// Desired length in milliseconds to write ahead of the playback cursor
|
||||||
int WantedLatency;
|
int WantedLatency;
|
||||||
|
|
Loading…
Reference in a new issue