19 #include "acm_iarm_interface.h"
20 #include "audiocapturemgr_iarm.h"
26 #include "safec_lib.h"
28 using namespace audiocapturemgr;
34 static unsigned int ticker = 0;
35 std::string audio_filename_prefix = AUDIOCAPTUREMGR_FILENAME_PREFIX;
36 std::string audio_file_path = AUDIOCAPTUREMGR_FILE_PATH;
37 static std::string get_suffix()
39 std::ostringstream stream;
41 std::string outstring = stream.str();
45 static void request_callback(
void * data, std::string &file,
int result)
50 ERROR(
"Failed to grab sample.\n");
55 rc = strcpy_s(payload.dataLocator,
sizeof(payload.dataLocator), file.c_str());
58 int ret =
IARM_Bus_BroadcastEvent(IARMBUS_AUDIOCAPTUREMGR_NAME, DATA_CAPTURE_IARM_EVENT_AUDIO_CLIP_READY, &payload,
sizeof(payload));
59 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
64 WARN(
"Incoming filename is too big for payload buffer.\n");
69 static IARM_Result_t enable_capture(
void * arg)
72 return IARM_RESULT_SUCCESS;
74 static IARM_Result_t request_sample(
void * arg)
77 return IARM_RESULT_SUCCESS;
80 acm_iarm_interface::acm_iarm_interface() : m_is_active(false), m_enable_audio_input(false), m_client(NULL)
84 acm_iarm_interface::~acm_iarm_interface()
100 ERROR(
"ACM IARM interface is already in use by another client.\n");
110 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
113 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
116 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
119 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
122 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
131 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
133 REPORT_IF_UNEQUAL(IARM_RESULT_SUCCESS, ret);
134 if(m_enable_audio_input)
137 m_enable_audio_input =
false;
146 unsigned int incoming_duration =
static_cast <int> (data->max_duration);
149 if(incoming_duration > max_supported_duration)
151 ERROR(
"Incoming duration %d is too long.\n", incoming_duration);
152 data->result = max_supported_duration;
158 if(0 == incoming_duration)
160 if(
true == m_enable_audio_input)
162 INFO(
"Disabling audio capture.\n");
164 m_enable_audio_input =
false;
167 else if(
false == m_enable_audio_input)
169 INFO(
"Enabling audio capture.\n");
171 m_enable_audio_input =
true;
173 data->result = ACM_RESULT_SUCCESS;
183 if(
false == m_enable_audio_input)
185 ERROR(
"Audio capture is currently disabled!\n");
186 data->result = ACM_RESULT_DURATION_OUT_OF_BOUNDS;
189 data->result = ACM_RESULT_SUCCESS;
190 std::string filename = audio_file_path + audio_filename_prefix + get_suffix();
192 if(data->is_precapture)
198 request_callback(NULL, filename, 0);
203 unsigned int duration =
static_cast <unsigned int> (data->duration);
204 if(duration <= m_client->get_max_supported_duration())
210 ERROR(
"Duration out of bounds!\n");
211 data->result = ACM_RESULT_DURATION_OUT_OF_BOUNDS;
218 data->result = ACM_RESULT_GENERAL_FAILURE;
225 audio_filename_prefix = prefix;