396 Commits

Author SHA1 Message Date
Glenn Kasten
ed4271e1c1 Merge "Add comments about sequence for setting parameters" 2012-03-07 10:38:12 -08:00
Glenn Kasten
761415bd7f Merge the calls to prepareTracks_l
Change-Id: I1dd759581333e2908d980180d44db7bf5ed6591d
2012-03-07 07:28:12 -08:00
Glenn Kasten
b7a4007563 Merge "Rename fields of AudioSessionRef" 2012-03-06 16:22:30 -08:00
Glenn Kasten
bf10657c8e Add comments about sequence for setting parameters
Change-Id: Iffa59a34c3c47bdc1d3234cdcb4d8ff99c102825
2012-03-06 16:18:17 -08:00
Glenn Kasten
6be5247cc5 Merge "Fix indentation for re-organized code" 2012-03-06 15:23:58 -08:00
Glenn Kasten
2bad67f3e3 Rename updateWaitTime since a lock is held
Change-Id: I9bb978cbd0debf5b21676467060f72eebafea3e6
2012-03-06 12:46:21 -08:00
Glenn Kasten
26bbc5c0d3 Fix indentation for re-organized code
Change-Id: I63471cebdbd095b7ad4e481611b785f9b02c7941
2012-03-06 12:14:54 -08:00
Glenn Kasten
9a42ac982e Rename fields of AudioSessionRef
Change-Id: I9f2a66094135c4ac6bec2d3e9db3ac5fbf988ede
2012-03-06 11:43:55 -08:00
Glenn Kasten
67cb3126e8 threadLoop merge
Change-Id: Id8e6330ac6be76f9c2debba94f856de87e2d98f7
2012-03-05 11:01:10 -08:00
Eric Laurent
45d8c80dea renamed audio policy output flag.
Renamed AUDIO_POLICY_OUTPUT_FLAG_INDIRECT to AUDIO_POLICY_OUTPUT_FLAG_NONE
which is more appropriate.

Change-Id: Ia14d60397df0f2dcd9bea0186400a09da35bc104
2012-03-01 09:43:32 -08:00
Glenn Kasten
f79760b4aa Merge "Shorten thread names" 2012-02-29 14:59:08 -08:00
Glenn Kasten
d9cccfa19d Prepare for threadLoop merge - active tracks
Continued work on making the copies of threadLoop more similar:
 - Remove alias for mActiveTracks in MixerThread and DuplicatingThread.
 - Pull in declaration of activeTrack in DirectOutputThread.
 - Remove redundant parameter of prepareTracks_l().
 - Comment prepareTracks_l().

Change-Id: If1087c1902b454acec01ddfdd9f055f0ca7abf04
2012-02-29 14:52:54 -08:00
Glenn Kasten
d555d70fd4 Merge "Update AudioFlinger comments" 2012-02-29 14:44:39 -08:00
Glenn Kasten
fa52678fbe Merge "Pull in declaration of effectChains to inner block" 2012-02-29 14:43:19 -08:00
Glenn Kasten
3c4f0dc3bc Pull in declaration of effectChains to inner block
Change-Id: I09eacf72124942abd604132b9f4e774b1236fcf3
2012-02-29 11:49:50 -08:00
Glenn Kasten
e70583e629 mSuspend comments and usage
Emphasize that playbackthread::mSuspend is a counter, not a bool

Change-Id: I7188e56814e1c54dbc65e560f3627f138257d644
2012-02-29 11:36:54 -08:00
Glenn Kasten
bea6b95228 Mark similar and different sections in threadLoop
Most of these comments will be removed after the threadLoop merge.

Note: the trivial change in assignments to mixBufferSize, and the
comments about "tracks to remove" is to make them all identical.

Change-Id: I3b1a33a7f2cd12ad557a1986bb71f6171161974a
2012-02-29 09:38:15 -08:00
Glenn Kasten
f2218b7549 Update AudioFlinger comments
Add comments to enum mixer_state
Note side-effect of lockEffectChains_l
Fix a typo

Change-Id: Ibd51678bac2193201cbcbe081ff5664046fbc494
2012-02-29 07:01:44 -08:00
Glenn Kasten
86e3362f15 Shorten thread names
prctl(PR_SET_NAME) limits to 15 characters.  Before we had names like
"Binder Thread #" and the counter was cut off :-( Also remove redundant
"thread" at end of name; it's always a thread.

Change-Id: I1f99c2730ba0787ed9b59c15914356cddf698e2f
2012-02-28 16:38:09 -08:00
Glenn Kasten
f64dfccd96 Merge "Unlock effect chains in the middle of two if's" 2012-02-28 07:23:42 -08:00
Glenn Kasten
c2dc1c4e57 Merge "Simplify removeNotificationClient" 2012-02-28 07:21:51 -08:00
Glenn Kasten
eb70fe50dd Merge "AudioFlinger const methods and parameters" 2012-02-28 07:21:09 -08:00
Glenn Kasten
0d07b6a55f Merge "Fix theoretical race condition in addOutputTrack" 2012-02-28 07:18:27 -08:00
Glenn Kasten
2b119a6336 Merge "AudioBufferProvider comments and cleanup" 2012-02-28 07:17:47 -08:00
Glenn Kasten
fa28f57f29 Merge "Fix tracking of hardware state for dump" 2012-02-27 13:23:51 -08:00
Glenn Kasten
40ba9cddea Merge "Make threadLoop() logs identical" 2012-02-27 07:24:46 -08:00
Glenn Kasten
db316b212f Merge "Move declaration of mixerStatus to inner block" 2012-02-27 07:21:00 -08:00
Glenn Kasten
538529b9dc Simplify removeNotificationClient
No need to check for presence of item before removing
(but we do lose the log of the previous value).

Change-Id: I2838430824de5f257f2ee15db0c22b1920c67d08
2012-02-24 17:00:30 -08:00
Glenn Kasten
0fccd35b32 AudioFlinger const methods and parameters
Change-Id: I93ec28024005ed23aa141518092a012a4a7c44c5
2012-02-24 16:34:43 -08:00
Glenn Kasten
3be2bc08ee Make threadLoop() logs identical
Change the wording of the logs in the various copies of threadLoop()
to be identical.  This will make it easier to merge them soon.

Change-Id: Idfa181e437738712c784dc7f746cac79f83d2931
2012-02-24 16:26:07 -08:00
Glenn Kasten
26debac448 Move declaration of mixerStatus to inner block
mixerStatus was being declared (and initialized) too early,
which also resulted in a duplicate initialization.  Moved
the declaration into the block where it is actually used.

Change-Id: Ifdcfefe362a5efe3493dd616cdb44645c6f9aed5
2012-02-24 16:14:46 -08:00
Glenn Kasten
2521a01970 Pull out duplicated copies of silent mode check
Also fix the error handling for the property_get.

This is part of preparation for the threadLoop() merge.

Change-Id: I6405190ea18146d1271575e1dfe9f279e8f36b17
2012-02-24 16:02:24 -08:00
Glenn Kasten
e20ab3811a Unlock effect chains in the middle of two if's
As part of the upcoming threadLoop() merge, this CL makes it clearer
what are the similar and different parts before and after unlocking
effect chains.

In each threadLoop(), the old code was:

    if (sleepTime == 0) {
        // A
        unlockEffectChains(effectChains);
        // B
    } else {
        unlockEffectChains(effectChains);
        // C
    }

The new code is:

    if (sleepTime == 0) {
        // A
    }
    unlockEffectChains(effectChains);
    if (sleepTime == 0) {
        // B
    } else {
        // C
    }

Also this is slightly slower by one "if", it has the advantage of making
it much more obvious about what is done before and after the unlock,
and also to see the similarities and differences among the various
copies of threadLoop().

Change-Id: I7bf4369d2dcb072573ec43b7e52c637f0097dc00
2012-02-24 15:55:08 -08:00
Glenn Kasten
baad42e3a3 Merge "Pull CPU statistics code out of threadLoop()" 2012-02-24 14:25:15 -08:00
Glenn Kasten
91540aeb6c Fix theoretical race condition in addOutputTrack
This is not a real race, because addOutputTrack was only called in two
places, and in both places there could be no other threads referencing
the DuplicatingThread instance.

Those two places are:
 - the DuplicatingThread constructor, which is of course safe
 - openDuplicateOutput - this is safe because it's called immediately
   after the new DuplicatingThread, and there are no sp<> either in the
   constructor or here which could cause onFirstRef() to do Thread::run().

But for safety in case addOutputTrack is ever called somewhere else,
or there are sp<> created earlier, it is safer to take the thread lock.

Change-Id: I1502d014fa37ec5dbf4bf40d3e2884af311cd5e9
2012-02-24 14:20:29 -08:00
Glenn Kasten
6ec27552a0 Pull CPU statistics code out of threadLoop()
This is to prepare for the threadLoop() merge

Change-Id: I118c7d5c6b011b5d5b95ec7d63fb03feb166a9cf
2012-02-24 13:56:12 -08:00
Glenn Kasten
c2db119d0a AudioBufferProvider comments and cleanup
Add comments about which methods implement the AudioBufferProvider interface.

Simplified the definition of kInvalidPts.  <stdint.h> is very hard to work
with, there seems to be no way to use it reliably to get INT64_MAX without
having a separate source file, which is ugly because it means kInvalidPts
is not a compile-time constant.  So I just deleted AudioBufferProvider.cpp
and used a hard-coded constant instead.

Added a default constructor for Buffer so that the fields aren't random
(especially .raw which is used to determine if the buffer is valid).

Make the pts for getNextBuffer default to kInvalidPTS so code that
doesn't need a pts doesn't have to specify a value.

Rename the parameter to AudioMixer::setBufferProvider to make it clearer.

Change-Id: I87e7290884d4ed975b019f62d1ab6ae2bc5065a5
2012-02-24 13:42:13 -08:00
Glenn Kasten
23c9c74017 Fix tracking of hardware state for dump
At end of AudioFlinger::onFirstRef(), the hardware status was being left
in wrong state.  It should be AUDIO_HW_IDLE but was AUDIO_HW_INIT.

mHardwareStatus was being set to AUDIO_HW_OUTPUT_OPEN too early, and so
a return would leave it in the wrong state until next hardware operation.

Take the hardware lock for dev->get_parameters, and update mHardwareStatus
before and after.

Keep hardware lock only for the duration of the dev->set_parameters.

Rename two constants in enum hardware_call_state to have the prefix
AUDIO_HW so they follow the naming conventions.

Add comments.

Change-Id: I6c7450b11f9b13adaeef9cec874333e478a58fc0
2012-02-24 13:31:26 -08:00
Glenn Kasten
3526982c1d Remove TrackBase::mFlags
The bit-field TrackBase::mFlags was supposed to have track-specific
flags in the upper 16 bits, and system flags in the lower 16 bits.

The upper 16 bits of mFlags were initialized in the TrackBase
constructor from the flags parameter of IAudioFlinger::createTrack()
and IAudioFlinger::openRecord(), and the lower 16 bits were cleared.

However, the upper 16 bits of mFlags were never acccessed again.
So really there are no track-specific flags.  I left the flags
in the parameter list of createTrack() and openRecord() but made a
note that these should be removed eventually as they are dead.

This leaves only the one system flag "step server failed".  I replaced
the bit-field mFlags by bool mStepServerFailed, which is simpler and
slightly faster.

Change-Id: I6650f5487be72791b4a67d73adcd10ffa04e2aa5
2012-02-24 13:14:28 -08:00
Glenn Kasten
3bf96c9c9a Merge "Avoid wp<>::unsafe_get() with a few exceptions" 2012-02-22 13:22:13 -08:00
Glenn Kasten
685c9ce3bd Avoid wp<>::unsafe_get() with a few exceptions
Avoid using wp<>::unsafe_get() except in a log, and other specific cases
when it's known to be safe.

Use more specific subclass types for parameters to avoid down-casts.

When a constructor or method parameter is "this" of an object that is
currently being constructed, it's better to use a raw pointer rather
than either sp<> or wp<>.

Using the raw pointer is safe, provided either:
 - it is "this" of an object being constructed (which has sp<> refcount of 0),
 - or the caller already holds an sp<>

The raw pointer is simpler and faster, and it avoids the problem of the
sp<> reference count being incremented and then decremented to zero on
scope exit, which would cause the object's destructor to run while the
object is still being constructed.

Also removed some dead code per a review comment.

Change-Id: I7375f64da3aec11b928c33cb01faff186252ef5e
2012-02-22 13:19:26 -08:00
Glenn Kasten
175b2be791 Fix build warning
warning: pointer of type 'void *' used in arithmetic
warning: enumeral and non-enumeral type in conditional expression

Change-Id: I7b8d626a636145ef648e3b5d0e77068216dd012e
2012-02-22 11:46:53 -08:00
Glenn Kasten
4f22c05eac Remove bit fields to improve performance
uint16_t enabled is (mostly) changed to bool in a separate CL

Change-Id: Ied9f8c034b2479cee9a8778cee7b8ff92ae75b7b
2012-02-17 09:41:56 -08:00
Glenn Kasten
e13ac73a38 Merge "Simplify code" 2012-02-17 09:40:43 -08:00
Glenn Kasten
7d3be3a3c1 Simplify code
Use DefaultKeyedVector::valueFor to avoid extra test
Make local variables as local as possible
No double parentheses
No typedef for single use
No parentheses around indirect function call
No AudioFlinger:: prefix when not needed
Remove unnecessary casts
Remove block with only one line

Saves 128 bytes

Change-Id: I3a87430eeb01b81e7b81a1c38f6fdd3274ec48f3
2012-02-17 09:39:07 -08:00
Mike Lockwood
e7c84be432 Merge "Put a bandaid on a segfault in timed audio track handling." 2012-02-17 09:20:43 -08:00
John Grossman
8c010615bf Put a bandaid on a segfault in timed audio track handling.
Add a bandaid to prevent a segfault which can occur while handling
timed audio buffers.  There is a deeper problem which should
eventually be addressed, but for now this fix should prevent any
crashing.

The deeper problem is as follows.

When the AudioFlinger mixer gets data to mix from an AudioTrack, it
ends up getting a structure filled out which points into an IMemory
region owned by the AudioTrack.  Unfortunately, this structure is not
holding a refcount on the IMemory which it points into.  If the
IMemory refcount hits 0 and the chunk of RAM is retuned to the binder
heap it came from, there can still be a Buffer object being held by
the AudioFlinger mixer which points into the region of memory which
was retuned to the binfer heap.  If AF reads from this buffer, it
could read corrupt data (if the region of memory gets handed back out
to a writer), or it could segfault (if the heap has been freed and the
pages unmapped).  Similar problems could happen if AF attempts to
write to the buffer, heap corruption in one case, segfaulting in the
other.

In the past, this has not been an issue for AF, because tracks
allocate a single IMemory (which serves as a ring buffer) and the
IMemory lives for as long as the track lives.  As an artifact of the
way the code came out, the mixer cannot be holding a Buffer structure
pointing into the IMemory which used to be owned by a track if the
track no longer exists.  Tracks cannot come into or out of existence
during a mix operation, which is the only thing which makes this safe.

TimedTracks work differently, however.  Timed tracks each allocate a
small binder heap, and then hand out IMemory instances  broken out of
this heap.  The heap lives as long as the track, so the worst which
could happen here is that a TimedTrack's IMemory gets returned to the
heap while there is still a buffer structure in flight pointing into
the memory region, then the region gets handed out again and
overwritten by new data causing the mixer to mix the wrong audio.  The
timing to cause this to happen is very difficult to encounter, and you
to generate the timing conditions required, you need to be in a pretty
bad failure state where audio is already breaking up and skipping, so
its unlikely that anyone would notice (which is why I'm band-aiding
the segfault and letting the deeper issue slide for now).

In general, however, it might be a good idea to revisit this buffering
design.  On principal, if someone is going to hold pointers into a
refcounted object, they should be holding a ref on the object at the
same time.  Failure to do this will usually lead to a situation where
there are corruption or segfault issues, or to a system where the
refcounted object's lifetime must be implicitly managed very carefully
in ways which are usually non-obvious and are easy to break by new
engineers on a project.

Change-Id: Ib391075395ed0ef46a03c37aa38a82d09e88abeb
2012-02-16 17:59:30 -08:00
Glenn Kasten
afe9833de9 Fixed possible heap corruption in EffectDesc
"EffectDesc *effect = new EffectDesc(*effects[i]);" was relying on the
default copy constructor for EffectDesc, but the default copy constructor
does a member-by-member copy.  This works OK for mUuid, but a member
copy of mName and mParams shares pointers.  This could result in heap
corruption later on due to a double free.  Changed to add an explicit
copy constructor that does a deep copy of both mName and mParams.

A malloc() and strdup() were being freed by delete, but the correct
matching API for these is free().  Fortunately our current memory runtime
implementation ignores the difference. Changed to use free().

EffectDesc and InputSourceDesc member fields were being torn down by
the code that does delete.  Changed to do the tear-down in ~EffectDesc()
and ~InputSourceDesc().

Added constructor EffectDesc() with name and UUID parameters, rather
than having caller fill in the object after construction.

Made ~EffectDesc() and ~InputSourceDesc() non-virtual to save memory,
since they have no subclasses.

Change-Id: Ibb5cc2e6760d72e0c4cf537068ac4432c717bafd
2012-02-16 16:57:44 -08:00
John Grossman
4fbe95ede2 Fix a segfault in AudioFlinger.
Check the string returned by a HAL's implementation of get_parameters
for NULL before attempting to make use of it.  That way, we won't
bring down the mediaserver because of a poorly written HAL.

Change-Id: Ic99d7b004520d7d6347842a681c0595e889b68ea
Signed-off-by: John Grossman <johngro@google.com>
2012-02-16 13:45:12 -08:00
John Grossman
d8cf2960d0 Upintegrate Audio Flinger changes from ICS_AAH
Bring in changes to audio flinger made to support timed audio tracks
and HW master volume control.

Change-Id: Ide52d48809bdbed13acf35fd59b24637e35064ae
Signed-off-by: John Grossman <johngro@google.com>
2012-02-16 13:45:11 -08:00