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

Commit 27dba52d authored by Alexy Joseph's avatar Alexy Joseph Committed by Gerrit - the friendly Code Review server
Browse files

libmediaplayerservice: Add support for PCM offloading

Add support for PCM offloading in MR1. The change
brings in support for both 16 bit and 24 bit
PCM offloading

Change-Id: I02cfb0be62d91e150b63c65e35eaad8d4744afdf

Conflicts:
	media/libmediaplayerservice/nuplayer/NuPlayer.cpp

Change-Id: If0d9f68890584eb2acdb50a4adacaf7807ce0e40
parent 14b2fd4e
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -267,10 +267,31 @@ status_t NuPlayer::GenericSource::initFromDataSource() {
    // Widevine sources might re-initialize crypto when starting, if we delay
    // this to start(), all data buffered during prepare would be wasted.
    // (We don't actually start reading until start().)
    if (mAudioTrack.mSource != NULL && mAudioTrack.mSource->start() != OK) {
    if (mAudioTrack.mSource != NULL) {
        bool overrideSourceStart = false;
        status_t status = false;
        sp<MetaData> audioMeta = NULL;
        audioMeta = mAudioTrack.mSource->getFormat();

        if (ExtendedUtils::is24bitPCMOffloadEnabled()) {
            if(ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
                overrideSourceStart = true;
            }
        }

        if (overrideSourceStart && audioMeta.get()) {
            ALOGV("Override AudioTrack source with Meta");
            status = mAudioTrack.mSource->start(audioMeta.get());
        } else {
            ALOGV("Do not override AudioTrack source with Meta");
            status = mAudioTrack.mSource->start();
        }

        if (status != OK ) {
            ALOGE("failed to start audio track!");
            return UNKNOWN_ERROR;
        }
    }

    if (mVideoTrack.mSource != NULL && mVideoTrack.mSource->start() != OK) {
        ALOGE("failed to start video track!");
@@ -335,6 +356,7 @@ void NuPlayer::GenericSource::prepareAsync() {

void NuPlayer::GenericSource::onPrepareAsync() {
    // delayed data source creation
    ALOGV("%s", __func__);
    if (mDataSource == NULL) {
        // set to false first, if the extractor
        // comes back as secure, set it to true then.
+48 −34
Original line number Diff line number Diff line
@@ -910,7 +910,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                ALOGV("media rendering started");
                notifyListener(MEDIA_STARTED, 0, 0);
            } else if (what == Renderer::kWhatAudioOffloadTearDown) {
                ALOGV("Tear down audio offload, fall back to s/w path if due to error.");
                ALOGI("Tear down audio offload, fall back to s/w path if due to error.");
                int64_t positionUs;
                CHECK(msg->findInt64("positionUs", &positionUs));
                int32_t reason;
@@ -1065,19 +1065,20 @@ void NuPlayer::onStart() {
            instantiateDecoder(true, &mAudioDecoder);
        }
    }

    bool overrideSourceStart = false;
    if (ExtendedUtils::is24bitPCMOffloadEnabled()) {
	//if 24 bit offloading is enabled and if its such a use
	//case do not call start since this will be called
	//after openAudioSink
        sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
		 overrideSourceStart = ExtendedUtils::is24bitPCMOffloaded(audioMeta);
        if (ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
            ALOGI("Override source start");
            overrideSourceStart = true;
        }
    }

    if (overrideSourceStart) {
	    ALOGV("%s: Do not start source, wait till openAudioSink");
	} else {
    if (!overrideSourceStart) {
        mSource->start();
    } else {
        //ignore start, this is called just before sink is opened
    }

    uint32_t flags = 0;
@@ -1108,7 +1109,7 @@ void NuPlayer::onStart() {
        }
    mOffloadAudio =
                ((mime && !ExtendedUtils::pcmOffloadException(mime)) &&
                canOffloadStream(audioMeta, (videoFormat != NULL), vMeta,
                canOffloadStream(audioPCMMeta, (videoFormat != NULL), vMeta,
                        mIsStreaming /* is_streaming */, streamType));
        mOffloadDecodedPCM = mOffloadAudio;
        ALOGI("Could not offload audio decode, pcm offload decided :%d",
@@ -1247,6 +1248,15 @@ void NuPlayer::tryOpenAudioSinkForOffload(const sp<AMessage> &format, bool hasVi
    // Note: This is called early in NuPlayer to determine whether offloading
    // is possible; otherwise the decoders call the renderer openAudioSink directly.

    //update bit width before opening audio sink
    if (ExtendedUtils::is24bitPCMOffloadEnabled()) {
        sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
        if (ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
            ALOGV("overriding format with 24 bits");
            format->setInt32("sbit", 24);
        }
    }

    status_t err = mRenderer->openAudioSink(
            format, true /* offloadOnly */, hasVideo, AUDIO_OUTPUT_FLAG_NONE, mIsStreaming, &mOffloadAudio);
    if (err != OK) {
@@ -1309,20 +1319,24 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
        sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);

        if (mOffloadAudio && !mOffloadDecodedPCM) {
             if(ExtendedUtils::is24bitPCMOffloadEnabled() &&
			         ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
                         //if offloaded, configure source for 24 bit
            if (ExtendedUtils::is24bitPCMOffloadEnabled()) {
                sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
                if (ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
                    ALOGV("Overriding PCM format with 24 bit and calling start");
                    ExtendedUtils::setKeyPCMFormat(audioMeta, AUDIO_FORMAT_PCM_8_24_BIT);
                    mSource->start();
                }
            }
            *decoder = new DecoderPassThrough(notify, mSource, mRenderer);
        } else {
             if(ExtendedUtils::is24bitPCMOffloadEnabled() &&
			         ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
                         //if NOT offloaded, configure source for 16 bit
            if (ExtendedUtils::is24bitPCMOffloadEnabled()) {
                sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
                if (ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
                    ALOGV("Setting 16 bit in case session is not offloaded");
                    ExtendedUtils::setKeyPCMFormat(audioMeta, AUDIO_FORMAT_PCM_16_BIT);
                    mSource->start();
                }
            }
            *decoder = new Decoder(notify, mSource, mRenderer);
        }
    } else {
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@

#include "ATSParser.h"

#include "ExtendedUtils.h"

namespace android {

// TODO optimize buffer size for power consumption
@@ -80,6 +82,13 @@ void NuPlayer::DecoderPassThrough::onConfigure(const sp<AMessage> &format) {
    // The audio sink is already opened before the PassThrough decoder is created.
    // Opening again might be relevant if decoder is instantiated after shutdown and
    // format is different.
    if (ExtendedUtils::is24bitPCMOffloadEnabled()) {
        sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);
        if (ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
            format->setInt32("sbit", 24);
        }
    }

    status_t err = mRenderer->openAudioSink(
            format, true /* offloadOnly */, false /* hasVideo */,
            AUDIO_OUTPUT_FLAG_NONE /* flags */, isStreaming, NULL /* isOffloaded */);
+1 −1
Original line number Diff line number Diff line
@@ -1896,7 +1896,7 @@ bool ExtendedUtils::is24bitPCMOffloaded(const sp<MetaData> &sMeta) {
   /* Return true, if
      1. 24 bit offload flag is enabled
      2. the bit stream is raw 
      3. this is a 24 bit PCM */
      3. this is 24 bit PCM */

    if (is24bitPCMOffloadEnabled() && isRAWFormat(sMeta) &&
        getPcmSampleBits(sMeta) == 24) {
+1 −1
Original line number Diff line number Diff line
@@ -796,7 +796,7 @@ bool canOffloadStream(const sp<MetaData>& meta, bool hasVideo, const sp<MetaData
    if(meta->findInt32(kKeySampleBits, &bitWidth) && 24 == bitWidth)
        ALOGV("%s Bits per sample is 24", __func__);
    else
        ALOGW("%s No Sample Bit info in meta data", __func__);
        ALOGV("%s Sample Bit info in meta data is %d", __func__, bitWidth);
#endif
#endif
    if (mapMimeToAudioFormat(info.format, mime) != OK) {