[vlc-commits] audiotrack: use writeV23 after Android M
Thomas Guillem
git at videolan.org
Fri Oct 7 18:59:39 CEST 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Oct 7 16:44:28 2016 +0200| [a20583b92c6976ab9b7f0c87869e05f0d587cb8d] | committer: Thomas Guillem
audiotrack: use writeV23 after Android M
Non blocking write function using a byte array.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a20583b92c6976ab9b7f0c87869e05f0d587cb8d
---
modules/audio_output/audiotrack.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index 98f8c75..eae1108 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -120,6 +120,7 @@ struct aout_sys_t {
enum {
WRITE_BYTEARRAY,
+ WRITE_BYTEARRAYV23,
WRITE_BYTEBUFFER,
WRITE_FLOATARRAY
} i_write_type;
@@ -192,6 +193,7 @@ static struct
jmethodID flush;
jmethodID pause;
jmethodID write;
+ jmethodID writeV23;
jmethodID writeBufferV21;
jmethodID writeFloat;
jmethodID getPlaybackHeadPosition;
@@ -308,8 +310,11 @@ InitJNIFields( audio_output_t *p_aout, JNIEnv* env )
GET_ID( GetMethodID, AudioTrack.flush, "flush", "()V", true );
GET_ID( GetMethodID, AudioTrack.pause, "pause", "()V", true );
- GET_ID( GetMethodID, AudioTrack.writeBufferV21, "write", "(Ljava/nio/ByteBuffer;II)I", false );
- if( jfields.AudioTrack.writeBufferV21 )
+ GET_ID( GetMethodID, AudioTrack.writeV23, "write", "([BIII)I", false );
+ if( !jfields.AudioTrack.writeV23 )
+ GET_ID( GetMethodID, AudioTrack.writeBufferV21, "write", "(Ljava/nio/ByteBuffer;II)I", false );
+
+ if( jfields.AudioTrack.writeV23 || jfields.AudioTrack.writeBufferV21 )
{
GET_CONST_INT( AudioTrack.WRITE_NON_BLOCKING, "WRITE_NON_BLOCKING", true );
#ifdef AUDIOTRACK_USE_FLOAT
@@ -1076,6 +1081,11 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
msg_Dbg( p_aout, "using WRITE_FLOATARRAY");
p_sys->i_write_type = WRITE_FLOATARRAY;
}
+ else if( jfields.AudioTrack.writeV23 )
+ {
+ msg_Dbg( p_aout, "using WRITE_BYTEARRAYV23");
+ p_sys->i_write_type = WRITE_BYTEARRAYV23;
+ }
else if( jfields.AudioTrack.writeBufferV21 )
{
msg_Dbg( p_aout, "using WRITE_BYTEBUFFER");
@@ -1098,6 +1108,7 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
switch( p_sys->i_write_type )
{
case WRITE_BYTEARRAY:
+ case WRITE_BYTEARRAYV23:
{
jbyteArray p_bytearray;
@@ -1213,6 +1224,7 @@ Stop( audio_output_t *p_aout )
switch( p_sys->i_write_type )
{
case WRITE_BYTEARRAY:
+ case WRITE_BYTEARRAYV23:
if( p_sys->circular.u.p_bytearray )
{
(*env)->DeleteGlobalRef( env, p_sys->circular.u.p_bytearray );
@@ -1280,6 +1292,22 @@ AudioTrack_PlayByteArray( JNIEnv *env, audio_output_t *p_aout,
}
/**
+ * Non blocking write function for Android M and after, run from
+ * AudioTrack_Thread. It calls a new write method with WRITE_NON_BLOCKING
+ * flags.
+ */
+static int
+AudioTrack_PlayByteArrayV23( JNIEnv *env, audio_output_t *p_aout,
+ size_t i_data_size, size_t i_data_offset )
+{
+ aout_sys_t *p_sys = p_aout->sys;
+
+ return JNI_AT_CALL_INT( writeV23, p_sys->circular.u.p_bytearray,
+ i_data_offset, i_data_size,
+ jfields.AudioTrack.WRITE_NON_BLOCKING );
+}
+
+/**
* Non blocking play function for Lollipop and after, run from
* AudioTrack_Thread. It calls a new write method with WRITE_NON_BLOCKING
* flags.
@@ -1346,6 +1374,10 @@ AudioTrack_Play( JNIEnv *env, audio_output_t *p_aout, size_t i_data_size,
switch( p_sys->i_write_type )
{
+ case WRITE_BYTEARRAYV23:
+ i_ret = AudioTrack_PlayByteArrayV23( env, p_aout, i_data_size,
+ i_data_offset );
+ break;
case WRITE_BYTEBUFFER:
i_ret = AudioTrack_PlayByteBuffer( env, p_aout, i_data_size,
i_data_offset );
@@ -1533,6 +1565,7 @@ Play( audio_output_t *p_aout, block_t *p_buffer )
switch( p_sys->i_write_type )
{
case WRITE_BYTEARRAY:
+ case WRITE_BYTEARRAYV23:
(*env)->SetByteArrayRegion( env, p_sys->circular.u.p_bytearray,
i_data_offset, i_data_size,
(jbyte *)p_buffer->p_buffer
More information about the vlc-commits
mailing list