/src/opus/silk/check_control_input.c
Line | Count | Source (jump to first uncovered line) |
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, are permitted provided that the following conditions |
5 | | 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 Internet Society, IETF or IETF Trust, nor the |
12 | | names of specific contributors, may be used to endorse or promote |
13 | | products derived from this software without specific prior written |
14 | | permission. |
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
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. |
26 | | ***********************************************************************/ |
27 | | |
28 | | #ifdef HAVE_CONFIG_H |
29 | | #include "config.h" |
30 | | #endif |
31 | | |
32 | | #include "main.h" |
33 | | #include "control.h" |
34 | | #include "errors.h" |
35 | | |
36 | | /* Check encoder control struct */ |
37 | | opus_int check_control_input( |
38 | | silk_EncControlStruct *encControl /* I Control structure */ |
39 | | ) |
40 | 0 | { |
41 | 0 | celt_assert( encControl != NULL ); |
42 | |
|
43 | 0 | if( ( ( encControl->API_sampleRate != 8000 ) && |
44 | 0 | ( encControl->API_sampleRate != 12000 ) && |
45 | 0 | ( encControl->API_sampleRate != 16000 ) && |
46 | 0 | ( encControl->API_sampleRate != 24000 ) && |
47 | 0 | ( encControl->API_sampleRate != 32000 ) && |
48 | 0 | ( encControl->API_sampleRate != 44100 ) && |
49 | 0 | ( encControl->API_sampleRate != 48000 ) ) || |
50 | 0 | ( ( encControl->desiredInternalSampleRate != 8000 ) && |
51 | 0 | ( encControl->desiredInternalSampleRate != 12000 ) && |
52 | 0 | ( encControl->desiredInternalSampleRate != 16000 ) ) || |
53 | 0 | ( ( encControl->maxInternalSampleRate != 8000 ) && |
54 | 0 | ( encControl->maxInternalSampleRate != 12000 ) && |
55 | 0 | ( encControl->maxInternalSampleRate != 16000 ) ) || |
56 | 0 | ( ( encControl->minInternalSampleRate != 8000 ) && |
57 | 0 | ( encControl->minInternalSampleRate != 12000 ) && |
58 | 0 | ( encControl->minInternalSampleRate != 16000 ) ) || |
59 | 0 | ( encControl->minInternalSampleRate > encControl->desiredInternalSampleRate ) || |
60 | 0 | ( encControl->maxInternalSampleRate < encControl->desiredInternalSampleRate ) || |
61 | 0 | ( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) { |
62 | 0 | celt_assert( 0 ); |
63 | 0 | return SILK_ENC_FS_NOT_SUPPORTED; |
64 | 0 | } |
65 | 0 | if( encControl->payloadSize_ms != 10 && |
66 | 0 | encControl->payloadSize_ms != 20 && |
67 | 0 | encControl->payloadSize_ms != 40 && |
68 | 0 | encControl->payloadSize_ms != 60 ) { |
69 | 0 | celt_assert( 0 ); |
70 | 0 | return SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; |
71 | 0 | } |
72 | 0 | if( encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100 ) { |
73 | 0 | celt_assert( 0 ); |
74 | 0 | return SILK_ENC_INVALID_LOSS_RATE; |
75 | 0 | } |
76 | 0 | if( encControl->useDTX < 0 || encControl->useDTX > 1 ) { |
77 | 0 | celt_assert( 0 ); |
78 | 0 | return SILK_ENC_INVALID_DTX_SETTING; |
79 | 0 | } |
80 | 0 | if( encControl->useCBR < 0 || encControl->useCBR > 1 ) { |
81 | 0 | celt_assert( 0 ); |
82 | 0 | return SILK_ENC_INVALID_CBR_SETTING; |
83 | 0 | } |
84 | 0 | if( encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1 ) { |
85 | 0 | celt_assert( 0 ); |
86 | 0 | return SILK_ENC_INVALID_INBAND_FEC_SETTING; |
87 | 0 | } |
88 | 0 | if( encControl->nChannelsAPI < 1 || encControl->nChannelsAPI > ENCODER_NUM_CHANNELS ) { |
89 | 0 | celt_assert( 0 ); |
90 | 0 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
91 | 0 | } |
92 | 0 | if( encControl->nChannelsInternal < 1 || encControl->nChannelsInternal > ENCODER_NUM_CHANNELS ) { |
93 | 0 | celt_assert( 0 ); |
94 | 0 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
95 | 0 | } |
96 | 0 | if( encControl->nChannelsInternal > encControl->nChannelsAPI ) { |
97 | 0 | celt_assert( 0 ); |
98 | 0 | return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR; |
99 | 0 | } |
100 | 0 | if( encControl->complexity < 0 || encControl->complexity > 10 ) { |
101 | 0 | celt_assert( 0 ); |
102 | 0 | return SILK_ENC_INVALID_COMPLEXITY_SETTING; |
103 | 0 | } |
104 | | |
105 | 0 | return SILK_NO_ERROR; |
106 | 0 | } |