2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <unique_ptr.h>
19 #include <FBaseSysLog.h>
20 #include "FMedia_PlayerEvent.h"
21 #include "FMedia_PlayerVideoEvent.h"
22 #include "FMedia_PlayerEventTypes.h"
23 #include "FMedia_PlayerVideoEventTypes.h"
24 #include "FMedia_PlayerImpl.h"
25 #include "FMedia_AudioEqualizerImpl.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
31 namespace Tizen { namespace Media
34 _AudioEqualizerImpl::_AudioEqualizerImpl(void):__pPlayerImpl(null)
39 _AudioEqualizerImpl::~_AudioEqualizerImpl(void)
45 _AudioEqualizerImpl::Construct(Player& player)
48 __pPlayerImpl = _PlayerImpl::GetInstance(&player);
49 SysAssertf(__pPlayerImpl != null, "Not yet Player::Construct() called! Player::Construct() should be called before use");
50 SysAssertf(__pPlayerImpl->__hPlayer != null, "Not yet Player handle assigned.");
51 __hPlayer = __pPlayerImpl->__hPlayer;
52 SysTryCatch(NID_MEDIA, GetBandCount() != 0, r = E_UNSUPPORTED_OPERATION, E_UNSUPPORTED_OPERATION,
53 "[E_UNSUPPORTED_OPERATION] Failed to construct _AudioEqualizerImpl");
62 _AudioEqualizerImpl::GetBandCount(void) const
64 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
65 int ret = PLAYER_ERROR_NONE;
69 ret = player_audio_effect_get_equalizer_bands_count(__hPlayer, &count);
70 r = MapExceptionToResult(ret);
71 SysTryLog(NID_MEDIA, r == E_SUCCESS, "[%s] Failed to perform GetBandCount operation.", GetErrorMessage(r));
77 _AudioEqualizerImpl::GetBandLevelRange(int index, int& minValue, int& maxValue) const
79 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
80 int ret = PLAYER_ERROR_NONE;
84 count = GetBandCount();
85 SysTryReturn(NID_MEDIA, index >= 0 && index < count , E_INVALID_ARG, E_INVALID_ARG,
86 "[E_INVALID_ARG] invalid argument is used. index = %d", index);
87 ret = player_audio_effect_get_equalizer_level_range(__hPlayer, &minValue, &maxValue);
88 r = MapExceptionToResult(ret);
93 _AudioEqualizerImpl::SetBandLevel(int index, int level)
95 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
96 int ret = PLAYER_ERROR_NONE;
102 count = GetBandCount();
103 SysTryReturn(NID_MEDIA, index >= 0 && index < count , E_INVALID_ARG, E_INVALID_ARG,
104 "[E_INVALID_ARG] invalid argument is used. index = %d", index);
105 r = GetBandLevelRange(index, minValue, maxValue);
107 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "%s error has been occurred in GetBandLevelRange", GetErrorMessage(r));
108 SysTryReturn(NID_MEDIA, (level <= maxValue) && (level >= minValue), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
109 "[E_OUT_OF_RANGE] Equalizer level %d is out of range.", level );
110 ret = player_audio_effect_set_equalizer_band_level(__hPlayer, index, level);
111 r = MapExceptionToResult(ret);
116 _AudioEqualizerImpl::SetAllBandsLevel(const Tizen::Base::Collection::IListT<int>* pLevels)
118 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
119 int ret = PLAYER_ERROR_NONE;
120 result r = E_SUCCESS;
121 std::unique_ptr<int[]> pArray;
124 int totalBandCount = 0;
125 totalBandCount = GetBandCount();
128 listCount = pLevels->GetCount();
130 SysTryReturn(NID_MEDIA, listCount == totalBandCount, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. pLevels");
132 pArray.reset(new (std::nothrow) int[listCount]);
133 SysTryReturn(NID_MEDIA, pArray.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory Allocation Failed");
135 for(int i=0; i<listCount; i++)
137 pLevels->GetAt(i,level);
138 (pArray.get())[i] = level;
141 ret = player_audio_effect_set_equalizer_all_bands(__hPlayer, pArray.get(), listCount);
142 r = MapExceptionToResult(ret);
147 _AudioEqualizerImpl::GetBandLevel(int index, int& level) const
149 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
150 int ret = PLAYER_ERROR_NONE;
151 result r = E_SUCCESS;
154 count = GetBandCount();
155 SysTryReturn(NID_MEDIA, index >= 0 && index < count , E_INVALID_ARG, E_INVALID_ARG,
156 "[E_INVALID_ARG] Invalid argument is used. Index = %d", index);
157 ret = player_audio_effect_get_equalizer_band_level(__hPlayer, index, &level);
158 r = MapExceptionToResult(ret);
164 _AudioEqualizerImpl::GetBandCenterFrequency(int index, int& frequency) const
166 //Not supported by SLP presently
167 result r = E_SUCCESS;
168 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
169 int ret = PLAYER_ERROR_NONE;
170 ret = player_audio_effect_get_equalizer_band_frequency(__hPlayer, index, &frequency);
171 r = MapExceptionToResult(ret);
172 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] player_audio_effect_get_equlizer_band_frequency", GetErrorMessage(r));
177 _AudioEqualizerImpl::ResetAllToDefault(void)
179 SysAssertf(__hPlayer != null, "Not yet constructed! Construct() should be called before use");
180 int ret = PLAYER_ERROR_NONE;
181 result r = E_SUCCESS;
182 ret = player_audio_effect_equalizer_clear(__hPlayer);
183 r = MapExceptionToResult(ret);
188 _AudioEqualizerImpl::MapExceptionToResult(int reason)
192 case PLAYER_ERROR_NONE:
196 case PLAYER_ERROR_OUT_OF_MEMORY:
197 return E_OUT_OF_MEMORY;
200 case PLAYER_ERROR_INVALID_PARAMETER:
201 return E_INVALID_ARG;
204 case PLAYER_ERROR_INVALID_STATE:
205 case PLAYER_ERROR_INVALID_OPERATION:
206 return E_INVALID_OPERATION;