Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 058520e9 authored by Dima Zavin's avatar Dima Zavin Committed by Android (Google) Code Review
Browse files

Merge changes I22d9e018,Ib0701fcc,Ibc637918,I9eb7e002,I4adcec73

* changes:
  audioflinger: don't do work in constructor, instead do it in onFirstRef
  audioflinger: enumerate all the possible audio interfaces
  audio/media: convert to using the audio HAL and new audio defs
  libmedia: move AudioParameter out of AudioSystem
  audioflinger: move legacy audio hw/policy out to libhardware_legacy
parents d21e7b5d 2986f5be
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>

#include <hardware/audio.h>

using namespace android;

int main() {
@@ -31,8 +33,8 @@ int main() {
            AUDIO_SOURCE_DEFAULT,
            kSampleRate,
            kNumChannels == 1
                ? AudioSystem::CHANNEL_IN_MONO
                : AudioSystem::CHANNEL_IN_STEREO);
                ? AUDIO_CHANNEL_IN_MONO
                : AUDIO_CHANNEL_IN_STEREO);
#endif

    sp<MetaData> meta = new MetaData;
+8 −5
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@
#include "media/AudioRecord.h"
#include "media/mediarecorder.h"

#include <cutils/bitops.h>

#include <hardware/audio.h>

// ----------------------------------------------------------------------------

@@ -130,11 +133,11 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
    //LOGV("sampleRate=%d, audioFormat=%d, channels=%x, buffSizeInBytes=%d",
    //     sampleRateInHertz, audioFormat, channels,     buffSizeInBytes);

    if (!AudioSystem::isInputChannel(channels)) {
    if (!audio_is_input_channel(channels)) {
        LOGE("Error creating AudioRecord: channel count is not 1 or 2.");
        return AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
    }
    uint32_t nbChannels = AudioSystem::popCount(channels);
    uint32_t nbChannels = popcount(channels);

    // compare the format against the Java constants
    if ((audioFormat != javaAudioRecordFields.PCM16) 
@@ -145,7 +148,7 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,

    int bytesPerSample = audioFormat==javaAudioRecordFields.PCM16 ? 2 : 1;
    int format = audioFormat==javaAudioRecordFields.PCM16 ? 
            AudioSystem::PCM_16_BIT : AudioSystem::PCM_8_BIT;
            AUDIO_FORMAT_PCM_16_BIT : AUDIO_FORMAT_PCM_8_BIT;

    if (buffSizeInBytes == 0) {
         LOGE("Error creating AudioRecord: frameCount is 0.");
@@ -154,7 +157,7 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
    int frameSize = nbChannels * bytesPerSample;
    size_t frameCount = buffSizeInBytes / frameSize;
    
    if (source >= AUDIO_SOURCE_LIST_END) {
    if (source >= AUDIO_SOURCE_CNT) {
        LOGE("Error creating AudioRecord: unknown source.");
        return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
    }
@@ -463,7 +466,7 @@ static jint android_media_AudioRecord_get_min_buff_size(JNIEnv *env, jobject th
    status_t result = AudioRecord::getMinFrameCount(&frameCount,
            sampleRateInHertz,
            (audioFormat == javaAudioRecordFields.PCM16 ?
                AudioSystem::PCM_16_BIT : AudioSystem::PCM_8_BIT),
                AUDIO_FORMAT_PCM_16_BIT : AUDIO_FORMAT_PCM_8_BIT),
            nbChannels);

    if (result == BAD_VALUE) {
+13 −10
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@
#include <media/AudioSystem.h>
#include <media/AudioTrack.h>

#include <hardware/audio.h>
#include <hardware/audio_policy.h>

// ----------------------------------------------------------------------------

using namespace android;
@@ -129,8 +132,8 @@ static int
android_media_AudioSystem_setDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jint state, jstring device_address)
{
    const char *c_address = env->GetStringUTFChars(device_address, NULL);
    int status = check_AudioSystem_Command(AudioSystem::setDeviceConnectionState(static_cast <AudioSystem::audio_devices>(device),
                                          static_cast <AudioSystem::device_connection_state>(state),
    int status = check_AudioSystem_Command(AudioSystem::setDeviceConnectionState(static_cast <audio_devices_t>(device),
                                          static_cast <audio_policy_dev_state_t>(state),
                                          c_address));
    env->ReleaseStringUTFChars(device_address, c_address);
    return status;
@@ -140,7 +143,7 @@ static int
android_media_AudioSystem_getDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jstring device_address)
{
    const char *c_address = env->GetStringUTFChars(device_address, NULL);
    int state = static_cast <int>(AudioSystem::getDeviceConnectionState(static_cast <AudioSystem::audio_devices>(device),
    int state = static_cast <int>(AudioSystem::getDeviceConnectionState(static_cast <audio_devices_t>(device),
                                          c_address));
    env->ReleaseStringUTFChars(device_address, c_address);
    return state;
@@ -161,20 +164,20 @@ android_media_AudioSystem_setRingerMode(JNIEnv *env, jobject thiz, jint mode, ji
static int
android_media_AudioSystem_setForceUse(JNIEnv *env, jobject thiz, jint usage, jint config)
{
    return check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <AudioSystem::force_use>(usage),
                                                           static_cast <AudioSystem::forced_config>(config)));
    return check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
                                                           static_cast <audio_policy_forced_cfg_t>(config)));
}

static int
android_media_AudioSystem_getForceUse(JNIEnv *env, jobject thiz, jint usage)
{
    return static_cast <int>(AudioSystem::getForceUse(static_cast <AudioSystem::force_use>(usage)));
    return static_cast <int>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
}

static int
android_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint stream, jint indexMin, jint indexMax)
{
    return check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <AudioSystem::stream_type>(stream),
    return check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
                                                                   indexMin,
                                                                   indexMax));
}
@@ -182,14 +185,14 @@ android_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint strea
static int
android_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env, jobject thiz, jint stream, jint index)
{
    return check_AudioSystem_Command(AudioSystem::setStreamVolumeIndex(static_cast <AudioSystem::stream_type>(stream), index));
    return check_AudioSystem_Command(AudioSystem::setStreamVolumeIndex(static_cast <audio_stream_type_t>(stream), index));
}

static int
android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env, jobject thiz, jint stream)
{
    int index;
    if (AudioSystem::getStreamVolumeIndex(static_cast <AudioSystem::stream_type>(stream), &index) != NO_ERROR) {
    if (AudioSystem::getStreamVolumeIndex(static_cast <audio_stream_type_t>(stream), &index) != NO_ERROR) {
        index = -1;
    }
    return index;
@@ -198,7 +201,7 @@ android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env, jobject thiz, jint s
static jint
android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream)
{
    return (jint) AudioSystem::getDevicesForStream(static_cast <AudioSystem::stream_type>(stream));
    return (jint) AudioSystem::getDevicesForStream(static_cast <audio_stream_type_t>(stream));
}

// ----------------------------------------------------------------------------
+27 −24
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@
#include <binder/MemoryHeapBase.h>
#include <binder/MemoryBase.h>

#include <cutils/bitops.h>

#include <hardware/audio.h>

// ----------------------------------------------------------------------------

@@ -77,7 +80,7 @@ class AudioTrackJniStorage {
    AudioTrackJniStorage() {
        mCallbackData.audioTrack_class = 0;
        mCallbackData.audioTrack_ref = 0;
        mStreamType = AudioSystem::DEFAULT;
        mStreamType = AUDIO_STREAM_DEFAULT;
    }

    ~AudioTrackJniStorage() {
@@ -181,30 +184,30 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
    }

    if (!AudioSystem::isOutputChannel(channels)) {
    if (!audio_is_output_channel(channels)) {
        LOGE("Error creating AudioTrack: invalid channel mask.");
        return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
    }
    int nbChannels = AudioSystem::popCount(channels);
    int nbChannels = popcount(channels);
    
    // check the stream type
    AudioSystem::stream_type atStreamType;
    audio_stream_type_t atStreamType;
    if (streamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
        atStreamType = AudioSystem::VOICE_CALL;
        atStreamType = AUDIO_STREAM_VOICE_CALL;
    } else if (streamType == javaAudioTrackFields.STREAM_SYSTEM) {
        atStreamType = AudioSystem::SYSTEM;
        atStreamType = AUDIO_STREAM_SYSTEM;
    } else if (streamType == javaAudioTrackFields.STREAM_RING) {
        atStreamType = AudioSystem::RING;
        atStreamType = AUDIO_STREAM_RING;
    } else if (streamType == javaAudioTrackFields.STREAM_MUSIC) {
        atStreamType = AudioSystem::MUSIC;
        atStreamType = AUDIO_STREAM_MUSIC;
    } else if (streamType == javaAudioTrackFields.STREAM_ALARM) {
        atStreamType = AudioSystem::ALARM;
        atStreamType = AUDIO_STREAM_ALARM;
    } else if (streamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
        atStreamType = AudioSystem::NOTIFICATION;
        atStreamType = AUDIO_STREAM_NOTIFICATION;
    } else if (streamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
        atStreamType = AudioSystem::BLUETOOTH_SCO;
        atStreamType = AUDIO_STREAM_BLUETOOTH_SCO;
    } else if (streamType == javaAudioTrackFields.STREAM_DTMF) {
        atStreamType = AudioSystem::DTMF;
        atStreamType = AUDIO_STREAM_DTMF;
    } else {
        LOGE("Error creating AudioTrack: unknown stream type.");
        return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
@@ -233,7 +236,7 @@ android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_th
    // compute the frame count
    int bytesPerSample = audioFormat == javaAudioTrackFields.PCM16 ? 2 : 1;
    int format = audioFormat == javaAudioTrackFields.PCM16 ? 
            AudioSystem::PCM_16_BIT : AudioSystem::PCM_8_BIT;
            AUDIO_FORMAT_PCM_16_BIT : AUDIO_FORMAT_PCM_8_BIT;
    int frameCount = buffSizeInBytes / (nbChannels * bytesPerSample);
    
    AudioTrackJniStorage* lpJniStorage = new AudioTrackJniStorage();
@@ -755,25 +758,25 @@ static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobjec
    int afSamplingRate;
    // convert the stream type from Java to native value
    // FIXME: code duplication with android_media_AudioTrack_native_setup()
    AudioSystem::stream_type nativeStreamType;
    audio_stream_type_t nativeStreamType;
    if (javaStreamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
        nativeStreamType = AudioSystem::VOICE_CALL;
        nativeStreamType = AUDIO_STREAM_VOICE_CALL;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_SYSTEM) {
        nativeStreamType = AudioSystem::SYSTEM;
        nativeStreamType = AUDIO_STREAM_SYSTEM;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_RING) {
        nativeStreamType = AudioSystem::RING;
        nativeStreamType = AUDIO_STREAM_RING;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_MUSIC) {
        nativeStreamType = AudioSystem::MUSIC;
        nativeStreamType = AUDIO_STREAM_MUSIC;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_ALARM) {
        nativeStreamType = AudioSystem::ALARM;
        nativeStreamType = AUDIO_STREAM_ALARM;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
        nativeStreamType = AudioSystem::NOTIFICATION;
        nativeStreamType = AUDIO_STREAM_NOTIFICATION;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
        nativeStreamType = AudioSystem::BLUETOOTH_SCO;
        nativeStreamType = AUDIO_STREAM_BLUETOOTH_SCO;
    } else if (javaStreamType == javaAudioTrackFields.STREAM_DTMF) {
        nativeStreamType = AudioSystem::DTMF;
        nativeStreamType = AUDIO_STREAM_DTMF;
    } else {
        nativeStreamType = AudioSystem::DEFAULT;
        nativeStreamType = AUDIO_STREAM_DEFAULT;
    }

    if (AudioSystem::getOutputSamplingRate(&afSamplingRate, nativeStreamType) != NO_ERROR) {
@@ -793,7 +796,7 @@ static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env, jobject thi
    jint sampleRateInHertz, jint nbChannels, jint audioFormat) {

    int frameCount = 0;
    if (AudioTrack::getMinFrameCount(&frameCount, AudioSystem::DEFAULT,
    if (AudioTrack::getMinFrameCount(&frameCount, AUDIO_STREAM_DEFAULT,
            sampleRateInHertz) != NO_ERROR) {
        return -1;
    }
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008-2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_AUDIOPARAMETER_H_
#define ANDROID_AUDIOPARAMETER_H_

#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/String8.h>

namespace android {

class AudioParameter {

public:
    AudioParameter() {}
    AudioParameter(const String8& keyValuePairs);
    virtual ~AudioParameter();

    // reserved parameter keys for changing standard parameters with setParameters() function.
    // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
    // configuration changes and act accordingly.
    //  keyRouting: to change audio routing, value is an int in audio_devices_t
    //  keySamplingRate: to change sampling rate routing, value is an int
    //  keyFormat: to change audio format, value is an int in audio_format_t
    //  keyChannels: to change audio channel configuration, value is an int in audio_channels_t
    //  keyFrameCount: to change audio output frame count, value is an int
    //  keyInputSource: to change audio input source, value is an int in audio_source_t
    //     (defined in media/mediarecorder.h)
    static const char *keyRouting;
    static const char *keySamplingRate;
    static const char *keyFormat;
    static const char *keyChannels;
    static const char *keyFrameCount;
    static const char *keyInputSource;

    String8 toString();

    status_t add(const String8& key, const String8& value);
    status_t addInt(const String8& key, const int value);
    status_t addFloat(const String8& key, const float value);

    status_t remove(const String8& key);

    status_t get(const String8& key, String8& value);
    status_t getInt(const String8& key, int& value);
    status_t getFloat(const String8& key, float& value);
    status_t getAt(size_t index, String8& key, String8& value);

    size_t size() { return mParameters.size(); }

private:
    String8 mKeyValuePairs;
    KeyedVector <String8, String8> mParameters;
};

};  // namespace android

#endif  /*ANDROID_AUDIOPARAMETER_H_*/
Loading