summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTejas Shikhare <tshikhar@codeaurora.org>2011-11-17 17:18:01 -0800
committerSteve Kondik <shade@chemlab.org>2012-05-21 11:43:55 -0700
commitef930d1572d5baab13e6a25ea842d83a861a96e2 (patch)
treecd3c40835715da0738295e812f46e0f6a9d4f345 /include
parent0a872611c6ebe9a8f67dfb294e18b06c8fffd52d (diff)
downloadframeworks_base-ef930d1572d5baab13e6a25ea842d83a861a96e2.zip
frameworks_base-ef930d1572d5baab13e6a25ea842d83a861a96e2.tar.gz
frameworks_base-ef930d1572d5baab13e6a25ea842d83a861a96e2.tar.bz2
audio: Squashed commit of LPA support from CAF
* Patches wrangled by Kali frameworks/base: LPA and routing api implementation - Integrated routing APIs for LPA with the new AUDIO HAL - Integrated LPAPlayer for LPA Playback on 8660 Change-Id: I345f62afa53057261602042ac348d43333cc8732 libstagefright: Integrate LPAPlayerALSA for LPA playback on 8960 Change-Id: Ie7ec686bef7a8c0b41c06ae11bdf49f84e136197 frameworks/base: Fix for no audio while playing specific ADIF clips - Now the SW AAC Decoder is OMX based and handles decoding from the beginning after the port reconfiguration. So it is not required to force seeking to the beginning when INFO_FORMAT_CHANGED received, after decoding the first frame. - Removed the same to fix no audio issue with specific ADIF clips which reports INFO_FORMAT_CHANGED. Change-Id: I057312d1f9e0e5ced26bb5234cbc79d95be53b1b CRs-fixed: 321723 libstagefright: fix for crash in AwesomePlayer startAudioPlayer_l -Issue: check(seeking) fails in startAudioPlayer_l for LPA playback -Cause: LPAPlayer does not set seeking flag after starting playback in the middle of a clip -Fix: Set mSeeking flag and ReadOptions in LPAPlayer::Start Change-Id: Iac91a2b328be41cb98f6fdfa7c62e0b93a3a48a4 CRs-fixed: 322725 frameworks/base: Fix for pause/resume issue while LPA playback - If LPA playback is paused and resumed immediately, the audio resumes for sometime and then the playback switches to next clip due to error in OMXCodec. - In the LPA pause implementation, the source, OMXCodec, pause is being called which does not handle executing to pause state transition. So this causes decoding issue while resuming. - Removed unnecessary pause/resume API calls to OMXCodec to fix the issue. Change-Id: Ic7713c43aeedd9ec4818def9275653e7756e3a91 CRs-fixed: 322324 libstagefright:Fix for no progress bar update while seeking at end of LPA clip -progress bar doesnt update while seeking at end of LPA clip. -EOS is not posted to Awesome player when i/p EOS is reached,all input buffers have been decoded and response queue is empty. -Post EOS to Awesome player when i/p EOS is reached,all input buffers have been decoded and response queue is empty. CRs-Fixed: 321961 Change-Id: I6f90ac577825d807b99e724b3948f7cca1478e8d frameworks/base: Enable Audio effects for LPA output - Added the support to apply Audio Effects on LPA output. Change-Id: I08b64167e9beac7fbe84ad2610f0177766be7c7e frameworks/base:Fix for memory leaks during LPA playback -Sigkill errors while running audio monkey causing the device the monkey to stop Memory is getting critically low leading to background process getting killed by the OOM killer. -Memory leaks during LPA playback is leading to memory exhaution. -Fixing the memory leaks. Change-Id: I546d2a08d33789b3433d8ea61c30f6cba02a9f7c CRs-Fixed: 326720 libstagefirght: Update timeStarted to use system time in LPAPlayer::start - Issues: Paussing LPA clips at the last second causes the control to the end of next clip - Causes: TimeStarted is not updated correctly if pause cmd is received before decoder thread starts. - FIX: Update timeStarted to use system time in LPAPlayer::start() Change-Id: If01b397b251c8aa20feed581c260d5ff818a2834 CRs-fixed: 324298 frameworks/base: Prevent effects application in paused state - The issue is that effects are being applied on the LPA buffers in paused state. - After 3s in paused state, session of the playback is deregistered hence effects should not be applied - The issue is fixed by stalling the effects thread till the playback is resumed and session for LPA is re-establised with MediaPlayerService Change-Id: I87f0f1cfcaaaf0f95a7218f46ea76d043c84bb77 CRs-Fixed: 328300 frameworks/base: Syncronize resume and onPauseTimeOut - All the mixer controls are closed 3s after pausing playback through the onPauseTimeOut function - A scenario where onPauseTimeOut is closing mixer controls, a resume is issued, causes a crash - Synchronize these 2 functions using a mutex to prevent concurrent execution. Change-Id: Ic0e84423f7e3e4a26c441c73235e61d9a13c225d CRs-Fixed: 329312 frameworks/base : Prevent pcm_prepare when A2DP is enabled - pcm_prepare should not be called without setting routing controls, as this will result in driver bad state. - Fix the issue by calling pcm_prepare only when A2DP is not enabled and routing controls are set. Change-Id: Ic2db9224d70500c392fa31804844aa934eca633d CRs-fixed: 327396 libstagefright: Flush ASM before closing the stream - By calling pcm_prepare we can flush the driver and dsp so that playback close can issue an eos from kernel Change-Id: Icb5249ff8c480405b4b8ac5ce5f995ed5d73bf0d CRs-Fixed: 331532 (cherry picked from commit 8bdfa122ec7ff72f61ea01f932d96d94dc27f016) libstagefright: Fix for seek issue in mp3 streaming playback -Issue: In LPA playback if seek is issued, the pcm driver starts after a fill buffer and write is completed. If pause is issued before the driver starts, audio pause fails and results to a sudden jump in the playback or to an EOS at random -Testscenario: Flush,immediately followed by Pause in LPA playback. -Fix: Pause is handled when the pcm write is completed. This is acheived by a conditional wait on the pcm write done. CRs-Fixed: 331099 (cherry picked from commit 6ce15986ee7f2155044f79c505ebcd5a310a6c0d) Change-Id: I605316bba2d964ba3d52f6a7cc42e7e390d92fdf libstagefright: prevent trigger for stale events - prevent event thread from running if response queue is empty which means there is no buffer with the driver CRs-Fixed: 336970 (cherry picked from commit 690fb2d96a58b2341e49e3424d7e0efe7093aad7) Change-Id: Ie86a900e77175b2786cfe10fc0c64457e9fc4bae libstagefright: Ensure pcm_prepare is called only when routing is still active. - LPAPlayer does Derouting, pcm_prepare and pcm_close during pause. - pcm_prepare should not be called after derouting, as the driver tries to prepare a session which is already derouted. - This results in no backend errors in kernel for LPA Front end session as the backend is already closed with derouting. - Fix the issue by ensuring pcm_prepare is always called only routing is still active. Change-Id: I4b4eef7f9775b6141a5ec9a0eed82ca2f7a5c6d6 CRs-fixed: 341268 libstagefright: Add support in LPA for DSP timestamp. Change-Id: Ie9525b0ab201b9de828a25ef1cd9731567f4610a CRs-Fixed: 338065 (cherry picked from commit 2457cb32ec93a11e2a95d77557daaf6be0e1529a) libstagefright: honor write done event during pause Queue up completed buffers for decoding even if playback is in paused state as there is concurrency between write done and pause CRs-Fixed: 340469 (cherry picked from commit c9116b67545c5d973c255fba55c031271d3c38a4) Change-Id: Ifdc2cec4d92773ac279c02df7067bd95c32ca4a4 libstagefright: Fix A2DP seek to EOS issue in LPA - In A2dp scenario, when seeked to EOS and 0 bytes returned by decoder, eos was not issued to the app. This resulted in no audio. - Put the buffer back in the request queue in case of 0 decoded bytes and post an AudioEOS event to the app. Change-Id: Icb2cc053d71d02c8adb90fc5be1922ea813331e9 CRs-Fixed: 339608 (cherry picked from commit cdcdc2e6c6967de31476b1ece3702b645989e1df) Conflicts: media/libstagefright/LPAPlayerALSA.cpp LPAPlayerALSA: Fix for acquire/release Wake-locks. -Requires a wake lock to ensure that 3s timer after playback runs in suspend mode to get into TCXO shutdown. -Add support for acquiring wake locks from mediaserver process -PowerService is used for acquiring/releasing wakelock Change-Id: Icb21c319eee24aa38d56afcd8eddcb6315b74558 CRs-Fixed: 338542 libstagefright: Fix concurrency issue during A2DP switch. - When A2DP is disconnected, Pause is issued by the app. Sometimes, pause happens concurrently with stop, resulting a stuck in write. - Fix the issue by switching the sessions, when resuming the playback so that above concurrency is avoided. CRs-Fixed: 338086 (cherry picked from commit 29c0c17f53b6c945605e91da9108eea958b17bea) Change-Id: I7ee7a3ca0569006c404cb5cca885271b53476695 libstagefright: Initialize audio routing flag in the constructor If the audio routing flag is not initialized, it could result in some rare errors which will cause routing to be in bad state. (cherry picked from commit 74d381b2ca643515abf2bafa587df0b1cc7e56c7) Change-Id: I3f4b9b3e172921a397f4ad2a55c8e0e429af13bc libstagefright: Fix for application not responding when going to next song - When a song is ended, the driver is paused, flushed and then close. - The issue is that under some scenario, the song is ended before the driver is initialized. Pausing the driver as result causes a native crash - Issue is fixed by only issuing the pause to the driver if it is started. Change-Id: Ib839a087136526e9186fc37c8cb29c681612e6c9 CRs-Fixed: 339578 (cherry picked from commit a7117328a21eca0fc422b56c12acfab25f17873a) libstagefright: Add wake lock support for LPAPlayerALSA - LPAPlayerALSA now holds the wake lock while LPA playback is on going - This allows external applications who do not hold wake lock to use LPA playback CRs-Fixed: 342451 (cherry picked from commit 9621db1c1cf2092b1b51983c91434612c4cd8480) Change-Id: I3ff8bbdc2535e29b3e0b94953d9ce6364b5c0782 libstagefright: pause AudioStream when bt is disconnected. Notify AudioPolicyManager that device is in paused state when BT is disconnected CRs-Fixed: 349091 (cherry picked from commit e2fd42a43f92696f917b74b23a1cce9ac276a707) Change-Id: I5377f8568e1fccb11685ca0e718968eb1823d539 libstagefright: Decrease LPA buffer size to 256 kb CRs-Fixed: 344793 Conflicts: media/libstagefright/LPAPlayerALSA.cpp Change-Id: Ia9d13985dffa0473b3bdadc547eeb06b114b5a8b libstagefright: Change thread priority for LPA threads - Since A2DP behaves like a render thread, there is a need for it run at urgent audio priority. (cherry picked from commit 3b81741adf7b743cfa72874f63bf561950c9cd22) Change-Id: I9d7ee924766fef1ac77c47dc445d8d32a305d700 libstagefright: Update LPA Player to use ION Create LPAPlayerION and LPAPlayerPMEM files to separate memory allocation using ION and PMEM and change the existing files accordingly. CRs-fixed: 341467 (cherry picked from commit 63a2671e848d5f8bc9295706974d5c7bee7b2002) Change-Id: Ife594fb9c36a98d4a3be47ae4140a9c82ec477f7 frameworks/base: Fix to prevent deadlocks with Audioeffects. -Initialization of LPAeffectschain is not protected and locking/unlocking the Effectschain based on this value can lead to a deadlock scenario's during Stability or Monkey runs on Music app with Audioeffects in action. -Protect the initialization of LPAeffectschain. CRs-Fixed: 336281 (cherry picked from commit f0c6443679b0244a6cddf3042aa4b92b69f4d178) Change-Id: I27ec5b6cbbd3c6e72fb234542aa159ebec5df6be AudioFlinger: Fix for LPA volume change when headset connected. -When headset connected, volume is increased for LPA media playback in repeat mode. -Fixed volume setting in LPA mode. CRs-Fixed: 339790 (cherry picked from commit bc410c04dfed2caca9759e6eaf1ada6984f359cb) Change-Id: Id94920580384812353e3ae95f8f61511a1ec37c2 frameworks/base: Add support for LPA volume control using mediaplayer API. -Issue: Setting LPA volume using MediaPlayer::setVolume() API fails. -Cause: Current implementation of this API has only software decoder volume setting. -Fix: Add support to call kernel API for volume, as LPA volume is applied in DSP. Change-Id: If2eee5d03f421b1097b9a7f53d3ba3e4f293f4d8 CRs-Fixed: 317323 frameworks/base: Do not use LPA mode for ADIF clips - When ADIF clips are being played in LPA mode, if it is paused for more than 3sec and resumed, it results ANR - This is due to the limitation that ADIF playback cannot be seeked. When LPA playback is paused for more than 3sec, all the buffers with LPA driver are flused and closed. On Resume, it tries to seek to the paused location, where it fails for ADIF clips. - Fixed by not allowing ADIF clips in LPA mode. Change-Id: I25890844b0a28a474c9ac073d2576fca56f60e8c CRs-fixed: 324296 libstagefright: Fix LPA mute issue via browser. -When Playing LPA clip via HTML link, mute option fails to work. -In MediaPlayerService, setVolume API handles only for non-LPA case. Need to change to call LPA Volume update too. -Call mSession setVolume incase of LPA. The AudioFlinger has to keep track of previous volume when muted. This volume is again applied back when unmuted since App sents volume as unity when unmuted which is not the previous volume before mute. This change fixes the below issues --mute/unmute option via browser --increase/decrease volume when mute-should not affect mute option. --While in mute pause for 3sec and resume,mute is lost. CRs-Fixed: 327159 (cherry picked from commit 440de6deaae11b527b7250039e5172a690152e8c) Change-Id: I73e9773f0a507c47947051bceebeb013ebca8e67 media/libmedia: Release the session only for non-lpa clip Issue 1: - The session id is not acquired for LPA clips in AudioTrack however destructor tries to release it at the end of LPA Playback. - This cause corruption and eventually causes the ref count to decrease on every LPA clip. As a result the application of effects is not consistent - This issue is fixed by releasing the session only during non-lpa clip Issue 2: - There was noise for initial buffers during LPA playback - Mixer thread was applying effects for LPA effect chain - Prevent this by ensuring when lpa session is active, mixer thread does not apply effects on the LPA chain (cherry picked from commit 95932d301acf6d331fd8c42154ae69a7c98a9a33) Change-Id: I96dbbab831f21bc40ff98f202902ee753ab61fb6 CRs-Fixed: 328645 libstagefright: Create new AAC and MP3 decoder libraries without OMX layer - With the current AAC and MP3 OMX SW decoders, the decoding time is increased w.r.t the libraries without OMX layer that are present in GB. This increase in decoding time results reduction in power savings in LPA mode. - This commit is to remove OMX layer for AAC and MP3 to reduce the power consumption in LPA mode. (cherry picked from commit 16b4260ff4a200b2ad69290be714578ffa33424f) Change-Id: I4ef13031207952074d0788a8953ebc38cfe48cee CRs-fixed: 334400 fix build Change-Id: I8fe32083911a41e1517b9e73b618521b38a0db25
Diffstat (limited to 'include')
-rw-r--r--include/media/AudioSystem.h13
-rw-r--r--include/media/AudioTrack.h34
-rw-r--r--include/media/IAudioFlinger.h32
-rw-r--r--include/media/IAudioPolicyService.h9
-rw-r--r--include/media/MediaPlayerInterface.h13
-rw-r--r--include/media/stagefright/AudioPlayer.h18
-rw-r--r--include/media/stagefright/LPAPlayer.h342
7 files changed, 451 insertions, 10 deletions
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 6a15f6e..f80a8d6 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -120,6 +120,10 @@ public:
INPUT_CLOSED,
INPUT_CONFIG_CHANGED,
STREAM_CONFIG_CHANGED,
+#ifdef WITH_QCOM_LPA
+ A2DP_OUTPUT_STATE,
+ EFFECT_CONFIG_CHANGED,
+#endif
NUM_CONFIG_EVENTS
};
@@ -151,6 +155,15 @@ public:
uint32_t format = AUDIO_FORMAT_DEFAULT,
uint32_t channels = AUDIO_CHANNEL_OUT_STEREO,
audio_policy_output_flags_t flags = AUDIO_POLICY_OUTPUT_FLAG_INDIRECT);
+#ifdef WITH_QCOM_LPA
+ static audio_io_handle_t getSession(audio_stream_type_t stream,
+ uint32_t format = AUDIO_FORMAT_DEFAULT,
+ audio_policy_output_flags_t flags = AUDIO_POLICY_OUTPUT_FLAG_DIRECT,
+ int32_t sessionId = -1);
+ static void closeSession(audio_io_handle_t output);
+ static status_t pauseSession(audio_io_handle_t output, audio_stream_type_t stream);
+ static status_t resumeSession(audio_io_handle_t output, audio_stream_type_t stream);
+#endif
static status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
int session = 0);
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 1c401e2..f518198 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -172,6 +172,20 @@ public:
void* user = 0,
int notificationFrames = 0,
int sessionId = 0);
+#ifdef WITH_QCOM_LPA
+ /* Creates an audio track and registers it with AudioFlinger. With this constructor,
+ * session ID of compressed stream can be registered AudioFlinger and AudioHardware,
+ * for routing purpose.
+ */
+
+ AudioTrack( int streamType,
+ uint32_t sampleRate = 0,
+ int format = 0,
+ int channels = 0,
+ uint32_t flags = 0,
+ int sessionId = 0,
+ int lpaSessionId =-1);
+#endif
/* Terminates the AudioTrack and unregisters it from AudioFlinger.
* Also destroys all resources assotiated with the AudioTrack.
@@ -198,7 +212,22 @@ public:
const sp<IMemory>& sharedBuffer = 0,
bool threadCanCallJava = false,
int sessionId = 0);
-
+#ifdef WITH_QCOM_LPA
+ /* Initialize an AudioTrack and registers session Id for Tunneled audio decoding.
+ * Returned status (from utils/Errors.h) can be:
+ * - NO_ERROR: successful intialization
+ * - INVALID_OPERATION: AudioTrack is already intitialized
+ * - BAD_VALUE: invalid parameter (channels, format, sampleRate...)
+ * - NO_INIT: audio server or audio hardware not initialized
+ * */
+ status_t set(int streamType =-1,
+ uint32_t sampleRate = 0,
+ int format = 0,
+ int channels = 0,
+ uint32_t flags = 0,
+ int sessionId = 0,
+ int lpaSessionId =-1);
+#endif
/* Result of constructing the AudioTrack. This must be checked
* before using any AudioTrack API (except for set()), using
@@ -485,6 +514,9 @@ private:
uint32_t mUpdatePeriod;
bool mFlushed; // FIXME will be made obsolete by making flush() synchronous
uint32_t mFlags;
+#ifdef WITH_QCOM_LPA
+ audio_io_handle_t mAudioSession;
+#endif
int mSessionId;
int mAuxEffectId;
Mutex mLock;
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index 9e3cb7f..6a9d4b0 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -57,6 +57,22 @@ public:
int *sessionId,
status_t *status) = 0;
+#ifdef WITH_QCOM_LPA
+ virtual void createSession(
+ pid_t pid,
+ uint32_t sampleRate,
+ int channelCount,
+ int *sessionId,
+ status_t *status) = 0;
+
+ virtual void deleteSession() = 0;
+
+ virtual void applyEffectsOn(
+ int16_t *buffer1,
+ int16_t *buffer2,
+ int size) = 0;
+#endif
+
virtual sp<IAudioRecord> openRecord(
pid_t pid,
int input,
@@ -86,6 +102,9 @@ public:
virtual float masterVolume() const = 0;
virtual bool masterMute() const = 0;
+#ifdef WITH_QCOM_LPA
+ virtual status_t setSessionVolume(int stream, float value, float right) = 0;
+#endif
/* set/get stream type state. This will probably be used by
* the preference panel, mostly.
*/
@@ -117,6 +136,16 @@ public:
uint32_t *pChannels,
uint32_t *pLatencyMs,
uint32_t flags) = 0;
+#ifdef WITH_QCOM_LPA
+ virtual int openSession(uint32_t *pDevices,
+ uint32_t *pFormat,
+ uint32_t flags,
+ int32_t stream,
+ int32_t sessionId){return 0;};
+ virtual status_t pauseSession(int output, int32_t stream) = 0;
+ virtual status_t resumeSession(int output, int32_t stream) = 0;
+ virtual status_t closeSession(int output) = 0;
+#endif
virtual int openDuplicateOutput(int output1, int output2) = 0;
virtual status_t closeOutput(int output) = 0;
virtual status_t suspendOutput(int output) = 0;
@@ -159,6 +188,9 @@ public:
int *enabled) = 0;
virtual status_t moveEffects(int session, int srcOutput, int dstOutput) = 0;
+#ifdef WITH_QCOM_LPA
+ virtual status_t deregisterClient(const sp<IAudioFlingerClient>& client) { return false; };
+#endif
};
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index 9807cbe..b8a4621 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -54,6 +54,15 @@ public:
uint32_t format = AUDIO_FORMAT_DEFAULT,
uint32_t channels = 0,
audio_policy_output_flags_t flags = AUDIO_POLICY_OUTPUT_FLAG_INDIRECT) = 0;
+#ifdef WITH_QCOM_LPA
+ virtual audio_io_handle_t getSession(audio_stream_type_t stream,
+ uint32_t format = AUDIO_FORMAT_DEFAULT,
+ audio_policy_output_flags_t flags = AUDIO_POLICY_OUTPUT_FLAG_DIRECT,
+ int32_t sessionId=-1) { return 0; }
+ virtual status_t pauseSession(audio_io_handle_t output, audio_stream_type_t stream) { return 0; }
+ virtual status_t resumeSession(audio_io_handle_t output, audio_stream_type_t stream) { return 0; }
+ virtual status_t closeSession(audio_io_handle_t output) = 0;
+#endif
virtual status_t startOutput(audio_io_handle_t output,
audio_stream_type_t stream,
int session = 0) = 0;
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index 80f43a3..e05e5c5 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -90,12 +90,25 @@ public:
AudioCallback cb = NULL,
void *cookie = NULL) = 0;
+#ifdef WITH_QCOM_LPA
+ // API to open a routing session for tunneled audio playback
+ virtual status_t openSession(
+ int format, int sessionId, uint32_t sampleRate = 44100, int channels = 2) {return 0;};
+#endif
+
virtual void start() = 0;
virtual ssize_t write(const void* buffer, size_t size) = 0;
virtual void stop() = 0;
virtual void flush() = 0;
virtual void pause() = 0;
+#ifdef WITH_QCOM_LPA
+ virtual void pauseSession() {return;};
+ virtual void resumeSession() {return;};
+#endif
virtual void close() = 0;
+#ifdef WITH_QCOM_LPA
+ virtual void closeSession() {return;};
+#endif
};
MediaPlayerBase() : mCookie(0), mNotify(0) {}
diff --git a/include/media/stagefright/AudioPlayer.h b/include/media/stagefright/AudioPlayer.h
index 7adefaa..bb05ba3 100644
--- a/include/media/stagefright/AudioPlayer.h
+++ b/include/media/stagefright/AudioPlayer.h
@@ -42,27 +42,27 @@ public:
virtual ~AudioPlayer();
// Caller retains ownership of "source".
- void setSource(const sp<MediaSource> &source);
+ virtual void setSource(const sp<MediaSource> &source);
// Return time in us.
virtual int64_t getRealTimeUs();
- status_t start(bool sourceAlreadyStarted = false);
+ virtual status_t start(bool sourceAlreadyStarted = false);
- void pause(bool playPendingSamples = false);
- void resume();
+ virtual void pause(bool playPendingSamples = false);
+ virtual void resume();
// Returns the timestamp of the last buffer played (in us).
- int64_t getMediaTimeUs();
+ virtual int64_t getMediaTimeUs();
// Returns true iff a mapping is established, i.e. the AudioPlayer
// has played at least one frame of audio.
- bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);
+ virtual bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);
- status_t seekTo(int64_t time_us);
+ virtual status_t seekTo(int64_t time_us);
- bool isSeeking();
- bool reachedEOS(status_t *finalStatus);
+ virtual bool isSeeking();
+ virtual bool reachedEOS(status_t *finalStatus);
private:
friend class VideoEditorAudioPlayer;
diff --git a/include/media/stagefright/LPAPlayer.h b/include/media/stagefright/LPAPlayer.h
new file mode 100644
index 0000000..0326d97
--- /dev/null
+++ b/include/media/stagefright/LPAPlayer.h
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LPA_PLAYER_H_
+
+#define LPA_PLAYER_H_
+
+#include "AudioPlayer.h"
+#include <media/IAudioFlinger.h>
+#include <utils/threads.h>
+#include <utils/List.h>
+#include <utils/Vector.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <binder/IServiceManager.h>
+#include <linux/unistd.h>
+#include <linux/msm_audio.h>
+#include <linux/ion.h>
+#include <include/TimedEventQueue.h>
+#include <binder/BinderService.h>
+#include <binder/MemoryDealer.h>
+#include <powermanager/IPowerManager.h>
+
+// Pause timeout = 3sec
+#define LPA_PAUSE_TIMEOUT_USEC 3000000
+
+namespace android {
+
+class LPAPlayer : public AudioPlayer {
+public:
+ enum {
+ REACHED_EOS,
+ SEEK_COMPLETE
+ };
+
+ LPAPlayer(const sp<MediaPlayerBase::AudioSink> &audioSink, bool &initCheck,
+ AwesomePlayer *audioObserver = NULL);
+
+ virtual ~LPAPlayer();
+
+ // Caller retains ownership of "source".
+ virtual void setSource(const sp<MediaSource> &source);
+
+ // Return time in us.
+ virtual int64_t getRealTimeUs();
+
+ virtual status_t start(bool sourceAlreadyStarted = false);
+
+ virtual void pause(bool playPendingSamples = false);
+ virtual void resume();
+
+ // Returns the timestamp of the last buffer played (in us).
+ virtual int64_t getMediaTimeUs();
+
+ // Returns true iff a mapping is established, i.e. the LPAPlayer
+ // has played at least one frame of audio.
+ virtual bool getMediaTimeMapping(int64_t *realtime_us, int64_t *mediatime_us);
+
+ virtual status_t seekTo(int64_t time_us);
+
+ virtual bool isSeeking();
+ virtual bool reachedEOS(status_t *finalStatus);
+
+
+ void* handle;
+ static int objectsAlive;
+private:
+
+ int afd;
+ int efd;
+ int ionfd;
+ int sessionId;
+ uint32_t bytesToWrite;
+ bool isPaused;
+ bool mSeeked;
+ bool a2dpDisconnectPause;
+ bool a2dpThreadStarted;
+ volatile bool asyncReset;
+ bool eventThreadCreated;
+ int mBuffSize;
+ int mBuffNumber;
+
+ void clearPowerManager();
+
+ class PMDeathRecipient : public IBinder::DeathRecipient {
+ public:
+ PMDeathRecipient(void *obj){parentClass = (LPAPlayer *)obj;}
+ virtual ~PMDeathRecipient() {}
+
+ // IBinder::DeathRecipient
+ virtual void binderDied(const wp<IBinder>& who);
+
+ private:
+ LPAPlayer *parentClass;
+ PMDeathRecipient(const PMDeathRecipient&);
+ PMDeathRecipient& operator = (const PMDeathRecipient&);
+
+ friend class LPAPlayer;
+ };
+
+ friend class PMDeathRecipient;
+
+ void acquireWakeLock();
+ void releaseWakeLock();
+
+ sp<IPowerManager> mPowerManager;
+ sp<IBinder> mWakeLockToken;
+ sp<PMDeathRecipient> mDeathRecipient;
+
+ //Structure to hold ion buffer information
+ class BuffersAllocated {
+ /* overload BuffersAllocated constructor to support both ion and pmem memory allocation */
+ public:
+ BuffersAllocated(void *buf1, void *buf2, int32_t nSize, int32_t fd) :
+ localBuf(buf1), memBuf(buf2), memBufsize(nSize), memFd(fd)
+ {}
+ BuffersAllocated(void *buf1, void *buf2, int32_t nSize, int32_t share_fd, struct ion_handle *handle) :
+ ion_handle(handle), localBuf(buf1), memBuf(buf2), memBufsize(nSize), memFd(share_fd)
+ {}
+ struct ion_handle *ion_handle;
+ void* localBuf;
+ void* memBuf;
+ int32_t memBufsize;
+ int32_t memFd;
+ uint32_t bytesToWrite;
+ };
+ void audio_register_memory();
+ void memBufferDeAlloc();
+ void *memBufferAlloc(int32_t nSize, int32_t *mem_fd);
+
+ List<BuffersAllocated> memBuffersRequestQueue;
+ List<BuffersAllocated> memBuffersResponseQueue;
+ List<BuffersAllocated> bufPool;
+ List<BuffersAllocated> effectsQueue;
+
+
+ //Declare all the threads
+ pthread_t eventThread;
+ pthread_t decoderThread;
+ pthread_t A2DPThread;
+ pthread_t EffectsThread;
+ pthread_t A2DPNotificationThread;
+
+ //Kill Thread boolean
+ bool killDecoderThread;
+ bool killEventThread;
+ bool killA2DPThread;
+ bool killEffectsThread;
+ bool killA2DPNotificationThread;
+
+ //Thread alive boolean
+ bool decoderThreadAlive;
+ bool eventThreadAlive;
+ bool a2dpThreadAlive;
+ bool effectsThreadAlive;
+ bool a2dpNotificationThreadAlive;
+
+ //Declare the condition Variables and Mutex
+ pthread_mutex_t mem_request_mutex;
+ pthread_mutex_t mem_response_mutex;
+ pthread_mutex_t decoder_mutex;
+ pthread_mutex_t event_mutex;
+ pthread_mutex_t a2dp_mutex;
+ pthread_mutex_t effect_mutex;
+ pthread_mutex_t apply_effect_mutex;
+ pthread_mutex_t a2dp_notification_mutex;
+ pthread_mutex_t pause_mutex;
+
+ pthread_cond_t event_cv;
+ pthread_cond_t decoder_cv;
+ pthread_cond_t a2dp_cv;
+ pthread_cond_t effect_cv;
+ pthread_cond_t event_thread_cv;
+ pthread_cond_t a2dp_notification_cv;
+ pthread_cond_t pause_cv;
+
+ // make sure Decoder thread has exited
+ void requestAndWaitForDecoderThreadExit();
+
+ // make sure the event thread also exited
+ void requestAndWaitForEventThreadExit();
+
+ // make sure the A2dp thread also exited
+ void requestAndWaitForA2DPThreadExit();
+
+ // make sure the Effects thread also exited
+ void requestAndWaitForEffectsThreadExit();
+
+ // make sure the Effects thread also exited
+ void requestAndWaitForA2DPNotificationThreadExit();
+
+ static void *eventThreadWrapper(void *me);
+ void eventThreadEntry();
+ static void *decoderThreadWrapper(void *me);
+ void decoderThreadEntry();
+ static void *A2DPThreadWrapper(void *me);
+ void A2DPThreadEntry();
+ static void *EffectsThreadWrapper(void *me);
+ void EffectsThreadEntry();
+ static void *A2DPNotificationThreadWrapper(void *me);
+ void A2DPNotificationThreadEntry();
+
+ void createThreads();
+
+ volatile bool bIsA2DPEnabled, bIsAudioRouted, bEffectConfigChanged;
+
+ //Structure to recieve the BT notification from the flinger.
+ class AudioFlingerLPAdecodeClient: public IBinder::DeathRecipient, public BnAudioFlingerClient {
+ public:
+ AudioFlingerLPAdecodeClient(void *obj);
+
+ LPAPlayer *pBaseClass;
+ // DeathRecipient
+ virtual void binderDied(const wp<IBinder>& who);
+
+ // IAudioFlingerClient
+
+ // indicate a change in the configuration of an output or input: keeps the cached
+ // values for output/input parameters upto date in client process
+ virtual void ioConfigChanged(int event, int ioHandle, void *param2);
+
+ friend class LPAPlayer;
+ };
+
+ sp<IAudioFlinger> mAudioFlinger;
+
+ // helper function to obtain AudioFlinger service handle
+ void getAudioFlinger();
+
+ void handleA2DPSwitch();
+
+ sp<AudioFlingerLPAdecodeClient> AudioFlingerClient;
+ friend class AudioFlingerLPAdecodeClient;
+ Mutex AudioFlingerLock;
+ bool mSourceEmpty;
+ bool mAudioSinkOpen;
+
+ sp<MediaSource> mSource;
+
+ MediaBuffer *mInputBuffer;
+ int32_t numChannels;
+ int mSampleRate;
+ int64_t mLatencyUs;
+ size_t mFrameSize;
+
+ Mutex pmLock;
+ Mutex mLock;
+ Mutex mSeekLock;
+ Mutex a2dpSwitchLock;
+ Mutex resumeLock;
+ int64_t mNumFramesPlayed;
+
+ int64_t mPositionTimeMediaUs;
+ int64_t mPositionTimeRealUs;
+
+ bool mSeeking;
+ bool mInternalSeeking;
+ bool mReachedEOS;
+ status_t mFinalStatus;
+ int64_t mSeekTimeUs;
+ int64_t mPauseTime;
+ int64_t mNumA2DPBytesPlayed;
+ int64_t timePlayed;
+ int64_t timeStarted;
+
+ bool mStarted;
+
+ bool mIsFirstBuffer;
+ status_t mFirstBufferResult;
+ MediaBuffer *mFirstBuffer;
+ TimedEventQueue mQueue;
+ bool mQueueStarted;
+ sp<TimedEventQueue::Event> mPauseEvent;
+ bool mPauseEventPending;
+ bool mPlaybackSuspended;
+ bool mIsDriverStarted;
+ bool mIsAudioRouted;
+
+ sp<MediaPlayerBase::AudioSink> mAudioSink;
+ AwesomePlayer *mObserver;
+
+ enum A2DPState {
+ A2DP_ENABLED,
+ A2DP_DISABLED,
+ A2DP_CONNECT,
+ A2DP_DISCONNECT
+ };
+
+ size_t fillBuffer(void *data, size_t size);
+
+ int64_t getRealTimeUsLocked();
+ int64_t getTimeStamp(A2DPState state);
+
+ void reset();
+
+ void onPauseTimeOut();
+
+
+ LPAPlayer(const LPAPlayer &);
+ LPAPlayer &operator=(const LPAPlayer &);
+};
+
+struct TimedEvent : public TimedEventQueue::Event {
+ TimedEvent(LPAPlayer *player,
+ void (LPAPlayer::*method)())
+ : mPlayer(player),
+ mMethod(method) {
+ }
+
+protected:
+ virtual ~TimedEvent() {}
+
+ virtual void fire(TimedEventQueue *queue, int64_t /* now_us */) {
+ (mPlayer->*mMethod)();
+ }
+
+private:
+ LPAPlayer *mPlayer;
+ void (LPAPlayer::*mMethod)();
+
+ TimedEvent(const TimedEvent &);
+ TimedEvent &operator=(const TimedEvent &);
+};
+
+} // namespace android
+
+#endif // LPA_PLAYER_H_
+