Permalink
Browse files

[videoplayer/db] Save and restore video stream selection.

  • Loading branch information...
ace20022 committed Dec 15, 2015
1 parent 352be9c commit c18b15ec6da5489798a589c96a0864f999a7fbd6
@@ -410,6 +410,7 @@ bool CDVDFileInfo::DemuxerToStreamDetails(CDVDInputStream *pInputStream, CDVDDem
pDemux->GetStreamCodecName(iStream, p->m_strCodec);
p->m_iDuration = pDemux->GetStreamLength();
p->m_strStereoMode = ((CDemuxStreamVideo *)stream)->stereo_mode;
p->m_strLanguage = ((CDemuxStreamVideo *)stream)->language;

// stack handling
if (URIUtils::IsStack(path))
@@ -312,6 +312,9 @@ class PredicateSubtitlePriority

static bool PredicateVideoPriority(const SelectionStream& lh, const SelectionStream& rh)
{
PREDICATE_RETURN(lh.type_index == CMediaSettings::GetInstance().GetCurrentVideoSettings().m_VideoStream
, rh.type_index == CMediaSettings::GetInstance().GetCurrentVideoSettings().m_VideoStream);

PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
, rh.flags & CDemuxStream::FLAG_DEFAULT);
return false;
@@ -551,6 +551,8 @@ namespace XBMCAddon
video->m_iDuration = strtol(value.c_str(), NULL, 10);
else if (key == "stereomode")
video->m_strStereoMode = value;
else if (key == "language")
video->m_strLanguage = value;
}
item->GetVideoInfoTag()->m_streamDetails.AddStream(video);
}
@@ -53,6 +53,7 @@ void CStreamDetailVideo::Archive(CArchive& ar)
ar << m_iWidth;
ar << m_iDuration;
ar << m_strStereoMode;
ar << m_strLanguage;
}
else
{
@@ -62,6 +63,7 @@ void CStreamDetailVideo::Archive(CArchive& ar)
ar >> m_iWidth;
ar >> m_iDuration;
ar >> m_strStereoMode;
ar >> m_strLanguage;
}
}
void CStreamDetailVideo::Serialize(CVariant& value) const
@@ -72,6 +74,7 @@ void CStreamDetailVideo::Serialize(CVariant& value) const
value["width"] = m_iWidth;
value["duration"] = m_iDuration;
value["stereomode"] = m_strStereoMode;
value["language"] = m_strLanguage;
}

bool CStreamDetailVideo::IsWorseThan(CStreamDetail *that)
@@ -267,6 +270,15 @@ CStreamDetail *CStreamDetails::NewStream(CStreamDetail::StreamType type)
return retVal;
}

std::string CStreamDetails::GetVideoLanguage(int idx) const
{
CStreamDetailVideo *item = (CStreamDetailVideo*)GetNthStream(CStreamDetail::VIDEO, idx);
if (item)
return item->m_strLanguage;
else
return "";
}

int CStreamDetails::GetStreamCount(CStreamDetail::StreamType type) const
{
int retVal = 0;
@@ -62,6 +62,7 @@ class CStreamDetailVideo : public CStreamDetail
int m_iDuration;
std::string m_strCodec;
std::string m_strStereoMode;
std::string m_strLanguage;
};

class CStreamDetailAudio : public CStreamDetail
@@ -116,6 +117,7 @@ class CStreamDetails : public IArchivable, public ISerializable
int GetVideoDuration(int idx = 0) const;
void SetVideoDuration(int idx, const int duration);
std::string GetStereoMode(int idx = 0) const;
std::string GetVideoLanguage(int idx = 0) const;

std::string GetAudioCodec(int idx = 0) const;
std::string GetAudioLanguage(int idx = 0) const;
@@ -35,6 +35,7 @@ TEST(TestStreamDetails, General)
video->m_iDuration = 30;
video->m_strCodec = "h264";
video->m_strStereoMode = "left_right";
video->m_strLanguage = "eng";

audio->m_iChannels = 2;
audio->m_strCodec = "aac";
@@ -107,7 +107,7 @@ void CVideoDatabase::CreateTables()
"SubtitleDelay float, SubtitlesOn bool, Brightness float, Contrast float, Gamma float,"
"VolumeAmplification float, AudioDelay float, OutputToAllSpeakers bool, ResumeTime integer,"
"Sharpness float, NoiseReduction float, NonLinStretch bool, PostProcess bool,"
"ScalingMethod integer, DeinterlaceMode integer, StereoMode integer, StereoInvert bool)\n");
"ScalingMethod integer, DeinterlaceMode integer, StereoMode integer, StereoInvert bool, VideoStream integer)\n");

CLog::Log(LOGINFO, "create stacktimes table");
m_pDS->exec("CREATE TABLE stacktimes (idFile integer, times text)\n");
@@ -186,7 +186,8 @@ void CVideoDatabase::CreateTables()
CLog::Log(LOGINFO, "create streaminfo table");
m_pDS->exec("CREATE TABLE streamdetails (idFile integer, iStreamType integer, "
"strVideoCodec text, fVideoAspect float, iVideoWidth integer, iVideoHeight integer, "
"strAudioCodec text, iAudioChannels integer, strAudioLanguage text, strSubtitleLanguage text, iVideoDuration integer, strStereoMode text)");
"strAudioCodec text, iAudioChannels integer, strAudioLanguage text, "
"strSubtitleLanguage text, iVideoDuration integer, strStereoMode text, strVideoLanguage text)");

CLog::Log(LOGINFO, "create sets table");
m_pDS->exec("CREATE TABLE sets ( idSet integer primary key, strSet text, strOverview text)");
@@ -2712,12 +2713,13 @@ void CVideoDatabase::SetStreamDetailsForFileId(const CStreamDetails& details, in
for (int i=1; i<=details.GetVideoStreamCount(); i++)
{
m_pDS->exec(PrepareSQL("INSERT INTO streamdetails "
"(idFile, iStreamType, strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight, iVideoDuration, strStereoMode) "
"VALUES (%i,%i,'%s',%f,%i,%i,%i,'%s')",
"(idFile, iStreamType, strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight, iVideoDuration, strStereoMode, strVideoLanguage) "
"VALUES (%i,%i,'%s',%f,%i,%i,%i,'%s','%s')",
idFile, (int)CStreamDetail::VIDEO,
details.GetVideoCodec(i).c_str(), details.GetVideoAspect(i),
details.GetVideoWidth(i), details.GetVideoHeight(i), details.GetVideoDuration(i),
details.GetStereoMode(i).c_str()));
details.GetStereoMode(i).c_str(),
details.GetVideoLanguage(i).c_str()));
}
for (int i=1; i<=details.GetAudioStreamCount(); i++)
{
@@ -3517,6 +3519,7 @@ bool CVideoDatabase::GetStreamDetails(CVideoInfoTag& tag) const
p->m_iHeight = pDS->fv(5).get_asInt();
p->m_iDuration = pDS->fv(10).get_asInt();
p->m_strStereoMode = pDS->fv(11).get_asString();
p->m_strLanguage = pDS->fv(12).get_asString();
details.AddStream(p);
retVal = true;
break;
@@ -3989,6 +3992,7 @@ bool CVideoDatabase::GetVideoSettings(int idFile, CVideoSettings &settings)
settings.m_StereoMode = m_pDS->fv("StereoMode").get_asInt();
settings.m_StereoInvert = m_pDS->fv("StereoInvert").get_asBool();
settings.m_SubtitleCached = false;
settings.m_VideoStream = m_pDS->fv("VideoStream").get_asInt();
m_pDS->close();
return true;
}
@@ -4027,7 +4031,8 @@ void CVideoDatabase::SetVideoSettings(const std::string& strFilenameAndPath, con
setting.m_OutputToAllSpeakers,setting.m_Sharpness,setting.m_NoiseReduction,setting.m_CustomNonLinStretch,setting.m_PostProcess,setting.m_ScalingMethod,
setting.m_DeinterlaceMode);
std::string strSQL2;
strSQL2=PrepareSQL("ResumeTime=%i,StereoMode=%i,StereoInvert=%i where idFile=%i\n", setting.m_ResumeTime, setting.m_StereoMode, setting.m_StereoInvert, idFile);
strSQL2=PrepareSQL("ResumeTime=%i,StereoMode=%i,StereoInvert=%i, VideoStream=%i where idFile=%i\n", setting.m_ResumeTime, setting.m_StereoMode,
setting.m_StereoInvert, setting.m_VideoStream, idFile);
strSQL += strSQL2;
m_pDS->exec(strSQL);
return ;
@@ -4039,15 +4044,15 @@ void CVideoDatabase::SetVideoSettings(const std::string& strFilenameAndPath, con
"AudioStream,SubtitleStream,SubtitleDelay,SubtitlesOn,Brightness,"
"Contrast,Gamma,VolumeAmplification,AudioDelay,OutputToAllSpeakers,"
"ResumeTime,"
"Sharpness,NoiseReduction,NonLinStretch,PostProcess,ScalingMethod,DeinterlaceMode,StereoMode,StereoInvert) "
"Sharpness,NoiseReduction,NonLinStretch,PostProcess,ScalingMethod,DeinterlaceMode,StereoMode,StereoInvert,VideoStream) "
"VALUES ";
strSQL += PrepareSQL("(%i,%i,%i,%f,%f,%f,%i,%i,%f,%i,%f,%f,%f,%f,%f,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i)",
strSQL += PrepareSQL("(%i,%i,%i,%f,%f,%f,%i,%i,%f,%i,%f,%f,%f,%f,%f,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i,%i)",
idFile, setting.m_InterlaceMethod, setting.m_ViewMode, setting.m_CustomZoomAmount, setting.m_CustomPixelRatio, setting.m_CustomVerticalShift,
setting.m_AudioStream, setting.m_SubtitleStream, setting.m_SubtitleDelay, setting.m_SubtitleOn, setting.m_Brightness,
setting.m_Contrast, setting.m_Gamma, setting.m_VolumeAmplification, setting.m_AudioDelay, setting.m_OutputToAllSpeakers,
setting.m_ResumeTime,
setting.m_Sharpness, setting.m_NoiseReduction, setting.m_CustomNonLinStretch, setting.m_PostProcess, setting.m_ScalingMethod,
setting.m_DeinterlaceMode, setting.m_StereoMode, setting.m_StereoInvert);
setting.m_DeinterlaceMode, setting.m_StereoMode, setting.m_StereoInvert, setting.m_VideoStream);
m_pDS->exec(strSQL);
}
}
@@ -4858,11 +4863,17 @@ void CVideoDatabase::UpdateTables(int iVersion)
}
m_pDS->close();
}

if (iVersion < 103)
{
m_pDS->exec("ALTER TABLE settings ADD VideoStream integer");
m_pDS->exec("ALTER TABLE streamdetails ADD strVideoLanguage text");
}
}

int CVideoDatabase::GetSchemaVersion() const
{
return 102;
return 103;
}

bool CVideoDatabase::LookupByFolders(const std::string &path, bool shows)
@@ -971,9 +971,12 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prioritise)
XMLUtils::GetInt(nodeDetail, "durationinseconds", p->m_iDuration);
if (XMLUtils::GetString(nodeDetail, "stereomode", value))
p->m_strStereoMode = StringUtils::Trim(value);
if (XMLUtils::GetString(nodeDetail, "language", value))
p->m_strLanguage = StringUtils::Trim(value);

StringUtils::ToLower(p->m_strCodec);
StringUtils::ToLower(p->m_strStereoMode);
StringUtils::ToLower(p->m_strLanguage);
m_streamDetails.AddStream(p);
}
nodeDetail = NULL;

0 comments on commit c18b15e

Please sign in to comment.