Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
[fixed] Sync issues with DTS audio in Matroska due to corrupted times…
Browse files Browse the repository at this point in the history
…tamps (bad muxing)
  • Loading branch information
a11599 committed Nov 5, 2014
1 parent 0ad14b8 commit 9daa2a9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/DVDDemux.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class CDemuxStreamAudio : public CDemuxStream
iBlockAlign = 0;
iBitRate = 0;
iBitsPerSample = 0;
bBrokenTimestamps = false;
type = STREAM_AUDIO;
}

Expand All @@ -199,6 +200,7 @@ class CDemuxStreamAudio : public CDemuxStream
int iBlockAlign;
int iBitRate;
int iBitsPerSample;
bool bBrokenTimestamps;
};

class CDemuxStreamSubtitle : public CDemuxStream
Expand Down
5 changes: 5 additions & 0 deletions xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,11 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int iId)
if(av_dict_get(pStream->metadata, "title", NULL, 0))
st->m_description = av_dict_get(pStream->metadata, "title", NULL, 0)->value;

// older versions of matroska muxers did a pretty bad job to audio timestamps; let the player know about this
// TODO: possibly flac is also affected? have some reports in forum, but cannot test it due to lack of samples
if (m_bMatroska && pStream->codec && (pStream->codec->codec_id == CODEC_ID_DTS))
st->bBrokenTimestamps = true;

break;
}
case AVMEDIA_TYPE_VIDEO:
Expand Down
5 changes: 4 additions & 1 deletion xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "DVDCodecs/Audio/DVDAudioCodec.h"
#include "DVDCodecs/DVDCodecs.h"
#include "DVDCodecs/DVDFactoryCodec.h"
#include "settings/AdvancedSettings.h"
#include "settings/Settings.h"
#include "video/VideoReferenceClock.h"
#include "utils/log.h"
Expand Down Expand Up @@ -194,6 +195,7 @@ void CDVDPlayerAudio::OpenStream( CDVDStreamInfo &hints, CDVDAudioCodec* codec )
m_prevskipped = false;
m_syncclock = true;
m_silence = false;
m_tsbroken = hints.audiotsbroken & g_advancedSettings.m_audioEnableAltSync;

m_maxspeedadjust = CSettings::Get().GetNumber("videoplayer.maxspeedadjust");
}
Expand Down Expand Up @@ -259,7 +261,7 @@ int CDVDPlayerAudio::DecodeFrame(DVDAudioFrame &audioframe)

/* the packet dts refers to the first audioframe that starts in the packet */
double dts = m_ptsInput.Get(m_decode.size + m_pAudioCodec->GetBufferSize(), true);
if (dts != DVD_NOPTS_VALUE)
if (dts != DVD_NOPTS_VALUE && !m_tsbroken)
m_audioClock = dts;

int len = m_pAudioCodec->Decode(m_decode.data, m_decode.size);
Expand Down Expand Up @@ -467,6 +469,7 @@ void CDVDPlayerAudio::UpdatePlayerInfo()
std::ostringstream s;
s << "aq:" << setw(2) << min(99,m_messageQueue.GetLevel() + MathUtils::round_int(100.0/8.0*m_dvdAudio.GetCacheTime())) << "%";
s << ", Kb/s:" << fixed << setprecision(2) << (double)GetAudioBitrate() / 1024.0;
s << ", ae:" << fixed << setprecision(2) << m_error / DVD_MSEC_TO_TIME(1) << " ms" << (m_tsbroken ? " (alt)" : "");

//print the inverse of the resample ratio, since that makes more sense
//if the resample ratio is 0.5, then we're playing twice as fast
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/dvdplayer/DVDPlayerAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class CDVDPlayerAudio : public CThread, public IDVDStreamPlayerAudio
bool m_prevskipped;
double m_maxspeedadjust;
double m_resampleratio; //resample ratio when using SYNC_RESAMPLE, used for the codec info
bool m_tsbroken; // true when audio timestamps are possibly broken and we are ignoring them

struct SInfo
{
Expand Down
6 changes: 5 additions & 1 deletion xbmc/cores/dvdplayer/DVDStreamInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void CDVDStreamInfo::Clear()
blockalign = 0;
bitrate = 0;
bitspersample = 0;
audiotsbroken = false;

orientation = 0;
}
Expand Down Expand Up @@ -116,7 +117,8 @@ bool CDVDStreamInfo::Equal(const CDVDStreamInfo& right, bool withextradata)
|| samplerate != right.samplerate
|| blockalign != right.blockalign
|| bitrate != right.bitrate
|| bitspersample != right.bitspersample ) return false;
|| bitspersample != right.bitspersample
|| audiotsbroken != right.audiotsbroken ) return false;

// SUBTITLE

Expand Down Expand Up @@ -180,6 +182,7 @@ void CDVDStreamInfo::Assign(const CDVDStreamInfo& right, bool withextradata)
blockalign = right.blockalign;
bitrate = right.bitrate;
bitspersample = right.bitspersample;
audiotsbroken = right.audiotsbroken;

// SUBTITLE
}
Expand Down Expand Up @@ -210,6 +213,7 @@ void CDVDStreamInfo::Assign(const CDemuxStream& right, bool withextradata)
blockalign = stream->iBlockAlign;
bitrate = stream->iBitRate;
bitspersample = stream->iBitsPerSample;
audiotsbroken = stream->bBrokenTimestamps;
}
else if( right.type == STREAM_VIDEO )
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/dvdplayer/DVDStreamInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CDVDStreamInfo
int bitrate;
int blockalign;
int bitspersample;
bool audiotsbroken; // audio timestamps possibly broken (some matroska audio tracks)

// SUBTITLE

Expand Down
4 changes: 4 additions & 0 deletions xbmc/settings/AdvancedSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void CAdvancedSettings::Initialize()
m_omxHWAudioDecode = false;
m_omxDecodeStartWithValidFrame = false;

m_audioEnableAltSync = true;

m_karaokeSyncDelayCDG = 0.0f;
m_karaokeSyncDelayLRC = 0.0f;
m_karaokeChangeGenreForKaraokeSongs = false;
Expand Down Expand Up @@ -503,6 +505,8 @@ void CAdvancedSettings::ParseSettingsFile(const CStdString &file)

XMLUtils::GetFloat(pElement, "limiterhold", m_limiterHold, 0.0f, 100.0f);
XMLUtils::GetFloat(pElement, "limiterrelease", m_limiterRelease, 0.001f, 100.0f);

XMLUtils::GetBoolean(pElement, "enablealtsync", m_audioEnableAltSync);
}

pElement = pRootElement->FirstChildElement("omx");
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/AdvancedSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CAdvancedSettings : public ISettingCallback, public ISettingsHandler
bool m_dvdplayerIgnoreDTSinWAV;
float m_limiterHold;
float m_limiterRelease;
bool m_audioEnableAltSync;

bool m_omxHWAudioDecode;
bool m_omxDecodeStartWithValidFrame;
Expand Down

0 comments on commit 9daa2a9

Please sign in to comment.