Modify nal parser to be parsed in au unit
[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_VIDEO_SUPPORTABLE_CHECK(p)       \
57 do {    \
58         if (p && !p->support_video) {   \
59                 LOGW("video display interface is not supported");       \
60                 return PLAYER_ERROR_INVALID_OPERATION;  \
61         }       \
62 } while (0)
63
64 #define PLAYER_FEATURE_CHECK(fkey) \
65 do { \
66         bool __supported__ = false; \
67         if (system_info_get_platform_bool(fkey, &__supported__) != SYSTEM_INFO_ERROR_NONE) { \
68                 LOGE("failed to get system feature info"); \
69                 return PLAYER_ERROR_INVALID_OPERATION; \
70         } \
71         if (!__supported__) { \
72                 LOGW("feature is not supported."); \
73                 return PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE; \
74         } \
75 } while (0)
76
77 #define CONNECTION_RETRY 51
78 #define CONNECTION_TIME_OUT 50 /* ms */
79 #define CREATE_CB_TIME_OUT 400 /* ms */
80 #define CALLBACK_TIME_OUT 5000 /* ms */
81 #define MAX_SERVER_TIME_OUT 35000 /* ms */
82 #define MAX_URL_LEN     2048    /**< Maximum length of the maximum URL */
83
84 /**
85  * @brief Enumeration for private display type
86  */
87 typedef enum {
88         PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY = 0,    /**< Overlay surface display */
89         PLAYER_PRIVATE_DISPLAY_TYPE_EVAS,           /**< Evas image object surface display */
90         PLAYER_PRIVATE_DISPLAY_TYPE_NONE,           /**< This disposes off buffers */
91 } player_private_display_type_e;
92
93 typedef enum {
94         PLAYER_SEEK_CB_STATE_NONE,
95         PLAYER_SEEK_CB_STATE_DROP,
96         PLAYER_SEEK_CB_STATE_WAIT,
97 } player_seek_cb_state_e;
98
99 typedef struct _ret_msg_s {
100         gint api;
101         gchar *msg;
102         struct _ret_msg_s *next;
103 } ret_msg_s;
104
105 typedef struct {
106         gint bufLen;
107         gchar *recvMsg;
108         gint recved;
109         ret_msg_s *retMsgHead;
110         gchar *part_of_msg; /* keep msg till we receive the hole msg */
111 } msg_buff_s;
112
113 typedef struct _player_data {
114         void *data;
115         struct _player_data *next;
116 } player_data_s;
117
118 typedef struct {
119         GThread *thread;
120         GQueue *queue;
121         GMutex qlock;
122         GMutex mutex;
123         GCond cond;
124         gboolean running;
125
126         GMutex idle_ev_mutex;
127         GList *idle_ev_list;
128 } player_event_queue;
129
130 typedef struct {
131         int key[4];
132         tbm_surface_h tsurf;
133 } player_tsurf_info_t;
134 #ifdef TIZEN_FEATURE_EVAS_RENDERER
135
136 typedef enum {
137         EVAS_VISIBLE_NONE,                      /* if user dont set visibility, it will be changed to true */
138         EVAS_VISIBLE_TRUE,
139         EVAS_VISIBLE_FALSE
140 } visible_info_e;
141
142 typedef struct {
143         void *handle;
144         visible_info_e visible;
145         player_display_rotation_e rotation;
146         player_display_mode_e mode;
147         gboolean update_needed;
148         int roi_x;
149         int roi_y;
150         int roi_w;
151         int roi_h;
152         gboolean support_video;
153 } player_evas_info_s;
154 #endif
155 typedef struct _callback_cb_info {
156         GThread *thread;
157         gint running;
158         gint fd;
159         gint data_fd;
160         gpointer user_cb[MUSE_PLAYER_EVENT_TYPE_NUM];
161         gpointer user_data[MUSE_PLAYER_EVENT_TYPE_NUM];
162         GMutex player_mutex;
163         GCond player_cond[MUSE_PLAYER_API_MAX];
164         GCond server_ack_cond;
165         GMutex data_mutex;
166         player_seek_cb_state_e seek_cb_state;
167         GMutex seek_cb_mutex;
168         msg_buff_s buff;
169         player_event_queue event_queue;
170         media_format_h pkt_fmt;
171 #ifdef TIZEN_FEATURE_EVAS_RENDERER
172         player_evas_info_s *evas_info;
173 #endif
174         tbm_bufmgr bufmgr;
175         tbm_fd tfd; /* for player_get_album_art*/
176         GList *tsurf_list; /* player_tsurf_info_t */
177         int video_frame_pool_size;
178         bool use_tsurf_pool;
179 } callback_cb_info_s;
180
181 typedef struct {
182         intptr_t bo;
183         gint timeout; /* ms */
184 } server_info_s;
185
186 typedef struct _player_cli_s {
187         callback_cb_info_s *cb_info;
188         player_data_s *head;
189         server_info_s server;
190         void *dl_handle;        /* dlopen handle for display interface */
191         gboolean have_evas_callback;
192         gboolean push_media_stream;
193         gboolean support_video;
194         gboolean is_audio_only;
195 } player_cli_s;
196
197 /* player callback information */
198 #define CALLBACK_INFO(h)        ((h)->cb_info)
199 /* MSG Channel socket fd */
200 #define MSG_FD(h)                       (CALLBACK_INFO(h)->fd)
201 /* Data Channel socket fd */
202 #define DATA_FD(h)                      (CALLBACK_INFO(h)->data_fd)
203 /* TBM buffer manager */
204 #define TBM_BUFMGR(h)           (CALLBACK_INFO(h)->bufmgr)
205 #ifdef TIZEN_FEATURE_EVAS_RENDERER
206 /* evas display handle */
207 #define EVAS_INFO(h)            ((h)->cb_info->evas_info)
208 #define EVAS_HANDLE(h)          (EVAS_INFO(h)->handle)
209 #endif
210 /* server tbm bo */
211 #define SERVER_TBM_BO(h)        ((h)->server.bo)
212 /* server state change timeout (sec) */
213 #define SERVER_TIMEOUT(h)               ((h)->server.timeout)
214
215
216 #define PATH_DISP_LIB PATH_LIBDIR"/libcapi-media-player-display.so"
217
218 #define PLAYER_DISP_DLOPEN(pc)  \
219 do {    \
220         pc->dl_handle = dlopen(PATH_DISP_LIB, RTLD_LAZY);       \
221         if (pc->dl_handle == NULL) {    \
222                 LOGW("not support video rendering"); \
223         } else {        \
224                 pc->support_video = TRUE;       \
225                 EVAS_INFO(pc)->support_video = TRUE;    \
226         }       \
227 } while (0)
228
229 #define PLAYER_DISP_DLSYM(handle, sym, function_name)   \
230 do {    \
231         char *error;    \
232         sym = dlsym(handle, function_name);     \
233         if ((error = dlerror()) != NULL) {      \
234                 dlclose(handle);        \
235                 LOGE("dlsym error %s", error);  \
236         }       \
237 } while (0)
238
239 #define PLAYER_DISP_DLCLOSE(handle)     \
240 do {    \
241         if (handle) {   \
242                 dlclose(handle); \
243         } \
244 } while (0)
245
246
247 int client_get_api_timeout(player_cli_s *pc, muse_player_api_e api);
248 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s *cb_info, char **ret_buf, int time_out);
249 int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type);
250 int _player_get_valid_path(const char *uri, char *origin);
251
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif  /*__TIZEN_MEDIA_PLAYER_PRIVATE_H__*/