Don't re-scan sources if no new ones will appear
The only scenario we might need to re-scan is when switching between
bitrate variants in HTTPLiveSources.
Bug: 23313819
Change-Id: I892033c8698f985de74801c39ac5b5417ed19e89
diff --git a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
index 126625a..3fffdc1a 100644
--- a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
@@ -101,15 +101,20 @@
}
sp<AMessage> NuPlayer::HTTPLiveSource::getFormat(bool audio) {
- if (mLiveSession == NULL) {
- return NULL;
+ sp<AMessage> format;
+ status_t err = -EWOULDBLOCK;
+ if (mLiveSession != NULL) {
+ err = mLiveSession->getStreamFormat(
+ audio ? LiveSession::STREAMTYPE_AUDIO
+ : LiveSession::STREAMTYPE_VIDEO,
+ &format);
}
- sp<AMessage> format;
- status_t err = mLiveSession->getStreamFormat(
- audio ? LiveSession::STREAMTYPE_AUDIO
- : LiveSession::STREAMTYPE_VIDEO,
- &format);
+ if (err == -EWOULDBLOCK) {
+ format = new AMessage();
+ format->setInt32("err", err);
+ return format;
+ }
if (err != OK) {
return NULL;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index aabe989..3420cc9 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -845,16 +845,21 @@
bool mHadAnySourcesBefore =
(mAudioDecoder != NULL) || (mVideoDecoder != NULL);
+ bool rescan = false;
// initialize video before audio because successful initialization of
// video may change deep buffer mode of audio.
if (mSurface != NULL) {
- instantiateDecoder(false, &mVideoDecoder);
+ if (instantiateDecoder(false, &mVideoDecoder) == -EWOULDBLOCK) {
+ rescan = true;
+ }
}
// Don't try to re-open audio sink if there's an existing decoder.
if (mAudioSink != NULL && mAudioDecoder == NULL) {
- instantiateDecoder(true, &mAudioDecoder);
+ if (instantiateDecoder(true, &mAudioDecoder) == -EWOULDBLOCK) {
+ rescan = true;
+ }
}
if (!mHadAnySourcesBefore
@@ -881,8 +886,7 @@
break;
}
- if ((mAudioDecoder == NULL && mAudioSink != NULL)
- || (mVideoDecoder == NULL && mSurface != NULL)) {
+ if (rescan) {
msg->post(100000ll);
mScanSourcesPending = true;
}
@@ -1519,7 +1523,12 @@
sp<AMessage> format = mSource->getFormat(audio);
if (format == NULL) {
- return -EWOULDBLOCK;
+ return UNKNOWN_ERROR;
+ } else {
+ status_t err;
+ if (format->findInt32("err", &err) && err) {
+ return err;
+ }
}
format->setInt32("priority", 0 /* realtime */);
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp
index 1557401..cebf95c 100644
--- a/media/libstagefright/httplive/LiveSession.cpp
+++ b/media/libstagefright/httplive/LiveSession.cpp
@@ -477,7 +477,7 @@
sp<MetaData> meta = packetSource->getFormat();
if (meta == NULL) {
- return -EAGAIN;
+ return -EWOULDBLOCK;
}
if (stream == STREAMTYPE_AUDIO) {