< prev index next >

modules/javafx.media/src/main/native/jfxmedia/jni/JavaInputStreamCallbacks.cpp

Print this page
rev 10028 : 8156563: JavaFX Ensemble8 media sample hang and crash
Reviewed-by: almatvee, kcr
   1 /*
   2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  84         m_IsSeekableMID = env->GetMethodID(klass, "isSeekable", "()Z");
  85         m_IsRandomAccessMID = env->GetMethodID(klass, "isRandomAccess", "()Z");
  86         m_SeekMID = env->GetMethodID(klass, "seek", "(J)J");
  87         m_CloseConnectionMID = env->GetMethodID(klass, "closeConnection", "()V");
  88         m_PropertyMID = env->GetMethodID(klass, "property", "(II)I");
  89         m_GetStreamSizeMID = env->GetMethodID(klass, "getStreamSize", "()I");
  90 
  91         methodIDsInitialized = true;
  92         env->DeleteLocalRef(klass);
  93     }
  94 
  95     javaEnv.reportException();
  96     return true;
  97 }
  98 
  99 bool CJavaInputStreamCallbacks::NeedBuffer()
 100 {
 101     bool     result = false;
 102     CJavaEnvironment javaEnv(m_jvm);
 103     JNIEnv *pEnv = javaEnv.getEnvironment();
 104     if (m_ConnectionHolder && pEnv)
 105     {
 106         result = (pEnv->CallBooleanMethod(m_ConnectionHolder, m_NeedBufferMID) == JNI_TRUE);





 107         javaEnv.reportException();
 108     }
 109 
 110     return result;
 111 }
 112 
 113 int CJavaInputStreamCallbacks::ReadNextBlock()
 114 {
 115     int result = -1;
 116     CJavaEnvironment javaEnv(m_jvm);
 117     JNIEnv *pEnv = javaEnv.getEnvironment();
 118 
 119     if (m_ConnectionHolder && pEnv) {
 120         result = pEnv->CallIntMethod(m_ConnectionHolder, m_ReadNextBlockMID);





 121         if (javaEnv.clearException()) {
 122             result = -2;
 123         }
 124     }
 125 
 126     return result;
 127 }
 128 
 129 int CJavaInputStreamCallbacks::ReadBlock(int64_t position, int size)
 130 {
 131     int result = -1;
 132     CJavaEnvironment javaEnv(m_jvm);
 133     JNIEnv *pEnv = javaEnv.getEnvironment();
 134 
 135     if (m_ConnectionHolder && pEnv)
 136     {
 137         result = pEnv->CallIntMethod(m_ConnectionHolder, m_ReadBlockMID, position, size);




 138         if (javaEnv.clearException()) {
 139             result = -2;
 140         }
 141     }
 142 
 143     return result;
 144 }
 145 
 146 void CJavaInputStreamCallbacks::CopyBlock(void* destination, int size)
 147 {
 148     CJavaEnvironment javaEnv(m_jvm);
 149     JNIEnv *pEnv = javaEnv.getEnvironment();
 150     if (m_ConnectionHolder && pEnv)
 151     {
 152         jobject buffer = pEnv->GetObjectField(m_ConnectionHolder, m_BufferFID);

 153         void *data = pEnv->GetDirectBufferAddress(buffer);
 154 
 155         memcpy(destination, data, size);
 156         pEnv->DeleteLocalRef(buffer);


 157     }
 158  }
 159 
 160 bool CJavaInputStreamCallbacks::IsSeekable()
 161 {
 162     CJavaEnvironment javaEnv(m_jvm);
 163     JNIEnv *pEnv = javaEnv.getEnvironment();
 164     bool result = false;
 165 
 166     if (m_ConnectionHolder && pEnv)
 167     {
 168         result = (pEnv->CallBooleanMethod(m_ConnectionHolder, m_IsSeekableMID) == JNI_TRUE);




 169         javaEnv.reportException();
 170     }
 171 
 172     return result;
 173 }
 174 
 175 bool CJavaInputStreamCallbacks::IsRandomAccess()
 176 {
 177     CJavaEnvironment javaEnv(m_jvm);
 178     JNIEnv *pEnv = javaEnv.getEnvironment();
 179     bool result = false;
 180 
 181     if (m_ConnectionHolder && pEnv)
 182     {
 183         result = (pEnv->CallBooleanMethod(m_ConnectionHolder, m_IsRandomAccessMID) == JNI_TRUE);




 184         javaEnv.reportException();
 185     }
 186 
 187     return result;
 188 }
 189 
 190 int64_t CJavaInputStreamCallbacks::Seek(int64_t position)
 191 {
 192     CJavaEnvironment javaEnv(m_jvm);
 193     JNIEnv *pEnv = javaEnv.getEnvironment();
 194     jlong result = -1;
 195 
 196     if (m_ConnectionHolder && pEnv)
 197     {
 198         result = pEnv->CallLongMethod(m_ConnectionHolder, m_SeekMID, (jlong)position);




 199         javaEnv.reportException();
 200     }
 201 
 202     return (int64_t)result;
 203 }
 204 
 205 void CJavaInputStreamCallbacks::CloseConnection()
 206 {
 207     CJavaEnvironment javaEnv(m_jvm);
 208     JNIEnv *pEnv = javaEnv.getEnvironment();
 209     if (m_ConnectionHolder && pEnv)
 210     {
 211         pEnv->CallVoidMethod(m_ConnectionHolder, m_CloseConnectionMID);




 212         javaEnv.reportException();


 213         pEnv->DeleteGlobalRef(m_ConnectionHolder);
 214         m_ConnectionHolder = NULL;
 215     }
 216 }
 217 
 218 int CJavaInputStreamCallbacks::Property(int prop, int value)
 219 {
 220     CJavaEnvironment javaEnv(m_jvm);
 221     JNIEnv *pEnv = javaEnv.getEnvironment();
 222     int result = 0;
 223 
 224     if (m_ConnectionHolder && pEnv)
 225     {
 226         result = pEnv->CallIntMethod(m_ConnectionHolder, m_PropertyMID, (jint)prop, (jint)value);




 227         javaEnv.reportException();
 228     }
 229 
 230     return result;
 231 }
 232 
 233 int CJavaInputStreamCallbacks::GetStreamSize()
 234 {
 235     CJavaEnvironment javaEnv(m_jvm);
 236     JNIEnv *pEnv = javaEnv.getEnvironment();
 237     int result = 0;
 238 
 239     if (m_ConnectionHolder && pEnv)
 240     {
 241         result = pEnv->CallIntMethod(m_ConnectionHolder, m_GetStreamSizeMID);




 242         javaEnv.reportException();
 243     }
 244 
 245     return result;
 246 }
   1 /*
   2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  84         m_IsSeekableMID = env->GetMethodID(klass, "isSeekable", "()Z");
  85         m_IsRandomAccessMID = env->GetMethodID(klass, "isRandomAccess", "()Z");
  86         m_SeekMID = env->GetMethodID(klass, "seek", "(J)J");
  87         m_CloseConnectionMID = env->GetMethodID(klass, "closeConnection", "()V");
  88         m_PropertyMID = env->GetMethodID(klass, "property", "(II)I");
  89         m_GetStreamSizeMID = env->GetMethodID(klass, "getStreamSize", "()I");
  90 
  91         methodIDsInitialized = true;
  92         env->DeleteLocalRef(klass);
  93     }
  94 
  95     javaEnv.reportException();
  96     return true;
  97 }
  98 
  99 bool CJavaInputStreamCallbacks::NeedBuffer()
 100 {
 101     bool result = false;
 102     CJavaEnvironment javaEnv(m_jvm);
 103     JNIEnv *pEnv = javaEnv.getEnvironment();
 104 
 105     if (pEnv) {
 106         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 107         if (connection) {
 108             result = (pEnv->CallBooleanMethod(connection, m_NeedBufferMID) == JNI_TRUE);
 109             pEnv->DeleteLocalRef(connection);
 110         }
 111 
 112         javaEnv.reportException();
 113     }
 114 
 115     return result;
 116 }
 117 
 118 int CJavaInputStreamCallbacks::ReadNextBlock()
 119 {
 120     int result = -1;
 121     CJavaEnvironment javaEnv(m_jvm);
 122     JNIEnv *pEnv = javaEnv.getEnvironment();
 123 
 124     if (pEnv) {
 125         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 126         if (connection) {
 127             result = pEnv->CallIntMethod(connection, m_ReadNextBlockMID);
 128             pEnv->DeleteLocalRef(connection);
 129         }
 130 
 131         if (javaEnv.clearException()) {
 132             result = -2;
 133         }
 134     }
 135 
 136     return result;
 137 }
 138 
 139 int CJavaInputStreamCallbacks::ReadBlock(int64_t position, int size)
 140 {
 141     int result = -1;
 142     CJavaEnvironment javaEnv(m_jvm);
 143     JNIEnv *pEnv = javaEnv.getEnvironment();
 144 
 145     if (pEnv) {
 146         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 147         if (connection) {
 148             result = pEnv->CallIntMethod(connection, m_ReadBlockMID, position, size);
 149             pEnv->DeleteLocalRef(connection);
 150         }
 151 
 152         if (javaEnv.clearException()) {
 153             result = -2;
 154         }
 155     }
 156 
 157     return result;
 158 }
 159 
 160 void CJavaInputStreamCallbacks::CopyBlock(void* destination, int size)
 161 {
 162     CJavaEnvironment javaEnv(m_jvm);
 163     JNIEnv *pEnv = javaEnv.getEnvironment();
 164     if (pEnv) {
 165         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 166         if (connection) {
 167             jobject buffer = pEnv->GetObjectField(connection, m_BufferFID);
 168             void *data = pEnv->GetDirectBufferAddress(buffer);
 169 
 170             memcpy(destination, data, size);
 171             pEnv->DeleteLocalRef(buffer);
 172             pEnv->DeleteLocalRef(connection);
 173         }
 174     }
 175  }
 176 
 177 bool CJavaInputStreamCallbacks::IsSeekable()
 178 {
 179     CJavaEnvironment javaEnv(m_jvm);
 180     JNIEnv *pEnv = javaEnv.getEnvironment();
 181     bool result = false;
 182 
 183     if (pEnv) {
 184         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 185         if (connection) {
 186             result = (pEnv->CallBooleanMethod(connection, m_IsSeekableMID) == JNI_TRUE);
 187             pEnv->DeleteLocalRef(connection);
 188         }
 189 
 190         javaEnv.reportException();
 191     }
 192 
 193     return result;
 194 }
 195 
 196 bool CJavaInputStreamCallbacks::IsRandomAccess()
 197 {
 198     CJavaEnvironment javaEnv(m_jvm);
 199     JNIEnv *pEnv = javaEnv.getEnvironment();
 200     bool result = false;
 201 
 202     if (pEnv) {
 203         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 204         if (connection) {
 205             result = (pEnv->CallBooleanMethod(connection, m_IsRandomAccessMID) == JNI_TRUE);
 206             pEnv->DeleteLocalRef(connection);
 207         }
 208 
 209         javaEnv.reportException();
 210     }
 211 
 212     return result;
 213 }
 214 
 215 int64_t CJavaInputStreamCallbacks::Seek(int64_t position)
 216 {
 217     CJavaEnvironment javaEnv(m_jvm);
 218     JNIEnv *pEnv = javaEnv.getEnvironment();
 219     jlong result = -1;
 220 
 221     if (pEnv) {
 222         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 223         if (connection) {
 224             result = pEnv->CallLongMethod(connection, m_SeekMID, (jlong)position);
 225             pEnv->DeleteLocalRef(connection);
 226         }
 227 
 228         javaEnv.reportException();
 229     }
 230 
 231     return (int64_t)result;
 232 }
 233 
 234 void CJavaInputStreamCallbacks::CloseConnection()
 235 {
 236     CJavaEnvironment javaEnv(m_jvm);
 237     JNIEnv *pEnv = javaEnv.getEnvironment();
 238 
 239     if (pEnv) {
 240         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 241         if (connection) {
 242             pEnv->CallVoidMethod(connection, m_CloseConnectionMID);
 243             pEnv->DeleteLocalRef(connection);
 244 
 245             javaEnv.reportException();
 246         }
 247 
 248         pEnv->DeleteGlobalRef(m_ConnectionHolder);
 249         m_ConnectionHolder = NULL;
 250     }
 251 }
 252 
 253 int CJavaInputStreamCallbacks::Property(int prop, int value)
 254 {
 255     CJavaEnvironment javaEnv(m_jvm);
 256     JNIEnv *pEnv = javaEnv.getEnvironment();
 257     int result = 0;
 258 
 259     if (pEnv) {
 260         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 261         if (connection) {
 262             result = pEnv->CallIntMethod(connection, m_PropertyMID, (jint)prop, (jint)value);
 263             pEnv->DeleteLocalRef(connection);
 264         }
 265 
 266         javaEnv.reportException();
 267     }
 268 
 269     return result;
 270 }
 271 
 272 int CJavaInputStreamCallbacks::GetStreamSize()
 273 {
 274     CJavaEnvironment javaEnv(m_jvm);
 275     JNIEnv *pEnv = javaEnv.getEnvironment();
 276     int result = 0;
 277 
 278     if (pEnv) {
 279         jobject connection = pEnv->NewLocalRef(m_ConnectionHolder);
 280         if (connection) {
 281             result = pEnv->CallIntMethod(connection, m_GetStreamSizeMID);
 282             pEnv->DeleteLocalRef(connection);
 283         }
 284 
 285         javaEnv.reportException();
 286     }
 287 
 288     return result;
 289 }
< prev index next >