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