OSDN Git Service

httplive: Set start time and segment start time in conjunction.
authorRobert Shih <robertshih@google.com>
Wed, 4 Feb 2015 19:32:50 +0000 (11:32 -0800)
committerRobert Shih <robertshih@google.com>
Wed, 4 Feb 2015 19:35:58 +0000 (11:35 -0800)
Also add comments describing how start time and segment start time are
used.

Based on AOSP CL https://android-review.googlesource.com/127653
by Joakim Johansson <joakim.c.johansson@sonymobile.com> but uses the
lowest segment start time instead of highest.

Bug: 18821145
Change-Id: I14cf1186d0daf517a24e8423c3a708b4c9ba06c4

media/libstagefright/httplive/LiveSession.cpp
media/libstagefright/httplive/PlaylistFetcher.cpp

index 9daab3b..ead54ef 100644 (file)
@@ -1509,14 +1509,15 @@ void LiveSession::onChangeConfiguration3(const sp<AMessage> &msg) {
 
                     if (meta != NULL && !meta->findInt32("discontinuity", &type)) {
                         int64_t tmpUs;
+                        int64_t tmpSegmentUs;
+
                         CHECK(meta->findInt64("timeUs", &tmpUs));
-                        if (startTimeUs < 0 || tmpUs < startTimeUs) {
+                        CHECK(meta->findInt64("segmentStartTimeUs", &tmpSegmentUs));
+                        if (startTimeUs < 0 || tmpSegmentUs < segmentStartTimeUs) {
+                            startTimeUs = tmpUs;
+                            segmentStartTimeUs = tmpSegmentUs;
+                        } else if (tmpSegmentUs == segmentStartTimeUs && tmpUs < startTimeUs) {
                             startTimeUs = tmpUs;
-                        }
-
-                        CHECK(meta->findInt64("segmentStartTimeUs", &tmpUs));
-                        if (segmentStartTimeUs < 0 || tmpUs < segmentStartTimeUs) {
-                            segmentStartTimeUs = tmpUs;
                         }
 
                         int32_t seq;
index 4a97803..2678224 100644 (file)
@@ -758,6 +758,9 @@ void PlaylistFetcher::onDownloadNext() {
                     mSeqNumber = firstSeqNumberInPlaylist;
                 }
             } else {
+                // When seeking mSegmentStartTimeUs is unavailable (< 0), we
+                // use mStartTimeUs (client supplied timestamp) to determine both start segment
+                // and relative position inside a segment
                 mSeqNumber = getSeqNumberForTime(mStartTimeUs);
                 mStartTimeUs -= getSegmentStartTimeUs(mSeqNumber);
             }
@@ -766,6 +769,10 @@ void PlaylistFetcher::onDownloadNext() {
                     mStartTimeUs, mSeqNumber, firstSeqNumberInPlaylist,
                     lastSeqNumberInPlaylist);
         } else {
+            // When adapting or track switching, mSegmentStartTimeUs (relative
+            // to media time 0) is used to determine the start segment; mStartTimeUs (absolute
+            // timestamps coming from the media container) is used to determine the position
+            // inside a segments.
             mSeqNumber = getSeqNumberForTime(mSegmentStartTimeUs);
             if (mAdaptive) {
                 // avoid double fetch/decode