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

Commit ad07410c authored by Chong Zhang's avatar Chong Zhang Committed by The Android Automerger
Browse files

use dedicated looper for GenericSource

- handle setVideoSurface in deferred action, and return
  to client immediately

- handle GenericSource's prepareAsync on its own looper,
  instead of sharing looper with NuPlayer

- let HTTPLiveSource share looper with LiveSession, instead
  of NuPlayer

- remove reflector in RTSPSource

Bug: 16892748
Change-Id: I1aed557320052012065f5a90adbcb03c238da988
parent a8a20985
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -192,9 +192,26 @@ status_t NuPlayer::GenericSource::setBuffers(
}

NuPlayer::GenericSource::~GenericSource() {
    if (mLooper != NULL) {
        mLooper->unregisterHandler(id());
        mLooper->stop();
    }
}

void NuPlayer::GenericSource::prepareAsync() {
    if (mLooper == NULL) {
        mLooper = new ALooper;
        mLooper->setName("generic");
        mLooper->start();

        mLooper->registerHandler(this);
    }

    sp<AMessage> msg = new AMessage(kWhatPrepareAsync, id());
    msg->post();
}

void NuPlayer::GenericSource::onPrepareAsync() {
    // delayed data source creation
    AString sniffedMIME;
    sp<DataSource> dataSource;
@@ -267,6 +284,11 @@ status_t NuPlayer::GenericSource::feedMoreTSData() {

void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
      case kWhatPrepareAsync:
      {
          onPrepareAsync();
          break;
      }
      case kWhatFetchSubtitleData:
      {
          fetchTextData(kWhatSendSubtitleData, MEDIA_TRACK_TYPE_SUBTITLE,
+6 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ protected:

private:
    enum {
        kWhatPrepareAsync,
        kWhatFetchSubtitleData,
        kWhatFetchTimedTextData,
        kWhatSendSubtitleData,
@@ -104,12 +105,17 @@ private:
    int64_t mOffset;
    int64_t mLength;

    sp<ALooper> mLooper;


    void resetDataSource();

    status_t initFromDataSource(
            const sp<DataSource> &dataSource,
            const char *mime);

    void onPrepareAsync();

    void fetchTextData(
            uint32_t what, media_track_type type,
            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
+11 −4
Original line number Diff line number Diff line
@@ -62,18 +62,25 @@ NuPlayer::HTTPLiveSource::HTTPLiveSource(
NuPlayer::HTTPLiveSource::~HTTPLiveSource() {
    if (mLiveSession != NULL) {
        mLiveSession->disconnect();
        mLiveSession.clear();

        mLiveLooper->unregisterHandler(mLiveSession->id());
        mLiveLooper->unregisterHandler(id());
        mLiveLooper->stop();

        mLiveSession.clear();
        mLiveLooper.clear();
    }
}

void NuPlayer::HTTPLiveSource::prepareAsync() {
    if (mLiveLooper == NULL) {
        mLiveLooper = new ALooper;
        mLiveLooper->setName("http live");
        mLiveLooper->start();

        mLiveLooper->registerHandler(this);
    }

    sp<AMessage> notify = new AMessage(kWhatSessionNotify, id());

    mLiveSession = new LiveSession(
+0 −10
Original line number Diff line number Diff line
@@ -372,7 +372,6 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            CHECK(msg->findObject("source", &obj));
            if (obj != NULL) {
                mSource = static_cast<Source *>(obj.get());
                looper()->registerHandler(mSource);
            } else {
                err = UNKNOWN_ERROR;
            }
@@ -1688,8 +1687,6 @@ void NuPlayer::performReset() {
    if (mSource != NULL) {
        mSource->stop();

        looper()->unregisterHandler(mSource->id());

        mSource.clear();
    }

@@ -1722,13 +1719,6 @@ void NuPlayer::performSetSurface(const sp<NativeWindowWrapper> &wrapper) {

    // XXX - ignore error from setVideoScalingMode for now
    setVideoScalingMode(mVideoScalingMode);

    if (mDriver != NULL) {
        sp<NuPlayerDriver> driver = mDriver.promote();
        if (driver != NULL) {
            driver->notifySetSurfaceComplete();
        }
    }
}

void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
+0 −20
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ NuPlayerDriver::NuPlayerDriver()
    : mState(STATE_IDLE),
      mIsAsyncPrepare(false),
      mAsyncResult(UNKNOWN_ERROR),
      mSetSurfaceInProgress(false),
      mDurationUs(-1),
      mPositionUs(-1),
      mNumFramesTotal(0),
@@ -135,10 +134,6 @@ status_t NuPlayerDriver::setVideoSurfaceTexture(
        const sp<IGraphicBufferProducer> &bufferProducer) {
    Mutex::Autolock autoLock(mLock);

    if (mSetSurfaceInProgress) {
        return INVALID_OPERATION;
    }

    switch (mState) {
        case STATE_SET_DATASOURCE_PENDING:
        case STATE_RESET_IN_PROGRESS:
@@ -148,14 +143,8 @@ status_t NuPlayerDriver::setVideoSurfaceTexture(
            break;
    }

    mSetSurfaceInProgress = true;

    mPlayer->setVideoSurfaceTextureAsync(bufferProducer);

    while (mSetSurfaceInProgress) {
        mCondition.wait(mLock);
    }

    return OK;
}

@@ -483,15 +472,6 @@ void NuPlayerDriver::notifyResetComplete() {
    mCondition.broadcast();
}

void NuPlayerDriver::notifySetSurfaceComplete() {
    Mutex::Autolock autoLock(mLock);

    CHECK(mSetSurfaceInProgress);
    mSetSurfaceInProgress = false;

    mCondition.broadcast();
}

void NuPlayerDriver::notifyDuration(int64_t durationUs) {
    Mutex::Autolock autoLock(mLock);
    mDurationUs = durationUs;
Loading