[0.2.98] avoid duplicated player releasement
[platform/core/multimedia/mmsvc-player.git] / legacy / src / legacy_player.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 <inttypes.h>
21 #include <mm.h>
22 #include <mm_player.h>
23 #include <mm_player_audioeffect.h>
24 #include <mm_player_internal.h>
25 #include <mm_types.h>
26 #include <sound_manager.h>
27 #include <sound_manager_internal.h>
28 #include <dlog.h>
29 #include "muse_player.h"
30 #include "legacy_player.h"
31 #include "legacy_player_private.h"
32
33 #define __RELEASEIF_PREPARE_THREAD(thread_id) \
34         do { \
35                 if (thread_id) { \
36                         pthread_join(thread_id, NULL); \
37                         thread_id = 0; \
38                         LOGI("prepare thread released\n"); \
39                 } \
40         } while (0)
41
42 #define __RELEASEIF_MESSAGE_THREAD(thread_id) \
43         do { \
44                 if (thread_id) { \
45                         pthread_join(thread_id, NULL); \
46                         thread_id = 0; \
47                         LOGI("message thread released\n"); \
48                 } \
49         } while (0)
50
51 #define __GET_MESSAGE(handle) \
52         do { \
53                 if (handle && handle->message_queue) { \
54                         g_mutex_lock(&handle->message_queue_lock); \
55                         if (g_queue_is_empty(handle->message_queue)) { \
56                                 g_cond_wait(&handle->message_queue_cond, &handle->message_queue_lock); \
57                         } \
58                         handle->current_message = (int)(intptr_t)g_queue_pop_head(handle->message_queue); \
59                         g_mutex_unlock(&handle->message_queue_lock); \
60                         LOGI("Retrieved  message [%d] from queue", handle->current_message); \
61                 } else { \
62                         LOGI("Failed to retrieve message from queue"); \
63                         handle->current_message = PLAYER_MESSAGE_NONE; \
64                 } \
65         } while (0)
66
67 #define __ADD_MESSAGE(handle, message) \
68         do { \
69                 if (handle && handle->message_queue) { \
70                         g_mutex_lock(&handle->message_queue_lock); \
71                         if (message == PLAYER_MESSAGE_LOOP_EXIT) \
72                                 g_queue_clear(handle->message_queue); \
73                         g_queue_push_tail(handle->message_queue, (gpointer)message); \
74                         g_cond_signal(&handle->message_queue_cond); \
75                         g_mutex_unlock(&handle->message_queue_lock); \
76                         LOGI("Adding message [%d] to queue", message); \
77                 } else { \
78                         LOGI("Failed to add message [%d] to queue", message); \
79                 } \
80         } while (0)
81
82 /*
83  * Internal Implementation
84  */
85 int __player_convert_error_code(int code, char *func_name)
86 {
87         int ret = PLAYER_ERROR_INVALID_OPERATION;
88         char *msg = "PLAYER_ERROR_INVALID_OPERATION";
89         switch (code) {
90         case MM_ERROR_NONE:
91                 ret = PLAYER_ERROR_NONE;
92                 msg = "PLAYER_ERROR_NONE";
93                 break;
94         case MM_ERROR_PLAYER_AUDIO_CODEC_NOT_FOUND:
95                 ret = PLAYER_ERROR_NOT_SUPPORTED_AUDIO_CODEC;
96                 msg = "PLAYER_ERROR_NOT_SUPPORTED_AUDIO_CODEC";
97                 break;
98         case MM_ERROR_PLAYER_VIDEO_CODEC_NOT_FOUND:
99                 ret = PLAYER_ERROR_NOT_SUPPORTED_VIDEO_CODEC;
100                 msg = "PLAYER_ERROR_NOT_SUPPORTED_VIDEO_CODEC";
101                 break;
102         case MM_ERROR_PLAYER_NOT_SUPPORTED_SUBTITLE:
103                 ret = PLAYER_ERROR_NOT_SUPPORTED_SUBTITLE;
104                 msg = "PLAYER_ERROR_NOT_SUPPORTED_SUBTITLE";
105                 break;
106         case MM_ERROR_INVALID_ARGUMENT:
107         case MM_ERROR_COMMON_INVALID_ARGUMENT:
108                 ret = PLAYER_ERROR_INVALID_PARAMETER;
109                 msg = "PLAYER_ERROR_INVALID_PARAMETER";
110                 break;
111         case MM_ERROR_PLAYER_CODEC_NOT_FOUND:
112         case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_AUDIO:
113         case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_VIDEO:
114         case MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_MEDIA_TYPE:
115         case MM_ERROR_PLAYER_NOT_SUPPORTED_FORMAT:
116                 ret = PLAYER_ERROR_NOT_SUPPORTED_FILE;
117                 msg = "PLAYER_ERROR_NOT_SUPPORTED_FILE";
118                 break;
119         case MM_ERROR_PLAYER_INVALID_STATE:
120         case MM_ERROR_PLAYER_NOT_INITIALIZED:
121                 ret = PLAYER_ERROR_INVALID_STATE;
122                 msg = "PLAYER_ERROR_INVALID_STATE";
123                 break;
124         case MM_ERROR_PLAYER_INTERNAL:
125         case MM_ERROR_PLAYER_INVALID_STREAM:
126         case MM_ERROR_PLAYER_STREAMING_FAIL:
127         case MM_ERROR_PLAYER_NO_OP:
128                 ret = PLAYER_ERROR_INVALID_OPERATION;
129                 msg = "PLAYER_ERROR_INVALID_OPERATION";
130                 break;
131         case MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS:
132         case MM_ERROR_NOT_SUPPORT_API:
133         case MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER:
134                 ret = PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE;
135                 msg = "PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE";
136                 break;
137         case MM_ERROR_PLAYER_NO_FREE_SPACE:
138                 ret = PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE;
139                 msg = "PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE";
140                 break;
141         case MM_ERROR_PLAYER_FILE_NOT_FOUND:
142                 ret = PLAYER_ERROR_NO_SUCH_FILE;
143                 msg = "PLAYER_ERROR_NO_SUCH_FILE";
144                 break;
145         case MM_ERROR_PLAYER_SEEK:
146                 ret = PLAYER_ERROR_SEEK_FAILED;
147                 msg = "PLAYER_ERROR_SEEK_FAILED";
148                 break;
149         case MM_ERROR_PLAYER_INVALID_URI:
150         case MM_ERROR_PLAYER_STREAMING_INVALID_URL:
151                 ret = PLAYER_ERROR_INVALID_URI;
152                 msg = "PLAYER_ERROR_INVALID_URI";
153                 break;
154         case MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL:
155         case MM_ERROR_PLAYER_STREAMING_DNS_FAIL:
156         case MM_ERROR_PLAYER_STREAMING_SERVER_DISCONNECTED:
157         case MM_ERROR_PLAYER_STREAMING_INVALID_PROTOCOL:
158         case MM_ERROR_PLAYER_STREAMING_UNEXPECTED_MSG:
159         case MM_ERROR_PLAYER_STREAMING_OUT_OF_MEMORIES:
160         case MM_ERROR_PLAYER_STREAMING_RTSP_TIMEOUT:
161         case MM_ERROR_PLAYER_STREAMING_BAD_REQUEST:
162         case MM_ERROR_PLAYER_STREAMING_NOT_AUTHORIZED:
163         case MM_ERROR_PLAYER_STREAMING_PAYMENT_REQUIRED:
164         case MM_ERROR_PLAYER_STREAMING_FORBIDDEN:
165         case MM_ERROR_PLAYER_STREAMING_CONTENT_NOT_FOUND:
166         case MM_ERROR_PLAYER_STREAMING_METHOD_NOT_ALLOWED:
167         case MM_ERROR_PLAYER_STREAMING_NOT_ACCEPTABLE:
168         case MM_ERROR_PLAYER_STREAMING_PROXY_AUTHENTICATION_REQUIRED:
169         case MM_ERROR_PLAYER_STREAMING_SERVER_TIMEOUT:
170         case MM_ERROR_PLAYER_STREAMING_GONE:
171         case MM_ERROR_PLAYER_STREAMING_LENGTH_REQUIRED:
172         case MM_ERROR_PLAYER_STREAMING_PRECONDITION_FAILED:
173         case MM_ERROR_PLAYER_STREAMING_REQUEST_ENTITY_TOO_LARGE:
174         case MM_ERROR_PLAYER_STREAMING_REQUEST_URI_TOO_LARGE:
175         case MM_ERROR_PLAYER_STREAMING_PARAMETER_NOT_UNDERSTOOD:
176         case MM_ERROR_PLAYER_STREAMING_CONFERENCE_NOT_FOUND:
177         case MM_ERROR_PLAYER_STREAMING_NOT_ENOUGH_BANDWIDTH:
178         case MM_ERROR_PLAYER_STREAMING_NO_SESSION_ID:
179         case MM_ERROR_PLAYER_STREAMING_METHOD_NOT_VALID_IN_THIS_STATE:
180         case MM_ERROR_PLAYER_STREAMING_HEADER_FIELD_NOT_VALID_FOR_SOURCE:
181         case MM_ERROR_PLAYER_STREAMING_INVALID_RANGE:
182         case MM_ERROR_PLAYER_STREAMING_PARAMETER_IS_READONLY:
183         case MM_ERROR_PLAYER_STREAMING_AGGREGATE_OP_NOT_ALLOWED:
184         case MM_ERROR_PLAYER_STREAMING_ONLY_AGGREGATE_OP_ALLOWED:
185         case MM_ERROR_PLAYER_STREAMING_BAD_TRANSPORT:
186         case MM_ERROR_PLAYER_STREAMING_DESTINATION_UNREACHABLE:
187         case MM_ERROR_PLAYER_STREAMING_INTERNAL_SERVER_ERROR:
188         case MM_ERROR_PLAYER_STREAMING_NOT_IMPLEMENTED:
189         case MM_ERROR_PLAYER_STREAMING_BAD_GATEWAY:
190         case MM_ERROR_PLAYER_STREAMING_SERVICE_UNAVAILABLE:
191         case MM_ERROR_PLAYER_STREAMING_GATEWAY_TIME_OUT:
192         case MM_ERROR_PLAYER_STREAMING_OPTION_NOT_SUPPORTED:
193                 ret = PLAYER_ERROR_CONNECTION_FAILED;
194                 msg = "PLAYER_ERROR_CONNECTION_FAILED";
195                 break;
196         case MM_ERROR_POLICY_BLOCKED:
197         case MM_ERROR_POLICY_INTERRUPTED:
198         case MM_ERROR_POLICY_INTERNAL:
199         case MM_ERROR_POLICY_DUPLICATED:
200                 ret = PLAYER_ERROR_SOUND_POLICY;
201                 msg = "PLAYER_ERROR_SOUND_POLICY";
202                 break;
203         case MM_ERROR_PLAYER_DRM_EXPIRED:
204                 ret = PLAYER_ERROR_DRM_EXPIRED;
205                 msg = "PLAYER_ERROR_DRM_EXPIRED";
206                 break;
207         case MM_ERROR_PLAYER_DRM_NOT_AUTHORIZED:
208         case MM_ERROR_PLAYER_DRM_NO_LICENSE:
209                 ret = PLAYER_ERROR_DRM_NO_LICENSE;
210                 msg = "PLAYER_ERROR_DRM_NO_LICENSE";
211                 break;
212         case MM_ERROR_PLAYER_DRM_FUTURE_USE:
213                 ret = PLAYER_ERROR_DRM_FUTURE_USE;
214                 msg = "PLAYER_ERROR_DRM_FUTURE_USE";
215                 break;
216         case MM_ERROR_PLAYER_DRM_OUTPUT_PROTECTION:
217                 ret = PLAYER_ERROR_DRM_NOT_PERMITTED;
218                 msg = "PLAYER_ERROR_DRM_NOT_PERMITTED";
219                 break;
220         case MM_ERROR_PLAYER_RESOURCE_LIMIT:
221                 ret = PLAYER_ERROR_RESOURCE_LIMIT;
222                 msg = "PLAYER_ERROR_RESOURCE_LIMIT";
223                 break;
224         case MM_ERROR_PLAYER_PERMISSION_DENIED:
225                 ret = PLAYER_ERROR_PERMISSION_DENIED;
226                 msg = "PLAYER_ERROR_PERMISSION_DENIED";
227                 break;
228         case MM_ERROR_PLAYER_BUFFER_SPACE:
229                 ret = PLAYER_ERROR_BUFFER_SPACE;
230                 msg = "PLAYER_ERROR_BUFFER_SPACE";
231                 break;
232         default:
233                 break;
234         }
235         LOGE("[%s] %s(0x%08x) : core fw error(0x%x)", func_name, msg, ret, code);
236         return ret;
237 }
238
239 static void __player_update_state(player_s *handle, player_internal_state_e state)
240 {
241         switch (state) {
242         case PLAYER_INTERNAL_STATE_NONE:
243                 handle->state = PLAYER_STATE_NONE;
244                 handle->internal_state = PLAYER_INTERNAL_STATE_IDLE;
245         break;
246         case PLAYER_INTERNAL_STATE_IDLE:
247                 handle->state = PLAYER_STATE_IDLE;
248                 handle->internal_state = PLAYER_INTERNAL_STATE_IDLE;
249         break;
250         case PLAYER_INTERNAL_STATE_PRE_READY:
251                 handle->internal_state = PLAYER_INTERNAL_STATE_PRE_READY;
252         break;
253         case PLAYER_INTERNAL_STATE_READY:
254                 handle->state = PLAYER_STATE_READY;
255                 handle->internal_state = PLAYER_INTERNAL_STATE_READY;
256         break;
257         case PLAYER_INTERNAL_STATE_PLAYING:
258                 handle->internal_state = PLAYER_INTERNAL_STATE_PLAYING;
259                 handle->state = PLAYER_STATE_PLAYING;
260         break;
261         case PLAYER_INTERNAL_STATE_PAUSED:
262                 handle->internal_state = PLAYER_INTERNAL_STATE_PAUSED;
263                 handle->state = PLAYER_STATE_PAUSED;
264         break;
265         case PLAYER_INTERNAL_STATE_STOPPED:
266                 handle->state = PLAYER_STATE_READY;
267                 handle->internal_state = PLAYER_INTERNAL_STATE_STOPPED;
268         break;
269         default:
270         break;
271         }
272
273         LOGD("player state is updated to 0x%X, 0x%X", handle->state, handle->internal_state);
274         return;
275 }
276
277 bool __player_state_validate(player_s *handle, player_state_e threshold)
278 {
279         if (handle->state < threshold)
280                 return false;
281
282         return true;
283 }
284
285 static int __set_callback(muse_player_event_e type, player_h player, void *callback, void *user_data)
286 {
287         player_s *handle = (player_s *)player;
288         PLAYER_INSTANCE_CHECK(player);
289         PLAYER_NULL_ARG_CHECK(callback);
290
291         handle->user_cb[type] = callback;
292         handle->user_data[type] = user_data;
293         LOGI("[%s] Event type : %d ", __FUNCTION__, type);
294         return PLAYER_ERROR_NONE;
295 }
296
297 static int __unset_callback(muse_player_event_e type, player_h player)
298 {
299         player_s *handle = (player_s *)player;
300         PLAYER_INSTANCE_CHECK(player);
301         handle->user_cb[type] = NULL;
302         handle->user_data[type] = NULL;
303         LOGI("[%s] Event type : %d ", __FUNCTION__, type);
304         return PLAYER_ERROR_NONE;
305 }
306
307 static void __message_cb_loop(void *data)
308 {
309         bool running = true;
310         player_s *handle = (player_s *)data;
311         if (!handle) {
312                 LOGE("null handle in __message_cb_loop");
313                 return;
314         }
315         do {
316                 __GET_MESSAGE(handle);
317                 switch (handle->current_message) {
318                 case PLAYER_MESSAGE_NONE:
319                         {
320                                 LOGW("PLAYER_MESSAGE_NONE");
321                                 running = false;
322                         }
323                         break;
324                 case PLAYER_MESSAGE_PREPARED:
325                         {
326                                 LOGW("PLAYER_MESSAGE_PREPARED");
327
328                                 LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
329                                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
330                                         __player_update_state(handle, PLAYER_INTERNAL_STATE_READY);
331                                         ((player_prepared_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
332                                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
333                                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
334                                 } else {
335                                         LOGE("null handle in PLAYER_MESSAGE_PREPARED");
336                                 }
337                                 LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
338                         }
339                         break;
340                 case PLAYER_MESSAGE_ERROR:
341                         {
342                                 LOGW("PLAYER_MESSAGE_ERROR");
343                                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
344                                         ((player_error_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])(handle->error_code, handle->user_data[MUSE_PLAYER_EVENT_TYPE_ERROR]);
345                                 else
346                                         LOGE("null handle in PLAYER_MESSAGE_ERROR");
347                         }
348                         break;
349                 case PLAYER_MESSAGE_SEEK_DONE:
350                         {
351                                 LOGW("PLAYER_MESSAGE_SEEK_DONE");
352                                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
353                                         ((player_seek_completed_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK]);
354                                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
355                                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
356                                 } else {
357                                         LOGE("null handle in PLAYER_MESSAGE_SEEK_DONE");
358                                 }
359                         }
360                         break;
361                 case PLAYER_MESSAGE_EOS:
362                         {
363                                 LOGW("PLAYER_MESSAGE_EOS");
364                                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])
365                                         ((player_completed_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_COMPLETE]);
366                                 else
367                                         LOGE("null handle in PLAYER_MESSAGE_EOS");
368                         }
369                         break;
370 #ifdef TIZEN_FEATURE_EVAS_RENDERER
371                 case PLAYER_MESSAGE_GAPLESS_CONSTRUCTION:
372                         {
373                                 LOGW("PLAYER_MESSAGE_GAPLESS_CONSTRUCTION");
374                                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])
375                                         ((player_retrieve_buffer_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER]);
376                                 else
377                                         LOGE("null handle in PLAYER_MESSAGE_GAPLESS_CONSTRUCTION");
378                         }
379                         break;
380 #endif
381                 case PLAYER_MESSAGE_LOOP_EXIT:
382                         {
383                                 LOGW("PLAYER_MESSAGE_LOOP_EXIT");
384                                 running = false;
385                         }
386                         break;
387                 case PLAYER_MESSAGE_MAX:
388                         {
389                                 LOGW("PLAYER_MESSAGE_MAX");
390                                 running = false;
391                         }
392                         break;
393                 default:
394                         break;
395                 }
396         } while (running);
397         return;
398 }
399
400 static player_state_e __convert_player_state(MMPlayerStateType state)
401 {
402         if (state == MM_PLAYER_STATE_NONE)
403                 return PLAYER_STATE_NONE;
404
405         return state + 1;
406 }
407
408 static int __msg_callback(int message, void *param, void *user_data)
409 {
410         player_s *handle = (player_s *)user_data;
411         MMMessageParamType *msg = (MMMessageParamType *)param;
412         LOGW("[%s] Got message type : 0x%x", __FUNCTION__, message);
413         player_error_e err_code = PLAYER_ERROR_NONE;
414         switch (message) {
415         case MM_MESSAGE_ERROR:  /* 0x01 */
416                 err_code = __player_convert_error_code(msg->code, (char *)__FUNCTION__);
417
418                 LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
419                 if (PLAYER_ERROR_NOT_SUPPORTED_FILE == err_code && handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
420                         LOGW("failed to pause, so prepare cb will be released soon");
421                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
422                         if (handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
423                                 g_free(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
424                                 handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
425                         }
426                 }
427                 LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
428                 break;
429         case MM_MESSAGE_STATE_CHANGED:  /* 0x03 */
430                 LOGI("STATE CHANGED INTERNALLY - from : %d,  to : %d (CAPI State : %d)", msg->state.previous, msg->state.current, handle->state);
431                 if (msg->state.previous == MM_PLAYER_STATE_READY && msg->state.current == MM_PLAYER_STATE_PAUSED) {
432                         LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
433                         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
434                                 /* asyc && prepared cb has been set */
435                                 LOGI("[%s] Prepared! [current state : %d]", __FUNCTION__, handle->state);
436                                 PLAYER_TRACE_ASYNC_END("MM:PLAYER:PREPARE_ASYNC", *(int *)handle);
437                                 __ADD_MESSAGE(handle, PLAYER_MESSAGE_PREPARED);
438                         }
439                         LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
440                 }
441                 break;
442         case MM_MESSAGE_BEGIN_OF_STREAM:        /* 0x104 */
443                 LOGI("[%s] Ready to streaming information (BOS) [current state : %d]", __FUNCTION__, handle->state);
444                 break;
445         case MM_MESSAGE_END_OF_STREAM:  /* 0x105 */
446                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_COMPLETE])
447                         __ADD_MESSAGE(handle, PLAYER_MESSAGE_EOS);
448                 break;
449 #ifdef TIZEN_FEATURE_EVAS_RENDERER
450         case MM_MESSAGE_GAPLESS_CONSTRUCTION:   /* 0x105 */
451                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER])
452                         __ADD_MESSAGE(handle, PLAYER_MESSAGE_GAPLESS_CONSTRUCTION);
453                 break;
454 #endif
455         case MM_MESSAGE_BUFFERING:      /* 0x103 */
456                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_BUFFERING])
457                         ((player_buffering_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_BUFFERING])(msg->connection.buffering, handle->user_data[MUSE_PLAYER_EVENT_TYPE_BUFFERING]);
458                 break;
459         case MM_MESSAGE_STATE_INTERRUPTED:      /* 0x04 */
460                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_INTERRUPT]) {
461                         if (msg->union_type == MM_MSG_UNION_STATE) {
462                                 LOGW("received mm state msg prev:%d, curr:%d", msg->state.previous, msg->state.current);
463                                 handle->state = __convert_player_state(msg->state.current);
464                                 LOGW("player state is changed to %d by resource conflict", handle->state);
465                         }
466                         ((player_interrupted_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_INTERRUPT])(handle->user_data[MUSE_PLAYER_EVENT_TYPE_INTERRUPT]);
467                 }
468                 break;
469         case MM_MESSAGE_CONNECTION_TIMEOUT:     /* 0x102 */
470                 LOGI("[%s] PLAYER_ERROR_CONNECTION_FAILED (0x%08x) : CONNECTION_TIMEOUT", __FUNCTION__, PLAYER_ERROR_CONNECTION_FAILED);
471                 err_code = PLAYER_ERROR_CONNECTION_FAILED;
472                 break;
473         case MM_MESSAGE_UPDATE_SUBTITLE:        /* 0x109 */
474                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SUBTITLE])
475                         ((player_subtitle_updated_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SUBTITLE])(msg->subtitle.duration, (char *)msg->data, handle->user_data[MUSE_PLAYER_EVENT_TYPE_SUBTITLE]);
476                 break;
477         case MM_MESSAGE_VIDEO_NOT_CAPTURED:     /* 0x113 */
478                 LOGI("[%s] PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x)", __FUNCTION__, PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
479                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])
480                         ((player_error_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR])(PLAYER_ERROR_VIDEO_CAPTURE_FAILED, handle->user_data[MUSE_PLAYER_EVENT_TYPE_ERROR]);
481                 break;
482         case MM_MESSAGE_VIDEO_CAPTURED: /* 0x110 */
483         {
484                 MMPlayerVideoCapture *capture = (MMPlayerVideoCapture *)msg->data;
485
486                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
487                         if (!capture || !capture->data) {
488                                 LOGE("PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : Failed to get capture data", PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
489                                 err_code = PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
490                         } else {
491                                 LOGI("captured image ori: %d, width: %d, height: %d, size: %d",
492                                                         capture->orientation, capture->width, capture->height, capture->size);
493
494                                 /* call application callback */
495                                 ((player_video_captured_cb)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE])
496                                                 (capture->data, capture->width, capture->height, capture->size, handle->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE]);
497                         }
498
499                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
500                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
501                 }
502
503                 /* capure->data have to be released to avoid mem leak in all cases. */
504                 if (capture) {
505                         g_free(capture->data);
506                         capture->data = NULL;
507                 }
508                 break;
509         }
510         case MM_MESSAGE_FILE_NOT_SUPPORTED:     /* 0x10f */
511                 LOGI("[%s] PLAYER_ERROR_NOT_SUPPORTED_FILE (0x%08x) : FILE_NOT_SUPPORTED", __FUNCTION__, PLAYER_ERROR_NOT_SUPPORTED_FILE);
512                 err_code = PLAYER_ERROR_NOT_SUPPORTED_FILE;
513                 break;
514         case MM_MESSAGE_FILE_NOT_FOUND: /* 0x110 */
515                 LOGI("[%s] PLAYER_ERROR_NOT_SUPPORTED_FILE (0x%08x) : FILE_NOT_FOUND", __FUNCTION__, PLAYER_ERROR_NOT_SUPPORTED_FILE);
516                 err_code = PLAYER_ERROR_NOT_SUPPORTED_FILE;
517                 break;
518         case MM_MESSAGE_SEEK_COMPLETED: /* 0x114 */
519                 if (handle->display_type != PLAYER_DISPLAY_TYPE_NONE && handle->state == PLAYER_STATE_READY) {
520                         if (handle->is_display_visible) {
521                                 int ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", 1, (char *)NULL);
522                                 if (ret != MM_ERROR_NONE)
523                                         LOGW("[%s] Failed to set display_visible '1' (0x%x)", __FUNCTION__, ret);
524                         }
525                 }
526                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
527                         __ADD_MESSAGE(handle, PLAYER_MESSAGE_SEEK_DONE);
528                 }
529                 break;
530         case MM_MESSAGE_PLAY_POSITION:
531                 LOGI("MM_MESSAGE_PLAY_POSITION (%"PRId64" ns)", msg->time.elapsed);
532                 handle->last_play_position = msg->time.elapsed;
533                 break;
534         case MM_MESSAGE_UNKNOWN:        /* 0x00 */
535         case MM_MESSAGE_WARNING:        /* 0x02 */
536         case MM_MESSAGE_CONNECTING:     /* 0x100 */
537         case MM_MESSAGE_CONNECTED:      /* 0x101 */
538         case MM_MESSAGE_BLUETOOTH_ON:   /* 0x106 */
539         case MM_MESSAGE_BLUETOOTH_OFF:  /* 0x107 */
540         case MM_MESSAGE_RTP_SENDER_REPORT:      /* 0x10a */
541         case MM_MESSAGE_RTP_RECEIVER_REPORT:    /* 0x10b */
542         case MM_MESSAGE_RTP_SESSION_STATUS:     /* 0x10c */
543         case MM_MESSAGE_SENDER_STATE:   /* 0x10d */
544         case MM_MESSAGE_RECEIVER_STATE: /* 0x10e */
545         default:
546                 break;
547         }
548
549         if (err_code != PLAYER_ERROR_NONE && handle->user_cb[MUSE_PLAYER_EVENT_TYPE_ERROR]) {
550                 handle->error_code = err_code;
551                 __ADD_MESSAGE(handle, PLAYER_MESSAGE_ERROR);
552         }
553         LOGW("[%s] End", __FUNCTION__);
554         return 1;
555 }
556
557 static MMDisplaySurfaceType __player_convert_display_type(player_display_type_e type)
558 {
559         switch (type) {
560         case PLAYER_DISPLAY_TYPE_OVERLAY:
561                 return MM_DISPLAY_SURFACE_OVERLAY;
562         case PLAYER_DISPLAY_TYPE_EVAS: /* fall through ifndef TIZEN_FEATURE_EVAS_RENDERER */
563 #ifdef TIZEN_FEATURE_EVAS_RENDERER
564                 return MM_DISPLAY_SURFACE_REMOTE;
565 #endif
566         case PLAYER_DISPLAY_TYPE_NONE:  /* fall through */
567         default:
568                 return MM_DISPLAY_SURFACE_NULL;
569         }
570 }
571
572 bool _check_enabled_user_cb_lock(int type)
573 {
574         switch (type) {
575         case MUSE_PLAYER_EVENT_TYPE_PREPARE:          /* fall through */
576         case MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO:    /* fall through */
577         case MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO:    /* fall through */
578                 return true;
579         default:
580                 return false;
581         }
582 }
583
584 /*
585  * Public Implementation
586  */
587
588 int legacy_player_create(player_h *player)
589 {
590         player_s *handle;
591         int ret = MM_ERROR_NONE;
592         PLAYER_INSTANCE_CHECK(player);
593         PLAYER_TRACE_BEGIN("MM:PLAYER:CREATE");
594         handle = g_try_new0(player_s, 1);
595         if (!handle) {
596                 LOGE("[%s] PLAYER_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, PLAYER_ERROR_OUT_OF_MEMORY);
597                 return PLAYER_ERROR_OUT_OF_MEMORY;
598         }
599         ret = mm_player_create(&handle->mm_handle);
600         if (ret != MM_ERROR_NONE) {
601                 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, PLAYER_ERROR_INVALID_OPERATION);
602                 __player_update_state(handle, PLAYER_INTERNAL_STATE_NONE);
603                 g_free(handle);
604                 handle = NULL;
605                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
606         }
607
608         muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PREPARE;
609
610         *player = (player_h)handle;
611         __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
612         handle->display_type = PLAYER_DISPLAY_TYPE_NONE;
613         handle->is_display_visible = true;
614         handle->is_media_stream = false;
615
616         for (type = MUSE_PLAYER_EVENT_TYPE_PREPARE; type < MUSE_PLAYER_EVENT_TYPE_NUM; type++) {
617                 if (_check_enabled_user_cb_lock(type))
618                         g_mutex_init(&handle->user_cb_lock[type]);
619         }
620
621         handle->message_queue = g_queue_new();
622         g_mutex_init(&handle->message_queue_lock);
623         g_cond_init(&handle->message_queue_cond);
624         ret = pthread_create(&handle->message_thread, NULL, (void *)__message_cb_loop, (void *)handle);
625         if (ret != 0) {
626                 LOGE("[%s] failed to create message thread ret = %d", __FUNCTION__, ret);
627                 return PLAYER_ERROR_OUT_OF_MEMORY;
628         }
629
630         LOGI("[%s] new handle : %p", __FUNCTION__, *player);
631         PLAYER_TRACE_END();
632         return PLAYER_ERROR_NONE;
633 }
634
635 int legacy_player_destroy(player_h player)
636 {
637         player_s *handle = (player_s *)player;
638         int ret = MM_ERROR_NONE;
639         LOGI("[%s] Start, handle to destroy : %p", __FUNCTION__, player);
640         PLAYER_TRACE_BEGIN("MM:PLAYER:DESTROY");
641         PLAYER_INSTANCE_CHECK(player);
642
643         handle->is_shutdown = true;
644
645         __ADD_MESSAGE(handle, PLAYER_MESSAGE_LOOP_EXIT);
646
647         LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
648         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
649                 handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
650                 g_free(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
651                 handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
652         }
653         LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
654
655         /* stop the pause state trasition to release prepare thread */
656         if (handle->internal_state == PLAYER_INTERNAL_STATE_PRE_READY)
657                 mm_player_abort_pause(handle->mm_handle);
658
659         __RELEASEIF_PREPARE_THREAD(handle->prepare_async_thread);
660         __RELEASEIF_MESSAGE_THREAD(handle->message_thread);
661
662         ret = mm_player_destroy(handle->mm_handle);
663         if (ret != MM_ERROR_NONE) {
664                 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x)", __FUNCTION__, PLAYER_ERROR_INVALID_OPERATION);
665                 return PLAYER_ERROR_INVALID_OPERATION;
666         }
667         LOGI("[%s] Done mm_player_destroy", __FUNCTION__);
668
669         muse_player_event_e type = MUSE_PLAYER_EVENT_TYPE_PREPARE;
670
671         __player_update_state(handle, PLAYER_INTERNAL_STATE_NONE);
672
673         for (type = MUSE_PLAYER_EVENT_TYPE_PREPARE; type < MUSE_PLAYER_EVENT_TYPE_NUM; type++) {
674                 if (_check_enabled_user_cb_lock(type))
675                         g_mutex_clear(&handle->user_cb_lock[type]);
676         }
677
678         if (handle->message_queue) {
679                 g_queue_free(handle->message_queue);
680                 handle->message_queue = NULL;
681         }
682
683         g_cond_broadcast(&handle->message_queue_cond);
684         g_mutex_clear(&handle->message_queue_lock);
685         g_cond_clear(&handle->message_queue_cond);
686
687         g_free(handle);
688         handle = NULL;
689         LOGI("[%s] End", __FUNCTION__);
690         PLAYER_TRACE_END();
691         return PLAYER_ERROR_NONE;
692 }
693
694 static void *__prepare_async_thread_func(void *data)
695 {
696         player_s *handle = data;
697         int ret = MM_ERROR_NONE;
698         LPLAYER_FENTER();
699
700         ret = mm_player_pause(handle->mm_handle);
701         if (ret != MM_ERROR_NONE) {
702                 LOGE("Failed to pause - core fw error(0x%x)", ret);
703                 __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
704
705                 if (handle->error_code == PLAYER_ERROR_NONE) {
706                         /* if there is no received error msg, it has to be posted here. */
707                         MMMessageParamType msg_param;
708                         msg_param.code = ret;
709                         __msg_callback(MM_MESSAGE_ERROR, (void *)&msg_param, (void *)handle);
710                 }
711
712                 if (!handle->is_shutdown) {
713                         ret = mm_player_unrealize(handle->mm_handle);
714                         if (ret != MM_ERROR_NONE)
715                                 LOGE("Failed to unrealize - 0x%x", ret);
716                 }
717         }
718
719         LPLAYER_FLEAVE();
720         return NULL;
721 }
722
723 int legacy_player_prepare_async(player_h player, player_prepared_cb callback, void *user_data)
724 {
725         player_s *handle = (player_s *)player;
726         int ret = MM_ERROR_NONE;
727         int visible = 0;
728         int value = 0;
729
730         LOGI("[%s] Start", __FUNCTION__);
731         PLAYER_INSTANCE_CHECK(player);
732         PLAYER_TRACE_ASYNC_BEGIN("MM:PLAYER:PREPARE_ASYNC", *(int *)handle);
733         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
734
735         __player_update_state(handle, PLAYER_INTERNAL_STATE_PRE_READY);
736         LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
737
738         handle->last_play_position = 0;
739         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
740                 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION (0x%08x) : preparing... we can't do any more ", __FUNCTION__, PLAYER_ERROR_INVALID_OPERATION);
741                 LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
742                 __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
743                 return PLAYER_ERROR_INVALID_OPERATION;
744         }
745
746         /* LOGI("[%s] Event type : %d ",__FUNCTION__, MUSE_PLAYER_EVENT_TYPE_PREPARE); */
747         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = callback;
748         handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = user_data;
749
750         LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
751
752         ret = mm_player_set_message_callback(handle->mm_handle, __msg_callback, (void *)handle);
753         if (ret != MM_ERROR_NONE)
754                 LOGW("[%s] Failed to set message callback function (0x%x)", __FUNCTION__, ret);
755
756         if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE) {
757                 ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_surface_type", MM_DISPLAY_SURFACE_NULL, (char *)NULL);
758                 if (ret != MM_ERROR_NONE)
759                         LOGW("[%s] Failed to set display surface type 'MM_DISPLAY_SURFACE_NULL' (0x%x)", __FUNCTION__, ret);
760         } else {
761
762                 /* FIXME : new funct path is needed to update video instead of set attr again */
763                 ret = mm_player_get_attribute(handle->mm_handle, NULL, "display_visible", &visible, (char *)NULL);
764                 if (ret != MM_ERROR_NONE) goto ERROR;
765
766                 if (!visible)
767                         value = FALSE;
768                 else
769                         value = TRUE;
770
771                 ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", value, (char *)NULL);
772                 if (ret != MM_ERROR_NONE) goto ERROR;
773         }
774
775         ret = mm_player_realize(handle->mm_handle);
776         if (ret != MM_ERROR_NONE) {
777                 LOGE("[%s] Failed to realize - 0x%x", __FUNCTION__, ret);
778                 goto ERROR;
779         }
780
781         ret = pthread_create(&handle->prepare_async_thread, NULL, (void *)__prepare_async_thread_func, (void *)handle);
782
783         if (ret != 0) {
784                 LOGE("[%s] failed to create thread ret = %d", __FUNCTION__, ret);
785                 LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
786                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
787                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
788                         /* user_data will be free at player_disp_prepare_async() */
789                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
790                 }
791                 LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
792                 __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
793                 return PLAYER_ERROR_OUT_OF_MEMORY;
794         }
795
796         LOGI("[%s] End", __FUNCTION__);
797         return PLAYER_ERROR_NONE;
798
799 ERROR:
800         LOGW("prepare cb is released");
801         LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
802         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
803                 handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
804                 /* user_data will be free at player_disp_prepare_async() */
805                 handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
806         }
807         LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
808         __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
809
810         LOGE("LEAVE mm_err:0x%X", ret);
811         return __player_convert_error_code(ret, (char *)__FUNCTION__);
812 }
813
814 int legacy_player_prepare(player_h player)
815 {
816         int ret = MM_ERROR_NONE;
817         int visible = 0;
818         player_s *handle = (player_s *)player;
819
820         LOGI("[%s] Start", __FUNCTION__);
821         PLAYER_TRACE_BEGIN("MM:PLAYER:PREPARE");
822         PLAYER_INSTANCE_CHECK(player);
823         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
824         __player_update_state(handle, PLAYER_INTERNAL_STATE_PRE_READY);
825
826         handle->last_play_position = 0;
827         ret = mm_player_set_message_callback(handle->mm_handle, __msg_callback, (void *)handle);
828         if (ret != MM_ERROR_NONE)
829                 LOGW("[%s] Failed to set message callback function (0x%x)", __FUNCTION__, ret);
830
831         if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE) {
832                 ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_surface_type", MM_DISPLAY_SURFACE_NULL, (char *)NULL);
833                 if (ret != MM_ERROR_NONE)
834                         LOGW("[%s] Failed to set display surface type 'MM_DISPLAY_SURFACE_NULL' (0x%x)", __FUNCTION__, ret);
835         } else {
836                 ret = mm_player_get_attribute(handle->mm_handle, NULL, "display_visible", &visible, (char *)NULL);
837                 if (ret != MM_ERROR_NONE) {
838                         __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
839                         return __player_convert_error_code(ret, (char *)__FUNCTION__);
840                 }
841
842                 ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", visible, (char *)NULL);
843                 if (ret != MM_ERROR_NONE)
844                         LOGW("[%s] Failed to set display display_visible '%d' (0x%x)", __FUNCTION__, visible, ret);
845         }
846
847         ret = mm_player_realize(handle->mm_handle);
848         if (ret != MM_ERROR_NONE) {
849                 LOGE("[%s] Failed to realize - 0x%x", __FUNCTION__, ret);
850                 __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
851                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
852         }
853
854         ret = mm_player_pause(handle->mm_handle);
855         if (ret != MM_ERROR_NONE) {
856                 int uret;
857                 uret = mm_player_unrealize(handle->mm_handle);
858                 if (uret != MM_ERROR_NONE)
859                         LOGE("[%s] Failed to unrealize - 0x%x", __FUNCTION__, uret);
860
861                 LOGE("[%s] Failed to pause - 0x%x", __FUNCTION__, ret);
862                 __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
863                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
864         }
865
866         __player_update_state(handle, PLAYER_INTERNAL_STATE_READY);
867         LOGI("[%s] End", __FUNCTION__);
868         PLAYER_TRACE_END();
869         return PLAYER_ERROR_NONE;
870 }
871
872 int legacy_player_unprepare(player_h player)
873 {
874         player_s *handle = (player_s *)player;
875         int ret = MM_ERROR_NONE;
876
877         LPLAYER_FENTER();
878         PLAYER_TRACE_BEGIN("MM:PLAYER:UNPREPARE");
879         PLAYER_INSTANCE_CHECK(player);
880
881         handle->is_shutdown = true;
882
883         /* Initialize the setting regardless of error return */
884         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
885                 handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
886                 handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
887         }
888
889         if (!__player_state_validate(handle, PLAYER_STATE_READY) && !handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
890                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
891                 return PLAYER_ERROR_INVALID_STATE;
892         }
893
894         LEGACY_PLAYER_USER_CB_LOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
895         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE]) {
896                 LOGW("Need to check. prepare cb have to be reset before");
897                 handle->user_cb[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
898                 g_free(handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE]);
899                 handle->user_data[MUSE_PLAYER_EVENT_TYPE_PREPARE] = NULL;
900         }
901         LEGACY_PLAYER_USER_CB_UNLOCK(handle, MUSE_PLAYER_EVENT_TYPE_PREPARE);
902
903         /* stop the pause state trasition to release prepare thread */
904         if (handle->internal_state == PLAYER_INTERNAL_STATE_PRE_READY)
905                 mm_player_abort_pause(handle->mm_handle);
906
907         __RELEASEIF_PREPARE_THREAD(handle->prepare_async_thread);
908
909         ret = mm_player_unrealize(handle->mm_handle);
910         if (ret != MM_ERROR_NONE)
911                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
912
913         __player_update_state(handle, PLAYER_INTERNAL_STATE_IDLE);
914         handle->is_display_visible = true;
915
916         LPLAYER_FLEAVE();
917         PLAYER_TRACE_END();
918         return PLAYER_ERROR_NONE;
919 }
920
921 int legacy_player_set_uri(player_h player, const char *uri)
922 {
923         player_s *handle = (player_s *)player;
924         int ret = MM_ERROR_NONE;
925         PLAYER_INSTANCE_CHECK(player);
926         PLAYER_NULL_ARG_CHECK(uri);
927         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
928
929         handle->is_media_stream = false;
930         ret = mm_player_set_uri(handle->mm_handle, uri);
931         if (ret != MM_ERROR_NONE)
932                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
933
934         return PLAYER_ERROR_NONE;
935 }
936
937 int legacy_player_set_memory_buffer(player_h player, const void *data, int size)
938 {
939         player_s *handle = (player_s *)player;
940         char uri[PATH_MAX];
941         int ret = MM_ERROR_NONE;
942         PLAYER_INSTANCE_CHECK(player);
943         PLAYER_NULL_ARG_CHECK(data);
944         PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
945         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
946
947         handle->is_media_stream = FALSE;
948
949         snprintf(uri, sizeof(uri), "mem:///ext=%s,size=%d", "", size);
950         ret = mm_player_set_attribute(handle->mm_handle, NULL, MM_PLAYER_CONTENT_URI, uri, strlen(uri), MM_PLAYER_MEMORY_SRC, data, size, (char *)NULL);
951         if (ret != MM_ERROR_NONE)
952                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
953
954         return PLAYER_ERROR_NONE;
955 }
956
957 int legacy_player_get_state(player_h player, player_state_e *state)
958 {
959         player_s *handle = (player_s *)player;
960         PLAYER_INSTANCE_CHECK(player);
961         PLAYER_NULL_ARG_CHECK(state);
962         *state = handle->state;
963         return PLAYER_ERROR_NONE;
964 }
965
966 int legacy_player_set_volume(player_h player, float left, float right)
967 {
968         player_s *handle = (player_s *)player;
969         MMPlayerVolumeType vol;
970         int ret = MM_ERROR_NONE;
971         PLAYER_INSTANCE_CHECK(player);
972         PLAYER_CHECK_CONDITION(left >= 0 && left <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
973         PLAYER_CHECK_CONDITION(right >= 0 && right <= 1.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
974
975         vol.level[MM_VOLUME_CHANNEL_LEFT] = left;
976         vol.level[MM_VOLUME_CHANNEL_RIGHT] = right;
977         ret = mm_player_set_volume(handle->mm_handle, &vol);
978         if (ret != MM_ERROR_NONE)
979                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
980
981         return PLAYER_ERROR_NONE;
982 }
983
984 int legacy_player_get_volume(player_h player, float *left, float *right)
985 {
986         player_s *handle = (player_s *)player;
987         MMPlayerVolumeType vol;
988         int ret = MM_ERROR_NONE;
989         PLAYER_INSTANCE_CHECK(player);
990         PLAYER_NULL_ARG_CHECK(left);
991         PLAYER_NULL_ARG_CHECK(right);
992
993         ret = mm_player_get_volume(handle->mm_handle, &vol);
994         if (ret != MM_ERROR_NONE) {
995                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
996         }
997
998         *left = vol.level[MM_VOLUME_CHANNEL_LEFT];
999         *right = vol.level[MM_VOLUME_CHANNEL_RIGHT];
1000         return PLAYER_ERROR_NONE;
1001 }
1002
1003 int legacy_player_set_sound_stream_info(player_h player, sound_stream_info_h stream_info)
1004 {
1005         player_s *handle = (player_s *)player;
1006         int ret = MM_ERROR_NONE;
1007         bool is_available = false;
1008         PLAYER_INSTANCE_CHECK(player);
1009         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
1010
1011         /* check if stream_info is valid */
1012         ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_PLAYER, &is_available);
1013         if (ret != MM_ERROR_NONE)
1014                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1015
1016         if (is_available) {
1017                 char *stream_type = NULL;
1018                 int stream_index = 0;
1019                 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
1020                 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_index);
1021                 if (ret == SOUND_MANAGER_ERROR_NONE)
1022                         ret = mm_player_set_sound_stream_info(handle->mm_handle, stream_type, stream_index);
1023                 else
1024                         ret = MM_ERROR_PLAYER_INTERNAL;
1025         } else {
1026                 ret = MM_ERROR_NOT_SUPPORT_API;
1027         }
1028
1029         if (ret != MM_ERROR_NONE)
1030                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1031
1032         return PLAYER_ERROR_NONE;
1033 }
1034
1035 int legacy_player_set_audio_latency_mode(player_h player, audio_latency_mode_e latency_mode)
1036 {
1037         player_s *handle = (player_s *)player;
1038         int ret = MM_ERROR_NONE;
1039         PLAYER_INSTANCE_CHECK(player);
1040
1041         ret = mm_player_set_attribute(handle->mm_handle, NULL, "sound_latency_mode", latency_mode, (char *)NULL);
1042         if (ret != MM_ERROR_NONE)
1043                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1044
1045         return PLAYER_ERROR_NONE;
1046 }
1047
1048 int legacy_player_get_audio_latency_mode(player_h player, audio_latency_mode_e *latency_mode)
1049 {
1050         player_s *handle = (player_s *)player;
1051         int ret = MM_ERROR_NONE;
1052         PLAYER_INSTANCE_CHECK(player);
1053         PLAYER_NULL_ARG_CHECK(latency_mode);
1054
1055         ret = mm_player_get_attribute(handle->mm_handle, NULL, "sound_latency_mode", latency_mode, (char *)NULL);
1056         if (ret != MM_ERROR_NONE)
1057                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1058
1059         return PLAYER_ERROR_NONE;
1060 }
1061
1062 int legacy_player_start(player_h player)
1063 {
1064         player_s *handle = (player_s *)player;
1065         int ret = MM_ERROR_NONE;
1066         LOGI("[%s] Start", __FUNCTION__);
1067         PLAYER_INSTANCE_CHECK(player);
1068
1069         if (handle->state > PLAYER_STATE_IDLE) {
1070                 if (handle->display_type == PLAYER_DISPLAY_TYPE_OVERLAY && handle->is_display_visible) {
1071                         ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", 1, (char *)NULL);
1072                         if (ret != MM_ERROR_NONE)
1073                                 LOGW("[%s] Failed to set display_visible '1' (0x%x)", __FUNCTION__, ret);
1074                 }
1075                 if (handle->internal_state == PLAYER_INTERNAL_STATE_STOPPED) {
1076                         ret = mm_player_start(handle->mm_handle);
1077                         LOGI("[%s] stop -> start() ", __FUNCTION__);
1078                 } else {
1079                         if (handle->state == PLAYER_STATE_READY)
1080                                 ret = mm_player_start(handle->mm_handle);
1081                         else
1082                                 ret = mm_player_resume(handle->mm_handle);
1083                 }
1084         } else {
1085                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1086                 return PLAYER_ERROR_INVALID_STATE;
1087         }
1088
1089         if (ret != MM_ERROR_NONE)
1090                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1091
1092         __player_update_state(handle, PLAYER_INTERNAL_STATE_PLAYING);
1093         LOGI("[%s] End", __FUNCTION__);
1094         return PLAYER_ERROR_NONE;
1095 }
1096
1097 int legacy_player_stop(player_h player)
1098 {
1099         player_s *handle = (player_s *)player;
1100         int ret = MM_ERROR_NONE;
1101         LOGI("[%s] Start", __FUNCTION__);
1102         PLAYER_INSTANCE_CHECK(player);
1103
1104         if (handle->state == PLAYER_STATE_PLAYING || handle->state == PLAYER_STATE_PAUSED) {
1105                 if (handle->display_type == PLAYER_DISPLAY_TYPE_OVERLAY) {
1106                         ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", 0, (char *)NULL);
1107                         if (ret != MM_ERROR_NONE)
1108                                 LOGW("[%s] Failed to set display_visible '0' (0x%x)", __FUNCTION__, ret);
1109                 }
1110
1111                 ret = mm_player_stop(handle->mm_handle);
1112                 if (ret != MM_ERROR_NONE) {
1113                         return __player_convert_error_code(ret, (char *)__FUNCTION__);
1114                 }
1115
1116                 if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK]) {
1117                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
1118                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
1119                 }
1120
1121                 __player_update_state(handle, PLAYER_INTERNAL_STATE_STOPPED);
1122
1123                 LOGI("[%s] End", __FUNCTION__);
1124                 return PLAYER_ERROR_NONE;
1125         }
1126
1127         LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1128         return PLAYER_ERROR_INVALID_STATE;
1129 }
1130
1131 int legacy_player_pause(player_h player)
1132 {
1133         player_s *handle = (player_s *)player;
1134         int ret = MM_ERROR_NONE;
1135         LOGI("[%s] Start", __FUNCTION__);
1136         PLAYER_INSTANCE_CHECK(player);
1137         PLAYER_STATE_CHECK(handle, PLAYER_STATE_PLAYING);
1138
1139         ret = mm_player_pause(handle->mm_handle);
1140         if (ret != MM_ERROR_NONE)
1141                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1142
1143         __player_update_state(handle, PLAYER_INTERNAL_STATE_PAUSED);
1144         LOGI("[%s] End", __FUNCTION__);
1145         return PLAYER_ERROR_NONE;
1146 }
1147
1148 int legacy_player_set_play_position(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data)
1149 {
1150         player_s *handle = (player_s *)player;
1151         int ret = MM_ERROR_NONE;
1152         int accurated = accurate ? 1 : 0;
1153         PLAYER_INSTANCE_CHECK(player);
1154         PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1155
1156         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1157                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1158                 return PLAYER_ERROR_INVALID_STATE;
1159         }
1160
1161         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] && !handle->is_media_stream) {
1162                 LOGE("[%s] PLAYER_ERROR_SEEK_FAILED temp (0x%08x) : seeking... we can't do any more ", __FUNCTION__, PLAYER_ERROR_SEEK_FAILED);
1163                 return PLAYER_ERROR_SEEK_FAILED;
1164         }
1165
1166         LOGI("[%s] Event type : %d, pos : %"PRId64, __FUNCTION__, MUSE_PLAYER_EVENT_TYPE_SEEK, nanoseconds);
1167         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback;
1168         handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data;
1169
1170         ret = mm_player_set_attribute(handle->mm_handle, NULL, "accurate_seek", accurated, (char *)NULL);
1171         if (ret != MM_ERROR_NONE)
1172                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1173
1174         ret = mm_player_set_position(handle->mm_handle, nanoseconds);
1175         if (ret != MM_ERROR_NONE) {
1176                 handle->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
1177                 handle->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = NULL;
1178                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1179         }
1180
1181         return PLAYER_ERROR_NONE;
1182 }
1183
1184 int legacy_player_get_play_position(player_h player, int64_t *nanoseconds)
1185 {
1186         player_s *handle = (player_s *)player;
1187         int ret = MM_ERROR_NONE;
1188         int64_t pos = 0;
1189         PLAYER_INSTANCE_CHECK(player);
1190         PLAYER_NULL_ARG_CHECK(nanoseconds);
1191
1192         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
1193                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1194                 return PLAYER_ERROR_INVALID_STATE;
1195         }
1196
1197         ret = mm_player_get_position(handle->mm_handle, &pos);
1198         if (ret != MM_ERROR_NONE) {
1199                 if (ret == MM_ERROR_PLAYER_NOT_INITIALIZED) {
1200                         /* During playbak if a interrupt is occurred, the player can be destroyed internally.
1201                            libmm-player will post position msg with last playback position before destory pipeline */
1202                         if (handle->state == PLAYER_STATE_IDLE) {
1203                                 if (handle->last_play_position > 0)
1204                                         *nanoseconds = handle->last_play_position;
1205                                 else
1206                                         *nanoseconds = 0;
1207                                 LOGD("position %"PRId64, *nanoseconds);
1208                                 return PLAYER_ERROR_NONE;
1209                         }
1210                 }
1211                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1212         }
1213
1214         *nanoseconds = pos;
1215         return PLAYER_ERROR_NONE;
1216 }
1217
1218 int legacy_player_set_mute(player_h player, bool muted)
1219 {
1220         player_s *handle = (player_s *)player;
1221         int ret = MM_ERROR_NONE;
1222         PLAYER_INSTANCE_CHECK(player);
1223
1224         ret = mm_player_set_mute(handle->mm_handle, muted);
1225         if (ret != MM_ERROR_NONE)
1226                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1227
1228         return PLAYER_ERROR_NONE;
1229 }
1230
1231 int legacy_player_is_muted(player_h player, bool *muted)
1232 {
1233         player_s *handle = (player_s *)player;
1234         int _mute;
1235         int ret = MM_ERROR_NONE;
1236         PLAYER_INSTANCE_CHECK(player);
1237         PLAYER_NULL_ARG_CHECK(muted);
1238
1239         ret = mm_player_get_mute(handle->mm_handle, &_mute);
1240         if (ret != MM_ERROR_NONE)
1241                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1242
1243         *muted = (bool)_mute;
1244
1245         return PLAYER_ERROR_NONE;
1246 }
1247
1248 int legacy_player_set_looping(player_h player, bool looping)
1249 {
1250         player_s *handle = (player_s *)player;
1251         int ret = MM_ERROR_NONE;
1252         int value = 0;
1253         PLAYER_INSTANCE_CHECK(player);
1254
1255         if (looping)
1256                 value = -1;
1257
1258         ret = mm_player_set_attribute(handle->mm_handle, NULL, MM_PLAYER_PLAYBACK_COUNT, value, (char *)NULL);
1259         if (ret != MM_ERROR_NONE)
1260                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1261
1262         return PLAYER_ERROR_NONE;
1263 }
1264
1265 int legacy_player_is_looping(player_h player, bool *looping)
1266 {
1267         player_s *handle = (player_s *)player;
1268         int ret = MM_ERROR_NONE;
1269         int count;
1270         PLAYER_INSTANCE_CHECK(player);
1271         PLAYER_NULL_ARG_CHECK(looping);
1272
1273         ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_PLAYBACK_COUNT, &count, (char *)NULL);
1274         if (ret != MM_ERROR_NONE)
1275                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1276
1277         *looping = (count == -1) ? true : false;
1278
1279         return PLAYER_ERROR_NONE;
1280 }
1281
1282 int legacy_player_get_duration(player_h player, int64_t *duration)
1283 {
1284         player_s *handle = (player_s *)player;
1285         int ret = MM_ERROR_NONE;
1286         PLAYER_INSTANCE_CHECK(player);
1287         PLAYER_NULL_ARG_CHECK(duration);
1288
1289         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1290                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1291                 return PLAYER_ERROR_INVALID_STATE;
1292         }
1293
1294         ret = mm_player_get_duration(handle->mm_handle, duration);
1295         if (ret != MM_ERROR_NONE)
1296                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1297
1298         LOGD("content dur: %"PRId64, *duration);
1299         return PLAYER_ERROR_NONE;
1300 }
1301
1302 int legacy_player_set_display_mode(player_h player, player_display_mode_e mode)
1303 {
1304         player_s *handle = (player_s *)player;
1305         int ret = MM_ERROR_NONE;
1306         PLAYER_INSTANCE_CHECK(player);
1307         LOGI("[%s] mode:%d", __FUNCTION__, mode);
1308
1309         ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_method", mode, (char *)NULL);
1310         if (ret != MM_ERROR_NONE)
1311                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1312
1313         return PLAYER_ERROR_NONE;
1314 }
1315
1316 int legacy_player_get_display_mode(player_h player, player_display_mode_e *mode)
1317 {
1318         player_s *handle = (player_s *)player;
1319         int ret = MM_ERROR_NONE;
1320         PLAYER_INSTANCE_CHECK(player);
1321         PLAYER_NULL_ARG_CHECK(mode);
1322
1323         ret = mm_player_get_attribute(handle->mm_handle, NULL, "display_method", mode, (char *)NULL);
1324         if (ret != MM_ERROR_NONE)
1325                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1326
1327         return PLAYER_ERROR_NONE;
1328 }
1329
1330 int legacy_player_set_playback_rate(player_h player, float rate)
1331 {
1332         player_s *handle = (player_s *)player;
1333         int ret = MM_ERROR_NONE;
1334         LOGI("[%s] rate : %0.1f", __FUNCTION__, rate);
1335         PLAYER_INSTANCE_CHECK(player);
1336         PLAYER_CHECK_CONDITION(rate >= -5.0 && rate <= 5.0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1337
1338         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1339                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1340                 return PLAYER_ERROR_INVALID_STATE;
1341         }
1342
1343         ret = mm_player_set_play_speed(handle->mm_handle, rate, false);
1344         switch (ret) {
1345         case MM_ERROR_NONE:
1346         case MM_ERROR_PLAYER_NO_OP:
1347                 ret = PLAYER_ERROR_NONE;
1348                 break;
1349         case MM_ERROR_NOT_SUPPORT_API:
1350         case MM_ERROR_PLAYER_SEEK:
1351                 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x) : seek error", __FUNCTION__, PLAYER_ERROR_INVALID_OPERATION);
1352                 ret = PLAYER_ERROR_INVALID_OPERATION;
1353                 break;
1354         default:
1355                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1356         }
1357
1358         return ret;
1359 }
1360
1361 int legacy_player_set_display_rotation(player_h player, player_display_rotation_e rotation)
1362 {
1363         player_s *handle = (player_s *)player;
1364         int ret = MM_ERROR_NONE;
1365         PLAYER_INSTANCE_CHECK(player);
1366
1367         ret = mm_player_set_attribute(handle->mm_handle, NULL, MM_PLAYER_VIDEO_ROTATION, rotation, (char *)NULL);
1368         if (ret != MM_ERROR_NONE)
1369                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1370
1371         return PLAYER_ERROR_NONE;
1372 }
1373
1374 int legacy_player_get_display_rotation(player_h player, player_display_rotation_e *rotation)
1375 {
1376         player_s *handle = (player_s *)player;
1377         int ret = MM_ERROR_NONE;
1378         PLAYER_INSTANCE_CHECK(player);
1379         PLAYER_NULL_ARG_CHECK(rotation);
1380
1381         ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_VIDEO_ROTATION, rotation, (char *)NULL);
1382         if (ret != MM_ERROR_NONE)
1383                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1384
1385         return PLAYER_ERROR_NONE;
1386 }
1387
1388 int legacy_player_set_display_visible(player_h player, bool visible)
1389 {
1390         player_s *handle = (player_s *)player;
1391         int ret = MM_ERROR_NONE;
1392         int value = 0;
1393         PLAYER_INSTANCE_CHECK(player);
1394
1395         if (visible)
1396                 value = 1;
1397
1398         ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_visible", value, (char *)NULL);
1399         if (ret != MM_ERROR_NONE)
1400                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1401
1402         handle->is_display_visible = visible;
1403         return PLAYER_ERROR_NONE;
1404 }
1405
1406 int legacy_player_is_display_visible(player_h player, bool *visible)
1407 {
1408         player_s *handle = (player_s *)player;
1409         int ret = MM_ERROR_NONE;
1410         int value;
1411         PLAYER_INSTANCE_CHECK(player);
1412         PLAYER_NULL_ARG_CHECK(visible);
1413
1414         ret = mm_player_get_attribute(handle->mm_handle, NULL, "display_visible", &value, (char *)NULL);
1415         if (ret != MM_ERROR_NONE)
1416                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1417
1418         *visible = (value == 0) ? false : true;
1419
1420         return PLAYER_ERROR_NONE;
1421 }
1422
1423 int legacy_player_get_content_info(player_h player, player_content_info_e key, char **value)
1424 {
1425         player_s *handle = (player_s *)player;
1426         int ret = MM_ERROR_NONE;
1427         char *attr = NULL;
1428         char *val = NULL;
1429         int val_len = 0;
1430         PLAYER_INSTANCE_CHECK(player);
1431         PLAYER_NULL_ARG_CHECK(value);
1432
1433         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1434                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1435                 return PLAYER_ERROR_INVALID_STATE;
1436         }
1437
1438         switch (key) {
1439         case PLAYER_CONTENT_INFO_ALBUM:
1440                 attr = MM_PLAYER_TAG_ALBUM;
1441                 break;
1442         case PLAYER_CONTENT_INFO_ARTIST:
1443                 attr = MM_PLAYER_TAG_ARTIST;
1444                 break;
1445         case PLAYER_CONTENT_INFO_AUTHOR:
1446                 attr = MM_PLAYER_TAG_AUTHOUR;
1447                 break;
1448         case PLAYER_CONTENT_INFO_GENRE:
1449                 attr = MM_PLAYER_TAG_GENRE;
1450                 break;
1451         case PLAYER_CONTENT_INFO_TITLE:
1452                 attr = MM_PLAYER_TAG_TITLE;
1453                 break;
1454         case PLAYER_CONTENT_INFO_YEAR:
1455                 attr = MM_PLAYER_TAG_DATE;
1456                 break;
1457         default:
1458                 attr = NULL;
1459         }
1460
1461         ret = mm_player_get_attribute(handle->mm_handle, NULL, attr, &val, &val_len, (char *)NULL);
1462         if (ret != MM_ERROR_NONE)
1463                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1464
1465         *value = NULL;
1466         if (val != NULL)
1467                 *value = strndup(val, val_len);
1468         else
1469                 *value = strndup("", 0);
1470
1471         if (*value == NULL) {
1472                 LOGE("[%s] PLAYER_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ", __FUNCTION__, PLAYER_ERROR_OUT_OF_MEMORY);
1473                 return PLAYER_ERROR_OUT_OF_MEMORY;
1474         }
1475
1476         return PLAYER_ERROR_NONE;
1477 }
1478
1479 int legacy_player_get_codec_info(player_h player, char **audio_codec, char **video_codec)
1480 {
1481         player_s *handle = (player_s *)player;
1482         int ret = MM_ERROR_NONE;
1483         char *audio = NULL;
1484         int audio_len = 0;
1485         char *video = NULL;
1486         int video_len = 0;
1487         PLAYER_INSTANCE_CHECK(player);
1488         PLAYER_NULL_ARG_CHECK(audio_codec);
1489         PLAYER_NULL_ARG_CHECK(video_codec);
1490
1491         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1492                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1493                 return PLAYER_ERROR_INVALID_STATE;
1494         }
1495
1496         ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_AUDIO_CODEC, &audio, &audio_len, MM_PLAYER_VIDEO_CODEC, &video, &video_len, (char *)NULL);
1497         if (ret != MM_ERROR_NONE)
1498                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1499
1500         *audio_codec = NULL;
1501         if (audio != NULL)
1502                 *audio_codec = strndup(audio, audio_len);
1503         else
1504                 *audio_codec = strndup("", 0);
1505
1506         *video_codec = NULL;
1507         if (video != NULL)
1508                 *video_codec = strndup(video, video_len);
1509         else
1510                 *video_codec = strndup("", 0);
1511
1512         LOGD("codec info: %s, %s", *audio_codec, *video_codec);
1513         return PLAYER_ERROR_NONE;
1514 }
1515
1516 int legacy_player_get_audio_stream_info(player_h player, int *sample_rate, int *channel, int *bit_rate)
1517 {
1518         player_s *handle = (player_s *)player;
1519         int ret = MM_ERROR_NONE;
1520         PLAYER_INSTANCE_CHECK(player);
1521         PLAYER_NULL_ARG_CHECK(sample_rate);
1522         PLAYER_NULL_ARG_CHECK(channel);
1523         PLAYER_NULL_ARG_CHECK(bit_rate);
1524
1525         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1526                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1527                 return PLAYER_ERROR_INVALID_STATE;
1528         }
1529         ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_AUDIO_SAMPLERATE, sample_rate, MM_PLAYER_AUDIO_CHANNEL, channel, MM_PLAYER_AUDIO_BITRATE, bit_rate, (char *)NULL);
1530         if (ret != MM_ERROR_NONE)
1531                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1532
1533         return PLAYER_ERROR_NONE;
1534 }
1535
1536 int legacy_player_get_video_stream_info(player_h player, int *fps, int *bit_rate)
1537 {
1538         player_s *handle = (player_s *)player;
1539         int ret = MM_ERROR_NONE;
1540         PLAYER_INSTANCE_CHECK(player);
1541         PLAYER_NULL_ARG_CHECK(fps);
1542         PLAYER_NULL_ARG_CHECK(bit_rate);
1543
1544         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1545                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1546                 return PLAYER_ERROR_INVALID_STATE;
1547         }
1548         ret = mm_player_get_attribute(handle->mm_handle, NULL, "content_video_fps", fps, "content_video_bitrate", bit_rate, (char *)NULL);
1549         if (ret != MM_ERROR_NONE)
1550                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1551
1552         return PLAYER_ERROR_NONE;
1553 }
1554
1555 int legacy_player_get_video_size(player_h player, int *width, int *height)
1556 {
1557         player_s *handle = (player_s *)player;
1558         int ret = MM_ERROR_NONE;
1559         int w;
1560         int h;
1561         PLAYER_INSTANCE_CHECK(player);
1562         PLAYER_NULL_ARG_CHECK(width);
1563         PLAYER_NULL_ARG_CHECK(height);
1564         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1565                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1566                 return PLAYER_ERROR_INVALID_STATE;
1567         }
1568         ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_VIDEO_WIDTH, &w, MM_PLAYER_VIDEO_HEIGHT, &h, (char *)NULL);
1569         if (ret != MM_ERROR_NONE)
1570                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1571
1572         *width = w;
1573         *height = h;
1574         LOGI("[%s] width : %d, height : %d", __FUNCTION__, w, h);
1575         return PLAYER_ERROR_NONE;
1576 }
1577
1578 int legacy_player_get_album_art(player_h player, void **album_art, int *size)
1579 {
1580         player_s *handle = (player_s *)player;
1581         int ret = MM_ERROR_NONE;
1582         PLAYER_INSTANCE_CHECK(player);
1583         PLAYER_NULL_ARG_CHECK(size);
1584         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1585                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1586                 return PLAYER_ERROR_INVALID_STATE;
1587         }
1588
1589         ret = mm_player_get_attribute(handle->mm_handle, NULL, "tag_album_cover", album_art, size, (char *)NULL);
1590         if (ret != MM_ERROR_NONE)
1591                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1592
1593         return PLAYER_ERROR_NONE;
1594 }
1595
1596 int legacy_player_audio_effect_get_equalizer_bands_count(player_h player, int *count)
1597 {
1598         player_s *handle = (player_s *)player;
1599         int ret = MM_ERROR_NONE;
1600         PLAYER_INSTANCE_CHECK(player);
1601         PLAYER_NULL_ARG_CHECK(count);
1602
1603         ret = mm_player_audio_effect_custom_get_eq_bands_number(handle->mm_handle, count);
1604         if (ret != MM_ERROR_NONE)
1605                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1606
1607         return PLAYER_ERROR_NONE;
1608 }
1609
1610 int legacy_player_audio_effect_set_equalizer_all_bands(player_h player, int *band_levels, int length)
1611 {
1612         player_s *handle = (player_s *)player;
1613         int ret = MM_ERROR_NONE;
1614         PLAYER_INSTANCE_CHECK(player);
1615         PLAYER_NULL_ARG_CHECK(band_levels);
1616
1617         ret = mm_player_audio_effect_custom_set_level_eq_from_list(handle->mm_handle, band_levels, length);
1618         if (ret != MM_ERROR_NONE)
1619                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1620
1621         ret = mm_player_audio_effect_custom_apply(handle->mm_handle);
1622         return (ret == MM_ERROR_NONE) ? PLAYER_ERROR_NONE : __player_convert_error_code(ret, (char *)__FUNCTION__);
1623 }
1624
1625 int legacy_player_audio_effect_set_equalizer_band_level(player_h player, int index, int level)
1626 {
1627         player_s *handle = (player_s *)player;
1628         int ret = MM_ERROR_NONE;
1629         PLAYER_INSTANCE_CHECK(player);
1630
1631         ret = mm_player_audio_effect_custom_set_level(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ, index, level);
1632         if (ret != MM_ERROR_NONE)
1633                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1634
1635         ret = mm_player_audio_effect_custom_apply(handle->mm_handle);
1636         if (ret != MM_ERROR_NONE)
1637                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1638
1639         return PLAYER_ERROR_NONE;
1640 }
1641
1642 int legacy_player_audio_effect_get_equalizer_band_level(player_h player, int index, int *level)
1643 {
1644         player_s *handle = (player_s *)player;
1645         int ret = MM_ERROR_NONE;
1646         PLAYER_INSTANCE_CHECK(player);
1647         PLAYER_NULL_ARG_CHECK(level);
1648
1649         ret = mm_player_audio_effect_custom_get_level(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ, index, level);
1650         if (ret != MM_ERROR_NONE)
1651                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1652
1653         return PLAYER_ERROR_NONE;
1654 }
1655
1656 int legacy_player_audio_effect_get_equalizer_level_range(player_h player, int *min, int *max)
1657 {
1658         player_s *handle = (player_s *)player;
1659         int ret = MM_ERROR_NONE;
1660         PLAYER_INSTANCE_CHECK(player);
1661         PLAYER_NULL_ARG_CHECK(min);
1662         PLAYER_NULL_ARG_CHECK(max);
1663
1664         ret = mm_player_audio_effect_custom_get_level_range(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ, min, max);
1665         if (ret != MM_ERROR_NONE)
1666                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1667
1668         return PLAYER_ERROR_NONE;
1669 }
1670
1671 int legacy_player_audio_effect_get_equalizer_band_frequency(player_h player, int index, int *frequency)
1672 {
1673         player_s *handle = (player_s *)player;
1674         int ret = MM_ERROR_NONE;
1675         PLAYER_INSTANCE_CHECK(player);
1676         PLAYER_NULL_ARG_CHECK(frequency);
1677
1678         ret = mm_player_audio_effect_custom_get_eq_bands_freq(handle->mm_handle, index, frequency);
1679         if (ret != MM_ERROR_NONE)
1680                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1681
1682         return PLAYER_ERROR_NONE;
1683 }
1684
1685 int legacy_player_audio_effect_get_equalizer_band_frequency_range(player_h player, int index, int *range)
1686 {
1687         player_s *handle = (player_s *)player;
1688         int ret = MM_ERROR_NONE;
1689         PLAYER_INSTANCE_CHECK(player);
1690         PLAYER_NULL_ARG_CHECK(range);
1691
1692         ret = mm_player_audio_effect_custom_get_eq_bands_width(handle->mm_handle, index, range);
1693         if (ret != MM_ERROR_NONE)
1694                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1695
1696         return PLAYER_ERROR_NONE;
1697 }
1698
1699 int legacy_player_audio_effect_equalizer_clear(player_h player)
1700 {
1701         player_s *handle = (player_s *)player;
1702         int ret = MM_ERROR_NONE;
1703         PLAYER_INSTANCE_CHECK(player);
1704
1705         ret = mm_player_audio_effect_custom_clear_eq_all(handle->mm_handle);
1706         if (ret != MM_ERROR_NONE)
1707                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1708
1709         ret = mm_player_audio_effect_custom_apply(handle->mm_handle);
1710         if (ret != MM_ERROR_NONE)
1711                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1712
1713         return PLAYER_ERROR_NONE;
1714 }
1715
1716 int legacy_player_audio_effect_equalizer_is_available(player_h player, bool *available)
1717 {
1718         player_s *handle = (player_s *)player;
1719         int ret = MM_ERROR_NONE;
1720         PLAYER_INSTANCE_CHECK(player);
1721         PLAYER_NULL_ARG_CHECK(available);
1722         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
1723                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1724                 return PLAYER_ERROR_INVALID_STATE;
1725         }
1726
1727         ret = mm_player_is_supported_custom_effect_type(handle->mm_handle, MM_AUDIO_EFFECT_CUSTOM_EQ);
1728         if (ret != MM_ERROR_NONE)
1729                 *available = false;
1730         else
1731                 *available = true;
1732
1733         return PLAYER_ERROR_NONE;
1734 }
1735
1736 int legacy_player_set_subtitle_path(player_h player, const char *path)
1737 {
1738         player_s *handle = (player_s *)player;
1739         int ret = MM_ERROR_NONE;
1740         PLAYER_INSTANCE_CHECK(player);
1741
1742         if ((path == NULL) && (handle->state != PLAYER_STATE_IDLE))
1743                 return PLAYER_ERROR_INVALID_PARAMETER;
1744
1745         ret = mm_player_set_external_subtitle_path(handle->mm_handle, path);
1746         if (ret != MM_ERROR_NONE)
1747                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1748
1749         return PLAYER_ERROR_NONE;
1750 }
1751
1752 int legacy_player_set_subtitle_position_offset(player_h player, int millisecond)
1753 {
1754         /* PLAYER_CHECK_CONDITION(millisecond>=0  ,PLAYER_ERROR_INVALID_PARAMETER ,"PLAYER_ERROR_INVALID_PARAMETER" ); */
1755         player_s *handle = (player_s *)player;
1756         int ret = MM_ERROR_NONE;
1757         PLAYER_INSTANCE_CHECK(player);
1758         if (!__player_state_validate(handle, PLAYER_STATE_PLAYING)) {
1759                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1760                 return PLAYER_ERROR_INVALID_STATE;
1761         }
1762
1763         ret = mm_player_adjust_subtitle_position(handle->mm_handle, MM_PLAYER_POS_FORMAT_TIME, millisecond);
1764         if (ret != MM_ERROR_NONE)
1765                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1766
1767         return PLAYER_ERROR_NONE;
1768 }
1769
1770 int legacy_player_capture_video(player_h player, player_video_captured_cb callback, void *user_data)
1771 {
1772         player_s *handle = (player_s *)player;
1773         int ret = MM_ERROR_NONE;
1774         PLAYER_INSTANCE_CHECK(player);
1775         PLAYER_NULL_ARG_CHECK(callback);
1776         if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE]) {
1777                 LOGE("[%s] PLAYER_ERROR_VIDEO_CAPTURE_FAILED (0x%08x) : capturing... we can't do any more ", __FUNCTION__, PLAYER_ERROR_VIDEO_CAPTURE_FAILED);
1778                 return PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
1779         }
1780
1781         LOGI("[%s] Event type : %d ", __FUNCTION__, MUSE_PLAYER_EVENT_TYPE_CAPTURE);
1782         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = callback;
1783         handle->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = user_data;
1784
1785         if (handle->state >= PLAYER_STATE_READY) {
1786                 ret = mm_player_do_video_capture(handle->mm_handle);
1787                 if (ret == MM_ERROR_PLAYER_NO_OP) {
1788                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
1789                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
1790                         LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION (0x%08x) : video display must be set : %d", __FUNCTION__, PLAYER_ERROR_INVALID_OPERATION, handle->display_type);
1791                         return PLAYER_ERROR_INVALID_OPERATION;
1792                 }
1793                 if (ret != MM_ERROR_NONE) {
1794                         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
1795                         handle->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
1796                         return __player_convert_error_code(ret, (char *)__FUNCTION__);
1797                 }
1798                 return PLAYER_ERROR_NONE;
1799         }
1800
1801         LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
1802         handle->user_cb[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
1803         handle->user_data[MUSE_PLAYER_EVENT_TYPE_CAPTURE] = NULL;
1804         return PLAYER_ERROR_INVALID_STATE;
1805 }
1806
1807 int legacy_player_set_streaming_cookie(player_h player, const char *cookie, int size)
1808 {
1809         player_s *handle = (player_s *)player;
1810         int ret = MM_ERROR_NONE;
1811         PLAYER_INSTANCE_CHECK(player);
1812         PLAYER_NULL_ARG_CHECK(cookie);
1813         PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1814         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
1815
1816         ret = mm_player_set_attribute(handle->mm_handle, NULL, MM_PLAYER_STREAMING_COOKIE, cookie, size, (char *)NULL);
1817         if (ret != MM_ERROR_NONE)
1818                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1819
1820         return PLAYER_ERROR_NONE;
1821 }
1822
1823 int legacy_player_set_streaming_user_agent(player_h player, const char *user_agent, int size)
1824 {
1825         player_s *handle = (player_s *)player;
1826         int ret = MM_ERROR_NONE;
1827         PLAYER_INSTANCE_CHECK(player);
1828         PLAYER_NULL_ARG_CHECK(user_agent);
1829         PLAYER_CHECK_CONDITION(size >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
1830         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
1831
1832         ret = mm_player_set_attribute(handle->mm_handle, NULL, MM_PLAYER_STREAMING_USER_AGENT, user_agent, size, (char *)NULL);
1833         if (ret != MM_ERROR_NONE)
1834                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1835
1836         return PLAYER_ERROR_NONE;
1837 }
1838
1839 int legacy_player_get_streaming_download_progress(player_h player, int *start_pos, int *end_pos)
1840 {
1841         player_s *handle = (player_s *)player;
1842         int ret = MM_ERROR_NONE;
1843         PLAYER_INSTANCE_CHECK(player);
1844         PLAYER_NULL_ARG_CHECK(start_pos && end_pos);
1845         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
1846                 LOGE("invalid state error, current state - %d", handle->state);
1847                 return PLAYER_ERROR_INVALID_STATE;
1848         }
1849
1850         ret = mm_player_get_buffer_position(handle->mm_handle, start_pos, end_pos);
1851         if (ret != MM_ERROR_NONE)
1852                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1853
1854         return PLAYER_ERROR_NONE;
1855 }
1856
1857 int legacy_player_set_completed_cb(player_h player, player_completed_cb callback, void *user_data)
1858 {
1859         return __set_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player, callback, user_data);
1860 }
1861
1862 int legacy_player_unset_completed_cb(player_h player)
1863 {
1864         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_COMPLETE, player);
1865 }
1866
1867 #ifdef TIZEN_FEATURE_EVAS_RENDERER
1868 int legacy_player_set_retrieve_buffer_cb(player_h player, player_retrieve_buffer_cb callback, void *user_data)
1869 {
1870         return __set_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player, callback, user_data);
1871 }
1872
1873 int legacy_player_unset_retrieve_buffer_cb(player_h player)
1874 {
1875         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_RETURN_BUFFER, player);
1876 }
1877 #endif
1878
1879 int legacy_player_set_interrupted_cb(player_h player, player_interrupted_cb callback, void *user_data)
1880 {
1881         return __set_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player, callback, user_data);
1882 }
1883
1884 int legacy_player_unset_interrupted_cb(player_h player)
1885 {
1886         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_INTERRUPT, player);
1887 }
1888
1889 int legacy_player_set_error_cb(player_h player, player_error_cb callback, void *user_data)
1890 {
1891         return __set_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player, callback, user_data);
1892 }
1893
1894 int legacy_player_unset_error_cb(player_h player)
1895 {
1896         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_ERROR, player);
1897 }
1898
1899 int legacy_player_set_buffering_cb(player_h player, player_buffering_cb callback, void *user_data)
1900 {
1901         return __set_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player, callback, user_data);
1902 }
1903
1904 int legacy_player_unset_buffering_cb(player_h player)
1905 {
1906         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_BUFFERING, player);
1907 }
1908
1909 int legacy_player_set_subtitle_updated_cb(player_h player, player_subtitle_updated_cb callback, void *user_data)
1910 {
1911         return __set_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player, callback, user_data);
1912 }
1913
1914 int legacy_player_unset_subtitle_updated_cb(player_h player)
1915 {
1916         return __unset_callback(MUSE_PLAYER_EVENT_TYPE_SUBTITLE, player);
1917 }
1918
1919 int legacy_player_release_video_stream_bo(player_h player, void *bo)
1920 {
1921         player_s *handle = (player_s *)player;
1922         PLAYER_INSTANCE_CHECK(player);
1923
1924         LOGD("ENTER %p %p", player, bo);
1925
1926         mm_player_release_video_stream_bo(handle->mm_handle, bo);
1927
1928         LOGD("LEAVE");
1929
1930         return PLAYER_ERROR_NONE;
1931 }
1932
1933 int legacy_player_set_media_packet_video_frame_decoded_cb(player_h player, legacy_player_media_packet_video_decoded_cb callback, void *user_data)
1934 {
1935         player_s *handle = (player_s *)player;
1936         int ret = MM_ERROR_NONE;
1937         PLAYER_INSTANCE_CHECK(player);
1938         PLAYER_NULL_ARG_CHECK(callback);
1939         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
1940
1941         ret = mm_player_set_video_stream_callback(handle->mm_handle, (mm_player_video_stream_callback)callback, user_data);
1942         if (ret != MM_ERROR_NONE)
1943                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1944
1945         return PLAYER_ERROR_NONE;
1946 }
1947
1948 static bool __video_stream_changed_callback(void *user_data)
1949 {
1950         player_s *handle = (player_s *)user_data;
1951         int ret = MM_ERROR_NONE;
1952         muse_player_event_e event_type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
1953
1954         LOGE("[%s] event type %d", __FUNCTION__, event_type);
1955
1956         if (handle->user_cb[event_type]) {
1957                 int width = 0, height = 0, fps = 0, bit_rate = 0;
1958                 ret = mm_player_get_attribute(handle->mm_handle, NULL,
1959                                                                                   MM_PLAYER_VIDEO_WIDTH, &width,
1960                                                                                   MM_PLAYER_VIDEO_HEIGHT, &height,
1961                                                                                   "content_video_fps", &fps,
1962                                                                                   "content_video_bitrate", &bit_rate, (char *)NULL);
1963
1964                 if (ret != MM_ERROR_NONE) {
1965                         LOGE("[%s] get attr is failed", __FUNCTION__);
1966                         return false;
1967                 }
1968                 ((player_video_stream_changed_cb)handle->user_cb[event_type])(width, height, fps, bit_rate, handle->user_data[event_type]);
1969                 return true;
1970         }
1971
1972         LOGE("[%s] video stream changed cb was not set.", __FUNCTION__);
1973         return false;
1974 }
1975
1976 int legacy_player_set_video_stream_changed_cb(player_h player, player_video_stream_changed_cb callback, void *user_data)
1977 {
1978         player_s *handle = (player_s *)player;
1979         int ret = MM_ERROR_NONE;
1980         PLAYER_INSTANCE_CHECK(player);
1981         PLAYER_NULL_ARG_CHECK(callback);
1982         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
1983
1984         ret = mm_player_set_video_stream_changed_callback(handle->mm_handle, (mm_player_stream_changed_callback)__video_stream_changed_callback, (void *)handle);
1985         if (ret != MM_ERROR_NONE)
1986                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
1987
1988         return __set_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player, callback, user_data);
1989 }
1990
1991 int legacy_player_unset_video_stream_changed_cb(player_h player)
1992 {
1993         PLAYER_INSTANCE_CHECK(player);
1994
1995         __unset_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player);
1996
1997         return PLAYER_ERROR_NONE;
1998 }
1999
2000 static bool __media_stream_buffer_status_callback(player_stream_type_e type, player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data)
2001 {
2002         player_s *handle = (player_s *)user_data;
2003         muse_player_event_e event_type;
2004
2005         if (type == PLAYER_STREAM_TYPE_AUDIO)
2006                 event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
2007         else if (type == PLAYER_STREAM_TYPE_VIDEO)
2008                 event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
2009         else
2010                 return false;
2011
2012         LOGE("[%s] event type %d", __FUNCTION__, event_type);
2013
2014         if (handle->user_cb[event_type]) {
2015                 ((player_media_stream_buffer_status_cb)handle->user_cb[event_type])(status, handle->user_data[event_type]);
2016         } else {
2017                 LOGE("[%s][type:%d] buffer status cb was not set.", __FUNCTION__, type);
2018                 return false;
2019         }
2020
2021         return true;
2022 }
2023
2024 static bool __media_stream_seek_data_callback(player_stream_type_e type, unsigned long long offset, void *user_data)
2025 {
2026         player_s *handle = (player_s *)user_data;
2027         muse_player_event_e event_type;
2028
2029         if (type == PLAYER_STREAM_TYPE_AUDIO)
2030                 event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
2031         else if (type == PLAYER_STREAM_TYPE_VIDEO)
2032                 event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
2033         else
2034                 return false;
2035
2036         LOGE("[%s] event type %d", __FUNCTION__, event_type);
2037
2038         if (handle->user_cb[event_type]) {
2039                 ((player_media_stream_seek_cb)handle->user_cb[event_type])(offset, handle->user_data[event_type]);
2040         } else {
2041                 LOGE("[%s][type:%d] seek cb was not set.", __FUNCTION__, type);
2042                 return false;
2043         }
2044
2045         return true;
2046 }
2047
2048 int legacy_player_set_media_stream_buffer_status_cb(player_h player, player_stream_type_e type, player_media_stream_buffer_status_cb callback, void *user_data)
2049 {
2050         player_s *handle = (player_s *)player;
2051         int ret = MM_ERROR_NONE;
2052         PLAYER_INSTANCE_CHECK(player);
2053         PLAYER_NULL_ARG_CHECK(callback);
2054         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
2055
2056         /* the type can be expaned with default and text. */
2057         if ((type != PLAYER_STREAM_TYPE_VIDEO) && (type != PLAYER_STREAM_TYPE_AUDIO)) {
2058                 LOGE("[%s] PLAYER_ERROR_INVALID_PARAMETER(type : %d)", __FUNCTION__, type);
2059                 return PLAYER_ERROR_INVALID_PARAMETER;
2060         }
2061
2062         ret = mm_player_set_media_stream_buffer_status_callback(handle->mm_handle, type, (mm_player_media_stream_buffer_status_callback)__media_stream_buffer_status_callback, (void *)handle);
2063
2064         if (ret != MM_ERROR_NONE)
2065                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2066
2067         if (type == PLAYER_STREAM_TYPE_VIDEO)
2068                 return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS, player, callback, user_data);
2069         else
2070                 return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS, player, callback, user_data);
2071 }
2072
2073 int legacy_player_unset_media_stream_buffer_status_cb(player_h player, player_stream_type_e type)
2074 {
2075         PLAYER_INSTANCE_CHECK(player);
2076
2077         if (type == PLAYER_STREAM_TYPE_VIDEO)
2078                 __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS, player);
2079         else if (type == PLAYER_STREAM_TYPE_AUDIO)
2080                 __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS, player);
2081         else
2082                 return PLAYER_ERROR_INVALID_PARAMETER;
2083
2084         return PLAYER_ERROR_NONE;
2085 }
2086
2087 int legacy_player_set_media_stream_seek_cb(player_h player, player_stream_type_e type, player_media_stream_seek_cb callback, void *user_data)
2088 {
2089         player_s *handle = (player_s *)player;
2090         int ret = MM_ERROR_NONE;
2091         PLAYER_INSTANCE_CHECK(player);
2092         PLAYER_NULL_ARG_CHECK(callback);
2093         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
2094
2095         /* the type can be expaned with default and text. */
2096         if ((type != PLAYER_STREAM_TYPE_VIDEO) && (type != PLAYER_STREAM_TYPE_AUDIO)) {
2097                 LOGE("[%s] PLAYER_ERROR_INVALID_PARAMETER(type : %d)", __FUNCTION__, type);
2098                 return PLAYER_ERROR_INVALID_PARAMETER;
2099         }
2100
2101         ret = mm_player_set_media_stream_seek_data_callback(handle->mm_handle, type, (mm_player_media_stream_seek_data_callback)__media_stream_seek_data_callback, (void *)handle);
2102         if (ret != MM_ERROR_NONE)
2103                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2104
2105         if (type == PLAYER_STREAM_TYPE_VIDEO)
2106                 return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK, player, callback, user_data);
2107
2108         return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK, player, callback, user_data);
2109 }
2110
2111 int legacy_player_unset_media_stream_seek_cb(player_h player, player_stream_type_e type)
2112 {
2113         PLAYER_INSTANCE_CHECK(player);
2114
2115         if (type == PLAYER_STREAM_TYPE_VIDEO)
2116                 __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK, player);
2117         else if (type == PLAYER_STREAM_TYPE_AUDIO)
2118                 __unset_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK, player);
2119         else
2120                 return PLAYER_ERROR_INVALID_PARAMETER;
2121
2122         return PLAYER_ERROR_NONE;
2123 }
2124
2125 int legacy_player_push_media_stream(player_h player, media_packet_h packet)
2126 {
2127         player_s *handle = (player_s *)player;
2128         int ret = MM_ERROR_NONE;
2129         PLAYER_INSTANCE_CHECK(player);
2130
2131         PLAYER_CHECK_CONDITION(handle->error_code == PLAYER_ERROR_NONE, PLAYER_ERROR_NOT_SUPPORTED_FILE, "can't support this format");
2132
2133         ret = mm_player_submit_packet(handle->mm_handle, packet);
2134         if (ret != MM_ERROR_NONE)
2135                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2136
2137         return PLAYER_ERROR_NONE;
2138 }
2139
2140 int legacy_player_set_media_stream_info(player_h player, player_stream_type_e type, media_format_h format)
2141 {
2142         player_s *handle = (player_s *)player;
2143         int ret = MM_ERROR_NONE;
2144         PLAYER_INSTANCE_CHECK(player);
2145         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
2146
2147         handle->is_media_stream = true;
2148
2149         if (type == PLAYER_STREAM_TYPE_VIDEO)
2150                 ret = mm_player_set_video_info(handle->mm_handle, format);
2151         else if (type == PLAYER_STREAM_TYPE_AUDIO)
2152                 ret = mm_player_set_audio_info(handle->mm_handle, format);
2153         else
2154                 return PLAYER_ERROR_INVALID_PARAMETER;
2155
2156         if (ret != MM_ERROR_NONE)
2157                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2158
2159         return PLAYER_ERROR_NONE;
2160 }
2161
2162 int legacy_player_set_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long max_size)
2163 {
2164         player_s *handle = (player_s *)player;
2165         int ret = MM_ERROR_NONE;
2166         PLAYER_INSTANCE_CHECK(player);
2167         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2168                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2169                 return PLAYER_ERROR_INVALID_STATE;
2170         }
2171
2172         ret = mm_player_set_media_stream_buffer_max_size(handle->mm_handle, type, max_size);
2173         if (ret != MM_ERROR_NONE)
2174                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2175
2176         return PLAYER_ERROR_NONE;
2177 }
2178
2179 int legacy_player_get_media_stream_buffer_max_size(player_h player, player_stream_type_e type, unsigned long long *max_size)
2180 {
2181         player_s *handle = (player_s *)player;
2182         int ret = MM_ERROR_NONE;
2183         unsigned long long _max_size;
2184         PLAYER_INSTANCE_CHECK(player);
2185         PLAYER_NULL_ARG_CHECK(max_size);
2186
2187         ret = mm_player_get_media_stream_buffer_max_size(handle->mm_handle, type, &_max_size);
2188         if (ret != MM_ERROR_NONE)
2189                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2190
2191         *max_size = _max_size;
2192         return PLAYER_ERROR_NONE;
2193 }
2194
2195 int legacy_player_set_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int percent)
2196 {
2197         player_s *handle = (player_s *)player;
2198         int ret = MM_ERROR_NONE;
2199         PLAYER_INSTANCE_CHECK(player);
2200         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2201                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2202                 return PLAYER_ERROR_INVALID_STATE;
2203         }
2204
2205         ret = mm_player_set_media_stream_buffer_min_percent(handle->mm_handle, type, percent);
2206         if (ret != MM_ERROR_NONE)
2207                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2208
2209         return PLAYER_ERROR_NONE;
2210 }
2211
2212 int legacy_player_get_media_stream_buffer_min_threshold(player_h player, player_stream_type_e type, unsigned int *percent)
2213 {
2214         player_s *handle = (player_s *)player;
2215         int ret = MM_ERROR_NONE;
2216         unsigned int _value;
2217         PLAYER_INSTANCE_CHECK(player);
2218         PLAYER_NULL_ARG_CHECK(percent);
2219
2220         ret = mm_player_get_media_stream_buffer_min_percent(handle->mm_handle, type, &_value);
2221         if (ret != MM_ERROR_NONE)
2222                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2223
2224         *percent = _value;
2225         return PLAYER_ERROR_NONE;
2226 }
2227
2228 int legacy_player_get_track_count(player_h player, player_stream_type_e type, int *count)
2229 {
2230         player_s *handle = (player_s *)player;
2231         int ret = MM_ERROR_NONE;
2232         MMPlayerTrackType track_type = 0;
2233         PLAYER_INSTANCE_CHECK(player);
2234         PLAYER_NULL_ARG_CHECK(count);
2235
2236         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2237                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2238                 return PLAYER_ERROR_INVALID_STATE;
2239         }
2240
2241         switch (type) {
2242         case PLAYER_STREAM_TYPE_AUDIO:
2243                 track_type = MM_PLAYER_TRACK_TYPE_AUDIO;
2244                 break;
2245         case PLAYER_STREAM_TYPE_TEXT:
2246                 track_type = MM_PLAYER_TRACK_TYPE_TEXT;
2247                 break;
2248         default:
2249                 LOGE("invalid stream type %d", type);
2250                 return PLAYER_ERROR_INVALID_PARAMETER;
2251         }
2252
2253         ret = mm_player_get_track_count(handle->mm_handle, track_type, count);
2254         if (ret != MM_ERROR_NONE)
2255                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2256
2257         return PLAYER_ERROR_NONE;
2258 }
2259
2260 int legacy_player_get_current_track(player_h player, player_stream_type_e type, int *index)
2261 {
2262         player_s *handle = (player_s *)player;
2263         int ret = MM_ERROR_NONE;
2264         MMPlayerTrackType track_type = 0;
2265         PLAYER_INSTANCE_CHECK(player);
2266         PLAYER_NULL_ARG_CHECK(index);
2267         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2268                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2269                 return PLAYER_ERROR_INVALID_STATE;
2270         }
2271
2272         switch (type) {
2273         case PLAYER_STREAM_TYPE_AUDIO:
2274                 track_type = MM_PLAYER_TRACK_TYPE_AUDIO;
2275                 break;
2276         case PLAYER_STREAM_TYPE_TEXT:
2277                 track_type = MM_PLAYER_TRACK_TYPE_TEXT;
2278                 break;
2279         default:
2280                 LOGE("invalid stream type %d", type);
2281                 return PLAYER_ERROR_INVALID_PARAMETER;
2282         }
2283
2284         ret = mm_player_get_current_track(handle->mm_handle, track_type, index);
2285         if (ret != MM_ERROR_NONE)
2286                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2287
2288         return PLAYER_ERROR_NONE;
2289 }
2290
2291 int legacy_player_select_track(player_h player, player_stream_type_e type, int index)
2292 {
2293         player_s *handle = (player_s *)player;
2294         int ret = MM_ERROR_NONE;
2295         MMPlayerTrackType track_type = 0;
2296         PLAYER_INSTANCE_CHECK(player);
2297         PLAYER_CHECK_CONDITION(index >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER");
2298         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2299                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2300                 return PLAYER_ERROR_INVALID_STATE;
2301         }
2302
2303         switch (type) {
2304         case PLAYER_STREAM_TYPE_AUDIO:
2305                 track_type = MM_PLAYER_TRACK_TYPE_AUDIO;
2306                 break;
2307         case PLAYER_STREAM_TYPE_TEXT:
2308                 track_type = MM_PLAYER_TRACK_TYPE_TEXT;
2309                 break;
2310         default:
2311                 LOGE("invalid stream type %d", type);
2312                 return PLAYER_ERROR_INVALID_PARAMETER;
2313         }
2314
2315         ret = mm_player_select_track(handle->mm_handle, track_type, index);
2316         if (ret != MM_ERROR_NONE)
2317                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2318
2319         return PLAYER_ERROR_NONE;
2320 }
2321
2322 int legacy_player_get_track_language_code(player_h player, player_stream_type_e type, int index, char **code, int *len)
2323 {
2324         player_s *handle = (player_s *)player;
2325         int ret = MM_ERROR_NONE;
2326         MMPlayerTrackType track_type = 0;
2327         PLAYER_INSTANCE_CHECK(player);
2328         PLAYER_NULL_ARG_CHECK(code);
2329         PLAYER_NULL_ARG_CHECK(len);
2330         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2331                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) :  current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2332                 return PLAYER_ERROR_INVALID_STATE;
2333         }
2334
2335         switch (type) {
2336         case PLAYER_STREAM_TYPE_AUDIO:
2337                 track_type = MM_PLAYER_TRACK_TYPE_AUDIO;
2338                 break;
2339         case PLAYER_STREAM_TYPE_VIDEO:
2340                 track_type = MM_PLAYER_TRACK_TYPE_VIDEO;
2341                 break;
2342         case PLAYER_STREAM_TYPE_TEXT:
2343                 track_type = MM_PLAYER_TRACK_TYPE_TEXT;
2344                 break;
2345         default:
2346                 LOGE("invalid stream type %d", type);
2347                 return PLAYER_ERROR_INVALID_PARAMETER;
2348         }
2349
2350         *code = NULL;
2351         ret = mm_player_get_track_language_code(handle->mm_handle, track_type, index, code);
2352         if (ret != MM_ERROR_NONE)
2353                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2354
2355         LOGD("idx %d, lang code %s", index, *code);
2356         *len = strlen(*code);
2357         return PLAYER_ERROR_NONE;
2358 }
2359
2360 int legacy_player_set_video_roi_area(player_h player, double scale_x,
2361                 double scale_y, double scale_width, double scale_heights)
2362 {
2363         player_s *handle = (player_s *)player;
2364         int ret = MM_ERROR_NONE;
2365         PLAYER_INSTANCE_CHECK(player);
2366
2367         LOGD("<Enter>");
2368
2369         if (handle->display_type != PLAYER_DISPLAY_TYPE_OVERLAY) {
2370                 LOGE("not supportable display type %d", handle->display_type);
2371                 return PLAYER_ERROR_INVALID_OPERATION;
2372         }
2373
2374         ret = mm_player_set_video_roi_area(handle->mm_handle, scale_x, scale_y, scale_width, scale_heights);
2375         if (ret != PLAYER_ERROR_NONE)
2376                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2377
2378         return PLAYER_ERROR_NONE;
2379 }
2380
2381 int legacy_player_get_video_roi_area(player_h player, double *scale_x,
2382                 double *scale_y, double *scale_width, double *scale_height)
2383 {
2384         player_s *handle = (player_s *)player;
2385         int ret = MM_ERROR_NONE;
2386         PLAYER_INSTANCE_CHECK(player);
2387         PLAYER_NULL_ARG_CHECK(scale_x);
2388         PLAYER_NULL_ARG_CHECK(scale_y);
2389         PLAYER_NULL_ARG_CHECK(scale_width);
2390         PLAYER_NULL_ARG_CHECK(scale_height);
2391
2392         LOGD("<Enter>");
2393
2394         ret = mm_player_get_video_roi_area(handle->mm_handle, scale_x, scale_y, scale_width, scale_height);
2395         if (ret != PLAYER_ERROR_NONE)
2396                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2397
2398         return PLAYER_ERROR_NONE;
2399 }
2400
2401 int legacy_player_set_roi_area(player_h player, int x, int y, int w, int h)
2402 {
2403         player_s *handle = (player_s *)player;
2404         int ret = MM_ERROR_NONE;
2405         PLAYER_INSTANCE_CHECK(player);
2406
2407         LOGD("<Enter>");
2408
2409         /* set roi area */
2410         ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_win_roi_x", x, "display_win_roi_y", y, "display_win_roi_width", w, "display_win_roi_height", h, (char *)NULL);
2411         if (ret != MM_ERROR_NONE)
2412                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2413
2414         return PLAYER_ERROR_NONE;
2415 }
2416
2417 int legacy_player_set_display(player_h player, player_display_type_e type, unsigned int wl_surface_id)
2418 {
2419         player_s *handle = (player_s *)player;
2420         int ret = MM_ERROR_NONE;
2421         void *set_handle = NULL;
2422         void *temp = NULL;
2423         MMDisplaySurfaceType mmType = __player_convert_display_type(type);
2424         PLAYER_INSTANCE_CHECK(player);
2425         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2426                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2427                 return PLAYER_ERROR_INVALID_STATE;
2428         }
2429
2430         if (type == PLAYER_DISPLAY_TYPE_NONE) {
2431                 /* NULL surface */
2432                 handle->display_handle = 0;
2433                 handle->display_type = type;
2434                 set_handle = NULL;
2435         } else {
2436                 /* get handle from overlay or evas surface */
2437                 temp = handle->display_handle;
2438                 if (type == PLAYER_DISPLAY_TYPE_OVERLAY) {
2439                         LOGI("Wayland overlay surface type");
2440                         LOGI("wl_surface_id %d", wl_surface_id);
2441                         handle->display_handle = (void *)(uintptr_t)wl_surface_id;
2442                         set_handle = &(handle->display_handle);
2443 #ifdef TIZEN_FEATURE_EVAS_RENDERER
2444                 } else if (type == PLAYER_DISPLAY_TYPE_EVAS) {
2445                         LOGI("Evas surface type");
2446                         set_handle = &(handle->display_handle);
2447 #endif
2448                 } else {
2449                         LOGE("invalid surface type");
2450                         return PLAYER_ERROR_INVALID_PARAMETER;
2451                 }
2452         }
2453
2454         /* set display handle */
2455         if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE || type == handle->display_type) {
2456                 /* first time or same type */
2457                 LOGW("first time or same type");
2458                 ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_surface_type", mmType, "display_overlay", set_handle, sizeof(wl_surface_id), NULL);
2459
2460                 if (ret != MM_ERROR_NONE) {
2461                         handle->display_handle = temp;
2462                         LOGE("Failed to display surface change: %d", ret);
2463                 } else {
2464                         if (type != PLAYER_DISPLAY_TYPE_NONE) {
2465                                 handle->display_type = type;
2466                                 LOGI("video display has been changed- type: %d, addr: %p", handle->display_type, handle->display_handle);
2467                         } else {
2468                                 LOGI("NULL surface");
2469                         }
2470                 }
2471         } else {
2472                 /* changing surface case */
2473                 ret = mm_player_change_videosink(handle->mm_handle, mmType, set_handle);
2474                 if (ret != MM_ERROR_NONE) {
2475                         handle->display_handle = temp;
2476                         if (ret == MM_ERROR_NOT_SUPPORT_API) {
2477                                 LOGE("change video sink is not available.");
2478                                 ret = PLAYER_ERROR_NONE;
2479                         } else {
2480                                 LOGE("Failed to display surface change: %d", ret);
2481                         }
2482                 } else {
2483                         handle->display_type = type;
2484                         LOGI("video display has been changed- type: %d, addr: %p", handle->display_type, handle->display_handle);
2485                 }
2486         }
2487
2488         if (ret != MM_ERROR_NONE) {
2489                 handle->display_type = PLAYER_DISPLAY_TYPE_NONE;
2490                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2491         }
2492
2493         return PLAYER_ERROR_NONE;
2494 }
2495
2496 int legacy_player_set_sound_stream_info_for_mused(player_h player, char *stream_type, int stream_index)
2497 {
2498         player_s *handle = (player_s *)player;
2499         int ret = MM_ERROR_NONE;
2500         PLAYER_INSTANCE_CHECK(player);
2501         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
2502
2503         if (stream_type == NULL || stream_index < 0) {
2504                 LOGE("invalid parameter %p %d", stream_type, stream_index);
2505                 return PLAYER_ERROR_INVALID_PARAMETER;
2506         }
2507
2508         ret = mm_player_set_sound_stream_info(handle->mm_handle, stream_type, stream_index);
2509         if (ret != MM_ERROR_NONE)
2510                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2511
2512         return PLAYER_ERROR_NONE;
2513 }
2514
2515 int legacy_player_get_timeout_for_muse(player_h player, int *timeout)
2516 {
2517         player_s *handle = (player_s *)player;
2518         int ret = MM_ERROR_NONE;
2519         PLAYER_INSTANCE_CHECK(player);
2520
2521         ret = mm_player_get_timeout(handle->mm_handle, timeout);
2522         if (ret != MM_ERROR_NONE)
2523                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2524
2525         return PLAYER_ERROR_NONE;
2526 }
2527
2528 int legacy_player_get_num_of_video_out_buffers(player_h player, int *num, int *extra_num)
2529 {
2530         player_s *handle = (player_s *)player;
2531         int ret = MM_ERROR_NONE;
2532         PLAYER_INSTANCE_CHECK(player);
2533         PLAYER_NULL_ARG_CHECK(num);
2534         PLAYER_NULL_ARG_CHECK(extra_num);
2535
2536         ret = mm_player_get_num_of_video_out_buffers(handle->mm_handle, num, extra_num);
2537         if (ret != MM_ERROR_NONE)
2538                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2539
2540         return PLAYER_ERROR_NONE;
2541 }
2542
2543 int legacy_player_manage_external_storage_state(player_h player, int id, int state)
2544 {
2545         player_s *handle = (player_s *)player;
2546         int ret = MM_ERROR_NONE;
2547         PLAYER_INSTANCE_CHECK(player);
2548
2549         ret = mm_player_manage_external_storage_state(handle->mm_handle, id, state);
2550         if (ret != MM_ERROR_NONE)
2551                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2552
2553         return PLAYER_ERROR_NONE;
2554 }
2555
2556 int legacy_player_get_adaptive_variant_info(player_h player, int *num, char **var_info)
2557 {
2558         int ret = MM_ERROR_NONE;
2559         player_s *handle = (player_s *)player;
2560         PLAYER_INSTANCE_CHECK(player);
2561         PLAYER_NULL_ARG_CHECK(num);
2562         PLAYER_NULL_ARG_CHECK(var_info);
2563
2564         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2565                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2566                 return PLAYER_ERROR_INVALID_STATE;
2567         }
2568
2569         ret = mm_player_get_adaptive_variant_info(handle->mm_handle, num, var_info);
2570         if (ret != MM_ERROR_NONE)
2571                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2572
2573         return PLAYER_ERROR_NONE;
2574 }
2575
2576 int legacy_player_set_max_adaptive_variant_limit(player_h player, int bandwidth, int width, int height)
2577 {
2578         int ret = MM_ERROR_NONE;
2579         player_s *handle = (player_s *)player;
2580         PLAYER_INSTANCE_CHECK(player);
2581
2582         ret = mm_player_set_max_adaptive_variant_limit(handle->mm_handle, bandwidth, width, height);
2583         if (ret != MM_ERROR_NONE)
2584                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2585
2586         return PLAYER_ERROR_NONE;
2587 }
2588
2589 int legacy_player_get_max_adaptive_variant_limit(player_h player, int *bandwidth, int *width, int *height)
2590 {
2591         player_s *handle = (player_s *)player;
2592         int ret = MM_ERROR_NONE;
2593         PLAYER_INSTANCE_CHECK(player);
2594         PLAYER_NULL_ARG_CHECK(bandwidth);
2595         PLAYER_NULL_ARG_CHECK(width);
2596         PLAYER_NULL_ARG_CHECK(height);
2597
2598         ret = mm_player_get_max_adaptive_variant_limit(handle->mm_handle, bandwidth, width, height);
2599         if (ret != MM_ERROR_NONE)
2600                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2601
2602         return PLAYER_ERROR_NONE;
2603 }
2604
2605 int legacy_player_set_audio_only(player_h player, bool audio_only)
2606 {
2607         player_s *handle = (player_s *)player;
2608         int ret = MM_ERROR_NONE;
2609         PLAYER_INSTANCE_CHECK(player);
2610
2611         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2612                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2613                 return PLAYER_ERROR_INVALID_STATE;
2614         }
2615
2616         ret = mm_player_set_audio_only(handle->mm_handle, audio_only);
2617         if (ret != MM_ERROR_NONE)
2618                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2619
2620         return PLAYER_ERROR_NONE;
2621 }
2622
2623 int legacy_player_is_audio_only(player_h player, bool *paudio_only)
2624 {
2625         player_s *handle = (player_s *)player;
2626         int ret = MM_ERROR_NONE;
2627         bool audio_only = false;
2628         PLAYER_INSTANCE_CHECK(player);
2629         PLAYER_NULL_ARG_CHECK(paudio_only);
2630
2631         ret = mm_player_get_audio_only(handle->mm_handle, &audio_only);
2632         if (ret != MM_ERROR_NONE)
2633                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2634
2635         *paudio_only = audio_only;
2636         return PLAYER_ERROR_NONE;
2637 }
2638
2639 int legacy_player_set_streaming_buffering_time(player_h player, int buffer_ms, int rebuffer_ms)
2640 {
2641         player_s *handle = (player_s *)player;
2642         int ret = MM_ERROR_NONE;
2643         PLAYER_INSTANCE_CHECK(player);
2644         PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
2645
2646         ret = mm_player_set_streaming_buffering_time(handle->mm_handle, buffer_ms, rebuffer_ms);
2647         if (ret != MM_ERROR_NONE)
2648                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2649
2650         return PLAYER_ERROR_NONE;
2651 }
2652
2653 int legacy_player_get_streaming_buffering_time(player_h player, int *buffer_ms, int *rebuffer_ms)
2654 {
2655         player_s *handle = (player_s *)player;
2656         int ret = MM_ERROR_NONE;
2657         PLAYER_INSTANCE_CHECK(player);
2658         PLAYER_NULL_ARG_CHECK(buffer_ms);
2659         PLAYER_NULL_ARG_CHECK(rebuffer_ms);
2660
2661         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2662                 LOGE("[%s] PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
2663                 return PLAYER_ERROR_INVALID_STATE;
2664         }
2665
2666         ret = mm_player_get_streaming_buffering_time(handle->mm_handle, buffer_ms, rebuffer_ms);
2667         if (ret != MM_ERROR_NONE)
2668                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2669
2670         return PLAYER_ERROR_NONE;
2671 }
2672
2673 int legacy_player_360_is_content_spherical(player_h player, bool *is_spherical)
2674 {
2675         player_s *handle = (player_s *)player;
2676         int ret = MM_ERROR_NONE;
2677         PLAYER_INSTANCE_CHECK(player);
2678         PLAYER_NULL_ARG_CHECK(is_spherical);
2679
2680         if (!__player_state_validate(handle, PLAYER_STATE_READY)) {
2681                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2682                 return PLAYER_ERROR_INVALID_STATE;
2683         }
2684
2685         ret = mm_player_360_is_content_spherical(handle->mm_handle, is_spherical);
2686         if (ret != MM_ERROR_NONE)
2687                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2688
2689         return PLAYER_ERROR_NONE;
2690 }
2691
2692 int legacy_player_360_set_enabled(player_h player, bool enabled)
2693 {
2694         player_s *handle = (player_s *)player;
2695         int ret = MM_ERROR_NONE;
2696         PLAYER_INSTANCE_CHECK(player);
2697
2698         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2699                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2700                 return PLAYER_ERROR_INVALID_STATE;
2701         }
2702
2703         ret = mm_player_360_set_enabled(handle->mm_handle, enabled);
2704         if (ret != MM_ERROR_NONE)
2705                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2706
2707         return PLAYER_ERROR_NONE;
2708 }
2709
2710 int legacy_player_360_is_enabled(player_h player, bool *enabled)
2711 {
2712         player_s *handle = (player_s *)player;
2713         int ret = MM_ERROR_NONE;
2714         PLAYER_INSTANCE_CHECK(player);
2715         PLAYER_NULL_ARG_CHECK(enabled);
2716         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2717                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2718                 return PLAYER_ERROR_INVALID_STATE;
2719         }
2720
2721         ret = mm_player_360_is_enabled(handle->mm_handle, enabled);
2722         if (ret != MM_ERROR_NONE)
2723                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2724
2725         return PLAYER_ERROR_NONE;
2726 }
2727
2728 int legacy_player_360_set_direction_of_view(player_h player, float yaw, float pitch)
2729 {
2730         player_s *handle = (player_s *)player;
2731         int ret = MM_ERROR_NONE;
2732         PLAYER_INSTANCE_CHECK(player);
2733
2734         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2735                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2736                 return PLAYER_ERROR_INVALID_STATE;
2737         }
2738
2739         ret = mm_player_360_set_direction_of_view(handle->mm_handle, yaw, pitch);
2740         if (ret != MM_ERROR_NONE)
2741                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2742
2743         return PLAYER_ERROR_NONE;
2744 }
2745
2746 int legacy_player_360_get_direction_of_view(player_h player, float *yaw, float *pitch)
2747 {
2748         player_s *handle = (player_s *)player;
2749         int ret = MM_ERROR_NONE;
2750         PLAYER_INSTANCE_CHECK(player);
2751         PLAYER_NULL_ARG_CHECK(yaw);
2752         PLAYER_NULL_ARG_CHECK(pitch);
2753
2754         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2755                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2756                 return PLAYER_ERROR_INVALID_STATE;
2757         }
2758
2759         ret = mm_player_360_get_direction_of_view(handle->mm_handle, yaw, pitch);
2760         if (ret != MM_ERROR_NONE)
2761                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2762
2763         return PLAYER_ERROR_NONE;
2764 }
2765
2766 int legacy_player_360_set_zoom(player_h player, float level)
2767 {
2768         player_s *handle = (player_s *)player;
2769         int ret = MM_ERROR_NONE;
2770         PLAYER_INSTANCE_CHECK(player);
2771
2772         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2773                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2774                 return PLAYER_ERROR_INVALID_STATE;
2775         }
2776
2777         ret = mm_player_360_set_zoom(handle->mm_handle, level);
2778         if (ret != MM_ERROR_NONE)
2779                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2780
2781         return PLAYER_ERROR_NONE;
2782 }
2783
2784 int legacy_player_360_get_zoom(player_h player, float *level)
2785 {
2786         player_s *handle = (player_s *)player;
2787         int ret = MM_ERROR_NONE;
2788         PLAYER_INSTANCE_CHECK(player);
2789
2790         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2791                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2792                 return PLAYER_ERROR_INVALID_STATE;
2793         }
2794
2795         ret = mm_player_360_get_zoom(handle->mm_handle, level);
2796         if (ret != MM_ERROR_NONE)
2797                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2798
2799         return PLAYER_ERROR_NONE;
2800 }
2801
2802 int legacy_player_360_set_field_of_view(player_h player, int horizontal_degrees, int vertical_degrees)
2803 {
2804         player_s *handle = (player_s *)player;
2805         int ret = MM_ERROR_NONE;
2806         PLAYER_INSTANCE_CHECK(player);
2807
2808         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2809                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2810                 return PLAYER_ERROR_INVALID_STATE;
2811         }
2812
2813         ret = mm_player_360_set_field_of_view(handle->mm_handle, horizontal_degrees, vertical_degrees);
2814         if (ret != MM_ERROR_NONE)
2815                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2816
2817         return PLAYER_ERROR_NONE;
2818 }
2819
2820 int legacy_player_360_get_field_of_view(player_h player, int *horizontal_degrees, int *vertical_degrees)
2821 {
2822         player_s *handle = (player_s *)player;
2823         int ret = MM_ERROR_NONE;
2824         PLAYER_INSTANCE_CHECK(player);
2825         PLAYER_NULL_ARG_CHECK(horizontal_degrees);
2826         PLAYER_NULL_ARG_CHECK(vertical_degrees);
2827
2828         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2829                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2830                 return PLAYER_ERROR_INVALID_STATE;
2831         }
2832
2833         ret = mm_player_360_get_field_of_view(handle->mm_handle, horizontal_degrees, vertical_degrees);
2834         if (ret != MM_ERROR_NONE)
2835                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2836
2837         return PLAYER_ERROR_NONE;
2838 }
2839
2840 int legacy_player_set_replaygain_enabled(player_h player, bool enabled)
2841 {
2842         player_s *handle = (player_s *)player;
2843         int ret = MM_ERROR_NONE;
2844         PLAYER_INSTANCE_CHECK(player);
2845
2846         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2847                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2848                 return PLAYER_ERROR_INVALID_STATE;
2849         }
2850
2851         ret = mm_player_set_replaygain_enabled(handle->mm_handle, enabled);
2852         if (ret != MM_ERROR_NONE)
2853                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2854
2855         return PLAYER_ERROR_NONE;
2856 }
2857
2858 int legacy_player_is_replaygain_enabled(player_h player, bool *enabled)
2859 {
2860         player_s *handle = (player_s *)player;
2861         int ret = MM_ERROR_NONE;
2862         bool _enable;
2863         PLAYER_INSTANCE_CHECK(player);
2864         PLAYER_NULL_ARG_CHECK(enabled);
2865
2866         if (!__player_state_validate(handle, PLAYER_STATE_IDLE)) {
2867                 LOGE("PLAYER_ERROR_INVALID_STATE (0x%08x) : current state - %d", PLAYER_ERROR_INVALID_STATE, handle->state);
2868                 return PLAYER_ERROR_INVALID_STATE;
2869         }
2870
2871         ret = mm_player_is_replaygain_enabled(handle->mm_handle, &_enable);
2872         if (ret != MM_ERROR_NONE)
2873                 return __player_convert_error_code(ret, (char *)__FUNCTION__);
2874
2875         *enabled = _enable;
2876         return PLAYER_ERROR_NONE;
2877 }