Fix build warnings
[platform/core/api/recorder.git] / src / recorder.c
index cc5ea19..e240071 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 #include <camera_internal.h>
 #include <recorder.h>
 #include <sound_manager.h>
@@ -35,8 +36,8 @@
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
-#define LOG_TAG "TIZEN_N_RECORDER"
-#define MODULE_NAME "recorder"
+#define LOG_TAG         "TIZEN_N_RECORDER"
+#define MODULE_NAME     "recorder"
 
 /* for device changed callback */
 static GMutex g_rec_dev_state_changed_cb_lock;
@@ -217,8 +218,8 @@ static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *re
                        int64_t cb_elapsed_time = 0;
                        int64_t cb_file_size = 0;
 
-                       muse_recorder_msg_get(cb_elapsed_time, recv_msg);
-                       muse_recorder_msg_get(cb_file_size, recv_msg);
+                       muse_recorder_msg_get_int64(cb_elapsed_time, recv_msg);
+                       muse_recorder_msg_get_int64(cb_file_size, recv_msg);
 
                        ((recorder_recording_status_cb)cb_info->user_cb[event])((unsigned long long)cb_elapsed_time,
                                (unsigned long long)cb_file_size,
@@ -282,10 +283,15 @@ static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *re
                                        muse_recorder_msg_get(channel, recv_msg);
                                        muse_recorder_msg_get(timestamp, recv_msg);
 
+                                       LOGD("%p, size %d, format %d, channel %d, timestamp %d",
+                                               bo_handle.ptr, size, format, channel, timestamp);
+
                                        ((recorder_audio_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
                                                size, (audio_sample_type_e)format, channel,
                                                (unsigned int)timestamp, cb_info->user_data[event]);
 
+                                       LOGD("returned");
+
                                        /* release imported bo */
                                        _recorder_release_imported_bo(&bo);
                                } else {
@@ -332,11 +338,15 @@ static void _recorder_client_user_callback(recorder_cb_info_s *cb_info, char *re
                        if (cb_info->user_cb[event]) {
                                if (_recorder_import_tbm_fd(cb_info->bufmgr, tfd, &bo, &bo_handle)) {
                                        muse_recorder_msg_get(size, recv_msg);
-                                       muse_recorder_msg_get(offset, recv_msg);
+                                       muse_recorder_msg_get_int64(offset, recv_msg);
+
+                                       LOGD("%p, size %d, offset %"PRId64, bo_handle.ptr, size, offset);
 
                                        ((recorder_muxed_stream_cb)cb_info->user_cb[event])((void *)bo_handle.ptr,
                                                size, (unsigned long long)offset, cb_info->user_data[event]);
 
+                                       LOGD("returned");
+
                                        /* release imported bo */
                                        _recorder_release_imported_bo(&bo);
                                } else {
@@ -781,7 +791,7 @@ static void __recorder_process_msg(recorder_cb_info_s *cb_info, char *msg, int t
 
                if (cb_info->api_waiting[api] > 0) {
                        cb_info->api_ret[api] = ret;
-                       cb_info->api_activating[api] = 1;
+                       cb_info->api_activating[api] = TRUE;
 
                        g_cond_signal(&cb_info->api_cond[api]);
                } else {
@@ -850,9 +860,9 @@ static void *_recorder_msg_handler_func(gpointer data)
                        if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
                                if (cb_info->api_waiting[api] > 0) {
                                        cb_info->api_ret[api] = ret;
-                                       cb_info->api_activating[api] = 1;
+                                       cb_info->api_activating[api] = TRUE;
 
-                                       /*LOGD("recorder api %d - return 0x%x", ret);*/
+                                       /*LOGD("recorder api %d - return 0x%x", api, ret);*/
 
                                        g_cond_signal(&cb_info->api_cond[api]);
                                } else {
@@ -878,7 +888,7 @@ static void *_recorder_msg_handler_func(gpointer data)
                                rec_idle_event->event = rec_msg->event;
                                rec_idle_event->cb_info = cb_info;
 
-                               strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
+                               strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg));
 
                                /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
 
@@ -1174,36 +1184,33 @@ static int _recorder_client_wait_for_cb_return(muse_recorder_api_e api, recorder
 
        g_mutex_lock(&(cb_info->api_mutex[api]));
 
-       if (cb_info->api_activating[api] == 0) {
+       LOGD("api [%d], timeout [%d sec]", api, time_out);
+
+       end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
+
+       while (!cb_info->api_activating[api]) {
                if (time_out == RECORDER_CB_NO_TIMEOUT) {
-                       LOGW("wait for api %d", api);
                        g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
-                       ret = cb_info->api_ret[api];
-                       cb_info->api_activating[api] = 0;
-                       LOGW("api %d returned 0x%x", api, ret);
-               } else {
-                       end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
-                       if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
-                               ret = cb_info->api_ret[api];
-                               cb_info->api_activating[api] = 0;
-                               /*LOGD("return value : 0x%x", ret);*/
-                       } else {
-                               ret = RECORDER_ERROR_INVALID_OPERATION;
-                               LOGE("api %d was TIMED OUT!", api);
-                       }
+                       LOGW("api %d returned 0x%x", api, cb_info->api_ret[api]);
+               } else if (!g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
+                       LOGE("api %d was TIMED OUT!", api);
+                       ret = RECORDER_ERROR_INVALID_OPERATION;
+                       goto _CB_RETURN_END;
                }
-       } else {
-               ret = cb_info->api_ret[api];
-               cb_info->api_activating[api] = 0;
 
-               /*LOGD("condition is already checked for the api[%d], return[0x%x]", api, ret);*/
+               if (!cb_info->api_activating[api])
+                       LOGW("invalid signal received, wait again...");
        }
 
-       if (ret != RECORDER_ERROR_NONE)
-               LOGE("ERROR : api %d - ret 0x%x", api, ret);
+       ret = cb_info->api_ret[api];
+       cb_info->api_activating[api] = FALSE;
 
+_CB_RETURN_END:
        g_mutex_unlock(&(cb_info->api_mutex[api]));
 
+       if (ret != RECORDER_ERROR_NONE)
+               LOGE("ERROR : api %d - ret 0x%x", api, ret);
+
        return ret;
 }
 
@@ -1348,7 +1355,7 @@ static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
 }
 
 
-static int _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+static bool _recorder_storage_device_supported_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)
 {
        char **root_directory = (char **)user_data;