diff options
author | Xerxes Rånby <[email protected]> | 2013-05-10 12:42:09 +0200 |
---|---|---|
committer | Xerxes Rånby <[email protected]> | 2013-05-10 12:42:09 +0200 |
commit | cc30fa7de95cffa961e9fd3aead2dd8f3bb55aeb (patch) | |
tree | f227ee582c659835f3760c970f04903b46dfa0ac /src/jogl | |
parent | c6081b03d1f47219aa789debf25aee55993e6dcb (diff) |
FFMPEGMediaPlayer: blocking Java Sound output
Diffstat (limited to 'src/jogl')
-rw-r--r-- | src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java | 33 | ||||
-rw-r--r-- | src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c | 10 |
2 files changed, 23 insertions, 20 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java index 55bb4799b..cf26bbd81 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java @@ -124,16 +124,16 @@ public class FFMPEGMediaPlayer extends EGLMediaPlayerImpl { public static final double BUFFER_TIME_IN_SECS = SAMPLE_TIME_IN_SECS * SAMPLES_PER_BUFFER; // Instance data - private AudioFormat format; - private DataLine.Info info; - private SourceDataLine auline; - private int bufferCount; - private byte [] sampleData = new byte[BUFFER_SIZE]; + private static AudioFormat format; + private static DataLine.Info info; + private static SourceDataLine auline; + private static int bufferCount; + private static byte [] sampleData = new byte[BUFFER_SIZE]; public static final VersionNumber avUtilVersion; public static final VersionNumber avFormatVersion; public static final VersionNumber avCodecVersion; - static final boolean available; + static boolean available; static { if(FFMPEGDynamicLibraryBundleInfo.initSingleton()) { @@ -143,9 +143,7 @@ public class FFMPEGMediaPlayer extends EGLMediaPlayerImpl { System.err.println("LIB_AV Util : "+avUtilVersion); System.err.println("LIB_AV Format: "+avFormatVersion); System.err.println("LIB_AV Codec : "+avCodecVersion); - available = initIDs0(); - - if(available) { + if(initIDs0()) { // init audio // Create the audio format we wish to use format = new AudioFormat(SAMPLE_RATE, SAMPLE_SIZE, CHANNELS, SIGNED, BIG_ENDIAN); @@ -155,12 +153,15 @@ public class FFMPEGMediaPlayer extends EGLMediaPlayerImpl { // Clear buffer initially Arrays.fill(sampleData, (byte) 0); - - // Get line to write data to - auline = (SourceDataLine) AudioSystem.getLine(info); - auline.open(format); - auline.start(); - + try{ + // Get line to write data to + auline = (SourceDataLine) AudioSystem.getLine(info); + auline.open(format); + auline.start(); + available = true; + } catch (LineUnavailableException e){ + available = false; + } } } else { @@ -261,7 +262,7 @@ public class FFMPEGMediaPlayer extends EGLMediaPlayerImpl { throw new InternalError("Unknown ProcAddressTable: "+pt.getClass().getName()+" of "+ctx.getClass().getName()); } } - private void updateSound() { + private void updateSound(byte[] sampleData, int data_size) { System.out.println("jA"); if (data_size > 0) { auline.write(sampleData, 0, data_size); diff --git a/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c b/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c index 8e5f4124c..b8ff9a6ca 100644 --- a/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c +++ b/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c @@ -192,10 +192,12 @@ JNIEXPORT jboolean JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGDynamicLibraryB return JNI_TRUE; } -static void _updateSound(JNIEnv *env, jobject instance, char *data, int32_t data_size, int32_t sample_rate) { +static void _updateSound(JNIEnv *env, jobject instance, char *data, int32_t data_size) { if(NULL!=env) { fprintf(stderr, "nA"); - (*env)->CallVoidMethod(env, instance, jni_mid_updateSound); + jbyteArray jbArray = (*env)->NewByteArray(env, data_size); + (*env)->SetByteArrayRegion(env, jbArray, 0, data_size, (jbyte*)data); + (*env)->CallVoidMethod(env, instance, jni_mid_updateSound, jbArray, data_size); } } @@ -342,7 +344,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_ini JoglCommon_FatalError(env, "JOGL FFMPEG: can't use %s", ClazzNameFFMPEGMediaPlayer); } - jni_mid_updateSound = (*env)->GetMethodID(env, ffmpegMediaPlayerClazz, "updateSound", "()V"); + jni_mid_updateSound = (*env)->GetMethodID(env, ffmpegMediaPlayerClazz, "updateSound", "([BI)V"); jni_mid_updateAttributes1 = (*env)->GetMethodID(env, ffmpegMediaPlayerClazz, "updateAttributes", "(IIIIIFIILjava/lang/String;Ljava/lang/String;)V"); jni_mid_updateAttributes2 = (*env)->GetMethodID(env, ffmpegMediaPlayerClazz, "updateAttributes2", "(IIIIIIIIII)V"); @@ -654,7 +656,7 @@ JNIEXPORT jint JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_readNex // TODO: Wrap audio buffer data in a com.jogamp.openal.sound3d.Buffer or similar // and hand it over to the user using a suitable API. // TODO: OR send the audio buffer data down to sound card directly using JOAL. - _updateSound(env, instance, pAV->pAFrame->data[0], data_size, pAV->aSampleRate); + _updateSound(env, instance, pAV->pAFrame->data[0], data_size); res = 1; } |