Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub fixes #4176

Merged
merged 4 commits into from Feb 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 32 additions & 23 deletions xbmc/cores/dvdplayer/DVDPlayer.cpp
Expand Up @@ -231,17 +231,27 @@ class PredicateSubtitlePriority
bool original;
bool preferextsubs;
bool subson;
PredicateSubtitleFilter filter;
public:
PredicateSubtitlePriority(std::string& lang)
: audiolang(lang),
original(StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original")),
preferextsubs(CSettings::Get().GetBool("subtitles.preferexternal")),
subson(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn)
subson(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn),
filter(lang)
{
};

bool relevant(const SelectionStream& ss) const
{
return !filter(ss);
}

bool operator()(const SelectionStream& lh, const SelectionStream& rh) const
{
PREDICATE_RETURN(relevant(lh)
, relevant(rh));

PREDICATE_RETURN(lh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream
, rh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream);

Expand Down Expand Up @@ -810,34 +820,28 @@ void CDVDPlayer::OpenDefaultStreams(bool reset)
CloseAudioStream(true);

// enable or disable subtitles
SetSubtitleVisible(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
bool visible = CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn;

// open subtitle stream
SelectionStream as = m_SelectionStreams.Get(STREAM_AUDIO, GetAudioStream());
PredicateSubtitleFilter psf(as.language);
streams = m_SelectionStreams.RemoveIf(STREAM_SUBTITLE, psf);
PredicateSubtitlePriority psp(as.language);
std::stable_sort(streams.begin(), streams.end(), psp);
streams = m_SelectionStreams.Get(STREAM_SUBTITLE, psp);
valid = false;
for(SelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
{
if(OpenSubtitleStream(it->id, it->source))
{
valid = true;
if(it->flags & CDemuxStream::FLAG_FORCED)
m_dvdPlayerVideo.EnableSubtitle(true);
if(!psp.relevant(*it))
visible = false;
else if(it->flags & CDemuxStream::FLAG_FORCED)
visible = true;
}
}
if(!valid)
{
CloseSubtitleStream(true);
if (m_pInputStream && !(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY)))
{
SetSubtitleVisible(false);
if (GetSubtitleCount() > 0 && CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream == -1)
CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = 0;
}
}

SetSubtitleVisibleInternal(visible);

// open teletext stream
streams = m_SelectionStreams.Get(STREAM_TELETEXT);
Expand Down Expand Up @@ -2259,11 +2263,7 @@ void CDVDPlayer::HandleMessages()
else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE))
{
CDVDMsgBool* pValue = (CDVDMsgBool*)pMsg;

m_dvdPlayerVideo.EnableSubtitle(pValue->m_value);

if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->EnableSubtitleStream(pValue->m_value);
SetSubtitleVisibleInternal(pValue->m_value);
}
else if (pMsg->IsType(CDVDMsg::PLAYER_SET_STATE))
{
Expand Down Expand Up @@ -2844,6 +2844,15 @@ void CDVDPlayer::SetSubtitleVisible(bool bVisible)
m_messenger.Put(new CDVDMsgBool(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE, bVisible));
}

void CDVDPlayer::SetSubtitleVisibleInternal(bool bVisible)
{
CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = bVisible;
m_dvdPlayerVideo.EnableSubtitle(bVisible);

if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->EnableSubtitleStream(bVisible);
}

int CDVDPlayer::GetAudioStreamCount()
{
return m_SelectionStreams.Count(STREAM_AUDIO);
Expand Down Expand Up @@ -3182,14 +3191,14 @@ bool CDVDPlayer::AdaptForcedSubtitles()
if(OpenSubtitleStream(it->id, it->source))
{
valid = true;
SetSubtitleVisible(true);
SetSubtitleVisibleInternal(true);
}
}
}
if(!valid)
{
CloseSubtitleStream(true);
SetSubtitleVisible(false);
SetSubtitleVisibleInternal(false);
}
}
return valid;
Expand Down Expand Up @@ -3483,7 +3492,7 @@ int CDVDPlayer::OnDVDNavResult(void* pData, int iMessage)
int iStream = event->physical_wide;
bool visible = !(iStream & 0x80);

SetSubtitleVisible(visible);
SetSubtitleVisibleInternal(visible);

if (iStream >= 0)
m_dvd.iSelectedSPUStream = (iStream & ~0x80);
Expand Down
9 changes: 1 addition & 8 deletions xbmc/cores/dvdplayer/DVDPlayer.h
Expand Up @@ -154,14 +154,6 @@ class CSelectionStreams
return streams;
}

template<typename Filter>
SelectionStreams RemoveIf(StreamType type, Filter filter)
{
SelectionStreams streams = Get(type);
streams.erase(std::remove_if(streams.begin(), streams.end(), filter), streams.end());
return streams;
}

void Clear (StreamType type, StreamSource source);
int Source (StreamSource source, std::string filename);

Expand Down Expand Up @@ -301,6 +293,7 @@ class CDVDPlayer : public IPlayer, public CThread, public IDVDPlayer
bool ShowPVRChannelInfo();

int AddSubtitleFile(const std::string& filename, const std::string& subfilename = "", CDemuxStream::EFlags flags = CDemuxStream::FLAG_NONE);
void SetSubtitleVisibleInternal(bool bVisible);

/**
* one of the DVD_PLAYSPEED defines
Expand Down
55 changes: 32 additions & 23 deletions xbmc/cores/omxplayer/OMXPlayer.cpp
Expand Up @@ -275,17 +275,27 @@ class PredicateSubtitlePriority
bool original;
bool preferextsubs;
bool subson;
PredicateSubtitleFilter filter;
public:
PredicateSubtitlePriority(std::string& lang)
: audiolang(lang),
original(StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original")),
preferextsubs(CSettings::Get().GetBool("subtitles.preferexternal")),
subson(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn)
subson(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn),
filter(lang)
{
};

bool relevant(const OMXSelectionStream& ss) const
{
return !filter(ss);
}

bool operator()(const OMXSelectionStream& lh, const OMXSelectionStream& rh) const
{
PREDICATE_RETURN(relevant(lh)
, relevant(rh));

PREDICATE_RETURN(lh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream
, rh.type_index == CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream);

Expand Down Expand Up @@ -866,34 +876,28 @@ void COMXPlayer::OpenDefaultStreams(bool reset)
CloseAudioStream(true);

// enable or disable subtitles
SetSubtitleVisible(CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn);
bool visible = CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn;

// open subtitle stream
OMXSelectionStream as = m_SelectionStreams.Get(STREAM_AUDIO, GetAudioStream());
PredicateSubtitleFilter psf(as.language);
streams = m_SelectionStreams.RemoveIf(STREAM_SUBTITLE, psf);
PredicateSubtitlePriority psp(as.language);
std::stable_sort(streams.begin(), streams.end(), psp);
streams = m_SelectionStreams.Get(STREAM_SUBTITLE, psp);
valid = false;
for(OMXSelectionStreams::iterator it = streams.begin(); it != streams.end() && !valid; ++it)
{
if(OpenSubtitleStream(it->id, it->source))
{
valid = true;
if(it->flags & CDemuxStream::FLAG_FORCED)
m_omxPlayerVideo.EnableSubtitle(true);
if(!psp.relevant(*it))
visible = false;
else if(it->flags & CDemuxStream::FLAG_FORCED)
visible = true;
}
}
if(!valid)
{
CloseSubtitleStream(true);
if (m_pInputStream && !(m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) || m_pInputStream->IsStreamType(DVDSTREAM_TYPE_BLURAY)))
{
SetSubtitleVisible(false);
if (GetSubtitleCount() > 0 && CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream == -1)
CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleStream = 0;
}
}

SetSubtitleVisibleInternal(visible);

// open teletext stream
streams = m_SelectionStreams.Get(STREAM_TELETEXT);
Expand Down Expand Up @@ -2497,11 +2501,7 @@ void COMXPlayer::HandleMessages()
else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE))
{
CDVDMsgBool* pValue = (CDVDMsgBool*)pMsg;

m_omxPlayerVideo.EnableSubtitle(pValue->m_value);

if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->EnableSubtitleStream(pValue->m_value);
SetSubtitleVisibleInternal(pValue->m_value);
}
else if (pMsg->IsType(CDVDMsg::PLAYER_SET_STATE))
{
Expand Down Expand Up @@ -3101,6 +3101,15 @@ void COMXPlayer::SetSubtitleVisible(bool bVisible)
m_messenger.Put(new CDVDMsgBool(CDVDMsg::PLAYER_SET_SUBTITLESTREAM_VISIBLE, bVisible));
}

void COMXPlayer::SetSubtitleVisibleInternal(bool bVisible)
{
CMediaSettings::Get().GetCurrentVideoSettings().m_SubtitleOn = bVisible;
m_omxPlayerVideo.EnableSubtitle(bVisible);

if (m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
static_cast<CDVDInputStreamNavigator*>(m_pInputStream)->EnableSubtitleStream(bVisible);
}

int COMXPlayer::GetAudioStreamCount()
{
return m_SelectionStreams.Count(STREAM_AUDIO);
Expand Down Expand Up @@ -3441,14 +3450,14 @@ bool COMXPlayer::AdaptForcedSubtitles()
if(OpenSubtitleStream(it->id, it->source))
{
valid = true;
SetSubtitleVisible(true);
SetSubtitleVisibleInternal(true);
}
}
}
if(!valid)
{
CloseSubtitleStream(true);
SetSubtitleVisible(false);
SetSubtitleVisibleInternal(false);
}
}
return valid;
Expand Down Expand Up @@ -3745,7 +3754,7 @@ int COMXPlayer::OnDVDNavResult(void* pData, int iMessage)
int iStream = event->physical_wide;
bool visible = !(iStream & 0x80);

SetSubtitleVisible(visible);
SetSubtitleVisibleInternal(visible);

if (iStream >= 0)
m_dvd.iSelectedSPUStream = (iStream & ~0x80);
Expand Down
9 changes: 1 addition & 8 deletions xbmc/cores/omxplayer/OMXPlayer.h
Expand Up @@ -148,14 +148,6 @@ class COMXSelectionStreams
return streams;
}

template<typename Filter>
OMXSelectionStreams RemoveIf(StreamType type, Filter filter)
{
OMXSelectionStreams streams = Get(type);
streams.erase(std::remove_if(streams.begin(), streams.end(), filter), streams.end());
return streams;
}

void Clear (StreamType type, StreamSource source);
int Source (StreamSource source, std::string filename);

Expand Down Expand Up @@ -306,6 +298,7 @@ class COMXPlayer : public IPlayer, public CThread, public IDVDPlayer
bool ShowPVRChannelInfo();

int AddSubtitleFile(const std::string& filename, const std::string& subfilename = "", CDemuxStream::EFlags flags = CDemuxStream::FLAG_NONE);
void SetSubtitleVisibleInternal(bool bVisible);

/**
* one of the DVD_PLAYSPEED defines
Expand Down