Merge patch for tone sound 07/113807/5
authoreonseok.lee <eonseok.lee@samsung.com>
Thu, 9 Feb 2017 02:12:30 +0000 (11:12 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 14 Feb 2017 05:41:01 +0000 (21:41 -0800)
- Two stops for the same slot in toneplayer create issue
- tone play does not stop issue

[Model] tizen3.0
[BinType] AP
[Customer] OPEN
[Issue#] N/A
[Request] N/A
[Occurrence Version] N/A
[Problem] Two stops for the same slot in toneplayer create issue/tone
 10 play does not stop issue
[Cause & Measure] sound_stop is called two times with the same
 handle/start and stop is too fast
[Checking Method] N/A
[Team] MMFW
[Developer] eonseok.lee
[Solution company] Samsung
[Change Type] N/A

Change-Id: Icad5cffc69909c0e3b3834660bb4d72071df5204

focus_server/mm_sound_mgr_focus.c [changed mode: 0644->0755]
server/plugin/tone/mm_sound_plugin_codec_tone.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 05bd28c..40beb58
@@ -545,16 +545,16 @@ static int _mm_sound_mgr_focus_list_dump ()
        GList *list = NULL;
        focus_node_t *node = NULL;
 
-       debug_log("================================================ focus node list : start ===================================================\n");
+       debug_msg("================================================ focus node list : start ===================================================\n");
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                if ((node = (focus_node_t *)list->data) && !node->is_for_watch) {
-                       debug_log("*** pid[%5d]/handle_id[%2d]/[%14s]:priority[%2d],status[%s],taken_by[P(%5d/%2d/%2d)C(%5d/%2d/%2d)],session[%d],option[0x%x/0x%x],ext_info[%s/%s]\n",
+                       debug_msg("*** pid[%5d]/handle_id[%2d]/[%14s]:priority[%2d],status[%s],taken_by[P(%5d/%2d/%2d)C(%5d/%2d/%2d)],session[%d],option[0x%x/0x%x],ext_info[%s/%s]\n",
                                        node->pid, node->handle_id, node->stream_type, node->priority, focus_status_str[node->status],
                                        node->taken_by_id[0].pid, node->taken_by_id[0].handle_id, node->taken_by_id[0].by_session, node->taken_by_id[1].pid,
                                        node->taken_by_id[1].handle_id, node->taken_by_id[1].by_session, node->is_for_session, node->option[0], node->option[1], node->ext_info[0], node->ext_info[1]);
                }
        }
-       debug_log("================================================ focus node list : end =====================================================\n");
+       debug_msg("================================================ focus node list : end =====================================================\n");
 
        return ret;
 }
@@ -565,12 +565,12 @@ static int _mm_sound_mgr_focus_watch_list_dump()
        GList *list = NULL;
        focus_node_t *node = NULL;
 
-       debug_log("============================================= focus watch node list : start =================================================\n");
+       debug_msg("============================================= focus watch node list : start =================================================\n");
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                if ((node = (focus_node_t *)list->data) && node->is_for_watch)
-                       debug_log("*** pid[%5d]/handle_id[%d]/watch on focus status[%s]/for_session[%d]\n", node->pid, node->handle_id, focus_status_str[node->status], node->is_for_session);
+                       debug_msg("*** pid[%5d]/handle_id[%d]/watch on focus status[%s]/for_session[%d]\n", node->pid, node->handle_id, focus_status_str[node->status], node->is_for_session);
        }
-       debug_log("============================================= focus watch node list : end ===================================================\n");
+       debug_msg("============================================= focus watch node list : end ===================================================\n");
 
        return ret;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 6507f1a..8599b9d
 #define CHANNELS 1
 #define MAX_DURATION 100
 #define TONE_COLUMN 6
+#define WAIT_THREAD_WAIT_CNT 100
+#define WAIT_THREAD_WAIT_TIME 10 /* ms */
 
 typedef enum {
-   STATE_NONE = 0,
-   STATE_READY,
-   STATE_BEGIN,
-   STATE_PLAY,
-   STATE_STOP,
+       STATE_NONE = 0,
+       STATE_READY,
+       STATE_BEGIN,
+       STATE_PLAY,
+       STATE_STOP,
 } state_e;
 
 typedef enum {
+       THREAD_STATE_NONE = 0,
+       THREAD_STATE_START,
+       THREAD_STATE_STOP,
+} thread_state_e;
+
+
+typedef enum {
        CONTROL_STOPPED,
        CONTROL_READY,
        CONTROL_STARTING,
@@ -79,6 +88,7 @@ typedef struct {
 typedef struct {
      /* AMR Buffer */
        int                             size; /* sizeof hole amr data */
+       pthread_mutex_t         mutex;
 
      /* Audio Infomations */
        int                             handle;
@@ -93,6 +103,7 @@ typedef struct {
        int                             time;
        int                             pid;
 
+       int                             thread_state;
 } tone_info_t;
 
 typedef enum
@@ -761,6 +772,7 @@ int MMSoundPlugCodecToneCreate(mmsound_codec_param_t *param, mmsound_codec_info_
        int size;
 
        int result = MM_ERROR_NONE;
+       int wait_count = 0;
 
        debug_enter("\n");
 
@@ -772,7 +784,11 @@ int MMSoundPlugCodecToneCreate(mmsound_codec_param_t *param, mmsound_codec_info_
 
        memset(toneInfo, 0, sizeof(tone_info_t));
 
+       pthread_mutex_init(&toneInfo->mutex, NULL);
+       pthread_mutex_lock(&toneInfo->mutex);
        toneInfo->state = STATE_READY;
+       toneInfo->thread_state = THREAD_STATE_NONE;
+       pthread_mutex_unlock(&toneInfo->mutex);
 
        ss.rate = SAMPLERATE;
        ss.channels = CHANNELS;
@@ -807,6 +823,18 @@ int MMSoundPlugCodecToneCreate(mmsound_codec_param_t *param, mmsound_codec_info_
 
        *handle = (MMHandleType)toneInfo;
 
+       debug_msg("wait until thread_stare THREAD_STATE_START");
+       while((toneInfo->thread_state == THREAD_STATE_NONE) && (wait_count < WAIT_THREAD_WAIT_CNT)) {
+               usleep(WAIT_THREAD_WAIT_TIME * 1000);
+               wait_count++;
+       }
+
+       if (wait_count >= WAIT_THREAD_WAIT_CNT) {
+               debug_error("timeout for thread pool. wait_count: %d ms ", WAIT_THREAD_WAIT_CNT * WAIT_THREAD_WAIT_TIME);
+       } else {
+               debug_msg("_running_tone thread is started");
+       }
+
        debug_leave("\n");
        return MM_ERROR_NONE;
 
@@ -834,6 +862,7 @@ int MMSoundPlugCodecToneDestroy(MMHandleType handle)
 
        debug_enter("(handle %x)\n", handle);
 
+       pthread_mutex_destroy(&toneInfo->mutex);
        if (toneInfo)
                free (toneInfo);
 
@@ -847,8 +876,9 @@ int MMSoundPlugCodecTonePlay(MMHandleType handle)
        tone_info_t *toneInfo = (tone_info_t *) handle;
 
        debug_enter("(handle %x)\n", handle);
-
+       pthread_mutex_lock(&toneInfo->mutex);
        toneInfo->state = STATE_BEGIN;
+       pthread_mutex_unlock(&toneInfo->mutex);
        debug_msg("sent start signal\n");
 
        debug_leave("\n");
@@ -1024,6 +1054,10 @@ static void _running_tone(void *param)
        gboolean is_cycle_ended = FALSE;
 
        debug_enter("\n");
+       pthread_mutex_lock(&toneInfo->mutex);
+       toneInfo->thread_state = THREAD_STATE_START;
+       debug_msg("set thread_state as  THREAD_STATE_START");
+       pthread_mutex_unlock(&toneInfo->mutex);
        double sample = 0;
        toneTime = toneInfo->time;
        if(toneTime != 0) {
@@ -1037,12 +1071,23 @@ static void _running_tone(void *param)
                while(toneInfo->state == STATE_READY)
                        usleep(10);
                debug_msg("Recv start signal\n");
-               toneInfo->state = STATE_PLAY;
+               pthread_mutex_lock(&toneInfo->mutex);
+
+               if ((toneInfo->state == STATE_STOP)||(toneInfo->thread_state == THREAD_STATE_STOP)) {
+                       debug_msg("state is stop. state(%d)  thread_state(%d) goto exit.\n", toneInfo->state, toneInfo->thread_state );
+                       pthread_mutex_unlock(&toneInfo->mutex);
+                       goto exit;
+               } else {
+                       debug_msg("set state STATE_PLAY\n");
+                       toneInfo->state = STATE_PLAY;
+               }
+               pthread_mutex_unlock(&toneInfo->mutex);
+
        } else {
                return;
        }
 
-       while (1) {
+       while (toneInfo->thread_state == THREAD_STATE_START) {
                TONE _TONE = _mm_get_tone(toneKey, CurIndex); /*Pop one of Tone Set */
                if(_mm_get_waveCnt_PlayingTime(toneTime, _TONE, &numWave, &waveRestPlayTime) != MM_ERROR_NONE) {
                        debug_error("_mm_get_waveCnt_PlayingTime return value error\n");
@@ -1115,7 +1160,9 @@ exit :
 #endif
 
        debug_msg("Play end\n");
+       pthread_mutex_lock(&toneInfo->mutex);
        toneInfo->state = STATE_NONE;
+       pthread_mutex_unlock(&toneInfo->mutex);
 
        if (toneInfo->stop_cb)
                toneInfo->stop_cb(toneInfo->cb_param);
@@ -1129,7 +1176,16 @@ int MMSoundPlugCodecToneStop(MMHandleType handle)
        tone_info_t *toneInfo = (tone_info_t*) handle;
 
        debug_enter("(handle %x)\n", handle);
+       pthread_mutex_lock(&toneInfo->mutex);
+       /*If stopped why stop again*/
+       if (toneInfo->state == STATE_NONE || toneInfo->state == STATE_STOP) {
+               pthread_mutex_unlock(&toneInfo->mutex);
+               debug_msg("state(%d) is already STOP or NONE. return\n", toneInfo->state);
+               return MM_ERROR_NONE;
+       }
        toneInfo->state = STATE_STOP;
+       toneInfo->thread_state = THREAD_STATE_STOP;
+       pthread_mutex_unlock(&toneInfo->mutex);
        debug_msg("sent stop signal\n");
 
        while(toneInfo->state != STATE_NONE) {