Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Avisynth compilation and update headers #161

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tools/repack-thes-dict.dSYM

# Meson
build*/
subprojects/avisynth
subprojects/boost*/
subprojects/cairo*
subprojects/ffmpeg
Expand Down
17 changes: 15 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project('Aegisub', ['c', 'cpp'],
license: 'BSD-3-Clause',
meson_version: '>=0.56.1',
meson_version: '>=0.57.0',
default_options: ['cpp_std=c++14', 'buildtype=debugoptimized'],
version: '3.2.2')

Expand Down Expand Up @@ -220,8 +220,21 @@ foreach dep: [
endif
endforeach

if host_machine.system() == 'windows' and get_option('avisynth').enabled()
if get_option('avisynth').enabled()
conf.set('WITH_AVISYNTH', 1) # bundled separately with installer
dep_avail += 'AviSynth'

avs_opt = cmake.subproject_options()
avs_opt.add_cmake_defines({
'HEADERS_ONLY': true
})

avs = cmake.subproject('avisynth', options: avs_opt)
deps_inc += avs.include_directories('AviSynth-Headers')

if host_machine.system() == 'windows'
deps += cc.find_library('avifil32', required: true)
endif
endif

if host_machine.system() == 'windows' and not get_option('directsound').disabled()
Expand Down
20 changes: 12 additions & 8 deletions src/audio_provider_avs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class AvisynthAudioProvider final : public agi::AudioProvider {
bool NeedsCache() const override { return true; }
};

AvisynthAudioProvider::AvisynthAudioProvider(agi::fs::path const& filename) {
agi::acs::CheckFileRead(filename);

AvisynthAudioProvider::AvisynthAudioProvider(agi::fs::path const& filename) try {
std::lock_guard<std::mutex> lock(avs_wrapper.GetMutex());

try {
Expand Down Expand Up @@ -100,19 +98,25 @@ AvisynthAudioProvider::AvisynthAudioProvider(agi::fs::path const& filename) {
throw agi::AudioProviderError("Avisynth error: " + errmsg);
}
}
catch (AvisynthError& err) {
throw agi::AudioProviderError("Avisynth error: " + std::string(err.msg));
}

void AvisynthAudioProvider::LoadFromClip(AVSValue clip) {
// Check if it has audio
VideoInfo vi = clip.AsClip()->GetVideoInfo();
if (!vi.HasAudio()) throw agi::AudioDataNotFound("No audio found.");

IScriptEnvironment *env = avs_wrapper.GetEnv();
AVSValue script;

// Convert to one channel
AVSValue script = env->Invoke(OPT_GET("Audio/Downmixer")->GetString().c_str(), clip);
std::string downmixtype = OPT_GET("Audio/Downmixer")->GetString();
if (downmixtype == "ConvertToMono" || downmixtype == "GetLeftChannel" || downmixtype == "GetRightChannel")
script = env->Invoke(downmixtype.c_str(), clip);
else
script = clip;

// Convert to 16 bits per sample
script = env->Invoke("ConvertAudioTo16bit", script);
vi = script.AsClip()->GetVideoInfo();

// Convert sample rate
Expand All @@ -132,8 +136,8 @@ void AvisynthAudioProvider::LoadFromClip(AVSValue clip) {
channels = vi.AudioChannels();
decoded_samples = num_samples = vi.num_audio_samples;
sample_rate = vi.SamplesPerSecond();
bytes_per_sample = vi.BytesPerAudioSample();
float_samples = false;
bytes_per_sample = vi.BytesPerChannelSample();
float_samples = vi.IsSampleType(SAMPLE_FLOAT);

this->clip = tempclip;
}
Expand Down
Loading
Loading