Add new field to configure to control interval of audio buffer
[platform/core/multimedia/libmm-camcorder.git] / src / include / mm_camcorder_util.h
index 67333c4..75a8a6a 100644 (file)
 /*=======================================================================================
 | INCLUDE FILES                                                                                |
 ========================================================================================*/
+#include <gio/gio.h>
+#include <linux/magic.h>
+#include <storage.h>
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,7 +42,7 @@ extern "C" {
 | MACRO DEFINITIONS                                                                    |
 ========================================================================================*/
 #ifndef CLEAR
-#define CLEAR(x)            memset (&(x), 0, sizeof (x))
+#define CLEAR(x)            memset(&(x), 0, sizeof(x))
 #endif
 
 #define MMCAMCORDER_ADD_BUFFER_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
@@ -52,9 +56,10 @@ do { \
        } else { \
                item->object = G_OBJECT(x_pad); \
                item->category = x_category; \
-        item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \
+               item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_BUFFER, x_callback, x_hcamcorder, NULL); \
                x_hcamcorder->buffer_probes = g_list_append(x_hcamcorder->buffer_probes, item); \
-               _mmcam_dbg_log("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
+               _mmcam_dbg_log("Adding buffer probe on [%s:%s] - [ID : %lu], [Category : %x] ", \
+                       GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
        } \
 } while (0);
 
@@ -68,81 +73,91 @@ do { \
        else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
                _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
        } else { \
-               item->object =G_OBJECT(x_pad); \
+               item->object = G_OBJECT(x_pad); \
                item->category = x_category; \
-        item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \
+               item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, x_callback, x_hcamcorder, NULL); \
                x_hcamcorder->event_probes = g_list_append(x_hcamcorder->event_probes, item); \
-               _mmcam_dbg_log("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
-       } \
-} while (0);
-
-#define MMCAMCORDER_ADD_DATA_PROBE(x_pad, x_category, x_callback, x_hcamcorder) \
-do { \
-       MMCamcorderHandlerItem *item = NULL; \
-       item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
-       if (!item) { \
-               _mmcam_dbg_err("Cannot connect buffer probe [malloc fail] \n"); \
-       } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
-               _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
-       } else { \
-               item->object =G_OBJECT(x_pad); \
-               item->category = x_category; \
-        item->handler_id = gst_pad_add_probe(x_pad, GST_PAD_PROBE_TYPE_DATA_BOTH, x_callback, x_hcamcorder, NULL); \
-               x_hcamcorder->data_probes = g_list_append(x_hcamcorder->data_probes, item); \
-               _mmcam_dbg_log("Adding data probe on [%s:%s] - [ID : %lu], [Category : %x] ", GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
+               _mmcam_dbg_log("Adding event probe on [%s:%s] - [ID : %lu], [Category : %x] ", \
+                       GST_DEBUG_PAD_NAME(item->object), item->handler_id, item->category); \
        } \
 } while (0);
 
-#define MMCAMCORDER_SIGNAL_CONNECT( x_object, x_category, x_signal, x_callback, x_hcamcorder) \
+#define MMCAMCORDER_SIGNAL_CONNECT(x_object, x_category, x_signal, x_callback, x_hcamcorder) \
 do { \
        MMCamcorderHandlerItem* item = NULL; \
        item = (MMCamcorderHandlerItem *) g_malloc(sizeof(MMCamcorderHandlerItem)); \
        if (!item) { \
-               _mmcam_dbg_err("Cannot connect signal [%s]\n", x_signal ); \
+               _mmcam_dbg_err("Cannot connect signal [%s]\n", x_signal); \
        } else if (x_category == 0 || !(x_category & _MMCAMCORDER_HANDLER_CATEGORY_ALL)) { \
                _mmcam_dbg_err("Invalid handler category : %x \n", x_category); \
        } else { \
                item->object = G_OBJECT(x_object); \
                item->category = x_category; \
-               item->handler_id = g_signal_connect(G_OBJECT(x_object), x_signal,\
-                                                   G_CALLBACK(x_callback), x_hcamcorder ); \
+               item->handler_id = g_signal_connect(G_OBJECT(x_object), x_signal, \
+                       G_CALLBACK(x_callback), x_hcamcorder); \
                x_hcamcorder->signals = g_list_append(x_hcamcorder->signals, item); \
-               _mmcam_dbg_log("Connecting signal on [%s] - [ID : %lu], [Category : %x] ", GST_OBJECT_NAME(item->object), item->handler_id, item->category); \
+               _mmcam_dbg_log("Connecting signal on [%s][%p] - [ID : %lu], [Category : %x] ", \
+                       GST_OBJECT_NAME(item->object), item->object, item->handler_id, item->category); \
        } \
 } while (0);
 
 #define MMCAMCORDER_G_OBJECT_GET(obj, name, value) \
 do { \
        if (obj) { \
-               if(g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
+               if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
                        g_object_get(G_OBJECT(obj), name, value, NULL); \
                } else { \
-                       _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
+                       _mmcam_dbg_warn("The object doesn't have a property named(%s)", name); \
                } \
        } else { \
                _mmcam_dbg_err("Null object"); \
        } \
-} while(0);
+} while (0);
 
 #define MMCAMCORDER_G_OBJECT_SET(obj, name, value) \
 do { \
        if (obj) { \
-               if(g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name)) { \
+               GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
+               if (spec) { \
+                       if (spec->value_type == G_TYPE_INT64) {\
+                               g_object_set(G_OBJECT(obj), name, (gint64)value, NULL); \
+                       } else if (spec->value_type == G_TYPE_UINT64) { \
+                               g_object_set(G_OBJECT(obj), name, (guint64)value, NULL); \
+                       } else if (spec->value_type == G_TYPE_FLOAT) { \
+                               g_object_set(G_OBJECT(obj), name, (float)value, NULL); \
+                       } else if (spec->value_type == G_TYPE_DOUBLE) { \
+                               g_object_set(G_OBJECT(obj), name, (double)value, NULL); \
+                       } else { \
+                               g_object_set(G_OBJECT(obj), name, value, NULL); \
+                       } \
+               } else { \
+                       _mmcam_dbg_warn("The object doesn't have a property named(%s)", name); \
+               } \
+       } else { \
+               _mmcam_dbg_err("Null object"); \
+       } \
+} while (0);
+
+#define MMCAMCORDER_G_OBJECT_SET_POINTER(obj, name, value) \
+do { \
+       if (obj) { \
+               GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(obj)), name);\
+               if (spec) { \
                        g_object_set(G_OBJECT(obj), name, value, NULL); \
                } else { \
-                       _mmcam_dbg_warn ("The object doesn't have a property named(%s)", name); \
+                       _mmcam_dbg_warn("The object doesn't have a property named(%s)", name); \
                } \
        } else { \
                _mmcam_dbg_err("Null object"); \
        } \
-} while(0);
+} while (0);
 
-#define MMCAM_FOURCC(a,b,c,d)  (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
+#define MMCAM_FOURCC(a, b, c, d)  (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
 #define MMCAM_FOURCC_ARGS(fourcc) \
-        ((gchar)((fourcc)&0xff)), \
-        ((gchar)(((fourcc)>>8)&0xff)), \
-        ((gchar)(((fourcc)>>16)&0xff)), \
-        ((gchar)(((fourcc)>>24)&0xff))
+               ((gchar)((fourcc)&0xff)), \
+               ((gchar)(((fourcc)>>8)&0xff)), \
+               ((gchar)(((fourcc)>>16)&0xff)), \
+               ((gchar)(((fourcc)>>24)&0xff))
 
 #define MMCAM_SEND_MESSAGE(handle, msg_id, msg_code) \
 {\
@@ -150,7 +165,7 @@ do { \
        msg.id = msg_id;\
        msg.param.code = msg_code;\
        _mmcam_dbg_log("msg id : %x, code : %x", msg_id, msg_code);\
-       _mmcamcroder_send_message((MMHandleType)handle, &msg);\
+       _mmcamcorder_send_message((MMHandleType)handle, &msg);\
 }
 
 
@@ -158,6 +173,18 @@ do { \
 | ENUM DEFINITIONS                                                                     |
 ========================================================================================*/
 /**
+ * Structure of GDBus Callback.
+ */
+typedef struct {
+       GCond sync_cond;
+       GMutex sync_mutex;
+       int param;
+       int is_playing;
+       guint subscribe_id;
+       void *mm_handle;
+} _MMCamcorderGDbusCbInfo;
+
+/**
  *Type define of util.
  */
 typedef enum {
@@ -193,77 +220,39 @@ typedef struct {
  * Structure of message item
  */
 typedef struct {
-       MMHandleType handle;            /**< handle */
-       int id;                         /**< message id */
-       MMMessageParamType param;       /**< message parameter */
+       MMHandleType handle;        /**< handle */
+       int id;                     /**< message id */
+       MMMessageParamType param;   /**< message parameter */
+       GMutex lock;                /**< mutex for item */
 } _MMCamcorderMsgItem;
 
 /**
- * Structure of zero copy image buffer
+ * Structure of storage information
  */
-#define SCMN_IMGB_MAX_PLANE         (4)
-
-/* image buffer definition ***************************************************
-
-    +------------------------------------------+ ---
-    |                                          |  ^
-    |     a[], p[]                             |  |
-    |     +---------------------------+ ---    |  |
-    |     |                           |  ^     |  |
-    |     |<---------- w[] ---------->|  |     |  |
-    |     |                           |  |     |  |
-    |     |                           |        |
-    |     |                           |  h[]   |  e[]
-    |     |                           |        |
-    |     |                           |  |     |  |
-    |     |                           |  |     |  |
-    |     |                           |  v     |  |
-    |     +---------------------------+ ---    |  |
-    |                                          |  v
-    +------------------------------------------+ ---
-
-    |<----------------- s[] ------------------>|
-*/
-
-typedef struct
-{
-       /* width of each image plane */
-       int w[SCMN_IMGB_MAX_PLANE];
-       /* height of each image plane */
-       int h[SCMN_IMGB_MAX_PLANE];
-       /* stride of each image plane */
-       int s[SCMN_IMGB_MAX_PLANE];
-       /* elevation of each image plane */
-       int e[SCMN_IMGB_MAX_PLANE];
-       /* user space address of each image plane */
-       void *a[SCMN_IMGB_MAX_PLANE];
-       /* physical address of each image plane, if needs */
-       void *p[SCMN_IMGB_MAX_PLANE];
-       /* color space type of image */
-       int cs;
-       /* left postion, if needs */
-       int x;
-       /* top position, if needs */
-       int y;
-       /* to align memory */
-       int __dummy2;
-       /* arbitrary data */
-       int data[16];
-} SCMN_IMGB;
+typedef struct {
+       storage_type_e type;
+       int id;
+} _MMCamcorderStorageInfo;
+
 
 /*=======================================================================================
 | CONSTANT DEFINITIONS                                                                 |
 ========================================================================================*/
+#define G_DBUS_CB_TIMEOUT_MSEC                  3000
+#define G_DBUS_REPLY_TIMEOUT                    (120 * 1000)
+#define FAT32_FILE_SYSTEM_MAX_SIZE              (4294967295UL)     /* 4 GigaByte - 1 byte */
+#define NANO_SEC_PER_MILI_SEC                   1000000
 #define _MMCAMCORDER_HANDLER_CATEGORY_ALL \
        (_MMCAMCORDER_HANDLER_PREVIEW | _MMCAMCORDER_HANDLER_VIDEOREC |_MMCAMCORDER_HANDLER_STILLSHOT | _MMCAMCORDER_HANDLER_AUDIOREC)
 
+
 /*=======================================================================================
 | GLOBAL FUNCTION PROTOTYPES                                                           |
 ========================================================================================*/
 /* GStreamer */
 void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
+void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object);
 void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
-void _mmcamcorder_remove_data_probe(MMHandleType handle, _MMCamcorderHandlerCategory category);
 void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCategory category);
 void _mmcamcorder_remove_all_handlers(MMHandleType handle, _MMCamcorderHandlerCategory category);
 void _mmcamcorder_element_release_noti(gpointer data, GObject *where_the_object_was);
@@ -271,9 +260,11 @@ gboolean _mmcamcorder_add_elements_to_bin(GstBin *bin, GList *element_list);
 gboolean _mmcamcorder_link_elements(GList *element_list);
 
 /* Message */
-gboolean _mmcamcroder_msg_callback(void *data);
-gboolean _mmcamcroder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data);
-void _mmcamcroder_remove_message_all(MMHandleType handle);
+#ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
+gboolean _mmcamcorder_msg_callback(void *data);
+#endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
+gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *data);
+void _mmcamcorder_remove_message_all(MMHandleType handle);
 
 /* Pixel format */
 int _mmcamcorder_get_pixel_format(GstCaps *pad);
@@ -282,29 +273,50 @@ unsigned int _mmcamcorder_get_fourcc(int pixtype, int codectype, int use_zero_co
 
 /* JPEG encode */
 gboolean _mmcamcorder_encode_jpeg(void *src_data, unsigned int src_width, unsigned int src_height,
-                                  int src_format, unsigned int src_length, unsigned int jpeg_quality,
-                                  void **result_data, unsigned int *result_length);
+       int src_format, unsigned int src_length, unsigned int jpeg_quality,
+       void **result_data, unsigned int *result_length);
 /* resize */
-gboolean _mmcamcorder_resize_frame(unsigned char *src_data, int src_width, int src_height, int src_length, int src_format,
-                                   unsigned char **dst_data, int *dst_width, int *dst_height, int *dst_length);
+gboolean _mmcamcorder_resize_frame(unsigned char *src_data, unsigned int src_width, unsigned int src_height, unsigned int src_length, int src_format,
+       unsigned char **dst_data, unsigned int *dst_width, unsigned int *dst_height, unsigned int *dst_length);
+gboolean _mmcamcorder_downscale_UYVYorYUYV(unsigned char *src, unsigned int src_width, unsigned int src_height,
+       unsigned char **dst, unsigned int dst_width, unsigned int dst_height);
 
 /* Recording */
 /* find top level tag only, do not use this function for finding sub level tags.
    tag_fourcc is Four-character-code (FOURCC) */
 gint _mmcamcorder_find_tag(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
+gboolean _mmcamcorder_find_fourcc(FILE *f, guint32 tag_fourcc, gboolean do_rewind);
 gint32 _mmcamcorder_double_to_fix(gdouble d_number);
 gboolean _mmcamcorder_update_size(FILE *f, gint64 prev_pos, gint64 curr_pos);
 gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info);
-gboolean _mmcamcorder_write_udta(FILE *f, _MMCamcorderLocationInfo info);
+gboolean _mmcamcorder_write_geodata(FILE *f, _MMCamcorderLocationInfo info);
+gboolean _mmcamcorder_write_udta(FILE *f, int gps_enable, _MMCamcorderLocationInfo info, _MMCamcorderLocationInfo geotag);
 guint64 _mmcamcorder_get_container_size(const guchar *size);
+guint64 _mmcamcorder_get_container_size64(const guchar *size);
 gboolean _mmcamcorder_update_composition_matrix(FILE *f, int orientation);
 
 /* File system */
-int _mmcamcorder_get_freespace(const gchar *path, guint64 *free_space);
+int _mmcamcorder_get_storage_info(const gchar *path, const gchar *root_directory, _MMCamcorderStorageInfo *storage_info);
+int _mmcamcorder_get_freespace(storage_type_e type, guint64 *free_space);
 int _mmcamcorder_get_file_size(const char *filename, guint64 *size);
+int _mmcamcorder_get_file_system_type(const gchar *path, int *file_system_type);
+
+/* Task */
+void *_mmcamcorder_util_task_thread_func(void *data);
+
+/* device */
+int _mmcamcorder_get_device_flash_brightness(GDBusConnection *conn, int *brightness);
+
+/* sound play via dbus*/
+int _mmcamcorder_send_sound_play_message(GDBusConnection *conn, _MMCamcorderGDbusCbInfo *gdbus_info,
+       const char *sample_name, const char *stream_role, const char *volume_gain, int sync_play);
+
+/* dbus signal emit */
+void _mmcamcorder_emit_dbus_signal(GDBusConnection *conn, const char *object_name,
+       const char *interface_name, const char *signal_name, int value);
 
-/* Debug */
-void _mmcamcorder_err_trace_write(char *str_filename, char *func_name, int line_num, char *fmt, ...);
+/* audio buffer */
+int _mmcamcorder_get_audiosrc_blocksize(int samplerate, int format, int channel, int interval, int *blocksize);
 
 #ifdef __cplusplus
 }