199e53b86eebb605b70dd7591b89bf61a9414ed0eGlenn Kasten/*
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
254ff14bae91075eb274eb1c2975982358946e7e63John Grossman#include <common_time/cc_helper.h>
264ff14bae91075eb274eb1c2975982358946e7e63John Grossman
2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioFlinger.h>
2865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioFlingerClient.h>
2965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioTrack.h>
3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/IAudioRecord.h>
31335787fe43596f38ea2fa50b24c54d0823a3fb1dGlenn Kasten#include <media/AudioSystem.h>
324ff14bae91075eb274eb1c2975982358946e7e63John Grossman#include <media/AudioTrack.h>
3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Atomic.h>
3565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Errors.h>
3665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/threads.h>
3765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/SortedVector.h>
38799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin#include <utils/TypeHelpers.h>
3965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Vector.h>
4065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
415462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian#include <binder/BinderService.h>
425462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian#include <binder/MemoryDealer.h>
435462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian
4464760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h>
457394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <hardware/audio.h>
46a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent#include <hardware/audio_policy.h>
4765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
482dd4bdd715f586d4d30cf90cc6fc2bbfbce60fe0Glenn Kasten#include <media/AudioBufferProvider.h>
492dd4bdd715f586d4d30cf90cc6fc2bbfbce60fe0Glenn Kasten#include <media/ExtendedAudioBufferProvider.h>
5058912562617941964939a4182cda71eaeb153d4bGlenn Kasten#include "FastMixer.h"
512dd4bdd715f586d4d30cf90cc6fc2bbfbce60fe0Glenn Kasten#include <media/nbaio/NBAIO.h>
52c15d6657a17d7cef91f800f40d11760e2e7340afGlenn Kasten#include "AudioWatchdog.h"
5365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
54feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent#include <powermanager/IPowerManager.h>
55feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
5665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android {
5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass audio_track_cblk_t;
5965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass effect_param_cblk_t;
6065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioMixer;
6165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioBuffer;
6265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianclass AudioResampler;
6358912562617941964939a4182cda71eaeb153d4bGlenn Kastenclass FastMixer;
6465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
6565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------------------------------------------------------------------------
6665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
6753d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// AudioFlinger has a hard-coded upper limit of 2 channels for capture and playback.
6853d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// There is support for > 2 channel tracks down-mixed to 2 channel output via a down-mix effect.
6953d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// Adding full support for > 2 channel capture or playback would require more than simply changing
7053d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// this #define.  There is an independent hard-coded upper limit in AudioMixer;
7153d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// removing that AudioMixer limit would be necessary but insufficient to support > 2 channels.
7253d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// The macro FCC_2 highlights some (but not all) places where there is are 2-channel assumptions.
7353d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten// Search also for "2", "left", "right", "[0]", "[1]", ">> 16", "<< 16", etc.
7453d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten#define FCC_2 2     // FCC_2 = Fixed Channel Count 2
7553d76dbe7c55821e89d9da02e7a563f7fb45de87Glenn Kasten
764ff14bae91075eb274eb1c2975982358946e7e63John Grossmanstatic const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);
7765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
785462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopianclass AudioFlinger :
795462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    public BinderService<AudioFlinger>,
805462fc9a38fa8c9dff434cd53fa5fb1782ae3042Mathias Agopian    public BnAudioFlinger
8165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
821998661fdb6b0b5ae103e047e3d653c5da1b99e3Glenn Kasten    friend class BinderService<AudioFlinger>;   // for AudioFlinger()
8365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianpublic:
8454c3b66444ebfb9f2265ee70ac3b76ccefa0506aGlenn Kasten    static const char* getServiceName() { return "media.audio_flinger"; }
8565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
8665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    dump(int fd, const Vector<String16>& args);
8765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
882f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten    // IAudioFlinger interface, in binder opcode order
8965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual sp<IAudioTrack> createTrack(
9065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                pid_t pid,
91fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                                audio_stream_type_t streamType,
9265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t sampleRate,
9358f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                audio_format_t format,
94dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten                                audio_channel_mask_t channelMask,
9565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int frameCount,
96a075db4ff9b086ac2885df77bb6da0869293df92Glenn Kasten                                IAudioFlinger::track_flags_t flags,
9765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                const sp<IMemory>& sharedBuffer,
9872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                                audio_io_handle_t output,
993acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten                                pid_t tid,
10065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                int *sessionId,
10165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                status_t *status);
10265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1032f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten    virtual sp<IAudioRecord> openRecord(
1042f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                pid_t pid,
1052f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                audio_io_handle_t input,
1062f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                uint32_t sampleRate,
1072f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                audio_format_t format,
108dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten                                audio_channel_mask_t channelMask,
1092f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                int frameCount,
110a075db4ff9b086ac2885df77bb6da0869293df92Glenn Kasten                                IAudioFlinger::track_flags_t flags,
1111879fff068422852c1483dcf8365c2ff0e2fadfcGlenn Kasten                                pid_t tid,
1122f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                int *sessionId,
1132f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten                                status_t *status);
1142f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten
11572ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     uint32_t    sampleRate(audio_io_handle_t output) const;
11672ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     int         channelCount(audio_io_handle_t output) const;
11772ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     audio_format_t format(audio_io_handle_t output) const;
11872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     size_t      frameCount(audio_io_handle_t output) const;
11972ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     uint32_t    latency(audio_io_handle_t output) const;
12065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setMasterVolume(float value);
12265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setMasterMute(bool muted);
12365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     float       masterVolume() const;
12565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     bool        masterMute() const;
12665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12772ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     status_t    setStreamVolume(audio_stream_type_t stream, float value,
12872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                                            audio_io_handle_t output);
129fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual     status_t    setStreamMute(audio_stream_type_t stream, bool muted);
13065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13172ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     float       streamVolume(audio_stream_type_t stream,
13272ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                                         audio_io_handle_t output) const;
133fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual     bool        streamMute(audio_stream_type_t stream) const;
13465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
135f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten    virtual     status_t    setMode(audio_mode_t mode);
13665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    setMicMute(bool state);
13865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     bool        getMicMute() const;
13965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14072ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     status_t    setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
14172ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual     String8     getParameters(audio_io_handle_t ioHandle, const String8& keys) const;
14265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     void        registerClient(const sp<IAudioFlingerClient>& client);
14465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
145dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten    virtual     size_t      getInputBufferSize(uint32_t sampleRate, audio_format_t format,
146dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten                                               audio_channel_mask_t channelMask) const;
14765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
148a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent    virtual audio_io_handle_t openOutput(audio_module_handle_t module,
149a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                         audio_devices_t *pDevices,
150a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                         uint32_t *pSamplingRate,
151a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                         audio_format_t *pFormat,
152a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                         audio_channel_mask_t *pChannelMask,
153a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                         uint32_t *pLatencyMs,
1540ca3cf94c0dfc173ad7886ae162c4b67067539f6Eric Laurent                                         audio_output_flags_t flags);
15565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
15672ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
15772ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                                                  audio_io_handle_t output2);
15865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
15972ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t closeOutput(audio_io_handle_t output);
16065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16172ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t suspendOutput(audio_io_handle_t output);
16265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16372ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t restoreOutput(audio_io_handle_t output);
16465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
165a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent    virtual audio_io_handle_t openInput(audio_module_handle_t module,
166a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                        audio_devices_t *pDevices,
167a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                        uint32_t *pSamplingRate,
168a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                        audio_format_t *pFormat,
169a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent                                        audio_channel_mask_t *pChannelMask);
17065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
17172ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t closeInput(audio_io_handle_t input);
17265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
17372ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output);
17465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
17565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t setVoiceVolume(float volume);
17665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
17772ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
17872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                                       audio_io_handle_t output) const;
17965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1802f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten    virtual     unsigned int  getInputFramesLost(audio_io_handle_t ioHandle) const;
1812f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten
18265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual int newAudioSessionId();
18365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1843a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    virtual void acquireAudioSessionId(int audioSession);
1853a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen
1863a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    virtual void releaseAudioSessionId(int audioSession);
1873a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen
188f587ba5b991c7cd91e4df093d0d796bd419e5d67Glenn Kasten    virtual status_t queryNumberEffects(uint32_t *numEffects) const;
18965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
190f587ba5b991c7cd91e4df093d0d796bd419e5d67Glenn Kasten    virtual status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor) const;
19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1925e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kasten    virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
193f587ba5b991c7cd91e4df093d0d796bd419e5d67Glenn Kasten                                         effect_descriptor_t *descriptor) const;
19465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
19565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual sp<IEffect> createEffect(pid_t pid,
19665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        effect_descriptor_t *pDesc,
19765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        const sp<IEffectClient>& effectClient,
19865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int32_t priority,
19972ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                        audio_io_handle_t io,
20065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int sessionId,
20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        status_t *status,
20265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int *id,
20365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        int *enabled);
20465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
20572ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten    virtual status_t moveEffects(int sessionId, audio_io_handle_t srcOutput,
20672ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten                        audio_io_handle_t dstOutput);
20765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
208a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent    virtual audio_module_handle_t loadHwModule(const char *name);
209a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent
210cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten    virtual int32_t getPrimaryOutputSamplingRate();
211cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten    virtual int32_t getPrimaryOutputFrameCount();
212cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten
21365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    onTransact(
21465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t code,
21565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                const Parcel& data,
21665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Parcel* reply,
21765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t flags);
21865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2192f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten    // end of IAudioFlinger interface
2202f732eb768004c6362fae8a02c60b69c9400b032Glenn Kasten
221a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    class SyncEvent;
222a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent
223a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    typedef void (*sync_event_callback_t)(const wp<SyncEvent>& event) ;
224a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent
225a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    class SyncEvent : public RefBase {
226a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    public:
227a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        SyncEvent(AudioSystem::sync_event_t type,
228a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                  int triggerSession,
229a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                  int listenerSession,
230a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                  sync_event_callback_t callBack,
231a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                  void *cookie)
232a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        : mType(type), mTriggerSession(triggerSession), mListenerSession(listenerSession),
233a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent          mCallback(callBack), mCookie(cookie)
234a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        {}
235a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent
236a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        virtual ~SyncEvent() {}
237a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent
238a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        void trigger() { Mutex::Autolock _l(mLock); if (mCallback) mCallback(this); }
239106e8a42038f9e90d5ff97f8ab6f1a42258bde9eGlenn Kasten        bool isCancelled() const { Mutex::Autolock _l(mLock); return (mCallback == NULL); }
240106e8a42038f9e90d5ff97f8ab6f1a42258bde9eGlenn Kasten        void cancel() { Mutex::Autolock _l(mLock); mCallback = NULL; }
241a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        AudioSystem::sync_event_t type() const { return mType; }
242a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        int triggerSession() const { return mTriggerSession; }
243a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        int listenerSession() const { return mListenerSession; }
244a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent        void *cookie() const { return mCookie; }
245a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent
246a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    private:
247a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent          const AudioSystem::sync_event_t mType;
248a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent          const int mTriggerSession;
249a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent          const int mListenerSession;
250a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent          sync_event_callback_t mCallback;
251a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent          void * const mCookie;
252106e8a42038f9e90d5ff97f8ab6f1a42258bde9eGlenn Kasten          mutable Mutex mLock;
253a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    };
254a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent
255a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent    sp<SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
256a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                                        int triggerSession,
257a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                                        int listenerSession,
258a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                                        sync_event_callback_t callBack,
259a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent                                        void *cookie);
260717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent
2612f732eb768004c6362fae8a02c60b69c9400b032Glenn Kastenprivate:
262ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman    class AudioHwDevice;    // fwd declaration for findSuitableHwDev_l
263ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman
264f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten               audio_mode_t getMode() const { return mMode; }
26565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
266c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten                bool        btNrecIsOff() const { return mBtNrecIsOff; }
26759bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent
26865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            AudioFlinger();
26965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual                 ~AudioFlinger();
27065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2712b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten    // call in any IAudioFlinger method that accesses mPrimaryHardwareDev
2722b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten    status_t                initCheck() const { return mPrimaryHardwareDev == NULL ? NO_INIT : NO_ERROR; }
2732b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten
274000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten    // RefBase
2755a61d2f277af3098fc10b2881babca16391362daDima Zavin    virtual     void        onFirstRef();
276000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten
277ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman    AudioHwDevice*          findSuitableHwDev_l(audio_module_handle_t module, audio_devices_t devices);
2783a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen    void                    purgeStaleEffects_l();
27965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
28066fcab972e9218d47c58a915f391b2f48a09903aGlenn Kasten    // standby delay for MIXER and DUPLICATING playback threads is read from property
28166fcab972e9218d47c58a915f391b2f48a09903aGlenn Kasten    // ro.audio.flinger_standbytime_ms or defaults to kDefaultStandbyTimeInNsecs
2824ff14bae91075eb274eb1c2975982358946e7e63John Grossman    static nsecs_t          mStandbyTimeInNsecs;
2834ff14bae91075eb274eb1c2975982358946e7e63John Grossman
284be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kasten    // Internal dump utilities.
285be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kasten    void dumpPermissionDenial(int fd, const Vector<String16>& args);
286be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kasten    void dumpClients(int fd, const Vector<String16>& args);
287be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kasten    void dumpInternals(int fd, const Vector<String16>& args);
28865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
28965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // --- Client ---
29065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class Client : public RefBase {
29165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
29265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            Client(const sp<AudioFlinger>& audioFlinger, pid_t pid);
29365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~Client();
294435dbe6c3ecd04bcb4bd80584064e287ebccd720Glenn Kasten        sp<MemoryDealer>    heap() const;
29565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        pid_t               pid() const { return mPid; }
296c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten        sp<AudioFlinger>    audioFlinger() const { return mAudioFlinger; }
29765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2984ff14bae91075eb274eb1c2975982358946e7e63John Grossman        bool reserveTimedTrack();
2994ff14bae91075eb274eb1c2975982358946e7e63John Grossman        void releaseTimedTrack();
3004ff14bae91075eb274eb1c2975982358946e7e63John Grossman
30165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
30265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            Client(const Client&);
30365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            Client& operator = (const Client&);
30484afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten        const sp<AudioFlinger> mAudioFlinger;
30584afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten        const sp<MemoryDealer> mMemoryDealer;
30684afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten        const pid_t         mPid;
3074ff14bae91075eb274eb1c2975982358946e7e63John Grossman
3084ff14bae91075eb274eb1c2975982358946e7e63John Grossman        Mutex               mTimedTrackLock;
3094ff14bae91075eb274eb1c2975982358946e7e63John Grossman        int                 mTimedTrackCount;
31065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
31165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
31265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // --- Notification Client ---
31365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class NotificationClient : public IBinder::DeathRecipient {
31465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
31565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            NotificationClient(const sp<AudioFlinger>& audioFlinger,
31665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                                const sp<IAudioFlingerClient>& client,
31765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                                pid_t pid);
31865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~NotificationClient();
31965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
32084afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten                sp<IAudioFlingerClient> audioFlingerClient() const { return mAudioFlingerClient; }
32165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
32265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                // IBinder::DeathRecipient
32365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                virtual     void        binderDied(const wp<IBinder>& who);
32465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
32565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
32665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            NotificationClient(const NotificationClient&);
32765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                            NotificationClient& operator = (const NotificationClient&);
32865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
32984afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten        const sp<AudioFlinger>  mAudioFlinger;
33084afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten        const pid_t             mPid;
33184afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten        const sp<IAudioFlingerClient> mAudioFlingerClient;
33265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
33365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
33465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class TrackHandle;
33565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordHandle;
33665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordThread;
33765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class PlaybackThread;
33865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class MixerThread;
33965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class DirectOutputThread;
34065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class DuplicatingThread;
34165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class Track;
34265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class RecordTrack;
34365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectModule;
34465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectHandle;
34565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class EffectChain;
346799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    struct AudioStreamOut;
347799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin    struct AudioStreamIn;
34865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
34965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class ThreadBase : public Thread {
35065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
3517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
35223bb8becff20449a9b1647d5a1a99b14c83f0cceGlenn Kasten        enum type_t {
3537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            MIXER,              // Thread class is MixerThread
3547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            DIRECT,             // Thread class is DirectOutputThread
3557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            DUPLICATING,        // Thread class is DuplicatingThread
3567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            RECORD              // Thread class is RecordThread
3577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        };
3587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
359f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent        ThreadBase (const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id,
360f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent                    audio_devices_t outDevice, audio_devices_t inDevice, type_t type);
36123bb8becff20449a9b1647d5a1a99b14c83f0cceGlenn Kasten        virtual             ~ThreadBase();
36223bb8becff20449a9b1647d5a1a99b14c83f0cceGlenn Kasten
363be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kasten        void dumpBase(int fd, const Vector<String16>& args);
364be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kasten        void dumpEffectChains(int fd, const Vector<String16>& args);
36565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
366feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        void clearPowerManager();
367feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
36865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // base for record and playback
369288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten        class TrackBase : public ExtendedAudioBufferProvider, public RefBase {
37065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
37165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
37265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            enum track_state {
37365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                IDLE,
37465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                TERMINATED,
3752986460984580833161bdaabc7f17da1005a8961Eric Laurent                FLUSHED,
37665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                STOPPED,
377d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten                // next 2 states are currently used for fast tracks only
378d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten                STOPPING_1,     // waiting for first underrun
379d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten                STOPPING_2,     // waiting for presentation complete
38065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                RESUMING,
38165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                ACTIVE,
38265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                PAUSING,
38365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                PAUSED
38465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            };
38565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3869eaa55756c5b245970447019250ce852f5189525Glenn Kasten                                TrackBase(ThreadBase *thread,
38765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<Client>& client,
38865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t sampleRate,
38958f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                        audio_format_t format,
390254af180475346b6186b49c297f340c9c4817511Glenn Kasten                                        audio_channel_mask_t channelMask,
39165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int frameCount,
39265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        const sp<IMemory>& sharedBuffer,
39365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        int sessionId);
394c19e22450e6e3d07594c935c7a9522e85e909e82Glenn Kasten            virtual             ~TrackBase();
39565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3960ec23ce0d1ff79566c402bc30df3074f6e25a22bGlenn Kasten            virtual status_t    start(AudioSystem::sync_event_t event,
3970ec23ce0d1ff79566c402bc30df3074f6e25a22bGlenn Kasten                                     int triggerSession) = 0;
39865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void        stop() = 0;
399c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten                    sp<IMemory> getCblk() const { return mCblkMemory; }
40065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    audio_track_cblk_t* cblk() const { return mCblk; }
401c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten                    int         sessionId() const { return mSessionId; }
402a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent            virtual status_t    setSyncEvent(const sp<SyncEvent>& event);
40365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
40465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        protected:
40565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                TrackBase(const TrackBase&);
40665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                TrackBase& operator = (const TrackBase&);
40765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
40801c4ebf6b794493898114a502ed36de13137f7e5Glenn Kasten            // AudioBufferProvider interface
40901c4ebf6b794493898114a502ed36de13137f7e5Glenn Kasten            virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer, int64_t pts) = 0;
41065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer);
41165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
412288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten            // ExtendedAudioBufferProvider interface is only needed for Track,
413288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten            // but putting it in TrackBase avoids the complexity of virtual inheritance
414288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten            virtual size_t  framesReady() const { return SIZE_MAX; }
415288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten
41658f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten            audio_format_t format() const {
41765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mFormat;
41865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
41965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
420c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten            int channelCount() const { return mChannelCount; }
42165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
422254af180475346b6186b49c297f340c9c4817511Glenn Kasten            audio_channel_mask_t channelMask() const { return mChannelMask; }
4230d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi
424c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten            int sampleRate() const; // FIXME inline after cblk sr moved
42565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4266648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // Return a pointer to the start of a contiguous slice of the track buffer.
4276648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // Parameter 'offset' is the requested start position, expressed in
4286648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // monotonically increasing frame units relative to the track epoch.
4296648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // Parameter 'frames' is the requested length, also in frame units.
4306648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // Always returns non-NULL.  It is the caller's responsibility to
4316648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // verify that this will be successful; the result of calling this
4326648821933dc06c0b09ab2c8b32135edddcd4291Glenn Kasten            // function with invalid 'offset' or 'frames' is undefined.
43365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void* getBuffer(uint32_t offset, uint32_t frames) const;
43465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
43565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isStopped() const {
4362986460984580833161bdaabc7f17da1005a8961Eric Laurent                return (mState == STOPPED || mState == FLUSHED);
43765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
43865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
439d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            // for fast tracks only
440d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            bool isStopping() const {
441d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten                return mState == STOPPING_1 || mState == STOPPING_2;
442d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            }
443d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            bool isStopping_1() const {
444d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten                return mState == STOPPING_1;
445d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            }
446d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            bool isStopping_2() const {
447d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten                return mState == STOPPING_2;
448d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten            }
449d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten
45065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool isTerminated() const {
45165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                return mState == TERMINATED;
45265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            }
45365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
45465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool step();
45565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void reset();
45665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
45784afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten            const wp<ThreadBase> mThread;
45884afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten            /*const*/ sp<Client> mClient;   // see explanation at ~TrackBase() why not const
45965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            sp<IMemory>         mCblkMemory;
46065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            audio_track_cblk_t* mCblk;
461c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten            void*               mBuffer;    // start of track buffer, typically in shared memory
462c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten            void*               mBufferEnd; // &mBuffer[mFrameCount * frameSize], where frameSize
463c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten                                            //   is based on mChannelCount and 16-bit samples
46465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            uint32_t            mFrameCount;
46565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            // we don't really need a lock for these
466b853e986caf43408ad95b9014f194aadff385e3cGlenn Kasten            track_state         mState;
46758912562617941964939a4182cda71eaeb153d4bGlenn Kasten            const uint32_t      mSampleRate;    // initial sample rate only; for tracks which
46858912562617941964939a4182cda71eaeb153d4bGlenn Kasten                                // support dynamic rates, the current value is in control block
46984afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten            const audio_format_t mFormat;
4705cf034d92d901169ca6e36c90475f40715827fcdGlenn Kasten            bool                mStepServerFailed;
47184afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten            const int           mSessionId;
4720d255b2d9061ba31f13ada3fc0f7e51916407176Jean-Michel Trivi            uint8_t             mChannelCount;
473254af180475346b6186b49c297f340c9c4817511Glenn Kasten            audio_channel_mask_t mChannelMask;
474a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent            Vector < sp<SyncEvent> >mSyncEvents;
47565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
47665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
477896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        enum {
478896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            CFG_EVENT_IO,
479896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            CFG_EVENT_PRIO
480896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        };
481896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
48265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class ConfigEvent {
48365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
484896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            ConfigEvent(int type) : mType(type) {}
485896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            virtual ~ConfigEvent() {}
486896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
487896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                     int type() const { return mType; }
488896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
489896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            virtual  void dump(char *buffer, size_t size) = 0;
490896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
491896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        private:
492896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            const int mType;
493896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        };
494896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
495896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        class IoConfigEvent : public ConfigEvent {
496896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        public:
497896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            IoConfigEvent(int event, int param) :
498896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                ConfigEvent(CFG_EVENT_IO), mEvent(event), mParam(event) {}
499896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            virtual ~IoConfigEvent() {}
500896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
501896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    int event() const { return mEvent; }
502896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    int param() const { return mParam; }
503896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
504896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            virtual  void dump(char *buffer, size_t size) {
505896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                snprintf(buffer, size, "IO event: event %d, param %d\n", mEvent, mParam);
506896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            }
507896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
508896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        private:
509896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            const int mEvent;
510896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            const int mParam;
511896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        };
512896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
513896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        class PrioConfigEvent : public ConfigEvent {
514896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        public:
515896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            PrioConfigEvent(pid_t pid, pid_t tid, int32_t prio) :
516896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                ConfigEvent(CFG_EVENT_PRIO), mPid(pid), mTid(tid), mPrio(prio) {}
517896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            virtual ~PrioConfigEvent() {}
51865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
519896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    pid_t pid() const { return mPid; }
520896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    pid_t tid() const { return mTid; }
521896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    int32_t prio() const { return mPrio; }
522896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
523896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            virtual  void dump(char *buffer, size_t size) {
524896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                snprintf(buffer, size, "Prio event: pid %d, tid %d, prio %d\n", mPid, mTid, mPrio);
525896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            }
526896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
527896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent        private:
528896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            const pid_t mPid;
529896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            const pid_t mTid;
530896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent            const int32_t mPrio;
53165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
53265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
533896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent
534feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        class PMDeathRecipient : public IBinder::DeathRecipient {
535feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        public:
536feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                        PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {}
537feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            virtual     ~PMDeathRecipient() {}
538feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
539feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            // IBinder::DeathRecipient
540feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            virtual     void        binderDied(const wp<IBinder>& who);
541feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
542feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        private:
543feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                        PMDeathRecipient(const PMDeathRecipient&);
544feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent                        PMDeathRecipient& operator = (const PMDeathRecipient&);
545feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
546feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent            wp<ThreadBase> mThread;
547feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent        };
548feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent
5497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     status_t    initCheck() const = 0;
55001542f2704f39956da09ae2840e192dab760091fGlenn Kasten
55101542f2704f39956da09ae2840e192dab760091fGlenn Kasten                    // static externally-visible
55223bb8becff20449a9b1647d5a1a99b14c83f0cceGlenn Kasten                    type_t      type() const { return mType; }
55301542f2704f39956da09ae2840e192dab760091fGlenn Kasten                    audio_io_handle_t id() const { return mId;}
55401542f2704f39956da09ae2840e192dab760091fGlenn Kasten
55501542f2704f39956da09ae2840e192dab760091fGlenn Kasten                    // dynamic externally-visible
556c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten                    uint32_t    sampleRate() const { return mSampleRate; }
557c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten                    int         channelCount() const { return mChannelCount; }
558254af180475346b6186b49c297f340c9c4817511Glenn Kasten                    audio_channel_mask_t channelMask() const { return mChannelMask; }
559c59c004a3a6042c0990d71179f88eee2ce781e3cGlenn Kasten                    audio_format_t format() const { return mFormat; }
56058912562617941964939a4182cda71eaeb153d4bGlenn Kasten                    // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects,
561cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten                    // and returns the normal mix buffer's frame count.
56258912562617941964939a4182cda71eaeb153d4bGlenn Kasten                    size_t      frameCount() const { return mNormalFrameCount; }
563cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten                    // Return's the HAL's frame count i.e. fast mixer buffer size.
564cc0f1cfb69ce8b8985fc2c0984847a06a13ad22dGlenn Kasten                    size_t      frameCountHAL() const { return mFrameCount; }
56501542f2704f39956da09ae2840e192dab760091fGlenn Kasten
566b28686f95daee16edeb5f39af2cd5274ac3dc99fGlenn Kasten        // Should be "virtual status_t requestExitAndWait()" and override same
567b28686f95daee16edeb5f39af2cd5274ac3dc99fGlenn Kasten        // method in Thread, but Thread::requestExitAndWait() is not yet virtual.
56865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        exit();
56965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        checkForNewParameters_l() = 0;
57065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     status_t    setParameters(const String8& keyValuePairs);
57165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     String8     getParameters(const String8& keys) = 0;
57265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        audioConfigChanged_l(int event, int param = 0) = 0;
573896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    void        sendIoConfigEvent(int event, int param = 0);
574896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    void        sendIoConfigEvent_l(int event, int param = 0);
575896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent                    void        sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio);
57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        processConfigEvents();
57701542f2704f39956da09ae2840e192dab760091fGlenn Kasten
578f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent                    // see note at declaration of mStandby, mOutDevice and mInDevice
57902fe1bf923bbe5789202dbd5810e2c04794562e6Glenn Kasten                    bool        standby() const { return mStandby; }
580f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent                    audio_devices_t outDevice() const { return mOutDevice; }
581f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent                    audio_devices_t inDevice() const { return mInDevice; }
58201542f2704f39956da09ae2840e192dab760091fGlenn Kasten
5830bf65bdde04b8e66c998ff37e2b2afafddddfa33Glenn Kasten        virtual     audio_stream_t* stream() const = 0;
5847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
5857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<EffectHandle> createEffect_l(
5867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        const sp<AudioFlinger::Client>& client,
5877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        const sp<IEffectClient>& effectClient,
5887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        int32_t priority,
5897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        int sessionId,
5907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        effect_descriptor_t *desc,
5917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        int *enabled,
5927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        status_t *status);
5937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    void disconnectEffect(const sp< EffectModule>& effect,
594a5f44ebaf58911805b4fb7fb479b19fd89d2e39bEric Laurent                                          EffectHandle *handle,
59558123c3a8b5f34f9d1f70264a3c568ed90288501Glenn Kasten                                          bool unpinIfLast);
5967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
5977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // return values for hasAudioSession (bit field)
5987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    enum effect_state {
5997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        EFFECT_SESSION = 0x1,   // the audio session corresponds to at least one
6007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                                // effect
6017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                        TRACK_SESSION = 0x2     // the audio session corresponds to at least one
6027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                                // track
6037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    };
6047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
6057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // get effect chain corresponding to session Id.
6067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<EffectChain> getEffectChain(int sessionId);
6077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // same as getEffectChain() but must be called with ThreadBase mutex locked
608106e8a42038f9e90d5ff97f8ab6f1a42258bde9eGlenn Kasten                    sp<EffectChain> getEffectChain_l(int sessionId) const;
6097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // add an effect chain to the chain list (mEffectChains)
6107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     status_t addEffectChain_l(const sp<EffectChain>& chain) = 0;
6117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // remove an effect chain from the chain list (mEffectChains)
6127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual     size_t removeEffectChain_l(const sp<EffectChain>& chain) = 0;
613d805b718b1fd2d5407ef665c8d4bb42e63dc71a9Glenn Kasten                    // lock all effect chains Mutexes. Must be called before releasing the
6147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // ThreadBase mutex before processing the mixer and effects. This guarantees the
6157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // integrity of the chains during the process.
616d805b718b1fd2d5407ef665c8d4bb42e63dc71a9Glenn Kasten                    // Also sets the parameter 'effectChains' to current value of mEffectChains.
617e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten                    void lockEffectChains_l(Vector< sp<EffectChain> >& effectChains);
6187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // unlock effect chains after process
619e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten                    void unlockEffectChains(const Vector< sp<EffectChain> >& effectChains);
6207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // set audio mode to all effect chains
621f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten                    void setMode(audio_mode_t mode);
6227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // get effect module with corresponding ID on specified audio session
623717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent                    sp<AudioFlinger::EffectModule> getEffect(int sessionId, int effectId);
6247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    sp<AudioFlinger::EffectModule> getEffect_l(int sessionId, int effectId);
6257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // add and effect module. Also creates the effect chain is none exists for
6267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // the effects audio session
6277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    status_t addEffect_l(const sp< EffectModule>& effect);
6287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // remove and effect module. Also removes the effect chain is this was the last
6297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                    // effect
630