summaryrefslogtreecommitdiffstats
path: root/opensles
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2010-10-22 11:03:10 -0700
committerGlenn Kasten <gkasten@google.com>2010-10-22 16:59:40 -0700
commit72018e7db99736eb056c79623a9e04ce83cadf1b (patch)
tree9a247d8e2ac0f384493bbf81f358235f7ee2a3c6 /opensles
parent9e6172548bb344c24962c8a57274281e4315feba (diff)
downloadandroid_system_media-72018e7db99736eb056c79623a9e04ce83cadf1b.tar.gz
android_system_media-72018e7db99736eb056c79623a9e04ce83cadf1b.tar.bz2
android_system_media-72018e7db99736eb056c79623a9e04ce83cadf1b.zip
Bug 3101247 - move track ownership
Preliminary fix for torture test failure - move track ownership Change-Id: I4c9de6a85cc0bd594f16bdb1a5de61f5f268cfdb
Diffstat (limited to 'opensles')
-rw-r--r--opensles/libopensles/android_AudioPlayer.cpp19
-rw-r--r--opensles/libopensles/android_SfPlayer.cpp19
2 files changed, 31 insertions, 7 deletions
diff --git a/opensles/libopensles/android_AudioPlayer.cpp b/opensles/libopensles/android_AudioPlayer.cpp
index f4138bfb..c52adaa5 100644
--- a/opensles/libopensles/android_AudioPlayer.cpp
+++ b/opensles/libopensles/android_AudioPlayer.cpp
@@ -465,6 +465,10 @@ static void sfplayer_handlePrefetchEvent(const int event, const int data1, void*
case(android::SfPlayer::kEventNewAudioTrack): {
object_lock_exclusive(&ap->mObject);
+#if 1
+ // SfPlayer has a new AudioTrack, update our pointer copy and configure the new one before
+ // starting to use it
+#else
// SfPlayer has a new AudioTrack, delete the old one and configure the new one before
// starting to use it
@@ -472,6 +476,7 @@ static void sfplayer_handlePrefetchEvent(const int event, const int data1, void*
delete ap->mAudioTrack;
ap->mAudioTrack = NULL;
}
+#endif
ap->mAudioTrack = ap->mSfPlayer->getAudioTrack();
ap->mNumChannels = ap->mSfPlayer->getNumChannels();
ap->mSampleRateMilliHz = android_to_sles_sampleRate(ap->mSfPlayer->getSampleRateHz());
@@ -1133,11 +1138,19 @@ SLresult android_audioPlayer_destroy(CAudioPlayer *pAudioPlayer) {
//-----------------------------------
// AudioTrack
case AUDIOTRACK_PULL:
+ // We own the audio track for PCM buffer queue players
+ if (pAudioPlayer->mAudioTrack != NULL) {
+ pAudioPlayer->mAudioTrack->stop();
+ delete pAudioPlayer->mAudioTrack;
+ pAudioPlayer->mAudioTrack = NULL;
+ }
break;
#ifndef USE_BACKPORT
//-----------------------------------
// MediaPlayer
case MEDIAPLAYER:
+ // We don't own this audio track, SfPlayer does
+ pAudioPlayer->mAudioTrack = NULL;
// FIXME might no longer be needed since we call explicit destructor
if (pAudioPlayer->mSfPlayer != 0) {
pAudioPlayer->mSfPlayer.clear();
@@ -1150,12 +1163,6 @@ SLresult android_audioPlayer_destroy(CAudioPlayer *pAudioPlayer) {
break;
}
- if (pAudioPlayer->mAudioTrack != NULL) {
- pAudioPlayer->mAudioTrack->stop();
- delete pAudioPlayer->mAudioTrack;
- pAudioPlayer->mAudioTrack = NULL;
- }
-
// FIXME might not be needed
pAudioPlayer->mAndroidObjType = INVALID_TYPE;
diff --git a/opensles/libopensles/android_SfPlayer.cpp b/opensles/libopensles/android_SfPlayer.cpp
index d391f206..613c1817 100644
--- a/opensles/libopensles/android_SfPlayer.cpp
+++ b/opensles/libopensles/android_SfPlayer.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+//#define USE_LOG SLAndroidLogLevel_Verbose
+
#include "android_SfPlayer.h"
#include <stdio.h>
@@ -68,6 +70,12 @@ SfPlayer::~SfPlayer() {
mRenderLooper->unregisterHandler(this->id());
mRenderLooper.clear();
+ if (mAudioTrack != NULL) {
+ mAudioTrack->stop();
+ delete mAudioTrack;
+ mAudioTrack = NULL;
+ }
+
if (mAudioSource != NULL) {
{
// don't even think about stopping the media source without releasing the decode buffer
@@ -310,6 +318,7 @@ void SfPlayer::onPrepare(const sp<AMessage> &msg) {
}
// at this point we have enough information about the source to create its associated AudioTrack
+ assert(NULL == mAudioTrack);
mAudioTrack = new android::AudioTrack(
mPlaybackParams.streamType, // streamType
mSampleRateHz, // sampleRate
@@ -453,6 +462,11 @@ void SfPlayer::updatePlaybackParamsFromSource() {
// the AudioTrack currently used by the AudioPlayer will be deleted by AudioPlayer itself
// SfPlayer never deletes the AudioTrack it creates and uses.
+ if (NULL != mAudioTrack) {
+ mAudioTrack->stop();
+ delete mAudioTrack;
+ mAudioTrack = NULL;
+ }
mAudioTrack = new android::AudioTrack(
mPlaybackParams.streamType, // streamType
mSampleRateHz, // sampleRate
@@ -669,13 +683,15 @@ void SfPlayer::onRender(const sp<AMessage> &msg) {
}
if (mFlags & kFlagPlaying) {
+ assert(NULL != mAudioTrack);
mAudioTrack->write( (const uint8_t *)mDecodeBuffer->data() + mDecodeBuffer->range_offset(),
mDecodeBuffer->range_length());
(new AMessage(kWhatDecode, id()))->post();
#ifdef _DEBUG_AUDIO_TESTS
// Automated tests: Intercept PCM data and write to file for later validations
if (mMonitorAudioFp != NULL) {
- fwrite((const uint8_t *)mDecodeBuffer->data() + mDecodeBuffer->range_offset(), mDecodeBuffer->range_length(), 1, mMonitorAudioFp);
+ fwrite((const uint8_t *)mDecodeBuffer->data() + mDecodeBuffer->range_offset(),
+ mDecodeBuffer->range_length(), 1, mMonitorAudioFp);
}
#endif
}
@@ -693,6 +709,7 @@ void SfPlayer::onCheckCache(const sp<AMessage> &msg) {
if (eos || status == kStatusHigh
|| ((mFlags & kFlagPreparing) && (status >= kStatusEnough))) {
if (mFlags & kFlagPlaying) {
+ assert(NULL != mAudioTrack);
mAudioTrack->start();
}
mFlags &= ~kFlagBuffering;