aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenen92 <enen92@users.noreply.github.com>2020-11-27 11:49:58 +0000
committerGitHub <noreply@github.com>2020-11-27 11:49:58 +0000
commit22a7f1463cd563f418973f9aed788f093110020d (patch)
tree9fe5e3809d16cdf6b07b65f56d1c0efdfbd8b35f
parent327f8a4aefd1a374080d2094220744375d05aafe (diff)
parentda383a996d7e0cb5e18a1666812682d9c4291e04 (diff)
Merge pull request #18869 from enen92/subas
[subtitles][ass] fix/extend detection of font attachments (mimetype)
-rw-r--r--xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp33
-rw-r--r--xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp47
2 files changed, 49 insertions, 31 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
index 46e29ba4c3..ff13cad28d 100644
--- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -70,6 +70,31 @@ static const struct StereoModeConversionMap WmvToInternalStereoModeMap[] =
{}
};
+namespace
+{
+const std::vector<std::string> font_mimetypes = {"application/x-truetype-font",
+ "application/vnd.ms-opentype",
+ "application/x-font-ttf",
+ "application/x-font", // probably incorrect
+ "application/font-sfnt",
+ "font/collection",
+ "font/otf",
+ "font/sfnt",
+ "font/ttf"};
+
+bool AttachmentIsFont(const AVDictionaryEntry* dict)
+{
+ if (dict)
+ {
+ const std::string mimeType = dict->value;
+ return std::find_if(font_mimetypes.begin(), font_mimetypes.end(), [&mimeType](std::string str) {
+ return str == mimeType;
+ }) != font_mimetypes.end();
+ }
+ return false;
+}
+} // namespace
+
#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
std::string CDemuxStreamAudioFFmpeg::GetStreamName()
@@ -1652,9 +1677,13 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int streamIdx)
}
}
case AVMEDIA_TYPE_ATTACHMENT:
- { //mkv attachments. Only bothering with fonts for now.
+ {
+ // mkv attachments. Only bothering with fonts for now.
+ AVDictionaryEntry* attachmentMimetype =
+ av_dict_get(pStream->metadata, "mimetype", nullptr, 0);
+
if (pStream->codecpar->codec_id == AV_CODEC_ID_TTF ||
- pStream->codecpar->codec_id == AV_CODEC_ID_OTF)
+ pStream->codecpar->codec_id == AV_CODEC_ID_OTF || AttachmentIsFont(attachmentMimetype))
{
std::string fileName = "special://temp/fonts/";
XFILE::CDirectory::Create(fileName);
diff --git a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp
index 41c824969f..6baddb26e0 100644
--- a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp
+++ b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDSubtitlesLibass.cpp
@@ -22,17 +22,8 @@
namespace
{
-void AppendFont(const std::string& font)
+std::string GetDefaultFontPath(std::string& font)
{
- std::string finalFontPath = URIUtils::AddFileToFolder("special://temp/fonts/", font);
- if (XFILE::CFile::Exists(finalFontPath))
- {
- CLog::Log(LOGDEBUG,
- "CDVDSubtitlesLibass: Skipping copy of {} to special://temp/fonts/ (already exists)",
- font);
- return;
- }
-
std::string fontSources[]{"special://home/media/Fonts/", "special://xbmc/media/Fonts/"};
for (const auto& path : fontSources)
@@ -40,12 +31,11 @@ void AppendFont(const std::string& font)
auto fontPath = URIUtils::AddFileToFolder(path, font);
if (XFILE::CFile::Exists(fontPath))
{
- XFILE::CFile::Copy(fontPath, finalFontPath);
- CLog::Log(LOGDEBUG, "CDVDSubtitlesLibass: Copied {} to {}", fontPath, finalFontPath);
- return;
+ return CSpecialProtocol::TranslatePath(fontPath).c_str();
}
- CLog::Log(LOGDEBUG, "CDVDSubtitlesLibass: Could not find font {} in font sources", font);
}
+ CLog::Log(LOGERROR, "CDVDSubtitlesLibass: Could not find font {} in font sources", font);
+ return "";
}
} // namespace
@@ -69,19 +59,18 @@ CDVDSubtitlesLibass::CDVDSubtitlesLibass()
ass_set_message_cb(m_library, libass_log, this);
- // Add configured subtitle font to special://temp/fonts/. This needs to be done before
- // ass_set_fonts_dir. If fontconfig fails it will use the default font.
- const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
- std::string forcedFont = settings->GetString(CSettings::SETTING_SUBTITLES_FONT);
- AppendFont(forcedFont);
- strPath = URIUtils::AddFileToFolder(strPath, forcedFont);
-
CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Initializing ASS library font settings");
- // libass uses fontconfig (system lib) which is not wrapped
- // so translate the path before calling into libass
- ass_set_fonts_dir(m_library, CSpecialProtocol::TranslatePath(strPath).c_str());
- ass_set_extract_fonts(m_library, 1);
- ass_set_style_overrides(m_library, NULL);
+
+ const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
+ bool overrideFont = settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEASSFONTS);
+ if (!overrideFont)
+ {
+ // libass uses fontconfig (system lib) which is not wrapped
+ // so translate the path before calling into libass
+ ass_set_fonts_dir(m_library, CSpecialProtocol::TranslatePath(strPath).c_str());
+ ass_set_extract_fonts(m_library, 1);
+ ass_set_style_overrides(m_library, nullptr);
+ }
CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Initializing ASS Renderer");
@@ -94,10 +83,10 @@ CDVDSubtitlesLibass::CDVDSubtitlesLibass()
ass_set_use_margins(m_renderer, 0);
ass_set_font_scale(m_renderer, 1);
- int fontconfig = settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEASSFONTS) ? 0 : 1;
// libass uses fontconfig (system lib) which is not wrapped
- // so translate the path before calling into libass
- ass_set_fonts(m_renderer, CSpecialProtocol::TranslatePath(strPath).c_str(), "Arial", fontconfig,
+ // so translate the path before calling into libass
+ std::string forcedFont = settings->GetString(CSettings::SETTING_SUBTITLES_FONT);
+ ass_set_fonts(m_renderer, GetDefaultFontPath(forcedFont).c_str(), "Arial", overrideFont ? 0 : 1,
nullptr, 1);
}