Merge "Activity Recognition HAL."
diff --git a/include/hardware/camera3.h b/include/hardware/camera3.h
index 4503885..6623dc7 100644
--- a/include/hardware/camera3.h
+++ b/include/hardware/camera3.h
@@ -1535,17 +1535,18 @@
  * Transport header for compressed JPEG buffers in output streams.
  *
  * To capture JPEG images, a stream is created using the pixel format
- * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
- * used as the buffer size. Since compressed JPEG images are of variable size,
- * the HAL needs to include the final size of the compressed image using this
- * structure inside the output stream buffer. The JPEG blob ID field must be set
- * to CAMERA3_JPEG_BLOB_ID.
+ * HAL_PIXEL_FORMAT_BLOB. The buffer size for the stream is calculated by the
+ * framework, based on the static metadata field android.jpeg.maxSize. Since
+ * compressed JPEG images are of variable size, the HAL needs to include the
+ * final size of the compressed image using this structure inside the output
+ * stream buffer. The JPEG blob ID field must be set to CAMERA3_JPEG_BLOB_ID.
  *
- * Transport header should be at the end of the JPEG output stream buffer.  That
- * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
- * sizeof(camera3_jpeg_blob)].  Any HAL using this transport header must
- * account for it in android.jpeg.maxSize.  The JPEG data itself starts at
- * the beginning of the buffer and should be jpeg_size bytes long.
+ * Transport header should be at the end of the JPEG output stream buffer. That
+ * means the jpeg_blob_id must start at byte[buffer_size -
+ * sizeof(camera3_jpeg_blob)], where the buffer_size is the size of gralloc buffer.
+ * Any HAL using this transport header must account for it in android.jpeg.maxSize
+ * The JPEG data itself starts at the beginning of the buffer and should be
+ * jpeg_size bytes long.
  */
 typedef struct camera3_jpeg_blob {
     uint16_t jpeg_blob_id;
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hw.c
index 51f636d..7b2a4f1 100644
--- a/modules/usbaudio/audio_hw.c
+++ b/modules/usbaudio/audio_hw.c
@@ -18,12 +18,13 @@
 /*#define LOG_NDEBUG 0*/
 
 #include <errno.h>
+#include <inttypes.h>
 #include <pthread.h>
 #include <stdint.h>
-#include <sys/time.h>
 #include <stdlib.h>
+#include <sys/time.h>
 
-#include <cutils/log.h>
+#include <log/log.h>
 #include <cutils/str_parms.h>
 #include <cutils/properties.h>
 
@@ -180,7 +181,7 @@
  *   This conversion is safe to do in-place (in_buff == out_buff).
  * TODO(pmclean, hung) Move this to a utilities module.
  */
-static size_t convert_16_to_24_3(short * in_buff, size_t num_in_samples, unsigned char * out_buff) {
+static size_t convert_16_to_24_3(const short * in_buff, size_t num_in_samples, unsigned char * out_buff) {
     /*
      * Move from back to front so that the conversion can be done in-place
      * i.e. in_buff == out_buff
@@ -190,7 +191,7 @@
     int out_buff_size_in_bytes = ((3 * in_buff_size_in_bytes) / 2);
     unsigned char* dst_ptr = out_buff + out_buff_size_in_bytes - 1;
     size_t src_smpl_index;
-    unsigned char* src_ptr = ((unsigned char *)in_buff) + in_buff_size_in_bytes - 1;
+    const unsigned char* src_ptr = ((const unsigned char *)in_buff) + in_buff_size_in_bytes - 1;
     for (src_smpl_index = 0; src_smpl_index < num_in_samples; src_smpl_index++) {
         *dst_ptr-- = *src_ptr--; /* hi-byte */
         *dst_ptr-- = *src_ptr--; /* low-byte */
@@ -216,14 +217,14 @@
  *   This conversion is safe to do in-place (in_buff == out_buff).
  * TODO(pmclean, hung) Move this to a utilities module.
  */
-static size_t convert_24_3_to_16(unsigned char * in_buff, size_t num_in_samples, short * out_buff) {
+static size_t convert_24_3_to_16(const unsigned char * in_buff, size_t num_in_samples, short * out_buff) {
     /*
      * Move from front to back so that the conversion can be done in-place
      * i.e. in_buff == out_buff
      */
     /* we need 2 bytes in the output for every 3 bytes in the input */
     unsigned char* dst_ptr = (unsigned char*)out_buff;
-    unsigned char* src_ptr = in_buff;
+    const unsigned char* src_ptr = in_buff;
     size_t src_smpl_index;
     for (src_smpl_index = 0; src_smpl_index < num_in_samples; src_smpl_index++) {
         src_ptr++;               /* lowest-(skip)-byte */
@@ -252,7 +253,7 @@
  * support 4-channel devices.
  * TODO(pmclean, hung) Move this to a utilities module.
  */
-static size_t expand_channels_16(short* in_buff, int in_buff_chans,
+static size_t expand_channels_16(const short* in_buff, int in_buff_chans,
                                  short* out_buff, int out_buff_chans,
                                  size_t num_in_samples) {
     /*
@@ -263,8 +264,8 @@
     int num_out_samples = (num_in_samples * out_buff_chans)/in_buff_chans;
 
     short* dst_ptr = out_buff + num_out_samples - 1;
-    int src_index;
-    short* src_ptr = in_buff + num_in_samples - 1;
+    size_t src_index;
+    const short* src_ptr = in_buff + num_in_samples - 1;
     int num_zero_chans = out_buff_chans - in_buff_chans;
     for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
         int dst_offset;
@@ -311,7 +312,7 @@
 
     short* dst_ptr = out_buff;
     short* src_ptr = in_buff;
-    int src_index;
+    size_t src_index;
     for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
         int dst_offset;
         for(dst_offset = 0; dst_offset < out_buff_chans; dst_offset++) {
@@ -331,7 +332,7 @@
  * gets the ALSA bit-format flag from a bits-per-sample value.
  * TODO(pmclean, hung) Move this to a utilities module.
  */
-static int bits_to_alsa_format(int bits_per_sample, int default_format)
+static int bits_to_alsa_format(unsigned int bits_per_sample, int default_format)
 {
     enum pcm_format format;
     for (format = PCM_FORMAT_S16_LE; format < PCM_FORMAT_MAX; format++) {
@@ -407,7 +408,7 @@
     config->period_size = pcm_params_get_max(alsa_hw_params, PCM_PARAM_PERIODS);
     config->period_count = pcm_params_get_min(alsa_hw_params, PCM_PARAM_PERIODS);
 
-    int bits_per_sample = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS);
+    unsigned int bits_per_sample = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS);
     config->format = bits_to_alsa_format(bits_per_sample, PCM_FORMAT_S16_LE);
 
     return 0;
@@ -554,9 +555,9 @@
         // if they are different, return a list containing those two values, otherwise just the one.
         min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE);
         max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE);
-        num_written = snprintf(buffer, buffer_size, "%d", min);
+        num_written = snprintf(buffer, buffer_size, "%u", min);
         if (min != max) {
-            snprintf(buffer + num_written, buffer_size - num_written, "|%d", max);
+            snprintf(buffer + num_written, buffer_size - num_written, "|%u", max);
         }
         str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES,
                           buffer);
@@ -567,9 +568,9 @@
         // Similarly for output channels count
         min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
         max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS);
-        num_written = snprintf(buffer, buffer_size, "%d", min);
+        num_written = snprintf(buffer, buffer_size, "%u", min);
         if (min != max) {
-            snprintf(buffer + num_written, buffer_size - num_written, "|%d", max);
+            snprintf(buffer + num_written, buffer_size - num_written, "|%u", max);
         }
         str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, buffer);
     }  // AUDIO_PARAMETER_STREAM_SUP_CHANNELS
@@ -580,9 +581,9 @@
         //TODO(pmclean): this is wrong.
         min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS);
         max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_SAMPLE_BITS);
-        num_written = snprintf(buffer, buffer_size, "%d", min);
+        num_written = snprintf(buffer, buffer_size, "%u", min);
         if (min != max) {
-            snprintf(buffer + num_written, buffer_size - num_written, "|%d", max);
+            snprintf(buffer + num_written, buffer_size - num_written, "|%u", max);
         }
         str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS, buffer);
     }  // AUDIO_PARAMETER_STREAM_SUP_FORMATS
@@ -654,7 +655,7 @@
     // compute maximum potential buffer size.
     // * 2 for stereo -> quad conversion
     // * 3/2 for 16bit -> 24 bit conversion
-    int required_conversion_buffer_size = (bytes * 3 * 2) / 2;
+    size_t required_conversion_buffer_size = (bytes * 3 * 2) / 2;
     if (required_conversion_buffer_size > out->conversion_buffer_size) {
         //TODO(pmclean) - remove this when AudioPolicyManger/AudioFlinger support arbitrary formats
         // (and do these conversions themselves)
@@ -662,7 +663,7 @@
         out->conversion_buffer = realloc(out->conversion_buffer, out->conversion_buffer_size);
     }
 
-    void * write_buff = buffer;
+    const void * write_buff = buffer;
     int num_write_buff_bytes = bytes;
 
     /*
@@ -896,7 +897,7 @@
 
 static size_t in_get_buffer_size(const struct audio_stream *stream)
 {
-    ALOGV("usb: in_get_buffer_size() = %d",
+    ALOGV("usb: in_get_buffer_size() = %zu",
           cached_input_hardware_config.period_size * audio_stream_frame_size(stream));
     return cached_input_hardware_config.period_size * audio_stream_frame_size(stream);
 
@@ -1018,9 +1019,9 @@
         // if they are different, return a list containing those two values, otherwise just the one.
         min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_RATE);
         max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_RATE);
-        num_written = snprintf(buffer, buffer_size, "%d", min);
+        num_written = snprintf(buffer, buffer_size, "%u", min);
         if (min != max) {
-            snprintf(buffer + num_written, buffer_size - num_written, "|%d", max);
+            snprintf(buffer + num_written, buffer_size - num_written, "|%u", max);
         }
         str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SAMPLING_RATE, buffer);
     }  // AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES
@@ -1030,9 +1031,9 @@
         // Similarly for output channels count
         min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_CHANNELS);
         max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_CHANNELS);
-        num_written = snprintf(buffer, buffer_size, "%d", min);
+        num_written = snprintf(buffer, buffer_size, "%u", min);
         if (min != max) {
-            snprintf(buffer + num_written, buffer_size - num_written, "|%d", max);
+            snprintf(buffer + num_written, buffer_size - num_written, "|%u", max);
         }
         str_parms_add_str(result, AUDIO_PARAMETER_STREAM_CHANNELS, buffer);
     }  // AUDIO_PARAMETER_STREAM_SUP_CHANNELS
@@ -1042,9 +1043,9 @@
         //TODO(pmclean): this is wrong.
         min = pcm_params_get_min(alsa_hw_params, PCM_PARAM_SAMPLE_BITS);
         max = pcm_params_get_max(alsa_hw_params, PCM_PARAM_SAMPLE_BITS);
-        num_written = snprintf(buffer, buffer_size, "%d", min);
+        num_written = snprintf(buffer, buffer_size, "%u", min);
         if (min != max) {
-            snprintf(buffer + num_written, buffer_size - num_written, "|%d", max);
+            snprintf(buffer + num_written, buffer_size - num_written, "|%u", max);
         }
         str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS, buffer);
     }  // AUDIO_PARAMETER_STREAM_SUP_FORMATS
@@ -1099,7 +1100,7 @@
 //TODO(pmclean) mutex stuff here (see out_write)
 static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t bytes)
 {
-    int num_read_buff_bytes = 0;
+    size_t num_read_buff_bytes = 0;
     void * read_buff = buffer;
     void * out_buff = buffer;
 
@@ -1192,7 +1193,7 @@
                                   struct audio_config *config,
                                   struct audio_stream_in **stream_in)
 {
-    ALOGV("usb: in adev_open_input_stream() rate:%d, chanMask:0x%X, fmt:%d",
+    ALOGV("usb: in adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8,
           config->sample_rate, config->channel_mask, config->format);
 
     struct stream_in *in = (struct stream_in *)calloc(1, sizeof(struct stream_in));