summaryrefslogtreecommitdiffstats
path: root/media/libmedia/AudioTrack.cpp
Commit message (Collapse)AuthorAgeFilesLines
* am 88876fb4: AudioTrack: fix obtainBuffer timeout calculationEric Laurent2014-03-051-1/+1
|\ | | | | | | | | * commit '88876fb4eb8365343f2a9ca0e8f53148ca38b845': AudioTrack: fix obtainBuffer timeout calculation
| * AudioTrack: fix obtainBuffer timeout calculationEric Laurent2014-03-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | AudioTrack::obtainBuffer() passes a pointer to a timeout variable that has gone out of scope when calling ClientProxy::obtainBuffer(). Same fix for AudioRecord. Bug: 11968591. Change-Id: I5b3d0d86ed2bd8c0412eb2432b1ab519d70efce9
| * update offloaded audio track sampling rateEric Laurent2014-03-051-0/+13
| | | | | | | | | | | | | | | | | | | | AudioPlayer must read the sampling rate from offloaded audio sinks whenever a new time position is computed as the decoder can update the sampling rate on the fly. Bug: 12823955. Change-Id: I997e5248cfd4017aeceb4e11689324ded2a5bc88
| * AudioTrack: fix position callback after restoreEric Laurent2013-11-271-1/+0
| | | | | | | | | | | | | | | | | | | | | | When restoring an AudioTrack, the next position callback point should not be modified and set ahead of current buffer head. Otherwise, as frames are dropped, the new position is never reached and an application relying on position callbacks to reload the buffer would be stalled. Bug: 11868603. Change-Id: I93b2a311642a0c89944b78bcc0482d4ceed98ae4
* | AudioTrack: fix position callback after restoreEric Laurent2013-12-171-1/+0
| | | | | | | | | | | | | | | | | | | | | | When restoring an AudioTrack, the next position callback point should not be modified and set ahead of current buffer head. Otherwise, as frames are dropped, the new position is never reached and an application relying on position callbacks to reload the buffer would be stalled. Bug: 11868603. Change-Id: I93b2a311642a0c89944b78bcc0482d4ceed98ae4
* | update offloaded audio track sampling rateEric Laurent2013-12-171-0/+13
| | | | | | | | | | | | | | | | AudioPlayer must read the sampling rate from offloaded audio sinks whenever a new time position is computed as the decoder can update the sampling rate on the fly. Change-Id: I997e5248cfd4017aeceb4e11689324ded2a5bc88
* | Merge "Increase kFastTrackMultiplier from 1 to 2"Glenn Kasten2013-12-171-4/+7
|\ \ | |/ |/|
| * Increase kFastTrackMultiplier from 1 to 2Glenn Kasten2013-12-041-4/+7
| | | | | | | | Change-Id: I158f147295eebcea96e4047d7618069bc48bdd7d
* | Assign blame for playback wakelocks.Marco Nelissen2013-10-251-5/+15
|/ | | | | | | | | | | Set a work source for the playback wakelock, so that playback is counted against the requesting app instead of the media server. Cherrypicked from master. b/9464621 Change-Id: I7329f88a288a95a582a78005a1c3d16a5a611e31
* Merge "Fix race condition in AudioTrack::pause followed by start" into klp-devGlenn Kasten2013-10-171-7/+8
|\
| * Fix race condition in AudioTrack::pause followed by startGlenn Kasten2013-10-161-7/+8
| | | | | | | | | | Bug: 11148722 Change-Id: Iec88f00c8510363d4418e4b8d5b34feb06ecf04d
* | AudioTrack: fix head position after restoreEric Laurent2013-10-161-1/+3
|/ | | | | | | | | | The head position transfered to the new track by restoreTrack_l() must take into account the frames that are dropped from the old track to avoid a non recoverable offset in the playback head position returned to applications. Bug: 11230062. Change-Id: I51143a08b95e8f264ed709ae2054360315f2b8b1
* fix volume and effect enable delay on offloaded tracksEric Laurent2013-09-301-0/+3
| | | | | | | | | | | | | Volume: add a method to wake up the mediaserver playback thread when a volume command is received on an offloaded track. Effects: call effect chain process on offloaded playback threads asynchronously from writes to allow effect state updates while waiting for async write callback. Bug: 10796540. Change-Id: Id2747ae88783575d1d7ffd6fc86fbd054ab2c739
* AudioTrack: fix music resumeEric Laurent2013-09-231-2/+3
| | | | | | | | Fix regression introduced by commit 5a6cd22 in AudioTrack resume: the callback thread was not signaled if paused internaly. Bug: 10895013. Change-Id: Ic356b115132d6fccbcee2d9bb855e92671dc20c5
* Fix slow AudioTrack and AudioRecord destructionGlenn Kasten2013-09-201-24/+29
| | | | | | | | | | | | | | | | | | | | There were two causes for the slowness: When thread was paused, it used nanosleep and sleep. These usually run to completion (except for POSIX signal, which we avoid because it is low-level). Instead, replace the nanosleep and sleep by condition timed wait, as that can be made to return early by a condition signal. Another advantage of condition timed wait is that a condition wait was already being used at top of thread loop, so it is a simpler change. The AudioRecord destructor was missing a proxy interrupt that was correct in AudioTrack. This proxy interrupt is needed in case another thread is blocked in proxy obtainBuffer. Does not address the 1 second polling for NS_WHENEVER. Bug: 10822765 Change-Id: Id665994551e87e4d7da9c7b015f424fd7a0b5560
* Fix underruns when fast track denied due to SRCGlenn Kasten2013-09-171-32/+35
| | | | | | | | | | | | | | | | | | | | | | | | | OpenSL ES requests a fast track. If sample rate conversion is needed, the request is denied by server, and a larger client buffer is used to handle the higher latency of a normal track. However the client notification period was calculated based on buffer being divided into 2 sub-buffers. That resulted in the notification period being too long. The server pulls chunks that are smaller than half the total buffer. So now the client uses 3 sub-buffers when there is SRC. Also removed the 'defer wake' optimization because it was incorrect. This optimization attempted to reduce the number of wakeups of client, when server releaseBuffer knows that another releaseBuffer will be following. But there is no way for the first releaseBuffer to predict how soon the second releaseBuffer will occur. In some cases it was a long time, and the client underran. So now the client is woken up immediately if the total number of available frames to client is >= the minimum number the client wants to see (the notification period). Also fix bug where minimum frame count was not being used in the calculation of notification period. Bug: 10342804 Change-Id: I3c246f4e7bc3684a344f2cf08268dc082e338e2a
* Fix miscellanous AudioTrack::getTimestamp() bugsGlenn Kasten2013-09-031-1/+12
| | | | | | | | | | | | | | Check that get_presentation_position is non-NULL before calling. AudioTrack::getTimestamp not implemented for fast tracks. Fix typo in Track::getTimestamp(). Fix bugs in AudioTrack::getTimestamp after stop: - getTimestamp while stopped is not allowed. - stop, start, getTimestamp now returns the correct value. Change-Id: Ie8d9dc1f28d8927634e04175a68b147ffc2ea8eb
* Merge "Add IAudioTrack::getTimestamp()" into klp-devGlenn Kasten2013-08-301-10/+7
|\
| * Add IAudioTrack::getTimestamp()Glenn Kasten2013-08-291-10/+7
| | | | | | | | | | | | | | | | | | | | with dummy implementation in AudioFlinger::TrackHandle, and implement AudioTrack::getTimestamp() using IAudioTrack. Also document invariant that mAudioTrack and control block are always non-0 after successful initialization. Change-Id: I9861d1454cff7decf795d5d5898ac7999a9f3b7e
* | Merge "New AudioTrack C++ API for audio timestamps" into klp-devGlenn Kasten2013-08-291-0/+5
|\ \ | |/
| * New AudioTrack C++ API for audio timestampsGlenn Kasten2013-08-281-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new API is intended to replace latency(), especially for A/V sync. The application will receive periodic timestamp notifications. The period is unspecified, but will likely be more frequent after a pause or stop, set position, underrun, display on/off change, route change, or when audio framework notices drift. It will be up to the higher level application (e.g. Stagefright) to reconstruct a clock that updates more frequently. The current latency() method doesn't indicate when latency changes due to screen on/off state, route changes, etc. Includes squahsed change-Id: I2082f8752040be0c234b1a6f1be2e269abf2ce7c Dummy implementation of AudioTrack:getTimestamp() Rename AudioTrack::Timestamp to AudioTimestamp. Renaming and pulling up to a higher level allows more modules to use it. Change-Id: Ibf7f6a207c3f8d8697f25ede2cd5200697fadb86 (cherry picked from commit dd69eb893867634fd169c03204a6ad7c74b351e7)
* | AudioTrack: fix write retries for compressed audioEric Laurent2013-08-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | When the amount of frames that can be written to the buffer is less than requested, AudioTrack::processAudioBuffer() estimates the time needed to free the missing amount of frames and asks the callback thread to sleep. This behavior is not possible for compressed audio and should not be enabled for offloaded tracks. Change-Id: I5b657283cfba06254c9ac0ea9b447467cce7eb61
* | AudioTrack: fix unwanted underrun when restartingEric Laurent2013-08-281-0/+3
|/ | | | | | | | | | | When restarting an AudioTrack from stopped state, it is necessary to force refresh of mRemainingFrames by processAudioBuffer() as the last write before stop() could be partial. No doing so will lead into unnecessary sleep before filling the non contiguous part of the buffer returned by obtainBuffer() when processAudioBuffer() is executed for the first time after start(). Change-Id: Id703f8dc092a6f07c905eee194054b4a978f979d
* Move control block mName to createTrack() outputGlenn Kasten2013-07-301-2/+3
| | | | | | | This is part of a series of CLs to clean up the shared memory control block, by removing any fields that don't have to be there. Change-Id: I6e51003a1293b6800258c31b22cff2eba42162e7
* Rename control block flags to mFlagsGlenn Kasten2013-07-301-9/+9
| | | | Change-Id: I7b6d31e24531954ab1ecdf3ed56c19433700bd89
* libmedia: offloaded playback supportRichard Fitzgerald2013-07-251-38/+187
| | | | | | | | | | | | | | | | | | | | | | | | | - start() returns a status so that upper layers can recreate a non offloaded track in case of error. - Added states to handle offloaded tracks specific: - waiting for stream end (drain) notification by audio flinger - allow pause while waiting for stream end notification - getPosition() queries the render position directly from audio HAL. - disable APIs not applicable to offloaded tracks - Modified track restoring behavior for invalidated offloaded tracks: just send the callback and wait for upper layers to create a new track. - Added wait for stream end management in audio track client proxy. Similar to obtainBuffer and should be factored in. Change-Id: I0fc48117946364cb255afd653195498891f622bd Signed-off-by: Eric Laurent <elaurent@google.com>
* Merge "Add comments"Glenn Kasten2013-07-171-0/+7
|\
| * Add commentsGlenn Kasten2013-07-101-0/+7
| | | | | | | | Change-Id: Ifbf3a46a4183c8abc0feee1c588953ab10303cc1
* | Fix type error in AudioTrack::processAudioBufferGlenn Kasten2013-07-101-1/+2
|/ | | | | | It returned a bool instead of nsecs_t Change-Id: If0c096dac411afc0a4142ec1e59c1fdd36d4867c
* Include what is neededGlenn Kasten2013-07-021-0/+1
| | | | | | | Remove old includes. Header files only include other header files that they directly need themselves. Change-Id: Ic471386808d9f42ea19ccbd59cb50a5f83a89dd0
* Public API changes for audio offload support.Richard Fitzgerald2013-06-271-6/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NOTE: this does _not_ include all private member variables added to classes as part of offload support. Only public/protected functions and stubs functions/variables needed to make the changes buildable. - isOffloadSupported() added to audio policy service A stub implementation is required to build, this always returns false - setParameters() added to IAudioTrack A stub implementation is required to build, this always returns INVALID_OPERATION - CBlk flag for stream end - Change AudioSystem::getRenderPosition() to take an audio_output_t so caller can specify which output to query - Add AudioSystem::isOffloadSupported() This is fully implemented down to the AudioFlinger function AudioPolicyServer::isOffloadSupported() which is just a stub that always returns false. - Add EVENT_STREAM_END to AudioTrack interface. STREAM_END is used to signal when the hardware has actually finished playing all the data it was sent. - Add event type enumeration to media player interface AudioSink callbacks so that the same callback can be used to handle multiple types of event. For offloaded tracks we also have to handle STREAM_END and TEAR_DOWN events - Pass audio_offload_info_t to various functions used for opening outputs, tracks and audio players. This passes additional information about the compressed stream down to the HAL when using offload. For publicly-available APIs this is an optional parameter (for some of the internal and low-level APIs around the HAL interface it is mandatory) - Add getParameters() and setParameters() API to AudioTrack Currently dummy implementations. - Change AudioPlayer contructor so that it takes a set of bitflags defining what options are required. This replaces the original bool which only specified whether to use deep buffering. - Changes to StageFright class definition related to handling tearing-down of an offloaded track when we need to switch back to software decode - Define new StageFright utility functions used for offloaded tracks Currently dummy implementations. - AudioFlinger changes to use extended audio_config_t. Fills in audio_offload_info_t member if this info is passed in when opening an output. - libvideoeditor changes required to add the new event type parameter to AudioSink callback functions - libmediaplayerservice changes required to add the new event type parameter to AudioSink callback functions Change-Id: I3ab41138aa1083d81fe83b886a9b1021ec7320f1 Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Eric Laurent <elaurent@google.com>
* New control block for AudioTrack and AudioRecordGlenn Kasten2013-06-121-571/+648
| | | | | | | | Main differences between old and new control block: - removes the mutex, which was a potential source of priority inversion - circular indices into shared buffer, which is now always a power-of-2 size Change-Id: I4e9b7fa99858b488ac98a441fa70e31dbba1b865
* Fix underruns when sample rate != native sample rateGlenn Kasten2013-06-041-2/+4
| | | | | | | | | | | | | | | | | | This forces a minimum of 3 application buffers when the sample rates don't match, using the normal mixer and low latency HAL. There is still an issue that the latency() varies depending on whether screen was off or on at the time of creating the AudioTrack. With screen on: I/AudioTrack( 2028): afFrameCount=960, minBufCount=2, afSampleRate=48000, afLatency=50 I/AudioTrack( 2028): minFrameCount: 2646, afFrameCount=960, minBufCount=3, sampleRate=44100, afSampleRate=48000, afLatency=50 With screen off: I/AudioTrack( 2817): afFrameCount=960, minBufCount=4, afSampleRate=48000, afLatency=84 I/AudioTrack( 2817): minFrameCount: 3528, afFrameCount=960, minBufCount=4, sampleRate=44100, afSampleRate=48000, afLatency=84 Change-Id: Ib45515edff2afcd672dda34881b658c800ffc25a
* Consistent whitespaceGlenn Kasten2013-05-301-1/+3
| | | | Change-Id: I118cce68d3b777f9ec9b6bfb70367496422a40f2
* am 1641f328: am 4170f515: Merge "Remove timing jitter during startup of ↵Eric Laurent2013-05-031-0/+21
|\ | | | | | | | | | | | | audio" into jb-mr2-dev * commit '1641f328d4de3b2b61481607dc482ccaefe808a9': Remove timing jitter during startup of audio
| * Remove timing jitter during startup of audioGlenn Kasten2013-04-231-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a regression introduced recently, that increased timing jitter during the startup of the FastMixer and AudioTrack callback threads. The regression was to make requestPriority() asynchronous as a way to avoid an apparent priority inversion in system_server. This means that the target thread could run briefly with the initial priority, before the new priority takes effect. This change removes the startup jitter for FastMixer, by making the requestPriority() synchronous again for that case. It doesn't matter that this restores the priority inversion involving normal mixer thread, because it happens during startup of both threads. The change also removes the startup jitter for the AudioTrack callback thread, by having the target thread check whether the requestPriority() has completed yet. If not, the target thread blocks with a timeout until the priority boost finishes. Finally, we now log an error message if the expected priority boost doesn't happen. Bug: 8698989 Change-Id: Id590e9a274b70ec1ba85b44a585ee37a22e41cbc
* | Propose new interpretation for setPosition and setLoopGlenn Kasten2013-01-071-0/+45
|/ | | | | | | Add new API getBufferPosition to return position relative to start of fixed buffer. Change-Id: I7aca8e392d45b988545f07b36b5032691057b03e
* Merge "Start isolating control block accesses in a proxy"Glenn Kasten2012-12-211-38/+71
|\
| * Start isolating control block accesses in a proxyGlenn Kasten2012-12-121-38/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The proxy object will eventually be the only code that understands the details of the control block. This should make it easier to change the control block in the future. Initial set of control block fields that are isolated: - sample rate - send level - volume Prepare for streaming/static separation by adding a union to the control block for the new fields. Fix bug in handling of max sample rate on a track. It was only checking at re-configuration, not at each mix. Simplify OutputTrack::obtainBuffer. Change-Id: I2249f9d04f73a911a922ad1d7f6197292c74cd92
* | Remove unnecessary parameterGlenn Kasten2012-12-181-2/+1
|/ | | | | | Just get the parameter on server side Change-Id: I433a63104dbb257e0d862be2ab61847cb36d1c15
* Split off the current control block to separate fileGlenn Kasten2012-12-031-176/+0
| | | | | | Prepare for a new implementation of step() etc. Change-Id: I268421976ba577aa1fb5d7015de5441c05861190
* Emphasize distinction between streaming and staticGlenn Kasten2012-12-031-9/+15
| | | | | | Update comments and improve error checks to match Change-Id: I7370d6e59a7ef26dfb284a8b058d5ab2e0a42ccf
* flush() comments and checksGlenn Kasten2012-12-031-9/+10
| | | | | | | flush() is only useful for streaming mode. It is a no-op if track is active or uses a static buffer. Change-Id: I918ac181ffae3d16a0d67d8a7208f4aec61b5bd6
* AudioTrack::mute() is unused so remove itGlenn Kasten2012-12-031-9/+2
| | | | | | | If ever needed again, it could be implemented on client side by forcing a track volume of 0. Change-Id: I88a9b4f675b6dca2948549414f9ec2c192d29269
* AudioTrack inline short const methodsGlenn Kasten2012-11-301-47/+0
| | | | Change-Id: I142917edb454d510bbe545e94e6eaea30b650fae
* Clean up channel count and channel maskGlenn Kasten2012-11-191-14/+10
| | | | | | | | Channel count is uint32_t. Remove redundant mask parameter to AudioTrack::createTrack_l() and AudioRecord::openRecord_l(). Change-Id: I5dc2b18eb609b2c0dc3091994cbaa4628062c17f
* Merge ""if" statements use curly braces per media style"Glenn Kasten2012-11-161-18/+52
|\
| * "if" statements use curly braces per media styleGlenn Kasten2012-11-161-18/+52
| | | | | | | | Change-Id: I130e7849fd1da7a0b7fe56c3c53919d26e3843b8
* | Merge "Don't use control block frame count after create"Glenn Kasten2012-11-161-47/+55
|\ \
| * | Don't use control block frame count after createGlenn Kasten2012-11-161-47/+55
| |/ | | | | | | | | | | This is part of a series to clean up the control block. Change-Id: I7f4cb05aef63053f8e2ab05b286d302260ef4758