Permalink
Browse files

VideoPlayer: make AudioCodecPassthrough handle pts

  • Loading branch information...
FernetMenta authored and popcornmix committed Jan 21, 2016
1 parent 7df357d commit 5ffa5d3caf06a69d21583c248fdb45304890f305
@@ -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)
@@ -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];
@@ -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;
}
@@ -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);
@@ -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)
@@ -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()
@@ -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 5ffa5d3

Please sign in to comment.