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

Commit 30e3c7d2 authored by Robert Shih's avatar Robert Shih
Browse files

Ndk extractor: add cached duration, file format and sample size API

Bug: 63934228
Change-Id: I965f58ac77eb2561979926f54adc4f6e16d44718
parent b2eb24b6
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ static media_status_t translate_error(status_t err) {
struct AMediaExtractor {
    sp<NuMediaExtractor> mImpl;
    sp<ABuffer> mPsshBuf;

};

extern "C" {
@@ -126,6 +125,13 @@ media_status_t AMediaExtractor_setDataSourceCustom(AMediaExtractor* mData, AMedi
    return translate_error(mData->mImpl->setDataSource(new NdkDataSource(src)));
}

EXPORT
AMediaFormat* AMediaExtractor_getFileFormat(AMediaExtractor *mData) {
    sp<AMessage> format;
    mData->mImpl->getFileFormat(&format);
    return AMediaFormat_fromMsg(&format);
}

EXPORT
size_t AMediaExtractor_getTrackCount(AMediaExtractor *mData) {
    return mData->mImpl->countTracks();
@@ -187,6 +193,16 @@ ssize_t AMediaExtractor_readSampleData(AMediaExtractor *mData, uint8_t *buffer,
    return -1;
}

EXPORT
ssize_t AMediaExtractor_getSampleSize(AMediaExtractor *mData) {
    size_t sampleSize;
    status_t err = mData->mImpl->getSampleSize(&sampleSize);
    if (err != OK) {
        return -1;
    }
    return sampleSize;
}

EXPORT
uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor *mData) {
    int sampleFlags = 0;
@@ -385,6 +401,15 @@ AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *ex)
            (size_t*) crypteddata);
}

EXPORT
int64_t AMediaExtractor_getCachedDuration(AMediaExtractor *ex) {
    bool eos;
    int64_t durationUs;
    if (ex->mImpl->getCachedDuration(&durationUs, &eos)) {
        return durationUs;
    }
    return -1;
}

} // extern "C"
+38 −1
Original line number Diff line number Diff line
@@ -162,12 +162,49 @@ PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor*);

AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *);


enum {
    AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC = 1,
    AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
};

#if __ANDROID_API__ >= 28

/**
 * Returns the format of the extractor. The caller must free the returned format
 * using AMediaFormat_delete(format).
 *
 * This function will always return a format; however, the format could be empty
 * (no key-value pairs) if the media container does not provide format information.
 */
AMediaFormat* AMediaExtractor_getFileFormat(AMediaExtractor*);

/**
 * Returns the size of the current sample in bytes, or -1 when no samples are
 * available (end of stream). This API can be used in in conjunction with
 * AMediaExtractor_readSampleData:
 *
 * ssize_t sampleSize = AMediaExtractor_getSampleSize(ex);
 * uint8_t *buf = new uint8_t[sampleSize];
 * AMediaExtractor_readSampleData(ex, buf, sampleSize);
 *
 */
ssize_t AMediaExtractor_getSampleSize(AMediaExtractor*);

/**
 * Returns the duration of cached media samples downloaded from a network data source
 * (AMediaExtractor_setDataSource with a "http(s)" URI) in microseconds.
 *
 * This information is calculated using total bitrate; if total bitrate is not in the
 * media container it is calculated using total duration and file size.
 *
 * Returns -1 when the extractor is not reading from a network data source, or when the
 * cached duration cannot be calculated (bitrate, duration, and file size information
 * not available).
 */
int64_t AMediaExtractor_getCachedDuration(AMediaExtractor *);

#endif /* __ANDROID_API__ >= 28 */

#endif /* __ANDROID_API__ >= 21 */

__END_DECLS
+3 −0
Original line number Diff line number Diff line
@@ -153,9 +153,12 @@ LIBMEDIANDK {
    AMediaDrm_verify;
    AMediaExtractor_advance;
    AMediaExtractor_delete;
    AMediaExtractor_getCachedDuration; # introduced=28
    AMediaExtractor_getFileFormat;     # introduced=28
    AMediaExtractor_getPsshInfo;
    AMediaExtractor_getSampleCryptoInfo;
    AMediaExtractor_getSampleFlags;
    AMediaExtractor_getSampleSize;     # introduced=28
    AMediaExtractor_getSampleTime;
    AMediaExtractor_getSampleTrackIndex;
    AMediaExtractor_getTrackCount;