Skip to content

Commit

Permalink
remove _ffmpeg_initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Jul 8, 2023
1 parent 8aa24f4 commit 6a3885c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion test/torchaudio_unittest/common_utils/case_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TorchaudioTestCase(TestBaseMixin, PytorchTestCase):


def is_ffmpeg_available():
return torchaudio._extension._FFMPEG_INITIALIZED
return torchaudio._extension._FFMPEG_EXT is not None


_IS_CTC_DECODER_AVAILABLE = None
Expand Down
6 changes: 3 additions & 3 deletions torchaudio/_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import torch
import torchaudio.backend.soundfile_backend as soundfile_backend
from torchaudio._extension import _FFMPEG_INITIALIZED, _SOX_INITIALIZED
from torchaudio._extension import _FFMPEG_EXT, _SOX_INITIALIZED
from torchaudio.backend.common import AudioMetaData

if _FFMPEG_INITIALIZED:
if _FFMPEG_EXT is not None:
from torchaudio.io._compat import info_audio, info_audio_fileobj, load_audio, load_audio_fileobj, save_audio


Expand Down Expand Up @@ -262,7 +262,7 @@ def can_encode(uri, format) -> bool:
@lru_cache(None)
def get_available_backends() -> Dict[str, Backend]:
backend_specs = {}
if _FFMPEG_INITIALIZED:
if _FFMPEG_EXT is not None:
backend_specs["ffmpeg"] = FFmpegBackend
if _SOX_INITIALIZED:
backend_specs["sox"] = SoXBackend
Expand Down
5 changes: 1 addition & 4 deletions torchaudio/_extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"_IS_TORCHAUDIO_EXT_AVAILABLE",
"_IS_RIR_AVAILABLE",
"_SOX_INITIALIZED",
"_FFMPEG_INITIALIZED",
"_FFMPEG_EXT",
]

Expand Down Expand Up @@ -60,12 +59,10 @@


# Initialize FFmpeg-related features
_FFMPEG_INITIALIZED = False
_FFMPEG_EXT = None
if _IS_TORCHAUDIO_EXT_AVAILABLE:
try:
_FFMPEG_EXT = _init_ffmpeg()
_FFMPEG_INITIALIZED = True
except Exception:
# The initialization of FFmpeg extension will fail if supported FFmpeg
# libraries are not found in the system.
Expand All @@ -83,7 +80,7 @@
)
)

fail_if_no_ffmpeg = no_op if _FFMPEG_INITIALIZED else _fail_since_no_ffmpeg
fail_if_no_ffmpeg = _fail_since_no_ffmpeg if _FFMPEG_EXT is None else no_op

fail_if_no_rir = (
no_op
Expand Down
2 changes: 1 addition & 1 deletion torchaudio/backend/sox_io_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _fail_load(
raise RuntimeError("Failed to load audio from {}".format(filepath))


if torchaudio._extension._FFMPEG_INITIALIZED:
if torchaudio._extension._FFMPEG_EXT is not None:
import torchaudio.io._compat as _compat

_fallback_info = _compat.info_audio
Expand Down

0 comments on commit 6a3885c

Please sign in to comment.