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

Commit ceb8b69d authored by Alin Jerpelea's avatar Alin Jerpelea
Browse files

ST_ERICSSON: support for latency

manualy ported from
commit e8cfc22c08e32b463186362ed40abb4d34eedca8
Author: Naveen Agarwal <naveen.agarwal@stericsson.com>
Date:   Thu Apr 5 21:06:59 2012 +0000

    Add support for update of audio output latency on Snowball

    Adds mechanisms enabling AudioPlayer to receive updated latency values
    for the audio output. The possibility to update the latency value is
    needed because the latency values for some devices (e.g., A2DP devices)
    are not known until they have been opened. Latency value updates will
    also occur when output device is exchanged on-the-fly during playback
    (e.g., audio output is moved from headset to A2DP device).

    This patch modifies the MediaPlayerService::open() function declaration
    which is part of an Android internal interface. Although, this is a
    backward compatible change since only a default parameter is added.

    ST-Ericsson ID: 372587

    ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-12221

    Introduce backward compatible changes to exposed interfaces

Change-Id: I0ac7eb7647d00c92719078aa5260d37fea795f15
parent 8769c86b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -46,6 +46,9 @@ public:
    static const char *keyChannels;
    static const char *keyFrameCount;
    static const char *keyInputSource;
#ifdef STE_HARDWARE
    static const char *keyLatency;
#endif

    String8 toString();

+19 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ namespace android {

typedef void (*audio_error_callback)(status_t err);

#ifdef STE_HARDWARE
typedef void (*latency_update_callback)(void *cookie, audio_io_handle_t output, uint32_t latency);
#endif
class IAudioPolicyService;
class String8;

@@ -110,6 +113,10 @@ public:
    static int newAudioSessionId();
    static void acquireAudioSessionId(int audioSession);
    static void releaseAudioSessionId(int audioSession);
#ifdef STE_HARDWARE
    static int registerLatencyNotificationClient(latency_update_callback cb, void *cookie);
    static void unregisterLatencyNotificationClient(int clientId);
#endif

    // types of io configuration change events received with ioConfigChanged()
    enum io_config_event {
@@ -239,6 +246,13 @@ private:
        virtual void binderDied(const wp<IBinder>& who);
    };

#ifdef STE_HARDWARE
    struct NotificationClient : public RefBase {
        latency_update_callback mCb;
        void * mCookie;
    };
#endif

    static sp<AudioFlingerClient> gAudioFlingerClient;
    static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
    friend class AudioFlingerClient;
@@ -261,6 +275,11 @@ private:
    // list of output descriptors containing cached parameters
    // (sampling rate, framecount, channel count...)
    static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
#ifdef STE_HARDWARE
    static Mutex gLatencyLock;
    static int gNextUniqueLatencyId;
    static DefaultKeyedVector<int, sp<AudioSystem::NotificationClient> > gLatencyNotificationClients;
#endif
};

};  // namespace android
+12 −0
Original line number Diff line number Diff line
@@ -55,7 +55,12 @@ public:
        EVENT_LOOP_END = 2,         // Sample loop end was reached; playback restarted from loop start if loop count was not 0.
        EVENT_MARKER = 3,           // Playback head is at the specified marker position (See setMarkerPosition()).
        EVENT_NEW_POS = 4,          // Playback head is at a new position (See setPositionUpdatePeriod()).
#ifdef STE_HARDWARE
        EVENT_BUFFER_END = 5,       // Playback head is at the end of the buffer.
        EVENT_LATENCY_CHANGED = 6   // Audio output has been reconfigured and latency has changed.
#else
        EVENT_BUFFER_END = 5        // Playback head is at the end of the buffer.
#endif
    };

    /* Create Buffer on the stack and pass it to obtainBuffer()
@@ -480,6 +485,10 @@ private:
            status_t setLoop_l(uint32_t loopStart, uint32_t loopEnd, int loopCount);
            audio_io_handle_t getOutput_l();
            status_t restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart);
#ifdef STE_HARDWARE
    static void LatencyCallbackWrapper(void *cookie, audio_io_handle_t output, uint32_t latency);
    void latencyCallback(audio_io_handle_t output, uint32_t latency);
#endif

    sp<IAudioTrack>         mAudioTrack;
    sp<IMemory>             mCblkMemory;
@@ -521,6 +530,9 @@ private:
    int                     mAuxEffectId;
    Mutex                   mLock;
    status_t                mRestoreStatus;
#ifdef STE_HARDWARE
    int                     mLatencyClientId;
#endif
};


+8 −0
Original line number Diff line number Diff line
@@ -68,6 +68,9 @@ public:
        // Callback returns the number of bytes actually written to the buffer.
        typedef size_t (*AudioCallback)(
                AudioSink *audioSink, void *buffer, size_t size, void *cookie);
#ifdef STE_HARDWARE
        typedef void (*LatencyCallback)(uint32_t latency, void *cookie);
#endif

        virtual             ~AudioSink() {}
        virtual bool        ready() const = 0; // audio output is open and ready
@@ -88,7 +91,12 @@ public:
                int format=AUDIO_FORMAT_PCM_16_BIT,
                int bufferCount=DEFAULT_AUDIOSINK_BUFFERCOUNT,
                AudioCallback cb = NULL,
#ifdef STE_HARDWARE
                void *cookie = NULL,
                LatencyCallback latencyCb = NULL) = 0;
#else
                void *cookie = NULL) = 0;
#endif

#ifdef WITH_QCOM_LPA
        // API to open a routing session for tunneled audio playback
+4 −0
Original line number Diff line number Diff line
@@ -104,6 +104,10 @@ private:
            MediaPlayerBase::AudioSink *audioSink,
            void *data, size_t size, void *me);

#ifdef STE_HARDWARE
    static void LatencyCallback(uint32_t latency, void *cookie);
#endif

    size_t fillBuffer(void *data, size_t size);

    int64_t getRealTimeUsLocked() const;
Loading