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

Commit d4633767 authored by Weiyin Jiang's avatar Weiyin Jiang Committed by Gerrit - the friendly Code Review server
Browse files

audio: revert the calculation of out_get_presentation_position

Revert the calcaulation of out_get_presentation_position for ULL/MMAP
streams as it used to be. This fixes frame being reset during standby.
Using hw_ptr instead of frames written causes a state mismatch between
HAL and AudioFlinger leading spurious error reported by AudioTrack.

CRs-Fixed: 2207829
Change-Id: I3701b8f440651313659cd2b917230ff78542e1b4
parent ba3b49df
Loading
Loading
Loading
Loading
+19 −35
Original line number Diff line number Diff line
@@ -4651,31 +4651,14 @@ static int out_get_presentation_position(const struct audio_stream_out *stream,
        clock_gettime(CLOCK_MONOTONIC, timestamp);
    } else {
        if (out->pcm) {
            int64_t signed_frames = -1;
            // XXX it might be better to identify these
            // as realtime usecases?
            if (out->usecase == USECASE_AUDIO_PLAYBACK_MMAP ||
                out->usecase == USECASE_AUDIO_PLAYBACK_ULL) {
                unsigned int hw_ptr;
                if (pcm_mmap_get_hw_ptr(out->pcm, &hw_ptr, timestamp) == 0) {
                    signed_frames = hw_ptr;
                }
                ALOGV("%s frames %lld", __func__, (long long)signed_frames);
            } else {
            unsigned int avail;
            if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) {
                    size_t kernel_buffer_size =
                            out->config.period_size * out->config.period_count;
                     signed_frames =
                            out->written - kernel_buffer_size + avail;
                }
            }

                size_t kernel_buffer_size = out->config.period_size * out->config.period_count;
                int64_t signed_frames = out->written - kernel_buffer_size + avail;
                // This adjustment accounts for buffering after app processor.
                // It is based on estimated DSP latency per use case, rather than exact.
                signed_frames -=
                    (platform_render_latency(out->usecase) *
                     out->sample_rate / 1000000LL);
                        (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL);

                // Adjustment accounts for A2dp encoder latency with non offload usecases
                // Note: Encoder latency is returned in ms, while platform_render_latency in us.
@@ -4689,6 +4672,7 @@ static int out_get_presentation_position(const struct audio_stream_out *stream,
                    *frames = signed_frames;
                    ret = 0;
                }
            }
        } else if (out->card_status == CARD_STATUS_OFFLINE) {
            *frames = out->written;
            clock_gettime(CLOCK_MONOTONIC, timestamp);