Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

jni: fixed Buffer/ByteBuffer and added ByteBuffer.duplicate

  • Loading branch information...
commit 5757df4326b5912a264601933a3ba9d036497e8b 1 parent b956b35
davilla davilla authored
1  xbmc/android/jni/Buffer.h
View
@@ -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);
10 xbmc/android/jni/ByteBuffer.cpp
View
@@ -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();
@@ -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;",
@@ -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;",
2  xbmc/android/jni/ByteBuffer.h
View
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.