-
-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Externalize opus binaries #659
Merged
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d323a33
Moved opus out into external repository
MinnDevelopment 027150f
opus submodule
MinnDevelopment 31046fc
Handling for missing opus dependency
MinnDevelopment 04b813c
Added information on how to exclude opus
MinnDevelopment 3113032
Updated .gitattributes and submodule
MinnDevelopment fa3e52f
Fix indentation
MinnDevelopment 91d72cf
Updated module
MinnDevelopment e04d19d
Merge remote-tracking branch 'origin/development' into patch-opus
MinnDevelopment f6cdc36
Move opus-java to bintray repository
MinnDevelopment 5183cea
Update to 1.0.1
MinnDevelopment f4c413d
Fix javadoc
MinnDevelopment 4fb22ad
Add support for optional opus binaries
MinnDevelopment 179ed1a
Cleanup imports
MinnDevelopment e95991f
Add opus-java to dependencies list in README
MinnDevelopment 7ad1622
Add support for using custom opus library paths
MinnDevelopment 2982aba
Remove old opus-java module reference
MinnDevelopment 6bfcd1c
Replace OpusLibrary with AudioNatives and move logic for loading
MinnDevelopment 6634a53
Add loadFrom to AudioNatives class
MinnDevelopment 3751763
Update version in README
MinnDevelopment 15d34d9
Update documentation and allow loadFrom to be used after ensureOpus f…
MinnDevelopment 3c1eb48
Update README and remove AudioNatives.loadFrom
MinnDevelopment 5cad61a
Update opus-java to 1.0.2
MinnDevelopment 964dc5f
Add artifact without opus natives
MinnDevelopment 1127ea1
Add JNA to exclude path of noOpusJar
MinnDevelopment 32c262a
Exclude opus classes from no-opus artifact
MinnDevelopment 5116ddb
Switch to runtime configuration
MinnDevelopment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/net/dv8tion/jda/core/audio/AudioNatives.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2015-2018 Austin Keener & Michael Ritter & Florian Spieß | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.dv8tion.jda.core.audio; | ||
|
||
import club.minnced.opus.util.OpusLibrary; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
public final class AudioNatives | ||
{ | ||
private static final Logger LOG = LoggerFactory.getLogger(AudioNatives.class); | ||
private static boolean initialized; | ||
private static boolean audioSupported; | ||
|
||
private AudioNatives() {} | ||
|
||
public static synchronized boolean loadFrom(String absolutePath) | ||
{ | ||
if (initialized) | ||
return false; | ||
initialized = true; | ||
System.load(absolutePath); | ||
System.setProperty("opus.lib", absolutePath); | ||
return audioSupported = true; | ||
} | ||
|
||
public static synchronized boolean ensureOpus() | ||
{ | ||
if (initialized) | ||
return audioSupported; | ||
initialized = true; | ||
try | ||
{ | ||
if (OpusLibrary.isInitialized()) | ||
return audioSupported = true; | ||
audioSupported = OpusLibrary.loadFromJar(); | ||
} | ||
catch (Throwable e) | ||
{ | ||
handleException(e); | ||
} | ||
finally | ||
{ | ||
if (audioSupported) | ||
LOG.info("Audio System successfully setup!"); | ||
else | ||
LOG.info("Audio System encountered problems while loading, thus, is disabled."); | ||
} | ||
return audioSupported; | ||
} | ||
|
||
private static void handleException(Throwable e) | ||
{ | ||
if (e instanceof UnsupportedOperationException) | ||
{ | ||
LOG.error("Sorry, JDA's audio system doesn't support this system.\n{}", e.getMessage()); | ||
} | ||
else if (e instanceof NoClassDefFoundError) | ||
{ | ||
LOG.error("Missing opus dependency, unable to initialize audio!"); | ||
} | ||
else if (e instanceof IOException) | ||
{ | ||
LOG.error("There was an IO Exception when setting up the temp files for audio.", e); | ||
} | ||
else if (e instanceof UnsatisfiedLinkError) | ||
{ | ||
LOG.error("JDA encountered a problem when attempting to load the Native libraries. Contact a DEV.", e); | ||
} | ||
else if (e instanceof Error) | ||
{ | ||
throw (Error) e; | ||
} | ||
else | ||
{ | ||
LOG.error("An unknown exception occurred while attempting to setup JDA's audio system!", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this return
audioSupported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensureOpus()
returnsaudioSupported
because it is used by JDA to check whether the library is available or not.loadFrom()
returns true if the library is loaded from that method invokation and false if not (it was already loaded).