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

Subtitle system for streaming audo/video #12224

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
523a3e8
basing subtitle display
PTwr Sep 18, 2023
b5bc249
fixed json parsing
PTwr Sep 18, 2023
846fb87
newest subtitles always on bottom
PTwr Sep 18, 2023
1eab7a4
multizone osd
PTwr Sep 19, 2023
358474f
subtitles in multizone osd
PTwr Sep 19, 2023
09f014d
make osdsubtitles use shared osd
PTwr Sep 20, 2023
a17c368
subtitles moved to plugin system
PTwr Sep 26, 2023
4e85734
bugfix on restarting game
PTwr Oct 1, 2023
a291d75
text scalling in subtitles
PTwr Oct 1, 2023
2f70286
log improvement
PTwr Oct 4, 2023
4467449
Subtitles integrated back into Dolphin
PTwr Oct 5, 2023
cf6264a
cleanup
PTwr Oct 5, 2023
8fb42b0
html colors, hex colors, and shitty decimal colors
PTwr Oct 6, 2023
617ffa4
fixed hex values
PTwr Oct 9, 2023
44edbdc
Merge branch 'dolphin-emu:master' into master
PTwr Oct 10, 2023
ea77d09
a little cleanup
PTwr Oct 10, 2023
c6e5d48
Cleanup, style fixes
PTwr Oct 10, 2023
d91784b
Merge branch 'master' of https://github.com/PTwr/dolphin-subtitles
PTwr Oct 10, 2023
4b7750f
build fix
PTwr Oct 10, 2023
4387e7c
reverted Visual Studio automatic changes
PTwr Oct 10, 2023
9d3529f
code cleanup
PTwr Oct 10, 2023
84edd57
code cleanup
PTwr Oct 11, 2023
5f9371e
code cleanup and switch from pass by copy to pass by reference
PTwr Oct 11, 2023
d1a7096
inline/copyconstructor/pointer fixes
PTwr Oct 11, 2023
29eb73a
variable naming cleanup
PTwr Oct 11, 2023
2399d59
Subtitles at timestamp
PTwr Oct 11, 2023
60efd6b
improved logger
PTwr Oct 18, 2023
0d9f99f
include filepath in json error message
PTwr Oct 18, 2023
701c794
Merge changes from upstream master
PTwr Oct 19, 2023
20aa5bf
Copy constructor fixes
PTwr Oct 19, 2023
d86a68e
relative offsets in filemonitor logs
PTwr Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/Core/Common/CommonPaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#define DYNAMICINPUT_DIR "DynamicInputTextures"
#define GRAPHICSMOD_DIR "GraphicMods"
#define WIISDSYNC_DIR "WiiSDSync"
#define SUBTITLE_DIR "Subtitles"

// This one is only used to remove it if it was present
#define SHADERCACHE_LEGACY_DIR "ShaderCache"
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ static void RebuildUserDirectories(unsigned int dir_index)
s_user_paths[D_WFSROOT_IDX] = s_user_paths[D_USER_IDX] + WFSROOT_DIR DIR_SEP;
s_user_paths[D_BACKUP_IDX] = s_user_paths[D_USER_IDX] + BACKUP_DIR DIR_SEP;
s_user_paths[D_RESOURCEPACK_IDX] = s_user_paths[D_USER_IDX] + RESOURCEPACK_DIR DIR_SEP;
s_user_paths[D_SUBTITLES_IDX] = s_user_paths[D_LOAD_IDX] + SUBTITLE_DIR DIR_SEP;
s_user_paths[D_DYNAMICINPUT_IDX] = s_user_paths[D_LOAD_IDX] + DYNAMICINPUT_DIR DIR_SEP;
s_user_paths[D_GRAPHICSMOD_IDX] = s_user_paths[D_LOAD_IDX] + GRAPHICSMOD_DIR DIR_SEP;
s_user_paths[D_WIISDCARDSYNCFOLDER_IDX] = s_user_paths[D_LOAD_IDX] + WIISDSYNC_DIR DIR_SEP;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum
D_WFSROOT_IDX,
D_BACKUP_IDX,
D_RESOURCEPACK_IDX,
D_SUBTITLES_IDX,
D_DYNAMICINPUT_IDX,
D_GRAPHICSMOD_IDX,
D_GBAUSER_IDX,
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/Logging/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class LogType : int
DYNA_REC,
EXPANSIONINTERFACE,
FILEMON,
SUBTITLES,
FRAMEDUMP,
GDB_STUB,
GPFIFO,
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/Logging/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ LogManager::LogManager()
m_log[LogType::DYNA_REC] = {"JIT", "JIT Dynamic Recompiler"};
m_log[LogType::EXPANSIONINTERFACE] = {"EXI", "Expansion Interface"};
m_log[LogType::FILEMON] = {"FileMon", "File Monitor"};
m_log[LogType::SUBTITLES] = {"Subtitles", "Subtitles"};
m_log[LogType::FRAMEDUMP] = {"FRAMEDUMP", "FrameDump"};
m_log[LogType::GDB_STUB] = {"GDB_STUB", "GDB Stub"};
m_log[LogType::GPFIFO] = {"GP", "GatherPipe FIFO"};
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/Boot/Boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
bool operator()(BootParameters::Disc& disc) const
{
NOTICE_LOG_FMT(BOOT, "Booting from disc: {}", disc.path);

const DiscIO::VolumeDisc* volume =
SetDisc(std::move(disc.volume), disc.auto_disc_change_paths);

Expand All @@ -520,6 +521,7 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
return false;

SConfig::OnNewTitleLoad(guard);

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeWad.h"

#include <Subtitles\Subtitles.h>
PTwr marked this conversation as resolved.
Show resolved Hide resolved

SConfig* SConfig::m_Instance;

SConfig::SConfig()
Expand Down Expand Up @@ -209,6 +211,7 @@ void SConfig::OnNewTitleLoad(const Core::CPUThreadGuard& guard)
PatchEngine::Reload();
HiresTexture::Update();
WC24PatchEngine::Reload();
Subtitles::Reload();
}

void SConfig::LoadDefaults()
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/DVD/DVDThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "DiscIO/Enums.h"
#include "DiscIO/Volume.h"
#include <Subtitles\Subtitles.h>
PTwr marked this conversation as resolved.
Show resolved Hide resolved

namespace DVD
{
Expand Down Expand Up @@ -343,6 +344,7 @@ void DVDThread::DVDThreadMain()
while (m_request_queue.Pop(request))
{
m_file_logger.Log(*m_disc, request.partition, request.dvd_offset);
Subtitles::OnFileAccess(*m_disc, request.partition, request.dvd_offset);
PTwr marked this conversation as resolved.
Show resolved Hide resolved

std::vector<u8> buffer(request.length);
if (!m_disc->Read(request.dvd_offset, request.length, buffer.data(), request.partition))
Expand Down
22 changes: 21 additions & 1 deletion Source/Core/Core/HW/DVD/FileMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ static bool IsSoundFile(const std::string& filename)

return extensions.find(extension) != extensions.end();
}
// Filtered files
static bool IsVideoFile(const std::string& filename)
{
std::string extension;
SplitPath(filename, nullptr, nullptr, &extension);
Common::ToLower(&extension);

static const std::unordered_set<std::string> extensions = {
".thp", // 1Wii/Game Cube Video File
PTwr marked this conversation as resolved.
Show resolved Hide resolved
};

return extensions.find(extension) != extensions.end();
}

FileLogger::FileLogger() = default;

Expand Down Expand Up @@ -79,9 +92,16 @@ void FileLogger::Log(const DiscIO::Volume& volume, const DiscIO::Partition& part

const std::string size_string = Common::ThousandSeparate(file_info->GetSize() / 1000, 7);
const std::string path = file_info->GetPath();
const std::string log_string = fmt::format("{} kB {}", size_string, path);
const std::string log_string = fmt::format("{} kB {} offset {}", size_string, path, offset);

//if (path.contains("BGM") || path.contains("bgm"))
// return;
PTwr marked this conversation as resolved.
Show resolved Hide resolved

//TODO just use colors instead of this horrid hack
if (IsSoundFile(path))
INFO_LOG_FMT(FILEMON, "{}", log_string);
else if (IsVideoFile(path))
NOTICE_LOG_FMT(FILEMON, "{}", log_string);
else
WARN_LOG_FMT(FILEMON, "{}", log_string);

Expand Down
28 changes: 15 additions & 13 deletions Source/Core/DolphinLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,33 @@
<ItemGroup>
<Text Include="$(BuildInfoTemplate)" />
</ItemGroup>
<UsingTask TaskName="GetProductVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ItemGroup>
<ClInclude Include="Subtitles\Helpers.h" />
<ClInclude Include="Subtitles\WebColors.h" />
<ClInclude Include="Subtitles\TranslationEntry.h" />
<ClInclude Include="Subtitles\Subtitles.h" />
<ClInclude Include="VideoCommon\OnScreenDisplay.enum.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Subtitles\Subtitles.cpp" />
</ItemGroup>
PTwr marked this conversation as resolved.
Show resolved Hide resolved
<UsingTask TaskName="GetProductVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Path ParameterType="System.String" Required="true" />
<ProductVersion ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs"><![CDATA[
ProductVersion = FileVersionInfo.GetVersionInfo(Path).ProductVersion;
]]>
</Code>
]]></Code>
</Task>
</UsingTask>
<Target Name="WriteBuildInfo" AfterTargets="Build" Inputs="$(BuildInfoTemplate)" Outputs="$(BuildInfoOutput)">
<GetProductVersion Path="$(VCToolsRedistInstallDir)vc_redist.x64.exe">
<Output PropertyName="VCToolsProductVersion" TaskParameter="ProductVersion" />
</GetProductVersion>
<Message Text="VCToolsProductVersion $(VCToolsProductVersion)" Importance="High" />
<WriteLinesToFile
File="$(BuildInfoOutput)"
Lines="$([System.IO.File]::ReadAllText($(BuildInfoTemplate)).Replace('${VC_TOOLS_VERSION}', $(VCToolsProductVersion)))"
Overwrite="true"
/>
<WriteLinesToFile File="$(BuildInfoOutput)" Lines="$([System.IO.File]::ReadAllText($(BuildInfoTemplate)).Replace('${VC_TOOLS_VERSION}', $(VCToolsProductVersion)))" Overwrite="true" />
</Target>
</Project>
69 changes: 69 additions & 0 deletions Source/Core/Subtitles/Helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once
PTwr marked this conversation as resolved.
Show resolved Hide resolved
#include <string>
#include <Common/CommonTypes.h>
#include <Common/StringUtil.h>
#include <VideoCommon/OnScreenDisplay.h>
#include <picojson.h>
#include "WebColors.h"

namespace Subtitles
{

void Info(std::string msg)
{
OSD::AddMessage(msg, 2000, OSD::Color::GREEN);
INFO_LOG_FMT(SUBTITLES, "{}", msg);
}
PTwr marked this conversation as resolved.
Show resolved Hide resolved
void Error(std::string err)
{
OSD::AddMessage(err, 2000, OSD::Color::RED);
ERROR_LOG_FMT(SUBTITLES, "{}", err);
}

u32 TryParsecolor(picojson::value raw, u32 defaultColor)
{
if (raw.is<double>())
return raw.get<double>();
else
PTwr marked this conversation as resolved.
Show resolved Hide resolved
{
auto str = raw.to_str();
Common::ToLower(&str);

if (str.starts_with("0x"))
// hex string
return std::stoul(str, nullptr, 16);
else if (WebColors.count(str) == 1)
// html color name
return WebColors[str];
else
// color noted with 3 or 4 base10 numers (rgb/argb)
try // string parsing suucks
{
// try parse (a)rgb space delimited color
u32 a, r, g, b;
auto parts = SplitString(str, ' ');
if (parts.size() == 4)
{
a = std::stoul(parts[0], nullptr, 10);
r = std::stoul(parts[1], nullptr, 10);
g = std::stoul(parts[2], nullptr, 10);
b = std::stoul(parts[3], nullptr, 10);
return a << 24 | r << 16 | g << 8 | b;
}
else if (parts.size() == 3)
{
a = 255;
r = std::stoul(parts[0], nullptr, 10);
g = std::stoul(parts[1], nullptr, 10);
b = std::stoul(parts[2], nullptr, 10);
return a << 24 | r << 16 | g << 8 | b;
}
}
catch (std::exception x)
PTwr marked this conversation as resolved.
Show resolved Hide resolved
{
Error("Invalid color: " + str);
}
PTwr marked this conversation as resolved.
Show resolved Hide resolved
}
return defaultColor;
}
} // namespace Subtitles
Loading