From 917912229515e4e30e2801a42b863dc88405c923 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Wed, 26 Jul 2023 17:12:20 +0900 Subject: [PATCH] Move setter and getter about audio id to public header file Change-Id: Ie327efff75ff540fac2182a49e1f2448554472e4 Signed-off-by: Suyeon Hwang --- client/stt.c | 12 ++++++--- include/stt.h | 64 +++++++++++++++++++++++++++++++++++++++++++++ include/stt_internal.h | 53 ------------------------------------- tests/src/stt_unittests.cpp | 36 ++++++++++++------------- 4 files changed, 90 insertions(+), 75 deletions(-) diff --git a/client/stt.c b/client/stt.c index 8a37d80..854f3b6 100644 --- a/client/stt.c +++ b/client/stt.c @@ -2489,7 +2489,7 @@ int stt_recover_system_volume(stt_h stt) return STT_ERROR_NONE; } -int stt_set_audio_type(stt_h stt, const char *audio_id) +int stt_set_audio_id(stt_h stt, const char *audio_id) { stt_client_s* client = NULL; int temp = __stt_check_precondition(stt, &client); @@ -2499,15 +2499,17 @@ int stt_set_audio_type(stt_h stt, const char *audio_id) RETVM_IF(NULL == audio_id, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); RETVM_IF(STT_STATE_CREATED != client->current_state && client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created' or 'Ready'", client->current_state); - SLOG(LOG_INFO, TAG_STTC, "[INFO] Set audio type(%s)", audio_id); + SLOG(LOG_INFO, TAG_STTC, "[INFO] Set audio ID(%s)", audio_id); free(client->audio_id); client->audio_id = strdup(audio_id); + RETVM_IF(NULL == client->audio_id, STT_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for saving audio id"); + return STT_ERROR_NONE; } -int stt_get_audio_type(stt_h stt, char **audio_id) +int stt_get_audio_id(stt_h stt, char **audio_id) { stt_client_s* client = NULL; int temp = __stt_check_precondition(stt, &client); @@ -2518,7 +2520,9 @@ int stt_get_audio_type(stt_h stt, char **audio_id) RETVM_IF(STT_STATE_CREATED != client->current_state && client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created' or 'Ready'", client->current_state); *audio_id = strdup(client->audio_id); - SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Get audio type(%s)", *audio_id); + RETVM_IF(NULL == *audio_id, STT_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for output audio id"); + + SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Get audio ID(%s)", *audio_id); return STT_ERROR_NONE; } diff --git a/include/stt.h b/include/stt.h index 7734c1e..e57c57d 100755 --- a/include/stt.h +++ b/include/stt.h @@ -152,6 +152,27 @@ typedef enum { /** + * @brief Definition for Bluetooth audio-in ID. + * @since_tizen 8.0 +*/ +#define STT_AUDIO_ID_BLUETOOTH "STT_AUDIO_ID_BLUETOOTH" + + +/** + * @brief Definition for Wi-Fi audio-in ID. + * @since_tizen 8.0 +*/ +#define STT_AUDIO_ID_WIFI "STT_AUDIO_ID_WIFI" + + +/** + * @brief Definition for none specified audio-in ID. + * @since_tizen 8.0 +*/ +#define STT_AUDIO_ID_NONE "STT_AUDIO_ID_NONE" + + +/** * @brief Enumeration for state. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ @@ -1264,6 +1285,49 @@ int stt_stop_audio_streaming(stt_h stt); int stt_get_audio_format(stt_h stt, stt_audio_type_e* type, int* rate, int* num_of_channels); +/** + * @brief Sets an ID of audio-in. + * @since_tizen 8.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * @param[in] stt The STT handle + * @param[in] audio_id The audio id (e.g. #STT_AUDIO_ID_BLUETOOTH, #STT_AUDIO_ID_WIFI, #STT_AUDIO_ID_NONE or USB device ID) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_PERMISSION_DENIED Permission denied + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @pre The state should be #STT_STATE_CREATED or #STT_STATE_READY. + * @see stt_get_audio_id() + */ +int stt_set_audio_id(stt_h stt, const char *audio_id); + + +/** + * @brief Gets an ID of audio-in. + * @since_tizen 8.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * @remarks @a audio_id must be released using free() when it is no longer required. + * @param[in] stt The STT handle + * @param[out] audio_id The audio id (e.g. #STT_AUDIO_ID_BLUETOOTH, #STT_AUDIO_ID_WIFI, #STT_AUDIO_ID_NONE or USB device ID) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_PERMISSION_DENIED Permission denied + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @pre The state should be #STT_STATE_CREATED or #STT_STATE_READY. + * @see stt_set_audio_id() + */ +int stt_get_audio_id(stt_h stt, char **audio_id); + + #ifdef __cplusplus } #endif diff --git a/include/stt_internal.h b/include/stt_internal.h index a742b7a..0ebef91 100644 --- a/include/stt_internal.h +++ b/include/stt_internal.h @@ -39,12 +39,6 @@ typedef enum { STT_SYSTEM_VOLUME_EVENT_RECOVER /**< Recover system volume event */ } stt_system_volume_event_e; -#define STT_AUDIO_ID_BLUETOOTH "STT_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */ - -#define STT_AUDIO_ID_WIFI "STT_AUDIO_ID_WIFI" /**< Wifi audio id */ - -#define STT_AUDIO_ID_NONE "STT_AUDIO_ID_NONE" /**< None audio id */ - /** * @brief Sets server STT. * @details Using this API, the application can set server STT with a @a key as a @a user_data @@ -182,53 +176,6 @@ int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event); */ int stt_recover_system_volume(stt_h stt); -/** - * @brief Sets a type of audio-in. - * @since_tizen 7.0 - * - * @privlevel public - * @privilege %http://tizen.org/privilege/recorder - * - * @param[in] audio_id The audio type (e.g. #STT_AUDIO_ID_BLUETOOTH or #STT_AUDIO_ID_FFV) - * - * @return 0 on success, otherwise a negative error value - * @retval #STT_ERROR_NONE Successful - * @retval #STT_ERROR_NOT_SUPPORTED STT not supported - * @retval #STT_ERROR_PERMISSION_DENIED Permission denied - * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STT_ERROR_INVALID_STATE Invalid state - * @retval #STT_ERROR_OPERATION_FAILED Operation failure - * - * @pre The state should be #STT_STATE_CREATED or #STT_STATE_READY. - * - * @see stt_get_audio_type() - */ -int stt_set_audio_type(stt_h stt, const char *audio_id); - -/** - * @brief Gets a type of audio-in. - * @since_tizen 7.0 - * - * @privlevel public - * @privilege %http://tizen.org/privilege/recorder - * - * @remarks audio_id must be released using free() when it is no longer required. - * - * @param[out] audio_id The audio id (e.g. #STT_AUDIO_ID_BLUETOOTH or USB device ID) - * - * @return 0 on success, otherwise a negative error value - * @retval #STT_ERROR_NONE Successful - * @retval #STT_ERROR_NOT_SUPPORTED STT not supported - * @retval #STT_ERROR_PERMISSION_DENIED Permission denied - * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STT_ERROR_INVALID_STATE Invalid state - * - * @pre The state should be #STT_STATE_CREATED or #STT_STATE_READY. - * - * @see stt_set_audio_type() - */ -int stt_get_audio_type(stt_h stt, char **audio_id); - #ifdef __cplusplus } diff --git a/tests/src/stt_unittests.cpp b/tests/src/stt_unittests.cpp index 71907c8..53b7ece 100644 --- a/tests/src/stt_unittests.cpp +++ b/tests/src/stt_unittests.cpp @@ -1980,14 +1980,14 @@ TEST_F(STTTest, utc_stt_set_audio_type_p1) const char *audio_id = "test"; if (false == mTestUtil->IsFeatureSupported()) { - EXPECT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_NOT_SUPPORTED); + EXPECT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_NOT_SUPPORTED); return; } - EXPECT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_NONE); + EXPECT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_NONE); EXPECT_EQ(mTestUtil->Prepare(), true); - EXPECT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_NONE); + EXPECT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_NONE); } TEST_F(STTTest, utc_stt_set_audio_type_n1) @@ -1995,12 +1995,12 @@ TEST_F(STTTest, utc_stt_set_audio_type_n1) const char *audio_id = "test"; if (false == mTestUtil->IsFeatureSupported()) { - EXPECT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_NOT_SUPPORTED); + EXPECT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_NOT_SUPPORTED); return; } - EXPECT_EQ(stt_set_audio_type(nullptr, audio_id), STT_ERROR_INVALID_PARAMETER); - EXPECT_EQ(stt_set_audio_type(mHandle, nullptr), STT_ERROR_INVALID_PARAMETER); + EXPECT_EQ(stt_set_audio_id(nullptr, audio_id), STT_ERROR_INVALID_PARAMETER); + EXPECT_EQ(stt_set_audio_id(mHandle, nullptr), STT_ERROR_INVALID_PARAMETER); } TEST_F(STTPreparedTest, utc_stt_set_audio_type_n2) @@ -2008,14 +2008,14 @@ TEST_F(STTPreparedTest, utc_stt_set_audio_type_n2) const char *audio_id = "test"; if (false == mTestUtil->IsFeatureSupported()) { - EXPECT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_NOT_SUPPORTED); + EXPECT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_NOT_SUPPORTED); return; } mTestUtil->SetTestMode(); EXPECT_EQ(mTestUtil->Start(TEST_LANGUAGE, TEST_RECOG_TYPE), true); - EXPECT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_INVALID_STATE); + EXPECT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_INVALID_STATE); } TEST_F(STTTest, utc_stt_get_audio_type_p1) @@ -2024,16 +2024,16 @@ TEST_F(STTTest, utc_stt_get_audio_type_p1) char *get_id = nullptr; if (false == mTestUtil->IsFeatureSupported()) { - EXPECT_EQ(stt_get_audio_type(mHandle, &get_id), STT_ERROR_NOT_SUPPORTED); + EXPECT_EQ(stt_get_audio_id(mHandle, &get_id), STT_ERROR_NOT_SUPPORTED); return; } - ASSERT_EQ(stt_set_audio_type(mHandle, audio_id), STT_ERROR_NONE); - EXPECT_EQ(stt_get_audio_type(mHandle, &get_id), STT_ERROR_NONE); + ASSERT_EQ(stt_set_audio_id(mHandle, audio_id), STT_ERROR_NONE); + EXPECT_EQ(stt_get_audio_id(mHandle, &get_id), STT_ERROR_NONE); EXPECT_STREQ(get_id, audio_id); EXPECT_EQ(mTestUtil->Prepare(), true); - EXPECT_EQ(stt_get_audio_type(mHandle, &get_id), STT_ERROR_NONE); + EXPECT_EQ(stt_get_audio_id(mHandle, &get_id), STT_ERROR_NONE); EXPECT_STREQ(get_id, audio_id); } @@ -2042,12 +2042,12 @@ TEST_F(STTTest, utc_stt_get_audio_type_n1) char *get_id = nullptr; if (false == mTestUtil->IsFeatureSupported()) { - EXPECT_EQ(stt_get_audio_type(mHandle, &get_id), STT_ERROR_NOT_SUPPORTED); + EXPECT_EQ(stt_get_audio_id(mHandle, &get_id), STT_ERROR_NOT_SUPPORTED); return; } - EXPECT_EQ(stt_get_audio_type(nullptr, &get_id), STT_ERROR_INVALID_PARAMETER); - EXPECT_EQ(stt_get_audio_type(mHandle, nullptr), STT_ERROR_INVALID_PARAMETER); + EXPECT_EQ(stt_get_audio_id(nullptr, &get_id), STT_ERROR_INVALID_PARAMETER); + EXPECT_EQ(stt_get_audio_id(mHandle, nullptr), STT_ERROR_INVALID_PARAMETER); } TEST_F(STTPreparedTest, utc_stt_get_audio_type_n2) @@ -2055,15 +2055,15 @@ TEST_F(STTPreparedTest, utc_stt_get_audio_type_n2) char *get_id = nullptr; if (false == mTestUtil->IsFeatureSupported()) { - EXPECT_EQ(stt_get_audio_type(mHandle, &get_id), STT_ERROR_NOT_SUPPORTED); + EXPECT_EQ(stt_get_audio_id(mHandle, &get_id), STT_ERROR_NOT_SUPPORTED); return; } mTestUtil->SetTestMode(); EXPECT_EQ(mTestUtil->Start(TEST_LANGUAGE, TEST_RECOG_TYPE), true); - EXPECT_EQ(stt_get_audio_type(nullptr, &get_id), STT_ERROR_INVALID_PARAMETER); - EXPECT_EQ(stt_get_audio_type(mHandle, nullptr), STT_ERROR_INVALID_PARAMETER); + EXPECT_EQ(stt_get_audio_id(nullptr, &get_id), STT_ERROR_INVALID_PARAMETER); + EXPECT_EQ(stt_get_audio_id(mHandle, nullptr), STT_ERROR_INVALID_PARAMETER); } } // namespace -- 2.7.4