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 __MMF_PLAYER_UTILS_H__
24 #define __MMF_PLAYER_UTILS_H__
28 #include <mm_player_ini.h>
31 #include <mm_message.h>
40 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
43 #define MMPLAYER_MAX_INT (2147483647)
45 #define MMPLAYER_FREEIF(x) \
50 #define MMPLAYER_CMD_LOCK(x_player) g_mutex_lock( ((mm_player_t*)x_player)->cmd_lock )
52 #define MMPLAYER_CMD_UNLOCK(x_player) g_mutex_unlock( ((mm_player_t*)x_player)->cmd_lock )
54 #define MMPLAYER_GET_ATTRS(x_player) ((mm_player_t*)x_player)->attrs
56 /* sbs : for bluetooth */
57 #define MAX_SOUND_DEVICE_LEN 18
60 #ifdef GST_EXT_PAD_LINK_UNCHECKED
61 #define GST_ELEMENT_LINK_FILTERED gst_element_link_filtered_unchecked
62 #define GST_ELEMENT_LINK_MANY gst_element_link_many_unchecked
63 #define GST_ELEMENT_LINK gst_element_link_unchecked
64 #define GST_ELEMENT_LINK_PADS gst_element_link_pads_unchecked
65 #define GST_PAD_LINK gst_pad_link_unchecked
67 #define GST_ELEMENT_LINK_FILTERED gst_element_link_filtered
68 #define GST_ELEMENT_LINK_MANY gst_element_link_many
69 #define GST_ELEMENT_LINK gst_element_link
70 #define GST_ELEMENT_LINK_PADS gst_element_link_pads
71 #define GST_PAD_LINK gst_pad_link
76 #define MMPLAYER_POST_MSG( x_player, x_msgtype, x_msg_param ) \
77 debug_log("posting %s to application\n", #x_msgtype); \
78 __mmplayer_post_message(x_player, x_msgtype, x_msg_param);
81 /* setting player state */
82 #define MMPLAYER_SET_STATE( x_player, x_state ) \
83 debug_log("setting player state to %d\n", x_state); \
84 __mmplayer_set_state(x_player, x_state);
87 #define MMPLAYER_CHECK_STATE_RETURN_IF_FAIL( x_player, x_command ) \
88 debug_log("checking player state before doing %s\n", #x_command); \
89 switch ( __mmplayer_check_state(x_player, x_command) ) \
91 case MM_ERROR_PLAYER_INVALID_STATE: \
92 return MM_ERROR_PLAYER_INVALID_STATE; \
94 /* NOTE : for robustness of player. we won't treat it as an error */ \
95 case MM_ERROR_PLAYER_NO_OP: \
96 return MM_ERROR_NONE; \
102 /* setting element state */
103 #define MMPLAYER_ELEMENT_SET_STATE( x_element, x_state ) \
104 debug_log("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME( x_element ) ); \
105 if ( GST_STATE_CHANGE_FAILURE == gst_element_set_state ( x_element, x_state) ) \
107 debug_error("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME( x_element )); \
108 goto STATE_CHANGE_FAILED; \
111 #define MMPLAYER_CHECK_NULL( x_var ) \
114 debug_error("[%s] is NULL\n", #x_var ); \
121 |----|-------|-------|-------|-------|
122 |Res. | HFK(7) | BT(7) | E.J(7) | SPK(7) |
123 |----|-------|-------|-------|-------|
126 /* 090424 Fix me : Currently volume is 0~9, so bt volume can be only 0.0 ~ 0.9 */
127 #define GET_VOLUME_BT(volume) (volume/10.)
130 #define GET_VOLUME_SPK(volume) ((volume) & 0x7F)
131 #define GET_VOLUME_EARJACK(volume) ((volume >> 7)& 0x7F)
132 #define GET_VOLUME_HFK(volume) ((volume >> 21) & 0x7F)
134 #define SET_VOLUME_SPK(volume,input) (volume |= (input &0x7F))
135 #define SET_VOLUME_EARJACK(volume,input) (volume |= ((input & 0x7F)<<7))
136 #define SET_VOLUME_BT(volume,input) (volume |= ((input & 0x7F)<<14))
137 #define SET_VOLUME_HFK(volume,input) (volume |= ((input & 0x7F)<<21))
141 /* pad probe for pipeilne debugging */
142 gboolean __util_gst_pad_probe(GstPad *pad, GstBuffer *buffer, gpointer u_data);
144 #define MM_PROBE_DEFAULT (0)
145 #define MM_PROBE_TIMESTAMP (1)
146 #define MM_PROBE_BUFFERSIZE (1 << 1)
147 #define MM_PROBE_CAPS (1 << 2)
148 #define MM_PROBE_BUFFER_DURATION (1 << 3)
149 #define MM_PROBE_DROP_BUFFER (1 << 4)
150 #define MM_PROBE_CLOCK_TIME (1 << 5)
153 /* messages are treated as warnings bcz those code should not be checked in.
154 * and no error handling will supported for same manner.
156 #define MMPLAYER_ADD_PROBE(x_pad, x_flag) \
157 debug_warning("adding pad probe\n"); \
158 if ( ! gst_pad_add_buffer_probe(x_pad, \
159 G_CALLBACK(__util_gst_pad_probe), \
160 (gpointer)x_flag) ) \
162 debug_error("failed to add pad probe\n"); \
167 #define MMPLAYER_GENERATE_DOT_IF_ENABLED( x_player, x_name ) \
168 if ( PLAYER_INI()->generate_dot ) \
170 debug_log("generating dot file(%s)\n", #x_name); \
171 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), \
172 GST_DEBUG_GRAPH_SHOW_ALL, x_name); \
175 /* signal manipulation */
176 #define MMPLAYER_SIGNAL_CONNECT( x_player, x_object, x_signal, x_callback, x_arg ) \
179 MMPlayerSignalItem* item = NULL; \
180 item = (MMPlayerSignalItem*) g_malloc( sizeof (MMPlayerSignalItem) ); \
183 debug_error("cannot connect signal [%s]\n", x_signal ); \
187 item->obj = G_OBJECT( x_object ); \
188 item->sig = g_signal_connect( G_OBJECT(x_object), x_signal, \
189 x_callback, x_arg ); \
190 x_player->signals = g_list_append(x_player->signals, item); \
196 #define MMPLAYER_PREV_STATE(x_player) ((mm_player_t*)x_player)->prev_state
197 #define MMPLAYER_CURRENT_STATE(x_player) ((mm_player_t*)x_player)->state
198 #define MMPLAYER_PENDING_STATE(x_player) ((mm_player_t*)x_player)->pending_state
199 #define MMPLAYER_TARGET_STATE(x_player) ((mm_player_t*)x_player)->target_state
200 #define MMPLAYER_STATE_GET_NAME(state) __get_state_name(state)
202 #define MMPLAYER_PRINT_STATE(x_player) \
203 debug_log("-----------------------PLAYER STATE-------------------------\n"); \
204 debug_log(" prev %s, current %s, pending %s, target %s \n", \
205 MMPLAYER_STATE_GET_NAME(MMPLAYER_PREV_STATE(x_player)), \
206 MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(x_player)), \
207 MMPLAYER_STATE_GET_NAME(MMPLAYER_PENDING_STATE(x_player)), \
208 MMPLAYER_STATE_GET_NAME(MMPLAYER_TARGET_STATE(x_player))); \
209 debug_log("------------------------------------------------------------\n");
212 #define MMPLAYER_STATE_CHANGE_TIMEOUT(x_player ) ((mm_player_t*)x_player)->state_change_timeout
215 #define MMPLAYER_IS_STREAMING(x_player) __is_streaming(x_player)
216 #define MMPLAYER_IS_RTSP_STREAMING(x_player) __is_rtsp_streaming(x_player)
217 #define MMPLAYER_IS_HTTP_STREAMING(x_player) __is_http_streaming(x_player)
218 #define MMPLAYER_IS_HTTP_PROGRESSIVE_DOWN(x_player) __is_http_progressive_down(x_player)
219 #define MMPLAYER_IS_HTTP_LIVE_STREAMING(x_player) __is_http_live_streaming(x_player)
220 #define MMPLAYER_IS_LIVE_STREAMING(x_player) __is_live_streaming(x_player)
223 #define MMF_PLAYER_FILE_BACKUP_PATH "/tmp/media_temp."
224 #define MMPLAYER_PT_IS_AUDIO( x_pt ) ( strstr(x_pt, "_97") || strstr(x_pt, "audio") )
225 #define MMPLAYER_PT_IS_VIDEO( x_pt ) ( strstr(x_pt, "_96") || strstr(x_pt, "video") )
227 bool util_is_sdp_file ( const char *path );
228 int64_t uti_get_time ( void );
229 int util_get_rank_increase ( const char *factory_class );
230 int util_factory_rank_compare(GstPluginFeature *f1, GstPluginFeature *f2); // @
233 bool util_exist_file_path(const char *file_path);
234 bool util_write_file_backup(const char *backup_path, char *data_ptr, int data_size);
235 bool util_remove_file_backup(const char *backup_path); /* For Midi Player */
237 int util_is_midi_type_by_mem(void *mem, int size);
238 int util_is_midi_type_by_file(const char *file_path);
240 char** util_get_cookie_list ( const char *cookies );
241 bool util_check_valid_url ( const char *proxy );
247 #endif /* __MMF_PLAYER_UTILS_H__ */