Skip to content
This repository
Browse code

jni: fixed Buffer/ByteBuffer and added ByteBuffer.duplicate

  • Loading branch information...
commit 5757df4326b5912a264601933a3ba9d036497e8b 1 parent b956b35
authored August 20, 2013
1  xbmc/android/jni/Buffer.h
@@ -27,6 +27,7 @@ class CJNIBuffer : public CJNIBase
27 27
   CJNIBuffer(const jni::jhobject &object) : CJNIBase(object) {};
28 28
   ~CJNIBuffer() {};
29 29
 
  30
+public:
30 31
   int           capacity();
31 32
   int           position();
32 33
   CJNIBuffer    position(int newPosition);
10  xbmc/android/jni/ByteBuffer.cpp
@@ -63,6 +63,12 @@ CJNIByteBuffer CJNIByteBuffer::wrap(const std::vector<char> &array)
63 63
     bytearray));
64 64
 }
65 65
 
  66
+CJNIByteBuffer CJNIByteBuffer::duplicate()
  67
+{
  68
+  return CJNIByteBuffer(call_method<jhobject>(m_object,
  69
+    "duplicate","()Ljava/nio/ByteBuffer;"));
  70
+}
  71
+
66 72
 CJNIByteBuffer CJNIByteBuffer::get(const std::vector<char> &dst, int dstOffset, int byteCount)
67 73
 {
68 74
   JNIEnv *env = xbmc_jnienv();
@@ -99,7 +105,7 @@ CJNIByteBuffer CJNIByteBuffer::put(const std::vector<char> &src, int srcOffset,
99 105
   JNIEnv *env = xbmc_jnienv();
100 106
   jsize size  = src.size();
101 107
   jbyteArray bytearray = env->NewByteArray(size);
102  
-  env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)&src[0]);
  108
+  env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)src.data());
103 109
 
104 110
   return CJNIByteBuffer(call_method<jhobject>(m_object,
105 111
     "put","([BII)Ljava/nio/ByteBuffer;",
@@ -111,7 +117,7 @@ CJNIByteBuffer CJNIByteBuffer::put(const std::vector<char> &src)
111 117
   JNIEnv *env = xbmc_jnienv();
112 118
   jsize size  = src.size();
113 119
   jbyteArray bytearray = env->NewByteArray(size);
114  
-  env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)&src[0]);
  120
+  env->SetByteArrayRegion(bytearray, 0, size, (jbyte*)src.data());
115 121
 
116 122
   return CJNIByteBuffer(call_method<jhobject>(m_object,
117 123
     "put","([B)Ljava/nio/ByteBuffer;",
2  xbmc/android/jni/ByteBuffer.h
@@ -32,6 +32,8 @@ class CJNIByteBuffer : public CJNIBuffer
32 32
   static CJNIByteBuffer wrap(const std::vector<char> &array, int start, int byteCount);
33 33
   static CJNIByteBuffer wrap(const std::vector<char> &array);
34 34
 
  35
+  CJNIByteBuffer    duplicate();
  36
+
35 37
   CJNIByteBuffer    get(const std::vector<char> &dst, int dstOffset, int byteCount);
36 38
   CJNIByteBuffer    get(const std::vector<char> &dst);
37 39
   CJNIByteBuffer    put(const CJNIByteBuffer &src);

0 notes on commit 5757df4

Please sign in to comment.
Something went wrong with that request. Please try again.