dvdplayer: make CDVDAudioCodec return a DVDAudioPacket directly
authorJoakim Plate <elupus@ecce.se>
Sat, 9 Nov 2013 18:33:27 +0000 (19:33 +0100)
committerJoakim Plate <elupus@ecce.se>
Sun, 10 Nov 2013 15:28:24 +0000 (16:28 +0100)
xbmc/cores/dvdplayer/DVDAudio.cpp
xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodec.h
xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
xbmc/cores/dvdplayer/DVDPlayerAudio.h

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 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;
index 3cc0b78..4d5129b 100644 (file)
@@ -295,22 +295,14 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket)
       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)
       {
@@ -327,16 +319,8 @@ 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;
-      }
+      // increase audioclock to after the packet
+      m_audioClock += audioframe.duration;
 
       if(audioframe.duration > 0)
         m_duration = audioframe.duration;
index 2fccc2d..631d0cc 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: