summaryrefslogtreecommitdiff
path: root/amadec/audio-dec.h (plain)
blob: 13c7935928d1dee101b16548aa8da8fa21fd4775
1/**
2 * \file audio-dec.h
3 * \brief Definitiond Of Audio Dec Types And Structures
4 * \version 1.0.0
5 * \date 2011-03-08
6 */
7/* Copyright (C) 2007-2011, Amlogic Inc.
8 * All right reserved
9 *
10 */
11#ifndef AUDIO_DEC_H
12#define AUDIO_DEC_H
13
14#include<pthread.h>
15
16#include <audio-out.h>
17#include <audiodsp.h>
18#include <system/audio.h>
19#include <adec-types.h>
20#include <adec-message.h>
21#include <log-print.h>
22#include <adec-armdec-mgt.h>
23#include <adec_write.h>
24ADEC_BEGIN_DECLS
25
26#define AUDIO_CTRL_DEVICE "/dev/amaudio_ctl"
27
28#define AMAUDIO_IOC_MAGIC 'A'
29#define AMAUDIO_IOC_SET_LEFT_MONO _IOW(AMAUDIO_IOC_MAGIC, 0x0e, int)
30#define AMAUDIO_IOC_SET_RIGHT_MONO _IOW(AMAUDIO_IOC_MAGIC, 0x0f, int)
31#define AMAUDIO_IOC_SET_STEREO _IOW(AMAUDIO_IOC_MAGIC, 0x10, int)
32#define AMAUDIO_IOC_SET_CHANNEL_SWAP _IOW(AMAUDIO_IOC_MAGIC, 0x11, int)
33
34//should in accordance with ../amcodec/include/amports/amstream.h
35#define AMAUDIO_IOC_SET_RESAMPLE_DELTA _IOW(AMAUDIO_IOC_MAGIC, 0x1d, unsigned long)
36
37//for ffmpeg audio decode
38#define AMSTREAM_IOC_MAGIC 'S'
39#define AMSTREAM_IOC_APTS_LOOKUP _IOR(AMSTREAM_IOC_MAGIC, 0x81, int)
40#define GET_FIRST_APTS_FLAG _IOR(AMSTREAM_IOC_MAGIC, 0x82, int)
41
42//-----------------------------------------------
43//copy from file: "../amcodec/include/amports/amstream.h"
44#ifndef AMSTREAM_IOC_PCRSCR
45#define AMSTREAM_IOC_PCRSCR _IOR(AMSTREAM_IOC_MAGIC, 0x42, int)
46#endif
47#ifndef AMSTREAM_IOC_SET_APTS
48#define AMSTREAM_IOC_SET_APTS _IOW(AMSTREAM_IOC_MAGIC, 0xa8, int)
49#endif
50
51//-----------------------------------------------
52
53
54/*******************************************************************************************/
55
56typedef struct aml_audio_dec aml_audio_dec_t;
57#define DECODE_ERR_PATH "/sys/class/audiodsp/codec_fatal_err"
58#define DECODE_NONE_ERR 0
59#define DECODE_INIT_ERR 1
60#define DECODE_FATAL_ERR 2
61#define lock_t pthread_mutex_t
62#define lp_lock_init(x,v) pthread_mutex_init(x,v)
63#define lp_lock(x) pthread_mutex_lock(x)
64#define lp_unlock(x) pthread_mutex_unlock(x)
65typedef enum {
66 HW_STEREO_MODE = 0,
67 HW_LEFT_CHANNEL_MONO,
68 HW_RIGHT_CHANNEL_MONO,
69 HW_CHANNELS_SWAP,
70} hw_command_t;
71struct package {
72 char *data;//buf ptr
73 int size; //package size
74 struct package * next;//next ptr
75};
76
77typedef struct {
78 struct package *first;
79 int pack_num;
80 struct package *current;
81 lock_t tslock;
82} Package_List;
83
84typedef struct adec_thread_mgt {
85 pthread_mutex_t pthread_mutex;
86 pthread_cond_t pthread_cond;
87 pthread_t pthread_id;
88} adec_thread_mgt_t;
89
90typedef struct {
91 char buff[10];
92 int size;
93 int status;//0 init 1 finding sync word 2 finding framesize 3 frame size found
94} StartCode;
95typedef void (*fp_arm_omx_codec_init)(aml_audio_dec_t*, int, void*, int*);
96typedef void (*fp_arm_omx_codec_read)(aml_audio_dec_t*, unsigned char *, unsigned *, int *);
97typedef void (*fp_arm_omx_codec_close)(aml_audio_dec_t*);
98typedef void (*fp_arm_omx_codec_start)(aml_audio_dec_t*);
99typedef void (*fp_arm_omx_codec_pause)(aml_audio_dec_t*);
100typedef int (*fp_arm_omx_codec_get_declen)(aml_audio_dec_t*);
101typedef int (*fp_arm_omx_codec_get_FS)(aml_audio_dec_t*);
102typedef int (*fp_arm_omx_codec_get_Nch)(aml_audio_dec_t*);
103typedef int (*fp_arm_omx_codex_read_assoc_data)(aml_audio_dec_t *,unsigned char *, int, int *);
104
105struct aml_audio_dec {
106 adec_state_t state;
107 pthread_t thread_pid;
108 adec_audio_format_t format;
109 int channels;
110 int samplerate;
111 int data_width;
112 int bitrate;
113 int block_align;
114 int codec_id;
115 int need_stop;
116 int auto_mute;
117 int muted;
118 int decoded_nb_frames;
119 int avsync_threshold;
120 float volume; //left or main volume
121 float volume_ext; //right
122 float pre_gain; //gain scope[-12dB,12dB]
123 int pre_gain_enable;
124 uint pre_mute;
125 int64_t refresh_pts_readytime_ms;
126 //codec_para_t *pcodec;
127 hw_command_t soundtrack;
128 audio_out_operations_t aout_ops;
129 dsp_operations_t adsp_ops;
130 message_pool_t message_pool;
131 audio_decoder_operations_t *adec_ops;//non audiodsp decoder operations
132 int extradata_size; ///< extra data size
133 char extradata[AUDIO_EXTRA_DATA_SIZE];
134 audio_session_t SessionID;
135 int format_changed_flag;
136 unsigned dspdec_not_supported;//check some profile that audiodsp decoder can not support,we switch to arm decoder
137 int droppcm_flag; // drop pcm flag, if switch audio (1)
138 int no_first_apts; // if can't get the first apts (1), default (0)
139 int apts_start_flag;
140 uint64_t first_apts;
141 int StageFrightCodecEnableType;
142 int64_t pcm_bytes_readed;
143 int64_t raw_bytes_readed;
144 float codec_type;
145 int raw_frame_size;
146 int pcm_frame_size;
147 int i2s_iec958_sync_flag;
148 int max_bytes_readded_diff;
149 int i2s_iec958_sync_gate;
150
151 buffer_stream_t *g_bst;
152 buffer_stream_t *g_bst_raw;
153 pthread_t sn_threadid;//same as the def: 'pthread_t thread_pid;'
154 pthread_t sn_getpackage_threadid;//same as the def: 'pthread_t thread_pid;'
155 int exit_decode_thread;
156 int exit_decode_thread_success;
157 unsigned long decode_offset;
158 int64_t decode_pcm_offset;
159 int use_get_out_posion;
160 int nDecodeErrCount;
161 int fd_uio;
162 uint64_t last_valid_pts;
163 int out_len_after_last_valid_pts;
164 int64_t last_out_postion;
165 int64_t last_get_postion_time_us;
166 int pcm_cache_size;
167 Package_List pack_list;
168 StartCode start_code;
169
170 void *arm_omx_codec;
171 fp_arm_omx_codec_init parm_omx_codec_init;
172 fp_arm_omx_codec_read parm_omx_codec_read ;
173 fp_arm_omx_codec_close parm_omx_codec_close;
174 fp_arm_omx_codec_start parm_omx_codec_start;
175 fp_arm_omx_codec_pause parm_omx_codec_pause;
176 fp_arm_omx_codec_get_declen parm_omx_codec_get_declen;
177 fp_arm_omx_codec_get_FS parm_omx_codec_get_FS;
178 fp_arm_omx_codec_get_Nch parm_omx_codec_get_Nch;
179 int OmxFirstFrameDecoded;
180 int tsync_mode;
181 adec_thread_mgt_t thread_mgt;
182 int dtshdll_flag;
183 int first_apts_lookup_over;
184 int audio_decoder_enabled; // if the audio decoder is enabled. if not enabled, muted pcm are output
185
186 //dvb pcr master
187 int fill_trackzero_thrsh;
188 int droppcm_ms;
189 int adis_flag;
190 int tsync_pcr_dispoint;
191 int pcrtsync_enable;
192 int pcrmaster_droppcm_thsh;
193 int64_t pcrscr64;
194 int64_t apts64;
195 int64_t last_apts64;
196 int64_t last_pcrscr64;
197 int mix_lr_channel_enable;
198
199 //code to handle small pts discontinue (1s < diff < 3s )
200 int last_discontinue_apts;//the apts when audio has little discontinue
201 int apts_reset_scr_delay_ms;
202 int64_t last_discontinue_time; //the time when littile discontinue happens
203
204 int VersionNum;
205 int DTSHDIEC958_FS;
206 int DTSHDIEC958_PktFrmSize;
207 int DTSHDIEC958_PktType;
208 int DTSHDPCM_SamsInFrmAtMaxSR;
209 unsigned int has_video;
210 int associate_dec_supported;//support associate or not
211 unsigned int associate_audio_enable;//control output associate audio
212 buffer_stream_t *g_assoc_bst;
213 fp_arm_omx_codex_read_assoc_data parm_omx_codec_read_assoc_data;
214 int mixing_level;//def=50, mixing level between main and associate, [0,100]
215};
216
217//from amcodec
218typedef struct {
219 int sample_rate; ///< audio stream sample rate
220 int channels; ///< audio stream channels
221 int format; ///< codec format id
222 int bitrate;
223 int block_align;
224 int codec_id; //original codecid corespingding to ffmepg
225 int handle; ///< codec device handler
226 int extradata_size; ///< extra data size
227 char extradata[AUDIO_EXTRA_DATA_SIZE];
228 int SessionID;
229 int dspdec_not_supported;//check some profile that audiodsp decoder can not support,we switch to arm decoder
230 int droppcm_flag; // drop pcm flag, if switch audio (1)
231 int automute;
232 unsigned int has_video;
233 int associate_dec_supported;//support associate or not
234 int mixing_level;//def=50, mixing level between main and associate, [0,100]
235} arm_audio_info;
236
237typedef struct {
238 int valid; ///< audio extradata valid(1) or invalid(0), set by dsp
239 int sample_rate; ///< audio stream sample rate
240 int channels; ///< audio stream channels
241 int bitrate; ///< audio stream bit rate
242 int codec_id; ///< codec format id
243 int block_align; ///< audio block align from ffmpeg
244 int extradata_size; ///< extra data size
245 char extradata[512];; ///< extra data information for decoder
246} Asf_audio_info_t;
247
248//status check
249struct adec_status {
250 unsigned int channels;
251 unsigned int sample_rate;
252 unsigned int resolution;
253 unsigned int error_count;
254 unsigned int status;
255};
256
257//audio decoder type, default arc
258#define AUDIO_ARC_DECODER 0
259#define AUDIO_ARM_DECODER 1
260#define AUDIO_FFMPEG_DECODER 2
261#define AUDIO_ARMWFD_DECODER 3
262
263//reference from " /amcodec/include/amports/aformat.h"
264#define ACODEC_FMT_NULL -1
265#define ACODEC_FMT_MPEG 0
266#define ACODEC_FMT_PCM_S16LE 1
267#define ACODEC_FMT_AAC 2
268#define ACODEC_FMT_AC3 3
269#define ACODEC_FMT_ALAW 4
270#define ACODEC_FMT_MULAW 5
271#define ACODEC_FMT_DTS 6
272#define ACODEC_FMT_PCM_S16BE 7
273#define ACODEC_FMT_FLAC 8
274#define ACODEC_FMT_COOK 9
275#define ACODEC_FMT_PCM_U8 10
276#define ACODEC_FMT_ADPCM 11
277#define ACODEC_FMT_AMR 12
278#define ACODEC_FMT_RAAC 13
279#define ACODEC_FMT_WMA 14
280#define ACODEC_FMT_WMAPRO 15
281#define ACODEC_FMT_PCM_BLURAY 16
282#define ACODEC_FMT_ALAC 17
283#define ACODEC_FMT_VORBIS 18
284#define ACODEC_FMT_AAC_LATM 19
285#define ACODEC_FMT_APE 20
286#define ACODEC_FMT_EAC3 21
287#define ACODEC_FMT_WIFIDISPLAY 22
288#define ACODEC_FMT_DRA 23
289#define ACODEC_FMT_TRUEHD 25
290#define ACODEC_FMT_MPEG1 26 //AFORMAT_MPEG-->mp3,AFORMAT_MPEG1-->mp1,AFROMAT_MPEG2-->mp2
291#define ACODEC_FMT_MPEG2 27
292#define ACODEC_FMT_WMAVOI 28
293
294
295
296
297
298/***********************************************************************************************/
299extern void android_basic_init(void);
300int audiodec_init(aml_audio_dec_t *aml_audio_dec);
301int adec_message_pool_init(aml_audio_dec_t *);
302adec_cmd_t *adec_message_alloc(void);
303int adec_message_free(adec_cmd_t *);
304int adec_send_message(aml_audio_dec_t *, adec_cmd_t *);
305adec_cmd_t *adec_get_message(aml_audio_dec_t *);
306int feeder_init(aml_audio_dec_t *);
307int feeder_release(aml_audio_dec_t *);
308void *adec_armdec_loop(void *args);
309void *adec_wfddec_msg_loop(void *args);
310int adec_thread_wait(aml_audio_dec_t *audec, int microseconds);
311int adec_thread_wakeup(aml_audio_dec_t *audec);
312
313ADEC_END_DECLS
314#endif
315