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