Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[iOS] Take possible data in AddPacket.

Protect internal buffer.
Avoid device reinit in Initialize.
Flush internal buffer on device stop.
  • Loading branch information...
commit b0b7aa90d98f74284d7283f189e04f0c39c344b0 1 parent 72765a5
gimli authored
View
46 xbmc/cores/AudioRenderers/IOSAudioRenderer.cpp
@@ -60,19 +60,10 @@ CIOSAudioRenderer::~CIOSAudioRenderer()
bool CIOSAudioRenderer::Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic /*Useless Legacy Parameter*/, bool bPassthrough)
{
- /* Taken from ALSA */
- /*
- static enum PCMChannels IOSChannelMap[6] =
- {PCM_FRONT_LEFT, PCM_FRONT_RIGHT, PCM_FRONT_CENTER, PCM_LOW_FREQUENCY, PCM_BACK_LEFT, PCM_BACK_RIGHT};
- */
// Limit to 2.0. It is only used for anloge audio.
static enum PCMChannels IOSChannelMap[2] =
{PCM_FRONT_LEFT, PCM_FRONT_RIGHT};
- // Have to clean house before we start again. TODO: Should we return failure instead?
- if (m_Initialized)
- Deinitialize();
-
if (!m_dllAvUtil->Load())
CLog::Log(LOGERROR,"CIOSAudioRenderer::Initialize - failed to load avutil library!");
@@ -224,6 +215,17 @@ bool CIOSAudioRenderer::Deinitialize()
return true;
}
+void CIOSAudioRenderer::Flush()
+{
+ if(!m_Buffer)
+ return;
+
+ CSingleLock lock (m_critSection);
+
+ Pause();
+ m_dllAvUtil->av_fifo_reset(m_Buffer);
+}
+
//***********************************************************************************************
// Transport control methods
//***********************************************************************************************
@@ -253,6 +255,7 @@ bool CIOSAudioRenderer::Stop()
m_Pause = true;
+ Flush();
return true;
}
@@ -285,16 +288,14 @@ unsigned int CIOSAudioRenderer::GetSpace()
unsigned int CIOSAudioRenderer::AddPackets(const void* data, DWORD len)
{
+ CSingleLock lock (m_critSection);
+
int free = m_BufferLen - m_dllAvUtil->av_fifo_size(m_Buffer);
len = (len / m_DataChannels) * m_Channels;
- if(len > free)
- return 0;
-
- //int length = std::min(free, (int)len);
- len = std::min(free, (int)len);
- int frames = len / m_Channels / (m_BitsPerChannel >> 3);
+ int length = std::min(free, (int)len);
+ int frames = length / m_Channels / (m_BitsPerChannel >> 3);
if(frames == 0)
return 0;
@@ -302,18 +303,18 @@ unsigned int CIOSAudioRenderer::AddPackets(const void* data, DWORD len)
// Call channel remapping routine if available available and required
if(m_remap.CanRemap() && !m_Passthrough)
{
- uint8_t outData[len];
+ uint8_t outData[length];
m_remap.Remap((void*)data, outData, frames);
- m_dllAvUtil->av_fifo_generic_write(m_Buffer, outData, len, NULL);
+ m_dllAvUtil->av_fifo_generic_write(m_Buffer, outData, length, NULL);
}
else
{
- m_dllAvUtil->av_fifo_generic_write(m_Buffer, (unsigned char *)data, len, NULL);
+ m_dllAvUtil->av_fifo_generic_write(m_Buffer, (unsigned char *)data, length, NULL);
}
Resume();
- return (len / m_Channels) * m_DataChannels;
+ return (length / m_Channels) * m_DataChannels;
}
float CIOSAudioRenderer::GetDelay()
@@ -364,10 +365,12 @@ OSStatus CIOSAudioRenderer::OnRender(AudioUnitRenderActionFlags *ioActionFlags,
{
if (!m_Initialized) {
CLog::Log(LOGERROR, "CIOSAudioRenderer::OnRender: Callback to de/unitialized renderer.");
+ ioData->mBuffers[m_OutputBufferIndex].mDataByteSize = 0;
return noErr;
}
if(m_Pause) {
+ ioData->mBuffers[m_OutputBufferIndex].mDataByteSize = 0;
return noErr;
}
@@ -382,9 +385,12 @@ OSStatus CIOSAudioRenderer::OnRender(AudioUnitRenderActionFlags *ioActionFlags,
{
m_DoRunout = 0;
}
+ ioData->mBuffers[m_OutputBufferIndex].mDataByteSize = 0;
+ return noErr;
}
-
+ CSingleLock lock (m_critSection);
+
m_dllAvUtil->av_fifo_generic_read(m_Buffer, (unsigned char *)ioData->mBuffers[m_OutputBufferIndex].mData, bytesRequested, NULL);
if (!m_EnableVolumeControl && m_CurrentVolume <= VOLUME_MINIMUM)
View
5 xbmc/cores/AudioRenderers/IOSAudioRenderer.h
@@ -21,10 +21,10 @@
#ifndef __COREAUDIO_RENDERER_H__
#define __COREAUDIO_RENDERER_H__
-//#include <osx/CoreAudio.h>
#include "IOSCoreAudio.h"
#include "PlatformDefs.h"
#include "IAudioRenderer.h"
+#include "utils/CriticalSection.h"
#include <utils/Event.h>
#include <utils/LockFree.h>
@@ -40,6 +40,7 @@ class CIOSAudioRenderer : public IAudioRenderer
virtual float GetDelay();
virtual bool Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic=false, bool bPassthrough = false);
virtual bool Deinitialize();
+ virtual void Flush();
virtual unsigned int AddPackets(const void* data, unsigned int len);
virtual unsigned int GetSpace();
virtual float GetCacheTime();
@@ -96,6 +97,8 @@ class CIOSAudioRenderer : public IAudioRenderer
bool m_Passthrough;
DllAvUtil *m_dllAvUtil;
+
+ CCriticalSection m_critSection;
};
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.