output/Multiple: move Wait() to struct PlayerControl
Eliminate a dependency from MultipleOutputs on PlayerControl.
This commit is contained in:
parent
7c6b0d5c31
commit
ece5971027
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "MultipleOutputs.hxx"
|
#include "MultipleOutputs.hxx"
|
||||||
#include "player/Control.hxx"
|
|
||||||
#include "Internal.hxx"
|
#include "Internal.hxx"
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "MusicBuffer.hxx"
|
#include "MusicBuffer.hxx"
|
||||||
@ -331,22 +330,6 @@ MultipleOutputs::Check()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
MultipleOutputs::Wait(PlayerControl &pc, unsigned threshold)
|
|
||||||
{
|
|
||||||
pc.Lock();
|
|
||||||
|
|
||||||
if (Check() < threshold) {
|
|
||||||
pc.Unlock();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
pc.Wait();
|
|
||||||
pc.Unlock();
|
|
||||||
|
|
||||||
return Check() < threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MultipleOutputs::Pause()
|
MultipleOutputs::Pause()
|
||||||
{
|
{
|
||||||
|
@ -159,16 +159,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
unsigned Check();
|
unsigned Check();
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the size of the #MusicPipe is below the #threshold. If
|
|
||||||
* not, it attempts to synchronize with all output threads, and waits
|
|
||||||
* until another #MusicChunk is finished.
|
|
||||||
*
|
|
||||||
* @param threshold the maximum number of chunks in the pipe
|
|
||||||
* @return true if there are less than #threshold chunks in the pipe
|
|
||||||
*/
|
|
||||||
bool Wait(PlayerControl &pc, unsigned threshold);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts all audio outputs into pause mode. Most implementations will
|
* Puts all audio outputs into pause mode. Most implementations will
|
||||||
* simply close it then.
|
* simply close it then.
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "Control.hxx"
|
#include "Control.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "DetachedSong.hxx"
|
#include "DetachedSong.hxx"
|
||||||
|
#include "output/MultipleOutputs.hxx"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -46,6 +47,18 @@ PlayerControl::~PlayerControl()
|
|||||||
delete tagged_song;
|
delete tagged_song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlayerControl::WaitOutputConsumed(unsigned threshold)
|
||||||
|
{
|
||||||
|
bool result = outputs.Check() < threshold;
|
||||||
|
if (!result && command == PlayerCommand::NONE) {
|
||||||
|
Wait();
|
||||||
|
result = outputs.Check() < threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlayerControl::Play(DetachedSong *song)
|
PlayerControl::Play(DetachedSong *song)
|
||||||
{
|
{
|
||||||
|
@ -280,6 +280,23 @@ struct PlayerControl {
|
|||||||
CommandFinished();
|
CommandFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the size of the #MusicPipe is below the #threshold. If
|
||||||
|
* not, it attempts to synchronize with all output threads, and waits
|
||||||
|
* until another #MusicChunk is finished.
|
||||||
|
*
|
||||||
|
* Caller must lock the mutex.
|
||||||
|
*
|
||||||
|
* @param threshold the maximum number of chunks in the pipe
|
||||||
|
* @return true if there are less than #threshold chunks in the pipe
|
||||||
|
*/
|
||||||
|
bool WaitOutputConsumed(unsigned threshold);
|
||||||
|
|
||||||
|
bool LockWaitOutputConsumed(unsigned threshold) {
|
||||||
|
const ScopeLock protect(mutex);
|
||||||
|
return WaitOutputConsumed(threshold);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Wait for the command to be finished by the player thread.
|
* Wait for the command to be finished by the player thread.
|
||||||
|
@ -500,7 +500,7 @@ Player::CheckDecoderStartup()
|
|||||||
pc.Unlock();
|
pc.Unlock();
|
||||||
|
|
||||||
if (output_open &&
|
if (output_open &&
|
||||||
!pc.outputs.Wait(pc, 1))
|
!pc.LockWaitOutputConsumed(1))
|
||||||
/* the output devices havn't finished playing
|
/* the output devices havn't finished playing
|
||||||
all chunks yet - wait for that */
|
all chunks yet - wait for that */
|
||||||
return true;
|
return true;
|
||||||
@ -813,7 +813,7 @@ play_chunk(PlayerControl &pc,
|
|||||||
inline bool
|
inline bool
|
||||||
Player::PlayNextChunk()
|
Player::PlayNextChunk()
|
||||||
{
|
{
|
||||||
if (!pc.outputs.Wait(pc, 64))
|
if (!pc.LockWaitOutputConsumed(64))
|
||||||
/* the output pipe is still large enough, don't send
|
/* the output pipe is still large enough, don't send
|
||||||
another chunk */
|
another chunk */
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user