2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sound_manager.h>
22 #include <sound_manager_internal.h>
24 #include <muse_recorder.h>
25 #include <muse_recorder_msg.h>
26 #include <muse_core_ipc.h>
27 #include <muse_core_module.h>
28 #include <recorder_private.h>
35 #define LOG_TAG "TIZEN_N_RECORDER"
38 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
41 tbm_bo_handle tmp_bo_handle = {NULL, };
43 if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
44 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
45 bufmgr, bo, bo_handle, tbm_key);
49 tmp_bo = tbm_bo_import(bufmgr, tbm_key);
51 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
55 tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
56 if (tmp_bo_handle.ptr == NULL) {
57 LOGE("bo map failed %p", tmp_bo);
63 /* set bo and bo_handle */
65 *bo_handle = tmp_bo_handle;
70 static void _recorder_release_imported_bo(tbm_bo *bo)
72 if (bo == NULL || *bo == NULL) {
84 static void _client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
86 if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
87 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
91 LOGD("get recorder msg %s, event %d", recv_msg, event);
93 if (cb_info->user_cb[event] == NULL) {
94 LOGW("user callback for event %d is not set", event);
99 case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
105 muse_recorder_msg_get(previous, recv_msg);
106 muse_recorder_msg_get(current, recv_msg);
107 muse_recorder_msg_get(by_policy, recv_msg);
109 ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
110 (recorder_state_e)current,
112 cb_info->user_data[event]);
115 case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
119 muse_recorder_msg_get(type, recv_msg);
121 ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
122 cb_info->user_data[event]);
125 case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
127 int64_t cb_elapsed_time = 0;
128 int64_t cb_file_size = 0;
130 muse_recorder_msg_get(cb_elapsed_time, recv_msg);
131 muse_recorder_msg_get(cb_file_size, recv_msg);
133 ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
134 (unsigned long long)cb_file_size,
135 cb_info->user_data[event]);
138 case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
144 muse_recorder_msg_get(policy, recv_msg);
145 muse_recorder_msg_get(previous, recv_msg);
146 muse_recorder_msg_get(current, recv_msg);
148 ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
149 (recorder_state_e)previous,
150 (recorder_state_e)current,
151 cb_info->user_data[event]);
154 case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
162 tbm_bo_handle bo_handle = {.ptr = NULL};
164 muse_recorder_msg_get(tbm_key, recv_msg);
170 if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
171 LOGE("tbm key %d import failed", tbm_key);
175 muse_recorder_msg_get(size, recv_msg);
176 muse_recorder_msg_get(format, recv_msg);
177 muse_recorder_msg_get(channel, recv_msg);
178 muse_recorder_msg_get(timestamp, recv_msg);
180 ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
182 (audio_sample_type_e)format,
184 (unsigned int)timestamp,
185 cb_info->user_data[event]);
187 /* release imported bo */
188 _recorder_release_imported_bo(&bo);
191 muse_recorder_msg_send1_no_return(MUSE_RECORDER_API_RETURN_BUFFER,
192 cb_info->fd, cb_info,
196 case MUSE_RECORDER_EVENT_TYPE_ERROR:
199 int current_state = 0;
201 muse_recorder_msg_get(error, recv_msg);
202 muse_recorder_msg_get(current_state, recv_msg);
204 ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
205 (recorder_state_e)current_state,
206 cb_info->user_data[event]);
209 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
213 muse_recorder_msg_get(codec, recv_msg);
215 if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
216 cb_info->user_cb[event] = NULL;
217 cb_info->user_data[event] = NULL;
218 LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");
222 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
226 muse_recorder_msg_get(format, recv_msg);
228 if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
229 cb_info->user_cb[event] = NULL;
230 cb_info->user_data[event] = NULL;
231 LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");
235 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
239 muse_recorder_msg_get(codec, recv_msg);
241 if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
242 cb_info->user_cb[event] = NULL;
243 cb_info->user_data[event] = NULL;
244 LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");
248 case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION:
253 muse_recorder_msg_get(width, recv_msg);
254 muse_recorder_msg_get(height, recv_msg);
256 if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
257 cb_info->user_cb[event] = NULL;
258 cb_info->user_data[event] = NULL;
259 LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");
265 LOGE("Unknonw recorder event %d", event);
273 static bool _recorder_idle_event_callback(void *data)
275 recorder_cb_info_s *cb_info = NULL;
276 recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
278 if (rec_idle_event == NULL) {
279 LOGE("rec_idle_event is NULL");
284 g_mutex_lock(&rec_idle_event->event_mutex);
286 cb_info = rec_idle_event->cb_info;
287 if (cb_info == NULL) {
288 LOGW("recorder cb_info is NULL. event %d", rec_idle_event->event);
289 goto IDLE_EVENT_CALLBACK_DONE;
292 /* remove event from list */
293 g_mutex_lock(&cb_info->idle_event_mutex);
294 if (cb_info->idle_event_list)
295 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
297 /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
298 g_mutex_unlock(&cb_info->idle_event_mutex);
301 _client_user_callback(rec_idle_event->cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
303 /* send signal for waiting thread */
304 g_cond_signal(&cb_info->idle_event_cond);
306 IDLE_EVENT_CALLBACK_DONE:
307 /* unlock and release event */
308 g_mutex_unlock(&rec_idle_event->event_mutex);
309 g_mutex_clear(&rec_idle_event->event_mutex);
311 free(rec_idle_event);
312 rec_idle_event = NULL;
318 static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
320 recorder_idle_event_s *rec_idle_event = NULL;
325 if (cb_info == NULL) {
326 LOGE("cb_info is NULL");
330 g_mutex_lock(&cb_info->idle_event_mutex);
332 if (cb_info->idle_event_list == NULL) {
333 LOGD("No idle event is remained.");
335 list = cb_info->idle_event_list;
338 rec_idle_event = list->data;
339 list = g_list_next(list);
341 if (!rec_idle_event) {
342 LOGW("Fail to remove idle event. The event is NULL");
344 if (g_mutex_trylock(&rec_idle_event->event_mutex)) {
345 ret = g_idle_remove_by_data(rec_idle_event);
347 LOGD("remove idle event [%p], ret[%d]", rec_idle_event, ret);
350 rec_idle_event->cb_info = NULL;
351 LOGW("idle callback for event %p will be called later", rec_idle_event);
354 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
356 g_mutex_unlock(&rec_idle_event->event_mutex);
359 g_mutex_clear(&rec_idle_event->event_mutex);
361 free(rec_idle_event);
362 rec_idle_event = NULL;
364 LOGD("remove idle event done");
367 LOGW("event lock failed. it's being called...");
369 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
371 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
372 LOGW("signal received");
379 g_list_free(cb_info->idle_event_list);
380 cb_info->idle_event_list = NULL;
383 g_mutex_unlock(&cb_info->idle_event_mutex);
389 static void *_recorder_msg_handler_func(gpointer data)
395 recorder_message_s *rec_msg = NULL;
396 recorder_idle_event_s *rec_idle_event = NULL;
397 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
399 if (cb_info == NULL) {
400 LOGE("cb_info NULL");
406 g_mutex_lock(&cb_info->msg_handler_mutex);
408 while (g_atomic_int_get(&cb_info->msg_handler_running)) {
409 if (g_queue_is_empty(cb_info->msg_queue)) {
410 LOGD("signal wait...");
411 g_cond_wait(&cb_info->msg_handler_cond, &cb_info->msg_handler_mutex);
412 LOGD("signal received");
414 if (g_atomic_int_get(&cb_info->msg_handler_running) == 0) {
415 LOGD("stop event thread");
420 rec_msg = (recorder_message_s *)g_queue_pop_head(cb_info->msg_queue);
421 g_mutex_unlock(&cb_info->msg_handler_mutex);
422 if (rec_msg == NULL) {
423 LOGE("NULL message");
424 g_mutex_lock(&cb_info->msg_handler_mutex);
428 if (api < MUSE_RECORDER_API_MAX) {
429 g_mutex_lock(&cb_info->api_mutex[api]);
430 if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
431 cb_info->api_ret[api] = ret;
432 cb_info->api_activating[api] = 1;
434 LOGD("recorder api %d - return 0x%x", ret);
436 g_cond_signal(&cb_info->api_cond[api]);
438 LOGE("failed to get ret for api %d, msg %s", rec_msg->api, rec_msg->recv_msg);
441 g_mutex_unlock(&cb_info->api_mutex[api]);
442 } else if (api == MUSE_RECORDER_CB_EVENT) {
446 if (!muse_recorder_msg_get(event, rec_msg->recv_msg) ||
447 !muse_recorder_msg_get(event_class, rec_msg->recv_msg)) {
448 LOGE("failed to get recorder event %d, class %d", event, event_class);
453 g_mutex_lock(&cb_info->msg_handler_mutex);
457 switch (event_class) {
458 case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
459 _client_user_callback(cb_info, rec_msg->recv_msg, event);
461 case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
462 rec_idle_event = (recorder_idle_event_s *)malloc(sizeof(recorder_idle_event_s));
463 if (rec_idle_event == NULL) {
464 LOGE("rec_idle_event alloc failed");
468 rec_idle_event->event = event;
469 rec_idle_event->cb_info = cb_info;
470 g_mutex_init(&rec_idle_event->event_mutex);
471 memcpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg));
473 LOGD("add recorder event[%d, %p] to IDLE", event, rec_idle_event);
475 g_mutex_lock(&cb_info->idle_event_mutex);
476 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
477 g_mutex_unlock(&cb_info->idle_event_mutex);
479 g_idle_add_full(G_PRIORITY_DEFAULT,
480 (GSourceFunc)_recorder_idle_event_callback,
481 (gpointer)rec_idle_event,
485 LOGE("unknown recorder event class %d", event_class);
489 LOGE("unknown recorder api[%d] message", api);
495 g_mutex_lock(&cb_info->msg_handler_mutex);
498 /* remove remained event */
499 while (!g_queue_is_empty(cb_info->msg_queue)) {
500 rec_msg = (recorder_message_s *)g_queue_pop_head(cb_info->msg_queue);
502 LOGD("remove recorder message %p", rec_msg);
506 LOGW("NULL recorder message");
510 g_mutex_unlock(&cb_info->msg_handler_mutex);
518 static void *_recorder_msg_recv_func(gpointer data)
527 char *recv_msg = NULL;
528 char **parse_str = NULL;
529 recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
531 if (cb_info == NULL) {
532 LOGE("cb_info NULL");
538 parse_str = (char **)malloc(sizeof(char *) * RECORDER_PARSE_STRING_SIZE);
539 if (parse_str == NULL) {
540 LOGE("parse_str malloc failed");
544 for (i = 0 ; i < RECORDER_PARSE_STRING_SIZE ; i++) {
545 parse_str[i] = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
546 if (parse_str[i] == NULL) {
547 LOGE("parse_str[%d] malloc failed", i);
548 goto CB_HANDLER_EXIT;
552 recv_msg = cb_info->recv_msg;
554 while (g_atomic_int_get(&cb_info->msg_recv_running)) {
555 ret = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
558 recv_msg[ret] = '\0';
564 /*LOGD("recvMSg : %s, length : %d", recv_msg, ret);*/
566 /* Need to split the combined entering msgs.
567 This module supports up to 200 combined msgs. */
568 for (str_pos = 0; str_pos < ret; str_pos++) {
569 if (recv_msg[str_pos] == '}') {
570 memset(parse_str[num_token], 0x0, sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
571 strncpy(parse_str[num_token], recv_msg + prev_pos, str_pos - prev_pos + 1);
572 LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);
573 prev_pos = str_pos+1;
578 /*LOGD("num_token : %d", num_token);*/
580 /* Re-construct to the useful single msg. */
581 for (i = 0; i < num_token; i++) {
582 if (i >= RECORDER_PARSE_STRING_SIZE) {
583 LOGE("invalid token index %d", i);
590 if (!muse_recorder_msg_get(api, parse_str[i])) {
591 LOGE("failed to get recorder api");
595 if (muse_recorder_msg_get(api_class, parse_str[i]))
596 LOGD("recorder api_class[%d]", api_class);
598 if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
599 g_mutex_lock(&cb_info->api_mutex[api]);
601 if (!muse_recorder_msg_get(ret, parse_str[i])) {
602 LOGE("failed to get recorder ret");
603 g_mutex_unlock(&cb_info->api_mutex[api]);
607 cb_info->api_ret[api] = ret;
608 cb_info->api_activating[api] = 1;
610 if (api == MUSE_RECORDER_API_CREATE) {
611 if (ret != RECORDER_ERROR_NONE) {
612 g_atomic_int_set(&cb_info->msg_recv_running, 0);
613 LOGE("recorder create error 0x%x. close client cb handler", ret);
615 } else if (api == MUSE_RECORDER_API_DESTROY) {
616 if (ret == RECORDER_ERROR_NONE) {
617 g_atomic_int_set(&cb_info->msg_recv_running, 0);
618 LOGD("recorder destroy done. close client cb handler");
622 g_cond_signal(&cb_info->api_cond[api]);
623 g_mutex_unlock(&cb_info->api_mutex[api]);
624 } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB ||
625 api == MUSE_RECORDER_CB_EVENT) {
626 recorder_message_s *rec_msg = g_new0(recorder_message_s, 1);
627 if (rec_msg == NULL) {
628 LOGE("failed to alloc rec_msg");
633 memcpy(rec_msg->recv_msg, parse_str[i], sizeof(rec_msg->recv_msg));
635 LOGD("add recorder message to queue : api %d", api);
637 g_mutex_lock(&cb_info->msg_handler_mutex);
638 g_queue_push_tail(cb_info->msg_queue, (gpointer)rec_msg);
639 g_cond_signal(&cb_info->msg_handler_cond);
640 g_mutex_unlock(&cb_info->msg_handler_mutex);
642 LOGW("unknown recorder api %d and api_class %d", api, api_class);
647 LOGD("client cb exit");
651 for (i = 0 ; i < RECORDER_PARSE_STRING_SIZE ; i++) {
665 static recorder_cb_info_s *_client_callback_new(gint sockfd)
667 recorder_cb_info_s *cb_info = NULL;
668 gint *tmp_activating = NULL;
669 gint *tmp_ret = NULL;
672 g_return_val_if_fail(sockfd > 0, NULL);
674 cb_info = g_new0(recorder_cb_info_s, 1);
675 if (cb_info == NULL) {
676 LOGE("cb_info failed");
680 g_mutex_init(&cb_info->msg_handler_mutex);
681 g_cond_init(&cb_info->msg_handler_cond);
682 g_mutex_init(&cb_info->idle_event_mutex);
683 g_cond_init(&cb_info->idle_event_cond);
685 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
686 g_mutex_init(&cb_info->api_mutex[i]);
687 g_cond_init(&cb_info->api_cond[i]);
690 tmp_activating = g_new0(gint, MUSE_RECORDER_API_MAX);
691 if (tmp_activating == NULL) {
692 LOGE("tmp_activating failed");
696 tmp_ret = g_new0(gint, MUSE_RECORDER_API_MAX);
697 if (tmp_ret == NULL) {
698 LOGE("tmp_ret failed");
702 cb_info->msg_queue = g_queue_new();
703 if (cb_info->msg_queue == NULL) {
704 LOGE("msg_queue new failed");
708 g_atomic_int_set(&cb_info->msg_handler_running, 1);
709 cb_info->msg_handler_thread = g_thread_try_new("recorder_msg_handler",
710 _recorder_msg_handler_func,
713 if (cb_info->msg_handler_thread == NULL) {
714 LOGE("message handler thread creation failed");
718 cb_info->fd = sockfd;
719 cb_info->api_activating = tmp_activating;
720 cb_info->api_ret = tmp_ret;
722 g_atomic_int_set(&cb_info->msg_recv_running, 1);
723 cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
724 _recorder_msg_recv_func,
727 if (cb_info->msg_recv_thread == NULL) {
728 LOGE("message receive thread creation failed");
737 if (cb_info->msg_handler_thread) {
738 g_mutex_lock(&cb_info->msg_handler_mutex);
739 g_atomic_int_set(&cb_info->msg_handler_running, 0);
740 g_cond_signal(&cb_info->msg_handler_cond);
741 g_mutex_unlock(&cb_info->msg_handler_mutex);
743 g_thread_join(cb_info->msg_handler_thread);
744 g_thread_unref(cb_info->msg_handler_thread);
745 cb_info->msg_handler_thread = NULL;
748 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
749 g_mutex_clear(&cb_info->api_mutex[i]);
750 g_cond_clear(&cb_info->api_cond[i]);
753 g_mutex_clear(&cb_info->msg_handler_mutex);
754 g_cond_clear(&cb_info->msg_handler_cond);
755 g_mutex_clear(&cb_info->idle_event_mutex);
756 g_cond_clear(&cb_info->idle_event_cond);
758 if (cb_info->msg_queue) {
759 g_queue_free(cb_info->msg_queue);
760 cb_info->msg_queue = NULL;
767 if (tmp_activating) {
768 g_free(tmp_activating);
769 tmp_activating = NULL;
779 static int client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
781 int ret = RECORDER_ERROR_NONE;
784 LOGD("Enter api : %d", api);
786 g_mutex_lock(&(cb_info->api_mutex[api]));
788 if (cb_info->api_activating[api] == 0) {
789 end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
790 if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
791 ret = cb_info->api_ret[api];
792 cb_info->api_activating[api] = 0;
794 LOGD("return value : 0x%x", ret);
796 ret = RECORDER_ERROR_INVALID_OPERATION;
798 LOGE("api %d was TIMED OUT!", api);
801 ret = cb_info->api_ret[api];
802 cb_info->api_activating[api] = 0;
804 LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);
807 g_mutex_unlock(&(cb_info->api_mutex[api]));
812 static void _client_callback_destroy(recorder_cb_info_s *cb_info)
816 g_return_if_fail(cb_info != NULL);
818 LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
820 g_thread_join(cb_info->msg_recv_thread);
821 g_thread_unref(cb_info->msg_recv_thread);
822 cb_info->msg_recv_thread = NULL;
824 LOGD("msg thread removed");
826 g_mutex_lock(&cb_info->msg_handler_mutex);
827 g_atomic_int_set(&cb_info->msg_handler_running, 0);
828 g_cond_signal(&cb_info->msg_handler_cond);
829 g_mutex_unlock(&cb_info->msg_handler_mutex);
831 g_thread_join(cb_info->msg_handler_thread);
832 g_thread_unref(cb_info->msg_handler_thread);
833 cb_info->msg_handler_thread = NULL;
835 g_queue_free(cb_info->msg_queue);
836 cb_info->msg_queue = NULL;
837 g_mutex_clear(&cb_info->msg_handler_mutex);
838 g_cond_clear(&cb_info->msg_handler_cond);
839 g_mutex_clear(&cb_info->idle_event_mutex);
840 g_cond_clear(&cb_info->idle_event_cond);
842 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
843 g_mutex_clear(&cb_info->api_mutex[i]);
844 g_cond_clear(&cb_info->api_cond[i]);
847 LOGD("event thread removed");
849 if (cb_info->fd > -1) {
850 muse_core_connection_close(cb_info->fd);
854 if (cb_info->bufmgr) {
855 tbm_bufmgr_deinit(cb_info->bufmgr);
856 cb_info->bufmgr = NULL;
858 if (cb_info->api_activating) {
859 g_free(cb_info->api_activating);
860 cb_info->api_activating = NULL;
862 if (cb_info->api_ret) {
863 g_free(cb_info->api_ret);
864 cb_info->api_ret = NULL;
873 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
875 char **root_directory = (char **)user_data;
877 if (root_directory == NULL) {
878 LOGE("user data is NULL");
882 LOGD("storage id %d, type %d, state %d, path %s",
883 storage_id, type, state, path ? path : "NULL");
885 if (type == STORAGE_TYPE_INTERNAL && path) {
886 if (*root_directory) {
887 free(*root_directory);
888 *root_directory = NULL;
891 *root_directory = strdup(path);
892 if (*root_directory) {
893 LOGD("get root directory %s", *root_directory);
896 LOGE("strdup %s failed");
903 static int _client_get_root_directory(char **root_directory)
905 int ret = STORAGE_ERROR_NONE;
907 if (root_directory == NULL) {
908 LOGE("user data is NULL");
912 ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
913 if (ret != STORAGE_ERROR_NONE) {
914 LOGE("storage_foreach_device_supported failed 0x%x", ret);
921 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
923 int ret = RECORDER_ERROR_NONE;
924 int destroy_ret = RECORDER_ERROR_NONE;
926 char *send_msg = NULL;
927 char *root_directory = NULL;
928 intptr_t camera_handle = 0;
930 tbm_bufmgr bufmgr = NULL;
931 recorder_cli_s *pc = NULL;
933 LOGD("Enter - type %d", type);
935 if (recorder == NULL) {
936 LOGE("NULL pointer for recorder handle");
937 return RECORDER_ERROR_INVALID_PARAMETER;
940 if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
941 LOGE("NULL pointer for camera handle on video recorder mode");
942 return RECORDER_ERROR_INVALID_PARAMETER;
945 bufmgr = tbm_bufmgr_init(-1);
946 if (bufmgr == NULL) {
947 LOGE("get tbm bufmgr failed");
948 return RECORDER_ERROR_INVALID_OPERATION;
951 pc = g_new0(recorder_cli_s, 1);
953 ret = RECORDER_ERROR_OUT_OF_MEMORY;
954 goto _ERR_RECORDER_EXIT;
957 sock_fd = muse_core_client_new();
959 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
960 ret = RECORDER_ERROR_INVALID_OPERATION;
961 goto _ERR_RECORDER_EXIT;
964 if (type == MUSE_RECORDER_TYPE_AUDIO) {
965 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
966 MUSE_TYPE_INT, "module", MUSE_RECORDER,
967 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
968 MUSE_TYPE_INT, "pid", getpid(),
971 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
972 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
973 MUSE_TYPE_INT, "module", MUSE_RECORDER,
974 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
975 MUSE_TYPE_POINTER, "camera_handle", camera_handle,
979 LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
981 muse_core_ipc_send_msg(sock_fd, send_msg);
982 muse_core_msg_json_factory_free(send_msg);
984 pc->cb_info = _client_callback_new(sock_fd);
985 if (pc->cb_info == NULL) {
986 ret = RECORDER_ERROR_OUT_OF_MEMORY;
987 goto _ERR_RECORDER_EXIT;
990 ret = client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CALLBACK_TIME_OUT);
991 if (ret == RECORDER_ERROR_NONE) {
992 muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
994 LOGE("Receiving Handle Failed!!");
995 goto _ERR_RECORDER_EXIT;
998 if (!_client_get_root_directory(&root_directory) || root_directory == NULL) {
999 LOGE("failed to get root directory of internal storage");
1000 ret = RECORDER_ERROR_INVALID_OPERATION;
1001 goto _ERR_RECORDER_AFTER_CREATE;
1004 LOGD("set root directory [%s]", root_directory);
1006 muse_recorder_msg_send1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY,
1007 sock_fd, pc->cb_info, ret, STRING, root_directory);
1008 if (ret != RECORDER_ERROR_NONE) {
1009 LOGE("failed to set root directory %s", root_directory);
1010 ret = RECORDER_ERROR_INVALID_OPERATION;
1011 goto _ERR_RECORDER_AFTER_CREATE;
1014 free(root_directory);
1015 root_directory = NULL;
1017 pc->remote_handle = handle;
1018 pc->cb_info->bufmgr = bufmgr;
1020 LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1021 type, pc, pc->remote_handle);
1023 *recorder = (recorder_h) pc;
1025 goto _ERR_RECORDER_EXIT;
1030 return RECORDER_ERROR_NONE;
1032 _ERR_RECORDER_AFTER_CREATE:
1033 muse_recorder_msg_send(MUSE_RECORDER_API_DESTROY, sock_fd, pc->cb_info, destroy_ret);
1034 LOGE("destroy return 0x%x", destroy_ret);
1037 tbm_bufmgr_deinit(bufmgr);
1040 if (root_directory) {
1041 free(root_directory);
1042 root_directory = NULL;
1047 _client_callback_destroy(pc->cb_info);
1057 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1059 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1063 int recorder_create_audiorecorder(recorder_h *recorder)
1065 return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1068 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1070 if (recorder == NULL) {
1071 LOGE("NULL pointer handle");
1072 return RECORDER_ERROR_INVALID_PARAMETER;
1074 if (state == NULL) {
1075 LOGE("NULL pointer state");
1076 return RECORDER_ERROR_INVALID_PARAMETER;
1079 int ret = RECORDER_ERROR_NONE;
1081 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1082 muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1084 if (pc->cb_info == NULL) {
1085 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1086 return RECORDER_ERROR_INVALID_PARAMETER;
1088 sock_fd = pc->cb_info->fd;
1091 LOGD("Enter, remote_handle : %x", pc->remote_handle);
1093 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1095 if (ret == RECORDER_ERROR_NONE) {
1096 muse_recorder_msg_get(get_state, pc->cb_info->recv_msg);
1097 *state = (recorder_state_e)get_state;
1100 LOGD("ret : 0x%x, get_state : %d", ret, get_state);
1106 int recorder_destroy(recorder_h recorder)
1108 if (recorder == NULL) {
1109 LOGE("NULL pointer handle");
1110 return RECORDER_ERROR_INVALID_PARAMETER;
1112 int ret = RECORDER_ERROR_NONE;
1113 muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1114 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1117 if (pc->cb_info == NULL) {
1118 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1119 return RECORDER_ERROR_INVALID_PARAMETER;
1122 sock_fd = pc->cb_info->fd;
1126 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1127 if (ret == RECORDER_ERROR_NONE) {
1128 _recorder_remove_idle_event_all(pc->cb_info);
1129 _client_callback_destroy(pc->cb_info);
1134 LOGD("ret : 0x%x", ret);
1140 int recorder_prepare(recorder_h recorder)
1142 if (recorder == NULL) {
1143 LOGE("NULL pointer handle");
1144 return RECORDER_ERROR_INVALID_PARAMETER;
1147 int ret = RECORDER_ERROR_NONE;
1148 muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1149 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1151 if (pc->cb_info == NULL) {
1152 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1153 return RECORDER_ERROR_INVALID_PARAMETER;
1155 sock_fd = pc->cb_info->fd;
1159 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1161 LOGD("ret : 0x%x", ret);
1167 int recorder_unprepare(recorder_h recorder)
1169 if (recorder == NULL) {
1170 LOGE("NULL pointer handle");
1171 return RECORDER_ERROR_INVALID_PARAMETER;
1173 int ret = RECORDER_ERROR_NONE;
1174 muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1175 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1177 if (pc->cb_info == NULL) {
1178 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1179 return RECORDER_ERROR_INVALID_PARAMETER;
1181 sock_fd = pc->cb_info->fd;
1185 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1186 LOGD("ret : 0x%x", ret);
1191 int recorder_start(recorder_h recorder)
1193 if (recorder == NULL) {
1194 LOGE("NULL pointer handle");
1195 return RECORDER_ERROR_INVALID_PARAMETER;
1197 int ret = RECORDER_ERROR_NONE;
1198 muse_recorder_api_e api = MUSE_RECORDER_API_START;
1199 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1201 if (pc->cb_info == NULL) {
1202 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1203 return RECORDER_ERROR_INVALID_PARAMETER;
1205 sock_fd = pc->cb_info->fd;
1209 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1210 LOGD("ret : 0x%x", ret);
1215 int recorder_pause(recorder_h recorder)
1217 if (recorder == NULL) {
1218 LOGE("NULL pointer handle");
1219 return RECORDER_ERROR_INVALID_PARAMETER;
1221 int ret = RECORDER_ERROR_NONE;
1222 muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1223 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1225 if (pc->cb_info == NULL) {
1226 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1227 return RECORDER_ERROR_INVALID_PARAMETER;
1229 sock_fd = pc->cb_info->fd;
1233 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1234 LOGD("ret : 0x%x", ret);
1239 int recorder_commit(recorder_h recorder)
1241 if (recorder == NULL) {
1242 LOGE("NULL pointer handle");
1243 return RECORDER_ERROR_INVALID_PARAMETER;
1245 int ret = RECORDER_ERROR_NONE;
1246 muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1247 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1249 if (pc->cb_info == NULL) {
1250 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1251 return RECORDER_ERROR_INVALID_PARAMETER;
1253 sock_fd = pc->cb_info->fd;
1257 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1258 LOGD("ret : 0x%x", ret);
1263 int recorder_cancel(recorder_h recorder)
1265 if (recorder == NULL) {
1266 LOGE("NULL pointer handle");
1267 return RECORDER_ERROR_INVALID_PARAMETER;
1269 int ret = RECORDER_ERROR_NONE;
1270 muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1271 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1273 if (pc->cb_info == NULL) {
1274 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1275 return RECORDER_ERROR_INVALID_PARAMETER;
1277 sock_fd = pc->cb_info->fd;
1281 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1282 LOGD("ret : 0x%x", ret);
1287 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1289 if (recorder == NULL) {
1290 LOGE("NULL pointer handle");
1291 return RECORDER_ERROR_INVALID_PARAMETER;
1293 int ret = RECORDER_ERROR_NONE;
1294 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1295 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1297 if (pc->cb_info == NULL) {
1298 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1299 return RECORDER_ERROR_INVALID_PARAMETER;
1301 sock_fd = pc->cb_info->fd;
1305 muse_recorder_msg_send2(api,
1311 LOGD("ret : 0x%x", ret);
1316 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
1318 if (recorder == NULL) {
1319 LOGE("NULL pointer handle");
1320 return RECORDER_ERROR_INVALID_PARAMETER;
1322 if (!width || !height) {
1323 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
1324 return RECORDER_ERROR_INVALID_PARAMETER;
1326 int ret = RECORDER_ERROR_NONE;
1327 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
1328 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1330 if (pc->cb_info == NULL) {
1331 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1332 return RECORDER_ERROR_INVALID_PARAMETER;
1334 sock_fd = pc->cb_info->fd;
1340 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1341 if (ret == RECORDER_ERROR_NONE) {
1342 muse_recorder_msg_get(get_width, pc->cb_info->recv_msg);
1343 muse_recorder_msg_get(get_height, pc->cb_info->recv_msg);
1345 *height = get_height;
1347 LOGD("ret : 0x%x", ret);
1352 int recorder_foreach_supported_video_resolution(recorder_h recorder,
1353 recorder_supported_video_resolution_cb foreach_cb, void *user_data)
1355 if (recorder == NULL || foreach_cb == NULL) {
1356 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1357 return RECORDER_ERROR_INVALID_PARAMETER;
1359 int ret = RECORDER_ERROR_NONE;
1361 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1362 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
1364 LOGD("Enter, handle :%x", pc->remote_handle);
1367 if (pc->cb_info == NULL) {
1368 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1369 return RECORDER_ERROR_INVALID_PARAMETER;
1371 sock_fd = pc->cb_info->fd;
1372 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
1373 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
1375 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1376 LOGD("ret : 0x%x", ret);
1381 int recorder_get_audio_level(recorder_h recorder, double *level)
1383 if (recorder == NULL || level == NULL) {
1384 LOGE("NULL pointer %p %p", recorder, level);
1385 return RECORDER_ERROR_INVALID_PARAMETER;
1388 int ret = RECORDER_ERROR_NONE;
1389 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
1390 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1392 if (pc->cb_info == NULL) {
1393 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1394 return RECORDER_ERROR_INVALID_PARAMETER;
1396 sock_fd = pc->cb_info->fd;
1401 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1402 if (ret == RECORDER_ERROR_NONE) {
1403 muse_recorder_msg_get_double(get_level, pc->cb_info->recv_msg);
1406 LOGD("ret : 0x%x", ret);
1411 int recorder_set_filename(recorder_h recorder, const char *filename)
1413 if (recorder == NULL) {
1414 LOGE("handle is NULL");
1415 return RECORDER_ERROR_INVALID_PARAMETER;
1418 if (filename == NULL) {
1419 LOGE("filename is NULL");
1420 return RECORDER_ERROR_INVALID_PARAMETER;
1422 int ret = RECORDER_ERROR_NONE;
1423 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
1424 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1426 if (pc->cb_info == NULL) {
1427 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1428 return RECORDER_ERROR_INVALID_PARAMETER;
1430 sock_fd = pc->cb_info->fd;
1434 muse_recorder_msg_send1(api, sock_fd, pc->cb_info, ret, STRING, filename);
1435 LOGD("ret : 0x%x", ret);
1440 int recorder_get_filename(recorder_h recorder, char **filename)
1442 if (recorder == NULL) {
1443 LOGE("handle is NULL");
1444 return RECORDER_ERROR_INVALID_PARAMETER;
1447 if (filename == NULL) {
1448 LOGE("filename is NULL");
1449 return RECORDER_ERROR_INVALID_PARAMETER;
1451 int ret = RECORDER_ERROR_NONE;
1452 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
1453 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1455 if (pc->cb_info == NULL) {
1456 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1457 return RECORDER_ERROR_INVALID_PARAMETER;
1459 sock_fd = pc->cb_info->fd;
1460 char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {0,};
1464 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1466 if (ret == RECORDER_ERROR_NONE) {
1467 muse_recorder_msg_get_string(get_filename, pc->cb_info->recv_msg);
1468 *filename = strdup(get_filename);
1470 LOGD("ret : 0x%x, filename : %s", ret, *filename);
1475 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
1477 if (recorder == NULL) {
1478 LOGE("NULL pointer handle");
1479 return RECORDER_ERROR_INVALID_PARAMETER;
1481 if (format < RECORDER_FILE_FORMAT_3GP || format > RECORDER_FILE_FORMAT_M2TS) {
1482 LOGE("invalid format %d", format);
1483 return RECORDER_ERROR_INVALID_PARAMETER;
1485 int ret = RECORDER_ERROR_NONE;
1486 muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
1487 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1489 if (pc->cb_info == NULL) {
1490 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1491 return RECORDER_ERROR_INVALID_PARAMETER;
1493 sock_fd = pc->cb_info->fd;
1494 int set_format = (int)format;
1496 LOGD("ENTER, set_format : %d", set_format);
1498 muse_recorder_msg_send1(api, sock_fd, pc->cb_info, ret, INT, set_format);
1499 LOGD("ret : 0x%x", ret);
1504 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
1506 if (recorder == NULL) {
1507 LOGE("NULL pointer handle");
1508 return RECORDER_ERROR_INVALID_PARAMETER;
1510 if (format == NULL) {
1511 LOGE("NULL pointer data");
1512 return RECORDER_ERROR_INVALID_PARAMETER;
1514 int ret = RECORDER_ERROR_NONE;
1515 muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
1516 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1518 if (pc->cb_info == NULL) {
1519 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1520 return RECORDER_ERROR_INVALID_PARAMETER;
1522 sock_fd = pc->cb_info->fd;
1527 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1529 if (ret == RECORDER_ERROR_NONE) {
1530 muse_recorder_msg_get(get_format, pc->cb_info->recv_msg);
1531 LOGD("get_fileformat : %d", get_format);
1532 *format = (recorder_file_format_e)get_format;
1534 LOGD("ret : 0x%x", ret);
1539 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
1541 int ret = RECORDER_ERROR_NONE;
1542 muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
1543 recorder_cli_s *pc = NULL;
1544 bool is_available = false;
1546 int stream_index = 0;
1547 char *stream_type = NULL;
1549 if (recorder == NULL || stream_info == NULL) {
1550 LOGE("NULL pointer handle");
1551 return RECORDER_ERROR_INVALID_PARAMETER;
1554 pc = (recorder_cli_s *)recorder;
1555 if (pc->cb_info == NULL) {
1556 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1557 return RECORDER_ERROR_INVALID_PARAMETER;
1560 sock_fd = pc->cb_info->fd;
1564 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
1565 if (ret != SOUND_MANAGER_ERROR_NONE) {
1566 LOGE("stream info verification failed");
1567 return RECORDER_ERROR_INVALID_OPERATION;
1570 if (is_available == false) {
1571 LOGE("stream information is not available");
1572 return RECORDER_ERROR_INVALID_OPERATION;
1575 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
1576 ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
1578 LOGD("sound manager return [0x%x]", ret);
1580 if (ret == SOUND_MANAGER_ERROR_NONE)
1581 muse_recorder_msg_send2(api, sock_fd, pc->cb_info, ret, STRING, stream_type, INT, stream_index);
1583 ret = RECORDER_ERROR_INVALID_OPERATION;
1589 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void* user_data)
1591 if (recorder == NULL || callback == NULL) {
1592 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1593 return RECORDER_ERROR_INVALID_PARAMETER;
1595 int ret = RECORDER_ERROR_NONE;
1597 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1598 muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
1600 LOGD("Enter, handle :%x", pc->remote_handle);
1603 if (pc->cb_info == NULL) {
1604 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1605 return RECORDER_ERROR_INVALID_PARAMETER;
1607 sock_fd = pc->cb_info->fd;
1608 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
1609 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
1611 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1612 LOGD("ret : 0x%x", ret);
1617 int recorder_unset_state_changed_cb(recorder_h recorder)
1619 if (recorder == NULL) {
1620 LOGE("NULL pointer handle");
1621 return RECORDER_ERROR_INVALID_PARAMETER;
1623 int ret = RECORDER_ERROR_NONE;
1624 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
1625 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1627 if (pc->cb_info == NULL) {
1628 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1629 return RECORDER_ERROR_INVALID_PARAMETER;
1631 sock_fd = pc->cb_info->fd;
1635 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1636 LOGD("ret : 0x%x", ret);
1641 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
1643 if (recorder == NULL || callback == NULL) {
1644 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1645 return RECORDER_ERROR_INVALID_PARAMETER;
1647 int ret = RECORDER_ERROR_NONE;
1649 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1650 muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
1652 LOGD("Enter, handle :%x", pc->remote_handle);
1655 if (pc->cb_info == NULL) {
1656 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1657 return RECORDER_ERROR_INVALID_PARAMETER;
1659 sock_fd = pc->cb_info->fd;
1660 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
1661 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
1663 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1664 LOGD("ret : 0x%x", ret);
1669 int recorder_unset_interrupted_cb(recorder_h recorder)
1671 if (recorder == NULL) {
1672 LOGE("NULL pointer handle");
1673 return RECORDER_ERROR_INVALID_PARAMETER;
1675 int ret = RECORDER_ERROR_NONE;
1676 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
1677 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1679 if (pc->cb_info == NULL) {
1680 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1681 return RECORDER_ERROR_INVALID_PARAMETER;
1683 sock_fd = pc->cb_info->fd;
1687 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1688 LOGD("ret : 0x%x", ret);
1693 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void* user_data)
1695 if (recorder == NULL || callback == NULL) {
1696 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1697 return RECORDER_ERROR_INVALID_PARAMETER;
1699 int ret = RECORDER_ERROR_NONE;
1701 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1702 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_STREAM_CB;
1704 LOGD("Enter, handle :%x", pc->remote_handle);
1707 if (pc->cb_info == NULL) {
1708 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1709 return RECORDER_ERROR_INVALID_PARAMETER;
1711 sock_fd = pc->cb_info->fd;
1712 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
1713 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
1715 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1716 LOGD("ret : 0x%x", ret);
1721 int recorder_unset_audio_stream_cb(recorder_h recorder)
1723 if (recorder == NULL) {
1724 LOGE("NULL pointer handle");
1725 return RECORDER_ERROR_INVALID_PARAMETER;
1727 int ret = RECORDER_ERROR_NONE;
1728 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
1729 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1731 if (pc->cb_info == NULL) {
1732 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1733 return RECORDER_ERROR_INVALID_PARAMETER;
1735 sock_fd = pc->cb_info->fd;
1739 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1740 LOGD("ret : 0x%x", ret);
1745 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
1747 if (recorder == NULL || callback == NULL) {
1748 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1749 return RECORDER_ERROR_INVALID_PARAMETER;
1751 int ret = RECORDER_ERROR_NONE;
1753 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1754 muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
1756 LOGD("Enter, handle :%x", pc->remote_handle);
1759 if (pc->cb_info == NULL) {
1760 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1761 return RECORDER_ERROR_INVALID_PARAMETER;
1763 sock_fd = pc->cb_info->fd;
1764 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
1765 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
1767 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1768 LOGD("ret : 0x%x", ret);
1773 int recorder_unset_error_cb(recorder_h recorder)
1775 if (recorder == NULL) {
1776 LOGE("NULL pointer handle");
1777 return RECORDER_ERROR_INVALID_PARAMETER;
1779 int ret = RECORDER_ERROR_NONE;
1780 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
1781 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1783 if (pc->cb_info == NULL) {
1784 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1785 return RECORDER_ERROR_INVALID_PARAMETER;
1787 sock_fd = pc->cb_info->fd;
1791 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1792 LOGD("ret : 0x%x", ret);
1797 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void* user_data)
1799 if (recorder == NULL || callback == NULL) {
1800 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1801 return RECORDER_ERROR_INVALID_PARAMETER;
1803 int ret = RECORDER_ERROR_NONE;
1805 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1806 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
1808 LOGD("Enter, handle :%x", pc->remote_handle);
1811 if (pc->cb_info == NULL) {
1812 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1813 return RECORDER_ERROR_INVALID_PARAMETER;
1815 sock_fd = pc->cb_info->fd;
1816 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
1817 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
1819 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1820 LOGD("ret : 0x%x", ret);
1825 int recorder_unset_recording_status_cb(recorder_h recorder)
1827 if (recorder == NULL) {
1828 LOGE("NULL pointer handle");
1829 return RECORDER_ERROR_INVALID_PARAMETER;
1831 int ret = RECORDER_ERROR_NONE;
1832 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
1833 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1835 if (pc->cb_info == NULL) {
1836 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1837 return RECORDER_ERROR_INVALID_PARAMETER;
1839 sock_fd = pc->cb_info->fd;
1843 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1844 LOGD("ret : 0x%x", ret);
1849 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void* user_data)
1851 if (recorder == NULL || callback == NULL) {
1852 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1853 return RECORDER_ERROR_INVALID_PARAMETER;
1855 int ret = RECORDER_ERROR_NONE;
1857 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1858 muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
1860 LOGD("Enter, handle :%x", pc->remote_handle);
1863 if (pc->cb_info == NULL) {
1864 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1865 return RECORDER_ERROR_INVALID_PARAMETER;
1867 sock_fd = pc->cb_info->fd;
1868 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
1869 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
1871 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1872 LOGD("ret : 0x%x", ret);
1877 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
1879 if (recorder == NULL) {
1880 LOGE("NULL pointer handle");
1881 return RECORDER_ERROR_INVALID_PARAMETER;
1883 int ret = RECORDER_ERROR_NONE;
1884 muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
1885 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1887 if (pc->cb_info == NULL) {
1888 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1889 return RECORDER_ERROR_INVALID_PARAMETER;
1891 sock_fd = pc->cb_info->fd;
1895 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1896 LOGD("ret : 0x%x", ret);
1901 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
1903 if (recorder == NULL || foreach_cb == NULL) {
1904 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1905 return RECORDER_ERROR_INVALID_PARAMETER;
1907 int ret = RECORDER_ERROR_NONE;
1909 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1910 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
1912 LOGD("Enter, handle :%x", pc->remote_handle);
1915 if (pc->cb_info == NULL) {
1916 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1917 return RECORDER_ERROR_INVALID_PARAMETER;
1919 sock_fd = pc->cb_info->fd;
1920 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
1921 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
1923 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
1924 LOGD("ret : 0x%x", ret);
1929 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
1931 if (recorder == NULL) {
1932 LOGE("NULL pointer handle");
1933 return RECORDER_ERROR_INVALID_PARAMETER;
1935 int ret = RECORDER_ERROR_NONE;
1936 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
1937 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1939 if (pc->cb_info == NULL) {
1940 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1941 return RECORDER_ERROR_INVALID_PARAMETER;
1943 sock_fd = pc->cb_info->fd;
1947 muse_recorder_msg_send1(api,
1952 LOGD("ret : 0x%x", ret);
1957 int recorder_attr_set_time_limit(recorder_h recorder, int second)
1959 if (recorder == NULL) {
1960 LOGE("NULL pointer handle");
1961 return RECORDER_ERROR_INVALID_PARAMETER;
1963 int ret = RECORDER_ERROR_NONE;
1964 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
1965 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1967 if (pc->cb_info == NULL) {
1968 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1969 return RECORDER_ERROR_INVALID_PARAMETER;
1971 sock_fd = pc->cb_info->fd;
1975 muse_recorder_msg_send1(api,
1980 LOGD("ret : 0x%x", ret);
1985 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
1987 if (recorder == NULL) {
1988 LOGE("NULL pointer handle");
1989 return RECORDER_ERROR_INVALID_PARAMETER;
1991 int ret = RECORDER_ERROR_NONE;
1992 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
1993 recorder_cli_s *pc = (recorder_cli_s *)recorder;
1995 if (pc->cb_info == NULL) {
1996 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
1997 return RECORDER_ERROR_INVALID_PARAMETER;
1999 sock_fd = pc->cb_info->fd;
2000 int set_device = (int)device;
2004 muse_recorder_msg_send1(api,
2009 LOGD("ret : 0x%x", ret);
2014 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2016 if (recorder == NULL) {
2017 LOGE("NULL pointer handle");
2018 return RECORDER_ERROR_INVALID_PARAMETER;
2020 if (codec != RECORDER_AUDIO_CODEC_DISABLE &&
2021 (codec < RECORDER_AUDIO_CODEC_AMR || codec > RECORDER_AUDIO_CODEC_PCM)) {
2022 LOGE("invalid parameter : codec %d", codec);
2023 return RECORDER_ERROR_INVALID_PARAMETER;
2025 int ret = RECORDER_ERROR_NONE;
2026 muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2027 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2029 if (pc->cb_info == NULL) {
2030 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2031 return RECORDER_ERROR_INVALID_PARAMETER;
2033 sock_fd = pc->cb_info->fd;
2034 int set_codec = (int)codec;
2038 muse_recorder_msg_send1(api,
2043 LOGD("ret : 0x%x", ret);
2048 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2050 if (recorder == NULL) {
2051 LOGE("NULL pointer handle");
2052 return RECORDER_ERROR_INVALID_PARAMETER;
2054 if (codec == NULL) {
2055 LOGE("codec is NULL");
2056 return RECORDER_ERROR_INVALID_PARAMETER;
2058 int ret = RECORDER_ERROR_NONE;
2059 muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2060 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2062 if (pc->cb_info == NULL) {
2063 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2064 return RECORDER_ERROR_INVALID_PARAMETER;
2066 sock_fd = pc->cb_info->fd;
2071 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2072 if (ret == RECORDER_ERROR_NONE) {
2073 muse_recorder_msg_get(get_codec, pc->cb_info->recv_msg);
2074 *codec = (recorder_audio_codec_e)get_codec;
2076 LOGD("ret : 0x%x", ret);
2081 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2083 if (recorder == NULL) {
2084 LOGE("NULL pointer handle");
2085 return RECORDER_ERROR_INVALID_PARAMETER;
2087 if (codec < RECORDER_VIDEO_CODEC_H263 || codec > RECORDER_VIDEO_CODEC_THEORA) {
2088 LOGE("invalid codec %d", codec);
2089 return RECORDER_ERROR_INVALID_PARAMETER;
2091 int ret = RECORDER_ERROR_NONE;
2092 muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2093 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2095 if (pc->cb_info == NULL) {
2096 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2097 return RECORDER_ERROR_INVALID_PARAMETER;
2099 sock_fd = pc->cb_info->fd;
2100 int set_codec = (int)codec;
2104 muse_recorder_msg_send1(api,
2109 LOGD("ret : 0x%x", ret);
2114 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2116 if (recorder == NULL) {
2117 LOGE("NULL pointer handle");
2118 return RECORDER_ERROR_INVALID_PARAMETER;
2120 if (codec == NULL) {
2121 LOGE("codec is NULL");
2122 return RECORDER_ERROR_INVALID_PARAMETER;
2124 int ret = RECORDER_ERROR_NONE;
2125 muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2126 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2128 if (pc->cb_info == NULL) {
2129 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2130 return RECORDER_ERROR_INVALID_PARAMETER;
2132 sock_fd = pc->cb_info->fd;
2137 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2138 if (ret == RECORDER_ERROR_NONE) {
2139 muse_recorder_msg_get(get_codec, pc->cb_info->recv_msg);
2140 *codec = (recorder_audio_codec_e)get_codec;
2142 LOGD("ret : 0x%x", ret);
2147 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2149 if (recorder == NULL) {
2150 LOGE("NULL pointer handle");
2151 return RECORDER_ERROR_INVALID_PARAMETER;
2153 if (samplerate < 1) {
2154 LOGE("invalid samplerate %d", samplerate);
2155 return RECORDER_ERROR_INVALID_PARAMETER;
2157 int ret = RECORDER_ERROR_NONE;
2158 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2159 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2161 if (pc->cb_info == NULL) {
2162 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2163 return RECORDER_ERROR_INVALID_PARAMETER;
2165 sock_fd = pc->cb_info->fd;
2167 LOGD("ENTER, samplerate : %d", samplerate);
2169 muse_recorder_msg_send1(api,
2174 LOGD("ret : 0x%x, samplerate : %d", ret, samplerate);
2179 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2181 if (recorder == NULL) {
2182 LOGE("NULL pointer handle");
2183 return RECORDER_ERROR_INVALID_PARAMETER;
2186 LOGE("invalid bitrate %d", bitrate);
2187 return RECORDER_ERROR_INVALID_PARAMETER;
2189 int ret = RECORDER_ERROR_NONE;
2190 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2191 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2193 if (pc->cb_info == NULL) {
2194 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2195 return RECORDER_ERROR_INVALID_PARAMETER;
2197 sock_fd = pc->cb_info->fd;
2201 muse_recorder_msg_send1(api,
2206 LOGD("ret : 0x%x", ret);
2211 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2213 if (recorder == NULL) {
2214 LOGE("NULL pointer handle");
2215 return RECORDER_ERROR_INVALID_PARAMETER;
2218 int ret = RECORDER_ERROR_NONE;
2219 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2220 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2222 if (pc->cb_info == NULL) {
2223 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2224 return RECORDER_ERROR_INVALID_PARAMETER;
2226 sock_fd = pc->cb_info->fd;
2230 muse_recorder_msg_send1(api,
2235 LOGD("ret : 0x%x", ret);
2240 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2242 if (recorder == NULL) {
2243 LOGE("NULL pointer handle");
2244 return RECORDER_ERROR_INVALID_PARAMETER;
2246 if (kbyte == NULL) {
2247 LOGE("NULL pointer kbyte");
2248 return RECORDER_ERROR_INVALID_PARAMETER;
2250 int ret = RECORDER_ERROR_NONE;
2251 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2252 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2254 if (pc->cb_info == NULL) {
2255 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2256 return RECORDER_ERROR_INVALID_PARAMETER;
2258 sock_fd = pc->cb_info->fd;
2263 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2264 if (ret == RECORDER_ERROR_NONE) {
2265 muse_recorder_msg_get(get_kbyte, pc->cb_info->recv_msg);
2268 LOGD("ret : 0x%x", ret);
2273 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
2275 if (recorder == NULL) {
2276 LOGE("NULL pointer handle");
2277 return RECORDER_ERROR_INVALID_PARAMETER;
2279 if (second == NULL) {
2280 LOGE("NULL pointer second");
2281 return RECORDER_ERROR_INVALID_PARAMETER;
2283 int ret = RECORDER_ERROR_NONE;
2284 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
2285 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2287 if (pc->cb_info == NULL) {
2288 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2289 return RECORDER_ERROR_INVALID_PARAMETER;
2291 sock_fd = pc->cb_info->fd;
2296 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2297 if (ret == RECORDER_ERROR_NONE) {
2298 muse_recorder_msg_get(get_second, pc->cb_info->recv_msg);
2299 *second = get_second;
2301 LOGD("ret : 0x%x", ret);
2306 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
2308 if (recorder == NULL) {
2309 LOGE("NULL pointer handle");
2310 return RECORDER_ERROR_INVALID_PARAMETER;
2312 if (device == NULL) {
2313 LOGE("NULL pointer device");
2314 return RECORDER_ERROR_INVALID_PARAMETER;
2316 int ret = RECORDER_ERROR_NONE;
2317 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
2318 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2320 if (pc->cb_info == NULL) {
2321 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2322 return RECORDER_ERROR_INVALID_PARAMETER;
2324 sock_fd = pc->cb_info->fd;
2329 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2330 if (ret == RECORDER_ERROR_NONE) {
2331 muse_recorder_msg_get(get_device, pc->cb_info->recv_msg);
2332 *device = (recorder_audio_device_e)get_device;
2335 LOGD("ret : 0x%x", ret);
2340 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
2342 if (recorder == NULL) {
2343 LOGE("NULL pointer handle");
2344 return RECORDER_ERROR_INVALID_PARAMETER;
2346 if (samplerate == NULL) {
2347 LOGE("NULL pointer handle");
2348 return RECORDER_ERROR_INVALID_PARAMETER;
2350 int ret = RECORDER_ERROR_NONE;
2351 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
2352 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2354 if (pc->cb_info == NULL) {
2355 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2356 return RECORDER_ERROR_INVALID_PARAMETER;
2358 sock_fd = pc->cb_info->fd;
2363 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2364 if (ret == RECORDER_ERROR_NONE) {
2365 muse_recorder_msg_get(get_samplerate, pc->cb_info->recv_msg);
2366 *samplerate = get_samplerate;
2368 LOGD("ret : 0x%x, get_samplerate : %d", ret, get_samplerate);
2373 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
2375 if (recorder == NULL) {
2376 LOGE("NULL pointer handle");
2377 return RECORDER_ERROR_INVALID_PARAMETER;
2379 if (bitrate == NULL) {
2380 LOGE("NULL pointer");
2381 return RECORDER_ERROR_INVALID_PARAMETER;
2383 int ret = RECORDER_ERROR_NONE;
2384 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
2385 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2387 if (pc->cb_info == NULL) {
2388 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2389 return RECORDER_ERROR_INVALID_PARAMETER;
2391 sock_fd = pc->cb_info->fd;
2396 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2397 if (ret == RECORDER_ERROR_NONE) {
2398 muse_recorder_msg_get(get_bitrate, pc->cb_info->recv_msg);
2399 *bitrate = get_bitrate;
2401 LOGD("ret : 0x%x", ret);
2406 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
2408 if (recorder == NULL) {
2409 LOGE("NULL pointer handle");
2410 return RECORDER_ERROR_INVALID_PARAMETER;
2412 if (bitrate == NULL) {
2413 LOGE("NULL pointer");
2414 return RECORDER_ERROR_INVALID_PARAMETER;
2416 int ret = RECORDER_ERROR_NONE;
2417 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
2418 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2420 if (pc->cb_info == NULL) {
2421 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2422 return RECORDER_ERROR_INVALID_PARAMETER;
2424 sock_fd = pc->cb_info->fd;
2429 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2430 if (ret == RECORDER_ERROR_NONE) {
2431 muse_recorder_msg_get(get_bitrate, pc->cb_info->recv_msg);
2432 *bitrate = get_bitrate;
2434 LOGD("ret : 0x%x", ret);
2439 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
2441 if (recorder == NULL || foreach_cb == NULL) {
2442 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2443 return RECORDER_ERROR_INVALID_PARAMETER;
2445 int ret = RECORDER_ERROR_NONE;
2447 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2448 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
2450 LOGD("Enter, handle :%x", pc->remote_handle);
2453 if (pc->cb_info == NULL) {
2454 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2455 return RECORDER_ERROR_INVALID_PARAMETER;
2457 sock_fd = pc->cb_info->fd;
2458 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
2459 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
2461 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2462 LOGD("ret : 0x%x", ret);
2467 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
2469 if (recorder == NULL || foreach_cb == NULL) {
2470 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2471 return RECORDER_ERROR_INVALID_PARAMETER;
2473 int ret = RECORDER_ERROR_NONE;
2475 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2476 muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
2478 LOGD("Enter, handle :%x", pc->remote_handle);
2481 if (pc->cb_info == NULL) {
2482 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2483 return RECORDER_ERROR_INVALID_PARAMETER;
2485 sock_fd = pc->cb_info->fd;
2486 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
2487 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
2489 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2490 LOGD("ret : 0x%x", ret);
2495 int recorder_attr_set_mute(recorder_h recorder, bool enable)
2497 if (recorder == NULL) {
2498 LOGE("NULL pointer handle");
2499 return RECORDER_ERROR_INVALID_PARAMETER;
2501 int ret = RECORDER_ERROR_NONE;
2502 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
2503 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2505 if (pc->cb_info == NULL) {
2506 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2507 return RECORDER_ERROR_INVALID_PARAMETER;
2509 sock_fd = pc->cb_info->fd;
2510 int set_enable = (int)enable;
2514 muse_recorder_msg_send1(api, sock_fd, pc->cb_info, ret, INT, set_enable);
2516 LOGD("ret : 0x%x", ret);
2522 bool recorder_attr_is_muted(recorder_h recorder)
2524 if (recorder == NULL) {
2525 LOGE("NULL pointer handle");
2528 int ret = RECORDER_ERROR_NONE;
2529 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
2530 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2532 if (pc->cb_info == NULL) {
2533 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2534 return RECORDER_ERROR_INVALID_PARAMETER;
2536 sock_fd = pc->cb_info->fd;
2540 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2541 LOGD("ret : 0x%x", ret);
2546 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
2548 if (recorder == NULL) {
2549 LOGE("NULL pointer handle");
2550 return RECORDER_ERROR_INVALID_PARAMETER;
2552 int ret = RECORDER_ERROR_NONE;
2553 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
2554 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2556 if (pc->cb_info == NULL) {
2557 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2558 return RECORDER_ERROR_INVALID_PARAMETER;
2560 sock_fd = pc->cb_info->fd;
2562 LOGD("ENTER - %.20lf", rate);
2564 muse_recorder_msg_send1(api,
2570 LOGD("ret : 0x%x", ret);
2576 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
2578 if (recorder == NULL) {
2579 LOGE("NULL pointer handle");
2580 return RECORDER_ERROR_INVALID_PARAMETER;
2583 LOGE("rate is NULL");
2584 return RECORDER_ERROR_INVALID_PARAMETER;
2586 int ret = RECORDER_ERROR_NONE;
2587 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
2588 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2590 if (pc->cb_info == NULL) {
2591 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2592 return RECORDER_ERROR_INVALID_PARAMETER;
2594 sock_fd = pc->cb_info->fd;
2599 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2600 if (ret == RECORDER_ERROR_NONE) {
2601 muse_recorder_msg_get_double(get_rate, pc->cb_info->recv_msg);
2604 LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
2609 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
2611 if (recorder == NULL) {
2612 LOGE("NULL pointer handle");
2613 return RECORDER_ERROR_INVALID_PARAMETER;
2615 if (channel_count < 1) {
2616 LOGE("invalid channel %d", channel_count);
2617 return RECORDER_ERROR_INVALID_PARAMETER;
2619 int ret = RECORDER_ERROR_NONE;
2620 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
2621 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2623 if (pc->cb_info == NULL) {
2624 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2625 return RECORDER_ERROR_INVALID_PARAMETER;
2627 sock_fd = pc->cb_info->fd;
2631 muse_recorder_msg_send1(api,
2635 INT, channel_count);
2636 LOGD("ret : 0x%x", ret);
2641 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
2643 if (recorder == NULL) {
2644 LOGE("NULL pointer handle");
2645 return RECORDER_ERROR_INVALID_PARAMETER;
2647 if (channel_count == NULL) {
2648 LOGE("channel_count is NULL");
2649 return RECORDER_ERROR_INVALID_PARAMETER;
2651 int ret = RECORDER_ERROR_NONE;
2652 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
2653 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2655 if (pc->cb_info == NULL) {
2656 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2657 return RECORDER_ERROR_INVALID_PARAMETER;
2659 sock_fd = pc->cb_info->fd;
2660 int get_channel_count;
2664 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2665 if (ret == RECORDER_ERROR_NONE) {
2666 muse_recorder_msg_get(get_channel_count, pc->cb_info->recv_msg);
2667 *channel_count = get_channel_count;
2669 LOGD("ret : 0x%x", ret);
2674 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
2676 if (recorder == NULL) {
2677 LOGE("NULL pointer handle");
2678 return RECORDER_ERROR_INVALID_PARAMETER;
2680 if (orientation > RECORDER_ROTATION_270) {
2681 LOGE("invalid orientation %d", orientation);
2682 return RECORDER_ERROR_INVALID_PARAMETER;
2684 int ret = RECORDER_ERROR_NONE;
2685 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
2686 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2688 if (pc->cb_info == NULL) {
2689 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2690 return RECORDER_ERROR_INVALID_PARAMETER;
2692 sock_fd = pc->cb_info->fd;
2693 int set_orientation = (int)orientation;
2697 muse_recorder_msg_send1(api,
2701 INT, set_orientation);
2702 LOGD("ret : 0x%x", ret);
2707 int recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
2709 if (recorder == NULL) {
2710 LOGE("NULL pointer handle");
2711 return RECORDER_ERROR_INVALID_PARAMETER;
2713 if (orientation == NULL) {
2714 LOGE("orientation is NULL");
2715 return RECORDER_ERROR_INVALID_PARAMETER;
2717 int ret = RECORDER_ERROR_NONE;
2718 muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
2719 recorder_cli_s *pc = (recorder_cli_s *)recorder;
2721 if (pc->cb_info == NULL) {
2722 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2723 return RECORDER_ERROR_INVALID_PARAMETER;
2725 sock_fd = pc->cb_info->fd;
2726 int get_orientation;
2730 muse_recorder_msg_send(api, sock_fd, pc->cb_info, ret);
2731 if (ret == RECORDER_ERROR_NONE) {
2732 muse_recorder_msg_get(get_orientation, pc->cb_info->recv_msg);
2733 *orientation = (recorder_rotation_e)get_orientation;
2735 LOGD("ret : 0x%x", ret);