Skip to content
Open

Sdl2 #18

Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ SmallPot是一个轻量级播放器。

## 编译

首先需要取得mlcc工程
部分源码在mlcc和kys-cpp(Engine.h和Engine.cpp)中,需同时将这些工程放到同级别的目录

```shell
git clone https://github.com/scarsty/mlcc mlcc
git clone https://github.com/scarsty/kys-cpp kys-cpp
```

Engine.h和Engine.cpp在kys-cpp中。

其余依赖库包括iconv,ffmpeg,libass,SDL2,SDL2-image,SDL2-ttf等,推荐使用系统的包管理工具获取这些库,Windows下推荐使用vcpkg。其中SDL2_image仅有一处使用,且并不是必须的,可以简单修改后去除。

Windows下也可以从<https://github.com/scarsty/lib-collection>取得头文件和导入库。
其余依赖库包括iconv,ffmpeg,libass,SDL2,SDL2-ttf等,推荐使用系统的包管理工具获取这些库,Windows下推荐使用vcpkg。

<https://github.com/AutoItConsulting/text-encoding-detect>直接包含代码到工程中。

Expand All @@ -57,9 +54,9 @@ Windows下也可以从<https://github.com/scarsty/lib-collection>取得头文件

### 单文件版

如果需要编译单文件(全静态链接)版,导入库比动态链接版要多出很多,建议使用vcpkg之类解决(vcpkg生成的fribidi静态库不正确,需手动修正)
如果需要编译单文件(全静态链接)版,导入库比动态链接版要多出很多,建议使用vcpkg之类解决。

以下为参考(fribidi及以下是动态链接不需要的)
以下为参考。其中fribidi及以下是动态链接不需要的,winmm.lib及以下是Windows自带的库

```
sdl2.lib
Expand All @@ -86,6 +83,9 @@ imm32.lib
bcrypt.lib
secur32.lib
ws2_32.Lib
mfplat.lib
mfuuid.lib
strmiids.lib
```

若是需要编译dll文件,用于在其他基于SDL2的游戏中播放视频时,则SmallPot和游戏均不应静态链接SDL。因为SDL的动态库中含有全局变量,多次静态链接后该变量会有多个副本,其中一个很可能是不正确的。
Expand All @@ -106,6 +106,10 @@ FFmpeg能解什么格式它就能放什么格式,FFmpeg不能解的,它也

查找字幕的方式是先依次将媒体文件的扩展名替换为ass、ssa、srt,并在媒体所在目录下以及subs子目录中寻找,即可以将字幕集中放到subs子目录。

### 字幕的字体文件

libass的字体文件只能设置一个目录,所以如果字体显示不正常请将其安装进系统。

### 功能键

| 按键 | 功能 |
Expand Down
2 changes: 1 addition & 1 deletion smallpot.dll/PotDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HBAPI void* MYTHAPI PotCreateFromHandle(void* handle)

HBAPI void* MYTHAPI PotCreateFromWindow(void* handle)
{
auto bp = new PotPlayer((BP_Window*)handle, 1);
auto bp = new PotPlayer((Window*)handle, 1);
return bp;
}

Expand Down
1 change: 0 additions & 1 deletion smallpot.dll/smallpot.dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<ClCompile Include="..\src\Config.cpp" />
<ClCompile Include="..\src\Font.cpp" />
<ClCompile Include="..\src\others\text_encoding_detect.cpp" />
<ClCompile Include="..\src\pot.cpp" />
<ClCompile Include="..\src\PotBase.cpp" />
<ClCompile Include="..\src\PotConv.cpp" />
<ClCompile Include="..\src\PotMedia.cpp" />
Expand Down
3 changes: 0 additions & 3 deletions smallpot.dll/smallpot.dll.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@
<ClCompile Include="..\src\Font.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\src\pot.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="..\src\PotBase.cpp">
<Filter>源文件</Filter>
</ClCompile>
Expand Down
113 changes: 31 additions & 82 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Config::Config()
".bt.td",
".td",
};
fmt1::print("Config init\n");
}

Config::~Config()
Expand All @@ -28,71 +29,21 @@ void Config::init(std::string filepath)
{
filepath = filepath + "/";
}
filename_ = filepath + "smallpot.config.ini";
filename_ = filepath + "smallpot.config.json";
fmt1::print("try find config file: {}\n", filename_);
ini_.loadFile(filename_);
//setString("filepath", filepath);

for (auto& s : ini_["record"].getAllKeys())
{
if (!s.empty())
{
Record r;
uint64_t t;
r.filename = s;
auto v = strfunc::findNumbers<int64_t>(ini_.getString("record", s));
if (v.size() >= 1)
{
r.second = v[0];
}
if (v.size() >= 2)
{
t = v[1];
}
ini_["record"][s]["progress"] = r.second;
ini_["record"][s]["time_int"] = t;
//ini_["record"][s]["time"] = Timer::timeToString(time_t(t));
}
}
parse(filefunc::readFileToString(filename_));
fmt1::print("read config file\n");
}

void Config::write()
{
ini_.saveFile(filename_);
}

std::string Config::getString(const std::string& name, std::string def /*= ""*/)
{
if (!ini_.hasKey("", name))
{
setString(name, def);
}
return ini_.getString("", name);
}

int Config::getInteger(const std::string& name, int def /*= 0*/)
{
if (!ini_.hasKey("", name))
{
setInteger(name, def);
}
return ini_.getInt("", name);
}

void Config::setString(const std::string& name, const std::string v)
{
ini_.setKey("", name, v);
}

void Config::setInteger(const std::string& name, int v)
{
setString(name, fmt1::format("{}", v));
filefunc::writeStringToFile(allToString(), filename_);
fmt1::print("write config file\n");
}

int Config::getRecord(const std::string& name)
{
//return ini_.getInt("record", enStr(name));
return ini_["record"][enStr(name)]["progress"].toInt();
return (*this)["record"][enStr(name)]["progress"].toInt();
}

std::string Config::getNewestRecord()
Expand All @@ -107,24 +58,21 @@ std::string Config::getNewestRecord()

void Config::removeRecord(const std::string& name)
{
ini_.eraseKey("record", enStr(name));
(*this)["record"].erase(enStr(name));
}

void Config::setRecord(const std::string& name, int v)
{
//ini_.setKey("record", enStr(name), std::to_string(v) + "," + std::to_string(time(0)));
ini_["record"][enStr(name)]["progress"] = v;
ini_["record"][enStr(name)]["time"] = Timer::getNowAsString();
(*this)["record"][enStr(name)]["progress"] = v;
(*this)["record"][enStr(name)]["time"] = Timer::getNowAsString();
}

void Config::clearAllRecord()
{
for (auto& s : ini_.getAllKeys("record"))
{
ini_.eraseKey("record", s);
}
(*this)["record"].clear();
}

//
void Config::autoClearRecord()
{
auto rv = getSortedRecord();
Expand All @@ -140,29 +88,29 @@ void Config::autoClearRecord()
{
if (i > 100)
{
ini_.eraseKey("record", rv[i].filename);
(*this)["record"].erase(rv[i].filename);
}
else
{
auto s1 = PotConv::conv(deStr(r.filename), "utf-8", getString("sys_encode"));
auto s1 = PotConv::conv(deStr(r.filename), "utf-8", (*this)["sys_encode"].toString());
if (!filefunc::fileExist(s1))
{
ini_.eraseKey("record", r.filename);
(*this)["record"].erase(r.filename);
}
}
}
}

std::string Config::dealFilename(const std::string& s0)
{
auto s = s0;
for (auto str : ignore_strs_)
{
s = strfunc::replaceAllSubString(s, str, "");
}
return s;
}

//std::string Config::dealFilename(const std::string& s0)
//{
// auto s = s0;
// for (auto str : ignore_strs_)
// {
// s = strfunc::replaceAllSubString(s, str, "");
// }
// return s;
//}
//
std::string Config::enStr(const std::string& in)
{
return in;
Expand Down Expand Up @@ -223,12 +171,13 @@ std::string Config::deStr(std::string out)
std::vector<Config::Record> Config::getSortedRecord()
{
std::vector<Record> rv;
for (auto& s : ini_["record"].getAllSections())
for (auto [k, v] : (*this)["record"].asMap())
{
Record r;
r.filename = s;
r.second = ini_["record"][s]["progress"].toInt();
r.time = ini_["record"][s]["time"].toString();
uint64_t t;
r.filename = k;
r.second = v["progress"].toInt();
r.time = v["time"].toString();
rv.push_back(r);
}
std::sort(rv.begin(), rv.end(), [](const Record& l, const Record& r)
Expand All @@ -248,7 +197,7 @@ std::string Config::findSuitableFilename(const std::string& filename)
{
return filename;
}
if (rv.filename.find(filename) == 0)
if (!filename.empty() && rv.filename.find(filename) == 0)
{
filename1 = rv.filename;
return filename1;
Expand Down
43 changes: 25 additions & 18 deletions src/Config.h
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
#pragma once

#include "INIReader.h"
#include <stdint.h>
#include "FakeJson.h"
#include <vector>

class Config
class Config : public FakeJson
{
struct Record
{
std::string filename;
std::string filename, path;
int second;
std::string time;
};

//
private:
std::string content_;
std::string filename_;
Config();
virtual ~Config();

INIReaderNormal ini_;

//
// INIReaderNormal ini_;
//
std::vector<std::string> ignore_strs_;

//
public:
void init(std::string filepath);

//
void write();
static Config* getInstance()

static Config& getInstance()
{
static Config c;
return &c;
return c;
}

//xml只有字串,故首先完成字串功能
std::string getString(const std::string& name, std::string def = "");
int getInteger(const std::string& name, int def = 0);

void setString(const std::string& name, const std::string v);
void setInteger(const std::string& name, int v);
template <typename K, typename T>
T get(const K& k, T default_v)
{
if (exist(k))
{
return (*this)[k].to<T>();
}
else
{
return default_v;
}
}

//记录
int getRecord(const std::string& name);
Expand All @@ -48,7 +55,7 @@ class Config
void clearAllRecord();
void autoClearRecord();

std::string dealFilename(const std::string& s0);
// std::string dealFilename(const std::string& s0);

std::string enStr(const std::string& in);
std::string deStr(std::string out);
Expand Down
Loading