muse_core_msg_free(__sndMsg__); \
} while (0)
+/**
+ * @brief Returning the event ack message from the server to client side, adding 2 parameters.
+ * @param[in] api The enumeration of the corresponding api.
+ * @param[in] event The enumeration of the event.
+ * @param[in] class The enumeration of the event class.
+ * @param[in] module The module info for the ipc transportation.
+ * @param[in] param1 The 1st parameter to be included in the message.
+ * @param[in] type2 The data type of the parameter.
+ * @param[in] param2 The 2nd parameter to be included in the message.
+ * @param[in] type3 The data type of the parameter.
+ * @param[in] param3 The 3rd parameter to be included in the message.
+ * @param[in] tfd The tbm fds to be delivered through the socket.
+ */
+#define muse_recorder_msg_event3_fd(api, event, class, module, type1, param1, type2, param2, type3, param3, tfd) \
+ do { \
+ char *__sndMsg__; \
+ int __len__; \
+ type1 __value1__ = (type1)param1; \
+ type2 __value2__ = (type2)param2; \
+ type3 __value3__ = (type3)param3; \
+ __sndMsg__ = muse_core_msg_new(api, \
+ MUSE_TYPE_INT, PARAM_EVENT, event, \
+ MUSE_TYPE_INT, PARAM_EVENT_CLASS, class, \
+ MUSE_TYPE_##type1, #param1, __value1__, \
+ MUSE_TYPE_##type2, #param2, __value2__, \
+ MUSE_TYPE_##type3, #param3, __value3__, \
+ 0); \
+ __len__ = muse_core_msg_send_fd(muse_server_module_get_msg_fd(module), (int *)tfd, __sndMsg__); \
+ if (__len__ <= 0) \
+ LOGE("sending message failed [%d]", __len__); \
+ muse_core_msg_free(__sndMsg__); \
+ } while (0)
+
/**
* @brief Returning the event ack message from the server to client side, adding 3 parameters.
* @param[in] api The enumeration of the corresponding api.
* @param[in] param4 The 4th parameter to be included in the message.
* @param[in] type5 The data type of the parameter.
* @param[in] param5 The 5th parameter to be included in the message.
+ * @param[in] tfd The tbm fds.
*/
-#define muse_recorder_msg_event5(api, event, class, module, type1, param1, type2, param2, type3, param3, type4, param4, type5, param5) \
+#define muse_recorder_msg_event5_fd(api, event, class, module, type1, param1, type2, param2, type3, param3, type4, param4, type5, param5, tfd) \
do { \
char *__sndMsg__; \
int __len__; \
type2 __value2__ = (type2)param2; \
type3 __value3__ = (type3)param3; \
type4 __value4__ = (type4)param4; \
- type5 __value5__ = (type5)param5; \
+ type5 __value5__ = (type4)param5; \
__sndMsg__ = muse_core_msg_new(api, \
MUSE_TYPE_INT, PARAM_EVENT, event, \
MUSE_TYPE_INT, PARAM_EVENT_CLASS, class, \
MUSE_TYPE_##type4, #param4, __value4__, \
MUSE_TYPE_##type5, #param5, __value5__, \
0); \
- __len__ = muse_core_msg_send(muse_server_module_get_msg_fd(module), __sndMsg__); \
+ __len__ = muse_core_msg_send_fd(muse_server_module_get_msg_fd(module), (int *)tfd, __sndMsg__); \
if (__len__ <= 0) \
LOGE("sending message failed [%d]", __len__); \
muse_core_msg_free(__sndMsg__); \
*/
typedef struct {
tbm_bo bo;
- int key;
+ tbm_fd fd;
} muse_recorder_export_data;
/**
muse_module_h module = (muse_module_h)user_data;
muse_recorder_handle_s *muse_recorder = NULL;
muse_recorder_export_data *export_data = NULL;
- int tbm_key = 0;
+ int audio_fd = -1;
+ tbm_fd tfd[MUSE_NUM_FD] = {-1, -1, -1, -1};
tbm_bo bo = NULL;
tbm_bo_handle bo_handle = {.ptr = NULL};
bo = tbm_bo_alloc(muse_recorder->bufmgr, size, TBM_BO_DEFAULT);
if (bo == NULL) {
LOGE("bo alloc failed : bufmgr %p, size %d", muse_recorder->bufmgr, size);
- g_free(export_data);
- export_data = NULL;
- return;
+ goto _BUFFER_FAILED;
}
bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE);
if (bo_handle.ptr == NULL) {
LOGE("bo map Error!");
- tbm_bo_unref(bo);
- g_free(export_data);
- export_data = NULL;
- return;
+ goto _BUFFER_FAILED;
}
memcpy(bo_handle.ptr, stream, size);
tbm_bo_unmap(bo);
- tbm_key = tbm_bo_export(bo);
- if (tbm_key == 0) {
- LOGE("Create key_info ERROR!!");
- tbm_bo_unref(bo);
- bo = NULL;
- g_free(export_data);
- export_data = NULL;
- return;
+ audio_fd = tbm_bo_export_fd(bo);
+ if (audio_fd < 0) {
+ LOGE("export bo ERROR");
+ goto _BUFFER_FAILED;
}
/* set bo info */
- export_data->key = tbm_key;
+ tfd[0] = audio_fd;
+ export_data->fd = audio_fd;
export_data->bo = bo;
/* add bo info to list */
g_mutex_unlock(&muse_recorder->list_lock);
/* send message */
- muse_recorder_msg_event5(MUSE_RECORDER_CB_EVENT,
+ muse_recorder_msg_event5_fd(MUSE_RECORDER_CB_EVENT,
MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM,
MUSE_RECORDER_EVENT_CLASS_THREAD_SUB,
module,
INT, format,
INT, channel,
INT, timestamp,
- INT, tbm_key);
+ INT, audio_fd,
+ tfd);
return;
+
+_BUFFER_FAILED:
+ tbm_bo_unref(bo);
+ g_free(export_data);
+ return;
}
void _recorder_disp_muxed_stream_cb(void* stream, int size, unsigned long long offset, void *user_data)
muse_module_h module = (muse_module_h)user_data;
muse_recorder_handle_s *muse_recorder = NULL;
muse_recorder_export_data *export_data = NULL;
- int tbm_key = 0;
+ int muxed_fd = -1;
+ tbm_fd tfd[MUSE_NUM_FD] = {-1, -1, -1, -1};
tbm_bo bo = NULL;
tbm_bo_handle bo_handle = {.ptr = NULL};
tbm_bo_unmap(bo);
- tbm_key = tbm_bo_export(bo);
- if (tbm_key == 0) {
- LOGE("Create key_info ERROR!!");
+ muxed_fd = tbm_bo_export_fd(bo);
+ if (muxed_fd < 0) {
+ LOGE("export bo ERROR");
goto _MUXED_STREAM_CB_ERROR;
}
/* set bo info */
- export_data->key = tbm_key;
+ tfd[0] = muxed_fd;
+ export_data->fd = muxed_fd;
export_data->bo = bo;
/* add bo info to list */
g_mutex_unlock(&muse_recorder->list_lock);
/* send message */
- muse_recorder_msg_event3(MUSE_RECORDER_CB_EVENT,
+ muse_recorder_msg_event3_fd(MUSE_RECORDER_CB_EVENT,
MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM,
MUSE_RECORDER_EVENT_CLASS_THREAD_SUB,
module,
INT, size,
- INT, tbm_key,
- INT64, offset);
+ INT64, offset,
+ INT, muxed_fd,
+ tfd);
return;
return true;
}
-static int _recorder_remove_export_data(muse_module_h module, int key, int remove_all)
+static int _recorder_remove_export_data(muse_module_h module, tbm_fd fd, int remove_all)
{
muse_recorder_handle_s *muse_recorder = NULL;
GList *tmp_list = NULL;
muse_recorder_export_data *export_data = NULL;
- if (module == NULL || (key <= 0 && remove_all == FALSE)) {
- LOGE("invalid parameter %p, %d", module, key);
+ if (module == NULL || (fd < 0 && remove_all == FALSE)) {
+ LOGE("invalid parameter %p, %d", module, fd);
return FALSE;
}
while (tmp_list) {
export_data = (muse_recorder_export_data *)tmp_list->data;
if (export_data) {
- if (export_data->key == key || remove_all) {
- /*LOGD("key %d matched, remove it (remove_all %d)", key, remove_all);*/
+ if (export_data->fd == fd || remove_all) {
+ /*LOGD("fd %d matched, remove it (remove_all %d)", fd, remove_all);*/
if (export_data->bo) {
tbm_bo_unref(export_data->bo);
export_data->bo = NULL;
} else {
- LOGW("bo for key %d is NULL", key);
+ LOGW("bo for fd %d is NULL", fd);
}
- export_data->key = 0;
+
+ /* close exported fd */
+ close(export_data->fd);
+ export_data->fd = -1;
muse_recorder->data_list = g_list_remove(muse_recorder->data_list, export_data);
export_data = NULL;
if (remove_all == FALSE) {
- /*LOGD("key %d, remove done");*/
+ /*LOGD("fd %d, remove done", fd);*/
g_mutex_unlock(&muse_recorder->list_lock);
return TRUE;
} else {
if (remove_all)
LOGD("remove all done");
else
- LOGE("should not be reached here - key %d", key);
+ LOGE("should not be reached here - fd %d", fd);
return FALSE;
}
int recorder_dispatcher_return_buffer(muse_module_h module)
{
- int tbm_key = 0;
+ int ret_fd = -1;
muse_recorder_handle_s *muse_recorder = NULL;
muse_recorder = (muse_recorder_handle_s *)muse_server_ipc_get_handle(module);
return MUSE_RECORDER_ERROR_NONE;
}
- muse_recorder_msg_get(tbm_key, muse_server_module_get_msg(module));
+ muse_recorder_msg_get(ret_fd, muse_server_module_get_msg(module));
- /*LOGD("handle : %p, key : %d", muse_recorder, tbm_key);*/
+ /*LOGD("handle : %p, ret_fd : %d", muse_recorder, ret_fd);*/
- if (!_recorder_remove_export_data(module, tbm_key, FALSE))
- LOGE("remove export data failed : key %d", tbm_key);
+ if (!_recorder_remove_export_data(module, (tbm_fd)ret_fd, FALSE))
+ LOGE("remove export data failed : fd %d", ret_fd);
return MUSE_RECORDER_ERROR_NONE;
}
legacy_recorder_get_state(muse_recorder->recorder_handle, &state);
- LOGW("current state : %d", state);
+ LOGW("shutdown handle %p [state:%d]", muse_recorder->recorder_handle, state);
switch (state) {
case RECORDER_STATE_PAUSED:
free(muse_recorder);
muse_recorder = NULL;
} else {
- LOGE("shutdown failed for handle %p %p",
- muse_recorder, muse_recorder->recorder_handle);
+ LOGE("shutdown failed");
}
break;
default: