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

Commit 5028e3bb authored by Ray Essick's avatar Ray Essick
Browse files

dup ESDS data before discarding extractor

make a copy of the ESDS data retrieved from the media extractor.
Avoid holding un-tracked reference to esds data which is discarded
when we destroy the extractor.

Bug: 328930702
Test: atest ESDSTest
Change-Id: I9e4939ef09d7af34f6744a16dba8bfed21c9995c
parent 5223c5e8
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ class ESDSUnitTest : public ::testing::TestWithParam<tuple<
                             /* BitrateMax */ int32_t,
                             /* BitrateAvg */ int32_t>> {
  public:
    ESDSUnitTest() : mESDSData(nullptr) {
    ESDSUnitTest() {
        mESDSParams.inputFile = get<0>(GetParam());
        mESDSParams.objectTypeIndication = get<1>(GetParam());
        mESDSParams.codecSpecificInfoData = get<2>(GetParam());
@@ -61,6 +61,13 @@ class ESDSUnitTest : public ::testing::TestWithParam<tuple<
        mESDSParams.bitrateAvg = get<5>(GetParam());
    };

    ~ESDSUnitTest() {
        if (mESDSData != nullptr) {
            free(mESDSData);
            mESDSData = nullptr;
        }
    }

    virtual void TearDown() override {
        if (mDataSource) mDataSource.clear();
        if (mInputFp) {
@@ -70,8 +77,8 @@ class ESDSUnitTest : public ::testing::TestWithParam<tuple<
    }

    virtual void SetUp() override { ASSERT_NO_FATAL_FAILURE(readESDSData()); }
    const void *mESDSData;
    size_t mESDSSize;
    void *mESDSData = nullptr;
    size_t mESDSSize = 0;
    ESDSParams mESDSParams;

  private:
@@ -105,10 +112,19 @@ class ESDSUnitTest : public ::testing::TestWithParam<tuple<
    bool esdsDataPresent(size_t numTracks, sp<IMediaExtractor> extractor) {
        bool foundESDS = false;
        uint32_t type;
        if (mESDSData != nullptr) {
            free(mESDSData);
            mESDSData = nullptr;
        }
        for (size_t i = 0; i < numTracks; ++i) {
            sp<MetaData> trackMeta = extractor->getTrackMetaData(i);
            const void *esdsData = nullptr;
            size_t esdsSize = 0;
            if (trackMeta != nullptr &&
                trackMeta->findData(kKeyESDS, &type, &mESDSData, &mESDSSize)) {
                trackMeta->findData(kKeyESDS, &type, &esdsData, &esdsSize)) {
                mESDSData = malloc(esdsSize);
                mESDSSize = esdsSize;
                memcpy(mESDSData, esdsData, esdsSize);
                trackMeta->clear();
                foundESDS = true;
                break;