80 Commits

Author SHA1 Message Date
Glenn Kasten
f55bc56490 Merge "Use audio_in_acoustics_t consistently" 2012-02-03 08:31:01 -08:00
Glenn Kasten
7bd4f6f4d0 Merge "For performance, return large objects by reference" 2012-02-03 07:46:42 -08:00
Glenn Kasten
dc3ac85009 Constructor initialization and const fields
In constructors, initialize member fields in the initialization list
rather than constructor body where possible.  This allows more fields
to be const, provided they are never modified.

Also initialize POD fields in constructor, unless it's obvious they
don't need to be initialized.  In that case, put a comment instead.

Remove explicit clear() in destructors on fields that are now const.

Give AudioSessionRef a default constructor, so it's immutable fields can
be marked const.

Add comment about ~TrackBase() trick.

Initialize fields in declaration order to make it easier to confirm that
all fields are set.

Move initialization of mHardwareStatus from onFirstRef() to constructor.

Use NULL not 0 to initialize raw pointers in initialization list.

Rename field mClient to mAudioFlingerClient, and getter from client()
to audioFlingerClient().

Change-Id: Ib36cf6ed32f3cd19003f40a5d84046eb4c122052
2012-02-03 07:37:14 -08:00
Glenn Kasten
a12b6d1d44 Merge "Cleanup thread types" 2012-02-03 07:26:28 -08:00
Glenn Kasten
9704026ccb For performance, return large objects by reference
Change-Id: Ibf737018ef1d3c7d717584615dcb2d4ecdb50c99
2012-01-30 13:01:17 -08:00
Glenn Kasten
1f812f720f Fix const sp<>& in parameter list and return value
EffectModule::addHandle and Client::heap() were declared incorrectly.

As a parameter, an sp<> should be & for efficiency, and for input
parameters it should also be const to protect the caller's value.

But as a return value, an sp<> should have neither const or &.  The "e"
in "return e;" might be located on the stack, and if there is "&" then
the caller would see the address of a variable which no longer exists.
Also, an & would make it hard to do "return 0;".
A "const" without & is meaningless in the return type.
(In this particular case, the "e" is a member field, so it was safe.)

Change-Id: I3df5f294214eb15a9d4d596c6d5ef29de97b5c27
2012-01-30 10:31:09 -08:00
Glenn Kasten
882c0a20c5 Use audio_in_acoustics_t consistently
Change-Id: I0a9dd668fb2e57b1c3ece3190588194974b99062
2012-01-27 13:31:54 -08:00
Glenn Kasten
c1f63ddba7 Merge "AudioStreamIn and AudioStreamOut" 2012-01-27 07:22:30 -08:00
Glenn Kasten
6562dadf3c Merge "Declare methods in binder opcode order" 2012-01-27 07:19:53 -08:00
Glenn Kasten
591993f162 Merge "Use enum effect_state consistently" 2012-01-27 07:19:10 -08:00
Glenn Kasten
86012869b8 Merge "Use enum track_state consistently" 2012-01-27 07:18:23 -08:00
Glenn Kasten
5b0135e41b AudioStreamIn and AudioStreamOut
These are immutable, so make the fields const.
getOutput() and getInput() methods are now const.

Change-Id: I128246ebd56ea50b3e542be43f2aa1bcb55f1373
2012-01-26 15:58:07 -08:00
Glenn Kasten
efd511a925 Cleanup thread types
Use type_t instead of int for thread types.
Initialize ThreadBase::mType in constructor and make it const.

Change-Id: I43d141388b9639e4783c30b97dbda5688bf7555f
2012-01-26 15:45:12 -08:00
Glenn Kasten
0ae4d97689 Declare methods in binder opcode order
This makes it easier to compare interface and implementation.

Change-Id: Ie060e43dec348902abcf40f5a610cec639d6d0d3
2012-01-26 14:34:30 -08:00
Glenn Kasten
789fef1f83 Use enum mixer_state consistently
Change-Id: I5b71ed20f939dfc4b98143334b7aa064d282f584
2012-01-26 14:23:47 -08:00
Glenn Kasten
452d6d6efe Use enum effect_state consistently
Also fix indentation

Change-Id: I393ef9e37ffceed5ad4a78df439726ae1fe139df
2012-01-26 14:20:34 -08:00
Glenn Kasten
563562032d Use enum track_state consistently
Change-Id: Ie5ebb7befa092e1de1e4df9c6e2d51e6bcfd176a
2012-01-26 14:13:43 -08:00
Glenn Kasten
34f9f8bb83 Remove AudioFlinger dependencies on client
Change-Id: Ibb591e41a3ca5d7015e2b66b98b8fef5f415fb37
2012-01-20 17:12:59 -08:00
Glenn Kasten
0a204ed0f5 Use audio_format_t consistently, continued
Was int or uint32_t.

When AudioFlinger::format can't determine the correct format,
return INVALID rather than DEFAULT.

Init mFormat to INVALID rather than DEFAULT in the constructor.
Subclass constructors will set mFormat to the correct value.

Change-Id: I9b62640aa107d24d2d27925f5563d0d7407d1b73
2012-01-20 14:41:34 -08:00
Eric Laurent
3562931af9 resolved conflicts for merge of 05683c85 to master
Change-Id: I7846b7da8c5813b7a9b1f3f71aede0229689ff0d
2012-01-19 10:00:02 -08:00
Eric Laurent
71c4496a97 AudioFlinger: mix track only when really ready (2)
This problem due to the way audio buffers are mixed when
low power mode is active was addressed by commits 19ddf0eb
and 8a04fe03 but only partially. As a matter of fact, when more
than one audio track is playing, the problem is still present.
This is most noticeable when playing music with screen off
and a notification or navigation instruction is played: in this case,
the music or notification is likely to skip.

The fix consists in declaring the mixer ready if all active tracks
are ready. Previous behavior was to declare ready if at least one track was
ready. To avoid that one application failing to fill the track buffer blocks other
tracks indefinitely, this condition is respected only if the mixer was ready
in the previous round.

Issue 5799167.

Change-Id: Iabd4ca08d3d45f563d9824c8a03c2c68a43ae179
2012-01-18 12:27:38 -08:00
Glenn Kasten
8df33080f9 Remove dead setVolume() and mVolume[2]
Change-Id: I94b835434093e920432614eb5007101e87758f32
2012-01-17 13:33:33 -08:00
Glenn Kasten
fb6b5bdcea Merge "Use audio_mode_t consistently" 2012-01-17 11:32:53 -08:00
Glenn Kasten
6e987a46f4 Check stream type in AudioFlinger::createTrack
A bad parameter to AudioFlinger::createTrack could cause mediaserver to crash.

Other AudioFlinger stream type cleanup:
 - Simplify range check for audio_stream_type_t
 - Add comment about mStreamTypes array initialization.

Change-Id: Ia33aa1cce0fdd694b08d9288816ffc097a9543d0
2012-01-17 07:45:07 -08:00
Glenn Kasten
c80f407829 Merge "Fix locking for mMasterVolume and mMute" 2012-01-17 07:28:14 -08:00
Glenn Kasten
8c17a2f088 Merge "Use size_t for frame size" 2012-01-17 07:27:46 -08:00
Glenn Kasten
e6f8a425da Fix locking for mMasterVolume and mMute
mMasterVolume and mMute are both protected by mutex in AudioFlinger class, but
there were two places where they were accessed without a mutex.

Also make AudioFlinger::mMasterMute private not protected.

Change-Id: Ia3897daeb5c50313df5bcc071824357526237f3e
2012-01-13 15:53:10 -08:00
Glenn Kasten
faf354dc7f Use size_t for frame size
except in the control block, where we don't have room.

In AudioFlinger::ThreadBase::TrackBase::getBuffer,
read the frame size from control block only once.

Change-Id: Id6c4bccd4ed3e07d91df6bbea43bae45524f9f4e
2012-01-13 14:58:44 -08:00
Glenn Kasten
bc1d77b6cb Use audio_stream_type_t consistently
At native level it was a mixture of audio_stream_type_t, int, uint32_t,
and uint8_t.  Java is still int.  Also fixed a couple of hard-coded -1
instead of AUDIO_STREAM_DEFAULT, and in startToneCommand a hard-coded 0
instead of AUDIO_STREAM_VOICE_CALL.

Change-Id: Ia33bfd70edca8c2daec9052984b369cd8eee2a83
2012-01-13 10:20:14 -08:00
Glenn Kasten
accb114e59 Use audio_mode_t consistently
It was int or uint32_t.
Also make getMode() const.

Change-Id: Ibe45aadbf413b9158e4dd17f2b3bcc6355288d37
2012-01-12 09:52:37 -08:00
Glenn Kasten
88ef0a73fc Merge "Use correct type for hardware call state" 2012-01-11 10:25:23 -08:00
Glenn Kasten
4e7191448d Merge "By convention const goes before the type specifier" 2012-01-09 11:59:17 -08:00
Glenn Kasten
a934c2cd2d Use correct type for hardware call state
Change-Id: Ic6d98b129e3ec653df1d8f7e829adf8dccb4f378
2012-01-06 13:29:47 -08:00
Glenn Kasten
99c2fd36dc By convention const goes before the type specifier
Change-Id: I70203abd6a6f54e5bd9f1412800cc01212157e58
2012-01-06 08:00:59 -08:00
Glenn Kasten
1dce841996 suspended() and isSuspended() are const
Change-Id: I04b95970b5a645b64e7e64fffd46d868354dda66
2012-01-05 10:51:02 -08:00
Glenn Kasten
e80a4ccd2b Use the standard CC_LIKELY and CC_UNLIKELY macros
Several source files privately defined macros LIKELY and UNLIKELY in terms
of __builtin_expect. But <cutils/compiler.h> already has CC_LIKELY and
CC_UNLIKELY which are intended for this purpose.  So rename the private
uses to use the standard names.

In addition, AudioFlinger was relying on the macro expanding to extra ( ).

Change-Id: I2494e087a0c0cac0ac998335f5e9c8ad02955873
2012-01-05 07:33:45 -08:00
Glenn Kasten
cf45596da3 Merge "Improve resistance to leaks for ConfigEvent" 2011-12-15 16:17:04 -08:00
Glenn Kasten
4b220f0a7b Improve resistance to leaks for ConfigEvent
A Vector of pointers is risky, as there is no ownership (and the
ThreadBase destructor was not deleting them, so if there were any left
over at end it would leak).  Replaced by a Vector of values.

Change-Id: Iddde72dc30134adfcf724dec26cbe0a742509b8c
2011-12-15 12:51:52 -08:00
Glenn Kasten
c434c90cc2 Use NULL not 0 for pointers
Change-Id: Iab3f9abbdab617dc5a599e657ec46a0b0a002eef
2011-12-15 09:18:17 -08:00
Eric Laurent
4433169a64 audioflinger: fix audio skipping over A2DP
The maximum sleep time allowed in the mixer thread when audio tracks
are enabled but not ready for mixing is derived from the latency
reported by the output stream.
This does not work for A2DP where the latency also reflects encoding, decoding
and transfer time.

Modified activeSleepTimeUs() to take A2DP case into account.

Issue 5682206.

Change-Id: I3784ac01fb6f836b5a6ce6f764fb15347586de35
2011-12-05 10:40:18 -08:00
Eric Laurent
f9c361dec4 audioflinger: fix noise when skipping to next song
When audio effects are enabled, a noise can be heard at the
beginning of the new song when skipping to next song in music app.

This is because some effects (especially virtualizer) have a tail.
This tail was not played when previous song was stopped because effects were
not processed when no tracks were present on a given session. This is to
reduce CPU load when effects are enabled but no audio is playing.
The tail was then rendered when the new song was started.

Added a delay before stopping effect process after all tracks have been removed from a session.

Issue 5584880.

Change-Id: I815e0f7441f9302e8dfe413dc269a94e4cc6fd95
2011-11-11 16:33:24 -08:00
Eric Laurent
7fa1cee12c Fix issue 381905: BassBoostTest CTS tests fail...
When AudioEffectTest is executed, an Equalizer is created
and enabled on a MediaPlayer session. Effects on the output
mix are therefore suspended.
Then the MediaPlayer is released with the effect still enabled.
In this case, Audioflinger::purgeStaleEffects_l() fails to restore
the suspended effects when the effect attached to the released audio session
is removed.
When subsequent tests are executed on output mix effects, these effects cannot be
enabled as they are still suspended.

Fixed purgeStaleEffects_l() to restore suspended effects if the effect removed is enabled.

Also fixed EffectHandle::disconnect() to only restore suspended effects if the disconnected
handle actually has control over the effect.

Change-Id: I67232e7c34680b0cc01abfd57d5d510a524e5d4f
2011-10-19 11:44:54 -07:00
Eric Laurent
6fccbd04fc Fix issue 5381089: problem with A2DP music volume
This problem only occurs when audio effects are present and
the music volume is applied by one effect engine.
When connecting or disconnecting A2DP, audio effects are moved from
one mixer thread to another. When removed from the source thread,
the effect is stopped but it is not restarted when added to the
destination thread.
This regression was introduced by commit 21b5c47e.

Change-Id: I4cc578d8d760ec65b185032b6fda98c739d331bc
2011-10-05 17:42:25 -07:00
Eric Laurent
0e35c78d25 Merge "226483: A2DP connected, but music out to speaker" 2011-08-30 10:51:54 -07:00
Eric Laurent
05ce094164 226483: A2DP connected, but music out to speaker
When the A2DP headset is connected, there is a possible
race condition when the audio tracks are moved from
the mixer thread attached to the speaker output to the thread
attached to A2DP output.
As the request to clear the stream type to output mapping cache in
the client process is asynchronous, it is possible that the flag
indicating to the client audio track to re-create the IAudioTrack
on the new thread is processed before the cache is invalidated.
In this case, the track will be attached to the old thread and
music will continue playing over the device speaker instead of being
redirected to A2DP headset.

Change-Id: Ib2ce1eb5320eaff83287b93779061bf4e7a330df
2011-08-30 10:19:38 -07:00
Eric Laurent
2d95dfbf4d Audioflinger: reverse logic of BT NREC indication
The interpretation of BT NREC by AudioFlinger to enable
or disable AEC and NS was wrong: NREC to ON (default) means
the phone (Audio Gateway) must enable local AEC and NS.

Change-Id: I88a264e7fc9831c43bbace4f6b585baec73f2006
2011-08-29 14:50:38 -07:00
Eric Laurent
6752ec80b2 Audio effects: track CPU and memory use separately
Before this change, CPU and memory usage for an audio effect were
registered and checked against the limit by audio policy manager
upon effect instantiation. Even if an effect was not enabled
it would prevent another effect to be created if the CPU load budget
was exceeded, which was too restrictive.

This change adds a method to register/unregister CPU load only when
an effect is enabled or disabled.
It also adds a mechanism to place all effects on the global output mix
in suspend state (disabled) when an effect is enabled on a specific session.
This will allow applications using session effects to have the priority
over others using global effects.

Also fixes some issues with suspend/restore mechanism:
- avoid taking actions when an effect is disconnected and was not enabled.
- do not remove a session from the suspended sessions list when corresponding
effect chain is destroyed.

Change-Id: I5225278aba1ae13d0d0997bfe26a0c9fb46b17d3
2011-08-11 14:33:45 -07:00
Marco Nelissen
c74b93fdf3 Keep effects sessions active when the caller dies.
Don't remove effects until the session they are in goes away or all
AudioEffects have been explicitly released. This allows the control
panel process to die without stopping the effects.

Change-Id: I4496e5df080230ca1af149dec95c1309ab8ea888
2011-08-09 10:21:10 -07:00
Eric Laurent
c993acbce6 Merge "AudioFlinger: protect input/output stream access" 2011-08-08 09:31:42 -07:00
Eric Laurent
828b9773cc AudioFlinger: protect input/output stream access
Some methods would not check that the output orinput stream of a thread
was still valid before calling functions on its interface.
This could cause a crash if those methods where called while the output or
input was being closed by another thread.

Make sure that the output or input stream pointer is cleared before closing the
stream.
Always check that the output or input pointer is not null before calling
functions at the stream interface.
Generalize the use of initCheck() method to verify that the output or input
stream is not null.

Change-Id: I9d9ca6b744d011bcf3a7bbacb4a581ac1477bfa5
2011-08-08 08:55:29 -07:00