aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-08-14 06:43:42 +0200
committerSven Gothel <[email protected]>2013-08-14 06:43:42 +0200
commitbc3776633ccad81199a96ff8116195133d862395 (patch)
treec5edc7fc7eb8d5ffb3def1efffea44af96f8515a /src/jogl/classes/jogamp/opengl/util
parentf53b7713e5eb58a86faf0db06db8be35cfa413d9 (diff)
GLMediaPlayer Multithreaded Decoding: AudioSink (Part-2) - WIP
- AudioSink.AudioDataFormat - add fixedP (fixed-point or floating-point) - AudioSink - rename 'buffer count' to 'frame count' - add setPlaySpeed(..) - add isPlaying() - add play() - add pause() - add flush() - add: getFrameCount(), getQueuedFrameCount(), getFreeFrameCount(), getEnqueuedFrameCount(), - rename: writeData() -> enqueueData(..) - ALAudioSink - multithreaded usage - make ALCcontext current per thread, now required for multithreaded use Use RecursiveLock encapsulating the ALCcontext's makeCurrent/release/destroy, since the native operations seem to be buggy. NOTE: Think about adding these general methods to ALCcontext - implement new methods -
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util')
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java88
-rw-r--r--src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java67
2 files changed, 132 insertions, 23 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java b/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java
index a5fedce59..e96bb6a50 100644
--- a/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java
+++ b/src/jogl/classes/jogamp/opengl/util/av/JavaSoundAudioSink.java
@@ -34,6 +34,8 @@ public class JavaSoundAudioSink implements AudioSink {
private boolean initialized = false;
private AudioDataFormat chosenFormat = null;
+ private volatile boolean playRequested = false;
+
static {
boolean ok = false;
try {
@@ -52,12 +54,20 @@ public class JavaSoundAudioSink implements AudioSink {
}
@Override
+ public final float getPlaySpeed() { return 1.0f; } // FIXME
+
+ @Override
+ public final boolean setPlaySpeed(float rate) {
+ return false; // FIXME
+ }
+
+ @Override
public AudioDataFormat getPreferredFormat() {
return DefaultFormat;
}
@Override
- public AudioDataFormat initSink(AudioDataFormat requestedFormat, int bufferCount) {
+ public AudioDataFormat initSink(AudioDataFormat requestedFormat, int frameCount) {
if( !staticAvailable ) {
return null;
}
@@ -84,6 +94,56 @@ public class JavaSoundAudioSink implements AudioSink {
}
@Override
+ public boolean isPlaying() {
+ return playRequested && auline.isRunning();
+ }
+
+ @Override
+ public void play() {
+ if( null != auline ) {
+ playRequested = true;
+ playImpl();
+ }
+ }
+ private void playImpl() {
+ if( playRequested && !auline.isRunning() ) {
+ auline.start();
+ }
+ }
+
+ @Override
+ public void pause() {
+ if( null != auline ) {
+ playRequested = false;
+ auline.stop();
+ }
+ }
+
+ @Override
+ public void flush() {
+ if( null != auline ) {
+ playRequested = false;
+ auline.stop();
+ auline.flush();
+ }
+ }
+
+ @Override
+ public final int getEnqueuedFrameCount() {
+ return 0; // FIXME
+ }
+
+ @Override
+ public int getFrameCount() {
+ return 1;
+ }
+
+ @Override
+ public int getQueuedFrameCount() {
+ return 0;
+ }
+
+ @Override
public boolean isInitialized() {
return initialized;
}
@@ -95,7 +155,7 @@ public class JavaSoundAudioSink implements AudioSink {
// FIXEM: complete code!
}
- public void writeData(AudioFrame audioFrame) {
+ public void enqueueData(AudioFrame audioFrame) {
int data_size = audioFrame.dataSize;
final byte[] lala = new byte[data_size];
final int p = audioFrame.data.position();
@@ -109,27 +169,29 @@ public class JavaSoundAudioSink implements AudioSink {
len = auline.write(lala, written, data_size);
data_size -= len;
written += len;
- }
+ }
+ playImpl();
}
-
+
@Override
public int getQueuedByteCount() {
- return auline.available();
+ return auline.getBufferSize() - auline.available();
}
@Override
- public int getQueuedTime() {
- return 0; // FIXME
+ public int getFreeFrameCount() {
+ return auline.available();
}
-
@Override
- public int getWritableBufferCount() {
- return 1;
+ public int getQueuedTime() {
+ return getQueuedTimeImpl( getQueuedByteCount() );
}
-
- public boolean isDataAvailable(int data_size) {
- return auline.available()>=data_size;
+ private final int getQueuedTimeImpl(int byteCount) {
+ final int bytesPerSample = chosenFormat.sampleSize >>> 3; // /8
+ return byteCount / ( chosenFormat.channelCount * bytesPerSample * ( chosenFormat.sampleRate / 1000 ) );
}
+ @Override
+ public final int getPTS() { return 0; } // FIXME
}
diff --git a/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java b/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java
index cef1c3361..c7fecae0b 100644
--- a/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java
+++ b/src/jogl/classes/jogamp/opengl/util/av/NullAudioSink.java
@@ -10,41 +10,88 @@ public class NullAudioSink implements AudioSink {
return true;
}
+ private volatile float playSpeed = 1.0f;
+ private volatile boolean playRequested = false;
+
+ @Override
+ public final float getPlaySpeed() { return playSpeed; }
+
+ @Override
+ public final boolean setPlaySpeed(float rate) {
+ if( Math.abs(1.0f - rate) < 0.01f ) {
+ rate = 1.0f;
+ }
+ playSpeed = rate;
+ return true;
+ }
+
@Override
public AudioDataFormat getPreferredFormat() {
return DefaultFormat;
}
@Override
- public AudioDataFormat initSink(AudioDataFormat requestedFormat, int bufferCount) {
+ public AudioDataFormat initSink(AudioDataFormat requestedFormat, int frameCount) {
return requestedFormat;
}
@Override
+ public boolean isPlaying() {
+ return playRequested;
+ }
+
+ @Override
+ public void play() {
+ playRequested = true;
+ }
+
+ @Override
+ public void pause() {
+ playRequested = false;
+ }
+
+ @Override
+ public void flush() {
+ }
+
+ @Override
public void destroy() {
}
@Override
- public int getQueuedByteCount() {
+ public final int getEnqueuedFrameCount() {
return 0;
}
@Override
- public int getQueuedTime() {
+ public int getFrameCount() {
return 0;
}
-
+
@Override
- public int getWritableBufferCount() {
- return 1;
+ public int getQueuedFrameCount() {
+ return 0;
}
@Override
- public boolean isDataAvailable(int data_size) {
- return false;
+ public int getQueuedByteCount() {
+ return 0;
}
-
+
@Override
- public void writeData(AudioFrame audioFrame) {
+ public int getQueuedTime() {
+ return 0;
}
+
+ @Override
+ public final int getPTS() { return 0; }
+
+ @Override
+ public int getFreeFrameCount() {
+ return 1;
+ }
+
+ @Override
+ public void enqueueData(AudioFrame audioFrame) {
+ }
}