1 /******************************************************************************
2  *
3  *  Copyright (C) 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 "common/bt_target.h"
37 #include <oi_codec_sbc_private.h>
38 
39 #if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE)
40 
OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT * context,OI_BOOL enhanced,OI_UINT8 frequency,OI_UINT8 mode,OI_UINT8 subbands,OI_UINT8 blocks,OI_UINT8 alloc,OI_UINT8 maxBitpool)41 OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
42         OI_BOOL enhanced,
43         OI_UINT8 frequency,
44         OI_UINT8 mode,
45         OI_UINT8 subbands,
46         OI_UINT8 blocks,
47         OI_UINT8 alloc,
48         OI_UINT8 maxBitpool)
49 {
50     if (frequency > SBC_FREQ_48000) {
51         return OI_STATUS_INVALID_PARAMETERS;
52     }
53 
54     if (enhanced) {
55 #ifdef SBC_ENHANCED
56         if (subbands != SBC_SUBBANDS_8) {
57             return OI_STATUS_INVALID_PARAMETERS;
58         }
59 #else
60         return OI_STATUS_INVALID_PARAMETERS;
61 #endif
62     }
63 
64     if (mode > SBC_JOINT_STEREO) {
65         return OI_STATUS_INVALID_PARAMETERS;
66     }
67 
68     if (subbands > SBC_SUBBANDS_8) {
69         return OI_STATUS_INVALID_PARAMETERS;
70     }
71 
72     if (blocks > SBC_BLOCKS_16) {
73         return OI_STATUS_INVALID_PARAMETERS;
74     }
75 
76     if (alloc > SBC_SNR) {
77         return OI_STATUS_INVALID_PARAMETERS;
78     }
79 
80 #ifdef SBC_ENHANCED
81     context->common.frameInfo.enhanced = enhanced;
82 #else
83     context->common.frameInfo.enhanced = FALSE;
84 #endif
85     context->common.frameInfo.freqIndex = frequency;
86     context->common.frameInfo.mode = mode;
87     context->common.frameInfo.subbands = subbands;
88     context->common.frameInfo.blocks = blocks;
89     context->common.frameInfo.alloc = alloc;
90     context->common.frameInfo.bitpool = maxBitpool;
91 
92     OI_SBC_ExpandFrameFields(&context->common.frameInfo);
93 
94     if (context->common.frameInfo.nrof_channels >= context->common.pcmStride) {
95         return OI_STATUS_INVALID_PARAMETERS;
96     }
97 
98     return OI_OK;
99 }
100 
101 
102 
OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT * context,OI_UINT8 bitpool,const OI_BYTE ** frameData,OI_UINT32 * frameBytes,OI_INT16 * pcmData,OI_UINT32 * pcmBytes)103 OI_STATUS OI_CODEC_SBC_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
104                                  OI_UINT8 bitpool,
105                                  const OI_BYTE **frameData,
106                                  OI_UINT32 *frameBytes,
107                                  OI_INT16 *pcmData,
108                                  OI_UINT32 *pcmBytes)
109 {
110     return internal_DecodeRaw(context,
111                               bitpool,
112                               frameData,
113                               frameBytes,
114                               pcmData,
115                               pcmBytes);
116 }
117 
OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT * context,OI_BOOL enhanced,OI_UINT8 subbands)118 OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context,
119                                     OI_BOOL                       enhanced,
120                                     OI_UINT8                      subbands)
121 {
122     if (enhanced) {
123 #ifdef SBC_ENHANCED
124         context->enhancedEnabled = TRUE;
125 #else
126         context->enhancedEnabled = FALSE;
127 #endif
128     } else {
129         context->enhancedEnabled = FALSE;
130     }
131     context->restrictSubbands = subbands;
132     context->limitFrameFormat = TRUE;
133     return OI_OK;
134 }
135 
136 
137 /**
138 @}
139 */
140 
141 #endif /* #if (defined(SBC_DEC_INCLUDED) && SBC_DEC_INCLUDED == TRUE) */
142