Merge "AGM: remove all aif_obj from aif_pool after close a session"
diff --git a/plugins/tinyalsa/src/agm_pcm_plugin.c b/plugins/tinyalsa/src/agm_pcm_plugin.c
index b8f375f..92c53ce 100644
--- a/plugins/tinyalsa/src/agm_pcm_plugin.c
+++ b/plugins/tinyalsa/src/agm_pcm_plugin.c
@@ -366,9 +366,13 @@
 
         // Set delta_wall_clk_us only if cached wall clk is non-zero
         if (priv->pos_buf->wall_clk_msw || priv->pos_buf->wall_clk_lsw) {
-                delta_wall_clk_us = (int64_t)((((uint64_t)wall_clk_msw) << 32 | wall_clk_lsw) -
-                                        (((uint64_t)priv->pos_buf->wall_clk_msw) << 32 |
-                                         priv->pos_buf->wall_clk_lsw));
+            uint64_t dsp_wall_clk =  (((uint64_t)wall_clk_msw) << 32 | wall_clk_lsw);
+            uint64_t cached_wall_clk = (((uint64_t)priv->pos_buf->wall_clk_msw) << 32 |
+                                         priv->pos_buf->wall_clk_lsw);
+            // Compute delta only if diff is greater than zero
+            if (dsp_wall_clk > cached_wall_clk) {
+                delta_wall_clk_us = (int64_t)(dsp_wall_clk - cached_wall_clk);
+            }
         }
         // Identify the number of times of shared buffer length that the
         // hw ptr has jumped through by checking wall clock time delta
diff --git a/plugins/tinyalsa/test/agmhostless.c b/plugins/tinyalsa/test/agmhostless.c
index 4819725..36e22b5 100644
--- a/plugins/tinyalsa/test/agmhostless.c
+++ b/plugins/tinyalsa/test/agmhostless.c
@@ -264,7 +264,7 @@
         goto err_close_mixer;
     }
 
-    if (set_agm_stream_metadata(mixer, c_device, stream_kv, LOOPBACK, STREAM_PCM,
+    if (set_agm_stream_metadata(mixer, p_device, stream_kv, LOOPBACK, STREAM_PCM,
                                 0)) {
         printf("Failed to capture stream metadata\n");
         goto err_close_mixer;