Skip to content

Commit

Permalink
smaller audio buffer will cause faster audio playing but not good
Browse files Browse the repository at this point in the history
  • Loading branch information
havlenapetr committed Jul 16, 2010
1 parent 51ecd6c commit 5cef032
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ static int FFMpegPlayerAndroid_processAudio(JNIEnv *env, AVPacket *packet, int16
samples_size = size;
samples = (int16_t *) av_malloc(samples_size);
}

int len = avcodec_decode_audio3(ffmpeg_audio.codec_ctx, samples, &samples_size, packet);
/*if(*/AndroidAudioTrack_write(samples, samples_size);// <= 0) {
/* jniThrowException(env,
if(AndroidAudioTrack_write(samples, samples_size) <= 0) {
jniThrowException(env,
"java/io/IOException",
"Couldn't write bytes to audio track");
return -1;
}*/
}
AndroidAudioTrack_flush();
return 0;
}

Expand Down Expand Up @@ -284,6 +285,12 @@ static void FFMpegPlayerAndroid_play(JNIEnv *env, jobject obj, jobject bitmap, j
"Couldn't register audio track");
return;
}
if(AndroidAudioTrack_start() != ANDROID_AUDIOTRACK_RESULT_SUCCESS) {
jniThrowException(env,
"java/io/IOException",
"Couldn't start audio track");
return;
}
}

status = STATE_PLAYING;
Expand Down
9 changes: 9 additions & 0 deletions jni/include/android/audiotrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@
#define ANDROID_AUDIOTRACK_RESULT_BAD_PARAMETER -1
#define ANDROID_AUDIOTRACK_RESULT_JNI_EXCEPTION -2
#define ANDROID_AUDIOTRACK_RESULT_ALLOCATION_FAILED -3
#define ANDROID_AUDIOTRACK_RESULT_ERRNO -4

#ifdef __cplusplus
extern "C" {
#endif

int AndroidAudioTrack_register(JNIEnv* env, jobject jaudioTrack);

int AndroidAudioTrack_start();

int AndroidAudioTrack_flush();

int AndroidAudioTrack_stop();

int AndroidAudioTrack_reload();

int AndroidAudioTrack_unregister();

Expand Down
Binary file modified libs/armeabi/libjniaudio.so
Binary file not shown.
21 changes: 2 additions & 19 deletions src/com/media/ffmpeg/android/FFMpegPlayerAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@
import android.widget.MediaController.MediaPlayerControl;

/**
*
* playing audio track in static mode:
*
* Hi,
Peter, Dave, do you have a clear description of what to do ?
I also want to replay a static AudioTrack instance, but i'm facing the
problems described below
http://groups.google.com/group/android-beginners/browse_thread/thread...
So basically what i do is : play() => stop() => reloadStaticData() =>
play() => etc...
It almost works but when i stop doing this, the sound is still
playing, even if i call release on the AudioTrack or set it to null.
I have noticed that this happens when i'm trying to replay an
AudioTrack more frequently than its duration. No way to play a sound
of 500ms every 250ms : all you can expect it to have it replayed every
500ms.
*
*
* @author petr
*
Expand Down Expand Up @@ -162,8 +145,8 @@ private void startVideo() {
mAudioCodecCtx.getSampleRate(),
(mAudioCodecCtx.getChannels() == 2) ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
FFMpegAVCodecTag.AVCODEC_MAX_AUDIO_FRAME_SIZE,
AudioTrack.MODE_STATIC);
mAudioCodecCtx.getFrameSize() * 2,
AudioTrack.MODE_STREAM);
}

attachMediaController();
Expand Down

0 comments on commit 5cef032

Please sign in to comment.