New AudioTrack C++ API for audio timestamps

This new API is intended to replace latency(), especially for A/V sync.
The application will receive periodic timestamp notifications.  The period
is unspecified, but will likely be more frequent after a pause or stop,
set position, underrun, display on/off change, route change, or when audio
framework notices drift.  It will be up to the higher level application
(e.g.  Stagefright) to reconstruct a clock that updates more frequently.

The current latency() method doesn't indicate when latency changes
due to screen on/off state, route changes, etc.

Includes squahsed change-Id: I2082f8752040be0c234b1a6f1be2e269abf2ce7c
 Dummy implementation of AudioTrack:getTimestamp()
 Rename AudioTrack::Timestamp to AudioTimestamp.
 Renaming and pulling up to a higher level allows more modules to use it.

Change-Id: Ibf7f6a207c3f8d8697f25ede2cd5200697fadb86
(cherry picked from commit dd69eb893867634fd169c03204a6ad7c74b351e7)
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index ae92cdd..ebb7ef3 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -19,6 +19,7 @@
 
 #include <cutils/sched_policy.h>
 #include <media/AudioSystem.h>
+#include <media/AudioTimestamp.h>
 #include <media/IAudioTrack.h>
 #include <utils/threads.h>
 
@@ -62,6 +63,9 @@
                                     // voluntary invalidation by mediaserver, or mediaserver crash.
         EVENT_STREAM_END = 7,       // Sent after all the buffers queued in AF and HW are played
                                     // back (after stop is called)
+        EVENT_NEW_TIMESTAMP = 8,    // Delivered periodically and when there's a significant change
+                                    // in the mapping from frame position to presentation time.
+                                    // See AudioTimestamp for the information included with event.
     };
 
     /* Client should declare Buffer on the stack and pass address to obtainBuffer()
@@ -107,6 +111,8 @@
      *          - EVENT_NEW_POS: pointer to const uint32_t containing the new position in frames.
      *          - EVENT_BUFFER_END: unused.
      *          - EVENT_NEW_IAUDIOTRACK: unused.
+     *          - EVENT_STREAM_END: unused.
+     *          - EVENT_NEW_TIMESTAMP: pointer to const AudioTimestamp.
      */
 
     typedef void (*callback_t)(int event, void* user, void *info);
@@ -564,6 +570,16 @@
     /* Get parameters */
             String8     getParameters(const String8& keys);
 
+    /* Poll for a timestamp on demand.
+     * Use if EVENT_NEW_TIMESTAMP is not delivered often enough for your needs,
+     * or if you need to get the most recent timestamp outside of the event callback handler.
+     * Caution: calling this method too often may be inefficient;
+     * if you need a high resolution mapping between frame position and presentation time,
+     * consider implementing that at application level, based on the low resolution timestamps.
+     * Returns NO_ERROR if timestamp is valid.
+     */
+            status_t    getTimestamp(AudioTimestamp& timestamp);
+
 protected:
     /* copying audio tracks is not allowed */
                         AudioTrack(const AudioTrack& other);