Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a554246a authored by Leena Winterrowd's avatar Leena Winterrowd Committed by Steve Kondik
Browse files

stagefright: httplive: Decouple block size from bandwidth estimate

A very small block size in PlaylistFetcher can lead to framework
overhead and difficulty streaming high bitrate content, but since
HTTPBase keeps a constant history of the past 100 HTTP reads, the
block size directly affects bandwidth estimation and in turn,
switching latency.

Add setBandwidthHistorySize() to HTTPBase to allow setting the
history size for bandwidth estimation. Call this within LiveSession
based on the current block size to ensure that the number of bytes
used for estimating bandwidth does not change if the block size is
changed in PlaylistFetcher.

Since a single TCP/IP packet can contain up to 64k of data, increase
the block size in PlaylistFetcher from 2k to 32k to avoid
inaccuracies in read timings due to up to 32 reads from the same
locally-cached packet instead of from the network.

Also make HTTPBase::addBandwidthMeasurement() virtual to allow
bandwidth estimation extensions that do not rely on a history list.

Change-Id: I5f957be01f5346e74cfb7eeb150ca4b397ad5798
parent ffa98d52
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ HTTPBase::HTTPBase()
      mTotalTransferBytes(0),
      mPrevBandwidthMeasureTimeUs(0),
      mPrevEstimatedBandWidthKbps(0),
      mBandWidthCollectFreqMs(5000) {
      mBandWidthCollectFreqMs(5000),
      mMaxBandwidthHistoryItems(100) {
}

void HTTPBase::addBandwidthMeasurement(
@@ -50,7 +51,7 @@ void HTTPBase::addBandwidthMeasurement(
    mTotalTransferBytes += numBytes;

    mBandwidthHistory.push_back(entry);
    if (++mNumBandwidthHistoryItems > 100) {
    if (++mNumBandwidthHistoryItems > mMaxBandwidthHistoryItems) {
        BandwidthEntry *entry = &*mBandwidthHistory.begin();
        mTotalTransferTimeUs -= entry->mDelayUs;
        mTotalTransferBytes -= entry->mNumBytes;
@@ -104,6 +105,10 @@ status_t HTTPBase::setBandwidthStatCollectFreq(int32_t freqMs) {
    return OK;
}

void HTTPBase::setBandwidthHistorySize(size_t numHistoryItems) {
    mMaxBandwidthHistoryItems = numHistoryItems;
}

// static
void HTTPBase::RegisterSocketUserTag(int sockfd, uid_t uid, uint32_t kTag) {
    int res = qtaguid_tagSocket(sockfd, kTag, uid);
+10 −0
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@

namespace android {

// Number of recently-read bytes to use for bandwidth estimation
const size_t LiveSession::kBandwidthHistoryBytes = 200 * 1024;

LiveSession::LiveSession(
        const sp<AMessage> &notify, uint32_t flags,
        const sp<IMediaHTTPService> &httpService)
@@ -84,6 +87,13 @@ LiveSession::LiveSession(
        mPacketSources2.add(indexToType(i), new AnotherPacketSource(NULL /* meta */));
        mBuffering[i] = false;
    }

    size_t numHistoryItems = kBandwidthHistoryBytes /
            PlaylistFetcher::kDownloadBlockSize + 1;
    if (numHistoryItems < 5) {
        numHistoryItems = 5;
    }
    mHTTPDataSource->setBandwidthHistorySize(numHistoryItems);
}

LiveSession::~LiveSession() {
+2 −0
Original line number Diff line number Diff line
@@ -112,6 +112,8 @@ private:
        kWhatSwitchDown                 = 'sDwn',
    };

    static const size_t kBandwidthHistoryBytes;

    struct BandwidthItem {
        size_t mPlaylistIndex;
        unsigned long mBandwidth;
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ namespace android {
// static
const int64_t PlaylistFetcher::kMinBufferedDurationUs = 10000000ll;
const int64_t PlaylistFetcher::kMaxMonitorDelayUs = 3000000ll;
const int32_t PlaylistFetcher::kDownloadBlockSize = 2048;
const int32_t PlaylistFetcher::kDownloadBlockSize = 32768;
const int32_t PlaylistFetcher::kNumSkipFrames = 10;

PlaylistFetcher::PlaylistFetcher(
+1 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ struct String8;

struct PlaylistFetcher : public AHandler {
    static const int64_t kMinBufferedDurationUs;
    static const int32_t kDownloadBlockSize;

    enum {
        kWhatStarted,
@@ -95,7 +96,6 @@ private:
    };

    static const int64_t kMaxMonitorDelayUs;
    static const int32_t kDownloadBlockSize;
    static const int32_t kNumSkipFrames;

    static bool bufferStartsWithTsSyncByte(const sp<ABuffer>& buffer);
Loading