Commit 0c74d42b authored by Sébastien Toque's avatar Sébastien Toque
Browse files

fix audio playback

parent 963904d9
......@@ -14,10 +14,10 @@
/** Unique Java VM instance, as defined in libvlcjni.c */
extern JavaVM *myVm;
void aout_open (void **opaque, unsigned int *rate, unsigned int *nb_channels,
unsigned int *fourCCFormat, unsigned int *nb_samples)
//void aout_open (void **opaque, unsigned int *rate, unsigned int *nb_channels, unsigned int *fourCCFormat, unsigned int *nb_samples)
int aout_open(void **opaque, char *format, unsigned *rate, unsigned *nb_channels)
{
LOGV("Opening the JNI audio output");
LOGI("Opening the JNI audio output");
aout_sys_t *p_sys;
JNIEnv *p_env;
......@@ -33,9 +33,9 @@ void aout_open (void **opaque, unsigned int *rate, unsigned int *nb_channels,
p_sys->j_libVlc = (jobject) *opaque;
*opaque = (void*) p_sys;
LOGV ("Parameters: %u channels, %u samples/frame, FOURCC '%4.4s', "
LOGI ("Parameters: %u channels, FOURCC '%4.4s', "
"sample rate: %uHz",
*nb_channels, *nb_samples, (const char *) fourCCFormat, *rate);
*nb_channels, format, *rate);
// Attach the thread to the VM. Keep this JNIEnv for aout_close()
if ((*myVm)->AttachCurrentThread (myVm, &p_env, NULL) != 0)
......@@ -58,13 +58,11 @@ void aout_open (void **opaque, unsigned int *rate, unsigned int *nb_channels,
return;
}
LOGV ("Fixed number of channels to 2, number of samples to %d",
FRAME_SIZE);
LOGV ("Fixed number of channels to 2, number of samples to %d", FRAME_SIZE);
*nb_channels = 2;
*nb_samples = FRAME_SIZE;
(*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, methodIdInitAout,
*rate, *nb_channels, *nb_samples);
*rate, *nb_channels, FRAME_SIZE);
if ((*p_env)->ExceptionCheck (p_env))
{
LOGE ("Unable to create audio player!");
......@@ -80,7 +78,7 @@ void aout_open (void **opaque, unsigned int *rate, unsigned int *nb_channels,
/* Create a new byte array to store the audio data. */
jbyteArray byteArray = (*p_env)->NewByteArray (p_env,
*nb_channels *
*nb_samples *
FRAME_SIZE *
sizeof (uint16_t) /* =2 */);
if (byteArray == NULL)
{
......@@ -109,13 +107,14 @@ void aout_open (void **opaque, unsigned int *rate, unsigned int *nb_channels,
// Get the play methodId
p_sys->play = (*p_env)->GetMethodID (p_env, cls, "playAudio", "([BII)V");
assert (p_sys->play != NULL);
return 0;
}
/**
* Play an audio sample
**/
void aout_play (void *opaque, unsigned char *buffer,
size_t bufferSize, unsigned int nb_samples)
//void aout_play (void *opaque, unsigned char *buffer, size_t bufferSize, unsigned int nb_samples)
void aout_play(void *opaque, const void *samples, unsigned count, int64_t pts)
{
aout_sys_t *p_sys = (aout_sys_t*) opaque;
JNIEnv *p_env;
......@@ -127,7 +126,7 @@ void aout_play (void *opaque, unsigned char *buffer,
(*myVm)->AttachCurrentThread (myVm, &p_env, NULL);
(*p_env)->SetByteArrayRegion (p_env, p_sys->byteArray, 0,
bufferSize, (jbyte*) buffer);
2 /*nb_channels*/ * count * sizeof (uint16_t), (jbyte*) samples);
if ((*p_env)->ExceptionCheck (p_env))
{
// This can happen if for some reason the size of the input buffer
......@@ -139,7 +138,7 @@ void aout_play (void *opaque, unsigned char *buffer,
}
(*p_env)->CallVoidMethod (p_env, p_sys->j_libVlc, p_sys->play,
p_sys->byteArray, bufferSize, nb_samples);
p_sys->byteArray, 2 /*nb_channels*/ * count * sizeof (uint16_t), FRAME_SIZE);
// FIXME: check for errors
(*myVm)->DetachCurrentThread (myVm);
......@@ -161,4 +160,3 @@ void aout_close(void *opaque)
(*myVm)->DetachCurrentThread (myVm);
free (p_sys);
}
......@@ -13,9 +13,8 @@ typedef struct
/// play thread! See comments in aout_play()
} aout_sys_t;
void aout_open(void **opaque, unsigned int *rate, unsigned int *nb_channels, unsigned int *fourCCFormat, unsigned int *nb_samples);
void aout_play(void *opaque, unsigned char *buffer, size_t bufferSize, unsigned int nb_samples);
int aout_open(void **opaque, char *format, unsigned *rate, unsigned *nb_channels);
void aout_play(void *opaque, const void *samples, unsigned count, int64_t pts);
void aout_close(void *opaque);
#endif // LIBVLCJNI_VOUT_H
......@@ -338,8 +338,9 @@ void Java_org_videolan_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz,
if ( currentSdk( env, thiz ) < 9 ) //On newer version, we can use SLES
{
//libvlc_audio_set_callbacks(mp, aout_open, aout_play, NULL, NULL, NULL,
// (void*) myJavaLibVLC);
libvlc_audio_set_callbacks(mp, aout_play, NULL, NULL, NULL, NULL,
(void*) myJavaLibVLC);
libvlc_audio_set_format_callbacks(mp, aout_open, aout_close);
}
/* No need to keep the media now */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment