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

Commit 94ed47c6 authored by jiabin's avatar jiabin
Browse files

Cache AudioFlinger track flags in client side.

Test: atest CtsMediaTestCases
Bug: 283221159
Change-Id: I7d33cdc752cc86c6d8f7734fb948d86b17b1af37
parent bec78753
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -817,7 +817,7 @@ status_t AudioTrack::start()
    (void) updateAndGetPosition_l();

    // save start timestamp
    if (isOffloadedOrDirect_l()) {
    if (isAfTrackOffloadedOrDirect_l()) {
        if (getTimestamp_l(mStartTs) != OK) {
            mStartTs.mPosition = 0;
        }
@@ -838,7 +838,7 @@ status_t AudioTrack::start()
        mTimestampStaleTimeReported = false;
        mPreviousLocation = ExtendedTimestamp::LOCATION_INVALID;

        if (!isOffloadedOrDirect_l()
        if (!isAfTrackOffloadedOrDirect_l()
                && mStartEts.mTimeNs[ExtendedTimestamp::LOCATION_SERVER] > 0) {
            // Server side has consumed something, but is it finished consuming?
            // It is possible since flush and stop are asynchronous that the server
@@ -1917,6 +1917,7 @@ status_t AudioTrack::createTrack_l()
    mAfChannelCount = audio_channel_count_from_out_mask(output.afChannelMask);
    mAfFormat = output.afFormat;
    mAfLatency = output.afLatencyMs;
    mAfTrackFlags = output.afTrackFlags;

    mLatency = mAfLatency + (1000LL * mFrameCount) / mSampleRate;

@@ -3182,7 +3183,7 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
    // To avoid a race, read the presented frames first.  This ensures that presented <= consumed.

    status_t status;
    if (isOffloadedOrDirect_l()) {
    if (isAfTrackOffloadedOrDirect_l()) {
        // use Binder to get timestamp
        media::AudioTimestampInternal ts;
        mAudioTrack->getTimestamp(&ts, &status);
@@ -3294,7 +3295,7 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
        ALOGV_IF(status != WOULD_BLOCK, "%s(%d): getTimestamp error:%#x", __func__, mPortId, status);
        return status;
    }
    if (isOffloadedOrDirect_l()) {
    if (isAfTrackOffloadedOrDirect_l()) {
        if (isOffloaded_l() && (mState == STATE_PAUSED || mState == STATE_PAUSED_STOPPING)) {
            // use cached paused position in case another offloaded track is running.
            timestamp.mPosition = mPausedPosition;
@@ -3740,7 +3741,7 @@ bool AudioTrack::hasStarted()
    // This is conservatively figured - if we encounter an unexpected error
    // then we will not wait.
    bool wait = false;
    if (isOffloadedOrDirect_l()) {
    if (isAfTrackOffloadedOrDirect_l()) {
        AudioTimestamp ts;
        status_t status = getTimestamp_l(ts);
        if (status == WOULD_BLOCK) {
+4 −0
Original line number Diff line number Diff line
@@ -116,6 +116,8 @@ IAudioFlinger::CreateTrackOutput::toAidl() const {
            legacy2aidl_audio_channel_mask_t_AudioChannelLayout(afChannelMask, false /*isInput*/));
    aidl.afFormat = VALUE_OR_RETURN(
            legacy2aidl_audio_format_t_AudioFormatDescription(afFormat));
    aidl.afTrackFlags = VALUE_OR_RETURN(
            legacy2aidl_audio_output_flags_t_int32_t_mask(afTrackFlags));
    aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId));
    aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
    aidl.audioTrack = audioTrack;
@@ -144,6 +146,8 @@ IAudioFlinger::CreateTrackOutput::fromAidl(
                                                                false /*isInput*/));
    legacy.afFormat = VALUE_OR_RETURN(
            aidl2legacy_AudioFormatDescription_audio_format_t(aidl.afFormat));
    legacy.afTrackFlags = VALUE_OR_RETURN(
            aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.afTrackFlags));
    legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId));
    legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
    legacy.audioTrack = aidl.audioTrack;
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ parcelable CreateTrackResponse {
    AudioChannelLayout afChannelMask;
    AudioFormatDescription afFormat;
    int afLatencyMs;
    int afTrackFlags;
    /** Interpreted as audio_io_handle_t. */
    int outputId;
    /** Interpreted as audio_port_handle_t. */
+6 −0
Original line number Diff line number Diff line
@@ -1238,6 +1238,11 @@ public:
            bool     isDirect_l() const
                { return (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0; }

            bool     isAfTrackOffloadedOrDirect_l() const
                { return isOffloadedOrDirect_l() ||
                        (mAfTrackFlags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|
                                AUDIO_OUTPUT_FLAG_DIRECT)) != 0; }

            // pure pcm data is mixable (which excludes HW_AV_SYNC, with embedded timing)
            bool     isPurePcmData_l() const
                { return audio_is_linear_pcm(mFormat)
@@ -1295,6 +1300,7 @@ public:
    uint32_t                mAfSampleRate;          // AudioFlinger sample rate
    uint32_t                mAfChannelCount;        // AudioFlinger channel count
    audio_format_t          mAfFormat;              // AudioFlinger format
    audio_output_flags_t    mAfTrackFlags;          // AudioFlinger track flags

    // constant after constructor or set()
    audio_format_t          mFormat;                // as requested by client, not forced to 16-bit
+1 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public:
        uint32_t afLatencyMs;
        audio_channel_mask_t afChannelMask;
        audio_format_t afFormat;
        audio_output_flags_t afTrackFlags;
        audio_io_handle_t outputId;
        audio_port_handle_t portId;
        sp<media::IAudioTrack> audioTrack;
Loading