AudioFlinger.h revision 335787fe43596f38ea2fa50b24c54d0823a3fb1d
165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/* //device/include/server/AudioFlinger/AudioFlinger.h
265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Copyright 2007, The Android Open Source Project
465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License");
665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** you may not use this file except in compliance with the License.
765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** You may obtain a copy of the License at
865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**     http://www.apache.org/licenses/LICENSE-2.0
1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian**
1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Unless required by applicable law or agreed to in writing, software
1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS,
1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** See the License for the specific language governing permissions and
1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** limitations under the License.
1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian*/
1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#ifndef ANDROID_AUDIO_FLINGER_H
1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define ANDROID_AUDIO_FLINGER_H
2065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <stdint.h>
2265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/types.h>
2365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <limits.h>
2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioFlinger.h>
2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioFlingerClient.h>
2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioTrack.h>
2865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioRecord.h>
29335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten#include <media/AudioSystem.h>
3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Atomic.h>
3265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Errors.h>
3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/threads.h>
3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/SortedVector.h>
35799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin#include <utils/TypeHelpers.h>
3665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Vector.h>
3765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
385462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian#include <binder/BinderService.h>
395462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian#include <binder/MemoryDealer.h>
405462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian
4164760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h>
427394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <hardware/audio.h>
4365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioBufferProvider.h"
4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
46feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent#include <powermanager/IPowerManager.h>
47feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android {
4965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass audio_track_cblk_t;
5165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass effect_param_cblk_t;
5265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioMixer;
5365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioBuffer;
5465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioResampler;
5565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------------------------------------------------------------------------
5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic const nsecs_t kStandbyTimeInNsecs = seconds(3);
5965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
605462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopianclass AudioFlinger :
615462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    public BinderService<AudioFlinger>,
625462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    public BnAudioFlinger
6365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
645462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    friend class BinderService<AudioFlinger>;
6565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianpublic:
6654c3b66444ebfb9f2265ee70ac3b76ccefa0506aGlenn Kasten    static const char* getServiceName() { return "media.audio_flinger"; }
6765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
6865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    dump(int fd, const Vector<String16>& args);
6965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
7065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // IAudioFlinger interface
7165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual sp<IAudioTrack> createTrack(
7265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                pid_t pid,
73fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                                audio_stream_type_t streamType,
7465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t sampleRate,
7558f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                audio_format_t format,
760d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                uint32_t channelMask,
7765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int frameCount,
7865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t flags,
7965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                const sp<IMemory>& sharedBuffer,
8065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int output,
8165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int *sessionId,
8265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                status_t *status);
8365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
8465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     uint32_t    sampleRate(int output) const;
8565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     int         channelCount(int output) const;
8658f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten    virtual     audio_format_t format(int output) const;
8765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     size_t      frameCount(int output) const;
8865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     uint32_t    latency(int output) const;
8965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
9065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setMasterVolume(float value);
9165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setMasterMute(bool muted);
9265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
9365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     float       masterVolume() const;
9465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     bool        masterMute() const;
9565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
96fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual     status_t    setStreamVolume(audio_stream_type_t stream, float value, int output);
97fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual     status_t    setStreamMute(audio_stream_type_t stream, bool muted);
9865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
99fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual     float       streamVolume(audio_stream_type_t stream, int output) const;
100fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual     bool        streamMute(audio_stream_type_t stream) const;
10165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
102f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten    virtual     status_t    setMode(audio_mode_t mode);
10365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
10465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setMicMute(bool state);
10565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     bool        getMicMute() const;
10665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
10765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setParameters(int ioHandle, const String8& keyValuePairs);
10865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     String8     getParameters(int ioHandle, const String8& keys);
10965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
11065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     void        registerClient(const sp<IAudioFlingerClient>& client);
11165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
11258f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten    virtual     size_t      getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount);
11365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     unsigned int  getInputFramesLost(int ioHandle);
11465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
11565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual int openOutput(uint32_t *pDevices,
11665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t *pSamplingRate,
11758f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                    audio_format_t *pFormat,
11865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t *pChannels,
11965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t *pLatencyMs,
12065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t flags);
12165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual int openDuplicateOutput(int output1, int output2);
12365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t closeOutput(int output);
12565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t suspendOutput(int output);
12765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t restoreOutput(int output);
12965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual int openInput(uint32_t *pDevices,
13165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            uint32_t *pSamplingRate,
13258f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                            audio_format_t *pFormat,
13365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            uint32_t *pChannels,
13465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            uint32_t acoustics);
13565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t closeInput(int input);
13765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
138fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual status_t setStreamOutput(audio_stream_type_t stream, int output);
13965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t setVoiceVolume(float volume);
14165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output);
14365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual int newAudioSessionId();
14565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1463a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    virtual void acquireAudioSessionId(int audioSession);
1473a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen
1483a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    virtual void releaseAudioSessionId(int audioSession);
1493a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen
15065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t queryNumberEffects(uint32_t *numEffects);
15165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
15265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor);
15365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
15465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *descriptor);
15565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
15665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual sp<IEffect> createEffect(pid_t pid,
15765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        effect_descriptor_t *pDesc,
15865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        const sp<IEffectClient>& effectClient,
15965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int32_t priority,
1607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        int io,
16165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int sessionId,
16265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        status_t *status,
16365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int *id,
16465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int *enabled);
16565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent    virtual status_t moveEffects(int sessionId, int srcOutput, int dstOutput);
16765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    enum hardware_call_state {
16965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_IDLE = 0,
17065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_INIT,
17165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_OUTPUT_OPEN,
17265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_OUTPUT_CLOSE,
17365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_INPUT_OPEN,
17465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_INPUT_CLOSE,
17565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_STANDBY,
17665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_SET_MASTER_VOLUME,
17765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_GET_ROUTING,
17865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_SET_ROUTING,
17965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_GET_MODE,
18065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_SET_MODE,
18165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_GET_MIC_MUTE,
18265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_HW_SET_MIC_MUTE,
18365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_SET_VOICE_VOLUME,
18465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AUDIO_SET_PARAMETER,
18565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
18665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
18765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // record interface
18865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual sp<IAudioRecord> openRecord(
18965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                pid_t pid,
19065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int input,
19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t sampleRate,
19258f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                audio_format_t format,
1930d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                uint32_t channelMask,
19465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int frameCount,
19565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t flags,
19665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int *sessionId,
19765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                status_t *status);
19865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
19965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    onTransact(
20065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t code,
20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                const Parcel& data,
20265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Parcel* reply,
20365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t flags);
20465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
205f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten               audio_mode_t getMode() const { return mMode; }
20665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
207bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent                bool        btNrecIsOff() { return mBtNrecIsOff; }
20859bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent
20965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianprivate:
210335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten
21165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            AudioFlinger();
21265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual                 ~AudioFlinger();
21365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2145a61d2f277af3098fc10b2881babca16391362daDima Zavin    status_t                initCheck() const;
2155a61d2f277af3098fc10b2881babca16391362daDima Zavin    virtual     void        onFirstRef();
216799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    audio_hw_device_t*      findSuitableHwDev_l(uint32_t devices);
2173a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    void                    purgeStaleEffects_l();
21865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
21965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // Internal dump utilites.
22065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    status_t dumpPermissionDenial(int fd, const Vector<String16>& args);
22165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    status_t dumpClients(int fd, const Vector<String16>& args);
22265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    status_t dumpInternals(int fd, const Vector<String16>& args);
22365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
22465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // --- Client ---
22565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class Client : public RefBase {
22665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
22765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            Client(const sp<AudioFlinger>& audioFlinger, pid_t pid);
22865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~Client();
22965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        const sp<MemoryDealer>&     heap() const;
23065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        pid_t               pid() const { return mPid; }
23165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<AudioFlinger>    audioFlinger() { return mAudioFlinger; }
23265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
23365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
23465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            Client(const Client&);
23565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            Client& operator = (const Client&);
23665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<AudioFlinger>    mAudioFlinger;
23765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<MemoryDealer>    mMemoryDealer;
23865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        pid_t               mPid;
23965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
24065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
24165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // --- Notification Client ---
24265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class NotificationClient : public IBinder::DeathRecipient {
24365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
24465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            NotificationClient(const sp<AudioFlinger>& audioFlinger,
24565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                                const sp<IAudioFlingerClient>& client,
24665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                                pid_t pid);
24765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~NotificationClient();
24865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
24965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                sp<IAudioFlingerClient>    client() { return mClient; }
25065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
25165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                // IBinder::DeathRecipient
25265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                virtual     void        binderDied(const wp<IBinder>& who);
25365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
25465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
25565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            NotificationClient(const NotificationClient&);
25665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            NotificationClient& operator = (const NotificationClient&);
25765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
25865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<AudioFlinger>        mAudioFlinger;
25965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        pid_t                   mPid;
26065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<IAudioFlingerClient> mClient;
26165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
26265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
26365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class TrackHandle;
26465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordHandle;
26565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordThread;
26665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class PlaybackThread;
26765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class MixerThread;
26865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class DirectOutputThread;
26965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class DuplicatingThread;
27065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class Track;
27165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordTrack;
27265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectModule;
27365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectHandle;
27465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectChain;
275799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    struct AudioStreamOut;
276799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    struct AudioStreamIn;
27765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
27865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class ThreadBase : public Thread {
27965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
2807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        ThreadBase (const sp<AudioFlinger>& audioFlinger, int id, uint32_t device);
28165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~ThreadBase();
28265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        enum type {
2857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            MIXER,              // Thread class is MixerThread
2867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            DIRECT,             // Thread class is DirectOutputThread
2877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            DUPLICATING,        // Thread class is DuplicatingThread
2887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            RECORD              // Thread class is RecordThread
2897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        };
2907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
29165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t dumpBase(int fd, const Vector<String16>& args);
2921d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent        status_t dumpEffectChains(int fd, const Vector<String16>& args);
29365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
294feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        void clearPowerManager();
295feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
29665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // base for record and playback
29765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class TrackBase : public AudioBufferProvider, public RefBase {
29865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
29965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
30065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            enum track_state {
30165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                IDLE,
30265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                TERMINATED,
30365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                STOPPED,
30465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                RESUMING,
30565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                ACTIVE,
30665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                PAUSING,
30765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                PAUSED
30865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            };
30965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
31065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            enum track_flags {
31165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                STEPSERVER_FAILED = 0x01, //  StepServer could not acquire cblk->lock mutex
31265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                SYSTEM_FLAGS_MASK = 0x0000ffffUL,
31365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                // The upper 16 bits are used for track-specific flags.
31465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            };
31565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
31665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                TrackBase(const wp<ThreadBase>& thread,
31765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<Client>& client,
31865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t sampleRate,
31958f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                        audio_format_t format,
3200d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                        uint32_t channelMask,
32165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int frameCount,
32265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t flags,
32365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<IMemory>& sharedBuffer,
32465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int sessionId);
32565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                ~TrackBase();
32665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
32765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t    start() = 0;
32865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void        stop() = 0;
32965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    sp<IMemory> getCblk() const;
33065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    audio_track_cblk_t* cblk() const { return mCblk; }
33165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int         sessionId() { return mSessionId; }
33265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
33365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        protected:
33465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class ThreadBase;
33565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class RecordHandle;
33665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class PlaybackThread;
33765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class RecordThread;
33865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class MixerThread;
33965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class DirectOutputThread;
34065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
34165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                TrackBase(const TrackBase&);
34265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                TrackBase& operator = (const TrackBase&);
34365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
34465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0;
34565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer);
34665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
34758f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten            audio_format_t format() const {
34865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mFormat;
34965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
35065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
35165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int channelCount() const ;
35265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3530d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi            uint32_t channelMask() const;
3540d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi
35565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int sampleRate() const;
35665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
35765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void* getBuffer(uint32_t offset, uint32_t frames) const;
35865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
35965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isStopped() const {
36065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mState == STOPPED;
36165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
36265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
36365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isTerminated() const {
36465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mState == TERMINATED;
36565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
36665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
36765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool step();
36865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void reset();
36965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
37065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            wp<ThreadBase>      mThread;
37165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            sp<Client>          mClient;
37265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            sp<IMemory>         mCblkMemory;
37365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            audio_track_cblk_t* mCblk;
37465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void*               mBuffer;
37565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void*               mBufferEnd;
37665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            uint32_t            mFrameCount;
37765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            // we don't really need a lock for these
37865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int                 mState;
37965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int                 mClientTid;
38058f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten            audio_format_t      mFormat;
38165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            uint32_t            mFlags;
38265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int                 mSessionId;
3830d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi            uint8_t             mChannelCount;
3840d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi            uint32_t            mChannelMask;
38565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
38665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
38765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class ConfigEvent {
38865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
38965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            ConfigEvent() : mEvent(0), mParam(0) {}
39065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
39165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int mEvent;
39265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int mParam;
39365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
39465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
395feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        class PMDeathRecipient : public IBinder::DeathRecipient {
396feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        public:
397feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                        PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {}
398feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            virtual     ~PMDeathRecipient() {}
399feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
400feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            // IBinder::DeathRecipient
401feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            virtual     void        binderDied(const wp<IBinder>& who);
402feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
403feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        private:
404feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                        PMDeathRecipient(const PMDeathRecipient&);
405feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                        PMDeathRecipient& operator = (const PMDeathRecipient&);
406feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
407feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            wp<ThreadBase> mThread;
408feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        };
409feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
4107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     status_t    initCheck() const = 0;
4117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    int         type() const { return mType; }
41265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    uint32_t    sampleRate() const;
41365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int         channelCount() const;
41458f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                    audio_format_t format() const;
41565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    size_t      frameCount() const;
41665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        wakeUp()    { mWaitWorkCV.broadcast(); }
41765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        exit();
41865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        checkForNewParameters_l() = 0;
41965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    setParameters(const String8& keyValuePairs);
42065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     String8     getParameters(const String8& keys) = 0;
42165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        audioConfigChanged_l(int event, int param = 0) = 0;
42265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        sendConfigEvent(int event, int param = 0);
42365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        sendConfigEvent_l(int event, int param = 0);
42465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        processConfigEvents();
42565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int         id() const { return mId;}
42665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        standby() { return mStandby; }
4277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    uint32_t    device() { return mDevice; }
4287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     audio_stream_t* stream() = 0;
4297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
4307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<EffectHandle> createEffect_l(
4317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        const sp<AudioFlinger::Client>& client,
4327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        const sp<IEffectClient>& effectClient,
4337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        int32_t priority,
4347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        int sessionId,
4357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        effect_descriptor_t *desc,
4367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        int *enabled,
4377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        status_t *status);
4387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    void disconnectEffect(const sp< EffectModule>& effect,
4393a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen                                          const wp<EffectHandle>& handle,
4403a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen                                          bool unpiniflast);
4417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
4427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // return values for hasAudioSession (bit field)
4437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    enum effect_state {
4447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        EFFECT_SESSION = 0x1,   // the audio session corresponds to at least one
4457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                                // effect
4467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        TRACK_SESSION = 0x2     // the audio session corresponds to at least one
4477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                                // track
4487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    };
4497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
4507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // get effect chain corresponding to session Id.
4517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<EffectChain> getEffectChain(int sessionId);
4527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // same as getEffectChain() but must be called with ThreadBase mutex locked
4537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<EffectChain> getEffectChain_l(int sessionId);
4547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // add an effect chain to the chain list (mEffectChains)
4557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     status_t addEffectChain_l(const sp<EffectChain>& chain) = 0;
4567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // remove an effect chain from the chain list (mEffectChains)
4577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     size_t removeEffectChain_l(const sp<EffectChain>& chain) = 0;
4587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // lock mall effect chains Mutexes. Must be called before releasing the
4597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // ThreadBase mutex before processing the mixer and effects. This guarantees the
4607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // integrity of the chains during the process.
4617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    void lockEffectChains_l(Vector<sp <EffectChain> >& effectChains);
4627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // unlock effect chains after process
4637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    void unlockEffectChains(Vector<sp <EffectChain> >& effectChains);
4647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // set audio mode to all effect chains
465f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten                    void setMode(audio_mode_t mode);
4667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // get effect module with corresponding ID on specified audio session
4677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<AudioFlinger::EffectModule> getEffect_l(int sessionId, int effectId);
4687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // add and effect module. Also creates the effect chain is none exists for
4697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // the effects audio session
4707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    status_t addEffect_l(const sp< EffectModule>& effect);
4717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // remove and effect module. Also removes the effect chain is this was the last
4727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // effect
4737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    void removeEffect_l(const sp< EffectModule>& effect);
4747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // detach all tracks connected to an auxiliary effect
4757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     void detachAuxEffect_l(int effectId) {}
4767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // returns either EFFECT_SESSION if effects on this audio session exist in one
4777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // chain, or TRACK_SESSION if tracks on this audio session exist, or both
4787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    virtual uint32_t hasAudioSession(int sessionId) = 0;
4797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // the value returned by default implementation is not important as the
4807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // strategy is only meaningful for PlaybackThread which implements this method
4817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    virtual uint32_t getStrategyForSession_l(int sessionId) { return 0; }
48265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
48359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // suspend or restore effect according to the type of effect passed. a NULL
48459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // type pointer means suspend all effects in the session
48559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    void setEffectSuspended(const effect_uuid_t *type,
48659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                            bool suspend,
48759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                            int sessionId = AUDIO_SESSION_OUTPUT_MIX);
48859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // check if some effects must be suspended/restored when an effect is enabled
48959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // or disabled
490a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent                    void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect,
49159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                                     bool enabled,
49259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                                     int sessionId = AUDIO_SESSION_OUTPUT_MIX);
493a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent                    void checkSuspendOnEffectEnabled_l(const sp<EffectModule>& effect,
494a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent                                                       bool enabled,
495a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent                                                       int sessionId = AUDIO_SESSION_OUTPUT_MIX);
49665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        mutable     Mutex                   mLock;
49765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
49865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
49965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
50059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // entry describing an effect being suspended in mSuspendedSessions keyed vector
50159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    class SuspendedSessionDesc : public RefBase {
50259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    public:
50359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                        SuspendedSessionDesc() : mRefCount(0) {}
50459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
50559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                        int mRefCount;          // number of active suspend requests
50659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                        effect_uuid_t mType;    // effect type UUID
50759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    };
50859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
509feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    void        acquireWakeLock();
510feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    void        acquireWakeLock_l();
511feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    void        releaseWakeLock();
512feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    void        releaseWakeLock_l();
51359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    void setEffectSuspended_l(const effect_uuid_t *type,
51459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                              bool suspend,
51559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                              int sessionId = AUDIO_SESSION_OUTPUT_MIX);
51659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // updated mSuspendedSessions when an effect suspended or restored
51759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    void        updateSuspendedSessions_l(const effect_uuid_t *type,
51859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                                          bool suspend,
51959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                                          int sessionId);
52059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // check if some effects must be suspended when an effect chain is added
52159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    void checkSuspendOnAddEffectChain_l(const sp<EffectChain>& chain);
522feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
5233a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        friend class AudioFlinger;
52465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class Track;
52565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class TrackBase;
52665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class PlaybackThread;
52765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class MixerThread;
52865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class DirectOutputThread;
52965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class DuplicatingThread;
53065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class RecordThread;
53165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class RecordTrack;
53265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    int                     mType;
53465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    Condition               mWaitWorkCV;
53565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    sp<AudioFlinger>        mAudioFlinger;
53665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    uint32_t                mSampleRate;
53765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    size_t                  mFrameCount;
5380d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                    uint32_t                mChannelMask;
53965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    uint16_t                mChannelCount;
540b9980659501d0428d65d8292f3c32da69d37fbd2Glenn Kasten                    size_t                  mFrameSize;
54158f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                    audio_format_t          mFormat;
54265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    Condition               mParamCond;
54365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    Vector<String8>         mNewParameters;
54465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    status_t                mParamStatus;
545f3990f2cc8fd824ae52a880a7b22248e1bdfb192Glenn Kasten                    Vector<ConfigEvent>     mConfigEvents;
54665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool                    mStandby;
54765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int                     mId;
54865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool                    mExiting;
5497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    Vector< sp<EffectChain> > mEffectChains;
5507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    uint32_t                mDevice;    // output device for PlaybackThread
5517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                                        // input + output devices for RecordThread
552feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    static const int        kNameLength = 32;
553feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    char                    mName[kNameLength];
554feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    sp<IPowerManager>       mPowerManager;
555feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    sp<IBinder>             mWakeLockToken;
556feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                    sp<PMDeathRecipient>    mDeathRecipient;
55759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // list of suspended effects per session and per type. The first vector is
55859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    // keyed by session ID, the second by type UUID timeLow field
55959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                    KeyedVector< int, KeyedVector< int, sp<SuspendedSessionDesc> > >  mSuspendedSessions;
56065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
56165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
56265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // --- PlaybackThread ---
56365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class PlaybackThread : public ThreadBase {
56465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
56565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
56665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        enum mixer_state {
56765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            MIXER_IDLE,
56865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            MIXER_TRACKS_ENABLED,
56965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            MIXER_TRACKS_READY
57065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
57165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
57265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // playback track
57365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class Track : public TrackBase {
57465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
57565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Track(  const wp<ThreadBase>& thread,
57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<Client>& client,
577fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                                        audio_stream_type_t streamType,
57865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t sampleRate,
57958f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                        audio_format_t format,
5800d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                        uint32_t channelMask,
58165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int frameCount,
58265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<IMemory>& sharedBuffer,
58365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int sessionId);
58465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                ~Track();
58565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
58665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        dump(char* buffer, size_t size);
58765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t    start();
58865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void        stop();
58965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        pause();
59065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
59165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        flush();
59265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        destroy();
59365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        mute(bool);
59465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int name() const {
59565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        return mName;
59665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    }
59765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
598fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                    audio_stream_type_t type() const {
59965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        return mStreamType;
60065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    }
60165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    status_t    attachAuxEffect(int EffectId);
60265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        setAuxBuffer(int EffectId, int32_t *buffer);
60365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int32_t     *auxBuffer() { return mAuxBuffer; }
60465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        setMainBuffer(int16_t *buffer) { mMainBuffer = buffer; }
60565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int16_t     *mainBuffer() { return mMainBuffer; }
60665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int         auxEffectId() { return mAuxEffectId; }
60765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
60865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
60965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        protected:
61065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class ThreadBase;
61165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class TrackHandle;
61265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class PlaybackThread;
61365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class MixerThread;
61465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class DirectOutputThread;
61565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
61665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Track(const Track&);
61765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Track& operator = (const Track&);
61865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
61965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
62065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isMuted() { return mMute; }
62165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isPausing() const {
62265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mState == PAUSING;
62365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
62465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isPaused() const {
62565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mState == PAUSED;
62665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
62765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isReady() const;
62865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void setPaused() { mState = PAUSED; }
62965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void reset();
63065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
63165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isOutputTrack() const {
632fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                return (mStreamType == AUDIO_STREAM_CNT);
63365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
63465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
63565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            // we don't really need a lock for these
63665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            volatile bool       mMute;
63765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            // FILLED state is used for suppressing volume ramp at begin of playing
63865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            enum {FS_FILLING, FS_FILLED, FS_ACTIVE};
63965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mutable uint8_t     mFillingUpStatus;
64065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int8_t              mRetryCount;
64165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            sp<IMemory>         mSharedBuffer;
64265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool                mResetDone;
643fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten            audio_stream_type_t mStreamType;
64465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int                 mName;
64565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int16_t             *mMainBuffer;
64665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int32_t             *mAuxBuffer;
64765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int                 mAuxEffectId;
6488f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            bool                mHasVolumeController;
64965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };  // end of Track
65065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
65165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
65265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // playback track
65365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class OutputTrack : public Track {
65465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
65565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
65665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            class Buffer: public AudioBufferProvider::Buffer {
65765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            public:
65865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                int16_t *mBuffer;
65965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            };
66065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
66165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                OutputTrack(  const wp<ThreadBase>& thread,
66265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        DuplicatingThread *sourceThread,
66365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t sampleRate,
66458f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                        audio_format_t format,
6650d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                        uint32_t channelMask,
66665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int frameCount);
66765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                ~OutputTrack();
66865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
66965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t    start();
67065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void        stop();
67165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        write(int16_t* data, uint32_t frames);
67265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        bufferQueueEmpty() { return (mBufferQueue.size() == 0) ? true : false; }
67365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        isActive() { return mActive; }
67465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            wp<ThreadBase>&     thread()  { return mThread; }
67565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
67665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        private:
67765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
678335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten            enum {
679335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten                NO_MORE_BUFFERS = 0x80000001,   // same in AudioTrack.h, ok to be different value
680335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten            };
681335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten
68265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            status_t            obtainBuffer(AudioBufferProvider::Buffer* buffer, uint32_t waitTimeMs);
68365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void                clearBufferQueue();
68465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
68565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            // Maximum number of pending buffers allocated by OutputTrack::write()
68665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            static const uint8_t kMaxOverFlowBuffers = 10;
68765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
68865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            Vector < Buffer* >          mBufferQueue;
68965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            AudioBufferProvider::Buffer mOutBuffer;
69065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool                        mActive;
69165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            DuplicatingThread*          mSourceThread;
69265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };  // end of OutputTrack
69365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
694799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        PlaybackThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device);
69565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~PlaybackThread();
69665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
69765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    dump(int fd, const Vector<String16>& args);
69865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
69965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Thread virtuals
70065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    readyToRun();
70165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        onFirstRef();
70265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
703e0feee3da22beeffbd9357540e265f13b2119cbbGlenn Kasten        virtual     status_t    initCheck() const { return (mOutput == NULL) ? NO_INIT : NO_ERROR; }
7047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
70565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     uint32_t    latency() const;
70665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
70765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    setMasterVolume(float value);
70865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    setMasterMute(bool muted);
70965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
71065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     float       masterVolume() const;
71165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        masterMute() const;
71265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
713fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten        virtual     status_t    setStreamVolume(audio_stream_type_t stream, float value);
714fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten        virtual     status_t    setStreamMute(audio_stream_type_t stream, bool muted);
71565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
716fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten        virtual     float       streamVolume(audio_stream_type_t stream) const;
717fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten        virtual     bool        streamMute(audio_stream_type_t stream) const;
71865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
71965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    sp<Track>   createTrack_l(
72065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    const sp<AudioFlinger::Client>& client,
721fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                                    audio_stream_type_t streamType,
72265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t sampleRate,
72358f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                    audio_format_t format,
7240d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                    uint32_t channelMask,
72565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    int frameCount,
72665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    const sp<IMemory>& sharedBuffer,
72765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    int sessionId,
72865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    status_t *status);
72965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
730b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent                    AudioStreamOut* getOutput();
731b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent                    AudioStreamOut* clearOutput();
732b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent                    virtual audio_stream_t* stream();
73365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
73465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        suspend() { mSuspended++; }
73565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        restore() { if (mSuspended) mSuspended--; }
736a3a854868a80fd9b9b8720e06a172754943f9417Glenn Kasten                    bool        isSuspended() const { return (mSuspended != 0); }
73765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     String8     getParameters(const String8& keys);
73865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        audioConfigChanged_l(int event, int param = 0);
73965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames);
74065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    int16_t     *mixBuffer() { return mMixBuffer; };
74165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
7427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     void detachAuxEffect_l(int effectId);
743de070137f11d346fba77605bd76a44c040a618fcEric Laurent                    status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track,
744de070137f11d346fba77605bd76a44c040a618fcEric Laurent                            int EffectId);
745de070137f11d346fba77605bd76a44c040a618fcEric Laurent                    status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track,
746de070137f11d346fba77605bd76a44c040a618fcEric Laurent                            int EffectId);
74765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
7487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    virtual status_t addEffectChain_l(const sp<EffectChain>& chain);
7497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    virtual size_t removeEffectChain_l(const sp<EffectChain>& chain);
7507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    virtual uint32_t hasAudioSession(int sessionId);
7517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    virtual uint32_t getStrategyForSession_l(int sessionId);
752de070137f11d346fba77605bd76a44c040a618fcEric Laurent
753fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                            void setStreamValid(audio_stream_type_t streamType, bool valid);
7549f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent
75565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        struct  stream_type_t {
75665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            stream_type_t()
75765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                :   volume(1.0f),
7589f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent                    mute(false),
7599f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent                    valid(true)
76065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            {
76165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
76265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            float       volume;
76365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool        mute;
7649f6530f53ae9eda43f4e7c1cb30d2379db00aa00Eric Laurent            bool        valid;
76565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
76665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
76765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
76865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t*                        mMixBuffer;
76965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                             mSuspended;
77065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                             mBytesWritten;
7719806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten    private:
77265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool                            mMasterMute;
7739806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten    protected:
77465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        SortedVector< wp<Track> >       mActiveTracks;
77565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
77665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual int             getTrackName_l() = 0;
77765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void            deleteTrackName_l(int name) = 0;
778162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent        virtual uint32_t        activeSleepTimeUs();
77965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual uint32_t        idleSleepTimeUs() = 0;
78025cbe0ecd6df8be7e40537c5d85c82f105038479Eric Laurent        virtual uint32_t        suspendSleepTimeUs() = 0;
78165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
78265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
78365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
78465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class AudioFlinger;
78565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class OutputTrack;
78665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class Track;
78765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class TrackBase;
78865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class MixerThread;
78965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class DirectOutputThread;
79065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        friend class DuplicatingThread;
79165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
79265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        PlaybackThread(const Client&);
79365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        PlaybackThread& operator = (const PlaybackThread&);
79465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
79565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t    addTrack_l(const sp<Track>& track);
79665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void        destroyTrack_l(const sp<Track>& track);
797b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        void        removeTrack_l(const sp<Track>& track);
79865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
79965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void        readOutputParameters();
80065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
80165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t    dumpInternals(int fd, const Vector<String16>& args);
80265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t    dumpTracks(int fd, const Vector<String16>& args);
80365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
80465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        SortedVector< sp<Track> >       mTracks;
805263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten        // mStreamTypes[] uses 1 additional stream type internally for the OutputTrack used by DuplicatingThread
806fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        stream_type_t                   mStreamTypes[AUDIO_STREAM_CNT + 1];
807799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        AudioStreamOut*                 mOutput;
80865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        float                           mMasterVolume;
80965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        nsecs_t                         mLastWriteTime;
81065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                             mNumWrites;
81165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                             mNumDelayedWrites;
81265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool                            mInWrite;
81365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
81465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
81565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class MixerThread : public PlaybackThread {
81665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
817de070137f11d346fba77605bd76a44c040a618fcEric Laurent        MixerThread (const sp<AudioFlinger>& audioFlinger,
818799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin                     AudioStreamOut* output,
819de070137f11d346fba77605bd76a44c040a618fcEric Laurent                     int id,
820de070137f11d346fba77605bd76a44c040a618fcEric Laurent                     uint32_t device);
82165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~MixerThread();
82265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
82365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Thread virtuals
82465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        threadLoop();
82565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
826fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                    void        invalidateTracks(audio_stream_type_t streamType);
82765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        checkForNewParameters_l();
82865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    dumpInternals(int fd, const Vector<String16>& args);
82965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
83065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
831de070137f11d346fba77605bd76a44c040a618fcEric Laurent                    uint32_t    prepareTracks_l(const SortedVector< wp<Track> >& activeTracks,
832de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                Vector< sp<Track> > *tracksToRemove);
83365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     int         getTrackName_l();
83465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        deleteTrackName_l(int name);
83565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     uint32_t    idleSleepTimeUs();
83625cbe0ecd6df8be7e40537c5d85c82f105038479Eric Laurent        virtual     uint32_t    suspendSleepTimeUs();
83765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
8382774144fa8283f1a7b43e17a53c97dec0c366dd3Eric Laurent                    AudioMixer* mAudioMixer;
8392774144fa8283f1a7b43e17a53c97dec0c366dd3Eric Laurent                    uint32_t    mPrevMixerStatus; // previous status (mixer_state) returned by
8402774144fa8283f1a7b43e17a53c97dec0c366dd3Eric Laurent                                                  // prepareTracks_l()
84165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
84265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
84365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class DirectOutputThread : public PlaybackThread {
84465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
84565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
846799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        DirectOutputThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device);
84765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        ~DirectOutputThread();
84865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
84965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Thread virtuals
85065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        threadLoop();
85165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
85265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        checkForNewParameters_l();
85365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
85465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
85565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     int         getTrackName_l();
85665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        deleteTrackName_l(int name);
85765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     uint32_t    activeSleepTimeUs();
85865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     uint32_t    idleSleepTimeUs();
85925cbe0ecd6df8be7e40537c5d85c82f105038479Eric Laurent        virtual     uint32_t    suspendSleepTimeUs();
86065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
86165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
86265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp);
86365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
86465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        float mLeftVolFloat;
86565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        float mRightVolFloat;
86665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint16_t mLeftVolShort;
86765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint16_t mRightVolShort;
86865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
86965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
87065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class DuplicatingThread : public MixerThread {
87165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
87265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        DuplicatingThread (const sp<AudioFlinger>& audioFlinger, MixerThread* mainThread, int id);
87365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        ~DuplicatingThread();
87465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
87565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Thread virtuals
87665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        threadLoop();
87765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        addOutputTrack(MixerThread* thread);
87865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        removeOutputTrack(MixerThread* thread);
87965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    uint32_t    waitTimeMs() { return mWaitTimeMs; }
88065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
88165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     uint32_t    activeSleepTimeUs();
88265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
88365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
88465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        outputsReady(SortedVector< sp<OutputTrack> > &outputTracks);
88565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        updateWaitTime();
88665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
88765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        SortedVector < sp<OutputTrack> >  mOutputTracks;
88865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    uint32_t    mWaitTimeMs;
88965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
89065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
89165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian              PlaybackThread *checkPlaybackThread_l(int output) const;
89265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian              MixerThread *checkMixerThread_l(int output) const;
89365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian              RecordThread *checkRecordThread_l(int input) const;
894fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten              float streamVolumeInternal(audio_stream_type_t stream) const { return mStreamTypes[stream].volume; }
89565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian              void audioConfigChanged_l(int event, int ioHandle, void *param2);
89665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
8977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent              uint32_t nextUniqueId();
89859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent              status_t moveEffectChain_l(int sessionId,
899de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                     AudioFlinger::PlaybackThread *srcThread,
90039e94f8f723d445447fdee0822291e664b631f60Eric Laurent                                     AudioFlinger::PlaybackThread *dstThread,
90139e94f8f723d445447fdee0822291e664b631f60Eric Laurent                                     bool reRegister);
9027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent              PlaybackThread *primaryPlaybackThread_l();
9037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent              uint32_t primaryOutputDevice_l();
90465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
90565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    friend class AudioBuffer;
90665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
90765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class TrackHandle : public android::BnAudioTrack {
90865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
90965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            TrackHandle(const sp<PlaybackThread::Track>& track);
91065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~TrackHandle();
91165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t    start();
91265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        stop();
91365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        flush();
91465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        mute(bool);
91565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        pause();
91665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual sp<IMemory> getCblk() const;
91765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t    attachAuxEffect(int effectId);
91865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t onTransact(
91965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
92065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
92165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<PlaybackThread::Track> mTrack;
92265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
92365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
92465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    friend class Client;
92565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    friend class PlaybackThread::Track;
92665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
92765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
92865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                void        removeClient_l(pid_t pid);
92965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                void        removeNotificationClient(pid_t pid);
93065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
93165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
93265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // record thread
93365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordThread : public ThreadBase, public AudioBufferProvider
93465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    {
93565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
93665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
93765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // record track
93865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class RecordTrack : public TrackBase {
93965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
94065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                RecordTrack(const wp<ThreadBase>& thread,
94165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<Client>& client,
94265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t sampleRate,
94358f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                        audio_format_t format,
9440d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi                                        uint32_t channelMask,
94565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int frameCount,
94665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t flags,
94765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int sessionId);
94865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                ~RecordTrack();
94965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
95065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t    start();
95165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void        stop();
95265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
95365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; }
95465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    bool        setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; }
95565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
95665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        dump(char* buffer, size_t size);
95759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
95865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        private:
95965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class AudioFlinger;
96065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            friend class RecordThread;
96165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
96265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                RecordTrack(const RecordTrack&);
96365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                RecordTrack& operator = (const RecordTrack&);
96465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
96565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
96665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
96765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool                mOverflow;
96865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
96965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
97065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
97165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                RecordThread(const sp<AudioFlinger>& audioFlinger,
972799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin                        AudioStreamIn *input,
97365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        uint32_t sampleRate,
97465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        uint32_t channels,
9757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        int id,
9767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        uint32_t device);
97765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                ~RecordThread();
97865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
97965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual bool        threadLoop();
980b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent        virtual status_t    readyToRun();
98165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        onFirstRef();
98265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
983e0feee3da22beeffbd9357540e265f13b2119cbbGlenn Kasten        virtual status_t    initCheck() const { return (mInput == NULL) ? NO_INIT : NO_ERROR; }
9847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                sp<AudioFlinger::RecordThread::RecordTrack>  createRecordTrack_l(
9857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        const sp<AudioFlinger::Client>& client,
9867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        uint32_t sampleRate,
98758f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                        audio_format_t format,
9887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        int channelMask,
9897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        int frameCount,
9907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        uint32_t flags,
9917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        int sessionId,
9927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        status_t *status);
9937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
99465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                status_t    start(RecordTrack* recordTrack);
99565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                void        stop(RecordTrack* recordTrack);
99665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                status_t    dump(int fd, const Vector<String16>& args);
997b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent                AudioStreamIn* getInput();
998b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent                AudioStreamIn* clearInput();
999b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent                virtual audio_stream_t* stream();
10007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
100165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t    getNextBuffer(AudioBufferProvider::Buffer* buffer);
100265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        releaseBuffer(AudioBufferProvider::Buffer* buffer);
100365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual bool        checkForNewParameters_l();
100465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual String8     getParameters(const String8& keys);
100565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        audioConfigChanged_l(int event, int param = 0);
100665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                void        readInputParameters();
100765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual unsigned int  getInputFramesLost();
100865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
10097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual status_t addEffectChain_l(const sp<EffectChain>& chain);
10107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual size_t removeEffectChain_l(const sp<EffectChain>& chain);
10117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual uint32_t hasAudioSession(int sessionId);
101259bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent                RecordTrack* track();
10137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
101465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
101565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                RecordThread();
1016799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin                AudioStreamIn                       *mInput;
10177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                RecordTrack*                        mTrack;
101865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                sp<RecordTrack>                     mActiveTrack;
101965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                Condition                           mStartStopCond;
102065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                AudioResampler                      *mResampler;
102165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                int32_t                             *mRsmpOutBuffer;
102265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                int16_t                             *mRsmpInBuffer;
102365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                size_t                              mRsmpInIndex;
102465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                size_t                              mInputBytes;
102565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                int                                 mReqChannelCount;
102665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                uint32_t                            mReqSampleRate;
102765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                ssize_t                             mBytesRead;
102865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
102965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
103065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordHandle : public android::BnAudioRecord {
103165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
103265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack);
103365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~RecordHandle();
103465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t    start();
103565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void        stop();
103665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual sp<IMemory> getCblk() const;
103765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t onTransact(
103865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
103965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
104065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<RecordThread::RecordTrack> mRecordTrack;
104165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
104265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
104365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    //--- Audio Effect Management
104465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
104565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // EffectModule and EffectChain classes both have their own mutex to protect
104665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // state changes or resource modifications. Always respect the following order
104765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // if multiple mutexes must be acquired to avoid cross deadlock:
104865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // AudioFlinger -> ThreadBase -> EffectChain -> EffectModule
104965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
105065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // The EffectModule class is a wrapper object controlling the effect engine implementation
105165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // in the effect library. It prevents concurrent calls to process() and command() functions
105265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // from different client threads. It keeps a list of EffectHandle objects corresponding
105365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // to all client applications using this effect and notifies applications of effect state,
105465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // control or parameter changes. It manages the activation state machine to send appropriate
105565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // reset, enable, disable commands to effect engine and provide volume
105665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // ramping when effects are activated/deactivated.
105765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // When controlling an auxiliary effect, the EffectModule also provides an input buffer used by
105865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // the attached track(s) to accumulate their auxiliary channel.
105965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectModule: public RefBase {
106065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
106165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectModule(const wp<ThreadBase>& wThread,
106265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        const wp<AudioFlinger::EffectChain>& chain,
106365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        effect_descriptor_t *desc,
106465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int id,
106565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int sessionId);
106665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        ~EffectModule();
106765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
106865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        enum effect_state {
106965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            IDLE,
107065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            RESTART,
107165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            STARTING,
107265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            ACTIVE,
107365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            STOPPING,
1074ec437d8d3db79459d7b19e1734e6fe309bd621e8Eric Laurent            STOPPED,
1075ec437d8d3db79459d7b19e1734e6fe309bd621e8Eric Laurent            DESTROYED
107665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
107765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
107865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int         id() { return mId; }
107965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void process();
108065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void updateState();
108125f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent        status_t command(uint32_t cmdCode,
108225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                         uint32_t cmdSize,
108325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                         void *pCmdData,
108425f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                         uint32_t *replySize,
108525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                         void *pReplyData);
108665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
108765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void reset_l();
108865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t configure();
108965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t init();
109065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint32_t state() {
109165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            return mState;
109265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
109365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint32_t status() {
109465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            return mStatus;
109565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
1096de070137f11d346fba77605bd76a44c040a618fcEric Laurent        int sessionId() {
1097de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return mSessionId;
1098de070137f11d346fba77605bd76a44c040a618fcEric Laurent        }
109965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t    setEnabled(bool enabled);
110065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool isEnabled();
11018f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        bool isProcessEnabled();
110265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
110365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void        setInBuffer(int16_t *buffer) { mConfig.inputCfg.buffer.s16 = buffer; }
110465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t     *inBuffer() { return mConfig.inputCfg.buffer.s16; }
110565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void        setOutBuffer(int16_t *buffer) { mConfig.outputCfg.buffer.s16 = buffer; }
110665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t     *outBuffer() { return mConfig.outputCfg.buffer.s16; }
1107de070137f11d346fba77605bd76a44c040a618fcEric Laurent        void        setChain(const wp<EffectChain>& chain) { mChain = chain; }
1108de070137f11d346fba77605bd76a44c040a618fcEric Laurent        void        setThread(const wp<ThreadBase>& thread) { mThread = thread; }
110959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        wp<ThreadBase>& thread() { return mThread; }
111065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
111165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t addHandle(sp<EffectHandle>& handle);
11123a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        void disconnect(const wp<EffectHandle>& handle, bool unpiniflast);
111365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        size_t removeHandle (const wp<EffectHandle>& handle);
111465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
111565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        effect_descriptor_t& desc() { return mDescriptor; }
111665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        wp<EffectChain>&     chain() { return mChain; }
111765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
111865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t         setDevice(uint32_t device);
111965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t         setVolume(uint32_t *left, uint32_t *right, bool controller);
1120f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten        status_t         setMode(audio_mode_t mode);
1121ec35a1416472865dbebc22b10199ad718ed2cc95Eric Laurent        status_t         start();
1122ec437d8d3db79459d7b19e1734e6fe309bd621e8Eric Laurent        status_t         stop();
112359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        void             setSuspended(bool suspended);
1124a3a854868a80fd9b9b8720e06a172754943f9417Glenn Kasten        bool             suspended() const;
112559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
112659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        sp<EffectHandle> controlHandle();
112765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
11283a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        bool             isPinned() { return mPinned; }
11293a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        void             unPin() { mPinned = false; }
11303a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen
113165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t         dump(int fd, const Vector<String16>& args);
113265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
113365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
11343a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        friend class EffectHandle;
11353a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        friend class AudioFlinger;
11363a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        bool                mPinned;
113765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
113865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Maximum time allocated to effect engines to complete the turn off sequence
113965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        static const uint32_t MAX_DISABLE_TIME_MS = 10000;
114065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
114165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectModule(const EffectModule&);
114265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectModule& operator = (const EffectModule&);
114365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
114465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t start_l();
114565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t stop_l();
114665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1147a3a854868a80fd9b9b8720e06a172754943f9417Glenn Kastenmutable Mutex               mLock;      // mutex for process, commands and handles list protection
114865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        wp<ThreadBase>      mThread;    // parent thread
114965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        wp<EffectChain>     mChain;     // parent effect chain
115065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                 mId;        // this instance unique ID
115165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int                 mSessionId; // audio session ID
115265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        effect_descriptor_t mDescriptor;// effect descriptor received from effect engine
115365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        effect_config_t     mConfig;    // input and output audio configuration
1154e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        effect_handle_t  mEffectInterface; // Effect module C API
115565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t mStatus;               // initialization status
115665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint32_t mState;                // current activation state (effect_state)
115765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        Vector< wp<EffectHandle> > mHandles;    // list of client handles
115865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint32_t mMaxDisableWaitCnt;    // maximum grace period before forcing an effect off after
115965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        // sending disable command.
116065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint32_t mDisableWaitCnt;       // current process() calls count during disable period.
116159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        bool     mSuspended;            // effect is suspended: temporarily disabled by framework
116265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
116365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
116465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // The EffectHandle class implements the IEffect interface. It provides resources
116565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // to receive parameter updates, keeps track of effect control
116665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // ownership and state and has a pointer to the EffectModule object it is controlling.
116765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // There is one EffectHandle object for each application controlling (or using)
116865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // an effect module.
116965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // The EffectHandle is obtained by calling AudioFlinger::createEffect().
117065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectHandle: public android::BnEffect {
117165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
117265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
117365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectHandle(const sp<EffectModule>& effect,
117465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                const sp<AudioFlinger::Client>& client,
117565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                const sp<IEffectClient>& effectClient,
117665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                int32_t priority);
117765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual ~EffectHandle();
117865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
117965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // IEffect
118065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t enable();
118165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t disable();
118225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent        virtual status_t command(uint32_t cmdCode,
118325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                                 uint32_t cmdSize,
118425f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                                 void *pCmdData,
118525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                                 uint32_t *replySize,
118625f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                                 void *pReplyData);
118765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual void disconnect();
11883a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        virtual void disconnect(bool unpiniflast);
118965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual sp<IMemory> getCblk() const;
119065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual status_t onTransact(uint32_t code, const Parcel& data,
119165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                Parcel* reply, uint32_t flags);
119265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
119365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
119465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Give or take control of effect module
119559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // - hasControl: true if control is given, false if removed
119659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // - signal: true client app should be signaled of change, false otherwise
119759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // - enabled: state of the effect when control is passed
119859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        void setControl(bool hasControl, bool signal, bool enabled);
119925f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent        void commandExecuted(uint32_t cmdCode,
120025f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                             uint32_t cmdSize,
120125f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                             void *pCmdData,
120225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                             uint32_t replySize,
120325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                             void *pReplyData);
120465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void setEnabled(bool enabled);
120559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        bool enabled() { return mEnabled; }
120665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
120765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Getters
120865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int id() { return mEffect->id(); }
120965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int priority() { return mPriority; }
121065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool hasControl() { return mHasControl; }
121165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<EffectModule> effect() { return mEffect; }
121265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
121365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void dump(char* buffer, size_t size);
121465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
121565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
12163a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        friend class AudioFlinger;
12173a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        friend class EffectModule;
121865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectHandle(const EffectHandle&);
121965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectHandle& operator =(const EffectHandle&);
122065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
122165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<EffectModule> mEffect;           // pointer to controlled EffectModule
122265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<IEffectClient> mEffectClient;    // callback interface for client notifications
122365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<Client>          mClient;        // client for shared memory allocation
122465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        sp<IMemory>         mCblkMemory;    // shared memory for control block
122565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        effect_param_cblk_t* mCblk;         // control block for deferred parameter setting via shared memory
122665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        uint8_t*            mBuffer;        // pointer to parameter area in shared memory
122765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int mPriority;                      // client application priority to control the effect
122865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool mHasControl;                   // true if this handle is controlling the effect
122959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        bool mEnabled;                      // cached enable state: needed when the effect is
123059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                            // restored after being suspended
123165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
123265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
123365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // the EffectChain class represents a group of effects associated to one audio session.
123465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // There can be any number of EffectChain objects per output mixer thread (PlaybackThread).
123565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // The EffecChain with session ID 0 contains global effects applied to the output mix.
123665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // Effects in this chain can be insert or auxiliary. Effects in other chains (attached to tracks)
123765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // are insert only. The EffectChain maintains an ordered list of effect module, the order corresponding
123865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // in the effect process order. When attached to a track (session ID != 0), it also provide it's own
123965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // input buffer used by the track as accumulation buffer.
124065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectChain: public RefBase {
124165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
124265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectChain(const wp<ThreadBase>& wThread, int sessionId);
124365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        ~EffectChain();
124465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
124559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // special key used for an entry in mSuspendedEffects keyed vector
124659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // corresponding to a suspend all request.
124759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        static const int        kKeyForSuspendAll = 0;
124859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
1249544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent        // minimum duration during which we force calling effect process when last track on
1250544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent        // a session is stopped or removed to allow effect tail to be rendered
1251544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent        static const int        kProcessTailDurationMs = 1000;
1252544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent
125365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void process_l();
125465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
125565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void lock() {
125665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mLock.lock();
125765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
125865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void unlock() {
125965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mLock.unlock();
126065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
126165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1262de070137f11d346fba77605bd76a44c040a618fcEric Laurent        status_t addEffect_l(const sp<EffectModule>& handle);
1263cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        size_t removeEffect_l(const sp<EffectModule>& handle);
126465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        int sessionId() { return mSessionId; }
12667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        void setSessionId(int sessionId) { mSessionId = sessionId; }
1267de070137f11d346fba77605bd76a44c040a618fcEric Laurent
1268cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        sp<EffectModule> getEffectFromDesc_l(effect_descriptor_t *descriptor);
1269cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        sp<EffectModule> getEffectFromId_l(int id);
127059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        sp<EffectModule> getEffectFromType_l(const effect_uuid_t *type);
1271cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        bool setVolume_l(uint32_t *left, uint32_t *right);
1272cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        void setDevice_l(uint32_t device);
1273f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten        void setMode_l(audio_mode_t mode);
127465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
127565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void setInBuffer(int16_t *buffer, bool ownsBuffer = false) {
127665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mInBuffer = buffer;
127765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mOwnInBuffer = ownsBuffer;
127865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
127965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t *inBuffer() {
128065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            return mInBuffer;
128165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
128265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        void setOutBuffer(int16_t *buffer) {
128365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            mOutBuffer = buffer;
128465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
128565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t *outBuffer() {
128665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            return mOutBuffer;
128765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        }
128865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1289b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        void incTrackCnt() { android_atomic_inc(&mTrackCnt); }
1290b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        void decTrackCnt() { android_atomic_dec(&mTrackCnt); }
1291b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        int32_t trackCnt() { return mTrackCnt;}
1292b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent
1293544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent        void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt);
1294544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent                                   mTailBufferCount = mMaxTailBuffers; }
1295b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        void decActiveTrackCnt() { android_atomic_dec(&mActiveTrackCnt); }
1296b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        int32_t activeTrackCnt() { return mActiveTrackCnt;}
129765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1298de070137f11d346fba77605bd76a44c040a618fcEric Laurent        uint32_t strategy() { return mStrategy; }
1299de070137f11d346fba77605bd76a44c040a618fcEric Laurent        void setStrategy(uint32_t strategy)
1300de070137f11d346fba77605bd76a44c040a618fcEric Laurent                 { mStrategy = strategy; }
1301de070137f11d346fba77605bd76a44c040a618fcEric Laurent
130259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // suspend effect of the given type
130359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        void setEffectSuspended_l(const effect_uuid_t *type,
130459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                  bool suspend);
130559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // suspend all eligible effects
130659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        void setEffectSuspendedAll_l(bool suspend);
130759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // check if effects should be suspend or restored when a given effect is enable or disabled
1308a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent        void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect,
130959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent                                              bool enabled);
131059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
131165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        status_t dump(int fd, const Vector<String16>& args);
131265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
131365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    protected:
13143a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        friend class AudioFlinger;
131565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectChain(const EffectChain&);
131665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        EffectChain& operator =(const EffectChain&);
131765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
131859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        class SuspendedEffectDesc : public RefBase {
131959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        public:
132059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent            SuspendedEffectDesc() : mRefCount(0) {}
132159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
132259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent            int mRefCount;
132359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent            effect_uuid_t mType;
132459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent            wp<EffectModule> mEffect;
132559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        };
132659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
132759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // get a list of effect modules to suspend when an effect of the type
132859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // passed is enabled.
132959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        Vector< sp<EffectModule> > getSuspendEligibleEffects();
133059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // get an effect module if it is currently enable
133159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        sp<EffectModule> getEffectIfEnabled(const effect_uuid_t *type);
1332db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent        // true if the effect whose descriptor is passed can be suspended
1333db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent        // OEMs can modify the rules implemented in this method to exclude specific effect
1334db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent        // types or implementations from the suspend/restore mechanism.
1335db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent        bool isEffectEligibleForSuspend(const effect_descriptor_t& desc);
133659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent
133765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        wp<ThreadBase> mThread;     // parent mixer thread
133865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        Mutex mLock;                // mutex protecting effect list
133965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        Vector<sp<EffectModule> > mEffects; // list of effect modules
134065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int mSessionId;             // audio session ID
134165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t *mInBuffer;         // chain input buffer
134265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        int16_t *mOutBuffer;        // chain output buffer
1343b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        volatile int32_t mActiveTrackCnt;  // number of active tracks connected
1344b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent        volatile int32_t mTrackCnt;        // number of tracks connected
1345544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent        int32_t mTailBufferCount;   // current effect tail buffer count
1346544fe9b6e9325701df4ab8c1d29774fc13c4cf6cEric Laurent        int32_t mMaxTailBuffers;    // maximum effect tail buffers
134765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        bool mOwnInBuffer;          // true if the chain owns its input buffer
1348cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        int mVolumeCtrlIdx;         // index of insert effect having control over volume
1349cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        uint32_t mLeftVolume;       // previous volume on left channel
1350cab112421da6e8eac19ffddbbe3d76067cffee78Eric Laurent        uint32_t mRightVolume;      // previous volume on right channel
1351f997cabca292d70d078ae828e21c28e6df62995fEric Laurent        uint32_t mNewLeftVolume;       // new volume on left channel
1352f997cabca292d70d078ae828e21c28e6df62995fEric Laurent        uint32_t mNewRightVolume;      // new volume on right channel
1353de070137f11d346fba77605bd76a44c040a618fcEric Laurent        uint32_t mStrategy; // strategy for this effect chain
135459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // mSuspendedEffects lists all effect currently suspended in the chain
135559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // use effect type UUID timelow field as key. There is no real risk of identical
135659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        // timeLow fields among effect type UUIDs.
135759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent        KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects;
135865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
135965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1360799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    struct AudioStreamOut {
1361799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        audio_hw_device_t   *hwDev;
1362799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        audio_stream_out_t  *stream;
1363799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin
1364799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        AudioStreamOut(audio_hw_device_t *dev, audio_stream_out_t *out) :
1365799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin            hwDev(dev), stream(out) {}
1366799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    };
1367799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin
1368799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    struct AudioStreamIn {
1369799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        audio_hw_device_t   *hwDev;
1370799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        audio_stream_in_t   *stream;
1371799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin
1372799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin        AudioStreamIn(audio_hw_device_t *dev, audio_stream_in_t *in) :
1373799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin            hwDev(dev), stream(in) {}
1374799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    };
1375799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin
13763a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    struct AudioSessionRef {
13773a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        int sessionid;
13783a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        pid_t pid;
13793a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen        int cnt;
13803a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    };
13813a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen
138265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    friend class RecordThread;
138365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    friend class PlaybackThread;
138465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
138565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    mutable     Mutex                               mLock;
138665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
138765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                DefaultKeyedVector< pid_t, wp<Client> >     mClients;
138865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
138965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                mutable     Mutex                   mHardwareLock;
1390799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin                audio_hw_device_t*                  mPrimaryHardwareDev;
1391799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin                Vector<audio_hw_device_t*>          mAudioHwDevs;
1392a4454b4765c5905f14186893b0688be375642283Glenn Kasten    mutable     hardware_call_state                 mHardwareStatus;    // for dump only
139365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
139465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
139565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                DefaultKeyedVector< int, sp<PlaybackThread> >  mPlaybackThreads;
1396fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                PlaybackThread::stream_type_t       mStreamTypes[AUDIO_STREAM_CNT];
13979806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten
13989806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten                // both are protected by mLock
139965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                float                               mMasterVolume;
140065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                bool                                mMasterMute;
140165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
140265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                DefaultKeyedVector< int, sp<RecordThread> >    mRecordThreads;
140365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
140465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                DefaultKeyedVector< pid_t, sp<NotificationClient> >    mNotificationClients;
140565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                volatile int32_t                    mNextUniqueId;
1406f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten                audio_mode_t                        mMode;
1407bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent                bool                                mBtNrecIsOff;
140865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14093a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen                Vector<AudioSessionRef*> mAudioSessionRefs;
14109806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten
14119806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten                float       masterVolume_l() const  { return mMasterVolume; }
14129806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten                bool        masterMute_l() const    { return mMasterMute; }
141365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian};
141465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1415799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin
141665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------------------------------------------------------------------------
141765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
141865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; // namespace android
141965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
142065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#endif // ANDROID_AUDIO_FLINGER_H
1421