Merge "Remove unnecessary backslashes at end of line"
diff --git a/audio/Android.bp b/audio/Android.bp
index bda39b4..010be18 100644
--- a/audio/Android.bp
+++ b/audio/Android.bp
@@ -20,3 +20,11 @@
         },
     }
 }
+
+filegroup {
+    name: "libaudio_system_audio_base",
+    srcs: [
+        "include/system/audio-base.h",
+    ],
+    path: "include",
+}
diff --git a/audio/include/system/audio.h b/audio/include/system/audio.h
index 27981dc..539fa4f 100644
--- a/audio/include/system/audio.h
+++ b/audio/include/system/audio.h
@@ -124,24 +124,31 @@
 }
 
 
-/* a unique ID allocated by AudioFlinger for use as an audio_io_handle_t, audio_session_t,
- * effect ID (int), audio_module_handle_t, and audio_patch_handle_t.
+/* A unique ID allocated by AudioFlinger for use as an audio_io_handle_t, audio_session_t,
+ * audio_effect_handle_t, audio_module_handle_t, and audio_patch_handle_t.
  * Audio port IDs (audio_port_handle_t) are allocated by AudioPolicy
  * in a different namespace than AudioFlinger unique IDs.
  */
 typedef int audio_unique_id_t;
 
+/* A unique ID with use AUDIO_UNIQUE_ID_USE_EFFECT */
+typedef int audio_effect_handle_t;
+
 /* Possible uses for an audio_unique_id_t */
 typedef enum {
     AUDIO_UNIQUE_ID_USE_UNSPECIFIED = 0,
-    AUDIO_UNIQUE_ID_USE_SESSION = 1,    // for allocated sessions, not special AUDIO_SESSION_*
-    AUDIO_UNIQUE_ID_USE_MODULE = 2,
-    AUDIO_UNIQUE_ID_USE_EFFECT = 3,
-    AUDIO_UNIQUE_ID_USE_PATCH = 4,
-    AUDIO_UNIQUE_ID_USE_OUTPUT = 5,
-    AUDIO_UNIQUE_ID_USE_INPUT = 6,
+    AUDIO_UNIQUE_ID_USE_SESSION = 1, // audio_session_t
+                                     // for allocated sessions, not special AUDIO_SESSION_*
+    AUDIO_UNIQUE_ID_USE_MODULE = 2,  // audio_module_handle_t
+    AUDIO_UNIQUE_ID_USE_EFFECT = 3,  // audio_effect_handle_t
+    AUDIO_UNIQUE_ID_USE_PATCH = 4,   // audio_patch_handle_t
+    AUDIO_UNIQUE_ID_USE_OUTPUT = 5,  // audio_io_handle_t
+    AUDIO_UNIQUE_ID_USE_INPUT = 6,   // audio_io_handle_t
     AUDIO_UNIQUE_ID_USE_CLIENT = 7,  // client-side players and recorders
-    AUDIO_UNIQUE_ID_USE_MAX = 8,  // must be a power-of-two
+                                     // FIXME should move to a separate namespace;
+                                     // these IDs are allocated by AudioFlinger on client request,
+                                     // but are never used by AudioFlinger
+    AUDIO_UNIQUE_ID_USE_MAX = 8,     // must be a power-of-two
     AUDIO_UNIQUE_ID_USE_MASK = AUDIO_UNIQUE_ID_USE_MAX - 1
 } audio_unique_id_use_t;
 
diff --git a/audio_utils/Android.bp b/audio_utils/Android.bp
index 74b2fc0..2cd662b 100644
--- a/audio_utils/Android.bp
+++ b/audio_utils/Android.bp
@@ -28,7 +28,7 @@
         "ErrorLog.cpp",
         "fifo.cpp",
         "fifo_index.cpp",
-        "fifo_writer32.cpp",
+        "fifo_writer_T.cpp",
         "format.c",
         "limiter.c",
         "minifloat.c",
diff --git a/audio_utils/fifo_index.cpp b/audio_utils/fifo_index.cpp
index ebb085d..54d9d3e 100644
--- a/audio_utils/fifo_index.cpp
+++ b/audio_utils/fifo_index.cpp
@@ -27,7 +27,7 @@
     return atomic_load_explicit(&mIndex, std::memory_order_acquire);
 }
 
-// FIXME should inline this, so that writer32 can also inline it
+// FIXME should inline this, so that writer_T can also inline it
 void audio_utils_fifo_index::storeRelease(uint32_t value)
 {
     atomic_store_explicit(&mIndex, value, std::memory_order_release);
diff --git a/audio_utils/fifo_writer32.cpp b/audio_utils/fifo_writer_T.cpp
similarity index 67%
rename from audio_utils/fifo_writer32.cpp
rename to audio_utils/fifo_writer_T.cpp
index 7551e67..5160773 100644
--- a/audio_utils/fifo_writer32.cpp
+++ b/audio_utils/fifo_writer_T.cpp
@@ -17,45 +17,45 @@
 #include <atomic>
 #include <stdlib.h>
 #include <string.h>
+#include <audio_utils/fifo_writer_T.h>
 
-// TODO templatize int32_t
-
-#include <audio_utils/fifo_writer32.h>
-
-static inline void memcpyWords(int32_t *dst, const int32_t *src, uint32_t count)
+template <typename T>
+static inline void memcpyWords(T *dst, const T *src, uint32_t count)
 {
     switch (count) {
     case 0: break;
 // TODO templatize here also, but first confirm no performance regression compared to current
 #define _(n) \
     case n: { \
-        struct s##n { int32_t a[n]; }; \
+        struct s##n { T a[n]; }; \
         *(struct s##n *)dst = *(const struct s##n *)src; \
         break; \
     }
     _(1) _(2) _(3) _(4) _(5) _(6) _(7) _(8) _(9) _(10) _(11) _(12) _(13) _(14) _(15) _(16)
 #undef _
     default:
-        memcpy(dst, src, count * sizeof(int32_t));
+        memcpy(dst, src, count * sizeof(T));
         break;
     }
 }
 
-audio_utils_fifo_writer32::audio_utils_fifo_writer32(audio_utils_fifo& fifo) :
-    mLocalRear(0), mFrameCountP2(fifo.mFrameCountP2), mBuffer((int32_t *) fifo.mBuffer),
+template <typename T>
+audio_utils_fifo_writer_T<T>::audio_utils_fifo_writer_T(audio_utils_fifo& fifo) :
+    mLocalRear(0), mFrameCountP2(fifo.mFrameCountP2), mBuffer((T *) fifo.mBuffer),
     mWriterRear(fifo.mWriterRear)
 {
-    if (fifo.mFrameSize != sizeof(int32_t) || fifo.mFudgeFactor != 0 ||
-            ((size_t) mBuffer & ((sizeof(int32_t) - 1))) != 0) {
+    if (fifo.mFrameSize != sizeof(T) || fifo.mFudgeFactor != 0) {
         abort();
     }
 }
 
-audio_utils_fifo_writer32::~audio_utils_fifo_writer32()
+template <typename T>
+audio_utils_fifo_writer_T<T>::~audio_utils_fifo_writer_T()
 {
 }
 
-void audio_utils_fifo_writer32::write(const int32_t *buffer, uint32_t count)
+template <typename T>
+void audio_utils_fifo_writer_T<T>::write(const T *buffer, uint32_t count)
         __attribute__((no_sanitize("integer")))     // mLocalRear += can wrap
 {
     uint32_t availToWrite = mFrameCountP2;
@@ -73,3 +73,8 @@
     memcpyWords(&mBuffer[0], &buffer[part1], part2);
     mLocalRear += availToWrite;
 }
+
+// Instantiate for the specific types we need, which is currently just int32_t and int64_t.
+
+template class audio_utils_fifo_writer_T<int32_t>;
+template class audio_utils_fifo_writer_T<int64_t>;
diff --git a/audio_utils/include/audio_utils/fifo.h b/audio_utils/include/audio_utils/fifo.h
index 4926c09..c4bacef 100644
--- a/audio_utils/include/audio_utils/fifo.h
+++ b/audio_utils/include/audio_utils/fifo.h
@@ -140,7 +140,7 @@
 
     friend class audio_utils_fifo_reader;
     friend class audio_utils_fifo_writer;
-    friend class audio_utils_fifo_writer32;
+    template <typename T> friend class audio_utils_fifo_writer_T;
 
 public:
 
diff --git a/audio_utils/include/audio_utils/fifo_writer32.h b/audio_utils/include/audio_utils/fifo_writer_T.h
similarity index 72%
rename from audio_utils/include/audio_utils/fifo_writer32.h
rename to audio_utils/include/audio_utils/fifo_writer_T.h
index d17d58d..c1531cb 100644
--- a/audio_utils/include/audio_utils/fifo_writer32.h
+++ b/audio_utils/include/audio_utils/fifo_writer_T.h
@@ -20,11 +20,11 @@
 #include <audio_utils/fifo.h>
 
 /**
- * Optimized FIFO writer for 32-bit words.
+ * Optimized FIFO writer for small multiples of fixed-sized POD such as primitives.
  *
  * Has these restrictions compared to the ordinary FIFO writer:
- *  - buffer must be aligned on a 32-bit boundary
- *  - frame size must be sizeof(int32_t)
+ *  - buffer must be aligned on an appropriate boundary for T
+ *  - frame size must be sizeof(T)
  *  - capacity must be power-of-2
  *  - effective size must be equal to capacity
  *  - no support for throttling of writer by one reader, and thus no blocking writes
@@ -38,30 +38,31 @@
  * Usage:
  *  - construct an ordinary FIFO that follows the restrictions above
  *  - construct an ordinary reader based on that FIFO
- *  - construct a writer32 using the FIFO
+ *  - construct a writer_T using the FIFO
  *  - use a sequence of write and write1, followed by storeRelease to commit
  */
-class audio_utils_fifo_writer32 /* : public audio_utils_fifo_provider */ {
+template <typename T>
+class audio_utils_fifo_writer_T /* : public audio_utils_fifo_provider */ {
 
 public:
     /**
-     * Construct a writer32 from a FIFO.
+     * Construct a writer_T from a FIFO.
      */
-    explicit audio_utils_fifo_writer32(audio_utils_fifo& fifo);
-    /*virtual*/ ~audio_utils_fifo_writer32();
+    explicit audio_utils_fifo_writer_T(audio_utils_fifo& fifo);
+    /*virtual*/ ~audio_utils_fifo_writer_T();
 
     /**
-     * Write an array of int32_t to FIFO.
+     * Write an array of T to FIFO.
      * If count is larger than capacity, then only the initial 'capacity' frames will be written.
      * TODO Instead of a silent truncation, consider adding a size_t or ssize_t return value
      * to indicate the actual transfer count.
      */
-    void write(const int32_t *buffer, uint32_t count /* FIXME size_t in writer */);
+    void write(const T *buffer, uint32_t count /* FIXME size_t in writer */);
 
     /**
-     * Write one int32_t value to FIFO.
+     * Write one T value to FIFO.
      */
-    void write1(const int32_t value)
+    void write1(const T& value)
             __attribute__((no_sanitize("integer")))     // mLocalRear ++ can wrap
     {
         mBuffer[mLocalRear++ & (mFrameCountP2 - 1)] = value;
@@ -79,9 +80,12 @@
     uint32_t    mLocalRear; // frame index of next frame slot available to write, or write index
 
     // These fields are copied from fifo for better performance (avoids an extra de-reference)
-    const uint32_t                     mFrameCountP2;
-    int32_t                    * const mBuffer;
-    audio_utils_fifo_index&            mWriterRear;
+    const uint32_t          mFrameCountP2;
+    T * const               mBuffer;
+    audio_utils_fifo_index& mWriterRear;
 };
 
+using audio_utils_fifo_writer32 = audio_utils_fifo_writer_T<int32_t>;
+using audio_utils_fifo_writer64 = audio_utils_fifo_writer_T<int64_t>;
+
 #endif // ANDROID_AUDIO_FIFO_WRITER32_H