Compare commits
No commits in common. "celt" and "steam" have entirely different histories.
644
AMBuildScript
644
AMBuildScript
@ -1,5 +1,26 @@
|
||||
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
||||
import os
|
||||
import os, sys
|
||||
|
||||
# Simple extensions do not need to modify this file.
|
||||
|
||||
class SDK(object):
|
||||
def __init__(self, sdk, ext, aDef, name, platform, dir):
|
||||
self.folder = 'hl2sdk-' + dir
|
||||
self.envvar = sdk
|
||||
self.ext = ext
|
||||
self.code = aDef
|
||||
self.define = name
|
||||
self.platform = platform
|
||||
self.name = dir
|
||||
self.path = None
|
||||
|
||||
WinOnly = ['windows']
|
||||
WinLinux = ['windows', 'linux']
|
||||
WinLinuxMac = ['windows', 'linux', 'mac']
|
||||
|
||||
PossibleSDKs = {
|
||||
'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'),
|
||||
}
|
||||
|
||||
def ResolveEnvPath(env, folder):
|
||||
if env in os.environ:
|
||||
@ -21,72 +42,15 @@ def ResolveEnvPath(env, folder):
|
||||
|
||||
def Normalize(path):
|
||||
return os.path.abspath(os.path.normpath(path))
|
||||
|
||||
def SetArchFlags(compiler):
|
||||
if compiler.behavior == 'gcc':
|
||||
if compiler.target.arch == 'x86_64':
|
||||
compiler.cflags += ['-fPIC']
|
||||
elif compiler.like('msvc'):
|
||||
if compiler.target.arch == 'x86_64':
|
||||
compiler.defines += ['WIN64']
|
||||
|
||||
hl2sdk_manifests_path = None
|
||||
|
||||
# First we check if the manifest exists in the current path
|
||||
hl2sdk_manifests_path = os.path.join(builder.sourcePath, 'hl2sdk-manifests/SdkHelpers.ambuild')
|
||||
|
||||
if not os.path.exists(hl2sdk_manifests_path):
|
||||
# manifests does not exists in the project file, use the path from --hl2sdk-manifest-path
|
||||
if not builder.options.hl2sdk_manifest:
|
||||
raise Exception('HL2SDK Manifest root path not set! (--hl2sdk-manifest-path)')
|
||||
else:
|
||||
hl2sdk_manifests_path = os.path.join(builder.options.hl2sdk_manifest, 'SdkHelpers.ambuild')
|
||||
|
||||
if not os.path.exists(hl2sdk_manifests_path):
|
||||
raise Exception('Could not find SdkHelpers.ambuild in the given HL2SDK Manifest path!')
|
||||
|
||||
|
||||
SdkHelpers = builder.Eval(hl2sdk_manifests_path, {
|
||||
'Project': 'sm-extension'
|
||||
})
|
||||
|
||||
class ExtensionConfig(object):
|
||||
def __init__(self):
|
||||
self.sdk_manifests = []
|
||||
self.sdks = {}
|
||||
self.sdk_targets = []
|
||||
self.binaries = []
|
||||
self.extensions = []
|
||||
self.generated_headers = None
|
||||
self.mms_root = None
|
||||
self.sm_root = None
|
||||
self.all_targets = []
|
||||
self.target_archs = set()
|
||||
self.libsafetyhook = {}
|
||||
|
||||
if builder.options.targets:
|
||||
target_archs = builder.options.targets.split(',')
|
||||
else:
|
||||
target_archs = ['x86', 'x86_64']
|
||||
|
||||
for arch in target_archs:
|
||||
try:
|
||||
cxx = builder.DetectCxx(target_arch = arch)
|
||||
self.target_archs.add(cxx.target.arch)
|
||||
except Exception as e:
|
||||
# Error if archs were manually overridden.
|
||||
if builder.options.targets:
|
||||
raise
|
||||
print('Skipping target {}: {}'.format(arch, e))
|
||||
continue
|
||||
self.all_targets.append(cxx)
|
||||
|
||||
if not self.all_targets:
|
||||
raise Exception('No suitable C/C++ compiler was found.')
|
||||
|
||||
def use_auto_versioning(self):
|
||||
if builder.backend != 'amb2':
|
||||
return False
|
||||
return not getattr(builder.options, 'disable_auto_versioning', False)
|
||||
|
||||
@property
|
||||
def tag(self):
|
||||
@ -94,50 +58,35 @@ class ExtensionConfig(object):
|
||||
return 'Debug'
|
||||
return 'Release'
|
||||
|
||||
def findSdkPath(self, sdk_name):
|
||||
dir_name = 'hl2sdk-{}'.format(sdk_name)
|
||||
if builder.options.hl2sdk_root:
|
||||
sdk_path = os.path.join(builder.options.hl2sdk_root, dir_name)
|
||||
if os.path.exists(sdk_path):
|
||||
return sdk_path
|
||||
return ResolveEnvPath('HL2SDK{}'.format(sdk_name.upper()), dir_name)
|
||||
|
||||
def shouldIncludeSdk(self, sdk):
|
||||
return not sdk.get('source2', False)
|
||||
|
||||
def detectSDKs(self):
|
||||
sdk_list = [s for s in builder.options.sdks.split(',') if s]
|
||||
SdkHelpers.sdk_filter = self.shouldIncludeSdk
|
||||
SdkHelpers.find_sdk_path = self.findSdkPath
|
||||
SdkHelpers.findSdks(builder, self.all_targets, sdk_list)
|
||||
sdk_list = builder.options.sdks.split(',')
|
||||
use_all = sdk_list[0] == 'all'
|
||||
use_present = sdk_list[0] == 'present'
|
||||
|
||||
self.sdks = SdkHelpers.sdks
|
||||
self.sdk_manifests = SdkHelpers.sdk_manifests
|
||||
self.sdk_targets = SdkHelpers.sdk_targets
|
||||
for sdk_name in PossibleSDKs:
|
||||
sdk = PossibleSDKs[sdk_name]
|
||||
if builder.target_platform in sdk.platform:
|
||||
if builder.options.hl2sdk_root:
|
||||
sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder)
|
||||
else:
|
||||
sdk_path = ResolveEnvPath(sdk.envvar, sdk.folder)
|
||||
if sdk_path is None or not os.path.isdir(sdk_path):
|
||||
if use_all or sdk_name in sdk_list:
|
||||
raise Exception('Could not find a valid path for {0}'.format(sdk.envvar))
|
||||
continue
|
||||
if use_all or use_present or sdk_name in sdk_list:
|
||||
sdk.path = Normalize(sdk_path)
|
||||
self.sdks[sdk_name] = sdk
|
||||
|
||||
if builder.options.mms_path:
|
||||
self.mms_root = builder.options.mms_path
|
||||
else:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE112', 'mmsource-1.12')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'metamod-source')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
|
||||
|
||||
if not self.mms_root or not os.path.isdir(self.mms_root):
|
||||
raise Exception('Could not find a source copy of Metamod:Source')
|
||||
self.mms_root = Normalize(self.mms_root)
|
||||
if len(self.sdks) < 1:
|
||||
raise Exception('At least one SDK must be available.')
|
||||
|
||||
if builder.options.sm_path:
|
||||
self.sm_root = builder.options.sm_path
|
||||
else:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD112', 'sourcemod-1.12')
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8')
|
||||
if not self.sm_root:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod')
|
||||
if not self.sm_root:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod')
|
||||
if not self.sm_root:
|
||||
self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central')
|
||||
|
||||
@ -145,188 +94,281 @@ class ExtensionConfig(object):
|
||||
raise Exception('Could not find a source copy of SourceMod')
|
||||
self.sm_root = Normalize(self.sm_root)
|
||||
|
||||
if builder.options.mms_path:
|
||||
self.mms_root = builder.options.mms_path
|
||||
else:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
|
||||
if not self.mms_root:
|
||||
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
|
||||
|
||||
if not self.mms_root or not os.path.isdir(self.mms_root):
|
||||
raise Exception('Could not find a source copy of Metamod:Source')
|
||||
self.mms_root = Normalize(self.mms_root)
|
||||
|
||||
def configure(self):
|
||||
|
||||
allowed_archs = ['x86','x86_64']
|
||||
|
||||
if not set(self.target_archs).issubset(allowed_archs):
|
||||
raise Exception('Unknown target architecture: {0}'.format(self.target_archs))
|
||||
|
||||
for cxx in self.all_targets:
|
||||
self.configure_cxx(cxx)
|
||||
|
||||
def configure_cxx(self, cxx):
|
||||
if cxx.family == 'msvc':
|
||||
if cxx.version < 1914 and builder.options.generator != 'vs':
|
||||
raise Exception(f'Only MSVC 2017 15.7 and later are supported, full C++17 support is required. ({str(cxx.version)} < 1914)')
|
||||
elif cxx.family == 'gcc':
|
||||
if cxx.version < 'gcc-8':
|
||||
raise Exception('Only GCC versions 8 or later are supported, full C++17 support is required.')
|
||||
elif cxx.family == 'clang':
|
||||
if cxx.version < 'clang-5':
|
||||
raise Exception('Only clang versions 5 or later are supported, full C++17 support is required.')
|
||||
cxx = builder.DetectCompilers()
|
||||
|
||||
if cxx.like('gcc'):
|
||||
self.configure_gcc(cxx)
|
||||
elif cxx.family == 'msvc':
|
||||
self.configure_msvc(cxx)
|
||||
cxx.defines += [
|
||||
'stricmp=strcasecmp',
|
||||
'_stricmp=strcasecmp',
|
||||
'_snprintf=snprintf',
|
||||
'_vsnprintf=vsnprintf',
|
||||
'HAVE_STDINT_H',
|
||||
'GNUC',
|
||||
]
|
||||
cxx.cflags += [
|
||||
'-pipe',
|
||||
'-fno-strict-aliasing',
|
||||
'-Wall',
|
||||
# '-Werror',
|
||||
'-Wno-unused',
|
||||
'-Wno-switch',
|
||||
'-Wno-array-bounds',
|
||||
'-msse',
|
||||
'-m32',
|
||||
]
|
||||
cxx.cxxflags += [
|
||||
'-std=c++11',
|
||||
]
|
||||
|
||||
have_gcc = cxx.vendor == 'gcc'
|
||||
have_clang = cxx.vendor == 'clang'
|
||||
if have_clang or (have_gcc and cxx.version >= '4'):
|
||||
cxx.cflags += ['-fvisibility=hidden']
|
||||
cxx.cxxflags += ['-fvisibility-inlines-hidden']
|
||||
if have_clang or (have_gcc and cxx.version >= '4.6'):
|
||||
cxx.cflags += ['-Wno-narrowing']
|
||||
if (have_gcc and cxx.version >= '4.7') or (have_clang and cxx.version >= '3'):
|
||||
cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
|
||||
if have_gcc and cxx.version >= '4.8':
|
||||
cxx.cflags += ['-Wno-unused-result']
|
||||
if have_clang:
|
||||
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
|
||||
if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4':
|
||||
cxx.cxxflags += ['-Wno-deprecated-register']
|
||||
else:
|
||||
cxx.cxxflags += ['-Wno-deprecated']
|
||||
cxx.cflags += ['-Wno-sometimes-uninitialized']
|
||||
|
||||
cxx.linkflags += ['-m32']
|
||||
cxx.cxxflags += [
|
||||
'-fno-exceptions',
|
||||
'-fno-threadsafe-statics',
|
||||
'-Wno-non-virtual-dtor',
|
||||
'-Wno-overloaded-virtual',
|
||||
]
|
||||
|
||||
if have_gcc:
|
||||
cxx.cflags += ['-mfpmath=sse']
|
||||
elif cxx.vendor == 'msvc':
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/MTd']
|
||||
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
|
||||
else:
|
||||
cxx.cflags += ['/MT']
|
||||
cxx.defines += [
|
||||
'_CRT_SECURE_NO_DEPRECATE',
|
||||
'_CRT_SECURE_NO_WARNINGS',
|
||||
'_CRT_NONSTDC_NO_DEPRECATE',
|
||||
'_ITERATOR_DEBUG_LEVEL=0',
|
||||
]
|
||||
cxx.cflags += [
|
||||
'/W3',
|
||||
]
|
||||
cxx.cxxflags += [
|
||||
'/EHsc',
|
||||
'/GR-',
|
||||
'/TP',
|
||||
]
|
||||
cxx.linkflags += [
|
||||
'/MACHINE:X86',
|
||||
'kernel32.lib',
|
||||
'user32.lib',
|
||||
'gdi32.lib',
|
||||
'winspool.lib',
|
||||
'comdlg32.lib',
|
||||
'advapi32.lib',
|
||||
'shell32.lib',
|
||||
'ole32.lib',
|
||||
'oleaut32.lib',
|
||||
'uuid.lib',
|
||||
'odbc32.lib',
|
||||
'odbccp32.lib',
|
||||
]
|
||||
|
||||
# Optimization
|
||||
if builder.options.opt == '1':
|
||||
cxx.defines += ['NDEBUG']
|
||||
if cxx.like('gcc'):
|
||||
cxx.cflags += ['-O3']
|
||||
elif cxx.like('msvc'):
|
||||
cxx.cflags += ['/Ox', '/Zo']
|
||||
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
|
||||
|
||||
# Debugging
|
||||
if builder.options.debug == '1':
|
||||
cxx.defines += ['DEBUG', '_DEBUG']
|
||||
|
||||
# Platform-specifics
|
||||
if cxx.target.platform == 'linux':
|
||||
self.configure_linux(cxx)
|
||||
elif cxx.target.platform == 'mac':
|
||||
self.configure_mac(cxx)
|
||||
elif cxx.target.platform == 'windows':
|
||||
self.configure_windows(cxx)
|
||||
|
||||
def configure_gcc(self, cxx):
|
||||
cxx.defines += [
|
||||
'stricmp=strcasecmp',
|
||||
'_stricmp=strcasecmp',
|
||||
'_snprintf=snprintf',
|
||||
'_vsnprintf=vsnprintf',
|
||||
'HAVE_STDINT_H',
|
||||
'GNUC',
|
||||
]
|
||||
cxx.cflags += [
|
||||
'-pipe',
|
||||
'-fno-strict-aliasing',
|
||||
'-Wall',
|
||||
'-Werror',
|
||||
'-Wno-unused',
|
||||
'-Wno-switch',
|
||||
'-Wno-array-bounds',
|
||||
'-fvisibility=hidden',
|
||||
]
|
||||
|
||||
if cxx.target.arch in ['x86', 'x86_64']:
|
||||
cxx.cflags += ['-msse']
|
||||
|
||||
cxx.cxxflags += [
|
||||
'-fno-threadsafe-statics',
|
||||
'-Wno-non-virtual-dtor',
|
||||
'-Wno-overloaded-virtual',
|
||||
'-Wno-register',
|
||||
'-fvisibility-inlines-hidden',
|
||||
'-std=c++17',
|
||||
]
|
||||
|
||||
|
||||
have_gcc = cxx.family == 'gcc'
|
||||
have_clang = cxx.family == 'clang'
|
||||
|
||||
# Work around errors from smsdk_ext.cpp
|
||||
if have_clang:
|
||||
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
|
||||
|
||||
# Work around SDK warnings.
|
||||
if cxx.version >= 'clang-10.0' or cxx.version >= 'apple-clang-12.0':
|
||||
cxx.cflags += [
|
||||
'-Wno-implicit-int-float-conversion',
|
||||
'-Wno-tautological-overlap-compare',
|
||||
]
|
||||
|
||||
if have_gcc:
|
||||
cxx.cflags += ['-mfpmath=sse']
|
||||
cxx.cflags += ['-Wno-maybe-uninitialized']
|
||||
|
||||
if builder.options.opt == '1':
|
||||
cxx.cflags += ['-O3']
|
||||
|
||||
# Don't omit the frame pointer.
|
||||
cxx.cflags += ['-fno-omit-frame-pointer']
|
||||
|
||||
def configure_msvc(self, cxx):
|
||||
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/MTd']
|
||||
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
|
||||
else:
|
||||
cxx.cflags += ['/MT']
|
||||
cxx.defines += [
|
||||
'_CRT_SECURE_NO_DEPRECATE',
|
||||
'_CRT_SECURE_NO_WARNINGS',
|
||||
'_CRT_NONSTDC_NO_DEPRECATE',
|
||||
'_ITERATOR_DEBUG_LEVEL=0',
|
||||
]
|
||||
cxx.cflags += [
|
||||
'/W3',
|
||||
]
|
||||
cxx.cxxflags += [
|
||||
'/EHsc',
|
||||
'/GR-',
|
||||
'/TP',
|
||||
'/std:c++17',
|
||||
]
|
||||
cxx.linkflags += [
|
||||
'kernel32.lib',
|
||||
'user32.lib',
|
||||
'gdi32.lib',
|
||||
'winspool.lib',
|
||||
'comdlg32.lib',
|
||||
'advapi32.lib',
|
||||
'shell32.lib',
|
||||
'ole32.lib',
|
||||
'oleaut32.lib',
|
||||
'uuid.lib',
|
||||
'odbc32.lib',
|
||||
'odbccp32.lib',
|
||||
]
|
||||
|
||||
if builder.options.opt == '1':
|
||||
cxx.cflags += ['/Ox', '/Zo']
|
||||
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
|
||||
|
||||
if builder.options.debug == '1':
|
||||
cxx.cflags += ['/Od', '/RTC1']
|
||||
if cxx.like('msvc'):
|
||||
cxx.cflags += ['/Od', '/RTC1']
|
||||
|
||||
# This needs to be after our optimization flags which could otherwise disable it.
|
||||
# Don't omit the frame pointer.
|
||||
cxx.cflags += ['/Oy-']
|
||||
if cxx.vendor == 'msvc':
|
||||
# Don't omit the frame pointer.
|
||||
cxx.cflags += ['/Oy-']
|
||||
|
||||
def configure_linux(self, cxx):
|
||||
cxx.defines += ['LINUX', '_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64']
|
||||
cxx.linkflags += ['-lm']
|
||||
if cxx.family == 'gcc':
|
||||
cxx.linkflags += ['-static-libgcc']
|
||||
elif cxx.family == 'clang':
|
||||
cxx.linkflags += ['-lgcc_eh']
|
||||
cxx.linkflags += ['-static-libstdc++']
|
||||
# Platform-specifics
|
||||
if builder.target_platform == 'linux':
|
||||
cxx.defines += ['_LINUX', 'POSIX']
|
||||
cxx.linkflags += ['-lm']
|
||||
if cxx.vendor == 'gcc':
|
||||
cxx.linkflags += ['-static-libgcc']
|
||||
elif cxx.vendor == 'clang':
|
||||
cxx.linkflags += ['-lgcc_eh']
|
||||
elif builder.target_platform == 'mac':
|
||||
cxx.defines += ['OSX', '_OSX', 'POSIX']
|
||||
cxx.cflags += ['-mmacosx-version-min=10.5']
|
||||
cxx.linkflags += [
|
||||
'-mmacosx-version-min=10.5',
|
||||
'-arch', 'i386',
|
||||
'-lstdc++',
|
||||
'-stdlib=libstdc++',
|
||||
]
|
||||
cxx.cxxflags += ['-stdlib=libstdc++']
|
||||
elif builder.target_platform == 'windows':
|
||||
cxx.defines += ['WIN32', '_WINDOWS']
|
||||
|
||||
def configure_mac(self, cxx):
|
||||
cxx.defines += ['OSX', '_OSX', 'POSIX', 'KE_ABSOLUTELY_NO_STL']
|
||||
cxx.cflags += ['-mmacosx-version-min=10.15']
|
||||
cxx.linkflags += [
|
||||
'-mmacosx-version-min=10.15',
|
||||
'-stdlib=libc++',
|
||||
'-lc++',
|
||||
# Finish up.
|
||||
cxx.includes += [
|
||||
os.path.join(self.sm_root, 'public'),
|
||||
]
|
||||
cxx.cxxflags += ['-stdlib=libc++']
|
||||
|
||||
def ConfigureForHL2(self, binary, sdk):
|
||||
compiler = binary.compiler
|
||||
|
||||
if sdk.name == 'episode1':
|
||||
mms_path = os.path.join(self.mms_root, 'core-legacy')
|
||||
else:
|
||||
mms_path = os.path.join(self.mms_root, 'core')
|
||||
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(mms_path),
|
||||
os.path.join(mms_path, 'sourcehook'),
|
||||
]
|
||||
|
||||
defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs]
|
||||
compiler.defines += defines
|
||||
|
||||
paths = [
|
||||
['public'],
|
||||
['public', 'engine'],
|
||||
['public', 'mathlib'],
|
||||
['public', 'vstdlib'],
|
||||
['public', 'tier0'],
|
||||
['public', 'tier1']
|
||||
]
|
||||
if sdk.name == 'episode1' or sdk.name == 'darkm':
|
||||
paths.append(['public', 'dlls'])
|
||||
paths.append(['game_shared'])
|
||||
else:
|
||||
paths.append(['public', 'game', 'server'])
|
||||
paths.append(['public', 'toolframework'])
|
||||
paths.append(['game', 'shared'])
|
||||
paths.append(['common'])
|
||||
|
||||
compiler.defines += ['SOURCE_ENGINE=' + sdk.code]
|
||||
|
||||
if sdk.name in ['sdk2013', 'bms'] and compiler.like('gcc'):
|
||||
# The 2013 SDK already has these in public/tier0/basetypes.h
|
||||
compiler.defines.remove('stricmp=strcasecmp')
|
||||
compiler.defines.remove('_stricmp=strcasecmp')
|
||||
compiler.defines.remove('_snprintf=snprintf')
|
||||
compiler.defines.remove('_vsnprintf=vsnprintf')
|
||||
|
||||
if compiler.like('msvc'):
|
||||
compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32']
|
||||
else:
|
||||
compiler.defines += ['COMPILER_GCC']
|
||||
|
||||
# For everything after Swarm, this needs to be defined for entity networking
|
||||
# to work properly with sendprop value changes.
|
||||
if sdk.name in ['blade', 'insurgency', 'csgo', 'dota']:
|
||||
compiler.defines += ['NETWORK_VARS_ENABLED']
|
||||
|
||||
if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota']:
|
||||
if builder.target_platform in ['linux', 'mac']:
|
||||
compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE']
|
||||
|
||||
if sdk.name == 'csgo' and builder.target_platform == 'linux':
|
||||
compiler.linkflags += ['-lstdc++']
|
||||
|
||||
for path in paths:
|
||||
compiler.cxxincludes += [os.path.join(sdk.path, *path)]
|
||||
|
||||
if builder.target_platform == 'linux':
|
||||
if sdk.name == 'episode1':
|
||||
lib_folder = os.path.join(sdk.path, 'linux_sdk')
|
||||
elif sdk.name in ['sdk2013', 'bms']:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32')
|
||||
else:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'linux')
|
||||
elif builder.target_platform == 'mac':
|
||||
if sdk.name in ['sdk2013', 'bms']:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32')
|
||||
else:
|
||||
lib_folder = os.path.join(sdk.path, 'lib', 'mac')
|
||||
|
||||
if builder.target_platform in ['linux', 'mac']:
|
||||
if sdk.name in ['sdk2013', 'bms']:
|
||||
compiler.postlink += [
|
||||
compiler.Dep(os.path.join(lib_folder, 'tier1.a')),
|
||||
compiler.Dep(os.path.join(lib_folder, 'mathlib.a'))
|
||||
]
|
||||
else:
|
||||
compiler.postlink += [
|
||||
compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a')),
|
||||
compiler.Dep(os.path.join(lib_folder, 'mathlib_i486.a'))
|
||||
]
|
||||
|
||||
if sdk.name in ['blade', 'insurgency', 'csgo', 'dota']:
|
||||
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))]
|
||||
|
||||
dynamic_libs = []
|
||||
if builder.target_platform == 'linux':
|
||||
if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2']:
|
||||
dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so']
|
||||
elif sdk.name in ['l4d', 'blade', 'insurgency', 'csgo', 'dota']:
|
||||
dynamic_libs = ['libtier0.so', 'libvstdlib.so']
|
||||
else:
|
||||
dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so']
|
||||
elif builder.target_platform == 'mac':
|
||||
compiler.linkflags.append('-liconv')
|
||||
dynamic_libs = ['libtier0.dylib', 'libvstdlib.dylib']
|
||||
elif builder.target_platform == 'windows':
|
||||
libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
|
||||
if sdk.name in ['swarm', 'blade', 'insurgency', 'csgo', 'dota']:
|
||||
libs.append('interfaces')
|
||||
for lib in libs:
|
||||
lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib'
|
||||
compiler.linkflags.append(compiler.Dep(lib_path))
|
||||
|
||||
for library in dynamic_libs:
|
||||
source_path = os.path.join(lib_folder, library)
|
||||
output_path = os.path.join(binary.localFolder, library)
|
||||
|
||||
def make_linker(source_path, output_path):
|
||||
def link(context, binary):
|
||||
cmd_node, (output,) = context.AddSymlink(source_path, output_path)
|
||||
return output
|
||||
return link
|
||||
|
||||
linker = make_linker(source_path, output_path)
|
||||
compiler.linkflags[0:0] = [compiler.Dep(library, linker)]
|
||||
|
||||
def configure_windows(self, cxx):
|
||||
cxx.defines += ['WIN32', '_WINDOWS']
|
||||
|
||||
def LibraryBuilder(self, compiler, name):
|
||||
binary = compiler.Library(name)
|
||||
self.AddVersioning(binary)
|
||||
if binary.compiler.like('msvc'):
|
||||
binary.compiler.linkflags += ['/SUBSYSTEM:WINDOWS']
|
||||
self.AddCxxCompat(binary)
|
||||
return binary
|
||||
|
||||
def Library(self, context, compiler, name):
|
||||
compiler = compiler.clone()
|
||||
SetArchFlags(compiler)
|
||||
return self.LibraryBuilder(compiler, name)
|
||||
|
||||
def ConfigureForExtension(self, context, compiler):
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(context.currentSourcePath),
|
||||
@ -334,89 +376,31 @@ class ExtensionConfig(object):
|
||||
os.path.join(self.sm_root, 'public'),
|
||||
os.path.join(self.sm_root, 'public', 'extensions'),
|
||||
os.path.join(self.sm_root, 'sourcepawn', 'include'),
|
||||
os.path.join(self.sm_root, 'public', 'amtl', 'amtl'),
|
||||
os.path.join(self.sm_root, 'public', 'amtl'),
|
||||
os.path.join(self.sm_root, 'public', 'amtl', 'include'),
|
||||
]
|
||||
return compiler
|
||||
|
||||
def HL2Project(self, context, name):
|
||||
project = context.compiler.LibraryProject(name)
|
||||
self.ConfigureForExtension(context, project.compiler)
|
||||
return project
|
||||
|
||||
def AddCDetour(self, binary):
|
||||
public_path = os.path.join(self.sm_root, 'public')
|
||||
binary.sources += [
|
||||
os.path.join(public_path, 'CDetour', 'detours.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'allocator.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'easy.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'inline_hook.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'mid_hook.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'os.linux.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'utility.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'src', 'vmt_hook.cpp'),
|
||||
os.path.join(public_path, 'safetyhook', 'zydis', 'Zydis.c')
|
||||
]
|
||||
|
||||
binary.compiler.includes += [
|
||||
os.path.join(public_path, 'safetyhook', 'include'),
|
||||
os.path.join(public_path, 'safetyhook', 'zydis'),
|
||||
]
|
||||
|
||||
def ExtLibrary(self, context, compiler, name):
|
||||
binary = self.Library(context, compiler, name)
|
||||
SetArchFlags(compiler)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return binary
|
||||
|
||||
def AddCxxCompat(self, binary):
|
||||
if binary.compiler.target.platform == 'linux':
|
||||
binary.sources += [
|
||||
os.path.join(self.sm_root, 'public', 'amtl', 'compat', 'stdcxx.cpp'),
|
||||
]
|
||||
|
||||
def ConfigureForHL2(self, context, binary, sdk):
|
||||
compiler = binary.compiler
|
||||
SetArchFlags(compiler)
|
||||
|
||||
compiler.cxxincludes += [
|
||||
os.path.join(self.mms_root, 'core'),
|
||||
os.path.join(self.mms_root, 'core', 'sourcehook'),
|
||||
]
|
||||
|
||||
for other_sdk in self.sdk_manifests:
|
||||
compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])]
|
||||
|
||||
SdkHelpers.configureCxx(context, binary, sdk)
|
||||
|
||||
return binary
|
||||
|
||||
def HL2Library(self, context, compiler, name, sdk):
|
||||
binary = self.Library(context, compiler, name)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return self.ConfigureForHL2(context, binary, sdk)
|
||||
|
||||
def HL2Config(self, project, context, compiler, name, sdk):
|
||||
binary = project.Configure(compiler, name,
|
||||
'{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch))
|
||||
self.AddCxxCompat(binary)
|
||||
return self.ConfigureForHL2(context, binary, sdk)
|
||||
|
||||
def HL2ExtConfig(self, project, context, compiler, name, sdk):
|
||||
binary = project.Configure(compiler, name,
|
||||
'{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch))
|
||||
self.AddCxxCompat(binary)
|
||||
self.ConfigureForHL2(context, binary, sdk)
|
||||
self.ConfigureForExtension(context, binary.compiler)
|
||||
return binary
|
||||
def HL2Config(self, project, name, sdk):
|
||||
binary = project.Configure(name, '{0} - {1}'.format(self.tag, sdk.name))
|
||||
return self.ConfigureForHL2(binary, sdk)
|
||||
|
||||
Extension = ExtensionConfig()
|
||||
Extension.detectSDKs()
|
||||
Extension.configure()
|
||||
|
||||
# This will clone the list and each cxx object as we recurse, preventing child
|
||||
# scripts from messing up global state.
|
||||
builder.targets = builder.CloneableList(Extension.all_targets)
|
||||
|
||||
# Add additional buildscripts here
|
||||
BuildScripts = [
|
||||
'AMBuilder',
|
||||
'PackageScript',
|
||||
]
|
||||
|
||||
builder.Build(BuildScripts, { 'Extension': Extension })
|
||||
if builder.backend == 'amb2':
|
||||
BuildScripts += [
|
||||
'PackageScript',
|
||||
]
|
||||
|
||||
builder.RunBuildScripts(BuildScripts, { 'Extension': Extension})
|
||||
|
41
AMBuilder
41
AMBuilder
@ -2,43 +2,26 @@
|
||||
import os
|
||||
|
||||
if not "SM" in globals():
|
||||
SM = Extension
|
||||
SM = Extension
|
||||
|
||||
projectName = 'Voice'
|
||||
|
||||
project = builder.LibraryProject(projectName)
|
||||
project = SM.HL2Project(builder, projectName + '.ext')
|
||||
project.sources += [
|
||||
'extension.cpp',
|
||||
os.path.join(SM.sm_root, 'public', 'smsdk_ext.cpp')
|
||||
'ringbuffer.cpp',
|
||||
'../../public/smsdk_ext.cpp'
|
||||
]
|
||||
|
||||
for sdk_name in SM.sdks:
|
||||
sdk = SM.sdks[sdk_name]
|
||||
if sdk['name'] in ['mock']:
|
||||
continue
|
||||
|
||||
for cxx in builder.targets:
|
||||
cxx.defines += ['HAVE_STRING_H'];
|
||||
if not cxx.target.arch in sdk['platforms'][cxx.target.platform]:
|
||||
continue
|
||||
|
||||
binary = Extension.HL2ExtConfig(project, builder, cxx, projectName + '.ext.' + sdk['extension'], sdk)
|
||||
|
||||
SM.AddCDetour(binary)
|
||||
|
||||
binary.compiler.cxxflags += [
|
||||
'-Wno-dangling-else',
|
||||
'-Wno-unknown-pragmas',
|
||||
'-Wno-unused-result',
|
||||
'-Wno-sign-compare',
|
||||
]
|
||||
|
||||
binary.compiler.cxxincludes += [
|
||||
os.path.join(builder.sourcePath, 'celt')
|
||||
]
|
||||
binary.compiler.linkflags += [
|
||||
os.path.join(builder.sourcePath, 'celt', 'libcelt0.a')
|
||||
]
|
||||
|
||||
binary = SM.HL2Config(project, projectName + '.ext', sdk)
|
||||
binary.compiler.cxxincludes += [
|
||||
os.path.join(SM.sm_root, 'public', 'extensions'),
|
||||
os.path.join(builder.sourcePath, 'silk')
|
||||
]
|
||||
binary.compiler.linkflags += [
|
||||
os.path.join(builder.sourcePath, 'silk', 'libSKP_SILK_SDK.a')
|
||||
]
|
||||
|
||||
SM.extensions += builder.Add(project)
|
||||
|
4
Makefile
4
Makefile
@ -109,7 +109,7 @@ else
|
||||
LIB_SUFFIX = .$(LIB_EXT)
|
||||
endif
|
||||
|
||||
INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/sourcepawn/include
|
||||
INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn
|
||||
|
||||
ifeq "$(USEMETA)" "true"
|
||||
LINK_HL2 = $(HL2LIB)/tier1_i486.a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX)
|
||||
@ -131,7 +131,7 @@ LINK += -m32 -lm -ldl
|
||||
CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
|
||||
-D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Werror \
|
||||
-Wno-overloaded-virtual -Wno-switch -Wno-unused -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H -m32
|
||||
CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti -std=c++11
|
||||
CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti
|
||||
|
||||
################################################
|
||||
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
|
||||
|
@ -7,14 +7,9 @@ builder.SetBuildFolder('package')
|
||||
|
||||
# Add any folders you need to this list
|
||||
folder_list = [
|
||||
'addons/sourcemod/extensions',
|
||||
'addons/sourcemod/extensions'
|
||||
]
|
||||
|
||||
if 'x86_64' in Extension.target_archs:
|
||||
folder_list.extend([
|
||||
'addons/sourcemod/extensions/x64',
|
||||
])
|
||||
|
||||
# Create the distribution folder hierarchy.
|
||||
folder_map = {}
|
||||
for folder in folder_list:
|
||||
@ -30,10 +25,6 @@ def CopyFiles(src, dest, files):
|
||||
source_path = os.path.join(builder.sourcePath, src, source_file)
|
||||
builder.AddCopy(source_path, dest_entry)
|
||||
|
||||
|
||||
# Copy binaries.
|
||||
for cxx_task in Extension.extensions:
|
||||
if cxx_task.target.arch == 'x86_64':
|
||||
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions/x64'])
|
||||
else:
|
||||
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions'])
|
||||
builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions'])
|
||||
|
325
celt/celt.h
325
celt/celt.h
@ -1,325 +0,0 @@
|
||||
/* Copyright (c) 2007-2008 CSIRO
|
||||
Copyright (c) 2007-2009 Xiph.Org Foundation
|
||||
Copyright (c) 2008 Gregory Maxwell
|
||||
Written by Jean-Marc Valin and Gregory Maxwell */
|
||||
/**
|
||||
@file celt.h
|
||||
@brief Contains all the functions for encoding and decoding audio
|
||||
*/
|
||||
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CELT_H
|
||||
#define CELT_H
|
||||
|
||||
#include "celt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && defined(CELT_BUILD)
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
#elif defined(WIN32)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
#define _celt_check_int(x) (((void)((x) == (celt_int32)0)), (celt_int32)(x))
|
||||
#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
|
||||
#define _celt_check_int_ptr(ptr) ((ptr) + ((ptr) - (int*)(ptr)))
|
||||
|
||||
/* Error codes */
|
||||
/** No error */
|
||||
#define CELT_OK 0
|
||||
/** An (or more) invalid argument (e.g. out of range) */
|
||||
#define CELT_BAD_ARG -1
|
||||
/** The mode struct passed is invalid */
|
||||
#define CELT_BUFFER_TOO_SMALL -2
|
||||
/** An internal error was detected */
|
||||
#define CELT_INTERNAL_ERROR -3
|
||||
/** The data passed (e.g. compressed data to decoder) is corrupted */
|
||||
#define CELT_CORRUPTED_DATA -4
|
||||
/** Invalid/unsupported request number */
|
||||
#define CELT_UNIMPLEMENTED -5
|
||||
/** An encoder or decoder structure is invalid or already freed */
|
||||
#define CELT_INVALID_STATE -6
|
||||
/** Memory allocation has failed */
|
||||
#define CELT_ALLOC_FAIL -7
|
||||
|
||||
|
||||
/* Encoder/decoder Requests */
|
||||
|
||||
#define CELT_SET_COMPLEXITY_REQUEST 2
|
||||
/** Controls the complexity from 0-10 (int) */
|
||||
#define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_SET_PREDICTION_REQUEST 4
|
||||
/** Controls the use of interframe prediction.
|
||||
0=Independent frames
|
||||
1=Short term interframe prediction allowed
|
||||
2=Long term prediction allowed
|
||||
*/
|
||||
#define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_SET_BITRATE_REQUEST 6
|
||||
/** Set the target VBR rate in bits per second(int); 0=CBR (default) */
|
||||
#define CELT_SET_BITRATE(x) CELT_SET_BITRATE_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_RESET_STATE_REQUEST 8
|
||||
/** Reset the encoder/decoder memories to zero*/
|
||||
#define CELT_RESET_STATE CELT_RESET_STATE_REQUEST
|
||||
|
||||
#define CELT_SET_VBR_CONSTRAINT_REQUEST 10
|
||||
#define CELT_SET_VBR_CONSTRAINT(x) CELT_SET_VBR_CONSTRAINT_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_SET_VBR_REQUEST 12
|
||||
#define CELT_SET_VBR(x) CELT_SET_VBR_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_SET_INPUT_CLIPPING_REQUEST 14
|
||||
#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_GET_AND_CLEAR_ERROR_REQUEST 15
|
||||
#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, _celt_check_int_ptr(x)
|
||||
|
||||
#define CELT_GET_LOOKAHEAD_REQUEST 17
|
||||
#define CELT_GET_LOOKAHEAD(x) CELT_GET_LOOKAHEAD_REQUEST, _celt_check_int_ptr(x)
|
||||
|
||||
#define CELT_SET_CHANNELS_REQUEST 18
|
||||
#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_SET_LOSS_PERC_REQUEST 20
|
||||
#define CELT_SET_LOSS_PERC(x) CELT_SET_LOSS_PERC_REQUEST, _celt_check_int(x)
|
||||
|
||||
/* Internal */
|
||||
#define CELT_SET_START_BAND_REQUEST 10000
|
||||
#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)
|
||||
|
||||
#define CELT_SET_END_BAND_REQUEST 10001
|
||||
#define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, _celt_check_int(x)
|
||||
|
||||
|
||||
|
||||
/** Contains the state of an encoder. One encoder state is needed
|
||||
for each stream. It is initialised once at the beginning of the
|
||||
stream. Do *not* re-initialise the state for every frame.
|
||||
@brief Encoder state
|
||||
*/
|
||||
typedef struct CELTEncoder CELTEncoder;
|
||||
|
||||
/** State of the decoder. One decoder state is needed for each stream.
|
||||
It is initialised once at the beginning of the stream. Do *not*
|
||||
re-initialise the state for every frame */
|
||||
typedef struct CELTDecoder CELTDecoder;
|
||||
|
||||
/** The mode contains all the information necessary to create an
|
||||
encoder. Both the encoder and decoder need to be initialised
|
||||
with exactly the same mode, otherwise the quality will be very
|
||||
bad */
|
||||
typedef struct CELTMode CELTMode;
|
||||
|
||||
|
||||
/** \defgroup codec Encoding and decoding */
|
||||
/* @{ */
|
||||
|
||||
/* Mode calls */
|
||||
|
||||
/** Creates a new mode struct. This will be passed to an encoder or
|
||||
decoder. The mode MUST NOT BE DESTROYED until the encoders and
|
||||
decoders that use it are destroyed as well.
|
||||
@param Fs Sampling rate (32000 to 96000 Hz)
|
||||
@param frame_size Number of samples (per channel) to encode in each
|
||||
packet (even values; 64 - 512)
|
||||
@param error Returned error code (if NULL, no error will be returned)
|
||||
@return A newly created mode
|
||||
*/
|
||||
EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error);
|
||||
|
||||
/** Destroys a mode struct. Only call this after all encoders and
|
||||
decoders using this mode are destroyed as well.
|
||||
@param mode Mode to be destroyed
|
||||
*/
|
||||
EXPORT void celt_mode_destroy(CELTMode *mode);
|
||||
|
||||
/* Encoder stuff */
|
||||
|
||||
EXPORT int celt_encoder_get_size(int channels);
|
||||
|
||||
EXPORT int celt_encoder_get_size_custom(const CELTMode *mode, int channels);
|
||||
|
||||
/** Creates a new encoder state. Each stream needs its own encoder
|
||||
state (can't be shared across simultaneous streams).
|
||||
@param channels Number of channels
|
||||
@param error Returns an error code
|
||||
@return Newly created encoder state.
|
||||
*/
|
||||
EXPORT CELTEncoder *celt_encoder_create(int sampling_rate, int channels, int *error);
|
||||
|
||||
/** Creates a new encoder state. Each stream needs its own encoder
|
||||
state (can't be shared across simultaneous streams).
|
||||
@param mode Contains all the information about the characteristics of
|
||||
* the stream (must be the same characteristics as used for the
|
||||
* decoder)
|
||||
@param channels Number of channels
|
||||
@param error Returns an error code
|
||||
@return Newly created encoder state.
|
||||
*/
|
||||
EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
|
||||
|
||||
EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int sampling_rate, int channels, int *error);
|
||||
|
||||
EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
|
||||
|
||||
/** Destroys a an encoder state.
|
||||
@param st Encoder state to be destroyed
|
||||
*/
|
||||
EXPORT void celt_encoder_destroy(CELTEncoder *st);
|
||||
|
||||
/** Encodes a frame of audio.
|
||||
@param st Encoder state
|
||||
@param pcm PCM audio in float format, with a normal range of ±1.0.
|
||||
* Samples with a range beyond ±1.0 are supported but will
|
||||
* be clipped by decoders using the integer API and should
|
||||
* only be used if it is known that the far end supports
|
||||
* extended dynmaic range. There must be exactly
|
||||
* frame_size samples per channel.
|
||||
@param compressed The compressed data is written here. This may not alias pcm or
|
||||
* optional_synthesis.
|
||||
@param nbCompressedBytes Maximum number of bytes to use for compressing the frame
|
||||
* (can change from one frame to another)
|
||||
@return Number of bytes written to "compressed". Will be the same as
|
||||
* "nbCompressedBytes" unless the stream is VBR and will never be larger.
|
||||
* If negative, an error has occurred (see error codes). It is IMPORTANT that
|
||||
* the length returned be somehow transmitted to the decoder. Otherwise, no
|
||||
* decoding is possible.
|
||||
*/
|
||||
EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes);
|
||||
|
||||
/** Encodes a frame of audio.
|
||||
@param st Encoder state
|
||||
@param pcm PCM audio in signed 16-bit format (native endian). There must be
|
||||
* exactly frame_size samples per channel.
|
||||
@param compressed The compressed data is written here. This may not alias pcm or
|
||||
* optional_synthesis.
|
||||
@param nbCompressedBytes Maximum number of bytes to use for compressing the frame
|
||||
* (can change from one frame to another)
|
||||
@return Number of bytes written to "compressed". Will be the same as
|
||||
* "nbCompressedBytes" unless the stream is VBR and will never be larger.
|
||||
* If negative, an error has occurred (see error codes). It is IMPORTANT that
|
||||
* the length returned be somehow transmitted to the decoder. Otherwise, no
|
||||
* decoding is possible.
|
||||
*/
|
||||
EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes);
|
||||
|
||||
/** Query and set encoder parameters
|
||||
@param st Encoder state
|
||||
@param request Parameter to change or query
|
||||
@param value Pointer to a 32-bit int value
|
||||
@return Error code
|
||||
*/
|
||||
EXPORT int celt_encoder_ctl(CELTEncoder * st, int request, ...);
|
||||
|
||||
/* Decoder stuff */
|
||||
|
||||
EXPORT int celt_decoder_get_size(int channels);
|
||||
|
||||
EXPORT int celt_decoder_get_size_custom(const CELTMode *mode, int channels);
|
||||
|
||||
/** Creates a new decoder state. Each stream needs its own decoder state (can't
|
||||
be shared across simultaneous streams).
|
||||
@param mode Contains all the information about the characteristics of the
|
||||
stream (must be the same characteristics as used for the encoder)
|
||||
@param channels Number of channels
|
||||
@param error Returns an error code
|
||||
@return Newly created decoder state.
|
||||
*/
|
||||
EXPORT CELTDecoder *celt_decoder_create(int sampling_rate, int channels, int *error);
|
||||
|
||||
/** Creates a new decoder state. Each stream needs its own decoder state (can't
|
||||
be shared across simultaneous streams).
|
||||
@param mode Contains all the information about the characteristics of the
|
||||
stream (must be the same characteristics as used for the encoder)
|
||||
@param channels Number of channels
|
||||
@param error Returns an error code
|
||||
@return Newly created decoder state.
|
||||
*/
|
||||
EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error);
|
||||
|
||||
EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int sampling_rate, int channels, int *error);
|
||||
|
||||
EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
|
||||
|
||||
/** Destroys a a decoder state.
|
||||
@param st Decoder state to be destroyed
|
||||
*/
|
||||
EXPORT void celt_decoder_destroy(CELTDecoder *st);
|
||||
|
||||
/** Decodes a frame of audio.
|
||||
@param st Decoder state
|
||||
@param data Compressed data produced by an encoder
|
||||
@param len Number of bytes to read from "data". This MUST be exactly the number
|
||||
of bytes returned by the encoder. Using a larger value WILL NOT WORK.
|
||||
@param pcm One frame (frame_size samples per channel) of decoded PCM will be
|
||||
returned here in float format.
|
||||
@return Error code.
|
||||
*/
|
||||
EXPORT int celt_decode_float(CELTDecoder *st, const unsigned char *data, int len, float *pcm, int frame_size);
|
||||
|
||||
/** Decodes a frame of audio.
|
||||
@param st Decoder state
|
||||
@param data Compressed data produced by an encoder
|
||||
@param len Number of bytes to read from "data". This MUST be exactly the number
|
||||
of bytes returned by the encoder. Using a larger value WILL NOT WORK.
|
||||
@param pcm One frame (frame_size samples per channel) of decoded PCM will be
|
||||
returned here in 16-bit PCM format (native endian).
|
||||
@return Error code.
|
||||
*/
|
||||
EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt_int16 *pcm, int frame_size);
|
||||
|
||||
/** Query and set decoder parameters
|
||||
@param st Decoder state
|
||||
@param request Parameter to change or query
|
||||
@param value Pointer to a 32-bit int value
|
||||
@return Error code
|
||||
*/
|
||||
EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...);
|
||||
|
||||
|
||||
/** Returns the English string that corresponds to an error code
|
||||
* @param error Error code (negative for an error, 0 for success
|
||||
* @return Constant string (must NOT be freed)
|
||||
*/
|
||||
EXPORT const char *celt_strerror(int error);
|
||||
|
||||
/* @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*CELT_H */
|
@ -1,66 +0,0 @@
|
||||
/* Copyright (c) 2007 CSIRO
|
||||
Copyright (c) 2007-2008 Xiph.Org Foundation
|
||||
Written by Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CELT_HEADER_H
|
||||
#define CELT_HEADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "celt.h"
|
||||
#include "celt_types.h"
|
||||
|
||||
/** Header data to be used for Ogg files (or possibly other encapsulation)
|
||||
@brief Header data
|
||||
*/
|
||||
typedef struct {
|
||||
char codec_id[8]; /**< MUST be "CELT " (four spaces) */
|
||||
char codec_version[20]; /**< Version used (as string) */
|
||||
celt_int32 version_id; /**< Version id (negative for until stream is frozen) */
|
||||
celt_int32 header_size; /**< Size of this header */
|
||||
celt_int32 sample_rate; /**< Sampling rate of the original audio */
|
||||
celt_int32 nb_channels; /**< Number of channels */
|
||||
celt_int32 frame_size; /**< Samples per frame (per channel) */
|
||||
celt_int32 overlap; /**< Overlapping samples (per channel) */
|
||||
celt_int32 bytes_per_packet; /**< Number of bytes per compressed packet (0 if unknown) */
|
||||
celt_int32 extra_headers; /**< Number of additional headers that follow this header */
|
||||
} CELTHeader;
|
||||
|
||||
/** Creates a basic header struct */
|
||||
EXPORT int celt_header_init(CELTHeader *header, const CELTMode *m, int frame_size, int channels);
|
||||
|
||||
EXPORT int celt_header_to_packet(const CELTHeader *header, unsigned char *packet, celt_uint32 size);
|
||||
|
||||
EXPORT int celt_header_from_packet(const unsigned char *packet, celt_uint32 size, CELTHeader *header);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CELT_HEADER_H */
|
@ -1,151 +0,0 @@
|
||||
/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */
|
||||
/* Modified by Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/* celt_types.h taken from libogg */
|
||||
|
||||
/**
|
||||
@file celt_types.h
|
||||
@brief CELT types
|
||||
*/
|
||||
#ifndef _CELT_TYPES_H
|
||||
#define _CELT_TYPES_H
|
||||
|
||||
/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */
|
||||
#if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H))
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int16_t celt_int16;
|
||||
typedef uint16_t celt_uint16;
|
||||
typedef int32_t celt_int32;
|
||||
typedef uint32_t celt_uint32;
|
||||
#elif defined(_WIN32)
|
||||
|
||||
# if defined(__CYGWIN__)
|
||||
# include <_G_config.h>
|
||||
typedef _G_int32_t celt_int32;
|
||||
typedef _G_uint32_t celt_uint32;
|
||||
typedef _G_int16 celt_int16;
|
||||
typedef _G_uint16 celt_uint16;
|
||||
# elif defined(__MINGW32__)
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
# elif defined(__MWERKS__)
|
||||
typedef int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
# else
|
||||
/* MSVC/Borland */
|
||||
typedef __int32 celt_int32;
|
||||
typedef unsigned __int32 celt_uint32;
|
||||
typedef __int16 celt_int16;
|
||||
typedef unsigned __int16 celt_uint16;
|
||||
# endif
|
||||
|
||||
#elif defined(__MACOS__)
|
||||
|
||||
# include <sys/types.h>
|
||||
typedef SInt16 celt_int16;
|
||||
typedef UInt16 celt_uint16;
|
||||
typedef SInt32 celt_int32;
|
||||
typedef UInt32 celt_uint32;
|
||||
|
||||
#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */
|
||||
|
||||
# include <sys/types.h>
|
||||
typedef int16_t celt_int16;
|
||||
typedef u_int16_t celt_uint16;
|
||||
typedef int32_t celt_int32;
|
||||
typedef u_int32_t celt_uint32;
|
||||
|
||||
#elif defined(__BEOS__)
|
||||
|
||||
/* Be */
|
||||
# include <inttypes.h>
|
||||
typedef int16 celt_int16;
|
||||
typedef u_int16 celt_uint16;
|
||||
typedef int32_t celt_int32;
|
||||
typedef u_int32_t celt_uint32;
|
||||
|
||||
#elif defined (__EMX__)
|
||||
|
||||
/* OS/2 GCC */
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
|
||||
#elif defined (DJGPP)
|
||||
|
||||
/* DJGPP */
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
|
||||
#elif defined(R5900)
|
||||
|
||||
/* PS2 EE */
|
||||
typedef int celt_int32;
|
||||
typedef unsigned celt_uint32;
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
|
||||
#elif defined(__SYMBIAN32__)
|
||||
|
||||
/* Symbian GCC */
|
||||
typedef signed short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef signed int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
|
||||
#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
|
||||
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef long celt_int32;
|
||||
typedef unsigned long celt_uint32;
|
||||
|
||||
#elif defined(CONFIG_TI_C6X)
|
||||
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
|
||||
#else
|
||||
|
||||
/* Give up, take a reasonable guess */
|
||||
typedef short celt_int16;
|
||||
typedef unsigned short celt_uint16;
|
||||
typedef int celt_int32;
|
||||
typedef unsigned int celt_uint32;
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _CELT_TYPES_H */
|
BIN
celt/libcelt0.a
BIN
celt/libcelt0.a
Binary file not shown.
30
configure.py
30
configure.py
@ -4,24 +4,20 @@ from ambuild2 import run
|
||||
|
||||
# Simple extensions do not need to modify this file.
|
||||
|
||||
parser = run.BuildParser(sourcePath=sys.path[0], api='2.2')
|
||||
parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
|
||||
help='Root search folder for HL2SDKs')
|
||||
parser.options.add_argument('--hl2sdk-manifest-path', type=str, dest='hl2sdk_manifest', default=None,
|
||||
help='Path to HL2SDK Manifests')
|
||||
parser.options.add_argument('--sm-path', type=str, dest='sm_path', default=None,
|
||||
help='Path to SourceMod')
|
||||
parser.options.add_argument('--mms-path', type=str, dest='mms_path', default=None,
|
||||
builder = run.PrepareBuild(sourcePath = sys.path[0])
|
||||
|
||||
builder.options.add_option('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
|
||||
help='Root search folder for HL2SDKs')
|
||||
builder.options.add_option('--mms-path', type=str, dest='mms_path', default=None,
|
||||
help='Path to Metamod:Source')
|
||||
|
||||
parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug',
|
||||
builder.options.add_option('--sm-path', type=str, dest='sm_path', default=None,
|
||||
help='Path to SourceMod')
|
||||
builder.options.add_option('--enable-debug', action='store_const', const='1', dest='debug',
|
||||
help='Enable debugging symbols')
|
||||
parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt',
|
||||
builder.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt',
|
||||
help='Enable optimization')
|
||||
parser.options.add_argument('-s', '--sdks', default='present', dest='sdks',
|
||||
help='Build against specified SDKs; valid args are "none", "all", "present",'
|
||||
' or comma-delimited list of engine names')
|
||||
parser.options.add_argument('--targets', type=str, dest='targets', default=None,
|
||||
help="Override the target architecture (use commas to separate multiple targets).")
|
||||
parser.Configure()
|
||||
builder.options.add_option('-s', '--sdks', default='all', dest='sdks',
|
||||
help='Build against specified SDKs; valid args are "all", "present", or '
|
||||
'comma-delimited list of engine names (default: %default)')
|
||||
|
||||
builder.Configure()
|
||||
|
506
extension.cpp
506
extension.cpp
@ -43,17 +43,8 @@
|
||||
#include <iserver.h>
|
||||
#include <ISDKTools.h>
|
||||
|
||||
#include "CDetour/detours.h"
|
||||
#include "extension.h"
|
||||
|
||||
// voice packets are sent over unreliable netchannel
|
||||
//#define NET_MAX_DATAGRAM_PAYLOAD 4000 // = maximum unreliable payload size
|
||||
// voice packetsize = 64 | netchannel overflows at >4000 bytes
|
||||
// with 22050 samplerate and 512 frames per packet -> 23.22ms per packet
|
||||
// SVC_VoiceData overhead = 5 bytes
|
||||
// sensible limit of 8 packets per frame = 552 bytes -> 185.76ms of voice data per frame
|
||||
#define NET_MAX_VOICE_BYTES_FRAME (8 * (5 + 64))
|
||||
|
||||
ConVar g_SmVoiceAddr("sm_voice_addr", "127.0.0.1", FCVAR_PROTECTED, "Voice server listen ip address.");
|
||||
ConVar g_SmVoicePort("sm_voice_port", "27020", FCVAR_PROTECTED, "Voice server listen port.", true, 1025.0, true, 65535.0);
|
||||
|
||||
@ -62,42 +53,76 @@ ConVar g_SmVoicePort("sm_voice_port", "27020", FCVAR_PROTECTED, "Voice server li
|
||||
* @brief Implement extension code here.
|
||||
*/
|
||||
|
||||
template <typename T> inline T min_ext(T a, T b) { return a<b?a:b; }
|
||||
template <typename T> inline T min(T a, T b) { return a<b?a:b; }
|
||||
|
||||
/**
|
||||
* Polynomial: 0x04C11DB7
|
||||
*/
|
||||
const unsigned int CRCTable[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
|
||||
|
||||
unsigned int UTIL_CRC32(const void *pdata, size_t data_length)
|
||||
{
|
||||
unsigned char *data = (unsigned char *)pdata;
|
||||
unsigned int crc = 0xFFFFFFFF;
|
||||
unsigned char c;
|
||||
|
||||
for(size_t i = 0; i < data_length; i++, data++)
|
||||
{
|
||||
c = (unsigned char)((crc ^ *data) & 0xFF);
|
||||
crc = CRCTable[c] ^ (crc >> 8);
|
||||
}
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
CVoice g_Interface;
|
||||
SMEXT_LINK(&g_Interface);
|
||||
|
||||
CGlobalVars *gpGlobals = NULL;
|
||||
ISDKTools *g_pSDKTools = NULL;
|
||||
IServer *iserver = NULL;
|
||||
|
||||
double g_fLastVoiceData[SM_MAXPLAYERS + 1];
|
||||
int g_aFrameVoiceBytes[SM_MAXPLAYERS + 1];
|
||||
|
||||
DETOUR_DECL_STATIC4(SV_BroadcastVoiceData, void, IClient *, pClient, int, nBytes, char *, data, int64, xuid)
|
||||
{
|
||||
if(g_Interface.OnBroadcastVoiceData(pClient, nBytes, data))
|
||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData)(pClient, nBytes, data, xuid);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
DETOUR_DECL_STATIC2(SV_BroadcastVoiceData_LTCG, void, char *, data, int64, xuid)
|
||||
{
|
||||
IClient *pClient = NULL;
|
||||
int nBytes = 0;
|
||||
|
||||
__asm mov pClient, ecx;
|
||||
__asm mov nBytes, edx;
|
||||
|
||||
bool ret = g_Interface.OnBroadcastVoiceData(pClient, nBytes, data);
|
||||
|
||||
__asm mov ecx, pClient;
|
||||
__asm mov edx, nBytes;
|
||||
|
||||
if(ret)
|
||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)(data, xuid);
|
||||
}
|
||||
#endif
|
||||
SH_DECL_MANUALHOOK0(GetPlayerSlot, 0, 0, 0, int); // IClient::GetPlayerSlot
|
||||
|
||||
double getTime()
|
||||
{
|
||||
@ -126,10 +151,8 @@ CVoice::CVoice()
|
||||
|
||||
m_AvailableTime = 0.0;
|
||||
|
||||
m_pMode = NULL;
|
||||
m_pCodec = NULL;
|
||||
m_Silk_EncoderState = NULL;
|
||||
|
||||
m_VoiceDetour = NULL;
|
||||
m_SV_BroadcastVoiceData = NULL;
|
||||
}
|
||||
|
||||
@ -152,39 +175,47 @@ bool CVoice::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
}
|
||||
|
||||
int engineVersion = g_SMAPI->GetSourceEngineBuild();
|
||||
void *adrVoiceData = NULL;
|
||||
int offsPlayerSlot = 0;
|
||||
|
||||
switch (engineVersion)
|
||||
{
|
||||
case SOURCE_ENGINE_CSGO:
|
||||
#ifdef _WIN32
|
||||
adrVoiceData = memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\x81\xEC\xD0\x00\x00\x00\x53\x56\x57", 12);
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\x81\xEC\xD0\x00\x00\x00\x53\x56\x57", 12);
|
||||
offsPlayerSlot = 15;
|
||||
#else
|
||||
adrVoiceData = memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
offsPlayerSlot = 16;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SOURCE_ENGINE_LEFT4DEAD2:
|
||||
#ifdef _WIN32
|
||||
adrVoiceData = memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\x83\xEC\x70\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\xFC\xA1\x2A\x2A\x2A\x2A\x53\x56", 23);
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\x83\xEC\x70\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\xFC\xA1\x2A\x2A\x2A\x2A\x53\x56", 23);
|
||||
offsPlayerSlot = 14;
|
||||
#else
|
||||
adrVoiceData = memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
offsPlayerSlot = 15;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SOURCE_ENGINE_NUCLEARDAWN:
|
||||
#ifdef _WIN32
|
||||
adrVoiceData = memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\xA1\x2A\x2A\x2A\x2A\x83\xEC\x58\x57\x33\xFF", 14);
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\xA1\x2A\x2A\x2A\x2A\x83\xEC\x58\x57\x33\xFF", 14);
|
||||
offsPlayerSlot = 14;
|
||||
#else
|
||||
adrVoiceData = memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
offsPlayerSlot = 15;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SOURCE_ENGINE_INSURGENCY:
|
||||
#ifdef _WIN32
|
||||
adrVoiceData = memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\x83\xEC\x74\x68\x2A\x2A\x2A\x2A\x8D\x4D\xE4\xE8", 15);
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\x83\xEC\x74\x68\x2A\x2A\x2A\x2A\x8D\x4D\xE4\xE8", 15);
|
||||
offsPlayerSlot = 14;
|
||||
#else
|
||||
adrVoiceData = memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
offsPlayerSlot = 15;
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -194,9 +225,11 @@ bool CVoice::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
case SOURCE_ENGINE_DODS:
|
||||
case SOURCE_ENGINE_SDK2013:
|
||||
#ifdef _WIN32
|
||||
adrVoiceData = memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\xA1\x2A\x2A\x2A\x2A\x83\xEC\x50\x83\x78\x30", 14);
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->FindPattern(pEngineSo, "\x55\x8B\xEC\xA1\x2A\x2A\x2A\x2A\x83\xEC\x50\x83\x78\x30", 14);
|
||||
offsPlayerSlot = 14;
|
||||
#else
|
||||
adrVoiceData = memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)memutils->ResolveSymbol(pEngineSo, "_Z21SV_BroadcastVoiceDataP7IClientiPcx");
|
||||
offsPlayerSlot = 15;
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -207,168 +240,34 @@ bool CVoice::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
}
|
||||
dlclose(pEngineSo);
|
||||
|
||||
m_SV_BroadcastVoiceData = (t_SV_BroadcastVoiceData)adrVoiceData;
|
||||
if(!m_SV_BroadcastVoiceData)
|
||||
{
|
||||
g_SMAPI->Format(error, maxlength, "SV_BroadcastVoiceData sigscan failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup voice detour.
|
||||
CDetourManager::Init(g_pSM->GetScriptingEngine(), NULL);
|
||||
|
||||
#ifdef _WIN32
|
||||
if (engineVersion == SOURCE_ENGINE_CSGO || engineVersion == SOURCE_ENGINE_INSURGENCY)
|
||||
{
|
||||
m_VoiceDetour = DETOUR_CREATE_STATIC(SV_BroadcastVoiceData_LTCG, adrVoiceData);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_VoiceDetour = DETOUR_CREATE_STATIC(SV_BroadcastVoiceData, adrVoiceData);
|
||||
}
|
||||
#else
|
||||
m_VoiceDetour = DETOUR_CREATE_STATIC(SV_BroadcastVoiceData, adrVoiceData);
|
||||
#endif
|
||||
|
||||
if (!m_VoiceDetour)
|
||||
{
|
||||
g_SMAPI->Format(error, maxlength, "SV_BroadcastVoiceData detour failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_VoiceDetour->EnableDetour();
|
||||
|
||||
// Encoder settings
|
||||
m_EncoderSettings.SampleRate_Hz = 22050;
|
||||
m_EncoderSettings.TargetBitRate_Kbps = 64;
|
||||
m_EncoderSettings.FrameSize = 512; // samples
|
||||
m_EncoderSettings.PacketSize = 64;
|
||||
m_EncoderSettings.Complexity = 10; // 0 - 10
|
||||
m_EncoderSettings.FrameTime = (double)m_EncoderSettings.FrameSize / (double)m_EncoderSettings.SampleRate_Hz;
|
||||
|
||||
// Init CELT encoder
|
||||
int theError;
|
||||
m_pMode = celt_mode_create(m_EncoderSettings.SampleRate_Hz, m_EncoderSettings.FrameSize, &theError);
|
||||
if(!m_pMode)
|
||||
{
|
||||
g_SMAPI->Format(error, maxlength, "celt_mode_create error: %d", theError);
|
||||
SDK_OnUnload();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pCodec = celt_encoder_create_custom(m_pMode, 1, &theError);
|
||||
if(!m_pCodec)
|
||||
{
|
||||
g_SMAPI->Format(error, maxlength, "celt_encoder_create_custom error: %d", theError);
|
||||
SDK_OnUnload();
|
||||
return false;
|
||||
}
|
||||
|
||||
celt_encoder_ctl(m_pCodec, CELT_RESET_STATE_REQUEST, NULL);
|
||||
celt_encoder_ctl(m_pCodec, CELT_SET_BITRATE(m_EncoderSettings.TargetBitRate_Kbps * 1000));
|
||||
celt_encoder_ctl(m_pCodec, CELT_SET_COMPLEXITY(m_EncoderSettings.Complexity));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVoice::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
||||
{
|
||||
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
|
||||
gpGlobals = ismm->GetCGlobals();
|
||||
ConVar_Register(0, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVoice::RegisterConCommandBase(ConCommandBase *pVar)
|
||||
{
|
||||
/* Always call META_REGCVAR instead of going through the engine. */
|
||||
return META_REGCVAR(pVar);
|
||||
}
|
||||
|
||||
cell_t IsClientTalking(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int client = params[1];
|
||||
|
||||
if(client < 1 || client > SM_MAXPLAYERS)
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
|
||||
double d = gpGlobals->curtime - g_fLastVoiceData[client];
|
||||
|
||||
if(d < 0) // mapchange
|
||||
return false;
|
||||
|
||||
if(d > 0.33)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const sp_nativeinfo_t MyNatives[] =
|
||||
{
|
||||
{ "IsClientTalking", IsClientTalking },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static void ListenSocketAction(void *pData)
|
||||
{
|
||||
CVoice *pThis = (CVoice *)pData;
|
||||
pThis->ListenSocket();
|
||||
}
|
||||
|
||||
void CVoice::SDK_OnAllLoaded()
|
||||
{
|
||||
sharesys->AddNatives(myself, MyNatives);
|
||||
sharesys->RegisterLibrary(myself, "Voice");
|
||||
|
||||
SM_GET_LATE_IFACE(SDKTOOLS, g_pSDKTools);
|
||||
if(g_pSDKTools == NULL)
|
||||
{
|
||||
smutils->LogError(myself, "SDKTools interface not found");
|
||||
SDK_OnUnload();
|
||||
return;
|
||||
}
|
||||
|
||||
iserver = g_pSDKTools->GetIServer();
|
||||
if(iserver == NULL)
|
||||
{
|
||||
smutils->LogError(myself, "Failed to get IServer interface from SDKTools!");
|
||||
SDK_OnUnload();
|
||||
return;
|
||||
}
|
||||
SH_MANUALHOOK_RECONFIGURE(GetPlayerSlot, offsPlayerSlot, 0, 0);
|
||||
|
||||
// Init tcp server
|
||||
m_ListenSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(m_ListenSocket < 0)
|
||||
{
|
||||
smutils->LogError(myself, "Failed creating socket.");
|
||||
g_SMAPI->Format(error, maxlength, "Failed creating socket.");
|
||||
SDK_OnUnload();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
int yes = 1;
|
||||
if(setsockopt(m_ListenSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0)
|
||||
{
|
||||
smutils->LogError(myself, "Failed setting SO_REUSEADDR on socket.");
|
||||
g_SMAPI->Format(error, maxlength, "Failed setting SO_REUSEADDR on socket.");
|
||||
SDK_OnUnload();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// This doesn't seem to work right away ...
|
||||
engine->ServerCommand("exec sourcemod/extension.Voice.cfg\n");
|
||||
engine->ServerExecute();
|
||||
|
||||
// ... delay starting listen server to next frame
|
||||
smutils->AddFrameAction(ListenSocketAction, this);
|
||||
}
|
||||
|
||||
void CVoice::ListenSocket()
|
||||
{
|
||||
if(m_PollFds > 0)
|
||||
return;
|
||||
|
||||
sockaddr_in bindAddr;
|
||||
memset(&bindAddr, 0, sizeof(bindAddr));
|
||||
bindAddr.sin_family = AF_INET;
|
||||
@ -379,35 +278,92 @@ void CVoice::ListenSocket()
|
||||
|
||||
if(bind(m_ListenSocket, (sockaddr *)&bindAddr, sizeof(sockaddr_in)) < 0)
|
||||
{
|
||||
smutils->LogError(myself, "Failed binding to socket (%d '%s').", errno, strerror(errno));
|
||||
g_SMAPI->Format(error, maxlength, "Failed binding to socket (%d '%s').", errno, strerror(errno));
|
||||
SDK_OnUnload();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(listen(m_ListenSocket, MAX_CLIENTS) < 0)
|
||||
{
|
||||
smutils->LogError(myself, "Failed listening on socket.");
|
||||
g_SMAPI->Format(error, maxlength, "Failed listening on socket.");
|
||||
SDK_OnUnload();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_aPollFds[0].fd = m_ListenSocket;
|
||||
m_aPollFds[0].events = POLLIN;
|
||||
m_PollFds++;
|
||||
|
||||
// Encoder settings
|
||||
m_EncoderSettings.InputSampleRate_kHz = 48; // 8, 12, 16, 24, 32, 44.1, 48
|
||||
m_EncoderSettings.OutputSampleRate_kHz = 16; // 8, 12, 16, 24
|
||||
m_EncoderSettings.TargetBitRate_Kbps = 100; // 6 - 40
|
||||
m_EncoderSettings.PacketSize_ms = 20; // 20, 40, 60, 80, 100
|
||||
m_EncoderSettings.FrameSize_ms = 20; //
|
||||
m_EncoderSettings.PacketLoss_perc = 0; // 0 - 100
|
||||
m_EncoderSettings.Complexity = 2; // 0 - 2
|
||||
m_EncoderSettings.InBandFEC = 0; // 0, 1
|
||||
m_EncoderSettings.DTX = 0; // 0, 1
|
||||
|
||||
// Init SILK encoder
|
||||
int encoderSize;
|
||||
SKP_Silk_SDK_Get_Encoder_Size(&encoderSize);
|
||||
|
||||
m_Silk_EncoderState = malloc(encoderSize);
|
||||
if(!m_Silk_EncoderState)
|
||||
{
|
||||
g_SMAPI->Format(error, maxlength, "Failed to malloc %d bytes for silk encoder.", encoderSize);
|
||||
SDK_OnUnload();
|
||||
return false;
|
||||
}
|
||||
|
||||
int retEnc = SKP_Silk_SDK_InitEncoder(m_Silk_EncoderState, &m_Silk_EncoderControl);
|
||||
if(retEnc != SKP_SILK_NO_ERROR)
|
||||
{
|
||||
g_SMAPI->Format(error, maxlength, "Silk encoder initialization failed with: %d", retEnc);
|
||||
SDK_OnUnload();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Silk_EncoderControl.API_sampleRate = m_EncoderSettings.InputSampleRate_kHz * 1000;
|
||||
m_Silk_EncoderControl.maxInternalSampleRate = m_EncoderSettings.OutputSampleRate_kHz * 1000;
|
||||
m_Silk_EncoderControl.bitRate = m_EncoderSettings.TargetBitRate_Kbps * 1000;
|
||||
m_Silk_EncoderControl.packetSize = m_EncoderSettings.PacketSize_ms * m_EncoderSettings.InputSampleRate_kHz;
|
||||
m_Silk_EncoderControl.packetLossPercentage = m_EncoderSettings.PacketLoss_perc;
|
||||
m_Silk_EncoderControl.complexity = m_EncoderSettings.Complexity;
|
||||
m_Silk_EncoderControl.useInBandFEC = m_EncoderSettings.InBandFEC;
|
||||
m_Silk_EncoderControl.useDTX = m_EncoderSettings.DTX;
|
||||
|
||||
smutils->AddGameFrameHook(::OnGameFrame);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVoice::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
||||
{
|
||||
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
|
||||
ConVar_Register(0, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVoice::RegisterConCommandBase(ConCommandBase *pVar)
|
||||
{
|
||||
/* Always call META_REGCVAR instead of going through the engine. */
|
||||
return META_REGCVAR(pVar);
|
||||
}
|
||||
|
||||
void CVoice::SDK_OnAllLoaded()
|
||||
{
|
||||
SM_GET_LATE_IFACE(SDKTOOLS, g_pSDKTools);
|
||||
if(g_pSDKTools == NULL)
|
||||
smutils->LogError(myself, "SDKTools interface not found");
|
||||
}
|
||||
|
||||
void CVoice::SDK_OnUnload()
|
||||
{
|
||||
smutils->RemoveGameFrameHook(::OnGameFrame);
|
||||
|
||||
if(m_VoiceDetour)
|
||||
{
|
||||
m_VoiceDetour->Destroy();
|
||||
m_VoiceDetour = NULL;
|
||||
}
|
||||
|
||||
if(m_ListenSocket != -1)
|
||||
{
|
||||
close(m_ListenSocket);
|
||||
@ -423,40 +379,17 @@ void CVoice::SDK_OnUnload()
|
||||
}
|
||||
}
|
||||
|
||||
if(m_pCodec)
|
||||
celt_encoder_destroy(m_pCodec);
|
||||
|
||||
if(m_pMode)
|
||||
celt_mode_destroy(m_pMode);
|
||||
if(m_Silk_EncoderState)
|
||||
{
|
||||
free(m_Silk_EncoderState);
|
||||
m_Silk_EncoderState = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CVoice::OnGameFrame(bool simulating)
|
||||
{
|
||||
HandleNetwork();
|
||||
HandleVoiceData();
|
||||
|
||||
// Reset per-client voice byte counter to 0 every frame.
|
||||
memset(g_aFrameVoiceBytes, 0, sizeof(g_aFrameVoiceBytes));
|
||||
}
|
||||
|
||||
bool CVoice::OnBroadcastVoiceData(IClient *pClient, int nBytes, char *data)
|
||||
{
|
||||
// Reject empty packets
|
||||
if(nBytes < 1)
|
||||
return false;
|
||||
|
||||
int client = pClient->GetPlayerSlot() + 1;
|
||||
|
||||
// Reject voice packet if we'd send more than NET_MAX_VOICE_BYTES_FRAME voice bytes from this client in the current frame.
|
||||
// 5 = SVC_VoiceData header/overhead
|
||||
g_aFrameVoiceBytes[client] += 5 + nBytes;
|
||||
|
||||
if(g_aFrameVoiceBytes[client] > NET_MAX_VOICE_BYTES_FRAME)
|
||||
return false;
|
||||
|
||||
g_fLastVoiceData[client] = gpGlobals->curtime;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CVoice::HandleNetwork()
|
||||
@ -483,7 +416,7 @@ void CVoice::HandleNetwork()
|
||||
if(Client != MAX_CLIENTS)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
socklen_t size = sizeof(sockaddr_in);
|
||||
size_t size = sizeof(sockaddr_in);
|
||||
int Socket = accept(m_ListenSocket, (sockaddr *)&addr, &size);
|
||||
|
||||
m_aClients[Client].m_Socket = Socket;
|
||||
@ -491,14 +424,13 @@ void CVoice::HandleNetwork()
|
||||
m_aClients[Client].m_LastLength = 0;
|
||||
m_aClients[Client].m_LastValidData = 0.0;
|
||||
m_aClients[Client].m_New = true;
|
||||
m_aClients[Client].m_UnEven = false;
|
||||
|
||||
m_aPollFds[m_PollFds].fd = Socket;
|
||||
m_aPollFds[m_PollFds].events = POLLIN | POLLHUP;
|
||||
m_aPollFds[m_PollFds].revents = 0;
|
||||
m_PollFds++;
|
||||
|
||||
//smutils->LogMessage(myself, "Client %d connected!\n", Client);
|
||||
smutils->LogMessage(myself, "Client %d connected!\n", Client);
|
||||
}
|
||||
}
|
||||
|
||||
@ -524,7 +456,7 @@ void CVoice::HandleNetwork()
|
||||
pClient->m_Socket = -1;
|
||||
m_aPollFds[PollFds].fd = -1;
|
||||
CompressPollFds = true;
|
||||
//smutils->LogMessage(myself, "Client %d disconnected!(2)\n", Client);
|
||||
smutils->LogMessage(myself, "Client %d disconnected!(2)\n", Client);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -546,19 +478,10 @@ void CVoice::HandleNetwork()
|
||||
|
||||
// Don't recv() when we can't fit data into the ringbuffer
|
||||
unsigned char aBuf[32768];
|
||||
if(min_ext(BytesAvailable, sizeof(aBuf)) > m_Buffer.CurrentFree() * sizeof(int16_t))
|
||||
if(min(BytesAvailable, sizeof(aBuf)) > m_Buffer.CurrentFree() * sizeof(int16_t))
|
||||
continue;
|
||||
|
||||
// Edge case: previously received data is uneven and last recv'd byte has to be prepended
|
||||
int Shift = 0;
|
||||
if(pClient->m_UnEven)
|
||||
{
|
||||
Shift = 1;
|
||||
aBuf[0] = pClient->m_Remainder;
|
||||
pClient->m_UnEven = false;
|
||||
}
|
||||
|
||||
ssize_t Bytes = recv(pClient->m_Socket, &aBuf[Shift], sizeof(aBuf) - Shift, 0);
|
||||
ssize_t Bytes = recv(pClient->m_Socket, aBuf, sizeof(aBuf), 0);
|
||||
|
||||
if(Bytes <= 0)
|
||||
{
|
||||
@ -566,21 +489,10 @@ void CVoice::HandleNetwork()
|
||||
pClient->m_Socket = -1;
|
||||
m_aPollFds[PollFds].fd = -1;
|
||||
CompressPollFds = true;
|
||||
//smutils->LogMessage(myself, "Client %d disconnected!(1)\n", Client);
|
||||
smutils->LogMessage(myself, "Client %d disconnected!(1)\n", Client);
|
||||
continue;
|
||||
}
|
||||
|
||||
Bytes += Shift;
|
||||
|
||||
// Edge case: data received is uneven (can't be divided by two)
|
||||
// store last byte, drop it here and prepend it right before the next recv
|
||||
if(Bytes & 1)
|
||||
{
|
||||
pClient->m_UnEven = true;
|
||||
pClient->m_Remainder = aBuf[Bytes - 1];
|
||||
Bytes -= 1;
|
||||
}
|
||||
|
||||
// Got data!
|
||||
OnDataReceived(pClient, (int16_t *)aBuf, Bytes / sizeof(int16_t));
|
||||
|
||||
@ -638,12 +550,21 @@ void CVoice::OnDataReceived(CClient *pClient, int16_t *pData, size_t Samples)
|
||||
pClient->m_LastValidData = getTime();
|
||||
}
|
||||
|
||||
struct SteamVoiceHeader
|
||||
{
|
||||
uint32_t iSteamAccountID : 32;
|
||||
uint32_t iSteamCommunity : 32;
|
||||
uint32_t nPayload1 : 8;
|
||||
uint32_t iSampleRate : 16;
|
||||
uint32_t nPayload2 : 8;
|
||||
uint32_t iDataLength : 16;
|
||||
};
|
||||
|
||||
void CVoice::HandleVoiceData()
|
||||
{
|
||||
int SamplesPerFrame = m_EncoderSettings.FrameSize;
|
||||
int PacketSize = m_EncoderSettings.PacketSize;
|
||||
int SamplesPerFrame = m_EncoderSettings.FrameSize_ms * m_EncoderSettings.InputSampleRate_kHz;
|
||||
int FramesAvailable = m_Buffer.TotalLength() / SamplesPerFrame;
|
||||
float TimeAvailable = (float)m_Buffer.TotalLength() / (float)m_EncoderSettings.SampleRate_Hz;
|
||||
float TimeAvailable = (float)m_Buffer.TotalLength() / (m_EncoderSettings.InputSampleRate_kHz * 1000.0);
|
||||
|
||||
if(!FramesAvailable)
|
||||
return;
|
||||
@ -657,13 +578,27 @@ void CVoice::HandleVoiceData()
|
||||
return;
|
||||
|
||||
// 5 = max frames per packet
|
||||
FramesAvailable = min_ext(FramesAvailable, 5);
|
||||
FramesAvailable = min(FramesAvailable, 5);
|
||||
|
||||
// 0 = SourceTV
|
||||
IClient *pClient = iserver->GetClient(0);
|
||||
IClient *pClient = g_pSDKTools->GetIServer()->GetClient(0);
|
||||
if(!pClient)
|
||||
return;
|
||||
|
||||
SteamVoiceHeader Header;
|
||||
size_t HeaderSize = 14;
|
||||
|
||||
Header.iSteamAccountID = 1; // Steam Account ID
|
||||
Header.iSteamCommunity = 0x01100001; // Steam Community ID part: 0x01100001 << 32
|
||||
Header.nPayload1 = 11; // nPayLoad | Type 11 = Samplerate
|
||||
Header.iSampleRate = m_EncoderSettings.OutputSampleRate_kHz * 1000; // Samplerate
|
||||
Header.nPayload2 = 4; // nPayLoad | Type 4 = Silk Frames
|
||||
Header.iDataLength = 0; // Silk Frames total length
|
||||
|
||||
// Header + Frames + CRC32
|
||||
unsigned char aFinal[HeaderSize + 8192 + sizeof(uint32_t)];
|
||||
size_t FinalSize = HeaderSize;
|
||||
|
||||
for(int Frame = 0; Frame < FramesAvailable; Frame++)
|
||||
{
|
||||
// Get data into buffer from ringbuffer.
|
||||
@ -675,22 +610,29 @@ void CVoice::HandleVoiceData()
|
||||
|
||||
if(!m_Buffer.Pop(aBuffer, SamplesPerFrame))
|
||||
{
|
||||
printf("Buffer pop failed!!! Samples: %u, Length: %zu\n", SamplesPerFrame, m_Buffer.TotalLength());
|
||||
smutils->LogError(myself, "Buffer pop failed!!! Samples: %u, Length: %u\n", SamplesPerFrame, m_Buffer.TotalLength());
|
||||
return;
|
||||
}
|
||||
|
||||
// Frame Size
|
||||
int16_t *pFrameSize = (int16_t *)(&aFinal[FinalSize]);
|
||||
FinalSize += sizeof(int16_t);
|
||||
Header.iDataLength += sizeof(int16_t);
|
||||
*pFrameSize = sizeof(aFinal) - HeaderSize - sizeof(uint32_t) - FinalSize;
|
||||
|
||||
// Encode it!
|
||||
unsigned char aFinal[PacketSize];
|
||||
size_t FinalSize = 0;
|
||||
int Ret = SKP_Silk_SDK_Encode(m_Silk_EncoderState, &m_Silk_EncoderControl, aBuffer,
|
||||
SamplesPerFrame, &aFinal[FinalSize], pFrameSize);
|
||||
|
||||
FinalSize = celt_encode(m_pCodec, aBuffer, SamplesPerFrame, aFinal, sizeof(aFinal));
|
||||
|
||||
if(FinalSize <= 0)
|
||||
if(Ret)
|
||||
{
|
||||
smutils->LogError(myself, "Compress returned %d\n", FinalSize);
|
||||
smutils->LogError(myself, "SKP_Silk_SDK_Encode returned %d\n", Ret);
|
||||
return;
|
||||
}
|
||||
|
||||
FinalSize += *pFrameSize;
|
||||
Header.iDataLength += *pFrameSize;
|
||||
|
||||
// Check for buffer underruns
|
||||
for(int Client = 0; Client < MAX_CLIENTS; Client++)
|
||||
{
|
||||
@ -707,24 +649,24 @@ void CVoice::HandleVoiceData()
|
||||
pClient->m_LastLength = m_Buffer.CurrentLength();
|
||||
}
|
||||
}
|
||||
|
||||
BroadcastVoiceData(pClient, FinalSize, aFinal);
|
||||
}
|
||||
|
||||
// Header
|
||||
memcpy(aFinal, &Header, HeaderSize);
|
||||
|
||||
// CRC32
|
||||
*(uint32_t *)(&aFinal[FinalSize]) = UTIL_CRC32(aFinal, FinalSize);
|
||||
FinalSize += sizeof(uint32_t);
|
||||
|
||||
SV_BroadcastVoiceData(pClient, FinalSize, aFinal);
|
||||
|
||||
if(m_AvailableTime < getTime())
|
||||
m_AvailableTime = getTime();
|
||||
|
||||
m_AvailableTime += (double)FramesAvailable * m_EncoderSettings.FrameTime;
|
||||
m_AvailableTime += (double)FramesAvailable * ((double)m_EncoderSettings.FrameSize_ms / 1000.0);
|
||||
}
|
||||
|
||||
void CVoice::BroadcastVoiceData(IClient *pClient, int nBytes, unsigned char *pData)
|
||||
void CVoice::SV_BroadcastVoiceData(IClient *pClient, int nBytes, unsigned char *pData)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
__asm mov ecx, pClient;
|
||||
__asm mov edx, nBytes;
|
||||
|
||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)((char *)pData, 0);
|
||||
#else
|
||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData)(pClient, nBytes, (char *)pData, 0);
|
||||
#endif
|
||||
m_SV_BroadcastVoiceData(pClient, nBytes, pData, 0);
|
||||
}
|
||||
|
31
extension.h
31
extension.h
@ -32,9 +32,8 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
|
||||
#include <poll.h>
|
||||
#include "smsdk_ext.h"
|
||||
#include "celt_header.h"
|
||||
#include <SKP_Silk_SDK_API.h>
|
||||
#include "ringbuffer.h"
|
||||
|
||||
/**
|
||||
@ -50,7 +49,6 @@ typedef __int64 int64;
|
||||
typedef long long int64;
|
||||
#endif
|
||||
|
||||
class CDetour;
|
||||
class IClient;
|
||||
typedef void (*t_SV_BroadcastVoiceData)(IClient *, int, unsigned char *, int64);
|
||||
|
||||
@ -137,9 +135,6 @@ public: // IConCommandBaseAccessor
|
||||
public:
|
||||
CVoice();
|
||||
void OnGameFrame(bool simulating);
|
||||
bool OnBroadcastVoiceData(IClient *pClient, int nBytes, char *data);
|
||||
|
||||
void ListenSocket();
|
||||
|
||||
private:
|
||||
int m_ListenSocket;
|
||||
@ -151,8 +146,6 @@ private:
|
||||
size_t m_LastLength;
|
||||
double m_LastValidData;
|
||||
bool m_New;
|
||||
bool m_UnEven;
|
||||
unsigned char m_Remainder;
|
||||
} m_aClients[MAX_CLIENTS];
|
||||
|
||||
struct pollfd m_aPollFds[1 + MAX_CLIENTS];
|
||||
@ -164,24 +157,26 @@ private:
|
||||
|
||||
struct CEncoderSettings
|
||||
{
|
||||
celt_int32 SampleRate_Hz;
|
||||
celt_int32 TargetBitRate_Kbps;
|
||||
celt_int32 FrameSize;
|
||||
celt_int32 PacketSize;
|
||||
celt_int32 Complexity;
|
||||
double FrameTime;
|
||||
SKP_int InputSampleRate_kHz;
|
||||
SKP_int OutputSampleRate_kHz;
|
||||
SKP_int TargetBitRate_Kbps;
|
||||
SKP_int PacketSize_ms;
|
||||
SKP_int FrameSize_ms;
|
||||
SKP_int PacketLoss_perc;
|
||||
SKP_int Complexity;
|
||||
SKP_int InBandFEC;
|
||||
SKP_int DTX;
|
||||
} m_EncoderSettings;
|
||||
|
||||
CELTMode *m_pMode;
|
||||
CELTEncoder *m_pCodec;
|
||||
void *m_Silk_EncoderState;
|
||||
SKP_SILK_SDK_EncControlStruct m_Silk_EncoderControl;
|
||||
|
||||
t_SV_BroadcastVoiceData m_SV_BroadcastVoiceData;
|
||||
CDetour *m_VoiceDetour;
|
||||
|
||||
void HandleNetwork();
|
||||
void OnDataReceived(CClient *pClient, int16_t *pData, size_t Samples);
|
||||
void HandleVoiceData();
|
||||
void BroadcastVoiceData(IClient *pClient, int nBytes, unsigned char *pData);
|
||||
void SV_BroadcastVoiceData(IClient *pClient, int nBytes, unsigned char *pData);
|
||||
};
|
||||
|
||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
|
BIN
silk/SKP_Silk_FLP_Win32_mt.lib
Normal file
BIN
silk/SKP_Silk_FLP_Win32_mt.lib
Normal file
Binary file not shown.
152
silk/SKP_Silk_SDK_API.h
Normal file
152
silk/SKP_Silk_SDK_API.h
Normal file
@ -0,0 +1,152 @@
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2012, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef SKP_SILK_SDK_API_H
|
||||
#define SKP_SILK_SDK_API_H
|
||||
|
||||
#include "SKP_Silk_control.h"
|
||||
#include "SKP_Silk_typedef.h"
|
||||
#include "SKP_Silk_errors.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define SILK_MAX_FRAMES_PER_PACKET 5
|
||||
|
||||
/* Struct for TOC (Table of Contents) */
|
||||
typedef struct {
|
||||
SKP_int framesInPacket; /* Number of 20 ms frames in packet */
|
||||
SKP_int fs_kHz; /* Sampling frequency in packet */
|
||||
SKP_int inbandLBRR; /* Does packet contain LBRR information */
|
||||
SKP_int corrupt; /* Packet is corrupt */
|
||||
SKP_int vadFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* VAD flag for each frame in packet */
|
||||
SKP_int sigtypeFlags[ SILK_MAX_FRAMES_PER_PACKET ]; /* Signal type for each frame in packet */
|
||||
} SKP_Silk_TOC_struct;
|
||||
|
||||
/****************************************/
|
||||
/* Encoder functions */
|
||||
/****************************************/
|
||||
|
||||
/***********************************************/
|
||||
/* Get size in bytes of the Silk encoder state */
|
||||
/***********************************************/
|
||||
SKP_int SKP_Silk_SDK_Get_Encoder_Size(
|
||||
SKP_int32 *encSizeBytes /* O: Number of bytes in SILK encoder state */
|
||||
);
|
||||
|
||||
/*************************/
|
||||
/* Init or reset encoder */
|
||||
/*************************/
|
||||
SKP_int SKP_Silk_SDK_InitEncoder(
|
||||
void *encState, /* I/O: State */
|
||||
SKP_SILK_SDK_EncControlStruct *encStatus /* O: Encoder Status */
|
||||
);
|
||||
|
||||
/***************************************/
|
||||
/* Read control structure from encoder */
|
||||
/***************************************/
|
||||
SKP_int SKP_Silk_SDK_QueryEncoder(
|
||||
const void *encState, /* I: State */
|
||||
SKP_SILK_SDK_EncControlStruct *encStatus /* O: Encoder Status */
|
||||
);
|
||||
|
||||
/**************************/
|
||||
/* Encode frame with Silk */
|
||||
/**************************/
|
||||
SKP_int SKP_Silk_SDK_Encode(
|
||||
void *encState, /* I/O: State */
|
||||
const SKP_SILK_SDK_EncControlStruct *encControl, /* I: Control status */
|
||||
const SKP_int16 *samplesIn, /* I: Speech sample input vector */
|
||||
SKP_int nSamplesIn, /* I: Number of samples in input vector */
|
||||
SKP_uint8 *outData, /* O: Encoded output vector */
|
||||
SKP_int16 *nBytesOut /* I/O: Number of bytes in outData (input: Max bytes) */
|
||||
);
|
||||
|
||||
/****************************************/
|
||||
/* Decoder functions */
|
||||
/****************************************/
|
||||
|
||||
/***********************************************/
|
||||
/* Get size in bytes of the Silk decoder state */
|
||||
/***********************************************/
|
||||
SKP_int SKP_Silk_SDK_Get_Decoder_Size(
|
||||
SKP_int32 *decSizeBytes /* O: Number of bytes in SILK decoder state */
|
||||
);
|
||||
|
||||
/*************************/
|
||||
/* Init or Reset decoder */
|
||||
/*************************/
|
||||
SKP_int SKP_Silk_SDK_InitDecoder(
|
||||
void *decState /* I/O: State */
|
||||
);
|
||||
|
||||
/******************/
|
||||
/* Decode a frame */
|
||||
/******************/
|
||||
SKP_int SKP_Silk_SDK_Decode(
|
||||
void* decState, /* I/O: State */
|
||||
SKP_SILK_SDK_DecControlStruct* decControl, /* I/O: Control Structure */
|
||||
SKP_int lostFlag, /* I: 0: no loss, 1 loss */
|
||||
const SKP_uint8 *inData, /* I: Encoded input vector */
|
||||
const SKP_int nBytesIn, /* I: Number of input bytes */
|
||||
SKP_int16 *samplesOut, /* O: Decoded output speech vector */
|
||||
SKP_int16 *nSamplesOut /* I/O: Number of samples (vector/decoded) */
|
||||
);
|
||||
|
||||
/***************************************************************/
|
||||
/* Find Low Bit Rate Redundancy (LBRR) information in a packet */
|
||||
/***************************************************************/
|
||||
void SKP_Silk_SDK_search_for_LBRR(
|
||||
const SKP_uint8 *inData, /* I: Encoded input vector */
|
||||
const SKP_int nBytesIn, /* I: Number of input Bytes */
|
||||
SKP_int lost_offset, /* I: Offset from lost packet */
|
||||
SKP_uint8 *LBRRData, /* O: LBRR payload */
|
||||
SKP_int16 *nLBRRBytes /* O: Number of LBRR Bytes */
|
||||
);
|
||||
|
||||
/**************************************/
|
||||
/* Get table of contents for a packet */
|
||||
/**************************************/
|
||||
void SKP_Silk_SDK_get_TOC(
|
||||
const SKP_uint8 *inData, /* I: Encoded input vector */
|
||||
const SKP_int nBytesIn, /* I: Number of input bytes */
|
||||
SKP_Silk_TOC_struct *Silk_TOC /* O: Table of contents */
|
||||
);
|
||||
|
||||
/**************************/
|
||||
/* Get the version number */
|
||||
/**************************/
|
||||
/* Return a pointer to string specifying the version */
|
||||
const char *SKP_Silk_SDK_get_version();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
91
silk/SKP_Silk_control.h
Normal file
91
silk/SKP_Silk_control.h
Normal file
@ -0,0 +1,91 @@
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2012, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef SKP_SILK_CONTROL_H
|
||||
#define SKP_SILK_CONTROL_H
|
||||
|
||||
#include "SKP_Silk_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/***********************************************/
|
||||
/* Structure for controlling encoder operation */
|
||||
/***********************************************/
|
||||
typedef struct {
|
||||
/* I: Input signal sampling rate in Hertz; 8000/12000/16000/24000 */
|
||||
SKP_int32 API_sampleRate;
|
||||
|
||||
/* I: Maximum internal sampling rate in Hertz; 8000/12000/16000/24000 */
|
||||
SKP_int32 maxInternalSampleRate;
|
||||
|
||||
/* I: Number of samples per packet; must be equivalent of 20, 40, 60, 80 or 100 ms */
|
||||
SKP_int packetSize;
|
||||
|
||||
/* I: Bitrate during active speech in bits/second; internally limited */
|
||||
SKP_int32 bitRate;
|
||||
|
||||
/* I: Uplink packet loss in percent (0-100) */
|
||||
SKP_int packetLossPercentage;
|
||||
|
||||
/* I: Complexity mode; 0 is lowest; 1 is medium and 2 is highest complexity */
|
||||
SKP_int complexity;
|
||||
|
||||
/* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */
|
||||
SKP_int useInBandFEC;
|
||||
|
||||
/* I: Flag to enable discontinuous transmission (DTX); 0/1 */
|
||||
SKP_int useDTX;
|
||||
} SKP_SILK_SDK_EncControlStruct;
|
||||
|
||||
/**************************************************************************/
|
||||
/* Structure for controlling decoder operation and reading decoder status */
|
||||
/**************************************************************************/
|
||||
typedef struct {
|
||||
/* I: Output signal sampling rate in Hertz; 8000/12000/16000/24000 */
|
||||
SKP_int32 API_sampleRate;
|
||||
|
||||
/* O: Number of samples per frame */
|
||||
SKP_int frameSize;
|
||||
|
||||
/* O: Frames per packet 1, 2, 3, 4, 5 */
|
||||
SKP_int framesPerPacket;
|
||||
|
||||
/* O: Flag to indicate that the decoder has remaining payloads internally */
|
||||
SKP_int moreInternalDecoderFrames;
|
||||
|
||||
/* O: Distance between main payload and redundant payload in packets */
|
||||
SKP_int inBandFECOffset;
|
||||
} SKP_SILK_SDK_DecControlStruct;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
89
silk/SKP_Silk_errors.h
Normal file
89
silk/SKP_Silk_errors.h
Normal file
@ -0,0 +1,89 @@
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2012, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef SKP_SILK_ERRORS_H
|
||||
#define SKP_SILK_ERRORS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/******************/
|
||||
/* Error messages */
|
||||
/******************/
|
||||
#define SKP_SILK_NO_ERROR 0
|
||||
|
||||
/**************************/
|
||||
/* Encoder error messages */
|
||||
/**************************/
|
||||
|
||||
/* Input length is not a multiplum of 10 ms, or length is longer than the packet length */
|
||||
#define SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES -1
|
||||
|
||||
/* Sampling frequency not 8000, 12000, 16000 or 24000 Hertz */
|
||||
#define SKP_SILK_ENC_FS_NOT_SUPPORTED -2
|
||||
|
||||
/* Packet size not 20, 40, 60, 80 or 100 ms */
|
||||
#define SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED -3
|
||||
|
||||
/* Allocated payload buffer too short */
|
||||
#define SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT -4
|
||||
|
||||
/* Loss rate not between 0 and 100 percent */
|
||||
#define SKP_SILK_ENC_INVALID_LOSS_RATE -5
|
||||
|
||||
/* Complexity setting not valid, use 0, 1 or 2 */
|
||||
#define SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING -6
|
||||
|
||||
/* Inband FEC setting not valid, use 0 or 1 */
|
||||
#define SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING -7
|
||||
|
||||
/* DTX setting not valid, use 0 or 1 */
|
||||
#define SKP_SILK_ENC_INVALID_DTX_SETTING -8
|
||||
|
||||
/* Internal encoder error */
|
||||
#define SKP_SILK_ENC_INTERNAL_ERROR -9
|
||||
|
||||
/**************************/
|
||||
/* Decoder error messages */
|
||||
/**************************/
|
||||
|
||||
/* Output sampling frequency lower than internal decoded sampling frequency */
|
||||
#define SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY -10
|
||||
|
||||
/* Payload size exceeded the maximum allowed 1024 bytes */
|
||||
#define SKP_SILK_DEC_PAYLOAD_TOO_LARGE -11
|
||||
|
||||
/* Payload has bit errors */
|
||||
#define SKP_SILK_DEC_PAYLOAD_ERROR -12
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
107
silk/SKP_Silk_typedef.h
Normal file
107
silk/SKP_Silk_typedef.h
Normal file
@ -0,0 +1,107 @@
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2012, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef _SKP_SILK_API_TYPDEF_H_
|
||||
#define _SKP_SILK_API_TYPDEF_H_
|
||||
|
||||
#ifndef SKP_USE_DOUBLE_PRECISION_FLOATS
|
||||
#define SKP_USE_DOUBLE_PRECISION_FLOATS 0
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
#if defined( __GNUC__ )
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#define SKP_int int /* used for counters etc; at least 16 bits */
|
||||
#ifdef __GNUC__
|
||||
# define SKP_int64 int64_t
|
||||
#else
|
||||
# define SKP_int64 long long
|
||||
#endif
|
||||
#define SKP_int32 int
|
||||
#define SKP_int16 short
|
||||
#define SKP_int8 signed char
|
||||
|
||||
#define SKP_uint unsigned int /* used for counters etc; at least 16 bits */
|
||||
#ifdef __GNUC__
|
||||
# define SKP_uint64 uint64_t
|
||||
#else
|
||||
# define SKP_uint64 unsigned long long
|
||||
#endif
|
||||
#define SKP_uint32 unsigned int
|
||||
#define SKP_uint16 unsigned short
|
||||
#define SKP_uint8 unsigned char
|
||||
|
||||
#define SKP_int_ptr_size intptr_t
|
||||
|
||||
#if SKP_USE_DOUBLE_PRECISION_FLOATS
|
||||
# define SKP_float double
|
||||
# define SKP_float_MAX DBL_MAX
|
||||
#else
|
||||
# define SKP_float float
|
||||
# define SKP_float_MAX FLT_MAX
|
||||
#endif
|
||||
|
||||
#define SKP_INLINE static __inline
|
||||
|
||||
#ifdef _WIN32
|
||||
# define SKP_STR_CASEINSENSITIVE_COMPARE(x, y) _stricmp(x, y)
|
||||
#else
|
||||
# define SKP_STR_CASEINSENSITIVE_COMPARE(x, y) strcasecmp(x, y)
|
||||
#endif
|
||||
|
||||
#define SKP_int64_MAX ((SKP_int64)0x7FFFFFFFFFFFFFFFLL) /* 2^63 - 1 */
|
||||
#define SKP_int64_MIN ((SKP_int64)0x8000000000000000LL) /* -2^63 */
|
||||
#define SKP_int32_MAX 0x7FFFFFFF /* 2^31 - 1 = 2147483647*/
|
||||
#define SKP_int32_MIN ((SKP_int32)0x80000000) /* -2^31 = -2147483648*/
|
||||
#define SKP_int16_MAX 0x7FFF /* 2^15 - 1 = 32767*/
|
||||
#define SKP_int16_MIN ((SKP_int16)0x8000) /* -2^15 = -32768*/
|
||||
#define SKP_int8_MAX 0x7F /* 2^7 - 1 = 127*/
|
||||
#define SKP_int8_MIN ((SKP_int8)0x80) /* -2^7 = -128*/
|
||||
|
||||
#define SKP_uint32_MAX 0xFFFFFFFF /* 2^32 - 1 = 4294967295 */
|
||||
#define SKP_uint32_MIN 0x00000000
|
||||
#define SKP_uint16_MAX 0xFFFF /* 2^16 - 1 = 65535 */
|
||||
#define SKP_uint16_MIN 0x0000
|
||||
#define SKP_uint8_MAX 0xFF /* 2^8 - 1 = 255 */
|
||||
#define SKP_uint8_MIN 0x00
|
||||
|
||||
#define SKP_TRUE 1
|
||||
#define SKP_FALSE 0
|
||||
|
||||
/* assertions */
|
||||
#if (defined _WIN32 && !defined _WINCE && !defined(__GNUC__) && !defined(NO_ASSERTS))
|
||||
# ifndef SKP_assert
|
||||
# include <crtdbg.h> /* ASSERTE() */
|
||||
# define SKP_assert(COND) _ASSERTE(COND)
|
||||
# endif
|
||||
#else
|
||||
# define SKP_assert(COND)
|
||||
#endif
|
||||
|
||||
#endif
|
BIN
silk/libSKP_SILK_SDK.a
Normal file
BIN
silk/libSKP_SILK_SDK.a
Normal file
Binary file not shown.
@ -40,7 +40,7 @@
|
||||
/* Basic information exposed publicly */
|
||||
#define SMEXT_CONF_NAME "Voice"
|
||||
#define SMEXT_CONF_DESCRIPTION "Inject voice data over existing clients"
|
||||
#define SMEXT_CONF_VERSION "1.1"
|
||||
#define SMEXT_CONF_VERSION "1.0"
|
||||
#define SMEXT_CONF_AUTHOR "BotoX"
|
||||
#define SMEXT_CONF_URL ""
|
||||
#define SMEXT_CONF_LOGTAG "VOICE"
|
||||
@ -61,7 +61,7 @@
|
||||
/** Enable interfaces you want to use here by uncommenting lines */
|
||||
//#define SMEXT_ENABLE_FORWARDSYS
|
||||
//#define SMEXT_ENABLE_HANDLESYS
|
||||
#define SMEXT_ENABLE_PLAYERHELPERS
|
||||
//#define SMEXT_ENABLE_PLAYERHELPERS
|
||||
//#define SMEXT_ENABLE_DBMANAGER
|
||||
#define SMEXT_ENABLE_GAMECONF
|
||||
#define SMEXT_ENABLE_MEMUTILS
|
||||
|
68
voice_packet.bt.txt
Normal file
68
voice_packet.bt.txt
Normal file
@ -0,0 +1,68 @@
|
||||
//--------------------------------------
|
||||
//--- 010 Editor v6.0.3 Binary Template
|
||||
//
|
||||
// File:
|
||||
// Author:
|
||||
// Revision:
|
||||
// Purpose:
|
||||
//--------------------------------------
|
||||
|
||||
// CClientAudio::DecompressVoice
|
||||
local int64 crcLength = FileSize() - sizeof(uint32);
|
||||
|
||||
uint64 steamId;
|
||||
|
||||
FSeek(crcLength);
|
||||
uint32 crc;
|
||||
|
||||
local int64 crc_calc = Checksum(CHECKSUM_CRC32, 0, crcLength);
|
||||
if (crc != crc_calc) {
|
||||
Warning("CRC mismatch!");
|
||||
return;
|
||||
}
|
||||
|
||||
// CVoiceDecoder::ProcessVoicePayload
|
||||
FSeek(sizeof(uint64));
|
||||
|
||||
while (FTell() < crcLength) {
|
||||
char payloadType;
|
||||
|
||||
switch (payloadType) {
|
||||
default:
|
||||
Warning("Unhandled payload!");
|
||||
return;
|
||||
case 11: // Sample Rate
|
||||
short sampleRate;
|
||||
break;
|
||||
case 10: // Unknown / Unused
|
||||
char unk1;
|
||||
char unk2;
|
||||
break;
|
||||
case 1: // Unknown Codec???
|
||||
case 2: // Speex Data (Unsupported)
|
||||
case 3: // Uncompressed Data
|
||||
case 4: // SILK Data
|
||||
short dataLength;
|
||||
char data[dataLength];
|
||||
break;
|
||||
case 0: // Silence
|
||||
short numSamples;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// CVoiceDecoder::AddIncomingData
|
||||
FSeek(startof(data));
|
||||
|
||||
// VoiceEncoder_SILK::Decompress
|
||||
|
||||
// chunkLength == -1 means ResetState
|
||||
|
||||
while ((FTell() - startof(data)) < dataLength) {
|
||||
struct Chunk {
|
||||
short chunkLength;
|
||||
if (chunkLength != -1) {
|
||||
char chunk[chunkLength];
|
||||
}
|
||||
} chunk;
|
||||
}
|
Loading…
Reference in New Issue
Block a user