diff options
| author | Rapptz <[email protected]> | 2016-05-06 12:22:03 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-05-06 12:23:24 -0400 |
| commit | 2fc496304c94a039d87ae4d6c39a87342180f208 (patch) | |
| tree | 777481fe2128dcc129e46868684d859e547b6856 | |
| parent | Enable FEC/PLR (diff) | |
| download | discord.py-2fc496304c94a039d87ae4d6c39a87342180f208.tar.xz discord.py-2fc496304c94a039d87ae4d6c39a87342180f208.zip | |
Add libopus DLLs for ease of use.
| -rw-r--r-- | MANIFEST.in | 1 | ||||
| -rw-r--r-- | discord/bin/libopus-0.x64.dll | bin | 0 -> 261632 bytes | |||
| -rw-r--r-- | discord/bin/libopus-0.x86.dll | bin | 0 -> 271872 bytes | |||
| -rw-r--r-- | discord/opus.py | 12 | ||||
| -rw-r--r-- | discord/voice_client.py | 7 |
5 files changed, 14 insertions, 6 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index bb910ebb..48577371 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include README.md include LICENSE include requirements.txt +include discord/bin/*.dll diff --git a/discord/bin/libopus-0.x64.dll b/discord/bin/libopus-0.x64.dll Binary files differnew file mode 100644 index 00000000..a962869f --- /dev/null +++ b/discord/bin/libopus-0.x64.dll diff --git a/discord/bin/libopus-0.x86.dll b/discord/bin/libopus-0.x86.dll Binary files differnew file mode 100644 index 00000000..a9eec802 --- /dev/null +++ b/discord/bin/libopus-0.x86.dll diff --git a/discord/opus.py b/discord/opus.py index 089a735e..a5f81486 100644 --- a/discord/opus.py +++ b/discord/opus.py @@ -29,6 +29,8 @@ import ctypes.util import array from .errors import DiscordException import logging +import sys +import os.path log = logging.getLogger(__name__) c_int_ptr = ctypes.POINTER(ctypes.c_int) @@ -75,8 +77,14 @@ def libopus_loader(name): return lib try: - _lib = libopus_loader(ctypes.util.find_library('opus')) -except: + if sys.platform == 'win32': + _basedir = os.path.dirname(os.path.abspath(__file__)) + _bitness = 'x64' if sys.maxsize > 2**32 else 'x86' + _filename = os.path.join(_basedir, 'bin', 'libopus-0.{}.dll'.format(_bitness)) + _lib = libopus_loader(_filename) + else: + _lib = libopus_loader(ctypes.util.find_library('opus')) +except Exception as e: _lib = None def load_opus(name): diff --git a/discord/voice_client.py b/discord/voice_client.py index 4079138f..5da25684 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -54,10 +54,9 @@ import nacl.secret log = logging.getLogger(__name__) -from . import utils +from . import utils, opus from .gateway import * from .errors import ClientException, InvalidArgument -from .opus import Encoder as OpusEncoder class StreamPlayer(threading.Thread): def __init__(self, stream, encoder, connected, player, after, **kwargs): @@ -176,7 +175,7 @@ class VoiceClient: self.endpoint = data.get('endpoint') self.sequence = 0 self.timestamp = 0 - self.encoder = OpusEncoder(48000, 2) + self.encoder = opus.Encoder(48000, 2) log.info('created opus encoder with {0.__dict__}'.format(self.encoder)) @property @@ -496,7 +495,7 @@ class VoiceClient: if channels not in (1, 2): raise InvalidArgument('Channels must be either 1 or 2.') - self.encoder = OpusEncoder(sample_rate, channels) + self.encoder = opus.Encoder(sample_rate, channels) log.info('created opus encoder with {0.__dict__}'.format(self.encoder)) def create_stream_player(self, stream, *, after=None): |