Merge branch 'tizen' into tizen_line_coverage
[platform/core/api/recorder.git] / src / recorder.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <camera_internal.h>
21 #include <recorder.h>
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
24 #include <storage.h>
25 #include <storage-internal.h>
26 #include <muse_recorder.h>
27 #include <muse_recorder_msg.h>
28 #include <muse_core_ipc.h>
29 #include <muse_core_module.h>
30 #include <recorder_private.h>
31 #include <glib.h>
32 #include <gio/gio.h>
33 #include <dlog.h>
34 #include <tzplatform_config.h>
35
36 #ifdef LOG_TAG
37 #undef LOG_TAG
38 #endif
39 #define LOG_TAG "TIZEN_N_RECORDER"
40
41 /* for device changed callback */
42 static GMutex g_rec_dev_state_changed_cb_lock;
43 static GList *g_rec_dev_state_changed_cb_list;
44 static int g_rec_dev_state_changed_cb_id;
45 static GDBusConnection *g_rec_dev_state_changed_cb_conn;
46 static guint g_rec_dev_state_changed_cb_subscribe_id;
47
48
49
50 static void __recorder_update_api_waiting(recorder_cb_info_s *cb_info, int api, int value)
51 {
52         if (!cb_info ||
53                 api < 0 || api >= MUSE_RECORDER_API_MAX) {
54                 LOGE("invalid param %p %d", cb_info, api);
55                 return;
56         }
57
58         g_mutex_lock(&(cb_info->api_mutex[api]));
59         cb_info->api_waiting[api] += value;
60         g_mutex_unlock(&(cb_info->api_mutex[api]));
61
62         /*LOGD("api %d, value %d, waiting %d",
63                 api, value, cb_info->api_waiting[api]);*/
64
65         return;
66 }
67
68
69 static void __recorder_device_state_changed_cb(GDBusConnection *connection,
70         const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
71         const gchar *signal_name, GVariant *param, gpointer user_data)
72 {
73         int value = 0;
74         recorder_type_e type = RECORDER_TYPE_AUDIO;
75         recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
76         GList *tmp_list = NULL;
77         recorder_cb_info *info = NULL;
78
79         g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
80
81         if (!g_rec_dev_state_changed_cb_list || !param) {
82                 LOGW("no callback or NULL param %p", param);
83                 goto _DONE;
84         }
85
86         /* get device type and state */
87         g_variant_get(param, "(i)", &value);
88
89         type = value >> 16;
90         state = 0x0000ffff & value;
91
92         LOGD("type %d, state %d", type, state);
93
94         tmp_list = g_rec_dev_state_changed_cb_list;
95
96         do {
97                 info = (recorder_cb_info *)tmp_list->data;
98
99                 if (info) {
100                         if (info->callback) {
101                                 LOGD("start id[%d] callback", info->id);
102                                 ((recorder_device_state_changed_cb)info->callback)(type, state, info->user_data);
103                                 LOGD("returned id[%d] callback", info->id);
104                         } else {
105                                 LOGW("NULL callback for id %d", info->id);
106                         }
107                 }
108
109                 tmp_list = tmp_list->next;
110         } while (tmp_list);
111
112 _DONE:
113         g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
114
115         return;
116 }
117
118
119 static int _recorder_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
120 {
121         tbm_bo tmp_bo = NULL;
122         tbm_bo_handle tmp_bo_handle = {NULL, };
123
124         if (bufmgr == NULL || bo == NULL || bo_handle == NULL || tbm_key == 0) {
125                 LOGE("invalid parameter - bufmgr %p, bo %p, bo_handle %p, key %d",
126                      bufmgr, bo, bo_handle, tbm_key);
127                 return false;
128         }
129
130         tmp_bo = tbm_bo_import(bufmgr, tbm_key);
131         if (tmp_bo == NULL) {
132                 LOGE("bo import failed - bufmgr %p, key %d", bufmgr, tbm_key);
133                 return false;
134         }
135
136         tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
137         if (tmp_bo_handle.ptr == NULL) {
138                 LOGE("bo map failed %p", tmp_bo);
139                 tbm_bo_unref(tmp_bo);
140                 tmp_bo = NULL;
141                 return false;
142         }
143
144         /* set bo and bo_handle */
145         *bo = tmp_bo;
146         *bo_handle = tmp_bo_handle;
147
148         return true;
149 }
150
151 static void _recorder_release_imported_bo(tbm_bo *bo)
152 {
153         if (bo == NULL || *bo == NULL) {
154                 LOGW("NULL bo");
155                 return;
156         }
157
158         tbm_bo_unmap(*bo);
159         tbm_bo_unref(*bo);
160         *bo = NULL;
161
162         return;
163 }
164
165 static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *recv_msg, muse_recorder_event_e event)
166 {
167         if (recv_msg == NULL || event >= MUSE_RECORDER_EVENT_TYPE_NUM) {
168                 LOGE("invalid parameter - recorder msg %p, event %d", recv_msg, event);
169                 return;
170         }
171
172         /*LOGD("get recorder msg %s, event %d", recv_msg, event);*/
173
174         if (cb_info->user_cb[event] == NULL) {
175                 LOGW("user callback for event %d is not set", event);
176                 return;
177         }
178
179         switch (event) {
180         case MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE:
181                 {
182                         int previous = 0;
183                         int current = 0;
184                         int by_policy = 0;
185
186                         muse_recorder_msg_get(previous, recv_msg);
187                         muse_recorder_msg_get(current, recv_msg);
188                         muse_recorder_msg_get(by_policy, recv_msg);
189
190                         ((recorder_state_changed_cb)cb_info->user_cb[event])((recorder_state_e)previous,
191                                 (recorder_state_e)current,
192                                 (bool)by_policy,
193                                 cb_info->user_data[event]);
194                         break;
195                 }
196         case MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED:
197                 {
198                         int type = 0;
199
200                         muse_recorder_msg_get(type, recv_msg);
201
202                         ((recorder_recording_limit_reached_cb)cb_info->user_cb[event])((recorder_recording_limit_type_e)type,
203                                 cb_info->user_data[event]);
204                         break;
205                 }
206         case MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS:
207                 {
208                         int64_t cb_elapsed_time = 0;
209                         int64_t cb_file_size = 0;
210
211                         muse_recorder_msg_get(cb_elapsed_time, recv_msg);
212                         muse_recorder_msg_get(cb_file_size, recv_msg);
213
214                         ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
215                                 (unsigned long long)cb_file_size,
216                                 cb_info->user_data[event]);
217                         break;
218                 }
219         case MUSE_RECORDER_EVENT_TYPE_INTERRUPTED:
220                 {
221                         int policy = 0;
222                         int previous = 0;
223                         int current = 0;
224
225                         muse_recorder_msg_get(policy, recv_msg);
226                         muse_recorder_msg_get(previous, recv_msg);
227                         muse_recorder_msg_get(current, recv_msg);
228
229                         if (policy == RECORDER_POLICY_SOUND)
230                                 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
231                         else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
232                                 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
233                         else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
234                                 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
235
236                         ((recorder_interrupted_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
237                                 (recorder_state_e)previous,
238                                 (recorder_state_e)current,
239                                 cb_info->user_data[event]);
240                         break;
241                 }
242         case MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED:
243                 {
244                         int policy = 0;
245                         int state = 0;
246
247                         muse_recorder_msg_get(policy, recv_msg);
248                         muse_recorder_msg_get(state, recv_msg);
249
250                         LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
251
252                         if (policy == RECORDER_POLICY_SOUND)
253                                 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND is deprecated and will be removed from next release.");
254                         else if (policy == RECORDER_POLICY_SOUND_BY_CALL)
255                                 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
256                         else if (policy == RECORDER_POLICY_SOUND_BY_ALARM)
257                                 LOGW("DEPRECATION WARNING: RECORDER_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
258
259                         ((recorder_interrupt_started_cb)cb_info->user_cb[event])((recorder_policy_e)policy,
260                                 (recorder_state_e)state, cb_info->user_data[event]);
261                 }
262                 break;
263         case MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM:
264                 {
265                         int tbm_key = 0;
266                         int size = 0;
267                         int format = 0;
268                         int channel = 0;
269                         int timestamp = 0;
270                         tbm_bo bo = NULL;
271                         tbm_bo_handle bo_handle = {.ptr = NULL};
272                         char *send_msg = NULL;
273
274                         muse_recorder_msg_get(tbm_key, recv_msg);
275                         if (tbm_key == 0) {
276                                 LOGE("invalid key");
277                                 break;
278                         }
279
280                         if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
281                                 LOGE("tbm key %d import failed", tbm_key);
282                                 break;
283                         }
284
285                         muse_recorder_msg_get(size, recv_msg);
286                         muse_recorder_msg_get(format, recv_msg);
287                         muse_recorder_msg_get(channel, recv_msg);
288                         muse_recorder_msg_get(timestamp, recv_msg);
289
290                         ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
291                                 size,
292                                 (audio_sample_type_e)format,
293                                 channel,
294                                 (unsigned int)timestamp,
295                                 cb_info->user_data[event]);
296
297                         /* release imported bo */
298                         _recorder_release_imported_bo(&bo);
299
300                         /* return buffer */
301                         send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
302                                 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
303
304                         if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
305                                 LOGE("sending message failed");
306
307                         muse_core_msg_json_factory_free(send_msg);
308                         break;
309                 }
310         case MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM:
311                 {
312                         int tbm_key = 0;
313                         int size = 0;
314                         int64_t offset = 0;
315
316                         tbm_bo bo = NULL;
317                         tbm_bo_handle bo_handle = {.ptr = NULL};
318                         char *send_msg = NULL;
319
320                         muse_recorder_msg_get(tbm_key, recv_msg);
321                         if (tbm_key == 0) {
322                                 LOGE("invalid key");
323                                 break;
324                         }
325
326                         if (!_recorder_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
327                                 LOGE("tbm key %d import failed", tbm_key);
328                                 break;
329                         }
330
331                         muse_recorder_msg_get(size, recv_msg);
332                         muse_recorder_msg_get(offset, recv_msg);
333
334                         ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
335                                 size, (unsigned long long)offset, cb_info->user_data[event]);
336
337                         /* release imported bo */
338                         _recorder_release_imported_bo(&bo);
339
340                         /* return buffer */
341                         send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_RETURN_BUFFER,
342                                 MUSE_TYPE_INT, "tbm_key", tbm_key, NULL);
343                         if (send_msg) {
344                                 if (muse_core_ipc_send_msg(cb_info->fd, send_msg) <= 0)
345                                         LOGE("sending message failed");
346
347                                 muse_core_msg_json_factory_free(send_msg);
348                                 send_msg = NULL;
349                         } else {
350                                 LOGE("failed to create send msg for key %d", tbm_key);
351                         }
352                         break;
353                 }
354 //LCOV_EXCL_START
355         case MUSE_RECORDER_EVENT_TYPE_ERROR:
356                 {
357                         int error = 0;
358                         int current_state = 0;
359
360                         muse_recorder_msg_get(error, recv_msg);
361                         muse_recorder_msg_get(current_state, recv_msg);
362
363                         if (error == RECORDER_ERROR_SOUND_POLICY)
364                                 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
365                         else if (error == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
366                                 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
367                         else if (error == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
368                                 LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
369
370                         ((recorder_error_cb)cb_info->user_cb[event])((recorder_error_e)error,
371                                 (recorder_state_e)current_state,
372                                 cb_info->user_data[event]);
373                         break;
374                 }
375 //LCOV_EXCL_STOP
376         case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER:
377                 {
378                         int codec = 0;
379
380                         muse_recorder_msg_get(codec, recv_msg);
381
382                         if (((recorder_supported_audio_encoder_cb)cb_info->user_cb[event])((recorder_audio_codec_e)codec, cb_info->user_data[event]) == false) {
383                                 cb_info->user_cb[event] = NULL;
384                                 cb_info->user_data[event] = NULL;
385                                 /*LOGD("stop foreach callback for SUPPORTED_AUDIO_ENCODER");*/
386                         }
387                         break;
388                 }
389         case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT:
390                 {
391                         int format = 0;
392
393                         muse_recorder_msg_get(format, recv_msg);
394
395                         if (((recorder_supported_file_format_cb)cb_info->user_cb[event])((recorder_file_format_e)format, cb_info->user_data[event]) == false) {
396                                 cb_info->user_cb[event] = NULL;
397                                 cb_info->user_data[event] = NULL;
398                                 /*LOGD("stop foreach callback for SUPPORTED_FILE_FORMAT");*/
399                         }
400                         break;
401                 }
402         case MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER:
403                 {
404                         int codec = 0;
405
406                         muse_recorder_msg_get(codec, recv_msg);
407
408                         if (((recorder_supported_video_encoder_cb)cb_info->user_cb[event])((recorder_video_codec_e)codec, cb_info->user_data[event]) == false) {
409                                 cb_info->user_cb[event] = NULL;
410                                 cb_info->user_data[event] = NULL;
411                                 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_ENCODER");*/
412                         }
413                         break;
414                 }
415         default: /* MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION */
416                 {
417                         int width = 0;
418                         int height = 0;
419
420                         muse_recorder_msg_get(width, recv_msg);
421                         muse_recorder_msg_get(height, recv_msg);
422
423                         if (((recorder_supported_video_resolution_cb)cb_info->user_cb[event])(width, height, cb_info->user_data[event]) == false) {
424                                 cb_info->user_cb[event] = NULL;
425                                 cb_info->user_data[event] = NULL;
426                                 /*LOGD("stop foreach callback for SUPPORTED_VIDEO_RESOLUTION");*/
427                         }
428                         break;
429                 }
430         }
431
432         return;
433 }
434
435
436 static bool _recorder_idle_event_callback(void *data)
437 {
438         recorder_cb_info_s *cb_info = NULL;
439         recorder_idle_event_s *rec_idle_event = (recorder_idle_event_s *)data;
440
441         if (rec_idle_event == NULL) {
442                 LOGE("rec_idle_event is NULL");
443                 return false;
444         }
445
446         /* lock event */
447         g_mutex_lock(&rec_idle_event->event_mutex);
448
449         cb_info = rec_idle_event->cb_info;
450         if (cb_info == NULL) {
451                 LOGW("recorder cb_info is NULL. event %p %d", rec_idle_event, rec_idle_event->event);
452                 goto IDLE_EVENT_CALLBACK_DONE;
453         }
454
455         /* remove event from list */
456         g_mutex_lock(&cb_info->idle_event_mutex);
457
458         if (cb_info->idle_event_list)
459                 cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
460
461         /*LOGD("remove recorder idle event %p, %p", rec_idle_event, cb_info->idle_event_list);*/
462         g_mutex_unlock(&cb_info->idle_event_mutex);
463
464         /* user callback */
465         _recorder_client_user_callback(cb_info, rec_idle_event->recv_msg, rec_idle_event->event);
466
467         /* send signal for waiting thread */
468         g_cond_signal(&cb_info->idle_event_cond);
469
470 IDLE_EVENT_CALLBACK_DONE:
471         /* unlock and release event */
472         g_mutex_unlock(&rec_idle_event->event_mutex);
473         g_mutex_clear(&rec_idle_event->event_mutex);
474
475         g_free(rec_idle_event);
476         rec_idle_event = NULL;
477
478         return false;
479 }
480
481
482 static void _recorder_deactivate_idle_event_all(recorder_cb_info_s *cb_info)
483 {
484         recorder_idle_event_s *rec_idle_event = NULL;
485         GList *list = NULL;
486         gint64 end_time = 0;
487
488         if (cb_info == NULL) {
489                 LOGE("cb_info is NULL");
490                 return;
491         }
492
493         g_mutex_lock(&cb_info->idle_event_mutex);
494
495         if (cb_info->idle_event_list == NULL) {
496                 LOGD("No event");
497         } else {
498                 list = cb_info->idle_event_list;
499
500                 while (list) {
501                         rec_idle_event = list->data;
502                         list = g_list_next(list);
503
504                         if (!rec_idle_event) {
505                                 LOGW("The event is NULL");
506                                 continue;
507                         }
508
509                         if (!g_mutex_trylock(&rec_idle_event->event_mutex)) {
510                                 LOGW("lock failed, %p event is calling now", rec_idle_event);
511
512                                 end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
513
514                                 if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
515                                         LOGW("signal received");
516                                 else
517                                         LOGW("timeout");
518
519                                 continue;
520                         }
521
522                         LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
523                                 rec_idle_event, rec_idle_event->event);
524
525                         rec_idle_event->cb_info = NULL;
526
527                         cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)rec_idle_event);
528
529                         g_mutex_unlock(&rec_idle_event->event_mutex);
530                 }
531
532                 g_list_free(cb_info->idle_event_list);
533                 cb_info->idle_event_list = NULL;
534         }
535
536         g_mutex_unlock(&cb_info->idle_event_mutex);
537
538         return;
539 }
540
541
542 static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
543 {
544         recorder_message_s *rec_msg = NULL;
545         recorder_msg_handler_info_s *msg_handler_info = NULL;
546
547         if (!cb_info || !msg) {
548                 LOGE("NULL pointer %p %p", cb_info, msg);
549                 return;
550         }
551
552         rec_msg = g_new0(recorder_message_s, 1);
553         if (!rec_msg) {
554                 LOGE("failed to alloc rec_msg for [%s]", msg);
555                 return;
556         }
557
558         rec_msg->api = api;
559         rec_msg->event = event;
560         rec_msg->event_class = event_class;
561
562         strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
563
564         /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
565
566         if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM)
567                 msg_handler_info = &cb_info->audio_stream_cb_info;
568         else if (event == MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM)
569                 msg_handler_info = &cb_info->muxed_stream_cb_info;
570         else
571                 msg_handler_info = &cb_info->msg_handler_info;
572
573         g_mutex_lock(&msg_handler_info->mutex);
574         g_queue_push_tail(msg_handler_info->queue, (gpointer)rec_msg);
575         g_cond_signal(&msg_handler_info->cond);
576         g_mutex_unlock(&msg_handler_info->mutex);
577
578         rec_msg = NULL;
579
580         return;
581 }
582
583
584 static void __recorder_get_api_operation(int api, recorder_cb_info_s *cb_info, char *msg)
585 {
586         if (!cb_info || !msg) {
587                 LOGE("NULL pointer %p %p", cb_info, msg);
588                 return;
589         }
590
591         switch (api) {
592         case MUSE_RECORDER_API_GET_STATE:
593                 {
594                         int get_state = 0;
595                         muse_recorder_msg_get(get_state, msg);
596                         cb_info->get_int_value[_RECORDER_GET_INT_STATE] = get_state;
597                 }
598                 break;
599         case MUSE_RECORDER_API_GET_VIDEO_RESOLUTION:
600                 {
601                         int get_width = 0;
602                         int get_height = 0;
603                         muse_recorder_msg_get(get_width, msg);
604                         muse_recorder_msg_get(get_height, msg);
605                         cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] = get_width << 16;
606                         cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] |= get_height;
607                 }
608                 break;
609         case MUSE_RECORDER_API_GET_FILE_FORMAT:
610                 {
611                         int get_format = 0;
612                         muse_recorder_msg_get(get_format, msg);
613                         cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT] = get_format;
614                 }
615                 break;
616         case MUSE_RECORDER_API_GET_AUDIO_ENCODER:
617                 {
618                         int get_codec = 0;
619                         muse_recorder_msg_get(get_codec, msg);
620                         cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER] = get_codec;
621                 }
622                 break;
623         case MUSE_RECORDER_API_GET_VIDEO_ENCODER:
624                 {
625                         int get_codec = 0;
626                         muse_recorder_msg_get(get_codec, msg);
627                         cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER] = get_codec;
628                 }
629                 break;
630         case MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT:
631                 {
632                         int get_kbyte = 0;
633                         muse_recorder_msg_get(get_kbyte, msg);
634                         cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT] = get_kbyte;
635                 }
636                 break;
637         case MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT:
638                 {
639                         int get_second = 0;
640                         muse_recorder_msg_get(get_second, msg);
641                         cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT] = get_second;
642                 }
643                 break;
644         case MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE:
645                 {
646                         int get_device = 0;
647                         muse_recorder_msg_get(get_device, msg);
648                         cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE] = get_device;
649                 }
650                 break;
651         case MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE:
652                 {
653                         int get_samplerate = 0;
654                         muse_recorder_msg_get(get_samplerate, msg);
655                         cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE] = get_samplerate;
656                 }
657                 break;
658         case MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE:
659                 {
660                         int get_bitrate = 0;
661                         muse_recorder_msg_get(get_bitrate, msg);
662                         cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE] = get_bitrate;
663                 }
664                 break;
665         case MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE:
666                 {
667                         int get_bitrate = 0;
668                         muse_recorder_msg_get(get_bitrate, msg);
669                         cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE] = get_bitrate;
670                 }
671                 break;
672         case MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE:
673                 {
674                         double get_rate = 0;
675                         muse_recorder_msg_get_double(get_rate, msg);
676                         cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE] = get_rate;
677                 }
678                 break;
679         case MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL:
680                 {
681                         int get_channel_count = 0;
682                         muse_recorder_msg_get(get_channel_count, msg);
683                         cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL] = get_channel_count;
684                 }
685                 break;
686         case MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG:
687                 {
688                         int get_orientation = 0;
689                         muse_recorder_msg_get(get_orientation, msg);
690                         cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG] = get_orientation;
691                 }
692                 break;
693         case MUSE_RECORDER_API_GET_AUDIO_LEVEL:
694                 {
695                         double get_level = 0.0;
696                         muse_recorder_msg_get_double(get_level, msg);
697                         cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL] = get_level;
698                 }
699                 break;
700         case MUSE_RECORDER_API_GET_FILENAME:
701                 {
702                         char get_filename[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
703                         muse_recorder_msg_get_string(get_filename, msg);
704                         if (cb_info->get_filename) {
705                                 free(cb_info->get_filename);
706                                 cb_info->get_filename = NULL;
707                         }
708                         cb_info->get_filename = strdup(get_filename);
709                 }
710                 break;
711         default:
712                 break;
713         }
714
715         return;
716 }
717
718
719 static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg)
720 {
721         int ret = RECORDER_ERROR_NONE;
722         int api = -1;
723         int api_class = -1;
724         int event = -1;
725         int event_class = -1;
726
727         if (!cb_info || !msg) {
728                 LOGE("invalid ptr %p %p", cb_info, msg);
729                 return;
730         }
731
732         /*LOGD("msg [%s]", msg);*/
733
734         if (!muse_recorder_msg_get(api, msg)) {
735                 LOGE("failed to get recorder api");
736                 return;
737         }
738
739         if (api == MUSE_RECORDER_CB_EVENT) {
740                 if (!muse_recorder_msg_get(event, msg) ||
741                         !muse_recorder_msg_get(event_class, msg)) {
742                         LOGE("failed to get event or event_class [%s]", msg);
743                         return;
744                 }
745         } else {
746                 if (!muse_recorder_msg_get(api_class, msg)) {
747                         LOGE("failed to get api_class [%s]", msg);
748                         return;
749                 }
750         }
751
752         if (api_class == MUSE_RECORDER_API_CLASS_IMMEDIATE) {
753                 if (api >= MUSE_RECORDER_API_MAX) {
754                         LOGE("invalid api %d", api);
755                         return;
756                 }
757
758                 if (!muse_recorder_msg_get(ret, msg)) {
759                         LOGE("failed to get recorder ret");
760                         return;
761                 }
762
763                 g_mutex_lock(&cb_info->api_mutex[api]);
764
765                 if (api == MUSE_RECORDER_API_GET_DEVICE_STATE) {
766                         g_atomic_int_set(&cb_info->msg_recv_running, 0);
767                         LOGD("get device state done. close client cb handler");
768                 } else {
769                         switch (api) {
770                         case MUSE_RECORDER_API_CREATE:
771                                 if (ret != RECORDER_ERROR_NONE) {
772                                         g_atomic_int_set(&cb_info->msg_recv_running, 0);
773                                         LOGE("create error 0x%x. closing..", ret);
774                                 }
775                                 break;
776                         case MUSE_RECORDER_API_DESTROY:
777                                 if (ret == RECORDER_ERROR_NONE) {
778                                         g_atomic_int_set(&cb_info->msg_recv_running, 0);
779                                         LOGD("destroy done. closing..");
780                                 }
781                                 break;
782                         default:
783                                 __recorder_get_api_operation(api, cb_info, msg);
784                                 break;
785                         }
786                 }
787
788                 if (cb_info->api_waiting[api] > 0) {
789                         cb_info->api_ret[api] = ret;
790                         cb_info->api_activating[api] = 1;
791
792                         g_cond_signal(&cb_info->api_cond[api]);
793                 } else {
794                         LOGE("no waiting for api [%d]", api);
795                 }
796
797                 g_mutex_unlock(&cb_info->api_mutex[api]);
798         } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
799                 __recorder_add_msg_to_queue(cb_info, api, event, event_class, msg);
800         } else {
801                 LOGW("unknown recorder api %d and api_class %d", api, api_class);
802         }
803
804         return;
805 }
806
807
808 static void *_recorder_msg_handler_func(gpointer data)
809 {
810         int api = 0;
811         int type = 0;
812         recorder_message_s *rec_msg = NULL;
813         recorder_idle_event_s *rec_idle_event = NULL;
814         recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
815         recorder_cb_info_s *cb_info = NULL;
816
817         if (!handler_info || !handler_info->cb_info) {
818                 LOGE("NULL handler %p", handler_info);
819                 return NULL;
820         }
821
822         cb_info = (recorder_cb_info_s *)handler_info->cb_info;
823         type = handler_info->type;
824
825         LOGD("t:%d start", type);
826
827         g_mutex_lock(&handler_info->mutex);
828
829         while (g_atomic_int_get(&handler_info->running)) {
830                 if (g_queue_is_empty(handler_info->queue)) {
831                         /*LOGD("signal wait...");*/
832                         g_cond_wait(&handler_info->cond, &handler_info->mutex);
833                         /*LOGD("signal received");*/
834
835                         if (g_atomic_int_get(&handler_info->running) == 0) {
836                                 LOGD("stop event thread");
837                                 break;
838                         }
839                 }
840
841                 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
842                 g_mutex_unlock(&handler_info->mutex);
843                 if (rec_msg == NULL) {
844                         LOGE("NULL message");
845                         g_mutex_lock(&handler_info->mutex);
846                         continue;
847                 }
848
849                 api = rec_msg->api;
850
851                 if (api < MUSE_RECORDER_API_MAX) {
852                         int ret = 0;
853
854                         g_mutex_lock(&cb_info->api_mutex[api]);
855
856                         if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
857                                 if (cb_info->api_waiting[api] > 0) {
858                                         cb_info->api_ret[api] = ret;
859                                         cb_info->api_activating[api] = 1;
860
861                                         /*LOGD("recorder api %d - return 0x%x", ret);*/
862
863                                         g_cond_signal(&cb_info->api_cond[api]);
864                                 } else {
865                                         LOGE("no waiting for api [%d]", api);
866                                 }
867                         } else {
868                                 LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
869                         }
870
871                         g_mutex_unlock(&cb_info->api_mutex[api]);
872                 } else if (api == MUSE_RECORDER_CB_EVENT) {
873                         switch (rec_msg->event_class) {
874                         case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
875                                 _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
876                                 break;
877                         case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
878                                 rec_idle_event = g_new0(recorder_idle_event_s, 1);
879                                 if (rec_idle_event == NULL) {
880                                         LOGE("event alloc failed");
881                                         break;
882                                 }
883
884                                 rec_idle_event->event = rec_msg->event;
885                                 rec_idle_event->cb_info = cb_info;
886                                 g_mutex_init(&rec_idle_event->event_mutex);
887                                 strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
888
889                                 /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
890
891                                 g_mutex_lock(&cb_info->idle_event_mutex);
892                                 cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
893                                 g_mutex_unlock(&cb_info->idle_event_mutex);
894
895                                 g_idle_add_full(G_PRIORITY_DEFAULT,
896                                         (GSourceFunc)_recorder_idle_event_callback,
897                                         (gpointer)rec_idle_event,
898                                         NULL);
899                                 break;
900                         default:
901                                 LOGE("unknown event class %d", rec_msg->event_class);
902                                 break;
903                         }
904                 } else {
905                         LOGE("unknown api[%d] message", api);
906                 }
907
908                 g_free(rec_msg);
909                 rec_msg = NULL;
910
911                 g_mutex_lock(&handler_info->mutex);
912         }
913
914         /* remove remained event */
915         while (!g_queue_is_empty(handler_info->queue)) {
916                 rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
917                 if (rec_msg) {
918                         LOGD("remove message %p", rec_msg);
919                         free(rec_msg);
920                         rec_msg = NULL;
921                 } else {
922                         LOGW("NULL message");
923                 }
924         }
925
926         g_mutex_unlock(&handler_info->mutex);
927
928         LOGD("return");
929
930         return NULL;
931 }
932
933
934 static void *_recorder_msg_recv_func(gpointer data)
935 {
936         int recv_length = 0;
937         int single_length = 0;
938         int remained_length = 0;
939         char *recv_msg = NULL;
940         char *single_msg = NULL;
941         char *remained_msg = NULL;
942         int num_msg = 0;
943         int cur_pos = 0;
944         int prev_pos = 0;
945         recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
946
947         if (cb_info == NULL) {
948                 LOGE("cb_info NULL");
949                 return NULL;
950         }
951
952         LOGD("start");
953
954         single_msg = (char *)malloc(sizeof(char) * MUSE_RECORDER_MSG_MAX_LENGTH);
955         if (single_msg == NULL) {
956                 LOGE("single_msg malloc failed");
957                 goto CB_HANDLER_EXIT;
958         }
959
960         recv_msg = cb_info->recv_msg;
961
962         while (g_atomic_int_get(&cb_info->msg_recv_running)) {
963                 recv_length = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
964                 if (recv_length <= 0) {
965 //LCOV_EXCL_START
966                         cb_info->is_server_connected = FALSE;
967                         LOGE("receive msg failed - server disconnected");
968                         break;
969 //LCOV_EXCL_STOP
970                 }
971
972                 recv_msg[recv_length] = '\0';
973
974                 cur_pos = 0;
975                 prev_pos = 0;
976                 num_msg = 0;
977
978                 /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
979
980                 /* Need to split the combined entering msgs */
981                 for (cur_pos = 0; cur_pos < recv_length; cur_pos++) {
982                         if (recv_msg[cur_pos] == '}') {
983                                 single_length = cur_pos - prev_pos + 1;
984
985                                 if (single_length < MUSE_RECORDER_MSG_MAX_LENGTH) {
986                                         /* check remained msg */
987                                         if (remained_length > 0) {
988 //LCOV_EXCL_START
989                                                 if (remained_msg) {
990                                                         strncpy(single_msg, remained_msg, remained_length);
991                                                         strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
992                                                         single_msg[remained_length + single_length] = '\0';
993
994                                                         free(remained_msg);
995                                                         remained_msg = NULL;
996                                                 } else {
997                                                         strncpy(single_msg, recv_msg + prev_pos, single_length);
998                                                         single_msg[single_length] = '\0';
999                                                         LOGE("lost msg [%s], skip...", single_msg);
1000                                                 }
1001
1002                                                 remained_length = 0;
1003 //LCOV_EXCL_STOP
1004                                         } else {
1005                                                 strncpy(single_msg, recv_msg + prev_pos, single_length);
1006                                                 single_msg[single_length] = '\0';
1007                                         }
1008
1009                                         if (single_msg[0] == '{') {
1010                                                 num_msg++;
1011                                                 /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
1012                                                 __recorder_process_msg(cb_info, single_msg);
1013                                         } else {
1014                                                 LOGE("invalid msg [%s]", single_msg);
1015                                         }
1016                                 } else {
1017                                         LOGE("too long message [len %d] skip...", single_length);
1018                                 }
1019
1020                                 prev_pos = cur_pos + 1;
1021                         }
1022                 }
1023
1024                 /* check incompleted message */
1025                 if (recv_msg[recv_length - 1] != '}') {
1026 //LCOV_EXCL_START
1027                         remained_length = recv_length - prev_pos;
1028
1029                         LOGW("incompleted message [len %d]", remained_length);
1030
1031                         remained_msg = (char *)malloc(remained_length + 1);
1032                         if (remained_msg) {
1033                                 strncpy(remained_msg, recv_msg + prev_pos, remained_length);
1034                                 remained_msg[remained_length] = '\0';
1035                         } else {
1036                                 LOGE("failed to alloc for remained msg");
1037                         }
1038 //LCOV_EXCL_STOP
1039                 } else {
1040                         remained_length = 0;
1041                 }
1042         }
1043
1044         LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
1045
1046         if (!cb_info->is_server_connected) {
1047 //LCOV_EXCL_START
1048                 /* send error msg for server disconnection */
1049                 char *error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
1050                         MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
1051                         MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
1052                         NULL);
1053
1054                 if (!error_msg) {
1055                         LOGE("error_msg failed");
1056                         goto CB_HANDLER_EXIT;
1057                 }
1058
1059                 LOGE("add error msg for service disconnection done");
1060
1061                 __recorder_add_msg_to_queue(cb_info,
1062                         MUSE_RECORDER_CB_EVENT,
1063                         MUSE_RECORDER_EVENT_TYPE_ERROR,
1064                         MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
1065                         error_msg);
1066
1067                 muse_core_msg_json_factory_free(error_msg);
1068                 error_msg = NULL;
1069
1070                 LOGE("add error msg for service disconnection done");
1071 //LCOV_EXCL_STOP
1072         }
1073
1074 CB_HANDLER_EXIT:
1075         if (single_msg) {
1076                 free(single_msg);
1077                 single_msg = NULL;
1078         }
1079
1080         if (remained_msg) {
1081                 free(remained_msg);
1082                 remained_msg = NULL;
1083         }
1084
1085         return NULL;
1086 }
1087
1088
1089 static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
1090         int type, const char *thread_name, recorder_cb_info_s *cb_info)
1091 {
1092         if (!handler_info || !thread_name || !cb_info) {
1093                 LOGE("t:%d NULL %p %p %p",
1094                         type, handler_info, thread_name, cb_info);
1095                 return false;
1096         }
1097
1098         LOGD("t:%d", type);
1099
1100         handler_info->type = type;
1101         handler_info->queue = g_queue_new();
1102         if (handler_info->queue == NULL) {
1103                 LOGE("t:%d queue failed", type);
1104                 return false;
1105         }
1106
1107         g_mutex_init(&handler_info->mutex);
1108         g_cond_init(&handler_info->cond);
1109
1110         handler_info->cb_info = (void *)cb_info;
1111         g_atomic_int_set(&handler_info->running, 1);
1112
1113         handler_info->thread = g_thread_try_new(thread_name,
1114                 _recorder_msg_handler_func, (gpointer)handler_info, NULL);
1115         if (handler_info->thread == NULL) {
1116 //LCOV_EXCL_START
1117                 LOGE("t:%d thread failed", type);
1118
1119                 g_mutex_clear(&handler_info->mutex);
1120                 g_cond_clear(&handler_info->cond);
1121                 g_queue_free(handler_info->queue);
1122                 handler_info->queue = NULL;
1123
1124                 return false;
1125 //LCOV_EXCL_STOP
1126         }
1127
1128         LOGD("t:%d done", type);
1129
1130         return true;
1131 }
1132
1133
1134 static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
1135 {
1136         int type = 0;
1137
1138         if (!handler_info) {
1139                 LOGE("NULL handler");
1140                 return;
1141         }
1142
1143         if (!handler_info->thread) {
1144                 LOGW("thread is not created");
1145                 return;
1146         }
1147
1148         type = handler_info->type;
1149
1150         LOGD("t:%d thread %p", type, handler_info->thread);
1151
1152         g_mutex_lock(&handler_info->mutex);
1153         g_atomic_int_set(&handler_info->running, 0);
1154         g_cond_signal(&handler_info->cond);
1155         g_mutex_unlock(&handler_info->mutex);
1156
1157         g_thread_join(handler_info->thread);
1158         handler_info->thread = NULL;
1159
1160         g_mutex_clear(&handler_info->mutex);
1161         g_cond_clear(&handler_info->cond);
1162         g_queue_free(handler_info->queue);
1163         handler_info->queue = NULL;
1164
1165         LOGD("t:%d done", type);
1166
1167         return;
1168 }
1169
1170
1171 static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
1172 {
1173         recorder_cb_info_s *cb_info = NULL;
1174         gint i = 0;
1175
1176         g_return_val_if_fail(sockfd > 0, NULL);
1177
1178         cb_info = g_new0(recorder_cb_info_s, 1);
1179         if (cb_info == NULL) {
1180                 LOGE("cb_info failed");
1181                 goto ErrorExit;
1182         }
1183
1184         cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 1;
1185
1186         for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1187                 g_mutex_init(&cb_info->api_mutex[i]);
1188                 g_cond_init(&cb_info->api_cond[i]);
1189         }
1190
1191         g_mutex_init(&cb_info->idle_event_mutex);
1192         g_cond_init(&cb_info->idle_event_cond);
1193
1194         /* message handler thread */
1195         if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
1196                 _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
1197                 LOGE("msg_handler_info failed");
1198                 goto ErrorExit;
1199         }
1200
1201         /* message handler thread for audio stream callback */
1202         if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
1203                 _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
1204                 LOGE("audio_stream_cb_info failed");
1205                 goto ErrorExit;
1206         }
1207
1208         /* message handler thread for muxed stream callback */
1209         if (!__create_msg_handler_thread(&cb_info->muxed_stream_cb_info,
1210                 _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB, "recorder_msg_handler:muxed_stream_cb", cb_info)) {
1211                 LOGE("muxed_stream_cb_info failed");
1212                 goto ErrorExit;
1213         }
1214
1215         cb_info->fd = sockfd;
1216
1217         /* message receive thread */
1218         g_atomic_int_set(&cb_info->msg_recv_running, 1);
1219         cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
1220                 _recorder_msg_recv_func, (gpointer)cb_info, NULL);
1221         if (cb_info->msg_recv_thread == NULL) {
1222                 LOGE("message receive thread creation failed");
1223                 goto ErrorExit;
1224         }
1225
1226         cb_info->is_server_connected = TRUE;
1227
1228         return cb_info;
1229 //LCOV_EXCL_START
1230 ErrorExit:
1231         if (cb_info) {
1232                 __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1233                 __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1234                 __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1235
1236                 g_mutex_clear(&cb_info->idle_event_mutex);
1237                 g_cond_clear(&cb_info->idle_event_cond);
1238
1239                 for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1240                         g_mutex_clear(&cb_info->api_mutex[i]);
1241                         g_cond_clear(&cb_info->api_cond[i]);
1242                 }
1243
1244                 g_free(cb_info);
1245                 cb_info = NULL;
1246         }
1247
1248         return NULL;
1249 //LCOV_EXCL_STOP
1250 }
1251
1252 static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder_cb_info_s *cb_info, int time_out)
1253 {
1254         int ret = RECORDER_ERROR_NONE;
1255         gint64 end_time;
1256
1257         /*LOGD("Enter api : %d", api);*/
1258
1259         if (!cb_info->is_server_connected) {
1260                 LOGE("server is disconnected");
1261                 return RECORDER_ERROR_SERVICE_DISCONNECTED;
1262         }
1263
1264         g_mutex_lock(&(cb_info->api_mutex[api]));
1265
1266         if (cb_info->api_activating[api] == 0) {
1267                 if (time_out == RECORDER_CB_NO_TIMEOUT) {
1268                         LOGW("wait for api %d", api);
1269                         g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
1270                         ret = cb_info->api_ret[api];
1271                         cb_info->api_activating[api] = 0;
1272                         LOGW("api %d returned 0x%x", api, ret);
1273                 } else {
1274                         end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
1275                         if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
1276                                 ret = cb_info->api_ret[api];
1277                                 cb_info->api_activating[api] = 0;
1278                                 /*LOGD("return value : 0x%x", ret);*/
1279                         } else {
1280                                 ret = RECORDER_ERROR_INVALID_OPERATION;
1281                                 LOGE("api %d was TIMED OUT!", api);
1282                         }
1283                 }
1284         } else {
1285                 ret = cb_info->api_ret[api];
1286                 cb_info->api_activating[api] = 0;
1287
1288                 /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
1289         }
1290
1291         if (ret != RECORDER_ERROR_NONE) {
1292                 LOGE("ERROR : api %d - ret 0x%x", api, ret);
1293
1294                 if (ret == RECORDER_ERROR_SOUND_POLICY)
1295                         LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY is deprecated and will be removed from next release.");
1296                 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_CALL)
1297                         LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_CALL is deprecated and will be removed from next release.");
1298                 else if (ret == RECORDER_ERROR_SOUND_POLICY_BY_ALARM)
1299                         LOGW("DEPRECATION WARNING: RECORDER_ERROR_SOUND_POLICY_BY_ALARM is deprecated and will be removed from next release.");
1300         }
1301
1302         g_mutex_unlock(&(cb_info->api_mutex[api]));
1303
1304         return ret;
1305 }
1306
1307
1308 static int _recorder_msg_send(int api, recorder_cb_info_s *cb_info, int *ret, int timeout)
1309 {
1310         int send_ret = 0;
1311         char *msg = NULL;
1312
1313         if (!cb_info || !ret) {
1314                 LOGE("invalid pointer for api %d - %p %p", api, cb_info, ret);
1315                 return RECORDER_ERROR_INVALID_PARAMETER;
1316         }
1317
1318         msg = muse_core_msg_json_factory_new(api, NULL);
1319         if (!msg) {
1320                 LOGE("msg creation failed: api %d", api);
1321                 return RECORDER_ERROR_OUT_OF_MEMORY;
1322         }
1323
1324         /*LOGD("send msg %s", msg);*/
1325
1326         if (cb_info->is_server_connected) {
1327                 __recorder_update_api_waiting(cb_info, api, 1);
1328                 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1329         }
1330
1331         if (send_ret < 0) {
1332                 LOGE("message send failed");
1333                 *ret = RECORDER_ERROR_INVALID_OPERATION;
1334         } else {
1335                 *ret = _recorder_client_wait_for_cb_return(api, cb_info, timeout);
1336         }
1337
1338         __recorder_update_api_waiting(cb_info, api, -1);
1339
1340         muse_core_msg_json_factory_free(msg);
1341
1342         return RECORDER_ERROR_NONE;
1343 }
1344
1345
1346 static int _recorder_msg_send_param1(int api, recorder_cb_info_s *cb_info, int *ret, recorder_msg_param *param)
1347 {
1348         int send_ret = 0;
1349         char *msg = NULL;
1350
1351         if (!cb_info || !ret || !param) {
1352                 LOGE("invalid pointer for api %d - %p %p %p", api, cb_info, ret, param);
1353                 return RECORDER_ERROR_INVALID_PARAMETER;
1354         }
1355
1356         /*LOGD("type %d, name %s", param->type, param->name);*/
1357
1358         switch (param->type) {
1359         case MUSE_TYPE_INT:
1360                 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_INT, NULL);
1361                 break;
1362         case MUSE_TYPE_DOUBLE:
1363                 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_DOUBLE, NULL);
1364                 break;
1365         case MUSE_TYPE_STRING:
1366                 msg = muse_core_msg_json_factory_new(api, param->type, param->name, param->value.value_STRING, NULL);
1367                 break;
1368         default:
1369                 LOGE("unknown type %d", param->type);
1370                 break;
1371         }
1372
1373         if (!msg) {
1374                 LOGE("msg creation failed: api %d, type %d, param name %s",
1375                         api, param->type, param->name);
1376                 return RECORDER_ERROR_OUT_OF_MEMORY;
1377         }
1378
1379         /*LOGD("send msg %s", msg);*/
1380
1381         if (cb_info->is_server_connected) {
1382                 __recorder_update_api_waiting(cb_info, api, 1);
1383
1384                 send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
1385         }
1386
1387         if (send_ret < 0) {
1388                 LOGE("message send failed");
1389                 *ret = RECORDER_ERROR_INVALID_OPERATION;
1390         } else {
1391                 *ret = _recorder_client_wait_for_cb_return(api, cb_info, RECORDER_CB_TIMEOUT);
1392         }
1393
1394         __recorder_update_api_waiting(cb_info, api, -1);
1395
1396         muse_core_msg_json_factory_free(msg);
1397
1398         return RECORDER_ERROR_NONE;
1399 }
1400
1401
1402 static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
1403 {
1404         gint i = 0;
1405
1406         g_return_if_fail(cb_info != NULL);
1407
1408         LOGD("MSG receive thread[%p] destroy", cb_info->msg_recv_thread);
1409
1410         g_thread_join(cb_info->msg_recv_thread);
1411         cb_info->msg_recv_thread = NULL;
1412
1413         LOGD("msg_recv thread removed");
1414
1415         __destroy_msg_handler_thread(&cb_info->msg_handler_info);
1416         __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
1417         __destroy_msg_handler_thread(&cb_info->muxed_stream_cb_info);
1418
1419         g_mutex_clear(&cb_info->idle_event_mutex);
1420         g_cond_clear(&cb_info->idle_event_cond);
1421
1422         for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
1423                 g_mutex_clear(&cb_info->api_mutex[i]);
1424                 g_cond_clear(&cb_info->api_cond[i]);
1425         }
1426
1427         if (cb_info->fd > -1) {
1428                 muse_core_connection_close(cb_info->fd);
1429                 cb_info->fd = -1;
1430         }
1431
1432         if (cb_info->bufmgr) {
1433                 tbm_bufmgr_deinit(cb_info->bufmgr);
1434                 cb_info->bufmgr = NULL;
1435         }
1436         if (cb_info->get_filename) {
1437                 free(cb_info->get_filename);
1438                 cb_info->get_filename = NULL;
1439         }
1440
1441         g_free(cb_info);
1442         cb_info = NULL;
1443
1444         return;
1445 }
1446
1447
1448 static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
1449 {
1450         char **root_directory = (char **)user_data;
1451
1452         if (root_directory == NULL) {
1453                 LOGE("user data is NULL");
1454                 return false;
1455         }
1456
1457         LOGD("storage id %d, type %d, state %d, path %s",
1458                 storage_id, type, state, path ? path : "NULL");
1459
1460         if (type == STORAGE_TYPE_INTERNAL && path) {
1461                 if (*root_directory) {
1462                         free(*root_directory);
1463                         *root_directory = NULL;
1464                 }
1465
1466                 *root_directory = strdup(path);
1467                 if (*root_directory) {
1468                         LOGD("get root directory %s", *root_directory);
1469                         return false;
1470                 } else {
1471                         LOGE("strdup %s failed", path);
1472                 }
1473         }
1474
1475         return true;
1476 }
1477
1478 static int _recorder_client_get_root_directory(char **root_directory)
1479 {
1480         int ret = STORAGE_ERROR_NONE;
1481
1482         if (root_directory == NULL) {
1483                 LOGE("user data is NULL");
1484                 return false;
1485         }
1486
1487         ret = storage_foreach_device_supported((storage_device_supported_cb)_recorder_storage_device_supported_cb, root_directory);
1488         if (ret != STORAGE_ERROR_NONE) {
1489                 LOGE("storage_foreach_device_supported failed 0x%x", ret);
1490                 return false;
1491         }
1492
1493         return true;
1494 }
1495
1496 static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e type, camera_h camera)
1497 {
1498         int ret = RECORDER_ERROR_NONE;
1499         int destroy_ret = RECORDER_ERROR_NONE;
1500         int sock_fd = -1;
1501         int send_ret = 0;
1502         char *send_msg = NULL;
1503         char *root_directory = NULL;
1504         intptr_t camera_handle = 0;
1505         intptr_t handle = 0;
1506         tbm_bufmgr bufmgr = NULL;
1507         recorder_cli_s *pc = NULL;
1508         recorder_msg_param param;
1509
1510         LOGD("Enter - type %d", type);
1511
1512         if (recorder == NULL) {
1513                 LOGE("NULL pointer for recorder handle");
1514                 return RECORDER_ERROR_INVALID_PARAMETER;
1515         }
1516
1517         if (type == MUSE_RECORDER_TYPE_VIDEO && camera == NULL) {
1518                 LOGE("NULL pointer for camera handle on video recorder mode");
1519                 return RECORDER_ERROR_INVALID_PARAMETER;
1520         }
1521
1522         bufmgr = tbm_bufmgr_init(-1);
1523         if (bufmgr == NULL) {
1524                 LOGE("get tbm bufmgr failed");
1525                 return RECORDER_ERROR_INVALID_OPERATION;
1526         }
1527
1528         pc = g_new0(recorder_cli_s, 1);
1529         if (pc == NULL) {
1530                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1531                 goto _ERR_RECORDER_EXIT;
1532         }
1533
1534         sock_fd = muse_core_client_new();
1535         if (sock_fd < 0) {
1536 //LCOV_EXCL_START
1537                 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
1538                 ret = RECORDER_ERROR_INVALID_OPERATION;
1539                 goto _ERR_RECORDER_EXIT;
1540 //LCOV_EXCL_STOP
1541         }
1542
1543         if (type == MUSE_RECORDER_TYPE_AUDIO) {
1544                 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1545                         MUSE_TYPE_INT, "module", MUSE_RECORDER,
1546                         MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_AUDIO,
1547                         MUSE_TYPE_INT, "pid", getpid(),
1548                         NULL);
1549         } else {
1550                 pc->camera = camera;
1551                 camera_handle = (intptr_t)((camera_cli_s *)camera)->remote_handle;
1552                 send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_CREATE,
1553                         MUSE_TYPE_INT, "module", MUSE_RECORDER,
1554                         MUSE_TYPE_INT, PARAM_RECORDER_TYPE, MUSE_RECORDER_TYPE_VIDEO,
1555                         MUSE_TYPE_INT, "pid", getpid(),
1556                         MUSE_TYPE_POINTER, "camera_handle", camera_handle,
1557                         NULL);
1558         }
1559
1560         if (!send_msg) {
1561 //LCOV_EXCL_START
1562                 LOGE("NULL msg");
1563                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1564                 goto _ERR_RECORDER_EXIT;
1565 //LCOV_EXCL_STOP
1566         }
1567
1568         LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
1569
1570         send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
1571
1572         muse_core_msg_json_factory_free(send_msg);
1573         send_msg = NULL;
1574
1575         if (send_ret < 0) {
1576 //LCOV_EXCL_START
1577                 LOGE("send msg failed %d", errno);
1578                 ret = RECORDER_ERROR_INVALID_OPERATION;
1579                 goto _ERR_RECORDER_EXIT;
1580 //LCOV_EXCL_STOP
1581         }
1582
1583         pc->cb_info = _recorder_client_callback_new(sock_fd);
1584         if (pc->cb_info == NULL) {
1585                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1586                 goto _ERR_RECORDER_EXIT;
1587         }
1588
1589         sock_fd = -1;
1590
1591         ret = _recorder_client_wait_for_cb_return(MUSE_RECORDER_API_CREATE, pc->cb_info, RECORDER_CB_TIMEOUT);
1592
1593         pc->cb_info->api_waiting[MUSE_RECORDER_API_CREATE] = 0;
1594
1595         if (ret != RECORDER_ERROR_NONE) {
1596                 LOGE("API_CREATE failed 0x%x", ret);
1597                 goto _ERR_RECORDER_EXIT;
1598         }
1599
1600         muse_recorder_msg_get_pointer(handle, pc->cb_info->recv_msg);
1601         if (handle == 0) {
1602 //LCOV_EXCL_START
1603                 LOGE("Receiving Handle Failed!!");
1604                 ret = RECORDER_ERROR_INVALID_OPERATION;
1605                 goto _ERR_RECORDER_AFTER_CREATE;
1606 //LCOV_EXCL_STOP
1607         }
1608
1609         if (!_recorder_client_get_root_directory(&root_directory) || root_directory == NULL) {
1610 //LCOV_EXCL_START
1611                 LOGE("failed to get root directory of internal storage");
1612                 ret = RECORDER_ERROR_INVALID_OPERATION;
1613                 goto _ERR_RECORDER_AFTER_CREATE;
1614 //LCOV_EXCL_STOP
1615         }
1616
1617         LOGD("root directory [%s]", root_directory);
1618
1619         RECORDER_MSG_PARAM_SET(param, STRING, root_directory);
1620
1621         _recorder_msg_send_param1(MUSE_RECORDER_API_ATTR_SET_ROOT_DIRECTORY, pc->cb_info, &ret, &param);
1622
1623         if (ret != RECORDER_ERROR_NONE) {
1624                 LOGE("failed to set root directory %s", root_directory);
1625                 ret = RECORDER_ERROR_INVALID_OPERATION;
1626                 goto _ERR_RECORDER_AFTER_CREATE;
1627         }
1628
1629         free(root_directory);
1630         root_directory = NULL;
1631
1632         pc->remote_handle = handle;
1633         pc->cb_info->bufmgr = bufmgr;
1634
1635         LOGD("recorder[type %d] %p create success : remote handle 0x%x",
1636                 type, pc, pc->remote_handle);
1637
1638         *recorder = (recorder_h)pc;
1639
1640         LOGD("done");
1641
1642         return RECORDER_ERROR_NONE;
1643 //LCOV_EXCL_START
1644 _ERR_RECORDER_AFTER_CREATE:
1645         _recorder_msg_send(MUSE_RECORDER_API_DESTROY, pc->cb_info, &destroy_ret, RECORDER_CB_TIMEOUT);
1646         LOGE("destroy return 0x%x", destroy_ret);
1647
1648 _ERR_RECORDER_EXIT:
1649         tbm_bufmgr_deinit(bufmgr);
1650         bufmgr = NULL;
1651
1652         if (root_directory) {
1653                 free(root_directory);
1654                 root_directory = NULL;
1655         }
1656
1657         if (sock_fd > -1) {
1658                 muse_core_connection_close(sock_fd);
1659                 sock_fd = -1;
1660         }
1661
1662         if (pc) {
1663                 if (pc->cb_info) {
1664                         _recorder_client_callback_destroy(pc->cb_info);
1665                         pc->cb_info = NULL;
1666                 }
1667                 g_free(pc);
1668                 pc = NULL;
1669         }
1670
1671         return ret;
1672 //LCOV_EXCL_STOP
1673 }
1674
1675
1676 int recorder_create_videorecorder(camera_h camera, recorder_h *recorder)
1677 {
1678         return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_VIDEO, camera);
1679 }
1680
1681
1682 int recorder_create_audiorecorder(recorder_h *recorder)
1683 {
1684         return _recorder_create_common(recorder, MUSE_RECORDER_TYPE_AUDIO, NULL);
1685 }
1686
1687
1688 int recorder_get_state(recorder_h recorder, recorder_state_e *state)
1689 {
1690         int ret = RECORDER_ERROR_NONE;
1691         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1692         muse_recorder_api_e api = MUSE_RECORDER_API_GET_STATE;
1693
1694         if (!pc || !pc->cb_info) {
1695                 LOGE("NULL handle");
1696                 return RECORDER_ERROR_INVALID_PARAMETER;
1697         }
1698
1699         if (state == NULL) {
1700                 LOGE("NULL pointer state");
1701                 return RECORDER_ERROR_INVALID_PARAMETER;
1702         }
1703
1704         LOGD("Enter, remote_handle : %x", pc->remote_handle);
1705
1706         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1707
1708         if (ret == RECORDER_ERROR_NONE)
1709                 *state = (recorder_state_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_STATE];
1710
1711         LOGD("ret : 0x%x, state : %d", ret, *state);
1712
1713         return ret;
1714 }
1715
1716
1717 int recorder_destroy(recorder_h recorder)
1718 {
1719         int ret = RECORDER_ERROR_NONE;
1720         muse_recorder_api_e api = MUSE_RECORDER_API_DESTROY;
1721         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1722
1723         if (!pc || !pc->cb_info) {
1724                 LOGE("NULL handle");
1725                 return RECORDER_ERROR_INVALID_PARAMETER;
1726         }
1727
1728         LOGD("ENTER");
1729
1730         if (pc->cb_info->is_server_connected)
1731                 _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1732         else
1733                 LOGW("server disconnected. release resource without send message.");
1734
1735         if (ret == RECORDER_ERROR_NONE) {
1736                 _recorder_deactivate_idle_event_all(pc->cb_info);
1737                 _recorder_client_callback_destroy(pc->cb_info);
1738                 g_free(pc);
1739                 pc = NULL;
1740         }
1741
1742         LOGD("ret : 0x%x", ret);
1743
1744         return ret;
1745 }
1746
1747
1748 int recorder_prepare(recorder_h recorder)
1749 {
1750         int ret = RECORDER_ERROR_NONE;
1751         muse_recorder_api_e api = MUSE_RECORDER_API_PREPARE;
1752         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1753
1754         if (!pc || !pc->cb_info) {
1755                 LOGE("NULL handle");
1756                 return RECORDER_ERROR_INVALID_PARAMETER;
1757         }
1758
1759         LOGD("ENTER");
1760
1761         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1762
1763         LOGD("ret : 0x%x", ret);
1764
1765         if (ret == RECORDER_ERROR_NONE && pc->camera)
1766                 camera_start_evas_rendering(pc->camera);
1767
1768         return ret;
1769 }
1770
1771
1772 int recorder_unprepare(recorder_h recorder)
1773 {
1774         int ret = RECORDER_ERROR_NONE;
1775         muse_recorder_api_e api = MUSE_RECORDER_API_UNPREPARE;
1776         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1777         camera_state_e camera_state = CAMERA_STATE_NONE;
1778
1779         if (!pc || !pc->cb_info) {
1780                 LOGE("NULL handle");
1781                 return RECORDER_ERROR_INVALID_PARAMETER;
1782         }
1783
1784         LOGD("ENTER");
1785
1786         if (pc->camera) {
1787 //LCOV_EXCL_START
1788                 ret = camera_get_state(pc->camera, &camera_state);
1789                 if (ret != CAMERA_ERROR_NONE) {
1790                         LOGE("failed to get camera state 0x%x", ret);
1791                         return RECORDER_ERROR_INVALID_OPERATION;
1792                 }
1793
1794                 if (camera_state == CAMERA_STATE_PREVIEW) {
1795                         ret = camera_stop_evas_rendering(pc->camera, false);
1796                         if (ret != CAMERA_ERROR_NONE) {
1797                                 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1798                                 return RECORDER_ERROR_INVALID_OPERATION;
1799                         }
1800                 }
1801 //LCOV_EXCL_STOP
1802         }
1803
1804         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1805
1806         LOGD("ret : 0x%x", ret);
1807
1808         return ret;
1809 }
1810
1811
1812 int recorder_start(recorder_h recorder)
1813 {
1814         int ret = RECORDER_ERROR_NONE;
1815         muse_recorder_api_e api = MUSE_RECORDER_API_START;
1816         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1817         recorder_state_e current_state = RECORDER_STATE_NONE;
1818
1819         if (!pc || !pc->cb_info) {
1820                 LOGE("NULL handle");
1821                 return RECORDER_ERROR_INVALID_PARAMETER;
1822         }
1823
1824         LOGD("ENTER");
1825
1826         if (pc->camera) {
1827 //LCOV_EXCL_START
1828                 ret = recorder_get_state(recorder, &current_state);
1829                 if (ret != RECORDER_ERROR_NONE) {
1830                         LOGE("failed to get current state 0x%x", ret);
1831                         return RECORDER_ERROR_INVALID_OPERATION;
1832                 }
1833
1834                 if (current_state == RECORDER_STATE_READY) {
1835                         ret = camera_stop_evas_rendering(pc->camera, true);
1836                         if (ret != CAMERA_ERROR_NONE) {
1837                                 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1838                                 return RECORDER_ERROR_INVALID_OPERATION;
1839                         }
1840                 }
1841 //LCOV_EXCL_STOP
1842         }
1843
1844         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_NO_TIMEOUT);
1845
1846         if (pc->camera && current_state == RECORDER_STATE_READY)
1847                 camera_start_evas_rendering(pc->camera);
1848
1849         LOGD("ret : 0x%x", ret);
1850
1851         return ret;
1852 }
1853
1854
1855 int recorder_pause(recorder_h recorder)
1856 {
1857         int ret = RECORDER_ERROR_NONE;
1858         muse_recorder_api_e api = MUSE_RECORDER_API_PAUSE;
1859         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1860
1861         if (!pc || !pc->cb_info) {
1862                 LOGE("NULL handle");
1863                 return RECORDER_ERROR_INVALID_PARAMETER;
1864         }
1865
1866         LOGD("ENTER");
1867
1868         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1869
1870         LOGD("ret : 0x%x", ret);
1871
1872         return ret;
1873 }
1874
1875
1876 int recorder_commit(recorder_h recorder)
1877 {
1878         int ret = RECORDER_ERROR_NONE;
1879         muse_recorder_api_e api = MUSE_RECORDER_API_COMMIT;
1880         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1881         recorder_state_e current_state = RECORDER_STATE_NONE;
1882
1883         if (!pc || !pc->cb_info) {
1884                 LOGE("NULL handle");
1885                 return RECORDER_ERROR_INVALID_PARAMETER;
1886         }
1887
1888         LOGD("ENTER");
1889
1890         if (pc->camera) {
1891 //LCOV_EXCL_START
1892                 ret = recorder_get_state(recorder, &current_state);
1893                 if (ret != RECORDER_ERROR_NONE) {
1894                         LOGE("failed to get current state 0x%x", ret);
1895                         return RECORDER_ERROR_INVALID_OPERATION;
1896                 }
1897
1898                 if (current_state >= RECORDER_STATE_RECORDING) {
1899                         ret = camera_stop_evas_rendering(pc->camera, true);
1900                         if (ret != CAMERA_ERROR_NONE) {
1901                                 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1902                                 return RECORDER_ERROR_INVALID_OPERATION;
1903                         }
1904                 }
1905 //LCOV_EXCL_STOP
1906         }
1907
1908         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1909
1910         if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1911                 camera_start_evas_rendering(pc->camera);
1912
1913         LOGD("ret : 0x%x", ret);
1914
1915         return ret;
1916 }
1917
1918
1919 int recorder_cancel(recorder_h recorder)
1920 {
1921         int ret = RECORDER_ERROR_NONE;
1922         muse_recorder_api_e api = MUSE_RECORDER_API_CANCEL;
1923         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1924         recorder_state_e current_state = RECORDER_STATE_NONE;
1925
1926         if (!pc || !pc->cb_info) {
1927                 LOGE("NULL handle");
1928                 return RECORDER_ERROR_INVALID_PARAMETER;
1929         }
1930
1931         LOGD("ENTER");
1932
1933         if (pc->camera) {
1934                 ret = recorder_get_state(recorder, &current_state);
1935                 if (ret != RECORDER_ERROR_NONE) {
1936                         LOGE("failed to get current state 0x%x", ret);
1937                         return RECORDER_ERROR_INVALID_OPERATION;
1938                 }
1939
1940                 if (current_state >= RECORDER_STATE_RECORDING) {
1941                         ret = camera_stop_evas_rendering(pc->camera, true);
1942                         if (ret != CAMERA_ERROR_NONE) {
1943                                 LOGE("camera_stop_evas_rendering failed 0x%x", ret);
1944                                 return RECORDER_ERROR_INVALID_OPERATION;
1945                         }
1946                 }
1947         }
1948
1949         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
1950
1951         if (pc->camera && current_state >= RECORDER_STATE_RECORDING)
1952                 camera_start_evas_rendering(pc->camera);
1953
1954         LOGD("ret : 0x%x", ret);
1955
1956         return ret;
1957 }
1958
1959
1960 int recorder_set_video_resolution(recorder_h recorder, int width, int height)
1961 {
1962         int ret = RECORDER_ERROR_NONE;
1963         int send_ret = 0;
1964         char *send_msg = NULL;
1965         muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_RESOLUTION;
1966         recorder_cli_s *pc = (recorder_cli_s *)recorder;
1967
1968         if (!pc || !pc->cb_info) {
1969                 LOGE("NULL handle");
1970                 return RECORDER_ERROR_INVALID_PARAMETER;
1971         }
1972
1973         LOGD("ENTER");
1974
1975         send_msg = muse_core_msg_json_factory_new(api,
1976                 MUSE_TYPE_INT, "width", width,
1977                 MUSE_TYPE_INT, "height", height,
1978                 NULL);
1979         if (send_msg) {
1980                 if (pc->cb_info->is_server_connected) {
1981                         __recorder_update_api_waiting(pc->cb_info, api, 1);
1982
1983                         send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
1984                 }
1985
1986                 if (send_ret < 0) {
1987                         LOGE("message send failed");
1988                         ret = RECORDER_ERROR_INVALID_OPERATION;
1989                 } else {
1990                         ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
1991                 }
1992
1993                 __recorder_update_api_waiting(pc->cb_info, api, -1);
1994
1995                 muse_core_msg_json_factory_free(send_msg);
1996         } else {
1997                 LOGE("failed to create msg");
1998                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
1999         }
2000
2001         LOGD("ret : 0x%x", ret);
2002
2003         return ret;
2004 }
2005
2006
2007 int recorder_get_video_resolution(recorder_h recorder, int *width, int *height)
2008 {
2009         int ret = RECORDER_ERROR_NONE;
2010         muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_RESOLUTION;
2011         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2012
2013         if (!pc || !pc->cb_info) {
2014                 LOGE("NULL handle");
2015                 return RECORDER_ERROR_INVALID_PARAMETER;
2016         }
2017
2018         if (!width || !height) {
2019                 LOGE("NULL pointer width = [%p], height = [%p]", width, height);
2020                 return RECORDER_ERROR_INVALID_PARAMETER;
2021         }
2022
2023         LOGD("ENTER");
2024
2025         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2026
2027         if (ret == RECORDER_ERROR_NONE) {
2028                 *width = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION] >> 16;
2029                 *height = (0x0000ffff & pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_RESOLUTION]);
2030         }
2031
2032         LOGD("ret : 0x%x, %dx%d", ret, *width, *height);
2033
2034         return ret;
2035 }
2036
2037
2038 int recorder_foreach_supported_video_resolution(recorder_h recorder,
2039         recorder_supported_video_resolution_cb foreach_cb, void *user_data)
2040 {
2041         int ret = RECORDER_ERROR_NONE;
2042         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2043         muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_RESOLUTION;
2044
2045         if (!pc || !pc->cb_info || foreach_cb == NULL) {
2046                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2047                 return RECORDER_ERROR_INVALID_PARAMETER;
2048         }
2049
2050         LOGD("Enter, handle :%x", pc->remote_handle);
2051
2052         pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = foreach_cb;
2053         pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_RESOLUTION] = user_data;
2054
2055         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2056
2057         LOGD("ret : 0x%x", ret);
2058
2059         return ret;
2060 }
2061
2062
2063 int recorder_get_audio_level(recorder_h recorder, double *level)
2064 {
2065         int ret = RECORDER_ERROR_NONE;
2066         muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_LEVEL;
2067         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2068
2069         if (!pc || !pc->cb_info || level == NULL) {
2070                 LOGE("NULL pointer %p %p", pc, level);
2071                 return RECORDER_ERROR_INVALID_PARAMETER;
2072         }
2073
2074         LOGD("ENTER");
2075
2076         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2077
2078         if (ret == RECORDER_ERROR_NONE)
2079                 *level = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_AUDIO_LEVEL];
2080
2081         LOGD("ret : 0x%x, level %lf", ret, *level);
2082
2083         return ret;
2084 }
2085
2086
2087 int recorder_set_filename(recorder_h recorder, const char *filename)
2088 {
2089         int ret = RECORDER_ERROR_NONE;
2090         size_t length = 0;
2091         muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILENAME;
2092         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2093         recorder_msg_param param;
2094         char set_filename[RECORDER_FILENAME_MAX] = {'\0',};
2095
2096         if (!pc || !pc->cb_info) {
2097                 LOGE("NULL handle");
2098                 return RECORDER_ERROR_INVALID_PARAMETER;
2099         }
2100
2101         if (filename == NULL) {
2102                 LOGE("filename is NULL");
2103                 return RECORDER_ERROR_INVALID_PARAMETER;
2104         }
2105
2106         LOGD("ENTER [%s]", filename);
2107
2108         length = strlen(filename);
2109
2110         if (length >= RECORDER_FILENAME_MAX - 1) {
2111                 LOGE("too long file name [%d]", length);
2112                 return RECORDER_ERROR_INVALID_PARAMETER;
2113         }
2114
2115         if (storage_get_origin_internal_path(filename, RECORDER_FILENAME_MAX, set_filename) < 0) {
2116                 /* Cannot convert. Use original path. */
2117                 strncpy(set_filename, filename, length + 1);
2118         } else {
2119                 /* Converted. Use converted path. */
2120                 LOGD("Converted filename : %s -> %s", filename, set_filename);
2121         }
2122
2123         RECORDER_MSG_PARAM_SET(param, STRING, set_filename);
2124
2125         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2126
2127         LOGD("ret : 0x%x", ret);
2128
2129         return ret;
2130 }
2131
2132
2133 int recorder_get_filename(recorder_h recorder,  char **filename)
2134 {
2135         int ret = RECORDER_ERROR_NONE;
2136         muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILENAME;
2137         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2138         char compat_filename[RECORDER_FILENAME_MAX] = {0, };
2139
2140         if (!pc || !pc->cb_info) {
2141                 LOGE("NULL handle");
2142                 return RECORDER_ERROR_INVALID_PARAMETER;
2143         }
2144
2145         if (filename == NULL) {
2146                 LOGE("filename is NULL");
2147                 return RECORDER_ERROR_INVALID_PARAMETER;
2148         }
2149
2150         LOGD("ENTER");
2151
2152         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2153
2154         if (ret == RECORDER_ERROR_NONE) {
2155                 if (storage_get_compat_internal_path(pc->cb_info->get_filename, RECORDER_FILENAME_MAX, compat_filename) < 0) {
2156                         /* Cannot convert. Use original path. */
2157                         *filename = pc->cb_info->get_filename;
2158                 } else {
2159                         /* Converted. Use converted path. */
2160                         LOGD("Converted filename : %s -> %s", pc->cb_info->get_filename, compat_filename);
2161                         *filename = strdup(compat_filename);
2162                         free(pc->cb_info->get_filename);
2163                 }
2164
2165                 pc->cb_info->get_filename = NULL;
2166         }
2167
2168         LOGD("ret : 0x%x, filename : [%s]", ret, (*filename) ? *filename : "NULL");
2169
2170         return ret;
2171 }
2172
2173
2174 int recorder_set_file_format(recorder_h recorder, recorder_file_format_e format)
2175 {
2176         int ret = RECORDER_ERROR_NONE;
2177         int set_format = (int)format;
2178         muse_recorder_api_e api = MUSE_RECORDER_API_SET_FILE_FORMAT;
2179         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2180         recorder_msg_param param;
2181
2182         if (!pc || !pc->cb_info) {
2183                 LOGE("NULL handle");
2184                 return RECORDER_ERROR_INVALID_PARAMETER;
2185         }
2186
2187         LOGD("ENTER, set_format : %d", set_format);
2188
2189         RECORDER_MSG_PARAM_SET(param, INT, set_format);
2190
2191         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2192
2193         LOGD("ret : 0x%x", ret);
2194         return ret;
2195 }
2196
2197
2198 int recorder_get_file_format(recorder_h recorder, recorder_file_format_e *format)
2199 {
2200         int ret = RECORDER_ERROR_NONE;
2201         muse_recorder_api_e api = MUSE_RECORDER_API_GET_FILE_FORMAT;
2202         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2203
2204         if (!pc || !pc->cb_info) {
2205                 LOGE("NULL handle");
2206                 return RECORDER_ERROR_INVALID_PARAMETER;
2207         }
2208
2209         if (format == NULL) {
2210                 LOGE("NULL pointer data");
2211                 return RECORDER_ERROR_INVALID_PARAMETER;
2212         }
2213
2214         LOGD("ENTER");
2215
2216         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2217
2218         if (ret == RECORDER_ERROR_NONE)
2219                 *format = (recorder_file_format_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_FILE_FORMAT];
2220
2221         LOGD("ret : 0x%x, format %d", ret, *format);
2222
2223         return ret;
2224 }
2225
2226
2227 int recorder_set_sound_stream_info(recorder_h recorder, sound_stream_info_h stream_info)
2228 {
2229         int ret = RECORDER_ERROR_NONE;
2230         muse_recorder_api_e api = MUSE_RECORDER_API_SET_SOUND_STREAM_INFO;
2231         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2232         bool is_available = false;
2233         int stream_index = 0;
2234         char *stream_type = NULL;
2235         char *send_msg = NULL;
2236         int send_ret = 0;
2237
2238         if (!pc || !pc->cb_info || stream_info == NULL) {
2239                 LOGE("NULL handle");
2240                 return RECORDER_ERROR_INVALID_PARAMETER;
2241         }
2242
2243         LOGD("ENTER");
2244
2245         ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_RECORDER, &is_available);
2246         if (ret != SOUND_MANAGER_ERROR_NONE) {
2247                 LOGE("stream info verification failed");
2248                 return RECORDER_ERROR_INVALID_OPERATION;
2249         }
2250
2251         if (is_available == false) {
2252                 LOGE("stream information is not available");
2253                 return RECORDER_ERROR_INVALID_OPERATION;
2254         }
2255
2256         ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
2257         ret |= sound_manager_get_index_from_stream_information(stream_info, &stream_index);
2258
2259         LOGD("sound manager return [0x%x]", ret);
2260
2261         if (ret == SOUND_MANAGER_ERROR_NONE) {
2262                 send_msg = muse_core_msg_json_factory_new(api,
2263                         MUSE_TYPE_STRING, "stream_type", stream_type,
2264                         MUSE_TYPE_INT, "stream_index", stream_index,
2265                         NULL);
2266                 if (send_msg) {
2267                         if (pc->cb_info->is_server_connected) {
2268                                 __recorder_update_api_waiting(pc->cb_info, api, 1);
2269
2270                                 send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, send_msg);
2271                         }
2272
2273                         if (send_ret < 0) {
2274                                 LOGE("message send failed");
2275                                 ret = RECORDER_ERROR_INVALID_OPERATION;
2276                         } else {
2277                                 ret = _recorder_client_wait_for_cb_return(api, pc->cb_info, RECORDER_CB_TIMEOUT);
2278                         }
2279
2280                         __recorder_update_api_waiting(pc->cb_info, api, -1);
2281
2282                         muse_core_msg_json_factory_free(send_msg);
2283                 } else {
2284                         LOGE("failed to create msg");
2285                         ret = RECORDER_ERROR_OUT_OF_MEMORY;
2286                 }
2287         } else {
2288                 ret = RECORDER_ERROR_INVALID_OPERATION;
2289         }
2290
2291         return ret;
2292 }
2293
2294
2295 int recorder_set_state_changed_cb(recorder_h recorder, recorder_state_changed_cb callback, void *user_data)
2296 {
2297         int ret = RECORDER_ERROR_NONE;
2298         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2299         muse_recorder_api_e api = MUSE_RECORDER_API_SET_STATE_CHANGED_CB;
2300
2301         if (!pc || !pc->cb_info || callback == NULL) {
2302                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2303                 return RECORDER_ERROR_INVALID_PARAMETER;
2304         }
2305
2306         LOGD("Enter, handle :%x", pc->remote_handle);
2307
2308         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2309
2310         if (ret == RECORDER_ERROR_NONE) {
2311                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = callback;
2312                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = user_data;
2313         }
2314
2315         LOGD("ret : 0x%x", ret);
2316
2317         return ret;
2318 }
2319
2320
2321 int recorder_unset_state_changed_cb(recorder_h recorder)
2322 {
2323         int ret = RECORDER_ERROR_NONE;
2324         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_STATE_CHANGED_CB;
2325         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2326
2327         if (!pc || !pc->cb_info) {
2328                 LOGE("NULL handle");
2329                 return RECORDER_ERROR_INVALID_PARAMETER;
2330         }
2331
2332         LOGD("ENTER");
2333
2334         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2335
2336         if (ret == RECORDER_ERROR_NONE) {
2337                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2338                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_STATE_CHANGE] = NULL;
2339         }
2340
2341         LOGD("ret : 0x%x", ret);
2342
2343         return ret;
2344 }
2345
2346
2347 int recorder_set_interrupted_cb(recorder_h recorder, recorder_interrupted_cb callback, void *user_data)
2348 {
2349         int ret = RECORDER_ERROR_NONE;
2350         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2351         muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPTED_CB;
2352
2353         if (!pc || !pc->cb_info || callback == NULL) {
2354                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2355                 return RECORDER_ERROR_INVALID_PARAMETER;
2356         }
2357
2358         LOGD("Enter, handle :%x", pc->remote_handle);
2359
2360         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2361
2362         if (ret == RECORDER_ERROR_NONE) {
2363                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = callback;
2364                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = user_data;
2365         }
2366
2367         LOGD("ret : 0x%x", ret);
2368
2369         return ret;
2370 }
2371
2372
2373 int recorder_unset_interrupted_cb(recorder_h recorder)
2374 {
2375         int ret = RECORDER_ERROR_NONE;
2376         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPTED_CB;
2377         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2378
2379         if (!pc || !pc->cb_info) {
2380                 LOGE("NULL handle");
2381                 return RECORDER_ERROR_INVALID_PARAMETER;
2382         }
2383
2384         LOGD("ENTER");
2385
2386         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2387
2388         if (ret == RECORDER_ERROR_NONE) {
2389                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2390                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPTED] = NULL;
2391         }
2392
2393         LOGD("ret : 0x%x", ret);
2394
2395         return ret;
2396 }
2397
2398
2399 int recorder_set_interrupt_started_cb(recorder_h recorder, recorder_interrupt_started_cb callback, void *user_data)
2400 {
2401         int ret = RECORDER_ERROR_NONE;
2402         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2403         muse_recorder_api_e api = MUSE_RECORDER_API_SET_INTERRUPT_STARTED_CB;
2404
2405         if (!pc || !pc->cb_info || callback == NULL) {
2406                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2407                 return RECORDER_ERROR_INVALID_PARAMETER;
2408         }
2409
2410         LOGD("Enter, handle :%x", pc->remote_handle);
2411
2412         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2413
2414         if (ret == RECORDER_ERROR_NONE) {
2415                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = callback;
2416                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
2417         }
2418
2419         LOGD("ret : 0x%x", ret);
2420
2421         return ret;
2422 }
2423
2424
2425 int recorder_unset_interrupt_started_cb(recorder_h recorder)
2426 {
2427         int ret = RECORDER_ERROR_NONE;
2428         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_INTERRUPT_STARTED_CB;
2429         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2430
2431         if (!pc || !pc->cb_info) {
2432                 LOGE("NULL handle");
2433                 return RECORDER_ERROR_INVALID_PARAMETER;
2434         }
2435
2436         LOGD("ENTER");
2437
2438         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2439
2440         if (ret == RECORDER_ERROR_NONE) {
2441                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2442                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
2443         }
2444
2445         LOGD("ret : 0x%x", ret);
2446
2447         return ret;
2448 }
2449
2450
2451 int recorder_set_audio_stream_cb(recorder_h recorder, recorder_audio_stream_cb callback, void *user_data)
2452 {
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_AUDIO_STREAM_CB;
2456
2457         if (!pc || !pc->cb_info || callback == NULL) {
2458                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2459                 return RECORDER_ERROR_INVALID_PARAMETER;
2460         }
2461
2462         LOGD("Enter, handle :%x", pc->remote_handle);
2463
2464         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2465
2466         if (ret == RECORDER_ERROR_NONE) {
2467                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = callback;
2468                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = user_data;
2469         }
2470
2471         LOGD("ret : 0x%x", ret);
2472
2473         return ret;
2474 }
2475
2476
2477 int recorder_unset_audio_stream_cb(recorder_h recorder)
2478 {
2479         int ret = RECORDER_ERROR_NONE;
2480         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_AUDIO_STREAM_CB;
2481         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2482
2483         if (!pc || !pc->cb_info) {
2484                 LOGE("NULL handle");
2485                 return RECORDER_ERROR_INVALID_PARAMETER;
2486         }
2487
2488         LOGD("ENTER");
2489
2490         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2491
2492         if (ret == RECORDER_ERROR_NONE) {
2493                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2494                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM] = NULL;
2495         }
2496
2497         LOGD("ret : 0x%x", ret);
2498
2499         return ret;
2500 }
2501
2502
2503 int recorder_set_muxed_stream_cb(recorder_h recorder, recorder_muxed_stream_cb callback, void *user_data)
2504 {
2505         int ret = RECORDER_ERROR_NONE;
2506         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2507         muse_recorder_api_e api = MUSE_RECORDER_API_SET_MUXED_STREAM_CB;
2508
2509         if (!pc || !pc->cb_info || !callback) {
2510                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2511                 return RECORDER_ERROR_INVALID_PARAMETER;
2512         }
2513
2514         LOGD("Enter, handle :%x", pc->remote_handle);
2515
2516         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2517
2518         if (ret == RECORDER_ERROR_NONE) {
2519                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = callback;
2520                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = user_data;
2521         }
2522
2523         LOGD("ret : 0x%x", ret);
2524
2525         return ret;
2526 }
2527
2528
2529 int recorder_unset_muxed_stream_cb(recorder_h recorder)
2530 {
2531         int ret = RECORDER_ERROR_NONE;
2532         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_MUXED_STREAM_CB;
2533         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2534
2535         if (!pc || !pc->cb_info) {
2536                 LOGE("NULL handle");
2537                 return RECORDER_ERROR_INVALID_PARAMETER;
2538         }
2539
2540         LOGD("ENTER");
2541
2542         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2543
2544         if (ret == RECORDER_ERROR_NONE) {
2545                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2546                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_MUXED_STREAM] = NULL;
2547         }
2548
2549         LOGD("ret : 0x%x", ret);
2550
2551         return ret;
2552 }
2553
2554
2555 int recorder_set_error_cb(recorder_h recorder, recorder_error_cb callback, void *user_data)
2556 {
2557         int ret = RECORDER_ERROR_NONE;
2558         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2559         muse_recorder_api_e api = MUSE_RECORDER_API_SET_ERROR_CB;
2560
2561         if (!pc || !pc->cb_info || callback == NULL) {
2562                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2563                 return RECORDER_ERROR_INVALID_PARAMETER;
2564         }
2565
2566         LOGD("Enter, handle :%x", pc->remote_handle);
2567
2568         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2569
2570         if (ret == RECORDER_ERROR_NONE) {
2571                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = callback;
2572                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = user_data;
2573         }
2574
2575         LOGD("ret : 0x%x", ret);
2576
2577         return ret;
2578 }
2579
2580
2581 int recorder_unset_error_cb(recorder_h recorder)
2582 {
2583         int ret = RECORDER_ERROR_NONE;
2584         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_ERROR_CB;
2585         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2586
2587         if (!pc || !pc->cb_info) {
2588                 LOGE("NULL handle");
2589                 return RECORDER_ERROR_INVALID_PARAMETER;
2590         }
2591
2592         LOGD("ENTER");
2593
2594         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2595
2596         if (ret == RECORDER_ERROR_NONE) {
2597                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2598                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_ERROR] = NULL;
2599         }
2600
2601         LOGD("ret : 0x%x", ret);
2602
2603         return ret;
2604 }
2605
2606
2607 int recorder_set_recording_status_cb(recorder_h recorder, recorder_recording_status_cb callback, void *user_data)
2608 {
2609         int ret = RECORDER_ERROR_NONE;
2610         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2611         muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_STATUS_CB;
2612
2613         if (!pc || !pc->cb_info || callback == NULL) {
2614                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2615                 return RECORDER_ERROR_INVALID_PARAMETER;
2616         }
2617
2618         LOGD("Enter, handle :%x", pc->remote_handle);
2619
2620         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2621
2622         if (ret == RECORDER_ERROR_NONE) {
2623                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = callback;
2624                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = user_data;
2625         }
2626
2627         LOGD("ret : 0x%x", ret);
2628
2629         return ret;
2630 }
2631
2632
2633 int recorder_unset_recording_status_cb(recorder_h recorder)
2634 {
2635         int ret = RECORDER_ERROR_NONE;
2636         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_STATUS_CB;
2637         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2638
2639         if (!pc || !pc->cb_info) {
2640                 LOGE("NULL handle");
2641                 return RECORDER_ERROR_INVALID_PARAMETER;
2642         }
2643
2644         LOGD("ENTER");
2645
2646         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2647
2648         if (ret == RECORDER_ERROR_NONE) {
2649                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2650                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_STATUS] = NULL;
2651         }
2652
2653         LOGD("ret : 0x%x", ret);
2654
2655         return ret;
2656 }
2657
2658
2659 int recorder_set_recording_limit_reached_cb(recorder_h recorder, recorder_recording_limit_reached_cb callback, void *user_data)
2660 {
2661         int ret = RECORDER_ERROR_NONE;
2662         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2663         muse_recorder_api_e api = MUSE_RECORDER_API_SET_RECORDING_LIMIT_REACHED_CB;
2664
2665         if (!pc || !pc->cb_info || callback == NULL) {
2666                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2667                 return RECORDER_ERROR_INVALID_PARAMETER;
2668         }
2669
2670         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2671
2672         if (ret == RECORDER_ERROR_NONE) {
2673                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = callback;
2674                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = user_data;
2675         }
2676
2677         LOGD("ret : 0x%x", ret);
2678
2679         return ret;
2680 }
2681
2682
2683 int recorder_unset_recording_limit_reached_cb(recorder_h recorder)
2684 {
2685         int ret = RECORDER_ERROR_NONE;
2686         muse_recorder_api_e api = MUSE_RECORDER_API_UNSET_RECORDING_LIMIT_REACHED_CB;
2687         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2688
2689         if (!pc || !pc->cb_info) {
2690                 LOGE("NULL handle");
2691                 return RECORDER_ERROR_INVALID_PARAMETER;
2692         }
2693
2694         LOGD("ENTER");
2695
2696         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2697
2698         if (ret == RECORDER_ERROR_NONE) {
2699                 pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2700                 pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_RECORDING_LIMITED] = NULL;
2701         }
2702
2703         LOGD("ret : 0x%x", ret);
2704
2705         return ret;
2706 }
2707
2708
2709 int recorder_foreach_supported_file_format(recorder_h recorder, recorder_supported_file_format_cb foreach_cb, void *user_data)
2710 {
2711         int ret = RECORDER_ERROR_NONE;
2712         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2713         muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_FILE_FORMAT;
2714
2715         if (!pc || !pc->cb_info || foreach_cb == NULL) {
2716                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
2717                 return RECORDER_ERROR_INVALID_PARAMETER;
2718         }
2719
2720         LOGD("Enter, handle :%x", pc->remote_handle);
2721
2722         pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = foreach_cb;
2723         pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_FILE_FORMAT] = user_data;
2724
2725         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2726
2727         LOGD("ret : 0x%x", ret);
2728
2729         return ret;
2730 }
2731
2732
2733 int recorder_attr_set_size_limit(recorder_h recorder, int kbyte)
2734 {
2735         int ret = RECORDER_ERROR_NONE;
2736         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_SIZE_LIMIT;
2737         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2738         recorder_msg_param param;
2739
2740         if (!pc || !pc->cb_info) {
2741                 LOGE("NULL handle");
2742                 return RECORDER_ERROR_INVALID_PARAMETER;
2743         }
2744
2745         LOGD("ENTER");
2746
2747         RECORDER_MSG_PARAM_SET(param, INT, kbyte);
2748
2749         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2750
2751         LOGD("ret : 0x%x", ret);
2752
2753         return ret;
2754 }
2755
2756
2757 int recorder_attr_set_time_limit(recorder_h recorder, int second)
2758 {
2759         int ret = RECORDER_ERROR_NONE;
2760         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_TIME_LIMIT;
2761         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2762         recorder_msg_param param;
2763
2764         if (!pc || !pc->cb_info) {
2765                 LOGE("NULL handle");
2766                 return RECORDER_ERROR_INVALID_PARAMETER;
2767         }
2768
2769         LOGD("ENTER");
2770
2771         RECORDER_MSG_PARAM_SET(param, INT, second);
2772
2773         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2774
2775         LOGD("ret : 0x%x", ret);
2776
2777         return ret;
2778 }
2779
2780
2781 int recorder_attr_set_audio_device(recorder_h recorder, recorder_audio_device_e device)
2782 {
2783         int ret = RECORDER_ERROR_NONE;
2784         int set_device = (int)device;
2785         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_DEVICE;
2786         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2787         recorder_msg_param param;
2788
2789         if (!pc || !pc->cb_info) {
2790                 LOGE("NULL handle");
2791                 return RECORDER_ERROR_INVALID_PARAMETER;
2792         };
2793
2794         LOGD("ENTER");
2795
2796         RECORDER_MSG_PARAM_SET(param, INT, set_device);
2797
2798         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2799
2800         LOGD("ret : 0x%x", ret);
2801
2802         return ret;
2803 }
2804
2805
2806 int recorder_set_audio_encoder(recorder_h recorder, recorder_audio_codec_e codec)
2807 {
2808         int ret = RECORDER_ERROR_NONE;
2809         int set_codec = (int)codec;
2810         muse_recorder_api_e api = MUSE_RECORDER_API_SET_AUDIO_ENCODER;
2811         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2812         recorder_msg_param param;
2813
2814         if (!pc || !pc->cb_info) {
2815                 LOGE("NULL handle");
2816                 return RECORDER_ERROR_INVALID_PARAMETER;
2817         }
2818
2819         LOGD("ENTER");
2820
2821         RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2822
2823         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2824
2825         LOGD("ret : 0x%x", ret);
2826
2827         return ret;
2828 }
2829
2830
2831 int recorder_get_audio_encoder(recorder_h recorder, recorder_audio_codec_e *codec)
2832 {
2833         int ret = RECORDER_ERROR_NONE;
2834         muse_recorder_api_e api = MUSE_RECORDER_API_GET_AUDIO_ENCODER;
2835         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2836
2837         if (!pc || !pc->cb_info) {
2838                 LOGE("NULL handle");
2839                 return RECORDER_ERROR_INVALID_PARAMETER;
2840         }
2841
2842         if (codec == NULL) {
2843                 LOGE("codec is NULL");
2844                 return RECORDER_ERROR_INVALID_PARAMETER;
2845         }
2846
2847         LOGD("ENTER");
2848
2849         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2850
2851         if (ret == RECORDER_ERROR_NONE)
2852                 *codec = (recorder_audio_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER];
2853
2854         LOGD("ret : 0x%x, codec %d", ret, *codec);
2855
2856         return ret;
2857 }
2858
2859
2860 int recorder_set_video_encoder(recorder_h recorder, recorder_video_codec_e codec)
2861 {
2862         int ret = RECORDER_ERROR_NONE;
2863         int set_codec = (int)codec;
2864         muse_recorder_api_e api = MUSE_RECORDER_API_SET_VIDEO_ENCODER;
2865         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2866         recorder_msg_param param;
2867
2868         if (!pc || !pc->cb_info) {
2869                 LOGE("NULL handle");
2870                 return RECORDER_ERROR_INVALID_PARAMETER;
2871         }
2872
2873         LOGD("ENTER");
2874
2875         RECORDER_MSG_PARAM_SET(param, INT, set_codec);
2876
2877         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2878
2879         LOGD("ret : 0x%x", ret);
2880
2881         return ret;
2882 }
2883
2884
2885 int recorder_get_video_encoder(recorder_h recorder, recorder_video_codec_e *codec)
2886 {
2887         int ret = RECORDER_ERROR_NONE;
2888         muse_recorder_api_e api = MUSE_RECORDER_API_GET_VIDEO_ENCODER;
2889         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2890
2891         if (!pc || !pc->cb_info) {
2892                 LOGE("NULL handle");
2893                 return RECORDER_ERROR_INVALID_PARAMETER;
2894         }
2895
2896         if (codec == NULL) {
2897                 LOGE("codec is NULL");
2898                 return RECORDER_ERROR_INVALID_PARAMETER;
2899         }
2900
2901         LOGD("ENTER");
2902
2903         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
2904
2905         if (ret == RECORDER_ERROR_NONE)
2906                 *codec = (recorder_video_codec_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER];
2907
2908         LOGD("ret : 0x%x, codec %d", ret, *codec);
2909
2910         return ret;
2911 }
2912
2913
2914 int recorder_attr_set_audio_samplerate(recorder_h recorder, int samplerate)
2915 {
2916         int ret = RECORDER_ERROR_NONE;
2917         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_SAMPLERATE;
2918         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2919         recorder_msg_param param;
2920
2921         if (!pc || !pc->cb_info) {
2922                 LOGE("NULL handle");
2923                 return RECORDER_ERROR_INVALID_PARAMETER;
2924         }
2925
2926         LOGD("ENTER, samplerate : %d", samplerate);
2927
2928         RECORDER_MSG_PARAM_SET(param, INT, samplerate);
2929
2930         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2931
2932         LOGD("ret : 0x%x", ret);
2933
2934         return ret;
2935 }
2936
2937
2938 int recorder_attr_set_audio_encoder_bitrate(recorder_h recorder, int bitrate)
2939 {
2940         int ret = RECORDER_ERROR_NONE;
2941         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_ENCODER_BITRATE;
2942         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2943         recorder_msg_param param;
2944
2945         if (!pc || !pc->cb_info) {
2946                 LOGE("NULL handle");
2947                 return RECORDER_ERROR_INVALID_PARAMETER;
2948         }
2949
2950         LOGD("ENTER");
2951
2952         RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2953
2954         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2955
2956         LOGD("ret : 0x%x", ret);
2957
2958         return ret;
2959 }
2960
2961
2962 int recorder_attr_set_video_encoder_bitrate(recorder_h recorder, int bitrate)
2963 {
2964         int ret = RECORDER_ERROR_NONE;
2965         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_VIDEO_ENCODER_BITRATE;
2966         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2967         recorder_msg_param param;
2968
2969         if (!pc || !pc->cb_info) {
2970                 LOGE("NULL handle");
2971                 return RECORDER_ERROR_INVALID_PARAMETER;
2972         }
2973
2974         LOGD("ENTER");
2975
2976         RECORDER_MSG_PARAM_SET(param, INT, bitrate);
2977
2978         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
2979
2980         LOGD("ret : 0x%x", ret);
2981
2982         return ret;
2983 }
2984
2985
2986 int recorder_attr_get_size_limit(recorder_h recorder, int *kbyte)
2987 {
2988         int ret = RECORDER_ERROR_NONE;
2989         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_SIZE_LIMIT;
2990         recorder_cli_s *pc = (recorder_cli_s *)recorder;
2991
2992         if (!pc || !pc->cb_info) {
2993                 LOGE("NULL handle");
2994                 return RECORDER_ERROR_INVALID_PARAMETER;
2995         }
2996
2997         if (kbyte == NULL) {
2998                 LOGE("NULL pointer kbyte");
2999                 return RECORDER_ERROR_INVALID_PARAMETER;
3000         }
3001
3002         LOGD("ENTER");
3003
3004         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3005
3006         if (ret == RECORDER_ERROR_NONE)
3007                 *kbyte = pc->cb_info->get_int_value[_RECORDER_GET_INT_SIZE_LIMIT];
3008
3009         LOGD("ret : 0x%x, %d kbyte", ret, *kbyte);
3010
3011         return ret;
3012 }
3013
3014
3015 int recorder_attr_get_time_limit(recorder_h recorder, int *second)
3016 {
3017         int ret = RECORDER_ERROR_NONE;
3018         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_TIME_LIMIT;
3019         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3020
3021         if (!pc || !pc->cb_info) {
3022                 LOGE("NULL handle");
3023                 return RECORDER_ERROR_INVALID_PARAMETER;
3024         }
3025
3026         if (second == NULL) {
3027                 LOGE("NULL pointer second");
3028                 return RECORDER_ERROR_INVALID_PARAMETER;
3029         }
3030
3031         LOGD("ENTER");
3032
3033         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3034
3035         if (ret == RECORDER_ERROR_NONE)
3036                 *second = pc->cb_info->get_int_value[_RECORDER_GET_INT_TIME_LIMIT];
3037
3038         LOGD("ret : 0x%x, %d second", ret, *second);
3039
3040         return ret;
3041 }
3042
3043
3044 int recorder_attr_get_audio_device(recorder_h recorder, recorder_audio_device_e *device)
3045 {
3046         int ret = RECORDER_ERROR_NONE;
3047         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_DEVICE;
3048         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3049
3050         if (!pc || !pc->cb_info) {
3051                 LOGE("NULL handle");
3052                 return RECORDER_ERROR_INVALID_PARAMETER;
3053         }
3054
3055         if (device == NULL) {
3056                 LOGE("NULL pointer device");
3057                 return RECORDER_ERROR_INVALID_PARAMETER;
3058         }
3059
3060         LOGD("ENTER");
3061
3062         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3063
3064         if (ret == RECORDER_ERROR_NONE)
3065                 *device = (recorder_audio_device_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_DEVICE];
3066
3067         LOGD("ret : 0x%x, device %d", ret, *device);
3068
3069         return ret;
3070 }
3071
3072
3073 int recorder_attr_get_audio_samplerate(recorder_h recorder, int *samplerate)
3074 {
3075         int ret = RECORDER_ERROR_NONE;
3076         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_SAMPLERATE;
3077         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3078
3079         if (!pc || !pc->cb_info) {
3080                 LOGE("NULL handle");
3081                 return RECORDER_ERROR_INVALID_PARAMETER;
3082         }
3083
3084         if (samplerate == NULL) {
3085                 LOGE("NULL pointer handle");
3086                 return RECORDER_ERROR_INVALID_PARAMETER;
3087         }
3088
3089         LOGD("ENTER");
3090
3091         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3092
3093         if (ret == RECORDER_ERROR_NONE)
3094                 *samplerate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_SAMPLERATE];
3095
3096         LOGD("ret : 0x%x, samplerate %d", ret, *samplerate);
3097
3098         return ret;
3099 }
3100
3101
3102 int recorder_attr_get_audio_encoder_bitrate(recorder_h recorder, int *bitrate)
3103 {
3104         int ret = RECORDER_ERROR_NONE;
3105         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_ENCODER_BITRATE;
3106         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3107
3108         if (!pc || !pc->cb_info) {
3109                 LOGE("NULL handle");
3110                 return RECORDER_ERROR_INVALID_PARAMETER;
3111         }
3112
3113         if (bitrate == NULL) {
3114                 LOGE("NULL pointer");
3115                 return RECORDER_ERROR_INVALID_PARAMETER;
3116         }
3117
3118         LOGD("ENTER");
3119
3120         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3121
3122         if (ret == RECORDER_ERROR_NONE)
3123                 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_ENCODER_BITRATE];
3124
3125         LOGD("ret : 0x%x, bitrate %d", ret, *bitrate);
3126
3127         return ret;
3128 }
3129
3130
3131 int recorder_attr_get_video_encoder_bitrate(recorder_h recorder, int *bitrate)
3132 {
3133         int ret = RECORDER_ERROR_NONE;
3134         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_VIDEO_ENCODER_BITRATE;
3135         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3136
3137         if (!pc || !pc->cb_info) {
3138                 LOGE("NULL handle");
3139                 return RECORDER_ERROR_INVALID_PARAMETER;
3140         }
3141
3142         if (bitrate == NULL) {
3143                 LOGE("NULL pointer");
3144                 return RECORDER_ERROR_INVALID_PARAMETER;
3145         }
3146
3147         LOGD("ENTER");
3148
3149         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3150
3151         if (ret == RECORDER_ERROR_NONE)
3152                 *bitrate = pc->cb_info->get_int_value[_RECORDER_GET_INT_VIDEO_ENCODER_BITRATE];
3153
3154         LOGD("ret : 0x%x", ret);
3155
3156         return ret;
3157 }
3158
3159
3160 int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_supported_audio_encoder_cb foreach_cb, void *user_data)
3161 {
3162         int ret = RECORDER_ERROR_NONE;
3163         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3164         muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_AUDIO_ENCODER;
3165
3166         if (!pc || !pc->cb_info || foreach_cb == NULL) {
3167                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3168                 return RECORDER_ERROR_INVALID_PARAMETER;
3169         }
3170
3171         LOGD("Enter, handle :%x", pc->remote_handle);
3172
3173         pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = foreach_cb;
3174         pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_AUDIO_ENCODER] = user_data;
3175
3176         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3177
3178         LOGD("ret : 0x%x", ret);
3179
3180         return ret;
3181 }
3182
3183
3184 int recorder_foreach_supported_video_encoder(recorder_h recorder, recorder_supported_video_encoder_cb foreach_cb, void *user_data)
3185 {
3186         int ret = RECORDER_ERROR_NONE;
3187         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3188         muse_recorder_api_e api = MUSE_RECORDER_API_FOREACH_SUPPORTED_VIDEO_ENCODER;
3189
3190         if (!pc || !pc->cb_info || foreach_cb == NULL) {
3191                 LOGE("INVALID_PARAMETER(0x%08x)", RECORDER_ERROR_INVALID_PARAMETER);
3192                 return RECORDER_ERROR_INVALID_PARAMETER;
3193         }
3194
3195         LOGD("Enter, handle :%x", pc->remote_handle);
3196
3197         pc->cb_info->user_cb[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = foreach_cb;
3198         pc->cb_info->user_data[MUSE_RECORDER_EVENT_TYPE_FOREACH_SUPPORTED_VIDEO_ENCODER] = user_data;
3199
3200         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3201
3202         LOGD("ret : 0x%x", ret);
3203
3204         return ret;
3205 }
3206
3207
3208 int recorder_attr_set_mute(recorder_h recorder, bool enable)
3209 {
3210         int ret = RECORDER_ERROR_NONE;
3211         int set_enable = (int)enable;
3212         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_MUTE;
3213         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3214         recorder_msg_param param;
3215
3216         if (!pc || !pc->cb_info) {
3217                 LOGE("NULL handle");
3218                 return RECORDER_ERROR_INVALID_PARAMETER;
3219         }
3220
3221         LOGD("ENTER");
3222
3223         RECORDER_MSG_PARAM_SET(param, INT, set_enable);
3224
3225         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
3226
3227         LOGD("ret : 0x%x", ret);
3228
3229         return ret;
3230 }
3231
3232
3233 bool recorder_attr_is_muted(recorder_h recorder)
3234 {
3235         int ret = false;
3236         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_IS_MUTED;
3237         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3238
3239         if (!pc || !pc->cb_info) {
3240                 LOGE("NULL handle");
3241                 return false;
3242         }
3243
3244         LOGD("ENTER");
3245
3246         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3247
3248         if (ret == RECORDER_ERROR_SERVICE_DISCONNECTED)
3249                 ret = false;
3250
3251         LOGD("ret : %d", ret);
3252
3253         return (bool)ret;
3254 }
3255
3256
3257 int recorder_attr_set_recording_motion_rate(recorder_h recorder, double rate)
3258 {
3259         int ret = RECORDER_ERROR_NONE;
3260         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_RECORDING_MOTION_RATE;
3261         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3262         recorder_msg_param param;
3263
3264         if (!pc || !pc->cb_info) {
3265                 LOGE("NULL handle");
3266                 return RECORDER_ERROR_INVALID_PARAMETER;
3267         }
3268
3269         LOGD("ENTER - %.20lf", rate);
3270
3271         RECORDER_MSG_PARAM_SET(param, DOUBLE, rate);
3272
3273         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
3274
3275         LOGD("ret : 0x%x", ret);
3276
3277         return ret;
3278 }
3279
3280
3281 int recorder_attr_get_recording_motion_rate(recorder_h recorder, double *rate)
3282 {
3283         int ret = RECORDER_ERROR_NONE;
3284         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_RECORDING_MOTION_RATE;
3285         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3286
3287         if (!pc || !pc->cb_info) {
3288                 LOGE("NULL handle");
3289                 return RECORDER_ERROR_INVALID_PARAMETER;
3290         }
3291
3292         if (rate == NULL) {
3293                 LOGE("rate is NULL");
3294                 return RECORDER_ERROR_INVALID_PARAMETER;
3295         }
3296
3297         LOGD("ENTER");
3298
3299         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3300         if (ret == RECORDER_ERROR_NONE)
3301                 *rate = pc->cb_info->get_double_value[_RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE];
3302
3303         LOGD("ret : 0x%x - rate %.20lf", ret, *rate);
3304
3305         return ret;
3306 }
3307
3308
3309 int recorder_attr_set_audio_channel(recorder_h recorder, int channel_count)
3310 {
3311         int ret = RECORDER_ERROR_NONE;
3312         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_AUDIO_CHANNEL;
3313         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3314         recorder_msg_param param;
3315
3316         if (!pc || !pc->cb_info) {
3317                 LOGE("NULL handle");
3318                 return RECORDER_ERROR_INVALID_PARAMETER;
3319         }
3320
3321         LOGD("ENTER");
3322
3323         RECORDER_MSG_PARAM_SET(param, INT, channel_count);
3324
3325         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
3326
3327         LOGD("ret : 0x%x", ret);
3328
3329         return ret;
3330 }
3331
3332
3333 int recorder_attr_get_audio_channel(recorder_h recorder, int *channel_count)
3334 {
3335         int ret = RECORDER_ERROR_NONE;
3336         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_AUDIO_CHANNEL;
3337         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3338
3339         if (!pc || !pc->cb_info) {
3340                 LOGE("NULL handle");
3341                 return RECORDER_ERROR_INVALID_PARAMETER;
3342         }
3343
3344         if (channel_count == NULL) {
3345                 LOGE("channel_count is NULL");
3346                 return RECORDER_ERROR_INVALID_PARAMETER;
3347         }
3348
3349         LOGD("ENTER");
3350
3351         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3352
3353         if (ret == RECORDER_ERROR_NONE)
3354                 *channel_count = pc->cb_info->get_int_value[_RECORDER_GET_INT_AUDIO_CHANNEL];
3355
3356         LOGD("ret : 0x%x, channel count %d", ret, *channel_count);
3357
3358         return ret;
3359 }
3360
3361
3362 int recorder_attr_set_orientation_tag(recorder_h recorder, recorder_rotation_e orientation)
3363 {
3364         int ret = RECORDER_ERROR_NONE;
3365         int set_orientation = (int)orientation;
3366         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_SET_ORIENTATION_TAG;
3367         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3368         recorder_msg_param param;
3369
3370         if (!pc || !pc->cb_info) {
3371                 LOGE("NULL handle");
3372                 return RECORDER_ERROR_INVALID_PARAMETER;
3373         }
3374
3375         LOGD("ENTER");
3376
3377         RECORDER_MSG_PARAM_SET(param, INT, set_orientation);
3378
3379         _recorder_msg_send_param1(api, pc->cb_info, &ret, &param);
3380
3381         LOGD("ret : 0x%x", ret);
3382
3383         return ret;
3384 }
3385
3386
3387 int  recorder_attr_get_orientation_tag(recorder_h recorder, recorder_rotation_e *orientation)
3388 {
3389         int ret = RECORDER_ERROR_NONE;
3390         muse_recorder_api_e api = MUSE_RECORDER_API_ATTR_GET_ORIENTATION_TAG;
3391         recorder_cli_s *pc = (recorder_cli_s *)recorder;
3392
3393         if (!pc || !pc->cb_info) {
3394                 LOGE("NULL handle");
3395                 return RECORDER_ERROR_INVALID_PARAMETER;
3396         }
3397
3398         if (orientation == NULL) {
3399                 LOGE("orientation is NULL");
3400                 return RECORDER_ERROR_INVALID_PARAMETER;
3401         }
3402
3403         LOGD("ENTER");
3404
3405         _recorder_msg_send(api, pc->cb_info, &ret, RECORDER_CB_TIMEOUT);
3406
3407         if (ret == RECORDER_ERROR_NONE)
3408                 *orientation = (recorder_rotation_e)pc->cb_info->get_int_value[_RECORDER_GET_INT_ORIENTATION_TAG];
3409
3410         LOGD("ret : 0x%x, orientation %d", ret, *orientation);
3411
3412         return ret;
3413 }
3414
3415
3416 int recorder_get_device_state(recorder_type_e type, recorder_device_state_e *state)
3417 {
3418         int ret = RECORDER_ERROR_NONE;
3419         int sock_fd = -1;
3420         int get_device_state = 0;
3421         char *send_msg = NULL;
3422         char recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH] = {'\0',};
3423
3424         if (!state) {
3425                 LOGE("NULL pointer");
3426                 return RECORDER_ERROR_INVALID_PARAMETER;
3427         }
3428
3429         LOGD("Enter - type %d", type);
3430
3431         sock_fd = muse_core_client_new();
3432         if (sock_fd < 0) {
3433 //LCOV_EXCL_START
3434                 LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
3435                 ret = RECORDER_ERROR_INVALID_OPERATION;
3436                 goto _GET_DEVICE_STATE_EXIT;
3437 //LCOV_EXCL_STOP
3438         }
3439
3440         send_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_API_GET_DEVICE_STATE,
3441                 MUSE_TYPE_INT, "module", MUSE_RECORDER,
3442                 MUSE_TYPE_INT, PARAM_RECORDER_TYPE, type,
3443                 NULL);
3444         if (!send_msg) {
3445 //LCOV_EXCL_START
3446                 LOGE("NULL msg");
3447                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3448                 goto _GET_DEVICE_STATE_EXIT;
3449 //LCOV_EXCL_STOP
3450         }
3451
3452         LOGD("sock_fd : %d, msg : %s", sock_fd, send_msg);
3453
3454         ret = muse_core_ipc_send_msg(sock_fd, send_msg);
3455
3456         muse_core_msg_json_factory_free(send_msg);
3457         send_msg = NULL;
3458
3459         if (ret < 0) {
3460 //LCOV_EXCL_START
3461                 LOGE("send msg failed %d", errno);
3462                 ret = RECORDER_ERROR_INVALID_OPERATION;
3463                 goto _GET_DEVICE_STATE_EXIT;
3464 //LCOV_EXCL_STOP
3465         }
3466
3467         ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
3468         if (ret <= 0) {
3469 //LCOV_EXCL_START
3470                 LOGE("recv msg failed %d", errno);
3471                 ret = RECORDER_ERROR_INVALID_OPERATION;
3472                 goto _GET_DEVICE_STATE_EXIT;
3473 //LCOV_EXCL_STOP
3474         }
3475
3476         if (!muse_recorder_msg_get(ret, recv_msg)) {
3477 //LCOV_EXCL_START
3478                 LOGE("failed to get return value from msg [%s]", recv_msg);
3479                 ret = RECORDER_ERROR_INVALID_OPERATION;
3480                 goto _GET_DEVICE_STATE_EXIT;
3481 //LCOV_EXCL_STOP
3482         }
3483
3484         if (ret == RECORDER_ERROR_NONE) {
3485                 if (muse_recorder_msg_get(get_device_state, recv_msg)) {
3486                         *state = (recorder_device_state_e)get_device_state;
3487                         LOGD("device type %d state %d", type, *state);
3488                 } else {
3489                         LOGE("failed to get device state from msg [%s]", recv_msg);
3490                         ret = RECORDER_ERROR_INVALID_OPERATION;
3491                 }
3492         } else {
3493                 LOGE("failed 0x%x", ret);
3494         }
3495
3496 _GET_DEVICE_STATE_EXIT:
3497         if (sock_fd > -1) {
3498                 muse_core_connection_close(sock_fd);
3499                 sock_fd = -1;
3500         }
3501
3502         return ret;
3503 }
3504
3505
3506 int recorder_add_device_state_changed_cb(recorder_device_state_changed_cb callback, void *user_data, int *cb_id)
3507 {
3508         int ret = RECORDER_ERROR_NONE;
3509         recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3510         recorder_cb_info *info = NULL;
3511
3512         if (!callback || !cb_id) {
3513                 LOGE("invalid pointer %p %p", callback, cb_id);
3514                 return RECORDER_ERROR_INVALID_PARAMETER;
3515         }
3516
3517         g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3518
3519         /* check recorder support */
3520         ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3521         if (ret != RECORDER_ERROR_NONE) {
3522                 LOGE("get device state failed");
3523                 g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3524                 return ret;
3525         }
3526
3527         info = g_new0(recorder_cb_info, 1);
3528         if (!info) {
3529                 LOGE("info failed");
3530                 ret = RECORDER_ERROR_OUT_OF_MEMORY;
3531                 goto _DONE;
3532         }
3533
3534         info->id = ++g_rec_dev_state_changed_cb_id;
3535         info->callback = (void *)callback;
3536         info->user_data = user_data;
3537
3538         *cb_id = info->id;
3539
3540         /* subscribe dbus signal for camera state change */
3541         if (!g_rec_dev_state_changed_cb_conn) {
3542                 g_rec_dev_state_changed_cb_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
3543                 if (!g_rec_dev_state_changed_cb_conn) {
3544                         LOGE("failed to get gdbus connection");
3545                         ret = RECORDER_ERROR_INVALID_OPERATION;
3546                         goto _DONE;
3547                 }
3548
3549                 LOGD("subscribe signal %s - %s - %s",
3550                         MM_CAMCORDER_DBUS_OBJECT,
3551                         MM_CAMCORDER_DBUS_INTERFACE_RECORDER,
3552                         MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED);
3553
3554                 g_rec_dev_state_changed_cb_subscribe_id = g_dbus_connection_signal_subscribe(g_rec_dev_state_changed_cb_conn,
3555                         NULL, MM_CAMCORDER_DBUS_INTERFACE_RECORDER, MM_CAMCORDER_DBUS_SIGNAL_STATE_CHANGED, MM_CAMCORDER_DBUS_OBJECT, NULL,
3556                         G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)__recorder_device_state_changed_cb, NULL, NULL);
3557                 if (!g_rec_dev_state_changed_cb_subscribe_id) {
3558                         LOGE("failed to get gdbus connection");
3559                         ret = RECORDER_ERROR_INVALID_OPERATION;
3560                         goto _DONE;
3561                 }
3562
3563                 LOGD("signal subscribe id %u", g_rec_dev_state_changed_cb_subscribe_id);
3564         }
3565
3566         g_rec_dev_state_changed_cb_list = g_list_prepend(g_rec_dev_state_changed_cb_list, (gpointer)info);
3567
3568         LOGD("callback id %d", info->id);
3569
3570 _DONE:
3571         if (ret != RECORDER_ERROR_NONE) {
3572 //LCOV_EXCL_START
3573                 if (info) {
3574                         g_free(info);
3575                         info = NULL;
3576                 }
3577
3578                 if (g_rec_dev_state_changed_cb_conn) {
3579                         g_object_unref(g_rec_dev_state_changed_cb_conn);
3580                         g_rec_dev_state_changed_cb_conn = NULL;
3581                 }
3582 //LCOV_EXCL_STOP
3583         }
3584
3585         g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3586
3587         return ret;
3588 }
3589
3590
3591 int recorder_remove_device_state_changed_cb(int cb_id)
3592 {
3593         int ret = RECORDER_ERROR_NONE;
3594         recorder_device_state_e state = RECORDER_DEVICE_STATE_IDLE;
3595         GList *tmp_list = NULL;
3596         recorder_cb_info *info = NULL;
3597
3598         /* check recorder support */
3599         ret = recorder_get_device_state(RECORDER_TYPE_AUDIO, &state);
3600         if (ret != RECORDER_ERROR_NONE) {
3601                 LOGE("get device state failed");
3602                 return ret;
3603         }
3604
3605         g_mutex_lock(&g_rec_dev_state_changed_cb_lock);
3606
3607         if (!g_rec_dev_state_changed_cb_list) {
3608                 LOGE("there is no callback info");
3609                 ret = RECORDER_ERROR_INVALID_OPERATION;
3610                 goto _DONE;
3611         }
3612
3613         tmp_list = g_rec_dev_state_changed_cb_list;
3614
3615         do {
3616                 info = tmp_list->data;
3617                 tmp_list = tmp_list->next;
3618
3619                 if (!info) {
3620                         LOGW("NULL info");
3621                         continue;
3622                 }
3623
3624                 if (info->id == cb_id) {
3625                         g_rec_dev_state_changed_cb_list = g_list_remove(g_rec_dev_state_changed_cb_list, info);
3626
3627                         g_free(info);
3628                         info = NULL;
3629
3630                         if (!g_rec_dev_state_changed_cb_list) {
3631                                 /* no remained callback */
3632                                 if (g_rec_dev_state_changed_cb_conn) {
3633                                         /* unsubscribe signal */
3634                                         g_dbus_connection_signal_unsubscribe(g_rec_dev_state_changed_cb_conn, g_rec_dev_state_changed_cb_subscribe_id);
3635                                         g_rec_dev_state_changed_cb_subscribe_id = 0;
3636
3637                                         /* unref connection */
3638                                         g_object_unref(g_rec_dev_state_changed_cb_conn);
3639                                         g_rec_dev_state_changed_cb_conn = NULL;
3640                                 }
3641                         }
3642
3643                         LOGD("id %d callback removed", cb_id);
3644                         ret = RECORDER_ERROR_NONE;
3645
3646                         goto _DONE;
3647                 }
3648         } while (tmp_list);
3649
3650         LOGE("id %d callback not found", cb_id);
3651         ret = RECORDER_ERROR_INVALID_PARAMETER;
3652
3653 _DONE:
3654         g_mutex_unlock(&g_rec_dev_state_changed_cb_lock);
3655
3656         return ret;
3657 }