#include <system_info.h>
#include <unistd.h>
#include <buxton2.h>
+#include <sound_manager.h>
+#include <sound_manager_internal.h>
#include "stt.h"
#include "stt_client.h"
static bool g_err_callback_status = false;
+/* for changing volume on each sound stream */
+static sound_stream_info_h g_stream_for_volume_h = NULL;
+static virtual_sound_stream_h g_virtual_sound_stream_h = NULL;
+
+typedef enum {
+ STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD,
+ STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD,
+ STT_SYSTEM_VOLUME_EVENT_RECOVER
+} stt_system_volume_event_e;
+
+
const char* stt_tag()
{
//LCOV_EXCL_START
return ret;
}
+
+int __stt_change_system_volume(stt_system_volume_event_e volume_event)
+{
+ int stream_type = -1;
+ if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD == volume_event) {
+ stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
+ } else if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD == volume_event) {
+ stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE;
+ } else {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] volume type is invalid, type(%d)", volume_event);
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ SLOG(LOG_INFO, TAG_STTC, "[INFO] Change system volume, volume_type(%d)", volume_event);
+
+ int ret = STT_ERROR_NONE;
+ if (g_stream_for_volume_h) {
+ SLOG(LOG_INFO, TAG_STTC, "[INFO] Stream is already created, destroy stream)");
+ ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
+ }
+ g_stream_for_volume_h = NULL;
+ }
+
+ ret = sound_manager_create_stream_information_internal(stream_type, NULL, NULL, &g_stream_for_volume_h);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to create stream information, ret(%d)", ret);
+ return STT_ERROR_OPERATION_FAILED;
+ }
+
+ if (g_virtual_sound_stream_h) {
+ SLOG(LOG_INFO, TAG_STTC, "[INFO] Virtual stream is already created, destroy virtual stream)");
+ ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
+ return STT_ERROR_OPERATION_FAILED;
+ }
+ g_virtual_sound_stream_h = NULL;
+ }
+
+ ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create virtual stream, ret(%d)", ret);
+ ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
+ }
+ g_stream_for_volume_h = NULL;
+ return STT_ERROR_OPERATION_FAILED;
+ }
+
+ ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start virtual stream, ret(%d)", ret);
+ ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
+ }
+ g_virtual_sound_stream_h = NULL;
+
+ ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
+ }
+ g_stream_for_volume_h = NULL;
+
+ return STT_ERROR_OPERATION_FAILED;
+ }
+
+ SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Change system volume");
+ return 0;
+}
+
+int __stt_recover_system_volume()
+{
+ SLOG(LOG_INFO, TAG_STTC, "[INFO] Recover system volume");
+
+ int ret = STT_ERROR_NONE;
+
+ if (g_virtual_sound_stream_h) {
+ ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop virtual stream, ret(%d)", ret);
+ return STT_ERROR_OPERATION_FAILED;
+ }
+ ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
+ return STT_ERROR_OPERATION_FAILED;
+ }
+ g_virtual_sound_stream_h = NULL;
+ }
+
+ if (g_stream_for_volume_h) {
+ ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
+ return STT_ERROR_OPERATION_FAILED;
+ }
+ g_stream_for_volume_h = NULL;
+ }
+
+ SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Recover system volume");
+ return 0;
+}
+
+int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event)
+{
+ SLOG(LOG_DEBUG, TAG_STTC, "[STT] Change system volume, volume_event(%d)", volume_event);
+
+ stt_client_s* client = NULL;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check state */
+ if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
+ return STT_ERROR_INVALID_STATE;
+ }
+
+ /* change system volume */
+ int ret = __stt_change_system_volume(volume_event);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to change volume");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to change volume");
+ }
+ return ret;
+}
+
+int stt_recover_system_volume(stt_h stt)
+{
+ SLOG(LOG_DEBUG, TAG_STTC, "[STT] recover system volume");
+
+ stt_client_s* client = NULL;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ /* check state */
+ if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
+ return STT_ERROR_INVALID_STATE;
+ }
+
+ /* recover volume */
+ int ret = __stt_recover_system_volume();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to recover volume");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to recover volume");
+ }
+ return ret;
+}
//LCOV_EXCL_STOP