Add descriptions for new apis in the doc header file
[platform/core/uifw/stt.git] / server / sttd_recorder.c
index c29c46d..9d35fc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -114,7 +114,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void
                        SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
                }
        }
-       
+
        if (0 == g_buffer_count || 0 == g_buffer_count % 50) {
                SLOG(LOG_WARN, TAG_STTD, "[Recorder][%d] Recording... : read_size(%d)", g_buffer_count, voice_data->length);
 
@@ -127,7 +127,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void
                        }
                }
                g_bt_extend_count++;
-               
+
                if (100000 == g_buffer_count) {
                        g_buffer_count = 0;
                }
@@ -180,7 +180,7 @@ void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_stream_foc
        }
 
        SLOG(LOG_WARN, TAG_STTD, "[Recorder] focus state changed to (%d) with reason(%s)", (int)state_for_recording, __stt_get_focus_changed_reason_code(reason));
-       
+
        if (STTD_RECORDER_STATE_RECORDING == g_recorder_state && SOUND_STREAM_FOCUS_STATE_RELEASED == state_for_recording) {
                SLOG(LOG_WARN, TAG_STTD, "[Recorder] Focus released as interrupt");
                if (NULL != g_interrupt_cb) {
@@ -251,8 +251,10 @@ int sttd_recorder_deinitialize()
 
                if (NULL != recorder) {
                        g_recorder_list = g_slist_remove(g_recorder_list, recorder);
-                       audio_in_destroy(recorder->audio_h);
-
+                       if(recorder->audio_h) {
+                               audio_in_destroy(recorder->audio_h);
+                               recorder->audio_h = NULL;
+                       }
                        free(recorder);
                }
 
@@ -349,7 +351,10 @@ int sttd_recorder_create(int engine_id, int uid, sttp_audio_type_e type, int cha
        recorder = (stt_recorder_s*)calloc(1, sizeof(stt_recorder_s));
        if (NULL == recorder) {
 #ifndef TV_BT_MODE
-               audio_in_destroy(temp_in_h);
+               if (temp_in_h) {
+                       audio_in_destroy(temp_in_h);
+                       temp_in_h = NULL;
+               }
 #endif
                SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to allocate memory");
                return STTD_ERROR_OUT_OF_MEMORY;
@@ -385,19 +390,24 @@ int sttd_recorder_destroy(int engine_id)
 #ifndef TV_BT_MODE
        int ret;
        if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
-               ret = audio_in_unprepare(recorder->audio_h);
-               if (AUDIO_IO_ERROR_NONE != ret) {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
+               if (recorder->audio_h) {
+                       ret = audio_in_unprepare(recorder->audio_h);
+                       if (AUDIO_IO_ERROR_NONE != ret) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
+                       }
                }
 
                g_recorder_state = STTD_RECORDER_STATE_READY;
        }
 
-       ret = audio_in_destroy(recorder->audio_h);
-       if (AUDIO_IO_ERROR_NONE != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy audioin : %d", ret);
+       if (recorder->audio_h) {
+               ret = audio_in_destroy(recorder->audio_h);
+               if (AUDIO_IO_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy audioin : %d", ret);
+               }
+               recorder->audio_h = NULL;
        }
-#else 
+#else
        if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
                g_recorder_state = STTD_RECORDER_STATE_READY;
        }
@@ -540,7 +550,7 @@ int sttd_recorder_start(int engine_id)
                        SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to set stream info");
                }
        }
-       
+
        ret = audio_in_prepare(recorder->audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to start audio : %d", ret);
@@ -615,7 +625,7 @@ int sttd_recorder_stop(int engine_id)
        if (AUDIO_IO_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
        }
-#else 
+#else
        int bt_retry = 0;
        bool stopped = false;
        while (5 > bt_retry) {