mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 14:22:00 +00:00
Added javadoc to the audio/video binding classes
This commit is contained in:
@@ -8,11 +8,24 @@ import com.limelight.binding.video.SwingCpuDecoderRenderer;
|
|||||||
import com.limelight.nvstream.av.audio.AudioRenderer;
|
import com.limelight.nvstream.av.audio.AudioRenderer;
|
||||||
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for platform-specific video/audio bindings.
|
||||||
|
* @author Cameron Gutman
|
||||||
|
*/
|
||||||
public class PlatformBinding {
|
public class PlatformBinding {
|
||||||
|
/**
|
||||||
|
* Gets an instance of a video decoder/renderer.
|
||||||
|
* @return a video decoder and renderer
|
||||||
|
*/
|
||||||
public static VideoDecoderRenderer getVideoDecoderRenderer() {
|
public static VideoDecoderRenderer getVideoDecoderRenderer() {
|
||||||
return new SwingCpuDecoderRenderer();
|
return new SwingCpuDecoderRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this device.
|
||||||
|
* <br>Currently, the hostname of the system.
|
||||||
|
* @return the name of this device
|
||||||
|
*/
|
||||||
public static String getDeviceName() {
|
public static String getDeviceName() {
|
||||||
try {
|
try {
|
||||||
return InetAddress.getLocalHost().getHostName();
|
return InetAddress.getLocalHost().getHostName();
|
||||||
@@ -21,6 +34,10 @@ public class PlatformBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an instance of an audio decoder/renderer.
|
||||||
|
* @return an audio decoder and renderer
|
||||||
|
*/
|
||||||
public static AudioRenderer getAudioRenderer() {
|
public static AudioRenderer getAudioRenderer() {
|
||||||
return new JavaxAudioRenderer();
|
return new JavaxAudioRenderer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,20 @@ import javax.sound.sampled.SourceDataLine;
|
|||||||
import com.limelight.nvstream.av.audio.AudioRenderer;
|
import com.limelight.nvstream.av.audio.AudioRenderer;
|
||||||
import com.limelight.nvstream.av.audio.OpusDecoder;
|
import com.limelight.nvstream.av.audio.OpusDecoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audio renderer implementation
|
||||||
|
* @author Cameron Gutman
|
||||||
|
*/
|
||||||
public class JavaxAudioRenderer implements AudioRenderer {
|
public class JavaxAudioRenderer implements AudioRenderer {
|
||||||
|
|
||||||
private SourceDataLine soundLine;
|
private SourceDataLine soundLine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes some audio data and writes it out to the renderer.
|
||||||
|
* @param pcmData the array that contains the audio data
|
||||||
|
* @param offset the offset at which the data starts in the array
|
||||||
|
* @param length the length of data to be rendered
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void playDecodedAudio(short[] pcmData, int offset, int length) {
|
public void playDecodedAudio(short[] pcmData, int offset, int length) {
|
||||||
if (soundLine != null) {
|
if (soundLine != null) {
|
||||||
@@ -29,6 +39,9 @@ public class JavaxAudioRenderer implements AudioRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when the stream session is closing and the audio renderer should stop.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void streamClosing() {
|
public void streamClosing() {
|
||||||
if (soundLine != null) {
|
if (soundLine != null) {
|
||||||
@@ -36,6 +49,11 @@ public class JavaxAudioRenderer implements AudioRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback for the audio stream being initialized and starting to receive.
|
||||||
|
* @param channelCount the number of channels in the audio
|
||||||
|
* @param sampleRate the sample rate for the audio.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void streamInitialized(int channelCount, int sampleRate) {
|
public void streamInitialized(int channelCount, int sampleRate) {
|
||||||
AudioFormat audioFormat = new AudioFormat(sampleRate, 16, channelCount, true, true);
|
AudioFormat audioFormat = new AudioFormat(sampleRate, 16, channelCount, true, true);
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ import com.limelight.nvstream.av.DecodeUnit;
|
|||||||
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
||||||
import com.limelight.nvstream.av.video.cpu.AvcDecoder;
|
import com.limelight.nvstream.av.video.cpu.AvcDecoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of a video decoder and renderer.
|
||||||
|
* @author Cameron Gutman
|
||||||
|
*/
|
||||||
public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
|
public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
|
||||||
|
|
||||||
private Thread rendererThread;
|
private Thread rendererThread;
|
||||||
@@ -28,6 +32,13 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
// Only sleep if the difference is above this value
|
// Only sleep if the difference is above this value
|
||||||
private static final int WAIT_CEILING_MS = 8;
|
private static final int WAIT_CEILING_MS = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the decoder and renderer to render video at the specified dimensions
|
||||||
|
* @param width the width of the video to render
|
||||||
|
* @param height the height of the video to render
|
||||||
|
* @param renderTarget what to render the video onto
|
||||||
|
* @param drFlags flags for the decoder and renderer
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setup(int width, int height, Object renderTarget, int drFlags) {
|
public void setup(int width, int height, Object renderTarget, int drFlags) {
|
||||||
this.targetFps = 30;
|
this.targetFps = 30;
|
||||||
@@ -62,6 +73,9 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
System.out.println("Using software decoding");
|
System.out.println("Using software decoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the decoding and rendering of the video stream on a new thread
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
rendererThread = new Thread() {
|
rendererThread = new Thread() {
|
||||||
@@ -112,10 +126,16 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
rendererThread.start();
|
rendererThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Computes the amount of time to display a certain frame
|
||||||
|
*/
|
||||||
private long computePresentationTimeMs(int frameRate) {
|
private long computePresentationTimeMs(int frameRate) {
|
||||||
return System.currentTimeMillis() + (1000 / frameRate);
|
return System.currentTimeMillis() + (1000 / frameRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the decoding and rendering of the video stream.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
rendererThread.interrupt();
|
rendererThread.interrupt();
|
||||||
@@ -125,11 +145,19 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases resources held by the decoder.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
AvcDecoder.destroy();
|
AvcDecoder.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give a unit to be decoded to the decoder.
|
||||||
|
* @param decodeUnit the unit to be decoded
|
||||||
|
* @return true if the unit was decoded successfully, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean submitDecodeUnit(DecodeUnit decodeUnit) {
|
public boolean submitDecodeUnit(DecodeUnit decodeUnit) {
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
|||||||
Reference in New Issue
Block a user