diff options
author | James Dong <jdong@google.com> | 2012-04-30 23:16:31 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-04-30 23:16:31 -0700 |
commit | 27431de020e535c31365884316f656bc60b4fe4f (patch) | |
tree | 7398ce098972c895ad9838a3047e8844d8d9d6d6 | |
parent | 048537455e1f6fc400f484e44d88c5617960df6a (diff) | |
parent | 0a2f0e047a2e593c62f54b07b903baf4728b9d0a (diff) | |
download | frameworks_av-27431de020e535c31365884316f656bc60b4fe4f.zip frameworks_av-27431de020e535c31365884316f656bc60b4fe4f.tar.gz frameworks_av-27431de020e535c31365884316f656bc60b4fe4f.tar.bz2 |
Merge "Fix a bug on subtitle (SRT)." into jb-dev
-rw-r--r-- | media/libstagefright/timedtext/TimedTextSRTSource.cpp | 22 | ||||
-rw-r--r-- | media/libstagefright/timedtext/TimedTextSRTSource.h | 2 |
2 files changed, 17 insertions, 7 deletions
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<int64_t, TextInfo> mTextVector; void reset(); |