Merge 8b9badaa078c507ecc34e632dd0cbc491a7dbc05 on remote branch

Change-Id: I3efb10962a0e70355007aa2e51a246273544b1aa
diff --git a/service/Android.mk b/service/Android.mk
index 0493ba0..50bf4d2 100644
--- a/service/Android.mk
+++ b/service/Android.mk
@@ -14,7 +14,7 @@
 LOCAL_MODULE_TAGS   := optional
 LOCAL_VENDOR_MODULE := true
 
-LOCAL_CFLAGS        := -D_ANDROID_
+LOCAL_CFLAGS        := -D_ANDROID_ -DAGM_DEBUG_METADATA
 LOCAL_CFLAGS        += -Wno-tautological-compare -Wno-macro-redefined -Wall
 LOCAL_CFLAGS        += -D_GNU_SOURCE -DACDB_PATH=\"/vendor/etc/acdbdata/\"
 LOCAL_CFLAGS        += -DACDB_DELTA_FILE_PATH="/data/vendor/audio/acdbdata/delta"
diff --git a/service/src/device.c b/service/src/device.c
index 5d509bc..78a3679 100644
--- a/service/src/device.c
+++ b/service/src/device.c
@@ -738,11 +738,13 @@
 {
    int ret = 0;
 
-   AGM_LOGI("Setting device metadata for %s\n", dev_obj->name);
    pthread_mutex_lock(&dev_obj->lock);
    metadata_free(&dev_obj->metadata);
    ret = metadata_copy(&(dev_obj->metadata), size, metadata);
+#ifdef AGM_DEBUG_METADATA
+   AGM_LOGI("Setting device metadata for %s\n", dev_obj->name);
    metadata_print(&(dev_obj->metadata));
+#endif
    pthread_mutex_unlock(&dev_obj->lock);
 
    return ret;
diff --git a/service/src/graph.c b/service/src/graph.c
index 481baa2..f78f0f6 100644
--- a/service/src/graph.c
+++ b/service/src/graph.c
@@ -931,7 +931,9 @@
     }
 
     if (meta_data) {
+#ifdef AGM_DEBUG_METADATA
         metadata_print(meta_data);
+#endif
         memcpy (&(gsl_cmd_prop.gkv), &(meta_data->gkv),
                                        sizeof(struct gsl_key_vector));
         gsl_cmd_prop.property_id = meta_data->sg_props.prop_id;
diff --git a/service/src/session_obj.c b/service/src/session_obj.c
index 7809de4..f9f43d1 100644
--- a/service/src/session_obj.c
+++ b/service/src/session_obj.c
@@ -1750,7 +1750,6 @@
     int ret = 0;
     struct aif *aif_obj = NULL;
 
-    AGM_LOGI("Setting metadata for sess aif id %d\n", aif_id);
     pthread_mutex_lock(&sess_obj->lock);
     ret = aif_obj_get(sess_obj, aif_id, &aif_obj);
     if (ret) {
@@ -1766,8 +1765,10 @@
                   sess_id:%d, aif_id:%d \n",
                   sess_obj->sess_id, aif_obj->aif_id);
     }
+#ifdef AGM_DEBUG_METADATA
+    AGM_LOGI("Setting metadata for sess aif id %d\n", aif_id);
     metadata_print(&(aif_obj->sess_aif_meta));
-
+#endif
 done:
     pthread_mutex_unlock(&sess_obj->lock);
     AGM_LOGI("Exit");
@@ -2276,14 +2277,41 @@
 int session_obj_flush(struct session_obj *sess_obj)
 {
     int ret = 0;
+    struct session_cb *sess_cb;
+    struct listnode *node, *next;
+    struct agm_event_cb_params *event_params = NULL;
 
     pthread_mutex_lock(&sess_obj->lock);
 
     ret = graph_flush(sess_obj->graph);
     if (ret) {
         AGM_LOGE("Error:%d flushing graph\n", ret);
+        goto done;
     }
 
+    // Unblock the call waiting for EARLY_EOS callback
+    event_params = (struct agm_event_cb_params*) calloc(1,
+                   (sizeof(struct agm_event_cb_params)));
+    if (!event_params) {
+        AGM_LOGE("Not enough memory for event_params");
+        goto done;
+    }
+
+    pthread_mutex_lock(&sess_obj->cb_pool_lock);
+    list_for_each_safe(node, next, &sess_obj->cb_pool) {
+        sess_cb = node_to_item(node, struct session_cb, node);
+        if (sess_cb && sess_cb->cb) {
+            event_params->event_id = AGM_EVENT_EARLY_EOS;
+            sess_cb->cb(sess_obj->sess_id,
+                        (struct agm_event_cb_params *)event_params,
+                        sess_cb->client_data);
+            break;
+        }
+    }
+    pthread_mutex_unlock(&sess_obj->cb_pool_lock);
+    if (event_params)
+        free(event_params);
+
 done:
     pthread_mutex_unlock(&sess_obj->lock);
     return ret;