/* * 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 DEVICE_PATCH_H_ #define DEVICE_PATCH_H_ #include #include #include #include "aml_ringbuffer.h" #include "component_picture_mode.h" #include "aml_audio_resampler.h" #include "aml_audio_heaacparser.h" #include "dtv_patch_utils.h" #include "dtv_patch.h" #include "dtv_patch_hal_avsync.h" typedef void (*dtv_avsync_process_cb)(struct audio_stream_out *stream, size_t bytes, audio_format_t output_format); enum patch_route_e { /*source is device, sink is device*/ PATCH_ROUTE_DEV_DEV = 0, /*source is mix, sink is device*/ PATCH_ROUTE_MIX_DEV = 1, /*source is dev, sink is mix*/ PATCH_ROUTE_DEV_MIX = 2, /*source is mix, sink is mix*/ PATCH_ROUTE_MIX_MIX = 3, }; enum patch_type_e { PATCH_TYPE_TV = 1, PATCH_TYPE_DTV = 1 << 1, PATCH_TYPE_ALL = 1 << 2, PATCH_TYPE_INVAL = 1 << 3, }; /**\brief Audio output mode*/ typedef enum { AM_AOUT_OUTPUT_STEREO, /**< Stereo output*/ AM_AOUT_OUTPUT_DUAL_LEFT, /**< Left audio output to dual channel*/ AM_AOUT_OUTPUT_DUAL_RIGHT, /**< Right audio output to dual channel*/ AM_AOUT_OUTPUT_SWAP, /**< Swap left and right channel*/ AM_AOUT_OUTPUT_LRMIX, /**< mix left and right channel*/ AM_AOUT_OUTPUT_JOINT_STEREO /**< JOINT output*/ } AM_AOUT_OutputMode_t; /* all latency in unit 'ms' */ struct audio_patch_latency_detail { unsigned int ringbuffer_latency; unsigned int smringbuffer_latency; unsigned int user_tune_latency; unsigned int alsa_in_latency; unsigned int alsa_i2s_out_latency; unsigned int alsa_spdif_out_latency; unsigned int ms12_latency; unsigned int submix_in_latency; unsigned int total_latency; }; struct tv_stream_param { hdmiin_audio_packet_t audio_packet_type; hdmiin_audio_packet_t last_audio_packet_type; int read_mul_factor; bool patch_input_thread_exit; }; struct aml_audio_patch { struct aml_audio_device *dev; enum patch_source patch_src; ring_buffer_t aml_ringbuffer; int decoder_id; dtv_path_t dtv_path[DVB_DEMUX_SUPPORT_MAX_NUM]; pthread_t audio_input_threadID; pthread_t audio_output_threadID; pthread_t audio_signal_detect_threadID; int signal_detect_thread_exit; pthread_t audio_parse_threadID; void *audio_parse_para; pthread_mutex_t mutex; pthread_cond_t cond; bool av_audio_only; struct timespec patch_start_ts; //for input audio_devices_t input_device; audio_input_config_t input_config; audio_input_type_e input_type; int input_open_counter; struct tv_stream_param tv_param; void *in_buf; size_t in_buf_size; int input_thread_exit; audio_channel_mask_t in_chanmask; int in_sample_rate;//For HDMI source: If hw resample is turned on, this value is 48000; if not, this value is the sample rate obtained from HDMI input audio_format_t in_format; //used for input read, only AUDIO_FORMAT_PCM_16_BIT or AUDIO_FORMAT_PCM_32_BIT int in_channel_count; void *input_tmp_buffer; size_t input_tmp_buffer_size; int in_read_frame_size; bool arc_layout_b; bool last_layout_b; int spdif_fmt_hw; /* HW parser audio format */ int last_parser_type; //for input status monitor bool mute_flag; int mute_log_cntr; int mute_mdelay; struct timespec mute_start_ts; //for input data continuous check int sync_offset; int read_size; struct timespec start_ts; int mdelay; bool start_mute; bool digital_input_fmt_change; //for output void *out_buf; size_t out_buf_size; int output_thread_exit; audio_devices_t output_device; audio_channel_mask_t out_chanmask; int out_channel_count; int out_sample_rate; audio_format_t out_format; struct audio_stream_out *stream_out; audio_format_t aformat; //current output audio format /* user setting picture mode */ bool is_game_mode; picture_mode_t pic_mode; bool IEC61937_format; bool mode_reconfig_flag; /* user setting picture mode end */ /* for hdmirx->earc multich passthrough */ bool hdmi_earc_passthrough_mode;//mch earc passthrough int hdmi_sample_rate;//pcm input sample rate before hw resample /* for AVSYNC tuning */ int vltcy; int altcy; int average_vltcy; int average_altcy; int avsync_sample_accumulated; int max_video_latency; int min_video_latency; bool need_do_avsync; bool input_signal_stable; bool is_avsync_start; bool skip_frames; int timeout_avsync_cnt; struct audio_patch_latency_detail audio_latency; /* end of AVSYNC tuning */ /*for dtv play parameters */ unsigned char dtv_NchOriginal; unsigned char dtv_lfepresent; /*end dtv play*/ // correspond to audio_patch:: audio_patch_handle_t id; // patch unique ID }; void create_tvin_buffer(struct aml_audio_patch *patch); void release_tvin_buffer(struct aml_audio_patch *patch); void adev_audio_patches_dump(struct aml_audio_device *aml_dev, int fd); #endif