Skip to content

Commit

Permalink
VideoPlayer: make AudioCodecPassthrough handle pts
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Jan 21, 2016
1 parent 6a8744b commit 0ad4065
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
8 changes: 8 additions & 0 deletions xbmc/cores/AudioEngine/Utils/AEStreamInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ CAEStreamParser::~CAEStreamParser()
{
}

void CAEStreamParser::Reset()
{
m_skipBytes = 0;
m_bufferSize = 0;
m_needBytes = 0;
m_hasSync = false;
}

int CAEStreamParser::AddData(uint8_t *data, unsigned int size, uint8_t **buffer/* = NULL */, unsigned int *bufferSize/* = 0 */)
{
if (size == 0)
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/Utils/AEStreamInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CAEStreamParser
bool IsLittleEndian() { return m_info.m_dataIsLE; }
unsigned int GetBufferSize() { return m_bufferSize; }
CAEStreamInfo& GetStreamInfo() { return m_info; }
void Reset();

private:
uint8_t m_buffer[MAX_IEC61937_PACKET];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ bool CDVDAudioCodecPassthrough::Open(CDVDStreamInfo &hints, CDVDCodecOptions &op

// only get the dts core from the parser if we don't support dtsHD
m_parser.SetCoreOnly(true);
m_bufferSize = 0;
}

m_dataSize = 0;
m_bufferSize = 0;
m_backlogSize = 0;
m_currentPts = DVD_NOPTS_VALUE;
m_nextPts = DVD_NOPTS_VALUE;
return ret;
}

Expand All @@ -102,15 +106,63 @@ void CDVDAudioCodecPassthrough::Dispose()

int CDVDAudioCodecPassthrough::Decode(uint8_t* pData, int iSize, double dts, double pts)
{
if (iSize <= 0)
return 0;
int used = 0;
if (m_backlogSize)
{
if (m_currentPts == DVD_NOPTS_VALUE)
{
m_currentPts = m_nextPts;
m_nextPts = DVD_NOPTS_VALUE;
}

m_dataSize = m_bufferSize;
unsigned int consumed = m_parser.AddData(m_backlogBuffer, m_backlogSize, &m_buffer, &m_dataSize);
m_bufferSize = std::max(m_bufferSize, m_dataSize);
if (consumed != m_backlogSize)
{
memmove(m_backlogBuffer, m_backlogBuffer+consumed, consumed);
m_backlogSize -= consumed;
}
}

if (pData && !m_dataSize)
{
if (iSize <= 0)
return 0;

if (m_currentPts == DVD_NOPTS_VALUE)
m_currentPts = pts;

unsigned int used;
m_dataSize = m_bufferSize;
used = m_parser.AddData(pData, iSize, &m_buffer, &m_dataSize);
m_bufferSize = std::max(m_bufferSize, m_dataSize);
m_dataSize = m_bufferSize;
used = m_parser.AddData(pData, iSize, &m_buffer, &m_dataSize);
m_bufferSize = std::max(m_bufferSize, m_dataSize);

if (m_format.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_TRUEHD && m_dataSize)
if (used != iSize)
{
m_backlogSize = iSize - used;
memcpy(m_backlogBuffer, pData + used, m_backlogSize);
if (m_nextPts != DVD_NOPTS_VALUE)
{
m_nextPts = pts;
}
used = iSize;
}
}
else if (pData)
{
if (m_nextPts != DVD_NOPTS_VALUE)
{
m_nextPts = pts;
}
memcpy(m_backlogBuffer + m_backlogSize, pData, iSize);
m_backlogSize += iSize;
used = iSize;
}

if (!m_dataSize)
return used;

if (m_format.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_TRUEHD)
{
if (!m_trueHDoffset)
memset(m_trueHDBuffer.get(), 0, TRUEHD_BUF_SIZE);
Expand Down Expand Up @@ -160,7 +212,9 @@ void CDVDAudioCodecPassthrough::GetData(DVDAudioFrame &frame)
frame.planes = 1;
frame.bits_per_sample = 8;
frame.duration = DVD_MSEC_TO_TIME(frame.format.m_streamInfo.GetDuration());
frame.pts = DVD_NOPTS_VALUE;
frame.pts = m_currentPts;
m_currentPts = DVD_NOPTS_VALUE;
m_dataSize = 0;
}

int CDVDAudioCodecPassthrough::GetData(uint8_t** dst)
Expand All @@ -175,6 +229,12 @@ int CDVDAudioCodecPassthrough::GetData(uint8_t** dst)
void CDVDAudioCodecPassthrough::Reset()
{
m_trueHDoffset = 0;
m_dataSize = 0;
m_bufferSize = 0;
m_backlogSize = 0;
m_currentPts = DVD_NOPTS_VALUE;
m_nextPts = DVD_NOPTS_VALUE;
m_parser.Reset();
}

int CDVDAudioCodecPassthrough::GetBufferSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ class CDVDAudioCodecPassthrough : public CDVDAudioCodec
unsigned int m_bufferSize;
unsigned int m_dataSize;
AEAudioFormat m_format;
uint8_t m_backlogBuffer[61440];
unsigned int m_backlogSize;
double m_currentPts;
double m_nextPts;

// TrueHD specifics
std::unique_ptr<uint8_t[]> m_trueHDBuffer;
unsigned int m_trueHDoffset;
unsigned int m_trueHDoffset;
};

0 comments on commit 0ad4065

Please sign in to comment.