summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/mpeg2ts
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/mpeg2ts')
-rw-r--r--media/libstagefright/mpeg2ts/AnotherPacketSource.cpp20
-rw-r--r--media/libstagefright/mpeg2ts/AnotherPacketSource.h3
2 files changed, 20 insertions, 3 deletions
diff --git a/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp b/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp
index a605a05..3de3a61 100644
--- a/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp
+++ b/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp
@@ -28,9 +28,12 @@
namespace android {
+const int64_t kNearEOSMarkUs = 2000000ll; // 2 secs
+
AnotherPacketSource::AnotherPacketSource(const sp<MetaData> &meta)
: mIsAudio(false),
mFormat(meta),
+ mLastQueuedTimeUs(0),
mEOSResult(OK) {
const char *mime;
CHECK(meta->findCString(kKeyMIMEType, &mime));
@@ -141,9 +144,8 @@ void AnotherPacketSource::queueAccessUnit(const sp<ABuffer> &buffer) {
return;
}
- int64_t timeUs;
- CHECK(buffer->meta()->findInt64("timeUs", &timeUs));
- ALOGV("queueAccessUnit timeUs=%lld us (%.2f secs)", timeUs, timeUs / 1E6);
+ CHECK(buffer->meta()->findInt64("timeUs", &mLastQueuedTimeUs));
+ ALOGV("queueAccessUnit timeUs=%lld us (%.2f secs)", mLastQueuedTimeUs, mLastQueuedTimeUs / 1E6);
Mutex::Autolock autoLock(mLock);
mBuffers.push_back(buffer);
@@ -171,6 +173,7 @@ void AnotherPacketSource::queueDiscontinuity(
}
mEOSResult = OK;
+ mLastQueuedTimeUs = 0;
sp<ABuffer> buffer = new ABuffer(0);
buffer->meta()->setInt32("discontinuity", static_cast<int32_t>(type));
@@ -247,4 +250,15 @@ status_t AnotherPacketSource::nextBufferTime(int64_t *timeUs) {
return OK;
}
+bool AnotherPacketSource::isFinished(int64_t duration) const {
+ if (duration > 0) {
+ int64_t diff = duration - mLastQueuedTimeUs;
+ if (diff < kNearEOSMarkUs && diff > -kNearEOSMarkUs) {
+ ALOGV("Detecting EOS due to near end");
+ return true;
+ }
+ }
+ return (mEOSResult != OK);
+}
+
} // namespace android
diff --git a/media/libstagefright/mpeg2ts/AnotherPacketSource.h b/media/libstagefright/mpeg2ts/AnotherPacketSource.h
index d685b98..1db4068 100644
--- a/media/libstagefright/mpeg2ts/AnotherPacketSource.h
+++ b/media/libstagefright/mpeg2ts/AnotherPacketSource.h
@@ -58,6 +58,8 @@ struct AnotherPacketSource : public MediaSource {
status_t dequeueAccessUnit(sp<ABuffer> *buffer);
+ bool isFinished(int64_t duration) const;
+
protected:
virtual ~AnotherPacketSource();
@@ -67,6 +69,7 @@ private:
bool mIsAudio;
sp<MetaData> mFormat;
+ int64_t mLastQueuedTimeUs;
List<sp<ABuffer> > mBuffers;
status_t mEOSResult;