From ee5433b9a55600ee45affa69f618a97a35924e14 Mon Sep 17 00:00:00 2001 From: Thomasys <31862942+Thomasyse@users.noreply.github.com> Date: Sun, 23 Jun 2024 00:01:19 -0700 Subject: [PATCH] 2.0.3 Updated Windows App SDK to 1.5.4 Supported printing FFmpeg error message --- BDMatch/BDMatch.aps | Bin 89232 -> 89232 bytes BDMatch/BDMatch.rc | Bin 5082 -> 5082 bytes BDMatch/MyForm.cpp | 2 +- BDMatchCore/BDMatchCore.aps | Bin 2688 -> 2688 bytes BDMatchCore/BDMatchCore.cpp | 3 -- BDMatchCore/BDMatchCore.rc | Bin 4546 -> 4546 bytes BDMatchCore/decoder.cpp | 64 ++++++++++++++++------------ BDMatchCore/headers/decoder.h | 2 + BDMatchCore/headers/language_pack.h | 2 +- BDMatchCore/language_pack.cpp | 2 +- BDMatchUI/App.xaml.cs | 2 +- BDMatchUI/BDMatchUI.csproj | 7 +-- 12 files changed, 46 insertions(+), 38 deletions(-) diff --git a/BDMatch/BDMatch.aps b/BDMatch/BDMatch.aps index 541efcd023d8a089e550725d1274a25e4b430c4c..7fc963b5d51aaf49dc31fbce192be784e2fa8df9 100644 GIT binary patch delta 41 xcmbQRlXb#Q)(u?joXiYt42%p649t^-+21l6Z)W5WXJj;PmgL+n$;ntA3;@9t2$KK+ delta 41 xcmbQRlXb#Q)(u?joJ -#define appversion "1.6.2" +#define appversion "1.6.3" #define secpurple 45 #define setintnum 5 #define MaxdB 20.0 diff --git a/BDMatchCore/BDMatchCore.aps b/BDMatchCore/BDMatchCore.aps index 4743c10cd37a1fbe212e9e427b58bb3d458ffde5..03e18a8b21506e3503d9871515f45a2c60e5e93d 100644 GIT binary patch delta 35 ncmZn=Z4lj{$HvLbzzBp449t_w*}gIwZ`Nh^X9QBU9L!7rcs2&X delta 35 ncmZn=Z4lj{$HvLTzzBp43`~>F*}gIwZPsP?X9QBU9L!7rcl8Fn diff --git a/BDMatchCore/BDMatchCore.cpp b/BDMatchCore/BDMatchCore.cpp index 583b3b6..419337a 100644 --- a/BDMatchCore/BDMatchCore.cpp +++ b/BDMatchCore/BDMatchCore.cpp @@ -367,6 +367,3 @@ int BDMatchCore::feedback_match() if (feed_func)feed_func(feedback.data(), feedback.size()); return 0; } - - - diff --git a/BDMatchCore/BDMatchCore.rc b/BDMatchCore/BDMatchCore.rc index 5f36dfadae6b549126d817adae3c0566e5646283..2dda073176636b6ae29c9e0cb2eb2f09ff537f03 100644 GIT binary patch delta 48 zcmX@4d`Nji8waEDfilefm = NULL;//文件格式; - if (avformat_open_input(&ffmpeg->filefm, file_name.data(), NULL, NULL) != 0) {//获取文件格式 - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 0));//"\n错误:无法打开文件!" + int ffmpeg_return = avformat_open_input(&ffmpeg->filefm, file_name.data(), NULL, NULL); + if (ffmpeg_return != 0) {//获取文件格式 + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 0), av_err_to_str(ffmpeg_return));//"\n错误:无法打开文件! 错误信息:{}" return_val = Match_Core_Return::File_Open_Err; clear_ffmpeg(); stop_src.request_stop(); return return_val; } - if (avformat_find_stream_info(ffmpeg->filefm, NULL) < 0) {//获取文件内音视频流的信息 - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 1));//"\n错误:无法读取文件流信息!" + ffmpeg_return = avformat_find_stream_info(ffmpeg->filefm, NULL); + if (ffmpeg_return < 0) {//获取文件内音视频流的信息 + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 1), av_err_to_str(ffmpeg_return));//"\n错误:无法读取文件流信息! 错误信息:{}" return_val = Match_Core_Return::File_Stream_Err; clear_ffmpeg(); stop_src.request_stop(); @@ -162,9 +164,9 @@ Match_Core_Return Decode::Decode::initialize(const std::string_view & file_name0 stop_src.request_stop(); return return_val; // Failed to allocate the codec context } - int getcodecpara = avcodec_parameters_to_context(ffmpeg->codecfm, ffmpeg->filefm->streams[audio_stream]->codecpar); - if (getcodecpara < 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 5));//"\n错误:无法复制音频的解码器参数!" + ffmpeg_return = avcodec_parameters_to_context(ffmpeg->codecfm, ffmpeg->filefm->streams[audio_stream]->codecpar); + if (ffmpeg_return < 0) { + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 5), av_err_to_str(ffmpeg_return));//"\n错误:无法复制音频的解码器参数! 错误信息:{}" return_val = Match_Core_Return::Codec_Copy_Para_Err; clear_ffmpeg(); stop_src.request_stop(); @@ -175,9 +177,10 @@ Match_Core_Return Decode::Decode::initialize(const std::string_view & file_name0 str_vfmt(lang_pack.get_text(Lang_Type::Decoder_Info, 8), audio_stream), //"音轨编号:**" str_vfmt(lang_pack.get_text(Lang_Type::Decoder_Info, 9), ffmpeg->codec->long_name));//" 音频编码:****" - if (avcodec_open2(ffmpeg->codecfm, ffmpeg->codec, NULL) < 0)//将两者结合以便在下面的解码函数中调用pInCodec中的对应解码函数 + ffmpeg_return = avcodec_open2(ffmpeg->codecfm, ffmpeg->codec, NULL);//将两者结合以便在下面的解码函数中调用pInCodec中的对应解码函数 + if (ffmpeg_return != 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 6));//"\n错误:无法打开音频的对应解码器!" + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 6), av_err_to_str(ffmpeg_return));//"\n错误:无法打开音频的对应解码器! 错误信息:{}" return_val = Match_Core_Return::Codec_Open_Err; clear_ffmpeg(); stop_src.request_stop(); @@ -275,6 +278,7 @@ Match_Core_Return Decode::Decode::decode_audio() { } if (ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_FLT || ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_FLTP) sample_type = 1; else if (ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_DBL || ffmpeg->codecfm->sample_fmt == AV_SAMPLE_FMT_DBLP) sample_type = 2; + int ffmpeg_return; //采样变量 int64_t samplenum = 0; c_min_db = 256.0 / (MaxdB - static_cast(min_db)); @@ -302,8 +306,9 @@ Match_Core_Return Decode::Decode::decode_audio() { av_opt_set_int(ffmpeg->swr_ctx, "out_sample_rate", resamp_rate, 0); av_opt_set_sample_fmt(ffmpeg->swr_ctx, "out_sample_fmt", ffmpeg->codecfm->sample_fmt, 0); /* initialize the resampling context */ - if ((swr_init(ffmpeg->swr_ctx)) < 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 9));//"\n错误:无法初始化重采样环境!" + ffmpeg_return = swr_init(ffmpeg->swr_ctx); + if (ffmpeg_return < 0) { + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 9), av_err_to_str(ffmpeg_return));//"\n错误:无法初始化重采样环境! 错误信息:{}" return_val = Match_Core_Return::Resample_Ctx_Init_Err; if (output_pcm)pcm.close(); clear_ffmpeg(); @@ -364,23 +369,21 @@ Match_Core_Return Decode::Decode::decode_audio() { return return_val; // Could not allocate frame } } - int ret = 0; - ret = avcodec_send_packet(ffmpeg->codecfm, ffmpeg->packet); - if (ret < 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 11));//"\n错误:无法提交音频至解码器!" + ffmpeg_return = avcodec_send_packet(ffmpeg->codecfm, ffmpeg->packet); + if (ffmpeg_return != 0) { + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 11), av_err_to_str(ffmpeg_return));//"\n错误:无法提交音频至解码器! 错误信息:{}" return_val = Match_Core_Return::Submit_Packet_Err; if (output_pcm)pcm.close(); clear_ffmpeg(); stop_src.request_stop(); return return_val; // Error submitting a packet for decoding } - int len = 0; - while (len >= 0) { - len = avcodec_receive_frame(ffmpeg->codecfm, ffmpeg->decoded_frame); - if (len == AVERROR(EAGAIN) || len == AVERROR_EOF) + while (ffmpeg_return >= 0) { + ffmpeg_return = avcodec_receive_frame(ffmpeg->codecfm, ffmpeg->decoded_frame); + if (ffmpeg_return == AVERROR(EAGAIN) || ffmpeg_return == AVERROR_EOF) break; - else if (len < 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 12));//"\n错误:音频解码出错!" + else if (ffmpeg_return < 0) { + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 12), av_err_to_str(ffmpeg_return));//"\n错误:音频解码出错! 错误信息:{}" return_val = Match_Core_Return::Decode_Err; if (output_pcm)pcm.close(); clear_ffmpeg(); @@ -390,7 +393,8 @@ Match_Core_Return Decode::Decode::decode_audio() { data_size = av_get_bytes_per_sample(ffmpeg->codecfm->sample_fmt); if (data_size < 0) { /* This should not occur, checking just for paranoia */ - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 13));//"\n错误:无法计算音频数据大小!" + ffmpeg_return = data_size; + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 13), av_err_to_str(ffmpeg_return));//"\n错误:无法计算音频数据大小! 错误信息:{}" return_val = Match_Core_Return::Data_Size_Err; if (output_pcm)pcm.close(); clear_ffmpeg(); @@ -407,20 +411,20 @@ Match_Core_Return Decode::Decode::decode_audio() { if (resamp) { nb_samples = static_cast( av_rescale_rnd(ffmpeg->decoded_frame->nb_samples, resamp_rate, sample_rate, AV_ROUND_ZERO)); - ret = av_samples_alloc_array_and_samples(&ffmpeg->dst_data, &dst_linesize, channels, + ffmpeg_return = av_samples_alloc_array_and_samples(&ffmpeg->dst_data, &dst_linesize, channels, nb_samples, ffmpeg->codecfm->sample_fmt, 0); - if (ret < 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 14));//"\n错误:无法为重采样数据分配内存!" + if (ffmpeg_return < 0) { + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 14), av_err_to_str(ffmpeg_return));//"\n错误:无法为重采样数据分配内存! 错误信息:{}" return_val = Match_Core_Return::Resample_Dst_Alloc_Err; if (output_pcm)pcm.close(); clear_ffmpeg(); stop_src.request_stop(); return return_val; // Could not allocate destination samples } - ret = swr_convert(ffmpeg->swr_ctx, ffmpeg->dst_data, nb_samples, + ffmpeg_return = swr_convert(ffmpeg->swr_ctx, ffmpeg->dst_data, nb_samples, (const uint8_t **)ffmpeg->decoded_frame->extended_data, ffmpeg->decoded_frame->nb_samples); - if (ret < 0) { - feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 2), lang_pack.get_text(Lang_Type::Decoder_Error, 15));//"\n错误:重采样错误!" + if (ffmpeg_return < 0) { + feedback = str_vfmt(lang_pack.get_text(Lang_Type::Notif, 3), lang_pack.get_text(Lang_Type::Decoder_Error, 15), av_err_to_str(ffmpeg_return));//"\n错误:重采样错误! 错误信息:{}" return_val = Match_Core_Return::Convert_Err; if (output_pcm)pcm.close(); clear_ffmpeg(); @@ -588,6 +592,10 @@ int Decode::Decode::set_vol_coef(const double &input) return 0; } +char* Decode::Decode::av_err_to_str(const int& err_code) +{ + return av_make_error_string(av_err_buf, AV_ERROR_MAX_STRING_SIZE, err_code); +} void Decode::Decode::sub_prog_back(double val) { if (prog_single) { diff --git a/BDMatchCore/headers/decoder.h b/BDMatchCore/headers/decoder.h index 65a457f..d0ea479 100644 --- a/BDMatchCore/headers/decoder.h +++ b/BDMatchCore/headers/decoder.h @@ -76,6 +76,7 @@ namespace Decode { int set_vol_coef(const double &input); int clear_ffmpeg(); protected: + char* av_err_to_str(const int &err_code); void sub_prog_back(double val); int clear_fft_data(); int clear_normalized_samples(double** normalized_samples); @@ -106,6 +107,7 @@ namespace Decode { char** fft_spec = nullptr; DataStruct::Spec_Node* fft_data_mem = nullptr; char* fft_spec_mem = nullptr; + char av_err_buf[AV_ERROR_MAX_STRING_SIZE] = { 0 }; //audio info std::string_view file_name; int out_bit_depth = 0; diff --git a/BDMatchCore/headers/language_pack.h b/BDMatchCore/headers/language_pack.h index f82bbd2..4ecef84 100644 --- a/BDMatchCore/headers/language_pack.h +++ b/BDMatchCore/headers/language_pack.h @@ -14,7 +14,7 @@ class Language_Pack { const std::string_view get_text(const Lang_Type& type, const size_t& index) const; private: std::vector general_texts = { u8"\n", u8" ", u8"->", u8"秒", u8", ", u8" " }; - std::vector notif_texts = { u8"\n 信息:{}", u8"\n 警告:{}", u8"\n 错误:{}" }; + std::vector notif_texts = { u8"\n 信息:{}", u8"\n 警告:{}", u8"\n 错误:{}", u8"\n 错误:{} 错误信息:{}" }; std::vector match_core_texts = { u8"\nTV文件:", u8"\nBD文件:", u8" 响度:{}dB" , u8"\n解码时间:{:.5f}{}", u8"\n字幕文件:" , u8"\n匹配时间:{:.5f}{}" }; std::vector decoder_error_texts = { u8"无法打开文件!", u8"无法读取文件流信息!", u8"无音频流!", u8"无法找到音频的对应解码器!", diff --git a/BDMatchCore/language_pack.cpp b/BDMatchCore/language_pack.cpp index a30dd43..1be182d 100644 --- a/BDMatchCore/language_pack.cpp +++ b/BDMatchCore/language_pack.cpp @@ -7,7 +7,7 @@ Language_Pack::Language_Pack(const Language& language) break; default: general_texts = { u8"\n", u8" ", u8"->", u8" Sec", u8", ", u8" " }; - notif_texts = { u8"\n Info: {}", u8"\n Warning: {}", u8"\n Error: {}" }; + notif_texts = { u8"\n Info: {}", u8"\n Warning: {}", u8"\n Error: {}", u8"\n Error: {} Err Msg: {}" }; match_core_texts = { u8"\nTV File: ", u8"\nBD File: ", u8" Loudness: {} dB" , u8"\nDecoding Time: {:.5f}{}", u8"\nSub File: " , u8"\nMatching time: {:.5f}{}" }; decoder_error_texts = { u8"Failed to open file!", u8"Failed to read file stream information!", u8"Didn't find a audio stream!", u8"Codec not found!", diff --git a/BDMatchUI/App.xaml.cs b/BDMatchUI/App.xaml.cs index 73117bf..fc7ceee 100644 --- a/BDMatchUI/App.xaml.cs +++ b/BDMatchUI/App.xaml.cs @@ -11,7 +11,7 @@ namespace BDMatchUI { static class Constants { - public const string App_Version = "2.0.2"; + public const string App_Version = "2.0.3"; public const string FFmpeg_Version = "7.0.1"; public const string FFTW_Version = "3.3.10"; public const string CopyRight_Year = "2024"; diff --git a/BDMatchUI/BDMatchUI.csproj b/BDMatchUI/BDMatchUI.csproj index c14c397..1086410 100644 --- a/BDMatchUI/BDMatchUI.csproj +++ b/BDMatchUI/BDMatchUI.csproj @@ -14,12 +14,13 @@ en-US 10.0.17763.0 BDMatch - 2.0.2 - 2.0.2 + 2.0.3 + 2.0.3 Thomasys By Thomasys logo.ico True + true true @@ -46,7 +47,7 @@ - +