• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 - 2016 Sony Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _LDACBT_INTERNAL_H_
18 #define _LDACBT_INTERNAL_H_
19 
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdint.h>
23 #include <unistd.h>
24 #include "struct_ldac.h"
25 
26 #ifdef    __cplusplus
27 extern "C" {
28 #endif
29 
30 /* Function declaration */
31 #define DECLFUNC static
32 
33 /* Limit for alter EQMID process */
34 #define LDACBT_LIMIT_ALTER_EQMID_PRIORITY LDACBT_EQMID_MQ
35 
36 
37 #include "ldaclib.h"
38 #include "ldacBT.h"
39 #include "ldacBT_ex.h"
40 
41 /* macro value */
42 /* The size of LDAC transport header. Unit:Byte. */
43 #define LDACBT_FRMHDRBYTES LDAC_FRMHDRBYTES
44 /* The Maximum number of frames that can transrate in one packet.(LDAC A2DP spec) */
45 #define LDACBT_NFRM_TX_MAX 15
46 /* Lowest Common Multiple of (2,3,4)Bytes * 2ch * 256samples */
47 #define LDACBT_ENC_PCM_BUF_SZ 6144
48 /* The maximum pcm word length allowed. Unit:Byte */
49 #define LDACBT_PCM_WLEN_MAX 4
50 /* The size of LDACBT_TRANSPORT_FRM_BUF's buffer. Unit:Byte  */
51 #define LDACBT_ENC_STREAM_BUF_SZ 1024
52 /* The size of rtp header and so on. Unit:Byte */
53 /*  = sizeof(struct rtp_header) + sizeof(struct rtp_payload) + 1 (scms-t). */
54 #define LDACBT_TX_HEADER_SIZE 18
55 /* The MTU size required for LDAC A2DP streaming. */
56 #define LDACBT_MTU_REQUIRED  679
57 #define LDACBT_MTU_3DH5 (990+LDACBT_TX_HEADER_SIZE)
58 
59 /* The state for alter operation */
60 #define LDACBT_ALTER_OP__NON 0
61 #define LDACBT_ALTER_OP__ACTIVE 1
62 #define LDACBT_ALTER_OP__STANDBY 2
63 #define LDACBT_ALTER_OP__FLASH 9
64 
65 /* other */
66 #ifndef LDACBT_S_OK
67 #define LDACBT_S_OK (0)
68 #endif
69 #ifndef LDACBT_E_FAIL
70 #define LDACBT_E_FAIL (-1)
71 #endif
72 #ifndef FALSE
73 #define FALSE  0
74 #endif
75 #ifndef TRUE
76 #define TRUE   1
77 #endif
78 #ifndef UNSET
79 #define UNSET -1
80 #endif
81 #define LDACBT_GET_LDACLIB_ERROR_CODE   9999
82 
83 /* The index for A2DP packets */
84 enum {
85     ___DH1,    ___DH3,    ___DH5, /* basic rate */
86     _2_DH1,    _2_DH3,    _2_DH5, /* EDR2M */
87     _3_DH1,    _3_DH3,    _3_DH5, /* EDR3M */
88 };
89 
90 /* The state for LDACBT handle processing mode. */
91 typedef enum {
92     LDACBT_PROCMODE_UNSET = -1,
93     LDACBT_PROCMODE_ENCODE = 1,
94     LDACBT_PROCMODE_DECODE = 2,
95 } LDACBT_PROCMODE;
96 
97 /* Structs */
98 /* The structure for the property of EQMID. */
99 typedef struct _st_ldacbt_eqmid_property
100 {
101     int  eqmid;
102     char strModeName[4];
103     int  id_for_2DH5;
104 } LDACBT_EQMID_PROPERTY, * P_LDACBT_EQMID_PROPERTY;
105 
106 /* The structure for the configuration of LDAC. */
107 typedef struct _st_ldacbt_config
108 {
109     int id;
110     int nfrm_in_pkt; /* number of ldac frame in packet */
111     int frmlen;      /* ldac frame length */
112     int frmlen_1ch;  /* ldac frame length per channel */
113 } LDACBT_CONFIG, * P_LDACBT_CONFIG;
114 
115 /* The structure for the pcm information. */
116 typedef struct _ldacbt_pcm_info {
117     int sf; /* sampling frequency */
118     int ch; /* number of channel */
119     int wl;
120     LDACBT_SMPL_FMT_T fmt; /* sample format */
121 } LDACBT_PCM_INFO;
122 
123 /* The structure for the A2DP streaming. */
124 typedef struct _ldacbt_tx_info {
125     int mtu;
126     int tx_size;     /* size for ldac stream */
127     int pkt_type;    /* packet type */
128     int pkt_hdr_sz;  /* packet header size */
129     int nfrm_in_pkt; /* number of ldac frame in packet */
130 } LDACBT_TX_INFO;
131 /* The structure for the ldac_transport_frame sequence. */
132 typedef struct _ldacbt_transport_frame_buf {
133     unsigned char buf[LDACBT_ENC_STREAM_BUF_SZ];
134     int used;
135     int nfrm_in;
136 } LDACBT_TRANSPORT_FRM_BUF;
137 /* The structure of ring buffer for the input PCM. */
138 typedef struct _ldacbt_pcm_ring_buf {
139     char buf[LDACBT_ENC_PCM_BUF_SZ];
140     int wp;
141     int rp;
142     int nsmpl;
143 } LDACBT_PCM_RING_BUF;
144 
145 /* The LDACBT handle. */
146 typedef struct _st_ldacbt_handle {
147     HANDLE_LDAC hLDAC;
148     LDACBT_PROCMODE proc_mode;
149     int error_code;
150     int error_code_api;
151 /* common */
152     /* pcm */
153     LDACBT_PCM_INFO    pcm;
154     /* tx */
155     LDACBT_TX_INFO     tx;
156     /* ldaclib config */
157     int frm_samples;  /* frame samples */
158     int sfid;         /* sampling frequency index */
159     int nshift;
160     int flg_encode_flushed;
161     int frm_status;
162     int frmlen;    /* Frame Length */
163     int frmlen_tx; /* Frame Length with transport header */
164     int bitrate;
165 
166     int eqmid;     /* Encode Quality Mode Index */
167     /* for alter frame length */
168     int tgt_eqmid;      /* target Encode Quality Mode Index */
169     int tgt_nfrm_in_pkt;/* target number of frame in packet */
170     int tgt_frmlen;     /* target frame length */
171     int stat_alter_op;  /* status of alter operation */
172 
173     int cm; /* Channel Mode */
174     int cci; /* Channel Config Index */
175     int transport;   /* Transport Stream ( with frame header) */
176     /* buffer for "ldac_transport_frame" sequence */
177     LDACBT_TRANSPORT_FRM_BUF ldac_trns_frm_buf;
178     /* buffer for input pcm */
179     LDACBT_PCM_RING_BUF pcmring;
180 
181 /* work buffer for LDACLIB I/O */
182     char **pp_pcm;
183     char *ap_pcm[LDAC_PRCNCH];
184     char a_pcm[LDAC_PRCNCH * LDACBT_MAX_LSU * LDACBT_PCM_WLEN_MAX];
185 } STRUCT_LDACBT_HANDLE;
186 
187 
188 
189 /* subfunctions */
190 DECLFUNC void ldacBT_param_clear(HANDLE_LDAC_BT hLdacBT);
191 DECLFUNC int  ldacBT_check_ldaclib_error_code(HANDLE_LDAC_BT hLdacBT);
192 DECLFUNC int  ldacBT_assert_cm( int cm );
193 DECLFUNC int  ldacBT_assert_cci( int cci );
194 DECLFUNC int  ldacBT_assert_sample_format( LDACBT_SMPL_FMT_T fmt );
195 DECLFUNC int  ldacBT_assert_pcm_sampling_freq( int sf );
196 DECLFUNC int  ldacBT_assert_mtu( int mtu );
197 DECLFUNC int  ldacBT_assert_eqmid( int eqmid );
198 DECLFUNC void ldacBT_set_eqmid_core( HANDLE_LDAC_BT hLdacBT, int eqmid );
199 DECLFUNC void ldacBT_prepare_pcm_encode( void *pbuff, char **ap_pcm, int nsmpl, int nch,
200                      LDACBT_SMPL_FMT_T fmt );
201 DECLFUNC int  ldacBT_frmlen_to_bitrate( int frmlen, int flgFrmHdr, int sf, int frame_samples );
202 DECLFUNC int  ldacBT_cm_to_cci( int cm );
203 DECLFUNC int  ldacBT_cci_to_cm( int cci );
204 DECLFUNC int  ldacBT_get_altered_eqmid ( HANDLE_LDAC_BT hLdacBT, int priority );
205 DECLFUNC int  ldacBT_get_eqmid_from_frmlen( int frmlen, int nch, int flgFrmHdr, int pktType );
206 DECLFUNC int  ldacBT_update_frmlen(HANDLE_LDAC_BT hLdacBT, int frmlen);
207 DECLFUNC P_LDACBT_EQMID_PROPERTY ldacBT_get_eqmid_conv_tbl ( int ldac_bt_mode );
208 DECLFUNC P_LDACBT_CONFIG ldacBT_get_config( int ldac_bt_mode, int pkt_type );
209 
210 #ifdef    __cplusplus
211 }
212 #endif
213 #endif /* _LDACBT_INTERNAL_H_ */
214