2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
25 #include <bluetooth_product.h>
29 #include "sttd_dbus.h"
30 #include "sttd_recorder.h"
31 #include "sttd_main.h"
34 #define FRAME_LENGTH 160
35 #define BUFFER_LENGTH FRAME_LENGTH * 2
37 static pthread_mutex_t sttd_audio_in_handle_mutex = PTHREAD_MUTEX_INITIALIZER;
40 STTD_RECORDER_STATE_NONE = -1,
41 STTD_RECORDER_STATE_READY = 0, /**< Recorder is ready to start */
42 STTD_RECORDER_STATE_RECORDING /**< In the middle of recording */
43 } sttd_recorder_state;
48 stte_audio_type_e audio_type;
51 static stt_recorder_s* g_recorder = NULL;
53 static stt_recorder_audio_cb g_audio_cb;
55 static sound_stream_info_h g_stream_info_h;
57 static stt_recorder_interrupt_cb g_interrupt_cb;
59 static sttd_recorder_state g_recorder_state = STTD_RECORDER_STATE_NONE;
61 static int g_buffer_count;
63 static int g_stream_focus_id;
65 /* Sound buf save for test */
70 static char g_temp_file_name[128] = {'\0',};
74 static int g_count = 1;
78 static float get_volume_decibel(char* data, int size, stte_audio_type_e type);
80 //static stt_recorder_s* __get_recorder(int engine_id);
82 static int g_bt_extend_count;
84 #define SMART_CONTROL_EXTEND_CMD 0x03
85 #define SMART_CONTROL_START_CMD 0x04
87 static void _bt_cb_hid_state_changed(int result, bool connected, const char *remote_address, void *user_data)
89 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Bluetooth Event [%d] Received address [%s]", result, remote_address);
92 static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data)
94 if (STTD_RECORDER_STATE_RECORDING != g_recorder_state) {
95 /* SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Exit audio reading normal func"); */
99 if (NULL != g_audio_cb) {
100 if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
101 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to read audio");
102 sttd_recorder_stop();
105 if (NULL == g_recorder) {
109 float vol_db = get_volume_decibel((char*)voice_data->audio_buf, (int)voice_data->length, g_recorder->audio_type);
110 if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
111 SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
115 if (0 == g_buffer_count || 0 == g_buffer_count % 50) {
116 SLOG(LOG_WARN, TAG_STTD, "[Recorder][%d] Recording... : read_size(%d)", g_buffer_count, voice_data->length);
118 if (0 == g_bt_extend_count % 5 && 0 != g_buffer_count) {
119 const unsigned char input_data[2] = {SMART_CONTROL_EXTEND_CMD, 0x10 };
120 if (BT_ERROR_NONE != bt_hid_send_rc_command(NULL, input_data, sizeof(input_data))) {
121 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail bt_hid_send_rc_command(NULL, %s, %d)", input_data, sizeof(input_data));
123 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Extend bt audio recorder");
128 if (100000 == g_buffer_count) {
136 /* write pcm buffer */
137 fwrite(data, 1, len, g_pFile);
144 const char* __stt_get_focus_changed_reason_code(sound_stream_focus_change_reason_e reason)
147 case SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA: return "SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA";
148 case SOUND_STREAM_FOCUS_CHANGED_BY_SYSTEM: return "SOUND_STREAM_FOCUS_CHANGED_BY_SYSTEM";
149 case SOUND_STREAM_FOCUS_CHANGED_BY_ALARM: return "SOUND_STREAM_FOCUS_CHANGED_BY_ALARM";
150 case SOUND_STREAM_FOCUS_CHANGED_BY_NOTIFICATION: return "SOUND_STREAM_FOCUS_CHANGED_BY_NOTIFICATION";
151 case SOUND_STREAM_FOCUS_CHANGED_BY_EMERGENCY: return "SOUND_STREAM_FOCUS_CHANGED_BY_EMERGENCY";
152 case SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION: return "SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION";
153 case SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_RECOGNITION: return "SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_RECOGNITION";
154 case SOUND_STREAM_FOCUS_CHANGED_BY_RINGTONE: return "SOUND_STREAM_FOCUS_CHANGED_BY_RINGTONE";
155 case SOUND_STREAM_FOCUS_CHANGED_BY_VOIP: return "SOUND_STREAM_FOCUS_CHANGED_BY_VOIP";
156 case SOUND_STREAM_FOCUS_CHANGED_BY_CALL: return "SOUND_STREAM_FOCUS_CHANGED_BY_CALL";
157 case SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA_EXTERNAL_ONLY: return "SOUND_STREAM_FOCUS_CHANGED_BY_MEDIA_EXTERNAL_ONLY";
158 default: return "Undefined reason code";
162 void __recorder_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
163 sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data)
165 SLOG(LOG_WARN, TAG_STTD, "[Recorder] focus_state_watch_cb is called, focus_state(%d), reason(%s)", (int)focus_state, __stt_get_focus_changed_reason_code(reason));
167 if (STTD_RECORDER_STATE_RECORDING == g_recorder_state && SOUND_STREAM_FOCUS_STATE_ACQUIRED == focus_state) {
168 SLOG(LOG_WARN, TAG_STTD, "[Recorder] Focus released as interrupt");
169 if (NULL != g_interrupt_cb) {
175 int sttd_recorder_initialize(stt_recorder_audio_cb audio_cb, stt_recorder_interrupt_cb interrupt_cb)
177 if (NULL == audio_cb || NULL == interrupt_cb) {
178 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Input param is NOT valid");
179 return STTD_ERROR_INVALID_PARAMETER;
182 if (STTD_RECORDER_STATE_NONE != g_recorder_state) {
183 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Current state of recorder is recording");
184 return STTD_ERROR_INVALID_STATE;
187 if (0 != pthread_mutex_init(&sttd_audio_in_handle_mutex, NULL)) {
188 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to initialize audio in handle mutex.");
191 g_audio_cb = audio_cb;
192 g_interrupt_cb = interrupt_cb;
193 g_recorder_state = STTD_RECORDER_STATE_NONE;
196 if (0 != sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE, NULL, NULL, &g_stream_info_h)) {
197 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to create stream info");
200 if (0 != sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_BOTH, __recorder_focus_state_watch_cb, NULL, &g_stream_focus_id)) {
201 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to add focus state watch callback");
205 if (BT_ERROR_NONE != bt_product_init()) {
206 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to init bt");
207 return STTD_ERROR_OPERATION_FAILED;
210 if (BT_ERROR_NONE != bt_hid_host_initialize(_bt_cb_hid_state_changed, NULL)) {
211 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail bt_hid_host_initialize()");
212 return STTD_ERROR_OPERATION_FAILED;
219 int sttd_recorder_deinitialize()
221 if (0 != pthread_mutex_destroy(&sttd_audio_in_handle_mutex)) {
222 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy audio in handle mutex.");
225 if (0 != sound_manager_remove_focus_state_watch_cb(g_stream_focus_id)) {
226 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to remove focus state watch callback");
229 if (0 != sound_manager_destroy_stream_information(g_stream_info_h)) {
230 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy stream info");
233 if (NULL != g_recorder) {
234 audio_in_destroy(g_recorder->audio_h);
235 g_recorder->audio_h = NULL;
240 #ifdef __UNUSED_CODES__
241 /* Remove all recorder */
243 stt_recorder_s *recorder = NULL;
245 iter = g_slist_nth(g_recorder_list, 0);
247 while (NULL != iter) {
248 recorder = iter->data;
250 if (NULL != recorder) {
251 g_recorder_list = g_slist_remove(g_recorder_list, recorder);
252 if (recorder->audio_h) {
253 audio_in_destroy(recorder->audio_h);
254 recorder->audio_h = NULL;
259 iter = g_slist_nth(g_recorder_list, 0);
264 bt_hid_host_deinitialize();
269 g_recorder_state = STTD_RECORDER_STATE_NONE;
274 int sttd_recorder_set_audio_session()
279 int sttd_recorder_unset_audio_session()
284 int sttd_recorder_create(stte_audio_type_e type, int channel, unsigned int sample_rate)
286 /* Check engine id is valid */
287 if (NULL != g_recorder) {
288 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is already registered");
289 return STTD_ERROR_INVALID_PARAMETER;
292 audio_in_h temp_in_h = NULL;
295 audio_channel_e audio_ch;
296 audio_sample_type_e audio_type;
299 case 1: audio_ch = AUDIO_CHANNEL_MONO; break;
300 case 2: audio_ch = AUDIO_CHANNEL_STEREO; break;
302 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Input channel is not supported");
303 return STTD_ERROR_OPERATION_FAILED;
308 case STTE_AUDIO_TYPE_PCM_S16_LE: audio_type = AUDIO_SAMPLE_TYPE_S16_LE; break;
309 case STTE_AUDIO_TYPE_PCM_U8: audio_type = AUDIO_SAMPLE_TYPE_U8; break;
311 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Invalid Audio Type");
312 return STTD_ERROR_OPERATION_FAILED;
317 ret = audio_in_create(sample_rate, audio_ch, audio_type, &temp_in_h);
318 if (AUDIO_IO_ERROR_NONE != ret) {
319 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to create audio handle : %d", ret);
320 return STTD_ERROR_OPERATION_FAILED;
323 if (BT_ERROR_NONE != bt_hid_set_audio_data_receive_cb(_bt_hid_audio_data_receive_cb, NULL)) {
324 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail bt_hid_set_audio_data_receive_cb()");
325 return STTD_ERROR_OPERATION_FAILED;
329 stt_recorder_s* recorder;
330 recorder = (stt_recorder_s*)calloc(1, sizeof(stt_recorder_s));
331 if (NULL == recorder) {
334 audio_in_destroy(temp_in_h);
338 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to allocate memory");
339 return STTD_ERROR_OUT_OF_MEMORY;
343 recorder->audio_h = temp_in_h;
344 recorder->audio_type = type;
346 g_recorder = recorder;
348 g_recorder_state = STTD_RECORDER_STATE_READY;
353 int sttd_recorder_destroy()
355 // critical section required because this function can be called from stt engine thread context
356 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
357 pthread_mutex_lock(&sttd_audio_in_handle_mutex);
359 /* Check engine id is valid */
360 if (NULL == g_recorder) {
361 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
362 pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
363 return STTD_ERROR_INVALID_PARAMETER;
368 if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
369 if (g_recorder->audio_h) {
370 ret = audio_in_unprepare(g_recorder->audio_h);
371 if (AUDIO_IO_ERROR_NONE != ret) {
372 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
376 g_recorder_state = STTD_RECORDER_STATE_READY;
379 if (g_recorder->audio_h) {
380 ret = audio_in_destroy(g_recorder->audio_h);
381 if (AUDIO_IO_ERROR_NONE != ret) {
382 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy audioin : %d", ret);
384 g_recorder->audio_h = NULL;
388 if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
389 g_recorder_state = STTD_RECORDER_STATE_READY;
392 bt_hid_unset_audio_data_receive_cb();
398 pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
399 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Leave critical section");
404 static float get_volume_decibel(char* data, int size, stte_audio_type_e type)
406 #define MAX_AMPLITUDE_MEAN_16 32768
407 #define MAX_AMPLITUDE_MEAN_08 128
414 unsigned long long square_sum = 0;
416 if (type == STTE_AUDIO_TYPE_PCM_S16_LE)
421 for (i = 0; i < size; i += (depthByte<<1)) {
422 if (depthByte == 2) {
424 memcpy(&pcm16, data + i, sizeof(short));
425 square_sum += pcm16 * pcm16;
428 memcpy(&pcm8, data + i, sizeof(char));
429 square_sum += pcm8 * pcm8;
437 rms = sqrt((double)square_sum/count);
440 db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16);
442 db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_08);
448 Eina_Bool __read_audio_func(void *data)
451 static char g_buffer[BUFFER_LENGTH];
453 /* Check engine id is valid */
454 if (NULL == g_recorder) {
458 if (STTD_RECORDER_STATE_READY == g_recorder_state) {
459 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Exit audio reading func");
463 read_byte = audio_in_read(g_recorder->audio_h, g_buffer, BUFFER_LENGTH);
465 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail to read audio : %d", read_byte);
466 g_recorder_state = STTD_RECORDER_STATE_READY;
470 if (0 != g_audio_cb(g_buffer, read_byte)) {
471 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail audio callback");
472 sttd_recorder_stop();
476 if (0 == g_buffer_count % 30) {
477 float vol_db = get_volume_decibel(g_buffer, BUFFER_LENGTH, g_recorder->audio_type);
478 if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
479 SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
484 if (0 == g_buffer_count % 50) {
485 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder][%d] Recording... : read_size(%d)", g_buffer_count, read_byte);
487 if (100000 == g_buffer_count) {
495 /* write pcm buffer */
496 fwrite(g_buffer, 1, BUFFER_LENGTH, g_pFile);
503 int sttd_recorder_start(int uid)
505 if (STTD_RECORDER_STATE_RECORDING == g_recorder_state)
510 /* Check engine id is valid */
511 if (NULL == g_recorder) {
512 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
513 return STTD_ERROR_INVALID_PARAMETER;
516 ret = audio_in_set_sound_stream_info(g_recorder->audio_h, g_stream_info_h);
517 if (AUDIO_IO_ERROR_NONE != ret) {
518 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to set stream info");
521 ret = audio_in_prepare(g_recorder->audio_h);
522 if (AUDIO_IO_ERROR_NONE != ret) {
523 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to start audio : %d", ret);
524 return STTD_ERROR_RECORDER_BUSY;
527 /* Add ecore timer to read audio data */
528 ecore_timer_add(0, __read_audio_func, NULL);
531 g_bt_extend_count = 0;
532 const unsigned char input_data[2] = {SMART_CONTROL_START_CMD, 0x00 };
534 bool started = false;
535 while (5 > bt_retry) {
536 ret = bt_hid_send_rc_command(NULL, input_data, sizeof(input_data));
537 if (BT_ERROR_NONE == ret) {
538 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Start bt audio recorder");
541 } else if (BT_ERROR_NOW_IN_PROGRESS == ret) {
542 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail bt_hid_send_rc_command(NULL, %s, %d)", input_data, sizeof(input_data));
549 if (false == started) {
550 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to start bt audio");
551 return STTD_ERROR_OPERATION_FAILED;
554 g_recorder_state = STTD_RECORDER_STATE_RECORDING;
555 g_recorder->uid = uid;
563 snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/stt_temp_%d_%d", getpid(), g_count);
564 ret = access(g_temp_file_name, 0);
567 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] File is already exist");
568 if (0 == remove(g_temp_file_name)) {
569 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Remove file");
579 SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Temp file name=[%s]", g_temp_file_name);
582 g_pFile = fopen(g_temp_file_name, "wb+x");
584 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] File not found!");
592 int sttd_recorder_stop()
594 if (STTD_RECORDER_STATE_READY == g_recorder_state)
597 // critical section required because this function can be called from stt engine thread context
598 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Enter critical section");
599 pthread_mutex_lock(&sttd_audio_in_handle_mutex);
601 /* Check engine id is valid */
602 if (NULL == g_recorder) {
603 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
604 pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
605 return STTD_ERROR_INVALID_PARAMETER;
608 g_recorder->uid = -1;
612 ret = audio_in_unprepare(g_recorder->audio_h);
613 if (AUDIO_IO_ERROR_NONE != ret) {
614 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to unprepare audioin : %d", ret);
618 bool stopped = false;
619 while (5 > bt_retry) {
620 ret = bt_hid_rc_stop_sending_voice(NULL);
621 if (BT_ERROR_NONE == ret) {
622 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Stop bt audio");
625 } else if (BT_ERROR_NOW_IN_PROGRESS == ret) {
626 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail bt_hid_rc_stop_sending_voice()");
630 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] bt_hid_rc_stop_sending_voice(): ret(%d)", ret);
634 if (false == stopped) {
635 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to stop bt audio(%d)", ret);
636 // return STTD_ERROR_OPERATION_FAILED;
640 g_recorder_state = STTD_RECORDER_STATE_READY;
645 pthread_mutex_unlock(&sttd_audio_in_handle_mutex);
646 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Leave critical section");
651 int sttd_recorder_start_file(int uid, const char *filepath)
653 if (STTD_RECORDER_STATE_RECORDING == g_recorder_state)
656 /* Check engine id is valid */
657 if (NULL == g_recorder) {
658 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
659 return STTD_ERROR_INVALID_PARAMETER;
661 g_recorder_state = STTD_RECORDER_STATE_RECORDING;
662 g_recorder->uid = uid;
665 int totalReadBytes = 0;
667 FILE *infile = fopen(filepath, "rb");
670 if (infile != NULL) {
671 while (!feof(infile)) {
672 static char pcm_buff[BUFFER_LENGTH];
673 int read_byte = fread(pcm_buff, 1, BUFFER_LENGTH, infile);
674 totalReadBytes += read_byte;
675 if (0 != read_byte) {
676 if (0 != g_audio_cb(pcm_buff, read_byte)) {
677 SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to call audio callback");
682 float vol_db = get_volume_decibel(pcm_buff, BUFFER_LENGTH, g_recorder->audio_type);
683 if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
684 SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
690 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder][%d] Recording... : read_size(%d)", cnt, read_byte);
697 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder][%d] total bytes(%d)", cnt, totalReadBytes);
701 int sttd_recorder_stop_file()
703 if (STTD_RECORDER_STATE_READY == g_recorder_state)
706 /* Check engine id is valid */
707 if (NULL == g_recorder) {
708 SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
709 return STTD_ERROR_INVALID_PARAMETER;
712 g_recorder->uid = -1;
713 g_recorder_state = STTD_RECORDER_STATE_READY;
718 int sttd_recorder_clear()
721 SLOG(LOG_DEBUG, TAG_STTD, "[Recorder DEBUG] Clear recorder on TV");
723 if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) {
724 sttd_recorder_stop();
726 if (STTD_RECORDER_STATE_READY == g_recorder_state) {
727 sttd_recorder_destroy();
731 return STTD_ERROR_NONE;