Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dvdplayer: make CDVDAudioCodec return a DVDAudioPacket directly
  • Loading branch information
elupus committed Nov 10, 2013
1 parent 9a1313c commit 151b0a9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
2 changes: 1 addition & 1 deletion xbmc/cores/dvdplayer/DVDAudio.cpp
Expand Up @@ -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"
Expand Down
47 changes: 46 additions & 1 deletion xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodec.h
Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -59,11 +79,36 @@ class CDVDAudioCodec
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
*/
Expand Down
26 changes: 5 additions & 21 deletions xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
17 changes: 0 additions & 17 deletions xbmc/cores/dvdplayer/DVDPlayerAudio.h
Expand Up @@ -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:
Expand Down

0 comments on commit 151b0a9

Please sign in to comment.