Skip to content

Commit

Permalink
AESinkPULSE: Start stream corked. Resume when starting to add packets
Browse files Browse the repository at this point in the history
  • Loading branch information
fritsch committed May 9, 2014
1 parent dacb585 commit c42d8ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp
Expand Up @@ -694,7 +694,8 @@ bool CAESinkPULSE::Initialize(AEAudioFormat &format, std::string &device)
m_format = format;
format.m_dataFormat = m_passthrough ? AE_FMT_S16NE : format.m_dataFormat;

Pause(false);
// Cork stream will resume when adding first package
Pause(true);
{
CSingleLock lock(m_sec);
m_IsAllocated = true;
Expand Down Expand Up @@ -772,6 +773,11 @@ unsigned int CAESinkPULSE::AddPackets(uint8_t *data, unsigned int frames, bool h
if (!m_IsAllocated)
return frames;

if (m_IsStreamPaused)
{
Pause(false);
}

pa_threaded_mainloop_lock(m_MainLoop);

unsigned int available = frames * m_format.m_frameSize;
Expand Down Expand Up @@ -907,16 +913,15 @@ bool CAESinkPULSE::IsInitialized()
return m_IsAllocated;
}

bool CAESinkPULSE::Pause(bool pause)
void CAESinkPULSE::Pause(bool pause)
{
pa_threaded_mainloop_lock(m_MainLoop);

if (!WaitForOperation(pa_stream_cork(m_Stream, pause ? 1 : 0, NULL, NULL), m_MainLoop, pause ? "Pause" : "Resume"))
pause = !pause;

m_IsStreamPaused = pause;
pa_threaded_mainloop_unlock(m_MainLoop);

return pause;
}

inline bool CAESinkPULSE::WaitForOperation(pa_operation *op, pa_threaded_mainloop *mainloop, const char *LogEntry = "")
Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/AudioEngine/Sinks/AESinkPULSE.h
Expand Up @@ -51,12 +51,13 @@ class CAESinkPULSE : public IAESink
bool IsInitialized();
CCriticalSection m_sec;
private:
bool Pause(bool pause);
void Pause(bool pause);
static inline bool WaitForOperation(pa_operation *op, pa_threaded_mainloop *mainloop, const char *LogEntry);
static bool SetupContext(const char *host, pa_context **context, pa_threaded_mainloop **mainloop);

bool m_IsAllocated;
bool m_passthrough;
bool m_IsStreamPaused;

AEAudioFormat m_format;
unsigned int m_BytesPerSecond;
Expand Down

0 comments on commit c42d8ce

Please sign in to comment.