forked from mia/Aegisub
Kill AudioPlayer::displayTimer
The rewritten audio display does not use displayTimer and that functionality shouldn't have been in the players in the first place. Originally committed to SVN as r6605.
This commit is contained in:
parent
2840fc0aea
commit
7218c04d52
|
@ -62,13 +62,6 @@
|
||||||
|
|
||||||
AudioPlayer::AudioPlayer() {
|
AudioPlayer::AudioPlayer() {
|
||||||
provider = NULL;
|
provider = NULL;
|
||||||
displayTimer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioPlayer::~AudioPlayer() {
|
|
||||||
if (displayTimer) {
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioPlayer* AudioPlayerFactory::GetAudioPlayer() {
|
AudioPlayer* AudioPlayerFactory::GetAudioPlayer() {
|
||||||
|
|
|
@ -404,33 +404,23 @@ void AlsaPlayer::Play(int64_t start, int64_t count)
|
||||||
{
|
{
|
||||||
OpenStream();
|
OpenStream();
|
||||||
|
|
||||||
{
|
PthreadMutexLocker ml(ps->mutex);
|
||||||
PthreadMutexLocker ml(ps->mutex);
|
ps->signal_start = true;
|
||||||
ps->signal_start = true;
|
ps->signal_stop = true; // make sure to stop any ongoing playback first
|
||||||
ps->signal_stop = true; // make sure to stop any ongoing playback first
|
ps->start_position = start;
|
||||||
ps->start_position = start;
|
ps->end_position = start + count;
|
||||||
ps->end_position = start + count;
|
pthread_cond_signal(&ps->cond);
|
||||||
pthread_cond_signal(&ps->cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (displayTimer && !displayTimer->IsRunning())
|
|
||||||
displayTimer->Start(15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AlsaPlayer::Stop(bool timerToo)
|
void AlsaPlayer::Stop()
|
||||||
{
|
{
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
|
|
||||||
{
|
PthreadMutexLocker ml(ps->mutex);
|
||||||
PthreadMutexLocker ml(ps->mutex);
|
ps->signal_stop = true;
|
||||||
ps->signal_stop = true;
|
LOG_D("audio/player/alsa") << "stop stream, stop signal";
|
||||||
LOG_D("audio/player/alsa") << "stop stream, stop signal";
|
pthread_cond_signal(&ps->cond);
|
||||||
pthread_cond_signal(&ps->cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timerToo && displayTimer)
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AlsaPlayer::IsPlaying()
|
bool AlsaPlayer::IsPlaying()
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
void CloseStream();
|
void CloseStream();
|
||||||
|
|
||||||
void Play(int64_t start, int64_t count);
|
void Play(int64_t start, int64_t count);
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
bool IsPlaying();
|
bool IsPlaying();
|
||||||
|
|
||||||
int64_t GetStartPosition();
|
int64_t GetStartPosition();
|
||||||
|
|
|
@ -258,15 +258,12 @@ void DirectSoundPlayer::Play(int64_t start,int64_t count) {
|
||||||
res = buffer->Play(0,0,play_flag);
|
res = buffer->Play(0,0,play_flag);
|
||||||
if (SUCCEEDED(res)) playing = true;
|
if (SUCCEEDED(res)) playing = true;
|
||||||
startTime = GetTickCount();
|
startTime = GetTickCount();
|
||||||
|
|
||||||
// Update timer
|
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Stop
|
/// @brief Stop
|
||||||
/// @param timerToo
|
/// @param timerToo
|
||||||
///
|
///
|
||||||
void DirectSoundPlayer::Stop(bool timerToo) {
|
void DirectSoundPlayer::Stop() {
|
||||||
// Stop the thread
|
// Stop the thread
|
||||||
if (thread) {
|
if (thread) {
|
||||||
if (thread->IsAlive()) {
|
if (thread->IsAlive()) {
|
||||||
|
@ -286,11 +283,6 @@ void DirectSoundPlayer::Stop(bool timerToo) {
|
||||||
startPos = 0;
|
startPos = 0;
|
||||||
endPos = 0;
|
endPos = 0;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
// Stop timer
|
|
||||||
if (timerToo && displayTimer) {
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Set end
|
/// @brief Set end
|
||||||
|
|
|
@ -137,7 +137,7 @@ public:
|
||||||
void CloseStream();
|
void CloseStream();
|
||||||
|
|
||||||
void Play(int64_t start,int64_t count);
|
void Play(int64_t start,int64_t count);
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
|
|
||||||
/// @brief DOCME
|
/// @brief DOCME
|
||||||
/// @return
|
/// @return
|
||||||
|
|
|
@ -870,8 +870,6 @@ void DirectSoundPlayer2::Play(int64_t start,int64_t count)
|
||||||
{
|
{
|
||||||
OpenStream();
|
OpenStream();
|
||||||
thread->Play(start, count);
|
thread->Play(start, count);
|
||||||
|
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
|
||||||
}
|
}
|
||||||
catch (const char *msg)
|
catch (const char *msg)
|
||||||
{
|
{
|
||||||
|
@ -879,15 +877,11 @@ void DirectSoundPlayer2::Play(int64_t start,int64_t count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectSoundPlayer2::Stop(bool timerToo)
|
void DirectSoundPlayer2::Stop()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (IsThreadAlive()) thread->Stop();
|
if (IsThreadAlive()) thread->Stop();
|
||||||
|
|
||||||
if (timerToo && displayTimer) {
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (const char *msg)
|
catch (const char *msg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -88,7 +88,7 @@ public:
|
||||||
|
|
||||||
/// @brief Stop audio playback
|
/// @brief Stop audio playback
|
||||||
/// @param timerToo Whether to also stop the playback update timer
|
/// @param timerToo Whether to also stop the playback update timer
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
|
|
||||||
/// @brief Tell whether playback is active
|
/// @brief Tell whether playback is active
|
||||||
/// @return True if audio is playing back
|
/// @return True if audio is playing back
|
||||||
|
|
|
@ -161,12 +161,9 @@ void OpenALPlayer::Play(int64_t start, int64_t count)
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
wxTimer::Start(100);
|
wxTimer::Start(100);
|
||||||
playback_segment_timer.Start();
|
playback_segment_timer.Start();
|
||||||
|
|
||||||
// Update timer
|
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenALPlayer::Stop(bool timerToo)
|
void OpenALPlayer::Stop()
|
||||||
{
|
{
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
if (!playing) return;
|
if (!playing) return;
|
||||||
|
@ -181,10 +178,6 @@ void OpenALPlayer::Stop(bool timerToo)
|
||||||
// Then drop the playback
|
// Then drop the playback
|
||||||
alSourceStop(source);
|
alSourceStop(source);
|
||||||
alSourcei(source, AL_BUFFER, 0);
|
alSourcei(source, AL_BUFFER, 0);
|
||||||
|
|
||||||
if (timerToo && displayTimer) {
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenALPlayer::FillBuffers(ALsizei count)
|
void OpenALPlayer::FillBuffers(ALsizei count)
|
||||||
|
@ -237,7 +230,7 @@ void OpenALPlayer::Notify()
|
||||||
LOG_D("player/audio/openal") << "frames played=" << (buffers_played - num_buffers) * decode_buffer.size() / bpf << " num frames=" << end_frame - start_frame;
|
LOG_D("player/audio/openal") << "frames played=" << (buffers_played - num_buffers) * decode_buffer.size() / bpf << " num frames=" << end_frame - start_frame;
|
||||||
// Check that all of the selected audio plus one full set of buffers has been queued
|
// Check that all of the selected audio plus one full set of buffers has been queued
|
||||||
if ((buffers_played - num_buffers) * (int64_t)decode_buffer.size() > (end_frame - start_frame) * bpf) {
|
if ((buffers_played - num_buffers) * (int64_t)decode_buffer.size() > (end_frame - start_frame) * bpf) {
|
||||||
Stop(true);
|
Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
void CloseStream();
|
void CloseStream();
|
||||||
|
|
||||||
void Play(int64_t start,int64_t count);
|
void Play(int64_t start,int64_t count);
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
bool IsPlaying() { return playing; }
|
bool IsPlaying() { return playing; }
|
||||||
|
|
||||||
int64_t GetStartPosition() { return start_frame; }
|
int64_t GetStartPosition() { return start_frame; }
|
||||||
|
|
|
@ -141,12 +141,10 @@ void OSSPlayer::Play(int64_t start, int64_t count)
|
||||||
thread->Create();
|
thread->Create();
|
||||||
thread->Run();
|
thread->Run();
|
||||||
|
|
||||||
// Update timer
|
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
|
||||||
playing = true;
|
playing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSSPlayer::Stop(bool timerToo)
|
void OSSPlayer::Stop()
|
||||||
{
|
{
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
if (!playing) return;
|
if (!playing) return;
|
||||||
|
@ -168,11 +166,6 @@ void OSSPlayer::Stop(bool timerToo)
|
||||||
start_frame = 0;
|
start_frame = 0;
|
||||||
cur_frame = 0;
|
cur_frame = 0;
|
||||||
end_frame = 0;
|
end_frame = 0;
|
||||||
|
|
||||||
// Stop timer
|
|
||||||
if (timerToo && displayTimer) {
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSSPlayer::SetEndPosition(int64_t pos)
|
void OSSPlayer::SetEndPosition(int64_t pos)
|
||||||
|
@ -208,10 +201,6 @@ int64_t OSSPlayer::GetCurrentPosition()
|
||||||
played_frames = pos.samples + pos.fifo_samples;
|
played_frames = pos.samples + pos.fifo_samples;
|
||||||
#endif
|
#endif
|
||||||
LOG_D("player/audio/oss") << "played_frames: " << played_frames << " fifo " << pos.fifo_samples;
|
LOG_D("player/audio/oss") << "played_frames: " << played_frames << " fifo " << pos.fifo_samples;
|
||||||
if (start_frame + played_frames >= end_frame) {
|
|
||||||
if (displayTimer)
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
return start_frame + played_frames;
|
return start_frame + played_frames;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -224,8 +213,6 @@ int64_t OSSPlayer::GetCurrentPosition()
|
||||||
LOG_D("player/audio/oss") << "cur_frame: " << cur_frame << " delay " << delay;
|
LOG_D("player/audio/oss") << "cur_frame: " << cur_frame << " delay " << delay;
|
||||||
// delay can jitter a bit at the end, detect that
|
// delay can jitter a bit at the end, detect that
|
||||||
if (cur_frame == end_frame && delay < rate / 20) {
|
if (cur_frame == end_frame && delay < rate / 20) {
|
||||||
if (displayTimer)
|
|
||||||
displayTimer->Stop();
|
|
||||||
return cur_frame;
|
return cur_frame;
|
||||||
}
|
}
|
||||||
return MAX(0, (long) cur_frame - delay);
|
return MAX(0, (long) cur_frame - delay);
|
||||||
|
|
|
@ -115,7 +115,7 @@ public:
|
||||||
void CloseStream();
|
void CloseStream();
|
||||||
|
|
||||||
void Play(int64_t start, int64_t count);
|
void Play(int64_t start, int64_t count);
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
bool IsPlaying() { return playing; }
|
bool IsPlaying() { return playing; }
|
||||||
|
|
||||||
int64_t GetStartPosition() { return start_frame; }
|
int64_t GetStartPosition() { return start_frame; }
|
||||||
|
|
|
@ -173,15 +173,11 @@ void PortAudioPlayer::OpenStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortAudioPlayer::CloseStream() {
|
void PortAudioPlayer::CloseStream() {
|
||||||
Stop(false);
|
Stop();
|
||||||
Pa_CloseStream(stream);
|
Pa_CloseStream(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortAudioPlayer::paStreamFinishedCallback(void *userData) {
|
void PortAudioPlayer::paStreamFinishedCallback(void *) {
|
||||||
PortAudioPlayer *player = (PortAudioPlayer *) userData;
|
|
||||||
|
|
||||||
if (player->displayTimer)
|
|
||||||
player->displayTimer->Stop();
|
|
||||||
LOG_D("audio/player/portaudio") << "stopping stream";
|
LOG_D("audio/player/portaudio") << "stopping stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,17 +201,10 @@ void PortAudioPlayer::Play(int64_t start_sample, int64_t count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pa_start = Pa_GetStreamTime(stream);
|
pa_start = Pa_GetStreamTime(stream);
|
||||||
|
|
||||||
// Update timer
|
|
||||||
if (displayTimer && !displayTimer->IsRunning())
|
|
||||||
displayTimer->Start(15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortAudioPlayer::Stop(bool timerToo) {
|
void PortAudioPlayer::Stop() {
|
||||||
Pa_StopStream(stream);
|
Pa_StopStream(stream);
|
||||||
|
|
||||||
if (timerToo && displayTimer)
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer,
|
int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer,
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
void Play(int64_t start,int64_t count);
|
void Play(int64_t start,int64_t count);
|
||||||
/// @brief Stop Playback
|
/// @brief Stop Playback
|
||||||
/// @param timerToo Stop display timer?
|
/// @param timerToo Stop display timer?
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
|
|
||||||
/// @brief Whether audio is currently being played.
|
/// @brief Whether audio is currently being played.
|
||||||
/// @return Status
|
/// @return Status
|
||||||
|
|
|
@ -217,12 +217,9 @@ void PulseAudioPlayer::Play(int64_t start,int64_t count)
|
||||||
paerror = pa_context_errno(context);
|
paerror = pa_context_errno(context);
|
||||||
printf("PulseAudio player: Error triggering stream: %s (%d)\n", pa_strerror(paerror), paerror);
|
printf("PulseAudio player: Error triggering stream: %s (%d)\n", pa_strerror(paerror), paerror);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update timer
|
|
||||||
if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PulseAudioPlayer::Stop(bool timerToo)
|
void PulseAudioPlayer::Stop()
|
||||||
{
|
{
|
||||||
if (!is_playing) return;
|
if (!is_playing) return;
|
||||||
//printf("Stopping PulseAudio\n");
|
//printf("Stopping PulseAudio\n");
|
||||||
|
@ -247,10 +244,6 @@ void PulseAudioPlayer::Stop(bool timerToo)
|
||||||
|
|
||||||
// And unref it
|
// And unref it
|
||||||
//printf("Stopped stream\n\n");
|
//printf("Stopped stream\n\n");
|
||||||
|
|
||||||
if (timerToo && displayTimer) {
|
|
||||||
displayTimer->Stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PulseAudioPlayer::IsPlaying()
|
bool PulseAudioPlayer::IsPlaying()
|
||||||
|
|
|
@ -131,7 +131,7 @@ public:
|
||||||
void CloseStream();
|
void CloseStream();
|
||||||
|
|
||||||
void Play(int64_t start,int64_t count);
|
void Play(int64_t start,int64_t count);
|
||||||
void Stop(bool timerToo=true);
|
void Stop();
|
||||||
bool IsPlaying();
|
bool IsPlaying();
|
||||||
|
|
||||||
int64_t GetStartPosition();
|
int64_t GetStartPosition();
|
||||||
|
|
|
@ -36,12 +36,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
|
||||||
#include <wx/event.h>
|
|
||||||
#include <wx/thread.h>
|
|
||||||
#include <wx/timer.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "factory_manager.h"
|
#include "factory_manager.h"
|
||||||
|
|
||||||
class AudioProvider;
|
class AudioProvider;
|
||||||
|
@ -55,18 +49,15 @@ protected:
|
||||||
/// DOCME
|
/// DOCME
|
||||||
AudioProvider *provider;
|
AudioProvider *provider;
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
wxTimer *displayTimer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioPlayer();
|
AudioPlayer();
|
||||||
virtual ~AudioPlayer();
|
virtual ~AudioPlayer() { }
|
||||||
|
|
||||||
virtual void OpenStream()=0;
|
virtual void OpenStream()=0;
|
||||||
virtual void CloseStream()=0;
|
virtual void CloseStream()=0;
|
||||||
|
|
||||||
virtual void Play(int64_t start,int64_t count)=0; // Play sample range
|
virtual void Play(int64_t start,int64_t count)=0; // Play sample range
|
||||||
virtual void Stop(bool timerToo=true)=0; // Stop playing
|
virtual void Stop()=0; // Stop playing
|
||||||
virtual bool IsPlaying()=0;
|
virtual bool IsPlaying()=0;
|
||||||
|
|
||||||
virtual void SetVolume(double volume)=0;
|
virtual void SetVolume(double volume)=0;
|
||||||
|
|
Loading…
Reference in a new issue