Merge pull request #3614 from elupus/audio_clean
authorJoakim Plate <elupus@ecce.se>
Mon, 11 Nov 2013 19:24:38 +0000 (11:24 -0800)
committerJoakim Plate <elupus@ecce.se>
Mon, 11 Nov 2013 19:24:38 +0000 (11:24 -0800)
DVDPlayerAudio cleanup

15 files changed:
XBMC.xcodeproj/project.pbxproj
project/VS2010Express/XBMC.vcxproj
project/VS2010Express/XBMC.vcxproj.filters
xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.cpp
xbmc/cores/VideoRenderers/RenderManager.cpp
xbmc/cores/dvdplayer/DVDAudio.cpp
xbmc/cores/dvdplayer/DVDClock.h
xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodec.h
xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp [deleted file]
xbmc/cores/dvdplayer/DVDPerformanceCounter.h [deleted file]
xbmc/cores/dvdplayer/DVDPlayer.cpp
xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
xbmc/cores/dvdplayer/DVDPlayerAudio.h
xbmc/cores/dvdplayer/DVDPlayerVideo.cpp
xbmc/cores/dvdplayer/Makefile.in

index 1ff209d..cfe592a 100644 (file)
                DFF0F19317528350002DA3A4 /* DVDMessageTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E157C0D25F9FA00618676 /* DVDMessageTracker.cpp */; };
                DFF0F19417528350002DA3A4 /* DVDOverlayContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E157E0D25F9FA00618676 /* DVDOverlayContainer.cpp */; };
                DFF0F19517528350002DA3A4 /* DVDOverlayRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15800D25F9FA00618676 /* DVDOverlayRenderer.cpp */; };
-               DFF0F19617528350002DA3A4 /* DVDPerformanceCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15820D25F9FA00618676 /* DVDPerformanceCounter.cpp */; };
                DFF0F19717528350002DA3A4 /* DVDPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15840D25F9FA00618676 /* DVDPlayer.cpp */; };
                DFF0F19817528350002DA3A4 /* DVDPlayerAudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15860D25F9FA00618676 /* DVDPlayerAudio.cpp */; };
                DFF0F19917528350002DA3A4 /* DVDPlayerSubtitle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15880D25F9FA00618676 /* DVDPlayerSubtitle.cpp */; };
                E38E1FA30D25F9FD00618676 /* DVDMessageTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E157C0D25F9FA00618676 /* DVDMessageTracker.cpp */; };
                E38E1FA40D25F9FD00618676 /* DVDOverlayContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E157E0D25F9FA00618676 /* DVDOverlayContainer.cpp */; };
                E38E1FA50D25F9FD00618676 /* DVDOverlayRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15800D25F9FA00618676 /* DVDOverlayRenderer.cpp */; };
-               E38E1FA60D25F9FD00618676 /* DVDPerformanceCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15820D25F9FA00618676 /* DVDPerformanceCounter.cpp */; };
                E38E1FA70D25F9FD00618676 /* DVDPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15840D25F9FA00618676 /* DVDPlayer.cpp */; };
                E38E1FA80D25F9FD00618676 /* DVDPlayerAudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15860D25F9FA00618676 /* DVDPlayerAudio.cpp */; };
                E38E1FA90D25F9FD00618676 /* DVDPlayerSubtitle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15880D25F9FA00618676 /* DVDPlayerSubtitle.cpp */; };
                E49911FB174E5D4500741B6D /* DVDMessageTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E157C0D25F9FA00618676 /* DVDMessageTracker.cpp */; };
                E49911FC174E5D4500741B6D /* DVDOverlayContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E157E0D25F9FA00618676 /* DVDOverlayContainer.cpp */; };
                E49911FD174E5D4500741B6D /* DVDOverlayRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15800D25F9FA00618676 /* DVDOverlayRenderer.cpp */; };
-               E49911FE174E5D4500741B6D /* DVDPerformanceCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15820D25F9FA00618676 /* DVDPerformanceCounter.cpp */; };
                E49911FF174E5D4500741B6D /* DVDPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15840D25F9FA00618676 /* DVDPlayer.cpp */; };
                E4991200174E5D4500741B6D /* DVDPlayerAudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15860D25F9FA00618676 /* DVDPlayerAudio.cpp */; };
                E4991201174E5D4500741B6D /* DVDPlayerSubtitle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E15880D25F9FA00618676 /* DVDPlayerSubtitle.cpp */; };
                E38E157F0D25F9FA00618676 /* DVDOverlayContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDOverlayContainer.h; sourceTree = "<group>"; };
                E38E15800D25F9FA00618676 /* DVDOverlayRenderer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDOverlayRenderer.cpp; sourceTree = "<group>"; };
                E38E15810D25F9FA00618676 /* DVDOverlayRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDOverlayRenderer.h; sourceTree = "<group>"; };
-               E38E15820D25F9FA00618676 /* DVDPerformanceCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDPerformanceCounter.cpp; sourceTree = "<group>"; };
-               E38E15830D25F9FA00618676 /* DVDPerformanceCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDPerformanceCounter.h; sourceTree = "<group>"; };
                E38E15840D25F9FA00618676 /* DVDPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDPlayer.cpp; sourceTree = "<group>"; };
                E38E15850D25F9FA00618676 /* DVDPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDPlayer.h; sourceTree = "<group>"; };
                E38E15860D25F9FA00618676 /* DVDPlayerAudio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDPlayerAudio.cpp; sourceTree = "<group>"; };
                                E38E157F0D25F9FA00618676 /* DVDOverlayContainer.h */,
                                E38E15800D25F9FA00618676 /* DVDOverlayRenderer.cpp */,
                                E38E15810D25F9FA00618676 /* DVDOverlayRenderer.h */,
-                               E38E15820D25F9FA00618676 /* DVDPerformanceCounter.cpp */,
-                               E38E15830D25F9FA00618676 /* DVDPerformanceCounter.h */,
                                E38E15840D25F9FA00618676 /* DVDPlayer.cpp */,
                                E38E15850D25F9FA00618676 /* DVDPlayer.h */,
                                E38E15860D25F9FA00618676 /* DVDPlayerAudio.cpp */,
                                E38E1FA30D25F9FD00618676 /* DVDMessageTracker.cpp in Sources */,
                                E38E1FA40D25F9FD00618676 /* DVDOverlayContainer.cpp in Sources */,
                                E38E1FA50D25F9FD00618676 /* DVDOverlayRenderer.cpp in Sources */,
-                               E38E1FA60D25F9FD00618676 /* DVDPerformanceCounter.cpp in Sources */,
                                E38E1FA70D25F9FD00618676 /* DVDPlayer.cpp in Sources */,
                                E38E1FA80D25F9FD00618676 /* DVDPlayerAudio.cpp in Sources */,
                                E38E1FA90D25F9FD00618676 /* DVDPlayerSubtitle.cpp in Sources */,
                                DFF0F19317528350002DA3A4 /* DVDMessageTracker.cpp in Sources */,
                                DFF0F19417528350002DA3A4 /* DVDOverlayContainer.cpp in Sources */,
                                DFF0F19517528350002DA3A4 /* DVDOverlayRenderer.cpp in Sources */,
-                               DFF0F19617528350002DA3A4 /* DVDPerformanceCounter.cpp in Sources */,
                                DFF0F19717528350002DA3A4 /* DVDPlayer.cpp in Sources */,
                                DFF0F19817528350002DA3A4 /* DVDPlayerAudio.cpp in Sources */,
                                DFF0F19917528350002DA3A4 /* DVDPlayerSubtitle.cpp in Sources */,
                                E49911FB174E5D4500741B6D /* DVDMessageTracker.cpp in Sources */,
                                E49911FC174E5D4500741B6D /* DVDOverlayContainer.cpp in Sources */,
                                E49911FD174E5D4500741B6D /* DVDOverlayRenderer.cpp in Sources */,
-                               E49911FE174E5D4500741B6D /* DVDPerformanceCounter.cpp in Sources */,
                                E49911FF174E5D4500741B6D /* DVDPlayer.cpp in Sources */,
                                E4991200174E5D4500741B6D /* DVDPlayerAudio.cpp in Sources */,
                                E4991201174E5D4500741B6D /* DVDPlayerSubtitle.cpp in Sources */,
index 8227280..9c5dddf 100644 (file)
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDMessageTracker.cpp" />
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDOverlayContainer.cpp" />
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDOverlayRenderer.cpp" />
-    <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDPerformanceCounter.cpp" />
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDPlayer.cpp" />
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDPlayerAudio.cpp" />
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDPlayerSubtitle.cpp" />
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDMessageTracker.h" />
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDOverlayContainer.h" />
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDOverlayRenderer.h" />
-    <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDPerformanceCounter.h" />
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDPlayer.h" />
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDPlayerAudio.h" />
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDPlayerSubtitle.h" />
index c3802c8..f525969 100644 (file)
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDOverlayRenderer.cpp">
       <Filter>cores\dvdplayer</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDPerformanceCounter.cpp">
-      <Filter>cores\dvdplayer</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\xbmc\cores\dvdplayer\DVDPlayer.cpp">
       <Filter>cores\dvdplayer</Filter>
     </ClCompile>
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDOverlayRenderer.h">
       <Filter>cores\dvdplayer</Filter>
     </ClInclude>
-    <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDPerformanceCounter.h">
-      <Filter>cores\dvdplayer</Filter>
-    </ClInclude>
     <ClInclude Include="..\..\xbmc\cores\dvdplayer\DVDPlayer.h">
       <Filter>cores\dvdplayer</Filter>
     </ClInclude>
index 400ff91..d606d83 100644 (file)
@@ -380,6 +380,9 @@ unsigned int CCoreAudioAEStream::AddData(void *data, unsigned int size)
   unsigned int addsize  = size;
   unsigned int channelsInBuffer = m_chLayoutCountStream;
 
+  if (m_flushRequested && m_paused)
+    InternalFlush();
+
   if (!m_valid || size == 0 || data == NULL || !m_Buffer || m_flushRequested)
     return 0;
 
index 6c8eef5..583cc9d 100644 (file)
@@ -166,14 +166,6 @@ void CXBMCRenderManager::WaitPresentTime(double presenttime)
     return;
   }
 
-  bool ismaster = CDVDClock::IsMasterClock();
-
-  //the videoreferenceclock updates its clock on every vertical blank
-  //we want every frame's presenttime to end up in the middle of two vblanks
-  //if CDVDPlayerAudio is the master clock, we add a correction to the presenttime
-  if (ismaster)
-    presenttime += m_presentcorr * frametime;
-
   double clock     = CDVDClock::WaitAbsoluteClock(presenttime * DVD_TIME_BASE) / DVD_TIME_BASE;
   double target    = 0.5;
   double error     = ( clock - presenttime ) / frametime - target;
@@ -203,20 +195,11 @@ void CXBMCRenderManager::WaitPresentTime(double presenttime)
   avgerror /= ERRORBUFFSIZE;
 
 
-  //if CDVDPlayerAudio is not the master clock, we change the clock speed slightly
+  //we change the clock speed slightly
   //to make every frame's presenttime end up in the middle of two vblanks
-  if (!ismaster)
-  {
-    //integral correction, clamp to -0.5:0.5 range
-    m_presentcorr = std::max(std::min(m_presentcorr + avgerror * 0.01, 0.1), -0.1);
-    g_VideoReferenceClock.SetFineAdjust(1.0 - avgerror * 0.01 - m_presentcorr * 0.01);
-  }
-  else
-  {
-    //integral correction, wrap to -0.5:0.5 range
-    m_presentcorr = wrap(m_presentcorr + avgerror * 0.01, target - 1.0, target);
-    g_VideoReferenceClock.SetFineAdjust(1.0);
-  }
+  //integral correction, clamp to -0.5:0.5 range
+  m_presentcorr = std::max(std::min(m_presentcorr + avgerror * 0.01, 0.1), -0.1);
+  g_VideoReferenceClock.SetFineAdjust(1.0 - avgerror * 0.01 - m_presentcorr * 0.01);
 
   //printf("%f %f % 2.0f%% % f % f\n", presenttime, clock, m_presentcorr * 100, error, error_org);
 }
index 3d3d3f7..b53d187 100644 (file)
@@ -23,7 +23,7 @@
 #include "DVDAudio.h"
 #include "DVDClock.h"
 #include "DVDCodecs/DVDCodecs.h"
-#include "DVDPlayerAudio.h"
+#include "DVDCodecs/Audio/DVDAudioCodec.h"
 #include "cores/AudioEngine/AEFactory.h"
 #include "cores/AudioEngine/Interfaces/AEStream.h"
 #include "settings/MediaSettings.h"
index 4df0c58..a7bdecc 100644 (file)
@@ -61,11 +61,6 @@ public:
   static double GetFrequency() { return (double)m_systemFrequency ; }
   static double WaitAbsoluteClock(double target);
 
-  //when m_ismasterclock is true, CDVDPlayerAudio synchronizes the clock to the audio stream
-  //when it's false, CDVDPlayerAudio synchronizes the audio stream to the clock
-  //the rendermanager needs to know about that because it can synchronize the videoreferenceclock to the video timestamps
-  static void SetMasterClock(bool ismasterclock) { m_ismasterclock = ismasterclock; }
-  static bool IsMasterClock()                    { return m_ismasterclock;          }
   static CDVDClock* GetMasterClock();
 protected:
   static void   CheckSystemClock();
index 9298f9e..08839ee 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "system.h"
 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
+#include "cores/AudioEngine/Utils/AEUtil.h"
+#include "DVDClock.h"
+
 
 #if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
   #include "config.h"
@@ -35,6 +38,23 @@ class CDVDStreamInfo;
 class CDVDCodecOption;
 class CDVDCodecOptions;
 
+typedef struct stDVDAudioFrame
+{
+  uint8_t*          data;
+  double            pts;
+  double            duration;
+  unsigned int      size;
+
+  int               channel_count;
+  int               encoded_channel_count;
+  CAEChannelInfo    channel_layout;
+  enum AEDataFormat data_format;
+  int               bits_per_sample;
+  int               sample_rate;
+  int               encoded_sample_rate;
+  bool              passthrough;
+} DVDAudioFrame;
+
 class CDVDAudioCodec
 {
 public:
@@ -59,12 +79,37 @@ public:
   virtual int Decode(uint8_t* pData, int iSize) = 0;
 
   /*
-   * returns nr of bytes used or -1 on error
+   * returns nr of bytes in decode buffer
    * the data is valid until the next Decode call
    */
   virtual int GetData(uint8_t** dst) = 0;
 
   /*
+   * the data is valid until the next Decode call
+   */
+  virtual void GetData(DVDAudioFrame &frame)
+  {
+    frame.size                  = GetData(&frame.data);
+    if(frame.size == 0u)
+      return;
+    frame.channel_layout        = GetChannelMap();
+    frame.channel_count         = GetChannels();
+    frame.encoded_channel_count = GetEncodedChannels();
+    frame.data_format           = GetDataFormat();
+    frame.bits_per_sample       = CAEUtil::DataFormatToBits(frame.data_format);
+    frame.sample_rate           = GetSampleRate();
+    frame.encoded_sample_rate   = GetEncodedSampleRate();
+    frame.passthrough           = NeedPassthrough();
+    frame.pts                   = DVD_NOPTS_VALUE;
+    // compute duration.
+    int n = (frame.channel_count * frame.bits_per_sample * frame.sample_rate)>>3;
+    if (n)
+      frame.duration = ((double)frame.size * DVD_TIME_BASE) / n;
+    else
+      frame.duration = 0.0;
+  }
+
+  /*
    * resets the decoder
    */
   virtual void Reset() = 0;
diff --git a/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp b/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp
deleted file mode 100644 (file)
index af1ff00..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- *      Copyright (C) 2005-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/>.
- *
- */
-
-#include "DVDPerformanceCounter.h"
-#include "DVDMessageQueue.h"
-#include "utils/TimeUtils.h"
-
-#include "dvd_config.h"
-
-#ifdef DVDDEBUG_WITH_PERFORMANCE_COUNTER
-#include <xbdm.h>
-#endif
-
-HRESULT __stdcall DVDPerformanceCounterAudioQueue(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
-{
-  numerator->QuadPart = 0LL;
-  //g_dvdPerformanceCounter.Lock();
-  if (g_dvdPerformanceCounter.m_pAudioQueue)
-  {
-    int iSize     = g_dvdPerformanceCounter.m_pAudioQueue->GetDataSize();
-    int iMaxSize  = g_dvdPerformanceCounter.m_pAudioQueue->GetMaxDataSize();
-    if (iMaxSize > 0)
-    {
-      int iPercent  = (iSize * 100) / iMaxSize;
-      if (iPercent > 100) iPercent = 100;
-      numerator->QuadPart = iPercent;
-    }
-  }
-  //g_dvdPerformanceCounter.Unlock();
-  return S_OK;
-}
-
-HRESULT __stdcall DVDPerformanceCounterVideoQueue(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
-{
-  numerator->QuadPart = 0LL;
-  //g_dvdPerformanceCounter.Lock();
-  if (g_dvdPerformanceCounter.m_pVideoQueue)
-  {
-    int iSize     = g_dvdPerformanceCounter.m_pVideoQueue->GetDataSize();
-    int iMaxSize  = g_dvdPerformanceCounter.m_pVideoQueue->GetMaxDataSize();
-    if (iMaxSize > 0)
-    {
-      int iPercent  = (iSize * 100) / iMaxSize;
-      if (iPercent > 100) iPercent = 100;
-      numerator->QuadPart = iPercent;
-    }
-  }
-  //g_dvdPerformanceCounter.Unlock();
-  return S_OK;
-}
-
-inline int64_t get_thread_cpu_usage(ProcessPerformance* p)
-{
-  if (p->thread)
-  {
-    ULARGE_INTEGER old_time_thread;
-    ULARGE_INTEGER old_time_system;
-
-    old_time_thread.QuadPart = p->timer_thread.QuadPart;
-    old_time_system.QuadPart = p->timer_system.QuadPart;
-
-    p->timer_thread.QuadPart = p->thread->GetAbsoluteUsage();
-    p->timer_system.QuadPart = CurrentHostCounter();
-
-    int64_t threadTime = (p->timer_thread.QuadPart - old_time_thread.QuadPart);
-    int64_t systemTime = (p->timer_system.QuadPart - old_time_system.QuadPart);
-
-    if (systemTime > 0 && threadTime > 0) return ((threadTime * 100) / systemTime);
-  }
-  return 0LL;
-}
-
-HRESULT __stdcall DVDPerformanceCounterVideoDecodePerformance(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
-{
-  //g_dvdPerformanceCounter.Lock();
-  numerator->QuadPart = get_thread_cpu_usage(&g_dvdPerformanceCounter.m_videoDecodePerformance);
-  //g_dvdPerformanceCounter.Unlock();
-  return S_OK;
-}
-
-HRESULT __stdcall DVDPerformanceCounterAudioDecodePerformance(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
-{
-  //g_dvdPerformanceCounter.Lock();
-  numerator->QuadPart = get_thread_cpu_usage(&g_dvdPerformanceCounter.m_audioDecodePerformance);
-  //g_dvdPerformanceCounter.Unlock();
-  return S_OK;
-}
-
-HRESULT __stdcall DVDPerformanceCounterMainPerformance(PLARGE_INTEGER numerator, PLARGE_INTEGER demoninator)
-{
-  //g_dvdPerformanceCounter.Lock();
-  numerator->QuadPart = get_thread_cpu_usage(&g_dvdPerformanceCounter.m_mainPerformance);
-  //g_dvdPerformanceCounter.Unlock();
-  return S_OK;
-}
-
-CDVDPerformanceCounter g_dvdPerformanceCounter;
-
-CDVDPerformanceCounter::CDVDPerformanceCounter()
-{
-  m_pAudioQueue = NULL;
-  m_pVideoQueue = NULL;
-
-  memset(&m_videoDecodePerformance, 0, sizeof(m_videoDecodePerformance)); // video decoding
-  memset(&m_audioDecodePerformance, 0, sizeof(m_audioDecodePerformance)); // audio decoding + output to audio device
-  memset(&m_mainPerformance,        0, sizeof(m_mainPerformance));        // reading files, demuxing, decoding of subtitles + menu overlays
-
-  Initialize();
-}
-
-CDVDPerformanceCounter::~CDVDPerformanceCounter()
-{
-  DeInitialize();
-}
-
-bool CDVDPerformanceCounter::Initialize()
-{
-  CSingleLock lock(m_critSection);
-
-#ifdef DVDDEBUG_WITH_PERFORMANCE_COUNTER
-
-  DmRegisterPerformanceCounter("DVDAudioQueue",               DMCOUNT_SYNC, DVDPerformanceCounterAudioQueue);
-  DmRegisterPerformanceCounter("DVDVideoQueue",               DMCOUNT_SYNC, DVDPerformanceCounterVideoQueue);
-  DmRegisterPerformanceCounter("DVDVideoDecodePerformance",   DMCOUNT_SYNC, DVDPerformanceCounterVideoDecodePerformance);
-  DmRegisterPerformanceCounter("DVDAudioDecodePerformance",   DMCOUNT_SYNC, DVDPerformanceCounterAudioDecodePerformance);
-  DmRegisterPerformanceCounter("DVDMainPerformance",          DMCOUNT_SYNC, DVDPerformanceCounterMainPerformance);
-
-#endif
-
-  return true;
-}
-
-void CDVDPerformanceCounter::DeInitialize()
-{
-
-}
-
diff --git a/xbmc/cores/dvdplayer/DVDPerformanceCounter.h b/xbmc/cores/dvdplayer/DVDPerformanceCounter.h
deleted file mode 100644 (file)
index b57d9e6..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#pragma once
-
-/*
- *      Copyright (C) 2005-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 FILETIME_TO_ULARGE_INTEGER(ularge, filetime) { ularge.u.HighPart = filetime.dwHighDateTime; ularge.u.LowPart = filetime.dwLowDateTime; }
-
-#include "system.h"
-#include "threads/Thread.h"
-#include "threads/SingleLock.h"
-
-class CDVDMessageQueue;
-
-typedef struct stProcessPerformance
-{
-  ULARGE_INTEGER  timer_thread;
-  ULARGE_INTEGER  timer_system;
-  CThread*        thread;
-} ProcessPerformance;
-
-class CDVDPerformanceCounter
-{
-public:
-  CDVDPerformanceCounter();
-  ~CDVDPerformanceCounter();
-
-  bool Initialize();
-  static void DeInitialize();
-
-  void EnableAudioQueue(CDVDMessageQueue* pQueue)     { CSingleLock lock(m_critSection); m_pAudioQueue = pQueue; }
-  void DisableAudioQueue()                            { CSingleLock lock(m_critSection); m_pAudioQueue = NULL;  }
-
-  void EnableVideoQueue(CDVDMessageQueue* pQueue)     { CSingleLock lock(m_critSection); m_pVideoQueue = pQueue;  }
-  void DisableVideoQueue()                            { CSingleLock lock(m_critSection); m_pVideoQueue = NULL;  }
-
-  void EnableVideoDecodePerformance(CThread *thread)  { CSingleLock lock(m_critSection); m_videoDecodePerformance.thread = thread;  }
-  void DisableVideoDecodePerformance()                { CSingleLock lock(m_critSection); m_videoDecodePerformance.thread = NULL;  }
-
-  void EnableAudioDecodePerformance(CThread *thread)  { CSingleLock lock(m_critSection); m_audioDecodePerformance.thread = thread;  }
-  void DisableAudioDecodePerformance()                { CSingleLock lock(m_critSection); m_audioDecodePerformance.thread = NULL;  }
-
-  void EnableMainPerformance(CThread *thread)         { CSingleLock lock(m_critSection); m_mainPerformance.thread = thread;  }
-  void DisableMainPerformance()                       { CSingleLock lock(m_critSection); m_mainPerformance.thread = NULL;  }
-
-  CDVDMessageQueue*         m_pAudioQueue;
-  CDVDMessageQueue*         m_pVideoQueue;
-
-  ProcessPerformance        m_videoDecodePerformance;
-  ProcessPerformance        m_audioDecodePerformance;
-  ProcessPerformance        m_mainPerformance;
-
-private:
-  CCriticalSection m_critSection;
-};
-
-extern CDVDPerformanceCounter g_dvdPerformanceCounter;
-
index bf36e1d..32c5abf 100644 (file)
@@ -49,7 +49,6 @@
 #include "guilib/StereoscopicsManager.h"
 #include "Application.h"
 #include "ApplicationMessenger.h"
-#include "DVDPerformanceCounter.h"
 #include "filesystem/File.h"
 #include "pictures/Picture.h"
 #include "DllSwScale.h"
@@ -642,7 +641,6 @@ void CDVDPlayer::OnStartup()
 
   m_messenger.Init();
 
-  g_dvdPerformanceCounter.EnableMainPerformance(this);
   CUtil::ClearTempFonts();
 }
 
@@ -2039,8 +2037,6 @@ void CDVDPlayer::SendPlayerMessage(CDVDMsg* pMsg, unsigned int target)
 
 void CDVDPlayer::OnExit()
 {
-  g_dvdPerformanceCounter.DisableMainPerformance();
-
   try
   {
     CLog::Log(LOGNOTICE, "CDVDPlayer::OnExit()");
index 0fb9dcf..f9ce725 100644 (file)
@@ -24,7 +24,6 @@
 #include "DVDCodecs/Audio/DVDAudioCodec.h"
 #include "DVDCodecs/DVDCodecs.h"
 #include "DVDCodecs/DVDFactoryCodec.h"
-#include "DVDPerformanceCounter.h"
 #include "settings/Settings.h"
 #include "video/VideoReferenceClock.h"
 #include "utils/log.h"
@@ -35,6 +34,7 @@
 
 #include <sstream>
 #include <iomanip>
+#include <math.h>
 
 /* for sync-based resampling */
 #define PROPORTIONAL 20.0
@@ -107,37 +107,28 @@ CDVDPlayerAudio::CDVDPlayerAudio(CDVDClock* pClock, CDVDMessageQueue& parent)
   m_pClock = pClock;
   m_pAudioCodec = NULL;
   m_audioClock = 0;
-  m_droptime = 0;
   m_speed = DVD_PLAYSPEED_NORMAL;
   m_stalled = true;
   m_started = false;
   m_silence = false;
-  m_duration = 0.0;
   m_resampleratio = 1.0;
   m_synctype = SYNC_DISCON;
   m_setsynctype = SYNC_DISCON;
   m_prevsynctype = -1;
   m_error = 0;
-  m_errorbuff = 0;
-  m_errorcount = 0;
+  m_errors.Flush();
   m_syncclock = true;
   m_integral = 0;
-  m_skipdupcount = 0;
   m_prevskipped = false;
   m_maxspeedadjust = 0.0;
 
-  m_errortime = 0;
-  m_freq = CurrentHostFrequency();
-
   m_messageQueue.SetMaxDataSize(6 * 1024 * 1024);
   m_messageQueue.SetMaxTimeSize(8.0);
-  g_dvdPerformanceCounter.EnableAudioQueue(&m_messageQueue);
 }
 
 CDVDPlayerAudio::~CDVDPlayerAudio()
 {
   StopThread();
-  g_dvdPerformanceCounter.DisableAudioQueue();
 
   // close the stream, and don't wait for the audio to be finished
   // CloseStream(true);
@@ -187,7 +178,6 @@ void CDVDPlayerAudio::OpenStream( CDVDStreamInfo &hints, CDVDAudioCodec* codec )
   if (hints.samplerate != m_streaminfo.samplerate)
     SwitchCodecIfNeeded();
 
-  m_droptime = 0;
   m_audioClock = 0;
   m_stalled = m_messageQueue.GetPacketCount(CDVDMsg::DEMUXER_PACKET) == 0;
   m_started = false;
@@ -199,13 +189,10 @@ void CDVDPlayerAudio::OpenStream( CDVDStreamInfo &hints, CDVDAudioCodec* codec )
   m_prevsynctype = -1;
 
   m_error = 0;
-  m_errorbuff = 0;
-  m_errorcount = 0;
+  m_errors.Flush();
   m_integral = 0;
-  m_skipdupcount = 0;
   m_prevskipped = false;
   m_syncclock = true;
-  m_errortime = CurrentHostCounter();
   m_silence = false;
 
   m_maxspeedadjust = CSettings::Get().GetNumber("videoplayer.maxspeedadjust");
@@ -254,7 +241,7 @@ void CDVDPlayerAudio::CloseStream(bool bWaitForBuffers)
 }
 
 // decode one audio frame and returns its uncompressed size
-int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
+int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, int priority)
 {
   int result = 0;
 
@@ -276,44 +263,28 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
         m_audioClock = dts;
 
       int len = m_pAudioCodec->Decode(m_decode.data, m_decode.size);
-      m_audioStats.AddSampleBytes(m_decode.size);
-      if (len < 0)
+      if (len < 0 || len > m_decode.size)
       {
         /* if error, we skip the packet */
-        CLog::Log(LOGERROR, "CDVDPlayerAudio::DecodeFrame - Decode Error. Skipping audio packet");
+        CLog::Log(LOGERROR, "CDVDPlayerAudio::DecodeFrame - Decode Error. Skipping audio packet (%d)", len);
         m_decode.Release();
         m_pAudioCodec->Reset();
         return DECODE_FLAG_ERROR;
       }
 
-      // fix for fucked up decoders
-      if( len > m_decode.size )
-      {
-        CLog::Log(LOGERROR, "CDVDPlayerAudio:DecodeFrame - Codec tried to consume more data than available. Potential memory corruption");
-        m_decode.Release();
-        m_pAudioCodec->Reset();
-        return DECODE_FLAG_ERROR;
-      }
+      m_audioStats.AddSampleBytes(len);
 
       m_decode.data += len;
       m_decode.size -= len;
 
-
       // get decoded data and the size of it
-      audioframe.size = m_pAudioCodec->GetData(&audioframe.data);
-      audioframe.pts  = m_audioClock;
+      m_pAudioCodec->GetData(audioframe);
 
       if (audioframe.size == 0)
         continue;
 
-      audioframe.channel_layout        = m_pAudioCodec->GetChannelMap();
-      audioframe.channel_count         = m_pAudioCodec->GetChannels();
-      audioframe.encoded_channel_count = m_pAudioCodec->GetEncodedChannels();
-      audioframe.data_format           = m_pAudioCodec->GetDataFormat();
-      audioframe.bits_per_sample       = CAEUtil::DataFormatToBits(audioframe.data_format);
-      audioframe.sample_rate           = m_pAudioCodec->GetSampleRate();
-      audioframe.encoded_sample_rate   = m_pAudioCodec->GetEncodedSampleRate();
-      audioframe.passthrough           = m_pAudioCodec->NeedPassthrough();
+      if (audioframe.pts == DVD_NOPTS_VALUE)
+        audioframe.pts = m_audioClock;
 
       if (m_streaminfo.samplerate != audioframe.encoded_sample_rate)
       {
@@ -330,28 +301,11 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
         }
       }
 
-      // compute duration.
-      int n = (audioframe.channel_count * audioframe.bits_per_sample * audioframe.sample_rate)>>3;
-      if (n > 0)
-      {
-        // safety check, if channels == 0, n will result in 0, and that will result in a nice devide exception
-        audioframe.duration = ((double)audioframe.size * DVD_TIME_BASE) / n;
-
-        // increase audioclock to after the packet
-        m_audioClock += audioframe.duration;
-      }
-
-      if(audioframe.duration > 0)
-        m_duration = audioframe.duration;
+      // increase audioclock to after the packet
+      m_audioClock += audioframe.duration;
 
       // if demux source want's us to not display this, continue
       if(m_decode.msg->GetPacketDrop())
-        continue;
-
-      //If we are asked to drop this packet, return a size of zero. then it won't be played
-      //we currently still decode the audio.. this is needed since we still need to know it's
-      //duration to make sure clock is updated correctly.
-      if( bDropPacket )
         result |= DECODE_FLAG_DROP;
 
       return result;
@@ -362,13 +316,7 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
     if (m_messageQueue.ReceivedAbortRequest()) return DECODE_FLAG_ABORT;
 
     CDVDMsg* pMsg;
-    int priority = (m_speed == DVD_PLAYSPEED_PAUSE && m_started) ? 1 : 0;
-
-    int timeout;
-    if(m_duration > 0)
-      timeout = (int)(1000 * (m_duration / DVD_TIME_BASE + m_dvdAudio.GetCacheTime()));
-    else
-      timeout = 1000;
+    int timeout  = (int)(1000 * m_dvdAudio.GetCacheTime()) + 100;
 
     // read next packet and return -1 on error
     MsgQueueReturnCode ret = m_messageQueue.Get(&pMsg, timeout, priority);
@@ -394,6 +342,9 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
     else if (pMsg->IsType(CDVDMsg::GENERAL_RESYNC))
     { //player asked us to set internal clock
       CDVDMsgGeneralResync* pMsgGeneralResync = (CDVDMsgGeneralResync*)pMsg;
+      CLog::Log(LOGDEBUG, "CDVDPlayerAudio - CDVDMsg::GENERAL_RESYNC(%f, %d)"
+                        , pMsgGeneralResync->m_timestamp
+                        , pMsgGeneralResync->m_clock);
 
       if (pMsgGeneralResync->m_timestamp != DVD_NOPTS_VALUE)
         m_audioClock = pMsgGeneralResync->m_timestamp;
@@ -401,12 +352,7 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
       m_ptsInput.Flush();
       m_dvdAudio.SetPlayingPts(m_audioClock);
       if (pMsgGeneralResync->m_clock)
-      {
-        CLog::Log(LOGDEBUG, "CDVDPlayerAudio - CDVDMsg::GENERAL_RESYNC(%f, 1)", m_audioClock);
         m_pClock->Discontinuity(m_dvdAudio.GetPlayingPts());
-      }
-      else
-        CLog::Log(LOGDEBUG, "CDVDPlayerAudio - CDVDMsg::GENERAL_RESYNC(%f, 0)", m_audioClock);
     }
     else if (pMsg->IsType(CDVDMsg::GENERAL_RESET))
     {
@@ -466,27 +412,26 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
     }
     else if (pMsg->IsType(CDVDMsg::PLAYER_SETSPEED))
     {
-      m_speed = static_cast<CDVDMsgInt*>(pMsg)->m_value;
+      double speed = static_cast<CDVDMsgInt*>(pMsg)->m_value;
 
-      if (m_speed == DVD_PLAYSPEED_NORMAL)
+      if (speed == DVD_PLAYSPEED_NORMAL)
       {
         m_dvdAudio.Resume();
       }
       else
       {
         m_syncclock = true;
-        if (m_speed != DVD_PLAYSPEED_PAUSE)
+        if (speed != DVD_PLAYSPEED_PAUSE)
           m_dvdAudio.Flush();
         m_dvdAudio.Pause();
       }
+      m_speed = speed;
     }
     else if (pMsg->IsType(CDVDMsg::AUDIO_SILENCE))
     {
       m_silence = static_cast<CDVDMsgBool*>(pMsg)->m_value;
-      if (m_silence)
-        CLog::Log(LOGDEBUG, "CDVDPlayerAudio - CDVDMsg::AUDIO_SILENCE(%f, 1)", m_audioClock);
-      else
-        CLog::Log(LOGDEBUG, "CDVDPlayerAudio - CDVDMsg::AUDIO_SILENCE(%f, 0)", m_audioClock);
+      CLog::Log(LOGDEBUG, "CDVDPlayerAudio - CDVDMsg::AUDIO_SILENCE(%f, %d)"
+                        , m_audioClock, m_silence);
     }
     else if (pMsg->IsType(CDVDMsg::GENERAL_STREAMCHANGE))
     {
@@ -504,8 +449,6 @@ void CDVDPlayerAudio::OnStartup()
 {
   m_decode.Release();
 
-  g_dvdPerformanceCounter.EnableAudioDecodePerformance(this);
-
 #ifdef TARGET_WINDOWS
   CoInitializeEx(NULL, COINIT_MULTITHREADED);
 #endif
@@ -540,9 +483,25 @@ void CDVDPlayerAudio::Process()
 
   while (!m_bStop)
   {
-    //Don't let anybody mess with our global variables
-    int result = DecodeFrame(audioframe, m_speed > DVD_PLAYSPEED_NORMAL || m_speed < 0 ||
-                         CAEFactory::IsSuspended()); // blocks if no audio is available, but leaves critical section before doing so
+    int priority;
+
+    //Do we want a new audio frame?
+    if (m_started == false                /* when not started */
+    ||  m_speed   == DVD_PLAYSPEED_NORMAL /* when playing normally */
+    ||  m_speed   <  DVD_PLAYSPEED_PAUSE  /* when rewinding */
+    || (m_speed   >  DVD_PLAYSPEED_NORMAL && m_audioClock < m_pClock->GetClock())) /* when behind clock in ff */
+      priority = 0;
+    else
+      priority = 1;
+
+    int result = DecodeFrame(audioframe, priority);
+
+    //Drop when not playing normally
+    if(m_speed   != DVD_PLAYSPEED_NORMAL
+    && m_started == true)
+    {
+      result |= DECODE_FLAG_DROP;
+    }
 
     UpdatePlayerInfo();
 
@@ -554,14 +513,12 @@ void CDVDPlayerAudio::Process()
 
     if( result & DECODE_FLAG_TIMEOUT )
     {
-      bool transitioningToStalled = !m_stalled;
-      m_stalled = true;
-
       // Flush as the audio output may keep looping if we don't
-      if(m_speed == DVD_PLAYSPEED_NORMAL && transitioningToStalled)
+      if(m_speed == DVD_PLAYSPEED_NORMAL && !m_stalled)
       {
         m_dvdAudio.Drain();
         m_dvdAudio.Flush();
+        m_stalled = true;
       }
 
       continue;
@@ -573,11 +530,6 @@ void CDVDPlayerAudio::Process()
       break;
     }
 
-#ifdef PROFILE /* during profiling we just drop all packets, after having decoded */
-    m_pClock->Discontinuity(audioframe.pts);
-    continue;
-#endif
-
     if( audioframe.size == 0 )
       continue;
 
@@ -604,24 +556,13 @@ void CDVDPlayerAudio::Process()
     if (m_silence)
       memset(audioframe.data, 0, audioframe.size);
 
-    if( result & DECODE_FLAG_DROP )
+    if(result & DECODE_FLAG_DROP)
     {
-      //frame should be dropped. Don't let audio move ahead of the current time thou
-      //we need to be able to start playing at any time
-      //when playing backwords, we try to keep as small buffers as possible
-
-      if(m_droptime == 0.0)
-        m_droptime = m_pClock->GetAbsoluteClock();
-      if(m_speed > 0)
-        m_droptime += audioframe.duration * DVD_PLAYSPEED_NORMAL / m_speed;
-      while( !m_bStop && m_droptime > m_pClock->GetAbsoluteClock() ) Sleep(1);
-
-      m_stalled = false;
+      // keep output times in sync
+     m_dvdAudio.SetPlayingPts(m_audioClock);
     }
     else
     {
-      m_droptime = 0.0;
-
       SetSyncType(audioframe.passthrough);
 
       // add any packets play
@@ -674,56 +615,30 @@ void CDVDPlayerAudio::SetSyncType(bool passthrough)
     CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: synctype set to %i: %s", m_synctype, synctypes[synctype]);
     m_prevsynctype = m_synctype;
   }
-
-  CDVDClock::SetMasterClock(false);
 }
 
 void CDVDPlayerAudio::HandleSyncError(double duration)
 {
   double clock = m_pClock->GetClock();
   double error = m_dvdAudio.GetPlayingPts() - clock;
-  int64_t now;
 
   if( fabs(error) > DVD_MSEC_TO_TIME(100) || m_syncclock )
   {
     m_pClock->Discontinuity(clock+error);
-    if(m_speed == DVD_PLAYSPEED_NORMAL)
-      CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Discontinuity1 - was:%f, should be:%f, error:%f", clock, clock+error, error);
+    CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Discontinuity1 - was:%f, should be:%f, error:%f", clock, clock+error, error);
 
-    m_errorbuff = 0;
-    m_errorcount = 0;
-    m_skipdupcount = 0;
+    m_errors.Flush();
     m_error = 0;
     m_syncclock = false;
-    m_errortime = CurrentHostCounter();
-
-    return;
-  }
 
-  if (m_speed != DVD_PLAYSPEED_NORMAL)
-  {
-    m_errorbuff = 0;
-    m_errorcount = 0;
-    m_integral = 0;
-    m_skipdupcount = 0;
-    m_error = 0;
-    m_errortime = CurrentHostCounter();
     return;
   }
 
-  m_errorbuff += error;
-  m_errorcount++;
+  m_errors.Add(error);
 
   //check if measured error for 2 seconds
-  now = CurrentHostCounter();
-  if ((now - m_errortime) >= m_freq * 2)
+  if (m_errors.Get(m_error))
   {
-    m_errortime = now;
-    m_error = m_errorbuff / m_errorcount;
-
-    m_errorbuff = 0;
-    m_errorcount = 0;
-
     if (m_synctype == SYNC_DISCON)
     {
       double limit, error;
@@ -748,25 +663,9 @@ void CDVDPlayerAudio::HandleSyncError(double duration)
       if (fabs(error) > limit - 0.001)
       {
         m_pClock->Discontinuity(clock+error);
-        if(m_speed == DVD_PLAYSPEED_NORMAL)
-          CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Discontinuity2 - was:%f, should be:%f, error:%f", clock, clock+error, error);
+        CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Discontinuity2 - was:%f, should be:%f, error:%f", clock, clock+error, error);
       }
     }
-    else if (m_synctype == SYNC_SKIPDUP && m_skipdupcount == 0 && fabs(m_error) > DVD_MSEC_TO_TIME(10))
-    {
-      //check how many packets to skip/duplicate
-      m_skipdupcount = (int)(m_error / duration);
-      //if less than one frame off, see if it's more than two thirds of a frame, so we can get better in sync
-      if (m_skipdupcount == 0 && fabs(m_error) > duration / 3 * 2)
-        m_skipdupcount = (int)(m_error / (duration / 3 * 2));
-
-      if (m_skipdupcount > 0)
-        CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Duplicating %i packet(s) of %.2f ms duration",
-                  m_skipdupcount, duration / DVD_TIME_BASE * 1000.0);
-      else if (m_skipdupcount < 0)
-        CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Skipping %i packet(s) of %.2f ms duration ",
-                  m_skipdupcount * -1,  duration / DVD_TIME_BASE * 1000.0);
-    }
     else if (m_synctype == SYNC_RESAMPLE)
     {
       //reset the integral on big errors, failsafe
@@ -774,6 +673,19 @@ void CDVDPlayerAudio::HandleSyncError(double duration)
         m_integral = 0;
       else if (fabs(m_error) > DVD_MSEC_TO_TIME(5))
         m_integral += m_error / DVD_TIME_BASE / INTEGRAL;
+
+      double proportional = 0.0;
+
+      //on big errors use more proportional
+      if (fabs(m_error / DVD_TIME_BASE) > 0.0)
+      {
+        double proportionaldiv = PROPORTIONAL * (PROPREF / fabs(m_error / DVD_TIME_BASE));
+        if (proportionaldiv < PROPDIVMIN) proportionaldiv = PROPDIVMIN;
+        else if (proportionaldiv > PROPDIVMAX) proportionaldiv = PROPDIVMAX;
+
+        proportional = m_error / DVD_TIME_BASE / proportionaldiv;
+      }
+      m_resampleratio = 1.0 / g_VideoReferenceClock.GetSpeed() + proportional + m_integral;
     }
   }
 }
@@ -786,41 +698,30 @@ bool CDVDPlayerAudio::OutputPacket(DVDAudioFrame &audioframe)
   }
   else if (m_synctype == SYNC_SKIPDUP)
   {
-    if (m_skipdupcount < 0)
+    double limit = std::max(DVD_MSEC_TO_TIME(10), audioframe.duration * 2.0 / 3.0);
+    if (m_error < -limit)
     {
       m_prevskipped = !m_prevskipped;
-      if (!m_prevskipped)
-      {
+      if (m_prevskipped)
         m_dvdAudio.AddPackets(audioframe);
-        m_skipdupcount++;
+      else
+      {
+        CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Dropping packet of %d ms", DVD_TIME_TO_MSEC(audioframe.duration));
+        m_error += audioframe.duration;
       }
     }
-    else if (m_skipdupcount > 0)
+    else if(m_error > limit)
     {
+      CLog::Log(LOGDEBUG, "CDVDPlayerAudio:: Duplicating packet of %d ms", DVD_TIME_TO_MSEC(audioframe.duration));
       m_dvdAudio.AddPackets(audioframe);
       m_dvdAudio.AddPackets(audioframe);
-      m_skipdupcount--;
+      m_error -= audioframe.duration;
     }
-    else if (m_skipdupcount == 0)
-    {
+    else
       m_dvdAudio.AddPackets(audioframe);
-    }
   }
   else if (m_synctype == SYNC_RESAMPLE)
   {
-    double proportional = 0.0;
-
-    //on big errors use more proportional
-    if (fabs(m_error / DVD_TIME_BASE) > 0.0)
-    {
-      double proportionaldiv = PROPORTIONAL * (PROPREF / fabs(m_error / DVD_TIME_BASE));
-      if (proportionaldiv < PROPDIVMIN) proportionaldiv = PROPDIVMIN;
-      else if (proportionaldiv > PROPDIVMAX) proportionaldiv = PROPDIVMAX;
-
-      proportional = m_error / DVD_TIME_BASE / proportionaldiv;
-    }
-
-    m_resampleratio = 1.0 / g_VideoReferenceClock.GetSpeed() + proportional + m_integral;
     m_dvdAudio.SetResampleRatio(m_resampleratio);
     m_dvdAudio.AddPackets(audioframe);
   }
@@ -830,8 +731,6 @@ bool CDVDPlayerAudio::OutputPacket(DVDAudioFrame &audioframe)
 
 void CDVDPlayerAudio::OnExit()
 {
-  g_dvdPerformanceCounter.DisableAudioDecodePerformance();
-
 #ifdef TARGET_WINDOWS
   CoUninitialize();
 #endif
index 2fccc2d..c5cfbf7 100644 (file)
@@ -44,23 +44,6 @@ class CDVDAudioCodec;
 #define DECODE_FLAG_ABORT   8
 #define DECODE_FLAG_TIMEOUT 16
 
-typedef struct stDVDAudioFrame
-{
-  uint8_t* data;
-  double pts;
-  double duration;
-  unsigned int size;
-
-  int               channel_count;
-  int               encoded_channel_count;
-  CAEChannelInfo    channel_layout;
-  enum AEDataFormat data_format;
-  int               bits_per_sample;
-  int               sample_rate;
-  int               encoded_sample_rate;
-  bool              passthrough;
-} DVDAudioFrame;
-
 class CPTSInputQueue
 {
 private:
@@ -73,6 +56,51 @@ public:
   void   Flush();
 };
 
+class CDVDErrorAverage
+{
+public:
+  CDVDErrorAverage()
+  {
+    Flush();
+  }
+  void    Add(double error)
+  {
+    m_buffer += error;
+    m_count++;
+  }
+
+  void    Flush()
+  {
+    m_buffer = 0.0f;
+    m_count  = 0;
+    m_timer.Set(2000);
+  }
+
+  double  Get()
+  {
+    if(m_count)
+      return m_buffer / m_count;
+    else
+      return 0.0;
+  }
+
+  bool    Get(double& error)
+  {
+    if(m_timer.IsTimePast())
+    {
+      error = Get();
+      Flush();
+      return true;
+    }
+    else
+      return false;
+  }
+
+  double               m_buffer; //place to store average errors
+  int                  m_count;  //number of errors stored
+  XbmcThreads::EndTime m_timer;
+};
+
 class CDVDPlayerAudio : public CThread
 {
 public:
@@ -124,7 +152,7 @@ protected:
   virtual void OnExit();
   virtual void Process();
 
-  int DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket);
+  int DecodeFrame(DVDAudioFrame &audioframe, int priority);
 
   void UpdatePlayerInfo();
 
@@ -179,10 +207,8 @@ protected:
   BitstreamStats m_audioStats;
 
   int     m_speed;
-  double  m_droptime;
   bool    m_stalled;
   bool    m_started;
-  double  m_duration; // last packets duration
   bool    m_silence;
 
   bool OutputPacket(DVDAudioFrame &audioframe);
@@ -194,17 +220,12 @@ protected:
 
   double m_error;    //last average error
 
-  int64_t m_errortime; //timestamp of last time we measured
-  int64_t m_freq;
-
   void   SetSyncType(bool passthrough);
   void   HandleSyncError(double duration);
-  double m_errorbuff; //place to store average errors
-  int    m_errorcount;//number of errors stored
+  CDVDErrorAverage m_errors;
   bool   m_syncclock;
 
   double m_integral; //integral correction for resampler
-  int    m_skipdupcount; //counter for skip/duplicate synctype
   bool   m_prevskipped;
   double m_maxspeedadjust;
   double m_resampleratio; //resample ratio when using SYNC_RESAMPLE, used for the codec info
index 2321d2c..2d7d0f1 100644 (file)
@@ -35,7 +35,6 @@
 #include "DVDDemuxers/DVDDemux.h"
 #include "DVDDemuxers/DVDDemuxUtils.h"
 #include "DVDOverlayRenderer.h"
-#include "DVDPerformanceCounter.h"
 #include "DVDCodecs/DVDCodecs.h"
 #include "DVDCodecs/Overlay/DVDOverlayCodecCC.h"
 #include "DVDCodecs/Overlay/DVDOverlaySSA.h"
@@ -147,7 +146,6 @@ CDVDPlayerVideo::CDVDPlayerVideo( CDVDClock* pClock
   m_iNrOfPicturesNotToSkip = 0;
   m_messageQueue.SetMaxDataSize(40 * 1024 * 1024);
   m_messageQueue.SetMaxTimeSize(8.0);
-  g_dvdPerformanceCounter.EnableVideoQueue(&m_messageQueue);
 
   m_iCurrentPts = DVD_NOPTS_VALUE;
   m_iDroppedFrames = 0;
@@ -166,7 +164,6 @@ CDVDPlayerVideo::CDVDPlayerVideo( CDVDClock* pClock
 CDVDPlayerVideo::~CDVDPlayerVideo()
 {
   StopThread();
-  g_dvdPerformanceCounter.DisableVideoQueue();
   g_VideoReferenceClock.StopThread();
 }
 
@@ -303,7 +300,6 @@ void CDVDPlayerVideo::OnStartup()
   m_iCurrentPts = DVD_NOPTS_VALUE;
   m_FlipTimeStamp = m_pClock->GetAbsoluteClock();
 
-  g_dvdPerformanceCounter.EnableVideoDecodePerformance(this);
 }
 
 void CDVDPlayerVideo::Process()
@@ -761,8 +757,6 @@ void CDVDPlayerVideo::Process()
 
 void CDVDPlayerVideo::OnExit()
 {
-  g_dvdPerformanceCounter.DisableVideoDecodePerformance();
-
   if (m_pOverlayCodecCC)
   {
     m_pOverlayCodecCC->Dispose();
index 6572157..564ab4b 100644 (file)
@@ -9,7 +9,6 @@ SRCS += DVDMessageQueue.cpp
 SRCS += DVDMessageTracker.cpp
 SRCS += DVDOverlayContainer.cpp
 SRCS += DVDOverlayRenderer.cpp
-SRCS += DVDPerformanceCounter.cpp
 SRCS += DVDPlayer.cpp
 SRCS += DVDPlayerAudio.cpp
 SRCS += DVDPlayerSubtitle.cpp