summaryrefslogtreecommitdiffstats
path: root/media/libmedia/AudioRecord.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix issues with synchronous record start.Eric Laurent2012-05-141-1/+4
| | | | | | | | | | | | | | | | - Added a timeout in case the trigger event is never fired. - Extend AudioRecord obtainBuffer() timeout in case of synchronous start to avoid spurious warning. - Make sure that the event is triggered if the track is destroyed. - Reject event if the triggering track is in an incompatible state. Also fix a problem when restoring a static AudioTrack after a mediaserver crash. Bug 6449468. Change-Id: Ib36e11111fb88f73caa31dcb0622792737d57a4b
* Use C APIs instead of C++ APIs for policyGlenn Kasten2012-04-231-4/+4
| | | | | | | | | The C++ APIs are going away. Note: we use tid == 0 which is not supported yet by the C APIs, do not submit this until that is added. Change-Id: I0e90789e6c81c69f2544e899c52421ea5d1342be
* Configure policy of mediaserver threadsGlenn Kasten2012-04-221-4/+4
| | | | Change-Id: Ifd825590ba36996064a458f64453a94b84722cb0
* Make AudioTrack/AudioRecord handle more than 2^32 framesMarco Nelissen2012-03-301-1/+1
| | | | | b/6160363 Change-Id: I471815012c6a113ec2c4dd7676e8fa288a70bc76
* implemented synchronous audio captureEric Laurent2012-03-291-5/+7
| | | | | | | | | | | | | | Added the infrastructure to support the synchronization of playback and capture actions on specific events. The first requirement for this feature is to synchronize the audio capture start with the full rendering of a given audio content. The applications can further be extended to other use cases (synchronized playback start...) by adding new synchronization events and new synchronous control methods on player or recorders. Also added a method to query the audio session from a ToneGenerator. Change-Id: I51f1167290d9cafdf2fbcdf9e4785156973af44c
* IAudioFlinger::createTrack and openRecord flagsGlenn Kasten2012-03-191-4/+3
| | | | | | | | | | | | | | | | | | | | createTrack and openRecord don't need the "old" flags parameter, which was either audio_policy_output_t or audio_in_acoustics_t shifted left by 16 bits. But they do need "new" flags, which are defined by the application use case. Initially, the only application use case flag is timed output, but others are planned. For output, the audio_policy_output_t flags are passed to AudioSystem::getOutput, which returns an audio_io_handle_t, and that handle is then passed to createTrack. So createTrack doesn't need the old flags parameter. For input, the audio_in_acoustics_t flags are passed to AudioSystem::getInput, which returns an audio_io_handle_t, and that handle is then passed to openRecord. So openRecord doesn't need the old flags parameter. Change-Id: I18a9870911846cca69d420c19fe6a9face2fe8c4
* Whitespace and indentationGlenn Kasten2012-03-131-9/+8
| | | | | | | | | | | | | | Fix indentation to be multiple of 4. Make it easier to search: sp< not sp < to "switch (...)" instead of "switch(...)" (also "if" and "while") Remove redundant blank line at start or EOF. Remove whitespace at end of line. Remove extra blank lines where they don't add value. Use git diff -b or -w to verify. Change-Id: I966b7ba852faa5474be6907fb212f5e267c2874e
* Use AudioRecord::record_flags consistentlyGlenn Kasten2012-03-081-2/+2
| | | | Change-Id: I6f369a2b99eb515603bc7d5629a07db2b96783fe
* Merge "Shorten thread names"Glenn Kasten2012-02-291-1/+1
|\
| * Shorten thread namesGlenn Kasten2012-02-281-1/+1
| | | | | | | | | | | | | | | | 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
* | AudioRecord const methodsGlenn Kasten2012-02-281-7/+7
|/ | | | Change-Id: Ifae4fd7820b650aaca2b13c8658c292db1c46c0f
* AudioRecord and AudioTrack client tidGlenn Kasten2012-02-141-4/+33
| | | | | | Inform AudioFlinger of the tid of the callback thread. Change-Id: I670df92dd06749b057238b48ed1094b13aab720b
* Merge "Remove dead mutex in AudioTrack/AudioRecord thread"Glenn Kasten2012-02-081-13/+0
|\
| * Remove dead mutex in AudioTrack/AudioRecord threadGlenn Kasten2012-02-021-13/+0
| | | | | | | | | | | | | | | | | | | | The client callback threads had mutexes called AudioTrackThread::mLock and ClientRecordThread::mLock. These mutexes were only used by start() and stop(), and were unused by the thread itself. But start() and stop() already have their own protection provided by AudioTrack::mLock and AudioRecord::mLock. So the thread mutexes can be removed. Change-Id: I098406d381645d77fba06a15511e179a327848ef
* | Use NULL not 0 for raw pointersGlenn Kasten2012-02-031-6/+6
|/ | | | | | Use if (p != NULL) instead of if (ptr) Change-Id: Iaec3413a59ccbf233c98fcd918cc7d70ac5da9fa
* Use audio_source_t consistentlyGlenn Kasten2012-01-261-5/+5
| | | | | | | | | | | | | | | | Was a mix of audio_source_t, uint8_t, and int. Related fixes: - fix comments in MediaRecorder.java - AudioPolicyService server side was not checking source parameter at all, so if the client wrapper was bypassed, invalid values could be passed into audio HAL - JNI android_media_AudioRecord_setup was checking source for positive values, but not negative values. This test is redundant, since already checked at Java and now checked by AudioPolicyService also, but might as well make it correct. Change-Id: Ie5e25d646dcd59a86d7985aa46cfcb4a1ba64a4a
* Use audio_format_t consistently, continuedGlenn Kasten2012-01-201-6/+6
| | | | | | | | | | | | 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
* Use size_t for frame sizeGlenn Kasten2012-01-131-1/+1
| | | | | | | | | 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
* libmedia new can't fail on AndroidGlenn Kasten2012-01-111-3/+0
| | | | Change-Id: Ie79dd5abb8078b35474bf0f1b3a6ff994a3a3360
* Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGESteve Block2012-01-081-9/+9
| | | | | | | See https://android-git.corp.google.com/g/#/c/157220 Bug: 5449033 Change-Id: Ic9c19d30693bd56755f55906127cd6bd7126096c
* Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF) DO NOT MERGESteve Block2012-01-061-6/+6
| | | | | | | See https://android-git.corp.google.com/g/157065 Bug: 5449033 Change-Id: I00a4b904f9449e6f93b7fd35eac28640d7929e69
* Use the standard CC_LIKELY and CC_UNLIKELY macrosGlenn Kasten2012-01-051-6/+4
| | | | | | | | | | | 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
* Bug 4903178 Restore priority and cgroup on stopGlenn Kasten2011-11-161-5/+10
| | | | | | | | | | On AudioTrack and AudioRecord stop or failed start, restore the priority and cgroup of the caller to their previous values, rather than forcing to NORMAL. Dependent on new thread APIs. Also fixes bug where priority was set to AUDIO but cgroup not set. Change-Id: Ib83893918fb4fdf57c6b87884b51038997a631d8
* Rename (IF_)LOGV(_IF) to (IF_)ALOGV(_IF) DO NOT MERGESteve Block2011-10-261-7/+7
| | | | | | | See https://android-git.corp.google.com/g/#/c/143865 Bug: 5449033 Change-Id: I0122812ed6ff6f5b59fe4a43ab8bff0577adde0a
* Keep effects sessions active when the caller dies.Marco Nelissen2011-08-091-0/+3
| | | | | | | | 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
* AudioRecord: Fix getInput()Eric Laurent2011-07-261-1/+1
| | | | | | | AudioRecord::getInput() was issuing a query to get a new input stream from audio policy service instead of returning the cached input stream in AudioRecord. Change-Id: Ice324b7c60bc0898149023797bcb56a72091b9d3
* Audio framework: support for audio pre processingEric Laurent2011-07-181-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | Audio effect framework is extended to suport effects on output and input audio path. AudioFlinger: Support for audio effects and effect chains is moved from PlaybackThread class to ThreadBase class so that RecordThread can manage effects. Effects of type pre processing are allowed on record thread only. When a pre processing is enabled, the effect interface handle is passed down to the input stream so that the audio HAL can call the process function. The record thread loop calls the effect chain process function that will only manage the effect state and commands and skip the process function. AudioRecord: The audio session is allocated before calling getInput() into audio policy serice so that the session is known before the input theead is created and pre processings can be created on the correct session. AudioPolicyService: default pre processing for a given input source are loaded from audio_effects.conf file. When an input is created, corresponding effects are created and enabled. Change-Id: Id17119e0979b4dcf189b5c7957fec30dc3478790
* Merge "Fix warnings for uninitialized local variables"Glenn Kasten2011-06-231-1/+1
|\
| * Fix warnings for uninitialized local variablesGlenn Kasten2011-06-221-1/+1
| | | | | | | | Change-Id: Ic9b03b0fd215444e76c7b7bebb385f7831c557e0
* | Added audio_bytes_per_sample() helper functionEric Laurent2011-06-171-2/+2
|/ | | | Change-Id: Ibfcd75c4c241a53d5f052c25ada091904991048a
* Remove unnecessary level of priority indirectionGlenn Kasten2011-06-011-2/+2
| | | | Change-Id: I942d43973c20a7ace8b0d3f78b4da97e45e996c6
* Use channel mask instead of channel count for track creationJean-Michel Trivi2011-06-011-14/+14
| | | | | | | | | | | | | | | | | Record and playback objects (resp AudioRecord and AudioTrack) are created using a channel mask, but this information is lost in the mixer because only the channel count is known to AudioFlinger. A channel count can always be derived from a channel mask. The change consists in: - disambiguiting variable names for channel masks and counts - passing the mask information from the client to AudioFlinger and the mixer. - when using the DIRECT ouput, only verifying the format of the track is compatible with the output's for PCM. Change-Id: I50d87bfb7d7afcabdf5f12d4ab75ef3a54132c0e
* update for new audio.h header locationDima Zavin2011-05-121-1/+1
| | | | | Change-Id: Ic4c62c4037800802427eb7d3c7f5eb8b25d18876 Signed-off-by: Dima Zavin <dima@android.com>
* audio/media: convert to using the audio HAL and new audio defsDima Zavin2011-04-271-10/+13
| | | | | Change-Id: Ibc637918637329e4f2b62f4ac7781102fbc269f5 Signed-off-by: Dima Zavin <dima@android.com>
* New fix for issue 4111672: control block flagsEric Laurent2011-04-051-14/+7
| | | | | | | | | | | | | | | The first fix (commit 913af0b4) is problematic because it makes threads in mediaserver process block on the cblk mutex. This is not permitted as it can cause audio to skip or worse have a malicious application prevent all audio playback by keeping the mutex locked. The fix consists in using atomic operations when modifying the control block flags. Also fixed audio_track_cblk_t::framesReady() so that it doesn't block when called from AudioFlinger (only applies when a loop is active). Change-Id: Ibf0abb562ced3e9f64118afdd5036854bb959428
* Fix issue 4111672: AudioTrack control block flagsEric Laurent2011-03-181-1/+4
| | | | | | | | | | | Make sure that all read/modify/write operations on the AudioTrack and AudioRecord control block flags field are protected by the control block's mutex. Also fix potential infinite loop in AudioTrack::write() if the written size is not a multiple of frame size. Change-Id: Ib3d557eb45dcc3abeb32c9aa56058e2873afee27
* Fix issue 3439872: video chat and bluetooth SCOEric Laurent2011-03-081-29/+143
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change fixes the stability problems experienced when using a bluetooth headset supporting both A2DP and SCO. Problems occur when starting the video chat at which time the A2DP output is being stopped to start SCO. At that time, active AudioTracks are invalidated by AudioFlinger so that a new AudioTrack binder interface can be recreated by the client process on the new mixer thread with correct parameters. The problem was that the process to restore the binder interface was not protected against concurrent requests which caused 2 binder interfaces to be created sometimes. This could lead to permanent client deadlock if one of the client threads was waiting for a condition of the first created binder interface while the second one was created (as the AudioFlinger would only signal conditions on the last one created). This concurrent request situation is more likely to happen when a client uses the JAVA AudioTrack as the JNI implementation uses simultaneously the native AudioTrack callback and write push mechanisms. By doing so, the code that checks if the binder interface should be restored (in obtainBuffer()) is much more likely to be called concurrently from two different threads. The fix consists in protecting the critical binder interface restore phase with a flag in the AudioTrack control block. The first thread acting upon the binder interface restore request will raise the flag and the second thread will just wait for a condition to be signaled when the restore process is complete. Also protected all accesses to the AudioTrack control block by a mutex to prevent access while the track is being destroyed and restored. If a mutex cannot be held (e.g because we call a callback function), acquire a strong reference on the IAudioTrack to prevent its destruction while the cblk is being accessed. Modified AudioTrack JNI to use GetByteArrayElements() instead of GetPrimitiveArrayCritical() when writing audio buffers. Entering a critical section would cause the JNI to abort if a mediaserver crash occurs during a write due to the AudioSystem callback being called during the critical section when media server process restarts. Anyway with current JNI implementation, either versions do not copy data most of the times and the criticial version does not guaranty no data copy. The same modifications have been made to AudioRecord. Change-Id: Idc5aa711a04c3eee180cdd03f44fe17f3c4dcb52
* Fix issue 3157123.Eric Laurent2010-11-191-6/+8
| | | | | | | Use a Mutex wherever atomic operations were used in AudioTrack, AudioRecord, AudioFlinger and AudioEffect classes. Change-Id: I6f55b2cabdcd93d64ef19446735b8f33720f8dbc
* media: add AudioRecord::getMinFrameCount().Chia-chi Yeh2010-06-231-25/+38
| | | | Change-Id: I952071ab10aa49aa96b727d157b68470d69fff3d
* Issue 2667801: [Audio Effect Framework] AudioFlinger, AudioMixer AudioTrack ↵Eric Laurent2010-06-031-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | modifications. First drop of audio framework modifications for audio effects support. - AudioTrack/AudioRecord: Added support for auxiliary effects in AudioTrack Added support for audio sessions Fixed left right channel inversion in setVolume() - IAudioFlinger: Added interface methods for effect enumeraiton and instantiation Added support for audio sessions. - IAudioTrack: Added method to attach auxiliary effect. - AudioFlinger Created new classes to control effect engines in effect library and manage effect connections to tracks or output mix: EffectModule: wrapper object controlling the effect engine implementation in the effect library. There is one EffectModule per instance of an effect in a given audio session EffectChain: group of effects associated to one audio session. There is one EffectChain per audio session. EffectChain for session 0 is for output mix effects, other chains are attached to audio tracks with same session ID. Each chain contains a variable number of EffectModules EffectHandle: implements the IEffect interface. There is one EffectHandle object for each application controlling (or using) an effect module. THe EffectModule maintians a list of EffectHandles. Added support for effect modules and effect chains creation in PlaybackThread. modified mixer thread loop to allow track volume control by effect modules and call effect processing. -AudioMixer Each track now specifies its output buffer used by mixer for accumulation Modified mixer process functions to process tracks by groups of tracks with same buffer Modified track process functions to support accumulation to auxiliary channel Change-Id: I26d5f7c9e070a89bdd383e1a659f8b7ca150379c
* Fix issue 2553359: Pandora does not work well with Passion deskdock / Cardock.Eric Laurent2010-05-171-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem is due to a too big difference between the buffer size used at the hardware interface and at the A2DP interface. When no resampling occurs we don't notice problems but the timing is very tight. As soon as resampling is activated, the AudioTrack underruns. This is because the AudioTrack buffers are not resized when moving the AudioTrack from hardware to A2DP output. The AudioTrack buffers are calculated based on a hardware output buffer size of 3072 bytes. Which is much less than the A2DP output buffer size (10240). The solution consists in creating new tracks with new buffers in AudioFlinger when the A2DP output is opened instead of just transfering active tracks from hardware output mixer thread to the new A2DP output mixer thread. To avoid synchronization issues between mixer threads and client processes, this is done by invalidating tracks by setting a flag in their control block and having AudioTrack release the handle on this track (IAudioTrack) and create a new IAudioTrack when this flag is detected next time obtainBuffer() or start() is executed. AudioFlinger modifications: - invalidate the tracks when setStreamOutput() is called - make sure that notifications of output opening/closing and change of stream type to output mapping are sent synchronously to client process. This is necessary so that AudioSystem has the new stream to output mapping when the AudioTrack detects the invalidate flag in the client process. Previously their were sent when the corresponding thread loop was executed. AudioTrack modifications: - move frame count calculation and verification from set() to createTrack() so that is is updated every time a new IAudioTrack is created. - detect track invalidate flag in obtainBuffer() and start() and create a new IAudioTrack. AudioTrackShared modifications - group all flags (out, flowControlFlag, forceReady...) into a single bit filed to save space. Change-Id: I9ac26b6192230627d35084e1449640caaf7d56ee
* Fix issue 2428563: Camera rendered inoperable by voice call interruption.Eric Laurent2010-03-051-3/+7
| | | | | | | | | | | | | | | | | The problem is that AudioRecord never exits read() when a timeout occurs while trying to get new PCM data from audio hardware input buffer: it just keeps waiting and retrying until stop() is called. In the same time, opencore AndroidAudioInput::audin_thread_func() loop cannot be exited when stuck in AudioRecord::read() because the iExitAudioThread flag can only be sampled when AudioRecord::read() returns. We remain stuck with the audio input thread running. The fix consists in modifying AudioRecord behavior in case of timeout when getting new PCM samples. We now wait only one timeout period and try to restart audio record, in case the problem is due to a media_server process crash. If this fails, we exit read() with a number of bytes read equals to 0 so that AndroidAudioInput::audin_thread_func() loop can exit. Also modified Audioflinger::RecordThread() loop so that we attempt to recover from HAL read errors. In case of read error, the input stream is forced to standby so that next read attempt does a reconfiguration and restart of the audio input device.
* Issue 2071329: audio track is shorter than video track for video capture on ↵Eric Laurent2010-03-021-1/+10
| | | | | | | | sholes Add API to retrieve number of frames dropped by audio input kernel driver. Submitted on behalf of Masaki Sato <masaki.sato@motorola.com>
* Simplify the MemoryDealer implementationMathias Agopian2010-01-291-1/+0
| | | | | | | | | | | | | | At some point the implementation became complicated because of SurfaceFlinger's special needs, since we are now relying on gralloc we can go back to much simpler MemoryDealer. Removed HeapInterface and AllocatorInterface, since those don't need to be paramterized anymore. Merged SimpleMemory and Allocation. Made SimplisticAllocator non virtual. Removed MemoryDealer flags (READ_ONLY, PAGE_ALIGNED) Removed a lot of unneeded code.
* Fix issue 2304669: VoiceIME: starting and canceling voice IME yields ↵Eric Laurent2009-12-071-2/+1
| | | | | | | | | | | | | | persistent "error 8" state on future attempts and breaks voice search. Fixed AudioFlinger::openInput() broken in change ddb78e7753be03937ad57ce7c3c842c52bdad65e so that an invalid IO handle (0) is returned in case of failure. Applied the same correction to openOutput(). Modified RecordThread start procedure so that a failure occuring during the first read from audio input stream is detected and causes the record start to fail. Modified RecordThread stop procedure to make sure that audio input stream fd is closed before we exit the stop function. Fixed AudioRecord JAVA and JNI implementation to take status of native AudioRecord::start() into account and not change mRecordingState to RECORDSTATE_RECORDING if start fails.
* Issue 2265163: Audio still reported routed through earpiece on sholesEric Laurent2009-11-191-31/+39
| | | | | | | | | | | | | This is a second attempt to fix the audio routed to earpiece syndrom. The root cause identified this time is the crash of an application having an active AudioTrack playing on the VOICE_CALL stream type. When this happens, the AudioTrack destructor is not called and the audio policy manager is not notified of the track stop. Results a situation where the VOICE_CALL stream is considered as always in use by audio policy manager which makes that audio is routed to earpiece. The fix consists in moving the track start/stop/close notification to audio policiy manager from AudioTrack to AudioFlinger Track objet. The net result is that in the case of a client application crash, the AudioFlinger TrackHandle object (which implements the remote side of the IAudioTrack binder interface) destructor is called which in turn destroys the Track object and we can notify the audio policy manager of the track stop and removal. The same modification is made for AudioRecord although no bug related to record has been reported yet. Also fixed a potential problem if record stop is called while the record thread is exiting.
* Fix issue 2203561: Sholes: audio playing out of earpiece.Eric Laurent2009-11-041-42/+85
| | | | | | | | | | | Create a new IAudioTrack interface to AudioFlinger when start() fails due to a broken pipe error. Do the same if start fails due to the same error after time out in obtainBuffer(). Do not indicate that the AudioTrack is started to AudioPolicyManager if IAudioTrack start fails. This avoids that an AudioTrack keeps a dead IAudioTrack after a media server crash. Same modifications for AudioRecord. Add a flag to ToneGenerator indicating that the callback thread can call Java. Without it, when the media server crashes and restarts, the AudioSystem error callback will crash in JNI if the IAudiotrack is created from AudioTrack callback thread.
* Fix issue 1795088 Improve audio routing codeEric Laurent2009-07-231-33/+57
| | | | | | | Initial commit for review. Integrated comments after patch set 1 review. Fixed lockup in AudioFlinger::ThreadBase::exit() Fixed lockup when playing tone with AudioPlocyService startTone()
* am 88e209dc: Fix issue 1743700: AudioTrack: setPlaybackRate can not set the ↵Eric Laurent2009-07-071-7/+6
|\ | | | | | | | | | | | | | | | | playback rate to twice of the ouputSR Merge commit '88e209dcf8c2ebddda5c272f46d1bd5478bc639c' * commit '88e209dcf8c2ebddda5c272f46d1bd5478bc639c': Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
| * Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate ↵Eric Laurent2009-07-071-7/+6
| | | | | | | | | | | | | | | | to twice of the ouputSR Store sample rate on 32 bits instead of 16 bits in audio_track_cblk_t. Removed sampleRate() methods from AudioTrack and AudioRecord: replaced by getSampleRate(). AudioTrack::setSampleRate() no returns a status.