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

Commit 29b1fab8 authored by Steve Kondik's avatar Steve Kondik
Browse files

Revert "libmediaplayerservice: Add support for PCM offloading"

 * Needs refactor

This reverts commit 27dba52d.

Change-Id: Ib6802c5a220e840f1049bb837e2b2e13ec5419e7
parent aa3a3946
Loading
Loading
Loading
Loading
+3 −25
Original line number Diff line number Diff line
@@ -267,31 +267,10 @@ 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) {
        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 ) {
    if (mAudioTrack.mSource != NULL && mAudioTrack.mSource->start() != OK) {
        ALOGE("failed to start audio track!");
        return UNKNOWN_ERROR;
    }
    }

    if (mVideoTrack.mSource != NULL && mVideoTrack.mSource->start() != OK) {
        ALOGE("failed to start video track!");
@@ -356,7 +335,6 @@ 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.
+34 −48
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) {
                ALOGI("Tear down audio offload, fall back to s/w path if due to error.");
                ALOGV("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,20 +1065,19 @@ 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 */);
        if (ExtendedUtils::is24bitPCMOffloaded(audioMeta)) {
            ALOGI("Override source start");
            overrideSourceStart = true;
        }
		 overrideSourceStart = ExtendedUtils::is24bitPCMOffloaded(audioMeta);
	}

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

    uint32_t flags = 0;
@@ -1109,7 +1108,7 @@ void NuPlayer::onStart() {
        }
    mOffloadAudio =
                ((mime && !ExtendedUtils::pcmOffloadException(mime)) &&
                canOffloadStream(audioPCMMeta, (videoFormat != NULL), vMeta,
                canOffloadStream(audioMeta, (videoFormat != NULL), vMeta,
                        mIsStreaming /* is_streaming */, streamType));
        mOffloadDecodedPCM = mOffloadAudio;
        ALOGI("Could not offload audio decode, pcm offload decided :%d",
@@ -1248,15 +1247,6 @@ 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) {
@@ -1319,24 +1309,20 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
        sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */);

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

#include "ATSParser.h"

#include "ExtendedUtils.h"

namespace android {

// TODO optimize buffer size for power consumption
@@ -82,13 +80,6 @@ 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 */);
+0 −3
Original line number Diff line number Diff line
@@ -1506,9 +1506,6 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
                    "audio_format", mime.c_str());
            onDisableOffloadAudio();
        } else {
                    audioFormat = AUDIO_FORMAT_PCM_24_BIT_OFFLOAD;
                } else if (ExtendedUtils::is16bitPCMOffloadEnabled()) {
                    bitWidth = 16;
#ifdef ENABLE_AV_ENHANCEMENTS
            if (pcmOffload) {
                if (bitsPerSample > 16) {
+1 −1
Original line number Diff line number Diff line
@@ -1987,7 +1987,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 24 bit PCM */
      3. this is a 24 bit PCM */

    if (is24bitPCMOffloadEnabled() && isRAWFormat(sMeta) &&
        getPcmSampleBits(sMeta) == 24) {