Skip to content

Commit

Permalink
jni: fixed Buffer/ByteBuffer and added ByteBuffer.duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
davilla committed Aug 23, 2013
1 parent b956b35 commit 5757df4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions xbmc/android/jni/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CJNIBuffer : public CJNIBase
CJNIBuffer(const jni::jhobject &object) : CJNIBase(object) {};
~CJNIBuffer() {};

public:
int capacity();
int position();
CJNIBuffer position(int newPosition);
Expand Down
10 changes: 8 additions & 2 deletions xbmc/android/jni/ByteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ CJNIByteBuffer CJNIByteBuffer::wrap(const std::vector<char> &array)
bytearray));
}

CJNIByteBuffer CJNIByteBuffer::duplicate()
{
return CJNIByteBuffer(call_method<jhobject>(m_object,
"duplicate","()Ljava/nio/ByteBuffer;"));
}

CJNIByteBuffer CJNIByteBuffer::get(const std::vector<char> &dst, int dstOffset, int byteCount)
{
JNIEnv *env = xbmc_jnienv();
Expand Down Expand Up @@ -99,7 +105,7 @@ CJNIByteBuffer CJNIByteBuffer::put(const std::vector<char> &src, int srcOffset,
JNIEnv *env = xbmc_jnienv();
jsize size = src.size();
jbyteArray bytearray = env->NewByteArray(size);
env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)&src[0]);
env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)src.data());

return CJNIByteBuffer(call_method<jhobject>(m_object,
"put","([BII)Ljava/nio/ByteBuffer;",
Expand All @@ -111,7 +117,7 @@ CJNIByteBuffer CJNIByteBuffer::put(const std::vector<char> &src)
JNIEnv *env = xbmc_jnienv();
jsize size = src.size();
jbyteArray bytearray = env->NewByteArray(size);
env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)&src[0]);
env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)src.data());

return CJNIByteBuffer(call_method<jhobject>(m_object,
"put","([B)Ljava/nio/ByteBuffer;",
Expand Down
2 changes: 2 additions & 0 deletions xbmc/android/jni/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CJNIByteBuffer : public CJNIBuffer
static CJNIByteBuffer wrap(const std::vector<char> &array, int start, int byteCount);
static CJNIByteBuffer wrap(const std::vector<char> &array);

CJNIByteBuffer duplicate();

CJNIByteBuffer get(const std::vector<char> &dst, int dstOffset, int byteCount);
CJNIByteBuffer get(const std::vector<char> &dst);
CJNIByteBuffer put(const CJNIByteBuffer &src);
Expand Down

0 comments on commit 5757df4

Please sign in to comment.