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