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

Commit ebbb848a authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Decrease HLS playlist memory usage

Instead of storing full cipher URIs, only store partial URIs, and
construct the full URI as needed.

Bug: 124940460
Test: CTS
Change-Id: Iedf84e2f6657c0abd5a3dafaa5cabb1b6e854579
parent 686dac0c
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -615,7 +615,7 @@ status_t M3UParser::parse(const void *_data, size_t size) {
                if (mIsVariantPlaylist) {
                    return ERROR_MALFORMED;
                }
                err = parseCipherInfo(line, &itemMeta, mBaseURI);
                err = parseCipherInfo(line, &itemMeta);
            } else if (line.startsWith("#EXT-X-ENDLIST")) {
                mIsComplete = true;
            } else if (line.startsWith("#EXT-X-PLAYLIST-TYPE:EVENT")) {
@@ -936,7 +936,7 @@ status_t M3UParser::parseStreamInf(

// static
status_t M3UParser::parseCipherInfo(
        const AString &line, sp<AMessage> *meta, const AString &baseURI) {
        const AString &line, sp<AMessage> *meta) {
    ssize_t colonPos = line.find(":");

    if (colonPos < 0) {
@@ -985,13 +985,9 @@ status_t M3UParser::parseCipherInfo(
                    val = tmp;
                }

                AString absURI;
                if (MakeURL(baseURI.c_str(), val.c_str(), &absURI)) {
                    val = absURI;
                } else {
                    ALOGE("failed to make absolute url for %s.",
                            uriDebugString(baseURI).c_str());
                }
                // To save space, we only store the partial Uri here
                // The full Uri will be constructed from this plus
                // the base Uri as needed by PlaylistFetcher
            }

            key.insert(AString("cipher-"), 0);
@@ -1003,6 +999,14 @@ status_t M3UParser::parseCipherInfo(
    return OK;
}

AString M3UParser::getFullCipherUri(const AString &partial) {
    AString full;
    if (MakeURL(mBaseURI.c_str(), partial.c_str(), &full)) {
        return full;
    }
    return AString("");
}

// static
status_t M3UParser::parseByteRange(
        const AString &line, uint64_t curOffset,
+3 −1
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ struct M3UParser : public RefBase {
    bool getTypeURI(size_t index, const char *key, AString *uri) const;
    bool hasType(size_t index, const char *key) const;

    AString getFullCipherUri(const AString &partial);

protected:
    virtual ~M3UParser();

@@ -99,7 +101,7 @@ private:
            const AString &line, sp<AMessage> *meta) const;

    static status_t parseCipherInfo(
            const AString &line, sp<AMessage> *meta, const AString &baseURI);
            const AString &line, sp<AMessage> *meta);

    static status_t parseByteRange(
            const AString &line, uint64_t curOffset,
+1 −0
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ status_t PlaylistFetcher::decryptBuffer(
        ALOGE("Missing key uri");
        return ERROR_MALFORMED;
    }
    keyURI = mPlaylist->getFullCipherUri(keyURI);

    ssize_t index = mAESKeyForURI.indexOfKey(keyURI);