Change data type of surface id
[platform/core/api/player.git] / include / player_private.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __TIZEN_MEDIA_PLAYER_PRIVATE_H__
18 #define __TIZEN_MEDIA_PLAYER_PRIVATE_H__
19 #include <tbm_bufmgr.h>
20 #include <media_format.h>
21 #include <muse_player.h>
22 #include <dlfcn.h>
23 #include "player.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #ifdef LOG_TAG
30 #undef LOG_TAG
31 #endif
32 #define LOG_TAG "TIZEN_N_PLAYER"
33
34 #define PLAYER_CHECK_CONDITION(condition, error, msg)     \
35 do {    \
36         if (condition) {} else \
37         { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg, error); return error; } \
38 } while (0)
39
40 #define PLAYER_INSTANCE_CHECK(player)   \
41                 PLAYER_CHECK_CONDITION(player != NULL, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
42
43 #define PLAYER_STATE_CHECK(player, expected_state)       \
44 do {    \
45         player_state_e __state; \
46         if (_get_current_state(player, &__state) != PLAYER_ERROR_NONE) {        \
47                 LOGE("Failed to get state");    \
48                 return PLAYER_ERROR_INVALID_OPERATION;  \
49         }       \
50         PLAYER_CHECK_CONDITION(__state == expected_state, PLAYER_ERROR_INVALID_STATE, "PLAYER_ERROR_INVALID_STATE"); \
51 } while (0)
52
53 #define PLAYER_NULL_ARG_CHECK(arg)      \
54                 PLAYER_CHECK_CONDITION((arg), PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
55
56 #define PLAYER_RANGE_ARG_CHECK(arg, min, max)      \
57         do {    \
58                 PLAYER_CHECK_CONDITION(arg >= min, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");   \
59                 PLAYER_CHECK_CONDITION(arg <= max, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");   \
60         } while (0)
61
62 #define PLAYER_VIDEO_SUPPORTABLE_CHECK(p)       \
63 do {    \
64         if (p && !p->support_video) {   \
65                 LOGW("video display interface is not supported");       \
66                 return PLAYER_ERROR_INVALID_OPERATION;  \
67         }       \
68 } while (0)
69
70 #define PLAYER_FEATURE_CHECK(fkey) \
71 do { \
72         bool __supported__ = false; \
73         if (system_info_get_platform_bool(fkey, &__supported__) != SYSTEM_INFO_ERROR_NONE) { \
74                 LOGE("failed to get system feature info"); \
75                 return PLAYER_ERROR_INVALID_OPERATION; \
76         } \
77         if (!__supported__) { \
78                 LOGW("feature is not supported."); \
79                 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE; \
80         } \
81 } while (0)
82
83 #define CONNECTION_RETRY 51
84 #define CONNECTION_TIME_OUT 50 /* ms */
85 #define CREATE_CB_TIME_OUT 400 /* ms */
86 #define CALLBACK_TIME_OUT 5000 /* ms */
87 #define MAX_SERVER_TIME_OUT 35000 /* ms */
88 #define MAX_URL_LEN     2048    /**< Maximum length of the maximum URL */
89 #define MAX_SUPPORTED_MEDIA_FORMAT 10
90
91 /**
92  * @brief Enumeration for private display type
93  */
94 typedef enum {
95         PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY = 0,    /**< Overlay surface display */
96         PLAYER_PRIVATE_DISPLAY_TYPE_EVAS,           /**< Evas image object surface display */
97         PLAYER_PRIVATE_DISPLAY_TYPE_NONE,           /**< This disposes off buffers */
98 } player_private_display_type_e;
99
100 typedef enum {
101         PLAYER_SEEK_CB_STATE_NONE,
102         PLAYER_SEEK_CB_STATE_DROP,
103         PLAYER_SEEK_CB_STATE_WAIT,
104 } player_seek_cb_state_e;
105
106 typedef struct _ret_msg_s {
107         gint api;
108         gchar *msg;
109         struct _ret_msg_s *next;
110 } ret_msg_s;
111
112 typedef struct {
113         gint bufLen;
114         gchar *recvMsg;
115         gint recved;
116         ret_msg_s *retMsgHead;
117         gchar *part_of_msg; /* keep msg till we receive the hole msg */
118 } msg_buff_s;
119
120 typedef struct _player_data {
121         void *data;
122         struct _player_data *next;
123 } player_data_s;
124
125 typedef struct {
126         GThread *thread;
127         GQueue *queue;
128         GMutex qlock;
129         GMutex mutex;
130         GCond cond;
131         gboolean running;
132
133         GMutex idle_ev_mutex;
134         GList *idle_ev_list;
135 } player_event_queue;
136
137 typedef struct {
138         int key[4];
139         tbm_surface_h tsurf;
140 } player_tsurf_info_t;
141 #ifdef TIZEN_FEATURE_EVAS_RENDERER
142
143 typedef enum {
144         EVAS_VISIBLE_NONE,                      /* if user dont set visibility, it will be changed to true */
145         EVAS_VISIBLE_TRUE,
146         EVAS_VISIBLE_FALSE
147 } visible_info_e;
148
149 typedef struct {
150         void *handle;
151         visible_info_e visible;
152         player_display_rotation_e rotation;
153         player_display_mode_e mode;
154         gboolean update_needed;
155         int roi_x;
156         int roi_y;
157         int roi_w;
158         int roi_h;
159         gboolean support_video;
160 } player_evas_info_s;
161 #endif
162 typedef struct _callback_cb_info {
163         GThread *thread;
164         gint running;
165         gint fd;
166         gint data_fd;
167         gpointer user_cb[MUSE_PLAYER_EVENT_TYPE_NUM];
168         gpointer user_data[MUSE_PLAYER_EVENT_TYPE_NUM];
169         GMutex player_mutex;
170         GCond player_cond[MUSE_PLAYER_API_MAX];
171         GCond server_ack_cond;
172         GMutex data_mutex;
173         player_seek_cb_state_e seek_cb_state;
174         GMutex seek_cb_mutex;
175         msg_buff_s buff;
176         player_event_queue event_queue;
177         media_format_h pkt_fmt;
178 #ifdef TIZEN_FEATURE_EVAS_RENDERER
179         player_evas_info_s *evas_info;
180 #endif
181         tbm_bufmgr bufmgr;
182         tbm_fd tfd; /* for player_get_album_art*/
183         GList *tsurf_list; /* player_tsurf_info_t */
184         int video_frame_pool_size;
185         bool use_tsurf_pool;
186 } callback_cb_info_s;
187
188 typedef struct {
189         intptr_t bo;
190         gint timeout; /* ms */
191 } server_info_s;
192
193 typedef struct _player_cli_s {
194         callback_cb_info_s *cb_info;
195         player_data_s *head;
196         server_info_s server;
197         void *dl_handle;        /* dlopen handle for display interface */
198         gboolean have_evas_callback;
199         gboolean push_media_stream;
200         gboolean support_video;
201         gboolean is_audio_only;
202 } player_cli_s;
203
204 typedef struct {
205         void *data;          /**< PCM data */
206         int size;            /**< Data Size */
207         int channel;         /**< Channel */
208         int rate;            /**<  Samplerate */
209         unsigned long long channel_mask;        /**< channel_mask */
210         media_format_mimetype_e pcm_format;
211 } player_audio_decoded_data_info_t;
212
213 /* player callback information */
214 #define CALLBACK_INFO(h)        ((h)->cb_info)
215 /* MSG Channel socket fd */
216 #define MSG_FD(h)                       (CALLBACK_INFO(h)->fd)
217 /* Data Channel socket fd */
218 #define DATA_FD(h)                      (CALLBACK_INFO(h)->data_fd)
219 /* TBM buffer manager */
220 #define TBM_BUFMGR(h)           (CALLBACK_INFO(h)->bufmgr)
221 #ifdef TIZEN_FEATURE_EVAS_RENDERER
222 /* evas display handle */
223 #define EVAS_INFO(h)            ((h)->cb_info->evas_info)
224 #define EVAS_HANDLE(h)          (EVAS_INFO(h)->handle)
225 #endif
226 /* server tbm bo */
227 #define SERVER_TBM_BO(h)        ((h)->server.bo)
228 /* server state change timeout (sec) */
229 #define SERVER_TIMEOUT(h)               ((h)->server.timeout)
230
231
232 #define PATH_DISP_LIB PATH_LIBDIR"/libcapi-media-player-display.so"
233
234 #define PLAYER_DISP_DLOPEN(pc)  \
235 do {    \
236         pc->dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);       \
237         if (pc->dl_handle == NULL) {    \
238                 LOGW("not support video rendering"); \
239         } else {        \
240                 pc->support_video = TRUE;       \
241                 EVAS_INFO(pc)->support_video = TRUE;    \
242         }       \
243 } while (0)
244
245 #define PLAYER_DISP_DLSYM(handle, sym, function_name)   \
246 do {    \
247         char *error;    \
248         sym = dlsym(handle, function_name);     \
249         if ((error = dlerror()) != NULL) {      \
250                 dlclose(handle);        \
251                 LOGE("dlsym error %s", error);  \
252         }       \
253 } while (0)
254
255 #define PLAYER_DISP_DLCLOSE(handle)     \
256 do {    \
257         if (handle) {   \
258                 dlclose(handle); \
259         } \
260 } while (0)
261
262
263 int client_get_api_timeout(player_cli_s *pc, muse_player_api_e api);
264 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s *cb_info, char **ret_buf, int time_out);
265 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type);
266 int _player_get_valid_path(const char *uri, char *origin);
267
268 #ifdef __cplusplus
269 }
270 #endif
271 #endif  /*__TIZEN_MEDIA_PLAYER_PRIVATE_H__*/