summaryrefslogtreecommitdiffstats
path: root/services/audioflinger
Commit message (Collapse)AuthorAgeFilesLines
* Merge "Pull CPU statistics code out of threadLoop()"Glenn Kasten2012-02-241-31/+42
|\
| * Pull CPU statistics code out of threadLoop()Glenn Kasten2012-02-241-31/+42
| | | | | | | | | | | | This is to prepare for the threadLoop() merge Change-Id: I118c7d5c6b011b5d5b95ec7d63fb03feb166a9cf
* | Remove TrackBase::mFlagsGlenn Kasten2012-02-242-24/+13
|/ | | | | | | | | | | | | | | | | | | | 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
* Merge "Avoid wp<>::unsafe_get() with a few exceptions"Glenn Kasten2012-02-222-38/+25
|\
| * Avoid wp<>::unsafe_get() with a few exceptionsGlenn Kasten2012-02-222-38/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Fix build warningGlenn Kasten2012-02-221-1/+1
|/ | | | | | | warning: pointer of type 'void *' used in arithmetic warning: enumeral and non-enumeral type in conditional expression Change-Id: I7b8d626a636145ef648e3b5d0e77068216dd012e
* Remove bit fields to improve performanceGlenn Kasten2012-02-173-21/+32
| | | | | | uint16_t enabled is (mostly) changed to bool in a separate CL Change-Id: Ied9f8c034b2479cee9a8778cee7b8ff92ae75b7b
* Merge "Simplify code"Glenn Kasten2012-02-175-45/+20
|\
| * Simplify codeGlenn Kasten2012-02-175-45/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Merge "Put a bandaid on a segfault in timed audio track handling."Mike Lockwood2012-02-171-4/+17
|\ \
| * | Put a bandaid on a segfault in timed audio track handling.John Grossman2012-02-161-4/+17
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Fixed possible heap corruption in EffectDescGlenn Kasten2012-02-162-22/+35
|/ | | | | | | | | | | | | | | | | | | | | | | | | "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
* Fix a segfault in AudioFlinger.John Grossman2012-02-161-1/+1
| | | | | | | | | 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>
* Upintegrate Audio Flinger changes from ICS_AAHJohn Grossman2012-02-1611-80/+874
| | | | | | | | 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>
* Merge "Fix races related to volume and mute"Glenn Kasten2012-02-142-31/+31
|\
| * Fix races related to volume and muteGlenn Kasten2012-02-082-31/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix race conditions when setting master volume, master mute, stream volume, stream mute for a playback thread, and when reading stream volume of a playback thread. Lock order is AudioFlinger, then thread. Rename streamVolumeInternal to streamVolume_l, comment, and use it to implement streamVolume(). Code size reduction: - Remove dead code: AudioFlinger::PlaybackThread::masterVolume, masterMute, streamMute. - Change return type of non-binder methods that always succeed from status_t to void. - Remove virtual from volume and mute methods that don't need it. This change saves 228 bytes but decreases performance of binder operations due to the added locks. Change-Id: Iac75abc1f54784873a667d1981b2e08f8f31e5c9
* | Merge "Update comments"Glenn Kasten2012-02-144-8/+27
|\ \
| * | Update commentsGlenn Kasten2012-02-144-8/+27
| | | | | | | | | | | | | | | | | | We no longer put the filename at start of file. Change-Id: Ic435b159a23105681e3d4a6cb1ac097bc853302e
* | | Use size_t and ssize_t with VectorGlenn Kasten2012-02-142-27/+27
|/ / | | | | | | | | | | | | | | Use size_t with size() and ssize_t with indexOfKey(). Exception: use ssize_t for backwards loops, and indices that are overloaded as a marker or error code. Change-Id: Ibf2a360af4539b72b09c818dda22ea2a0de92431
* | AudioRecord and AudioTrack client tidGlenn Kasten2012-02-142-20/+21
| | | | | | | | | | | | Inform AudioFlinger of the tid of the callback thread. Change-Id: I670df92dd06749b057238b48ed1094b13aab720b
* | Factor out and speed up permission-checking codeGlenn Kasten2012-02-135-33/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | Use the caching permission check for dump to save IPC. Cache getpid() to save kernel call for other permission checks. The C runtime library getpid() can't cache due to a fork race condition, but we know that mediaserver doesn't fork. Don't construct String16 on the stack. Change-Id: I6be6161dae5155d39ba6ed6228e7683e67be34ed
* | mAudioHwDevs and related cleanupGlenn Kasten2012-02-102-23/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Inline AudioFlinger::initCheck and remove unnecessary lock. Remove redundant check of mAudioHwDevs.size(). No need to lock mHardwareLock for each device separately during initialization. Use size_t not int to loop through Vector, since size() returns size_t. Add missing hardware lock for get_mic_mute() and get_input_buffer_size(). Add comments. Change-Id: Iafae78ef78bbf65f703d99fcc27c2f4ff221aedc
* | Merge "Simplify ThreadBase::exit() aka requestExitAndWait"Glenn Kasten2012-02-102-9/+20
|\ \
| * | Simplify ThreadBase::exit() aka requestExitAndWaitGlenn Kasten2012-02-102-9/+20
| |/ | | | | | | | | | | | | | | | | | | | | | | We can remove mExiting and use Thread::exitPending() instead. The local sp<> on "this" in exit() is not needed, since the caller must also hold an sp<> in order to be calling us. (Unless it was using a raw pointer, but that would be dangerous for other reasons.) Add comment explaining the mLock in exit(). Change-Id: I319e5107533a1a7cdbd13c292685f3e2be60f6c4
* | Merge "Disable HQ resamplers for now until qualified"Glenn Kasten2012-02-102-2/+6
|\ \
| * | Disable HQ resamplers for now until qualifiedGlenn Kasten2012-02-092-2/+6
| |/ | | | | | | | | | | This saves about 6500 bytes. Change-Id: I87102fe561c95c19c9e615dea3de914f96639257
* | Merge "Move header declarations around for clarity"Glenn Kasten2012-02-101-35/+37
|\ \
| * | Move header declarations around for clarityGlenn Kasten2012-02-091-35/+37
| |/ | | | | | | | | | | | | | | Put IAudioFlinger methods in binder opcode order. Move hardware call state closer to where it is used. getMode() and btNrecIsOff() are private. Change-Id: Ie50340b396c39c763f2b155cbc08da8a0d0f2424
* | Merge "Camel case readability & private disconnect(bool)"Glenn Kasten2012-02-102-10/+12
|\ \
| * | Camel case readability & private disconnect(bool)Glenn Kasten2012-02-092-10/+12
| |/ | | | | | | Change-Id: If66516ed2703e048c5e6ccc6cd431446a024f4a1
* | Merge "Remove aliasing"Glenn Kasten2012-02-101-12/+11
|\ \
| * | Remove aliasingGlenn Kasten2012-02-091-12/+11
| |/ | | | | | | | | | | | | | | | | Code was aliasing mBuffer as buffer, but continuing to use both buffer and mBuffer after that point. This was at best misleading, and at worst could confuse the compiler into generating bad code. There was no performance advantage to the alias, in fact removing it saves 16 bytes. Change-Id: I55023ddba465d9be82f66745b088d18af658ac60
* | Merge "Use mul from audioutils"Glenn Kasten2012-02-101-15/+0
|\ \
| * | Use mul from audioutilsGlenn Kasten2012-02-091-15/+0
| |/ | | | | | | | | | | I verified that the disassembled output is identical. Change-Id: I34a76f0842ebc4aef2c923e079e38d0bc1f98b5c
* | Merge "Mark fields const if only set in constructor"Glenn Kasten2012-02-101-3/+3
|\ \
| * | Mark fields const if only set in constructorGlenn Kasten2012-02-091-3/+3
| |/ | | | | | | Change-Id: Iacd06bb9efaf708cf965033be1f2297b58f7f75c
* | Follow raw pointer and sp<> conventionsGlenn Kasten2012-02-101-2/+2
| | | | | | | | | | | | | | | | Unconditional delete for raw pointers. Use "if (sp != 0)" not "if (sp.get() != 0)" or "if (sp != NULL)". Use "if (raw != NULL)" not "if (raw)". Change-Id: I531a8da7c37149261ed2f34b862ec4896a4b785b
* | Merge "No newline or space at end of ALOG format string"Glenn Kasten2012-02-103-23/+23
|\ \
| * | No newline or space at end of ALOG format stringGlenn Kasten2012-02-083-23/+23
| |/ | | | | | | Change-Id: I0bef580cbc818cb7c87aea23919d26f1446cec32
* | Merge "Move declaration of stream_type_t up earlier"Glenn Kasten2012-02-101-13/+13
|\ \
| * | Move declaration of stream_type_t up earlierGlenn Kasten2012-02-081-13/+13
| |/ | | | | | | | | | | | | stream_type_t is used by AudioFlinger class, so it should be declared there. This way we don't have to peek into PlaybackThread to get the declaration. Change-Id: Ie08bab1604699214d1e8df2d48d3fbfbbc436e96
* | Merge "Fix typos in ALOG for pid vs tid"Glenn Kasten2012-02-102-7/+7
|\ \
| * | Fix typos in ALOG for pid vs tidGlenn Kasten2012-02-092-7/+7
| |/ | | | | | | Change-Id: I6dc70f137d0ff8a86427ab8882a81886e1de0782
* | Rename type() to streamType()Glenn Kasten2012-02-082-23/+14
|/ | | | | | | This avoids possible confusion with thread's type(). Also remove redundant cast "(audio_stream_type_t)". Change-Id: I320b9177b6c267a102d215f002228bcf988c437a
* Combine duplicate code & document wp<> in mClientsGlenn Kasten2012-02-082-30/+23
| | | | Change-Id: Iea8cfe8e57563337fb2484a1246ef79d6ad3db18
* Use audio_io_handle_t consistently instead of intGlenn Kasten2012-02-084-86/+103
| | | | | | | | Other: - add a comment to nextUniqueId - made ThreadBase::mId const, since it is only assigned in constructor. Change-Id: I4e8b7bec4e45badcde6274d574b8a9aabd046837
* Simplify destructorsGlenn Kasten2012-02-081-4/+2
| | | | | | Remove explicit clear() when the order doesn't matter. Change-Id: I5931bc7ef5f681c7ce329aa9ec0a6e46d34a56c5
* Effect UUID inputs passed by pointer are constGlenn Kasten2012-02-082-2/+2
| | | | Change-Id: I1f5c338bcb7368e3dd8cd5f804b2e6d9fbe087f8
* Merge "Use pid_t not int"Glenn Kasten2012-02-081-3/+3
|\
| * Use pid_t not intGlenn Kasten2012-02-031-3/+3
| | | | | | | | Change-Id: Iad1c2fd4152e94080ad8c65c13ddf4519fc2ed27