- int count = 0;
- mmsound_codec_info_t info;
- mmsound_codec_param_t codec_param;
- int err = MM_ERROR_NONE;
- int need_focus_unregister = 0;
-
-#ifdef DEBUG_DETAIL
- debug_enter("\n");
-#endif
-
- for (count = 0; g_plugins[count].GetSupportTypes; count++) {
- /* Find codec */
- if (g_plugins[count].Parse(param->source, &info) == MM_ERROR_NONE)
- break;
- }
-
- /*The count num means codec type WAV, MP3 */
- debug_msg("DTMF[%d] Repeat[%d] Volume[%f] plugin_codec[%d]\n", param->tone, param->repeat_count, param->volume, count);
-
- if (g_plugins[count].GetSupportTypes == NULL) { /* Codec not found */
- debug_error("unsupported file type %d\n", count);
- err = MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
- goto cleanup;
- }
-
-#ifdef DEBUG_DETAIL
- debug_msg("Get New handle\n");
-#endif
-
- err = _MMSoundMgrCodecGetEmptySlot(slotid);
- if (err != MM_ERROR_NONE || *slotid < 0) {
- debug_error("Empty g_slot is not found\n");
- goto cleanup;
- }
-
- codec_param.tone = param->tone;
- codec_param.volume_config = param->volume_config;
- codec_param.repeat_count = param->repeat_count;
- codec_param.volume = param->volume;
- codec_param.source = param->source;
- codec_param.priority = param->priority;
- codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
- codec_param.param = *slotid;
- codec_param.pid = (int)param->param;
- codec_param.handle_route = param->handle_route;
- codec_param.codec_wave_mutex = &codec_wave_mutex;
- codec_param.stream_index = param->stream_index;
- MMSOUND_STRNCPY(codec_param.stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
- pthread_mutex_lock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
- debug_msg("After Slot_mutex LOCK\n");
-#endif
-
- /*
- * Register FOCUS here
- */
-
- if (param->session_type != MM_SESSION_TYPE_CALL &&
- param->session_type != MM_SESSION_TYPE_VIDEOCALL &&
- param->session_type != MM_SESSION_TYPE_VOIP &&
- param->session_type != MM_SESSION_TYPE_VOICE_RECOGNITION &&
- param->enable_session) {
-
- unsigned int subs_id = 0;
-
- err = mm_sound_add_device_connected_callback(MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG, (mm_sound_device_connected_cb)sound_codec_device_connected_callback, (void*) *slotid, &subs_id);
- if (err) {
- debug_error("mm_sound_add_device_connected_callback failed [0x%x]", err);
- pthread_mutex_unlock(&g_slot_mutex);
- return MM_ERROR_POLICY_INTERNAL;
- }
- g_slots[*slotid].subs_id = subs_id;
-
- if ((param->session_options & MM_SESSION_OPTION_PAUSE_OTHERS) || param->session_type == MM_SESSION_TYPE_ALARM || param->session_type == MM_SESSION_TYPE_NOTIFY || param->session_type == MM_SESSION_TYPE_EMERGENCY) {
- debug_warning("session option is PAUSE_OTHERS -> acquire focus");
- err = mm_sound_focus_get_id((int *)(¶m->focus_handle));
- err = mm_sound_register_focus_for_session(param->focus_handle, (int)param->param, "media", sound_codec_focus_callback, (void*)*slotid);
- if (err) {
- debug_error("mm_sound_register_focus_for_session failed [0x%x]", err);
- pthread_mutex_unlock(&g_slot_mutex);
- return MM_ERROR_POLICY_INTERNAL;
- }
- err = mm_sound_acquire_focus(param->focus_handle, FOCUS_FOR_BOTH, NULL);
- if (err) {
- debug_error("mm_sound_acquire_focus failed [0x%x]", err);
- err = mm_sound_unregister_focus(param->focus_handle);
- pthread_mutex_unlock(&g_slot_mutex);
- return MM_ERROR_POLICY_INTERNAL;
- }
- g_slots[*slotid].current_focus_type = FOCUS_FOR_BOTH;
- } else if (param->session_options & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
- /* do nothing */
- debug_warning("session option is UNINTERRUPTIBLE, nothing to do with focus");
- } else {
- debug_warning("need to set focus watch callback");
- err = mm_sound_set_focus_watch_callback_for_session((int)param->param, FOCUS_FOR_BOTH, sound_codec_focus_watch_callback, (void*)*slotid, (int *)(¶m->focus_wcb_id));
- if (err) {
- debug_error("mm_sound_set_focus_watch_callback_for_session failed [0x%x]", err);
- pthread_mutex_unlock(&g_slot_mutex);
- return MM_ERROR_POLICY_INTERNAL;
- }
- }
- }
- //
-
- /* Codec id WAV or MP3 */
- g_slots[*slotid].pluginid = count;
- g_slots[*slotid].param = param->param; /* This arg is used callback data */
- g_slots[*slotid].session_type = param->session_type;
- g_slots[*slotid].session_options = param->session_options;
- g_slots[*slotid].focus_handle = param->focus_handle;
- g_slots[*slotid].focus_wcb_id = param->focus_wcb_id;
- g_slots[*slotid].enable_session = true;
- g_slots[*slotid].pid = (int)param->param;
-
-
- debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
-
- err = g_plugins[g_slots[*slotid].pluginid].Create(&codec_param, &info, &(g_slots[*slotid].plughandle));
- debug_msg("Created audio handle : [%d]\n", g_slots[*slotid].plughandle);
- if (err != MM_ERROR_NONE) {
- debug_error("Plugin create fail : 0x%08X\n", err);
- g_slots[*slotid].status = STATUS_IDLE;
- pthread_mutex_unlock(&g_slot_mutex);
- debug_warning("After Slot_mutex UNLOCK\n");
- if (param->focus_handle) {
- need_focus_unregister = 1;
- }
- goto cleanup;
- }
-
- err = g_plugins[g_slots[*slotid].pluginid].Play(g_slots[*slotid].plughandle);
- if (err != MM_ERROR_NONE) {
- debug_error("Fail to play : 0x%08X\n", err);
- g_plugins[g_slots[*slotid].pluginid].Destroy(g_slots[*slotid].plughandle);
- if (param->focus_handle) {
- need_focus_unregister = 1;
- }
- }
-
- pthread_mutex_unlock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
- debug_msg("After Slot_mutex UNLOCK\n");
-#endif