Skip to content
This repository
Browse code

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 authored
4  XBMC.xcodeproj/project.pbxproj
@@ -4070,6 +4070,7 @@
4070 4070
 		DF527732151BAF4C00B5B63B /* WebSocketV8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketV8.h; sourceTree = "<group>"; };
4071 4071
 		DF529BAC1741697B00523FB4 /* Environment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Environment.cpp; sourceTree = "<group>"; };
4072 4072
 		DF529BAD1741697B00523FB4 /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Environment.h; sourceTree = "<group>"; };
  4073
+		DF5EEEFB17CE977A003DEC49 /* AERingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AERingBuffer.h; sourceTree = "<group>"; };
4073 4074
 		DF64FE3516C07AAA00D028FB /* GUIViewControl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIViewControl.cpp; sourceTree = "<group>"; };
4074 4075
 		DF64FE3616C07AAA00D028FB /* GUIViewControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUIViewControl.h; sourceTree = "<group>"; };
4075 4076
 		DF64FE3716C07AAA00D028FB /* GUIViewState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIViewState.cpp; sourceTree = "<group>"; };
@@ -4184,7 +4185,6 @@
4184 4185
 		DFB65F7615373AE7006B8FF1 /* CoreAudioAESound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioAESound.h; path = CoreAudio/CoreAudioAESound.h; sourceTree = "<group>"; };
4185 4186
 		DFB65F7715373AE7006B8FF1 /* CoreAudioAEStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CoreAudioAEStream.cpp; path = CoreAudio/CoreAudioAEStream.cpp; sourceTree = "<group>"; };
4186 4187
 		DFB65F7815373AE7006B8FF1 /* CoreAudioAEStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioAEStream.h; path = CoreAudio/CoreAudioAEStream.h; sourceTree = "<group>"; };
4187  
-		DFB65F7915373AE7006B8FF1 /* CoreAudioRingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreAudioRingBuffer.h; path = CoreAudio/CoreAudioRingBuffer.h; sourceTree = "<group>"; };
4188 4188
 		DFB65F7A15373AE7006B8FF1 /* ICoreAudioAEHAL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ICoreAudioAEHAL.h; path = CoreAudio/ICoreAudioAEHAL.h; sourceTree = "<group>"; };
4189 4189
 		DFB65F7B15373AE7006B8FF1 /* ICoreAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ICoreAudioSource.h; path = CoreAudio/ICoreAudioSource.h; sourceTree = "<group>"; };
4190 4190
 		DFB65F8915373AE7006B8FF1 /* AE.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AE.h; sourceTree = "<group>"; };
@@ -7049,6 +7049,7 @@
7049 7049
 				DFB65FAC15373AE7006B8FF1 /* AEPackIEC61937.h */,
7050 7050
 				DFB65FAD15373AE7006B8FF1 /* AERemap.cpp */,
7051 7051
 				DFB65FAE15373AE7006B8FF1 /* AERemap.h */,
  7052
+				DF5EEEFB17CE977A003DEC49 /* AERingBuffer.h */,
7052 7053
 				DFB65FAF15373AE7006B8FF1 /* AEStreamInfo.cpp */,
7053 7054
 				DFB65FB015373AE7006B8FF1 /* AEStreamInfo.h */,
7054 7055
 				DFB65FB115373AE7006B8FF1 /* AEUtil.cpp */,
@@ -9218,7 +9219,6 @@
9218 9219
 				F5ED942D155D729500842059 /* CoreAudioHardware.h */,
9219 9220
 				F5ED9494155D7B9900842059 /* CoreAudioMixMap.cpp */,
9220 9221
 				F5ED9495155D7B9900842059 /* CoreAudioMixMap.h */,
9221  
-				DFB65F7915373AE7006B8FF1 /* CoreAudioRingBuffer.h */,
9222 9222
 				F5ED943C155D743700842059 /* CoreAudioStream.cpp */,
9223 9223
 				F5ED943D155D743700842059 /* CoreAudioStream.h */,
9224 9224
 				F5ED94A9155D7F8000842059 /* CoreAudioUnit.cpp */,
2  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.cpp
@@ -308,7 +308,7 @@ void CCoreAudioAEStream::Initialize()
308 308
   m_AvgBytesPerSec = m_OutputFormat.m_frameSize * m_OutputFormat.m_sampleRate;
309 309
 
310 310
   delete m_Buffer;
311  
-  m_Buffer = new CoreAudioRingBuffer(m_AvgBytesPerSec);
  311
+  m_Buffer = new AERingBuffer(m_AvgBytesPerSec);
312 312
 
313 313
   m_fadeRunning = false;
314 314
 
6  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.h
@@ -22,13 +22,13 @@
22 22
 #include <samplerate.h>
23 23
 #include <list>
24 24
 
25  
-#include "CoreAudioRingBuffer.h"
26 25
 #include "ICoreAudioSource.h"
27 26
 #include "cores/AudioEngine/AEAudioFormat.h"
28 27
 #include "cores/AudioEngine/Interfaces/AEStream.h"
29 28
 #include "cores/AudioEngine/Utils/AEConvert.h"
30 29
 #include "cores/AudioEngine/Utils/AERemap.h"
31 30
 #include "cores/AudioEngine/Utils/AELimiter.h"
  31
+#include "cores/AudioEngine/Utils/AERingBuffer.h"
32 32
 
33 33
 #if defined(TARGET_DARWIN_IOS)
34 34
 # include "CoreAudioAEHALIOS.h"
@@ -36,7 +36,7 @@
36 36
 # include "CoreAudioAEHALOSX.h"
37 37
 #endif
38 38
 
39  
-class CoreAudioRingBuffer;
  39
+class AERingBuffer;
40 40
 
41 41
 class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
42 42
 {
@@ -139,7 +139,7 @@ class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
139 139
 
140 140
   CAEConvert::AEConvertToFn m_convertFn;
141 141
 
142  
-  CoreAudioRingBuffer    *m_Buffer;
  142
+  AERingBuffer           *m_Buffer;
143 143
   float                  *m_convertBuffer;      /* buffer for converted data */
144 144
   int                     m_convertBufferSize;
145 145
   //float                  *m_resampleBuffer;     /* buffer for resample data */
253  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioRingBuffer.h
... ...
@@ -1,253 +0,0 @@
1  
-#pragma once
2  
-/*
3  
- *      Copyright (C) 2010-2013 Team XBMC
4  
- *      http://xbmc.org
5  
- *
6  
- *  This Program is free software; you can redistribute it and/or modify
7  
- *  it under the terms of the GNU General Public License as published by
8  
- *  the Free Software Foundation; either version 2, or (at your option)
9  
- *  any later version.
10  
- *
11  
- *  This Program is distributed in the hope that it will be useful,
12  
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  
- *  GNU General Public License for more details.
15  
- *
16  
- *  You should have received a copy of the GNU General Public License
17  
- *  along with XBMC; see the file COPYING.  If not, see
18  
- *  <http://www.gnu.org/licenses/>.
19  
- *
20  
- */
21  
-
22  
-#define RING_BUFFER_OK 0;
23  
-#define RING_BUFFER_EMPTY 1;
24  
-#define RING_BUFFER_FULL 2;
25  
-#define RING_BUFFER_NOTAVAILABLE 3;
26  
-
27  
-//#define RING_BUFFER_DEBUG
28  
-
29  
-#include "utils/log.h"  //CLog
30  
-#include <string.h>     //memset, memcpy
31  
-
32  
-/**
33  
- * This buffer can be used by one read and one write thread at any one time
34  
- * without the risk of data corruption.
35  
- * If you intend to call the Reset() method, please use Locks.
36  
- * All other operations are thread-safe.
37  
- */
38  
-class CoreAudioRingBuffer {
39  
-
40  
-public:
41  
-  CoreAudioRingBuffer() :
42  
-    m_iReadPos(0),
43  
-    m_iWritePos(0),
44  
-    m_iRead(0),
45  
-    m_iWritten(0),
46  
-    m_iSize(0),
47  
-    m_Buffer(NULL)
48  
-  {
49  
-  }
50  
-
51  
-  CoreAudioRingBuffer(unsigned int size) :
52  
-    m_iReadPos(0),
53  
-    m_iWritePos(0),
54  
-    m_iRead(0),
55  
-    m_iWritten(0),
56  
-    m_iSize(0),
57  
-    m_Buffer(NULL)
58  
-  {
59  
-    Create(size);
60  
-  }
61  
-
62  
-  ~CoreAudioRingBuffer()
63  
-  {
64  
-#ifdef RING_BUFFER_DEBUG
65  
-    CLog::Log(LOGDEBUG, "CoreAudioRingBuffer::~CoereAudioRingBuffer: Deleting buffer.");
66  
-#endif
67  
-    _aligned_free(m_Buffer);
68  
-  }
69  
-
70  
-  /**
71  
-   * Allocates space for buffer, and sets it's contents to 0.
72  
-   *
73  
-   * @return true on success, false otherwise
74  
-   */
75  
-  bool Create(int size)
76  
-  {
77  
-    m_Buffer =  (unsigned char*)_aligned_malloc(size,16);
78  
-    if ( m_Buffer )
79  
-    {
80  
-      m_iSize = size;
81  
-      memset(m_Buffer, 0, m_iSize);
82  
-      return true;
83  
-    }
84  
-    return false;
85  
-  }
86  
-
87  
-  /**
88  
-   * Fills the buffer with zeros and resets the pointers.
89  
-   * This method is not thread-safe, so before using this method
90  
-   * please acquire a Lock()
91  
-   */
92  
-  void Reset() {
93  
-#ifdef RING_BUFFER_DEBUG
94  
-    CLog::Log(LOGDEBUG, "CoereAudioRingBuffer::Reset: Buffer reset.");
95  
-#endif
96  
-    m_iWritten = 0;
97  
-    m_iRead = 0;
98  
-    m_iReadPos = 0;
99  
-    m_iWritePos = 0;
100  
-  }
101  
-
102  
-  /**
103  
-   * Writes data to buffer.
104  
-   * Attempt to write more bytes than available results in RING_BUFFER_FULL.
105  
-   *
106  
-   * @return RING_BUFFER_OK on success, otherwise an error code
107  
-   */
108  
-  int Write(unsigned char *src, unsigned int size)
109  
-  {
110  
-    unsigned int space = GetWriteSize();
111  
-
112  
-    //do we have enough space for all the data?
113  
-    if (size > space) {
114  
-#ifdef RING_BUFFER_DEBUG
115  
-    CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Not enough space, ignoring data. Requested: %u Available: %u",size, space);
116  
-#endif
117  
-      return RING_BUFFER_FULL;
118  
-    }
119  
-
120  
-    //no wrapping?
121  
-    if ( m_iSize > size + m_iWritePos )
122  
-    {
123  
-#ifdef RING_BUFFER_DEBUG
124  
-      CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Written to: %u size: %u space before: %u\n", m_iWritePos, size, space);
125  
-#endif
126  
-      memcpy(&(m_Buffer[m_iWritePos]), src, size);
127  
-      m_iWritePos+=size;
128  
-    }
129  
-    //need to wrap
130  
-    else
131  
-    {
132  
-      unsigned int first = m_iSize - m_iWritePos;
133  
-      unsigned int second = size - first;
134  
-#ifdef RING_BUFFER_DEBUG
135  
-      CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Written to (split) first: %u second: %u size: %u space before: %u\n", first, second, size, space);
136  
-#endif
137  
-      memcpy(&(m_Buffer[m_iWritePos]), src, first);
138  
-      memcpy(&(m_Buffer[0]), &src[first], second);
139  
-      m_iWritePos = second;
140  
-    }
141  
-
142  
-    //we can increase the write count now
143  
-    m_iWritten+=size;
144  
-    return RING_BUFFER_OK;
145  
-  }
146  
-
147  
-  /**
148  
-   * Reads data from buffer.
149  
-   * Attempt to read more bytes than available results in RING_BUFFER_NOTAVAILABLE.
150  
-   * Reading from empty buffer returns RING_BUFFER_EMPTY
151  
-   *
152  
-   * @return RING_BUFFER_OK on success, otherwise an error code
153  
-   */
154  
-  int Read(unsigned char *dest, unsigned int size)
155  
-  {
156  
-    unsigned int space = GetReadSize();
157  
-
158  
-    //want to read more than we have written?
159  
-    if( space == 0 )
160  
-    {
161  
-#ifdef RING_BUFFER_DEBUG
162  
-      CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Can't read from empty buffer.");
163  
-#endif
164  
-      return RING_BUFFER_EMPTY;
165  
-    }
166  
-
167  
-    //want to read more than we have available
168  
-    if( size > space )
169  
-    {
170  
-#ifdef RING_BUFFER_DEBUG
171  
-      CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Can't read %u bytes when we only have %u.", size, space);
172  
-#endif
173  
-      return RING_BUFFER_NOTAVAILABLE;
174  
-    }
175  
-
176  
-    //no wrapping?
177  
-    if ( size + m_iReadPos < m_iSize )
178  
-    {
179  
-#ifdef RING_BUFFER_DEBUG
180  
-      CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Reading from: %u size: %u space before: %u\n", m_iWritePos, size, space);
181  
-#endif
182  
-      memcpy(dest, &(m_Buffer[m_iReadPos]), size);
183  
-      m_iReadPos+=size;
184  
-    }
185  
-    //need to wrap
186  
-    else
187  
-    {
188  
-      unsigned int first = m_iSize - m_iReadPos;
189  
-      unsigned int second = size - first;
190  
-#ifdef RING_BUFFER_DEBUG
191  
-      CLog::Log(LOGDEBUG, "CoereAudioRingBuffer: Reading from (split) first: %u second: %u size: %u space before: %u\n", first, second, size, space);
192  
-#endif
193  
-      memcpy(dest, &(m_Buffer[m_iReadPos]), first);
194  
-      memcpy(&dest[first], &(m_Buffer[0]), second);
195  
-      m_iReadPos = second;
196  
-    }
197  
-    //we can increase the read count now
198  
-    m_iRead+=size;
199  
-
200  
-    return RING_BUFFER_OK;
201  
-  }
202  
-
203  
-  /**
204  
-   * Dumps the buffer.
205  
-   */
206  
-  void Dump()
207  
-  {
208  
-    unsigned char* bufferContents =  (unsigned char *)_aligned_malloc(m_iSize + 1,16);
209  
-    for (unsigned int i=0; i<m_iSize; i++) {
210  
-      if (i >= m_iReadPos && i<m_iWritePos)
211  
-        bufferContents[i] = m_Buffer[i];
212  
-      else
213  
-        bufferContents[i] = '_';
214  
-    }
215  
-    bufferContents[m_iSize] = '\0';
216  
-    CLog::Log(LOGDEBUG, "CoereAudioRingBuffer::Dump()\n%s",bufferContents);
217  
-    _aligned_free(bufferContents);
218  
-  }
219  
-
220  
-  /**
221  
-   * Returns available space for writing to buffer.
222  
-   * Attempt to write more bytes than available results in RING_BUFFER_FULL.
223  
-   */
224  
-  unsigned int GetWriteSize()
225  
-  {
226  
-    return m_iSize - ( m_iWritten - m_iRead );
227  
-  }
228  
-
229  
-  /**
230  
-   * Returns available space for reading from buffer.
231  
-   * Attempt to read more bytes than available results in RING_BUFFER_EMPTY.
232  
-   */
233  
-  unsigned int GetReadSize()
234  
-  {
235  
-    return m_iWritten - m_iRead;
236  
-  }
237  
-
238  
-  /**
239  
-   * Returns the buffer size.
240  
-   */
241  
-  unsigned int GetMaxSize()
242  
-  {
243  
-    return m_iSize;
244  
-  }
245  
-
246  
-private:
247  
-  unsigned int m_iReadPos;
248  
-  unsigned int m_iWritePos;
249  
-  unsigned int m_iRead;
250  
-  unsigned int m_iWritten;
251  
-  unsigned int m_iSize;
252  
-  unsigned char *m_Buffer;
253  
-};
2  xbmc/cores/AudioEngine/Utils/AERingBuffer.h
@@ -156,7 +156,7 @@ class AERingBuffer {
156 156
     unsigned int space = GetReadSize();
157 157
 
158 158
     //want to read more than we have written?
159  
-    if( space <= 0 )
  159
+    if( space == 0 )
160 160
     {
161 161
 #ifdef AE_RING_BUFFER_DEBUG
162 162
       CLog::Log(LOGDEBUG, "AERingBuffer: Can't read from empty buffer.");

0 notes on commit 18a4377

Please sign in to comment.
Something went wrong with that request. Please try again.