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

Commit 2b01f009 authored by Andy Hung's avatar Andy Hung
Browse files

Replace old audio time conversion macros and functions

Test: Play Movies, Youtube, CTS
Bug: 25569135
Change-Id: Ib6e304f149c381dc7af7f4aa959c3d79d7bdb2aa
parent 38217e0d
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <math.h>
#include <sys/resource.h>

#include <audio_utils/clock.h>
#include <audio_utils/primitives.h>
#include <binder/IPCThreadState.h>
#include <media/AudioTrack.h>
@@ -62,11 +63,6 @@ static int64_t convertTimespecToUs(const struct timespec &tv)
    return tv.tv_sec * 1000000ll + tv.tv_nsec / 1000;
}

static inline nsecs_t convertTimespecToNs(const struct timespec &tv)
{
    return tv.tv_sec * (long long)NANOS_PER_SECOND + tv.tv_nsec;
}

// current monotonic time in microseconds.
static int64_t getNowUs()
{
@@ -2563,7 +2559,7 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
                // We update the timestamp time even when paused.
                if (mState == STATE_PAUSED /* not needed: STATE_PAUSED_STOPPING */) {
                    const int64_t now = systemTime();
                    const int64_t at = convertTimespecToNs(timestamp.mTime);
                    const int64_t at = audio_utils_ns_from_timespec(&timestamp.mTime);
                    const int64_t lag =
                            (ets.mTimeNs[ExtendedTimestamp::LOCATION_SERVER_LASTKERNELOK] < 0 ||
                                ets.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL_LASTKERNELOK] < 0)
@@ -2695,8 +2691,9 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
    // This is sometimes caused by erratic reports of the available space in the ALSA drivers.
    if (status == NO_ERROR) {
        if (previousTimestampValid) {
            const int64_t previousTimeNanos = convertTimespecToNs(mPreviousTimestamp.mTime);
            const int64_t currentTimeNanos = convertTimespecToNs(timestamp.mTime);
            const int64_t previousTimeNanos =
                    audio_utils_ns_from_timespec(&mPreviousTimestamp.mTime);
            const int64_t currentTimeNanos = audio_utils_ns_from_timespec(&timestamp.mTime);
            if (currentTimeNanos < previousTimeNanos) {
                ALOGW("retrograde timestamp time corrected, %lld < %lld",
                        (long long)currentTimeNanos, (long long)previousTimeNanos);
@@ -2726,7 +2723,7 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
#if 0
            // Uncomment this to verify audio timestamp rate.
            const int64_t deltaTime =
                    convertTimespecToNs(timestamp.mTime) - previousTimeNanos;
                    audio_utils_ns_from_timespec(&timestamp.mTime) - previousTimeNanos;
            if (deltaTime != 0) {
                const int64_t computedSampleRate =
                        deltaPosition * (long long)NANOS_PER_SECOND / deltaTime;
+2 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0

#include <utils/Log.h>
#include <audio_utils/clock.h>
#include <media/audiohal/StreamHalInterface.h>
#include <media/nbaio/AudioStreamOutSink.h>

@@ -82,8 +83,7 @@ status_t AudioStreamOutSink::getTimestamp(ExtendedTimestamp &timestamp)
        return INVALID_OPERATION;
    }
    timestamp.mPosition[ExtendedTimestamp::LOCATION_KERNEL] = position64;
    timestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL] =
            time.tv_sec * 1000000000LL + time.tv_nsec;
    timestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL] = audio_utils_ns_from_timespec(&time);
    return OK;
}

+0 −4
Original line number Diff line number Diff line
@@ -50,10 +50,6 @@
#define ALOGVV(a...) do { } while(0)
#endif

// TODO move to a common header  (Also shared with AudioTrack.cpp)
#define NANOS_PER_SECOND    1000000000
#define TIME_TO_NANOS(time) ((uint64_t)(time).tv_sec * NANOS_PER_SECOND + (time).tv_nsec)

namespace android {

// ----------------------------------------------------------------------------