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

Commit 55e2f4ca authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Make NuPlayer send global timed text info too

For feature parity with AwesomePlayer. Also add a small hack to
AwesomePlayer to make timed text track selection work again, so
the timed text CTS test can run with both AwesomePlayer and NuPlayer

Change-Id: I1be451c4b3191cae65bc46b3b721a1924b4fadc8
parent cc75adb4
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -748,6 +748,11 @@ void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
          break;
      }

      case kWhatSendGlobalTimedTextData:
      {
          sendGlobalTextData(kWhatTimedTextData, mFetchTimedTextDataGeneration, msg);
          break;
      }
      case kWhatSendTimedTextData:
      {
          sendTextData(kWhatTimedTextData, MEDIA_TRACK_TYPE_TIMEDTEXT,
@@ -942,6 +947,37 @@ void NuPlayer::GenericSource::sendTextData(
    }
}

void NuPlayer::GenericSource::sendGlobalTextData(
        uint32_t what,
        int32_t curGen,
        sp<AMessage> msg) {
    int32_t msgGeneration;
    CHECK(msg->findInt32("generation", &msgGeneration));
    if (msgGeneration != curGen) {
        // stale
        return;
    }

    uint32_t textType;
    const void *data;
    size_t size = 0;
    if (mTimedTextTrack.mSource->getFormat()->findData(
                    kKeyTextFormatData, &textType, &data, &size)) {
        mGlobalTimedText = new ABuffer(size);
        if (mGlobalTimedText->data()) {
            memcpy(mGlobalTimedText->data(), data, size);
            sp<AMessage> globalMeta = mGlobalTimedText->meta();
            globalMeta->setInt64("timeUs", 0);
            globalMeta->setString("mime", MEDIA_MIMETYPE_TEXT_3GPP);
            globalMeta->setInt32("global", 1);
            sp<AMessage> notify = dupNotify();
            notify->setInt32("what", what);
            notify->setBuffer("buffer", mGlobalTimedText);
            notify->post();
        }
    }
}

sp<MetaData> NuPlayer::GenericSource::getFormatMeta(bool audio) {
    sp<AMessage> msg = new AMessage(kWhatGetFormat, this);
    msg->setInt32("audio", audio);
@@ -1254,6 +1290,10 @@ status_t NuPlayer::GenericSource::doSelectTrack(size_t trackIndex, bool select,
            msg->post();
        }

        sp<AMessage> msg2 = new AMessage(kWhatSendGlobalTimedTextData, this);
        msg2->setInt32("generation", mFetchTimedTextDataGeneration);
        msg2->post();

        if (mTimedTextTrack.mSource != NULL
                && !mTimedTextTrack.mPackets->hasBufferAvailable(&eosResult)) {
            sp<AMessage> msg = new AMessage(kWhatFetchTimedTextData, this);
+6 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ private:
        kWhatFetchSubtitleData,
        kWhatFetchTimedTextData,
        kWhatSendSubtitleData,
        kWhatSendGlobalTimedTextData,
        kWhatSendTimedTextData,
        kWhatChangeAVSource,
        kWhatPollBuffering,
@@ -151,6 +152,7 @@ private:
    bool mBuffering;
    bool mPrepareBuffering;
    int32_t mPrevBufferPercentage;
    sp<ABuffer> mGlobalTimedText;

    mutable Mutex mReadBufferLock;

@@ -186,6 +188,10 @@ private:
            uint32_t what, media_track_type type,
            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);

    void sendGlobalTextData(
            uint32_t what,
            int32_t curGen, sp<AMessage> msg);

    void sendTextData(
            uint32_t what, media_track_type type,
            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
+7 −2
Original line number Diff line number Diff line
@@ -2290,7 +2290,7 @@ void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
    const void *data;
    size_t size = 0;
    int64_t timeUs;
    int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS;
    int32_t flag = TextDescriptions::IN_BAND_TEXT_3GPP;

    AString mime;
    CHECK(buffer->meta()->findString("mime", &mime));
@@ -2302,7 +2302,12 @@ void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) {
    Parcel parcel;
    if (size > 0) {
        CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
        flag |= TextDescriptions::IN_BAND_TEXT_3GPP;
        int32_t global = 0;
        if (buffer->meta()->findInt32("global", &global) && global) {
            flag |= TextDescriptions::GLOBAL_DESCRIPTIONS;
        } else {
            flag |= TextDescriptions::LOCAL_DESCRIPTIONS;
        }
        TextDescriptions::getParcelOfDescriptions(
                (const uint8_t *)data, size, flag, timeUs / 1000, &parcel);
    }
+13 −0
Original line number Diff line number Diff line
@@ -215,6 +215,7 @@ AwesomePlayer::AwesomePlayer()
      mDecryptHandle(NULL),
      mLastVideoTimeUs(-1),
      mTextDriver(NULL),
      mSelectedTimedTextTrack(-1),
      mOffloadAudio(false),
      mAudioTearDown(false) {
    CHECK_EQ(mClient.connect(), (status_t)OK);
@@ -2679,6 +2680,7 @@ status_t AwesomePlayer::getTrackInfo(Parcel *reply) const {
        } else {
            reply->writeInt32(MEDIA_TRACK_TYPE_UNKNOWN);
        }
        reply->writeString16(String16(mime));

        const char *lang;
        if (!meta->findCString(kKeyMediaLanguage, &lang)) {
@@ -2813,12 +2815,14 @@ status_t AwesomePlayer::selectTrack(size_t trackIndex, bool select) {
                mTextDriver->start();
                modifyFlags(TEXT_RUNNING, SET);
            }
            mSelectedTimedTextTrack = trackIndex;
        }
    } else {
        err = mTextDriver->unselectTrack(trackIndex);
        if (err == OK) {
            modifyFlags(TEXTPLAYER_INITIALIZED, CLEAR);
            modifyFlags(TEXT_RUNNING, CLEAR);
            mSelectedTimedTextTrack = -1;
        }
    }
    return err;
@@ -2903,6 +2907,15 @@ status_t AwesomePlayer::invoke(const Parcel &request, Parcel *reply) {
            int trackIndex = request.readInt32();
            return selectTrack(trackIndex, false /* select */);
        }
        case INVOKE_ID_GET_SELECTED_TRACK:
        {
            int trackType = request.readInt32();
            if (trackType == MEDIA_TRACK_TYPE_TIMEDTEXT) {
                reply->writeInt32(mSelectedTimedTextTrack);
                return mSelectedTimedTextTrack;
            }

        }
        default:
        {
            return ERROR_UNSUPPORTED;
+1 −0
Original line number Diff line number Diff line
@@ -250,6 +250,7 @@ private:

    int64_t mLastVideoTimeUs;
    TimedTextDriver *mTextDriver;
    int32_t mSelectedTimedTextTrack;

    sp<WVMExtractor> mWVMExtractor;
    sp<MediaExtractor> mExtractor;