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.
20 #include <camera_internal.h>
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
25 #include <storage-internal.h>
26 #include <muse_recorder.h>
27 #include <muse_recorder_msg.h>
28 #include <muse_core.h>
29 #include <muse_client.h>
30 #include <recorder_private.h>
33 #include <tzplatform_config.h>
38 #define LOG_TAG "TIZEN_N_RECORDER"
40 /* for device changed callback */
41 static GMutex g_rec_dev_state_changed_cb_lock;
42 static GList *g_rec_dev_state_changed_cb_list;
43 static int g_rec_dev_state_changed_cb_id;
44 static GDBusConnection *g_rec_dev_state_changed_cb_conn;
45 static guint g_rec_dev_state_changed_cb_subscribe_id;
49 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
52 api < 0 || api >= MUSE_RECORDER_API_MAX) {
53 LOGE("invalid param %p %d", cb_info, api);
57 g_mutex_lock(&(cb_info->api_mutex[api]));
58 cb_info->api_waiting[api] += value;
59 g_mutex_unlock(&(cb_info->api_mutex[api]));
61 /*LOGD("api %d, value %d, waiting %d",
62 api, value, cb_info->api_waiting[api]);*/
68 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
69 const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
70 const gchar *signal_name, GVariant *param, gpointer user_data)
73 recorder_type_e type = RECORDER_TYPE_AUDIO;
74 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
75 GList *tmp_list = NULL;
76 recorder_cb_info *info = NULL;
78 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
80 if (!g_rec_dev_state_changed_cb_list || !param) {
81 LOGW("no callback or NULL param %p", param);
85 /* get device type and state */
86 g_variant_get(param, "(i)", &value);
89 state = 0x0000ffff & value;
91 LOGD("type %d, state %d", type, state);
93 tmp_list = g_rec_dev_state_changed_cb_list;
96 info = (recorder_cb_info *)tmp_list->data;
100 LOGD("start id[%d] callback", info->id);
101 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
102 LOGD("returned id[%d] callback", info->id);
104 LOGW("NULL callback for id %d", info->id);
108 tmp_list = tmp_list->next;
112 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
118 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
120 tbm_bo tmp_bo = NULL;
121 tbm_bo_handle tmp_bo_handle = {NULL, };
123 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
124 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
125 bufmgr, bo, bo_handle, tbm_key);
129 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
130 if (tmp_bo == NULL) {
131 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
135 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
136 if (tmp_bo_handle.ptr == NULL) {
137 LOGE("bo map failed %p", tmp_bo);
138 tbm_bo_unref(tmp_bo);
143 /* set bo and bo_handle */
145 *bo_handle = tmp_bo_handle;
150 static void _recorder_release_imported_bo(tbm_bo *bo)
152 if (bo == NULL || *bo == NULL) {
164 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
166 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
167 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
171 /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
173 g_mutex_lock(&cb_info->user_cb_mutex[event]);
175 if (cb_info->user_cb[event] == NULL) {
176 if (event != MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM &&
177 event != MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM) {
178 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
179 LOGW("NULL callback for event %d, return here", event);
182 LOGW("NULL callback for event %d, NOT return here", event);
187 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
193 muse_recorder_msg_get(previous, recv_msg);
194 muse_recorder_msg_get(current, recv_msg);
195 muse_recorder_msg_get(by_policy, recv_msg);
197 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
198 (recorder_state_e)current,
200 cb_info->user_data[event]);
203 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
207 muse_recorder_msg_get(type, recv_msg);
209 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
210 cb_info->user_data[event]);
213 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
215 int64_t cb_elapsed_time = 0;
216 int64_t cb_file_size = 0;
218 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
219 muse_recorder_msg_get(cb_file_size, recv_msg);
221 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
222 (unsigned long long)cb_file_size,
223 cb_info->user_data[event]);
226 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
232 muse_recorder_msg_get(policy, recv_msg);
233 muse_recorder_msg_get(previous, recv_msg);
234 muse_recorder_msg_get(current, recv_msg);
236 if (policy == RECORDER_POLICY_SOUND)
237 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
238 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
239 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
240 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
241 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
243 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
244 (recorder_state_e)previous,
245 (recorder_state_e)current,
246 cb_info->user_data[event]);
249 case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
254 muse_recorder_msg_get(policy, recv_msg);
255 muse_recorder_msg_get(state, recv_msg);
257 LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
259 if (policy == RECORDER_POLICY_SOUND)
260 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
261 else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
262 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
263 else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
264 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
266 ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
267 (recorder_state_e)state, cb_info->user_data[event]);
270 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
278 tbm_bo_handle bo_handle = {.ptr = NULL};
279 char *send_msg = NULL;
281 muse_recorder_msg_get(tbm_key, recv_msg);
287 if (cb_info->user_cb[event]) {
288 if (_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
289 muse_recorder_msg_get(size, recv_msg);
290 muse_recorder_msg_get(format, recv_msg);
291 muse_recorder_msg_get(channel, recv_msg);
292 muse_recorder_msg_get(timestamp, recv_msg);
294 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
295 size, (audio_sample_type_e)format, channel,
296 (unsigned int)timestamp, cb_info->user_data[event]);
298 /* release imported bo */
299 _recorder_release_imported_bo(&bo);
301 LOGE("tbm key %d import failed", tbm_key);
306 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
307 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
309 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
310 LOGE("sending message failed");
312 muse_core_msg_free(send_msg);
315 case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
322 tbm_bo_handle bo_handle = {.ptr = NULL};
323 char *send_msg = NULL;
325 muse_recorder_msg_get(tbm_key, recv_msg);
331 if (cb_info->user_cb[event]) {
332 if (_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
333 muse_recorder_msg_get(size, recv_msg);
334 muse_recorder_msg_get(offset, recv_msg);
336 ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
337 size, (unsigned long long)offset, cb_info->user_data[event]);
339 /* release imported bo */
340 _recorder_release_imported_bo(&bo);
342 LOGE("tbm key %d import failed", tbm_key);
347 send_msg = muse_core_msg_new(MUSE_RECORDER_API_RETURN_BUFFER,
348 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
350 if (muse_core_msg_send(cb_info->fd, send_msg) <= 0)
351 LOGE("sending message failed");
353 muse_core_msg_free(send_msg);
356 LOGE("failed to create send msg for key %d", tbm_key);
361 case MUSE_RECORDER_EVENT_TYPE_ERROR:
364 int current_state = 0;
366 muse_recorder_msg_get(error, recv_msg);
367 muse_recorder_msg_get(current_state, recv_msg);
369 if (error == RECORDER_ERROR_SOUND_POLICY)
370 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
371 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
372 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
373 else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
374 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
376 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
377 (recorder_state_e)current_state,
378 cb_info->user_data[event]);
382 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
386 muse_recorder_msg_get(codec, recv_msg);
388 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
389 cb_info->user_cb[event] = NULL;
390 cb_info->user_data[event] = NULL;
391 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
395 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
399 muse_recorder_msg_get(format, recv_msg);
401 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
402 cb_info->user_cb[event] = NULL;
403 cb_info->user_data[event] = NULL;
404 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
408 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
412 muse_recorder_msg_get(codec, recv_msg);
414 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
415 cb_info->user_cb[event] = NULL;
416 cb_info->user_data[event] = NULL;
417 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
421 default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
426 muse_recorder_msg_get(width, recv_msg);
427 muse_recorder_msg_get(height, recv_msg);
429 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
430 cb_info->user_cb[event] = NULL;
431 cb_info->user_data[event] = NULL;
432 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
438 g_mutex_unlock(&cb_info->user_cb_mutex[event]);
444 static bool _recorder_idle_event_callback(void *data)
446 recorder_cb_info_s *cb_info = NULL;
447 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
449 if (rec_idle_event == NULL) {
450 LOGE("rec_idle_event is NULL");
455 g_mutex_lock(&rec_idle_event->event_mutex);
457 cb_info = rec_idle_event->cb_info;
458 if (cb_info == NULL) {
459 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
460 goto IDLE_EVENT_CALLBACK_DONE;
463 /* remove event from list */
464 g_mutex_lock(&cb_info->idle_event_mutex);
466 if (cb_info->idle_event_list)
467 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
469 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
470 g_mutex_unlock(&cb_info->idle_event_mutex);
473 _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
475 /* send signal for waiting thread */
476 g_cond_signal(&cb_info->idle_event_cond);
478 IDLE_EVENT_CALLBACK_DONE:
479 /* unlock and release event */
480 g_mutex_unlock(&rec_idle_event->event_mutex);
481 g_mutex_clear(&rec_idle_event->event_mutex);
483 g_free(rec_idle_event);
484 rec_idle_event = NULL;
490 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
492 recorder_idle_event_s *rec_idle_event = NULL;
496 if (cb_info == NULL) {
497 LOGE("cb_info is NULL");
501 g_mutex_lock(&cb_info->idle_event_mutex);
503 if (cb_info->idle_event_list == NULL) {
506 list = cb_info->idle_event_list;
509 rec_idle_event = list->data;
510 list = g_list_next(list);
512 if (!rec_idle_event) {
513 LOGW("The event is NULL");
517 if (g_idle_remove_by_data(rec_idle_event)) {
518 LOGW("remove idle event %p done", rec_idle_event);
520 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
522 g_mutex_clear(&rec_idle_event->event_mutex);
523 g_free(rec_idle_event);
524 rec_idle_event = NULL;
529 LOGW("remove idle event %p failed", rec_idle_event);
531 if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
532 LOGW("lock failed, %p event is calling now", rec_idle_event);
534 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
536 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
537 LOGW("signal received");
544 LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
545 rec_idle_event, rec_idle_event->event);
547 rec_idle_event->cb_info = NULL;
549 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
551 g_mutex_unlock(&rec_idle_event->event_mutex);
554 g_list_free(cb_info->idle_event_list);
555 cb_info->idle_event_list = NULL;
558 g_mutex_unlock(&cb_info->idle_event_mutex);
564 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
566 recorder_message_s *rec_msg = NULL;
567 recorder_msg_handler_info_s *msg_handler_info = NULL;
569 if (!cb_info || !msg) {
570 LOGE("NULL pointer %p %p", cb_info, msg);
574 rec_msg = g_new0(recorder_message_s, 1);
576 LOGE("failed to alloc rec_msg for [%s]", msg);
581 rec_msg->event = event;
582 rec_msg->event_class = event_class;
584 strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
586 /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
588 if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
589 msg_handler_info = &cb_info->audio_stream_cb_info;
590 else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
591 msg_handler_info = &cb_info->muxed_stream_cb_info;
593 msg_handler_info = &cb_info->msg_handler_info;
595 g_mutex_lock(&msg_handler_info->mutex);
596 g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
597 g_cond_signal(&msg_handler_info->cond);
598 g_mutex_unlock(&msg_handler_info->mutex);
606 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
608 if (!cb_info || !msg) {
609 LOGE("NULL pointer %p %p", cb_info, msg);
614 case MUSE_RECORDER_API_GET_STATE:
617 muse_recorder_msg_get(get_state, msg);
618 cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
621 case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
625 muse_recorder_msg_get(get_width, msg);
626 muse_recorder_msg_get(get_height, msg);
627 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
628 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
631 case MUSE_RECORDER_API_GET_FILE_FORMAT:
634 muse_recorder_msg_get(get_format, msg);
635 cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
638 case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
641 muse_recorder_msg_get(get_codec, msg);
642 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
645 case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
648 muse_recorder_msg_get(get_codec, msg);
649 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
652 case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
655 muse_recorder_msg_get(get_kbyte, msg);
656 cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
659 case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
662 muse_recorder_msg_get(get_second, msg);
663 cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
666 case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
669 muse_recorder_msg_get(get_device, msg);
670 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
673 case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
675 int get_samplerate = 0;
676 muse_recorder_msg_get(get_samplerate, msg);
677 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
680 case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
683 muse_recorder_msg_get(get_bitrate, msg);
684 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
687 case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
690 muse_recorder_msg_get(get_bitrate, msg);
691 cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
694 case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
697 muse_recorder_msg_get_double(get_rate, msg);
698 cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
701 case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
703 int get_channel_count = 0;
704 muse_recorder_msg_get(get_channel_count, msg);
705 cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
708 case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
710 int get_orientation = 0;
711 muse_recorder_msg_get(get_orientation, msg);
712 cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
715 case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
717 double get_level = 0.0;
718 muse_recorder_msg_get_double(get_level, msg);
719 cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
722 case MUSE_RECORDER_API_GET_FILENAME:
724 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
725 muse_recorder_msg_get_string(get_filename, msg);
726 if (cb_info->get_filename) {
727 free(cb_info->get_filename);
728 cb_info->get_filename = NULL;
730 cb_info->get_filename = strdup(get_filename);
741 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
743 int ret = RECORDER_ERROR_NONE;
747 int event_class = -1;
749 if (!cb_info || !msg) {
750 LOGE("invalid ptr %p %p", cb_info, msg);
754 /*LOGD("msg [%s]", msg);*/
756 if (!muse_recorder_msg_get(api, msg)) {
757 LOGE("failed to get recorder api");
761 if (api == MUSE_RECORDER_CB_EVENT) {
762 if (!muse_recorder_msg_get(event, msg) ||
763 !muse_recorder_msg_get(event_class, msg)) {
764 LOGE("failed to get event or event_class [%s]", msg);
768 if (!muse_recorder_msg_get(api_class, msg)) {
769 LOGE("failed to get api_class [%s]", msg);
774 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
775 if (api >= MUSE_RECORDER_API_MAX) {
776 LOGE("invalid api %d", api);
780 if (!muse_recorder_msg_get(ret, msg)) {
781 LOGE("failed to get recorder ret");
785 g_mutex_lock(&cb_info->api_mutex[api]);
787 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
788 g_atomic_int_set(&cb_info->msg_recv_running, 0);
789 LOGD("get device state done. close client cb handler");
792 case MUSE_RECORDER_API_CREATE:
793 if (ret != RECORDER_ERROR_NONE) {
794 g_atomic_int_set(&cb_info->msg_recv_running, 0);
795 LOGE("create error 0x%x. closing..", ret);
798 case MUSE_RECORDER_API_DESTROY:
799 if (ret == RECORDER_ERROR_NONE) {
800 g_atomic_int_set(&cb_info->msg_recv_running, 0);
801 LOGD("destroy done. closing..");
805 __recorder_get_api_operation(api, cb_info, msg);
810 if (cb_info->api_waiting[api] > 0) {
811 cb_info->api_ret[api] = ret;
812 cb_info->api_activating[api] = 1;
814 g_cond_signal(&cb_info->api_cond[api]);
816 LOGE("no waiting for api [%d]", api);
819 g_mutex_unlock(&cb_info->api_mutex[api]);
820 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
821 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
823 LOGW("unknown recorder api %d and api_class %d", api, api_class);
830 static void *_recorder_msg_handler_func(gpointer data)
834 recorder_message_s *rec_msg = NULL;
835 recorder_idle_event_s *rec_idle_event = NULL;
836 recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
837 recorder_cb_info_s *cb_info = NULL;
839 if (!handler_info || !handler_info->cb_info) {
840 LOGE("NULL handler %p", handler_info);
844 cb_info = (recorder_cb_info_s *)handler_info->cb_info;
845 type = handler_info->type;
847 LOGD("t:%d start", type);
849 g_mutex_lock(&handler_info->mutex);
851 while (g_atomic_int_get(&handler_info->running)) {
852 if (g_queue_is_empty(handler_info->queue)) {
853 /*LOGD("signal wait...");*/
854 g_cond_wait(&handler_info->cond, &handler_info->mutex);
855 /*LOGD("signal received");*/
857 if (g_atomic_int_get(&handler_info->running) == 0) {
858 LOGD("stop event thread");
863 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
864 g_mutex_unlock(&handler_info->mutex);
865 if (rec_msg == NULL) {
866 LOGE("NULL message");
867 g_mutex_lock(&handler_info->mutex);
873 if (api < MUSE_RECORDER_API_MAX) {
876 g_mutex_lock(&cb_info->api_mutex[api]);
878 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
879 if (cb_info->api_waiting[api] > 0) {
880 cb_info->api_ret[api] = ret;
881 cb_info->api_activating[api] = 1;
883 /*LOGD("recorder api %d - return 0x%x", ret);*/
885 g_cond_signal(&cb_info->api_cond[api]);
887 LOGE("no waiting for api [%d]", api);
890 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
893 g_mutex_unlock(&cb_info->api_mutex[api]);
894 } else if (api == MUSE_RECORDER_CB_EVENT) {
895 switch (rec_msg->event_class) {
896 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
897 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
899 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
900 rec_idle_event = g_new0(recorder_idle_event_s, 1);
901 if (rec_idle_event == NULL) {
902 LOGE("event alloc failed");
906 rec_idle_event->event = rec_msg->event;
907 rec_idle_event->cb_info = cb_info;
908 g_mutex_init(&rec_idle_event->event_mutex);
909 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
911 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
913 g_mutex_lock(&cb_info->idle_event_mutex);
914 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
915 g_mutex_unlock(&cb_info->idle_event_mutex);
917 g_idle_add_full(G_PRIORITY_DEFAULT,
918 (GSourceFunc)_recorder_idle_event_callback,
919 (gpointer)rec_idle_event,
923 LOGE("unknown event class %d", rec_msg->event_class);
927 LOGE("unknown api[%d] message", api);
933 g_mutex_lock(&handler_info->mutex);
936 /* remove remained event */
937 while (!g_queue_is_empty(handler_info->queue)) {
938 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
940 LOGD("remove message %p", rec_msg);
944 LOGW("NULL message");
948 g_mutex_unlock(&handler_info->mutex);
956 static void *_recorder_msg_recv_func(gpointer data)
959 int single_length = 0;
960 int remained_length = 0;
961 char *recv_msg = NULL;
962 char *single_msg = NULL;
963 char *remained_msg = NULL;
967 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
969 if (cb_info == NULL) {
970 LOGE("cb_info NULL");
976 single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
977 if (single_msg == NULL) {
978 LOGE("single_msg malloc failed");
979 goto CB_HANDLER_EXIT;
982 recv_msg = cb_info->recv_msg;
984 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
985 recv_length = muse_core_msg_recv(cb_info->fd, recv_msg);
986 if (recv_length <= 0) {
988 cb_info->is_server_connected = FALSE;
989 LOGE("receive msg failed - server disconnected");
994 recv_msg[recv_length] = '\0';
1000 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
1002 /* Need to split the combined entering msgs */
1003 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
1004 if (recv_msg[cur_pos] == '}') {
1005 single_length = cur_pos - prev_pos + 1;
1007 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
1008 /* check remained msg */
1009 if (remained_length > 0) {
1012 strncpy(single_msg, remained_msg, remained_length);
1013 strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
1014 single_msg[remained_length + single_length] = '\0';
1017 remained_msg = NULL;
1019 strncpy(single_msg, recv_msg + prev_pos, single_length);
1020 single_msg[single_length] = '\0';
1021 LOGE("lost msg [%s], skip...", single_msg);
1024 remained_length = 0;
1027 strncpy(single_msg, recv_msg + prev_pos, single_length);
1028 single_msg[single_length] = '\0';
1031 if (single_msg[0] == '{') {
1033 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
1034 __recorder_process_msg(cb_info, single_msg);
1036 LOGE("invalid msg [%s]", single_msg);
1039 LOGE("too long message [len %d] skip...", single_length);
1042 prev_pos = cur_pos + 1;
1046 /* check incompleted message */
1047 if (recv_msg[recv_length - 1] != '}') {
1049 remained_length = recv_length - prev_pos;
1051 LOGW("incompleted message [len %d]", remained_length);
1055 remained_msg = NULL;
1058 remained_msg = (char *)malloc(remained_length + 1);
1060 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
1061 remained_msg[remained_length] = '\0';
1063 LOGE("failed to alloc for remained msg");
1067 remained_length = 0;
1071 LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1073 if (!cb_info->is_server_connected) {
1075 /* send error msg for server disconnection */
1076 char *error_msg = muse_core_msg_new(MUSE_RECORDER_CB_EVENT,
1077 MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1078 MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1082 LOGE("error_msg failed");
1083 goto CB_HANDLER_EXIT;
1086 LOGE("add error msg for service disconnection done");
1088 __recorder_add_msg_to_queue(cb_info,
1089 MUSE_RECORDER_CB_EVENT,
1090 MUSE_RECORDER_EVENT_TYPE_ERROR,
1091 MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1094 muse_core_msg_free(error_msg);
1097 LOGE("add error msg for service disconnection done");
1109 remained_msg = NULL;
1116 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1117 int type, const char *thread_name, recorder_cb_info_s *cb_info)
1119 if (!handler_info || !thread_name || !cb_info) {
1120 LOGE("t:%d NULL %p %p %p",
1121 type, handler_info, thread_name, cb_info);
1127 handler_info->type = type;
1128 handler_info->queue = g_queue_new();
1129 if (handler_info->queue == NULL) {
1130 LOGE("t:%d queue failed", type);
1134 g_mutex_init(&handler_info->mutex);
1135 g_cond_init(&handler_info->cond);
1137 handler_info->cb_info = (void *)cb_info;
1138 g_atomic_int_set(&handler_info->running, 1);
1140 handler_info->thread = g_thread_try_new(thread_name,
1141 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1142 if (handler_info->thread == NULL) {
1144 LOGE("t:%d thread failed", type);
1146 g_mutex_clear(&handler_info->mutex);
1147 g_cond_clear(&handler_info->cond);
1148 g_queue_free(handler_info->queue);
1149 handler_info->queue = NULL;
1155 LOGD("t:%d done", type);
1161 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1165 if (!handler_info) {
1166 LOGE("NULL handler");
1170 if (!handler_info->thread) {
1171 LOGW("thread is not created");
1175 type = handler_info->type;
1177 LOGD("t:%d thread %p", type, handler_info->thread);
1179 g_mutex_lock(&handler_info->mutex);
1180 g_atomic_int_set(&handler_info->running, 0);
1181 g_cond_signal(&handler_info->cond);
1182 g_mutex_unlock(&handler_info->mutex);
1184 g_thread_join(handler_info->thread);
1185 handler_info->thread = NULL;
1187 g_mutex_clear(&handler_info->mutex);
1188 g_cond_clear(&handler_info->cond);
1189 g_queue_free(handler_info->queue);
1190 handler_info->queue = NULL;
1192 LOGD("t:%d done", type);
1198 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1200 recorder_cb_info_s *cb_info = NULL;
1203 g_return_val_if_fail(sockfd > 0, NULL);
1205 cb_info = g_new0(recorder_cb_info_s, 1);
1206 if (cb_info == NULL) {
1207 LOGE("cb_info failed");
1211 cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1213 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1214 g_mutex_init(&cb_info->api_mutex[i]);
1215 g_cond_init(&cb_info->api_cond[i]);
1218 g_mutex_init(&cb_info->idle_event_mutex);
1219 g_cond_init(&cb_info->idle_event_cond);
1221 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1222 g_mutex_init(&cb_info->user_cb_mutex[i]);
1224 /* message handler thread */
1225 if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1226 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1227 LOGE("msg_handler_info failed");
1231 /* message handler thread for audio stream callback */
1232 if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1233 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1234 LOGE("audio_stream_cb_info failed");
1238 /* message handler thread for muxed stream callback */
1239 if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
1240 _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
1241 LOGE("muxed_stream_cb_info failed");
1245 cb_info->fd = sockfd;
1247 /* message receive thread */
1248 g_atomic_int_set(&cb_info->msg_recv_running, 1);
1249 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1250 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1251 if (cb_info->msg_recv_thread == NULL) {
1252 LOGE("message receive thread creation failed");
1256 cb_info->is_server_connected = TRUE;
1262 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1263 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1264 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1266 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1267 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1269 g_mutex_clear(&cb_info->idle_event_mutex);
1270 g_cond_clear(&cb_info->idle_event_cond);
1272 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1273 g_mutex_clear(&cb_info->api_mutex[i]);
1274 g_cond_clear(&cb_info->api_cond[i]);
1285 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1287 int ret = RECORDER_ERROR_NONE;
1290 /*LOGD("Enter api : %d", api);*/
1292 if (!cb_info->is_server_connected) {
1293 LOGE("server is disconnected");
1294 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1297 g_mutex_lock(&(cb_info->api_mutex[api]));
1299 if (cb_info->api_activating[api] == 0) {
1300 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1301 LOGW("wait for api %d", api);
1302 g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1303 ret = cb_info->api_ret[api];
1304 cb_info->api_activating[api] = 0;
1305 LOGW("api %d returned 0x%x", api, ret);
1307 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1308 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1309 ret = cb_info->api_ret[api];
1310 cb_info->api_activating[api] = 0;
1311 /*LOGD("return value : 0x%x", ret);*/
1313 ret = RECORDER_ERROR_INVALID_OPERATION;
1314 LOGE("api %d was TIMED OUT!", api);
1318 ret = cb_info->api_ret[api];
1319 cb_info->api_activating[api] = 0;
1321 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1324 if (ret != RECORDER_ERROR_NONE) {
1325 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1327 if (ret == RECORDER_ERROR_SOUND_POLICY)
1328 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1329 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1330 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1331 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1332 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1335 g_mutex_unlock(&(cb_info->api_mutex[api]));
1341 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
1346 if (!cb_info || !ret) {
1347 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1348 return RECORDER_ERROR_INVALID_PARAMETER;
1351 msg = muse_core_msg_new(api, NULL);
1353 LOGE("msg creation failed: api %d", api);
1354 return RECORDER_ERROR_OUT_OF_MEMORY;
1357 /*LOGD("send msg %s", msg);*/
1359 if (cb_info->is_server_connected) {
1360 __recorder_update_api_waiting(cb_info, api, 1);
1361 send_ret = muse_core_msg_send(cb_info->fd, msg);
1365 LOGE("message send failed");
1366 *ret = RECORDER_ERROR_INVALID_OPERATION;
1368 *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
1371 __recorder_update_api_waiting(cb_info, api, -1);
1373 muse_core_msg_free(msg);
1375 return RECORDER_ERROR_NONE;
1379 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1384 if (!cb_info || !ret || !param) {
1385 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1386 return RECORDER_ERROR_INVALID_PARAMETER;
1389 /*LOGD("type %d, name %s", param->type, param->name);*/
1391 switch (param->type) {
1393 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_INT, NULL);
1395 case MUSE_TYPE_DOUBLE:
1396 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1398 case MUSE_TYPE_STRING:
1399 msg = muse_core_msg_new(api, param->type, param->name, param->value.value_STRING, NULL);
1402 LOGE("unknown type %d", param->type);
1407 LOGE("msg creation failed: api %d, type %d, param name %s",
1408 api, param->type, param->name);
1409 return RECORDER_ERROR_OUT_OF_MEMORY;
1412 /*LOGD("send msg %s", msg);*/
1414 if (cb_info->is_server_connected) {
1415 __recorder_update_api_waiting(cb_info, api, 1);
1417 send_ret = muse_core_msg_send(cb_info->fd, msg);
1421 LOGE("message send failed");
1422 *ret = RECORDER_ERROR_INVALID_OPERATION;
1424 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1427 __recorder_update_api_waiting(cb_info, api, -1);
1429 muse_core_msg_free(msg);
1431 return RECORDER_ERROR_NONE;
1435 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1439 g_return_if_fail(cb_info != NULL);
1441 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1443 g_thread_join(cb_info->msg_recv_thread);
1444 cb_info->msg_recv_thread = NULL;
1446 LOGD("msg_recv thread removed");
1448 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1449 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1450 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1452 for (i = 0 ; i < MUSE_RECORDER_EVENT_TYPE_NUM ; i++)
1453 g_mutex_clear(&cb_info->user_cb_mutex[i]);
1455 g_mutex_clear(&cb_info->idle_event_mutex);
1456 g_cond_clear(&cb_info->idle_event_cond);
1458 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1459 g_mutex_clear(&cb_info->api_mutex[i]);
1460 g_cond_clear(&cb_info->api_cond[i]);
1463 if (cb_info->fd > -1) {
1464 muse_client_close(cb_info->fd);
1468 if (cb_info->bufmgr) {
1469 tbm_bufmgr_deinit(cb_info->bufmgr);
1470 cb_info->bufmgr = NULL;
1472 if (cb_info->get_filename) {
1473 free(cb_info->get_filename);
1474 cb_info->get_filename = NULL;
1484 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1486 char **root_directory = (char **)user_data;
1488 if (root_directory == NULL) {
1489 LOGE("user data is NULL");
1493 LOGD("storage id %d, type %d, state %d, path %s",
1494 storage_id, type, state, path ? path : "NULL");
1496 if (type == STORAGE_TYPE_INTERNAL && path) {
1497 if (*root_directory) {
1498 free(*root_directory);
1499 *root_directory = NULL;
1502 *root_directory = strdup(path);
1503 if (*root_directory) {
1504 LOGD("get root directory %s", *root_directory);
1507 LOGE("strdup %s failed", path);
1514 static int _recorder_client_get_root_directory(char **root_directory)
1516 int ret = STORAGE_ERROR_NONE;
1518 if (root_directory == NULL) {
1519 LOGE("user data is NULL");
1523 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1524 if (ret != STORAGE_ERROR_NONE) {
1525 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1532 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1534 int ret = RECORDER_ERROR_NONE;
1535 int destroy_ret = RECORDER_ERROR_NONE;
1538 char *send_msg = NULL;
1539 char *root_directory = NULL;
1540 intptr_t camera_handle = 0;
1541 intptr_t handle = 0;
1542 tbm_bufmgr bufmgr = NULL;
1543 recorder_cli_s *pc = NULL;
1544 recorder_msg_param param;
1546 LOGD("Enter - type %d", type);
1548 if (recorder == NULL) {
1549 LOGE("NULL pointer for recorder handle");
1550 return RECORDER_ERROR_INVALID_PARAMETER;
1553 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1554 LOGE("NULL pointer for camera handle on video recorder mode");
1555 return RECORDER_ERROR_INVALID_PARAMETER;
1558 bufmgr = tbm_bufmgr_init(-1);
1559 if (bufmgr == NULL) {
1560 LOGE("get tbm bufmgr failed");
1561 return RECORDER_ERROR_INVALID_OPERATION;
1564 pc = g_new0(recorder_cli_s, 1);
1566 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1567 goto _ERR_RECORDER_EXIT;
1570 sock_fd = muse_client_new();
1573 LOGE("muse_client_new failed - returned fd %d", sock_fd);
1574 ret = RECORDER_ERROR_INVALID_OPERATION;
1575 goto _ERR_RECORDER_EXIT;
1579 if (type == MUSE_RECORDER_TYPE_AUDIO) {
1580 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1581 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1582 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1583 MUSE_TYPE_INT, "pid", getpid(),
1586 pc->camera = camera;
1587 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1588 send_msg = muse_core_msg_new(MUSE_RECORDER_API_CREATE,
1589 MUSE_TYPE_INT, "module", MUSE_RECORDER,
1590 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1591 MUSE_TYPE_INT, "pid", getpid(),
1592 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1599 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1600 goto _ERR_RECORDER_EXIT;
1604 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1606 send_ret = muse_core_msg_send(sock_fd, send_msg);
1608 muse_core_msg_free(send_msg);
1613 LOGE("send msg failed %d", errno);
1614 ret = RECORDER_ERROR_INVALID_OPERATION;
1615 goto _ERR_RECORDER_EXIT;
1619 pc->cb_info = _recorder_client_callback_new(sock_fd);
1620 if (pc->cb_info == NULL) {
1621 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1622 goto _ERR_RECORDER_EXIT;
1627 ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1629 pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1631 if (ret != RECORDER_ERROR_NONE) {
1632 LOGE("API_CREATE failed 0x%x", ret);
1633 goto _ERR_RECORDER_EXIT;
1636 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1639 LOGE("Receiving Handle Failed!!");
1640 ret = RECORDER_ERROR_INVALID_OPERATION;
1641 goto _ERR_RECORDER_AFTER_CREATE;
1645 if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1647 LOGE("failed to get root directory of internal storage");
1648 ret = RECORDER_ERROR_INVALID_OPERATION;
1649 goto _ERR_RECORDER_AFTER_CREATE;
1653 LOGD("root directory [%s]", root_directory);
1655 RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1657 _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, ¶m);
1659 if (ret != RECORDER_ERROR_NONE) {
1660 LOGE("failed to set root directory %s", root_directory);
1661 ret = RECORDER_ERROR_INVALID_OPERATION;
1662 goto _ERR_RECORDER_AFTER_CREATE;
1665 free(root_directory);
1666 root_directory = NULL;
1668 pc->remote_handle = handle;
1669 pc->cb_info->bufmgr = bufmgr;
1671 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1672 type, pc, pc->remote_handle);
1674 *recorder = (recorder_h)pc;
1678 return RECORDER_ERROR_NONE;
1680 _ERR_RECORDER_AFTER_CREATE:
1681 _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
1682 LOGE("destroy return 0x%x", destroy_ret);
1685 tbm_bufmgr_deinit(bufmgr);
1688 if (root_directory) {
1689 free(root_directory);
1690 root_directory = NULL;
1694 muse_client_close(sock_fd);
1700 _recorder_client_callback_destroy(pc->cb_info);
1712 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1714 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1718 int recorder_create_audiorecorder(recorder_h *recorder)
1720 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1724 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1726 int ret = RECORDER_ERROR_NONE;
1727 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1728 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1730 if (!pc || !pc->cb_info) {
1731 LOGE("NULL handle");
1732 return RECORDER_ERROR_INVALID_PARAMETER;
1735 if (state == NULL) {
1736 LOGE("NULL pointer state");
1737 return RECORDER_ERROR_INVALID_PARAMETER;
1740 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1742 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1744 if (ret == RECORDER_ERROR_NONE)
1745 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1747 LOGD("ret : 0x%x, state : %d", ret, *state);
1753 int recorder_destroy(recorder_h recorder)
1755 int ret = RECORDER_ERROR_NONE;
1756 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1757 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1759 if (!pc || !pc->cb_info) {
1760 LOGE("NULL handle");
1761 return RECORDER_ERROR_INVALID_PARAMETER;
1766 if (pc->cb_info->is_server_connected)
1767 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1769 LOGW("server disconnected. release resource without send message.");
1771 if (ret == RECORDER_ERROR_NONE) {
1772 _recorder_deactivate_idle_event_all(pc->cb_info);
1773 _recorder_client_callback_destroy(pc->cb_info);
1778 LOGD("ret : 0x%x", ret);
1784 int recorder_prepare(recorder_h recorder)
1786 int ret = RECORDER_ERROR_NONE;
1787 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1788 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1790 if (!pc || !pc->cb_info) {
1791 LOGE("NULL handle");
1792 return RECORDER_ERROR_INVALID_PARAMETER;
1797 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1799 LOGD("ret : 0x%x", ret);
1801 if (ret == RECORDER_ERROR_NONE && pc->camera)
1802 camera_start_evas_rendering(pc->camera);
1808 int recorder_unprepare(recorder_h recorder)
1810 int ret = RECORDER_ERROR_NONE;
1811 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1812 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1813 camera_state_e camera_state = CAMERA_STATE_NONE;
1815 if (!pc || !pc->cb_info) {
1816 LOGE("NULL handle");
1817 return RECORDER_ERROR_INVALID_PARAMETER;
1824 ret = camera_get_state(pc->camera, &camera_state);
1825 if (ret != CAMERA_ERROR_NONE) {
1826 LOGE("failed to get camera state 0x%x", ret);
1827 return RECORDER_ERROR_INVALID_OPERATION;
1830 if (camera_state == CAMERA_STATE_PREVIEW) {
1831 ret = camera_stop_evas_rendering(pc->camera, false);
1832 if (ret != CAMERA_ERROR_NONE) {
1833 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1834 return RECORDER_ERROR_INVALID_OPERATION;
1840 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1842 LOGD("ret : 0x%x", ret);
1848 int recorder_start(recorder_h recorder)
1850 int ret = RECORDER_ERROR_NONE;
1851 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1852 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1853 recorder_state_e current_state = RECORDER_STATE_NONE;
1855 if (!pc || !pc->cb_info) {
1856 LOGE("NULL handle");
1857 return RECORDER_ERROR_INVALID_PARAMETER;
1864 ret = recorder_get_state(recorder, ¤t_state);
1865 if (ret != RECORDER_ERROR_NONE) {
1866 LOGE("failed to get current state 0x%x", ret);
1867 return RECORDER_ERROR_INVALID_OPERATION;
1870 if (current_state == RECORDER_STATE_READY) {
1871 ret = camera_stop_evas_rendering(pc->camera, true);
1872 if (ret != CAMERA_ERROR_NONE) {
1873 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1874 return RECORDER_ERROR_INVALID_OPERATION;
1880 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
1882 if (pc->camera && current_state == RECORDER_STATE_READY)
1883 camera_start_evas_rendering(pc->camera);
1885 LOGD("ret : 0x%x", ret);
1891 int recorder_pause(recorder_h recorder)
1893 int ret = RECORDER_ERROR_NONE;
1894 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1895 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1897 if (!pc || !pc->cb_info) {
1898 LOGE("NULL handle");
1899 return RECORDER_ERROR_INVALID_PARAMETER;
1904 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1906 LOGD("ret : 0x%x", ret);
1912 int recorder_commit(recorder_h recorder)
1914 int ret = RECORDER_ERROR_NONE;
1915 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1916 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1917 recorder_state_e current_state = RECORDER_STATE_NONE;
1919 if (!pc || !pc->cb_info) {
1920 LOGE("NULL handle");
1921 return RECORDER_ERROR_INVALID_PARAMETER;
1928 ret = recorder_get_state(recorder, ¤t_state);
1929 if (ret != RECORDER_ERROR_NONE) {
1930 LOGE("failed to get current state 0x%x", ret);
1931 return RECORDER_ERROR_INVALID_OPERATION;
1934 if (current_state >= RECORDER_STATE_RECORDING) {
1935 ret = camera_stop_evas_rendering(pc->camera, true);
1936 if (ret != CAMERA_ERROR_NONE) {
1937 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1938 return RECORDER_ERROR_INVALID_OPERATION;
1944 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1946 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1947 camera_start_evas_rendering(pc->camera);
1949 LOGD("ret : 0x%x", ret);
1955 int recorder_cancel(recorder_h recorder)
1957 int ret = RECORDER_ERROR_NONE;
1958 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1959 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1960 recorder_state_e current_state = RECORDER_STATE_NONE;
1962 if (!pc || !pc->cb_info) {
1963 LOGE("NULL handle");
1964 return RECORDER_ERROR_INVALID_PARAMETER;
1970 ret = recorder_get_state(recorder, ¤t_state);
1971 if (ret != RECORDER_ERROR_NONE) {
1972 LOGE("failed to get current state 0x%x", ret);
1973 return RECORDER_ERROR_INVALID_OPERATION;
1976 if (current_state >= RECORDER_STATE_RECORDING) {
1977 ret = camera_stop_evas_rendering(pc->camera, true);
1978 if (ret != CAMERA_ERROR_NONE) {
1979 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1980 return RECORDER_ERROR_INVALID_OPERATION;
1985 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1987 if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1988 camera_start_evas_rendering(pc->camera);
1990 LOGD("ret : 0x%x", ret);
1996 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1998 int ret = RECORDER_ERROR_NONE;
2000 char *send_msg = NULL;
2001 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
2002 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2004 if (!pc || !pc->cb_info) {
2005 LOGE("NULL handle");
2006 return RECORDER_ERROR_INVALID_PARAMETER;
2011 send_msg = muse_core_msg_new(api,
2012 MUSE_TYPE_INT, "width", width,
2013 MUSE_TYPE_INT, "height", height,
2016 if (pc->cb_info->is_server_connected) {
2017 __recorder_update_api_waiting(pc->cb_info, api, 1);
2019 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
2023 LOGE("message send failed");
2024 ret = RECORDER_ERROR_INVALID_OPERATION;
2026 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2029 __recorder_update_api_waiting(pc->cb_info, api, -1);
2031 muse_core_msg_free(send_msg);
2033 LOGE("failed to create msg");
2034 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2037 LOGD("ret : 0x%x", ret);
2043 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
2045 int ret = RECORDER_ERROR_NONE;
2046 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
2047 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2049 if (!pc || !pc->cb_info) {
2050 LOGE("NULL handle");
2051 return RECORDER_ERROR_INVALID_PARAMETER;
2054 if (!width || !height) {
2055 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
2056 return RECORDER_ERROR_INVALID_PARAMETER;
2061 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2063 if (ret == RECORDER_ERROR_NONE) {
2064 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
2065 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
2068 LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
2074 int recorder_foreach_supported_video_resolution(recorder_h recorder,
2075 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
2077 int ret = RECORDER_ERROR_NONE;
2078 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2079 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
2081 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2082 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2083 return RECORDER_ERROR_INVALID_PARAMETER;
2086 LOGD("Enter, handle :%x", pc->remote_handle);
2088 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2089 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2091 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2093 LOGD("ret : 0x%x", ret);
2099 int recorder_get_audio_level(recorder_h recorder, double *level)
2101 int ret = RECORDER_ERROR_NONE;
2102 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2103 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2105 if (!pc || !pc->cb_info || level == NULL) {
2106 LOGE("NULL pointer %p %p", pc, level);
2107 return RECORDER_ERROR_INVALID_PARAMETER;
2112 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2114 if (ret == RECORDER_ERROR_NONE)
2115 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2117 LOGD("ret : 0x%x, level %lf", ret, *level);
2123 int recorder_set_filename(recorder_h recorder, const char *filename)
2125 int ret = RECORDER_ERROR_NONE;
2127 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2128 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2129 recorder_msg_param param;
2130 char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2132 if (!pc || !pc->cb_info) {
2133 LOGE("NULL handle");
2134 return RECORDER_ERROR_INVALID_PARAMETER;
2137 if (filename == NULL) {
2138 LOGE("filename is NULL");
2139 return RECORDER_ERROR_INVALID_PARAMETER;
2142 LOGD("ENTER [%s]", filename);
2144 length = strlen(filename);
2146 if (length >= RECORDER_FILENAME_MAX - 1) {
2147 LOGE("too long file name [%d]", length);
2148 return RECORDER_ERROR_INVALID_PARAMETER;
2151 if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2152 /* Cannot convert. Use original path. */
2153 strncpy(set_filename, filename, length + 1);
2155 /* Converted. Use converted path. */
2156 LOGD("Converted filename : %s -> %s", filename, set_filename);
2159 RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2161 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2163 LOGD("ret : 0x%x", ret);
2169 int recorder_get_filename(recorder_h recorder, char **filename)
2171 int ret = RECORDER_ERROR_NONE;
2172 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2173 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2174 char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2176 if (!pc || !pc->cb_info) {
2177 LOGE("NULL handle");
2178 return RECORDER_ERROR_INVALID_PARAMETER;
2181 if (filename == NULL) {
2182 LOGE("filename is NULL");
2183 return RECORDER_ERROR_INVALID_PARAMETER;
2188 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2190 if (ret == RECORDER_ERROR_NONE) {
2191 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2192 /* Cannot convert. Use original path. */
2193 *filename = pc->cb_info->get_filename;
2195 /* Converted. Use converted path. */
2196 LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2197 *filename = strdup(compat_filename);
2198 free(pc->cb_info->get_filename);
2201 pc->cb_info->get_filename = NULL;
2204 LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2210 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2212 int ret = RECORDER_ERROR_NONE;
2213 int set_format = (int)format;
2214 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2215 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2216 recorder_msg_param param;
2218 if (!pc || !pc->cb_info) {
2219 LOGE("NULL handle");
2220 return RECORDER_ERROR_INVALID_PARAMETER;
2223 LOGD("ENTER, set_format : %d", set_format);
2225 RECORDER_MSG_PARAM_SET(param, INT, set_format);
2227 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2229 LOGD("ret : 0x%x", ret);
2234 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2236 int ret = RECORDER_ERROR_NONE;
2237 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2238 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2240 if (!pc || !pc->cb_info) {
2241 LOGE("NULL handle");
2242 return RECORDER_ERROR_INVALID_PARAMETER;
2245 if (format == NULL) {
2246 LOGE("NULL pointer data");
2247 return RECORDER_ERROR_INVALID_PARAMETER;
2252 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2254 if (ret == RECORDER_ERROR_NONE)
2255 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2257 LOGD("ret : 0x%x, format %d", ret, *format);
2263 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2265 int ret = RECORDER_ERROR_NONE;
2266 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2267 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2268 bool is_available = false;
2269 int stream_index = 0;
2270 char *stream_type = NULL;
2271 char *send_msg = NULL;
2274 if (!pc || !pc->cb_info || stream_info == NULL) {
2275 LOGE("NULL handle");
2276 return RECORDER_ERROR_INVALID_PARAMETER;
2281 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2282 if (ret != SOUND_MANAGER_ERROR_NONE) {
2283 LOGE("stream info verification failed");
2284 return RECORDER_ERROR_INVALID_OPERATION;
2287 if (is_available == false) {
2288 LOGE("stream information is not available");
2289 return RECORDER_ERROR_INVALID_OPERATION;
2292 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2293 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2295 LOGD("sound manager return [0x%x]", ret);
2297 if (ret == SOUND_MANAGER_ERROR_NONE) {
2298 send_msg = muse_core_msg_new(api,
2299 MUSE_TYPE_STRING, "stream_type", stream_type,
2300 MUSE_TYPE_INT, "stream_index", stream_index,
2303 if (pc->cb_info->is_server_connected) {
2304 __recorder_update_api_waiting(pc->cb_info, api, 1);
2306 send_ret = muse_core_msg_send(pc->cb_info->fd, send_msg);
2310 LOGE("message send failed");
2311 ret = RECORDER_ERROR_INVALID_OPERATION;
2313 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2316 __recorder_update_api_waiting(pc->cb_info, api, -1);
2318 muse_core_msg_free(send_msg);
2320 LOGE("failed to create msg");
2321 ret = RECORDER_ERROR_OUT_OF_MEMORY;
2324 ret = RECORDER_ERROR_INVALID_OPERATION;
2331 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2333 int ret = RECORDER_ERROR_NONE;
2334 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2335 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2337 if (!pc || !pc->cb_info || callback == NULL) {
2338 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2339 return RECORDER_ERROR_INVALID_PARAMETER;
2342 LOGD("Enter, handle :%x", pc->remote_handle);
2344 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2346 if (ret == RECORDER_ERROR_NONE) {
2347 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2349 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2350 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2352 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2355 LOGD("ret : 0x%x", ret);
2361 int recorder_unset_state_changed_cb(recorder_h recorder)
2363 int ret = RECORDER_ERROR_NONE;
2364 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2365 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2367 if (!pc || !pc->cb_info) {
2368 LOGE("NULL handle");
2369 return RECORDER_ERROR_INVALID_PARAMETER;
2374 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2376 if (ret == RECORDER_ERROR_NONE) {
2377 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2379 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2380 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2382 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE]);
2385 LOGD("ret : 0x%x", ret);
2391 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2393 int ret = RECORDER_ERROR_NONE;
2394 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2395 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2397 if (!pc || !pc->cb_info || callback == NULL) {
2398 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2399 return RECORDER_ERROR_INVALID_PARAMETER;
2402 LOGD("Enter, handle :%x", pc->remote_handle);
2404 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2406 if (ret == RECORDER_ERROR_NONE) {
2407 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2409 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2410 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2412 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2415 LOGD("ret : 0x%x", ret);
2421 int recorder_unset_interrupted_cb(recorder_h recorder)
2423 int ret = RECORDER_ERROR_NONE;
2424 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2425 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2427 if (!pc || !pc->cb_info) {
2428 LOGE("NULL handle");
2429 return RECORDER_ERROR_INVALID_PARAMETER;
2434 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2436 if (ret == RECORDER_ERROR_NONE) {
2437 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2439 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2440 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2442 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED]);
2445 LOGD("ret : 0x%x", ret);
2451 int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
2453 int ret = RECORDER_ERROR_NONE;
2454 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2455 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
2457 if (!pc || !pc->cb_info || callback == NULL) {
2458 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2459 return RECORDER_ERROR_INVALID_PARAMETER;
2462 LOGD("Enter, handle :%x", pc->remote_handle);
2464 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2466 if (ret == RECORDER_ERROR_NONE) {
2467 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2469 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
2470 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
2472 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2475 LOGD("ret : 0x%x", ret);
2481 int recorder_unset_interrupt_started_cb(recorder_h recorder)
2483 int ret = RECORDER_ERROR_NONE;
2484 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
2485 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2487 if (!pc || !pc->cb_info) {
2488 LOGE("NULL handle");
2489 return RECORDER_ERROR_INVALID_PARAMETER;
2494 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2496 if (ret == RECORDER_ERROR_NONE) {
2497 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2499 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2500 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2502 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED]);
2505 LOGD("ret : 0x%x", ret);
2511 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2513 int ret = RECORDER_ERROR_NONE;
2514 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2515 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
2517 if (!pc || !pc->cb_info || callback == NULL) {
2518 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2519 return RECORDER_ERROR_INVALID_PARAMETER;
2522 LOGD("Enter, handle :%x", pc->remote_handle);
2524 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2526 if (ret == RECORDER_ERROR_NONE) {
2527 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2529 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2530 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2532 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2535 LOGD("ret : 0x%x", ret);
2541 int recorder_unset_audio_stream_cb(recorder_h recorder)
2543 int ret = RECORDER_ERROR_NONE;
2544 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2545 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2547 if (!pc || !pc->cb_info) {
2548 LOGE("NULL handle");
2549 return RECORDER_ERROR_INVALID_PARAMETER;
2554 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2556 if (ret == RECORDER_ERROR_NONE) {
2557 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2559 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2560 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2562 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM]);
2565 LOGD("ret : 0x%x", ret);
2571 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2573 int ret = RECORDER_ERROR_NONE;
2574 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2575 muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2577 if (!pc || !pc->cb_info || !callback) {
2578 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2579 return RECORDER_ERROR_INVALID_PARAMETER;
2582 LOGD("Enter, handle :%x", pc->remote_handle);
2584 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2586 if (ret == RECORDER_ERROR_NONE) {
2587 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2589 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2590 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2592 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2595 LOGD("ret : 0x%x", ret);
2601 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2603 int ret = RECORDER_ERROR_NONE;
2604 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2605 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2607 if (!pc || !pc->cb_info) {
2608 LOGE("NULL handle");
2609 return RECORDER_ERROR_INVALID_PARAMETER;
2614 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2616 if (ret == RECORDER_ERROR_NONE) {
2617 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2619 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2620 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2622 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM]);
2625 LOGD("ret : 0x%x", ret);
2631 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2633 int ret = RECORDER_ERROR_NONE;
2634 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2635 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2637 if (!pc || !pc->cb_info || callback == NULL) {
2638 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2639 return RECORDER_ERROR_INVALID_PARAMETER;
2642 LOGD("Enter, handle :%x", pc->remote_handle);
2644 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2646 if (ret == RECORDER_ERROR_NONE) {
2647 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2649 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2650 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2652 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2655 LOGD("ret : 0x%x", ret);
2661 int recorder_unset_error_cb(recorder_h recorder)
2663 int ret = RECORDER_ERROR_NONE;
2664 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2665 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2667 if (!pc || !pc->cb_info) {
2668 LOGE("NULL handle");
2669 return RECORDER_ERROR_INVALID_PARAMETER;
2674 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2676 if (ret == RECORDER_ERROR_NONE) {
2677 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2679 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2680 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2682 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_ERROR]);
2685 LOGD("ret : 0x%x", ret);
2691 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2693 int ret = RECORDER_ERROR_NONE;
2694 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2695 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2697 if (!pc || !pc->cb_info || callback == NULL) {
2698 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2699 return RECORDER_ERROR_INVALID_PARAMETER;
2702 LOGD("Enter, handle :%x", pc->remote_handle);
2704 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2706 if (ret == RECORDER_ERROR_NONE) {
2707 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2709 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2710 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2712 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2715 LOGD("ret : 0x%x", ret);
2721 int recorder_unset_recording_status_cb(recorder_h recorder)
2723 int ret = RECORDER_ERROR_NONE;
2724 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2725 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2727 if (!pc || !pc->cb_info) {
2728 LOGE("NULL handle");
2729 return RECORDER_ERROR_INVALID_PARAMETER;
2734 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2736 if (ret == RECORDER_ERROR_NONE) {
2737 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2739 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2740 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2742 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS]);
2745 LOGD("ret : 0x%x", ret);
2751 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2753 int ret = RECORDER_ERROR_NONE;
2754 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2755 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2757 if (!pc || !pc->cb_info || callback == NULL) {
2758 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2759 return RECORDER_ERROR_INVALID_PARAMETER;
2762 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2764 if (ret == RECORDER_ERROR_NONE) {
2765 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2767 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2768 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2770 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2773 LOGD("ret : 0x%x", ret);
2779 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2781 int ret = RECORDER_ERROR_NONE;
2782 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2783 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2785 if (!pc || !pc->cb_info) {
2786 LOGE("NULL handle");
2787 return RECORDER_ERROR_INVALID_PARAMETER;
2792 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2794 if (ret == RECORDER_ERROR_NONE) {
2795 g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2797 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2798 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2800 g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED]);
2803 LOGD("ret : 0x%x", ret);
2809 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2811 int ret = RECORDER_ERROR_NONE;
2812 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2813 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2815 if (!pc || !pc->cb_info || foreach_cb == NULL) {
2816 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2817 return RECORDER_ERROR_INVALID_PARAMETER;
2820 LOGD("Enter, handle :%x", pc->remote_handle);
2822 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2823 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2825 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2827 LOGD("ret : 0x%x", ret);
2833 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2835 int ret = RECORDER_ERROR_NONE;
2836 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2837 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2838 recorder_msg_param param;
2840 if (!pc || !pc->cb_info) {
2841 LOGE("NULL handle");
2842 return RECORDER_ERROR_INVALID_PARAMETER;
2847 RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2849 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2851 LOGD("ret : 0x%x", ret);
2857 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2859 int ret = RECORDER_ERROR_NONE;
2860 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2861 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2862 recorder_msg_param param;
2864 if (!pc || !pc->cb_info) {
2865 LOGE("NULL handle");
2866 return RECORDER_ERROR_INVALID_PARAMETER;
2871 RECORDER_MSG_PARAM_SET(param, INT, second);
2873 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2875 LOGD("ret : 0x%x", ret);
2881 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2883 int ret = RECORDER_ERROR_NONE;
2884 int set_device = (int)device;
2885 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2886 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2887 recorder_msg_param param;
2889 if (!pc || !pc->cb_info) {
2890 LOGE("NULL handle");
2891 return RECORDER_ERROR_INVALID_PARAMETER;
2896 RECORDER_MSG_PARAM_SET(param, INT, set_device);
2898 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2900 LOGD("ret : 0x%x", ret);
2906 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2908 int ret = RECORDER_ERROR_NONE;
2909 int set_codec = (int)codec;
2910 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2911 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2912 recorder_msg_param param;
2914 if (!pc || !pc->cb_info) {
2915 LOGE("NULL handle");
2916 return RECORDER_ERROR_INVALID_PARAMETER;
2921 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2923 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2925 LOGD("ret : 0x%x", ret);
2931 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2933 int ret = RECORDER_ERROR_NONE;
2934 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2935 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2937 if (!pc || !pc->cb_info) {
2938 LOGE("NULL handle");
2939 return RECORDER_ERROR_INVALID_PARAMETER;
2942 if (codec == NULL) {
2943 LOGE("codec is NULL");
2944 return RECORDER_ERROR_INVALID_PARAMETER;
2949 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2951 if (ret == RECORDER_ERROR_NONE)
2952 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2954 LOGD("ret : 0x%x, codec %d", ret, *codec);
2960 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2962 int ret = RECORDER_ERROR_NONE;
2963 int set_codec = (int)codec;
2964 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2965 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2966 recorder_msg_param param;
2968 if (!pc || !pc->cb_info) {
2969 LOGE("NULL handle");
2970 return RECORDER_ERROR_INVALID_PARAMETER;
2975 RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2977 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
2979 LOGD("ret : 0x%x", ret);
2985 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2987 int ret = RECORDER_ERROR_NONE;
2988 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2989 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2991 if (!pc || !pc->cb_info) {
2992 LOGE("NULL handle");
2993 return RECORDER_ERROR_INVALID_PARAMETER;
2996 if (codec == NULL) {
2997 LOGE("codec is NULL");
2998 return RECORDER_ERROR_INVALID_PARAMETER;
3003 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3005 if (ret == RECORDER_ERROR_NONE)
3006 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
3008 LOGD("ret : 0x%x, codec %d", ret, *codec);
3014 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
3016 int ret = RECORDER_ERROR_NONE;
3017 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
3018 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3019 recorder_msg_param param;
3021 if (!pc || !pc->cb_info) {
3022 LOGE("NULL handle");
3023 return RECORDER_ERROR_INVALID_PARAMETER;
3026 LOGD("ENTER, samplerate : %d", samplerate);
3028 RECORDER_MSG_PARAM_SET(param, INT, samplerate);
3030 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3032 LOGD("ret : 0x%x", ret);
3038 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
3040 int ret = RECORDER_ERROR_NONE;
3041 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
3042 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3043 recorder_msg_param param;
3045 if (!pc || !pc->cb_info) {
3046 LOGE("NULL handle");
3047 return RECORDER_ERROR_INVALID_PARAMETER;
3052 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
3054 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3056 LOGD("ret : 0x%x", ret);
3062 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
3064 int ret = RECORDER_ERROR_NONE;
3065 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
3066 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3067 recorder_msg_param param;
3069 if (!pc || !pc->cb_info) {
3070 LOGE("NULL handle");
3071 return RECORDER_ERROR_INVALID_PARAMETER;
3076 RECORDER_MSG_PARAM_SET(param, INT, bitrate);
3078 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3080 LOGD("ret : 0x%x", ret);
3086 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
3088 int ret = RECORDER_ERROR_NONE;
3089 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
3090 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3092 if (!pc || !pc->cb_info) {
3093 LOGE("NULL handle");
3094 return RECORDER_ERROR_INVALID_PARAMETER;
3097 if (kbyte == NULL) {
3098 LOGE("NULL pointer kbyte");
3099 return RECORDER_ERROR_INVALID_PARAMETER;
3104 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3106 if (ret == RECORDER_ERROR_NONE)
3107 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
3109 LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
3115 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
3117 int ret = RECORDER_ERROR_NONE;
3118 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
3119 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3121 if (!pc || !pc->cb_info) {
3122 LOGE("NULL handle");
3123 return RECORDER_ERROR_INVALID_PARAMETER;
3126 if (second == NULL) {
3127 LOGE("NULL pointer second");
3128 return RECORDER_ERROR_INVALID_PARAMETER;
3133 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3135 if (ret == RECORDER_ERROR_NONE)
3136 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
3138 LOGD("ret : 0x%x, %d second", ret, *second);
3144 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
3146 int ret = RECORDER_ERROR_NONE;
3147 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
3148 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3150 if (!pc || !pc->cb_info) {
3151 LOGE("NULL handle");
3152 return RECORDER_ERROR_INVALID_PARAMETER;
3155 if (device == NULL) {
3156 LOGE("NULL pointer device");
3157 return RECORDER_ERROR_INVALID_PARAMETER;
3162 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3164 if (ret == RECORDER_ERROR_NONE)
3165 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
3167 LOGD("ret : 0x%x, device %d", ret, *device);
3173 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
3175 int ret = RECORDER_ERROR_NONE;
3176 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
3177 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3179 if (!pc || !pc->cb_info) {
3180 LOGE("NULL handle");
3181 return RECORDER_ERROR_INVALID_PARAMETER;
3184 if (samplerate == NULL) {
3185 LOGE("NULL pointer handle");
3186 return RECORDER_ERROR_INVALID_PARAMETER;
3191 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3193 if (ret == RECORDER_ERROR_NONE)
3194 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3196 LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3202 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3204 int ret = RECORDER_ERROR_NONE;
3205 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3206 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3208 if (!pc || !pc->cb_info) {
3209 LOGE("NULL handle");
3210 return RECORDER_ERROR_INVALID_PARAMETER;
3213 if (bitrate == NULL) {
3214 LOGE("NULL pointer");
3215 return RECORDER_ERROR_INVALID_PARAMETER;
3220 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3222 if (ret == RECORDER_ERROR_NONE)
3223 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3225 LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3231 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3233 int ret = RECORDER_ERROR_NONE;
3234 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3235 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3237 if (!pc || !pc->cb_info) {
3238 LOGE("NULL handle");
3239 return RECORDER_ERROR_INVALID_PARAMETER;
3242 if (bitrate == NULL) {
3243 LOGE("NULL pointer");
3244 return RECORDER_ERROR_INVALID_PARAMETER;
3249 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3251 if (ret == RECORDER_ERROR_NONE)
3252 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3254 LOGD("ret : 0x%x", ret);
3260 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3262 int ret = RECORDER_ERROR_NONE;
3263 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3264 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3266 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3267 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3268 return RECORDER_ERROR_INVALID_PARAMETER;
3271 LOGD("Enter, handle :%x", pc->remote_handle);
3273 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3274 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3276 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3278 LOGD("ret : 0x%x", ret);
3284 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3286 int ret = RECORDER_ERROR_NONE;
3287 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3288 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3290 if (!pc || !pc->cb_info || foreach_cb == NULL) {
3291 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3292 return RECORDER_ERROR_INVALID_PARAMETER;
3295 LOGD("Enter, handle :%x", pc->remote_handle);
3297 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3298 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3300 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3302 LOGD("ret : 0x%x", ret);
3308 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3310 int ret = RECORDER_ERROR_NONE;
3311 int set_enable = (int)enable;
3312 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3313 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3314 recorder_msg_param param;
3316 if (!pc || !pc->cb_info) {
3317 LOGE("NULL handle");
3318 return RECORDER_ERROR_INVALID_PARAMETER;
3323 RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3325 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3327 LOGD("ret : 0x%x", ret);
3333 bool recorder_attr_is_muted(recorder_h recorder)
3336 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3337 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3339 if (!pc || !pc->cb_info) {
3340 LOGE("NULL handle");
3346 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3348 if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3351 LOGD("ret : %d", ret);
3357 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3359 int ret = RECORDER_ERROR_NONE;
3360 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3361 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3362 recorder_msg_param param;
3364 if (!pc || !pc->cb_info) {
3365 LOGE("NULL handle");
3366 return RECORDER_ERROR_INVALID_PARAMETER;
3369 LOGD("ENTER - %.20lf", rate);
3371 RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3373 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3375 LOGD("ret : 0x%x", ret);
3381 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3383 int ret = RECORDER_ERROR_NONE;
3384 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3385 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3387 if (!pc || !pc->cb_info) {
3388 LOGE("NULL handle");
3389 return RECORDER_ERROR_INVALID_PARAMETER;
3393 LOGE("rate is NULL");
3394 return RECORDER_ERROR_INVALID_PARAMETER;
3399 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3400 if (ret == RECORDER_ERROR_NONE)
3401 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3403 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3409 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3411 int ret = RECORDER_ERROR_NONE;
3412 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3413 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3414 recorder_msg_param param;
3416 if (!pc || !pc->cb_info) {
3417 LOGE("NULL handle");
3418 return RECORDER_ERROR_INVALID_PARAMETER;
3423 RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3425 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3427 LOGD("ret : 0x%x", ret);
3433 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3435 int ret = RECORDER_ERROR_NONE;
3436 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3437 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3439 if (!pc || !pc->cb_info) {
3440 LOGE("NULL handle");
3441 return RECORDER_ERROR_INVALID_PARAMETER;
3444 if (channel_count == NULL) {
3445 LOGE("channel_count is NULL");
3446 return RECORDER_ERROR_INVALID_PARAMETER;
3451 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3453 if (ret == RECORDER_ERROR_NONE)
3454 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3456 LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3462 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3464 int ret = RECORDER_ERROR_NONE;
3465 int set_orientation = (int)orientation;
3466 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3467 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3468 recorder_msg_param param;
3470 if (!pc || !pc->cb_info) {
3471 LOGE("NULL handle");
3472 return RECORDER_ERROR_INVALID_PARAMETER;
3477 RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3479 _recorder_msg_send_param1(api, pc->cb_info, &ret, ¶m);
3481 LOGD("ret : 0x%x", ret);
3487 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3489 int ret = RECORDER_ERROR_NONE;
3490 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3491 recorder_cli_s *pc = (recorder_cli_s *)recorder;
3493 if (!pc || !pc->cb_info) {
3494 LOGE("NULL handle");
3495 return RECORDER_ERROR_INVALID_PARAMETER;
3498 if (orientation == NULL) {
3499 LOGE("orientation is NULL");
3500 return RECORDER_ERROR_INVALID_PARAMETER;
3505 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3507 if (ret == RECORDER_ERROR_NONE)
3508 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3510 LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3516 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3518 int ret = RECORDER_ERROR_NONE;
3520 int get_device_state = 0;
3521 char *send_msg = NULL;
3522 char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3525 LOGE("NULL pointer");
3526 return RECORDER_ERROR_INVALID_PARAMETER;
3529 LOGD("Enter - type %d", type);
3531 sock_fd = muse_client_new();
3534 LOGE("muse_client_new failed - returned fd %d", sock_fd);
3535 ret = RECORDER_ERROR_INVALID_OPERATION;
3536 goto _GET_DEVICE_STATE_EXIT;
3540 send_msg = muse_core_msg_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3541 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3542 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3547 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3548 goto _GET_DEVICE_STATE_EXIT;
3552 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3554 ret = muse_core_msg_send(sock_fd, send_msg);
3556 muse_core_msg_free(send_msg);
3561 LOGE("send msg failed %d", errno);
3562 ret = RECORDER_ERROR_INVALID_OPERATION;
3563 goto _GET_DEVICE_STATE_EXIT;
3567 ret = muse_core_msg_recv(sock_fd, recv_msg);
3570 LOGE("recv msg failed %d", errno);
3571 ret = RECORDER_ERROR_INVALID_OPERATION;
3572 goto _GET_DEVICE_STATE_EXIT;
3576 if (!muse_recorder_msg_get(ret, recv_msg)) {
3578 LOGE("failed to get return value from msg [%s]", recv_msg);
3579 ret = RECORDER_ERROR_INVALID_OPERATION;
3580 goto _GET_DEVICE_STATE_EXIT;
3584 if (ret == RECORDER_ERROR_NONE) {
3585 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3586 *state = (recorder_device_state_e)get_device_state;
3587 LOGD("device type %d state %d", type, *state);
3589 LOGE("failed to get device state from msg [%s]", recv_msg);
3590 ret = RECORDER_ERROR_INVALID_OPERATION;
3593 LOGE("failed 0x%x", ret);
3596 _GET_DEVICE_STATE_EXIT:
3598 muse_client_close(sock_fd);
3606 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3608 int ret = RECORDER_ERROR_NONE;
3609 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3610 recorder_cb_info *info = NULL;
3612 if (!callback || !cb_id) {
3613 LOGE("invalid pointer %p %p", callback, cb_id);
3614 return RECORDER_ERROR_INVALID_PARAMETER;
3617 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3619 /* check recorder support */
3620 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3621 if (ret != RECORDER_ERROR_NONE) {
3622 LOGE("get device state failed");
3623 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3627 info = g_new0(recorder_cb_info, 1);
3629 LOGE("info failed");
3630 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3634 info->id = ++g_rec_dev_state_changed_cb_id;
3635 info->callback = (void *)callback;
3636 info->user_data = user_data;
3640 /* subscribe dbus signal for camera state change */
3641 if (!g_rec_dev_state_changed_cb_conn) {
3642 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3643 if (!g_rec_dev_state_changed_cb_conn) {
3644 LOGE("failed to get gdbus connection");
3645 ret = RECORDER_ERROR_INVALID_OPERATION;
3649 LOGD("subscribe signal %s - %s - %s",
3650 MM_CAMCORDER_DBUS_OBJECT,
3651 MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3652 MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3654 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3655 NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3656 G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3657 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3658 LOGE("failed to get gdbus connection");
3659 ret = RECORDER_ERROR_INVALID_OPERATION;
3663 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3666 g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3668 LOGD("callback id %d", info->id);
3671 if (ret != RECORDER_ERROR_NONE) {
3678 if (g_rec_dev_state_changed_cb_conn) {
3679 g_object_unref(g_rec_dev_state_changed_cb_conn);
3680 g_rec_dev_state_changed_cb_conn = NULL;
3685 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3691 int recorder_remove_device_state_changed_cb(int cb_id)
3693 int ret = RECORDER_ERROR_NONE;
3694 recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3695 GList *tmp_list = NULL;
3696 recorder_cb_info *info = NULL;
3698 /* check recorder support */
3699 ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3700 if (ret != RECORDER_ERROR_NONE) {
3701 LOGE("get device state failed");
3705 g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3707 if (!g_rec_dev_state_changed_cb_list) {
3708 LOGE("there is no callback info");
3709 ret = RECORDER_ERROR_INVALID_OPERATION;
3713 tmp_list = g_rec_dev_state_changed_cb_list;
3716 info = tmp_list->data;
3717 tmp_list = tmp_list->next;
3724 if (info->id == cb_id) {
3725 g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3730 if (!g_rec_dev_state_changed_cb_list) {
3731 /* no remained callback */
3732 if (g_rec_dev_state_changed_cb_conn) {
3733 /* unsubscribe signal */
3734 g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3735 g_rec_dev_state_changed_cb_subscribe_id = 0;
3737 /* unref connection */
3738 g_object_unref(g_rec_dev_state_changed_cb_conn);
3739 g_rec_dev_state_changed_cb_conn = NULL;
3743 LOGD("id %d callback removed", cb_id);
3744 ret = RECORDER_ERROR_NONE;
3750 LOGE("id %d callback not found", cb_id);
3751 ret = RECORDER_ERROR_INVALID_PARAMETER;
3754 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);