Merge "add internal api to enable media packet callback" into tizen
[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 <Evas.h>
21 #include <media_format.h>
22 #include <muse_player.h>
23 #include "player.h"
24 #include "player_display.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33 #define LOG_TAG "TIZEN_N_PLAYER"
34
35 #define PLAYER_CHECK_CONDITION(condition, error, msg)     \
36                 if (condition) {} else \
37                 { LOGE("[%s] %s(0x%08x)", __FUNCTION__, msg, error); return error; }; \
38
39 #define PLAYER_INSTANCE_CHECK(player)   \
40                 PLAYER_CHECK_CONDITION(player != NULL, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
41
42 #define PLAYER_STATE_CHECK(player, expected_state)       \
43                 PLAYER_CHECK_CONDITION(player->state == expected_state, PLAYER_ERROR_INVALID_STATE, "PLAYER_ERROR_INVALID_STATE")
44
45 #define PLAYER_NULL_ARG_CHECK(arg)      \
46                 PLAYER_CHECK_CONDITION(arg != NULL, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
47
48 #define CONNECTION_RETRY 51
49 #define CONNECTION_TIME_OUT 50 /* ms */
50 #define CREATE_CB_TIME_OUT 400 /* ms */
51 #define CALLBACK_TIME_OUT 5000 /* ms */
52 #define MAX_SERVER_TIME_OUT 35000 /* ms */
53
54
55 typedef struct _ret_msg_s {
56         gint api;
57         gchar *msg;
58         struct _ret_msg_s *next;
59 } ret_msg_s;
60
61 typedef struct {
62         gint bufLen;
63         gchar *recvMsg;
64         gint recved;
65         ret_msg_s *retMsgHead;
66         gchar *part_of_msg; /* keep msg till we receive the hole msg */
67 } msg_buff_s;
68
69 typedef struct _player_data {
70         void *data;
71         struct _player_data *next;
72 } player_data_s;
73
74 typedef struct {
75         GThread *thread;
76         GQueue *queue;
77         GMutex qlock;
78         GMutex mutex;
79         GCond cond;
80         gboolean running;
81 } player_event_queue;
82
83 typedef struct {
84         tbm_key key;
85         tbm_surface_h tsurf;
86 } player_tsurf_info_t;
87
88 typedef struct _callback_cb_info {
89         GThread *thread;
90         gint running;
91         gint fd;
92         gint data_fd;
93         gpointer user_cb[MUSE_PLAYER_EVENT_TYPE_NUM];
94         gpointer user_data[MUSE_PLAYER_EVENT_TYPE_NUM];
95         GMutex player_mutex;
96         GCond player_cond[MUSE_PLAYER_API_MAX];
97         GCond server_ack_cond;
98         GMutex data_mutex;
99         gboolean block_seek_cb;
100         GMutex seek_cb_mutex;
101         msg_buff_s buff;
102         player_event_queue event_queue;
103         media_format_h pkt_fmt;
104         void *evas_info;
105         tbm_bufmgr bufmgr;
106         GList *tsurf_list; /* player_tsurf_info_t */
107         int video_frame_pool_size;
108         bool use_tsurf_pool;
109 } callback_cb_info_s;
110
111 typedef struct {
112         intptr_t bo;
113         gint timeout; /* ms */
114 } server_info_s;
115
116 typedef struct _player_cli_s {
117         callback_cb_info_s *cb_info;
118         player_data_s *head;
119         server_info_s server;
120         wl_client *wlclient;
121         Evas_Object *eo;
122         gboolean have_evas_callback;
123         gboolean push_media_stream;
124 } player_cli_s;
125
126 /* player callback information */
127 #define CALLBACK_INFO(h)        ((h)->cb_info)
128 /* MSG Channel socket fd */
129 #define MSG_FD(h)                       (CALLBACK_INFO(h)->fd)
130 /* Data Channel socket fd */
131 #define DATA_FD(h)                      (CALLBACK_INFO(h)->data_fd)
132 /* TBM buffer manager */
133 #define TBM_BUFMGR(h)           (CALLBACK_INFO(h)->bufmgr)
134 /* evas display handle */
135 #define EVAS_HANDLE(h)          ((h)->cb_info->evas_info)
136
137 /* server tbm bo */
138 #define SERVER_TBM_BO(h)        ((h)->server.bo)
139 /* server state change timeout (sec) */
140 #define SERVER_TIMEOUT(h)               ((h)->server.timeout)
141
142 int client_get_api_timeout(player_cli_s * pc, muse_player_api_e api);
143 int client_wait_for_cb_return(muse_player_api_e api, callback_cb_info_s * cb_info, char **ret_buf, int time_out);
144
145 #ifdef __cplusplus
146 }
147 #endif
148 #endif  /*__TIZEN_MEDIA_PLAYER_PRIVATE_H__*/