Added javadoc to the audio/video binding classes

This commit is contained in:
Diego Waxemberg
2013-12-29 11:53:16 -05:00
parent 1501d45534
commit 9bf6e95e0b
3 changed files with 63 additions and 0 deletions

View File

@@ -8,11 +8,24 @@ import com.limelight.binding.video.SwingCpuDecoderRenderer;
import com.limelight.nvstream.av.audio.AudioRenderer;
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
/**
* Used for platform-specific video/audio bindings.
* @author Cameron Gutman
*/
public class PlatformBinding {
/**
* Gets an instance of a video decoder/renderer.
* @return a video decoder and renderer
*/
public static VideoDecoderRenderer getVideoDecoderRenderer() {
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() {
try {
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() {
return new JavaxAudioRenderer();
}

View File

@@ -11,10 +11,20 @@ import javax.sound.sampled.SourceDataLine;
import com.limelight.nvstream.av.audio.AudioRenderer;
import com.limelight.nvstream.av.audio.OpusDecoder;
/**
* Audio renderer implementation
* @author Cameron Gutman
*/
public class JavaxAudioRenderer implements AudioRenderer {
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
public void playDecodedAudio(short[] pcmData, int offset, int length) {
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
public void streamClosing() {
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
public void streamInitialized(int channelCount, int sampleRate) {
AudioFormat audioFormat = new AudioFormat(sampleRate, 16, channelCount, true, true);

View File

@@ -12,6 +12,10 @@ import com.limelight.nvstream.av.DecodeUnit;
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
import com.limelight.nvstream.av.video.cpu.AvcDecoder;
/**
* Implementation of a video decoder and renderer.
* @author Cameron Gutman
*/
public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
private Thread rendererThread;
@@ -28,6 +32,13 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
// Only sleep if the difference is above this value
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
public void setup(int width, int height, Object renderTarget, int drFlags) {
this.targetFps = 30;
@@ -62,6 +73,9 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
System.out.println("Using software decoding");
}
/**
* Starts the decoding and rendering of the video stream on a new thread
*/
@Override
public void start() {
rendererThread = new Thread() {
@@ -112,10 +126,16 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
rendererThread.start();
}
/*
* Computes the amount of time to display a certain frame
*/
private long computePresentationTimeMs(int frameRate) {
return System.currentTimeMillis() + (1000 / frameRate);
}
/**
* Stops the decoding and rendering of the video stream.
*/
@Override
public void stop() {
rendererThread.interrupt();
@@ -125,11 +145,19 @@ public class SwingCpuDecoderRenderer implements VideoDecoderRenderer {
} catch (InterruptedException e) { }
}
/**
* Releases resources held by the decoder.
*/
@Override
public void release() {
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
public boolean submitDecodeUnit(DecodeUnit decodeUnit) {
byte[] data;