* limitations under the License.
*/
-#ifdef TV_PRODUCT
-#define TV_BT_MODE
-#define TV_MSF_WIFI_MODE
-#define TV_FFV_MODE
-#endif
-
#include <audio_io.h>
#include <math.h>
#include <sound_manager.h>
#include <sound_manager_internal.h>
-#ifdef TV_PRODUCT
-#ifdef TV_BT_MODE
-#include <bluetooth_product.h>
-#endif
-#ifdef TV_MSF_WIFI_MODE
-#include <MSFVoiceInterface.h>
-#endif
-#ifdef TV_FFV_MODE
-#include <farfield-voice-api.h>
-#endif
-#endif
#include "vcd_client_data.h"
#include "vcd_config.h"
static sound_stream_info_h g_stream_for_volume_h = NULL;
static virtual_sound_stream_h g_virtual_sound_stream_h = NULL;
-static bool g_is_valid_audio_in = false;
-static bool g_is_valid_bt_in = false;
-static char* g_current_audio_type = NULL;
static int g_buffer_count = 0;
static int g_device_id = -1;
static char* g_pcm_path = NULL;
static FILE* g_pcm_fp = NULL;
-#ifdef TV_FFV_MODE
-farfield_voice_h g_farfieldvoice_h = NULL;
-#endif
-
/* Sound buf save */
#if 0
static int g_count = 1;
#endif
-static float get_volume_decibel(const char* data, const unsigned int size);
-
-#ifdef TV_MSF_WIFI_MODE
-static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, void* user_data)
-{
- if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, sizeof(VCE_AUDIO_ID_WIFI))) {
- vcd_state_e state = vcd_config_get_service_state();
- if (VCD_STATE_READY == state) {
- vcd_recorder_set(VCE_AUDIO_ID_WIFI, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1);
- } else {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type);
- return;
- }
- }
-
- if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
- SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi Wi-Fi");
- vcd_recorder_start();
- }
-
- if (NULL != g_audio_cb) {
- if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to read audio");
- vcd_recorder_stop();
- }
- }
-
- /* Set volume */
- if (0 == g_buffer_count % 30) {
- float vol_db = get_volume_decibel((char*)voice_data->audio_buf, (unsigned int)voice_data->length);
- if (0 != vcdc_send_set_volume(vcd_client_manager_get_pid(), vol_db)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder] Fail to send recording volume(%f)", vol_db);
- }
- }
- if (0 == g_buffer_count || 0 == g_buffer_count % 50) {
- SLOG(LOG_WARN, TAG_VCD, "[Recorder][%d] Recording... : read_size(%ld)", g_buffer_count, voice_data->length);
-
- if (100000 == g_buffer_count)
- g_buffer_count = 0;
- }
-
- g_buffer_count++;
-
-#ifdef BUF_SAVE_MODE
- /* write pcm buffer */
- fwrite(voice_data->audio_buf, 1, voice_data->length, g_normal_file);
-#endif
- return;
-}
-
-#endif
-
-
-#ifdef TV_BT_MODE
-static int g_bt_extend_count;
-
-#define SMART_CONTROL_EXTEND_CMD 0x03
-#define SMART_CONTROL_START_CMD 0x04
-
-static void _bt_cb_hid_state_changed(int result, bool connected, const char *remote_address, void *user_data)
-{
- SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Bluetooth Event [%d] Received address [%s]", result, remote_address);
- return;
-}
-
-static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data)
+// TODO: make common function?
+static float get_volume_decibel(const char* data, const unsigned int size)
{
- if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, sizeof(VCE_AUDIO_ID_BLUETOOTH))) {
- vcd_state_e state = vcd_config_get_service_state();
- if (VCD_STATE_READY == state) {
- vcd_recorder_set(VCE_AUDIO_ID_BLUETOOTH, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1);
- } else {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type);
- return;
- }
- }
-
- if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
- SLOG(LOG_WARN, TAG_VCD, "[Recorder] Not start yet, but send audio data vi Bluetooth");
- // vcd_recorder_start();
- }
-
- if (NULL != g_audio_cb) {
- if (0 != g_audio_cb((void*)voice_data->audio_buf, (unsigned int)voice_data->length)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to read audio");
- vcd_recorder_stop();
- }
- }
-
- /* Set volume */
- if (0 == g_buffer_count % 15) {
- float vol_db = get_volume_decibel((char*)voice_data->audio_buf, (unsigned int)voice_data->length);
- if (0 != vcdc_send_set_volume(vcd_client_manager_get_pid(), vol_db)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder] Fail to send recording volume(%f)", vol_db);
- }
- }
-
- if (0 == g_buffer_count || 0 == g_buffer_count % 50) {
- SLOG(LOG_WARN, TAG_VCD, "[Recorder][%d] Recording... : read_size(%d)", g_buffer_count, voice_data->length);
-
- if (0 == g_bt_extend_count % 5 && 0 != g_buffer_count) {
- const unsigned char input_data[2] = {SMART_CONTROL_EXTEND_CMD, 0x10 };
- if (BT_ERROR_NONE != bt_hid_send_rc_command(NULL, input_data, sizeof(input_data))) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_send_rc_command");
- } else {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] Extend bt audio recorder");
- }
- }
- g_bt_extend_count++;
-
- if (100000 == g_buffer_count) {
- g_buffer_count = 0;
- }
- }
+ const int MAX_AMPLITUDE_MEAN_16 = 32768;
- g_buffer_count++;
+ int i, depthByte;
+ int count = 0;
-#ifdef BUF_SAVE_MODE
- /* write pcm buffer */
- fwrite(voice_data->audio_buf, 1, voice_data->length, g_normal_file);
-#endif
- return;
-}
-#endif
+ float db = 0.0;
+ float rms = 0.0;
+ unsigned long long square_sum = 0;
+ short pcm16 = 0;
-#ifdef TV_FFV_MODE
-static void _ffv_audio_function_cb(void* data, unsigned int length, void* user_data)
-{
- if (0 == g_buffer_count || 0 == g_buffer_count % 50) {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder INFO] farfield audio function callback is invoked");
+ depthByte = 2;
- if (100000 == g_buffer_count) {
- g_buffer_count = 0;
- }
+ for (i = 0; i < size; i += (depthByte<<1)) {
+ pcm16 = 0;
+ memcpy(&pcm16, data + i, sizeof(short));
+ square_sum += pcm16 * pcm16;
+ count++;
}
- g_buffer_count++;
-
- if (0 != strncmp(g_current_audio_type, VCE_AUDIO_ID_FFV, sizeof(VCE_AUDIO_ID_FFV))) {
- vcd_state_e state = vcd_config_get_service_state();
- if (VCD_STATE_READY == state) {
- vcd_recorder_set(VCE_AUDIO_ID_FFV, VCE_AUDIO_TYPE_PCM_S16_LE, 16000, 1);
- } else {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type);
- return;
- }
+ if (0 == count || 0 == square_sum) {
+ SLOG(LOG_ERROR, TAG_VCD, "[ERROR] No data");
+ rms = 1.0;
+ } else {
+ rms = sqrt((float)square_sum/count);
}
- if (NULL != g_audio_cb) {
- if (0 != g_audio_cb(data, length)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to read audio");
- vcd_recorder_stop();
- }
- }
+ db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16);
+ return db;
}
-#endif
-#if 1
static const char* __get_focus_changed_reason_code(sound_stream_focus_change_reason_e reason)
{
switch (reason) {
}
}
}
-#endif
static int __apply_device_for_stream_routing()
{
}
}
- int ret = 0;
-
- /* set init value */
- g_is_valid_audio_in = false;
- g_is_valid_bt_in = false;
-
- ret = sound_manager_add_device_connection_changed_cb(SOUND_DEVICE_IO_DIRECTION_IN_MASK, __device_connection_changed_cb, NULL, &g_device_id);
+ int ret = sound_manager_add_device_connection_changed_cb(SOUND_DEVICE_IO_DIRECTION_IN_MASK, __device_connection_changed_cb, NULL, &g_device_id);
if (0 != ret)
SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to add device connection changed callback");
if (0 != dependency_audio_manager_initialize(g_stream_info_h, __feed_audio_data_cb)) {
SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize dependency audio manager");
- g_is_valid_audio_in = false;
- } else {
- g_is_valid_audio_in = true;
+ return VCD_ERROR_OPERATION_FAILED;
}
g_audio_cb = audio_cb;
g_interrupt_cb = interrupt_cb;
g_recorder_state = VCD_RECORDER_STATE_READY;
-#ifdef TV_FFV_MODE
- g_farfieldvoice_h = farfield_voice_init();
- if (NULL == g_farfieldvoice_h) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to init farfield_voice_init");
- }
-#endif
-
-#ifdef TV_BT_MODE
- bool is_bt_failed = false;
-
- if (false == is_bt_failed && BT_ERROR_NONE != bt_product_init()) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to init bt");
- is_bt_failed = true;
- }
-
- if (false == is_bt_failed && BT_ERROR_NONE != bt_hid_host_initialize(_bt_cb_hid_state_changed, NULL)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_host_initialize()");
- is_bt_failed = true;
- }
-
- if (false == is_bt_failed) {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] Bluetooth is available");
- g_is_valid_bt_in = true;
- }
-#endif
-
- /* Select default audio type */
- if (true == g_is_valid_audio_in) {
- g_current_audio_type = strdup(VCE_AUDIO_ID_NONE);
- } else {
- if (true == g_is_valid_bt_in) {
- g_current_audio_type = strdup(VCE_AUDIO_ID_BLUETOOTH);
- } else {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] No valid audio");
- return -1;
- }
- }
-
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] Audio type : %s", g_current_audio_type);
-
- /* Set audio feed callback */
-#ifdef TV_BT_MODE
- if (BT_ERROR_NONE != bt_hid_set_audio_data_receive_cb(_bt_hid_audio_data_receive_cb, NULL)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_set_audio_data_receive_cb()");
- }
-#endif
-#ifdef TV_FFV_MODE
- if (g_farfieldvoice_h) {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder INFO] Register farfield voice audio callback");
- farfield_voice_register_audio_cb(g_farfieldvoice_h, _ffv_audio_function_cb, NULL);
- }
-#endif
-#ifdef TV_MSF_WIFI_MODE
- if (MSFResult_OK != RegisterMSFAudioCallback(__msf_wifi_audio_data_receive_cb, NULL)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start Wi-Fi audio");
- }
-#endif
-
- return 0;
+ return ret;
}
int vcd_recorder_destroy()
SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to audio in destroy, ret(%d)", ret);
}
-
-#ifdef TV_MSF_WIFI_MODE
- UnRegisterMSFAudioCallback();
-#endif
-
-#ifdef TV_FFV_MODE
- if (NULL != g_farfieldvoice_h) {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder INFO] Unregister farfield voice");
- farfield_voice_final(g_farfieldvoice_h);
- g_farfieldvoice_h = NULL;
- }
-#endif
-
-#ifdef TV_BT_MODE
- bt_hid_unset_audio_data_receive_cb();
- bt_hid_host_deinitialize();
- bt_product_deinit();
-#endif
-
g_audio_cb = NULL;
- if (NULL != g_current_audio_type) {
- free(g_current_audio_type);
- g_current_audio_type = NULL;
- }
-
if (NULL != g_pcm_path) {
free(g_pcm_path);
g_pcm_path = NULL;
return VCD_ERROR_NONE;
}
-static int __set_audio_source_type(const char* audio_source_type)
+int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel)
{
- if (NULL == audio_source_type) {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] Audio source type is NULL");
+ if (NULL == audio_type) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] audio_type is NULL");
return VCD_ERROR_INVALID_PARAMETER;
}
- if (NULL != g_current_audio_type) {
- if (0 == strncmp(g_current_audio_type, audio_source_type, strlen(g_current_audio_type))) {
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] Current audio type is already set : %s", audio_source_type);
- return VCD_ERROR_NONE;
- }
- } else {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT created");
- return VCD_ERROR_INVALID_STATE;
- }
-
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] set audio type (%s)", audio_source_type);
- vcd_engine_set_audio_type(audio_source_type);
-
- // Set new audio source type
- if (NULL != g_current_audio_type) {
- free(g_current_audio_type);
- g_current_audio_type = NULL;
- }
-
- g_current_audio_type = strdup(audio_source_type);
+ SLOG(LOG_INFO, TAG_VCD, "[Recorder] set audio type (%s)", audio_type);
+ vcd_engine_set_audio_type(audio_type);
- return VCD_ERROR_NONE;
-}
-
-int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel)
-{
int ret = -1;
- ret = __set_audio_source_type(audio_type);
- if (0 != ret) {
- return ret;
- }
-
- /* Check BT audio */
- if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) {
- if (false == g_is_valid_bt_in) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder] BT audio is NOT valid");
- return VCD_ERROR_OPERATION_REJECTED;
- }
- } else if (0 == strncmp(VCE_AUDIO_ID_WIFI, audio_type, strlen(VCE_AUDIO_ID_WIFI))) {
- } else if (0 == strncmp(VCE_AUDIO_ID_FFV, audio_type, strlen(VCE_AUDIO_ID_FFV))) {
- } else {
- if (false == g_is_valid_audio_in) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Audio-in is NOT valid");
- return VCD_ERROR_OPERATION_REJECTED;
- }
- }
-
ret = dependency_audio_manager_set_audio_info(g_stream_info_h, audio_type, type, rate, channel);
if (0 != ret) {
- g_is_valid_audio_in = false;
SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set audio information");
+ return VCD_ERROR_OPERATION_FAILED;
}
- SLOG(LOG_INFO, TAG_VCD, "[Recorder] Current audio type is changed : %s", g_current_audio_type);
-
return VCD_ERROR_NONE;
}
return VCD_ERROR_NONE;
}
-// TODO: make common function?
-static float get_volume_decibel(const char* data, const unsigned int size)
-{
- const int MAX_AMPLITUDE_MEAN_16 = 32768;
-
- int i, depthByte;
- int count = 0;
-
- float db = 0.0;
- float rms = 0.0;
- unsigned long long square_sum = 0;
- short pcm16 = 0;
-
- depthByte = 2;
-
- for (i = 0; i < size; i += (depthByte<<1)) {
- pcm16 = 0;
- memcpy(&pcm16, data + i, sizeof(short));
- square_sum += pcm16 * pcm16;
- count++;
- }
-
- if (0 == count || 0 == square_sum) {
- SLOG(LOG_ERROR, TAG_VCD, "[ERROR] No data");
- rms = 1.0;
- } else {
- rms = sqrt((float)square_sum/count);
- }
-
- db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16);
- return db;
-}
-
Eina_Bool __read_test_func(void *data)
{
if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) {
}
g_buffer_count = 0;
-#ifdef TV_BT_MODE
- g_bt_extend_count = 0;
-#endif
SLOG(LOG_INFO, TAG_VCD, "[Recorder] Enter, recorder state(%d)", g_recorder_state);
if (VCD_RECORDER_STATE_RECORDING == g_recorder_state) {