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 |
Jean-Marc Valin | ae00e60 | 2012-04-20 16:31:04 -0400 | [diff] [blame] | 4 | modification, are permitted provided that the following conditions |
| 5 | are met: |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 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. |
Ralph Giles | f2446c2 | 2013-09-16 14:40:04 -0700 | [diff] [blame] | 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the |
Jean-Marc Valin | ae00e60 | 2012-04-20 16:31:04 -0400 | [diff] [blame] | 12 | names of specific contributors, may be used to endorse or promote |
| 13 | products derived from this software without specific prior written |
| 14 | permission. |
Timothy B. Terriberry | 80ad383 | 2013-05-19 18:00:39 -0700 | [diff] [blame] | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Jean-Marc Valin | ae00e60 | 2012-04-20 16:31:04 -0400 | [diff] [blame] | 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | POSSIBILITY OF SUCH DAMAGE. |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 26 | ***********************************************************************/ |
| 27 | |
Jean-Marc Valin | 5a48412 | 2011-08-15 10:49:53 -0400 | [diff] [blame] | 28 | #ifdef HAVE_CONFIG_H |
| 29 | #include "config.h" |
| 30 | #endif |
| 31 | |
Jean-Marc Valin | 1c2f563 | 2011-09-16 01:16:53 -0700 | [diff] [blame] | 32 | #include "main.h" |
| 33 | #include "control.h" |
| 34 | #include "errors.h" |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 35 | |
| 36 | /* Check encoder control struct */ |
| 37 | opus_int check_control_input( |
Koen Vos | acc7a6c | 2011-10-28 19:44:26 -0400 | [diff] [blame] | 38 | silk_EncControlStruct *encControl /* I Control structure */ |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 39 | ) |
| 40 | { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 41 | celt_assert( encControl != NULL ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 42 | |
| 43 | if( ( ( encControl->API_sampleRate != 8000 ) && |
| 44 | ( encControl->API_sampleRate != 12000 ) && |
| 45 | ( encControl->API_sampleRate != 16000 ) && |
| 46 | ( encControl->API_sampleRate != 24000 ) && |
| 47 | ( encControl->API_sampleRate != 32000 ) && |
| 48 | ( encControl->API_sampleRate != 44100 ) && |
| 49 | ( encControl->API_sampleRate != 48000 ) ) || |
| 50 | ( ( encControl->desiredInternalSampleRate != 8000 ) && |
| 51 | ( encControl->desiredInternalSampleRate != 12000 ) && |
| 52 | ( encControl->desiredInternalSampleRate != 16000 ) ) || |
| 53 | ( ( encControl->maxInternalSampleRate != 8000 ) && |
| 54 | ( encControl->maxInternalSampleRate != 12000 ) && |
| 55 | ( encControl->maxInternalSampleRate != 16000 ) ) || |
| 56 | ( ( encControl->minInternalSampleRate != 8000 ) && |
| 57 | ( encControl->minInternalSampleRate != 12000 ) && |
| 58 | ( encControl->minInternalSampleRate != 16000 ) ) || |
| 59 | ( encControl->minInternalSampleRate > encControl->desiredInternalSampleRate ) || |
| 60 | ( encControl->maxInternalSampleRate < encControl->desiredInternalSampleRate ) || |
| 61 | ( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 62 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 63 | return SILK_ENC_FS_NOT_SUPPORTED; |
| 64 | } |
| 65 | if( encControl->payloadSize_ms != 10 && |
| 66 | encControl->payloadSize_ms != 20 && |
| 67 | encControl->payloadSize_ms != 40 && |
| 68 | encControl->payloadSize_ms != 60 ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 69 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 70 | return SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; |
| 71 | } |
| 72 | if( encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100 ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 73 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 74 | return SILK_ENC_INVALID_LOSS_RATE; |
| 75 | } |
| 76 | if( encControl->useDTX < 0 || encControl->useDTX > 1 ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 77 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 78 | return SILK_ENC_INVALID_DTX_SETTING; |
| 79 | } |
| 80 | if( encControl->useCBR < 0 || encControl->useCBR > 1 ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 81 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 82 | return SILK_ENC_INVALID_CBR_SETTING; |
| 83 | } |
| 84 | if( encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1 ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 85 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 86 | return SILK_ENC_INVALID_INBAND_FEC_SETTING; |
| 87 | } |
| 88 | if( encControl->nChannelsAPI < 1 || encControl->nChannelsAPI > ENCODER_NUM_CHANNELS ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 89 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 90 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
| 91 | } |
| 92 | if( encControl->nChannelsInternal < 1 || encControl->nChannelsInternal > ENCODER_NUM_CHANNELS ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 93 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 94 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
| 95 | } |
| 96 | if( encControl->nChannelsInternal > encControl->nChannelsAPI ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 97 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 98 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
| 99 | } |
| 100 | if( encControl->complexity < 0 || encControl->complexity > 10 ) { |
Jean-Marc Valin | 7e3352e | 2018-03-24 02:16:15 -0400 | [diff] [blame] | 101 | celt_assert( 0 ); |
Gregory Maxwell | ae23114 | 2011-07-30 08:18:48 -0400 | [diff] [blame] | 102 | return SILK_ENC_INVALID_COMPLEXITY_SETTING; |
| 103 | } |
| 104 | |
| 105 | return SILK_NO_ERROR; |
| 106 | } |