Merge branch 'tizen_3.0' into tizen 89/114689/1 submit/tizen/20170214.125635
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 14 Feb 2017 11:34:13 +0000 (20:34 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 14 Feb 2017 11:34:22 +0000 (20:34 +0900)
Change-Id: I2037657f5a355a60197e30841c97721c9feb0c6a

focus_server/mm_sound_mgr_focus.c
packaging/libmm-sound.spec
server/plugin/ogg/mm_sound_plugin_codec_ogg.c
server/plugin/tone/mm_sound_plugin_codec_tone.c

index 05bd28c..40beb58 100644 (file)
@@ -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;
 }
index 17c9fa1..59630cf 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.10.93
+Version:    0.10.94
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 5151aa0..805c7a6 100644 (file)
@@ -90,36 +90,70 @@ typedef struct {
 
 static int (*g_thread_pool_func)(void*, void (*)(void*)) = NULL;
 
+static void _reset_ogg_decoder(ogg_info_t *p)
+{
+       int err, used_size, skipsize;
+       OGG_DEC_INFO ogg_info;
+
+       err = OGGDEC_ResetDecode(p->decoder);
+       if (err != OGGDEC_SUCCESS) {
+               debug_error("Failed to RESET decoder!");
+               return;
+       }
+
+       err = OGGDEC_InitDecode(p->decoder, (unsigned char*)p->source->ptr, p->BufferSize, &skipsize);
+       if (err != OGGDEC_SUCCESS) {
+               debug_error("Failed to INIT decoder!");
+               return;
+       }
+
+       err = OGGDEC_InfoDecode(p->decoder, p->source->ptr + skipsize, &used_size, &ogg_info);
+       if (err != OGGDEC_SUCCESS) {
+               debug_error("Failed to INFO decoder!");
+               return;
+       }
+}
+
 void _pcm_out_func(void *data)
 {
-       ogg_info_t *p = (ogg_info_t*) data;
-       int used_size;
-       int decoded_len;
-       unsigned char* ogg_buf;
-       unsigned int ogg_remain;
-       int err;
+       ogg_info_t *p = (ogg_info_t *)data;
+       int used_size = 0;
+       int decoded_len = 0;
+       unsigned char* ogg_buf = NULL;
+       int err = 0;
 
-       debug_enter("\n");
+       debug_enter();
+
+       if (!p) {
+               debug_error("Invalid ogg_info_t...");
+               return;
+       }
 
        sem_wait(&p->start_wave_signal);
-       ogg_buf = MMSourceGetPtr(p->source);
-       ogg_remain = MMSourceGetCurSize(p->source);
 
-       while (p->state == STATE_PLAY) {
-               err = OGGDEC_FrameDecode(p->decoder, ogg_buf+p->offset, &used_size, p->pcm_out_buf, &decoded_len);
-               if (decoded_len > 0) {
+       while (((p->repeat_count == -1) ? (1) : (p->repeat_count--)) && p->state == STATE_PLAY) {
+               ogg_buf = MMSourceGetPtr(p->source) + p->offset;
+
+               while (p->state == STATE_PLAY) {
+                       decoded_len = 0;
+                       err = OGGDEC_FrameDecode(p->decoder, ogg_buf, &used_size, p->pcm_out_buf, &decoded_len);
+                       if (decoded_len <= 0) {
+                               debug_error("decoded len = %d", decoded_len);
+                               break;
+                       }
+
                        mm_sound_pa_write(p->handle, p->pcm_out_buf, decoded_len);
                        ogg_buf += used_size;
-                       ogg_remain -= used_size;
-                       if(err != OGGDEC_SUCCESS) {
-                               MMSoundPlugCodecOggStop((MMHandleType)p);
-                               debug_error("Decode done :: %d\n", err);
+
+                       if (err != OGGDEC_SUCCESS)
                                break;
-                       }
-               } else {
-                       MMSoundPlugCodecOggStop((MMHandleType)p);
-                       break;
                }
+
+               debug_error("decode done = [%d], repeat_count = [%d]", err, p->repeat_count);
+               if (err == OGGDEC_FAIL || p->repeat_count == 0)
+                       MMSoundPlugCodecOggStop((MMHandleType)p);
+               else
+                       _reset_ogg_decoder(p);
        }
 
        mm_sound_pa_drain(p->handle);
@@ -128,10 +162,10 @@ void _pcm_out_func(void *data)
        /* Notice */
        /* OggDestory is called by stop_cb func */
        /* INDEED the stop_cb must be called, after end of all progress */
-       if(p->stop_cb) {
+       if (p->stop_cb)
                p->stop_cb(p->cb_param);
-       }
-       debug_leave("\n");
+
+       debug_leave();
 }
 
 int MMSoundPlugCodecOggSetThreadPool(int (*func)(void*, void (*)(void*)))
index 6507f1a..8599b9d 100644 (file)
 #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) {