blob: 0a8d7269afd36d2accdd5745db8d5c197fcd8fa7 [file] [log] [blame]
Gregory Maxwellae231142011-07-30 08:18:48 -04001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, (subject to the limitations in the disclaimer below)
5are permitted provided that the following conditions are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Skype Limited, nor the names of specific
12contributors, may be used to endorse or promote products derived from
13this software without specific prior written permission.
14NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
Jean-Marc Valin5a484122011-08-15 10:49:53 -040028#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
Jean-Marc Valin1c2f5632011-09-16 01:16:53 -070032#include "main.h"
33#include "control.h"
34#include "errors.h"
Gregory Maxwellae231142011-07-30 08:18:48 -040035
36/* Check encoder control struct */
37opus_int check_control_input(
38 silk_EncControlStruct *encControl /* I: Control structure */
39)
40{
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070041 silk_assert( encControl != NULL );
Gregory Maxwellae231142011-07-30 08:18:48 -040042
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 Valinfb3a4372011-09-16 00:58:26 -070062 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040063 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 Valinfb3a4372011-09-16 00:58:26 -070069 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040070 return SILK_ENC_PACKET_SIZE_NOT_SUPPORTED;
71 }
72 if( encControl->packetLossPercentage < 0 || encControl->packetLossPercentage > 100 ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070073 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040074 return SILK_ENC_INVALID_LOSS_RATE;
75 }
76 if( encControl->useDTX < 0 || encControl->useDTX > 1 ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070077 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040078 return SILK_ENC_INVALID_DTX_SETTING;
79 }
80 if( encControl->useCBR < 0 || encControl->useCBR > 1 ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070081 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040082 return SILK_ENC_INVALID_CBR_SETTING;
83 }
84 if( encControl->useInBandFEC < 0 || encControl->useInBandFEC > 1 ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070085 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040086 return SILK_ENC_INVALID_INBAND_FEC_SETTING;
87 }
88 if( encControl->nChannelsAPI < 1 || encControl->nChannelsAPI > ENCODER_NUM_CHANNELS ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070089 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040090 return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR;
91 }
92 if( encControl->nChannelsInternal < 1 || encControl->nChannelsInternal > ENCODER_NUM_CHANNELS ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070093 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040094 return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR;
95 }
96 if( encControl->nChannelsInternal > encControl->nChannelsAPI ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070097 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -040098 return SILK_ENC_INVALID_NUMBER_OF_CHANNELS_ERROR;
99 }
100 if( encControl->complexity < 0 || encControl->complexity > 10 ) {
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700101 silk_assert( 0 );
Gregory Maxwellae231142011-07-30 08:18:48 -0400102 return SILK_ENC_INVALID_COMPLEXITY_SETTING;
103 }
104
105 return SILK_NO_ERROR;
106}