audio: Legacy: Use monotonic clock for presentation position

The timestamp returned by AudioHAL's get_presentation_position()
must be from the MONOTONIC clock.  An additional flag has to be
passed when opening the pcm ports in tinyalsa in order to get
timestamps from the monotonic clock.

Change-Id: Ib06c686985ae9229df59a2756c5da35e858e2d0e
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
diff --git a/audio/legacy/audio_hw.c b/audio/legacy/audio_hw.c
index 12459e5..6912570 100644
--- a/audio/legacy/audio_hw.c
+++ b/audio/legacy/audio_hw.c
@@ -524,8 +524,12 @@
         return ret;
     }
 
-    stream->pcm_in = pcm_open(in_card, in_port, PCM_IN, &stream->in_config);
-    stream->pcm_out = pcm_open(out_card, out_port, PCM_OUT, &stream->out_config);
+    stream->pcm_in = pcm_open(in_card, in_port,
+                              PCM_IN | PCM_MONOTONIC,
+                              &stream->in_config);
+    stream->pcm_out = pcm_open(out_card, out_port,
+                               PCM_OUT | PCM_MONOTONIC,
+                               &stream->out_config);
 
     if (!pcm_is_ready(stream->pcm_in) || !pcm_is_ready(stream->pcm_out)) {
         ALOGE("voice_stream_init() failed to open pcm %s devices", stream->name);
@@ -848,7 +852,9 @@
             select_output_device(adev);
 
             ALOGI("out_write() open card %u port %u", adev->card, adev->out_port);
-            out->pcm = pcm_open(adev->card, adev->out_port, PCM_OUT, &out->config);
+            out->pcm = pcm_open(adev->card, adev->out_port,
+                                PCM_OUT | PCM_MONOTONIC,
+                                &out->config);
             if (!pcm_is_ready(out->pcm)) {
                 ALOGE("out_write() failed to open pcm out: %s", pcm_get_error(out->pcm));
                 pcm_close(out->pcm);
@@ -932,7 +938,7 @@
             signed_frames = out->written - pcm_get_buffer_size(out->pcm) + avail;
         }
     } else {
-        clock_gettime(CLOCK_REALTIME, timestamp);
+        clock_gettime(CLOCK_MONOTONIC, timestamp);
         signed_frames = out->written +
             (time_diff(*timestamp, out->last) * out->config.rate) / 1000000;
     }
@@ -1202,7 +1208,9 @@
         select_input_device(adev);
 
         ALOGI("in_read() open card %u port %u", adev->card, adev->in_port);
-        in->pcm = pcm_open(adev->card, adev->in_port, PCM_IN, &in->config);
+        in->pcm = pcm_open(adev->card, adev->in_port,
+                           PCM_IN | PCM_MONOTONIC,
+                           &in->config);
         if (!pcm_is_ready(in->pcm)) {
             ALOGE("in_read() failed to open pcm in: %s", pcm_get_error(in->pcm));
             pcm_close(in->pcm);