IRatePitch.c revision d2a7f0d6883a6d3835642e7b282f05ed1c54fe63
161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten/*
261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * Copyright (C) 2010 The Android Open Source Project
361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *
461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * Licensed under the Apache License, Version 2.0 (the "License");
561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * you may not use this file except in compliance with the License.
661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * You may obtain a copy of the License at
761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *
861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *      http://www.apache.org/licenses/LICENSE-2.0
961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten *
1061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * Unless required by applicable law or agreed to in writing, software
1161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * distributed under the License is distributed on an "AS IS" BASIS,
1261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * See the License for the specific language governing permissions and
1461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten * limitations under the License.
1561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten */
1661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
1761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten/* RatePitch implementation */
1861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
1961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten#include "sles_allinclusive.h"
2061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
2161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenstatic SLresult IRatePitch_SetRate(SLRatePitchItf self, SLpermille rate)
2261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
2361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch *this = (IRatePitch *) self;
24d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    if (!(this->mMinRate <= rate && rate <= this->mMaxRate))
25d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten        return SL_RESULT_PARAMETER_INVALID;
2661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    interface_lock_poke(this);
2761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    this->mRate = rate;
2861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    interface_unlock_poke(this);
2961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    return SL_RESULT_SUCCESS;
3061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
3161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
3261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenstatic SLresult IRatePitch_GetRate(SLRatePitchItf self, SLpermille *pRate)
3361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
3461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    if (NULL == pRate)
3561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten        return SL_RESULT_PARAMETER_INVALID;
3661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch *this = (IRatePitch *) self;
3761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    interface_lock_peek(this);
3861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    SLpermille rate = this->mRate;
3961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    interface_unlock_peek(this);
4061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    *pRate = rate;
4161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    return SL_RESULT_SUCCESS;
4261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
4361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
4461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenstatic SLresult IRatePitch_GetRatePitchCapabilities(SLRatePitchItf self,
4561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    SLpermille *pMinRate, SLpermille *pMaxRate)
4661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
47d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    // per spec, each is optional, and does not require that at least one must be non-NULL
48d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten#if 0
49d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    if (NULL == pMinRate && NULL == pMaxRate)
5061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten        return SL_RESULT_PARAMETER_INVALID;
51d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten#endif
5261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch *this = (IRatePitch *) self;
53d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    // const, so no lock required
5461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    SLpermille minRate = this->mMinRate;
5561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    SLpermille maxRate = this->mMaxRate;
56d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    if (NULL != pMinRate)
57d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten        *pMinRate = minRate;
58d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    if (NULL != pMaxRate)
59d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten        *pMaxRate = maxRate;
6061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    return SL_RESULT_SUCCESS;
6161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
6261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
6361ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenstatic const struct SLRatePitchItf_ IRatePitch_Itf = {
6461ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch_SetRate,
6561ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch_GetRate,
6661ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch_GetRatePitchCapabilities
6761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten};
6861ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten
6961ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kastenvoid IRatePitch_init(void *self)
7061ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten{
7161ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    IRatePitch *this = (IRatePitch *) self;
7261ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten    this->mItf = &IRatePitch_Itf;
730b167267bda99b68346045ccab14e810121d5de4Glenn Kasten    this->mRate = 0;
74d2a7f0d6883a6d3835642e7b282f05ed1c54fe63Glenn Kasten    // const
750b167267bda99b68346045ccab14e810121d5de4Glenn Kasten    this->mMinRate = 500;
760b167267bda99b68346045ccab14e810121d5de4Glenn Kasten    this->mMaxRate = 2000;
7761ac0ade16f84d877dfd8d0e984eb203d4a2901dGlenn Kasten}
78