Improve log of default dependency module 11/238211/6
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 18 Jun 2020 02:04:38 +0000 (11:04 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 8 Jun 2021 08:05:46 +0000 (17:05 +0900)
Change-Id: Id1d6166c87fbc62980c2143f1bdd28e4e9424624
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
audio-manager/inc/vc_audio_manager.h
audio-manager/src/vc_audio_manager.cpp
audio-manager/src/vc_audio_manager_dlog.h [new file with mode: 0644]

index 6b7cdfd..16230dd 100644 (file)
 extern "C" {
 #endif
 
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "vc_audio_manager"
-
 typedef int (*dependency_audio_manager_feed_audio_data)(const void* data, const unsigned int length);
 
 int vcd_dependency_initialize(sound_stream_info_h stream_info_h, dependency_audio_manager_feed_audio_data callback);
index 89a1788..e676d2b 100644 (file)
@@ -25,6 +25,7 @@
 #include <sound_manager_internal.h>
 
 #include "vce.h"
+#include "vc_audio_manager_dlog.h"
 #include "vc_audio_manager.h"
 
 
@@ -58,7 +59,7 @@ static bool __convert_audio_channel(int channel, audio_channel_e* output)
        case 7: audio_ch = AUDIO_CHANNEL_MULTI_7;       break;
        case 8: audio_ch = AUDIO_CHANNEL_MULTI_8;       break;
        default:
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Input channel is not supported. [channel(%d)]", channel);
+               VCAM_LOGE("[ERROR] Input channel is not supported. [channel(%d)]", channel);
                return false;
        }
 
@@ -78,7 +79,7 @@ static bool __convert_audio_sample_type(vce_audio_type_e audio_type, audio_sampl
                audio_sample_type = AUDIO_SAMPLE_TYPE_U8;
                break;
        default:
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Invalid Audio Type. [type(%d)]", audio_type);
+               VCAM_LOGE("[ERROR] Invalid Audio Type. [type(%d)]", audio_type);
                return false;
        }
 
@@ -91,20 +92,22 @@ static Eina_Bool __recorder_timer_func(void *data)
        const int FRAME_LENGTH = 160;
        const int BUFFER_LENGTH = FRAME_LENGTH * 2;
 
-       if (g_is_recording && nullptr != g_feed_audio_data) {
+       if (g_is_recording) {
                unsigned char buffer[BUFFER_LENGTH];
                memset(buffer, '\0', BUFFER_LENGTH);
 
                int read_bytes = audio_in_read(g_audio_h, buffer, BUFFER_LENGTH);
                if (0 > read_bytes) {
-                       SLOG(LOG_WARN, LOG_TAG, "[WARNING] Fail to read audio : %d", read_bytes);
+                       VCAM_LOGW("[WARNING] Fail to read audio : %d", read_bytes);
                        return ECORE_CALLBACK_DONE;
                }
 
                // TODO: check return value?
-               g_feed_audio_data(buffer, read_bytes);
+               if (nullptr != g_feed_audio_data) {
+                       g_feed_audio_data(buffer, read_bytes);
+               }
        } else {
-               SLOG(LOG_DEBUG, LOG_TAG, "[DEBUG] Recording is finished");
+               VCAM_LOGD("[DEBUG] Recording is finished");
                return ECORE_CALLBACK_DONE;
        }
 
@@ -122,8 +125,6 @@ int vcd_dependency_initialize(sound_stream_info_h stream_info_h, dependency_audi
        audio_channel_e audio_ch = AUDIO_CHANNEL_MONO;
        audio_sample_type_e audio_sample_type = AUDIO_SAMPLE_TYPE_U8;
 
-       SLOG(LOG_INFO, LOG_TAG, "[Recorder] Audio type(%d) rate(%d) channel(%d)", g_audio_type, g_audio_rate, g_audio_channel);
-
        if (false == __convert_audio_channel(g_audio_channel, &audio_ch)) {
                return VCE_ERROR_INVALID_PARAMETER;
        }
@@ -132,37 +133,43 @@ int vcd_dependency_initialize(sound_stream_info_h stream_info_h, dependency_audi
                return VCE_ERROR_INVALID_PARAMETER;
        }
 
+       VCAM_LOGI("Audio type(%d), rate(%d), channel(%d)", g_audio_type, g_audio_rate, g_audio_channel);
+
        ret = audio_in_create(g_audio_rate, audio_ch, audio_sample_type, &g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Rate(%d) Channel(%d) Type(%d)", g_audio_rate, audio_ch, audio_sample_type);
-               SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Fail to create audio handle : %d", ret);
+               VCAM_LOGE("[ERROR] Fail to create audio handle : %d", ret);
+               return VCE_ERROR_OPERATION_FAILED;
        }
 
-       if (0 != audio_in_set_sound_stream_info(g_audio_h, stream_info_h)) {
-               SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Fail to set stream info");
+       ret = audio_in_set_sound_stream_info(g_audio_h, stream_info_h);
+       if (AUDIO_IO_ERROR_NONE != ret) {
+               VCAM_LOGE("[ERROR] Fail to set stream info : %d", ret);
+               audio_in_destroy(g_audio_h);
+               return VCE_ERROR_OPERATION_FAILED;
        }
 
        g_audio_source_type = strdup(VCE_AUDIO_ID_NONE);
        g_feed_audio_data = callback;
        g_is_recording = false;
 
-       return ret;
+       return VCE_ERROR_NONE;
 }
 
 int vcd_dependency_deinitialize(void)
 {
+       VCAM_LOGI("");
        int ret = 0;
        if (g_is_recording) {
                ret = audio_in_unprepare(g_audio_h);
                if (0 != ret) {
-                       SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Fail to stop audio : %d", ret);
+                       VCAM_LOGE("[ERROR] Fail to stop audio : %d", ret);
                }
                g_is_recording = false;
        }
 
        ret = audio_in_destroy(g_audio_h);
        if (0 != ret) {
-               SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Fail to audio in destroy, ret(%d)", ret);
+               VCAM_LOGE("[ERROR] Fail to audio in destroy, ret(%d)", ret);
        }
 
        g_audio_h = nullptr;
@@ -178,22 +185,22 @@ int vcd_dependency_deinitialize(void)
 int vcd_dependency_set_audio_info(sound_stream_info_h stream_info_h, const char* audio_source_type, vce_audio_type_e type, int rate, int channel)
 {
        if (nullptr == audio_source_type) {
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Invalid audio source type.");
+               VCAM_LOGE("[ERROR] Invalid audio source type.");
                return VCE_ERROR_INVALID_PARAMETER;
        }
 
        if (nullptr == g_audio_h || nullptr == g_audio_source_type) {
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Audio in handle is not valid.");
+               VCAM_LOGE("[ERROR] Audio in handle is not valid.");
                return VCE_ERROR_INVALID_STATE;
        }
 
        if (0 == strncmp(g_audio_source_type, audio_source_type, strlen(g_audio_source_type)) ||
                        (g_audio_type == type && g_audio_rate == rate && g_audio_channel == channel)) {
-               SLOG(LOG_INFO, LOG_TAG, "[DEBUG] No changed information");
+               VCAM_LOGI("No changed information");
                return VCE_ERROR_NONE;
        }
 
-       SLOG(LOG_INFO, LOG_TAG, "[Recorder] New audio type(%d) rate(%d) channel(%d)", type, rate, channel);
+       VCAM_LOGI("New audio type(%d) rate(%d) channel(%d)", type, rate, channel);
        audio_in_destroy(g_audio_h);
 
        audio_channel_e audio_ch = AUDIO_CHANNEL_MONO;
@@ -210,37 +217,38 @@ int vcd_dependency_set_audio_info(sound_stream_info_h stream_info_h, const char*
        int ret = 0;
        ret = audio_in_create(rate, audio_ch, audio_sample_type, &g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Fail to create audio handle. [ret(%d)]", ret);
+               VCAM_LOGE("[ERROR] Fail to create audio handle. [ret(%d)]", ret);
                return ret;
        }
 
        if (0 != audio_in_set_sound_stream_info(g_audio_h, stream_info_h)) {
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Fail to set stream info");
+               VCAM_LOGE("[ERROR] Fail to set stream info");
        }
 
        g_audio_type = type;
        g_audio_rate = rate;
        g_audio_channel = channel;
 
+       VCAM_LOGI("");
        return ret;
 }
 
 int vcd_dependency_start_recording(void)
 {
+       VCAM_LOGI("");
        int ret = 0;
 
        if (nullptr == g_audio_h) {
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Audio in handle is not valid.");
-
+               VCAM_LOGE("[ERROR] Audio in handle is not valid.");
                return VCE_ERROR_INVALID_STATE;
        }
 
        ret = audio_in_prepare(g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
                if (AUDIO_IO_ERROR_SOUND_POLICY == ret) {
-                       SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Audio is busy.");
+                       VCAM_LOGE("[ERROR] Audio is busy.");
                } else {
-                       SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Fail to start audio : %d", ret);
+                       VCAM_LOGE("[ERROR] Fail to start audio : %d", ret);
                }
 
                return ret;
@@ -259,10 +267,11 @@ int vcd_dependency_start_recording(void)
 
 int vcd_dependency_stop_recording(void)
 {
+       VCAM_LOGI("");
        int ret = 0;
 
        if (nullptr == g_audio_h) {
-               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Audio in handle is not valid.");
+               VCAM_LOGE("[ERROR] Audio in handle is not valid.");
 
                return VCE_ERROR_INVALID_STATE;
        }
@@ -271,7 +280,7 @@ int vcd_dependency_stop_recording(void)
 
        ret = audio_in_unprepare(g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, LOG_TAG, "[Recorder ERROR] Fail to stop audio : %d", ret);
+               VCAM_LOGE("[ERROR] Fail to stop audio : %d", ret);
        }
 
        return ret;
diff --git a/audio-manager/src/vc_audio_manager_dlog.h b/audio-manager/src/vc_audio_manager_dlog.h
new file mode 100644 (file)
index 0000000..61c53c5
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __VC_AUDIO_MANAGER_DLOG__
+#define __VC_AUDIO_MANAGER_DLOG__
+
+#include <dlog.h>
+#include <glib.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "vc_audio_manager"
+
+#ifdef __MODULE__
+#undef __MODULE__
+#endif
+#define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define VCAM_LOG_(prio, tag, fmt, arg...) \
+       ({ do { \
+               dlog_print(prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
+       } while (0); })
+
+#define VCAM_LOGD(fmt, args...) VCAM_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args)
+#define VCAM_LOGI(fmt, args...) VCAM_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args)
+#define VCAM_LOGW(fmt, args...) VCAM_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args)
+#define VCAM_LOGE(fmt, args...) VCAM_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args)
+
+
+#endif /* __VC_AUDIO_MANAGER_DLOG__ */