blob: 62133e70c9849fbbd676b84a1f2d1fe46d8d7c18
1 | /* |
2 | * Copyright (C) 2011 The Android Open Source Project |
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 HUITONG_AUDIO_H |
18 | #define HUITONG_AUDIO_H |
19 | |
20 | #include <sys/types.h> |
21 | #include <sys/socket.h> |
22 | #include <sys/un.h> |
23 | #include <signal.h> |
24 | #include <sys/poll.h> |
25 | #include <cutils/sockets.h> |
26 | |
27 | #include <errno.h> |
28 | #include <pthread.h> |
29 | #include <stdint.h> |
30 | #include <sys/time.h> |
31 | #include <stdlib.h> |
32 | #include <sys/stat.h> |
33 | #include <fcntl.h> |
34 | |
35 | #include <cutils/log.h> |
36 | #include <cutils/str_parms.h> |
37 | #include <cutils/properties.h> |
38 | |
39 | #include <hardware/hardware.h> |
40 | #include <system/audio.h> |
41 | #include <hardware/audio.h> |
42 | |
43 | #include <tinyalsa/asoundlib.h> |
44 | #include <hardware/audio_effect.h> |
45 | #include <time.h> |
46 | #include <utils/Timers.h> |
47 | |
48 | ////////////////////////// switch of huitong ////////////////////////////////////////////////// |
49 | #define ENABLE_HUITONG 1 |
50 | |
51 | |
52 | |
53 | ////////////////////////// bowdlerized huitong_audio_hw.h ///////////////////////////////////// |
54 | /* ALSA cards for AML */ |
55 | #define CARD_AMLOGIC_USB 1 |
56 | /* ALSA ports for AML */ |
57 | #define PORT_MM 0 // this macro is different between amlogic and huitong |
58 | /* number of frames per period */ |
59 | #define DEFAULT_WFD_PERIOD_SIZE 256 |
60 | #define DEFAULT_CAPTURE_PERIOD_SIZE 1024 |
61 | #define MIXER_XML_PATH "/system/etc/mixer_paths.xml" |
62 | |
63 | extern struct pcm_config pcm_config_vg; |
64 | |
65 | |
66 | ////////////////////////// huitong_audio_hw.c ///////////////////////////////////////////////// |
67 | #include <linux/input.h> |
68 | #include <linux/hidraw.h> |
69 | //#include <huitong_audio.h> |
70 | #include "def.h" |
71 | #include "ti_audio.h" |
72 | #include "mainSBC.h" |
73 | #include "dvi_adpcm.h" |
74 | #include "opus.h" |
75 | #include "typedef.h" |
76 | #include "bvcommon.h" |
77 | #include "bv32cnst.h" |
78 | #include "bv32strct.h" |
79 | #include "bv32.h" |
80 | #include "bitpack.h" |
81 | |
82 | #include "huitong_log.h" |
83 | |
84 | #define BV32_FRAME_LEN 80 |
85 | |
86 | #define MAX_HIDRAW_ID 20 |
87 | |
88 | #define HUITONG_TI_VID 0x000D |
89 | #define HUITONG_TI_PID 0x0001 |
90 | |
91 | #define HUITONG_BCM_VID 0x000F |
92 | #define HUITONG_BCM_PID_20734 0x0001 |
93 | #define HUITONG_BCM_PID_20735 0x0002 |
94 | |
95 | |
96 | #define HUITONG_DIALOG_VID 0x2ba5 |
97 | #define HUITONG_DIALOG_PID 0x8082 |
98 | |
99 | #define HUITONG_NORDIC_VID 0x1915 |
100 | #define HUITONG_NORDIC_PID 0x0001 |
101 | |
102 | enum { |
103 | RC_PLATFORM_UNKOWN, |
104 | RC_PLATFORM_TI, |
105 | RC_PLATFORM_BCM, |
106 | RC_PLATFORM_DIALOG, |
107 | RC_PLATFORM_NORDIC |
108 | }; |
109 | |
110 | #define REPORT_ID 0x05 |
111 | #define REPORT_ID_NORDIC_BV32 0x01 |
112 | #define REPORT_ID_NORDIC_ADPCM 0x02 |
113 | #define REPORT_ID_NORDIC_OPUS 0x03 |
114 | |
115 | |
116 | #define GATT_PDU_LENGTH 20 |
117 | #define HIDRAW_PDU_LENGTH (1 + GATT_PDU_LENGTH) //the first byte is report id added by stack |
118 | |
119 | static int part_index = 0; |
120 | static int total_lenth = 0; |
121 | static int receive_index = 0; |
122 | #define ADPCM_DATA_PART_NUM 5 //five parts as a frame |
123 | static unsigned char ADPCM_Data_Frame[ADPCM_DATA_PART_NUM*GATT_PDU_LENGTH]; |
124 | |
125 | static OpusDecoder *st; |
126 | static struct BV32_Decoder_State bv32_st; |
127 | |
128 | |
129 | static short decode_buf[1024]; |
130 | |
131 | static int hidraw_fd = -1; |
132 | |
133 | static int huitong_rc_platform = RC_PLATFORM_UNKOWN; |
134 | |
135 | ///////////////////// function prototype definition used in huitong_audio_hw.c //////////////// |
136 | uint32_t huitong_in_get_sample_rate(const struct audio_stream *stream); |
137 | int huitong_in_set_sample_rate(struct audio_stream *stream, uint32_t rate); |
138 | size_t huitong_in_get_buffer_size(const struct audio_stream *stream); |
139 | audio_channel_mask_t huitong_in_get_channels(const struct audio_stream *stream); |
140 | audio_format_t huitong_in_get_format(const struct audio_stream *stream); |
141 | int huitong_in_set_format(struct audio_stream *stream, audio_format_t format); |
142 | int huitong_in_standby(struct audio_stream *stream); |
143 | int huitong_in_dump(const struct audio_stream *stream, int fd); |
144 | int huitong_in_set_parameters(struct audio_stream *stream, const char *kvpairs); |
145 | char * huitong_in_get_parameters(const struct audio_stream *stream, const char *keys); |
146 | int huitong_in_set_gain(struct audio_stream_in *stream, float gain); |
147 | ssize_t huitong_in_read(struct audio_stream_in *stream, void* buffer, size_t bytes); |
148 | uint32_t huitong_in_get_input_frames_lost(struct audio_stream_in *stream); |
149 | int get_hidraw_device_fd(); |
150 | |
151 | #endif |
152 | |
153 |