Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame^] | 1 | /*********************************************************************** |
| 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
| 3 | Redistribution and use in source and binary forms, with or without |
| 4 | modification, (subject to the limitations in the disclaimer below) |
| 5 | are permitted provided that the following conditions are met: |
| 6 | - Redistributions of source code must retain the above copyright notice, |
| 7 | this list of conditions and the following disclaimer. |
| 8 | - Redistributions in binary form must reproduce the above copyright |
| 9 | notice, this list of conditions and the following disclaimer in the |
| 10 | documentation and/or other materials provided with the distribution. |
| 11 | - Neither the name of Skype Limited, nor the names of specific |
| 12 | contributors, may be used to endorse or promote products derived from |
| 13 | this software without specific prior written permission. |
| 14 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED |
| 15 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 16 | CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, |
| 17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 22 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | ***********************************************************************/ |
| 27 | |
| 28 | #include "silk_main.h" |
| 29 | #include "silk_control.h" |
| 30 | #include "silk_errors.h" |
| 31 | |
| 32 | /* Check encoder control struct */ |
| 33 | opus_int check_control_input( |
| 34 | silk_EncControlStruct *encControl /* I: Control structure */ |
| 35 | ) |
| 36 | { |
| 37 | SKP_assert( encControl != NULL ); |
| 38 | |
| 39 | if( ( ( encControl->API_sampleRate != 8000 ) && |
| 40 | ( encControl->API_sampleRate != 12000 ) && |
| 41 | ( encControl->API_sampleRate != 16000 ) && |
| 42 | ( encControl->API_sampleRate != 24000 ) && |
| 43 | ( encControl->API_sampleRate != 32000 ) && |
| 44 | ( encControl->API_sampleRate != 44100 ) && |
| 45 | ( encControl->API_sampleRate != 48000 ) ) || |
| 46 | ( ( encControl->desiredInternalSampleRate != 8000 ) && |
| 47 | ( encControl->desiredInternalSampleRate != 12000 ) && |
| 48 | ( encControl->desiredInternalSampleRate != 16000 ) ) || |
| 49 | ( ( encControl->maxInternalSampleRate != 8000 ) && |
| 50 | ( encControl->maxInternalSampleRate != 12000 ) && |
| 51 | ( encControl->maxInternalSampleRate != 16000 ) ) || |
| 52 | ( ( encControl->minInternalSampleRate != 8000 ) && |
| 53 | ( encControl->minInternalSampleRate != 12000 ) && |
| 54 | ( encControl->minInternalSampleRate != 16000 ) ) || |
| 55 | ( encControl->minInternalSampleRate > encControl->desiredInternalSampleRate ) || |
| 56 | ( encControl->maxInternalSampleRate < encControl->desiredInternalSampleRate ) || |
| 57 | ( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) { |
| 58 | SKP_assert( 0 ); |
| 59 | return SILK_ENC_FS_NOT_SUPPORTED; |
| 60 | } |
| 61 | if( encControl->payloadSize_ms != 10 && |
| 62 | encControl->payloadSize_ms != 20 && |
| 63 | encControl->payloadSize_ms != 40 && |
| 64 | encControl->payloadSize_ms != 60 ) { |
| 65 | SKP_assert( 0 ); |
| 66 | return SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; |
| 67 | } |
| 68 | if( encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100 ) { |
| 69 | SKP_assert( 0 ); |
| 70 | return SILK_ENC_INVALID_LOSS_RATE; |
| 71 | } |
| 72 | if( encControl->useDTX < 0 || encControl->useDTX > 1 ) { |
| 73 | SKP_assert( 0 ); |
| 74 | return SILK_ENC_INVALID_DTX_SETTING; |
| 75 | } |
| 76 | if( encControl->useCBR < 0 || encControl->useCBR > 1 ) { |
| 77 | SKP_assert( 0 ); |
| 78 | return SILK_ENC_INVALID_CBR_SETTING; |
| 79 | } |
| 80 | if( encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1 ) { |
| 81 | SKP_assert( 0 ); |
| 82 | return SILK_ENC_INVALID_INBAND_FEC_SETTING; |
| 83 | } |
| 84 | if( encControl->nChannelsAPI < 1 || encControl->nChannelsAPI > ENCODER_NUM_CHANNELS ) { |
| 85 | SKP_assert( 0 ); |
| 86 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
| 87 | } |
| 88 | if( encControl->nChannelsInternal < 1 || encControl->nChannelsInternal > ENCODER_NUM_CHANNELS ) { |
| 89 | SKP_assert( 0 ); |
| 90 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
| 91 | } |
| 92 | if( encControl->nChannelsInternal > encControl->nChannelsAPI ) { |
| 93 | SKP_assert( 0 ); |
| 94 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
| 95 | } |
| 96 | if( encControl->complexity < 0 || encControl->complexity > 10 ) { |
| 97 | SKP_assert( 0 ); |
| 98 | return SILK_ENC_INVALID_COMPLEXITY_SETTING; |
| 99 | } |
| 100 | |
| 101 | return SILK_NO_ERROR; |
| 102 | } |