diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-19 10:57:31 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-19 10:57:31 -0800 |
commit | 3001a035439d8134a7d70d796376d1dfbff3cdcd (patch) | |
tree | 343ccdba15a594ff6e50c874a145232753315a30 /core/jni | |
parent | da996f390e17e16f2dfa60e972e7ebc4f868f37e (diff) | |
download | frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.zip frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.gz frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.bz2 |
auto import from //branches/cupcake/...@132276
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_hardware_Camera.cpp | 21 | ||||
-rw-r--r-- | core/jni/android_media_AudioTrack.cpp | 59 | ||||
-rw-r--r-- | core/jni/android_media_JetPlayer.cpp | 2 | ||||
-rw-r--r-- | core/jni/android_os_Debug.cpp | 15 | ||||
-rw-r--r-- | core/jni/android_server_BluetoothDeviceService.cpp | 33 | ||||
-rw-r--r-- | core/jni/android_server_BluetoothEventLoop.cpp | 7 | ||||
-rw-r--r-- | core/jni/android_view_Surface.cpp | 12 |
7 files changed, 105 insertions, 44 deletions
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index 79965b9..2f1f9b8 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -51,9 +51,9 @@ struct fields_t { static fields_t fields; static Mutex sLock; +static jclass sCameraClass; struct callback_cookie { - jclass camera_class; jobject camera_ref; }; @@ -87,7 +87,7 @@ static void err_callback(status_t err, void *cookie) } LOGV("err_callback: camera_ref=%x, cookie=%x", (int)c->camera_ref, (int)cookie); - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kErrorCallback, error, 0, NULL); } @@ -115,7 +115,6 @@ static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, jobj jniThrowException(env, "java/lang/Exception", NULL); return; } - cookie->camera_class = (jclass)env->NewGlobalRef(clazz); // We use a weak reference so the Camera object can be garbage collected. // The reference is only used as a proxy for callbacks. @@ -157,7 +156,6 @@ static void android_hardware_Camera_release(JNIEnv *env, jobject thiz) if (cookie) { env->DeleteGlobalRef(cookie->camera_ref); - env->DeleteGlobalRef(cookie->camera_class); delete cookie; env->SetIntField(thiz, fields.listener_context, 0); } @@ -207,7 +205,7 @@ static void preview_callback(const sp<IMemory>& mem, void *cookie) obj = array; - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kPreviewCallback, arg1, arg2, obj); env->DeleteLocalRef(array); } @@ -270,13 +268,11 @@ static void autofocus_callback_impl(bool success, void *cookie) return; } callback_cookie *c = (callback_cookie *)cookie; - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kAutoFocusCallback, success, 0, NULL); } - - static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz) { sp<Camera> c = get_native_camera(env, thiz); @@ -301,7 +297,7 @@ static void jpeg_callback(const sp<IMemory>& mem, void *cookie) jobject obj = NULL; if (mem == NULL) { - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kJpegCallback, arg1, arg2, NULL); return; } @@ -331,7 +327,7 @@ static void jpeg_callback(const sp<IMemory>& mem, void *cookie) obj = array; - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kJpegCallback, arg1, arg2, obj); env->DeleteLocalRef(array); } @@ -344,7 +340,7 @@ static void shutter_callback_impl(void *cookie) return; } callback_cookie *c = (callback_cookie *)cookie; - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kShutterCallback, 0, 0, NULL); } @@ -357,7 +353,7 @@ static void raw_callback(const sp<IMemory>& mem __attribute__((unused)), return; } callback_cookie *c = (callback_cookie *)cookie; - env->CallStaticVoidMethod(c->camera_class, fields.post_event, + env->CallStaticVoidMethod(sCameraClass, fields.post_event, c->camera_ref, kRawCallback, 0, 0, NULL); } @@ -524,6 +520,7 @@ int register_android_hardware_Camera(JNIEnv *env) return -1; jclass clazz = env->FindClass("android/hardware/Camera"); + sCameraClass = (jclass)env->NewGlobalRef(clazz); fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", "(Ljava/lang/Object;IIILjava/lang/Object;)V"); if (fields.post_event == NULL) { diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index 6ca821d..d9effee 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "AudioTrack-JNI" @@ -164,8 +164,8 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th jint streamType, jint sampleRateInHertz, jint nbChannels, jint audioFormat, jint buffSizeInBytes, jint memoryMode) { - //LOGV("sampleRate=%d, audioFormat(from Java)=%d, nbChannels=%d, buffSize=%d", - // sampleRateInHertz, audioFormat, nbChannels, buffSizeInBytes); + LOGV("sampleRate=%d, audioFormat(from Java)=%d, nbChannels=%d, buffSize=%d", + sampleRateInHertz, audioFormat, nbChannels, buffSizeInBytes); int afSampleRate; int afFrameCount; @@ -210,7 +210,20 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th LOGE("Error creating AudioTrack: unsupported audio format."); return AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT; } - + + // for the moment 8bitPCM in MODE_STATIC is not supported natively in the AudioTrack C++ class + // so we declare everything as 16bitPCM, the 8->16bit conversion for MODE_STATIC will be handled + // in android_media_AudioTrack_native_write() + if ((audioFormat == javaAudioTrackFields.PCM8) + && (memoryMode == javaAudioTrackFields.MODE_STATIC)) { + LOGV("android_media_AudioTrack_native_setup(): requesting MODE_STATIC for 8bit \ + buff size of %dbytes, switching to 16bit, buff size of %dbytes", + buffSizeInBytes, 2*buffSizeInBytes); + audioFormat = javaAudioTrackFields.PCM16; + // we will need twice the memory to store the data + buffSizeInBytes *= 2; + } + // compute the frame count int bytesPerSample = audioFormat == javaAudioTrackFields.PCM16 ? 2 : 1; int format = audioFormat == javaAudioTrackFields.PCM16 ? @@ -387,13 +400,13 @@ android_media_AudioTrack_set_volume(JNIEnv *env, jobject thiz, jfloat leftVol, j // ---------------------------------------------------------------------------- static void android_media_AudioTrack_native_finalize(JNIEnv *env, jobject thiz) { - LOGV("android_media_AudioTrack_native_finalize jobject: %x\n", (int)thiz); + //LOGV("android_media_AudioTrack_native_finalize jobject: %x\n", (int)thiz); // delete the AudioTrack object AudioTrack *lpTrack = (AudioTrack *)env->GetIntField( thiz, javaAudioTrackFields.nativeTrackInJavaObj); if (lpTrack) { - LOGV("deleting lpTrack: %x\n", (int)lpTrack); + //LOGV("deleting lpTrack: %x\n", (int)lpTrack); lpTrack->stop(); delete lpTrack; } @@ -402,7 +415,7 @@ static void android_media_AudioTrack_native_finalize(JNIEnv *env, jobject thiz) AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetIntField( thiz, javaAudioTrackFields.jniData); if (pJniStorage) { - LOGV("deleting pJniStorage: %x\n", (int)pJniStorage); + //LOGV("deleting pJniStorage: %x\n", (int)pJniStorage); delete pJniStorage; } } @@ -422,7 +435,8 @@ static void android_media_AudioTrack_native_release(JNIEnv *env, jobject thiz) // ---------------------------------------------------------------------------- static jint android_media_AudioTrack_native_write(JNIEnv *env, jobject thiz, jbyteArray javaAudioData, - jint offsetInBytes, jint sizeInBytes) { + jint offsetInBytes, jint sizeInBytes, + jint javaAudioFormat) { jbyte* cAudioData = NULL; AudioTrack *lpTrack = NULL; //LOGV("android_media_AudioTrack_native_write(offset=%d, sizeInBytes=%d) called", @@ -453,8 +467,22 @@ static jint android_media_AudioTrack_native_write(JNIEnv *env, jobject thiz, if (lpTrack->sharedBuffer() == 0) { written = lpTrack->write(cAudioData + offsetInBytes, sizeInBytes); } else { - memcpy(lpTrack->sharedBuffer()->pointer(), cAudioData + offsetInBytes, sizeInBytes); - written = sizeInBytes; + if (javaAudioFormat == javaAudioTrackFields.PCM16) { + memcpy(lpTrack->sharedBuffer()->pointer(), cAudioData + offsetInBytes, sizeInBytes); + written = sizeInBytes; + } else if (javaAudioFormat == javaAudioTrackFields.PCM8) { + // cAudioData contains 8bit data we need to expand to 16bit before copying + // to the shared memory + int count = sizeInBytes; + int16_t *dst = (int16_t *)lpTrack->sharedBuffer()->pointer(); + const int8_t *src = (const int8_t *)(cAudioData + offsetInBytes); + while(count--) { + *dst++ = (int16_t)(*src++^0x80) << 8; + } + // even though we wrote 2*sizeInBytes, we only report sizeInBytes as written to hide + // the 8bit mixer restriction from the user of this function + written = sizeInBytes; + } } env->ReleasePrimitiveArrayCritical(javaAudioData, cAudioData, 0); @@ -468,10 +496,12 @@ static jint android_media_AudioTrack_native_write(JNIEnv *env, jobject thiz, // ---------------------------------------------------------------------------- static jint android_media_AudioTrack_native_write_short(JNIEnv *env, jobject thiz, jshortArray javaAudioData, - jint offsetInShorts, jint sizeInShorts) { + jint offsetInShorts, jint sizeInShorts, + jint javaAudioFormat) { return (android_media_AudioTrack_native_write(env, thiz, (jbyteArray) javaAudioData, - offsetInShorts*2, sizeInShorts*2) + offsetInShorts*2, sizeInShorts*2, + javaAudioFormat) / 2); } @@ -676,6 +706,7 @@ static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobjec // ---------------------------------------------------------------------------- // returns the minimum required size for the successful creation of a streaming AudioTrack +// returns -1 if there was an error querying the hardware. static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env, jobject thiz, jint sampleRateInHertz, jint nbChannels, jint audioFormat) { int afSamplingRate; @@ -715,8 +746,8 @@ static JNINativeMethod gMethods[] = { (void *)android_media_AudioTrack_native_setup}, {"native_finalize", "()V", (void *)android_media_AudioTrack_native_finalize}, {"native_release", "()V", (void *)android_media_AudioTrack_native_release}, - {"native_write_byte", "([BII)I", (void *)android_media_AudioTrack_native_write}, - {"native_write_short", "([SII)I", (void *)android_media_AudioTrack_native_write_short}, + {"native_write_byte", "([BIII)I", (void *)android_media_AudioTrack_native_write}, + {"native_write_short", "([SIII)I", (void *)android_media_AudioTrack_native_write_short}, {"native_setVolume", "(FF)V", (void *)android_media_AudioTrack_set_volume}, {"native_get_native_frame_count", "()I", (void *)android_media_AudioTrack_get_native_frame_count}, diff --git a/core/jni/android_media_JetPlayer.cpp b/core/jni/android_media_JetPlayer.cpp index fe60943..e345af6 100644 --- a/core/jni/android_media_JetPlayer.cpp +++ b/core/jni/android_media_JetPlayer.cpp @@ -81,7 +81,7 @@ android_media_JetPlayer_setup(JNIEnv *env, jobject thiz, jobject weak_this, jint maxTracks, jint trackBufferSize) { //LOGV("android_media_JetPlayer_setup(): entering."); - JetPlayer* lpJet = new JetPlayer(weak_this, maxTracks, trackBufferSize); + JetPlayer* lpJet = new JetPlayer(env->NewGlobalRef(weak_this), maxTracks, trackBufferSize); EAS_RESULT result = lpJet->init(); diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index a7a0428..a6b63d8 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -117,22 +117,25 @@ static void read_mapinfo(FILE *fp, stats_t* stats) line[--len] = 0; /* ignore guard pages */ - if (len > 18 && line[18] == '-') skip = true; + if (len > 18 && line[17] == '-') skip = true; start = strtoul(line, 0, 16); - if (strstr("[heap]", line)) { + if (strstr(line, "[heap]")) { isNativeHeap = 1; - } else if (strstr("/dalvik-LinearAlloc", line)) { + } else if (strstr(line, "/dalvik-LinearAlloc")) { isDalvikHeap = 1; - } else if (strstr("/mspace/dalvik-heap", line)) { + } else if (strstr(line, "/mspace/dalvik-heap")) { isDalvikHeap = 1; - } else if (strstr("/dalvik-heap-bitmap/", line)) { + } else if (strstr(line, "/dalvik-heap-bitmap/")) { isDalvikHeap = 1; - } else if (strstr("/tmp/sqlite-heap", line)) { + } else if (strstr(line, "/tmp/sqlite-heap")) { isSqliteHeap = 1; } + //LOGI("native=%d dalvik=%d sqlite=%d: %s\n", isNativeHeap, isDalvikHeap, + // isSqliteHeap, line); + while (true) { if (fgets(line, 1024, fp) == 0) { done = true; diff --git a/core/jni/android_server_BluetoothDeviceService.cpp b/core/jni/android_server_BluetoothDeviceService.cpp index 0936310..796da15 100644 --- a/core/jni/android_server_BluetoothDeviceService.cpp +++ b/core/jni/android_server_BluetoothDeviceService.cpp @@ -515,24 +515,39 @@ static jboolean cancelBondingProcessNative(JNIEnv *env, jobject object, static jboolean removeBondingNative(JNIEnv *env, jobject object, jstring address) { LOGV(__FUNCTION__); + jboolean result = JNI_FALSE; #ifdef HAVE_BLUETOOTH native_data_t *nat = get_native_data(env, object); if (nat) { const char *c_address = env->GetStringUTFChars(address, NULL); LOGV("... address = %s", c_address); + DBusError err; + dbus_error_init(&err); DBusMessage *reply = - dbus_func_args_timeout(env, nat->conn, -1, nat->adapter, - DBUS_CLASS_NAME, "RemoveBonding", - DBUS_TYPE_STRING, &c_address, - DBUS_TYPE_INVALID); - env->ReleaseStringUTFChars(address, c_address); - if (reply) { - dbus_message_unref(reply); + dbus_func_args_error(env, nat->conn, &err, nat->adapter, + DBUS_CLASS_NAME, "RemoveBonding", + DBUS_TYPE_STRING, &c_address, + DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + if (dbus_error_has_name(&err, + BLUEZ_DBUS_BASE_IFC ".Error.DoesNotExist")) { + LOGW("%s: Warning: %s (%s)", __FUNCTION__, err.message, + c_address); + result = JNI_TRUE; + } else { + LOGE("%s: D-Bus error %s (%s)", __FUNCTION__, err.name, + err.message); + } + } else { + result = JNI_TRUE; } - return JNI_TRUE; + + env->ReleaseStringUTFChars(address, c_address); + dbus_error_free(&err); + if (reply) dbus_message_unref(reply); } #endif - return JNI_FALSE; + return result; } static jobjectArray listBondingsNative(JNIEnv *env, jobject object) { diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp index e5ae2ea..9100e81 100644 --- a/core/jni/android_server_BluetoothEventLoop.cpp +++ b/core/jni/android_server_BluetoothEventLoop.cpp @@ -755,17 +755,22 @@ void onCreateBondingResult(DBusMessage *msg, void *user) { // already bonded LOGV("... error = %s (%s)\n", err.name, err.message); result = BOND_RESULT_SUCCESS; + } else if (!strcmp(err.name, BLUEZ_DBUS_BASE_IFC ".Error.InProgress")) { + // don't make the java callback + LOGV("... error = %s (%s)\n", err.name, err.message); + goto done; } else { LOGE("%s: D-Bus error: %s (%s)\n", __FUNCTION__, err.name, err.message); result = BOND_RESULT_ERROR; } - dbus_error_free(&err); } env->CallVoidMethod(event_loop_nat->me, method_onCreateBondingResult, env->NewStringUTF(address), result); +done: + dbus_error_free(&err); free(user); } diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index f09bd4c..8baaa84 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -212,7 +212,9 @@ static jobject Surface_lockCanvas(JNIEnv* env, jobject clazz, jobject dirtyRect) dirty.top = env->GetIntField(dirtyRect, ro.t); dirty.right = env->GetIntField(dirtyRect, ro.r); dirty.bottom= env->GetIntField(dirtyRect, ro.b); - dirtyRegion.set(dirty); + if (dirty.left < dirty.right && dirty.top < dirty.bottom) { + dirtyRegion.set(dirty); + } } else { dirtyRegion.set(Rect(0x3FFF,0x3FFF)); } @@ -246,6 +248,14 @@ static jobject Surface_lockCanvas(JNIEnv* env, jobject clazz, jobject dirtyRect) int saveCount = nativeCanvas->save(); env->SetIntField(clazz, so.saveCount, saveCount); + if (dirtyRect) { + Rect bounds(dirtyRegion.bounds()); + env->SetIntField(dirtyRect, ro.l, bounds.left); + env->SetIntField(dirtyRect, ro.t, bounds.top); + env->SetIntField(dirtyRect, ro.r, bounds.right); + env->SetIntField(dirtyRect, ro.b, bounds.bottom); + } + return canvas; } |