From bae00e73c6d1d87cc5fd42b50f95d1d9572162ea Mon Sep 17 00:00:00 2001 From: Insun Kang Date: Wed, 14 Mar 2012 08:16:35 +0900 Subject: Handling end times of subtitles. Change-Id: Ic19ec8980d0a2bf9f265d375cd56e638a2460af8 --- .../timedtext/TimedText3GPPSource.cpp | 14 +++++----- .../libstagefright/timedtext/TimedText3GPPSource.h | 3 ++- media/libstagefright/timedtext/TimedTextPlayer.cpp | 30 ++++++++++++++++++---- media/libstagefright/timedtext/TimedTextPlayer.h | 1 + .../timedtext/TimedTextSRTSource.cpp | 12 ++++----- .../libstagefright/timedtext/TimedTextSRTSource.h | 3 ++- media/libstagefright/timedtext/TimedTextSource.h | 3 ++- 7 files changed, 46 insertions(+), 20 deletions(-) (limited to 'media/libstagefright/timedtext') diff --git a/media/libstagefright/timedtext/TimedText3GPPSource.cpp b/media/libstagefright/timedtext/TimedText3GPPSource.cpp index c423ef0..4854121 100644 --- a/media/libstagefright/timedtext/TimedText3GPPSource.cpp +++ b/media/libstagefright/timedtext/TimedText3GPPSource.cpp @@ -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; } diff --git a/media/libstagefright/timedtext/TimedText3GPPSource.h b/media/libstagefright/timedtext/TimedText3GPPSource.h index 4ec3d8a..4170940 100644 --- a/media/libstagefright/timedtext/TimedText3GPPSource.h +++ b/media/libstagefright/timedtext/TimedText3GPPSource.h @@ -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); diff --git a/media/libstagefright/timedtext/TimedTextPlayer.cpp b/media/libstagefright/timedtext/TimedTextPlayer.cpp index 8717914..917c62a 100644 --- a/media/libstagefright/timedtext/TimedTextPlayer.cpp +++ b/media/libstagefright/timedtext/TimedTextPlayer.cpp @@ -31,6 +31,7 @@ namespace android { static const int64_t kAdjustmentProcessingTimeUs = 100000ll; +static const int64_t kWaitTimeUsToRetryRead = 100000ll; TimedTextPlayer::TimedTextPlayer(const wp &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 = 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& parcel, int64_t timeU } else { delayUs = timeUs - positionUs - kAdjustmentProcessingTimeUs; } + postTextEventDelayUs(parcel, delayUs); + } +} + +void TimedTextPlayer::postTextEventDelayUs(const sp& parcel, int64_t delayUs) { + sp listener = mListener.promote(); + if (listener != NULL) { sp msg = new AMessage(kWhatSendSubtitle, id()); msg->setInt32("generation", mSendSubtitleGeneration); if (parcel != NULL) { diff --git a/media/libstagefright/timedtext/TimedTextPlayer.h b/media/libstagefright/timedtext/TimedTextPlayer.h index b869f18..47aff03 100644 --- a/media/libstagefright/timedtext/TimedTextPlayer.h +++ b/media/libstagefright/timedtext/TimedTextPlayer.h @@ -67,6 +67,7 @@ private: void doRead(MediaSource::ReadOptions* options = NULL); void onTextEvent(); void postTextEvent(const sp& parcel = NULL, int64_t timeUs = -1); + void postTextEventDelayUs(const sp& parcel = NULL, int64_t delayUs = -1); void notifyError(int error = 0); void notifyListener(const Parcel *parcel = NULL); diff --git a/media/libstagefright/timedtext/TimedTextSRTSource.cpp b/media/libstagefright/timedtext/TimedTextSRTSource.cpp index c44a99b..7b1f7f6 100644 --- a/media/libstagefright/timedtext/TimedTextSRTSource.cpp +++ b/media/libstagefright/timedtext/TimedTextSRTSource.cpp @@ -19,6 +19,7 @@ #include #include +#include // for CHECK_xx #include #include #include // 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; } diff --git a/media/libstagefright/timedtext/TimedTextSRTSource.h b/media/libstagefright/timedtext/TimedTextSRTSource.h index 62710a0..e1371b8 100644 --- a/media/libstagefright/timedtext/TimedTextSRTSource.h +++ b/media/libstagefright/timedtext/TimedTextSRTSource.h @@ -36,7 +36,8 @@ public: virtual status_t start(); virtual status_t stop(); virtual status_t read( - int64_t *timeUs, + int64_t *startTimeUs, + int64_t *endTimeUs, Parcel *parcel, const MediaSource::ReadOptions *options = NULL); virtual sp getFormat(); diff --git a/media/libstagefright/timedtext/TimedTextSource.h b/media/libstagefright/timedtext/TimedTextSource.h index 9349342..756cc31 100644 --- a/media/libstagefright/timedtext/TimedTextSource.h +++ b/media/libstagefright/timedtext/TimedTextSource.h @@ -43,7 +43,8 @@ class TimedTextSource : public RefBase { virtual status_t stop() = 0; // Returns subtitle parcel and its start time. virtual status_t read( - int64_t *timeUs, + int64_t *startTimeUs, + int64_t *endTimeUs, Parcel *parcel, const MediaSource::ReadOptions *options = NULL) = 0; virtual status_t extractGlobalDescriptions(Parcel *parcel) { -- cgit v1.1