From fedf26bf3e91e12a403144e8282300a785c204d4 Mon Sep 17 00:00:00 2001 From: Imayhaveborkedit Date: Sat, 22 Jun 2019 02:33:53 -0400 Subject: Add FFmpegOpusAudio and other voice improvements Rework FFmpeg player and add FFmpegOpusAudio I have extracted some of the base FFmpeg source code into its own base class and reimplemented the PCM and the new Opus variants. Support avconv probing Also fix a few things Update `__all__` Fix the bugs Rework probe functions and add factory function Probing involves subprocess so it has been reworked into an async factory function. Add docs + a few tweaks * Removed unnecessary read() and is_opus() functions from FFmpegAudio * Clear self._stdout in cleanup() * Add 20 second process communication timeout to probe functions * Capped probe function bitrate values at 512 Change AudioPlayer to use more accurate, monotonic time.perf_counter() Add lazy opus loading The library now no longer loads libopus on import, only on opus.Encoder creation or manually. Fix review nits --- discord/oggparse.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 discord/oggparse.py (limited to 'discord/oggparse.py') diff --git a/discord/oggparse.py b/discord/oggparse.py new file mode 100644 index 00000000..6f50502f --- /dev/null +++ b/discord/oggparse.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015-2019 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +import struct + +from .errors import DiscordException + +class OggError(DiscordException): + """An exception that is thrown for Ogg stream parsing errors.""" + pass + +# https://tools.ietf.org/html/rfc3533 +# https://tools.ietf.org/html/rfc7845 + +class OggPage: + _header = struct.Struct('