[T108][AUDIO] Add audio loopback interface test

Change-Id: I1a19ee4a8540593a59d86f75680c4e7443e9924b
diff --git a/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c b/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
index e178b56..213534b 100755
--- a/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
+++ b/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
@@ -755,6 +755,23 @@
     return NULL;
 }
 
+int mbtk_audio_playback_set_block_flag(mbtk_audio_handle handle, int flags)
+{
+    if (handle == NULL) {
+        LOGE("Invalid handle: NULL");
+        return -1;
+    }
+
+    if (flags < 0) {
+        LOGE("Invalid flags: %d", flags);
+        return -1;
+    }
+
+    LOGD("Setting block flag: %d", flags);
+
+    return 0;
+}
+
 int mbtk_audio_play_file_new(void *dev_hdl, int file_fd, int offset)
 {
     unsigned bufsize = 0;
diff --git a/mbtk/libmbtk_lib/audio/mbtk_wav.c b/mbtk/libmbtk_lib/audio/mbtk_wav.c
index f2e104c..ac4bed8 100755
--- a/mbtk/libmbtk_lib/audio/mbtk_wav.c
+++ b/mbtk/libmbtk_lib/audio/mbtk_wav.c
@@ -26,6 +26,10 @@
 
 static audio_buff_t audio_buff;
 
+static int current_loopback_state = 0;
+static int current_loopback_device = -1;
+static mbtk_audio_service_error_cb_f service_error_cb = NULL;
+
 static void audio_play_thread(void *arg)
 {
     int rc, len, frames = 0;
@@ -125,6 +129,17 @@
     }
 }
 
+int mbtk_register_error_callback(mbtk_audio_service_error_cb_f cb)
+{
+    if (cb == NULL) {
+        LOGE("Error: Callback function is NULL.");
+        return -1;
+    }
+    service_error_cb = cb;
+    LOGD("Callback function registered successfully.");
+    return 0;
+}
+
 int mbtk_audio_wav_init()
 {
     //mbtk_log_init("radio", "MBTK_AUDIO");
@@ -407,3 +422,49 @@
     return mbtk_audio_pcm_deinit();
 }
 
+int mbtk_audio_set_loopback_enable_state(int device, int enable_state)
+{
+    char command[128];
+
+    if (device < 0 || device > 2 || (enable_state != 0 && enable_state != 1)) {
+        LOGE("Invalid device or enable_state");
+        return -1;
+    }
+
+    snprintf(command, sizeof(command), "ubus call audio_if audio_mode_set '{\"param0\":0}'");
+    if (system(command) != 0) {
+        LOGE("Failed to set audio mode");
+        return -1;
+    }
+
+    if (enable_state == 1) {
+        snprintf(command, sizeof(command), "ubus call audio_if loopback_enable '{\"param0\":%d}'", device);
+        if (system(command) != 0) {
+            LOGE("Failed to enable loopback");
+            return -1;
+        }
+    } else {
+        if (system("ubus call audio_if loopback_disable") != 0) {
+            LOGE("Failed to disable loopback");
+            return -1;
+        }
+    }
+
+    current_loopback_device = device;
+    current_loopback_state = enable_state;
+
+    return 0;
+}
+
+int mbtk_audio_get_loopback_enable_state(int *device, int *enable_state)
+{
+    if (device == NULL || enable_state == NULL) {
+        LOGE("Null pointer provided for device or enable_state");
+        return -1;
+    }
+
+    *device = current_loopback_device;
+    *enable_state = current_loopback_state;
+
+    return 0;
+}