Skip to content

Commit

Permalink
2.0.3
Browse files Browse the repository at this point in the history
Updated Windows App SDK to 1.5.4
Supported printing FFmpeg error message
  • Loading branch information
Thomasyse committed Jun 23, 2024
1 parent 93f1a95 commit ee5433b
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 38 deletions.
Binary file modified BDMatch/BDMatch.aps
Binary file not shown.
Binary file modified BDMatch/BDMatch.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion BDMatch/MyForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma managed
#include <msclr\marshal_cppstd.h>

#define appversion "1.6.2"
#define appversion "1.6.3"
#define secpurple 45
#define setintnum 5
#define MaxdB 20.0
Expand Down
Binary file modified BDMatchCore/BDMatchCore.aps
Binary file not shown.
3 changes: 0 additions & 3 deletions BDMatchCore/BDMatchCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,3 @@ int BDMatchCore::feedback_match()
if (feed_func)feed_func(feedback.data(), feedback.size());
return 0;
}



Binary file modified BDMatchCore/BDMatchCore.rc
Binary file not shown.
64 changes: 36 additions & 28 deletions BDMatchCore/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ Match_Core_Return Decode::Decode::initialize(const std::string_view & file_name0
file_name = file_name0;
ffmpeg = new FFmpeg;
ffmpeg->filefm = 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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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<double>(min_db));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -407,20 +411,20 @@ Match_Core_Return Decode::Decode::decode_audio() {
if (resamp) {
nb_samples = static_cast<int>(
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();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions BDMatchCore/headers/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion BDMatchCore/headers/language_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::u8string_view> general_texts = { u8"\n", u8" ", u8"->", u8"", u8", ", u8" " };
std::vector<std::u8string_view> notif_texts = { u8"\n 信息:{}", u8"\n 警告:{}", u8"\n 错误:{}" };
std::vector<std::u8string_view> notif_texts = { u8"\n 信息:{}", u8"\n 警告:{}", u8"\n 错误:{}", u8"\n 错误:{} 错误信息:{}" };
std::vector<std::u8string_view> match_core_texts = { u8"\nTV文件:", u8"\nBD文件:", u8" 响度:{}dB" , u8"\n解码时间:{:.5f}{}", u8"\n字幕文件:" ,
u8"\n匹配时间:{:.5f}{}" };
std::vector<std::u8string_view> decoder_error_texts = { u8"无法打开文件!", u8"无法读取文件流信息!", u8"无音频流!", u8"无法找到音频的对应解码器!",
Expand Down
2 changes: 1 addition & 1 deletion BDMatchCore/language_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
2 changes: 1 addition & 1 deletion BDMatchUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 4 additions & 3 deletions BDMatchUI/BDMatchUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
<DefaultLanguage>en-US</DefaultLanguage>
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>
<AssemblyName>BDMatch</AssemblyName>
<Version>2.0.2</Version>
<FileVersion>2.0.2</FileVersion>
<Version>2.0.3</Version>
<FileVersion>2.0.3</FileVersion>
<Authors>Thomasys</Authors>
<Copyright>By Thomasys</Copyright>
<ApplicationIcon>logo.ico</ApplicationIcon>
<IsPublishable>True</IsPublishable>
<SelfContained>true</SelfContained>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
</PropertyGroup>
<ItemGroup>
Expand All @@ -46,7 +47,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240607001" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down

0 comments on commit ee5433b

Please sign in to comment.