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 ========================================================================================*/
29 #include <linux/magic.h>
37 /*=======================================================================================
38 | GLOBAL DEFINITIONS AND DECLARATIONS FOR CAMCORDER |
39 ========================================================================================*/
42 /*=======================================================================================
44 ========================================================================================*/
46 #define CLEAR(x) memset(&(x), 0, sizeof(x))
50 #define MMCAM_LOG_CRITICAL(format, args...) \
52 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_CRITICAL) \
53 SLOGF(format, ##args); \
56 #define MMCAM_LOG_ERROR(format, args...) \
58 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_ERROR) \
59 SLOGE(format, ##args); \
62 #define MMCAM_LOG_WARNING(format, args...) \
64 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_WARNING) \
65 SLOGW(format, ##args); \
68 #define MMCAM_LOG_INFO(format, args...) \
70 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_INFO) \
71 SLOGI(format, ##args); \
74 #define MMCAM_LOG_DEBUG(format, args...) \
76 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_DEBUG) \
77 SLOGD(format, ##args); \
80 #define MMCAM_LOG_VERBOSE(format, args...) \
82 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_VERBOSE) \
83 SLOGD("[V] "format, ##args); \
86 #define MMCAMCORDER_ADD_BUFFER_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
88 MMCamcorderHandlerItem *item = NULL; \
89 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
90 if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
91 MMCAM_LOG_ERROR("Invalid handler category : %x", x_category); \
93 item->object = G_OBJECT(x_pad); \
94 item->category = x_category; \
95 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \
96 x_hcamcorder->buffer_probes = g_list_append(x_hcamcorder->buffer_probes, item); \
97 MMCAM_LOG_INFO("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", \
98 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
102 #define MMCAMCORDER_ADD_EVENT_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
104 MMCamcorderHandlerItem *item = NULL; \
105 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
106 if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
107 MMCAM_LOG_ERROR("Invalid handler category : %x", x_category); \
109 item->object = G_OBJECT(x_pad); \
110 item->category = x_category; \
111 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \
112 x_hcamcorder->event_probes = g_list_append(x_hcamcorder->event_probes, item); \
113 MMCAM_LOG_INFO("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", \
114 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
118 #define MMCAMCORDER_SIGNAL_CONNECT(x_object, x_category, x_signal, x_callback, x_hcamcorder) \
120 MMCamcorderHandlerItem* item = NULL; \
121 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
122 if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
123 MMCAM_LOG_ERROR("Invalid handler category : %x", x_category); \
125 item->object = G_OBJECT(x_object); \
126 item->category = x_category; \
127 item->handler_id = g_signal_connect(G_OBJECT(x_object), x_signal, \
128 G_CALLBACK(x_callback), x_hcamcorder); \
129 x_hcamcorder->signals = g_list_append(x_hcamcorder->signals, item); \
130 MMCAM_LOG_INFO("Connecting signal on [%s][%p] - [ID : %lu], [Category : %x] ", \
131 GST_OBJECT_NAME(item->object), item->object, item->handler_id, item->category); \
135 #define MMCAMCORDER_G_OBJECT_GET(obj, name, value) \
138 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
139 g_object_get(G_OBJECT(obj), name, value, NULL); \
141 MMCAM_LOG_WARNING("The object doesn't have a property named(%s)", name); \
144 MMCAM_LOG_ERROR("Null object"); \
148 #define MMCAMCORDER_G_OBJECT_SET(obj, name, value) \
151 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
153 if (spec->value_type == G_TYPE_INT64) {\
154 g_object_set(G_OBJECT(obj), name, (gint64)value, NULL); \
155 } else if (spec->value_type == G_TYPE_UINT64) { \
156 g_object_set(G_OBJECT(obj), name, (guint64)value, NULL); \
157 } else if (spec->value_type == G_TYPE_FLOAT) { \
158 g_object_set(G_OBJECT(obj), name, (float)value, NULL); \
159 } else if (spec->value_type == G_TYPE_DOUBLE) { \
160 g_object_set(G_OBJECT(obj), name, (double)value, NULL); \
162 g_object_set(G_OBJECT(obj), name, value, NULL); \
165 MMCAM_LOG_WARNING("The object doesn't have a property named(%s)", name); \
168 MMCAM_LOG_ERROR("Null object"); \
172 #define MMCAMCORDER_G_OBJECT_SET_POINTER(obj, name, value) \
175 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
177 g_object_set(G_OBJECT(obj), name, value, NULL); \
179 MMCAM_LOG_WARNING("The object doesn't have a property named(%s)", name); \
182 MMCAM_LOG_ERROR("Null object"); \
186 #define MMCAM_FOURCC(a, b, c, d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
187 #define MMCAM_FOURCC_ARGS(fourcc) \
188 ((gchar)((fourcc)&0xff)), \
189 ((gchar)(((fourcc)>>8)&0xff)), \
190 ((gchar)(((fourcc)>>16)&0xff)), \
191 ((gchar)(((fourcc)>>24)&0xff))
193 #define MMCAM_SEND_MESSAGE(handle, msg_id, msg_code) \
195 _MMCamcorderMsgItem msg;\
197 msg.param.code = msg_code;\
198 MMCAM_LOG_INFO("msg id : %x, code : %x", msg_id, msg_code);\
199 _mmcamcorder_send_message((MMHandleType)handle, &msg);\
203 /*=======================================================================================
205 ========================================================================================*/
207 * Structure of GDBus Callback.
216 } _MMCamcorderGDbusCbInfo;
219 *Type define of util.
222 _MMCAMCORDER_HANDLER_PREVIEW = (1 << 0),
223 _MMCAMCORDER_HANDLER_VIDEOREC = (1 << 1),
224 _MMCAMCORDER_HANDLER_STILLSHOT = (1 << 2),
225 _MMCAMCORDER_HANDLER_AUDIOREC = (1 << 3),
226 } _MMCamcorderHandlerCategory;
228 /*=======================================================================================
229 | STRUCTURE DEFINITIONS |
230 ========================================================================================*/
233 * Structure of location info
239 } _MMCamcorderLocationInfo;
242 * Structure of handler item
246 _MMCamcorderHandlerCategory category;
248 } MMCamcorderHandlerItem;
251 * Structure of message item
254 MMHandleType handle; /**< handle */
255 int id; /**< message id */
256 MMMessageParamType param; /**< message parameter */
257 GMutex lock; /**< mutex for item */
258 } _MMCamcorderMsgItem;
261 * Structure of storage information
266 } _MMCamcorderStorageInfo;
269 /*=======================================================================================
270 | CONSTANT DEFINITIONS |
271 ========================================================================================*/
272 #define G_DBUS_TIMEOUT 3000
273 #define FAT32_FILE_SYSTEM_MAX_SIZE (4294967295UL) /* 4 GigaByte - 1 byte */
274 #define _MMCAMCORDER_HANDLER_CATEGORY_ALL \
275 (_MMCAMCORDER_HANDLER_PREVIEW | _MMCAMCORDER_HANDLER_VIDEOREC |_MMCAMCORDER_HANDLER_STILLSHOT | _MMCAMCORDER_HANDLER_AUDIOREC)
278 /*=======================================================================================
279 | GLOBAL FUNCTION PROTOTYPES |
280 ========================================================================================*/
282 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
283 void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object);
284 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
285 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category);
286 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category);
287 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was);
288 gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list);
289 gboolean _mmcamcorder_link_elements(GList *element_list);
292 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
293 gboolean _mmcamcorder_msg_callback(void *data);
294 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
295 gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data);
296 void _mmcamcorder_remove_message_all(MMHandleType handle);
299 int _mmcamcorder_get_pixel_format(GstCaps *pad);
300 int _mmcamcorder_get_pixtype(unsigned int fourcc);
301 unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format);
304 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
305 int src_format, unsigned int src_length, unsigned int jpeg_quality,
306 void **result_data, unsigned int *result_length);
308 gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_width, unsigned int src_height, unsigned int src_length, int src_format,
309 unsigned char **dst_data, unsigned int *dst_width, unsigned int *dst_height, size_t *dst_length);
310 gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height,
311 unsigned char **dst, unsigned int dst_width, unsigned int dst_height);
314 /* find top level tag only, do not use this function for finding sub level tags.
315 tag_fourcc is Four-character-code (FOURCC) */
316 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
317 gboolean _mmcamcorder_find_fourcc(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
318 gint32 _mmcamcorder_double_to_fix(gdouble d_number);
319 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos);
320 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info);
321 gboolean _mmcamcorder_write_geodata(FILE *f, _MMCamcorderLocationInfo info);
322 gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationInfo info, _MMCamcorderLocationInfo geotag);
323 guint64 _mmcamcorder_get_container_size(const guchar *size);
324 guint64 _mmcamcorder_get_container_size64(const guchar *size);
325 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation);
326 void _mmcamcorder_adjust_recording_max_size(const char *filename, guint64 *max_size);
329 int _mmcamcorder_get_storage_validity(MMHandleType handle, const char *filename, guint64 min_space, gboolean *storage_validity);
330 int _mmcamcorder_get_storage_info(const gchar *path, const gchar *root_directory, _MMCamcorderStorageInfo *storage_info);
331 int _mmcamcorder_get_freespace(storage_type_e type, guint64 *free_space);
332 int _mmcamcorder_get_file_size(const char *filename, guint64 *size);
333 int _mmcamcorder_get_file_system_type(const gchar *path, int *file_system_type);
336 void *_mmcamcorder_util_task_thread_func(void *data);
339 int _mmcamcorder_get_device_led_brightness(GDBusConnection *conn, int *brightness);
341 /* sound play via dbus*/
342 int _mmcamcorder_send_sound_play_message(GDBusConnection *conn, _MMCamcorderGDbusCbInfo *gdbus_info,
343 const char *sample_name, const char *stream_role, const char *volume_gain, int sync_play);
345 /* request to show pop-up related DPM policy */
346 void _mmcamcorder_request_dpm_popup(GDBusConnection *conn, const char *restricted_policy);
348 /* dbus signal emit */
349 void _mmcamcorder_emit_dbus_signal(GDBusConnection *conn, const char *object_name,
350 const char *interface_name, const char *signal_name, int value);
353 int _mmcamcorder_get_audiosrc_blocksize(int samplerate, int format, int channel, int interval, int *blocksize);
355 /* check encoded pixel format */
356 gboolean _mmcamcorder_is_encoded_preview_pixel_format(int pixel_format);
359 void _mmcamcorder_set_log_level(int level);
360 int _mmcamcorder_get_log_level(void);
367 #endif /* __MM_CAMCORDER_UTIL_H__ */