-int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
-{
- int plugin_id = 0;
- mmsound_codec_info_t info;
- mmsound_codec_param_t codec_param;
- int err = MM_ERROR_NONE;
-
-#ifdef FOCUS_INTEGRATION
- int need_focus_unregister = 0;
-#endif
-
-#ifdef DEBUG_DETAIL
- debug_enter();
-#endif
- plugin_id = _MMSoundMgrCodecFindCodecPluginID(MM_SOUND_SUPPORTED_CODEC_WAVE);
- if (plugin_id == -1) {
- debug_error("Could not find proper codec plugin!!!");
- err = MM_ERROR_SOUND_INTERNAL;
- goto cleanup;
- }
-
- err = g_plugins[plugin_id].Parse(param->pfilename, &info);
- if (err != MM_ERROR_NONE) {
- debug_error("Could not parse file [%s] by plugin[%d]\n", param->pfilename, plugin_id);
- goto cleanup;
- }
-
- debug_msg("DTMF[%d] Repeat[%d] Volume[%f] plugin_codec[%d]\n", param->tone, param->repeat_count, param->volume, plugin_id);
-
-#ifdef DEBUG_DETAIL
- debug_msg("Get New handle\n");
-#endif
-
- err = _mm_sound_mgr_codec_slot_get_empty(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.pfilename = param->pfilename;
- codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
- codec_param.param = *slotid;
- codec_param.pid = (int)param->param;
- codec_param.stream_index = param->stream_index;
- MMSOUND_STRNCPY(codec_param.stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
- SLOT_LOCK();
-
-#ifdef FOCUS_INTEGRATION
- /*
- * 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);
- SLOT_UNLOCK();
- 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);
- SLOT_UNLOCK();
- 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);
- SLOT_UNLOCK();
- 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);
- SLOT_UNLOCK();
- return MM_ERROR_POLICY_INTERNAL;
- }
- }
- }
- //
-#endif
-
- /* Codec id WAV or MP3 */
- g_slots[*slotid].pluginid = plugin_id;
- 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;
-#ifdef FOCUS_INTEGRATION
- g_slots[*slotid].focus_handle = param->focus_handle;
- g_slots[*slotid].focus_wcb_id = param->focus_wcb_id;
-#endif
- 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;
- SLOT_UNLOCK();
-#ifdef FOCUS_INTEGRATION
- if (param->focus_handle) {
- need_focus_unregister = 1;
- }
-#endif
- 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);
-#ifdef FOCUS_INTEGRATION
- if (param->focus_handle) {
- need_focus_unregister = 1;
- }
-#endif
- }
-
- SLOT_UNLOCK();
-
-cleanup:
- if (_mm_sound_mgr_codec_slot_is_empty())
- _mm_sound_mgr_codec_shutdown_timer_start();
-
-#ifdef FOCUS_INTEGRATION
- 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 &&
- need_focus_unregister == 1) {
-
- 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) {
- err = mm_sound_release_focus(param->focus_handle, FOCUS_FOR_BOTH, NULL);
- if (mm_sound_unregister_focus(param->focus_handle) || err) {
- debug_error("focus cleaning up failed[0x%x]", err);
- return MM_ERROR_POLICY_INTERNAL;
- }
- } else if (~(param->session_options & MM_SESSION_OPTION_PAUSE_OTHERS)) {
- err = mm_sound_unset_focus_watch_callback(param->focus_wcb_id);
- if (err) {
- debug_error("focus watch cleaning up failed[0x%x]", err);
- return MM_ERROR_POLICY_INTERNAL;
- }
- }
- }
-#endif
-
-
-#ifdef DEBUG_DETAIL
- debug_leave();
-#endif
-
- return err;
-}
-