mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 06:11:36 +00:00
Possible to specify audio device and default to hw:0 to stop using PusleAudio
This commit is contained in:
@@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
snd_pcm_t *handle;
|
snd_pcm_t *handle;
|
||||||
|
|
||||||
int nv_alsa_init(unsigned int channelCount, unsigned int sampleRate) {
|
int nv_alsa_init(unsigned int channelCount, unsigned int sampleRate, unsigned char* device) {
|
||||||
int rc;
|
int rc;
|
||||||
snd_pcm_hw_params_t *params;
|
snd_pcm_hw_params_t *params;
|
||||||
int dir;
|
int dir;
|
||||||
|
|
||||||
/* Open PCM device for playback. */
|
/* Open PCM device for playback. */
|
||||||
if ((rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0)) != 0)
|
if ((rc = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) != 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
snd_pcm_hw_params_alloca(¶ms);
|
snd_pcm_hw_params_alloca(¶ms);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
int nv_alsa_init(unsigned int channelCount, unsigned int sampleRate);
|
int nv_alsa_init(unsigned int channelCount, unsigned int sampleRate, unsigned char* indata);
|
||||||
int nv_alsa_play(unsigned char* indata, int inlen);
|
int nv_alsa_play(unsigned char* indata, int inlen);
|
||||||
void nv_alsa_close(void);
|
void nv_alsa_close(void);
|
||||||
|
|||||||
@@ -6,9 +6,19 @@
|
|||||||
// This function must be called before
|
// This function must be called before
|
||||||
// any other decoding functions
|
// any other decoding functions
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_com_limelight_binding_audio_AlsaAudio_init(JNIEnv *env, jobject this, jint channelCount, jint sampleRate)
|
Java_com_limelight_binding_audio_AlsaAudio_init(JNIEnv *env, jobject this, jint channelCount, jint sampleRate, jbyteArray device)
|
||||||
{
|
{
|
||||||
return nv_alsa_init(channelCount, sampleRate);
|
jint ret;
|
||||||
|
jbyte* jni_device;
|
||||||
|
|
||||||
|
jni_device = (*env)->GetByteArrayElements(env, device, 0);
|
||||||
|
|
||||||
|
ret = nv_alsa_init(channelCount, sampleRate, jni_device);
|
||||||
|
|
||||||
|
// The input data isn't changed so it can be safely aborted
|
||||||
|
(*env)->ReleaseByteArrayElements(env, device, jni_device, JNI_ABORT);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Limelight implements NvConnectionListener {
|
|||||||
/*
|
/*
|
||||||
* Creates a connection to the host and starts up the stream.
|
* Creates a connection to the host and starts up the stream.
|
||||||
*/
|
*/
|
||||||
private void startUp(StreamConfiguration streamConfig, List<String> inputs, String mappingFile) {
|
private void startUp(StreamConfiguration streamConfig, List<String> inputs, String mappingFile, String audioDevice) {
|
||||||
String vm = System.getProperties().getProperty("java.vm.name");
|
String vm = System.getProperties().getProperty("java.vm.name");
|
||||||
if (!vm.contains("HotSpot")) {
|
if (!vm.contains("HotSpot")) {
|
||||||
System.err.println("You are using a unsupported VM: " + vm);
|
System.err.println("You are using a unsupported VM: " + vm);
|
||||||
@@ -87,11 +87,11 @@ public class Limelight implements NvConnectionListener {
|
|||||||
displayError("Input", "Are you running as root?");
|
displayError("Input", "Are you running as root?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.start(PlatformBinding.getDeviceName(), null,
|
conn.start(PlatformBinding.getDeviceName(), null,
|
||||||
VideoDecoderRenderer.FLAG_PREFER_QUALITY,
|
VideoDecoderRenderer.FLAG_PREFER_QUALITY,
|
||||||
PlatformBinding.getAudioRenderer(),
|
PlatformBinding.getAudioRenderer(audioDevice),
|
||||||
PlatformBinding.getVideoDecoderRenderer());
|
PlatformBinding.getVideoDecoderRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +151,7 @@ public class Limelight implements NvConnectionListener {
|
|||||||
int refresh = 60;
|
int refresh = 60;
|
||||||
boolean parse = true;
|
boolean parse = true;
|
||||||
String mapping = null;
|
String mapping = null;
|
||||||
|
String audio = "hw:0";
|
||||||
|
|
||||||
for (int i = 0; i < args.length - 1; i++) {
|
for (int i = 0; i < args.length - 1; i++) {
|
||||||
if (args[i].equals("-input")) {
|
if (args[i].equals("-input")) {
|
||||||
@@ -169,6 +170,14 @@ public class Limelight implements NvConnectionListener {
|
|||||||
System.out.println("Syntax error: mapping file expected after -mapping");
|
System.out.println("Syntax error: mapping file expected after -mapping");
|
||||||
System.exit(3);
|
System.exit(3);
|
||||||
}
|
}
|
||||||
|
} else if (args[i].equals("-audio")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
audio = args[i+1];
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
System.out.println("Syntax error: audio device expected after -audio");
|
||||||
|
System.exit(3);
|
||||||
|
}
|
||||||
} else if (args[i].equals("-pair")) {
|
} else if (args[i].equals("-pair")) {
|
||||||
pair = true;
|
pair = true;
|
||||||
} else if (args[i].equals("-720")) {
|
} else if (args[i].equals("-720")) {
|
||||||
@@ -194,6 +203,7 @@ public class Limelight implements NvConnectionListener {
|
|||||||
System.out.println("\t-input <device>\tUse <device> as input. Can be used multiple times");
|
System.out.println("\t-input <device>\tUse <device> as input. Can be used multiple times");
|
||||||
System.out.println("\t\t\t[default uses all devices in /dev/input]");
|
System.out.println("\t\t\t[default uses all devices in /dev/input]");
|
||||||
System.out.println("\t-mapping <file>\tUse <file> as gamepad mapping configuration file");
|
System.out.println("\t-mapping <file>\tUse <file> as gamepad mapping configuration file");
|
||||||
|
System.out.println("\t-audio <device>\tUse <device> as ALSA audio output device (default hw:0)");
|
||||||
System.out.println("\t-pair\t\tPair with host");
|
System.out.println("\t-pair\t\tPair with host");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Use ctrl-c to exit application");
|
System.out.println("Use ctrl-c to exit application");
|
||||||
@@ -205,7 +215,7 @@ public class Limelight implements NvConnectionListener {
|
|||||||
|
|
||||||
Limelight limelight = new Limelight(host);
|
Limelight limelight = new Limelight(host);
|
||||||
if (!pair)
|
if (!pair)
|
||||||
limelight.startUp(streamConfig, inputs, mapping);
|
limelight.startUp(streamConfig, inputs, mapping, audio);
|
||||||
else
|
else
|
||||||
limelight.pair();
|
limelight.pair();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class PlatformBinding {
|
|||||||
* Gets an instance of an audio decoder/renderer.
|
* Gets an instance of an audio decoder/renderer.
|
||||||
* @return an audio decoder and renderer
|
* @return an audio decoder and renderer
|
||||||
*/
|
*/
|
||||||
public static AudioRenderer getAudioRenderer() {
|
public static AudioRenderer getAudioRenderer(String device) {
|
||||||
return new AlsaAudioRenderer();
|
return new AlsaAudioRenderer(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class AlsaAudio {
|
|||||||
System.loadLibrary("nv_alsa");
|
System.loadLibrary("nv_alsa");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static native int init(int channelCount, int sampleRate);
|
public static native int init(int channelCount, int sampleRate, byte[] device);
|
||||||
|
|
||||||
public static native void close();
|
public static native void close();
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,16 @@ import com.limelight.nvstream.av.audio.AudioRenderer;
|
|||||||
* @author Iwan Timmer
|
* @author Iwan Timmer
|
||||||
*/
|
*/
|
||||||
public class AlsaAudioRenderer implements AudioRenderer {
|
public class AlsaAudioRenderer implements AudioRenderer {
|
||||||
|
|
||||||
|
private String device;
|
||||||
|
|
||||||
|
public AlsaAudioRenderer(String device) {
|
||||||
|
this.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void streamInitialized(int channelCount, int sampleRate) {
|
public void streamInitialized(int channelCount, int sampleRate) {
|
||||||
int ret = AlsaAudio.init(channelCount, sampleRate);
|
int ret = AlsaAudio.init(channelCount, sampleRate, device.getBytes());
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
throw new IllegalStateException("AVC decoder initialization failure: "+ret);
|
throw new IllegalStateException("AVC decoder initialization failure: "+ret);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user