4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #ifndef __MM_CAMCORDER_UTIL_H__
23 #define __MM_CAMCORDER_UTIL_H__
25 /*=======================================================================================
27 ========================================================================================*/
28 #include <linux/magic.h>
35 /*=======================================================================================
36 | GLOBAL DEFINITIONS AND DECLARATIONS FOR CAMCORDER |
37 ========================================================================================*/
39 /*=======================================================================================
41 ========================================================================================*/
43 #define CLEAR(x) memset (&(x), 0, sizeof (x))
46 #define MMCAMCORDER_ADD_BUFFER_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
48 MMCamcorderHandlerItem *item = NULL; \
49 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
51 _mmcam_dbg_err("Cannot connect buffer probe [malloc fail] \n"); \
52 } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
53 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
55 item->object = G_OBJECT(x_pad); \
56 item->category = x_category; \
57 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \
58 x_hcamcorder->buffer_probes = g_list_append(x_hcamcorder->buffer_probes, item); \
59 _mmcam_dbg_log("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
63 #define MMCAMCORDER_ADD_EVENT_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
65 MMCamcorderHandlerItem *item = NULL; \
66 item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
68 _mmcam_dbg_err("Cannot connect buffer probe [malloc fail] \n"); \
70 else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
71 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
73 item->object =G_OBJECT(x_pad); \
74 item->category = x_category; \
75 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \
76 x_hcamcorder->event_probes = g_list_append(x_hcamcorder->event_probes, item); \
77 _mmcam_dbg_log("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
81 #define MMCAMCORDER_SIGNAL_CONNECT( x_object, x_category, x_signal, x_callback, x_hcamcorder) \
83 MMCamcorderHandlerItem* item = NULL; \
84 item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
86 _mmcam_dbg_err("Cannot connect signal [%s]\n", x_signal ); \
87 } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
88 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
90 item->object = G_OBJECT(x_object); \
91 item->category = x_category; \
92 item->handler_id = g_signal_connect(G_OBJECT(x_object), x_signal,\
93 G_CALLBACK(x_callback), x_hcamcorder ); \
94 x_hcamcorder->signals = g_list_append(x_hcamcorder->signals, item); \
95 _mmcam_dbg_log("Connecting signal on [%s][%p] - [ID : %lu], [Category : %x] ", GST_OBJECT_NAME(item->object), item->object, item->handler_id, item->category); \
99 #define MMCAMCORDER_G_OBJECT_GET(obj, name, value) \
102 if(g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
103 g_object_get(G_OBJECT(obj), name, value, NULL); \
105 _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
108 _mmcam_dbg_err("Null object"); \
112 #define MMCAMCORDER_G_OBJECT_SET(obj, name, value) \
115 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
117 if (spec->value_type == G_TYPE_INT64) {\
118 g_object_set(G_OBJECT(obj), name, (gint64)value, NULL); \
119 } else if (spec->value_type == G_TYPE_UINT64) { \
120 g_object_set(G_OBJECT(obj), name, (guint64)value, NULL); \
121 } else if (spec->value_type == G_TYPE_FLOAT) { \
122 g_object_set(G_OBJECT(obj), name, (float)value, NULL); \
123 } else if (spec->value_type == G_TYPE_DOUBLE) { \
124 g_object_set(G_OBJECT(obj), name, (double)value, NULL); \
126 g_object_set(G_OBJECT(obj), name, value, NULL); \
129 _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
132 _mmcam_dbg_err("Null object"); \
136 #define MMCAMCORDER_G_OBJECT_SET_POINTER(obj, name, value) \
139 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
141 g_object_set(G_OBJECT(obj), name, value, NULL); \
143 _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
146 _mmcam_dbg_err("Null object"); \
150 #define MMCAM_FOURCC(a,b,c,d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
151 #define MMCAM_FOURCC_ARGS(fourcc) \
152 ((gchar)((fourcc)&0xff)), \
153 ((gchar)(((fourcc)>>8)&0xff)), \
154 ((gchar)(((fourcc)>>16)&0xff)), \
155 ((gchar)(((fourcc)>>24)&0xff))
157 #define MMCAM_SEND_MESSAGE(handle, msg_id, msg_code) \
159 _MMCamcorderMsgItem msg;\
161 msg.param.code = msg_code;\
162 _mmcam_dbg_log("msg id : %x, code : %x", msg_id, msg_code);\
163 _mmcamcorder_send_message((MMHandleType)handle, &msg);\
167 /*=======================================================================================
169 ========================================================================================*/
171 *Type define of util.
174 _MMCAMCORDER_HANDLER_PREVIEW = (1 << 0),
175 _MMCAMCORDER_HANDLER_VIDEOREC = (1 << 1),
176 _MMCAMCORDER_HANDLER_STILLSHOT = (1 << 2),
177 _MMCAMCORDER_HANDLER_AUDIOREC = (1 << 3),
178 } _MMCamcorderHandlerCategory;
180 /*=======================================================================================
181 | STRUCTURE DEFINITIONS |
182 ========================================================================================*/
185 * Structure of location info
191 } _MMCamcorderLocationInfo;
194 * Structure of handler item
198 _MMCamcorderHandlerCategory category;
200 } MMCamcorderHandlerItem;
203 * Structure of message item
206 MMHandleType handle; /**< handle */
207 int id; /**< message id */
208 MMMessageParamType param; /**< message parameter */
209 pthread_mutex_t lock; /**< mutex for item */
210 } _MMCamcorderMsgItem;
213 /*=======================================================================================
214 | CONSTANT DEFINITIONS |
215 ========================================================================================*/
216 #define FAT32_FILE_SYSTEM_MAX_SIZE (4294967295UL) /* 4 GigaByte - 1 byte */
217 #define NANO_SEC_PER_MILI_SEC 1000000
218 #define _MMCAMCORDER_HANDLER_CATEGORY_ALL \
219 (_MMCAMCORDER_HANDLER_PREVIEW | _MMCAMCORDER_HANDLER_VIDEOREC |_MMCAMCORDER_HANDLER_STILLSHOT | _MMCAMCORDER_HANDLER_AUDIOREC)
220 #define G_DBUS_REPLY_TIMEOUT (120 * 1000)
222 /*=======================================================================================
223 | GLOBAL FUNCTION PROTOTYPES |
224 ========================================================================================*/
226 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
227 void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object);
228 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
229 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category);
230 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category);
231 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was);
232 gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list);
233 gboolean _mmcamcorder_link_elements(GList *element_list);
236 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
237 gboolean _mmcamcorder_msg_callback(void *data);
238 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
239 gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data);
240 void _mmcamcorder_remove_message_all(MMHandleType handle);
243 int _mmcamcorder_get_pixel_format(GstCaps *pad);
244 int _mmcamcorder_get_pixtype(unsigned int fourcc);
245 unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format);
248 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
249 int src_format, unsigned int src_length, unsigned int jpeg_quality,
250 void **result_data, unsigned int *result_length);
252 gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_width, unsigned int src_height, unsigned int src_length, int src_format,
253 unsigned char **dst_data, unsigned int *dst_width, unsigned int *dst_height, unsigned int *dst_length);
254 gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height,
255 unsigned char **dst, unsigned int dst_width, unsigned int dst_height);
258 /* find top level tag only, do not use this function for finding sub level tags.
259 tag_fourcc is Four-character-code (FOURCC) */
260 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
261 gboolean _mmcamcorder_find_fourcc(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
262 gint32 _mmcamcorder_double_to_fix(gdouble d_number);
263 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos);
264 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info);
265 gboolean _mmcamcorder_write_geodata(FILE *f,_MMCamcorderLocationInfo info);
266 gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationInfo info, _MMCamcorderLocationInfo geotag);
267 guint64 _mmcamcorder_get_container_size(const guchar *size);
268 guint64 _mmcamcorder_get_container_size64(const guchar *size);
269 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation);
272 int _mmcamcorder_get_freespace(const gchar *path, const gchar *root_directory, guint64 *free_space);
273 int _mmcamcorder_get_file_size(const char *filename, guint64 *size);
274 int _mmcamcorder_get_file_system_type(const gchar *path, int *file_system_type);
277 void *_mmcamcorder_util_task_thread_func(void *data);
280 int _mmcamcorder_get_device_flash_brightness(int *brightness);
286 #endif /* __MM_CAMCORDER_UTIL_H__ */