Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44945f04 authored by Chong Zhang's avatar Chong Zhang Committed by Android Git Automerger
Browse files

am 43febe72: Merge "add buffering update to GenericSource" into lmp-dev

* commit '43febe72':
  add buffering update to GenericSource
parents c3c107ca 43febe72
Loading
Loading
Loading
Loading
+92 −6
Original line number Original line Diff line number Diff line
@@ -49,7 +49,9 @@ NuPlayer::GenericSource::GenericSource(
      mIsWidevine(false),
      mIsWidevine(false),
      mUIDValid(uidValid),
      mUIDValid(uidValid),
      mUID(uid),
      mUID(uid),
      mMetaDataSize(-1ll) {
      mMetaDataSize(-1ll),
      mBitrate(-1ll),
      mPollBufferingGeneration(0) {
    resetDataSource();
    resetDataSource();
    DataSource::RegisterDefaultSniffers();
    DataSource::RegisterDefaultSniffers();
}
}
@@ -113,12 +115,12 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
            return UNKNOWN_ERROR;
            return UNKNOWN_ERROR;
        }
        }


        sp<WVMExtractor> wvmExtractor = new WVMExtractor(mDataSource);
        mWVMExtractor = new WVMExtractor(mDataSource);
        wvmExtractor->setAdaptiveStreamingMode(true);
        mWVMExtractor->setAdaptiveStreamingMode(true);
        if (mUIDValid) {
        if (mUIDValid) {
            wvmExtractor->setUID(mUID);
            mWVMExtractor->setUID(mUID);
        }
        }
        extractor = wvmExtractor;
        extractor = mWVMExtractor;
    } else {
    } else {
        extractor = MediaExtractor::Create(mDataSource,
        extractor = MediaExtractor::Create(mDataSource,
                mSniffedMIME.empty() ? NULL: mSniffedMIME.c_str());
                mSniffedMIME.empty() ? NULL: mSniffedMIME.c_str());
@@ -136,6 +138,8 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
        }
        }
    }
    }


    int32_t totalBitrate = 0;

    for (size_t i = 0; i < extractor->countTracks(); ++i) {
    for (size_t i = 0; i < extractor->countTracks(); ++i) {
        sp<MetaData> meta = extractor->getTrackMetaData(i);
        sp<MetaData> meta = extractor->getTrackMetaData(i);


@@ -180,8 +184,17 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
                    mDurationUs = durationUs;
                    mDurationUs = durationUs;
                }
                }
            }
            }

            int32_t bitrate;
            if (totalBitrate >= 0 && meta->findInt32(kKeyBitRate, &bitrate)) {
                totalBitrate += bitrate;
            } else {
                totalBitrate = -1;
            }
            }
        }
        }
    }

    mBitrate = totalBitrate;


    return OK;
    return OK;
}
}
@@ -239,6 +252,10 @@ void NuPlayer::GenericSource::onPrepareAsync() {
        if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
        if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
            mCachedSource = static_cast<NuCachedSource2 *>(mDataSource.get());
            mCachedSource = static_cast<NuCachedSource2 *>(mDataSource.get());
        }
        }

        if (mIsWidevine || mCachedSource != NULL) {
            schedulePollBuffering();
        }
    }
    }


    // check initial caching status
    // check initial caching status
@@ -283,6 +300,8 @@ void NuPlayer::GenericSource::notifyPreparedAndCleanup(status_t err) {
        mSniffedMIME = "";
        mSniffedMIME = "";
        mDataSource.clear();
        mDataSource.clear();
        mCachedSource.clear();
        mCachedSource.clear();

        cancelPollBuffering();
    }
    }
    notifyPrepared(err);
    notifyPrepared(err);
}
}
@@ -381,6 +400,65 @@ status_t NuPlayer::GenericSource::feedMoreTSData() {
    return OK;
    return OK;
}
}


void NuPlayer::GenericSource::schedulePollBuffering() {
    sp<AMessage> msg = new AMessage(kWhatPollBuffering, id());
    msg->setInt32("generation", mPollBufferingGeneration);
    msg->post(1000000ll);
}

void NuPlayer::GenericSource::cancelPollBuffering() {
    ++mPollBufferingGeneration;
}

void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage) {
    sp<AMessage> msg = dupNotify();
    msg->setInt32("what", kWhatBufferingUpdate);
    msg->setInt32("percentage", percentage);
    msg->post();
}

void NuPlayer::GenericSource::onPollBuffering() {
    status_t finalStatus = UNKNOWN_ERROR;
    int64_t cachedDurationUs = 0ll;

    if (mCachedSource != NULL) {
        size_t cachedDataRemaining =
                mCachedSource->approxDataRemaining(&finalStatus);

        if (finalStatus == OK) {
            off64_t size;
            int64_t bitrate = 0ll;
            if (mDurationUs > 0 && mCachedSource->getSize(&size) == OK) {
                bitrate = size * 8000000ll / mDurationUs;
            } else if (mBitrate > 0) {
                bitrate = mBitrate;
            }
            if (bitrate > 0) {
                cachedDurationUs = cachedDataRemaining * 8000000ll / bitrate;
            }
        }
    } else if (mWVMExtractor != NULL) {
        cachedDurationUs
            = mWVMExtractor->getCachedDurationUs(&finalStatus);
    }

    if (finalStatus == ERROR_END_OF_STREAM) {
        notifyBufferingUpdate(100);
        cancelPollBuffering();
        return;
    } else if (cachedDurationUs > 0ll && mDurationUs > 0ll) {
        int percentage = 100.0 * cachedDurationUs / mDurationUs;
        if (percentage > 100) {
            percentage = 100;
        }

        notifyBufferingUpdate(percentage);
    }

    schedulePollBuffering();
}


void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
    switch (msg->what()) {
      case kWhatPrepareAsync:
      case kWhatPrepareAsync:
@@ -463,7 +541,15 @@ void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {


          break;
          break;
      }
      }

      case kWhatPollBuffering:
      {
          int32_t generation;
          CHECK(msg->findInt32("generation", &generation));
          if (generation == mPollBufferingGeneration) {
              onPollBuffering();
          }
          break;
      }
      default:
      default:
          Source::onMessageReceived(msg);
          Source::onMessageReceived(msg);
          break;
          break;
+10 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ struct IMediaHTTPService;
struct MediaSource;
struct MediaSource;
class MediaBuffer;
class MediaBuffer;
struct NuCachedSource2;
struct NuCachedSource2;
struct WVMExtractor;


struct NuPlayer::GenericSource : public NuPlayer::Source {
struct NuPlayer::GenericSource : public NuPlayer::Source {
    GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
    GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
@@ -77,6 +78,7 @@ private:
        kWhatSendSubtitleData,
        kWhatSendSubtitleData,
        kWhatSendTimedTextData,
        kWhatSendTimedTextData,
        kWhatChangeAVSource,
        kWhatChangeAVSource,
        kWhatPollBuffering,
    };
    };


    Vector<sp<MediaSource> > mSources;
    Vector<sp<MediaSource> > mSources;
@@ -108,9 +110,12 @@ private:


    sp<DataSource> mDataSource;
    sp<DataSource> mDataSource;
    sp<NuCachedSource2> mCachedSource;
    sp<NuCachedSource2> mCachedSource;
    sp<WVMExtractor> mWVMExtractor;
    String8 mContentType;
    String8 mContentType;
    AString mSniffedMIME;
    AString mSniffedMIME;
    off64_t mMetaDataSize;
    off64_t mMetaDataSize;
    int64_t mBitrate;
    int32_t mPollBufferingGeneration;


    sp<ALooper> mLooper;
    sp<ALooper> mLooper;


@@ -141,6 +146,11 @@ private:
            media_track_type trackType,
            media_track_type trackType,
            int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);
            int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);


    void schedulePollBuffering();
    void cancelPollBuffering();
    void onPollBuffering();
    void notifyBufferingUpdate(int percentage);

    DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
    DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
};
};


+9 −0
Original line number Original line Diff line number Diff line
@@ -1797,6 +1797,15 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
            break;
            break;
        }
        }


        case Source::kWhatBufferingUpdate:
        {
            int32_t percentage;
            CHECK(msg->findInt32("percentage", &percentage));

            notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
            break;
        }

        case Source::kWhatBufferingStart:
        case Source::kWhatBufferingStart:
        {
        {
            notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
            notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
+1 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ struct NuPlayer::Source : public AHandler {
        kWhatPrepared,
        kWhatPrepared,
        kWhatFlagsChanged,
        kWhatFlagsChanged,
        kWhatVideoSizeChanged,
        kWhatVideoSizeChanged,
        kWhatBufferingUpdate,
        kWhatBufferingStart,
        kWhatBufferingStart,
        kWhatBufferingEnd,
        kWhatBufferingEnd,
        kWhatSubtitleData,
        kWhatSubtitleData,