2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <mm_player.h>
24 #include <mm_player_internal.h>
27 #include <player_internal.h>
28 #include <player_private.h>
34 #define PLAYER_SET_CALLBACK(event_type, handle, callback, user_data) \
37 PLAYER_INSTANCE_CHECK(handle); \
38 PLAYER_NULL_ARG_CHECK(callback); \
39 handle->user_cb[event_type] = callback; \
40 handle->user_data[event_type] = user_data; \
41 LOGI("[%s] Event type : %d ",__FUNCTION__, event_type); \
44 bool __audio_stream_callback_ex(MMPlayerAudioStreamDataType *stream, void *user_data)
46 player_s * handle = (player_s*)user_data;
48 if (!__player_state_validate(handle, PLAYER_STATE_READY))
50 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d" ,__FUNCTION__,PLAYER_ERROR_INVALID_STATE, handle->state);
54 if( handle->user_cb[_PLAYER_EVENT_TYPE_AUDIO_FRAME] )
56 ((player_audio_pcm_extraction_cb)handle->user_cb[_PLAYER_EVENT_TYPE_AUDIO_FRAME])((player_audio_raw_data_s *)stream, handle->user_data[_PLAYER_EVENT_TYPE_AUDIO_FRAME]);
61 int player_set_pcm_extraction_mode(player_h player, bool sync, player_audio_pcm_extraction_cb callback, void *user_data)
63 PLAYER_INSTANCE_CHECK(player);
64 PLAYER_NULL_ARG_CHECK(callback);
65 player_s * handle = (player_s *) player;
66 int ret = MM_ERROR_NONE;
68 PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
70 ret = mm_player_set_attribute(handle->mm_handle, NULL, "pcm_extraction",TRUE, "pcm_extraction_start_msec", 0, "pcm_extraction_end_msec", 0, NULL);
71 if(ret != MM_ERROR_NONE)
72 return __player_convert_error_code(ret,(char*)__FUNCTION__);
74 ret = mm_player_set_audio_stream_callback_ex(handle->mm_handle, sync, __audio_stream_callback_ex, (void*)handle);
75 if(ret != MM_ERROR_NONE)
76 return __player_convert_error_code(ret,(char*)__FUNCTION__);
78 PLAYER_SET_CALLBACK(_PLAYER_EVENT_TYPE_AUDIO_FRAME, handle, callback, user_data);
79 return PLAYER_ERROR_NONE;
82 int player_set_pcm_spec(player_h player, const char *format, int samplerate, int channel)
84 PLAYER_INSTANCE_CHECK(player);
86 player_s * handle = (player_s *) player;
87 int ret = MM_ERROR_NONE;
89 LOGE("[%s] player_set_pcm_spec %s %d %d", __FUNCTION__, format, samplerate, channel);
90 ret = mm_player_set_attribute(handle->mm_handle, NULL, "pcm_audioformat", format , strlen(format), NULL);
91 if(ret != MM_ERROR_NONE)
92 return __player_convert_error_code(ret,(char*)__FUNCTION__);
94 ret = mm_player_set_pcm_spec(handle->mm_handle, samplerate, channel);
95 if(ret != MM_ERROR_NONE)
96 return __player_convert_error_code(ret,(char*)__FUNCTION__);
98 return PLAYER_ERROR_NONE;
101 int player_set_streaming_playback_rate(player_h player, float rate)
103 LOGI("[%s] rate : %0.1f", __FUNCTION__, rate);
104 PLAYER_INSTANCE_CHECK(player);
105 player_s * handle = (player_s *) player;
107 if (!__player_state_validate(handle, PLAYER_STATE_READY))
109 LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d" ,__FUNCTION__,PLAYER_ERROR_INVALID_STATE, handle->state);
110 return PLAYER_ERROR_INVALID_STATE;
113 int ret = mm_player_set_play_speed(handle->mm_handle, rate, TRUE);
118 case MM_ERROR_PLAYER_NO_OP:
119 ret = PLAYER_ERROR_NONE;
121 case MM_ERROR_NOT_SUPPORT_API:
122 case MM_ERROR_PLAYER_SEEK:
123 LOGE("[%s] PLAYER_ERROR_INVALID_OPERATION(0x%08x) : seek error",__FUNCTION__, PLAYER_ERROR_INVALID_OPERATION);
124 ret = PLAYER_ERROR_INVALID_OPERATION;
127 return __player_convert_error_code(ret,(char*)__FUNCTION__);