291 lines
9.3 KiB
C
291 lines
9.3 KiB
C
/*
|
||
* Copyright (C) 2017 Amlogic Corporation.
|
||
*
|
||
* 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.
|
||
*/
|
||
|
||
|
||
#ifndef _AUDIO_CONTROLS_UTILS_H_
|
||
#define _AUDIO_CONTROLS_UTILS_H_
|
||
|
||
#include <cutils/list.h>
|
||
#include <tinyalsa/asoundlib.h>
|
||
#include "audio_hw.h"
|
||
#include "aml_ringbuffer.h"
|
||
#include "aml_audio_log.h"
|
||
#include "aml_enc_api.h"
|
||
|
||
#include <linux/alsa-ext/alsa-ext-common.h>
|
||
#include <linux/alsa-ext/alsa-ext-delay.h>
|
||
#include <linux/alsa-ext/alsa-ext-gain.h>
|
||
#include <linux/alsa-ext/alsa-ext-mute.h>
|
||
#include <linux/alsa-ext/alsa-ext-sndout.h>
|
||
#include <linux/alsa-ext/alsa-ext-adc.h>
|
||
#include <linux/alsa-ext/alsa-ext-adec.h>
|
||
#include <linux/alsa-ext/alsa-ext-atv.h>
|
||
#include <linux/alsa-ext/alsa-ext-soundengine-common.h>
|
||
#include <linux/alsa-ext/alsa-ext-soundengine-lite.h>
|
||
#include <linux/alsa-ext/alsa-ext-lgse.h>
|
||
#include <linux/alsa-ext/alsa-ext-dap.h>
|
||
#include <linux/alsa-ext/alsa-ext-aenc.h>
|
||
#include <linux/alsa-ext/alsa-ext-displayport.h>
|
||
|
||
struct audio_card_info {
|
||
int card;
|
||
int device;
|
||
int stream_type;
|
||
int rate;
|
||
int format;
|
||
int channels;
|
||
};
|
||
|
||
typedef struct audio_capture_param {
|
||
struct pcm *capture_handle; // 4 is for hw:0,10~hw:0,13
|
||
bool capture_need_close;
|
||
struct pcm_config hardware_config;
|
||
pthread_mutex_t cap_handle_lock;
|
||
struct audio_card_info info;
|
||
} audio_capture_param_t;
|
||
|
||
typedef enum input_type {
|
||
INPUT_UNKNOWN = 0x0000,
|
||
INPUT_ADEC = 0x0001, /**< Input is Adec */
|
||
INPUT_AMIXER = 0x0010, /**< Input is Amixer */
|
||
} input_type_e;
|
||
|
||
typedef struct data_info {
|
||
unsigned int device_id; // from or to which device of card 0
|
||
unsigned int sample_rate;
|
||
audio_format_t audio_format;
|
||
unsigned int need_close;
|
||
} data_info_t;
|
||
|
||
typedef struct audio_data_info_set {
|
||
struct listnode list;
|
||
data_info_t data_info;
|
||
} audio_data_info_set_t;
|
||
|
||
|
||
typedef enum input_source_type {
|
||
INPUT_SOURCE_ATV,
|
||
INPUT_SOURCE_DTV,
|
||
INPUT_SOURCE_AV,
|
||
INPUT_SOURCE_HDMI,
|
||
} input_source_type_e;
|
||
|
||
|
||
//output device type define come from alsa-ext-common.h begin
|
||
typedef enum output_device_idx {
|
||
OUTPUT_DEVICE_UNKNOWN = 0,
|
||
OUTPUT_DEVICE_SPK = 1, // COMMON_SPK
|
||
OUTPUT_DEVICE_OPTIC = 2, //COMMON_OPTIC
|
||
OUTPUT_DEVICE_OPTIC_LG = 3, //COMMON_OPTIC_LG
|
||
OUTPUT_DEVICE_BLUETOOTH = 4,
|
||
OUTPUT_DEVICE_HP = 5,
|
||
OUTPUT_DEVICE_ARC = 6,
|
||
OUTPUT_DEVICE_WISA = 7,
|
||
OUTPUT_DEVICE_SE_BT = 8,
|
||
OUTPUT_DEVICE_CAPTURE = 9,
|
||
OUTPUT_DEVICE_SE_ARC = 10,
|
||
OUTPUT_DEVICE_SE_BT_SUR = 11,
|
||
OUTPUT_DEVICE_MAX = 12,
|
||
} output_device_idx_e;
|
||
//output device type define come from alsa-ext-common.h end
|
||
|
||
typedef enum audio_output_type {
|
||
AUDIO_OUTPUT_TYPE_NONE = 0x0000,
|
||
AUDIO_OUTPUT_TYPE_SPK = 0x0001,
|
||
AUDIO_OUTPUT_TYPE_OPTIC = 0x0002,
|
||
AUDIO_OUTPUT_TYPE_OPTIC_LG = 0x0004,
|
||
AUDIO_OUTPUT_TYPE_BLUETOOTH = 0x0008,
|
||
AUDIO_OUTPUT_TYPE_HP = 0x0010,
|
||
AUDIO_OUTPUT_TYPE_ARC = 0x0020,
|
||
AUDIO_OUTPUT_TYPE_WISA = 0x0040,
|
||
AUDIO_OUTPUT_TYPE_SE_BT = 0x0080,
|
||
AUDIO_OUTPUT_TYPE_CAPTURE = 0x0100,
|
||
AUDIO_OUTPUT_TYPE_SE_ARC = 0x0200,
|
||
AUDIO_OUTPUT_TYPE_BT_SUR = 0x0400,
|
||
AUDIO_OUTPUT_TYPE_MAX = 0x0800
|
||
} audio_output_type_e;
|
||
|
||
typedef struct gain_input {
|
||
float current_gain;
|
||
float save_gain;
|
||
float target_gain;
|
||
float gain_step;
|
||
unsigned int fade_frames;
|
||
int duration;
|
||
} gain_input_t;
|
||
|
||
#define VOLUME_GAIN_0DB 0x00800000//0x00800000
|
||
#define DATA_SIZE CAPTURE_PERIOD_SIZE*2//384frame*2channel 8ms audio data
|
||
#define READ_SIZE DATA_SIZE*sizeof(short)
|
||
#define AUDIO_DATA_TYPE_MAX (32767) // 2^15(short)
|
||
#define AUDIO_DATA_TYPE_MIN (-32768)
|
||
#define CHANNEL_NUM 2
|
||
#define HW_SYNC_HEADER_SIZE 20
|
||
#define TEMP_SET_MEDIASYNC_INSTANCE_ID 11
|
||
#define USER_RECEIVED_UEVENT "USER RECEIVED UEVENTS"
|
||
#define USER_RECEIVED_UEVENT_LEN (32)
|
||
#define CTRL_CARD0 (0)
|
||
#define START_THRESHOLD_COUNT 10
|
||
|
||
|
||
#define DEVICE_NUM 8
|
||
#define ADEC_NUM 4
|
||
#define AMIXER_NUM 8
|
||
#define OUTPUT_DEVICE_NUM 16
|
||
#define DIRCET_PLAY_NUM 2 // hw:0,8 and hw:0,9
|
||
#define DIRCET_PLAY_START_INDEX 8 //hw:0,8
|
||
#define DIRCET_PLAY_END_INDEX 9 //hw:0,9
|
||
#define ENCODER_CAP_DEV 11 //hw:0,11
|
||
#define AUD_DEV_IOCTL_GOT_UEVENT _IO('A', 0)
|
||
|
||
#define CAPTURE_START_INDEX 10 //hw:0,10
|
||
#define CAPTURE_END_INDEX 13 //hw:0,13
|
||
|
||
typedef enum adec_src_codec_type {
|
||
ADEC_CODEC_UNKNOWN = 0x00, /**< Codec is UNKNOWN */
|
||
ADEC_CODEC_PCM = 0x01, /**< Codec is PCM */
|
||
|
||
ADEC_CODEC_AC3 = 0x10, /**< Codec is AC3 */
|
||
ADEC_CODEC_EAC3 = 0x11, /**< Codec is EAC3 */
|
||
ADEC_CODEC_EAC3_ATMOS = 0x12, /**< Codec is EAC3 ATMOS */
|
||
ADEC_CODEC_AC4 = 0x13, /**< Codec is (Non ATMOS) AC4 */
|
||
ADEC_CODEC_AC4_ATMOS = 0x14, /**< Codec is AC4 ATMOS */
|
||
ADEC_CODEC_MAT = 0x15, /**< Codec is MAT */
|
||
ADEC_CODEC_MAT_ATMOS = 0x16, /**< Codec is MAT ATMOS */
|
||
ADEC_CODEC_TRUEHD = 0x17, /**< Codec is True HD */
|
||
ADEC_CODEC_TRUEHD_ATMOS = 0x18, /**< Codec is True HD ATMOS */
|
||
ADEC_CODEC_AAC = 0x19, /**< Codec is AAC */
|
||
ADEC_CODEC_HEAAC = 0x1a, /**< Codec is HEAAC */
|
||
|
||
ADEC_CODEC_MPEG = 0x20, /**< Codec is MPEG */
|
||
ADEC_CODEC_MPEG_H = 0x21, /**< Codec is MPEG H */
|
||
ADEC_CODEC_DRA = 0x22, /**< Codec is DRA */
|
||
|
||
ADEC_CODEC_DTS = 0x30, /**< Codec is DTS */
|
||
ADEC_CODEC_DTS_HD_MA = 0x31, /**< Codec is DTS HD MA */
|
||
ADEC_CODEC_DTS_EXPRESS = 0x32, /**< Codec is DTS EXPRESS */
|
||
ADEC_CODEC_DTS_CD = 0x33, /**< Codec is DTS CD */
|
||
|
||
ADEC_CODEC_SIF = 0x40, /**< For ATV */
|
||
ADEC_CODEC_SIF_BTSC = 0x41, /**< For ATV (BTSC system) */
|
||
ADEC_CODEC_SIF_A2 = 0x42 /**< For ATV (A2 system) */
|
||
} adec_src_codec_type_t;
|
||
|
||
typedef enum adec_state {
|
||
ADEC_STATE_NULL = 0,
|
||
ADEC_STATE_INIT = 1,
|
||
ADEC_STATE_CONNECTED = 2,
|
||
ADEC_STATE_RUNNING = 3,
|
||
} adec_state_t;
|
||
|
||
typedef enum sif_state {
|
||
SIF_STATE_NULL = 0,
|
||
SIF_STATE_INIT = 1,
|
||
SIF_STATE_CONNECTED = 2,
|
||
} sif_state_t;
|
||
|
||
typedef enum adec_index {
|
||
ADEC_INDEX_0 = 0,
|
||
ADEC_INDEX_1 = 1,
|
||
ADEC_INDEX_2 = 2,
|
||
ADEC_INDEX_3 = 3,
|
||
} adec_index_t;
|
||
|
||
#define AENC_BUF_SIZE_MAX (10 * 1024)
|
||
struct aenc_data_t {
|
||
unsigned long long pts; // PTS
|
||
unsigned char pData[AENC_BUF_SIZE_MAX]; // pointer to Audio Data
|
||
unsigned int dataLen; // Audio Data Length
|
||
} ;
|
||
|
||
typedef struct adec_play_info {
|
||
adec_src_port_index_ext_type_t src_id;
|
||
audio_format_t adec_codec;
|
||
adec_state_t adec_state;
|
||
void * handle;
|
||
} adec_play_info_t;
|
||
|
||
typedef struct {
|
||
struct aml_audio_device * adev;
|
||
int aud_dev_fd;
|
||
volatile struct listnode alsa_data_info_list; // device data list for input mixer thread
|
||
volatile struct listnode alsa_resample_data_info_list; //device data list for resample thread
|
||
int adec_gain[ADEC_NUM];
|
||
int adec_mute[ADEC_NUM];
|
||
volatile gain_input_t amixer_gain[DEVICE_NUM];
|
||
volatile int amixer_mute[DEVICE_NUM];
|
||
volatile int output_device_gain[OUTPUT_DEVICE_NUM];//range is [0,100]
|
||
volatile int output_device_mute[OUTPUT_DEVICE_NUM];
|
||
|
||
//snd_pcm_t *amixer_capture_pcm_handle[DEVICE_NUM];
|
||
//snd_pcm_t *direct_play_alsa_handle[DIRCET_PLAY_NUM];
|
||
int ad_adec_index;// indicate which is ad,reference https://harmony.lge.com:8443/issue/browse/AMLREQ-104
|
||
adec_play_info_t adec_play_info[ADEC_NUM];
|
||
int sif_play_state;
|
||
|
||
pthread_t uevent_threadID;
|
||
pthread_t input_mixer_threadID;
|
||
pthread_t mixer_output_threadID;
|
||
|
||
pthread_t input_resample_threadID;
|
||
pthread_t direct_play_threadID;
|
||
pthread_t direct_out_to_decoder_threadID;
|
||
volatile int uevent_thread_exit;
|
||
volatile int input_mixer_thread_exit;
|
||
volatile int output_mixer_thread_exit;
|
||
|
||
volatile int input_resample_thread_exit;
|
||
volatile int direct_play_thread_exit;
|
||
volatile struct ring_buffer input_resample_ring_buffer;
|
||
volatile struct ring_buffer direct_play_ring_buffer;
|
||
volatile struct ring_buffer input_mixer_ring_buffer;
|
||
aml_audio_resample_t *input_resample_handle;
|
||
volatile unsigned int input_need_resample_num;
|
||
volatile unsigned int need_read_resample_data;
|
||
|
||
audio_patch_handle_t patch_handle;
|
||
|
||
adec_index_t adec_idx;
|
||
|
||
//capture
|
||
audio_capture_param_t capture_param[CAPTURE_END_INDEX - CAPTURE_START_INDEX + 1];
|
||
audio_output_type_e audio_output_type;
|
||
volatile int32_t capture_open_count;
|
||
void * capture_buffer;
|
||
int capture_buffer_size;
|
||
|
||
//for LG dtv sync
|
||
//aml_dtvsync_t *dtvsync;
|
||
|
||
//for mixer
|
||
volatile unsigned int mixerdata_ready;
|
||
/* -End- */
|
||
|
||
} aml_audio_control;
|
||
|
||
typedef struct {
|
||
audio_patch_handle_t atv_patch_handle;
|
||
audio_patch_handle_t dtv_patch_handle;
|
||
audio_patch_handle_t av_patch_handle;
|
||
audio_patch_handle_t hdmi_patch_handle;
|
||
} aml_audio_patch_handle;
|
||
|
||
void audio_control_init(struct aml_audio_device * adev);
|
||
void audio_control_deinit();
|
||
aml_audio_control* get_audio_control(void);
|
||
void control_utils(char *msg);
|
||
#endif
|