Merge "enhance document description related to display and add return type in display...
[platform/core/api/player.git] / src / player_internal.c
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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <muse_core.h>
21 #include <muse_core_msg_json.h>
22 #include <muse_core_ipc.h>
23 #include <mm_error.h>
24 #include <dlog.h>
25 #include <Evas.h>
26 #include <Ecore_Evas.h>
27 #include <Ecore_Wayland.h>
28 #include <muse_player.h>
29 #include <muse_player_msg.h>
30 #include "player_private.h"
31 #include "player_msg.h"
32 #include "player_internal.h"
33 #include "player_display.h"
34
35 int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data)
36 {
37         PLAYER_INSTANCE_CHECK(player);
38         PLAYER_NULL_ARG_CHECK(callback);
39         int ret = PLAYER_ERROR_NONE;
40         muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_EXTRACTION_MODE;
41         player_cli_s *pc = (player_cli_s *) player;
42         char *ret_buf = NULL;
43         muse_player_event_e event = MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME;
44
45         LOGD("ENTER");
46
47         player_msg_send1(api, pc, ret_buf, ret, INT, sync);
48
49         if (ret == PLAYER_ERROR_NONE) {
50                 pc->cb_info->user_cb[event] = callback;
51                 pc->cb_info->user_data[event] = user_data;
52                 LOGI("Event type : %d ", event);
53         }
54
55         g_free(ret_buf);
56         return ret;
57 }
58
59 int player_set_pcm_spec(player_h player, const char *format, int samplerate, int channel)
60 {
61         PLAYER_INSTANCE_CHECK(player);
62         int ret = PLAYER_ERROR_NONE;
63         muse_player_api_e api = MUSE_PLAYER_API_SET_PCM_SPEC;
64         player_cli_s *pc = (player_cli_s *) player;
65         char *ret_buf = NULL;
66
67         LOGD("ENTER");
68
69         player_msg_send3(api, pc, ret_buf, ret, STRING, format, INT, samplerate, INT, channel);
70
71         g_free(ret_buf);
72         return ret;
73 }
74
75 int player_set_streaming_playback_rate(player_h player, float rate)
76 {
77         PLAYER_INSTANCE_CHECK(player);
78         int ret = PLAYER_ERROR_NONE;
79         muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
80         player_cli_s *pc = (player_cli_s *) player;
81         char *ret_buf = NULL;
82
83         LOGD("ENTER");
84
85         player_msg_send1(api, pc, ret_buf, ret, DOUBLE, rate);
86         g_free(ret_buf);
87         return ret;
88 }
89
90 int player_set_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type, player_media_stream_buffer_status_cb_ex callback, void *user_data)
91 {
92         PLAYER_INSTANCE_CHECK(player);
93         PLAYER_NULL_ARG_CHECK(callback);
94         int ret = PLAYER_ERROR_NONE;
95         player_cli_s *pc = (player_cli_s *) player;
96         muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
97         char *ret_buf = NULL;
98         muse_player_event_e type;
99         int set = 1;
100
101         LOGD("ENTER");
102
103         if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
104                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
105         else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
106                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
107         else {
108                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
109                 return PLAYER_ERROR_INVALID_PARAMETER;
110         }
111
112         player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
113
114         if (ret == PLAYER_ERROR_NONE) {
115                 pc->cb_info->user_cb[type] = callback;
116                 pc->cb_info->user_data[type] = user_data;
117                 LOGI("Event type : %d ", type);
118         }
119
120         g_free(ret_buf);
121         return ret;
122 }
123
124 static void set_null_user_cb(callback_cb_info_s * cb_info, muse_player_event_e event)
125 {
126         if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
127                 cb_info->user_cb[event] = NULL;
128                 cb_info->user_data[event] = NULL;
129         }
130 }
131
132 static void set_null_user_cb_lock(callback_cb_info_s * cb_info, muse_player_event_e event)
133 {
134         bool lock = g_thread_self() != cb_info->event_queue.thread;
135
136         if (lock)
137                 g_mutex_lock(&cb_info->event_queue.mutex);
138
139         set_null_user_cb(cb_info, event);
140
141         if (lock)
142                 g_mutex_unlock(&cb_info->event_queue.mutex);
143 }
144
145 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
146 {
147         PLAYER_INSTANCE_CHECK(player);
148         int ret = PLAYER_ERROR_NONE;
149         player_cli_s *pc = (player_cli_s *) player;
150         muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
151         char *ret_buf = NULL;
152         muse_player_event_e type;
153         int set = 0;
154
155         LOGD("ENTER");
156
157         if (stream_type == PLAYER_STREAM_TYPE_VIDEO)
158                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
159         else if (stream_type == PLAYER_STREAM_TYPE_AUDIO)
160                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
161         else {
162                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
163                 return PLAYER_ERROR_INVALID_PARAMETER;
164         }
165
166         set_null_user_cb_lock(pc->cb_info, type);
167
168         player_msg_send2(api, pc, ret_buf, ret, INT, type, INT, set);
169
170         g_free(ret_buf);
171         return ret;
172 }
173
174 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
175 {
176         PLAYER_INSTANCE_CHECK(player);
177         int ret = PLAYER_ERROR_NONE;
178         muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
179         player_cli_s *pc = (player_cli_s *) player;
180         char *ret_buf = NULL;
181
182         LOGD("ENTER");
183
184         player_msg_send1(api, pc, ret_buf, ret, INT, drc);
185         g_free(ret_buf);
186         return ret;
187 }
188
189 int player_set_ecore_wl_display(player_h player, player_display_type_e type, Ecore_Wl_Window *ecore_wl_window, int x, int y, int  width, int height)
190 {
191         PLAYER_INSTANCE_CHECK(player);
192         int ret = PLAYER_ERROR_NONE;
193         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
194         player_cli_s *pc = (player_cli_s *) player;
195         char *ret_buf = NULL;
196         wl_win_msg_type wl_win;
197         char *wl_win_msg = (char *)&wl_win;
198         unsigned int wl_surface_id;
199         struct wl_surface *wl_surface;
200         struct wl_display *wl_display;
201         Ecore_Wl_Window *wl_window = NULL;
202
203         LOGD("ENTER");
204         if (type != PLAYER_DISPLAY_TYPE_OVERLAY) {
205                 LOGE("Display type(%d) is not overlay", type);
206                 return PLAYER_ERROR_INVALID_PARAMETER;
207         }
208         if (!ecore_wl_window)
209                 return PLAYER_ERROR_INVALID_PARAMETER;
210
211         LOGI("Wayland overlay surface type");
212         LOGD("Ecore Wayland Window handle(%p), size (%d, %d, %d, %d)", ecore_wl_window, x, y, width, height);
213         wl_window = ecore_wl_window;
214
215         /* set wl_win */
216         wl_win.type = type;
217         wl_win.wl_window_x = x;
218         wl_win.wl_window_y = y;
219         wl_win.wl_window_width = width;
220         wl_win.wl_window_height = height;
221
222         wl_surface = (struct wl_surface *)ecore_wl_window_surface_get(wl_window);
223         /* get wl_display */
224         wl_display = (struct wl_display *)ecore_wl_display_get();
225
226         if (!pc->wlclient) {
227                 ret = _wl_client_create(&pc->wlclient);
228                 if (ret != MM_ERROR_NONE) {
229                         LOGE("Wayland client create failure");
230                         return ret;
231                 }
232         }
233
234         if (wl_surface && wl_display) {
235                 LOGD("surface = %p, wl_display = %p", wl_surface, wl_display);
236                 wl_surface_id = _wl_client_get_wl_window_wl_surface_id(pc->wlclient, wl_surface, wl_display);
237                 LOGD("wl_surface_id = %d", wl_surface_id);
238                 wl_win.wl_surface_id = wl_surface_id;
239                 LOGD("wl_win.wl_surface_id = %d", wl_win.wl_surface_id);
240         } else {
241                 LOGE("Fail to get wl_surface or wl_display");
242                 return PLAYER_ERROR_INVALID_OPERATION;
243         }
244
245         if (pc->wlclient) {
246                 g_free(pc->wlclient);
247                 pc->wlclient = NULL;
248         }
249
250         player_msg_send_array(api, pc, ret_buf, ret, wl_win_msg, sizeof(wl_win_msg_type), sizeof(char));
251
252         g_free(ret_buf);
253
254         return ret;
255 }
256
257 #ifndef TIZEN_TV
258 int player_set_next_uri(player_h player, const char *uri)
259 {
260         PLAYER_INSTANCE_CHECK(player);
261         PLAYER_NULL_ARG_CHECK(uri);
262         int ret = PLAYER_ERROR_NONE;
263         muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
264         player_cli_s *pc = (player_cli_s *) player;
265         char *ret_buf = NULL;
266         char path[MAX_URL_LEN];
267
268         LOGD("ENTER");
269
270         _player_replace_old_path(uri, path);
271         player_msg_send1(api, pc, ret_buf, ret, STRING, path);
272
273         g_free(ret_buf);
274         return ret;
275 }
276
277 int player_get_next_uri(player_h player, char **uri)
278 {
279         PLAYER_INSTANCE_CHECK(player);
280         PLAYER_NULL_ARG_CHECK(uri);
281         int ret = PLAYER_ERROR_NONE;
282         muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
283         player_cli_s *pc = (player_cli_s *) player;
284         char *ret_buf = NULL;
285         char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
286
287         LOGD("ENTER");
288
289         player_msg_send(api, pc, ret_buf, ret);
290         if (ret == PLAYER_ERROR_NONE) {
291                 player_msg_get_string(next_uri, ret_buf);
292                 *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
293         }
294         g_free(ret_buf);
295         return ret;
296 }
297
298 int player_set_gapless(player_h player, bool gapless)
299 {
300         PLAYER_INSTANCE_CHECK(player);
301         int ret = PLAYER_ERROR_NONE;
302         muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
303         player_cli_s *pc = (player_cli_s *) player;
304         char *ret_buf = NULL;
305
306         LOGD("ENTER");
307
308         player_msg_send1(api, pc, ret_buf, ret, INT, gapless);
309         g_free(ret_buf);
310         return ret;
311 }
312
313 int player_is_gapless(player_h player, bool *gapless)
314 {
315         PLAYER_INSTANCE_CHECK(player);
316         PLAYER_NULL_ARG_CHECK(gapless);
317         int ret = PLAYER_ERROR_NONE;
318         muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
319         player_cli_s *pc = (player_cli_s *) player;
320         char *ret_buf = NULL;
321         int value = 0;
322
323         LOGD("ENTER");
324
325         player_msg_send(api, pc, ret_buf, ret);
326         if (ret == PLAYER_ERROR_NONE) {
327                 player_msg_get(value, ret_buf);
328                 *gapless = value;
329         }
330         g_free(ret_buf);
331         return ret;
332 }
333
334 int player_enable_tsurf_pool(player_h player, bool enable)
335 {
336         PLAYER_INSTANCE_CHECK(player);
337         int ret = PLAYER_ERROR_NONE;
338         player_cli_s *pc = (player_cli_s *) player;
339
340         LOGD("ENTER enable:%d", enable);
341
342         if (pc && pc->cb_info) {
343                 pc->cb_info->use_tsurf_pool = enable;
344         } else {
345                 LOGE("failed to enable the tbm surf pool");
346                 ret = PLAYER_ERROR_INVALID_OPERATION;
347         }
348
349         return ret;
350 }
351
352 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
353 {
354         PLAYER_INSTANCE_CHECK(player);
355         PLAYER_NULL_ARG_CHECK(enabled);
356         int ret = PLAYER_ERROR_NONE;
357         player_cli_s *pc = (player_cli_s *) player;
358
359         LOGD("ENTER");
360         if (pc && pc->cb_info) {
361                 *enabled = pc->cb_info->use_tsurf_pool;
362         } else {
363                 LOGE("failed to get the tbm surf pool state");
364                 ret = PLAYER_ERROR_INVALID_OPERATION;
365         }
366
367         return ret;
368 }
369
370 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
371 {
372         PLAYER_INSTANCE_CHECK(player);
373         PLAYER_NULL_ARG_CHECK(size);
374
375         int ret = PLAYER_ERROR_NONE;
376         muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
377         player_cli_s *pc = (player_cli_s *) player;
378         char *ret_buf = NULL;
379         int value = 0;
380
381         LOGD("ENTER");
382
383         player_msg_send(api, pc, ret_buf, ret);
384         if (ret == PLAYER_ERROR_NONE) {
385                 player_msg_get(value, ret_buf);
386                 *size = value;
387                 pc->cb_info->video_frame_pool_size = value;
388                 LOGD("packet pool size : %d", *size);
389         }
390         g_free(ret_buf);
391         return ret;
392 }
393
394 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
395 {
396         PLAYER_INSTANCE_CHECK(player);
397         int ret = PLAYER_ERROR_NONE;
398         muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
399         player_cli_s *pc = (player_cli_s *) player;
400         char *ret_buf = NULL;
401
402         LOGD("ENTER");
403
404         player_msg_send1(api, pc, ret_buf, ret, INT, enable);
405         g_free(ret_buf);
406         return ret;
407 }
408 #endif