[0.6.66] remove deadcode
[platform/core/multimedia/libmm-player.git] / src / include / mm_player_utils.h
1 /*
2  * libmm-player
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
7  * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #ifndef __MM_PLAYER_UTILS_H__
24 #define __MM_PLAYER_UTILS_H__
25
26 #include <glib.h>
27 #include <gst/gst.h>
28 #include <dlog.h>
29 #include <mm_player_ini.h>
30 #include <mm_types.h>
31 #include <mm_error.h>
32 #include <mm_message.h>
33 #include "mm_player_priv.h"
34
35 #ifdef __cplusplus
36         extern "C" {
37 #endif
38
39 #ifdef LOG_TAG
40 #undef LOG_TAG
41 #endif
42 #define LOG_TAG "MM_PLAYER"
43
44 /* general */
45 #ifndef ARRAY_SIZE
46 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
47 #endif
48
49 #define MMPLAYER_MAX_INT (2147483647)
50
51 #define MMPLAYER_FREEIF(x) \
52 do {    \
53         if (x) \
54                 g_free(x); \
55         x = NULL;       \
56 } while (0)
57
58 #define MMPLAYER_GET_ATTRS(x_player) ((mm_player_t*)x_player)->attrs
59
60 /* command */
61 #define MMPLAYER_CMD_LOCK(x_player)                          g_mutex_lock(&((mm_player_t *)x_player)->cmd_lock)
62 #define MMPLAYER_CMD_TRYLOCK(x_player)                       g_mutex_trylock(&((mm_player_t *)x_player)->cmd_lock)
63 #define MMPLAYER_CMD_UNLOCK(x_player)                        g_mutex_unlock(&((mm_player_t*)x_player)->cmd_lock)
64
65 /* playback */
66 #define MMPLAYER_PLAYBACK_LOCK(x_player)                     g_mutex_lock(&((mm_player_t *)x_player)->playback_lock)
67 #define MMPLAYER_PLAYBACK_UNLOCK(x_player)                   g_mutex_unlock(&((mm_player_t*)x_player)->playback_lock)
68
69 /* capture thread */
70 #define MMPLAYER_CAPTURE_THREAD_LOCK(x_player)               g_mutex_lock(&((mm_player_t *)x_player)->capture_thread_mutex)
71 #define MMPLAYER_CAPTURE_THREAD_UNLOCK(x_player)             g_mutex_unlock(&((mm_player_t *)x_player)->capture_thread_mutex)
72 #define MMPLAYER_CAPTURE_THREAD_WAIT(x_player)               g_cond_wait(&((mm_player_t *)x_player)->capture_thread_cond, &((mm_player_t *)x_player)->capture_thread_mutex)
73 #define MMPLAYER_CAPTURE_THREAD_SIGNAL(x_player)             g_cond_signal(&((mm_player_t *)x_player)->capture_thread_cond);
74
75 /* next play thread */
76 #define MMPLAYER_NEXT_PLAY_THREAD_LOCK(x_player)             g_mutex_lock(&((mm_player_t *)x_player)->next_play_thread_mutex)
77 #define MMPLAYER_NEXT_PLAY_THREAD_UNLOCK(x_player)           g_mutex_unlock(&((mm_player_t *)x_player)->next_play_thread_mutex)
78 #define MMPLAYER_NEXT_PLAY_THREAD_WAIT(x_player)             g_cond_wait(&((mm_player_t *)x_player)->next_play_thread_cond, &((mm_player_t *)x_player)->next_play_thread_mutex)
79 #define MMPLAYER_NEXT_PLAY_THREAD_SIGNAL(x_player)           g_cond_signal(&((mm_player_t *)x_player)->next_play_thread_cond);
80
81 /* repeat thread */
82 #define MMPLAYER_REPEAT_THREAD_LOCK(x_player)                g_mutex_lock(&((mm_player_t *)x_player)->repeat_thread_mutex)
83 #define MMPLAYER_REPEAT_THREAD_UNLOCK(x_player)              g_mutex_unlock(&((mm_player_t *)x_player)->repeat_thread_mutex)
84 #define MMPLAYER_REPEAT_THREAD_WAIT(x_player)                g_cond_wait(&((mm_player_t *)x_player)->repeat_thread_cond, &((mm_player_t *)x_player)->repeat_thread_mutex)
85 #define MMPLAYER_REPEAT_THREAD_SIGNAL(x_player)              g_cond_signal(&((mm_player_t *)x_player)->repeat_thread_cond);
86
87 /* handling fakesink */
88 #define MMPLAYER_FSINK_LOCK(x_player)                        g_mutex_lock(&((mm_player_t *)x_player)->fsink_lock)
89 #define MMPLAYER_FSINK_UNLOCK(x_player)                      g_mutex_unlock(&((mm_player_t *)x_player)->fsink_lock)
90
91
92 /* handling update tag */
93 #define MMPLAYER_UPDATE_TAG_LOCK(x_player)                   g_mutex_lock(&((mm_player_t *)x_player)->update_tag_lock)
94 #define MMPLAYER_UPDATE_TAG_UNLOCK(x_player)                 g_mutex_unlock(&((mm_player_t *)x_player)->update_tag_lock)
95
96 /* video stream bo */
97 #define MMPLAYER_VIDEO_BO_LOCK(x_player)                     g_mutex_lock(&((mm_player_t *)x_player)->video_bo_mutex)
98 #define MMPLAYER_VIDEO_BO_UNLOCK(x_player)                   g_mutex_unlock(&((mm_player_t *)x_player)->video_bo_mutex)
99 #define MMPLAYER_VIDEO_BO_WAIT(x_player)                     g_cond_wait(&((mm_player_t *)x_player)->video_bo_cond, &((mm_player_t *)x_player)->video_bo_mutex)
100 #define MMPLAYER_VIDEO_BO_WAIT_UNTIL(x_player, end_time)     g_cond_wait_until(&((mm_player_t *)x_player)->video_bo_cond, &((mm_player_t *)x_player)->video_bo_mutex, end_time);
101 #define MMPLAYER_VIDEO_BO_SIGNAL(x_player)                   g_cond_signal(&((mm_player_t *)x_player)->video_bo_cond);
102
103 /* media stream lock */
104 #define MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(x_player)        g_mutex_lock(&((mm_player_t *)x_player)->media_stream_cb_lock)
105 #define MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(x_player)      g_mutex_unlock(&((mm_player_t *)x_player)->media_stream_cb_lock)
106
107 #if 0
108 #define MMPLAYER_FENTER();                                      LOGD("<ENTER>");
109 #define MMPLAYER_FLEAVE();                                      LOGD("<LEAVE>");
110 #else
111 #define MMPLAYER_FENTER();
112 #define MMPLAYER_FLEAVE();
113 #endif
114
115 #define MMPLAYER_RETURN_IF_FAIL(expr) \
116 if (!(expr)) { \
117         LOGW("faild [%s]", #expr); \
118         return; \
119 }
120
121 #define MMPLAYER_RETURN_VAL_IF_FAIL(expr, var) \
122 if (!(expr)) { \
123         LOGW("faild [%s]", #expr); \
124         return (var); \
125 }
126
127 /* debug caps string */
128 #define MMPLAYER_LOG_GST_CAPS_TYPE(x_caps) \
129 do { \
130         gchar* caps_type = NULL; \
131         caps_type = gst_caps_to_string(x_caps); \
132         LOGD("caps: %s\n", caps_type); \
133         MMPLAYER_FREEIF(caps_type); \
134 } while (0)
135
136 /* message posting */
137 #define MMPLAYER_POST_MSG(x_player, x_msgtype, x_msg_param) \
138 do { \
139         LOGD("posting %s to application\n", #x_msgtype); \
140         __mmplayer_post_message(x_player, x_msgtype, x_msg_param); \
141 } while (0)
142
143 /* setting player state */
144 #define MMPLAYER_SET_STATE(x_player, x_state) \
145 do { \
146         LOGD("update state machine to %d\n", x_state); \
147         __mmplayer_set_state(x_player, x_state); \
148 } while (0)
149
150 #define MMPLAYER_CHECK_STATE(x_player, x_command) \
151 do {    \
152         LOGD("checking player state before doing %s\n", #x_command); \
153         switch (__mmplayer_check_state(x_player, x_command)) { \
154         case MM_ERROR_PLAYER_INVALID_STATE: \
155                 return MM_ERROR_PLAYER_INVALID_STATE; \
156                 break; \
157                 /* NOTE : for robustness of player. we won't treat it as an error */ \
158         case MM_ERROR_PLAYER_NO_OP: \
159                 return MM_ERROR_NONE; \
160                 break; \
161         case MM_ERROR_PLAYER_DOING_SEEK: \
162                 return MM_ERROR_PLAYER_DOING_SEEK; \
163         default: \
164                 break; \
165         }       \
166 } while (0)
167
168 /* setting element state */
169 #define MMPLAYER_ELEMENT_SET_STATE(x_element, x_state) \
170 do {    \
171         LOGD("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \
172         if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(x_element, x_state)) { \
173                 LOGE("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element)); \
174                 goto STATE_CHANGE_FAILED; \
175         }       \
176 } while (0)
177
178 #define MMPLAYER_CHECK_NULL(x_var) \
179 if (!x_var) { \
180         LOGE("[%s] is NULL\n", #x_var); \
181         goto ERROR; \
182 }
183
184 /* generating dot */
185 #define MMPLAYER_GENERATE_DOT_IF_ENABLED(x_player, x_name) \
186 if (x_player->ini.generate_dot) { \
187         GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), \
188         GST_DEBUG_GRAPH_SHOW_ALL, x_name); \
189 }
190
191 /* signal manipulation */
192 #define MMPLAYER_SIGNAL_CONNECT(x_player, x_object, x_type, x_signal, x_callback, x_arg) \
193 do { \
194         MMPlayerSignalItem* item = NULL; \
195         item = (MMPlayerSignalItem*) g_malloc(sizeof(MMPlayerSignalItem)); \
196         if (!item) { \
197                 LOGE("cannot connect signal [%s]\n", x_signal); \
198         } else { \
199                 item->obj = G_OBJECT(x_object); \
200                 item->sig = g_signal_connect(G_OBJECT(x_object), x_signal, \
201                                         x_callback, x_arg); \
202                 if ((x_type >= MM_PLAYER_SIGNAL_TYPE_AUTOPLUG) && (x_type < MM_PLAYER_SIGNAL_TYPE_MAX)) \
203                         x_player->signals[x_type] = g_list_append(x_player->signals[x_type], item); \
204                 else \
205                         LOGE("wrong signal type [%d]\n", x_type); \
206         } \
207 } while (0)
208
209 /* release element resource */
210 #define MMPLAYER_RELEASE_ELEMENT(x_player, x_bin, x_id) \
211 do { \
212         if (x_bin[x_id].gst) { \
213                 gst_element_set_state(x_bin[x_id].gst, GST_STATE_NULL); \
214                 gst_bin_remove(GST_BIN(x_player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), x_bin[x_id].gst); \
215                 x_bin[x_id].gst = NULL; \
216                 LOGD("release done [element %d]", x_id); \
217         } \
218 } while (0)
219
220 /* state */
221 #define MMPLAYER_PREV_STATE(x_player) ((mm_player_t*)x_player)->prev_state
222 #define MMPLAYER_CURRENT_STATE(x_player) ((mm_player_t*)x_player)->state
223 #define MMPLAYER_PENDING_STATE(x_player) ((mm_player_t*)x_player)->pending_state
224 #define MMPLAYER_TARGET_STATE(x_player) ((mm_player_t*)x_player)->target_state
225 #define MMPLAYER_STATE_GET_NAME(state) __get_state_name(state)
226
227 #define MMPLAYER_PRINT_STATE(x_player) \
228 LOGD("-- prev %s, current %s, pending %s, target %s --\n", \
229         MMPLAYER_STATE_GET_NAME(MMPLAYER_PREV_STATE(x_player)), \
230         MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(x_player)), \
231         MMPLAYER_STATE_GET_NAME(MMPLAYER_PENDING_STATE(x_player)), \
232         MMPLAYER_STATE_GET_NAME(MMPLAYER_TARGET_STATE(x_player)));
233
234 #define MMPLAYER_STATE_CHANGE_TIMEOUT(x_player)  ((mm_player_t*)x_player)->state_change_timeout
235
236 /* streaming */
237 #define MMPLAYER_IS_STREAMING(x_player) __is_streaming(x_player)
238 #define MMPLAYER_IS_RTSP_STREAMING(x_player) __is_rtsp_streaming(x_player)
239 #define MMPLAYER_IS_HTTP_STREAMING(x_player) __is_http_streaming(x_player)
240 #define MMPLAYER_IS_HTTP_PD(x_player) __is_http_progressive_down(x_player)
241 #define MMPLAYER_IS_HTTP_LIVE_STREAMING(x_player) __is_http_live_streaming(x_player)
242 #define MMPLAYER_IS_LIVE_STREAMING(x_player) __is_live_streaming(x_player)
243 #define MMPLAYER_IS_DASH_STREAMING(x_player) __is_dash_streaming(x_player)
244 #define MMPLAYER_IS_SMOOTH_STREAMING(x_player) __is_smooth_streaming(x_player)
245 #define MMPLAYER_IS_MS_BUFF_SRC(x_player) __is_ms_buff_src(x_player)
246
247 #define MMPLAYER_URL_HAS_DASH_SUFFIX(x_player) __has_suffix(x_player, "mpd")
248 #define MMPLAYER_URL_HAS_HLS_SUFFIX(x_player) __has_suffix(x_player, "m3u8")
249
250 bool util_is_sdp_file(const char *path);
251 int util_exist_file_path(const char *file_path);
252 char** util_get_cookie_list(const char *cookies);
253 bool util_check_valid_url(const char *proxy);
254 const char* util_get_charset(const char *file_path);
255 int util_get_pixtype(unsigned int fourcc);
256 bool util_get_storage_info(const char *path, MMPlayerStorageInfo *storage_info);
257
258 #ifdef __cplusplus
259         }
260 #endif
261
262 #endif /* __MM_PLAYER_UTILS_H__ */
263