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

Commit 4d432f1d authored by Robert Shih's avatar Robert Shih
Browse files

AMediaDataSourceWrapper: keep DataSource sp alive

Bug: 118506674
Test: android.media.cts.MediaPlayer2Test#testConsecutiveSeeks
Change-Id: Iafa26d6a0fa6ad4aa7dee696fff1673075e51624
parent 69c9844b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -291,6 +291,7 @@ cc_library_static {
        "libmediaextractor",
        "libmediandk",
        "libnativewindow",
        "libmediandk_utils",
        "libstagefright_foundation",
        "libui",
        "libutils",
@@ -305,6 +306,10 @@ cc_library_static {
        "media_plugin_headers",
    ],

    include_dirs: [
        "frameworks/av/media/ndk",
    ],

    static_libs: [
        "libstagefright_rtsp",
        "libstagefright_timedtext",
+9 −1
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@
#include <media/stagefright/foundation/AMessage.h>
#include <utils/Errors.h>

#include "NdkMediaDataSourceCallbacksPriv.h"

namespace android {

static const size_t kAESBlockSize = 16;  // AES_BLOCK_SIZE
@@ -1244,8 +1246,14 @@ sp<AMediaCodecCryptoInfoWrapper> AMediaExtractorWrapper::getSampleCryptoInfo() {
    return new AMediaCodecCryptoInfoWrapper(AMediaExtractor_getSampleCryptoInfo(mAMediaExtractor));
}

AMediaDataSourceWrapper::AMediaDataSourceWrapper(const sp<DataSource> &dataSource)
    : mDataSource(dataSource),
      mAMediaDataSource(convertDataSourceToAMediaDataSource(dataSource)) {
}

AMediaDataSourceWrapper::AMediaDataSourceWrapper(AMediaDataSource *aDataSource)
    : mAMediaDataSource(aDataSource) {
    : mDataSource(NULL),
      mAMediaDataSource(aDataSource) {
}

AMediaDataSourceWrapper::~AMediaDataSourceWrapper() {
+2 −7
Original line number Diff line number Diff line
@@ -280,13 +280,10 @@ private:

struct AMediaDataSourceWrapper : public RefBase {

    AMediaDataSourceWrapper(const sp<DataSource>&);
    AMediaDataSourceWrapper(AMediaDataSource*);
    AMediaDataSourceWrapper(int fd, int64_t offset, int64_t length);

    AMediaDataSource *getAMediaDataSource();
    int getFd() { return mFd; }
    int64_t getOffset() { return mOffset; }
    int64_t getLength() { return mLength; }

    void close();

@@ -294,10 +291,8 @@ protected:
    virtual ~AMediaDataSourceWrapper();

private:
    sp<DataSource> mDataSource;
    AMediaDataSource *mAMediaDataSource;
    int mFd;
    int64_t mOffset;
    int64_t mLength;

    DISALLOW_EVIL_CONSTRUCTORS(AMediaDataSourceWrapper);
};
+1 −3
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <media/stagefright/MetaData.h>
#include <media/stagefright/NdkUtils.h>
#include <media/stagefright/Utils.h>
#include "NdkMediaDataSourceCallbacksPriv.h"

namespace android {

@@ -137,8 +136,7 @@ status_t NuPlayer2::GenericSource2::setDataSource(const sp<DataSource>& source)
    ALOGV("setDataSource (source: %p)", source.get());

    resetDataSource();
    AMediaDataSource *aSource = convertDataSourceToAMediaDataSource(source);
    mDataSourceWrapper = new AMediaDataSourceWrapper(aSource);
    mDataSourceWrapper = new AMediaDataSourceWrapper(source);
    return OK;
}