[0.3.121] remove deprecated internal api
[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 <mm_error.h>
21 #include <dlog.h>
22 #include <muse_player.h>
23 #include <muse_player_msg.h>
24 #include <storage-internal.h>
25 #include "player_private.h"
26 #include "player_msg.h"
27 #include "player_internal.h"
28
29 int player_set_streaming_playback_rate(player_h player, float rate)
30 {
31         PLAYER_INSTANCE_CHECK(player);
32         int ret = PLAYER_ERROR_NONE;
33         muse_player_api_e api = MUSE_PLAYER_API_SET_STREAMING_PLAYBACK_RATE;
34         player_cli_s *pc = (player_cli_s *)player;
35         char *ret_buf = NULL;
36
37         LOGD("ENTER");
38
39         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_DOUBLE, "rate", rate);
40         g_free(ret_buf);
41         return ret;
42 }
43
44 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)
45 {
46         PLAYER_INSTANCE_CHECK(player);
47         PLAYER_NULL_ARG_CHECK(callback);
48         int ret = PLAYER_ERROR_NONE;
49         player_cli_s *pc = (player_cli_s *)player;
50         muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
51         char *ret_buf = NULL;
52         muse_player_event_e type;
53         int set = 1;
54
55         LOGD("ENTER");
56
57         if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
58                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
59         } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
60                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
61         } else {
62                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
63                 return PLAYER_ERROR_INVALID_PARAMETER;
64         }
65
66         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
67
68         if (ret == PLAYER_ERROR_NONE) {
69                 pc->cb_info->user_cb[type] = callback;
70                 pc->cb_info->user_data[type] = user_data;
71                 LOGI("Event type : %d ", type);
72         }
73
74         g_free(ret_buf);
75         return ret;
76 }
77
78 static void set_null_user_cb(callback_cb_info_s *cb_info, muse_player_event_e event)
79 {
80         if (cb_info && event < MUSE_PLAYER_EVENT_TYPE_NUM) {
81                 cb_info->user_cb[event] = NULL;
82                 cb_info->user_data[event] = NULL;
83         }
84 }
85
86 static void set_null_user_cb_lock(callback_cb_info_s *cb_info, muse_player_event_e event)
87 {
88         bool lock = g_thread_self() != cb_info->event_queue.thread;
89
90         if (lock)
91                 g_mutex_lock(&cb_info->event_queue.mutex);
92
93         set_null_user_cb(cb_info, event);
94
95         if (lock)
96                 g_mutex_unlock(&cb_info->event_queue.mutex);
97 }
98
99 int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e stream_type)
100 {
101         PLAYER_INSTANCE_CHECK(player);
102         int ret = PLAYER_ERROR_NONE;
103         player_cli_s *pc = (player_cli_s *)player;
104         muse_player_api_e api = MUSE_PLAYER_API_SET_CALLBACK;
105         char *ret_buf = NULL;
106         muse_player_event_e type;
107         int set = 0;
108
109         LOGD("ENTER");
110
111         if (stream_type == PLAYER_STREAM_TYPE_VIDEO) {
112                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
113         } else if (stream_type == PLAYER_STREAM_TYPE_AUDIO) {
114                 type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
115         } else {
116                 LOGE("PLAYER_ERROR_INVALID_PARAMETER(type : %d)", stream_type);
117                 return PLAYER_ERROR_INVALID_PARAMETER;
118         }
119
120         set_null_user_cb_lock(pc->cb_info, type);
121
122         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "type", type, MUSE_TYPE_INT, "set", set);
123
124         g_free(ret_buf);
125         return ret;
126 }
127
128 int player_set_media_stream_dynamic_resolution(player_h player, bool drc)
129 {
130         PLAYER_INSTANCE_CHECK(player);
131         int ret = PLAYER_ERROR_NONE;
132         muse_player_api_e api = MUSE_PLAYER_API_SET_MEDIA_STREAM_DYNAMIC_RESOLUTION;
133         player_cli_s *pc = (player_cli_s *)player;
134         char *ret_buf = NULL;
135
136         LOGD("ENTER");
137
138         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "drc", drc);
139         g_free(ret_buf);
140         return ret;
141 }
142
143 int player_set_ecore_wl_display(player_h player, player_display_type_e type, void *ecore_wl2_window, int x, int y, int width, int height)
144 {
145         PLAYER_INSTANCE_CHECK(player);
146         int ret = PLAYER_ERROR_NONE;
147         muse_player_api_e api = MUSE_PLAYER_API_SET_DISPLAY;
148         player_cli_s *pc = (player_cli_s *)player;
149         char *ret_buf = NULL;
150         wl_win_msg_type wl_win;
151         char *wl_win_msg = (char *)&wl_win;
152         unsigned int wl_surface_id;
153         player_private_display_type_e conv_type;
154         unsigned int (*p_disp_set_wl_display)(int, void *) = NULL;
155         int arr_msg_len = 0;
156
157         LOGD("ENTER");
158         PLAYER_VIDEO_SUPPORTABLE_CHECK(pc);
159
160         ret = _player_convert_display_type(type, &conv_type);
161         if (ret != PLAYER_ERROR_NONE)
162                 return ret;
163
164         if (conv_type != PLAYER_PRIVATE_DISPLAY_TYPE_OVERLAY) {
165                 LOGE("Display type(%d) is not overlay", conv_type);
166                 return PLAYER_ERROR_INVALID_PARAMETER;
167         }
168         if (!ecore_wl2_window)
169                 return PLAYER_ERROR_INVALID_PARAMETER;
170
171         PLAYER_DISP_DLSYM(pc->dl_handle, p_disp_set_wl_display, "disp_set_wl_display");
172         wl_surface_id = p_disp_set_wl_display(ECORE_WAYLAND_WIN, ecore_wl2_window);
173         if (wl_surface_id > 0) {
174                 wl_win.surface_id = wl_surface_id;
175                 wl_win.type = conv_type;
176         } else {
177                 return PLAYER_ERROR_INVALID_OPERATION;
178         }
179
180         arr_msg_len = (sizeof(wl_win_msg_type) / sizeof(int) + (sizeof(wl_win_msg_type) % sizeof(int) ? 1 : 0));
181         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
182                                         MUSE_TYPE_ARRAY, "wl_win_msg", arr_msg_len, (int *)wl_win_msg);
183         g_free(ret_buf);
184
185         return ret;
186
187 }
188 int player_set_next_uri(player_h player, const char *uri)
189 {
190         PLAYER_INSTANCE_CHECK(player);
191         PLAYER_NULL_ARG_CHECK(uri);
192         int ret = PLAYER_ERROR_NONE;
193         muse_player_api_e api = MUSE_PLAYER_API_SET_NEXT_URI;
194         player_cli_s *pc = (player_cli_s *)player;
195         char *ret_buf = NULL;
196         char path[MAX_URL_LEN] = {0, };
197
198         LOGD("ENTER");
199
200         if (_player_get_valid_path(uri, path) != PLAYER_ERROR_NONE)
201                 return PLAYER_ERROR_INVALID_PARAMETER;
202
203         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_STRING, "path", path);
204
205         g_free(ret_buf);
206         return ret;
207 }
208
209 int player_get_next_uri(player_h player, char **uri)
210 {
211         PLAYER_INSTANCE_CHECK(player);
212         PLAYER_NULL_ARG_CHECK(uri);
213         int ret = PLAYER_ERROR_NONE;
214         muse_player_api_e api = MUSE_PLAYER_API_GET_NEXT_URI;
215         player_cli_s *pc = (player_cli_s *)player;
216         char *ret_buf = NULL;
217         char next_uri[MUSE_MSG_MAX_LENGTH] = { 0, };
218
219         LOGD("ENTER");
220
221         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
222         if (ret == PLAYER_ERROR_NONE) {
223                 player_msg_get_string(next_uri, ret_buf);
224
225                 char dest[MUSE_MSG_MAX_LENGTH] = {0,};
226                 if (storage_get_compat_internal_path(next_uri, sizeof(dest), dest) < 0) {
227                         /* cannot convert path. use the original one. */
228                         *uri = strndup(next_uri, MUSE_MSG_MAX_LENGTH);
229                 } else {
230                         /* need to use converted path. */
231                         LOGD("Converted path : %s -> %s", next_uri, dest);
232                         *uri = strndup(dest, MUSE_MSG_MAX_LENGTH);
233                 }
234         }
235         g_free(ret_buf);
236         return ret;
237 }
238
239 int player_set_gapless(player_h player, bool gapless)
240 {
241         PLAYER_INSTANCE_CHECK(player);
242         int ret = PLAYER_ERROR_NONE;
243         muse_player_api_e api = MUSE_PLAYER_API_SET_GAPLESS;
244         player_cli_s *pc = (player_cli_s *)player;
245         char *ret_buf = NULL;
246
247         LOGD("ENTER");
248
249         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "gapless", gapless);
250         g_free(ret_buf);
251         return ret;
252 }
253
254 int player_is_gapless(player_h player, bool *gapless)
255 {
256         PLAYER_INSTANCE_CHECK(player);
257         PLAYER_NULL_ARG_CHECK(gapless);
258         int ret = PLAYER_ERROR_NONE;
259         muse_player_api_e api = MUSE_PLAYER_API_IS_GAPLESS;
260         player_cli_s *pc = (player_cli_s *)player;
261         char *ret_buf = NULL;
262         int value = 0;
263
264         LOGD("ENTER");
265
266         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
267         if (ret == PLAYER_ERROR_NONE) {
268                 player_msg_get(value, ret_buf);
269                 *gapless = value;
270         }
271         g_free(ret_buf);
272         return ret;
273 }
274
275 int player_enable_tsurf_pool(player_h player, bool enable)
276 {
277         PLAYER_INSTANCE_CHECK(player);
278         int ret = PLAYER_ERROR_NONE;
279         player_cli_s *pc = (player_cli_s *)player;
280
281         LOGD("ENTER enable:%d", enable);
282
283         if (pc && pc->cb_info) {
284                 pc->cb_info->use_tsurf_pool = enable;
285         } else {
286                 LOGE("failed to enable the tbm surf pool");
287                 ret = PLAYER_ERROR_INVALID_OPERATION;
288         }
289
290         return ret;
291 }
292
293 int player_is_enabled_tsurf_pool(player_h player, bool *enabled)
294 {
295         PLAYER_INSTANCE_CHECK(player);
296         PLAYER_NULL_ARG_CHECK(enabled);
297         int ret = PLAYER_ERROR_NONE;
298         player_cli_s *pc = (player_cli_s *)player;
299
300         LOGD("ENTER");
301         if (pc && pc->cb_info) {
302                 *enabled = pc->cb_info->use_tsurf_pool;
303         } else {
304                 LOGE("failed to get the tbm surf pool state");
305                 ret = PLAYER_ERROR_INVALID_OPERATION;
306         }
307
308         return ret;
309 }
310
311 int player_get_media_packet_video_frame_pool_size(player_h player, int *size)
312 {
313         PLAYER_INSTANCE_CHECK(player);
314         PLAYER_NULL_ARG_CHECK(size);
315
316         int ret = PLAYER_ERROR_NONE;
317         muse_player_api_e api = MUSE_PLAYER_API_GET_MEDIA_PACKET_VIDEO_FRAME_POOL_SIZE;
318         player_cli_s *pc = (player_cli_s *)player;
319         char *ret_buf = NULL;
320         int value = 0;
321
322         LOGD("ENTER");
323
324         PLAYER_SEND_MSG(api, pc, ret_buf, ret);
325         if (ret == PLAYER_ERROR_NONE) {
326                 player_msg_get(value, ret_buf);
327                 *size = value;
328                 pc->cb_info->video_frame_pool_size = value;
329                 LOGD("packet pool size : %d", *size);
330         }
331         g_free(ret_buf);
332         return ret;
333 }
334
335 int player_enable_media_packet_video_frame_decoded_cb(player_h player, bool enable)
336 {
337         PLAYER_INSTANCE_CHECK(player);
338         int ret = PLAYER_ERROR_NONE;
339         muse_player_api_e api = MUSE_PLAYER_API_ENABLE_MEDIA_PACKET_VIDEO_FRAME_DECODED_CB;
340         player_cli_s *pc = (player_cli_s *)player;
341         char *ret_buf = NULL;
342
343         LOGD("ENTER %d", enable);
344
345         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "enable", enable);
346         g_free(ret_buf);
347         return ret;
348 }
349
350 int player_set_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e codec_type)
351 {
352         PLAYER_INSTANCE_CHECK(player);
353         PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
354
355         int ret = PLAYER_ERROR_NONE;
356         muse_player_api_e api = MUSE_PLAYER_API_SET_CODEC_TYPE;
357         player_cli_s *pc = (player_cli_s *)player;
358         char *ret_buf = NULL;
359
360         LOGD("ENTER stream: %d, codec: %d", stream_type, codec_type);
361
362         PLAYER_SEND_MSG(api, pc, ret_buf, ret,
363                                         MUSE_TYPE_INT, "stream_type", stream_type,
364                                         MUSE_TYPE_INT, "codec_type", codec_type);
365
366         g_free(ret_buf);
367         LOGD("LEAVE");
368         return ret;
369 }
370
371 int player_get_codec_type(player_h player, player_stream_type_e stream_type, player_codec_type_e *pcodec_type)
372 {
373         PLAYER_INSTANCE_CHECK(player);
374         PLAYER_NULL_ARG_CHECK(pcodec_type);
375         PLAYER_CHECK_CONDITION(stream_type == PLAYER_STREAM_TYPE_AUDIO || stream_type == PLAYER_STREAM_TYPE_VIDEO, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
376
377         int ret = PLAYER_ERROR_NONE;
378         muse_player_api_e api = MUSE_PLAYER_API_GET_CODEC_TYPE;
379         player_cli_s *pc = (player_cli_s *)player;
380         char *ret_buf = NULL;
381         int codec_type = 0;
382
383         LOGD("ENTER stream_type: %d", stream_type);
384
385         PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "stream_type", stream_type);
386         if (ret == PLAYER_ERROR_NONE) {
387                 player_msg_get(codec_type, ret_buf);
388                 *pcodec_type = codec_type;
389         }
390
391         g_free(ret_buf);
392         LOGD("LEAVE");
393         return ret;
394 }