From d3b0bbb8a37f90fba84eb4e95c58aa0fec6c51e7 Mon Sep 17 00:00:00 2001 From: Robert Shih Date: Wed, 23 Jul 2014 15:00:25 -0700 Subject: NuPlayer: timed text support Bug: 16385674 Change-Id: Ifa9fbc17a1276aa774d57b82cdce500876a0b543 --- media/libmediaplayerservice/nuplayer/Android.mk | 1 + media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 74 ++++++++++++++++++++++ media/libmediaplayerservice/nuplayer/NuPlayer.h | 2 + .../nuplayer/NuPlayerSource.h | 1 + 4 files changed, 78 insertions(+) (limited to 'media') diff --git a/media/libmediaplayerservice/nuplayer/Android.mk b/media/libmediaplayerservice/nuplayer/Android.mk index 25002e3..0dd2b61 100644 --- a/media/libmediaplayerservice/nuplayer/Android.mk +++ b/media/libmediaplayerservice/nuplayer/Android.mk @@ -18,6 +18,7 @@ LOCAL_C_INCLUDES := \ $(TOP)/frameworks/av/media/libstagefright/include \ $(TOP)/frameworks/av/media/libstagefright/mpeg2ts \ $(TOP)/frameworks/av/media/libstagefright/rtsp \ + $(TOP)/frameworks/av/media/libstagefright/timedtext \ $(TOP)/frameworks/native/include/media/openmax LOCAL_MODULE:= libstagefright_nuplayer diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 6ccd27a..f876cce 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -29,6 +29,7 @@ #include "RTSPSource.h" #include "StreamingSource.h" #include "GenericSource.h" +#include "TextDescriptions.h" #include "ATSParser.h" @@ -151,6 +152,7 @@ NuPlayer::NuPlayer() mScanSourcesPending(false), mScanSourcesGeneration(0), mPollDurationGeneration(0), + mTimedTextGeneration(0), mTimeDiscontinuityPending(false), mFlushingAudio(NONE), mFlushingVideo(NONE), @@ -428,6 +430,16 @@ void NuPlayer::onMessageReceived(const sp &msg) { if (trackIndex < inbandTracks) { err = mSource->selectTrack(trackIndex, select); + + if (!select && err == OK) { + int32_t type; + sp info = mSource->getTrackInfo(trackIndex); + if (info != NULL + && info->findInt32("type", &type) + && type == MEDIA_TRACK_TYPE_TIMEDTEXT) { + ++mTimedTextGeneration; + } + } } else { trackIndex -= inbandTracks; @@ -1475,6 +1487,7 @@ void NuPlayer::performSeek(int64_t seekTimeUs) { seekTimeUs / 1E6); mSource->seekTo(seekTimeUs); + ++mTimedTextGeneration; if (mDriver != NULL) { sp driver = mDriver.promote(); @@ -1683,6 +1696,39 @@ void NuPlayer::onSourceNotify(const sp &msg) { break; } + case Source::kWhatTimedTextData: + { + int32_t generation; + if (msg->findInt32("generation", &generation) + && generation != mTimedTextGeneration) { + break; + } + + sp buffer; + CHECK(msg->findBuffer("buffer", &buffer)); + + sp driver = mDriver.promote(); + if (driver == NULL) { + break; + } + + int posMs; + int64_t timeUs, posUs; + driver->getCurrentPosition(&posMs); + posUs = posMs * 1000; + CHECK(buffer->meta()->findInt64("timeUs", &timeUs)); + + if (posUs < timeUs) { + if (!msg->findInt32("generation", &generation)) { + msg->setInt32("generation", mTimedTextGeneration); + } + msg->post(timeUs - posUs); + } else { + sendTimedTextData(buffer); + } + break; + } + case Source::kWhatQueueDecoderShutdown: { int32_t audio, video; @@ -1751,6 +1797,34 @@ void NuPlayer::sendSubtitleData(const sp &buffer, int32_t baseIndex) { notifyListener(MEDIA_SUBTITLE_DATA, 0, 0, &in); } + +void NuPlayer::sendTimedTextData(const sp &buffer) { + const void *data; + size_t size = 0; + int64_t timeUs; + int32_t flag = TextDescriptions::LOCAL_DESCRIPTIONS; + + AString mime; + CHECK(buffer->meta()->findString("mime", &mime)); + CHECK(strcasecmp(mime.c_str(), MEDIA_MIMETYPE_TEXT_3GPP) == 0); + + data = buffer->data(); + size = buffer->size(); + + Parcel parcel; + if (size > 0) { + CHECK(buffer->meta()->findInt64("timeUs", &timeUs)); + flag |= TextDescriptions::IN_BAND_TEXT_3GPP; + TextDescriptions::getParcelOfDescriptions( + (const uint8_t *)data, size, flag, timeUs / 1000, &parcel); + } + + if ((parcel.dataSize() > 0)) { + notifyListener(MEDIA_TIMED_TEXT, 0, 0, &parcel); + } else { // send an empty timed text + notifyListener(MEDIA_TIMED_TEXT, 0, 0); + } +} //////////////////////////////////////////////////////////////////////////////// void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) { diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h index c04e277..8bcf10e 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h @@ -136,6 +136,7 @@ private: int32_t mScanSourcesGeneration; int32_t mPollDurationGeneration; + int32_t mTimedTextGeneration; enum FlushStatus { NONE, @@ -198,6 +199,7 @@ private: bool audio, bool video, const sp &reply); void sendSubtitleData(const sp &buffer, int32_t baseIndex); + void sendTimedTextData(const sp &buffer); void writeTrackInfo(Parcel* reply, const sp format) const; diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h index 259925f..0ec017e 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h @@ -47,6 +47,7 @@ struct NuPlayer::Source : public AHandler { kWhatBufferingStart, kWhatBufferingEnd, kWhatSubtitleData, + kWhatTimedTextData, kWhatQueueDecoderShutdown, }; -- cgit v1.1