OSDN Git Service

Signal an appropriate error even if there are no active streams yet.
authorAndreas Huber <andih@google.com>
Tue, 27 Sep 2011 19:12:25 +0000 (12:12 -0700)
committerAndreas Huber <andih@google.com>
Tue, 27 Sep 2011 19:13:37 +0000 (12:13 -0700)
Change-Id: I3ac1053ad288558b62ee18056dfd0a9ce0da8f49
related-to-bug: 5372901

media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
media/libmediaplayerservice/nuplayer/NuPlayer.cpp
media/libmediaplayerservice/nuplayer/NuPlayerSource.h
media/libmediaplayerservice/nuplayer/StreamingSource.cpp
media/libmediaplayerservice/nuplayer/StreamingSource.h

index fb14204..079f6fa 100644 (file)
@@ -41,7 +41,7 @@ NuPlayer::HTTPLiveSource::HTTPLiveSource(
       mUIDValid(uidValid),
       mUID(uid),
       mFlags(0),
-      mEOS(false),
+      mFinalResult(OK),
       mOffset(0) {
     if (headers) {
         mExtraHeaders = *headers;
@@ -95,9 +95,9 @@ sp<MetaData> NuPlayer::HTTPLiveSource::getFormat(bool audio) {
     return source->getFormat();
 }
 
-bool NuPlayer::HTTPLiveSource::feedMoreTSData() {
-    if (mEOS) {
-        return false;
+status_t NuPlayer::HTTPLiveSource::feedMoreTSData() {
+    if (mFinalResult != OK) {
+        return mFinalResult;
     }
 
     sp<LiveDataSource> source =
@@ -111,12 +111,12 @@ bool NuPlayer::HTTPLiveSource::feedMoreTSData() {
             break;
         } else if (n < 0) {
             if (n != ERROR_END_OF_STREAM) {
-                LOGI("input data EOS reached, error %d", n);
+                LOGI("input data EOS reached, error %ld", n);
             } else {
                 LOGI("input data EOS reached.");
             }
             mTSParser->signalEOS(n);
-            mEOS = true;
+            mFinalResult = n;
             break;
         } else {
             if (buffer[0] == 0x00) {
@@ -133,7 +133,7 @@ bool NuPlayer::HTTPLiveSource::feedMoreTSData() {
                 if (err != OK) {
                     LOGE("TS Parser returned error %d", err);
                     mTSParser->signalEOS(err);
-                    mEOS = true;
+                    mFinalResult = err;
                     break;
                 }
             }
@@ -142,7 +142,7 @@ bool NuPlayer::HTTPLiveSource::feedMoreTSData() {
         }
     }
 
-    return true;
+    return OK;
 }
 
 status_t NuPlayer::HTTPLiveSource::dequeueAccessUnit(
@@ -172,7 +172,7 @@ status_t NuPlayer::HTTPLiveSource::getDuration(int64_t *durationUs) {
 status_t NuPlayer::HTTPLiveSource::seekTo(int64_t seekTimeUs) {
     // We need to make sure we're not seeking until we have seen the very first
     // PTS timestamp in the whole stream (from the beginning of the stream).
-    while (!mTSParser->PTSTimeDeltaEstablished() && feedMoreTSData()) {
+    while (!mTSParser->PTSTimeDeltaEstablished() && feedMoreTSData() == OK) {
         usleep(100000);
     }
 
index 36c67c5..f22af5b 100644 (file)
@@ -35,8 +35,7 @@ struct NuPlayer::HTTPLiveSource : public NuPlayer::Source {
 
     virtual void start();
 
-    // Returns true iff more data was available, false on EOS.
-    virtual bool feedMoreTSData();
+    virtual status_t feedMoreTSData();
 
     virtual sp<MetaData> getFormat(bool audio);
     virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
@@ -59,7 +58,7 @@ private:
     bool mUIDValid;
     uid_t mUID;
     uint32_t mFlags;
-    bool mEOS;
+    status_t mFinalResult;
     off64_t mOffset;
     sp<ALooper> mLiveLooper;
     sp<LiveSession> mLiveSession;
index 7bfd358..6b40528 100644 (file)
@@ -235,11 +235,17 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                 instantiateDecoder(true, &mAudioDecoder);
             }
 
-            if (!mSource->feedMoreTSData()) {
+            status_t err;
+            if ((err = mSource->feedMoreTSData()) != OK) {
                 if (mAudioDecoder == NULL && mVideoDecoder == NULL) {
                     // We're not currently decoding anything (no audio or
                     // video tracks found) and we just ran out of input data.
-                    notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
+
+                    if (err == ERROR_END_OF_STREAM) {
+                        notifyListener(MEDIA_PLAYBACK_COMPLETE, 0, 0);
+                    } else {
+                        notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);
+                    }
                 }
                 break;
             }
@@ -267,7 +273,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                         audio, codecRequest);
 
                 if (err == -EWOULDBLOCK) {
-                    if (mSource->feedMoreTSData()) {
+                    if (mSource->feedMoreTSData() == OK) {
                         msg->post();
                     }
                 }
index 5e55487..8a7eece 100644 (file)
@@ -29,8 +29,9 @@ struct NuPlayer::Source : public RefBase {
 
     virtual void start() = 0;
 
-    // Returns true iff more data was available, false on EOS.
-    virtual bool feedMoreTSData() = 0;
+    // Returns OK iff more data was available,
+    // an error or ERROR_END_OF_STREAM if not.
+    virtual status_t feedMoreTSData() = 0;
 
     virtual sp<MetaData> getFormat(bool audio) = 0;
 
index 7319e4c..f795654 100644 (file)
@@ -34,7 +34,7 @@ namespace android {
 
 NuPlayer::StreamingSource::StreamingSource(const sp<IStreamSource> &source)
     : mSource(source),
-      mEOS(false) {
+      mFinalResult(OK) {
 }
 
 NuPlayer::StreamingSource::~StreamingSource() {
@@ -47,9 +47,9 @@ void NuPlayer::StreamingSource::start() {
     mStreamListener->start();
 }
 
-bool NuPlayer::StreamingSource::feedMoreTSData() {
-    if (mEOS) {
-        return false;
+status_t NuPlayer::StreamingSource::feedMoreTSData() {
+    if (mFinalResult != OK) {
+        return mFinalResult;
     }
 
     for (int32_t i = 0; i < 50; ++i) {
@@ -60,7 +60,7 @@ bool NuPlayer::StreamingSource::feedMoreTSData() {
         if (n == 0) {
             LOGI("input data EOS reached.");
             mTSParser->signalEOS(ERROR_END_OF_STREAM);
-            mEOS = true;
+            mFinalResult = ERROR_END_OF_STREAM;
             break;
         } else if (n == INFO_DISCONTINUITY) {
             ATSParser::DiscontinuityType type = ATSParser::DISCONTINUITY_SEEK;
@@ -92,14 +92,14 @@ bool NuPlayer::StreamingSource::feedMoreTSData() {
                     LOGE("TS Parser returned error %d", err);
 
                     mTSParser->signalEOS(err);
-                    mEOS = true;
+                    mFinalResult = err;
                     break;
                 }
             }
         }
     }
 
-    return true;
+    return OK;
 }
 
 sp<MetaData> NuPlayer::StreamingSource::getFormat(bool audio) {
index 7abce84..ca00ef9 100644 (file)
@@ -31,8 +31,7 @@ struct NuPlayer::StreamingSource : public NuPlayer::Source {
 
     virtual void start();
 
-    // Returns true iff more data was available, false on EOS.
-    virtual bool feedMoreTSData();
+    virtual status_t feedMoreTSData();
 
     virtual sp<MetaData> getFormat(bool audio);
     virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit);
@@ -42,7 +41,7 @@ protected:
 
 private:
     sp<IStreamSource> mSource;
-    bool mEOS;
+    status_t mFinalResult;
     sp<NuPlayerStreamListener> mStreamListener;
     sp<ATSParser> mTSParser;