diff --git a/BDMatch/BDMatch.aps b/BDMatch/BDMatch.aps index e63a7e4..9ccf225 100644 Binary files a/BDMatch/BDMatch.aps and b/BDMatch/BDMatch.aps differ diff --git a/BDMatch/BDMatch.rc b/BDMatch/BDMatch.rc index f2ee8e7..bc6cf43 100644 Binary files a/BDMatch/BDMatch.rc and b/BDMatch/BDMatch.rc differ diff --git a/BDMatch/MyForm.cpp b/BDMatch/MyForm.cpp index e408ff1..7d10a56 100644 --- a/BDMatch/MyForm.cpp +++ b/BDMatch/MyForm.cpp @@ -5,7 +5,7 @@ #pragma managed #include -#define appversion "1.5.16" +#define appversion "1.5.17" #define secpurple 45 #define setintnum 5 #define MaxdB 20.0 @@ -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); } } // @@ -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(); @@ -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(tv_draw.fft_num) * 100.0); - bd_draw.ttf = BDMatchCoreAPI::get_decode_info(Decode_File::TV_Decode, Decode_Info::Samp_Rate) / (static_cast(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(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(bd_draw.fft_num) * 100.0); ViewSel->SelectedIndex = 0; ChSelect->SelectedIndex = 0; ChSelect->Enabled = true; @@ -890,7 +890,7 @@ void BDMatch::MyForm::feedback(const char* input, const long long len) if (len > 0) { array^ bytes = gcnew array(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(input); diff --git a/BDMatchCore/BDMatchCore.aps b/BDMatchCore/BDMatchCore.aps index 49d3ab9..a8ce14d 100644 Binary files a/BDMatchCore/BDMatchCore.aps and b/BDMatchCore/BDMatchCore.aps differ diff --git a/BDMatchCore/BDMatchCore.cpp b/BDMatchCore/BDMatchCore.cpp index 583329e..38c9574 100644 --- a/BDMatchCore/BDMatchCore.cpp +++ b/BDMatchCore/BDMatchCore.cpp @@ -1,9 +1,10 @@ #include "headers/BDMatchCore.h" #include "headers/multithreading.h" -#include BDMatchCore::BDMatchCore() { + keep_processing = std::make_shared(); + keep_processing->test_and_set(); } BDMatchCore::~BDMatchCore() { @@ -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); @@ -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; } @@ -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); @@ -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; @@ -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(); - keep_processing->test_and_set(); - return 0; -} int BDMatchCore::start_process() { keep_processing->test_and_set(); @@ -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(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(proc)) + spend_str + + lang_pack.get_text(Lang_Type::General, 3);//"\r\n解码(/匹配)时间:**.***秒" feed_func(feedback.c_str(), feedback.length()); } return 0; diff --git a/BDMatchCore/BDMatchCore.rc b/BDMatchCore/BDMatchCore.rc index 70cfc50..88edd78 100644 Binary files a/BDMatchCore/BDMatchCore.rc and b/BDMatchCore/BDMatchCore.rc differ diff --git a/BDMatchCore/BDMatchCore.vcxproj b/BDMatchCore/BDMatchCore.vcxproj index 76d0d23..0afd921 100644 --- a/BDMatchCore/BDMatchCore.vcxproj +++ b/BDMatchCore/BDMatchCore.vcxproj @@ -170,7 +170,7 @@ - + @@ -187,7 +187,7 @@ - + diff --git a/BDMatchCore/BDMatchCore.vcxproj.filters b/BDMatchCore/BDMatchCore.vcxproj.filters index 67bf61e..b9dcea7 100644 --- a/BDMatchCore/BDMatchCore.vcxproj.filters +++ b/BDMatchCore/BDMatchCore.vcxproj.filters @@ -33,9 +33,6 @@ 头文件 - - 头文件 - 头文件 @@ -45,11 +42,11 @@ 头文件 + + 头文件 + - - 源文件 - 源文件 @@ -71,6 +68,9 @@ 源文件 + + 源文件 + diff --git a/BDMatchCore/BDMatchCoreAPI.cpp b/BDMatchCore/BDMatchCoreAPI.cpp index 65760ea..2a3b64d 100644 --- a/BDMatchCore/BDMatchCoreAPI.cpp +++ b/BDMatchCore/BDMatchCoreAPI.cpp @@ -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(); } @@ -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); } diff --git a/BDMatchCore/CLI.cpp b/BDMatchCore/CLI.cpp index 0b98b4f..27e3da6 100644 --- a/BDMatchCore/CLI.cpp +++ b/BDMatchCore/CLI.cpp @@ -8,6 +8,8 @@ A simple example of command line usage of BDMatchCore #include #include "headers/BDMatchCore.h" +constexpr const char* version = "1.0.17"; + void print(const char* in, const long long len) { std::cout << in; } @@ -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 << " \t" << i.tip << std::endl; - std::cout << "\t" << "-o \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 << " \t" << i.tip << std::endl; + std::cout << "\t" << "-o \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; @@ -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); diff --git a/BDMatchCore/headers/BDMatchCore.h b/BDMatchCore/headers/BDMatchCore.h index ad8d73c..5a6eaa8 100644 --- a/BDMatchCore/headers/BDMatchCore.h +++ b/BDMatchCore/headers/BDMatchCore.h @@ -1,12 +1,15 @@ #pragma once #include +#include #include "decoder.h" -#include "matching.h" +#include "match.h" #include "language_pack.h" typedef void(*prog_func)(int, double); typedef void(*feedback_func)(const char*, const long long len); +enum class Procedure { Decode = 4, Match = 6 }; + class BDMatchCore { public: BDMatchCore(); @@ -22,21 +25,20 @@ class BDMatchCore { int match_2(const char* output_path0); int clear_match(); size_t get_nb_timeline(); - int get_timeline(const int& index, const int& type); - int get_decode_info(const Decode_File& file, const Decode_Info& type); - char** get_decode_spec(const Decode_File& file); - int initialize_cancel_token(); + int get_timeline(const int& index, const Match::Timeline_Time_Type& type); + int get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type); + char** get_decode_spec(const Decode::Decode_File& file); int start_process(); int stop_process(); private: language_pack lang_pack;//language pack int feedback_tv(const std::string& tv_path); int feedback_bd(const std::string& bd_path, const double& bd_pre_avg_vol); - int feedback_time(const double& spend); + int feedback_time(const Procedure& proc); int feedback_match(); std::unique_ptr tv_decode; std::unique_ptr bd_decode; - std::unique_ptr match; + std::unique_ptr match; std::shared_ptr keep_processing = nullptr;//multithreading cancel token prog_func prog_back = nullptr; feedback_func feed_func = nullptr; @@ -53,4 +55,5 @@ class BDMatchCore { bool match_ass = true; bool fast_match = false; bool debug_mode = false; + std::chrono::time_point clock_start; }; \ No newline at end of file diff --git a/BDMatchCore/headers/datastruct.h b/BDMatchCore/headers/datastruct.h index 1cfff5d..dedea64 100644 --- a/BDMatchCore/headers/datastruct.h +++ b/BDMatchCore/headers/datastruct.h @@ -22,12 +22,11 @@ namespace DataStruct { } -enum class Decode_File { TV_Decode, BD_Decode }; -enum class Decode_Info { Channels, FFT_Samp_Num, Milisec, Samp_Rate, FFT_Num }; -enum class Sub_Type { ASS, SRT }; - -namespace Matching { - constexpr int Timeline_Start_Time = 0; - constexpr int Timeline_End_Time = 1; +namespace Decode { + enum class Decode_File { TV_Decode, BD_Decode }; + enum class Decode_Info { Channels, FFT_Samp_Num, Milisec, Samp_Rate, FFT_Num }; } +namespace Match { + enum class Timeline_Time_Type { Start_Time, End_Time }; +} \ No newline at end of file diff --git a/BDMatchCore/headers/language_pack.h b/BDMatchCore/headers/language_pack.h index 3ef6901..44d582c 100644 --- a/BDMatchCore/headers/language_pack.h +++ b/BDMatchCore/headers/language_pack.h @@ -11,7 +11,8 @@ class language_pack { std::string get_text(const Lang_Type& type, const int& index); private: std::vector general_texts = { u8"\r\n", u8" ", u8"->", u8"秒", u8", " }; - std::vector match_core_texts = { u8"TV文件:", u8"BD文件:", u8" 响度:", u8"dB" , u8"解码时间:", u8"\r\n字幕文件:" }; + std::vector match_core_texts = { u8"TV文件:", u8"BD文件:", u8" 响度:", u8"dB" , u8"\r\n解码时间:", u8"\r\n字幕文件:" , + u8"\r\n匹配时间:" }; std::vector decoder_texts = { u8"\r\n无法打开文件!", u8"\r\n无法读取文件流信息!", u8"\r\n无音频流!", u8"\r\n无法找到音频的对应解码器!", u8"\r\n无法创建音频的解码器信息!", u8"\r\n无法获取音频的解码器信息!", u8"\r\n无法打开音频的对应解码器!", u8"\r\n无法打开要写入的PCM文件!", u8"\r\n无法构建重采样环境!", u8"\r\n无法初始化重采样环境!", u8"\r\n无法为音频帧分配内存!", u8"\r\n无法提交音频至解码器!", u8"\r\n音频解码出错!", @@ -22,6 +23,6 @@ class language_pack { u8"行时长为零,将不作处理。", u8"\r\n警告:第", u8"行时长过长,将不作处理。", u8"行超过音频长度,将不作处理。", u8"行声音过小,将不作处理。", u8"\r\n信息:使用快速匹配。", u8"\r\nAverage Found Index = ", u8"% ", u8"Max Found Index= ", u8"%\r\nMax Found Line= ", u8" Max Delta= ", u8"行(与第", u8"行时间相同)可能存在匹配错误!", u8"行可能存在匹配错误:与前一行次序不一致!", u8"行可能存在匹配错误:与后一行次序不一致!", - u8"行可能存在匹配错误:与前后行时差不一致!", u8"行和第", u8"行发生微小重叠,已自动修正。", u8"\r\n打开输出字幕文件失败!", u8"\r\n写入字幕文件失败!", - u8"\r\n匹配时间:", u8"\r\nDiffa Consistency = " }; + u8"行可能存在匹配错误:与前后行时差不一致!", u8"行和第", u8"行发生微小重叠,已自动修正。", u8"\r\n打开输出字幕文件失败!", u8"\r\n写入字幕文件失败!", + u8"\r\nDiffa Consistency = " }; }; diff --git a/BDMatchCore/headers/matching.h b/BDMatchCore/headers/match.h similarity index 97% rename from BDMatchCore/headers/matching.h rename to BDMatchCore/headers/match.h index da095f0..5d5bb1f 100644 --- a/BDMatchCore/headers/matching.h +++ b/BDMatchCore/headers/match.h @@ -7,12 +7,14 @@ #include #include "language_pack.h" -namespace Matching { +namespace Match { using namespace DataStruct; typedef void (*prog_func)(int, double); + enum class Sub_Type { ASS, SRT }; + class timeline { public: @@ -84,7 +86,7 @@ namespace Matching { int output(const std::string &output_path);//write and check results at specific address int output();//write and check results at auto address long long get_nb_timeline();//return num of timeline - int get_timeline(const int &line, const int &type);//return timeline info + int get_timeline(const int& line, const Timeline_Time_Type& type);//return timeline info std::string get_feedback();//return timeline info protected: int load_ass(const std::string& ass_path0);//load ass file @@ -99,7 +101,6 @@ namespace Matching { prog_func prog_single = nullptr;//func_ptr for progress bar std::shared_ptr const keep_processing;//multithreading cancel token language_pack& lang_pack;//language pack - long startclock = 0;//timing //sub info and data Sub_Type sub_type = Sub_Type::ASS; std::string sub_path; diff --git a/BDMatchCore/include/BDMatchCoreAPI.h b/BDMatchCore/include/BDMatchCoreAPI.h index b857a38..f30ff26 100644 --- a/BDMatchCore/include/BDMatchCoreAPI.h +++ b/BDMatchCore/include/BDMatchCoreAPI.h @@ -24,9 +24,9 @@ namespace BDMatchCoreAPI { BDMatchCore_API int match_2(const char* output_path); BDMatchCore_API int clear_match(); BDMatchCore_API size_t get_nb_timeline(); - BDMatchCore_API int get_timeline(const int& index, const int& type); - BDMatchCore_API int get_decode_info(const Decode_File& file, const Decode_Info& type); - BDMatchCore_API char** get_decode_spec(const Decode_File& file); + BDMatchCore_API int get_timeline(const int& index, const Match::Timeline_Time_Type& type); + BDMatchCore_API int get_decode_info(const Decode::Decode_File& file, const Decode::Decode_Info& type); + BDMatchCore_API char** get_decode_spec(const Decode::Decode_File& file); BDMatchCore_API int search_ISA_mode(); BDMatchCore_API const char* get_CPU_brand(); BDMatchCore_API int start_process(); diff --git a/BDMatchCore/makefile b/BDMatchCore/makefile index 17b19e2..dcee50b 100644 --- a/BDMatchCore/makefile +++ b/BDMatchCore/makefile @@ -62,14 +62,14 @@ decoder.o: $(headers)language_pack.h $(headers)datastruct.h $(headers)multithrea $(FFmpeg_headers) $(fftw_headers) $(headers)decoder.h $(CXX) $(CXXFLAGS) -c -o decoder.o decoder.cpp -# ==== Matching ===== -matching.o: $(headers)language_pack.h $(headers)datastruct.h $(headers)multithreading.h \ - $(headers)matching.h - $(CXX) $(CXXFLAGS) -c -o matching.o matching.cpp +# ==== Match ===== +match.o: $(headers)language_pack.h $(headers)datastruct.h $(headers)multithreading.h \ + $(headers)match.h + $(CXX) $(CXXFLAGS) -c -o match.o match.cpp # ==== BDMatchCore ===== bdmatchcore.o: $(headers)language_pack.h $(headers)multithreading.h \ - $(headers)decoder.h $(headers)matching.h \ + $(headers)decoder.h $(headers)match.h \ $(headers)BDMatchCore.h $(CXX) $(CXXFLAGS) -c -o bdmatchcore.o BDMatchCore.cpp @@ -77,9 +77,9 @@ bdmatchcore.o: $(headers)language_pack.h $(headers)multithreading.h \ bdmatch.o: $(CXX) $(CXXFLAGS) -c -o bdmatch.o CLI.cpp -bdmatch: bdmatch.o bdmatchcore.o matching.o decoder.o \ +bdmatch: bdmatch.o bdmatchcore.o match.o decoder.o \ datastruct.o language_pack.o $(CXX) -o bdmatch \ - bdmatch.o bdmatchcore.o matching.o decoder.o \ + bdmatch.o bdmatchcore.o match.o decoder.o \ datastruct.o language_pack.o \ -lc -lm -lpthread $(FFmpeg_libs) $(fftw_libs) $(STDLIB) \ No newline at end of file diff --git a/BDMatchCore/matching.cpp b/BDMatchCore/match.cpp similarity index 90% rename from BDMatchCore/matching.cpp rename to BDMatchCore/match.cpp index b4fe95b..3c55d6e 100644 --- a/BDMatchCore/matching.cpp +++ b/BDMatchCore/match.cpp @@ -1,9 +1,8 @@ -#include "headers/matching.h" +#include "headers/match.h" #include "headers/multithreading.h" #include #include #include -#include #include constexpr int tvmax_num = 12; @@ -14,7 +13,7 @@ using namespace DataStruct; using std::min; using std::max; -Matching::timeline::timeline(int start0, int end0, bool iscom0, +Match::timeline::timeline(int start0, int end0, bool iscom0, const std::string &head0, const std::string &text0) { start_ = start0; @@ -23,69 +22,69 @@ Matching::timeline::timeline(int start0, int end0, bool iscom0, head_ = head0; former_text_ = text0; } -int Matching::timeline::start() +int Match::timeline::start() { return start_; } -int Matching::timeline::end() +int Match::timeline::end() { return end_; } -int Matching::timeline::duration() +int Match::timeline::duration() { return end_ - start_; } -bool Matching::timeline::iscom() +bool Match::timeline::iscom() { return iscom_; } -std::string Matching::timeline::head() +std::string Match::timeline::head() { return head_; } -std::string Matching::timeline::former_text() +std::string Match::timeline::former_text() { return former_text_; } -int Matching::timeline::start(const int &start0) +int Match::timeline::start(const int &start0) { start_ = start0; return 0; } -int Matching::timeline::end(const int &end0) +int Match::timeline::end(const int &end0) { end_ = end0; return 0; } -int Matching::timeline::iscom(const bool &iscom0) +int Match::timeline::iscom(const bool &iscom0) { iscom_ = iscom0; return 0; } -int Matching::timeline::head(std::string &head0) +int Match::timeline::head(std::string &head0) { head_ = head0; return 0; } -Matching::bdsearch::bdsearch() +Match::bdsearch::bdsearch() { } -int Matching::bdsearch::reserve(const int &num) +int Match::bdsearch::reserve(const int &num) { bditem.reserve(num); return 0; } -int Matching::bdsearch::push(const int &time, const int &diff) +int Match::bdsearch::push(const int &time, const int &diff) { bditem.emplace_back(std::array({ time, diff })); return 0; } -int Matching::bdsearch::read(const int &pos) +int Match::bdsearch::read(const int &pos) { return bditem[pos][0]; } -int Matching::bdsearch::find(const int &searchnum, const int &retype) +int Match::bdsearch::find(const int &searchnum, const int &retype) { int index = 0; for (auto &i : bditem) { @@ -98,37 +97,37 @@ int Matching::bdsearch::find(const int &searchnum, const int &retype) if (index >= bditem.size())index = -1; return index; } -int Matching::bdsearch::sort() +int Match::bdsearch::sort() { std::sort(bditem.begin(), bditem.end(), [](std::array &a, std::array&b) { return a[1] < b[1]; }); return 0; } -size_t Matching::bdsearch::size() +size_t Match::bdsearch::size() { return bditem.size(); } -int Matching::bdsearch::clear() +int Match::bdsearch::clear() { bditem.clear(); return 0; } -Matching::se_re::se_re() +Match::se_re::se_re() { } -long long& Matching::se_re::operator[](const int & index) +long long& Match::se_re::operator[](const int & index) { return data[index]; } -Matching::se_re::se_re(se_re &in) +Match::se_re::se_re(se_re &in) { data[0] = in[0]; data[1] = in[1]; } -int Matching::se_re::init() +int Match::se_re::init() { data[0] = 922372036854775808; data[1] = 0; @@ -136,17 +135,17 @@ int Matching::se_re::init() } -Matching::Match::Match(language_pack& lang_pack0, std::shared_ptr keep_processing0) +Match::Match::Match(language_pack& lang_pack0, std::shared_ptr keep_processing0) :keep_processing(keep_processing0), lang_pack(lang_pack0) { } -Matching::Match::~Match() +Match::Match::~Match() { if (search_result)delete[] search_result; search_result = nullptr; } -int Matching::Match::load_settings(const int & min_check_num0, const int & find_field0, const int &sub_offset0, +int Match::Match::load_settings(const int & min_check_num0, const int & find_field0, const int &sub_offset0, const int &max_length0, const bool & fast_match0, const bool & debug_mode0, const prog_func &prog_single0) { @@ -160,14 +159,12 @@ int Matching::Match::load_settings(const int & min_check_num0, const int & find_ return 0; } -int Matching::Match::load_decode_info(node ** const & tv_fft_data0, node ** const & bd_fft_data0, +int Match::Match::load_decode_info(node ** const & tv_fft_data0, node ** const & bd_fft_data0, const int & tv_ch0, const int & bd_ch0, const int & tv_fft_samp_num0, const int & bd_fft_samp_num0, const int & tv_milisec0, const int & bd_milisec0, const int & tv_samp_rate, const std::string & tv_file_name0, const std::string & bd_file_name0, const bool & bd_audio_only0) { - startclock = clock();//timing - //fft data tv_fft_data = tv_fft_data0; bd_fft_data = bd_fft_data0; fft_size = tv_fft_data[0][0].size(); @@ -204,7 +201,7 @@ int Matching::Match::load_decode_info(node ** const & tv_fft_data0, node ** cons return 0; } -int Matching::Match::load_sub(const std::string &sub_path0) +int Match::Match::load_sub(const std::string &sub_path0) { std::string ext_name = sub_path0.find_last_of('.') != std::string::npos ? sub_path0.substr(sub_path0.find_last_of('.')) : ""; @@ -217,7 +214,7 @@ int Matching::Match::load_sub(const std::string &sub_path0) else return load_ass(sub_path0); return 0; } -int Matching::Match::load_srt(const std::string &srt_path0) +int Match::Match::load_srt(const std::string &srt_path0) { using std::ios, std::regex, std::ifstream, std::smatch, std::string; feedback = ""; @@ -272,7 +269,7 @@ int Matching::Match::load_srt(const std::string &srt_path0) } return 0; } -int Matching::Match::load_ass(const std::string &ass_path0) +int Match::Match::load_ass(const std::string &ass_path0) { using std::ios, std::regex, std::ifstream, std::smatch, std::string; feedback = ""; @@ -341,7 +338,7 @@ int Matching::Match::load_ass(const std::string &ass_path0) } return 0; } -int Matching::Match::add_timeline(const int &start, const int &end, const bool &iscom, const std::string &header, const std::string &text) +int Match::Match::add_timeline(const int &start, const int &end, const bool &iscom, const std::string &header, const std::string &text) { timeline_list.emplace_back(timeline(start, end, iscom, header, text)); if (iscom) { @@ -413,7 +410,7 @@ int Matching::Match::add_timeline(const int &start, const int &end, const bool & return 0; } -int Matching::Match::match() +int Match::Match::match() { feedback = ""; //multithreading @@ -575,13 +572,13 @@ int Matching::Match::match() lang_pack.get_text(Lang_Type::Match_Sub, 13) + //"Max Found Index= ***%\r\nMax Found Line= " std::to_string(deb_info.max_line) + lang_pack.get_text(Lang_Type::Match_Sub, 14) + std::to_string(deb_info.max_delta) +//"*** Max Delta= ***" - lang_pack.get_text(Lang_Type::Match_Sub, 25) + std::to_string(deb_info.diffa_consis) + + lang_pack.get_text(Lang_Type::Match_Sub, 24) + std::to_string(deb_info.diffa_consis) + lang_pack.get_text(Lang_Type::Match_Sub, 11);//"\r\nDiffa Consistency = ***% " } return 0; } -int Matching::Match::output(const std::string &output_path) +int Match::Match::output(const std::string &output_path) { using std::vector, std::string, std::fstream, std::ios; feedback = ""; @@ -688,16 +685,10 @@ int Matching::Match::output(const std::string &output_path) feedback += lang_pack.get_text(Lang_Type::Match_Sub, 23);//"\r\n写入字幕文件失败!" return -1; } - long endclock = clock(); - double spend = (double(endclock) - double(startclock)) / (double)CLOCKS_PER_SEC; - 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::Match_Sub, 24) + spend_str + - lang_pack.get_text(Lang_Type::General, 3);//"\r\n匹配时间:***秒" if (prog_single)prog_single(3, 1.0); return 0; } -int Matching::Match::output() +int Match::Match::output() { std::string output_path; switch (sub_type) { @@ -717,17 +708,17 @@ int Matching::Match::output() return 0; } -long long Matching::Match::get_nb_timeline() +long long Match::Match::get_nb_timeline() { return nb_timeline; } -int Matching::Match::get_timeline(const int &line, const int &type) +int Match::Match::get_timeline(const int& line, const Timeline_Time_Type& type) { switch (type) { - case Timeline_Start_Time: + case Timeline_Time_Type::Start_Time: return timeline_list[line].start(); break; - case Timeline_End_Time: + case Timeline_Time_Type::End_Time: return timeline_list[line].end(); break; default: @@ -735,12 +726,12 @@ int Matching::Match::get_timeline(const int &line, const int &type) } return 0; } -std::string Matching::Match::get_feedback() +std::string Match::Match::get_feedback() { return feedback; } -std::string Matching::Match::cs2time(const int &cs0) +std::string Match::Match::cs2time(const int &cs0) { int hh, mm, ss, cs; cs = cs0; @@ -776,7 +767,7 @@ std::string Matching::Match::cs2time(const int &cs0) } return timeout; } -int Matching::Match::time2cs(const std::string &time) +int Match::Match::time2cs(const std::string &time) { using std::stoi; int cs = 0; @@ -800,7 +791,7 @@ int Matching::Match::time2cs(const std::string &time) return cs; } -int Matching::Match::caldiff(const int tv_start, const int se_start, const int se_end, const int min_check_num, +int Match::Match::caldiff(const int tv_start, const int se_start, const int se_end, const int min_check_num, const int check_field, se_re *re) { se_re feedback; @@ -847,7 +838,7 @@ int Matching::Match::caldiff(const int tv_start, const int se_start, const int s *re = feedback; return 0; } -int Matching::Match_SSE::caldiff(const int tv_start, const int se_start, const int se_end, const int min_check_num, +int Match::Match_SSE::caldiff(const int tv_start, const int se_start, const int se_end, const int min_check_num, const int check_field, se_re *re) { se_re feedback; @@ -910,7 +901,7 @@ int Matching::Match_SSE::caldiff(const int tv_start, const int se_start, const i *re = feedback; return 0; } -int Matching::Match_AVX2::caldiff(const int tv_start, const int se_start, const int se_end, const int min_check_num, +int Match::Match_AVX2::caldiff(const int tv_start, const int se_start, const int se_end, const int min_check_num, const int check_field, se_re *re) { se_re feedback; diff --git a/BDMatchCore/resource.h b/BDMatchCore/resource.h index 3bfe8a9..f83194b 100644 --- a/BDMatchCore/resource.h +++ b/BDMatchCore/resource.h @@ -1,9 +1,9 @@ //{{NO_DEPENDENCIES}} -// No need for platform other than Windows -// Microsoft Visual C++ generated include file. -// Used by BDMatchCore.rc +// Microsoft Visual C++ 生成的包含文件。 +// 供 BDMatchCore.rc 使用 +// -// 新对象的下一组默认值 +// Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS