4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #ifndef __MM_PLAYER_UTILS_H__
24 #define __MM_PLAYER_UTILS_H__
29 #include <mm_player_ini.h>
32 #include <mm_message.h>
33 #include "mm_player_priv.h"
42 #define LOG_TAG "MM_PLAYER"
46 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
49 #define MMPLAYER_MAX_INT (2147483647)
51 #define MMPLAYER_FREEIF(x) \
58 #define MMPLAYER_GET_ATTRS(x_player) ((mm_player_t*)x_player)->attrs
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)
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)
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);
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);
81 /* gst bus msg thread */
82 #define MMPLAYER_BUS_MSG_THREAD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->bus_msg_thread_mutex)
83 #define MMPLAYER_BUS_MSG_THREAD_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->bus_msg_thread_mutex)
84 #define MMPLAYER_BUS_MSG_THREAD_WAIT(x_player) g_cond_wait(&((mm_player_t *)x_player)->bus_msg_thread_cond, &((mm_player_t *)x_player)->bus_msg_thread_mutex)
85 #define MMPLAYER_BUS_MSG_THREAD_WAIT_UNTIL(x_player, end_time) g_cond_wait_until(&((mm_player_t *)x_player)->bus_msg_thread_cond, &((mm_player_t *)x_player)->bus_msg_thread_mutex, end_time)
86 #define MMPLAYER_BUS_MSG_THREAD_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->bus_msg_thread_cond);
88 /* handling fakesink */
89 #define MMPLAYER_FSINK_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->fsink_lock)
90 #define MMPLAYER_FSINK_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->fsink_lock)
93 /* handling update tag */
94 #define MMPLAYER_UPDATE_TAG_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->update_tag_lock)
95 #define MMPLAYER_UPDATE_TAG_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->update_tag_lock)
98 #define MMPLAYER_VIDEO_BO_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->video_bo_mutex)
99 #define MMPLAYER_VIDEO_BO_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->video_bo_mutex)
100 #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)
101 #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)
102 #define MMPLAYER_VIDEO_BO_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->video_bo_cond);
104 /* media stream lock */
105 #define MMPLAYER_MEDIA_STREAM_CALLBACK_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->media_stream_cb_lock)
106 #define MMPLAYER_MEDIA_STREAM_CALLBACK_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->media_stream_cb_lock)
109 #define MMPLAYER_SUBTITLE_INFO_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->subtitle_info_mutex)
110 #define MMPLAYER_SUBTITLE_INFO_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->subtitle_info_mutex)
111 #define MMPLAYER_SUBTITLE_INFO_WAIT(x_player) g_cond_wait(&((mm_player_t *)x_player)->subtitle_info_cond, &((mm_player_t *)x_player)->subtitle_info_mutex)
112 #define MMPLAYER_SUBTITLE_INFO_WAIT_UNTIL(x_player, end_time) g_cond_wait_until(&((mm_player_t *)x_player)->subtitle_info_cond, &((mm_player_t *)x_player)->subtitle_info_mutex, end_time)
113 #define MMPLAYER_SUBTITLE_INFO_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->subtitle_info_cond);
116 #define MMPLAYER_FENTER(); LOGD("<ENTER>");
117 #define MMPLAYER_FLEAVE(); LOGD("<LEAVE>");
119 #define MMPLAYER_FENTER();
120 #define MMPLAYER_FLEAVE();
123 #define MMPLAYER_RETURN_IF_FAIL(expr) \
125 LOGW("faild [%s]", #expr); \
129 #define MMPLAYER_RETURN_VAL_IF_FAIL(expr, var) \
131 LOGW("faild [%s]", #expr); \
135 /* debug caps string */
136 #define MMPLAYER_LOG_GST_CAPS_TYPE(x_caps) \
138 gchar* caps_type = NULL; \
139 caps_type = gst_caps_to_string(x_caps); \
140 LOGD("caps: %s\n", caps_type); \
141 MMPLAYER_FREEIF(caps_type); \
144 /* message posting */
145 #define MMPLAYER_POST_MSG(x_player, x_msgtype, x_msg_param) \
147 LOGD("[handle: %p] posting %s to application\n", x_player, #x_msgtype); \
148 __mmplayer_post_message(x_player, x_msgtype, x_msg_param); \
151 /* setting player state */
152 #define MMPLAYER_SET_STATE(x_player, x_state) \
154 LOGD("[handle: %p] update state machine to %d\n", x_player, x_state); \
155 __mmplayer_set_state(x_player, x_state); \
158 #define MMPLAYER_CHECK_STATE(x_player, x_command) \
160 LOGD("[handle: %p] checking player state before doing %s\n", x_player, #x_command); \
161 switch (__mmplayer_check_state(x_player, x_command)) { \
162 case MM_ERROR_PLAYER_INVALID_STATE: \
163 return MM_ERROR_PLAYER_INVALID_STATE; \
165 /* NOTE : for robustness of player. we won't treat it as an error */ \
166 case MM_ERROR_PLAYER_NO_OP: \
167 return MM_ERROR_NONE; \
169 case MM_ERROR_PLAYER_DOING_SEEK: \
170 return MM_ERROR_PLAYER_DOING_SEEK; \
176 /* setting element state */
177 #define MMPLAYER_ELEMENT_SET_STATE(x_element, x_state) \
179 LOGD("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \
180 if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(x_element, x_state)) { \
181 LOGE("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element)); \
182 goto STATE_CHANGE_FAILED; \
186 #define MMPLAYER_CHECK_NULL(x_var) \
188 LOGE("[%s] is NULL\n", #x_var); \
193 #define MMPLAYER_GENERATE_DOT_IF_ENABLED(x_player, x_name) \
194 if (x_player->ini.generate_dot) { \
195 GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), \
196 GST_DEBUG_GRAPH_SHOW_ALL, x_name); \
199 /* signal manipulation */
200 #define MMPLAYER_SIGNAL_CONNECT(x_player, x_object, x_type, x_signal, x_callback, x_arg) \
202 MMPlayerSignalItem* item = NULL; \
203 item = (MMPlayerSignalItem*) g_malloc(sizeof(MMPlayerSignalItem)); \
205 LOGE("cannot connect signal [%s]\n", x_signal); \
207 item->obj = G_OBJECT(x_object); \
208 item->sig = g_signal_connect(G_OBJECT(x_object), x_signal, \
209 x_callback, x_arg); \
210 if ((x_type >= MM_PLAYER_SIGNAL_TYPE_AUTOPLUG) && (x_type < MM_PLAYER_SIGNAL_TYPE_MAX)) \
211 x_player->signals[x_type] = g_list_append(x_player->signals[x_type], item); \
213 LOGE("wrong signal type [%d]\n", x_type); \
217 /* release element resource */
218 #define MMPLAYER_RELEASE_ELEMENT(x_player, x_bin, x_id) \
220 if (x_bin[x_id].gst) { \
221 gst_element_set_state(x_bin[x_id].gst, GST_STATE_NULL); \
222 gst_bin_remove(GST_BIN(x_player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), x_bin[x_id].gst); \
223 x_bin[x_id].gst = NULL; \
224 LOGD("release done [element %d]", x_id); \
229 #define MMPLAYER_PREV_STATE(x_player) ((mm_player_t*)x_player)->prev_state
230 #define MMPLAYER_CURRENT_STATE(x_player) ((mm_player_t*)x_player)->state
231 #define MMPLAYER_PENDING_STATE(x_player) ((mm_player_t*)x_player)->pending_state
232 #define MMPLAYER_TARGET_STATE(x_player) ((mm_player_t*)x_player)->target_state
233 #define MMPLAYER_STATE_GET_NAME(state) __get_state_name(state)
235 #define MMPLAYER_PRINT_STATE(x_player) \
236 LOGD("-- prev %s, current %s, pending %s, target %s --\n", \
237 MMPLAYER_STATE_GET_NAME(MMPLAYER_PREV_STATE(x_player)), \
238 MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(x_player)), \
239 MMPLAYER_STATE_GET_NAME(MMPLAYER_PENDING_STATE(x_player)), \
240 MMPLAYER_STATE_GET_NAME(MMPLAYER_TARGET_STATE(x_player)));
242 #define MMPLAYER_STATE_CHANGE_TIMEOUT(x_player) ((mm_player_t*)x_player)->state_change_timeout
245 #define MMPLAYER_IS_STREAMING(x_player) __is_streaming(x_player)
246 #define MMPLAYER_IS_RTSP_STREAMING(x_player) __is_rtsp_streaming(x_player)
247 #define MMPLAYER_IS_HTTP_STREAMING(x_player) __is_http_streaming(x_player)
248 #define MMPLAYER_IS_HTTP_PD(x_player) __is_http_progressive_down(x_player)
249 #define MMPLAYER_IS_HTTP_LIVE_STREAMING(x_player) __is_http_live_streaming(x_player)
250 #define MMPLAYER_IS_LIVE_STREAMING(x_player) __is_live_streaming(x_player)
251 #define MMPLAYER_IS_DASH_STREAMING(x_player) __is_dash_streaming(x_player)
252 #define MMPLAYER_IS_SMOOTH_STREAMING(x_player) __is_smooth_streaming(x_player)
253 #define MMPLAYER_IS_MS_BUFF_SRC(x_player) __is_ms_buff_src(x_player)
255 #define MMPLAYER_URL_HAS_DASH_SUFFIX(x_player) __has_suffix(x_player, "mpd")
256 #define MMPLAYER_URL_HAS_HLS_SUFFIX(x_player) __has_suffix(x_player, "m3u8")
258 #define MMPLAYER_STREAM_TYPE_GET_NAME(type) __get_stream_type_name(type)
260 /*===========================================================================================
262 | GLOBAL FUNCTION PROTOTYPES |
264 ========================================================================================== */
266 const gchar* __get_state_name(int state);
267 const gchar* __get_stream_type_name(int type);
269 gboolean __is_streaming(mm_player_t* player);
270 gboolean __is_rtsp_streaming(mm_player_t* player);
271 gboolean __is_live_streaming(mm_player_t* player);
272 gboolean __is_http_streaming(mm_player_t* player);
273 gboolean __is_http_live_streaming(mm_player_t* player);
274 gboolean __is_dash_streaming(mm_player_t* player);
275 gboolean __is_smooth_streaming(mm_player_t* player);
276 gboolean __is_http_progressive_down(mm_player_t* player);
277 gboolean __is_ms_buff_src(mm_player_t* player);
278 gboolean __has_suffix(mm_player_t* player, const gchar* suffix);
280 gboolean __mmplayer_post_message(mm_player_t* player, enum MMMessageType msgtype, MMMessageParamType* param);
281 gboolean __mmplayer_dump_pipeline_state(mm_player_t* player);
283 bool util_is_sdp_file(const char *path);
284 int util_exist_file_path(const char *file_path);
285 char** util_get_cookie_list(const char *cookies);
286 const char* util_get_charset(const char *file_path);
287 int util_get_pixtype(unsigned int fourcc);
288 bool util_get_storage_info(const char *path, MMPlayerStorageInfo *storage_info);
294 #endif /* __MM_PLAYER_UTILS_H__ */