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

Commit 0cd95065 authored by Robert Shih's avatar Robert Shih
Browse files

nuplayer2: port GenericSource2 to NDK APIs

Bug: 63934228
Change-Id: I8bddacf5ce9eb8f22f3d4a945e0a7db1b52628d3
parent bb32f870
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -81,11 +81,16 @@ static const char *AMediaFormatKeyGroupInt32[] = {
    AMEDIAFORMAT_KEY_STRIDE,
    AMEDIAFORMAT_KEY_TRACK_ID,
    AMEDIAFORMAT_KEY_WIDTH,
    AMEDIAFORMAT_KEY_DISPLAY_HEIGHT,
    AMEDIAFORMAT_KEY_DISPLAY_WIDTH,
    AMEDIAFORMAT_KEY_TEMPORAL_LAYER_ID,
    AMEDIAFORMAT_KEY_TRACK_INDEX,
};

static const char *AMediaFormatKeyGroupInt64[] = {
    AMEDIAFORMAT_KEY_DURATION,
    AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER,
    AMEDIAFORMAT_KEY_TIME_US,
};

static const char *AMediaFormatKeyGroupString[] = {
@@ -96,6 +101,14 @@ static const char *AMediaFormatKeyGroupString[] = {

static const char *AMediaFormatKeyGroupBuffer[] = {
    AMEDIAFORMAT_KEY_HDR_STATIC_INFO,
    AMEDIAFORMAT_KEY_SEI,
    AMEDIAFORMAT_KEY_MPEG_USER_DATA,
};

static const char *AMediaFormatKeyGroupCsd[] = {
    AMEDIAFORMAT_KEY_CSD_0,
    AMEDIAFORMAT_KEY_CSD_1,
    AMEDIAFORMAT_KEY_CSD_2,
};

static const char *AMediaFormatKeyGroupRect[] = {
@@ -307,11 +320,19 @@ AMediaFormat *AMediaFormatWrapper::getAMediaFormat() const {
}

sp<AMessage> AMediaFormatWrapper::toAMessage() const {
  sp<AMessage> msg;
  writeToAMessage(msg);
  return msg;
}

void AMediaFormatWrapper::writeToAMessage(sp<AMessage> &msg) const {
    if (mAMediaFormat == NULL) {
        return NULL;
        msg = NULL;
    }

    sp<AMessage> msg = new AMessage;
    if (msg == NULL) {
        msg = new AMessage;
    }
    for (auto& key : AMediaFormatKeyGroupInt32) {
        int32_t val;
        if (getInt32(key, &val)) {
@@ -338,6 +359,16 @@ sp<AMessage> AMediaFormatWrapper::toAMessage() const {
            msg->setBuffer(key, buffer);
        }
    }
    for (auto& key : AMediaFormatKeyGroupCsd) {
        void *data;
        size_t size;
        if (getBuffer(key, &data, &size)) {
            sp<ABuffer> buffer = ABuffer::CreateAsCopy(data, size);
            buffer->meta()->setInt32(AMEDIAFORMAT_KEY_CSD, 1);
            buffer->meta()->setInt64(AMEDIAFORMAT_KEY_TIME_US, 0);
            msg->setBuffer(key, buffer);
        }
    }
    for (auto& key : AMediaFormatKeyGroupRect) {
        int32_t left, top, right, bottom;
        if (getRect(key, &left, &top, &right, &bottom)) {
@@ -355,7 +386,6 @@ sp<AMessage> AMediaFormatWrapper::toAMessage() const {
            }
        }
    }
    return msg;
}

const char* AMediaFormatWrapper::toString() const {
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ struct AMessage;
class MetaData;

struct AMediaFormatWrapper : public RefBase {

    static sp<AMediaFormatWrapper> Create(const sp<AMessage> &message);

    AMediaFormatWrapper();
@@ -54,6 +55,7 @@ struct AMediaFormatWrapper : public RefBase {
    AMediaFormat *getAMediaFormat() const;

    sp<AMessage> toAMessage() const ;
    void writeToAMessage(sp<AMessage>&) const ;
    const char* toString() const ;

    status_t release();
+184 −257

File changed.

Preview size limit exceeded, changes collapsed.

+14 −6
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@

#include <media/stagefright/MediaBuffer.h>
#include <mediaplayer2/mediaplayer2.h>
#include <media/NdkMediaDataSource.h>
#include <media/NdkMediaExtractor.h>
#include <media/NdkWrapper.h>

namespace android {

@@ -101,6 +104,7 @@ protected:

    virtual void onMessageReceived(const sp<AMessage> &msg);

    virtual sp<AMessage> getFormat(bool audio);
    virtual sp<MetaData> getFormatMeta(bool audio);

private:
@@ -122,19 +126,14 @@ private:

    struct Track {
        size_t mIndex;
        sp<IMediaSource> mSource;
        sp<AMediaExtractorWrapper> mExtractor;
        sp<AnotherPacketSource> mPackets;
    };

    Vector<sp<IMediaSource> > mSources;
    Track mAudioTrack;
    int64_t mAudioTimeUs;
    int64_t mAudioLastDequeueTimeUs;
    Track mVideoTrack;
    int64_t mVideoTimeUs;
    int64_t mVideoLastDequeueTimeUs;
    Track mSubtitleTrack;
    Track mTimedTextTrack;

    BufferingSettings mBufferingSettings;
    int32_t mPrevBufferPercentage;
@@ -164,12 +163,20 @@ private:
    sp<NuCachedSource2> mCachedSource;
    sp<DataSource> mHttpSource;
    sp<MetaData> mFileMeta;
    sp<AMediaDataSourceWrapper> mDataSourceWrapper;
    sp<AMediaExtractorWrapper> mExtractor;
    Vector<sp<AMediaExtractorWrapper> > mExtractors;
    bool mStarted;
    bool mPreparing;
    int64_t mBitrate;
    uint32_t mPendingReadBufferTypes;
    sp<ABuffer> mGlobalTimedText;

    Track mVideoTrack;
    Track mAudioTrack;
    Track mSubtitleTrack;
    Track mTimedTextTrack;

    mutable Mutex mLock;

    sp<ALooper> mLooper;
@@ -227,6 +234,7 @@ private:

    void sendCacheStats();

    sp<AMessage> getFormat_l(bool audio);
    sp<MetaData> getFormatMeta_l(bool audio);
    int32_t getDataGeneration(media_track_type type) const;

+7 −0
Original line number Diff line number Diff line
@@ -286,7 +286,13 @@ EXPORT const char* AMEDIAFORMAT_KEY_COLOR_RANGE = "color-range";
EXPORT const char* AMEDIAFORMAT_KEY_COLOR_STANDARD = "color-standard";
EXPORT const char* AMEDIAFORMAT_KEY_COLOR_TRANSFER = "color-transfer";
EXPORT const char* AMEDIAFORMAT_KEY_COMPLEXITY = "complexity";
EXPORT const char* AMEDIAFORMAT_KEY_CSD = "csd";
EXPORT const char* AMEDIAFORMAT_KEY_CSD_0 = "csd-0";
EXPORT const char* AMEDIAFORMAT_KEY_CSD_1 = "csd-1";
EXPORT const char* AMEDIAFORMAT_KEY_CSD_2 = "csd-2";
EXPORT const char* AMEDIAFORMAT_KEY_DISPLAY_CROP = "crop";
EXPORT const char* AMEDIAFORMAT_KEY_DISPLAY_HEIGHT = "display-height";
EXPORT const char* AMEDIAFORMAT_KEY_DISPLAY_WIDTH = "display-width";
EXPORT const char* AMEDIAFORMAT_KEY_DURATION = "durationUs";
EXPORT const char* AMEDIAFORMAT_KEY_FLAC_COMPRESSION_LEVEL = "flac-compression-level";
EXPORT const char* AMEDIAFORMAT_KEY_FRAME_RATE = "frame-rate";
@@ -323,6 +329,7 @@ EXPORT const char* AMEDIAFORMAT_KEY_SLICE_HEIGHT = "slice-height";
EXPORT const char* AMEDIAFORMAT_KEY_STRIDE = "stride";
EXPORT const char* AMEDIAFORMAT_KEY_TEMPORAL_LAYER_ID = "temporal-layer-id";
EXPORT const char* AMEDIAFORMAT_KEY_TEMPORAL_LAYERING = "ts-schema";
EXPORT const char* AMEDIAFORMAT_KEY_TIME_US = "timeUs";
EXPORT const char* AMEDIAFORMAT_KEY_TRACK_ID = "track-id";
EXPORT const char* AMEDIAFORMAT_KEY_TRACK_INDEX = "track-index";
EXPORT const char* AMEDIAFORMAT_KEY_WIDTH = "width";
Loading