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

Commit bae00e73 authored by Insun Kang's avatar Insun Kang
Browse files

Handling end times of subtitles.

Change-Id: Ic19ec8980d0a2bf9f265d375cd56e638a2460af8
parent 1bb8e81b
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -39,19 +39,21 @@ TimedText3GPPSource::~TimedText3GPPSource() {
}

status_t TimedText3GPPSource::read(
        int64_t *timeUs, Parcel *parcel, const MediaSource::ReadOptions *options) {
        int64_t *startTimeUs, int64_t *endTimeUs, Parcel *parcel,
        const MediaSource::ReadOptions *options) {
    MediaBuffer *textBuffer = NULL;
    status_t err = mSource->read(&textBuffer, options);
    if (err != OK) {
        return err;
    }
    CHECK(textBuffer != NULL);
    textBuffer->meta_data()->findInt64(kKeyTime, timeUs);
    // TODO: this is legacy code. when 'timeUs' can be <= 0?
    if (*timeUs > 0) {
        extractAndAppendLocalDescriptions(*timeUs, textBuffer, parcel);
    }
    textBuffer->meta_data()->findInt64(kKeyTime, startTimeUs);
    CHECK_GE(*startTimeUs, 0);
    extractAndAppendLocalDescriptions(*startTimeUs, textBuffer, parcel);
    textBuffer->release();
    // endTimeUs is a dummy parameter for 3gpp timed text format.
    // Set a negative value to it to mark it is unavailable.
    *endTimeUs = -1;
    return OK;
}

+2 −1
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ public:
    virtual status_t start() { return mSource->start(); }
    virtual status_t stop() { return mSource->stop(); }
    virtual status_t read(
            int64_t *timeUs,
            int64_t *startTimeUs,
            int64_t *endTimeUs,
            Parcel *parcel,
            const MediaSource::ReadOptions *options = NULL);
    virtual status_t extractGlobalDescriptions(Parcel *parcel);
+25 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
namespace android {

static const int64_t kAdjustmentProcessingTimeUs = 100000ll;
static const int64_t kWaitTimeUsToRetryRead = 100000ll;

TimedTextPlayer::TimedTextPlayer(const wp<MediaPlayerBase> &listener)
    : mListener(listener),
@@ -139,13 +140,25 @@ void TimedTextPlayer::doSeekAndRead(int64_t seekTimeUs) {
}

void TimedTextPlayer::doRead(MediaSource::ReadOptions* options) {
    int64_t timeUs = 0;
    int64_t startTimeUs = 0;
    int64_t endTimeUs = 0;
    sp<ParcelEvent> parcelEvent = new ParcelEvent();
    status_t err = mSource->read(&timeUs, &(parcelEvent->parcel), options);
    if (err != OK) {
    status_t err = mSource->read(&startTimeUs, &endTimeUs,
                                 &(parcelEvent->parcel), options);
    if (err == WOULD_BLOCK) {
        postTextEventDelayUs(NULL, kWaitTimeUsToRetryRead);
        return;
    } else if (err != OK) {
        notifyError(err);
    } else {
        postTextEvent(parcelEvent, timeUs);
        return;
    }

    postTextEvent(parcelEvent, startTimeUs);
    if (endTimeUs > 0) {
        CHECK_GE(endTimeUs, startTimeUs);
        // send an empty timed text to clear the subtitle when it reaches to the
        // end time.
        postTextEvent(NULL, endTimeUs);
    }
}

@@ -162,6 +175,13 @@ void TimedTextPlayer::postTextEvent(const sp<ParcelEvent>& parcel, int64_t timeU
        } else {
            delayUs = timeUs - positionUs - kAdjustmentProcessingTimeUs;
        }
        postTextEventDelayUs(parcel, delayUs);
    }
}

void TimedTextPlayer::postTextEventDelayUs(const sp<ParcelEvent>& parcel, int64_t delayUs) {
    sp<MediaPlayerBase> listener = mListener.promote();
    if (listener != NULL) {
        sp<AMessage> msg = new AMessage(kWhatSendSubtitle, id());
        msg->setInt32("generation", mSendSubtitleGeneration);
        if (parcel != NULL) {
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ private:
    void doRead(MediaSource::ReadOptions* options = NULL);
    void onTextEvent();
    void postTextEvent(const sp<ParcelEvent>& parcel = NULL, int64_t timeUs = -1);
    void postTextEventDelayUs(const sp<ParcelEvent>& parcel = NULL, int64_t delayUs = -1);
    void notifyError(int error = 0);
    void notifyListener(const Parcel *parcel = NULL);

+6 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <utils/Log.h>

#include <binder/Parcel.h>
#include <media/stagefright/foundation/ADebug.h>  // for CHECK_xx
#include <media/stagefright/foundation/AString.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaDefs.h>  // for MEDIA_MIMETYPE_xxx
@@ -63,19 +64,18 @@ status_t TimedTextSRTSource::stop() {
}

status_t TimedTextSRTSource::read(
        int64_t *timeUs,
        int64_t *startTimeUs,
        int64_t *endTimeUs,
        Parcel *parcel,
        const MediaSource::ReadOptions *options) {
    int64_t endTimeUs;
    AString text;
    status_t err = getText(options, &text, timeUs, &endTimeUs);
    status_t err = getText(options, &text, startTimeUs, endTimeUs);
    if (err != OK) {
        return err;
    }

    if (*timeUs > 0) {
        extractAndAppendLocalDescriptions(*timeUs, text, parcel);
    }
    CHECK_GE(*startTimeUs, 0);
    extractAndAppendLocalDescriptions(*startTimeUs, text, parcel);
    return OK;
}

Loading