1 /******************************************************************************
2  *
3  *  Copyright 2014 The Android Open Source Project
4  *  Copyright 2006 Open Interface North America, Inc. All rights reserved.
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 
20 /*******************************************************************************
21   $Revision: #1 $
22  ******************************************************************************/
23 
24 /**
25 @file
26 This file exposes OINA-specific interfaces to decoder functions.
27 
28 @ingroup codec_internal
29 */
30 
31 /**
32 @addtogroup codec_internal
33 @{
34 */
35 
36 #include <oi_codec_sbc_private.h>
37 
OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT * context,OI_BOOL enhanced,uint8_t frequency,uint8_t mode,uint8_t subbands,uint8_t blocks,uint8_t alloc,uint8_t maxBitpool)38 OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT* context, OI_BOOL enhanced,
39                                            uint8_t frequency, uint8_t mode, uint8_t subbands,
40                                            uint8_t blocks, uint8_t alloc, uint8_t maxBitpool) {
41   if (frequency > SBC_FREQ_48000) {
42     return OI_STATUS_INVALID_PARAMETERS;
43   }
44 
45   if (enhanced) {
46 #ifdef SBC_ENHANCED
47     if (subbands != SBC_SUBBANDS_8) {
48       return OI_STATUS_INVALID_PARAMETERS;
49     }
50 #else
51     return OI_STATUS_INVALID_PARAMETERS;
52 #endif
53   }
54 
55   if (mode > SBC_JOINT_STEREO) {
56     return OI_STATUS_INVALID_PARAMETERS;
57   }
58 
59   if (subbands > SBC_SUBBANDS_8) {
60     return OI_STATUS_INVALID_PARAMETERS;
61   }
62 
63   if (blocks > SBC_BLOCKS_15) {
64     return OI_STATUS_INVALID_PARAMETERS;
65   }
66 
67   if (alloc > SBC_SNR) {
68     return OI_STATUS_INVALID_PARAMETERS;
69   }
70 
71 #ifdef SBC_ENHANCED
72   context->common.frameInfo.enhanced = enhanced;
73 #else
74   context->common.frameInfo.enhanced = FALSE;
75 #endif
76   context->common.frameInfo.freqIndex = frequency;
77   context->common.frameInfo.mode = mode;
78   context->common.frameInfo.subbands = subbands;
79   context->common.frameInfo.blocks = blocks;
80   context->common.frameInfo.alloc = alloc;
81   context->common.frameInfo.bitpool = maxBitpool;
82 
83   OI_SBC_ExpandFrameFields(&context->common.frameInfo);
84 
85   if (context->common.frameInfo.nrof_channels >= context->common.pcmStride) {
86     return OI_STATUS_INVALID_PARAMETERS;
87   }
88 
89   return OI_OK;
90 }
91 
OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT * context,uint8_t bitpool,const OI_BYTE ** frameData,uint32_t * frameBytes,int16_t * pcmData,uint32_t * pcmBytes)92 OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT* context, uint8_t bitpool,
93                                  const OI_BYTE** frameData, uint32_t* frameBytes, int16_t* pcmData,
94                                  uint32_t* pcmBytes) {
95   return internal_DecodeRaw(context, bitpool, frameData, frameBytes, pcmData, pcmBytes);
96 }
97 
OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT * context,OI_BOOL enhanced,uint8_t subbands)98 OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT* context, OI_BOOL enhanced,
99                                     uint8_t subbands) {
100   if (enhanced) {
101 #ifdef SBC_ENHANCED
102     context->enhancedEnabled = TRUE;
103 #else
104     context->enhancedEnabled = FALSE;
105 #endif
106   } else {
107     context->enhancedEnabled = FALSE;
108   }
109   context->restrictSubbands = subbands;
110   context->limitFrameFormat = TRUE;
111   return OI_OK;
112 }
113 
114 /**
115 @}
116 */
117