summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2010-09-27 17:12:52 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2010-09-28 09:32:25 -0700
commitb8e52590d14863805bc1ba9d58efa95cbf8ae302 (patch)
treec365775b0673ea1a2c6586d2d7a4b99e3bfee01a
parent0673981b5807e901fc8f025052bcac0ac3654a7f (diff)
downloadandroid_system_media-b8e52590d14863805bc1ba9d58efa95cbf8ae302.tar.gz
android_system_media-b8e52590d14863805bc1ba9d58efa95cbf8ae302.tar.bz2
android_system_media-b8e52590d14863805bc1ba9d58efa95cbf8ae302.zip
Fix bug 3004701 do not prefetch during Realize.
Removed unused Android object states in enum, not used in play state machine. Made SfPlayer responsible for the creation of its AudioTrack once it knows the sample rate and number of channels of the content to play once it's done preparing. Added notification from SfPlayer to signal when it's done preparing. This informs of the audio characteristics and kicks off the content prefetching. In the AudioPlayer realize: - do not start the prefetching, do it when the player is set to PAUSED - don not create the AudioTrack, do it when SfPlayer is done preparing. Change-Id: Ic345040e71cef0e5953ea47366930d1dfbc5e761
-rw-r--r--opensles/libopensles/android_AudioPlayer.cpp159
-rw-r--r--opensles/libopensles/android_SfPlayer.cpp110
-rw-r--r--opensles/libopensles/android_SfPlayer.h24
-rw-r--r--opensles/libopensles/android_prompts.h2
-rw-r--r--opensles/libopensles/sles_allinclusive.h2
-rw-r--r--opensles/tests/mimeUri/Android.mk2
6 files changed, 179 insertions, 120 deletions
diff --git a/opensles/libopensles/android_AudioPlayer.cpp b/opensles/libopensles/android_AudioPlayer.cpp
index a85e7c76..7a01b818 100644
--- a/opensles/libopensles/android_AudioPlayer.cpp
+++ b/opensles/libopensles/android_AudioPlayer.cpp
@@ -365,17 +365,48 @@ SLresult audioPlayer_getStreamType(CAudioPlayer* ap, SLint32 *pType) {
//-----------------------------------------------------------------------------
#ifndef USE_BACKPORT
+static void sfplayer_prepare(CAudioPlayer *ap) {
+ if (ap->mSfPlayer != 0) {
+ ap->mSfPlayer->prepare();
+ }
+ ap->mAndroidObjState = ANDROID_PREPARING;
+}
+#endif
+
+//-----------------------------------------------------------------------------
+#ifndef USE_BACKPORT
// Callback associated with an SfPlayer of an SL ES AudioPlayer that gets its data
-// from a URI or FD, for prefetching events
+// from a URI or FD, for prepare and prefetch events
static void sfplayer_handlePrefetchEvent(const int event, const int data1, void* user) {
if (NULL == user) {
return;
}
CAudioPlayer *ap = (CAudioPlayer *)user;
- //SL_LOGV("received event %d, data %d from SfAudioPlayer", event, data1);
+ SL_LOGV("received event %d, data %d from SfAudioPlayer", event, data1);
switch(event) {
+ case(android::SfPlayer::kEventPrepared): {
+ object_lock_exclusive(&ap->mObject);
+
+ if (SFPLAYER_SUCCESS != data1) {
+ ap->mAudioTrack = NULL;
+ ap->mNumChannels = 0;
+ ap->mSampleRateMilliHz = 0;
+ ap->mAndroidObjState = ANDROID_UNINITIALIZED;
+
+ } else {
+ ap->mAudioTrack = ap->mSfPlayer->getAudioTrack();
+ ap->mNumChannels = ap->mSfPlayer->getNumChannels();
+ ap->mSampleRateMilliHz = android_to_sles_sampleRate(ap->mSfPlayer->getSampleRateHz());
+ ap->mSfPlayer->startPrefetch_async();
+
+ ap->mAndroidObjState = ANDROID_READY;
+ }
+
+ object_unlock_exclusive(&ap->mObject);
+ } break;
+
case(android::SfPlayer::kEventPrefetchFillLevelUpdate): {
if (!IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) {
break;
@@ -428,9 +459,9 @@ static void sfplayer_handlePrefetchEvent(const int event, const int data1, void*
case(android::SfPlayer::kEventEndOfStream): {
audioPlayer_dispatch_headAtEnd_lockPlay(ap, true /*set state to paused?*/, true);
- // FIXME update play position to make sure it's at the same value
- // as getDuration if it's known?
- ap->mAudioTrack->stop();
+ if (NULL != ap->mAudioTrack) {
+ ap->mAudioTrack->stop();
+ }
} break;
default:
@@ -921,26 +952,36 @@ SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async
pAudioPlayer->mNumChannels = df_pcm->numChannels;
pAudioPlayer->mSampleRateMilliHz = df_pcm->samplesPerSec; // Note: bad field name in SL ES
+
+ pAudioPlayer->mAndroidObjState = ANDROID_READY;
} break;
#ifndef USE_BACKPORT
//-----------------------------------
// MediaPlayer
case MEDIAPLAYER: {
object_lock_exclusive(&pAudioPlayer->mObject);
- pAudioPlayer->mAndroidObjState = ANDROID_PREPARING;
- pAudioPlayer->mSfPlayer = new android::SfPlayer();
+ pAudioPlayer->mAndroidObjState = ANDROID_UNINITIALIZED;
+ pAudioPlayer->mNumChannels = 0;
+ pAudioPlayer->mSampleRateMilliHz = 0;
+ pAudioPlayer->mAudioTrack = NULL;
+
+ AudioPlayback_Parameters app;
+ app.sessionId = pAudioPlayer->mSessionId;
+ app.streamType = pAudioPlayer->mStreamType;
+ app.trackcb = audioTrack_callBack_uri;
+ app.trackcbUser = (void *) pAudioPlayer;
+
+ pAudioPlayer->mSfPlayer = new android::SfPlayer(&app);
pAudioPlayer->mSfPlayer->setNotifListener(sfplayer_handlePrefetchEvent,
(void*)pAudioPlayer /*notifUSer*/);
pAudioPlayer->mSfPlayer->armLooper();
object_unlock_exclusive(&pAudioPlayer->mObject);
- int res;
switch (pAudioPlayer->mDataSource.mLocator.mLocatorType) {
case SL_DATALOCATOR_URI:
pAudioPlayer->mSfPlayer->setDataSource(
(const char*)pAudioPlayer->mDataSource.mLocator.mURI.URI);
- res = pAudioPlayer->mSfPlayer->prepare_sync();
break;
case SL_DATALOCATOR_ANDROIDFD: {
int64_t offset = (int64_t)pAudioPlayer->mDataSource.mLocator.mFD.offset;
@@ -949,50 +990,12 @@ SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async
offset == SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ?
(int64_t)SFPLAYER_FD_FIND_FILE_SIZE : offset,
(int64_t)pAudioPlayer->mDataSource.mLocator.mFD.length);
- res = pAudioPlayer->mSfPlayer->prepare_sync();
} break;
default:
- res = ~SFPLAYER_SUCCESS;
+ SL_LOGE(ERROR_PLAYERREALIZE_UNKNOWN_DATASOURCE_LOCATOR);
break;
}
- object_lock_exclusive(&pAudioPlayer->mObject);
- if (SFPLAYER_SUCCESS != res) {
- pAudioPlayer->mAndroidObjState = ANDROID_UNINITIALIZED;
- pAudioPlayer->mNumChannels = 0;
- pAudioPlayer->mSampleRateMilliHz = 0;
- pAudioPlayer->mAudioTrack = NULL;
- } else {
- // create audio track based on parameters retrieved from Stagefright
- pAudioPlayer->mAudioTrack = new android::AudioTrack(
- pAudioPlayer->mStreamType, // streamType
- pAudioPlayer->mSfPlayer->getSampleRateHz(), // sampleRate
- android::AudioSystem::PCM_16_BIT, // format
- pAudioPlayer->mSfPlayer->getNumChannels() == 1 ? //channel mask
- android::AudioSystem::CHANNEL_OUT_MONO :
- android::AudioSystem::CHANNEL_OUT_STEREO,
- 0, // frameCount (here min)
- 0, // flags
- audioTrack_callBack_uri, // callback
- (void *) pAudioPlayer, // user
- 0 // notificationFrame
-#ifndef USE_BACKPORT
- , pAudioPlayer->mSessionId
-#endif
- );
- pAudioPlayer->mNumChannels = pAudioPlayer->mSfPlayer->getNumChannels();
- pAudioPlayer->mSampleRateMilliHz =
- android_to_sles_sampleRate(pAudioPlayer->mSfPlayer->getSampleRateHz());
- pAudioPlayer->mSfPlayer->useAudioTrack(pAudioPlayer->mAudioTrack);
-
- if (pAudioPlayer->mSfPlayer->wantPrefetch()) {
- pAudioPlayer->mAndroidObjState = ANDROID_PREPARED;
- } else {
- pAudioPlayer->mAndroidObjState = ANDROID_READY;
- }
- }
- object_unlock_exclusive(&pAudioPlayer->mObject);
-
} break;
#endif
default:
@@ -1003,10 +1006,6 @@ SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async
#ifndef USE_BACKPORT
- if (ANDROID_UNINITIALIZED == pAudioPlayer->mAndroidObjState) {
- return result;
- }
-
// proceed with effect initialization
// initialize EQ
// FIXME use a table of effect descriptors when adding support for more effects
@@ -1173,16 +1172,22 @@ void android_audioPlayer_setPlayState(CAudioPlayer *ap) {
case AUDIOTRACK_PULL:
switch (state) {
case SL_PLAYSTATE_STOPPED:
- SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_STOPPED");
- ap->mAudioTrack->stop();
+ SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_STOPPED");
+ if (NULL != ap->mAudioTrack) {
+ ap->mAudioTrack->stop();
+ }
break;
case SL_PLAYSTATE_PAUSED:
- SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PAUSED");
- ap->mAudioTrack->pause();
+ SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PAUSED");
+ if (NULL != ap->mAudioTrack) {
+ ap->mAudioTrack->pause();
+ }
break;
case SL_PLAYSTATE_PLAYING:
- SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PLAYING");
- ap->mAudioTrack->start();
+ SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PLAYING");
+ if (NULL != ap->mAudioTrack) {
+ ap->mAudioTrack->start();
+ }
break;
default:
// checked by caller, should not happen
@@ -1193,28 +1198,22 @@ void android_audioPlayer_setPlayState(CAudioPlayer *ap) {
case MEDIAPLAYER:
switch (state) {
case SL_PLAYSTATE_STOPPED: {
- SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_STOPPED");
+ SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_STOPPED");
if (ap->mSfPlayer != 0) {
ap->mSfPlayer->stop();
}
} break;
case SL_PLAYSTATE_PAUSED: {
- SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PAUSED");
+ SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PAUSED");
object_lock_peek(&ap);
AndroidObject_state state = ap->mAndroidObjState;
object_unlock_peek(&ap);
switch(state) {
case(ANDROID_UNINITIALIZED):
+ sfplayer_prepare(ap);
+ break;
case(ANDROID_PREPARING):
- if (ap->mSfPlayer != 0) {
- ap->mSfPlayer->pause();
- }
break;
- case(ANDROID_PREPARED):
- if (ap->mSfPlayer != 0) {
- ap->mSfPlayer->startPrefetch_async();
- }
- case(ANDROID_PREFETCHING):
case(ANDROID_READY):
if (ap->mSfPlayer != 0) {
ap->mSfPlayer->pause();
@@ -1225,15 +1224,25 @@ void android_audioPlayer_setPlayState(CAudioPlayer *ap) {
}
} break;
case SL_PLAYSTATE_PLAYING: {
- SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PLAYING");
+ SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PLAYING");
object_lock_peek(&ap);
AndroidObject_state state = ap->mAndroidObjState;
object_unlock_peek(&ap);
- // FIXME check in spec when playback is allowed to start in another state
- if ((state >= ANDROID_READY) && (ap->mSfPlayer != 0)) {
- ap->mSfPlayer->play();
+ switch(state) {
+ case(ANDROID_UNINITIALIZED):
+ sfplayer_prepare(ap);
+ // fall through
+ case(ANDROID_PREPARING):
+ case(ANDROID_READY):
+ if (ap->mSfPlayer != 0) {
+ ap->mSfPlayer->play();
+ }
+ break;
+ default:
+ break;
}
} break;
+
default:
// checked by caller, should not happen
break;
@@ -1321,11 +1330,11 @@ void android_audioPlayer_getPosition(IPlay *pPlayItf, SLmillisecond *pPosMsec) {
CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis;
switch(ap->mAndroidObjType) {
case AUDIOTRACK_PULL:
- uint32_t positionInFrames;
- ap->mAudioTrack->getPosition(&positionInFrames);
- if (ap->mSampleRateMilliHz == 0) {
+ if ((ap->mSampleRateMilliHz == 0) || (NULL == ap->mAudioTrack)) {
*pPosMsec = 0;
} else {
+ uint32_t positionInFrames;
+ ap->mAudioTrack->getPosition(&positionInFrames);
*pPosMsec = ((int64_t)positionInFrames * 1000) /
sles_to_android_sampleRate(ap->mSampleRateMilliHz);
}
diff --git a/opensles/libopensles/android_SfPlayer.cpp b/opensles/libopensles/android_SfPlayer.cpp
index 43661dc9..94101da3 100644
--- a/opensles/libopensles/android_SfPlayer.cpp
+++ b/opensles/libopensles/android_SfPlayer.cpp
@@ -24,7 +24,7 @@
namespace android {
-SfPlayer::SfPlayer()
+SfPlayer::SfPlayer(AudioPlayback_Parameters *app)
: mAudioTrack(NULL),
mFlags(0),
mBitrate(-1),
@@ -44,6 +44,11 @@ SfPlayer::SfPlayer()
mDecodeBuffer(NULL) {
mRenderLooper = new android::ALooper();
+
+ mPlaybackParams.sessionId = app->sessionId;
+ mPlaybackParams.streamType = app->streamType;
+ mPlaybackParams.trackcb = app->trackcb;
+ mPlaybackParams.trackcbUser = app->trackcbUser;
}
@@ -85,6 +90,13 @@ void SfPlayer::setNotifListener(const notif_client_t cbf, void* notifUser) {
}
+void SfPlayer::notifyPrepared(status_t prepareRes) {
+ sp<AMessage> msg = new AMessage(kWhatNotif, id());
+ msg->setInt32(EVENT_PREPARED, (int32_t)prepareRes);
+ notify(msg, true /*async*/);
+}
+
+
void SfPlayer::notifyStatus() {
sp<AMessage> msg = new AMessage(kWhatNotif, id());
msg->setInt32(EVENT_PREFETCHSTATUSCHANGE, (int32_t)mCacheStatus);
@@ -155,27 +167,22 @@ void SfPlayer::setDataSource(const int fd, const int64_t offset, const int64_t l
mDataLocatorType = kDataLocatorFd;
}
-void SfPlayer::prepare_async() {
- //SL_LOGV("SfPlayer::prepare_async()");
+void SfPlayer::prepare() {
+ //SL_LOGV("SfPlayer::prepare()");
sp<AMessage> msg = new AMessage(kWhatPrepare, id());
msg->post();
}
-int SfPlayer::prepare_sync() {
- //SL_LOGV("SfPlayer::prepare_sync()");
- sp<AMessage> msg = new AMessage(kWhatPrepare, id());
- return onPrepare(msg);
-}
-int SfPlayer::onPrepare(const sp<AMessage> &msg) {
- //SL_LOGV("SfPlayer::onPrepare");
+void SfPlayer::onPrepare(const sp<AMessage> &msg) {
+ SL_LOGV("SfPlayer::onPrepare");
sp<DataSource> dataSource;
switch (mDataLocatorType) {
case kDataLocatorNone:
SL_LOGE("SfPlayer::onPrepare: no data locator set");
- return MEDIA_ERROR_BASE;
+ notifyPrepared(MEDIA_ERROR_BASE);
break;
case kDataLocatorUri:
@@ -197,7 +204,8 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) {
mDataLocator.fdi.fd, mDataLocator.fdi.offset, mDataLocator.fdi.length);
status_t err = dataSource->initCheck();
if (err != OK) {
- return err;
+ notifyPrepared(err);
+ return;
}
}
break;
@@ -208,13 +216,15 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) {
if (dataSource == NULL) {
SL_LOGE("SfPlayer::onPrepare: Could not create data source.");
- return ERROR_UNSUPPORTED;
+ notifyPrepared(ERROR_UNSUPPORTED);
+ return;
}
sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource);
if (extractor == NULL) {
SL_LOGE("SfPlayer::onPrepare: Could not instantiate extractor.");
- return ERROR_UNSUPPORTED;
+ notifyPrepared(ERROR_UNSUPPORTED);
+ return;
}
ssize_t audioTrackIndex = -1;
@@ -237,7 +247,7 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) {
if (audioTrackIndex < 0) {
SL_LOGE("SfPlayer::onPrepare: Could not find an audio track.");
- return ERROR_UNSUPPORTED;
+ notifyPrepared(ERROR_UNSUPPORTED);
}
sp<MediaSource> source = extractor->getTrack(audioTrackIndex);
@@ -264,7 +274,8 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) {
if (source == NULL) {
SL_LOGE("SfPlayer::onPrepare: Could not instantiate decoder.");
- return ERROR_UNSUPPORTED;
+ notifyPrepared(ERROR_UNSUPPORTED);
+ return;
}
meta = source->getFormat();
@@ -272,7 +283,8 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) {
if (source->start() != OK) {
SL_LOGE("SfPlayer::onPrepare: Failed to start source/decoder.");
- return MEDIA_ERROR_BASE;
+ notifyPrepared(MEDIA_ERROR_BASE);
+ return;
}
mDataSource = dataSource;
@@ -290,8 +302,24 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) {
notifyCacheFill();
}
+ // at this point we have enough information about the source to create its associated AudioTrack
+ mAudioTrack = new android::AudioTrack(
+ mPlaybackParams.streamType, // streamType
+ mSampleRateHz, // sampleRate
+ android::AudioSystem::PCM_16_BIT, // format
+ mNumChannels == 1 ? //channel mask
+ android::AudioSystem::CHANNEL_OUT_MONO :
+ android::AudioSystem::CHANNEL_OUT_STEREO,
+ 0, // frameCount (here min)
+ 0, // flags
+ mPlaybackParams.trackcb, // callback
+ mPlaybackParams.trackcbUser, // user
+ 0, // notificationFrame
+ mPlaybackParams.sessionId
+ );
+
//SL_LOGV("SfPlayer::onPrepare: end");
- return SFPLAYER_SUCCESS;
+ notifyPrepared(SFPLAYER_SUCCESS);
}
@@ -302,25 +330,20 @@ bool SfPlayer::wantPrefetch() {
void SfPlayer::startPrefetch_async() {
- //SL_LOGV("SfPlayer::startPrefetch_async()");
+ SL_LOGV("SfPlayer::startPrefetch_async()");
if (wantPrefetch()) {
//SL_LOGV("SfPlayer::startPrefetch_async(): sending check cache msg");
mFlags |= kFlagPreparing;
mFlags |= kFlagBuffering;
- (new AMessage(kWhatCheckCache, id()))->post(100000);
+ (new AMessage(kWhatCheckCache, id()))->post();
}
}
void SfPlayer::play() {
SL_LOGV("SfPlayer::play");
- if (NULL == mAudioTrack) {
- return;
- }
-
- mAudioTrack->start();
(new AMessage(kWhatPlay, id()))->post();
(new AMessage(kWhatDecode, id()))->post();
@@ -330,10 +353,9 @@ void SfPlayer::play() {
void SfPlayer::stop() {
SL_LOGV("SfPlayer::stop");
- if (NULL == mAudioTrack) {
- return;
+ if (NULL != mAudioTrack) {
+ mAudioTrack->stop();
}
- mAudioTrack->stop();
(new AMessage(kWhatPause, id()))->post();
@@ -416,6 +438,10 @@ void SfPlayer::reachedEndOfStream() {
void SfPlayer::onPlay() {
SL_LOGV("SfPlayer::onPlay");
mFlags |= kFlagPlaying;
+
+ if (NULL != mAudioTrack) {
+ mAudioTrack->start();
+ }
}
@@ -507,6 +533,9 @@ void SfPlayer::onDecode() {
// FIXME handle error
} else {
// handle notification and looping at end of stream
+ if (0 < mDurationUsec) {
+ mLastDecodedPositionUs = mDurationUsec;
+ }
reachedEndOfStream();
}
return;
@@ -584,18 +613,23 @@ void SfPlayer::onNotify(const sp<AMessage> &msg) {
if (NULL == mNotifyClient) {
return;
}
- int32_t cacheInfo;
- if (msg->findInt32(EVENT_PREFETCHSTATUSCHANGE, &cacheInfo)) {
- SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHSTATUSCHANGE, cacheInfo);
- mNotifyClient(kEventPrefetchStatusChange, cacheInfo, mNotifyUser);
+ int32_t val;
+ if (msg->findInt32(EVENT_PREFETCHSTATUSCHANGE, &val)) {
+ SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHSTATUSCHANGE, val);
+ mNotifyClient(kEventPrefetchStatusChange, val, mNotifyUser);
+ }
+ if (msg->findInt32(EVENT_PREFETCHFILLLEVELUPDATE, &val)) {
+ SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHFILLLEVELUPDATE, val);
+ mNotifyClient(kEventPrefetchFillLevelUpdate, val, mNotifyUser);
}
- if (msg->findInt32(EVENT_PREFETCHFILLLEVELUPDATE, &cacheInfo)) {
- SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHFILLLEVELUPDATE, cacheInfo);
- mNotifyClient(kEventPrefetchFillLevelUpdate, cacheInfo, mNotifyUser);
+ if (msg->findInt32(EVENT_ENDOFSTREAM, &val)) {
+ SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_ENDOFSTREAM, val);
+ mNotifyClient(kEventEndOfStream, val, mNotifyUser);
}
- if (msg->findInt32(EVENT_ENDOFSTREAM, &cacheInfo)) {
- SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_ENDOFSTREAM, cacheInfo);
- mNotifyClient(kEventEndOfStream, cacheInfo, mNotifyUser);
+
+ if (msg->findInt32(EVENT_PREPARED, &val)) {
+ SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREPARED, val);
+ mNotifyClient(kEventPrepared, val, mNotifyUser);
}
}
diff --git a/opensles/libopensles/android_SfPlayer.h b/opensles/libopensles/android_SfPlayer.h
index 9fcd2bd7..15467b50 100644
--- a/opensles/libopensles/android_SfPlayer.h
+++ b/opensles/libopensles/android_SfPlayer.h
@@ -40,6 +40,10 @@
#define SIZE_CACHED_MED_BYTES 700000
#define SIZE_CACHED_LOW_BYTES 400000
+/*
+ * events sent to mNotifyClient during prepare, prefetch, and playback
+ */
+#define EVENT_PREPARED "prep"
#define EVENT_PREFETCHSTATUSCHANGE "prsc"
#define EVENT_PREFETCHFILLLEVELUPDATE "pflu"
#define EVENT_ENDOFSTREAM "eos"
@@ -50,12 +54,21 @@
#define NO_FILL_LEVEL_UPDATE -1
#define NO_STATUS_UPDATE kStatusUnknown
+
+typedef struct AudioPlayback_Parameters_struct {
+ int streamType;
+ int sessionId;
+ android::AudioTrack::callback_t trackcb;
+ void* trackcbUser;
+} AudioPlayback_Parameters;
+
+
namespace android {
typedef void (*notif_client_t)(int event, const int data1, void* notifUser);
struct SfPlayer : public AHandler {
- SfPlayer();
+ SfPlayer(AudioPlayback_Parameters *app);
enum CacheStatus {
kStatusUnknown = -1,
@@ -67,6 +80,7 @@ struct SfPlayer : public AHandler {
};
enum {
+ kEventPrepared = 'prep',
kEventPrefetchStatusChange = 'prsc',
kEventPrefetchFillLevelUpdate = 'pflu',
kEventEndOfStream = 'eos',
@@ -81,8 +95,7 @@ struct SfPlayer : public AHandler {
void setCacheFillUpdateThreshold(int16_t thr) { mCacheFillNotifThreshold = thr; }
- void prepare_async();
- int prepare_sync();
+ void prepare();
void play();
void pause();
void stop();
@@ -97,6 +110,7 @@ struct SfPlayer : public AHandler {
int64_t getDurationUsec() { return mDurationUsec; }
int32_t getNumChannels() { return mNumChannels; }
int32_t getSampleRateHz() { return mSampleRateHz; }
+ AudioTrack* getAudioTrack() { return mAudioTrack; }
uint32_t getPositionMsec();
protected:
@@ -162,6 +176,7 @@ private:
int16_t mCacheFill; // cache fill level in permille
int16_t mLastNotifiedCacheFill; // last cache fill level communicated to the listener
int16_t mCacheFillNotifThreshold; // threshold in cache fill level for cache fill to be reported
+ AudioPlayback_Parameters mPlaybackParams;
DataLocator mDataLocator;
int mDataLocatorType;
@@ -175,7 +190,7 @@ private:
MediaBuffer *mDecodeBuffer;
// message handlers
- int onPrepare(const sp<AMessage> &msg);
+ void onPrepare(const sp<AMessage> &msg);
void onDecode();
void onRender(const sp<AMessage> &msg);
void onCheckCache(const sp<AMessage> &msg);
@@ -190,6 +205,7 @@ private:
void reachedEndOfStream();
void notifyStatus();
void notifyCacheFill();
+ void notifyPrepared(status_t prepareRes);
void notify(const sp<AMessage> &msg, bool async);
void resetDataLocator();
diff --git a/opensles/libopensles/android_prompts.h b/opensles/libopensles/android_prompts.h
index 2e11952f..8dbbd957 100644
--- a/opensles/libopensles/android_prompts.h
+++ b/opensles/libopensles/android_prompts.h
@@ -22,6 +22,8 @@
"Cannot set stream type: unknown or invalid stream type"
#define ERROR_PLAYERSTREAMTYPE_REALIZED \
"Cannot set stream type: audio player already realized"
+#define ERROR_PLAYERREALIZE_UNKNOWN_DATASOURCE_LOCATOR \
+ "Cannot realize AudioPlayer: with unknown data source locator"
//-----------------------------------------------------------------------------
// Android AudioRecorder errors
diff --git a/opensles/libopensles/sles_allinclusive.h b/opensles/libopensles/sles_allinclusive.h
index 8d960e59..63f13216 100644
--- a/opensles/libopensles/sles_allinclusive.h
+++ b/opensles/libopensles/sles_allinclusive.h
@@ -902,8 +902,6 @@ enum AndroidObject_type {
enum AndroidObject_state {
ANDROID_UNINITIALIZED = -1,
ANDROID_PREPARING,
- ANDROID_PREPARED,
- ANDROID_PREFETCHING,
ANDROID_READY,
NUM_ANDROID_STATES
};
diff --git a/opensles/tests/mimeUri/Android.mk b/opensles/tests/mimeUri/Android.mk
index a157b484..f7c6240d 100644
--- a/opensles/tests/mimeUri/Android.mk
+++ b/opensles/tests/mimeUri/Android.mk
@@ -70,6 +70,7 @@ endif
LOCAL_MODULE:= slesTest_playUri
+include $(BUILD_EXECUTABLE)
# slesTest_loopUri
@@ -93,7 +94,6 @@ endif
LOCAL_MODULE:= slesTest_loopUri
-
include $(BUILD_EXECUTABLE)
# slesTest_playUri2