Cleanup/stream part1 (#1093)

* use find_library from cytypes, enable rtc tests again

* install libvpx and libopus for unix on CI

* bug found when sending audio first

* no need for source path guard

* add more tests for libraries

* add more tests for libraries

* fix testing

* disable tests to see what happens

* disable tests to see what happens

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* debug ci

* hope to solve everything via ENV

* hope to solve everything via ENV

* hope to solve everything via ENV

* hope to solve everything via ENV

* hope to solve everything via ENV

* hope to solve everything via ENV

* hope to solve everything via ENV

* hope to solve everything via ENV

* fix testing

* fix testing

* fix testing

* fix testing

* fix testing

* fix testing

* switch to self hosted libraries

* fixes for macos

* switch to self hosted libraries

* switch to self hosted libraries

* switch to self hosted libraries

* switch to self hosted libraries

* switch to self hosted libraries

* switch to self hosted libraries

* switch to self hosted libraries

* switch to self hosted libraries
This commit is contained in:
Henry Ruhs
2026-05-11 16:36:23 +02:00
committed by henryruhs
parent 76c413a2c1
commit 8bbb6e7062
41 changed files with 277 additions and 105 deletions
+4 -11
View File
@@ -1,22 +1,15 @@
import ctypes
import ctypes.util
from functools import lru_cache
from typing import List, Optional
from facefusion.common_helper import is_linux
def resolve_library_file() -> Optional[str]:
if is_linux():
return 'libamd_smi.so'
return None
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_file = resolve_library_file()
library_path = ctypes.util.find_library('amd_smi')
if library_file:
library = ctypes.CDLL(library_file)
if library_path:
library = ctypes.CDLL(library_path)
if library:
return init_ctypes(library)
+4 -1
View File
@@ -56,7 +56,10 @@ def create_static_library() -> Optional[ctypes.CDLL]:
library_path = create_static_library_set().get('sources').get('datachannel').get('path')
if library_path:
library = ctypes.CDLL(library_path)
if is_windows():
library = ctypes.CDLL(library_path, winmode = 0)
else:
library = ctypes.CDLL(library_path)
if library:
return init_ctypes(library)
+4 -13
View File
@@ -1,24 +1,15 @@
import ctypes
import ctypes.util
from functools import lru_cache
from typing import List, Optional
from facefusion.common_helper import is_linux, is_windows
def resolve_library_file() -> Optional[str]:
if is_linux():
return 'libnvidia-ml.so.1'
if is_windows():
return 'nvml.dll'
return None
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_file = resolve_library_file()
library_path = ctypes.util.find_library('nvidia-ml') or ctypes.util.find_library('nvml')
if library_file:
library = ctypes.CDLL(library_file)
if library_path:
library = ctypes.CDLL(library_path)
if library:
return init_ctypes(library)
+49 -13
View File
@@ -1,26 +1,65 @@
import ctypes
import os
from functools import lru_cache
from typing import Optional
from typing import Dict, Optional, Tuple
from facefusion.common_helper import is_linux, is_macos, is_windows
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url_by_provider
from facefusion.filesystem import resolve_relative_path
from facefusion.types import DownloadSet
def resolve_library_file() -> Optional[str]:
def resolve_library_paths() -> Optional[Tuple[str, str]]:
if is_linux():
return 'libopus.so.0'
return 'linux/libopus.hash', 'linux/libopus.so'
if is_macos():
return 'libopus.dylib'
return 'macos/libopus.hash', 'macos/libopus.dylib'
if is_windows():
return 'opus.dll'
return 'windows/opus.hash', 'windows/opus.dll'
return None
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_file = resolve_library_file()
def create_static_library_set() -> Dict[str, DownloadSet]:
library_hash_path, library_source_path = resolve_library_paths()
if library_file:
library = ctypes.CDLL(library_file)
return\
{
'hashes':
{
'opus':
{
'url': resolve_download_url_by_provider('huggingface', 'libraries-4.0.0', library_hash_path),
'path': resolve_relative_path('../.libraries/' + os.path.basename(library_hash_path))
}
},
'sources':
{
'opus':
{
'url': resolve_download_url_by_provider('huggingface', 'libraries-4.0.0', library_source_path),
'path': resolve_relative_path('../.libraries/' + os.path.basename(library_source_path))
}
}
}
def pre_check() -> bool:
library_hash_set = create_static_library_set().get('hashes')
library_source_set = create_static_library_set().get('sources')
return conditional_download_hashes(library_hash_set) and conditional_download_sources(library_source_set)
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_path = create_static_library_set().get('sources').get('opus').get('path')
if library_path:
if is_windows():
library = ctypes.CDLL(library_path, winmode = 0)
else:
library = ctypes.CDLL(library_path)
if library:
return init_ctypes(library)
@@ -32,13 +71,10 @@ def init_ctypes(library : ctypes.CDLL) -> ctypes.CDLL:
library.opus_encoder_create.argtypes = [ ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int) ]
library.opus_encoder_create.restype = ctypes.c_void_p
library.opus_encode_float.argtypes = [ ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int, ctypes.c_char_p, ctypes.c_int ]
library.opus_encode_float.argtypes = [ ctypes.c_void_p, ctypes.POINTER(ctypes.c_float), ctypes.c_int, ctypes.c_char_p, ctypes.c_int ]
library.opus_encode_float.restype = ctypes.c_int
library.opus_encoder_destroy.argtypes = [ ctypes.c_void_p ]
library.opus_encoder_destroy.restype = None
library.opus_encoder_ctl.argtypes = [ ctypes.c_void_p, ctypes.c_int, ctypes.c_int ]
library.opus_encoder_ctl.restype = ctypes.c_int
return library
+4 -11
View File
@@ -1,22 +1,15 @@
import ctypes
import ctypes.util
from functools import lru_cache
from typing import Optional
from facefusion.common_helper import is_linux
def resolve_library_file() -> Optional[str]:
if is_linux():
return 'librocm-core.so'
return None
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_file = resolve_library_file()
library_path = ctypes.util.find_library('rocm-core')
if library_file:
library = ctypes.CDLL(library_file)
if library_path:
library = ctypes.CDLL(library_path)
if library:
return init_ctypes(library)
+48 -9
View File
@@ -1,26 +1,65 @@
import ctypes
import os
from functools import lru_cache
from typing import Optional
from typing import Dict, Optional, Tuple
from facefusion.common_helper import is_linux, is_macos, is_windows
from facefusion.download import conditional_download_hashes, conditional_download_sources, resolve_download_url_by_provider
from facefusion.filesystem import resolve_relative_path
from facefusion.types import DownloadSet
def resolve_library_file() -> Optional[str]:
def resolve_library_paths() -> Optional[Tuple[str, str]]:
if is_linux():
return 'libvpx.so'
return 'linux/libvpx.hash', 'linux/libvpx.so'
if is_macos():
return 'libvpx.dylib'
return 'macos/libvpx.hash', 'macos/libvpx.dylib'
if is_windows():
return 'vpx.dll'
return 'windows/vpx.hash', 'windows/vpx.dll'
return None
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_file = resolve_library_file()
def create_static_library_set() -> Dict[str, DownloadSet]:
library_hash_path, library_source_path = resolve_library_paths()
if library_file:
library = ctypes.CDLL(library_file)
return\
{
'hashes':
{
'vpx':
{
'url': resolve_download_url_by_provider('huggingface', 'libraries-4.0.0', library_hash_path),
'path': resolve_relative_path('../.libraries/' + os.path.basename(library_hash_path))
}
},
'sources':
{
'vpx':
{
'url': resolve_download_url_by_provider('huggingface', 'libraries-4.0.0', library_source_path),
'path': resolve_relative_path('../.libraries/' + os.path.basename(library_source_path))
}
}
}
def pre_check() -> bool:
library_hash_set = create_static_library_set().get('hashes')
library_source_set = create_static_library_set().get('sources')
return conditional_download_hashes(library_hash_set) and conditional_download_sources(library_source_set)
@lru_cache
def create_static_library() -> Optional[ctypes.CDLL]:
library_path = create_static_library_set().get('sources').get('vpx').get('path')
if library_path:
if is_windows():
library = ctypes.CDLL(library_path, winmode = 0)
else:
library = ctypes.CDLL(library_path)
if library:
return init_ctypes(library)