From 0a2f0e047a2e593c62f54b07b903baf4728b9d0a Mon Sep 17 00:00:00 2001 From: Insun Kang Date: Sat, 21 Apr 2012 15:38:02 +0900 Subject: Fix a bug on subtitle (SRT). Bug: 6375542 Change-Id: Ic5dd5a1826b9f78ccbbddc4dec33b0e915b9329f --- .../timedtext/TimedTextSRTSource.cpp | 22 ++++++++++++++++------ .../libstagefright/timedtext/TimedTextSRTSource.h | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'media/libstagefright/timedtext') diff --git a/media/libstagefright/timedtext/TimedTextSRTSource.cpp b/media/libstagefright/timedtext/TimedTextSRTSource.cpp index 7b1f7f6..1f5d037 100644 --- a/media/libstagefright/timedtext/TimedTextSRTSource.cpp +++ b/media/libstagefright/timedtext/TimedTextSRTSource.cpp @@ -212,6 +212,9 @@ status_t TimedTextSRTSource::readNextLine(off64_t *offset, AString *data) { status_t TimedTextSRTSource::getText( const MediaSource::ReadOptions *options, AString *text, int64_t *startTimeUs, int64_t *endTimeUs) { + if (mTextVector.size() == 0) { + return ERROR_END_OF_STREAM; + } text->clear(); int64_t seekTimeUs; MediaSource::ReadOptions::SeekMode mode; @@ -225,31 +228,38 @@ status_t TimedTextSRTSource::getText( mIndex = 0; } else { // binary search - ssize_t low = 0; - ssize_t high = mTextVector.size() - 1; - ssize_t mid = 0; + size_t low = 0; + size_t high = mTextVector.size() - 1; + size_t mid = 0; int64_t currTimeUs; while (low <= high) { mid = low + (high - low)/2; currTimeUs = mTextVector.keyAt(mid); - const int diff = currTimeUs - seekTimeUs; + const int64_t diffTime = currTimeUs - seekTimeUs; - if (diff == 0) { + if (diffTime == 0) { break; - } else if (diff < 0) { + } else if (diffTime < 0) { low = mid + 1; } else { if ((high == mid + 1) && (seekTimeUs < mTextVector.keyAt(high))) { break; } + if (mid < 1) { + break; + } high = mid - 1; } } mIndex = mid; } } + + if (mIndex >= mTextVector.size()) { + return ERROR_END_OF_STREAM; + } const TextInfo &info = mTextVector.valueAt(mIndex); *startTimeUs = mTextVector.keyAt(mIndex); *endTimeUs = info.endTimeUs; diff --git a/media/libstagefright/timedtext/TimedTextSRTSource.h b/media/libstagefright/timedtext/TimedTextSRTSource.h index e1371b8..9eeab39 100644 --- a/media/libstagefright/timedtext/TimedTextSRTSource.h +++ b/media/libstagefright/timedtext/TimedTextSRTSource.h @@ -56,7 +56,7 @@ private: int textLen; }; - int mIndex; + size_t mIndex; KeyedVector mTextVector; void reset(); -- cgit v1.1