Merge "[Feature][T106][task-view-1454]Add interface function for real-time control log level"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp
index 7a3a333..2d94df9 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp
@@ -2,15 +2,77 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <atomic>
+#include <csignal>
+#include <signal.h>
#include "ring_tele.h"
#include <include/lynq-qser-audio.h>
+// Add atomic flag for one-time cleanup
+namespace {
+ std::atomic<bool> g_cleanup_done{false}; // Atomic flag for one-time cleanup
+}
+
typedef int (*audio_test_func)(void);
int g_audio_owner_id = 0;
char player_device[] = "device1";
char recorder_device[] = "device2";
+/********************************************************************
+* @brief: Signal handler for audio resource cleanup
+* @param sig [IN]: Signal number received
+* @note: Ensures audio resources are properly released on termination
+*********************************************************************/
+static void audio_signal_handler(int sig)
+{
+ if(!g_cleanup_done.exchange(true)) {
+ printf("[Audio Demo] Received termination signal:%d, performing hardware-level cleanup...\n", sig);
+ fflush(stdout); // Ensure log integrity
+ fflush(stderr);
+ qser_Audio_Deinit();
+ }
+ _Exit(sig); // Use _Exit to avoid atexit handlers
+}
+
+/********************************************************************
+* @brief: Signal handler registration (auto-executed before main())
+* @note: 1. Registers common termination signals
+* 2. Uses sigaction for better signal masking
+* 3. Blocks related signals during handling
+*********************************************************************/
+__attribute__((constructor))
+static void register_signal_handlers()
+{
+ struct sigaction act;
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = audio_signal_handler;
+
+ // Block related signals during handling
+ sigemptyset(&act.sa_mask);
+ sigaddset(&act.sa_mask, SIGTERM); // Termination request
+ sigaddset(&act.sa_mask, SIGINT); // Terminal interrupt (Ctrl+C)
+ sigaddset(&act.sa_mask, SIGQUIT); // Terminal quit (Ctrl+\)
+ sigaddset(&act.sa_mask, SIGHUP); // Terminal hangup detection
+
+ // Register standard POSIX signals
+ sigaction(SIGINT, &act, NULL); // Terminal interrupt (Ctrl+C)
+ sigaction(SIGTERM, &act, NULL); // Default kill signal
+ sigaction(SIGQUIT, &act, NULL); // Terminal quit (Ctrl+\)
+ sigaction(SIGHUP, &act, NULL); // Terminal hangup
+
+ // Register critical error signals
+ struct sigaction crash_act;
+ memset(&crash_act, 0, sizeof(crash_act));
+ crash_act.sa_handler = audio_signal_handler;
+ crash_act.sa_flags = SA_RESETHAND; // Single-shot handler
+
+ sigaction(SIGSEGV, &crash_act, NULL); // Invalid memory access
+ sigaction(SIGILL, &crash_act, NULL); // Illegal instruction
+ sigaction(SIGFPE, &crash_act, NULL); // Floating-point exception
+ sigaction(SIGBUS, &crash_act, NULL); // Bus error (bad alignment)
+}
+
_cb_onPlayer cb_fun = [](int result)
{
if (result == 0)