Skip to content

Commit

Permalink
Further fixes to audio/video provider selection
Browse files Browse the repository at this point in the history
- Fix selection not aborting when the preferred provider returns null
- Fix the default video provider being "ffmpegsource" (lowercase)
  instead of "FFmpegSource", which would trip up provider selection
- More generally, make sure the preferred video provider actually exists
  and fall back to the default (FFmpegSource) if not.

Fixes #23 .
Fixes #61 .
Fixes #83 .
  • Loading branch information
arch1t3cht committed Oct 15, 2023
1 parent 02567c2 commit dd3016a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src/audio_provider_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ std::unique_ptr<agi::AudioProvider> SelectAudioProvider(fs::path const& filename
Path const& path_helper,
BackgroundRunner *br) {
auto preferred = OPT_GET("Audio/Provider")->GetString();

if (!std::any_of(std::begin(providers), std::end(providers), [&](factory provider) { return provider.name == preferred; })) {
preferred = OPT_GET("Audio/Provider")->GetDefaultString();
}

auto sorted = GetSorted(boost::make_iterator_range(std::begin(providers), std::end(providers)), preferred);

RearrangeWithPriority(sorted, filename);
Expand All @@ -84,9 +89,12 @@ std::unique_ptr<agi::AudioProvider> SelectAudioProvider(fs::path const& filename
std::string err;
try {
auto provider = factory->create(filename, br);
if (!provider) continue;
LOG_I("audio_provider") << "Using audio provider: " << factory->name;
return provider;
if (!provider) {
err = "Failed to create provider."; // Some generic error message here
} else {
LOG_I("audio_provider") << "Using audio provider: " << factory->name;
return provider;
}
}
catch (AudioDataNotFound const& ex) {
found_file = true;
Expand Down
4 changes: 2 additions & 2 deletions src/libresrc/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"Next Line on Commit" : true,
"Player" : "",
"Plays When Stepping Video" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Renderer" : {
"Spectrum" : {
"Cutoff" : 0,
Expand Down Expand Up @@ -660,7 +660,7 @@
"Last Script Resolution Mismatch Choice" : 2,
"Open Audio" : true,
"Overscan Mask" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Script Resolution Mismatch" : 1,
"Slider" : {
"Fast Jump Step" : 10,
Expand Down
4 changes: 2 additions & 2 deletions src/libresrc/osx/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"Next Line on Commit" : true,
"Player" : "",
"Plays When Stepping Video" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Renderer" : {
"Spectrum" : {
"Cutoff" : 0,
Expand Down Expand Up @@ -660,7 +660,7 @@
"Last Script Resolution Mismatch Choice" : 2,
"Open Audio" : true,
"Overscan Mask" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Script Resolution Mismatch" : 1,
"Slider" : {
"Fast Jump Step" : 10,
Expand Down
14 changes: 11 additions & 3 deletions src/video_provider_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ std::vector<std::string> VideoProviderFactory::GetClasses() {

std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br) {
auto preferred = OPT_GET("Video/Provider")->GetString();

if (!std::any_of(std::begin(providers), std::end(providers), [&](factory provider) { return provider.name == preferred; })) {
preferred = OPT_GET("Audio/Provider")->GetDefaultString();
}

auto sorted = GetSorted(boost::make_iterator_range(std::begin(providers), std::end(providers)), preferred);

RearrangeWithPriority(sorted, filename);
Expand All @@ -89,9 +94,12 @@ std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path c
std::string err;
try {
auto provider = factory->create(filename, colormatrix, br);
if (!provider) continue;
LOG_I("manager/video/provider") << factory->name << ": opened " << filename;
return finalize_provider(std::move(provider));
if (!provider) {
err = "Failed to create provider."; // Some generic error message here
} else {
LOG_I("manager/video/provider") << factory->name << ": opened " << filename;
return finalize_provider(std::move(provider));
}
}
catch (VideoNotSupported const& ex) {
found = true;
Expand Down

0 comments on commit dd3016a

Please sign in to comment.