Revise code related to coding conventions and adjust some log levels 22/226222/1
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 28 Feb 2020 04:54:45 +0000 (13:54 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 28 Feb 2020 04:54:45 +0000 (13:54 +0900)
[Version] 0.12.63
[Issue Type] Revision

Change-Id: I5ac7e618fbab8f2d972a9fd94748ccd10c5776b4

packaging/libmm-sound.spec
server/mm_sound_mgr_codec.c
server/plugin/wav/mm_sound_plugin_codec_wave.c

index a479f0e..a6bf755 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.12.62
+Version:    0.12.63
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 1bb36f1..6e4192f 100644 (file)
@@ -67,8 +67,21 @@ static pthread_mutex_t g_slot_mutex;
 static GSourceFunc g_shutdown_cb;
 static guint g_timer_id = 0;
 
-#define SLOT_LOCK() do { pthread_mutex_lock(&g_slot_mutex); /* debug_msg("After Slot_mutex LOCK"); */ } while (0)
-#define SLOT_UNLOCK() do { pthread_mutex_unlock(&g_slot_mutex); /* debug_msg("After Slot_mutex UNLOCK"); */ } while (0)
+#ifdef DEBUG_DETAIL
+#define SLOT_LOCK() do { \
+       debug_msg("Before Slot_mutex LOCK"); \
+       pthread_mutex_lock(&g_slot_mutex); \
+       debug_msg("After Slot_mutex LOCK"); \
+} while (0)
+#define SLOT_UNLOCK() do { \
+       debug_msg("Before Slot_mutex UNLOCK"); \
+       pthread_mutex_unlock(&g_slot_mutex); \
+       debug_msg("After Slot_mutex UNLOCK"); \
+} while (0)
+#else
+#define SLOT_LOCK() do { pthread_mutex_lock(&g_slot_mutex); } while (0)
+#define SLOT_UNLOCK() do { pthread_mutex_unlock(&g_slot_mutex); } while (0)
+#endif
 
 static int _MMSoundMgrCodecRegisterInterface(MMSoundPluginType *plugin);
 static int _MMSoundMgrCodecStopCallback(int param);
@@ -107,7 +120,7 @@ static void _mm_sound_mgr_codec_shutdown_timer_start()
        }
        if (g_shutdown_cb) {
                g_timer_id = g_timeout_add_seconds(SHUTDOWN_TIMEOUT_SEC, _timeout_cb, NULL);
-               debug_error("TIMER : new timer [%d]", g_timer_id);
+               debug_warning("TIMER : new timer [%d]", g_timer_id);
        } else {
                debug_warning("No Timer started due to invalid shutdown callback");
        }
@@ -116,7 +129,7 @@ static void _mm_sound_mgr_codec_shutdown_timer_start()
 static void _mm_sound_mgr_codec_shutdown_timer_stop()
 {
        if (g_timer_id > 0) {
-               debug_error("TIMER : remove timer id [%d]", g_timer_id);
+               debug_warning("TIMER : remove timer id [%d]", g_timer_id);
                g_source_remove(g_timer_id);
                g_timer_id = 0;
        } else {
@@ -169,12 +182,13 @@ static gboolean _mm_sound_mgr_codec_slot_is_empty()
        return (slotid == MANAGER_HANDLE_MAX) ? TRUE : FALSE;
 }
 
-static void _mm_sound_mgr_codec_slot_clear(int slotid)
+static void _mm_sound_mgr_codec_slot_clear(int slotid, bool dump)
 {
        memset(&g_slots[slotid], 0, sizeof(__mmsound_mgr_codec_handle_t));
        g_slots[slotid].status = STATUS_IDLE;
 
-       debug_error("SlotID [%d] cleared", slotid);
+       if (dump)
+               debug_warning("SlotID [%d] cleared", slotid);
 }
 
 int MMSoundMgrCodecInit(const char *targetdir, GSourceFunc _shutdown_cb)
@@ -192,7 +206,7 @@ int MMSoundMgrCodecInit(const char *targetdir, GSourceFunc _shutdown_cb)
        }
 
        for (slotid = 0; slotid < MANAGER_HANDLE_MAX; slotid++)
-               _mm_sound_mgr_codec_slot_clear(slotid);
+               _mm_sound_mgr_codec_slot_clear(slotid, false);
 
        if (g_codec_plugins) {
                debug_warning("Please Check Init twice");
@@ -437,11 +451,11 @@ static int _MMSoundMgrCodecStopCallback(int param)
        int err = MM_ERROR_NONE;
 
        if (param < 0 || param >= MANAGER_HANDLE_MAX) {
-               debug_error("Slot index param [%d] is invalid", param);
+               debug_error("Slot(%d) is invalid", param);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       debug_enter("(Slot : %d) stop-by-user : %d", param, g_slots[param].stop_by_user);
+       debug_enter("Slot(%d) : stop-by-user(%d)", param, g_slots[param].stop_by_user);
 
        if (!g_slots[param].stop_by_user) {
                SLOT_LOCK();
@@ -452,9 +466,9 @@ static int _MMSoundMgrCodecStopCallback(int param)
        debug_msg("Handle allocated handle : [%p]", g_slots[param].plughandle);
        err = g_plugins[g_slots[param].pluginid].Destroy(g_slots[param].plughandle);
        if (err < 0)
-               debug_critical("[CODEC MGR] Fail to destroy slot number : [%d] err [0x%x]", param, err);
+               debug_critical("Slot(%d) : Fail to destroy slot, err [0x%x]", param, err);
 
-       _mm_sound_mgr_codec_slot_clear(param);
+       _mm_sound_mgr_codec_slot_clear(param, true);
        if (_mm_sound_mgr_codec_slot_is_empty())
                _mm_sound_mgr_codec_shutdown_timer_start();
 
index 933d5db..7174ca3 100644 (file)
@@ -49,9 +49,9 @@ typedef struct {
 
        pa_threaded_mainloop *m;
        pa_context *c;
-       pa_streams;
+       pa_stream *s;
        pa_sample_spec spec;
-       SNDFILEsf;
+       SNDFILE *sf;
        SF_INFO si;
 } wave_info_t;
 
@@ -198,15 +198,15 @@ static void _pa_stream_state_callback(pa_stream *s, void *userdata)
        }
 }
 
-static void _pa_stream_drain_complete_callback(pa_streams, int success, void *userdata)
+static void _pa_stream_drain_complete_callback(pa_stream *s, int success, void *userdata)
 {
        pa_operation *o = NULL;
        wave_info_t *h = (wave_info_t *)userdata;
 
-       debug_msg("drain complete : %p, %d", s, success);
+       debug_msg("stream(%p) : drain completed(%d)", s, success);
 
        if (!success) {
-               debug_error("drain failed. s(%p), success(%d)", s, success);
+               debug_error("stream(%p) : drain failed(%d)", s, success);
                //pa_threaded_mainloop_signal(h->m, 0);
        }
 
@@ -215,7 +215,7 @@ static void _pa_stream_drain_complete_callback(pa_stream* s, int success, void *
        h->s = NULL;
 
        if (!(o = pa_context_drain(h->c, _pa_context_drain_complete_callback, h->m))) {
-               debug_error("failed to drain context!");
+               debug_error("context(%p) failed to drain context!", h->c);
                pa_context_disconnect(h->c);
                pa_context_unref(h->c);
                h->c = NULL;
@@ -223,7 +223,7 @@ static void _pa_stream_drain_complete_callback(pa_stream* s, int success, void *
                pa_operation_unref(o);
        }
 
-       debug_msg("Call stop callback(%p, %d) of mgr_codec", h->stop_cb, h->cb_param);
+       debug_msg("Invoke stop callback(%p, %d) of mgr_codec", h->stop_cb, h->cb_param);
        if (h->stop_cb)
                h->stop_cb(h->cb_param);
 }
@@ -231,7 +231,7 @@ static void _pa_stream_drain_complete_callback(pa_stream* s, int success, void *
 static void _pa_stream_moved_callback(pa_stream *s, void *userdata)
 {
        assert(s);
-       debug_msg("stream moved callback : %p", s);
+       debug_msg("stream(%p)", s);
 }
 
 static void _pa_stream_underflow_callback(pa_stream *s, void *userdata)
@@ -239,13 +239,13 @@ static void _pa_stream_underflow_callback(pa_stream *s, void *userdata)
        wave_info_t *h = (wave_info_t *)userdata;
        assert(s);
 
-       debug_msg("stream underflow callback : %p, file(%s)", s, h->filename);
+       debug_msg("stream(%p) : file(%s)", s, h->filename);
 }
 
 static void _pa_stream_buffer_attr_callback(pa_stream *s, void *userdata)
 {
        assert(s);
-       debug_msg("stream underflow callback : %p", s);
+       debug_msg("stream(%p)", s);
 }
 
 static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdata)
@@ -258,7 +258,7 @@ static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdat
        wave_info_t *h = (wave_info_t *)userdata;
 
        if (!s || length <= 0) {
-               debug_error("write error. stream(%p), length(%zu)", s, length);
+               debug_error("stream(%p) : length(%zu)", s, length);
                return;
        }
 
@@ -266,19 +266,19 @@ static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdat
        data_length = length;
 
        if (frame_size == 0) {
-               debug_error("frame size can't be 0");
+               debug_error("stream(%p) : frame size can't be 0", s);
                return;
        }
 
        if (pa_stream_begin_write(s, &data, &data_length) < 0) {
-               debug_error("failed to pa_stream_begin_write()");
+               debug_error("stream(%p) : failed to pa_stream_begin_write()", s);
                return;
        }
 
        if ((bytes = sf_readf_short(h->sf, data, (sf_count_t)(data_length / frame_size))) > 0)
                bytes *= (sf_count_t)frame_size;
 
-       debug_log("=== %"PRId64" / %zu ===", bytes, data_length);
+       debug_msg("stream(%p) : === %"PRId64" / %zu ===", s, bytes, data_length);
 
        if (bytes > 0)
                pa_stream_write(s, data, (size_t)bytes, NULL, 0, PA_SEEK_RELATIVE);
@@ -287,11 +287,11 @@ static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdat
 
        /* If No more data, drain stream */
        if (bytes < (sf_count_t)data_length) {
-               debug_msg("EOS!!!!! %"PRId64"/%zu", bytes, data_length);
+               debug_msg("stream(%p) : End Of Stream", s);
 
                /* Handle loop */
                if (_sound_is_rewind_needed(h)) {
-                       debug_msg("repeat count = %d", h->repeat_count);
+                       debug_msg("stream(%p) : repeat count = %d", s, h->repeat_count);
                        /* do not decrease it in case of -1 for infinite play */
                        if (h->repeat_count != -1)
                                h->repeat_count--;
@@ -299,7 +299,7 @@ static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdat
                        if (_sound_rewind(h) == 0)
                                return;
 
-                       debug_error("REWIND failed....");
+                       debug_error("stream(%p) : REWIND failed....", s);
                        /* can't loop anymore, fallback and do drain */
                }
 
@@ -309,7 +309,8 @@ static void _pa_stream_write_callback(pa_stream *s, size_t length, void *userdat
                if (o)
                        pa_operation_unref(o);
                else
-                       debug_error("failed to drain stream %p", s);
+                       debug_error("stream(%p) : failed to drain", s);
+               debug_msg("stream(%p) : reset write callback and drain requested", s);
        }
 }
 
@@ -407,7 +408,7 @@ static int _pa_stream_connect(wave_info_t *h)
                PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_START_CORKED,
                NULL, NULL);
        if (ret < 0) {
-               debug_error("failed to pa_stream_connect_playback(), ret(%d)", ret);
+               debug_error("stream(%p) : failed to connect playback, ret(%d)", s, ret);
                goto error;
        }
        for (;;) {
@@ -417,7 +418,7 @@ static int _pa_stream_connect(wave_info_t *h)
                        break;
 
                if (!PA_STREAM_IS_GOOD(state)) {
-                       debug_error("Stream error!!!! %d", state);
+                       debug_error("stream(%p) : state(%d)", s, state);
                        goto error;
                }
 
@@ -453,7 +454,7 @@ static void _pa_stream_uncork(wave_info_t *h)
        if ((o = pa_stream_cork(h->s, 0, NULL, NULL)))
                pa_operation_unref(o);
        else
-               debug_error("stream uncork failed");
+               debug_error("stream(%p) : uncork failed", h->s);
 
        pa_threaded_mainloop_unlock(h->m);
 }
@@ -480,7 +481,7 @@ static void _pa_stream_stop_disconnect(wave_info_t *h)
        h->m = NULL;
 }
 
-static int* _mm_sound_plug_codec_wave_get_supported_types(void)
+static int * _mm_sound_plug_codec_wave_get_supported_types(void)
 {
        static int suported[2] = { MM_SOUND_SUPPORTED_CODEC_WAVE, 0 };
        return suported;
@@ -488,7 +489,7 @@ static int* _mm_sound_plug_codec_wave_get_supported_types(void)
 
 static int _mm_sound_plug_codec_wave_parse(const char *filename, mmsound_codec_info_t *info)
 {
-       SNDFILEsf = NULL;
+       SNDFILE *sf = NULL;
        SF_INFO si;
 
        if (!filename || !info) {
@@ -511,7 +512,7 @@ static int _mm_sound_plug_codec_wave_parse(const char *filename, mmsound_codec_i
        info->channels = si.channels;
        info->samplerate = si.samplerate;
 
-       debug_msg("filename = %s, frames[%"PRId64"], samplerate[%d], channels[%d], format[%x], sections[%d], seekable[%d]",
+       debug_msg("filename[%s], frames[%"PRId64"], samplerate[%d], channels[%d], format[%x], sections[%d], seekable[%d]",
                        filename, si.frames, si.samplerate, si.channels, si.format, si.sections, si.seekable);
        sf_close(sf);
 
@@ -520,103 +521,101 @@ static int _mm_sound_plug_codec_wave_parse(const char *filename, mmsound_codec_i
 
 static int _mm_sound_plug_codec_wave_create(mmsound_codec_param_t *param, mmsound_codec_info_t *info, MMHandleType *handle)
 {
-       wave_info_t* p = NULL;
+       wave_info_t *h = NULL;
        int ret = 0;
 
 #ifdef DEBUG_DETAIL
        debug_enter();
 #endif
 
-       p = (wave_info_t *) malloc(sizeof(wave_info_t));
-       if (p == NULL) {
+       h = (wave_info_t *)calloc(1, sizeof(wave_info_t));
+       if (h == NULL) {
                debug_error("memory allocation failed");
                return MM_ERROR_OUT_OF_MEMORY;
        }
 
-       memset(p, 0, sizeof(wave_info_t));
-       p->handle = 0;
-       p->repeat_count = param->repeat_count;
-       p->stop_cb = param->stop_cb;
-       p->cb_param = param->param;
-       MMSOUND_STRNCPY(p->filename, param->pfilename, MM_SOUND_MAX_FILENAME);
-       p->client_pid = param->pid;
-       p->stream_index = param->stream_index;
-       MMSOUND_STRNCPY(p->stream_type, param->stream_type, MAX_STREAM_TYPE_LEN);
-
-       ret = _sound_prepare(p);
+       h->handle = 0;
+       h->repeat_count = param->repeat_count;
+       h->stop_cb = param->stop_cb;
+       h->cb_param = param->param;
+       MMSOUND_STRNCPY(h->filename, param->pfilename, MM_SOUND_MAX_FILENAME);
+       h->client_pid = param->pid;
+       h->stream_index = param->stream_index;
+       MMSOUND_STRNCPY(h->stream_type, param->stream_type, MAX_STREAM_TYPE_LEN);
+
+       ret = _sound_prepare(h);
        if (ret < 0) {
                debug_error("failed to prepare sound");
                goto error;
        }
 
-       ret = _pa_context_connect(p);
+       ret = _pa_context_connect(h);
        if (ret < 0) {
                debug_error("failed to connect context...");
                goto error;
        }
 
-       ret = _pa_stream_connect(p);
+       ret = _pa_stream_connect(h);
        if (ret < 0) {
                debug_error("failed to connect stream...");
                goto error;
        }
 
-       *handle = (MMHandleType)p;
+       *handle = (MMHandleType)h;
 
 #ifdef DEBUG_DETAIL
-       debug_leave("%p", p);
+       debug_leave("%p", h);
 #endif
        return MM_ERROR_NONE;
 
 error:
-       _sound_unprepare(p);
-       free(p);
+       _sound_unprepare(h);
+       free(h);
        return MM_ERROR_SOUND_INTERNAL;
 }
 
 
 static int _mm_sound_plug_codec_wave_play(MMHandleType handle)
 {
-       wave_info_t *p = (wave_info_t *) handle;
+       wave_info_t *h = (wave_info_t *)handle;
 
-       debug_msg("Start handle %p", p);
-       _pa_stream_uncork(p);
+       debug_msg("Start handle(%p), stream(%p)", h, h->s);
+       _pa_stream_uncork(h);
 
        return MM_ERROR_NONE;
 }
 
 static int _mm_sound_plug_codec_wave_stop(MMHandleType handle)
 {
-       wave_info_t *p = (wave_info_t*) handle;
-
-       if (!p) {
+       wave_info_t *h = (wave_info_t *)handle;
+       if (!h) {
                debug_error("The handle is null");
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       debug_msg("Handle %p stop requested", p);
+       debug_msg("Handle %p stop requested", h);
 
-       _pa_stream_stop_disconnect(p);
+       _pa_stream_stop_disconnect(h);
 
-       if (p->stop_cb)
-               p->stop_cb(p->cb_param);
+       if (h->stop_cb)
+               h->stop_cb(h->cb_param);
 
        return MM_ERROR_NONE;
 }
 
 static int _mm_sound_plug_codec_wave_destroy(MMHandleType handle)
 {
-       wave_info_t *p = (wave_info_t *)handle;
+       wave_info_t *h = (wave_info_t *)handle;
 
-       if (!p) {
+       if (!h) {
                debug_error("Can not destroy handle :: handle is invalid");
                return MM_ERROR_SOUND_INVALID_POINTER;
        }
 
-       _sound_unprepare(p);
+       _sound_unprepare(h);
 
-       free(p);
-       p = NULL;
+       free(h);
+       h = NULL;
 
        return MM_ERROR_NONE;
 }