2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <camera_internal.h>
23 #include <sound_manager.h>
24 #include <sound_manager_internal.h>
26 #include <storage-internal.h>
27 #include <muse_recorder.h>
28 #include <muse_recorder_msg.h>
29 #include <muse_core.h>
30 #include <muse_client.h>
31 #include <recorder_private.h>
34 #include <tzplatform_config.h>
39 #define LOG_TAG "TIZEN_N_RECORDER"
40 #define MODULE_NAME "recorder"
42 /* for device changed callback */
43 static GMutex g_rec_dev_state_changed_cb_lock;
44 static GList *g_rec_dev_state_changed_cb_list;
45 static int g_rec_dev_state_changed_cb_id;
46 static GDBusConnection *g_rec_dev_state_changed_cb_conn;
47 static guint g_rec_dev_state_changed_cb_subscribe_id;
48 static GMutex g_rec_idle_event_lock;
52 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
55 api < 0 || api >= MUSE_RECORDER_API_MAX) {
56 LOGE("invalid param %p %d", cb_info, api);
60 g_mutex_lock(&(cb_info->api_mutex[api]));
61 cb_info->api_waiting[api] += value;
62 g_mutex_unlock(&(cb_info->api_mutex[api]));
64 /*LOGD("api %d, value %d, waiting %d",
65 api, value, cb_info->api_waiting[api]);*/
71 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
72 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
73 const gchar *signal_name, GVariant *param, gpointer user_data)
76 recorder_type_e type = RECORDER_TYPE_AUDIO;
77 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
78 GList *tmp_list = NULL;
79 recorder_cb_info *info = NULL;
81 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
83 if (!g_rec_dev_state_changed_cb_list || !param) {
84 LOGW("no callback or NULL param %p", param);
88 /* get device type and state */
89 g_variant_get(param, "(i)", &value);
92 state = 0x0000ffff & value;
94 LOGD("type %d, state %d", type, state);
96 tmp_list = g_rec_dev_state_changed_cb_list;
99 info = (recorder_cb_info *)tmp_list->data;
102 if (info->callback) {
103 LOGD("start id[%d] callback", info->id);
104 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
105 LOGD("returned id[%d] callback", info->id);
107 LOGW("NULL callback for id %d", info->id);
111 tmp_list = tmp_list->next;
115 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
121 static int _recorder_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
123 tbm_bo tmp_bo = NULL;
124 tbm_bo_handle tmp_bo_handle = {NULL, };
126 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || fd < 0) {
127 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, fd %d",
128 bufmgr, bo, bo_handle, fd);
132 tmp_bo = tbm_bo_import_fd(bufmgr, (tbm_fd)fd);
133 if (tmp_bo == NULL) {
134 LOGE("bo import failed - bufmgr %p, fd %d", bufmgr, fd);
138 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
139 if (tmp_bo_handle.ptr == NULL) {
140 LOGE("bo map failed %p", tmp_bo);
141 tbm_bo_unref(tmp_bo);
146 /* set bo and bo_handle */
148 *bo_handle = tmp_bo_handle;
153 static void _recorder_release_imported_bo(tbm_bo *bo)
155 if (bo == NULL || *bo == NULL) {
167 static void _recorder_event_handler_video_encode_decision(recorder_cb_info_s *cb_info, char *recv_msg, int *tfd)
170 int event = MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION;
172 int num_buffer_fd = 0;
173 bool do_encode = true;
176 tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM] = {NULL, };
177 tbm_bo_handle bo_handle = {.ptr = NULL};
178 tbm_bo_handle buffer_bo_handle[BUFFER_MAX_PLANE_NUM] = {{.ptr = NULL}, };
179 tbm_bo data_bo = NULL;
180 tbm_bo_handle data_bo_handle = {.ptr = NULL};
182 recorder_video_data_s frame;
183 camera_stream_data_s *stream = NULL;
185 char *send_msg = NULL;
187 /* tfd[0]: MMCamcorderVideoStreamDataType
188 tfd[1]: data_bo or zero copy bo[0]
189 tfd[2]: zero copy bo[1]
190 tfd[3]: zero copy bo[2] */
191 if (!tfd || tfd[0] < 0) {
192 LOGE("invalid fd %d", tfd ? tfd[0] : 0);
196 muse_recorder_msg_get(video_fd, recv_msg);
197 muse_recorder_msg_get(num_buffer_fd, recv_msg);
199 /*LOGD("video_fd %d, num_buffer_fd %d", video_fd, num_buffer_fd);*/
201 memset(&frame, 0x0, sizeof(recorder_video_data_s));
203 if (num_buffer_fd < 0 || num_buffer_fd > BUFFER_MAX_PLANE_NUM) {
204 LOGE("invalid num buffer fd %d", num_buffer_fd);
205 goto _VIDEO_ENCODE_DECISION_CB_HANDLER_DONE;
208 /* import tbm bo and get virtual address */
209 if (!_recorder_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
210 LOGE("failed to import fd %d", tfd[0]);
211 goto _VIDEO_ENCODE_DECISION_CB_HANDLER_DONE;
214 if (num_buffer_fd == 0 && tfd[1] >= 0) {
215 /* import tbm data_bo and get virtual address */
216 if (!_recorder_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
217 LOGE("failed to import data fd %d", tfd[1]);
218 goto _VIDEO_ENCODE_DECISION_CB_HANDLER_DONE;
222 /* get stream info */
223 stream = (camera_stream_data_s *)bo_handle.ptr;
225 for (i = 0 ; i < num_buffer_fd ; i++) {
226 /* import buffer bo and get virtual address */
227 if (!_recorder_import_tbm_fd(cb_info->bufmgr, tfd[i + 1], &buffer_bo[i], &buffer_bo_handle[i])) {
228 LOGE("failed to import buffer fd %d", tfd[i + 1]);
229 goto _VIDEO_ENCODE_DECISION_CB_HANDLER_DONE;
233 if (cb_info->user_cb[event]) {
234 camera_create_preview_frame(stream, num_buffer_fd, buffer_bo_handle, &data_bo_handle, &frame);
235 do_encode = ((recorder_video_encode_decision_cb)cb_info->user_cb[event])(&frame, cb_info->user_data[event]);
238 _VIDEO_ENCODE_DECISION_CB_HANDLER_DONE:
240 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
241 MUSE_TYPE_INT, "ret_fd", video_fd,
242 MUSE_TYPE_INT, "buffer_type", MUSE_RECORDER_BUFFER_TYPE_VIDEO_ENCODE_DECISION,
243 MUSE_TYPE_INT, "video_encode_decision", (int)do_encode,
246 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
247 LOGE("sending message failed");
249 muse_core_msg_free(send_msg);
252 LOGE("failed to create send msg for fd %d", tfd[0]);
255 /* release imported bo and fd */
256 for (i = 0 ; i < num_buffer_fd && i < BUFFER_MAX_PLANE_NUM ; i++)
257 _recorder_release_imported_bo(&buffer_bo[i]);
259 /* unmap and unref tbm bo */
261 _recorder_release_imported_bo(&data_bo);
263 _recorder_release_imported_bo(&bo);
265 /* close imported fd */
266 for (i = 0 ; i < MUSE_NUM_FD ; i++) {
276 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event, int *tfd)
278 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
279 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
283 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
285 g_mutex_lock(&cb_info->user_cb_mutex[event]);
287 if (cb_info->user_cb[event] == NULL) {
288 if (event != MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM &&
289 event != MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM &&
290 event != MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION) {
291 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
292 LOGW("NULL callback for event %d, return here", event);
295 LOGW("NULL callback for event %d, NOT return here", event);
300 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
306 muse_recorder_msg_get(previous, recv_msg);
307 muse_recorder_msg_get(current, recv_msg);
308 muse_recorder_msg_get(by_policy, recv_msg);
310 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
311 (recorder_state_e)current,
313 cb_info->user_data[event]);
316 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
320 muse_recorder_msg_get(type, recv_msg);
322 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
323 cb_info->user_data[event]);
326 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
328 int64_t cb_elapsed_time = 0;
329 int64_t cb_file_size = 0;
331 muse_recorder_msg_get_int64(cb_elapsed_time, recv_msg);
332 muse_recorder_msg_get_int64(cb_file_size, recv_msg);
334 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
335 (unsigned long long)cb_file_size,
336 cb_info->user_data[event]);
339 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
345 muse_recorder_msg_get(policy, recv_msg);
346 muse_recorder_msg_get(previous, recv_msg);
347 muse_recorder_msg_get(current, recv_msg);
349 LOGW("INTERRUPTED - policy %d, state %d -> %d", policy, previous, current);
351 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
352 (recorder_state_e)previous,
353 (recorder_state_e)current,
354 cb_info->user_data[event]);
357 case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
362 muse_recorder_msg_get(policy, recv_msg);
363 muse_recorder_msg_get(state, recv_msg);
365 LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
367 ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
368 (recorder_state_e)state, cb_info->user_data[event]);
371 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
379 tbm_bo_handle bo_handle = {.ptr = NULL};
380 char *send_msg = NULL;
382 if (tfd && tfd[0] < 0) {
383 LOGE("invalid fd %d", tfd ? tfd[0] : 0);
387 muse_recorder_msg_get(audio_fd, recv_msg);
389 if (cb_info->user_cb[event]) {
390 if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
391 muse_recorder_msg_get(size, recv_msg);
392 muse_recorder_msg_get(format, recv_msg);
393 muse_recorder_msg_get(channel, recv_msg);
394 muse_recorder_msg_get(timestamp, recv_msg);
396 LOGD("%p, size %d, format %d, channel %d, timestamp %d",
397 bo_handle.ptr, size, format, channel, timestamp);
399 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
400 size, (audio_sample_type_e)format, channel,
401 (unsigned int)timestamp, cb_info->user_data[event]);
405 /* release imported bo */
406 _recorder_release_imported_bo(&bo);
408 LOGE("tbm fd %d import failed", tfd[0]);
413 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
414 MUSE_TYPE_INT, "ret_fd", audio_fd,
415 MUSE_TYPE_INT, "buffer_type", MUSE_RECORDER_BUFFER_TYPE_AUDIO_STREAM,
418 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
419 LOGE("sending message failed");
421 muse_core_msg_free(send_msg);
424 LOGE("failed to create send msg for fd %d", audio_fd);
427 /* close imported fd */
432 case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
439 tbm_bo_handle bo_handle = {.ptr = NULL};
440 char *send_msg = NULL;
442 if (!tfd || tfd[0] < 0) {
443 LOGE("invalid fd %d", tfd ? tfd[0] : 0);
447 muse_recorder_msg_get(muxed_fd, recv_msg);
449 if (cb_info->user_cb[event]) {
450 if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
451 muse_recorder_msg_get(size, recv_msg);
452 muse_recorder_msg_get_int64(offset, recv_msg);
454 LOGD("%p, size %d, offset %"PRId64, bo_handle.ptr, size, offset);
456 ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
457 size, (unsigned long long)offset, cb_info->user_data[event]);
461 /* release imported bo */
462 _recorder_release_imported_bo(&bo);
464 LOGE("tbm fd %d import failed", tfd[0]);
469 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
470 MUSE_TYPE_INT, "ret_fd", muxed_fd,
471 MUSE_TYPE_INT, "buffer_type", MUSE_RECORDER_BUFFER_TYPE_MUXED_STREAM,
474 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
475 LOGE("sending message failed");
477 muse_core_msg_free(send_msg);
480 LOGE("failed to create send msg for fd %d", tfd[0]);
483 /* close imported fd */
488 case MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION:
489 _recorder_event_handler_video_encode_decision(cb_info, recv_msg, tfd);
492 case MUSE_RECORDER_EVENT_TYPE_ERROR:
495 int current_state = 0;
497 muse_recorder_msg_get(error, recv_msg);
498 muse_recorder_msg_get(current_state, recv_msg);
500 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
501 (recorder_state_e)current_state,
502 cb_info->user_data[event]);
506 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
510 muse_recorder_msg_get(codec, recv_msg);
512 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
513 cb_info->user_cb[event] = NULL;
514 cb_info->user_data[event] = NULL;
515 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
519 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
523 muse_recorder_msg_get(format, recv_msg);
525 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
526 cb_info->user_cb[event] = NULL;
527 cb_info->user_data[event] = NULL;
528 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
532 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
536 muse_recorder_msg_get(codec, recv_msg);
538 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
539 cb_info->user_cb[event] = NULL;
540 cb_info->user_data[event] = NULL;
541 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
545 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
550 muse_recorder_msg_get(width, recv_msg);
551 muse_recorder_msg_get(height, recv_msg);
553 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
554 cb_info->user_cb[event] = NULL;
555 cb_info->user_data[event] = NULL;
556 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
562 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
568 static gboolean _recorder_idle_event_callback(gpointer data)
570 recorder_cb_info_s *cb_info = NULL;
571 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
573 if (rec_idle_event == NULL) {
574 LOGE("rec_idle_event is NULL");
579 g_mutex_lock(&g_rec_idle_event_lock);
581 cb_info = rec_idle_event->cb_info;
582 if (cb_info == NULL) {
583 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
584 g_mutex_unlock(&g_rec_idle_event_lock);
585 goto IDLE_EVENT_CALLBACK_DONE;
588 /* remove event from list */
589 if (cb_info->idle_event_list)
590 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
592 g_mutex_unlock(&g_rec_idle_event_lock);
595 _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event, NULL);
597 IDLE_EVENT_CALLBACK_DONE:
599 g_free(rec_idle_event);
600 rec_idle_event = NULL;
606 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
608 recorder_idle_event_s *rec_idle_event = NULL;
611 if (cb_info == NULL) {
612 LOGE("cb_info is NULL");
616 g_mutex_lock(&g_rec_idle_event_lock);
618 if (cb_info->idle_event_list == NULL) {
621 list = cb_info->idle_event_list;
624 rec_idle_event = list->data;
625 list = g_list_next(list);
627 if (!rec_idle_event) {
628 LOGW("The event is NULL");
632 if (g_idle_remove_by_data(rec_idle_event)) {
633 LOGW("remove idle event %p done", rec_idle_event);
635 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
637 g_free(rec_idle_event);
638 rec_idle_event = NULL;
643 LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
644 rec_idle_event, rec_idle_event->event);
646 rec_idle_event->cb_info = NULL;
648 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
651 g_list_free(cb_info->idle_event_list);
652 cb_info->idle_event_list = NULL;
655 g_mutex_unlock(&g_rec_idle_event_lock);
661 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg, int *tfd)
663 recorder_message_s *rec_msg = NULL;
664 recorder_msg_handler_info_s *msg_handler_info = NULL;
666 if (!cb_info || !msg) {
667 LOGE("NULL pointer %p %p", cb_info, msg);
671 rec_msg = g_new0(recorder_message_s, 1);
673 LOGE("failed to alloc rec_msg for [%s]", msg);
678 rec_msg->event = event;
679 rec_msg->event_class = event_class;
681 if (tfd && tfd[0] >= 0)
682 memcpy(rec_msg->tfd, tfd, sizeof(rec_msg->tfd));
684 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
686 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
688 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
689 msg_handler_info = &cb_info->audio_stream_cb_info;
690 else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
691 msg_handler_info = &cb_info->muxed_stream_cb_info;
693 msg_handler_info = &cb_info->msg_handler_info;
695 g_mutex_lock(&msg_handler_info->mutex);
696 g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
697 g_cond_signal(&msg_handler_info->cond);
698 g_mutex_unlock(&msg_handler_info->mutex);
706 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
708 if (!cb_info || !msg) {
709 LOGE("NULL pointer %p %p", cb_info, msg);
714 case MUSE_RECORDER_API_GET_STATE:
717 muse_recorder_msg_get(get_state, msg);
718 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
721 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
725 muse_recorder_msg_get(get_width, msg);
726 muse_recorder_msg_get(get_height, msg);
727 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
728 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
731 case MUSE_RECORDER_API_GET_FILE_FORMAT:
734 muse_recorder_msg_get(get_format, msg);
735 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
738 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
741 muse_recorder_msg_get(get_codec, msg);
742 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
745 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
748 muse_recorder_msg_get(get_codec, msg);
749 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
752 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
755 muse_recorder_msg_get(get_kbyte, msg);
756 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
759 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
762 muse_recorder_msg_get(get_second, msg);
763 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
766 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
769 muse_recorder_msg_get(get_device, msg);
770 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
773 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
775 int get_samplerate = 0;
776 muse_recorder_msg_get(get_samplerate, msg);
777 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
780 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
783 muse_recorder_msg_get(get_bitrate, msg);
784 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
787 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
790 muse_recorder_msg_get(get_bitrate, msg);
791 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
794 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
797 muse_recorder_msg_get_double(get_rate, msg);
798 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
801 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
803 int get_channel_count = 0;
804 muse_recorder_msg_get(get_channel_count, msg);
805 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
808 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
810 int get_orientation = 0;
811 muse_recorder_msg_get(get_orientation, msg);
812 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
815 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
817 double get_level = 0.0;
818 muse_recorder_msg_get_double(get_level, msg);
819 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
822 case MUSE_RECORDER_API_GET_FILENAME:
824 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
825 muse_recorder_msg_get_string(get_filename, msg);
826 if (cb_info->get_filename) {
827 free(cb_info->get_filename);
828 cb_info->get_filename = NULL;
830 cb_info->get_filename = strdup(get_filename);
841 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg, int *tfd)
843 int ret = RECORDER_ERROR_NONE;
847 int event_class = -1;
849 if (!cb_info || !msg) {
850 LOGE("invalid ptr %p %p", cb_info, msg);
854 /*LOGD("msg [%s]", msg);*/
856 if (!muse_recorder_msg_get(api, msg)) {
857 LOGE("failed to get recorder api");
861 if (api == MUSE_RECORDER_CB_EVENT) {
862 if (!muse_recorder_msg_get(event, msg) ||
863 !muse_recorder_msg_get(event_class, msg)) {
864 LOGE("failed to get event or event_class [%s]", msg);
868 if (!muse_recorder_msg_get(api_class, msg)) {
869 LOGE("failed to get api_class [%s]", msg);
874 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
875 if (api >= MUSE_RECORDER_API_MAX) {
876 LOGE("invalid api %d", api);
880 if (!muse_recorder_msg_get(ret, msg)) {
881 LOGE("failed to get recorder ret");
885 g_mutex_lock(&cb_info->api_mutex[api]);
887 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
888 g_atomic_int_set(&cb_info->msg_recv_running, 0);
889 LOGD("get device state done. close client cb handler");
892 case MUSE_RECORDER_API_CREATE:
893 if (ret != RECORDER_ERROR_NONE) {
894 g_atomic_int_set(&cb_info->msg_recv_running, 0);
895 LOGE("create error 0x%x. closing..", ret);
898 case MUSE_RECORDER_API_DESTROY:
899 if (ret == RECORDER_ERROR_NONE) {
900 g_atomic_int_set(&cb_info->msg_recv_running, 0);
901 LOGD("destroy done. closing..");
905 __recorder_get_api_operation(api, cb_info, msg);
910 if (cb_info->api_waiting[api] > 0) {
911 cb_info->api_ret[api] = ret;
912 cb_info->api_activating[api] = TRUE;
914 g_cond_signal(&cb_info->api_cond[api]);
916 LOGE("no waiting for api [%d]", api);
919 g_mutex_unlock(&cb_info->api_mutex[api]);
920 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
921 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg, tfd);
923 LOGW("unknown recorder api %d and api_class %d", api, api_class);
930 static void *_recorder_msg_handler_func(gpointer data)
934 recorder_message_s *rec_msg = NULL;
935 recorder_idle_event_s *rec_idle_event = NULL;
936 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
937 recorder_cb_info_s *cb_info = NULL;
939 if (!handler_info || !handler_info->cb_info) {
940 LOGE("NULL handler %p", handler_info);
944 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
945 type = handler_info->type;
947 LOGD("t:%d start", type);
949 g_mutex_lock(&handler_info->mutex);
951 while (g_atomic_int_get(&handler_info->running)) {
952 if (g_queue_is_empty(handler_info->queue)) {
953 /*LOGD("signal wait...");*/
954 g_cond_wait(&handler_info->cond, &handler_info->mutex);
955 /*LOGD("signal received");*/
957 if (g_atomic_int_get(&handler_info->running) == 0) {
958 LOGD("stop event thread");
963 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
964 g_mutex_unlock(&handler_info->mutex);
965 if (rec_msg == NULL) {
966 LOGE("NULL message");
967 g_mutex_lock(&handler_info->mutex);
973 if (api < MUSE_RECORDER_API_MAX) {
976 g_mutex_lock(&cb_info->api_mutex[api]);
978 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
979 if (cb_info->api_waiting[api] > 0) {
980 cb_info->api_ret[api] = ret;
981 cb_info->api_activating[api] = TRUE;
983 /*LOGD("recorder api %d - return 0x%x", api, ret);*/
985 g_cond_signal(&cb_info->api_cond[api]);
987 LOGE("no waiting for api [%d]", api);
990 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
993 g_mutex_unlock(&cb_info->api_mutex[api]);
994 } else if (api == MUSE_RECORDER_CB_EVENT) {
995 switch (rec_msg->event_class) {
996 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
997 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event, rec_msg->tfd);
999 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
1000 rec_idle_event = g_new0(recorder_idle_event_s, 1);
1001 if (rec_idle_event == NULL) {
1002 LOGE("event alloc failed");
1006 rec_idle_event->event = rec_msg->event;
1007 rec_idle_event->cb_info = cb_info;
1009 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg));
1011 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
1013 g_mutex_lock(&g_rec_idle_event_lock);
1014 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
1015 g_mutex_unlock(&g_rec_idle_event_lock);
1017 g_idle_add_full(G_PRIORITY_DEFAULT,
1018 (GSourceFunc)_recorder_idle_event_callback,
1019 (gpointer)rec_idle_event,
1023 LOGE("unknown event class %d", rec_msg->event_class);
1027 LOGE("unknown api[%d] message", api);
1033 g_mutex_lock(&handler_info->mutex);
1036 /* remove remained event */
1037 while (!g_queue_is_empty(handler_info->queue)) {
1038 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
1040 LOGD("remove message %p", rec_msg);
1044 LOGW("NULL message");
1048 g_mutex_unlock(&handler_info->mutex);
1056 static void *_recorder_msg_recv_func(gpointer data)
1059 int recv_length = 0;
1060 int tfd[MUSE_NUM_FD] = {-1, -1, -1, -1};
1061 char *recv_msg = NULL;
1062 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
1064 if (cb_info == NULL) {
1065 LOGE("cb_info NULL");
1071 recv_msg = cb_info->recv_msg;
1073 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
1074 for (i = 0 ; i < MUSE_NUM_FD ; i++)
1077 recv_length = muse_core_msg_recv_fd(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH, tfd);
1078 if (recv_length <= 0) {
1080 cb_info->is_server_connected = FALSE;
1081 LOGE("receive msg failed - server disconnected");
1086 recv_msg[recv_length] = '\0';
1088 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
1090 __recorder_process_msg(cb_info, recv_msg, tfd);
1093 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1095 if (!cb_info->is_server_connected) {
1097 /* send error msg for server disconnection */
1098 char *error_msg = muse_core_msg_new(MUSE_RECORDER_CB_EVENT,
1099 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1100 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1104 LOGE("error_msg failed");
1105 goto CB_HANDLER_EXIT;
1108 LOGE("add error msg for service disconnection done");
1110 __recorder_add_msg_to_queue(cb_info,
1111 MUSE_RECORDER_CB_EVENT,
1112 MUSE_RECORDER_EVENT_TYPE_ERROR,
1113 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1117 muse_core_msg_free(error_msg);
1120 LOGE("add error msg for service disconnection done");
1129 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1130 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1132 if (!handler_info || !thread_name || !cb_info) {
1133 LOGE("t:%d NULL %p %p %p",
1134 type, handler_info, thread_name, cb_info);
1140 handler_info->type = type;
1141 handler_info->queue = g_queue_new();
1142 if (handler_info->queue == NULL) {
1143 LOGE("t:%d queue failed", type);
1147 g_mutex_init(&handler_info->mutex);
1148 g_cond_init(&handler_info->cond);
1150 handler_info->cb_info = (void *)cb_info;
1151 g_atomic_int_set(&handler_info->running, 1);
1153 handler_info->thread = g_thread_try_new(thread_name,
1154 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1155 if (handler_info->thread == NULL) {
1157 LOGE("t:%d thread failed", type);
1159 g_mutex_clear(&handler_info->mutex);
1160 g_cond_clear(&handler_info->cond);
1161 g_queue_free(handler_info->queue);
1162 handler_info->queue = NULL;
1168 LOGD("t:%d done", type);
1174 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1178 if (!handler_info) {
1179 LOGE("NULL handler");
1183 if (!handler_info->thread) {
1184 LOGW("thread is not created");
1188 type = handler_info->type;
1190 LOGD("t:%d thread %p", type, handler_info->thread);
1192 g_mutex_lock(&handler_info->mutex);
1193 g_atomic_int_set(&handler_info->running, 0);
1194 g_cond_signal(&handler_info->cond);
1195 g_mutex_unlock(&handler_info->mutex);
1197 g_thread_join(handler_info->thread);
1198 handler_info->thread = NULL;
1200 g_mutex_clear(&handler_info->mutex);
1201 g_cond_clear(&handler_info->cond);
1202 g_queue_free(handler_info->queue);
1203 handler_info->queue = NULL;
1205 LOGD("t:%d done", type);
1211 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1213 recorder_cb_info_s *cb_info = NULL;
1216 g_return_val_if_fail(sockfd > 0, NULL);
1218 cb_info = g_new0(recorder_cb_info_s, 1);
1219 if (cb_info == NULL) {
1220 LOGE("cb_info failed");
1224 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1226 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1227 g_mutex_init(&cb_info->api_mutex[i]);
1228 g_cond_init(&cb_info->api_cond[i]);
1231 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1232 g_mutex_init(&cb_info->user_cb_mutex[i]);
1234 /* message handler thread */
1235 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1236 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1237 LOGE("msg_handler_info failed");
1241 /* message handler thread for audio stream callback */
1242 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1243 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1244 LOGE("audio_stream_cb_info failed");
1248 /* message handler thread for muxed stream callback */
1249 if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
1250 _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
1251 LOGE("muxed_stream_cb_info failed");
1255 cb_info->fd = sockfd;
1257 /* message receive thread */
1258 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1259 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1260 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1261 if (cb_info->msg_recv_thread == NULL) {
1262 LOGE("message receive thread creation failed");
1266 cb_info->is_server_connected = TRUE;
1272 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1273 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1274 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1276 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1277 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1279 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1280 g_mutex_clear(&cb_info->api_mutex[i]);
1281 g_cond_clear(&cb_info->api_cond[i]);
1292 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1294 int ret = RECORDER_ERROR_NONE;
1297 /*LOGD("Enter api : %d", api);*/
1299 if (!cb_info->is_server_connected) {
1300 LOGE("server is disconnected");
1301 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1304 g_mutex_lock(&(cb_info->api_mutex[api]));
1306 LOGD("api [%d], timeout [%d sec]", api, time_out);
1308 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1310 while (!cb_info->api_activating[api]) {
1311 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1312 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1313 LOGW("api %d returned 0x%x", api, cb_info->api_ret[api]);
1314 } else if (!g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1315 LOGE("api %d was TIMED OUT!", api);
1316 ret = RECORDER_ERROR_INVALID_OPERATION;
1317 goto _CB_RETURN_END;
1320 if (!cb_info->api_activating[api])
1321 LOGW("invalid signal received, wait again...");
1324 ret = cb_info->api_ret[api];
1325 cb_info->api_activating[api] = FALSE;
1328 g_mutex_unlock(&(cb_info->api_mutex[api]));
1330 if (ret != RECORDER_ERROR_NONE)
1331 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1337 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
1342 if (!cb_info || !ret) {
1343 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1344 return RECORDER_ERROR_INVALID_PARAMETER;
1347 msg = muse_core_msg_new(api, NULL);
1349 LOGE("msg creation failed: api %d", api);
1350 return RECORDER_ERROR_OUT_OF_MEMORY;
1353 /*LOGD("send msg %s", msg);*/
1355 if (cb_info->is_server_connected) {
1356 __recorder_update_api_waiting(cb_info, api, 1);
1357 send_ret = muse_core_msg_send(cb_info->fd, msg);
1361 LOGE("message send failed");
1362 *ret = RECORDER_ERROR_INVALID_OPERATION;
1364 *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
1367 __recorder_update_api_waiting(cb_info, api, -1);
1369 muse_core_msg_free(msg);
1371 return RECORDER_ERROR_NONE;
1375 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1380 if (!cb_info || !ret || !param) {
1381 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1382 return RECORDER_ERROR_INVALID_PARAMETER;
1385 /*LOGD("type %d, name %s", param->type, param->name);*/
1387 switch (param->type) {
1389 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_INT, NULL);
1391 case MUSE_TYPE_DOUBLE:
1392 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1394 case MUSE_TYPE_STRING:
1395 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_STRING, NULL);
1398 LOGE("unknown type %d", param->type);
1403 LOGE("msg creation failed: api %d, type %d, param name %s",
1404 api, param->type, param->name);
1405 return RECORDER_ERROR_OUT_OF_MEMORY;
1408 /*LOGD("send msg %s", msg);*/
1410 if (cb_info->is_server_connected) {
1411 __recorder_update_api_waiting(cb_info, api, 1);
1413 send_ret = muse_core_msg_send(cb_info->fd, msg);
1417 LOGE("message send failed");
1418 *ret = RECORDER_ERROR_INVALID_OPERATION;
1420 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1423 __recorder_update_api_waiting(cb_info, api, -1);
1425 muse_core_msg_free(msg);
1427 return RECORDER_ERROR_NONE;
1431 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1435 g_return_if_fail(cb_info != NULL);
1437 /* remove idle event */
1438 _recorder_deactivate_idle_event_all(cb_info);
1440 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1442 g_thread_join(cb_info->msg_recv_thread);
1443 cb_info->msg_recv_thread = NULL;
1445 LOGD("msg_recv thread removed");
1447 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1448 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1449 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1451 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1452 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1454 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1455 g_mutex_clear(&cb_info->api_mutex[i]);
1456 g_cond_clear(&cb_info->api_cond[i]);
1459 if (cb_info->fd > -1) {
1460 muse_client_close(cb_info->fd);
1464 if (cb_info->bufmgr) {
1465 tbm_bufmgr_deinit(cb_info->bufmgr);
1466 cb_info->bufmgr = NULL;
1468 if (cb_info->get_filename) {
1469 free(cb_info->get_filename);
1470 cb_info->get_filename = NULL;
1480 static bool _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1482 char **root_directory = (char **)user_data;
1484 if (root_directory == NULL) {
1485 LOGE("user data is NULL");
1489 LOGD("storage id %d, type %d, state %d, path %s",
1490 storage_id, type, state, path ? path : "NULL");
1492 if (type == STORAGE_TYPE_INTERNAL && path) {
1493 if (*root_directory) {
1494 free(*root_directory);
1495 *root_directory = NULL;
1498 *root_directory = strdup(path);
1499 if (*root_directory) {
1500 LOGD("get root directory %s", *root_directory);
1503 LOGE("strdup %s failed", path);
1510 static int _recorder_client_get_root_directory(char **root_directory)
1512 int ret = STORAGE_ERROR_NONE;
1514 if (root_directory == NULL) {
1515 LOGE("user data is NULL");
1519 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1520 if (ret != STORAGE_ERROR_NONE) {
1521 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1528 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1530 int ret = RECORDER_ERROR_NONE;
1531 int destroy_ret = RECORDER_ERROR_NONE;
1533 int module_index = -1;
1535 char *send_msg = NULL;
1536 char *root_directory = NULL;
1537 intptr_t camera_handle = 0;
1538 intptr_t handle = 0;
1539 tbm_bufmgr bufmgr = NULL;
1540 recorder_cli_s *pc = NULL;
1541 recorder_msg_param param;
1543 LOGD("Enter - type %d", type);
1545 if (recorder == NULL) {
1546 LOGE("NULL pointer for recorder handle");
1547 return RECORDER_ERROR_INVALID_PARAMETER;
1550 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1551 LOGE("NULL pointer for camera handle on video recorder mode");
1552 return RECORDER_ERROR_INVALID_PARAMETER;
1555 bufmgr = tbm_bufmgr_init(-1);
1556 if (bufmgr == NULL) {
1557 LOGE("get tbm bufmgr failed");
1558 return RECORDER_ERROR_INVALID_OPERATION;
1561 pc = g_new0(recorder_cli_s, 1);
1563 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1564 goto _ERR_RECORDER_EXIT;
1567 sock_fd = muse_client_new();
1570 LOGE("muse_client_new failed - returned fd %d", sock_fd);
1571 ret = RECORDER_ERROR_INVALID_OPERATION;
1572 goto _ERR_RECORDER_EXIT;
1576 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
1577 LOGE("muse client get module index failed");
1578 ret = RECORDER_ERROR_INVALID_OPERATION;
1579 goto _ERR_RECORDER_EXIT;
1582 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1583 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1584 MUSE_TYPE_INT, "module", module_index,
1585 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1586 MUSE_TYPE_INT, "pid", getpid(),
1589 pc->camera = camera;
1590 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1591 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1592 MUSE_TYPE_INT, "module", module_index,
1593 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1594 MUSE_TYPE_INT, "pid", getpid(),
1595 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1602 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1603 goto _ERR_RECORDER_EXIT;
1607 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1609 send_ret = muse_core_msg_send(sock_fd, send_msg);
1611 muse_core_msg_free(send_msg);
1616 LOGE("send msg failed %d", errno);
1617 ret = RECORDER_ERROR_INVALID_OPERATION;
1618 goto _ERR_RECORDER_EXIT;
1622 pc->cb_info = _recorder_client_callback_new(sock_fd);
1623 if (pc->cb_info == NULL) {
1624 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1625 goto _ERR_RECORDER_EXIT;
1630 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1632 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1634 if (ret != RECORDER_ERROR_NONE) {
1635 LOGE("API_CREATE failed 0x%x", ret);
1636 goto _ERR_RECORDER_EXIT;
1639 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1642 LOGE("Receiving Handle Failed!!");
1643 ret = RECORDER_ERROR_INVALID_OPERATION;
1644 goto _ERR_RECORDER_AFTER_CREATE;
1648 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1650 LOGE("failed to get root directory of internal storage");
1651 ret = RECORDER_ERROR_INVALID_OPERATION;
1652 goto _ERR_RECORDER_AFTER_CREATE;
1656 LOGD("root directory [%s]", root_directory);
1658 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1660 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1662 if (ret != RECORDER_ERROR_NONE) {
1663 LOGE("failed to set root directory %s", root_directory);
1664 ret = RECORDER_ERROR_INVALID_OPERATION;
1665 goto _ERR_RECORDER_AFTER_CREATE;
1668 free(root_directory);
1669 root_directory = NULL;
1671 pc->remote_handle = handle;
1672 pc->cb_info->bufmgr = bufmgr;
1674 LOGD("recorder[type %d] %p create success : remote handle 0x%td",
1675 type, pc, pc->remote_handle);
1677 *recorder = (recorder_h)pc;
1681 return RECORDER_ERROR_NONE;
1683 _ERR_RECORDER_AFTER_CREATE:
1684 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
1685 LOGE("destroy return 0x%x", destroy_ret);
1688 tbm_bufmgr_deinit(bufmgr);
1691 if (root_directory) {
1692 free(root_directory);
1693 root_directory = NULL;
1697 muse_client_close(sock_fd);
1703 _recorder_client_callback_destroy(pc->cb_info);
1715 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1717 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1721 int recorder_create_audiorecorder(recorder_h *recorder)
1723 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1727 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1729 int ret = RECORDER_ERROR_NONE;
1730 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1731 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1733 if (!pc || !pc->cb_info) {
1734 LOGE("NULL handle");
1735 return RECORDER_ERROR_INVALID_PARAMETER;
1738 if (state == NULL) {
1739 LOGE("NULL pointer state");
1740 return RECORDER_ERROR_INVALID_PARAMETER;
1743 LOGD("Enter, remote_handle : %td", pc->remote_handle);
1745 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1747 if (ret == RECORDER_ERROR_NONE)
1748 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1750 LOGD("ret : 0x%x, state : %d", ret, *state);
1756 int recorder_destroy(recorder_h recorder)
1758 int ret = RECORDER_ERROR_NONE;
1759 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1760 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1762 if (!pc || !pc->cb_info) {
1763 LOGE("NULL handle");
1764 return RECORDER_ERROR_INVALID_PARAMETER;
1769 if (pc->cb_info->is_server_connected)
1770 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1772 LOGW("server disconnected. release resource without send message.");
1774 if (ret == RECORDER_ERROR_NONE) {
1775 _recorder_client_callback_destroy(pc->cb_info);
1780 LOGD("ret : 0x%x", ret);
1786 int recorder_prepare(recorder_h recorder)
1788 int ret = RECORDER_ERROR_NONE;
1789 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1790 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1792 if (!pc || !pc->cb_info) {
1793 LOGE("NULL handle");
1794 return RECORDER_ERROR_INVALID_PARAMETER;
1799 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1801 LOGD("ret : 0x%x", ret);
1803 if (ret == RECORDER_ERROR_NONE && pc->camera)
1804 camera_start_evas_rendering(pc->camera);
1810 int recorder_unprepare(recorder_h recorder)
1812 int ret = RECORDER_ERROR_NONE;
1813 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1814 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1815 camera_state_e camera_state = CAMERA_STATE_NONE;
1817 if (!pc || !pc->cb_info) {
1818 LOGE("NULL handle");
1819 return RECORDER_ERROR_INVALID_PARAMETER;
1826 ret = camera_get_state(pc->camera, &camera_state);
1827 if (ret != CAMERA_ERROR_NONE) {
1828 LOGE("failed to get camera state 0x%x", ret);
1829 return RECORDER_ERROR_INVALID_OPERATION;
1832 if (camera_state == CAMERA_STATE_PREVIEW) {
1833 ret = camera_stop_evas_rendering(pc->camera, false);
1834 if (ret != CAMERA_ERROR_NONE) {
1835 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1836 return RECORDER_ERROR_INVALID_OPERATION;
1842 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1844 LOGD("ret : 0x%x", ret);
1850 int recorder_start(recorder_h recorder)
1852 int ret = RECORDER_ERROR_NONE;
1853 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1854 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1855 recorder_state_e current_state = RECORDER_STATE_NONE;
1857 if (!pc || !pc->cb_info) {
1858 LOGE("NULL handle");
1859 return RECORDER_ERROR_INVALID_PARAMETER;
1866 ret = recorder_get_state(recorder, ¤t_state);
1867 if (ret != RECORDER_ERROR_NONE) {
1868 LOGE("failed to get current state 0x%x", ret);
1869 return RECORDER_ERROR_INVALID_OPERATION;
1872 if (current_state == RECORDER_STATE_READY) {
1873 ret = camera_stop_evas_rendering(pc->camera, true);
1874 if (ret != CAMERA_ERROR_NONE) {
1875 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1876 return RECORDER_ERROR_INVALID_OPERATION;
1882 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
1884 if (pc->camera && current_state == RECORDER_STATE_READY)
1885 camera_start_evas_rendering(pc->camera);
1887 LOGD("ret : 0x%x", ret);
1893 int recorder_pause(recorder_h recorder)
1895 int ret = RECORDER_ERROR_NONE;
1896 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1897 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1899 if (!pc || !pc->cb_info) {
1900 LOGE("NULL handle");
1901 return RECORDER_ERROR_INVALID_PARAMETER;
1906 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1908 LOGD("ret : 0x%x", ret);
1914 int recorder_commit(recorder_h recorder)
1916 int ret = RECORDER_ERROR_NONE;
1917 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1918 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1919 recorder_state_e current_state = RECORDER_STATE_NONE;
1921 if (!pc || !pc->cb_info) {
1922 LOGE("NULL handle");
1923 return RECORDER_ERROR_INVALID_PARAMETER;
1930 ret = recorder_get_state(recorder, ¤t_state);
1931 if (ret != RECORDER_ERROR_NONE) {
1932 LOGE("failed to get current state 0x%x", ret);
1933 return RECORDER_ERROR_INVALID_OPERATION;
1936 if (current_state >= RECORDER_STATE_RECORDING) {
1937 ret = camera_stop_evas_rendering(pc->camera, true);
1938 if (ret != CAMERA_ERROR_NONE) {
1939 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1940 return RECORDER_ERROR_INVALID_OPERATION;
1946 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1948 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1949 camera_start_evas_rendering(pc->camera);
1951 LOGD("ret : 0x%x", ret);
1957 int recorder_cancel(recorder_h recorder)
1959 int ret = RECORDER_ERROR_NONE;
1960 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1961 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1962 recorder_state_e current_state = RECORDER_STATE_NONE;
1964 if (!pc || !pc->cb_info) {
1965 LOGE("NULL handle");
1966 return RECORDER_ERROR_INVALID_PARAMETER;
1972 ret = recorder_get_state(recorder, ¤t_state);
1973 if (ret != RECORDER_ERROR_NONE) {
1974 LOGE("failed to get current state 0x%x", ret);
1975 return RECORDER_ERROR_INVALID_OPERATION;
1978 if (current_state >= RECORDER_STATE_RECORDING) {
1979 ret = camera_stop_evas_rendering(pc->camera, true);
1980 if (ret != CAMERA_ERROR_NONE) {
1981 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1982 return RECORDER_ERROR_INVALID_OPERATION;
1987 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1989 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1990 camera_start_evas_rendering(pc->camera);
1992 LOGD("ret : 0x%x", ret);
1998 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
2000 int ret = RECORDER_ERROR_NONE;
2002 char *send_msg = NULL;
2003 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
2004 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2006 if (!pc || !pc->cb_info) {
2007 LOGE("NULL handle");
2008 return RECORDER_ERROR_INVALID_PARAMETER;
2013 send_msg = muse_core_msg_new(api,
2014 MUSE_TYPE_INT, "width", width,
2015 MUSE_TYPE_INT, "height", height,
2018 if (pc->cb_info->is_server_connected) {
2019 __recorder_update_api_waiting(pc->cb_info, api, 1);
2021 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
2025 LOGE("message send failed");
2026 ret = RECORDER_ERROR_INVALID_OPERATION;
2028 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2031 __recorder_update_api_waiting(pc->cb_info, api, -1);
2033 muse_core_msg_free(send_msg);
2035 LOGE("failed to create msg");
2036 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2039 LOGD("ret : 0x%x", ret);
2045 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
2047 int ret = RECORDER_ERROR_NONE;
2048 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
2049 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2051 if (!pc || !pc->cb_info) {
2052 LOGE("NULL handle");
2053 return RECORDER_ERROR_INVALID_PARAMETER;
2056 if (!width || !height) {
2057 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
2058 return RECORDER_ERROR_INVALID_PARAMETER;
2063 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2065 if (ret == RECORDER_ERROR_NONE) {
2066 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
2067 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
2070 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
2076 int recorder_foreach_supported_video_resolution(recorder_h recorder,
2077 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
2079 int ret = RECORDER_ERROR_NONE;
2080 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2081 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
2083 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2084 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2085 return RECORDER_ERROR_INVALID_PARAMETER;
2088 LOGD("Enter, handle :%td", pc->remote_handle);
2090 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2091 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2093 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2095 LOGD("ret : 0x%x", ret);
2101 int recorder_get_audio_level(recorder_h recorder, double *level)
2103 int ret = RECORDER_ERROR_NONE;
2104 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2105 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2107 if (!pc || !pc->cb_info || level == NULL) {
2108 LOGE("NULL pointer %p %p", pc, level);
2109 return RECORDER_ERROR_INVALID_PARAMETER;
2114 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2116 if (ret == RECORDER_ERROR_NONE)
2117 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2119 LOGD("ret : 0x%x, level %lf", ret, *level);
2125 int recorder_set_filename(recorder_h recorder, const char *filename)
2127 int ret = RECORDER_ERROR_NONE;
2129 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2130 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2131 recorder_msg_param param;
2132 char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2134 if (!pc || !pc->cb_info) {
2135 LOGE("NULL handle");
2136 return RECORDER_ERROR_INVALID_PARAMETER;
2139 if (filename == NULL) {
2140 LOGE("filename is NULL");
2141 return RECORDER_ERROR_INVALID_PARAMETER;
2144 LOGD("ENTER [%s]", filename);
2146 length = strlen(filename);
2148 if (length >= RECORDER_FILENAME_MAX - 1) {
2149 LOGE("too long file name [%zu]", length);
2150 return RECORDER_ERROR_INVALID_PARAMETER;
2153 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2154 /* Cannot convert. Use original path. */
2155 strncpy(set_filename, filename, length + 1);
2156 pc->cb_info->is_filename_converted = FALSE;
2158 /* Converted. Use converted path. */
2159 LOGD("Converted filename : %s -> %s", filename, set_filename);
2160 pc->cb_info->is_filename_converted = TRUE;
2163 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2165 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2167 LOGD("ret : 0x%x", ret);
2173 int recorder_get_filename(recorder_h recorder, char **filename)
2175 int ret = RECORDER_ERROR_NONE;
2176 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2177 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2178 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2180 if (!pc || !pc->cb_info) {
2181 LOGE("NULL handle");
2182 return RECORDER_ERROR_INVALID_PARAMETER;
2185 if (filename == NULL) {
2186 LOGE("filename is NULL");
2187 return RECORDER_ERROR_INVALID_PARAMETER;
2192 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2194 if (ret == RECORDER_ERROR_NONE) {
2195 if (pc->cb_info->is_filename_converted == FALSE ||
2196 storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2197 /* Use original path. */
2198 *filename = pc->cb_info->get_filename;
2200 /* Converted. Use converted path. */
2201 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2202 *filename = strdup(compat_filename);
2203 free(pc->cb_info->get_filename);
2206 pc->cb_info->get_filename = NULL;
2209 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2215 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2217 int ret = RECORDER_ERROR_NONE;
2218 int set_format = (int)format;
2219 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2220 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2221 recorder_msg_param param;
2223 if (!pc || !pc->cb_info) {
2224 LOGE("NULL handle");
2225 return RECORDER_ERROR_INVALID_PARAMETER;
2228 LOGD("ENTER, set_format : %d", set_format);
2230 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2232 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2234 LOGD("ret : 0x%x", ret);
2239 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2241 int ret = RECORDER_ERROR_NONE;
2242 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2243 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2245 if (!pc || !pc->cb_info) {
2246 LOGE("NULL handle");
2247 return RECORDER_ERROR_INVALID_PARAMETER;
2250 if (format == NULL) {
2251 LOGE("NULL pointer data");
2252 return RECORDER_ERROR_INVALID_PARAMETER;
2257 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2259 if (ret == RECORDER_ERROR_NONE)
2260 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2262 LOGD("ret : 0x%x, format %d", ret, *format);
2268 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2270 int ret = RECORDER_ERROR_NONE;
2271 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2272 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2273 bool is_available = false;
2274 int stream_index = 0;
2275 char *stream_type = NULL;
2276 char *send_msg = NULL;
2279 if (!pc || !pc->cb_info || stream_info == NULL) {
2280 LOGE("NULL handle");
2281 return RECORDER_ERROR_INVALID_PARAMETER;
2286 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2287 if (ret != SOUND_MANAGER_ERROR_NONE) {
2288 LOGE("stream info verification failed");
2289 return RECORDER_ERROR_INVALID_OPERATION;
2292 if (is_available == false) {
2293 LOGE("stream information is not available");
2294 return RECORDER_ERROR_INVALID_OPERATION;
2297 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2298 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2300 LOGD("sound manager return [0x%x]", ret);
2302 if (ret == SOUND_MANAGER_ERROR_NONE) {
2303 send_msg = muse_core_msg_new(api,
2304 MUSE_TYPE_STRING, "stream_type", stream_type,
2305 MUSE_TYPE_INT, "stream_index", stream_index,
2308 if (pc->cb_info->is_server_connected) {
2309 __recorder_update_api_waiting(pc->cb_info, api, 1);
2311 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
2315 LOGE("message send failed");
2316 ret = RECORDER_ERROR_INVALID_OPERATION;
2318 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2321 __recorder_update_api_waiting(pc->cb_info, api, -1);
2323 muse_core_msg_free(send_msg);
2325 LOGE("failed to create msg");
2326 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2329 ret = RECORDER_ERROR_INVALID_OPERATION;
2336 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2338 int ret = RECORDER_ERROR_NONE;
2339 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2340 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2342 if (!pc || !pc->cb_info || callback == NULL) {
2343 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2344 return RECORDER_ERROR_INVALID_PARAMETER;
2347 LOGD("Enter, handle :%td", pc->remote_handle);
2349 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2351 if (ret == RECORDER_ERROR_NONE) {
2352 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2354 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2355 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2357 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2360 LOGD("ret : 0x%x", ret);
2366 int recorder_unset_state_changed_cb(recorder_h recorder)
2368 int ret = RECORDER_ERROR_NONE;
2369 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2370 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2372 if (!pc || !pc->cb_info) {
2373 LOGE("NULL handle");
2374 return RECORDER_ERROR_INVALID_PARAMETER;
2379 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2381 if (ret == RECORDER_ERROR_NONE) {
2382 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2384 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2385 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2387 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2390 LOGD("ret : 0x%x", ret);
2396 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2398 int ret = RECORDER_ERROR_NONE;
2399 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2400 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2402 if (!pc || !pc->cb_info || callback == NULL) {
2403 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2404 return RECORDER_ERROR_INVALID_PARAMETER;
2407 LOGD("Enter, handle :%td", pc->remote_handle);
2409 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2411 if (ret == RECORDER_ERROR_NONE) {
2412 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2414 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2415 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2417 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2420 LOGD("ret : 0x%x", ret);
2426 int recorder_unset_interrupted_cb(recorder_h recorder)
2428 int ret = RECORDER_ERROR_NONE;
2429 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2430 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2432 if (!pc || !pc->cb_info) {
2433 LOGE("NULL handle");
2434 return RECORDER_ERROR_INVALID_PARAMETER;
2439 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2441 if (ret == RECORDER_ERROR_NONE) {
2442 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2444 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2445 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2447 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2450 LOGD("ret : 0x%x", ret);
2456 int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
2458 int ret = RECORDER_ERROR_NONE;
2459 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2460 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
2462 if (!pc || !pc->cb_info || callback == NULL) {
2463 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2464 return RECORDER_ERROR_INVALID_PARAMETER;
2467 LOGD("Enter, handle :%td", pc->remote_handle);
2469 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2471 if (ret == RECORDER_ERROR_NONE) {
2472 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2474 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
2475 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
2477 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2480 LOGD("ret : 0x%x", ret);
2486 int recorder_unset_interrupt_started_cb(recorder_h recorder)
2488 int ret = RECORDER_ERROR_NONE;
2489 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
2490 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2492 if (!pc || !pc->cb_info) {
2493 LOGE("NULL handle");
2494 return RECORDER_ERROR_INVALID_PARAMETER;
2499 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2501 if (ret == RECORDER_ERROR_NONE) {
2502 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2504 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2505 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2507 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2510 LOGD("ret : 0x%x", ret);
2516 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2518 int ret = RECORDER_ERROR_NONE;
2519 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2520 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2522 if (!pc || !pc->cb_info || callback == NULL) {
2523 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2524 return RECORDER_ERROR_INVALID_PARAMETER;
2527 LOGD("Enter, handle :%td", pc->remote_handle);
2529 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2531 if (ret == RECORDER_ERROR_NONE) {
2532 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2534 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2535 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2537 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2540 LOGD("ret : 0x%x", ret);
2546 int recorder_unset_audio_stream_cb(recorder_h recorder)
2548 int ret = RECORDER_ERROR_NONE;
2549 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2550 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2552 if (!pc || !pc->cb_info) {
2553 LOGE("NULL handle");
2554 return RECORDER_ERROR_INVALID_PARAMETER;
2559 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2561 if (ret == RECORDER_ERROR_NONE) {
2562 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2564 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2565 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2567 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2570 LOGD("ret : 0x%x", ret);
2576 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2578 int ret = RECORDER_ERROR_NONE;
2579 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2580 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2582 if (!pc || !pc->cb_info || !callback) {
2583 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2584 return RECORDER_ERROR_INVALID_PARAMETER;
2587 LOGD("Enter, handle :%td", pc->remote_handle);
2589 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2591 if (ret == RECORDER_ERROR_NONE) {
2592 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2594 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2595 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2597 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2600 LOGD("ret : 0x%x", ret);
2606 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2608 int ret = RECORDER_ERROR_NONE;
2609 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2610 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2612 if (!pc || !pc->cb_info) {
2613 LOGE("NULL handle");
2614 return RECORDER_ERROR_INVALID_PARAMETER;
2619 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2621 if (ret == RECORDER_ERROR_NONE) {
2622 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2624 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2625 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2627 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2630 LOGD("ret : 0x%x", ret);
2636 int recorder_set_video_encode_decision_cb(recorder_h recorder, recorder_video_encode_decision_cb callback, void *user_data)
2638 int ret = RECORDER_ERROR_NONE;
2639 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2640 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODE_DECISION_CB;
2642 if (!pc || !pc->cb_info || !callback) {
2643 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2644 return RECORDER_ERROR_INVALID_PARAMETER;
2647 LOGD("Enter, handle :%td", pc->remote_handle);
2649 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2651 if (ret == RECORDER_ERROR_NONE) {
2652 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION]);
2654 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = callback;
2655 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = user_data;
2657 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION]);
2660 LOGD("ret : 0x%x", ret);
2666 int recorder_unset_video_encode_decision_cb(recorder_h recorder)
2668 int ret = RECORDER_ERROR_NONE;
2669 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_VIDEO_ENCODE_DECISION_CB;
2670 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2672 if (!pc || !pc->cb_info) {
2673 LOGE("NULL handle");
2674 return RECORDER_ERROR_INVALID_PARAMETER;
2679 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2681 if (ret == RECORDER_ERROR_NONE) {
2682 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION]);
2684 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = NULL;
2685 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION] = NULL;
2687 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_VIDEO_ENCODE_DECISION]);
2690 LOGD("ret : 0x%x", ret);
2696 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2698 int ret = RECORDER_ERROR_NONE;
2699 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2700 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2702 if (!pc || !pc->cb_info || callback == NULL) {
2703 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2704 return RECORDER_ERROR_INVALID_PARAMETER;
2707 LOGD("Enter, handle :%td", pc->remote_handle);
2709 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2711 if (ret == RECORDER_ERROR_NONE) {
2712 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2714 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2715 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2717 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2720 LOGD("ret : 0x%x", ret);
2726 int recorder_unset_error_cb(recorder_h recorder)
2728 int ret = RECORDER_ERROR_NONE;
2729 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2730 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2732 if (!pc || !pc->cb_info) {
2733 LOGE("NULL handle");
2734 return RECORDER_ERROR_INVALID_PARAMETER;
2739 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2741 if (ret == RECORDER_ERROR_NONE) {
2742 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2744 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2745 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2747 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2750 LOGD("ret : 0x%x", ret);
2756 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2758 int ret = RECORDER_ERROR_NONE;
2759 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2760 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2762 if (!pc || !pc->cb_info || callback == NULL) {
2763 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2764 return RECORDER_ERROR_INVALID_PARAMETER;
2767 LOGD("Enter, handle :%td", pc->remote_handle);
2769 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2771 if (ret == RECORDER_ERROR_NONE) {
2772 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2774 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2775 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2777 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2780 LOGD("ret : 0x%x", ret);
2786 int recorder_unset_recording_status_cb(recorder_h recorder)
2788 int ret = RECORDER_ERROR_NONE;
2789 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2790 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2792 if (!pc || !pc->cb_info) {
2793 LOGE("NULL handle");
2794 return RECORDER_ERROR_INVALID_PARAMETER;
2799 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2801 if (ret == RECORDER_ERROR_NONE) {
2802 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2804 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2805 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2807 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2810 LOGD("ret : 0x%x", ret);
2816 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2818 int ret = RECORDER_ERROR_NONE;
2819 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2820 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2822 if (!pc || !pc->cb_info || callback == NULL) {
2823 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2824 return RECORDER_ERROR_INVALID_PARAMETER;
2827 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2829 if (ret == RECORDER_ERROR_NONE) {
2830 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2832 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2833 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2835 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2838 LOGD("ret : 0x%x", ret);
2844 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2846 int ret = RECORDER_ERROR_NONE;
2847 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2848 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2850 if (!pc || !pc->cb_info) {
2851 LOGE("NULL handle");
2852 return RECORDER_ERROR_INVALID_PARAMETER;
2857 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2859 if (ret == RECORDER_ERROR_NONE) {
2860 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2862 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2863 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2865 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2868 LOGD("ret : 0x%x", ret);
2874 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2876 int ret = RECORDER_ERROR_NONE;
2877 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2878 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2880 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2881 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2882 return RECORDER_ERROR_INVALID_PARAMETER;
2885 LOGD("Enter, handle :%td", pc->remote_handle);
2887 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2888 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2890 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2892 LOGD("ret : 0x%x", ret);
2898 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2900 int ret = RECORDER_ERROR_NONE;
2901 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2902 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2903 recorder_msg_param param;
2905 if (!pc || !pc->cb_info) {
2906 LOGE("NULL handle");
2907 return RECORDER_ERROR_INVALID_PARAMETER;
2912 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2914 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2916 LOGD("ret : 0x%x", ret);
2922 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2924 int ret = RECORDER_ERROR_NONE;
2925 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2926 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2927 recorder_msg_param param;
2929 if (!pc || !pc->cb_info) {
2930 LOGE("NULL handle");
2931 return RECORDER_ERROR_INVALID_PARAMETER;
2936 RECORDER_MSG_PARAM_SET(param, INT, second);
2938 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2940 LOGD("ret : 0x%x", ret);
2946 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2948 int ret = RECORDER_ERROR_NONE;
2949 int set_device = (int)device;
2950 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2951 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2952 recorder_msg_param param;
2954 if (!pc || !pc->cb_info) {
2955 LOGE("NULL handle");
2956 return RECORDER_ERROR_INVALID_PARAMETER;
2961 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2963 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2965 LOGD("ret : 0x%x", ret);
2971 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2973 int ret = RECORDER_ERROR_NONE;
2974 int set_codec = (int)codec;
2975 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2976 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2977 recorder_msg_param param;
2979 if (!pc || !pc->cb_info) {
2980 LOGE("NULL handle");
2981 return RECORDER_ERROR_INVALID_PARAMETER;
2986 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2988 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2990 LOGD("ret : 0x%x", ret);
2996 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2998 int ret = RECORDER_ERROR_NONE;
2999 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
3000 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3002 if (!pc || !pc->cb_info) {
3003 LOGE("NULL handle");
3004 return RECORDER_ERROR_INVALID_PARAMETER;
3007 if (codec == NULL) {
3008 LOGE("codec is NULL");
3009 return RECORDER_ERROR_INVALID_PARAMETER;
3014 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3016 if (ret == RECORDER_ERROR_NONE)
3017 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
3019 LOGD("ret : 0x%x, codec %d", ret, *codec);
3025 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
3027 int ret = RECORDER_ERROR_NONE;
3028 int set_codec = (int)codec;
3029 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
3030 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3031 recorder_msg_param param;
3033 if (!pc || !pc->cb_info) {
3034 LOGE("NULL handle");
3035 return RECORDER_ERROR_INVALID_PARAMETER;
3040 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
3042 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3044 LOGD("ret : 0x%x", ret);
3050 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
3052 int ret = RECORDER_ERROR_NONE;
3053 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
3054 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3056 if (!pc || !pc->cb_info) {
3057 LOGE("NULL handle");
3058 return RECORDER_ERROR_INVALID_PARAMETER;
3061 if (codec == NULL) {
3062 LOGE("codec is NULL");
3063 return RECORDER_ERROR_INVALID_PARAMETER;
3068 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3070 if (ret == RECORDER_ERROR_NONE)
3071 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
3073 LOGD("ret : 0x%x, codec %d", ret, *codec);
3079 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
3081 int ret = RECORDER_ERROR_NONE;
3082 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
3083 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3084 recorder_msg_param param;
3086 if (!pc || !pc->cb_info) {
3087 LOGE("NULL handle");
3088 return RECORDER_ERROR_INVALID_PARAMETER;
3091 LOGD("ENTER, samplerate : %d", samplerate);
3093 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
3095 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3097 LOGD("ret : 0x%x", ret);
3103 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
3105 int ret = RECORDER_ERROR_NONE;
3106 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
3107 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3108 recorder_msg_param param;
3110 if (!pc || !pc->cb_info) {
3111 LOGE("NULL handle");
3112 return RECORDER_ERROR_INVALID_PARAMETER;
3117 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
3119 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3121 LOGD("ret : 0x%x", ret);
3127 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
3129 int ret = RECORDER_ERROR_NONE;
3130 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
3131 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3132 recorder_msg_param param;
3134 if (!pc || !pc->cb_info) {
3135 LOGE("NULL handle");
3136 return RECORDER_ERROR_INVALID_PARAMETER;
3141 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
3143 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3145 LOGD("ret : 0x%x", ret);
3151 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
3153 int ret = RECORDER_ERROR_NONE;
3154 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
3155 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3157 if (!pc || !pc->cb_info) {
3158 LOGE("NULL handle");
3159 return RECORDER_ERROR_INVALID_PARAMETER;
3162 if (kbyte == NULL) {
3163 LOGE("NULL pointer kbyte");
3164 return RECORDER_ERROR_INVALID_PARAMETER;
3169 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3171 if (ret == RECORDER_ERROR_NONE)
3172 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
3174 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
3180 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
3182 int ret = RECORDER_ERROR_NONE;
3183 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
3184 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3186 if (!pc || !pc->cb_info) {
3187 LOGE("NULL handle");
3188 return RECORDER_ERROR_INVALID_PARAMETER;
3191 if (second == NULL) {
3192 LOGE("NULL pointer second");
3193 return RECORDER_ERROR_INVALID_PARAMETER;
3198 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3200 if (ret == RECORDER_ERROR_NONE)
3201 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
3203 LOGD("ret : 0x%x, %d second", ret, *second);
3209 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
3211 int ret = RECORDER_ERROR_NONE;
3212 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
3213 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3215 if (!pc || !pc->cb_info) {
3216 LOGE("NULL handle");
3217 return RECORDER_ERROR_INVALID_PARAMETER;
3220 if (device == NULL) {
3221 LOGE("NULL pointer device");
3222 return RECORDER_ERROR_INVALID_PARAMETER;
3227 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3229 if (ret == RECORDER_ERROR_NONE)
3230 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
3232 LOGD("ret : 0x%x, device %d", ret, *device);
3238 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
3240 int ret = RECORDER_ERROR_NONE;
3241 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
3242 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3244 if (!pc || !pc->cb_info) {
3245 LOGE("NULL handle");
3246 return RECORDER_ERROR_INVALID_PARAMETER;
3249 if (samplerate == NULL) {
3250 LOGE("NULL pointer handle");
3251 return RECORDER_ERROR_INVALID_PARAMETER;
3256 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3258 if (ret == RECORDER_ERROR_NONE)
3259 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3261 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3267 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3269 int ret = RECORDER_ERROR_NONE;
3270 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3271 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3273 if (!pc || !pc->cb_info) {
3274 LOGE("NULL handle");
3275 return RECORDER_ERROR_INVALID_PARAMETER;
3278 if (bitrate == NULL) {
3279 LOGE("NULL pointer");
3280 return RECORDER_ERROR_INVALID_PARAMETER;
3285 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3287 if (ret == RECORDER_ERROR_NONE)
3288 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3290 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3296 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3298 int ret = RECORDER_ERROR_NONE;
3299 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3300 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3302 if (!pc || !pc->cb_info) {
3303 LOGE("NULL handle");
3304 return RECORDER_ERROR_INVALID_PARAMETER;
3307 if (bitrate == NULL) {
3308 LOGE("NULL pointer");
3309 return RECORDER_ERROR_INVALID_PARAMETER;
3314 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3316 if (ret == RECORDER_ERROR_NONE)
3317 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3319 LOGD("ret : 0x%x", ret);
3325 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3327 int ret = RECORDER_ERROR_NONE;
3328 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3329 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3331 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3332 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3333 return RECORDER_ERROR_INVALID_PARAMETER;
3336 LOGD("Enter, handle :%td", pc->remote_handle);
3338 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3339 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3341 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3343 LOGD("ret : 0x%x", ret);
3349 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3351 int ret = RECORDER_ERROR_NONE;
3352 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3353 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3355 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3356 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3357 return RECORDER_ERROR_INVALID_PARAMETER;
3360 LOGD("Enter, handle :%td", pc->remote_handle);
3362 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3363 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3365 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3367 LOGD("ret : 0x%x", ret);
3373 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3375 int ret = RECORDER_ERROR_NONE;
3376 int set_enable = (int)enable;
3377 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3378 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3379 recorder_msg_param param;
3381 if (!pc || !pc->cb_info) {
3382 LOGE("NULL handle");
3383 return RECORDER_ERROR_INVALID_PARAMETER;
3388 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3390 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3392 LOGD("ret : 0x%x", ret);
3398 bool recorder_attr_is_muted(recorder_h recorder)
3401 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3402 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3404 if (!pc || !pc->cb_info) {
3405 LOGE("NULL handle");
3411 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3413 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3416 LOGD("ret : %d", ret);
3422 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3424 int ret = RECORDER_ERROR_NONE;
3425 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3426 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3427 recorder_msg_param param;
3429 if (!pc || !pc->cb_info) {
3430 LOGE("NULL handle");
3431 return RECORDER_ERROR_INVALID_PARAMETER;
3434 LOGD("ENTER - %.20lf", rate);
3436 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3438 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3440 LOGD("ret : 0x%x", ret);
3446 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3448 int ret = RECORDER_ERROR_NONE;
3449 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3450 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3452 if (!pc || !pc->cb_info) {
3453 LOGE("NULL handle");
3454 return RECORDER_ERROR_INVALID_PARAMETER;
3458 LOGE("rate is NULL");
3459 return RECORDER_ERROR_INVALID_PARAMETER;
3464 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3465 if (ret == RECORDER_ERROR_NONE)
3466 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3468 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3474 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3476 int ret = RECORDER_ERROR_NONE;
3477 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3478 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3479 recorder_msg_param param;
3481 if (!pc || !pc->cb_info) {
3482 LOGE("NULL handle");
3483 return RECORDER_ERROR_INVALID_PARAMETER;
3488 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3490 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3492 LOGD("ret : 0x%x", ret);
3498 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3500 int ret = RECORDER_ERROR_NONE;
3501 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3502 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3504 if (!pc || !pc->cb_info) {
3505 LOGE("NULL handle");
3506 return RECORDER_ERROR_INVALID_PARAMETER;
3509 if (channel_count == NULL) {
3510 LOGE("channel_count is NULL");
3511 return RECORDER_ERROR_INVALID_PARAMETER;
3516 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3518 if (ret == RECORDER_ERROR_NONE)
3519 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3521 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3527 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3529 int ret = RECORDER_ERROR_NONE;
3530 int set_orientation = (int)orientation;
3531 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3532 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3533 recorder_msg_param param;
3535 if (!pc || !pc->cb_info) {
3536 LOGE("NULL handle");
3537 return RECORDER_ERROR_INVALID_PARAMETER;
3542 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3544 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3546 LOGD("ret : 0x%x", ret);
3552 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3554 int ret = RECORDER_ERROR_NONE;
3555 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3556 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3558 if (!pc || !pc->cb_info) {
3559 LOGE("NULL handle");
3560 return RECORDER_ERROR_INVALID_PARAMETER;
3563 if (orientation == NULL) {
3564 LOGE("orientation is NULL");
3565 return RECORDER_ERROR_INVALID_PARAMETER;
3570 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3572 if (ret == RECORDER_ERROR_NONE)
3573 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3575 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3581 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3583 int ret = RECORDER_ERROR_NONE;
3585 int module_index = -1;
3586 int get_device_state = 0;
3587 char *send_msg = NULL;
3588 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3591 LOGE("NULL pointer");
3592 return RECORDER_ERROR_INVALID_PARAMETER;
3595 LOGD("Enter - type %d", type);
3597 sock_fd = muse_client_new();
3600 LOGE("muse_client_new failed - returned fd %d", sock_fd);
3601 ret = RECORDER_ERROR_INVALID_OPERATION;
3602 goto _GET_DEVICE_STATE_EXIT;
3606 if (muse_client_get_module_index(MODULE_NAME, &module_index) != MM_ERROR_NONE) {
3607 LOGE("muse client get module index failed");
3608 ret = RECORDER_ERROR_INVALID_OPERATION;
3609 goto _GET_DEVICE_STATE_EXIT;
3612 send_msg = muse_core_msg_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3613 MUSE_TYPE_INT, "module", module_index,
3614 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3619 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3620 goto _GET_DEVICE_STATE_EXIT;
3624 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3626 ret = muse_core_msg_send(sock_fd, send_msg);
3628 muse_core_msg_free(send_msg);
3633 LOGE("send msg failed %d", errno);
3634 ret = RECORDER_ERROR_INVALID_OPERATION;
3635 goto _GET_DEVICE_STATE_EXIT;
3639 ret = muse_core_msg_recv(sock_fd, recv_msg, MUSE_RECORDER_MSG_MAX_LENGTH);
3642 LOGE("recv msg failed %d", errno);
3643 ret = RECORDER_ERROR_INVALID_OPERATION;
3644 goto _GET_DEVICE_STATE_EXIT;
3648 if (!muse_recorder_msg_get(ret, recv_msg)) {
3650 LOGE("failed to get return value from msg [%s]", recv_msg);
3651 ret = RECORDER_ERROR_INVALID_OPERATION;
3652 goto _GET_DEVICE_STATE_EXIT;
3656 if (ret == RECORDER_ERROR_NONE) {
3657 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3658 *state = (recorder_device_state_e)get_device_state;
3659 LOGD("device type %d state %d", type, *state);
3661 LOGE("failed to get device state from msg [%s]", recv_msg);
3662 ret = RECORDER_ERROR_INVALID_OPERATION;
3665 LOGE("failed 0x%x", ret);
3668 _GET_DEVICE_STATE_EXIT:
3670 muse_client_close(sock_fd);
3678 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3680 int ret = RECORDER_ERROR_NONE;
3681 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3682 recorder_cb_info *info = NULL;
3684 if (!callback || !cb_id) {
3685 LOGE("invalid pointer %p %p", callback, cb_id);
3686 return RECORDER_ERROR_INVALID_PARAMETER;
3689 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3691 /* check recorder support */
3692 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3693 if (ret != RECORDER_ERROR_NONE) {
3694 LOGE("get device state failed");
3695 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3699 info = g_new0(recorder_cb_info, 1);
3701 LOGE("info failed");
3702 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3706 info->id = ++g_rec_dev_state_changed_cb_id;
3707 info->callback = (void *)callback;
3708 info->user_data = user_data;
3712 /* subscribe dbus signal for camera state change */
3713 if (!g_rec_dev_state_changed_cb_conn) {
3714 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3715 if (!g_rec_dev_state_changed_cb_conn) {
3716 LOGE("failed to get gdbus connection");
3717 ret = RECORDER_ERROR_INVALID_OPERATION;
3721 LOGD("subscribe signal %s - %s - %s",
3722 MM_CAMCORDER_DBUS_OBJECT,
3723 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3724 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3726 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3727 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3728 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3729 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3730 LOGE("failed to get gdbus connection");
3731 ret = RECORDER_ERROR_INVALID_OPERATION;
3735 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3738 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3740 LOGD("callback id %d", info->id);
3743 if (ret != RECORDER_ERROR_NONE) {
3750 if (g_rec_dev_state_changed_cb_conn) {
3751 g_object_unref(g_rec_dev_state_changed_cb_conn);
3752 g_rec_dev_state_changed_cb_conn = NULL;
3757 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3763 int recorder_remove_device_state_changed_cb(int cb_id)
3765 int ret = RECORDER_ERROR_NONE;
3766 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3767 GList *tmp_list = NULL;
3768 recorder_cb_info *info = NULL;
3770 /* check recorder support */
3771 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3772 if (ret != RECORDER_ERROR_NONE) {
3773 LOGE("get device state failed");
3777 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3779 if (!g_rec_dev_state_changed_cb_list) {
3780 LOGE("there is no callback info");
3781 ret = RECORDER_ERROR_INVALID_OPERATION;
3785 tmp_list = g_rec_dev_state_changed_cb_list;
3788 info = tmp_list->data;
3789 tmp_list = tmp_list->next;
3796 if (info->id == cb_id) {
3797 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3802 if (!g_rec_dev_state_changed_cb_list) {
3803 /* no remained callback */
3804 if (g_rec_dev_state_changed_cb_conn) {
3805 /* unsubscribe signal */
3806 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3807 g_rec_dev_state_changed_cb_subscribe_id = 0;
3809 /* unref connection */
3810 g_object_unref(g_rec_dev_state_changed_cb_conn);
3811 g_rec_dev_state_changed_cb_conn = NULL;
3815 LOGD("id %d callback removed", cb_id);
3816 ret = RECORDER_ERROR_NONE;
3822 LOGE("id %d callback not found", cb_id);
3823 ret = RECORDER_ERROR_INVALID_PARAMETER;
3826 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);