Skip to content
This repository
Browse code

changed, audiotrack, add volume/drain locks, default volume to 1.0, r…

…emove AE_FMT_S16NE handling
  • Loading branch information...
commit c218d5c22c739cbc90bf36dc33863b4afa6eafd7 1 parent e565394
authored July 14, 2013
24  xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp
@@ -82,7 +82,7 @@ CAESinkAUDIOTRACK::CAESinkAUDIOTRACK()
82 82
   m_draining = false;
83 83
   m_audiotrackbuffer_sec = 0.0;
84 84
   m_audiotrack_empty_sec = 0.0;
85  
-  m_volume = 0.0;
  85
+  m_volume = 1.0;
86 86
 #if defined(HAS_AMLPLAYER) || defined(HAS_LIBAMCODEC)
87 87
   aml_cpufreq_limit(true);
88 88
 #endif
@@ -225,9 +225,7 @@ unsigned int CAESinkAUDIOTRACK::AddPackets(uint8_t *data, unsigned int frames, b
225 225
   {
226 226
     switch(m_format.m_dataFormat)
227 227
     {
228  
-      // 99.95 percent of Android is LE so treat NE the same.
229 228
       case AE_FMT_S16LE:
230  
-      case AE_FMT_S16NE:
231 229
         m_sinkbuffer->Write(data, write_frames * m_sink_frameSize);
232 230
         m_wake.Set();
233 231
         break;
@@ -251,6 +249,7 @@ unsigned int CAESinkAUDIOTRACK::AddPackets(uint8_t *data, unsigned int frames, b
251 249
 void CAESinkAUDIOTRACK::Drain()
252 250
 {
253 251
   CLog::Log(LOGDEBUG, "CAESinkAUDIOTRACK::Drain");
  252
+  CSingleLock lock(m_drain_lock);
254 253
   m_draining = true;
255 254
   m_wake.Set();
256 255
 }
@@ -266,7 +265,10 @@ void  CAESinkAUDIOTRACK::SetVolume(float scale)
266 265
   float gain = CAEUtil::ScaleToGain(scale);
267 266
   m_volume = CAEUtil::GainToPercent(gain);
268 267
   if (!m_passthrough)
  268
+  {
  269
+    CSingleLock lock(m_volume_lock);
269 270
     m_volume_changed = true;
  271
+  }
270 272
 }
271 273
 
272 274
 void CAESinkAUDIOTRACK::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
@@ -284,7 +286,6 @@ void CAESinkAUDIOTRACK::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
284 286
   m_info.m_sampleRates.push_back(44100);
285 287
   m_info.m_sampleRates.push_back(48000);
286 288
   m_info.m_dataFormats.push_back(AE_FMT_S16LE);
287  
-  m_info.m_dataFormats.push_back(AE_FMT_S16NE);
288 289
 #if defined(__ARM_NEON__)
289 290
   if (g_cpuInfo.GetCPUFeatures() & CPU_FEATURE_NEON)
290 291
     m_info.m_dataFormats.push_back(AE_FMT_FLOAT);
@@ -363,23 +364,30 @@ void CAESinkAUDIOTRACK::Process()
363 364
       // check of volume changes and make them,
364 365
       // do it here to keep jni calls local to this thread.
365 366
       CXBMCApp::SetSystemVolume(jenv, m_volume);
  367
+      CSingleLock lock(m_volume_lock);
366 368
       m_volume_changed = false;
367 369
     }
368 370
     if (m_draining)
369 371
     {
370 372
       unsigned char byte_drain[1024];
371  
-      unsigned int  byte_drain_size = m_sinkbuffer->GetReadSize() % 1024;
  373
+      unsigned int  byte_drain_size = m_sinkbuffer->GetReadSize();
  374
+      if (byte_drain_size > 1024)
  375
+        byte_drain_size = 1024;
372 376
       while (byte_drain_size)
373 377
       {
374 378
         m_sinkbuffer->Read(byte_drain, byte_drain_size);
375  
-        byte_drain_size = m_sinkbuffer->GetReadSize() % 1024;
  379
+        byte_drain_size = m_sinkbuffer->GetReadSize();
  380
+        if (byte_drain_size > 1024)
  381
+          byte_drain_size = 1024;
376 382
       }
377 383
       jenv->CallVoidMethod(joAudioTrack, jmStop);
378 384
       jenv->CallVoidMethod(joAudioTrack, jmFlush);
  385
+      CSingleLock lock(m_drain_lock);
  386
+      m_draining = false;
379 387
     }
380 388
 
381 389
     unsigned int read_bytes = m_sinkbuffer->GetReadSize();
382  
-    if (read_bytes > min_buffer_size)
  390
+    if (read_bytes > (unsigned int)min_buffer_size)
383 391
       read_bytes = min_buffer_size;
384 392
 
385 393
     if (read_bytes > 0)
@@ -388,7 +396,7 @@ void CAESinkAUDIOTRACK::Process()
388 396
       // check it and set playing if it does this. Do this before
389 397
       // writing into its buffer.
390 398
       if (jenv->CallIntMethod(joAudioTrack, jmPlayState) != playing)
391  
-        jenv->CallVoidMethod(joAudioTrack, jmPlay);
  399
+        jenv->CallVoidMethod( joAudioTrack, jmPlay);
392 400
 
393 401
       // Write a buffer of audio data to Java AudioTrack.
394 402
       // Warning, no other JNI function can be called after
3  xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.h
@@ -21,6 +21,7 @@
21 21
 
22 22
 #include "Interfaces/AESink.h"
23 23
 #include "Utils/AEDeviceInfo.h"
  24
+#include "threads/CriticalSection.h"
24 25
 
25 26
 class AERingBuffer;
26 27
 
@@ -52,6 +53,7 @@ class CAESinkAUDIOTRACK : public CThread, public IAESink
52 53
   AEAudioFormat      m_format;
53 54
   double             m_volume;
54 55
   bool               m_volume_changed;
  56
+  CCriticalSection   m_volume_lock;
55 57
   volatile int       m_min_frames;
56 58
   int16_t           *m_alignedS16;
57 59
   AERingBuffer      *m_sinkbuffer;
@@ -62,6 +64,7 @@ class CAESinkAUDIOTRACK : public CThread, public IAESink
62 64
   CEvent             m_wake;
63 65
   CEvent             m_inited;
64 66
   volatile bool      m_draining;
  67
+  CCriticalSection   m_drain_lock;
65 68
   bool               m_passthrough;
66 69
 
67 70
   double             m_audiotrackbuffer_sec;

0 notes on commit c218d5c

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