summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-13 12:57:50 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-13 12:57:50 -0800
commitda996f390e17e16f2dfa60e972e7ebc4f868f37e (patch)
tree00a0f15270d4c7b619fd34d8383257e1761082f4 /core/jni
parentd24b8183b93e781080b2c16c487e60d51c12da31 (diff)
downloadframeworks_base-da996f390e17e16f2dfa60e972e7ebc4f868f37e.zip
frameworks_base-da996f390e17e16f2dfa60e972e7ebc4f868f37e.tar.gz
frameworks_base-da996f390e17e16f2dfa60e972e7ebc4f868f37e.tar.bz2
auto import from //branches/cupcake/...@131421
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_media_AudioRecord.cpp37
-rw-r--r--core/jni/android_media_AudioSystem.cpp16
-rw-r--r--core/jni/android_media_AudioTrack.cpp33
-rw-r--r--core/jni/android_server_BluetoothEventLoop.cpp4
-rw-r--r--core/jni/android_util_EventLog.cpp2
5 files changed, 65 insertions, 27 deletions
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 307c6fd..288433a 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -267,7 +267,7 @@ static void android_media_AudioRecord_finalize(JNIEnv *env, jobject thiz) {
(AudioRecord *)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
if (lpRecorder) {
- //LOGV("About to delete lpRecorder: %x\n", (int)lpRecorder);
+ LOGV("About to delete lpRecorder: %x\n", (int)lpRecorder);
lpRecorder->stop();
delete lpRecorder;
}
@@ -449,6 +449,39 @@ static jint android_media_AudioRecord_get_pos_update_period(JNIEnv *env, jobjec
// ----------------------------------------------------------------------------
+// returns the minimum required size for the successful creation of an AudioRecord instance.
+// returns 0 if the parameter combination is not supported.
+// return -1 if there was an error querying the buffer size.
+static jint android_media_AudioRecord_get_min_buff_size(JNIEnv *env, jobject thiz,
+ jint sampleRateInHertz, jint nbChannels, jint audioFormat) {
+
+ size_t inputBuffSize = 0;
+ LOGV(">> android_media_AudioRecord_get_min_buff_size(%d, %d, %d)", sampleRateInHertz, nbChannels, audioFormat);
+
+ status_t result = AudioSystem::getInputBufferSize(
+ sampleRateInHertz,
+ (audioFormat == javaAudioRecordFields.PCM16 ?
+ AudioSystem::PCM_16_BIT : AudioSystem::PCM_8_BIT),
+ nbChannels, &inputBuffSize);
+ switch(result) {
+ case(NO_ERROR):
+ if(inputBuffSize == 0) {
+ LOGV("Recording parameters are not supported: %dHz, %d channel(s), (java) format %d",
+ sampleRateInHertz, nbChannels, audioFormat);
+ return 0;
+ } else {
+ // the minimum buffer size is twice the hardware input buffer size
+ return 2*inputBuffSize;
+ }
+ break;
+ case(PERMISSION_DENIED):
+ default:
+ return -1;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
// name, signature, funcPtr
@@ -470,6 +503,8 @@ static JNINativeMethod gMethods[] = {
"(I)I", (void *)android_media_AudioRecord_set_pos_update_period},
{"native_get_pos_update_period",
"()I", (void *)android_media_AudioRecord_get_pos_update_period},
+ {"native_get_min_buff_size",
+ "(III)I", (void *)android_media_AudioRecord_get_min_buff_size},
};
// field names found in android/media/AudioRecord.java
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 6bd3655..692610e 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -53,13 +53,8 @@ static int
android_media_AudioSystem_setVolume(JNIEnv *env, jobject clazz, jint type, jint volume)
{
LOGV("setVolume(%d)", int(volume));
- if (int(type) == AudioTrack::VOICE_CALL) {
- return check_AudioSystem_Command(AudioSystem::setStreamVolume(type, float(volume) / 100.0));
- } else if (int(type) == AudioTrack::BLUETOOTH_SCO) {
- return check_AudioSystem_Command(AudioSystem::setStreamVolume(type, float(1.0)));
- } else {
- return check_AudioSystem_Command(AudioSystem::setStreamVolume(type, AudioSystem::linearToLog(volume)));
- }
+
+ return check_AudioSystem_Command(AudioSystem::setStreamVolume(type, AudioSystem::linearToLog(volume)));
}
static int
@@ -68,12 +63,7 @@ android_media_AudioSystem_getVolume(JNIEnv *env, jobject clazz, jint type)
float v;
int v_int = -1;
if (AudioSystem::getStreamVolume(int(type), &v) == NO_ERROR) {
- // voice call volume is converted to log scale in the hardware
- if (int(type) == AudioTrack::VOICE_CALL) {
- v_int = lrint(v * 100.0);
- } else {
- v_int = AudioSystem::logToLinear(v);
- }
+ v_int = AudioSystem::logToLinear(v);
}
return v_int;
}
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index bbecc1b..6ca821d 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -72,6 +72,7 @@ class AudioTrackJniStorage {
sp<MemoryHeapBase> mMemHeap;
sp<MemoryBase> mMemBase;
audiotrack_callback_cookie mCallbackData;
+ int mStreamType;
AudioTrackJniStorage() {
}
@@ -168,11 +169,11 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
int afSampleRate;
int afFrameCount;
- if (AudioSystem::getOutputFrameCount(&afFrameCount) != NO_ERROR) {
+ if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
LOGE("Error creating AudioTrack: Could not get AudioSystem frame count.");
return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
}
- if (AudioSystem::getOutputSamplingRate(&afSampleRate) != NO_ERROR) {
+ if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
LOGE("Error creating AudioTrack: Could not get AudioSystem sampling rate.");
return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
}
@@ -183,21 +184,21 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
}
// check the stream type
- AudioTrack::stream_type atStreamType;
+ AudioSystem::stream_type atStreamType;
if (streamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
- atStreamType = AudioTrack::VOICE_CALL;
+ atStreamType = AudioSystem::VOICE_CALL;
} else if (streamType == javaAudioTrackFields.STREAM_SYSTEM) {
- atStreamType = AudioTrack::SYSTEM;
+ atStreamType = AudioSystem::SYSTEM;
} else if (streamType == javaAudioTrackFields.STREAM_RING) {
- atStreamType = AudioTrack::RING;
+ atStreamType = AudioSystem::RING;
} else if (streamType == javaAudioTrackFields.STREAM_MUSIC) {
- atStreamType = AudioTrack::MUSIC;
+ atStreamType = AudioSystem::MUSIC;
} else if (streamType == javaAudioTrackFields.STREAM_ALARM) {
- atStreamType = AudioTrack::ALARM;
+ atStreamType = AudioSystem::ALARM;
} else if (streamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
- atStreamType = AudioTrack::NOTIFICATION;
+ atStreamType = AudioSystem::NOTIFICATION;
} else if (streamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
- atStreamType = AudioTrack::BLUETOOTH_SCO;
+ atStreamType = AudioSystem::BLUETOOTH_SCO;
} else {
LOGE("Error creating AudioTrack: unknown stream type.");
return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
@@ -238,6 +239,8 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
// we use a weak reference so the AudioTrack object can be garbage collected.
lpJniStorage->mCallbackData.audioTrack_ref = env->NewGlobalRef(weak_this);
+ lpJniStorage->mStreamType = atStreamType;
+
// create the native AudioTrack object
AudioTrack* lpTrack = new AudioTrack();
if (lpTrack == NULL) {
@@ -656,8 +659,14 @@ static jint android_media_AudioTrack_reload(JNIEnv *env, jobject thiz) {
// ----------------------------------------------------------------------------
static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobject thiz) {
- int afSamplingRate;
- if (AudioSystem::getOutputSamplingRate(&afSamplingRate) != NO_ERROR) {
+ int afSamplingRate;
+ AudioTrackJniStorage* lpJniStorage = (AudioTrackJniStorage *)env->GetIntField(
+ thiz, javaAudioTrackFields.jniData);
+ if (lpJniStorage == NULL) {
+ return DEFAULT_OUTPUT_SAMPLE_RATE;
+ }
+
+ if (AudioSystem::getOutputSamplingRate(&afSamplingRate, lpJniStorage->mStreamType) != NO_ERROR) {
return DEFAULT_OUTPUT_SAMPLE_RATE;
} else {
return afSamplingRate;
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index 75a0fbe..e5ae2ea 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -751,6 +751,10 @@ void onCreateBondingResult(DBusMessage *msg, void *user) {
// Other device is not responding at all
LOGV("... error = %s (%s)\n", err.name, err.message);
result = BOND_RESULT_REMOTE_DEVICE_DOWN;
+ } else if (!strcmp(err.name, BLUEZ_DBUS_BASE_IFC ".Error.AlreadyExists")) {
+ // already bonded
+ LOGV("... error = %s (%s)\n", err.name, err.message);
+ result = BOND_RESULT_SUCCESS;
} else {
LOGE("%s: D-Bus error: %s (%s)\n", __FUNCTION__, err.name, err.message);
result = BOND_RESULT_ERROR;
diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp
index d0cac18..5e5103a 100644
--- a/core/jni/android_util_EventLog.cpp
+++ b/core/jni/android_util_EventLog.cpp
@@ -19,7 +19,7 @@
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
#include "jni.h"
-#include "utils/logger.h"
+#include "cutils/logger.h"
#define END_DELIMITER '\n'
#define INT_BUFFER_SIZE (sizeof(jbyte)+sizeof(jint)+sizeof(END_DELIMITER))