Skip to content

Commit

Permalink
1.5.17
Browse files Browse the repository at this point in the history
Better support for platforms other than Windows(#4 ).
Code simplification.
Timing with better precision.
  • Loading branch information
Thomasyse committed May 8, 2020
1 parent 55b1502 commit 18312fe
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 161 deletions.
Binary file modified BDMatch/BDMatch.aps
Binary file not shown.
Binary file modified BDMatch/BDMatch.rc
Binary file not shown.
36 changes: 18 additions & 18 deletions BDMatch/MyForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma managed
#include <msclr\marshal_cppstd.h>

#define appversion "1.5.16"
#define appversion "1.5.17"
#define secpurple 45
#define setintnum 5
#define MaxdB 20.0
Expand Down Expand Up @@ -112,8 +112,8 @@ int BDMatch::MyForm::write_ass(const char* sub_path, const char* output_path)
bd_draw.line_num = nb_timeline;
LineSel->Maximum = nb_timeline;
for (int i = 0; i < nb_timeline; i++) {
tv_draw.time_list[i, 0] = BDMatchCoreAPI::get_timeline(i, Matching::Timeline_Start_Time);
tv_draw.time_list[i, 1] = BDMatchCoreAPI::get_timeline(i, Matching::Timeline_End_Time);
tv_draw.time_list[i, 0] = BDMatchCoreAPI::get_timeline(i, Match::Timeline_Time_Type::Start_Time);
tv_draw.time_list[i, 1] = BDMatchCoreAPI::get_timeline(i, Match::Timeline_Time_Type::End_Time);
}
}
//
Expand All @@ -125,8 +125,8 @@ int BDMatch::MyForm::write_ass(const char* sub_path, const char* output_path)
//绘图相关
if (setting->draw) {
for (int i = 0; i < nb_timeline; i++) {
bd_draw.time_list[i, 0] = BDMatchCoreAPI::get_timeline(i, Matching::Timeline_Start_Time);
bd_draw.time_list[i, 1] = BDMatchCoreAPI::get_timeline(i, Matching::Timeline_End_Time);
bd_draw.time_list[i, 0] = BDMatchCoreAPI::get_timeline(i, Match::Timeline_Time_Type::Start_Time);
bd_draw.time_list[i, 1] = BDMatchCoreAPI::get_timeline(i, Match::Timeline_Time_Type::End_Time);
}
}
BDMatchCoreAPI::clear_match();
Expand Down Expand Up @@ -165,18 +165,18 @@ int BDMatch::MyForm::draw_pre()
int BDMatch::MyForm::draw_pre(const int &re)
{
if (setting->draw && !re) {
tv_draw.spec = BDMatchCoreAPI::get_decode_spec(Decode_File::TV_Decode);
bd_draw.spec = BDMatchCoreAPI::get_decode_spec(Decode_File::BD_Decode);
tv_draw.num = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::FFT_Samp_Num);
bd_draw.num = BDMatchCoreAPI::get_decode_info(Decode_File::BD_Decode, Decode_Info::FFT_Samp_Num);
tv_draw.ch = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::Channels);
bd_draw.ch = BDMatchCoreAPI::get_decode_info(Decode_File::BD_Decode, Decode_Info::Channels);
tv_draw.milisec = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::Milisec);
bd_draw.milisec = BDMatchCoreAPI::get_decode_info(Decode_File::BD_Decode, Decode_Info::Milisec);
tv_draw.fft_num = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::FFT_Num);
bd_draw.fft_num = BDMatchCoreAPI::get_decode_info(Decode_File::BD_Decode, Decode_Info::FFT_Num);
tv_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::Samp_Rate) / (static_cast<double>(tv_draw.fft_num) * 100.0);
bd_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::Samp_Rate) / (static_cast<double>(bd_draw.fft_num) * 100.0);
tv_draw.spec = BDMatchCoreAPI::get_decode_spec(Decode::Decode_File::TV_Decode);
bd_draw.spec = BDMatchCoreAPI::get_decode_spec(Decode::Decode_File::BD_Decode);
tv_draw.num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::FFT_Samp_Num);
bd_draw.num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::FFT_Samp_Num);
tv_draw.ch = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Channels);
bd_draw.ch = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::Channels);
tv_draw.milisec = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Milisec);
bd_draw.milisec = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::Milisec);
tv_draw.fft_num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::FFT_Num);
bd_draw.fft_num = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::BD_Decode, Decode::Decode_Info::FFT_Num);
tv_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Samp_Rate) / (static_cast<double>(tv_draw.fft_num) * 100.0);
bd_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode::Decode_File::TV_Decode, Decode::Decode_Info::Samp_Rate) / (static_cast<double>(bd_draw.fft_num) * 100.0);
ViewSel->SelectedIndex = 0;
ChSelect->SelectedIndex = 0;
ChSelect->Enabled = true;
Expand Down Expand Up @@ -890,7 +890,7 @@ void BDMatch::MyForm::feedback(const char* input, const long long len)
if (len > 0) {
array<Byte>^ bytes = gcnew array<Byte>(len);
Marshal::Copy(IntPtr((void*)input), bytes, 0, len);
Encoding^ encoder = Encoding::Unicode;
Encoding^ encoder = Encoding::UTF8;
Result->Text += encoder->GetString(bytes);
}
else if (len == -1) Result->Text += marshal_as<String^>(input);
Expand Down
Binary file modified BDMatchCore/BDMatchCore.aps
Binary file not shown.
67 changes: 33 additions & 34 deletions BDMatchCore/BDMatchCore.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "headers/BDMatchCore.h"
#include "headers/multithreading.h"
#include <time.h>

BDMatchCore::BDMatchCore()
{
keep_processing = std::make_shared<std::atomic_flag>();
keep_processing->test_and_set();
}
BDMatchCore::~BDMatchCore()
{
Expand Down Expand Up @@ -50,7 +51,7 @@ int BDMatchCore::decode(const char* tv_path0, const char* bd_path0)
std::string tv_path = tv_path0;
std::string bd_path = bd_path0;
if (prog_back)prog_back(0, 0);
long start = clock();//开始计时
clock_start = std::chrono::high_resolution_clock::now();//开始计时
//fftw设置
double* in = (double*)fftw_malloc(sizeof(double)*fft_num);
fftw_complex* out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*fft_num);
Expand Down Expand Up @@ -131,12 +132,9 @@ int BDMatchCore::decode(const char* tv_path0, const char* bd_path0)
return re;
}
}
//输出解码时间
long end = clock();
double spend = (double(end) - double(start)) / (double)CLOCKS_PER_SEC;
feedback_tv(tv_path);
feedback_bd(bd_path, bd_pre_avg_vol);
feedback_time(spend);
feedback_time(Procedure::Decode);
fftw_destroy_plan(plan);
return 0;
}
Expand All @@ -149,9 +147,10 @@ int BDMatchCore::match_1(const char *sub_path0)
keep_processing->clear();
return -2;
}
if (isa_mode == 0)match.reset(new Matching::Match(lang_pack, keep_processing));
else if (isa_mode <= 2)match.reset(new Matching::Match_SSE(lang_pack, keep_processing));
else if (isa_mode == 3)match.reset(new Matching::Match_AVX2(lang_pack, keep_processing));
clock_start = std::chrono::high_resolution_clock::now();//开始计时
if (isa_mode == 0)match.reset(new Match::Match(lang_pack, keep_processing));
else if (isa_mode <= 2)match.reset(new Match::Match_SSE(lang_pack, keep_processing));
else if (isa_mode == 3)match.reset(new Match::Match_AVX2(lang_pack, keep_processing));
int re = 0;
match->load_settings(min_check_num, find_field, sub_offset, max_length,
fast_match, debug_mode, prog_back);
Expand Down Expand Up @@ -192,6 +191,7 @@ int BDMatchCore::match_2(const char *output_path0)
re = match->output(output_path);
}
feedback_match();
feedback_time(Procedure::Match);
if (re < 0) return re;
}
return 0;
Expand All @@ -208,54 +208,52 @@ size_t BDMatchCore::get_nb_timeline()
if (match)return match->get_nb_timeline();
else return 0;
}
int BDMatchCore::get_timeline(const int & index, const int & type)
int BDMatchCore::get_timeline(const int & index, const Match::Timeline_Time_Type& type)
{
if (match)return match->get_timeline(index, type);
else return -1;
}

int BDMatchCore::get_decode_info(const Decode_File & file, const Decode_Info & type)
int BDMatchCore::get_decode_info(const Decode::Decode_File & file, const Decode::Decode_Info & type)
{
Decode::Decode *decode_ptr;
if (file == Decode_File::BD_Decode)decode_ptr = bd_decode.get();
if (file == Decode::Decode_File::BD_Decode)decode_ptr = bd_decode.get();
else decode_ptr = tv_decode.get();
if (!decode_ptr)return -1;
switch (type) {
case Decode_Info::Channels:
case Decode::Decode_Info::Channels:
return decode_ptr->get_channels();
break;
case Decode_Info::FFT_Samp_Num:
case Decode::Decode_Info::FFT_Samp_Num:
return decode_ptr->get_fft_samp_num();
break;
case Decode_Info::Milisec:
case Decode::Decode_Info::Milisec:
return decode_ptr->get_milisec();
break;
case Decode_Info::Samp_Rate:
case Decode::Decode_Info::Samp_Rate:
return decode_ptr->get_samp_rate();
break;
case Decode_Info::FFT_Num:
case Decode::Decode_Info::FFT_Num:
return decode_ptr->get_fft_num();
break;
default:
break;
}
return 0;
}
char ** BDMatchCore::get_decode_spec(const Decode_File & file)
char ** BDMatchCore::get_decode_spec(const Decode::Decode_File & file)
{
Decode::Decode *decode_ptr;
if (file == Decode_File::TV_Decode)decode_ptr = tv_decode.get();
else decode_ptr = bd_decode.get();
Decode::Decode* decode_ptr = nullptr;
switch (file) {
case Decode::Decode_File::TV_Decode:
decode_ptr = tv_decode.get();
break;
case Decode::Decode_File::BD_Decode:
decode_ptr = bd_decode.get();
break;
}
if (!decode_ptr)return nullptr;
else return decode_ptr->get_fft_spec();
}

int BDMatchCore::initialize_cancel_token()
{
keep_processing = std::make_shared<std::atomic_flag>();
keep_processing->test_and_set();
return 0;
}
int BDMatchCore::start_process()
{
keep_processing->test_and_set();
Expand Down Expand Up @@ -306,14 +304,15 @@ int BDMatchCore::feedback_bd(const std::string& bd_path, const double& bd_pre_av
}
return 0;
}
int BDMatchCore::feedback_time(const double& spend)
int BDMatchCore::feedback_time(const Procedure& proc)
{
if (feed_func) {
std::string feedback = "";
auto clock_end = std::chrono::high_resolution_clock::now();
double spend = std::chrono::duration<double>(clock_end - clock_start).count();
std::string spend_str = std::to_string(spend);
spend_str = spend_str.substr(0, spend_str.find_last_of('.') + 8);
feedback += lang_pack.get_text(Lang_Type::General, 0) + lang_pack.get_text(Lang_Type::Core, 4) +
spend_str + lang_pack.get_text(Lang_Type::General, 3);//"\r\n解码时间:**.***秒"
spend_str = spend_str.substr(0, spend_str.find_last_of('.') + 6);
std::string feedback = lang_pack.get_text(Lang_Type::Core, static_cast<int>(proc)) + spend_str +
lang_pack.get_text(Lang_Type::General, 3);//"\r\n解码(/匹配)时间:**.***秒"
feed_func(feedback.c_str(), feedback.length());
}
return 0;
Expand Down
Binary file modified BDMatchCore/BDMatchCore.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions BDMatchCore/BDMatchCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<ClInclude Include="headers\datastruct.h" />
<ClInclude Include="headers\decoder.h" />
<ClInclude Include="headers\language_pack.h" />
<ClInclude Include="headers\matching.h" />
<ClInclude Include="headers\match.h" />
<ClInclude Include="headers\multithreading.h" />
<ClInclude Include="headers\targetver.h" />
<ClInclude Include="include\BDMatchCoreAPI.h" />
Expand All @@ -187,7 +187,7 @@
<ClCompile Include="decoder.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="language_pack.cpp" />
<ClCompile Include="matching.cpp" />
<ClCompile Include="match.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BDMatchCore.rc" />
Expand Down
12 changes: 6 additions & 6 deletions BDMatchCore/BDMatchCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
<ClInclude Include="headers\language_pack.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="headers\matching.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="headers\multithreading.h">
<Filter>头文件</Filter>
</ClInclude>
Expand All @@ -45,11 +42,11 @@
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="headers\match.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="matching.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="datastruct.cpp">
<Filter>源文件</Filter>
</ClCompile>
Expand All @@ -71,6 +68,9 @@
<ClCompile Include="CLI.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="match.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BDMatchCore.rc">
Expand Down
7 changes: 3 additions & 4 deletions BDMatchCore/BDMatchCoreAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ BDMatchCore_API int BDMatchCoreAPI::new_BDMatchCore()
{
if (!match_core) {
match_core.reset(new BDMatchCore);
match_core->initialize_cancel_token();
cal_ISA_mode();
CPU_Brand = InstructionSet::Brand();
}
Expand Down Expand Up @@ -66,17 +65,17 @@ BDMatchCore_API size_t BDMatchCoreAPI::get_nb_timeline()
return match_core->get_nb_timeline();
}

BDMatchCore_API int BDMatchCoreAPI::get_timeline(const int& index, const int& type)
BDMatchCore_API int BDMatchCoreAPI::get_timeline(const int& index, const Match::Timeline_Time_Type& type)
{
return match_core->get_timeline(index, type);
}

BDMatchCore_API int BDMatchCoreAPI::get_decode_info(const Decode_File& file, const Decode_Info& type)
BDMatchCore_API int BDMatchCoreAPI::get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type)
{
return match_core->get_decode_info(file, type);
}

BDMatchCore_API char** BDMatchCoreAPI::get_decode_spec(const Decode_File& file)
BDMatchCore_API char** BDMatchCoreAPI::get_decode_spec(const Decode::Decode_File& file)
{
return match_core->get_decode_spec(file);
}
Expand Down
26 changes: 18 additions & 8 deletions BDMatchCore/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ A simple example of command line usage of BDMatchCore
#include <iostream>
#include "headers/BDMatchCore.h"

constexpr const char* version = "1.0.17";

void print(const char* in, const long long len) {
std::cout << in;
}
Expand Down Expand Up @@ -40,13 +42,22 @@ int main(int argc, char* argv[]) {
{20, "-maxlen", "the max length of the timeline to be matched, with the unit of second (default: 20)"} };
//help
std::string help_s = "--help";
if (argc == 2 && std::string(argv[1]) == help_s) {
std::cout << "Usage:" << std::endl <<
"bdmatch TV_file BD_file subtitle_file [Options] " << std::endl << "Options:" << std::endl;
for (auto& i : bool_settings) std::cout << "\t" << i.flag << "\t\t" << i.tip << std::endl;
for (auto& i : int_settings) std::cout << "\t" << i.flag << " <arg>\t" << i.tip << std::endl;
std::cout << "\t" << "-o <file>\toutput subtitle file path" << std::endl;
return 0;
if (argc == 2) {
if (argc == 2 && std::string(argv[1]) == help_s) {
std::cout << "Usage:" << std::endl <<
"bdmatch TV_file BD_file subtitle_file [Options]" << std::endl <<
"Verision:" << std::endl << "bdmatch -v" << std::endl <<
"Options:" << std::endl;
for (auto& i : bool_settings) std::cout << "\t" << i.flag << "\t\t" << i.tip << std::endl;
for (auto& i : int_settings) std::cout << "\t" << i.flag << " <arg>\t" << i.tip << std::endl;
std::cout << "\t" << "-o <file>\toutput subtitle file path" << std::endl;
return 0;
}
else if (std::string(argv[1]) == "-v") {
std::cout << "BDMatchCore" << std::endl << "Version " << version << std::endl <<
"Copyright (c) 2020, Thomasys" << std::endl;
return 0;
}
}
if (argc < 3) {
std::cout << "insufficient inputs, type 'bdmatch " << help_s << "' for help." << std::endl;
Expand Down Expand Up @@ -98,7 +109,6 @@ int main(int argc, char* argv[]) {
bool_settings[0].val, bool_settings[1].val, bool_settings[2].val,
int_settings[3].val, int_settings[4].val, int_settings[5].val, int_settings[6].val,
!bool_settings[3].val, bool_settings[4].val, bool_settings[5].val);
match_core->initialize_cancel_token();
//decode
int re = 0;
re = match_core->decode(tv_path, bd_path);
Expand Down
Loading

0 comments on commit 18312fe

Please sign in to comment.