Skip to content

Commit

Permalink
Allow disabling backend using environment variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuAuahDark committed Aug 3, 2024
1 parent f527d30 commit 7dcab09
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/nav_backend_androidndk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,16 @@ const char *AndroidNDKBackend::getInfo()

Backend *create()
{
if (checkBackendDisabled("ANDROIDNDK"))
return nullptr;

try
{
return new AndroidNDKBackend();
}
catch(const std::exception& e)
{
nav::error::set(e);
return nullptr;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/nav_backend_ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@ const char *FFmpegBackend::getInfo()

Backend *create()
{
if (checkBackendDisabled("FFMPEG"))
return nullptr;

try
{
return new FFmpegBackend();
Expand Down
6 changes: 5 additions & 1 deletion src/nav_backend_mediafoundation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,12 +879,16 @@ const char *MediaFoundationBackend::getInfo()

Backend *create()
{
if (checkBackendDisabled("MEDIAFOUNDATION"))
return nullptr;

try
{
return new MediaFoundationBackend();
}
catch(const std::exception&)
catch(const std::exception &e)
{
nav::error::set(e);
return nullptr;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/nav_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ void *FrameVector::data() noexcept
return buffer.data();
}

bool checkBackendDisabled(const std::string &backendNameUppercase)
{
std::string name = "NAV_DISABLE_" + backendNameUppercase;
const char *value = getenv(name.c_str());

return value != nullptr && (
strcmp(value, "1") == 0 ||
strcmp(value, "ON") == 0 ||
strcmp(value, "on") == 0 ||
strcmp(value, "On") == 0 ||
strcmp(value, "YES") == 0 ||
strcmp(value, "yes") == 0 ||
strcmp(value, "Yes") == 0
);
}

#ifdef _WIN32
std::wstring fromUTF8(const std::string &str)
{
Expand Down
2 changes: 2 additions & 0 deletions src/nav_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ inline nav_audioformat makeAudioFormat(uint8_t bps, bool is_float, bool is_signe
return nav_audioformat(uint16_t(bps) | floatval | signedval);
}

bool checkBackendDisabled(const std::string &backendNameUppercase);

#ifdef _WIN32
std::wstring fromUTF8(const std::string &str);
#endif /* _WIN32 */
Expand Down

0 comments on commit 7dcab09

Please sign in to comment.