Tizen coding convention
[platform/core/multimedia/libmm-streamrecorder.git] / src / include / mm_streamrecorder_util.h
1 /*
2  * libmm-streamrecorder
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyuntae Kim <ht1211.kim@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #ifndef __MM_STREAMRECORDER_UTIL_H__
23 #define __MM_STREAMRECORDER_UTIL_H__
24
25 /*=======================================================================================
26 | INCLUDE FILES                                                                         |
27 ========================================================================================*/
28 #include <gst/gst.h>
29 #include <gst/gstutils.h>
30 #include <gst/gstpad.h>
31 #include "mm_debug.h"
32 #include <glib.h>
33 #include<stdio.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /*=======================================================================================
40 | GLOBAL DEFINITIONS AND DECLARATIONS FOR STREAMRECORDER                                        |
41 ========================================================================================*/
42
43 /*=======================================================================================
44 | MACRO DEFINITIONS                                                                     |
45 ========================================================================================*/
46 #ifndef CLEAR
47 #define CLEAR(x)            memset(&(x), 0, sizeof(x))
48 #endif
49
50 #define SAFE_FREE(x) \
51         if (x) {\
52                 g_free(x); \
53                 x = NULL; \
54         }
55
56 #define _mmstreamrec_dbg_verb(fmt, args...)  debug_verbose(" "fmt"\n", ##args);
57 #define _mmstreamrec_dbg_log(fmt, args...)   debug_log(" "fmt"\n", ##args);
58 #define _mmstreamrec_dbg_warn(fmt, args...)  debug_warning(" "fmt"\n", ##args);
59 #define _mmstreamrec_dbg_err(fmt, args...)   debug_error(" "fmt"\n", ##args);
60 #define _mmstreamrec_dbg_crit(fmt, args...)  debug_critical(" "fmt"\n", ##args);
61
62 /**
63  *      Macro for checking validity and debugging
64  */
65 #define mmf_return_if_fail(expr)        \
66         if (!(expr)) { \
67                 _mmstreamrec_dbg_err("failed [%s]", #expr);     \
68                 return;                                         \
69         };
70
71 /**
72  *      Macro for checking validity and debugging
73  */
74 #define mmf_return_val_if_fail(expr, val)       \
75         do { \
76                 if (!(expr)) { \
77                         _mmstreamrec_dbg_err("failed [%s]", #expr);     \
78                         return (val); \
79                 } \
80         } while (0)
81
82 /**
83  *      Minimum integer value
84  */
85 #define _MMSTREAMRECORDER_MIN_INT       (INT_MIN)
86
87 /**
88  *      Maximum integer value
89  */
90 #define _MMSTREAMRECORDER_MAX_INT       (INT_MAX)
91
92 /**
93  *      Minimum double value
94  */
95 #define _MMSTREAMRECORDER_MIN_DOUBLE    (DBL_MIN)
96
97 /**
98  *      Maximum integer value
99  */
100 #define _MMSTREAMRECORDER_MAX_DOUBLE    (DBL_MAX)
101
102 // TODO : MOVE OTHERS
103 enum {
104         PUSH_ENCODING_BUFFER_INIT = 0,
105         PUSH_ENCODING_BUFFER_RUN,
106         PUSH_ENCODING_BUFFER_STOP,
107 };
108
109 #define FPUTC_CHECK(x_char, x_file)\
110 {\
111         if (fputc(x_char, x_file) == EOF) {\
112                 _mmstreamrec_dbg_err("[Critical] fputc() returns fail.\n");     \
113                 return FALSE;\
114         } \
115 }
116
117 #define FPUTS_CHECK(x_str, x_file)\
118 {\
119         if (fputs(x_str, x_file) == EOF) {\
120                 _mmstreamrec_dbg_err("[Critical] fputs() returns fail.\n");\
121                 SAFE_FREE(str); \
122                 return FALSE;\
123         } \
124 }
125
126 /*=======================================================================================
127 | ENUM DEFINITIONS                                                                      |
128 ========================================================================================*/
129 #define MAX_ERROR_MESSAGE_LEN         128
130 #define MM_STREAMRECORDER_MIN_LOG_COUNT 10
131
132 /*=======================================================================================
133 | STRUCTURE DEFINITIONS                                                                 |
134 ========================================================================================*/
135 #if 0
136         typedef struct __mm_streamrecorder_ini {
137                 /* video converter element */
138                 gchar video_converter_element[STREAMRECORDER_INI_MAX_STRLEN];
139         } mm_streamrecorder_ini_t;
140 #endif
141
142 /*=======================================================================================
143 | CONSTANT DEFINITIONS                                                                  |
144 ========================================================================================*/
145
146 /*=======================================================================================
147 | GLOBAL FUNCTION PROTOTYPES                                                            |
148 ========================================================================================*/
149
150 /* Pixel format */
151
152 int _mmstreamrecorder_get_pixel_format(GstCaps *caps);
153 int _mmstreamrecorder_get_pixtype(unsigned int fourcc);
154 unsigned int _mmstreamrecorder_get_fourcc(int pixtype, int codectype, int use_zero_copy_format);
155
156 /* Recording */
157 /* find top level tag only, do not use this function for finding sub level tags. tag_fourcc is Four-character-code (FOURCC) */
158 gint32 _mmstreamrecorder_double_to_fix(gdouble d_number);
159
160 /* File system */
161 int _mmstreamrecorder_get_freespace(const gchar *path, guint64 *free_space);
162 int _mmstreamrecorder_get_file_size(const char *filename, guint64 *size);
163
164 /* Debug */
165 void _mmstreamrecorder_err_trace_write(char *str_filename, char *func_name, int line_num, char *fmt, ...);
166
167 guint16 get_language_code(const char *str);
168 gchar *str_to_utf8(const gchar *str);
169 __attribute__ ((gnu_inline)) inline gboolean write_tag(FILE *f, const gchar *tag);
170 __attribute__ ((gnu_inline)) inline gboolean write_to_32(FILE *f, guint val);
171 #ifdef __cplusplus
172 }
173 #endif
174 #endif                                                  /* __MM_STREAMRECORDER_UTIL_H__ */