diff --git a/audio/alsa_utils/alsa_device_proxy.c b/audio/alsa_utils/alsa_device_proxy.c index e53ab10..9084080 100644 --- a/audio/alsa_utils/alsa_device_proxy.c +++ b/audio/alsa_utils/alsa_device_proxy.c @@ -385,7 +385,8 @@ int proxy_get_presentation_position(const alsa_device_proxy * proxy, struct timespec alsaTs; if (proxy->pcm != NULL && pcm_get_htimestamp(proxy->pcm, &avail, &alsaTs) == 0) { - const size_t kernel_buffer_size = pcm_get_buffer_size(proxy->pcm); + const size_t kernel_buffer_size = proxy->alsa_config.period_count + * proxy->alsa_config.period_size; if (avail > kernel_buffer_size) { // pcm_get_htimestamp() computes the available frames by comparing the ALSA driver // hw_ptr and the appl_ptr levels. In underrun, the hw_ptr may keep running and report @@ -402,6 +403,8 @@ int proxy_get_presentation_position(const alsa_device_proxy * proxy, // It is possible to compensate for additional driver and device delay // by changing signed_frames. Example: // signed_frames -= 20 /* ms */ * proxy->alsa_config.rate / 1000; + signed_frames -= proxy->alsa_config.period_count + * proxy->alsa_config.period_size; // start_threshold if (signed_frames >= 0) { *frames = signed_frames; ret = 0; @@ -419,7 +422,8 @@ int hdmi_proxy_get_presentation_position(const alsa_device_proxy * proxy, struct timespec alsaTs; if (proxy->pcm_alsa != NULL && snd_pcm_htimestamp(proxy->pcm_alsa, &avail, &alsaTs) == 0) { - const snd_pcm_uframes_t kernel_buffer_size = proxy->alsa_config.period_count * proxy->alsa_config.period_size * 2; + const snd_pcm_uframes_t kernel_buffer_size = proxy->alsa_config.period_count + * proxy->alsa_config.period_size * 2; if (avail > kernel_buffer_size) { // pcm_get_htimestamp() computes the available frames by comparing the ALSA driver // hw_ptr and the appl_ptr levels. In underrun, the hw_ptr may keep running and report @@ -436,7 +440,8 @@ int hdmi_proxy_get_presentation_position(const alsa_device_proxy * proxy, // It is possible to compensate for additional driver and device delay // by changing signed_frames. Example: // signed_frames -= 20 /* ms */ * proxy->alsa_config.rate / 1000; - signed_frames -= EXTRA_START_THRESHOLD; + signed_frames -= proxy->alsa_config.period_count + * proxy->alsa_config.period_size + EXTRA_START_THRESHOLD; // start_threshold if (signed_frames >= 0) { *frames = signed_frames; ret = 0; diff --git a/audio/primary/StreamPrimary.cpp b/audio/primary/StreamPrimary.cpp index 7a2b0c8..2c1eb6d 100644 --- a/audio/primary/StreamPrimary.cpp +++ b/audio/primary/StreamPrimary.cpp @@ -133,9 +133,8 @@ StreamPrimary::StreamPrimary(StreamContext* context, const Metadata& metadata) return ::android::OK; } -::android::status_t StreamPrimary::refinePosition(StreamDescriptor::Position*) { - // Since not all data is actually sent to the HAL, use the position maintained by Stream class - // which accounts for all frames passed from / to the client. +::android::status_t StreamPrimary::refinePosition(StreamDescriptor::Position* position) { + RETURN_STATUS_IF_ERROR(StreamAlsa::refinePosition(position)); return ::android::OK; }