Skip to content

Commit

Permalink
Use main bitstreaming timing logic for TrueHD
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevcairiel committed Jun 11, 2018
1 parent 5ba039a commit a1b40a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
36 changes: 11 additions & 25 deletions decoder/LAVAudio/Bitstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,31 +414,17 @@ HRESULT CLAVAudio::DeliverBitstream(AVCodecID codec, const BYTE *buffer, DWORD d
}

REFERENCE_TIME rtStart = m_rtStart, rtStop = AV_NOPTS_VALUE;
// TrueHD timings
// Since the SPDIF muxer takes 24 frames and puts them into one IEC61937 frame, we use the cached timestamp from before.
if (codec == AV_CODEC_ID_TRUEHD) {
// long-term cache is valid
if (m_rtBitstreamCache != AV_NOPTS_VALUE)
rtStart = m_rtBitstreamCache;
// Duration - stop time of the current frame is valid
if (rtStopInput != AV_NOPTS_VALUE)
rtStop = rtStopInput;
else // no actual time of the current frame, use typical TrueHD frame size, 24 * 0.83333ms
rtStop = rtStart + (REFERENCE_TIME)(200000 / m_dRate);
m_rtStart = rtStop;
} else {
double dDuration = DBL_SECOND_MULT * (double)m_bsParser.m_dwSamples / m_bsParser.m_dwSampleRate / m_dRate;
m_dStartOffset += fmod(dDuration, 1.0);

// Add rounded duration to rtStop
rtStop = rtStart + (REFERENCE_TIME)(dDuration + 0.5);
// and unrounded to m_rtStart..
m_rtStart += (REFERENCE_TIME)dDuration;
// and accumulate error..
if (m_dStartOffset > 0.5) {
m_rtStart++;
m_dStartOffset -= 1.0;
}
double dDuration = DBL_SECOND_MULT * (double)m_bsParser.m_dwSamples / m_bsParser.m_dwSampleRate / m_dRate;
m_dStartOffset += fmod(dDuration, 1.0);

// Add rounded duration to rtStop
rtStop = rtStart + (REFERENCE_TIME)(dDuration + 0.5);
// and unrounded to m_rtStart..
m_rtStart += (REFERENCE_TIME)dDuration;
// and accumulate error..
if (m_dStartOffset > 0.5) {
m_rtStart++;
m_dStartOffset -= 1.0;
}

REFERENCE_TIME rtJitter = 0;
Expand Down
15 changes: 15 additions & 0 deletions decoder/LAVAudio/BitstreamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ HRESULT CBitstreamParser::Parse(AVCodecID codec, BYTE *pBuffer, DWORD dwSize, vo
case AV_CODEC_ID_AC3:
case AV_CODEC_ID_EAC3:
return ParseAC3(pBuffer, dwSize, pParserContext);
case AV_CODEC_ID_TRUEHD:
return ParseTrueHD(pBuffer, dwSize);
}
return S_OK;
}
Expand Down Expand Up @@ -86,3 +88,16 @@ HRESULT CBitstreamParser::ParseAC3(BYTE *pBuffer, DWORD dwSize, void *pParserCon

return S_OK;
}

HRESULT CBitstreamParser::ParseTrueHD(BYTE *pBuffer, DWORD dwSize)
{
if (AV_RB32(pBuffer + 4) == 0xf8726fba)
{
int nRatebits = pBuffer[8] >> 4;

m_dwSampleRate = (nRatebits & 8 ? 44100 : 48000) << (nRatebits & 7);
m_dwSamples = 24 * (40 << (nRatebits & 7));
}

return S_OK;
}
1 change: 1 addition & 0 deletions decoder/LAVAudio/BitstreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CBitstreamParser {
private:
HRESULT ParseDTS(BYTE *pBuffer, DWORD dwSize);
HRESULT ParseAC3(BYTE *pBuffer, DWORD dwSize, void *pParserContext);
HRESULT ParseTrueHD(BYTE *pBuffer, DWORD dwSize);

public:
DWORD m_dwSampleRate = 0;
Expand Down

0 comments on commit a1b40a6

Please sign in to comment.