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>
31 #include <gst/video/cameracontrol.h>
38 /*=======================================================================================
39 | GLOBAL DEFINITIONS AND DECLARATIONS FOR CAMCORDER |
40 ========================================================================================*/
43 /*=======================================================================================
45 ========================================================================================*/
47 #define CLEAR(x) memset(&(x), 0, sizeof(x))
51 #define MMCAM_LOG_CRITICAL(format, args...) \
53 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_CRITICAL) \
54 SLOGF(format, ##args); \
57 #define MMCAM_LOG_ERROR(format, args...) \
59 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_ERROR) \
60 SLOGE(format, ##args); \
63 #define MMCAM_LOG_WARNING(format, args...) \
65 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_WARNING) \
66 SLOGW(format, ##args); \
69 #define MMCAM_LOG_INFO(format, args...) \
71 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_INFO) \
72 SLOGI(format, ##args); \
75 #define MMCAM_LOG_DEBUG(format, args...) \
77 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_DEBUG) \
78 SLOGD(format, ##args); \
81 #define MMCAM_LOG_VERBOSE(format, args...) \
83 if (_mmcamcorder_get_log_level() >= MM_CAMCORDER_LOG_LEVEL_VERBOSE) \
84 SLOGD("[V] "format, ##args); \
87 #define MMCAMCORDER_ADD_BUFFER_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
89 MMCamcorderHandlerItem *item = NULL; \
90 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
91 if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
92 MMCAM_LOG_ERROR("Invalid handler category : %x", x_category); \
94 item->object = G_OBJECT(x_pad); \
95 item->category = x_category; \
96 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \
97 x_hcamcorder->buffer_probes = g_list_append(x_hcamcorder->buffer_probes, item); \
98 MMCAM_LOG_INFO("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", \
99 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
103 #define MMCAMCORDER_ADD_EVENT_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
105 MMCamcorderHandlerItem *item = NULL; \
106 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
107 if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
108 MMCAM_LOG_ERROR("Invalid handler category : %x", x_category); \
110 item->object = G_OBJECT(x_pad); \
111 item->category = x_category; \
112 item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \
113 x_hcamcorder->event_probes = g_list_append(x_hcamcorder->event_probes, item); \
114 MMCAM_LOG_INFO("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", \
115 GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
119 #define MMCAMCORDER_SIGNAL_CONNECT(x_object, x_category, x_signal, x_callback, x_hcamcorder) \
121 MMCamcorderHandlerItem* item = NULL; \
122 item = (MMCamcorderHandlerItem *)g_malloc(sizeof(MMCamcorderHandlerItem)); \
123 if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
124 MMCAM_LOG_ERROR("Invalid handler category : %x", x_category); \
126 item->object = G_OBJECT(x_object); \
127 item->category = x_category; \
128 item->handler_id = g_signal_connect(G_OBJECT(x_object), x_signal, \
129 G_CALLBACK(x_callback), x_hcamcorder); \
130 x_hcamcorder->signals = g_list_append(x_hcamcorder->signals, item); \
131 MMCAM_LOG_INFO("Connecting signal on [%s][%p] - [ID : %lu], [Category : %x] ", \
132 GST_OBJECT_NAME(item->object), item->object, item->handler_id, item->category); \
136 #define MMCAMCORDER_G_OBJECT_GET(obj, name, value) \
139 if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
140 g_object_get(G_OBJECT(obj), name, value, NULL); \
142 MMCAM_LOG_WARNING("The object doesn't have a property named(%s)", name); \
145 MMCAM_LOG_ERROR("Null object"); \
149 #define MMCAMCORDER_G_OBJECT_SET(obj, name, value) \
152 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
154 if (spec->value_type == G_TYPE_INT64) {\
155 g_object_set(G_OBJECT(obj), name, (gint64)value, NULL); \
156 } else if (spec->value_type == G_TYPE_UINT64) { \
157 g_object_set(G_OBJECT(obj), name, (guint64)value, NULL); \
158 } else if (spec->value_type == G_TYPE_FLOAT) { \
159 g_object_set(G_OBJECT(obj), name, (float)value, NULL); \
160 } else if (spec->value_type == G_TYPE_DOUBLE) { \
161 g_object_set(G_OBJECT(obj), name, (double)value, NULL); \
163 g_object_set(G_OBJECT(obj), name, value, NULL); \
166 MMCAM_LOG_WARNING("The object doesn't have a property named(%s)", name); \
169 MMCAM_LOG_ERROR("Null object"); \
173 #define MMCAMCORDER_G_OBJECT_SET_POINTER(obj, name, value) \
176 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
178 g_object_set(G_OBJECT(obj), name, value, NULL); \
180 MMCAM_LOG_WARNING("The object doesn't have a property named(%s)", name); \
183 MMCAM_LOG_ERROR("Null object"); \
187 #define MMCAM_FOURCC(a, b, c, d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
188 #define MMCAM_FOURCC_ARGS(fourcc) \
189 ((gchar)((fourcc)&0xff)), \
190 ((gchar)(((fourcc)>>8)&0xff)), \
191 ((gchar)(((fourcc)>>16)&0xff)), \
192 ((gchar)(((fourcc)>>24)&0xff))
194 #define MMCAM_SEND_MESSAGE(handle, msg_id, msg_code) \
196 _MMCamcorderMsgItem msg;\
198 msg.param.code = msg_code;\
199 MMCAM_LOG_INFO("msg id : %x, code : %x", msg_id, msg_code);\
200 _mmcamcorder_send_message((MMHandleType)handle, &msg);\
204 /*=======================================================================================
206 ========================================================================================*/
208 * Structure of GDBus Callback.
217 } _MMCamcorderGDbusCbInfo;
220 *Type define of util.
223 _MMCAMCORDER_HANDLER_PREVIEW = (1 << 0),
224 _MMCAMCORDER_HANDLER_VIDEOREC = (1 << 1),
225 _MMCAMCORDER_HANDLER_STILLSHOT = (1 << 2),
226 _MMCAMCORDER_HANDLER_AUDIOREC = (1 << 3),
227 _MMCAMCORDER_HANDLER_EXTRA_PREVIEW = (1 << 4),
228 } _MMCamcorderHandlerCategory;
230 /*=======================================================================================
231 | STRUCTURE DEFINITIONS |
232 ========================================================================================*/
235 * Structure of location info
241 } _MMCamcorderLocationInfo;
244 * Structure of handler item
248 _MMCamcorderHandlerCategory category;
250 } MMCamcorderHandlerItem;
253 * Structure of message item
256 MMHandleType handle; /**< handle */
257 int id; /**< message id */
258 MMMessageParamType param; /**< message parameter */
259 GMutex lock; /**< mutex for item */
260 } _MMCamcorderMsgItem;
263 * Structure of storage information
268 } _MMCamcorderStorageInfo;
271 /*=======================================================================================
272 | CONSTANT DEFINITIONS |
273 ========================================================================================*/
274 #define G_DBUS_TIMEOUT 3000
275 #define FAT32_FILE_SYSTEM_MAX_SIZE (4294967295UL) /* 4 GigaByte - 1 byte */
276 #define _MMCAMCORDER_HANDLER_CATEGORY_ALL \
277 (_MMCAMCORDER_HANDLER_PREVIEW |\
278 _MMCAMCORDER_HANDLER_VIDEOREC |\
279 _MMCAMCORDER_HANDLER_STILLSHOT |\
280 _MMCAMCORDER_HANDLER_AUDIOREC |\
281 _MMCAMCORDER_HANDLER_EXTRA_PREVIEW)
284 /*=======================================================================================
285 | GLOBAL FUNCTION PROTOTYPES |
286 ========================================================================================*/
288 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
289 void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object);
290 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
291 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category);
292 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category);
293 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was);
294 gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list);
295 gboolean _mmcamcorder_link_elements(GList *element_list);
296 GstCaps *_mmcamcorder_get_video_caps(MMHandleType handle, MMPixelFormatType format, int width, int height, int fps, int rotate);
299 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
300 gboolean _mmcamcorder_msg_callback(void *data);
301 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
302 gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data);
303 void _mmcamcorder_remove_message_all(MMHandleType handle);
306 int _mmcamcorder_get_pixel_format(GstCaps *caps, gboolean is_preview);
307 int _mmcamcorder_get_pixtype(unsigned int fourcc);
308 unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format);
309 MMPixelFormatType _mmcamcorder_get_pixel_format2(GstCameraControlImageFormat img_fmt);
310 GstCameraControlImageFormat _mmcamcorder_get_camera_control_image_format(int pixel_format);
313 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
314 int src_format, unsigned int src_length, unsigned int jpeg_quality,
315 void **result_data, unsigned int *result_length);
317 gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_width, unsigned int src_height, unsigned int src_length, int src_format,
318 unsigned char **dst_data, unsigned int *dst_width, unsigned int *dst_height, size_t *dst_length);
319 gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height,
320 unsigned char **dst, unsigned int dst_width, unsigned int dst_height);
323 /* find top level tag only, do not use this function for finding sub level tags.
324 tag_fourcc is Four-character-code (FOURCC) */
325 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
326 gboolean _mmcamcorder_find_fourcc(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
327 gint32 _mmcamcorder_double_to_fix(gdouble d_number);
328 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos);
329 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info);
330 gboolean _mmcamcorder_write_geodata(FILE *f, _MMCamcorderLocationInfo info);
331 gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationInfo info, _MMCamcorderLocationInfo geotag);
332 guint64 _mmcamcorder_get_container_size(const guchar *size);
333 guint64 _mmcamcorder_get_container_size64(const guchar *size);
334 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation);
335 void _mmcamcorder_adjust_recording_max_size(const char *filename, guint64 *max_size);
338 int _mmcamcorder_get_storage_validity(MMHandleType handle, const char *filename, guint64 min_space, gboolean *storage_validity);
339 int _mmcamcorder_get_storage_info(const gchar *path, const gchar *root_directory, _MMCamcorderStorageInfo *storage_info);
340 int _mmcamcorder_get_freespace(storage_type_e type, guint64 *free_space);
341 int _mmcamcorder_get_file_size(const char *filename, guint64 *size);
342 int _mmcamcorder_get_file_system_type(const gchar *path, int *file_system_type);
345 void *_mmcamcorder_util_task_thread_func(void *data);
348 int _mmcamcorder_get_camera_id(int device_type, int *camera_id);
349 int _mmcamcorder_get_device_led_brightness(GDBusConnection *conn, int *brightness);
351 /* sound play via dbus*/
352 int _mmcamcorder_send_sound_play_message(GDBusConnection *conn, _MMCamcorderGDbusCbInfo *gdbus_info,
353 const char *sample_name, const char *stream_role, const char *volume_gain, int sync_play);
355 /* request to show pop-up related DPM policy */
356 void _mmcamcorder_request_dpm_popup(GDBusConnection *conn, const char *restricted_policy);
358 /* dbus signal emit */
359 void _mmcamcorder_emit_dbus_signal(GDBusConnection *conn, const char *object_name,
360 const char *interface_name, const char *signal_name, int value);
363 int _mmcamcorder_get_audiosrc_blocksize(int samplerate, int format, int channel, int interval, int *blocksize);
365 /* check encoded pixel format */
366 gboolean _mmcamcorder_is_encoded_preview_pixel_format(int pixel_format);
369 void _mmcamcorder_set_log_level(int level);
370 int _mmcamcorder_get_log_level(void);
373 void _mmcamcorder_measure_fps(void *data);
380 #endif /* __MM_CAMCORDER_UTIL_H__ */