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__
28 #include <mm_player_ini.h>
31 #include <mm_message.h>
39 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
42 #define MMPLAYER_MAX_INT (2147483647)
44 #define MMPLAYER_FREEIF(x) \
49 #define MMPLAYER_CMD_LOCK(x_player) \
52 GMutex* cmd_lock = ((mm_player_t *)x_player)->cmd_lock; \
54 g_mutex_lock(cmd_lock); \
57 debug_log("no command lock"); \
58 return MM_ERROR_PLAYER_NOT_INITIALIZED; \
62 #define MMPLAYER_CMD_UNLOCK(x_player) g_mutex_unlock( ((mm_player_t*)x_player)->cmd_lock )
63 #define MMPLAYER_MSG_POST_LOCK(x_player) g_mutex_lock( ((mm_player_t*)x_player)->msg_cb_lock )
64 #define MMPLAYER_MSG_POST_UNLOCK(x_player) g_mutex_unlock( ((mm_player_t*)x_player)->msg_cb_lock )
65 #define MMPLAYER_GET_ATTRS(x_player) ((mm_player_t*)x_player)->attrs
67 #define MMPLAYER_PLAYBACK_LOCK(x_player) \
70 GMutex* playback_lock = ((mm_player_t *)x_player)->playback_lock; \
73 debug_log("lock playback_lock"); \
74 g_mutex_lock(playback_lock); \
78 debug_log("no playback lock"); \
82 #define MMPLAYER_PLAYBACK_UNLOCK(x_player) \
85 GMutex* playback_lock = ((mm_player_t *)x_player)->playback_lock; \
88 g_mutex_unlock( ((mm_player_t*)x_player)->playback_lock ); \
89 debug_log("unlock playback_lock"); \
93 debug_warning("can't unlock> no playback lock"); \
98 #define MMPLAYER_FENTER(); debug_fenter();
99 #define MMPLAYER_FLEAVE(); debug_fleave();
101 #define MMPLAYER_FENTER();
102 #define MMPLAYER_FLEAVE();
105 #define MAX_SOUND_DEVICE_LEN 18
107 /* element linking */
108 #ifdef GST_EXT_PAD_LINK_UNCHECKED
109 #define GST_ELEMENT_LINK_FILTERED gst_element_link_filtered_unchecked
110 #define GST_ELEMENT_LINK_MANY gst_element_link_many_unchecked
111 #define GST_ELEMENT_LINK gst_element_link_unchecked
112 #define GST_ELEMENT_LINK_PADS gst_element_link_pads_unchecked
113 #define GST_PAD_LINK gst_pad_link_unchecked
115 #define GST_ELEMENT_LINK_FILTERED gst_element_link_filtered
116 #define GST_ELEMENT_LINK_MANY gst_element_link_many
117 #define GST_ELEMENT_LINK gst_element_link
118 #define GST_ELEMENT_UNLINK gst_element_unlink
119 #define GST_ELEMENT_LINK_PADS gst_element_link_pads
120 #define GST_PAD_LINK gst_pad_link
123 /* debug caps string */
124 #define MMPLAYER_LOG_GST_CAPS_TYPE(x_caps) \
127 gchar* caps_type = NULL; \
128 caps_type = gst_caps_to_string(x_caps); \
129 debug_log ("caps: %s\n", caps_type ); \
130 MMPLAYER_FREEIF (caps_type) \
133 /* message posting */
134 #define MMPLAYER_POST_MSG( x_player, x_msgtype, x_msg_param ) \
135 debug_log("posting %s to application\n", #x_msgtype); \
136 __mmplayer_post_message(x_player, x_msgtype, x_msg_param);
138 /* setting player state */
139 #define MMPLAYER_SET_STATE( x_player, x_state ) \
140 debug_log("update state machine to %d\n", x_state); \
141 __mmplayer_set_state(x_player, x_state);
143 #define MMPLAYER_CHECK_STATE_RETURN_IF_FAIL( x_player, x_command ) \
144 debug_log("checking player state before doing %s\n", #x_command); \
145 switch ( __mmplayer_check_state(x_player, x_command) ) \
147 case MM_ERROR_PLAYER_INVALID_STATE: \
148 return MM_ERROR_PLAYER_INVALID_STATE; \
150 /* NOTE : for robustness of player. we won't treat it as an error */ \
151 case MM_ERROR_PLAYER_NO_OP: \
152 return MM_ERROR_NONE; \
154 case MM_ERROR_PLAYER_DOING_SEEK: \
155 return MM_ERROR_PLAYER_DOING_SEEK; \
160 /* setting element state */
161 #define MMPLAYER_ELEMENT_SET_STATE( x_element, x_state ) \
162 debug_log("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME( x_element ) ); \
163 if ( GST_STATE_CHANGE_FAILURE == gst_element_set_state ( x_element, x_state) ) \
165 debug_error("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME( x_element )); \
166 goto STATE_CHANGE_FAILED; \
169 #define MMPLAYER_CHECK_NULL( x_var ) \
172 debug_error("[%s] is NULL\n", #x_var ); \
176 #define MMPLAYER_CHECK_CMD_IF_EXIT( x_player ) \
177 if ( x_player->cmd == MMPLAYER_COMMAND_UNREALIZE || x_player->cmd == MMPLAYER_COMMAND_DESTROY ) \
179 debug_log("it's exit state...\n");\
183 /* pad probe for pipeilne debugging */
184 gboolean __util_gst_pad_probe(GstPad *pad, GstBuffer *buffer, gpointer u_data);
186 #define MM_PROBE_DEFAULT (0)
187 #define MM_PROBE_TIMESTAMP (1)
188 #define MM_PROBE_BUFFERSIZE (1 << 1)
189 #define MM_PROBE_CAPS (1 << 2)
190 #define MM_PROBE_BUFFER_DURATION (1 << 3)
191 #define MM_PROBE_DROP_BUFFER (1 << 4)
192 #define MM_PROBE_CLOCK_TIME (1 << 5)
195 /* messages are treated as warnings bcz those code should not be checked in.
196 * and no error handling will supported for same manner.
198 #define MMPLAYER_ADD_PROBE(x_pad, x_flag) \
199 debug_warning("adding pad probe\n"); \
200 if ( ! gst_pad_add_buffer_probe(x_pad, \
201 G_CALLBACK(__util_gst_pad_probe), \
202 (gpointer)x_flag) ) \
204 debug_error("failed to add pad probe\n"); \
209 #define MMPLAYER_GENERATE_DOT_IF_ENABLED( x_player, x_name ) \
210 if ( x_player->ini.generate_dot ) \
212 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), \
213 GST_DEBUG_GRAPH_SHOW_ALL, x_name); \
216 /* signal manipulation */
217 #define MMPLAYER_SIGNAL_CONNECT( x_player, x_object, x_type, x_signal, x_callback, x_arg ) \
220 MMPlayerSignalItem* item = NULL; \
221 item = (MMPlayerSignalItem*) g_malloc( sizeof (MMPlayerSignalItem) ); \
224 debug_error("cannot connect signal [%s]\n", x_signal ); \
228 item->obj = G_OBJECT( x_object ); \
229 item->sig = g_signal_connect( G_OBJECT(x_object), x_signal, \
230 x_callback, x_arg ); \
231 if ((x_type >= MM_PLAYER_SIGNAL_TYPE_AUTOPLUG) && (x_type < MM_PLAYER_SIGNAL_TYPE_MAX)) \
232 x_player->signals[x_type] = g_list_append(x_player->signals[x_type], item); \
234 debug_error("wrong signal type [%d]\n", x_type ); \
238 /* release element resource */
239 #define MMPLAYER_RELEASE_ELEMENT( x_player, x_bin, x_id ) \
242 if (x_bin[x_id].gst) \
244 gst_element_set_state(x_bin[x_id].gst, GST_STATE_NULL); \
245 gst_bin_remove(GST_BIN(x_player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), x_bin[x_id].gst); \
246 x_bin[x_id].gst = NULL; \
247 debug_log("release done [element %d]", x_id); \
252 #define MMPLAYER_PREV_STATE(x_player) ((mm_player_t*)x_player)->prev_state
253 #define MMPLAYER_CURRENT_STATE(x_player) ((mm_player_t*)x_player)->state
254 #define MMPLAYER_PENDING_STATE(x_player) ((mm_player_t*)x_player)->pending_state
255 #define MMPLAYER_TARGET_STATE(x_player) ((mm_player_t*)x_player)->target_state
256 #define MMPLAYER_STATE_GET_NAME(state) __get_state_name(state)
258 #define MMPLAYER_PRINT_STATE(x_player) \
259 debug_log("-- prev %s, current %s, pending %s, target %s --\n", \
260 MMPLAYER_STATE_GET_NAME(MMPLAYER_PREV_STATE(x_player)), \
261 MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(x_player)), \
262 MMPLAYER_STATE_GET_NAME(MMPLAYER_PENDING_STATE(x_player)), \
263 MMPLAYER_STATE_GET_NAME(MMPLAYER_TARGET_STATE(x_player)));
265 #define MMPLAYER_STATE_CHANGE_TIMEOUT(x_player ) ((mm_player_t*)x_player)->state_change_timeout
268 #define MMPLAYER_IS_STREAMING(x_player) __is_streaming(x_player)
269 #define MMPLAYER_IS_RTSP_STREAMING(x_player) __is_rtsp_streaming(x_player)
270 #define MMPLAYER_IS_WFD_STREAMING(x_player) __is_wfd_streaming(x_player)
271 #define MMPLAYER_IS_HTTP_STREAMING(x_player) __is_http_streaming(x_player)
272 #define MMPLAYER_IS_HTTP_PD(x_player) __is_http_progressive_down(x_player)
273 #define MMPLAYER_IS_HTTP_LIVE_STREAMING(x_player) __is_http_live_streaming(x_player)
274 #define MMPLAYER_IS_LIVE_STREAMING(x_player) __is_live_streaming(x_player)
275 #define MMPLAYER_IS_DASH_STREAMING(x_player) __is_dash_streaming(x_player)
276 #define MMPLAYER_IS_SMOOTH_STREAMING(x_player) __is_smooth_streaming(x_player)
278 #define MMPLAYER_URL_HAS_DASH_SUFFIX(x_player) __has_suffix(x_player, "mpd")
279 #define MMPLAYER_URL_HAS_HLS_SUFFIX(x_player) __has_suffix(x_player, "m3u8")
282 #define MMF_PLAYER_FILE_BACKUP_PATH "/tmp/media_temp."
283 #define MMPLAYER_PT_IS_AUDIO( x_pt ) ( strstr(x_pt, "_97") || strstr(x_pt, "audio") )
284 #define MMPLAYER_PT_IS_VIDEO( x_pt ) ( strstr(x_pt, "_96") || strstr(x_pt, "video") )
286 #define MMPLAYER_VIDEO_SINK_CHECK(x_player) \
289 return_val_if_fail ( x_player && \
290 x_player->pipeline && \
291 x_player->pipeline->videobin && \
292 x_player->pipeline->videobin[MMPLAYER_V_SINK].gst, \
293 MM_ERROR_PLAYER_NOT_INITIALIZED ); \
298 MMPLAYER_DISPLAY_NULL = 0,
299 MMPLAYER_DISPLAY_HDMI_ACTIVE,
300 MMPLAYER_DISPLAY_MIRRORING_ACTIVE,
303 bool util_is_sdp_file ( const char *path );
304 int64_t uti_get_time ( void );
305 int util_get_rank_increase ( const char *factory_class );
306 int util_factory_rank_compare(GstPluginFeature *f1, GstPluginFeature *f2); // @
307 int util_exist_file_path(const char *file_path);
308 bool util_write_file_backup(const char *backup_path, char *data_ptr, int data_size);
309 bool util_remove_file_backup(const char *backup_path); /* For Midi Player */
310 int util_is_midi_type_by_mem(void *mem, int size);
311 int util_is_midi_type_by_file(const char *file_path);
312 char** util_get_cookie_list ( const char *cookies );
313 bool util_check_valid_url ( const char *proxy );
314 const char* util_get_charset(const char *file_path);
316 int util_get_is_connected_external_display(void);
317 gboolean util_is_miracast_connected(void);
318 int util_get_pixtype(unsigned int fourcc);
324 #endif /* __MM_PLAYER_UTILS_H__ */