Update idle event handling to fix crash in idle event callback
[platform/core/api/recorder.git] / include / recorder_private.h
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
18
19 #ifndef __TIZEN_MULTIMEDIA_RECORDER_PRIVATE_H__
20 #define __TIZEN_MULTIMEDIA_RECORDER_PRIVATE_H__
21 #include <camera.h>
22 #include <recorder.h>
23 #include <muse_core.h>
24 #include <glib.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define RECORDER_CB_TIMEOUT        5
31 #define RECORDER_CB_NO_TIMEOUT     0
32 #define RECORDER_FILENAME_MAX      256
33
34 #define RECORDER_MSG_PARAM_SET(param, msg_type, set_value) { \
35         param.type = MUSE_TYPE_##msg_type; \
36         param.name = #set_value; \
37         param.value.value_##msg_type = set_value; \
38 }
39
40 enum {
41         _RECORDER_GET_INT_STATE = 0,
42         _RECORDER_GET_INT_VIDEO_RESOLUTION,
43         _RECORDER_GET_INT_FILE_FORMAT,
44         _RECORDER_GET_INT_AUDIO_ENCODER,
45         _RECORDER_GET_INT_VIDEO_ENCODER,
46         _RECORDER_GET_INT_SIZE_LIMIT,
47         _RECORDER_GET_INT_TIME_LIMIT,
48         _RECORDER_GET_INT_AUDIO_DEVICE,
49         _RECORDER_GET_INT_AUDIO_SAMPLERATE,
50         _RECORDER_GET_INT_AUDIO_ENCODER_BITRATE,
51         _RECORDER_GET_INT_VIDEO_ENCODER_BITRATE,
52         _RECORDER_GET_INT_AUDIO_CHANNEL,
53         _RECORDER_GET_INT_ORIENTATION_TAG,
54         _RECORDER_GET_INT_MAX
55 };
56
57 enum {
58         _RECORDER_GET_DOUBLE_AUDIO_LEVEL = 0,
59         _RECORDER_GET_DOUBLE_RECORDING_MOTION_RATE,
60         _RECORDER_GET_DOUBLE_MAX
61 };
62
63 enum {
64         _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL,
65         _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB,
66         _RECORDER_MESSAGE_HANDLER_TYPE_MUXED_STREAM_CB
67 };
68
69 typedef struct _recorder_msg_handler_info_s {
70         int type;
71         void *cb_info;
72         int running;
73         GCond cond;
74         GMutex mutex;
75         GQueue *queue;
76         GThread *thread;
77 } recorder_msg_handler_info_s;
78
79 typedef struct _recorder_cb_info_s {
80         /* server connection */
81         gint fd;
82         gboolean is_server_connected;
83
84         /* message receive thread */
85         GThread *msg_recv_thread;
86         gint msg_recv_running;
87         gchar recv_msg[MUSE_MSG_MAX_LENGTH + 1];
88         GCond api_cond[MUSE_RECORDER_API_MAX];
89         GMutex api_mutex[MUSE_RECORDER_API_MAX];
90         gint api_activating[MUSE_RECORDER_API_MAX];
91         gint api_waiting[MUSE_RECORDER_API_MAX];
92         gint api_ret[MUSE_RECORDER_API_MAX];
93
94         /* general message handler info */
95         recorder_msg_handler_info_s msg_handler_info;
96
97         /* audio stream cb message handler info */
98         recorder_msg_handler_info_s audio_stream_cb_info;
99
100         /* muxed stream cb message handler info */
101         recorder_msg_handler_info_s muxed_stream_cb_info;
102
103         /* idle event */
104         GList *idle_event_list;
105
106         /* user callback */
107         gpointer user_cb[MUSE_RECORDER_EVENT_TYPE_NUM];
108         gpointer user_data[MUSE_RECORDER_EVENT_TYPE_NUM];
109         GMutex user_cb_mutex[MUSE_RECORDER_EVENT_TYPE_NUM];
110
111         /* tbm */
112         tbm_bufmgr bufmgr;
113
114         /* get values */
115         char *get_filename;
116         gint get_int_value[_RECORDER_GET_INT_MAX];
117         gdouble get_double_value[_RECORDER_GET_DOUBLE_MAX];
118         gboolean is_filename_converted;
119 } recorder_cb_info_s;
120
121 typedef struct _recorder_message_s {
122         gchar recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH + 1];
123         muse_recorder_api_e api;
124         muse_recorder_event_e event;
125         muse_recorder_event_class_e event_class;
126 } recorder_message_s;
127
128 typedef struct _recorder_idle_event_s {
129         recorder_cb_info_s *cb_info;
130         gchar recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH + 1];
131         muse_recorder_event_e event;
132         GMutex event_mutex;
133 } recorder_idle_event_s;
134
135 typedef struct _recorder_cli_s {
136         intptr_t remote_handle;
137         recorder_cb_info_s *cb_info;
138         camera_h camera;
139 } recorder_cli_s;
140
141 typedef struct _recorder_msg_param {
142         int type;
143         const char *name;
144         union {
145                 int value_INT;
146                 double value_DOUBLE;
147                 const char *value_STRING;
148         } value;
149 } recorder_msg_param;
150
151 typedef struct _camera_cli_s {
152         intptr_t remote_handle;
153         void *cb_info;
154 } camera_cli_s;
155
156 typedef struct _recorder_cb_info {
157         int id;
158         void *callback;
159         void *user_data;
160 } recorder_cb_info;
161
162 int __convert_recorder_error_code(const char *func, int code);
163
164 #ifdef __cplusplus
165 }
166 #endif
167
168 #endif /* __TIZEN_MULTIMEDIA_RECORDER_PRIVATE_H__ */
169
170