Skip to content
This repository
Browse code

Merge pull request #3273 from FernetMenta/cuefile

paplayer fixes - all were tested by affected users in the testing thread
  • Loading branch information...
commit 92169a699b18a94b07d28e9d8a8aa5fd929c5f12 2 parents 0acee90 + 7093b1c
Peter Frühberger authored September 17, 2013
71  xbmc/cores/paplayer/PAPlayer.cpp
@@ -75,7 +75,8 @@ PAPlayer::PAPlayer(IPlayerCallback& callback) :
75 75
   m_currentStream      (NULL ),
76 76
   m_audioCallback      (NULL ),
77 77
   m_FileItem           (new CFileItem()),
78  
-  m_jobCounter         (0)
  78
+  m_jobCounter         (0),
  79
+  m_continueStream     (false)
79 80
 {
80 81
   memset(&m_playerGUIData, 0, sizeof(m_playerGUIData));
81 82
 }
@@ -276,7 +277,11 @@ bool PAPlayer::OpenFile(const CFileItem& file, const CPlayerOptions &options)
276 277
 
277 278
 void PAPlayer::UpdateCrossfadeTime(const CFileItem& file)
278 279
 {
279  
-  m_upcomingCrossfadeMS = m_defaultCrossfadeMS = CSettings::Get().GetInt("musicplayer.crossfade") * 1000;
  280
+  // we explicitely disable crossfading for audio cds
  281
+  if(file.IsCDDA())
  282
+   m_upcomingCrossfadeMS = 0;
  283
+  else
  284
+    m_upcomingCrossfadeMS = m_defaultCrossfadeMS = CSettings::Get().GetInt("musicplayer.crossfade") * 1000;
280 285
   if (m_upcomingCrossfadeMS)
281 286
   {
282 287
     if (m_streams.size() == 0 ||
@@ -310,6 +315,23 @@ bool PAPlayer::QueueNextFileEx(const CFileItem &file, bool fadeIn/* = true */, b
310 315
 {
311 316
   StreamInfo *si = new StreamInfo();
312 317
 
  318
+  // check if we advance a track of a CUE sheet
  319
+  // if this is the case we don't need to open a new stream
  320
+  if (file.GetPath().Equals(m_FileItem->GetPath()) &&
  321
+      file.m_lStartOffset &&
  322
+      file.m_lStartOffset == m_FileItem->m_lEndOffset &&
  323
+      m_currentStream && m_currentStream->m_prepareTriggered)
  324
+  {
  325
+    m_continueStream = true;
  326
+    m_upcomingCrossfadeMS = 0;
  327
+    *m_FileItem = file;
  328
+    return true;
  329
+  }
  330
+  else
  331
+  {
  332
+    m_continueStream = false;
  333
+  }
  334
+
313 335
   if (!si->m_decoder.Create(file, (file.m_lStartOffset * 1000) / 75))
314 336
   {
315 337
     CLog::Log(LOGWARNING, "PAPlayer::QueueNextFileEx - Failed to create the decoder");
@@ -369,8 +391,12 @@ bool PAPlayer::QueueNextFileEx(const CFileItem &file, bool fadeIn/* = true */, b
369 391
     streamTotalTime = si->m_endOffset - si->m_startOffset;
370 392
   
371 393
   si->m_prepareNextAtFrame = 0;
372  
-  if (streamTotalTime >= TIME_TO_CACHE_NEXT_FILE + m_defaultCrossfadeMS)
373  
-    si->m_prepareNextAtFrame = (int)((streamTotalTime - TIME_TO_CACHE_NEXT_FILE - m_defaultCrossfadeMS) * si->m_sampleRate / 1000.0f);
  394
+  // cd drives don't really like it to be crossfaded or prepared
  395
+  if(!file.IsCDDA())
  396
+  {
  397
+    if (streamTotalTime >= TIME_TO_CACHE_NEXT_FILE + m_defaultCrossfadeMS)
  398
+      si->m_prepareNextAtFrame = (int)((streamTotalTime - TIME_TO_CACHE_NEXT_FILE - m_defaultCrossfadeMS) * si->m_sampleRate / 1000.0f);
  399
+  }
374 400
 
375 401
   si->m_prepareTriggered = false;
376 402
 
@@ -708,8 +734,41 @@ inline bool PAPlayer::ProcessStream(StreamInfo *si, double &delay, double &buffe
708 734
       si->m_decoder.ReadSamples(PACKET_SIZE) == RET_ERROR ||
709 735
       ((si->m_endOffset) && (si->m_framesSent / si->m_sampleRate >= (si->m_endOffset - si->m_startOffset) / 1000)))
710 736
   {
711  
-    CLog::Log(LOGINFO, "PAPlayer::ProcessStream - Stream Finished");
712  
-    return false;
  737
+    if (si == m_currentStream && m_continueStream)
  738
+    {
  739
+      // update current stream with info of next track
  740
+      si->m_startOffset = m_FileItem->m_lStartOffset * 1000 / 75;
  741
+      if (m_FileItem->m_lEndOffset)
  742
+        si->m_endOffset = m_FileItem->m_lEndOffset * 1000 / 75;
  743
+      else
  744
+        si->m_endOffset = 0;
  745
+      si->m_framesSent = 0;
  746
+
  747
+      int64_t streamTotalTime = si->m_decoder.TotalTime() - si->m_startOffset;
  748
+      if (si->m_endOffset)
  749
+        streamTotalTime = si->m_endOffset - si->m_startOffset;
  750
+
  751
+      // calculate time when to prepare next stream
  752
+      si->m_prepareNextAtFrame = 0;
  753
+      if (streamTotalTime >= TIME_TO_CACHE_NEXT_FILE + m_defaultCrossfadeMS)
  754
+        si->m_prepareNextAtFrame = (int)((streamTotalTime - TIME_TO_CACHE_NEXT_FILE - m_defaultCrossfadeMS) * si->m_sampleRate / 1000.0f);
  755
+
  756
+      si->m_prepareTriggered = false;
  757
+      si->m_playNextAtFrame = 0;
  758
+      si->m_playNextTriggered = false;
  759
+
  760
+      //update the current stream to start playing the next track at the correct frame.
  761
+      UpdateStreamInfoPlayNextAtFrame(m_currentStream, m_upcomingCrossfadeMS);
  762
+
  763
+      UpdateGUIData(si);
  764
+      m_callback.OnPlayBackStarted();
  765
+      m_continueStream = false;
  766
+    }
  767
+    else
  768
+    {
  769
+      CLog::Log(LOGINFO, "PAPlayer::ProcessStream - Stream Finished");
  770
+      return false;
  771
+    }
713 772
   }
714 773
 
715 774
   if (!QueueData(si))
1  xbmc/cores/paplayer/PAPlayer.h
@@ -142,6 +142,7 @@ friend class CQueueNextFileJob;
142 142
   StreamList          m_finishing;           /* finishing streams */
143 143
   int                 m_jobCounter;
144 144
   CEvent              m_jobEvent;
  145
+  bool                m_continueStream;
145 146
 
146 147
   bool QueueNextFileEx(const CFileItem &file, bool fadeIn = true, bool job = false);
147 148
   void SoftStart(bool wait = false);

0 notes on commit 92169a6

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