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

Commit c1895144 authored by Steve Kondik's avatar Steve Kondik
Browse files

nuplayer: Avoid PCM offload when resampler is used

 * We don't support use of the resampler on the PCM offload path,
   this kind of defeats the purpose. While the offload output path
   handles most sample rates, there are cases such as Facebook's
   video preview which use weird formats like 24000KHz mono.
 * To resolve this in NuPlayer, compare metadata from the original
   format with the output format decided by the audio system. Fail
   offload if they don't match.

Change-Id: Ibf7c3a2fa4f54b56c39cc69b1ff6b474738ee339
parent e557bb35
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -1168,10 +1168,32 @@ void NuPlayer::openAudioSink(const sp<AMessage> &format, bool offloadOnly) {
        flags = AUDIO_OUTPUT_FLAG_NONE;
    }


    format->setInt64("durationUs", durationUs);

    ALOGV("openAudioSink: format=%s", format->debugString().c_str());
    // avoid PCM offload when resampler is used
    bool resampled = false;
    sp<MetaData> audioMeta = mSource->getFormatMeta(true);

    AString mime;
    CHECK(format->findString("mime", &mime));
    if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_RAW)) {
        int32_t srcBitsPerSample, bitsPerSample = 16;
        int32_t srcChannels, channels = 0;
        int32_t srcSampleRate, sampleRate = 0;
        audioMeta->findInt32(kKeyBitsPerSample, &srcBitsPerSample);
        format->findInt32("bits-per-sample", &bitsPerSample);
        audioMeta->findInt32(kKeyChannelCount, &srcChannels);
        format->findInt32("channel-count", &channels);
        audioMeta->findInt32(kKeySampleRate, &srcSampleRate);
        format->findInt32("sample-rate", &sampleRate);

        resampled = !((srcBitsPerSample == bitsPerSample) &&
                      (srcChannels == channels) &&
                      (srcSampleRate == sampleRate));
        format->setInt32("resampled", resampled);
    }

    ALOGV("openAudioSink: resampled=%d format=%s", resampled, format->debugString().c_str());

    mOffloadAudio = mRenderer->openAudioSink(
            format, offloadOnly, (mVideoDecoder != NULL), flags);
+4 −1
Original line number Diff line number Diff line
@@ -1394,8 +1394,11 @@ bool NuPlayer::Renderer::onOpenAudioSink(
    pcmOffload = ExtendedUtils::isPcmOffloadEnabled() &&
            !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_RAW);

    int32_t resampled = 0;
    format->findInt32("resampled", &resampled);

    // At this point we can check if PCM should be offloaded
    if (!offloadingAudio() && (!offloadOnly && pcmOffload)) {
    if (!offloadingAudio() && (!offloadOnly && pcmOffload && !resampled)) {
        sp<MetaData> aMeta = new MetaData;
        convertMessageToMetaData(format, aMeta);
        if  (canOffloadStream(aMeta, false, new MetaData,