2009-03-04 03:31:44 +00:00
|
|
|
/* //device/include/server/AudioFlinger/AudioFlinger.h
|
|
|
|
**
|
|
|
|
** Copyright 2007, 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_AUDIO_FLINGER_H
|
|
|
|
#define ANDROID_AUDIO_FLINGER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
2009-12-18 13:47:48 +00:00
|
|
|
#include <limits.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <media/IAudioFlinger.h>
|
|
|
|
#include <media/IAudioFlingerClient.h>
|
|
|
|
#include <media/IAudioTrack.h>
|
|
|
|
#include <media/IAudioRecord.h>
|
|
|
|
#include <media/AudioTrack.h>
|
|
|
|
|
|
|
|
#include <utils/Atomic.h>
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/threads.h>
|
2009-05-20 02:08:10 +00:00
|
|
|
#include <binder/MemoryDealer.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <utils/SortedVector.h>
|
|
|
|
#include <utils/Vector.h>
|
|
|
|
|
|
|
|
#include <hardware_legacy/AudioHardwareInterface.h>
|
|
|
|
|
|
|
|
#include "AudioBufferProvider.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
class audio_track_cblk_t;
|
2010-06-02 06:49:17 +00:00
|
|
|
class effect_param_cblk_t;
|
2009-03-04 03:31:44 +00:00
|
|
|
class AudioMixer;
|
|
|
|
class AudioBuffer;
|
2009-07-17 19:17:14 +00:00
|
|
|
class AudioResampler;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
|
|
|
|
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const nsecs_t kStandbyTimeInNsecs = seconds(3);
|
|
|
|
|
2010-05-12 09:05:53 +00:00
|
|
|
class AudioFlinger : public BnAudioFlinger
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void instantiate();
|
|
|
|
|
|
|
|
virtual status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
// IAudioFlinger interface
|
|
|
|
virtual sp<IAudioTrack> createTrack(
|
|
|
|
pid_t pid,
|
|
|
|
int streamType,
|
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount,
|
|
|
|
uint32_t flags,
|
|
|
|
const sp<IMemory>& sharedBuffer,
|
2009-07-28 15:44:33 +00:00
|
|
|
int output,
|
2010-06-02 06:49:17 +00:00
|
|
|
int *sessionId,
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t *status);
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual uint32_t sampleRate(int output) const;
|
|
|
|
virtual int channelCount(int output) const;
|
|
|
|
virtual int format(int output) const;
|
|
|
|
virtual size_t frameCount(int output) const;
|
|
|
|
virtual uint32_t latency(int output) const;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
virtual status_t setMasterVolume(float value);
|
|
|
|
virtual status_t setMasterMute(bool muted);
|
|
|
|
|
|
|
|
virtual float masterVolume() const;
|
|
|
|
virtual bool masterMute() const;
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t setStreamVolume(int stream, float value, int output);
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual status_t setStreamMute(int stream, bool muted);
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual float streamVolume(int stream, int output) const;
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual bool streamMute(int stream) const;
|
|
|
|
|
|
|
|
virtual status_t setMode(int mode);
|
|
|
|
|
|
|
|
virtual status_t setMicMute(bool state);
|
|
|
|
virtual bool getMicMute() const;
|
|
|
|
|
2010-01-25 16:49:09 +00:00
|
|
|
virtual bool isStreamActive(int stream) const;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t setParameters(int ioHandle, const String8& keyValuePairs);
|
|
|
|
virtual String8 getParameters(int ioHandle, const String8& keys);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
virtual void registerClient(const sp<IAudioFlingerClient>& client);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount);
|
2010-02-26 10:47:27 +00:00
|
|
|
virtual unsigned int getInputFramesLost(int ioHandle);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual int openOutput(uint32_t *pDevices,
|
2009-07-17 19:17:14 +00:00
|
|
|
uint32_t *pSamplingRate,
|
|
|
|
uint32_t *pFormat,
|
|
|
|
uint32_t *pChannels,
|
|
|
|
uint32_t *pLatencyMs,
|
|
|
|
uint32_t flags);
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual int openDuplicateOutput(int output1, int output2);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t closeOutput(int output);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t suspendOutput(int output);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t restoreOutput(int output);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual int openInput(uint32_t *pDevices,
|
2009-07-17 19:17:14 +00:00
|
|
|
uint32_t *pSamplingRate,
|
|
|
|
uint32_t *pFormat,
|
|
|
|
uint32_t *pChannels,
|
|
|
|
uint32_t acoustics);
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t closeInput(int input);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
virtual status_t setStreamOutput(uint32_t stream, int output);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-10-21 15:14:22 +00:00
|
|
|
virtual status_t setVoiceVolume(float volume);
|
|
|
|
|
2010-01-20 01:37:09 +00:00
|
|
|
virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output);
|
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
virtual int newAudioSessionId();
|
|
|
|
|
|
|
|
virtual status_t loadEffectLibrary(const char *libPath, int *handle);
|
|
|
|
|
|
|
|
virtual status_t unloadEffectLibrary(int handle);
|
|
|
|
|
|
|
|
virtual status_t queryNumberEffects(uint32_t *numEffects);
|
|
|
|
|
2010-06-24 00:38:20 +00:00
|
|
|
virtual status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor);
|
2010-06-02 06:49:17 +00:00
|
|
|
|
|
|
|
virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *descriptor);
|
|
|
|
|
|
|
|
virtual sp<IEffect> createEffect(pid_t pid,
|
|
|
|
effect_descriptor_t *pDesc,
|
|
|
|
const sp<IEffectClient>& effectClient,
|
|
|
|
int32_t priority,
|
|
|
|
int output,
|
|
|
|
int sessionId,
|
|
|
|
status_t *status,
|
|
|
|
int *id,
|
|
|
|
int *enabled);
|
|
|
|
|
2010-06-24 00:38:20 +00:00
|
|
|
status_t registerEffectResource_l(effect_descriptor_t *desc);
|
|
|
|
void unregisterEffectResource_l(effect_descriptor_t *desc);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
enum hardware_call_state {
|
|
|
|
AUDIO_HW_IDLE = 0,
|
|
|
|
AUDIO_HW_INIT,
|
|
|
|
AUDIO_HW_OUTPUT_OPEN,
|
|
|
|
AUDIO_HW_OUTPUT_CLOSE,
|
|
|
|
AUDIO_HW_INPUT_OPEN,
|
|
|
|
AUDIO_HW_INPUT_CLOSE,
|
|
|
|
AUDIO_HW_STANDBY,
|
|
|
|
AUDIO_HW_SET_MASTER_VOLUME,
|
|
|
|
AUDIO_HW_GET_ROUTING,
|
|
|
|
AUDIO_HW_SET_ROUTING,
|
|
|
|
AUDIO_HW_GET_MODE,
|
|
|
|
AUDIO_HW_SET_MODE,
|
|
|
|
AUDIO_HW_GET_MIC_MUTE,
|
|
|
|
AUDIO_HW_SET_MIC_MUTE,
|
|
|
|
AUDIO_SET_VOICE_VOLUME,
|
|
|
|
AUDIO_SET_PARAMETER,
|
|
|
|
};
|
|
|
|
|
|
|
|
// record interface
|
|
|
|
virtual sp<IAudioRecord> openRecord(
|
|
|
|
pid_t pid,
|
2009-07-28 15:44:33 +00:00
|
|
|
int input,
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount,
|
|
|
|
uint32_t flags,
|
2010-06-02 06:49:17 +00:00
|
|
|
int *sessionId,
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t *status);
|
|
|
|
|
|
|
|
virtual status_t onTransact(
|
|
|
|
uint32_t code,
|
|
|
|
const Parcel& data,
|
|
|
|
Parcel* reply,
|
|
|
|
uint32_t flags);
|
|
|
|
|
2010-06-24 00:38:20 +00:00
|
|
|
uint32_t getMode() { return mMode; }
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
|
|
|
AudioFlinger();
|
|
|
|
virtual ~AudioFlinger();
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// Internal dump utilites.
|
|
|
|
status_t dumpPermissionDenial(int fd, const Vector<String16>& args);
|
|
|
|
status_t dumpClients(int fd, const Vector<String16>& args);
|
|
|
|
status_t dumpInternals(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
// --- Client ---
|
|
|
|
class Client : public RefBase {
|
|
|
|
public:
|
|
|
|
Client(const sp<AudioFlinger>& audioFlinger, pid_t pid);
|
|
|
|
virtual ~Client();
|
|
|
|
const sp<MemoryDealer>& heap() const;
|
|
|
|
pid_t pid() const { return mPid; }
|
2009-09-17 12:12:56 +00:00
|
|
|
sp<AudioFlinger> audioFlinger() { return mAudioFlinger; }
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
|
|
|
Client(const Client&);
|
|
|
|
Client& operator = (const Client&);
|
|
|
|
sp<AudioFlinger> mAudioFlinger;
|
|
|
|
sp<MemoryDealer> mMemoryDealer;
|
|
|
|
pid_t mPid;
|
|
|
|
};
|
|
|
|
|
2010-05-12 09:05:53 +00:00
|
|
|
// --- Notification Client ---
|
|
|
|
class NotificationClient : public IBinder::DeathRecipient {
|
|
|
|
public:
|
|
|
|
NotificationClient(const sp<AudioFlinger>& audioFlinger,
|
|
|
|
const sp<IAudioFlingerClient>& client,
|
|
|
|
pid_t pid);
|
|
|
|
virtual ~NotificationClient();
|
|
|
|
|
|
|
|
sp<IAudioFlingerClient> client() { return mClient; }
|
|
|
|
|
|
|
|
// IBinder::DeathRecipient
|
|
|
|
virtual void binderDied(const wp<IBinder>& who);
|
|
|
|
|
|
|
|
private:
|
|
|
|
NotificationClient(const NotificationClient&);
|
|
|
|
NotificationClient& operator = (const NotificationClient&);
|
|
|
|
|
|
|
|
sp<AudioFlinger> mAudioFlinger;
|
|
|
|
pid_t mPid;
|
|
|
|
sp<IAudioFlingerClient> mClient;
|
|
|
|
};
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
class TrackHandle;
|
|
|
|
class RecordHandle;
|
2009-07-17 19:17:14 +00:00
|
|
|
class RecordThread;
|
|
|
|
class PlaybackThread;
|
|
|
|
class MixerThread;
|
|
|
|
class DirectOutputThread;
|
2009-12-18 13:47:48 +00:00
|
|
|
class DuplicatingThread;
|
2009-07-17 19:17:14 +00:00
|
|
|
class Track;
|
|
|
|
class RecordTrack;
|
2010-06-02 06:49:17 +00:00
|
|
|
class EffectModule;
|
|
|
|
class EffectHandle;
|
|
|
|
class EffectChain;
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
class ThreadBase : public Thread {
|
2009-03-04 03:31:44 +00:00
|
|
|
public:
|
2009-11-19 17:00:56 +00:00
|
|
|
ThreadBase (const sp<AudioFlinger>& audioFlinger, int id);
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual ~ThreadBase();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-11-07 08:01:32 +00:00
|
|
|
status_t dumpBase(int fd, const Vector<String16>& args);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// base for record and playback
|
|
|
|
class TrackBase : public AudioBufferProvider, public RefBase {
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum track_state {
|
|
|
|
IDLE,
|
|
|
|
TERMINATED,
|
|
|
|
STOPPED,
|
|
|
|
RESUMING,
|
|
|
|
ACTIVE,
|
|
|
|
PAUSING,
|
|
|
|
PAUSED
|
|
|
|
};
|
|
|
|
|
|
|
|
enum track_flags {
|
|
|
|
STEPSERVER_FAILED = 0x01, // StepServer could not acquire cblk->lock mutex
|
|
|
|
SYSTEM_FLAGS_MASK = 0x0000ffffUL,
|
|
|
|
// The upper 16 bits are used for track-specific flags.
|
|
|
|
};
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
TrackBase(const wp<ThreadBase>& thread,
|
2009-03-04 03:31:44 +00:00
|
|
|
const sp<Client>& client,
|
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount,
|
|
|
|
uint32_t flags,
|
2010-06-02 06:49:17 +00:00
|
|
|
const sp<IMemory>& sharedBuffer,
|
|
|
|
int sessionId);
|
2009-03-04 03:31:44 +00:00
|
|
|
~TrackBase();
|
|
|
|
|
|
|
|
virtual status_t start() = 0;
|
|
|
|
virtual void stop() = 0;
|
|
|
|
sp<IMemory> getCblk() const;
|
2009-08-11 06:22:32 +00:00
|
|
|
audio_track_cblk_t* cblk() const { return mCblk; }
|
2010-06-02 06:49:17 +00:00
|
|
|
int sessionId() { return mSessionId; }
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
protected:
|
2009-07-17 19:17:14 +00:00
|
|
|
friend class ThreadBase;
|
2009-03-04 03:31:44 +00:00
|
|
|
friend class RecordHandle;
|
2009-07-23 20:17:39 +00:00
|
|
|
friend class PlaybackThread;
|
|
|
|
friend class RecordThread;
|
|
|
|
friend class MixerThread;
|
|
|
|
friend class DirectOutputThread;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
TrackBase(const TrackBase&);
|
|
|
|
TrackBase& operator = (const TrackBase&);
|
|
|
|
|
|
|
|
virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0;
|
|
|
|
virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer);
|
|
|
|
|
|
|
|
int format() const {
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
int channelCount() const ;
|
|
|
|
|
|
|
|
int sampleRate() const;
|
|
|
|
|
|
|
|
void* getBuffer(uint32_t offset, uint32_t frames) const;
|
|
|
|
|
|
|
|
bool isStopped() const {
|
|
|
|
return mState == STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isTerminated() const {
|
|
|
|
return mState == TERMINATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool step();
|
|
|
|
void reset();
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
wp<ThreadBase> mThread;
|
2009-03-04 03:31:44 +00:00
|
|
|
sp<Client> mClient;
|
|
|
|
sp<IMemory> mCblkMemory;
|
|
|
|
audio_track_cblk_t* mCblk;
|
|
|
|
void* mBuffer;
|
|
|
|
void* mBufferEnd;
|
|
|
|
uint32_t mFrameCount;
|
|
|
|
// we don't really need a lock for these
|
|
|
|
int mState;
|
|
|
|
int mClientTid;
|
|
|
|
uint8_t mFormat;
|
|
|
|
uint32_t mFlags;
|
2010-06-02 06:49:17 +00:00
|
|
|
int mSessionId;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
class ConfigEvent {
|
|
|
|
public:
|
|
|
|
ConfigEvent() : mEvent(0), mParam(0) {}
|
|
|
|
|
|
|
|
int mEvent;
|
|
|
|
int mParam;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t sampleRate() const;
|
|
|
|
int channelCount() const;
|
|
|
|
int format() const;
|
|
|
|
size_t frameCount() const;
|
|
|
|
void wakeUp() { mWaitWorkCV.broadcast(); }
|
|
|
|
void exit();
|
|
|
|
virtual bool checkForNewParameters_l() = 0;
|
|
|
|
virtual status_t setParameters(const String8& keyValuePairs);
|
|
|
|
virtual String8 getParameters(const String8& keys) = 0;
|
2010-05-14 10:26:45 +00:00
|
|
|
virtual void audioConfigChanged_l(int event, int param = 0) = 0;
|
2009-07-17 19:17:14 +00:00
|
|
|
void sendConfigEvent(int event, int param = 0);
|
2009-08-04 16:45:33 +00:00
|
|
|
void sendConfigEvent_l(int event, int param = 0);
|
2009-07-17 19:17:14 +00:00
|
|
|
void processConfigEvents();
|
2009-11-19 17:00:56 +00:00
|
|
|
int id() const { return mId;}
|
2009-12-18 13:47:48 +00:00
|
|
|
bool standby() { return mStandby; }
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-07-23 20:17:39 +00:00
|
|
|
mutable Mutex mLock;
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
friend class Track;
|
|
|
|
friend class TrackBase;
|
|
|
|
friend class PlaybackThread;
|
|
|
|
friend class MixerThread;
|
|
|
|
friend class DirectOutputThread;
|
|
|
|
friend class DuplicatingThread;
|
|
|
|
friend class RecordThread;
|
|
|
|
friend class RecordTrack;
|
|
|
|
|
|
|
|
Condition mWaitWorkCV;
|
|
|
|
sp<AudioFlinger> mAudioFlinger;
|
|
|
|
uint32_t mSampleRate;
|
|
|
|
size_t mFrameCount;
|
2010-05-14 12:45:46 +00:00
|
|
|
uint32_t mChannels;
|
|
|
|
uint16_t mChannelCount;
|
|
|
|
uint16_t mFrameSize;
|
2009-07-17 19:17:14 +00:00
|
|
|
int mFormat;
|
|
|
|
Condition mParamCond;
|
2009-08-04 16:45:33 +00:00
|
|
|
Vector<String8> mNewParameters;
|
2009-07-17 19:17:14 +00:00
|
|
|
status_t mParamStatus;
|
|
|
|
Vector<ConfigEvent *> mConfigEvents;
|
|
|
|
bool mStandby;
|
2009-11-19 17:00:56 +00:00
|
|
|
int mId;
|
|
|
|
bool mExiting;
|
2009-07-17 19:17:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// --- PlaybackThread ---
|
|
|
|
class PlaybackThread : public ThreadBase {
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum type {
|
|
|
|
MIXER,
|
|
|
|
DIRECT,
|
|
|
|
DUPLICATING
|
|
|
|
};
|
|
|
|
|
2009-11-10 07:32:22 +00:00
|
|
|
enum mixer_state {
|
|
|
|
MIXER_IDLE,
|
|
|
|
MIXER_TRACKS_ENABLED,
|
|
|
|
MIXER_TRACKS_READY
|
|
|
|
};
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// playback track
|
|
|
|
class Track : public TrackBase {
|
|
|
|
public:
|
2009-07-17 19:17:14 +00:00
|
|
|
Track( const wp<ThreadBase>& thread,
|
2009-03-04 03:31:44 +00:00
|
|
|
const sp<Client>& client,
|
|
|
|
int streamType,
|
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount,
|
2010-06-02 06:49:17 +00:00
|
|
|
const sp<IMemory>& sharedBuffer,
|
|
|
|
int sessionId);
|
2009-03-04 03:31:44 +00:00
|
|
|
~Track();
|
|
|
|
|
|
|
|
void dump(char* buffer, size_t size);
|
|
|
|
virtual status_t start();
|
|
|
|
virtual void stop();
|
|
|
|
void pause();
|
|
|
|
|
|
|
|
void flush();
|
|
|
|
void destroy();
|
|
|
|
void mute(bool);
|
|
|
|
void setVolume(float left, float right);
|
2009-07-17 19:17:14 +00:00
|
|
|
int name() const {
|
|
|
|
return mName;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-05-22 16:18:15 +00:00
|
|
|
int type() const {
|
|
|
|
return mStreamType;
|
|
|
|
}
|
2010-06-02 06:49:17 +00:00
|
|
|
status_t attachAuxEffect(int EffectId);
|
|
|
|
void setAuxBuffer(int EffectId, int32_t *buffer);
|
|
|
|
int32_t *auxBuffer() { return mAuxBuffer; }
|
|
|
|
void setMainBuffer(int16_t *buffer) { mMainBuffer = buffer; }
|
|
|
|
int16_t *mainBuffer() { return mMainBuffer; }
|
|
|
|
int auxEffectId() { return mAuxEffectId; }
|
2009-05-22 16:18:15 +00:00
|
|
|
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
protected:
|
2009-07-17 19:17:14 +00:00
|
|
|
friend class ThreadBase;
|
2009-03-04 03:31:44 +00:00
|
|
|
friend class AudioFlinger;
|
2009-07-23 20:17:39 +00:00
|
|
|
friend class TrackHandle;
|
|
|
|
friend class PlaybackThread;
|
|
|
|
friend class MixerThread;
|
|
|
|
friend class DirectOutputThread;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
Track(const Track&);
|
|
|
|
Track& operator = (const Track&);
|
|
|
|
|
|
|
|
virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
|
2009-07-17 19:17:14 +00:00
|
|
|
bool isMuted() { return mMute; }
|
2009-03-04 03:31:44 +00:00
|
|
|
bool isPausing() const {
|
|
|
|
return mState == PAUSING;
|
|
|
|
}
|
|
|
|
bool isPaused() const {
|
|
|
|
return mState == PAUSED;
|
|
|
|
}
|
|
|
|
bool isReady() const;
|
|
|
|
void setPaused() { mState = PAUSED; }
|
|
|
|
void reset();
|
|
|
|
|
2009-11-19 17:00:56 +00:00
|
|
|
bool isOutputTrack() const {
|
|
|
|
return (mStreamType == AudioSystem::NUM_STREAM_TYPES);
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// we don't really need a lock for these
|
|
|
|
float mVolume[2];
|
|
|
|
volatile bool mMute;
|
|
|
|
// FILLED state is used for suppressing volume ramp at begin of playing
|
|
|
|
enum {FS_FILLING, FS_FILLED, FS_ACTIVE};
|
|
|
|
mutable uint8_t mFillingUpStatus;
|
|
|
|
int8_t mRetryCount;
|
|
|
|
sp<IMemory> mSharedBuffer;
|
|
|
|
bool mResetDone;
|
2009-05-22 16:18:15 +00:00
|
|
|
int mStreamType;
|
2009-07-17 19:17:14 +00:00
|
|
|
int mName;
|
2010-06-02 06:49:17 +00:00
|
|
|
int16_t *mMainBuffer;
|
|
|
|
int32_t *mAuxBuffer;
|
|
|
|
int mAuxEffectId;
|
2009-03-04 03:31:44 +00:00
|
|
|
}; // end of Track
|
|
|
|
|
|
|
|
|
|
|
|
// playback track
|
|
|
|
class OutputTrack : public Track {
|
|
|
|
public:
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
class Buffer: public AudioBufferProvider::Buffer {
|
|
|
|
public:
|
|
|
|
int16_t *mBuffer;
|
|
|
|
};
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
OutputTrack( const wp<ThreadBase>& thread,
|
2009-12-18 13:47:48 +00:00
|
|
|
DuplicatingThread *sourceThread,
|
2009-03-04 03:31:44 +00:00
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount);
|
|
|
|
~OutputTrack();
|
|
|
|
|
|
|
|
virtual status_t start();
|
|
|
|
virtual void stop();
|
2009-07-17 19:17:14 +00:00
|
|
|
bool write(int16_t* data, uint32_t frames);
|
2009-03-04 03:31:44 +00:00
|
|
|
bool bufferQueueEmpty() { return (mBufferQueue.size() == 0) ? true : false; }
|
2009-07-17 19:17:14 +00:00
|
|
|
bool isActive() { return mActive; }
|
|
|
|
wp<ThreadBase>& thread() { return mThread; }
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
status_t obtainBuffer(AudioBufferProvider::Buffer* buffer, uint32_t waitTimeMs);
|
2009-03-04 03:31:44 +00:00
|
|
|
void clearBufferQueue();
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
// Maximum number of pending buffers allocated by OutputTrack::write()
|
2009-12-18 13:47:48 +00:00
|
|
|
static const uint8_t kMaxOverFlowBuffers = 10;
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
Vector < Buffer* > mBufferQueue;
|
|
|
|
AudioBufferProvider::Buffer mOutBuffer;
|
2009-07-17 19:17:14 +00:00
|
|
|
bool mActive;
|
2009-12-18 13:47:48 +00:00
|
|
|
DuplicatingThread* mSourceThread;
|
2009-07-17 19:17:14 +00:00
|
|
|
}; // end of OutputTrack
|
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
PlaybackThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device);
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual ~PlaybackThread();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
virtual status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
// Thread virtuals
|
|
|
|
virtual status_t readyToRun();
|
|
|
|
virtual void onFirstRef();
|
|
|
|
|
|
|
|
virtual uint32_t latency() const;
|
|
|
|
|
|
|
|
virtual status_t setMasterVolume(float value);
|
|
|
|
virtual status_t setMasterMute(bool muted);
|
|
|
|
|
|
|
|
virtual float masterVolume() const;
|
|
|
|
virtual bool masterMute() const;
|
|
|
|
|
|
|
|
virtual status_t setStreamVolume(int stream, float value);
|
|
|
|
virtual status_t setStreamMute(int stream, bool muted);
|
|
|
|
|
|
|
|
virtual float streamVolume(int stream) const;
|
|
|
|
virtual bool streamMute(int stream) const;
|
|
|
|
|
2010-01-25 16:49:09 +00:00
|
|
|
bool isStreamActive(int stream) const;
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-09 18:52:12 +00:00
|
|
|
sp<Track> createTrack_l(
|
2009-03-04 03:31:44 +00:00
|
|
|
const sp<AudioFlinger::Client>& client,
|
|
|
|
int streamType,
|
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount,
|
|
|
|
const sp<IMemory>& sharedBuffer,
|
2010-06-02 06:49:17 +00:00
|
|
|
int sessionId,
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t *status);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
AudioStreamOut* getOutput() { return mOutput; }
|
|
|
|
|
|
|
|
virtual int type() const { return mType; }
|
2009-08-06 15:49:39 +00:00
|
|
|
void suspend() { mSuspended++; }
|
|
|
|
void restore() { if (mSuspended) mSuspended--; }
|
2009-12-18 13:47:48 +00:00
|
|
|
bool isSuspended() { return (mSuspended != 0); }
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual String8 getParameters(const String8& keys);
|
2010-05-14 10:26:45 +00:00
|
|
|
virtual void audioConfigChanged_l(int event, int param = 0);
|
2010-01-20 01:37:09 +00:00
|
|
|
virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames);
|
2010-06-02 06:49:17 +00:00
|
|
|
int16_t *mixBuffer() { return mMixBuffer; };
|
|
|
|
|
|
|
|
sp<EffectHandle> createEffect_l(
|
|
|
|
const sp<AudioFlinger::Client>& client,
|
|
|
|
const sp<IEffectClient>& effectClient,
|
|
|
|
int32_t priority,
|
|
|
|
int sessionId,
|
|
|
|
effect_descriptor_t *desc,
|
|
|
|
int *enabled,
|
|
|
|
status_t *status);
|
2010-06-24 00:38:20 +00:00
|
|
|
void disconnectEffect(const sp< EffectModule>& effect,
|
|
|
|
const wp<EffectHandle>& handle);
|
2010-06-02 06:49:17 +00:00
|
|
|
|
|
|
|
bool hasAudioSession(int sessionId);
|
|
|
|
sp<EffectChain> getEffectChain(int sessionId);
|
|
|
|
sp<EffectChain> getEffectChain_l(int sessionId);
|
|
|
|
status_t addEffectChain_l(const sp<EffectChain>& chain);
|
|
|
|
size_t removeEffectChain_l(const sp<EffectChain>& chain);
|
|
|
|
void lockEffectChains_l();
|
|
|
|
void unlockEffectChains();
|
|
|
|
|
|
|
|
sp<AudioFlinger::EffectModule> getEffect_l(int sessionId, int effectId);
|
|
|
|
void detachAuxEffect_l(int effectId);
|
|
|
|
status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track, int EffectId);
|
|
|
|
status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track, int EffectId);
|
2010-06-24 00:38:20 +00:00
|
|
|
void setMode(uint32_t mode);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
struct stream_type_t {
|
|
|
|
stream_type_t()
|
|
|
|
: volume(1.0f),
|
|
|
|
mute(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
float volume;
|
|
|
|
bool mute;
|
|
|
|
};
|
|
|
|
|
2009-07-23 20:17:39 +00:00
|
|
|
protected:
|
|
|
|
int mType;
|
|
|
|
int16_t* mMixBuffer;
|
2009-08-06 15:49:39 +00:00
|
|
|
int mSuspended;
|
2009-07-23 20:17:39 +00:00
|
|
|
int mBytesWritten;
|
|
|
|
bool mMasterMute;
|
|
|
|
SortedVector< wp<Track> > mActiveTracks;
|
|
|
|
|
2009-10-06 03:29:18 +00:00
|
|
|
virtual int getTrackName_l() = 0;
|
|
|
|
virtual void deleteTrackName_l(int name) = 0;
|
2009-11-10 07:32:22 +00:00
|
|
|
virtual uint32_t activeSleepTimeUs() = 0;
|
|
|
|
virtual uint32_t idleSleepTimeUs() = 0;
|
2009-10-06 03:29:18 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
friend class AudioFlinger;
|
2009-08-11 06:22:32 +00:00
|
|
|
friend class OutputTrack;
|
2009-03-04 03:31:44 +00:00
|
|
|
friend class Track;
|
|
|
|
friend class TrackBase;
|
2009-07-17 19:17:14 +00:00
|
|
|
friend class MixerThread;
|
|
|
|
friend class DirectOutputThread;
|
|
|
|
friend class DuplicatingThread;
|
|
|
|
|
|
|
|
PlaybackThread(const Client&);
|
|
|
|
PlaybackThread& operator = (const PlaybackThread&);
|
|
|
|
|
2009-03-09 18:52:12 +00:00
|
|
|
status_t addTrack_l(const sp<Track>& track);
|
|
|
|
void destroyTrack_l(const sp<Track>& track);
|
2009-10-06 03:29:18 +00:00
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
void readOutputParameters();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
uint32_t device() { return mDevice; }
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual status_t dumpInternals(int fd, const Vector<String16>& args);
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t dumpTracks(int fd, const Vector<String16>& args);
|
2010-06-02 06:49:17 +00:00
|
|
|
status_t dumpEffectChains(int fd, const Vector<String16>& args);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
SortedVector< sp<Track> > mTracks;
|
2009-07-17 19:17:14 +00:00
|
|
|
// mStreamTypes[] uses 1 additionnal stream type internally for the OutputTrack used by DuplicatingThread
|
|
|
|
stream_type_t mStreamTypes[AudioSystem::NUM_STREAM_TYPES + 1];
|
2009-03-04 03:31:44 +00:00
|
|
|
AudioStreamOut* mOutput;
|
|
|
|
float mMasterVolume;
|
|
|
|
nsecs_t mLastWriteTime;
|
|
|
|
int mNumWrites;
|
|
|
|
int mNumDelayedWrites;
|
|
|
|
bool mInWrite;
|
2010-06-02 06:49:17 +00:00
|
|
|
Vector< sp<EffectChain> > mEffectChains;
|
|
|
|
uint32_t mDevice;
|
2009-07-17 19:17:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MixerThread : public PlaybackThread {
|
|
|
|
public:
|
2010-06-02 06:49:17 +00:00
|
|
|
MixerThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device);
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual ~MixerThread();
|
|
|
|
|
|
|
|
// Thread virtuals
|
|
|
|
virtual bool threadLoop();
|
|
|
|
|
2010-05-14 10:26:45 +00:00
|
|
|
void invalidateTracks(int streamType);
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual bool checkForNewParameters_l();
|
|
|
|
virtual status_t dumpInternals(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
protected:
|
2009-11-10 07:32:22 +00:00
|
|
|
uint32_t prepareTracks_l(const SortedVector< wp<Track> >& activeTracks, Vector< sp<Track> > *tracksToRemove);
|
2009-10-06 03:29:18 +00:00
|
|
|
virtual int getTrackName_l();
|
|
|
|
virtual void deleteTrackName_l(int name);
|
2009-11-10 07:32:22 +00:00
|
|
|
virtual uint32_t activeSleepTimeUs();
|
|
|
|
virtual uint32_t idleSleepTimeUs();
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
AudioMixer* mAudioMixer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DirectOutputThread : public PlaybackThread {
|
|
|
|
public:
|
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
DirectOutputThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device);
|
2009-07-17 19:17:14 +00:00
|
|
|
~DirectOutputThread();
|
|
|
|
|
|
|
|
// Thread virtuals
|
|
|
|
virtual bool threadLoop();
|
|
|
|
|
2009-10-06 03:29:18 +00:00
|
|
|
virtual bool checkForNewParameters_l();
|
|
|
|
|
|
|
|
protected:
|
2009-07-17 19:17:14 +00:00
|
|
|
virtual int getTrackName_l();
|
|
|
|
virtual void deleteTrackName_l(int name);
|
2009-11-10 07:32:22 +00:00
|
|
|
virtual uint32_t activeSleepTimeUs();
|
|
|
|
virtual uint32_t idleSleepTimeUs();
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
private:
|
2010-06-02 06:49:17 +00:00
|
|
|
void applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp);
|
|
|
|
|
|
|
|
float mLeftVolFloat;
|
|
|
|
float mRightVolFloat;
|
|
|
|
uint16_t mLeftVolShort;
|
|
|
|
uint16_t mRightVolShort;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
class DuplicatingThread : public MixerThread {
|
|
|
|
public:
|
2009-11-19 17:00:56 +00:00
|
|
|
DuplicatingThread (const sp<AudioFlinger>& audioFlinger, MixerThread* mainThread, int id);
|
2009-07-17 19:17:14 +00:00
|
|
|
~DuplicatingThread();
|
|
|
|
|
|
|
|
// Thread virtuals
|
|
|
|
virtual bool threadLoop();
|
|
|
|
void addOutputTrack(MixerThread* thread);
|
|
|
|
void removeOutputTrack(MixerThread* thread);
|
2009-12-18 13:47:48 +00:00
|
|
|
uint32_t waitTimeMs() { return mWaitTimeMs; }
|
|
|
|
protected:
|
|
|
|
virtual uint32_t activeSleepTimeUs();
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
private:
|
2009-12-18 13:47:48 +00:00
|
|
|
bool outputsReady(SortedVector< sp<OutputTrack> > &outputTracks);
|
|
|
|
void updateWaitTime();
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
SortedVector < sp<OutputTrack> > mOutputTracks;
|
2009-12-18 13:47:48 +00:00
|
|
|
uint32_t mWaitTimeMs;
|
2009-07-17 19:17:14 +00:00
|
|
|
};
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
PlaybackThread *checkPlaybackThread_l(int output) const;
|
|
|
|
MixerThread *checkMixerThread_l(int output) const;
|
|
|
|
RecordThread *checkRecordThread_l(int input) const;
|
2009-07-17 19:17:14 +00:00
|
|
|
float streamVolumeInternal(int stream) const { return mStreamTypes[stream].volume; }
|
2009-11-19 17:00:56 +00:00
|
|
|
void audioConfigChanged_l(int event, int ioHandle, void *param2);
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
int nextUniqueId();
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
friend class AudioBuffer;
|
|
|
|
|
|
|
|
class TrackHandle : public android::BnAudioTrack {
|
|
|
|
public:
|
2009-07-17 19:17:14 +00:00
|
|
|
TrackHandle(const sp<PlaybackThread::Track>& track);
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual ~TrackHandle();
|
|
|
|
virtual status_t start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual void flush();
|
|
|
|
virtual void mute(bool);
|
|
|
|
virtual void pause();
|
|
|
|
virtual void setVolume(float left, float right);
|
|
|
|
virtual sp<IMemory> getCblk() const;
|
2010-06-02 06:49:17 +00:00
|
|
|
virtual status_t attachAuxEffect(int effectId);
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual status_t onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
|
|
|
|
private:
|
2009-07-17 19:17:14 +00:00
|
|
|
sp<PlaybackThread::Track> mTrack;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
friend class Client;
|
2009-07-17 19:17:14 +00:00
|
|
|
friend class PlaybackThread::Track;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
2009-09-17 12:12:56 +00:00
|
|
|
void removeClient_l(pid_t pid);
|
2010-05-12 09:05:53 +00:00
|
|
|
void removeNotificationClient(pid_t pid);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
// record thread
|
|
|
|
class RecordThread : public ThreadBase, public AudioBufferProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// record track
|
|
|
|
class RecordTrack : public TrackBase {
|
|
|
|
public:
|
|
|
|
RecordTrack(const wp<ThreadBase>& thread,
|
|
|
|
const sp<Client>& client,
|
|
|
|
uint32_t sampleRate,
|
|
|
|
int format,
|
|
|
|
int channelCount,
|
|
|
|
int frameCount,
|
2010-06-02 06:49:17 +00:00
|
|
|
uint32_t flags,
|
|
|
|
int sessionId);
|
2009-07-17 19:17:14 +00:00
|
|
|
~RecordTrack();
|
|
|
|
|
|
|
|
virtual status_t start();
|
|
|
|
virtual void stop();
|
|
|
|
|
|
|
|
bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; }
|
|
|
|
bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; }
|
|
|
|
|
2009-11-07 08:01:32 +00:00
|
|
|
void dump(char* buffer, size_t size);
|
2009-07-17 19:17:14 +00:00
|
|
|
private:
|
|
|
|
friend class AudioFlinger;
|
2009-07-23 20:17:39 +00:00
|
|
|
friend class RecordThread;
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
RecordTrack(const RecordTrack&);
|
|
|
|
RecordTrack& operator = (const RecordTrack&);
|
|
|
|
|
|
|
|
virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
|
|
|
|
|
|
|
|
bool mOverflow;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RecordThread(const sp<AudioFlinger>& audioFlinger,
|
|
|
|
AudioStreamIn *input,
|
|
|
|
uint32_t sampleRate,
|
2009-11-19 17:00:56 +00:00
|
|
|
uint32_t channels,
|
|
|
|
int id);
|
2009-07-17 19:17:14 +00:00
|
|
|
~RecordThread();
|
|
|
|
|
|
|
|
virtual bool threadLoop();
|
|
|
|
virtual status_t readyToRun() { return NO_ERROR; }
|
|
|
|
virtual void onFirstRef();
|
|
|
|
|
|
|
|
status_t start(RecordTrack* recordTrack);
|
|
|
|
void stop(RecordTrack* recordTrack);
|
|
|
|
status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
AudioStreamIn* getInput() { return mInput; }
|
|
|
|
|
|
|
|
virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
|
|
|
|
virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer);
|
|
|
|
virtual bool checkForNewParameters_l();
|
|
|
|
virtual String8 getParameters(const String8& keys);
|
2010-05-14 10:26:45 +00:00
|
|
|
virtual void audioConfigChanged_l(int event, int param = 0);
|
2009-07-17 19:17:14 +00:00
|
|
|
void readInputParameters();
|
2010-02-26 10:47:27 +00:00
|
|
|
virtual unsigned int getInputFramesLost();
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
RecordThread();
|
|
|
|
AudioStreamIn *mInput;
|
|
|
|
sp<RecordTrack> mActiveTrack;
|
|
|
|
Condition mStartStopCond;
|
|
|
|
AudioResampler *mResampler;
|
|
|
|
int32_t *mRsmpOutBuffer;
|
|
|
|
int16_t *mRsmpInBuffer;
|
|
|
|
size_t mRsmpInIndex;
|
|
|
|
size_t mInputBytes;
|
|
|
|
int mReqChannelCount;
|
|
|
|
uint32_t mReqSampleRate;
|
2009-12-05 13:20:01 +00:00
|
|
|
ssize_t mBytesRead;
|
2009-07-17 19:17:14 +00:00
|
|
|
};
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
class RecordHandle : public android::BnAudioRecord {
|
|
|
|
public:
|
2009-07-17 19:17:14 +00:00
|
|
|
RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack);
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual ~RecordHandle();
|
|
|
|
virtual status_t start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual sp<IMemory> getCblk() const;
|
|
|
|
virtual status_t onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
|
|
|
|
private:
|
2009-07-17 19:17:14 +00:00
|
|
|
sp<RecordThread::RecordTrack> mRecordTrack;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
//--- Audio Effect Management
|
|
|
|
|
|
|
|
// EffectModule and EffectChain classes both have their own mutex to protect
|
|
|
|
// state changes or resource modifications. Always respect the following order
|
|
|
|
// if multiple mutexes must be acquired to avoid cross deadlock:
|
|
|
|
// AudioFlinger -> ThreadBase -> EffectChain -> EffectModule
|
|
|
|
|
|
|
|
// The EffectModule class is a wrapper object controlling the effect engine implementation
|
|
|
|
// in the effect library. It prevents concurrent calls to process() and command() functions
|
|
|
|
// from different client threads. It keeps a list of EffectHandle objects corresponding
|
|
|
|
// to all client applications using this effect and notifies applications of effect state,
|
|
|
|
// control or parameter changes. It manages the activation state machine to send appropriate
|
|
|
|
// reset, enable, disable commands to effect engine and provide volume
|
|
|
|
// ramping when effects are activated/deactivated.
|
|
|
|
// When controlling an auxiliary effect, the EffectModule also provides an input buffer used by
|
|
|
|
// the attached track(s) to accumulate their auxiliary channel.
|
|
|
|
class EffectModule: public RefBase {
|
|
|
|
public:
|
|
|
|
EffectModule(const wp<ThreadBase>& wThread,
|
|
|
|
const wp<AudioFlinger::EffectChain>& chain,
|
|
|
|
effect_descriptor_t *desc,
|
|
|
|
int id,
|
|
|
|
int sessionId);
|
|
|
|
~EffectModule();
|
|
|
|
|
|
|
|
enum effect_state {
|
|
|
|
IDLE,
|
|
|
|
RESET,
|
|
|
|
STARTING,
|
|
|
|
ACTIVE,
|
|
|
|
STOPPING,
|
|
|
|
STOPPED
|
|
|
|
};
|
|
|
|
|
|
|
|
int id() { return mId; }
|
|
|
|
void process();
|
|
|
|
status_t command(int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData);
|
|
|
|
|
2010-07-02 15:12:41 +00:00
|
|
|
void reset_l();
|
2010-06-02 06:49:17 +00:00
|
|
|
status_t configure();
|
|
|
|
status_t init();
|
|
|
|
uint32_t state() {
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
uint32_t status() {
|
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
status_t setEnabled(bool enabled);
|
|
|
|
bool isEnabled();
|
|
|
|
|
|
|
|
void setInBuffer(int16_t *buffer) { mConfig.inputCfg.buffer.s16 = buffer; }
|
|
|
|
int16_t *inBuffer() { return mConfig.inputCfg.buffer.s16; }
|
|
|
|
void setOutBuffer(int16_t *buffer) { mConfig.outputCfg.buffer.s16 = buffer; }
|
|
|
|
int16_t *outBuffer() { return mConfig.outputCfg.buffer.s16; }
|
|
|
|
|
|
|
|
status_t addHandle(sp<EffectHandle>& handle);
|
|
|
|
void disconnect(const wp<EffectHandle>& handle);
|
|
|
|
size_t removeHandle (const wp<EffectHandle>& handle);
|
|
|
|
|
|
|
|
effect_descriptor_t& desc() { return mDescriptor; }
|
2010-06-24 00:38:20 +00:00
|
|
|
wp<EffectChain>& chain() { return mChain; }
|
2010-06-02 06:49:17 +00:00
|
|
|
|
|
|
|
status_t setDevice(uint32_t device);
|
|
|
|
status_t setVolume(uint32_t *left, uint32_t *right, bool controller);
|
2010-06-24 00:38:20 +00:00
|
|
|
status_t setMode(uint32_t mode);
|
2010-06-02 06:49:17 +00:00
|
|
|
|
|
|
|
status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
EffectModule(const EffectModule&);
|
|
|
|
EffectModule& operator = (const EffectModule&);
|
|
|
|
|
2010-07-02 15:12:41 +00:00
|
|
|
status_t start_l();
|
|
|
|
status_t stop_l();
|
2010-06-02 06:49:17 +00:00
|
|
|
|
2010-06-24 00:38:20 +00:00
|
|
|
// update this table when AudioSystem::audio_devices or audio_device_e (in EffectApi.h) are modified
|
|
|
|
static const uint32_t sDeviceConvTable[];
|
|
|
|
static uint32_t deviceAudioSystemToEffectApi(uint32_t device);
|
|
|
|
|
|
|
|
// update this table when AudioSystem::audio_mode or audio_mode_e (in EffectApi.h) are modified
|
|
|
|
static const uint32_t sModeConvTable[];
|
|
|
|
static int modeAudioSystemToEffectApi(uint32_t mode);
|
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
Mutex mLock; // mutex for process, commands and handles list protection
|
|
|
|
wp<ThreadBase> mThread; // parent thread
|
|
|
|
wp<EffectChain> mChain; // parent effect chain
|
|
|
|
int mId; // this instance unique ID
|
|
|
|
int mSessionId; // audio session ID
|
|
|
|
effect_descriptor_t mDescriptor;// effect descriptor received from effect engine
|
|
|
|
effect_config_t mConfig; // input and output audio configuration
|
|
|
|
effect_interface_t mEffectInterface; // Effect module C API
|
|
|
|
status_t mStatus; // initialization status
|
|
|
|
uint32_t mState; // current activation state (effect_state)
|
|
|
|
Vector< wp<EffectHandle> > mHandles; // list of client handles
|
|
|
|
};
|
|
|
|
|
|
|
|
// The EffectHandle class implements the IEffect interface. It provides resources
|
|
|
|
// to receive parameter updates, keeps track of effect control
|
|
|
|
// ownership and state and has a pointer to the EffectModule object it is controlling.
|
|
|
|
// There is one EffectHandle object for each application controlling (or using)
|
|
|
|
// an effect module.
|
|
|
|
// The EffectHandle is obtained by calling AudioFlinger::createEffect().
|
|
|
|
class EffectHandle: public android::BnEffect {
|
|
|
|
public:
|
|
|
|
|
|
|
|
EffectHandle(const sp<EffectModule>& effect,
|
|
|
|
const sp<AudioFlinger::Client>& client,
|
|
|
|
const sp<IEffectClient>& effectClient,
|
|
|
|
int32_t priority);
|
|
|
|
virtual ~EffectHandle();
|
|
|
|
|
|
|
|
// IEffect
|
|
|
|
virtual status_t enable();
|
|
|
|
virtual status_t disable();
|
|
|
|
virtual status_t command(int cmdCode, int cmdSize, void *pCmdData, int *replySize, void *pReplyData);
|
|
|
|
virtual void disconnect();
|
|
|
|
virtual sp<IMemory> getCblk() const;
|
|
|
|
virtual status_t onTransact(uint32_t code, const Parcel& data,
|
|
|
|
Parcel* reply, uint32_t flags);
|
|
|
|
|
|
|
|
|
|
|
|
// Give or take control of effect module
|
|
|
|
void setControl(bool hasControl, bool signal);
|
|
|
|
void commandExecuted(int cmdCode, int cmdSize, void *pCmdData, int replySize, void *pReplyData);
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
int id() { return mEffect->id(); }
|
|
|
|
int priority() { return mPriority; }
|
|
|
|
bool hasControl() { return mHasControl; }
|
|
|
|
sp<EffectModule> effect() { return mEffect; }
|
|
|
|
|
|
|
|
void dump(char* buffer, size_t size);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
EffectHandle(const EffectHandle&);
|
|
|
|
EffectHandle& operator =(const EffectHandle&);
|
|
|
|
|
|
|
|
sp<EffectModule> mEffect; // pointer to controlled EffectModule
|
|
|
|
sp<IEffectClient> mEffectClient; // callback interface for client notifications
|
|
|
|
sp<Client> mClient; // client for shared memory allocation
|
|
|
|
sp<IMemory> mCblkMemory; // shared memory for control block
|
|
|
|
effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory
|
|
|
|
uint8_t* mBuffer; // pointer to parameter area in shared memory
|
|
|
|
int mPriority; // client application priority to control the effect
|
|
|
|
bool mHasControl; // true if this handle is controlling the effect
|
|
|
|
};
|
|
|
|
|
|
|
|
// the EffectChain class represents a group of effects associated to one audio session.
|
|
|
|
// There can be any number of EffectChain objects per output mixer thread (PlaybackThread).
|
|
|
|
// The EffecChain with session ID 0 contains global effects applied to the output mix.
|
|
|
|
// Effects in this chain can be insert or auxiliary. Effects in other chains (attached to tracks)
|
|
|
|
// are insert only. The EffectChain maintains an ordered list of effect module, the order corresponding
|
|
|
|
// in the effect process order. When attached to a track (session ID != 0), it also provide it's own
|
|
|
|
// input buffer used by the track as accumulation buffer.
|
|
|
|
class EffectChain: public RefBase {
|
|
|
|
public:
|
|
|
|
EffectChain(const wp<ThreadBase>& wThread, int sessionId);
|
|
|
|
~EffectChain();
|
|
|
|
|
|
|
|
void process_l();
|
|
|
|
|
|
|
|
void lock() {
|
|
|
|
mLock.lock();
|
|
|
|
}
|
|
|
|
void unlock() {
|
|
|
|
mLock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t addEffect(sp<EffectModule>& handle);
|
|
|
|
size_t removeEffect(const sp<EffectModule>& handle);
|
|
|
|
|
|
|
|
int sessionId() {
|
|
|
|
return mSessionId;
|
|
|
|
}
|
|
|
|
sp<EffectModule> getEffectFromDesc(effect_descriptor_t *descriptor);
|
|
|
|
sp<EffectModule> getEffectFromId(int id);
|
|
|
|
sp<EffectModule> getVolumeController();
|
|
|
|
bool setVolume(uint32_t *left, uint32_t *right);
|
|
|
|
void setDevice(uint32_t device);
|
2010-06-24 00:38:20 +00:00
|
|
|
void setMode(uint32_t mode);
|
|
|
|
|
2010-06-02 06:49:17 +00:00
|
|
|
|
|
|
|
void setInBuffer(int16_t *buffer, bool ownsBuffer = false) {
|
|
|
|
mInBuffer = buffer;
|
|
|
|
mOwnInBuffer = ownsBuffer;
|
|
|
|
}
|
|
|
|
int16_t *inBuffer() {
|
|
|
|
return mInBuffer;
|
|
|
|
}
|
|
|
|
void setOutBuffer(int16_t *buffer) {
|
|
|
|
mOutBuffer = buffer;
|
|
|
|
}
|
|
|
|
int16_t *outBuffer() {
|
|
|
|
return mOutBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void startTrack() {mActiveTrackCnt++;}
|
|
|
|
void stopTrack() {mActiveTrackCnt--;}
|
|
|
|
int activeTracks() { return mActiveTrackCnt;}
|
|
|
|
|
|
|
|
status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
EffectChain(const EffectChain&);
|
|
|
|
EffectChain& operator =(const EffectChain&);
|
|
|
|
|
|
|
|
wp<ThreadBase> mThread; // parent mixer thread
|
|
|
|
Mutex mLock; // mutex protecting effect list
|
|
|
|
Vector<sp<EffectModule> > mEffects; // list of effect modules
|
|
|
|
int mSessionId; // audio session ID
|
|
|
|
int16_t *mInBuffer; // chain input buffer
|
|
|
|
int16_t *mOutBuffer; // chain output buffer
|
|
|
|
int mVolumeCtrlIdx; // index of insert effect having control over volume
|
|
|
|
int mActiveTrackCnt; // number of active tracks connected
|
|
|
|
bool mOwnInBuffer; // true if the chain owns its input buffer
|
|
|
|
};
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
friend class RecordThread;
|
|
|
|
friend class PlaybackThread;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
2009-03-09 18:52:12 +00:00
|
|
|
mutable Mutex mLock;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
DefaultKeyedVector< pid_t, wp<Client> > mClients;
|
|
|
|
|
2009-07-17 19:17:14 +00:00
|
|
|
mutable Mutex mHardwareLock;
|
2009-03-04 03:31:44 +00:00
|
|
|
AudioHardwareInterface* mAudioHardware;
|
|
|
|
mutable int mHardwareStatus;
|
2009-07-17 19:17:14 +00:00
|
|
|
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
DefaultKeyedVector< int, sp<PlaybackThread> > mPlaybackThreads;
|
2009-07-17 19:17:14 +00:00
|
|
|
PlaybackThread::stream_type_t mStreamTypes[AudioSystem::NUM_STREAM_TYPES];
|
|
|
|
float mMasterVolume;
|
|
|
|
bool mMasterMute;
|
|
|
|
|
2009-07-28 15:44:33 +00:00
|
|
|
DefaultKeyedVector< int, sp<RecordThread> > mRecordThreads;
|
2009-07-17 19:17:14 +00:00
|
|
|
|
2010-05-12 09:05:53 +00:00
|
|
|
DefaultKeyedVector< pid_t, sp<NotificationClient> > mNotificationClients;
|
2010-06-02 06:49:17 +00:00
|
|
|
volatile int32_t mNextUniqueId;
|
2010-05-12 09:05:53 +00:00
|
|
|
#ifdef LVMX
|
|
|
|
int mLifeVibesClientPid;
|
|
|
|
#endif
|
2010-06-24 00:38:20 +00:00
|
|
|
uint32_t mMode;
|
|
|
|
|
|
|
|
// Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
|
|
|
|
static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
|
|
|
|
// Maximum memory allocated to audio effects in KB
|
|
|
|
static const uint32_t MAX_EFFECTS_MEMORY = 512;
|
|
|
|
uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects
|
|
|
|
uint32_t mTotalEffectsMemory; // current memory used by effects
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_AUDIO_FLINGER_H
|