Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3160 from Memphiz/removecaringbuffer

[CA/AE] - remove CoreAudioRingBuffer and use the duped impl called AERingBuffer
  • Loading branch information...
commit 18a43774cd8cb4b2dace709ff26a0118d41769bd 2 parents abf0372 + fe4062c
davilla davilla authored
4 XBMC.xcodeproj/project.pbxproj
View
@@ -4070,6 +4070,7 @@
DF527732151BAF4C00B5B63B /* WebSocketV8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketV8.h; sourceTree = "<group>"; };
DF529BAC1741697B00523FB4 /* Environment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Environment.cpp; sourceTree = "<group>"; };
DF529BAD1741697B00523FB4 /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Environment.h; sourceTree = "<group>"; };
+ DF5EEEFB17CE977A003DEC49 /* AERingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AERingBuffer.h; sourceTree = "<group>"; };
DF64FE3516C07AAA00D028FB /* GUIViewControl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIViewControl.cpp; sourceTree = "<group>"; };
DF64FE3616C07AAA00D028FB /* GUIViewControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUIViewControl.h; sourceTree = "<group>"; };
DF64FE3716C07AAA00D028FB /* GUIViewState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIViewState.cpp; sourceTree = "<group>"; };
@@ -4184,7 +4185,6 @@
DFB65F7615373AE7006B8FF1 /* CoreAudioAESound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioAESound.h; path = CoreAudio/CoreAudioAESound.h; sourceTree = "<group>"; };
DFB65F7715373AE7006B8FF1 /* CoreAudioAEStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CoreAudioAEStream.cpp; path = CoreAudio/CoreAudioAEStream.cpp; sourceTree = "<group>"; };
DFB65F7815373AE7006B8FF1 /* CoreAudioAEStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioAEStream.h; path = CoreAudio/CoreAudioAEStream.h; sourceTree = "<group>"; };
- DFB65F7915373AE7006B8FF1 /* CoreAudioRingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioRingBuffer.h; path = CoreAudio/CoreAudioRingBuffer.h; sourceTree = "<group>"; };
DFB65F7A15373AE7006B8FF1 /* ICoreAudioAEHAL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ICoreAudioAEHAL.h; path = CoreAudio/ICoreAudioAEHAL.h; sourceTree = "<group>"; };
DFB65F7B15373AE7006B8FF1 /* ICoreAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ICoreAudioSource.h; path = CoreAudio/ICoreAudioSource.h; sourceTree = "<group>"; };
DFB65F8915373AE7006B8FF1 /* AE.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AE.h; sourceTree = "<group>"; };
@@ -7049,6 +7049,7 @@
DFB65FAC15373AE7006B8FF1 /* AEPackIEC61937.h */,
DFB65FAD15373AE7006B8FF1 /* AERemap.cpp */,
DFB65FAE15373AE7006B8FF1 /* AERemap.h */,
+ DF5EEEFB17CE977A003DEC49 /* AERingBuffer.h */,
DFB65FAF15373AE7006B8FF1 /* AEStreamInfo.cpp */,
DFB65FB015373AE7006B8FF1 /* AEStreamInfo.h */,
DFB65FB115373AE7006B8FF1 /* AEUtil.cpp */,
@@ -9218,7 +9219,6 @@
F5ED942D155D729500842059 /* CoreAudioHardware.h */,
F5ED9494155D7B9900842059 /* CoreAudioMixMap.cpp */,
F5ED9495155D7B9900842059 /* CoreAudioMixMap.h */,
- DFB65F7915373AE7006B8FF1 /* CoreAudioRingBuffer.h */,
F5ED943C155D743700842059 /* CoreAudioStream.cpp */,
F5ED943D155D743700842059 /* CoreAudioStream.h */,
F5ED94A9155D7F8000842059 /* CoreAudioUnit.cpp */,
2  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.cpp
View
@@ -308,7 +308,7 @@ void CCoreAudioAEStream::Initialize()
m_AvgBytesPerSec = m_OutputFormat.m_frameSize * m_OutputFormat.m_sampleRate;
delete m_Buffer;
- m_Buffer = new CoreAudioRingBuffer(m_AvgBytesPerSec);
+ m_Buffer = new AERingBuffer(m_AvgBytesPerSec);
m_fadeRunning = false;
6 xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.h
View
@@ -22,13 +22,13 @@
#include <samplerate.h>
#include <list>
-#include "CoreAudioRingBuffer.h"
#include "ICoreAudioSource.h"
#include "cores/AudioEngine/AEAudioFormat.h"
#include "cores/AudioEngine/Interfaces/AEStream.h"
#include "cores/AudioEngine/Utils/AEConvert.h"
#include "cores/AudioEngine/Utils/AERemap.h"
#include "cores/AudioEngine/Utils/AELimiter.h"
+#include "cores/AudioEngine/Utils/AERingBuffer.h"
#if defined(TARGET_DARWIN_IOS)
# include "CoreAudioAEHALIOS.h"
@@ -36,7 +36,7 @@
# include "CoreAudioAEHALOSX.h"
#endif
-class CoreAudioRingBuffer;
+class AERingBuffer;
class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
{
@@ -139,7 +139,7 @@ class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
CAEConvert::AEConvertToFn m_convertFn;
- CoreAudioRingBuffer *m_Buffer;
+ AERingBuffer *m_Buffer;
float *m_convertBuffer; /* buffer for converted data */
int m_convertBufferSize;
//float *m_resampleBuffer; /* buffer for resample data */
253 xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioRingBuffer.h
View
@@ -1,253 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 2010-2013 Team XBMC
- * http://xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#define RING_BUFFER_OK 0;
-#define RING_BUFFER_EMPTY 1;
-#define RING_BUFFER_FULL 2;
-#define RING_BUFFER_NOTAVAILABLE 3;
-
-//#define RING_BUFFER_DEBUG
-
-#include "utils/log.h" //CLog
-#include <string.h> //memset, memcpy
-
-/**
- * This buffer can be used by one read and one write thread at any one time
- * without the risk of data corruption.
- * If you intend to call the Reset() method, please use Locks.
- * All other operations are thread-safe.
- */
-class CoreAudioRingBuffer {
-
-public:
- CoreAudioRingBuffer() :
- m_iReadPos(0),
- m_iWritePos(0),
- m_iRead(0),
- m_iWritten(0),
- m_iSize(0),
- m_Buffer(NULL)
- {
- }
-
- CoreAudioRingBuffer(unsigned int size) :
- m_iReadPos(0),
- m_iWritePos(0),
- m_iRead(0),
- m_iWritten(0),
- m_iSize(0),
- m_Buffer(NULL)
- {
- Create(size);
- }
-
- ~CoreAudioRingBuffer()
- {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoreAudioRingBuffer::~CoereAudioRingBuffer: Deleting buffer.");
-#endif
- _aligned_free(m_Buffer);
- }
-
- /**
- * Allocates space for buffer, and sets it's contents to 0.
- *
- * @return true on success, false otherwise
- */
- bool Create(int size)
- {
- m_Buffer = (unsigned char*)_aligned_malloc(size,16);
- if ( m_Buffer )
- {
- m_iSize = size;
- memset(m_Buffer, 0, m_iSize);
- return true;
- }
- return false;
- }
-
- /**
- * Fills the buffer with zeros and resets the pointers.
- * This method is not thread-safe, so before using this method
- * please acquire a Lock()
- */
- void Reset() {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer::Reset: Buffer reset.");
-#endif
- m_iWritten = 0;
- m_iRead = 0;
- m_iReadPos = 0;
- m_iWritePos = 0;
- }
-
- /**
- * Writes data to buffer.
- * Attempt to write more bytes than available results in RING_BUFFER_FULL.
- *
- * @return RING_BUFFER_OK on success, otherwise an error code
- */
- int Write(unsigned char *src, unsigned int size)
- {
- unsigned int space = GetWriteSize();
-
- //do we have enough space for all the data?
- if (size > space) {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Not enough space, ignoring data. Requested: %u Available: %u",size, space);
-#endif
- return RING_BUFFER_FULL;
- }
-
- //no wrapping?
- if ( m_iSize > size + m_iWritePos )
- {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Written to: %u size: %u space before: %u\n", m_iWritePos, size, space);
-#endif
- memcpy(&(m_Buffer[m_iWritePos]), src, size);
- m_iWritePos+=size;
- }
- //need to wrap
- else
- {
- unsigned int first = m_iSize - m_iWritePos;
- unsigned int second = size - first;
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Written to (split) first: %u second: %u size: %u space before: %u\n", first, second, size, space);
-#endif
- memcpy(&(m_Buffer[m_iWritePos]), src, first);
- memcpy(&(m_Buffer[0]), &src[first], second);
- m_iWritePos = second;
- }
-
- //we can increase the write count now
- m_iWritten+=size;
- return RING_BUFFER_OK;
- }
-
- /**
- * Reads data from buffer.
- * Attempt to read more bytes than available results in RING_BUFFER_NOTAVAILABLE.
- * Reading from empty buffer returns RING_BUFFER_EMPTY
- *
- * @return RING_BUFFER_OK on success, otherwise an error code
- */
- int Read(unsigned char *dest, unsigned int size)
- {
- unsigned int space = GetReadSize();
-
- //want to read more than we have written?
- if( space == 0 )
- {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Can't read from empty buffer.");
-#endif
- return RING_BUFFER_EMPTY;
- }
-
- //want to read more than we have available
- if( size > space )
- {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Can't read %u bytes when we only have %u.", size, space);
-#endif
- return RING_BUFFER_NOTAVAILABLE;
- }
-
- //no wrapping?
- if ( size + m_iReadPos < m_iSize )
- {
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Reading from: %u size: %u space before: %u\n", m_iWritePos, size, space);
-#endif
- memcpy(dest, &(m_Buffer[m_iReadPos]), size);
- m_iReadPos+=size;
- }
- //need to wrap
- else
- {
- unsigned int first = m_iSize - m_iReadPos;
- unsigned int second = size - first;
-#ifdef RING_BUFFER_DEBUG
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Reading from (split) first: %u second: %u size: %u space before: %u\n", first, second, size, space);
-#endif
- memcpy(dest, &(m_Buffer[m_iReadPos]), first);
- memcpy(&dest[first], &(m_Buffer[0]), second);
- m_iReadPos = second;
- }
- //we can increase the read count now
- m_iRead+=size;
-
- return RING_BUFFER_OK;
- }
-
- /**
- * Dumps the buffer.
- */
- void Dump()
- {
- unsigned char* bufferContents = (unsigned char *)_aligned_malloc(m_iSize + 1,16);
- for (unsigned int i=0; i<m_iSize; i++) {
- if (i >= m_iReadPos && i<m_iWritePos)
- bufferContents[i] = m_Buffer[i];
- else
- bufferContents[i] = '_';
- }
- bufferContents[m_iSize] = '\0';
- CLog::Log(LOGDEBUG, "CoereAudioRingBuffer::Dump()\n%s",bufferContents);
- _aligned_free(bufferContents);
- }
-
- /**
- * Returns available space for writing to buffer.
- * Attempt to write more bytes than available results in RING_BUFFER_FULL.
- */
- unsigned int GetWriteSize()
- {
- return m_iSize - ( m_iWritten - m_iRead );
- }
-
- /**
- * Returns available space for reading from buffer.
- * Attempt to read more bytes than available results in RING_BUFFER_EMPTY.
- */
- unsigned int GetReadSize()
- {
- return m_iWritten - m_iRead;
- }
-
- /**
- * Returns the buffer size.
- */
- unsigned int GetMaxSize()
- {
- return m_iSize;
- }
-
-private:
- unsigned int m_iReadPos;
- unsigned int m_iWritePos;
- unsigned int m_iRead;
- unsigned int m_iWritten;
- unsigned int m_iSize;
- unsigned char *m_Buffer;
-};
2  xbmc/cores/AudioEngine/Utils/AERingBuffer.h
View
@@ -156,7 +156,7 @@ class AERingBuffer {
unsigned int space = GetReadSize();
//want to read more than we have written?
- if( space <= 0 )
+ if( space == 0 )
{
#ifdef AE_RING_BUFFER_DEBUG
CLog::Log(LOGDEBUG, "AERingBuffer: Can't read from empty buffer.");
Please sign in to comment.
Something went wrong with that request. Please try again.