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

Commit 10c638d2 authored by vivek mehta's avatar vivek mehta Committed by Gerrit - the friendly Code Review server
Browse files

libmedia : audio: handle set playback rate when direct pcm used

- In direct PCM usecase if setplayback rate is called then
  invalidate the common block and send empty offload structure
  below to use default path.

CRs-Fixed: 916660
Change-Id: I6df7c10b7115c77a19564e2f9fabc511d76a2410
parent 27194a9a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -942,6 +942,7 @@ protected:
    // For Device Selection API
    //  a value of AUDIO_PORT_HANDLE_NONE indicated default (AudioPolicyManager) routing.
    audio_port_handle_t     mSelectedDeviceId;
    bool                    mPlaybackRateSet;

private:
    class DeathNotifier : public IBinder::DeathRecipient {
+23 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <media/AudioPolicyHelper.h>
#include <media/AudioResamplerPublic.h>
#include "media/AVMediaExtensions.h"
#include <cutils/properties.h>

#define WAIT_PERIOD_MS                  10
#define WAIT_STREAM_END_TIMEOUT_SEC     120
@@ -168,7 +169,8 @@ AudioTrack::AudioTrack()
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE)
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mPlaybackRateSet(false)
{
    mAttributes.content_type = AUDIO_CONTENT_TYPE_UNKNOWN;
    mAttributes.usage = AUDIO_USAGE_UNKNOWN;
@@ -198,7 +200,8 @@ AudioTrack::AudioTrack(
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE)
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mPlaybackRateSet(false)
{
    mStatus = set(streamType, sampleRate, format, channelMask,
            frameCount, flags, cbf, user, notificationFrames,
@@ -228,7 +231,8 @@ AudioTrack::AudioTrack(
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE)
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mPlaybackRateSet(false)
{
    mStatus = set(streamType, sampleRate, format, channelMask,
            0 /*frameCount*/, flags, cbf, user, notificationFrames,
@@ -844,6 +848,15 @@ status_t AudioTrack::setPlaybackRate(const AudioPlaybackRate &playbackRate)
    //set effective rates
    mProxy->setPlaybackRate(playbackRateTemp);
    mProxy->setSampleRate(effectiveRate); // FIXME: not quite "atomic" with setPlaybackRate

    // fallback out of Direct PCM if setPlaybackRate is called on PCM track
    if (property_get_bool("audio.offload.track.enable", false) &&
        (mFormat == AUDIO_FORMAT_PCM_16_BIT) && (mOffloadInfo == NULL) &&
        (mFlags == AUDIO_OUTPUT_FLAG_NONE)) {
        mPlaybackRateSet = true;
        android_atomic_or(CBLK_INVALID, &mCblk->mFlags);
    }

    return NO_ERROR;
}

@@ -1135,11 +1148,16 @@ status_t AudioTrack::createTrack_l()
    audio_stream_type_t streamType = mStreamType;
    audio_attributes_t *attr = (mStreamType == AUDIO_STREAM_DEFAULT) ? &mAttributes : NULL;

    status_t status;
    status = AudioSystem::getOutputForAttr(attr, &output,
    audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER;
    if (mPlaybackRateSet == true && mOffloadInfo == NULL && mFormat == AUDIO_FORMAT_PCM_16_BIT) {
        mOffloadInfo = &tOffloadInfo;
    }
    status_t status = AudioSystem::getOutputForAttr(attr, &output,
                                           (audio_session_t)mSessionId, &streamType, mClientUid,
                                           mSampleRate, mFormat, mChannelMask,
                                           mFlags, mSelectedDeviceId, mOffloadInfo);
    //reset offload info if forced
    mOffloadInfo = (mOffloadInfo == &tOffloadInfo) ? NULL : mOffloadInfo;

    if (status != NO_ERROR || output == AUDIO_IO_HANDLE_NONE) {
        ALOGE("Could not get audio output for session %d, stream type %d, usage %d, sample rate %u, format %#x,"