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

Commit ad0fe922 authored by Vlad Popa's avatar Vlad Popa
Browse files

AudioTrack: Report port ID updates to AudioService

The port mapping needs to be set every time a new track is
created/restored and after the first time the piid is created.

This way we can inform the upper layers about changes the happen for a
track with the specified port id

Test: adb shell dumpsys audio
Bug: 235521198
Change-Id: I576c4375e6c1b3c2add07876f66a390c97d20fce
parent 9c2642df
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <audio_utils/clock.h>
#include <audio_utils/primitives.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <media/AudioTrack.h>
#include <utils/Log.h>
#include <private/media/AudioTrackShared.h>
@@ -42,7 +43,9 @@

#define WAIT_PERIOD_MS                  10
#define WAIT_STREAM_END_TIMEOUT_SEC     120

static const int kMaxLoopCountNotifications = 32;
static constexpr char kAudioServiceName[] = "audio";

using ::android::aidl_utils::statusTFromBinderStatus;
using ::android::base::StringPrintf;
@@ -1945,6 +1948,9 @@ status_t AudioTrack::createTrack_l()
    }

    mPortId = output.portId;
    // notify the upper layers about the new portId
    triggerPortIdUpdate_l();

    // We retain a copy of the I/O handle, but don't own the reference
    mOutput = output.outputId;
    mRefreshRemaining = true;
@@ -3507,12 +3513,34 @@ void AudioTrack::setPlayerIId(int playerIId)
    if (mPlayerIId == playerIId) return;

    mPlayerIId = playerIId;
    triggerPortIdUpdate_l();
    mediametrics::LogItem(mMetricsId)
        .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_SETPLAYERIID)
        .set(AMEDIAMETRICS_PROP_PLAYERIID, playerIId)
        .record();
}

void AudioTrack::triggerPortIdUpdate_l() {
    if (mAudioManager == nullptr) {
        // use checkService() to avoid blocking if audio service is not up yet
        sp<IBinder> binder =
            defaultServiceManager()->checkService(String16(kAudioServiceName));
        if (binder == nullptr) {
            ALOGE("%s(%d): binding to audio service failed.",
                  __func__,
                  mPlayerIId);
            return;
        }

        mAudioManager = interface_cast<IAudioManager>(binder);
    }

    // first time when the track is created we do not have a valid piid
    if (mPlayerIId != PLAYER_PIID_INVALID) {
        mAudioManager->playerEvent(mPlayerIId, PLAYER_UPDATE_PORT_ID, mPortId);
    }
}

status_t AudioTrack::addAudioDeviceCallback(const sp<AudioSystem::AudioDeviceCallback>& callback)
{

+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef ANDROID_AUDIOTRACK_H
#define ANDROID_AUDIOTRACK_H

#include <audiomanager/IAudioManager.h>
#include <binder/IMemory.h>
#include <cutils/sched_policy.h>
#include <media/AudioSystem.h>
@@ -1145,6 +1146,8 @@ public:
            void setAudioTrackCallback(const sp<media::IAudioTrackCallback>& callback) {
                mAudioTrackCallback->setAudioTrackCallback(callback);
            }
 private:
            void triggerPortIdUpdate_l();

 protected:
    /* copying audio tracks is not allowed */
@@ -1419,6 +1422,9 @@ public:
     */
    int                     mPlayerIId = -1;  // AudioManager.h PLAYER_PIID_INVALID

    /** Interface for interacting with the AudioService. */
    sp<IAudioManager>       mAudioManager;

    /**
     * mLogSessionId is a string identifying this AudioTrack for the metrics service.
     * It may be unique or shared with other objects.  An empty string means the