summaryrefslogtreecommitdiff
path: root/embdrv/sbc/decoder/srce/decoder-oina.c
blob: 5811584d8cb3cf57558f194b16977a60fc97524f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/******************************************************************************
 *
 *  Copyright (C) 2014 The Android Open Source Project
 *  Copyright 2006 Open Interface North America, Inc. All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/*******************************************************************************
  $Revision: #1 $
 ******************************************************************************/

/**
@file
This file exposes OINA-specific interfaces to decoder functions.

@ingroup codec_internal
*/

/**
@addtogroup codec_internal
@{
*/

#include <oi_codec_sbc_private.h>

OI_STATUS 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) {
  if (frequency > SBC_FREQ_48000) {
    return OI_STATUS_INVALID_PARAMETERS;
  }

  if (enhanced) {
#ifdef SBC_ENHANCED
    if (subbands != SBC_SUBBANDS_8) {
      return OI_STATUS_INVALID_PARAMETERS;
    }
#else
    return OI_STATUS_INVALID_PARAMETERS;
#endif
  }

  if (mode > SBC_JOINT_STEREO) {
    return OI_STATUS_INVALID_PARAMETERS;
  }

  if (subbands > SBC_SUBBANDS_8) {
    return OI_STATUS_INVALID_PARAMETERS;
  }

  if (blocks > SBC_BLOCKS_16) {
    return OI_STATUS_INVALID_PARAMETERS;
  }

  if (alloc > SBC_SNR) {
    return OI_STATUS_INVALID_PARAMETERS;
  }

#ifdef SBC_ENHANCED
  context->common.frameInfo.enhanced = enhanced;
#else
  context->common.frameInfo.enhanced = FALSE;
#endif
  context->common.frameInfo.freqIndex = frequency;
  context->common.frameInfo.mode = mode;
  context->common.frameInfo.subbands = subbands;
  context->common.frameInfo.blocks = blocks;
  context->common.frameInfo.alloc = alloc;
  context->common.frameInfo.bitpool = maxBitpool;

  OI_SBC_ExpandFrameFields(&context->common.frameInfo);

  if (context->common.frameInfo.nrof_channels >= context->common.pcmStride) {
    return OI_STATUS_INVALID_PARAMETERS;
  }

  return OI_OK;
}

OI_STATUS 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) {
  return internal_DecodeRaw(context, bitpool, frameData, frameBytes, pcmData,
                            pcmBytes);
}

OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT* context,
                                    OI_BOOL enhanced, uint8_t subbands) {
  if (enhanced) {
#ifdef SBC_ENHANCED
    context->enhancedEnabled = TRUE;
#else
    context->enhancedEnabled = FALSE;
#endif
  } else {
    context->enhancedEnabled = FALSE;
  }
  context->restrictSubbands = subbands;
  context->limitFrameFormat = TRUE;
  return OI_OK;
}

/**
@}
*/