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 ========================================================================================*/
33 /*=======================================================================================
34 | GLOBAL DEFINITIONS AND DECLARATIONS FOR CAMCORDER |
35 ========================================================================================*/
37 /*=======================================================================================
39 ========================================================================================*/
41 #define CLEAR(x) memset (&(x), 0, sizeof (x))
44 #define MMCAMCORDER_ADD_BUFFER_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
46 MMCamcorderHandlerItem *item = NULL; \
47 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
49 _mmcam_dbg_err("Cannot connect buffer probe [malloc fail] \n"); \
50 } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
51 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
53 item->object = G_OBJECT(x_pad); \
54 item->category = x_category; \
55 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \
56 x_hcamcorder->buffer_probes = g_list_append(x_hcamcorder->buffer_probes, item); \
57 _mmcam_dbg_log("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
61 #define MMCAMCORDER_ADD_EVENT_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
63 MMCamcorderHandlerItem *item = NULL; \
64 item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
66 _mmcam_dbg_err("Cannot connect buffer probe [malloc fail] \n"); \
68 else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
69 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
71 item->object =G_OBJECT(x_pad); \
72 item->category = x_category; \
73 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \
74 x_hcamcorder->event_probes = g_list_append(x_hcamcorder->event_probes, item); \
75 _mmcam_dbg_log("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
79 #define MMCAMCORDER_ADD_DATA_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
81 MMCamcorderHandlerItem *item = NULL; \
82 item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
84 _mmcam_dbg_err("Cannot connect buffer probe [malloc fail] \n"); \
85 } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
86 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
88 item->object =G_OBJECT(x_pad); \
89 item->category = x_category; \
90 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_DATA_BOTH, x_callback, x_hcamcorder, NULL); \
91 x_hcamcorder->data_probes = g_list_append(x_hcamcorder->data_probes, item); \
92 _mmcam_dbg_log("Adding data probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
96 #define MMCAMCORDER_SIGNAL_CONNECT( x_object, x_category, x_signal, x_callback, x_hcamcorder) \
98 MMCamcorderHandlerItem* item = NULL; \
99 item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
101 _mmcam_dbg_err("Cannot connect signal [%s]\n", x_signal ); \
102 } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
103 _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
105 item->object = G_OBJECT(x_object); \
106 item->category = x_category; \
107 item->handler_id = g_signal_connect(G_OBJECT(x_object), x_signal,\
108 G_CALLBACK(x_callback), x_hcamcorder ); \
109 x_hcamcorder->signals = g_list_append(x_hcamcorder->signals, item); \
110 _mmcam_dbg_log("Connecting signal on [%s] - [ID : %lu], [Category : %x] ", GST_OBJECT_NAME(item->object), item->handler_id, item->category); \
114 #define MMCAMCORDER_G_OBJECT_GET(obj, name, value) \
117 if(g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
118 g_object_get(G_OBJECT(obj), name, value, NULL); \
120 _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
123 _mmcam_dbg_err("Null object"); \
127 #define MMCAMCORDER_G_OBJECT_SET(obj, name, value) \
130 if(g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
131 g_object_set(G_OBJECT(obj), name, value, NULL); \
133 _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
136 _mmcam_dbg_err("Null object"); \
140 #define MMCAM_FOURCC(a,b,c,d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
141 #define MMCAM_FOURCC_ARGS(fourcc) \
142 ((gchar)((fourcc)&0xff)), \
143 ((gchar)(((fourcc)>>8)&0xff)), \
144 ((gchar)(((fourcc)>>16)&0xff)), \
145 ((gchar)(((fourcc)>>24)&0xff))
147 #define MMCAM_SEND_MESSAGE(handle, msg_id, msg_code) \
149 _MMCamcorderMsgItem msg;\
151 msg.param.code = msg_code;\
152 _mmcam_dbg_log("msg id : %x, code : %x", msg_id, msg_code);\
153 _mmcamcroder_send_message((MMHandleType)handle, &msg);\
157 /*=======================================================================================
159 ========================================================================================*/
161 *Type define of util.
164 _MMCAMCORDER_HANDLER_PREVIEW = (1 << 0),
165 _MMCAMCORDER_HANDLER_VIDEOREC = (1 << 1),
166 _MMCAMCORDER_HANDLER_STILLSHOT = (1 << 2),
167 _MMCAMCORDER_HANDLER_AUDIOREC = (1 << 3),
168 } _MMCamcorderHandlerCategory;
170 /*=======================================================================================
171 | STRUCTURE DEFINITIONS |
172 ========================================================================================*/
175 * Structure of location info
181 } _MMCamcorderLocationInfo;
184 * Structure of handler item
188 _MMCamcorderHandlerCategory category;
190 } MMCamcorderHandlerItem;
193 * Structure of message item
196 MMHandleType handle; /**< handle */
197 int id; /**< message id */
198 MMMessageParamType param; /**< message parameter */
199 } _MMCamcorderMsgItem;
202 * Structure of zero copy image buffer
204 #define SCMN_IMGB_MAX_PLANE (4)
206 /* image buffer definition ***************************************************
208 +------------------------------------------+ ---
211 | +---------------------------+ --- | |
213 | |<---------- w[] ---------->| | | |
221 | +---------------------------+ --- | |
223 +------------------------------------------+ ---
225 |<----------------- s[] ------------------>|
230 /* width of each image plane */
231 int w[SCMN_IMGB_MAX_PLANE];
232 /* height of each image plane */
233 int h[SCMN_IMGB_MAX_PLANE];
234 /* stride of each image plane */
235 int s[SCMN_IMGB_MAX_PLANE];
236 /* elevation of each image plane */
237 int e[SCMN_IMGB_MAX_PLANE];
238 /* user space address of each image plane */
239 void *a[SCMN_IMGB_MAX_PLANE];
240 /* physical address of each image plane, if needs */
241 void *p[SCMN_IMGB_MAX_PLANE];
242 /* color space type of image */
244 /* left postion, if needs */
246 /* top position, if needs */
248 /* to align memory */
254 /*=======================================================================================
255 | CONSTANT DEFINITIONS |
256 ========================================================================================*/
257 #define _MMCAMCORDER_HANDLER_CATEGORY_ALL \
258 (_MMCAMCORDER_HANDLER_PREVIEW | _MMCAMCORDER_HANDLER_VIDEOREC |_MMCAMCORDER_HANDLER_STILLSHOT | _MMCAMCORDER_HANDLER_AUDIOREC)
260 /*=======================================================================================
261 | GLOBAL FUNCTION PROTOTYPES |
262 ========================================================================================*/
264 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
265 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
266 void _mmcamcorder_remove_data_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
267 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category);
268 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category);
269 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was);
270 gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list);
271 gboolean _mmcamcorder_link_elements(GList *element_list);
274 gboolean _mmcamcroder_msg_callback(void *data);
275 gboolean _mmcamcroder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data);
276 void _mmcamcroder_remove_message_all(MMHandleType handle);
279 int _mmcamcorder_get_pixel_format(GstCaps *pad);
280 int _mmcamcorder_get_pixtype(unsigned int fourcc);
281 unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format);
284 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
285 int src_format, unsigned int src_length, unsigned int jpeg_quality,
286 void **result_data, unsigned int *result_length);
288 gboolean _mmcamcorder_resize_frame(unsigned char *src_data, int src_width, int src_height, int src_length, int src_format,
289 unsigned char **dst_data, int *dst_width, int *dst_height, int *dst_length);
292 /* find top level tag only, do not use this function for finding sub level tags.
293 tag_fourcc is Four-character-code (FOURCC) */
294 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
295 gint32 _mmcamcorder_double_to_fix(gdouble d_number);
296 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos);
297 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info);
298 gboolean _mmcamcorder_write_udta(FILE *f, _MMCamcorderLocationInfo info);
299 guint64 _mmcamcorder_get_container_size(const guchar *size);
300 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation);
303 int _mmcamcorder_get_freespace(const gchar *path, guint64 *free_space);
304 int _mmcamcorder_get_file_size(const char *filename, guint64 *size);
307 void _mmcamcorder_err_trace_write(char *str_filename, char *func_name, int line_num, char *fmt, ...);
313 #endif /* __MM_CAMCORDER_UTIL_H__ */