diff --git a/Android.mk b/Android.mk
old mode 100644
new mode 100755
diff --git a/audio/octopus/ac100_paths.xml b/audio/octopus/ac100_paths.xml
index 3a10538..2a43e43 100755
--- a/audio/octopus/ac100_paths.xml
+++ b/audio/octopus/ac100_paths.xml
@@ -95,6 +95,7 @@
+
@@ -104,7 +105,8 @@
-
+
+
diff --git a/audio/octopus/audio_hw.c b/audio/octopus/audio_hw.c
index 51f1160..9da68d4 100755
--- a/audio/octopus/audio_hw.c
+++ b/audio/octopus/audio_hw.c
@@ -86,7 +86,7 @@ static bool NO_EARPIECE = 1;
/* number of frames per long period (low power) */
#define LONG_PERIOD_SIZE (SHORT_PERIOD_SIZE * LONG_PERIOD_MULTIPLIER)
/* number of pseudo periods for playback */
-#define PLAYBACK_PERIOD_COUNT 4
+#define PLAYBACK_PERIOD_COUNT 3
/* number of periods for capture */
#define CAPTURE_PERIOD_COUNT 2
/* minimum sleep time in out_write() when write threshold is not reached */
@@ -109,7 +109,6 @@ static bool last_call_path_is_bt = 0;
static bool dmic_used = 0;
static bool last_communication_is_bt = 0;
-
/*VOLUME CTL*/
#define MIXER_HP_VOLUME "headphone volume"
#define MIXER_SPK_VOLUME "speaker volume"
@@ -1736,6 +1735,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
WritePcmData((void *)buf, out_frames * frame_size, &adev->PcmManager);
memset(buf, 0, out_frames * frame_size); //mute
}
+
ret = pcm_write(out->pcm, (void *)buf, out_frames * frame_size);
if(ret!=0)
{
@@ -2390,6 +2390,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
struct sunxi_audio_device *adev = in->dev;
size_t frames_rq = bytes / audio_stream_frame_size(&stream->common);
+ int is_first_data = 0;
if (adev->mode == AUDIO_MODE_IN_CALL) {
//ALOGD("in call mode, in_read, return ;");
@@ -2432,6 +2433,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
pthread_mutex_lock(&in->lock);
if (in->standby) {
ret = start_input_stream(in);
+ is_first_data = 1;
if (ret == 0)
in->standby = 0;
}
@@ -2450,6 +2452,15 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
ret = pcm_read(in->pcm, buffer, bytes);
}
+
+ /* If connect headset, set the first data to zero.
+ * There may be a noise pulse.
+ */
+ if (is_first_data &&
+ (adev->in_device & AUDIO_DEVICE_IN_WIRED_HEADSET)) {
+ memset(buffer, 0, bytes);
+ }
+
if (ret > 0)
ret = 0;
@@ -2962,6 +2973,7 @@ static int adev_close(hw_device_t *device)
audio_route_free(adev->ar);
free(adev->vol_array);
free(device);
+
return 0;
}
diff --git a/audio/octopus/audio_policy.conf b/audio/octopus/audio_policy.conf
index c1ce9e7..e04323a 100755
--- a/audio/octopus/audio_policy.conf
+++ b/audio/octopus/audio_policy.conf
@@ -75,7 +75,7 @@ audio_hw_modules {
usb_device {
sampling_rates dynamic
channel_masks AUDIO_CHANNEL_IN_STEREO
- formats AUDIO_FORMAT_PCM_16_BIT
+ formats AUDIO_FORMAT_PCM_24_BIT_PACKED
devices AUDIO_DEVICE_IN_USB_DEVICE
}
}
diff --git a/audio/tulip/Android.mk b/audio/tulip/Android.mk
index 2d5ef25..851d50b 100755
--- a/audio/tulip/Android.mk
+++ b/audio/tulip/Android.mk
@@ -17,7 +17,7 @@ LOCAL_PATH := $(call my-dir)
# libAwHeadpSurround
include $(CLEAR_VARS)
LOCAL_MODULE := libAwHeadpSurround
-LOCAL_SRC_FILES := libAwHeadpSurround.so
+LOCAL_SRC_FILES := audio_3d_surround/libAwHeadpSurround.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
@@ -31,7 +31,7 @@ LOCAL_MODULE := audio.primary.$(TARGET_BOARD_PLATFORM)
#LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := audio_hw.c audio_iface.c sunxi_volume.c
+LOCAL_SRC_FILES := audio_hw.c audio_iface.c sunxi_volume.c audio_3d_surround/audio_3d_surround.c
#ifneq ($(SW_BOARD_HAVE_3G), true)
#LOCAL_SRC_FILES += audio_ril_stub.c
diff --git a/audio/tulip/a64_paths.xml b/audio/tulip/a64_paths.xml
index 24c84d5..a826935 100755
--- a/audio/tulip/a64_paths.xml
+++ b/audio/tulip/a64_paths.xml
@@ -22,8 +22,8 @@
-
-
+
+
@@ -56,8 +56,8 @@
-
-
+
+
diff --git a/audio/tulip/audio_3d_surround/audio_3d_surround.c b/audio/tulip/audio_3d_surround/audio_3d_surround.c
new file mode 100755
index 0000000..b127012
--- /dev/null
+++ b/audio/tulip/audio_3d_surround/audio_3d_surround.c
@@ -0,0 +1,91 @@
+#define LOG_TAG "audio_3d_surround"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "audio_3d_surround.h"
+
+#define SUR_LIB_PATH "libAwHeadpSurround.so"
+
+#define SPACE_GAIN (0.50)
+#define BASS_GAIN (0.33)
+#define DEFINTION_GAIN (0.80)
+
+int surround_init(struct audio_3d_surround *sur,
+ int samp_rate, int chn, int num_frame)
+{
+ memset(sur, 0, sizeof(*sur));
+
+ /* open lib */
+ sur->lib = dlopen(SUR_LIB_PATH, RTLD_LAZY);
+ if (NULL == sur->lib) {
+ ALOGW("%s,line:%d, can't open surround lib.", __func__, __LINE__);
+ return -1;
+ }
+
+ /* get 3d srround function */
+ sur->process_init = dlsym(sur->lib, "process_init");
+ sur->process_exit = dlsym(sur->lib, "process_exit");
+ sur->surround_pro_in_out = dlsym(sur->lib, "surround_pro_in_out");
+ sur->set_bass = dlsym(sur->lib, "set_bass");
+ sur->set_defintion = dlsym(sur->lib, "set_defintion");
+ sur->set_space = dlsym(sur->lib, "set_space");
+
+ /* init 3d suround parameter */
+ sur->sur_handle = sur->process_init(sur->sur_handle, samp_rate, chn, num_frame);
+ sur->set_bass(sur->sur_handle, BASS_GAIN);
+ sur->set_defintion(sur->sur_handle, DEFINTION_GAIN);
+ sur->set_space(sur->sur_handle, SPACE_GAIN);
+
+ return 0;
+}
+
+bool surround_ready(struct audio_3d_surround sur)
+{
+ if ( (NULL == sur.lib) || (NULL == sur.sur_handle) )
+ return false;
+ return true;
+}
+
+/*
+ * if out device is headset and android settings
+ * 3d surround switch opened, use surround.
+ */
+bool surround_use(int out_device)
+{
+ int hs_on;
+ int use;
+ char value[PROPERTY_VALUE_MAX];
+
+ /* get the current switch state. Default value is close. */
+ property_get("persist.sys.audio_3d_surround", value, "0");
+ use = atoi(value);
+
+ hs_on = out_device & (AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
+ return (hs_on && use);
+}
+
+int surround_process(struct audio_3d_surround sur, short *buf, int frames, int channels)
+{
+ sur.surround_pro_in_out(sur.sur_handle, buf, buf, frames * channels);
+
+ return 0;
+}
+
+void surround_exit(struct audio_3d_surround *sur)
+{
+ if (sur->sur_handle != NULL) {
+ sur->process_exit(sur->sur_handle);
+ sur->sur_handle = NULL;
+ }
+
+ if (sur->lib != NULL) {
+ dlclose(sur->lib);
+ sur->lib = NULL;
+ }
+}
+
diff --git a/audio/tulip/audio_3d_surround/audio_3d_surround.h b/audio/tulip/audio_3d_surround/audio_3d_surround.h
new file mode 100755
index 0000000..7325043
--- /dev/null
+++ b/audio/tulip/audio_3d_surround/audio_3d_surround.h
@@ -0,0 +1,30 @@
+#ifndef __AUDIO_3D_SURROUND_H_
+#define __AUDIO_3D_SURROUND_H_
+
+/*
+ * the 3d surround struct
+ *
+ */
+struct audio_3d_surround {
+ void *lib;
+
+ void *sur_handle;
+ void *(*process_init)(void *handle, int samp_rate, int chn, int num_frame);
+ void (*surround_pro_in_out)(void *handle, short *buf, short *new_sp, int data_num);
+ void (*process_exit)(void *handle);
+ void (*set_space)(void *handle, double space_gain);
+ void (*set_bass)(void *handle, double sub_gain);
+ void (*set_defintion)(void *handle, double defintion_gain);
+};
+
+/*
+ * interface for user
+ *
+ */
+int surround_init(struct audio_3d_surround *sur, int samp_rate, int chn, int num_frame);
+bool surround_ready(struct audio_3d_surround sur);
+bool surround_use(int out_device);
+int surround_process(struct audio_3d_surround sur, short *buf, int frames, int channels);
+void surround_exit(struct audio_3d_surround *sur);
+
+#endif
diff --git a/audio/tulip/libAwHeadpSurround.so b/audio/tulip/audio_3d_surround/libAwHeadpSurround.so
similarity index 100%
rename from audio/tulip/libAwHeadpSurround.so
rename to audio/tulip/audio_3d_surround/libAwHeadpSurround.so
diff --git a/audio/tulip/audio_hw.c b/audio/tulip/audio_hw.c
index c16c44e..068bd11 100755
--- a/audio/tulip/audio_hw.c
+++ b/audio/tulip/audio_hw.c
@@ -41,11 +41,11 @@
#include "audio_iface.h"
#include "volume.h"
+#include
+#include
-#include // for property_get
-
-#include //add by wjc
-#define VVS_USED 1
+#include "audio_3d_surround/audio_3d_surround.h"
+#define USE_3D_SURROUND 1
#define F_LOG ALOGV("%s, line: %d", __FUNCTION__, __LINE__);
@@ -67,14 +67,15 @@ static bool NO_EARPIECE = 1;
#define PORT_HDMI 0
#define PORT_SPDIF 0
#define PORT_MODEM 1
-#define PORT_VIR_CODEC 2
-#define PORT_bt 3
+#define PORT_VIR_CODEC 2
+#define PORT_bt 3
#define SAMPLING_RATE_8K 8000
#define SAMPLING_RATE_11K 11025
#define SAMPLING_RATE_44K 44100
#define SAMPLING_RATE_48K 48000
#define SAMPLING_RATE_22050 22050
+
/* constraint imposed by ABE: all period sizes must be multiples of 24 */
#define ABE_BASE_FRAME_COUNT 24
/* number of base blocks in a short period (low latency) */
@@ -84,14 +85,13 @@ static bool NO_EARPIECE = 1;
//#define SHORT_PERIOD_SIZE (ABE_BASE_FRAME_COUNT * SHORT_PERIOD_MULTIPLIER)
#define SHORT_PERIOD_SIZE 1024
-
/* number of short periods in a long period (low power) */
//#define LONG_PERIOD_MULTIPLIER 14 /* 308 ms */
#define LONG_PERIOD_MULTIPLIER 6 /* 240 ms */
/* number of frames per long period (low power) */
#define LONG_PERIOD_SIZE (SHORT_PERIOD_SIZE * LONG_PERIOD_MULTIPLIER)
/* number of pseudo periods for playback */
-#define PLAYBACK_PERIOD_COUNT 4
+#define PLAYBACK_PERIOD_COUNT 3
/* number of periods for capture */
#define CAPTURE_PERIOD_COUNT 2
/* minimum sleep time in out_write() when write threshold is not reached */
@@ -115,7 +115,6 @@ static bool dmic_used = 0;
static bool spk_dul_used = 0;
static bool last_communication_is_bt = 0;
-
/*VOLUME CTL*/
#define MIXER_HP_VOLUME "headphone volume"
#define MIXER_SPK_VOLUME "speaker volume"
@@ -137,168 +136,175 @@ static bool last_communication_is_bt = 0;
static int spkvolume_init = 0x1b;
static int earpiecevolume_init = 0x1e;
static int hpvolume_init = 0x3b;
+
enum tty_modes {
- TTY_MODE_OFF,
- TTY_MODE_VCO,
- TTY_MODE_HCO,
- TTY_MODE_FULL
+ TTY_MODE_OFF,
+ TTY_MODE_VCO,
+ TTY_MODE_HCO,
+ TTY_MODE_FULL
};
enum {
- OUT_DEVICE_SPEAKER,
- OUT_DEVICE_HEADSET,
- OUT_DEVICE_HEADPHONES,
- OUT_DEVICE_BT_SCO,
- OUT_DEVICE_SPEAKER_AND_HEADSET,
- OUT_DEVICE_EARPIECE,
- OUT_DEVICE_SINGLE_SPEAKER,
- OUT_DEVICE_TAB_SIZE, /* number of rows in route_configs[][] */
+ OUT_DEVICE_SPEAKER,
+ OUT_DEVICE_HEADSET,
+ OUT_DEVICE_HEADPHONES,
+ OUT_DEVICE_BT_SCO,
+ OUT_DEVICE_SPEAKER_AND_HEADSET,
+ OUT_DEVICE_EARPIECE,
+ OUT_DEVICE_SINGLE_SPEAKER,
+ OUT_DEVICE_TAB_SIZE, /* number of rows in route_configs[][] */
};
enum {
- IN_SOURCE_MAINMIC,
- IN_SOURCE_HEADSETMIC,
- IN_SOURCE_BTMIC,
- IN_SOURCE_TAB_SIZE, /* number of lines in route_configs[][] */
- IN_SOURCE_NONE,
+ IN_SOURCE_MAINMIC,
+ IN_SOURCE_HEADSETMIC,
+ IN_SOURCE_BTMIC,
+ IN_SOURCE_TAB_SIZE, /* number of lines in route_configs[][] */
+ IN_SOURCE_NONE,
};
+
const char * const normal_route_configs[OUT_DEVICE_TAB_SIZE] = {
- media_speaker, /* OUT_DEVICE_SPEAKER */
- media_headset, /* OUT_DEVICE_HEADSET */
- media_headphones, /* OUT_DEVICE_HEADPHONES */
- media_bluetooth_sco, /* OUT_DEVICE_BT_SCO */
- media_speaker_and_headphones, /* OUT_DEVICE_SPEAKER_AND_HEADSET */
- media_earpiece, /* OUT_DEVICE_EARPIECE */
- media_single_speaker, /* OUT_DEVICE_SINGLE_SPEAKER */
+ media_speaker, /* OUT_DEVICE_SPEAKER */
+ media_headset, /* OUT_DEVICE_HEADSET */
+ media_headphones, /* OUT_DEVICE_HEADPHONES */
+ media_bluetooth_sco, /* OUT_DEVICE_BT_SCO */
+ media_speaker_and_headphones, /* OUT_DEVICE_SPEAKER_AND_HEADSET */
+ media_earpiece, /* OUT_DEVICE_EARPIECE */
+ media_single_speaker, /* OUT_DEVICE_SINGLE_SPEAKER */
};
+
const char * const ringtone_route_configs[OUT_DEVICE_TAB_SIZE] = {
- media_speaker, /* OUT_DEVICE_SPEAKER */
- "null", /* OUT_DEVICE_HEADSET */
- "null", /* OUT_DEVICE_HEADPHONES */
- "null", /* OUT_DEVICE_BT_SCO */
- media_speaker_and_headphones, /* OUT_DEVICE_SPEAKER_AND_HEADSET */
- "null", /* OUT_DEVICE_EARPIECE */
- "null",
+ media_speaker, /* OUT_DEVICE_SPEAKER */
+ "null", /* OUT_DEVICE_HEADSET */
+ "null", /* OUT_DEVICE_HEADPHONES */
+ "null", /* OUT_DEVICE_BT_SCO */
+ media_speaker_and_headphones, /* OUT_DEVICE_SPEAKER_AND_HEADSET */
+ "null", /* OUT_DEVICE_EARPIECE */
+ "null",
};
+
const char * const phone_keytone_route_configs[2][OUT_DEVICE_TAB_SIZE] = {
{
- "abb-phone-keytone-speaker", /* OUT_DEVICE_SPEAKER */
- "abb-phone-keytone-headphones", /* OUT_DEVICE_HEADSET */
- "abb-phone-keytone-headphones", /* OUT_DEVICE_HEADPHONES */
- "abb-phone-keytone-bt", /* OUT_DEVICE_BT_SCO */
- "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
- "abb-phone-keytone-earpiece", /* OUT_DEVICE_EARPIECE */
- "null"
+ "abb-phone-keytone-speaker", /* OUT_DEVICE_SPEAKER */
+ "abb-phone-keytone-headphones", /* OUT_DEVICE_HEADSET */
+ "abb-phone-keytone-headphones", /* OUT_DEVICE_HEADPHONES */
+ "abb-phone-keytone-bt", /* OUT_DEVICE_BT_SCO */
+ "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
+ "abb-phone-keytone-earpiece", /* OUT_DEVICE_EARPIECE */
+ "null"
},
- {
- "null", /* OUT_DEVICE_SPEAKER */
- "null", /* OUT_DEVICE_HEADSET */
- "null", /* OUT_DEVICE_HEADPHONES */
- "null", /* OUT_DEVICE_BT_SCO */
- "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
- "null", /* OUT_DEVICE_EARPIECE */
- "null"
+ {
+ "null", /* OUT_DEVICE_SPEAKER */
+ "null", /* OUT_DEVICE_HEADSET */
+ "null", /* OUT_DEVICE_HEADPHONES */
+ "null", /* OUT_DEVICE_BT_SCO */
+ "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
+ "null", /* OUT_DEVICE_EARPIECE */
+ "null"
}
};
+
const char * const phone_route_configs[2][OUT_DEVICE_TAB_SIZE] = {
{
- /*plan_one*/
- "analog-phone-speaker", /* OUT_DEVICE_SPEAKER */
- "analog-phone-headset", /* OUT_DEVICE_HEADSET */
- "analog-phone-headphone", /* OUT_DEVICE_HEADPHONES */
- "analog-phone-bt", /* OUT_DEVICE_BT_SCO */
- "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
- "analog-phone-earpiece", /* OUT_DEVICE_EARPIECE */
- "null"
- }
- ,
+ /* plan_one */
+ "analog-phone-speaker", /* OUT_DEVICE_SPEAKER */
+ "analog-phone-headset", /* OUT_DEVICE_HEADSET */
+ "analog-phone-headphone", /* OUT_DEVICE_HEADPHONES */
+ "analog-phone-bt", /* OUT_DEVICE_BT_SCO */
+ "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
+ "analog-phone-earpiece", /* OUT_DEVICE_EARPIECE */
+ "null"
+ },
{
- /*plan_two*/
- "digital-phone-speaker", /* OUT_DEVICE_SPEAKER */
- "digital-phone-headset", /* OUT_DEVICE_HEADSET */
- "digital-phone-headphone", /* OUT_DEVICE_HEADPHONES */
- "digital-phone-bt", /* OUT_DEVICE_BT_SCO */
- "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
- "digital-phone-earpiece", /* OUT_DEVICE_EARPIECE */
- "null"
+ /* plan_two */
+ "digital-phone-speaker", /* OUT_DEVICE_SPEAKER */
+ "digital-phone-headset", /* OUT_DEVICE_HEADSET */
+ "digital-phone-headphone", /* OUT_DEVICE_HEADPHONES */
+ "digital-phone-bt", /* OUT_DEVICE_BT_SCO */
+ "null", /* OUT_DEVICE_SPEAKER_AND_HEADSET */
+ "digital-phone-earpiece", /* OUT_DEVICE_EARPIECE */
+ "null"
}
};
+
const char * const cap_normal_route_configs[IN_SOURCE_TAB_SIZE] = {
- media_mainmic, /* IN_DEVICE_MAINMIC */
- media_headsetmic, /* IN_DEVICE_HEADSET */
- media_btmic, /* IN_DEVICE_bt */
+ media_mainmic, /* IN_DEVICE_MAINMIC */
+ media_headsetmic, /* IN_DEVICE_HEADSET */
+ media_btmic, /* IN_DEVICE_bt */
};
const char * const dmic_cap_normal_route_configs[IN_SOURCE_TAB_SIZE] = {
- media_main_dmic, /* IN_DEVICE_MAINMIC */
- media_headsetmic, /* IN_DEVICE_HEADSET */
- media_btmic, /* IN_DEVICE_bt */
+ media_main_dmic, /* IN_DEVICE_MAINMIC */
+ media_headsetmic, /* IN_DEVICE_HEADSET */
+ media_btmic, /* IN_DEVICE_bt */
};
const char * const cap_phone_normal_route_configs[2][IN_SOURCE_TAB_SIZE] = {
{
- "capture-abb-phone-mainmic", /* IN_DEVICE_MAINMIC */
- "capture-abb-phone-headsetmic", /* IN_DEVICE_HEADSET */
- "capture-abb-phone-btmic", /* IN_DEVICE_bt */
- }
- ,
+ "capture-abb-phone-mainmic", /* IN_DEVICE_MAINMIC */
+ "capture-abb-phone-headsetmic", /* IN_DEVICE_HEADSET */
+ "capture-abb-phone-btmic", /* IN_DEVICE_bt */
+ },
{
- "capture-dbb-phone-mainmic", /* IN_DEVICE_MAINMIC */
- "capture-dbb-phone-headsetmic", /* IN_DEVICE_HEADSET */
- "capture-dbb-phone-btmic", /* IN_DEVICE_bt */
+ "capture-dbb-phone-mainmic", /* IN_DEVICE_MAINMIC */
+ "capture-dbb-phone-headsetmic", /* IN_DEVICE_HEADSET */
+ "capture-dbb-phone-btmic", /* IN_DEVICE_bt */
}
};
+
struct pcm_config pcm_config_mm_out = {
- .channels = 2,
- .rate = MM_SAMPLING_RATE,
- .period_size = SHORT_PERIOD_SIZE,
- .period_count = PLAYBACK_PERIOD_COUNT,
- .format = PCM_FORMAT_S16_LE,
+ .channels = 2,
+ .rate = MM_SAMPLING_RATE,
+ .period_size = SHORT_PERIOD_SIZE,
+ .period_count = PLAYBACK_PERIOD_COUNT,
+ .format = PCM_FORMAT_S16_LE,
};
struct pcm_config pcm_config_mm_in = {
- .channels = 2,
- .rate = MM_SAMPLING_RATE,
- .period_size = 1024,
- .period_count = CAPTURE_PERIOD_COUNT,
- .format = PCM_FORMAT_S16_LE,
+ .channels = 2,
+ .rate = MM_SAMPLING_RATE,
+ .period_size = 1024,
+ .period_count = CAPTURE_PERIOD_COUNT,
+ .format = PCM_FORMAT_S16_LE,
};
+
struct pcm_config pcm_config_vx = {
- .channels = 1,
- .rate = SAMPLING_RATE_8K,
- .period_size = 160,
- .period_count = 2,
- .format = PCM_FORMAT_S16_LE,
+ .channels = 1,
+ .rate = SAMPLING_RATE_8K,
+ .period_size = 160,
+ .period_count = 2,
+ .format = PCM_FORMAT_S16_LE,
};
+
struct route_setting
{
- char *ctl_name;
- int intval;
- char *strval;
+ char *ctl_name;
+ int intval;
+ char *strval;
};
struct mixer_volumectls
{
- struct mixer_ctl *hpvolume;
- struct mixer_ctl *spkvolume;
- struct mixer_ctl *earpiecevolume;
+ struct mixer_ctl *hpvolume;
+ struct mixer_ctl *spkvolume;
+ struct mixer_ctl *earpiecevolume;
};
struct pcm_buf_manager
{
- pthread_mutex_t lock; /* see note below on mutex acquisition order */
- bool BufExist;
- unsigned char *BufStart;
- int BufTotalLen;
- unsigned char *BufReadPtr;
- int DataLen;
- unsigned char *BufWritPtr;
- int BufValideLen;
- int SampleRate;
- int Channel;
- struct sunxi_audio_device *dev;
+ pthread_mutex_t lock; /* see note below on mutex acquisition order */
+ bool BufExist;
+ unsigned char *BufStart;
+ int BufTotalLen;
+ unsigned char *BufReadPtr;
+ int DataLen;
+ unsigned char *BufWritPtr;
+ int BufValideLen;
+ int SampleRate;
+ int Channel;
+ struct sunxi_audio_device *dev;
};
struct sunxi_audio_device {
@@ -334,83 +340,54 @@ struct sunxi_audio_device {
};
-#if VVS_USED
-/* vvs is the struct about 3D audio */
-struct vvs {
- bool vvs_used;
- void *lib_handle;
- void *vvs_handle;
- void *(*process_init)(void *handle, int samp_rate, int chn, int NumFrame);
- void (*surround_pro_in_out)(void *handle, short* BUFFER, short* NewSp, int DataNum);
- void (*process_exit)(void *handle);
-
- void (*set_space)(void *handle, double space_gain);
- void (*set_bass)(void *handle, double sub_gain);
- void (*set_defintion)(void *handle, double defintion_gain);
-};
-
-struct vvs vvs = {
- .vvs_used = false,
- .lib_handle = NULL,
- .vvs_handle = NULL,
- .process_init = NULL,
- .surround_pro_in_out = NULL,
- .process_exit = NULL,
- .set_space = NULL,
- .set_bass = NULL,
- .set_defintion = NULL,
- };
-
+#if USE_3D_SURROUND
+struct audio_3d_surround sur;
#endif
-
struct sunxi_stream_out {
- struct audio_stream_out stream;
+ struct audio_stream_out stream;
- pthread_mutex_t lock; /* see note below on mutex acquisition order */
- struct pcm_config config;
- struct pcm *pcm;
- struct resampler_itfe *resampler;
- char *buffer;
- int standby;
- struct echo_reference_itfe *echo_reference;
- struct sunxi_audio_device *dev;
- int write_threshold;
- uint64_t written;
+ pthread_mutex_t lock; /* see note below on mutex acquisition order */
+ struct pcm_config config;
+ struct pcm *pcm;
+ struct resampler_itfe *resampler;
+ char *buffer;
+ int standby;
+ struct echo_reference_itfe *echo_reference;
+ struct sunxi_audio_device *dev;
+ int write_threshold;
+ uint64_t written;
};
-
-
-
#define MAX_PREPROCESSORS 3 /* maximum one AGC + one NS + one AEC per input stream */
struct sunxi_stream_in {
- struct audio_stream_in stream;
+ struct audio_stream_in stream;
- pthread_mutex_t lock; /* see note below on mutex acquisition order */
- struct pcm_config config;
- struct pcm *pcm;
- int device;
- struct resampler_itfe *resampler;
- struct resampler_buffer_provider buf_provider;
- int16_t *buffer;
- size_t frames_in;
- unsigned int requested_rate;
- int standby;
- int source;
- struct echo_reference_itfe *echo_reference;
- bool need_echo_reference;
- effect_handle_t preprocessors[MAX_PREPROCESSORS];
- int num_preprocessors;
- int16_t *proc_buf;
- size_t proc_buf_size;
- size_t proc_frames_in;
- int16_t *ref_buf;
- size_t ref_buf_size;
- size_t ref_frames_in;
- int read_status;
+ pthread_mutex_t lock; /* see note below on mutex acquisition order */
+ struct pcm_config config;
+ struct pcm *pcm;
+ int device;
+ struct resampler_itfe *resampler;
+ struct resampler_buffer_provider buf_provider;
+ int16_t *buffer;
+ size_t frames_in;
+ unsigned int requested_rate;
+ int standby;
+ int source;
+ struct echo_reference_itfe *echo_reference;
+ bool need_echo_reference;
+ effect_handle_t preprocessors[MAX_PREPROCESSORS];
+ int num_preprocessors;
+ int16_t *proc_buf;
+ size_t proc_buf_size;
+ size_t proc_frames_in;
+ int16_t *ref_buf;
+ size_t ref_buf_size;
+ size_t ref_frames_in;
+ int read_status;
- struct sunxi_audio_device *dev;
+ struct sunxi_audio_device *dev;
};
/*wifi display buffer manager*/
@@ -418,8 +395,7 @@ static int WritePcmData(void * pInbuf, int inSize, struct pcm_buf_manager *PcmMa
{
ALOGV("RequestWriteBuf ++: size: %d", inSize);
- if (PcmManager->BufValideLen< inSize)
- {
+ if (PcmManager->BufValideLen< inSize) {
ALOGE("not enough buffer to write");
return -1;
}
@@ -427,8 +403,7 @@ static int WritePcmData(void * pInbuf, int inSize, struct pcm_buf_manager *PcmMa
pthread_mutex_lock(&PcmManager->lock);
if ((PcmManager->BufWritPtr + inSize)
- > (PcmManager->BufStart + PcmManager->BufTotalLen))
- {
+ > (PcmManager->BufStart + PcmManager->BufTotalLen)) {
int endSize = PcmManager->BufStart + PcmManager->BufTotalLen
- PcmManager->BufWritPtr;
memcpy(PcmManager->BufWritPtr, pInbuf, endSize);
@@ -436,9 +411,7 @@ static int WritePcmData(void * pInbuf, int inSize, struct pcm_buf_manager *PcmMa
PcmManager->BufWritPtr = PcmManager->BufWritPtr
+ inSize - PcmManager->BufTotalLen;
- }
- else
- {
+ } else {
memcpy(PcmManager->BufWritPtr, pInbuf, inSize);
PcmManager->BufWritPtr += inSize;
}
@@ -447,8 +420,8 @@ static int WritePcmData(void * pInbuf, int inSize, struct pcm_buf_manager *PcmMa
PcmManager->DataLen += inSize;
ALOGV("after wr: BufTotalLen: %d, DataLen: %d, BufValideLen: %d, BufReadPtr: %p, BufWritPtr: %p",
- PcmManager->BufTotalLen, PcmManager->DataLen, PcmManager->BufValideLen,
- PcmManager->BufReadPtr, PcmManager->BufWritPtr);
+ PcmManager->BufTotalLen, PcmManager->DataLen, PcmManager->BufValideLen,
+ PcmManager->BufReadPtr, PcmManager->BufWritPtr);
pthread_mutex_unlock(&PcmManager->lock);
ALOGV("RequestWriteBuf --");
@@ -467,29 +440,25 @@ static int ReadPcmData(void *pBuf, int uGetLen, struct pcm_buf_manager *PcmManag
max_wait_count *= 2;//twice
ALOGV("ReadPcmDataForEnc ++, getLen: %d max_wait_count=%d", uGetLen,max_wait_count);
- if (adev->active_output != NULL)
- {
- while(PcmManager->DataLen < uGetLen)
- {
- ALOGV("pcm is not enough for audio encoder! uGetLen: %d, uDataLen: %d\n",
- uGetLen, PcmManager->DataLen);
- usleep(10 * 1000);
- timeout++;
- if(timeout > max_wait_count) {
+ if (adev->active_output != NULL) {
+ while (PcmManager->DataLen < uGetLen) {
+ ALOGV("pcm is not enough for audio encoder! uGetLen: %d, uDataLen: %d\n",
+ uGetLen, PcmManager->DataLen);
+ usleep(10 * 1000);
+ timeout++;
+ if (timeout > max_wait_count) {
if (PcmManager->DataLen < uGetLen) {
underflow = 1;
size_read = PcmManager->DataLen;
fill_dc_size = uGetLen - PcmManager->DataLen;
ALOGV("fill with dc size:%d",uGetLen - PcmManager->DataLen);
}
- break;
- }
- }
- }
- else
- {
- ALOGV("pcm is not enough for audio encoder! uGetLen: %d, uDataLen: %d\n",
- uGetLen, PcmManager->DataLen);
+ break;
+ }
+ }
+ } else {
+ ALOGV("pcm is not enough for audio encoder! uGetLen: %d, uDataLen: %d\n",
+ uGetLen, PcmManager->DataLen);
if (PcmManager->DataLen < uGetLen) {
underflow = 1;
size_read = PcmManager->DataLen;
@@ -499,44 +468,40 @@ static int ReadPcmData(void *pBuf, int uGetLen, struct pcm_buf_manager *PcmManag
}
}
- if((PcmManager->BufReadPtr + size_read)
- > (PcmManager->BufStart + PcmManager->BufTotalLen))
- {
- int len1 = PcmManager->BufStart
+ if ((PcmManager->BufReadPtr + size_read)
+ > (PcmManager->BufStart + PcmManager->BufTotalLen)) {
+ int len1 = PcmManager->BufStart
+ PcmManager->BufTotalLen - PcmManager->BufReadPtr;
- memcpy((void *)pBuf, (void *)PcmManager->BufReadPtr, len1);
- memcpy((void *)((char *)pBuf + len1), (void *)PcmManager->BufStart, size_read - len1);
- }
- else
- {
- memcpy(pBuf, PcmManager->BufReadPtr, size_read);
- }
+ memcpy((void *)pBuf, (void *)PcmManager->BufReadPtr, len1);
+ memcpy((void *)((char *)pBuf + len1), (void *)PcmManager->BufStart, size_read - len1);
+ } else {
+ memcpy(pBuf, PcmManager->BufReadPtr, size_read);
+ }
- pthread_mutex_lock(&PcmManager->lock);
+ pthread_mutex_lock(&PcmManager->lock);
- PcmManager->BufReadPtr += size_read;
+ PcmManager->BufReadPtr += size_read;
- if(PcmManager->BufReadPtr
- >= PcmManager->BufStart + PcmManager->BufTotalLen)
- {
- PcmManager->BufReadPtr -= PcmManager->BufTotalLen;
- }
- PcmManager->DataLen -= size_read;
- PcmManager->BufValideLen += size_read;
+ if (PcmManager->BufReadPtr
+ >= PcmManager->BufStart + PcmManager->BufTotalLen) {
+ PcmManager->BufReadPtr -= PcmManager->BufTotalLen;
+ }
+ PcmManager->DataLen -= size_read;
+ PcmManager->BufValideLen += size_read;
- ALOGV("after rd: BufTotalLen: %d, DataLen: %d, BufValideLen: %d, pBufReadPtr: %p, pBufWritPtr: %p",
- PcmManager->BufTotalLen, PcmManager->DataLen, PcmManager->BufValideLen,
- PcmManager->BufReadPtr, PcmManager->BufWritPtr);
+ ALOGV("after rd: BufTotalLen: %d, DataLen: %d, BufValideLen: %d, pBufReadPtr: %p, pBufWritPtr: %p",
+ PcmManager->BufTotalLen, PcmManager->DataLen, PcmManager->BufValideLen,
+ PcmManager->BufReadPtr, PcmManager->BufWritPtr);
- pthread_mutex_unlock(&PcmManager->lock);
- ALOGV("ReadPcmDataForEnc --");
+ pthread_mutex_unlock(&PcmManager->lock);
+ ALOGV("ReadPcmDataForEnc --");
- if (underflow) {
- char *ptr = (char*)pBuf;
- memset(ptr+size_read, ptr[size_read-1], fill_dc_size);
- }
+ if (underflow) {
+ char *ptr = (char*)pBuf;
+ memset(ptr+size_read, ptr[size_read-1], fill_dc_size);
+ }
- return uGetLen;
+ return uGetLen;
}
/**
@@ -545,7 +510,6 @@ static int ReadPcmData(void *pBuf, int uGetLen, struct pcm_buf_manager *PcmManag
*/
static void select_device(struct sunxi_audio_device *adev);
-//static void select_device(struct sunxi_audio_device *adev);
static int adev_set_voice_volume(struct audio_hw_device *dev, float volume);
static int do_input_standby(struct sunxi_stream_in *in);
static int do_output_standby(struct sunxi_stream_out *out);
@@ -553,41 +517,43 @@ static int do_output_standby(struct sunxi_stream_out *out);
/* The enable flag when 0 makes the assumption that enums are disabled by
* "Off" and integers/booleans by 0 */
static int set_route_by_array(struct mixer *mixer, struct route_setting *route,
- int enable)
+ int enable)
{
- struct mixer_ctl *ctl;
- unsigned int i, j;
+ struct mixer_ctl *ctl;
+ unsigned int i, j;
- /* Go through the route array and set each value */
- i = 0;
- while (route[i].ctl_name) {
- ctl = mixer_get_ctl_by_name(mixer, route[i].ctl_name);
- if (!ctl)
- return -EINVAL;
+ /* Go through the route array and set each value */
+ i = 0;
+ while (route[i].ctl_name) {
+ ctl = mixer_get_ctl_by_name(mixer, route[i].ctl_name);
+ if (!ctl)
+ return -EINVAL;
- if (route[i].strval) {
- if (enable)
- mixer_ctl_set_enum_by_string(ctl, route[i].strval);
- else
- mixer_ctl_set_enum_by_string(ctl, "Off");
- } else {
- /* This ensures multiple (i.e. stereo) values are set jointly */
- for (j = 0; j < mixer_ctl_get_num_values(ctl); j++) {
- if (enable)
- mixer_ctl_set_value(ctl, j, route[i].intval);
- else
- mixer_ctl_set_value(ctl, j, 0);
- }
- }
- i++;
- }
+ if (route[i].strval) {
+ if (enable)
+ mixer_ctl_set_enum_by_string(ctl, route[i].strval);
+ else
+ mixer_ctl_set_enum_by_string(ctl, "Off");
+ } else {
+ /* This ensures multiple (i.e. stereo) values are set jointly */
+ for (j = 0; j < mixer_ctl_get_num_values(ctl); j++) {
+ if (enable)
+ mixer_ctl_set_value(ctl, j, route[i].intval);
+ else
+ mixer_ctl_set_value(ctl, j, 0);
+ }
+ }
+ i++;
+ }
- return 0;
+ return 0;
}
+
static int bt_start_call(struct sunxi_audio_device *adev)
{
ALOGE("Opening modem PCMs");
ALOGV("%s, line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
+
if (CASE_NAME == 1){
/* Open modem PCM channels */
if (adev->pcm_modem_dl == NULL) {
@@ -628,8 +594,8 @@ static int bt_start_call(struct sunxi_audio_device *adev)
pcm_start(adev->pcm_bt_dl);
pcm_start(adev->pcm_bt_ul);
- } else if(CASE_NAME == 2){
- /* Open bt PCM channels */
+ } else if (CASE_NAME == 2) {
+ /* Open bt PCM channels */
if (adev->pcm_bt_dl == NULL) {
adev->pcm_bt_dl = pcm_open(0, PORT_bt, PCM_OUT, &pcm_config_vx);
if (!pcm_is_ready(adev->pcm_bt_dl)) {
@@ -648,8 +614,8 @@ static int bt_start_call(struct sunxi_audio_device *adev)
pcm_start(adev->pcm_bt_dl);
pcm_start(adev->pcm_bt_ul);
- }else {
- ALOGV("%s,PHONE CASE ERR!!!!!!!! line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
+ } else {
+ ALOGV("%s,PHONE CASE ERR!!!!!!!! line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
}
return 0;
@@ -666,12 +632,14 @@ err_open_bt_ul:
err_open_bt_dl:
pcm_close(adev->pcm_bt_dl);
adev->pcm_bt_dl = NULL;
+
return -ENOMEM;
}
+
static void end_bt_call(struct sunxi_audio_device *adev)
{
F_LOG;
- if (CASE_NAME == 1){
+ if (CASE_NAME == 1) {
pcm_stop(adev->pcm_modem_dl);
pcm_stop(adev->pcm_modem_ul);
pcm_close(adev->pcm_modem_dl);
@@ -685,8 +653,8 @@ static void end_bt_call(struct sunxi_audio_device *adev)
pcm_close(adev->pcm_bt_ul);
adev->pcm_bt_dl = NULL;
adev->pcm_bt_ul = NULL;
- //return 0;
- } else if(CASE_NAME == 2){
+
+ } else if (CASE_NAME == 2) {
pcm_stop(adev->pcm_bt_dl);
pcm_stop(adev->pcm_bt_ul);
pcm_close(adev->pcm_bt_dl);
@@ -694,33 +662,36 @@ static void end_bt_call(struct sunxi_audio_device *adev)
adev->pcm_bt_dl = NULL;
adev->pcm_bt_ul = NULL;
}
- ALOGE("Closing modem PCMs");
+
+ ALOGE("Closing modem PCMs");
}
+
static int start_call(struct sunxi_audio_device *adev)
{
ALOGE("Opening modem PCMs");
ALOGV("%s, line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
- if (CASE_NAME == 1){
- return 0;
- } else if(CASE_NAME == 2){
- }else {
- ALOGV("%s,PHONE CASE ERR!!!!!!!! line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
+ if (CASE_NAME == 1) {
+ return 0;
+ } else if (CASE_NAME == 2) {
+
+ } else {
+ ALOGV("%s,PHONE CASE ERR!!!!!!!! line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
}
/* Open modem PCM channels */
if (adev->pcm_modem_dl == NULL) {
- adev->pcm_modem_dl = pcm_open(0, PORT_MODEM, PCM_OUT, &pcm_config_vx);
- if (!pcm_is_ready(adev->pcm_modem_dl)) {
- ALOGE("cannot open PCM modem DL stream: %s", pcm_get_error(adev->pcm_modem_dl));
+ adev->pcm_modem_dl = pcm_open(0, PORT_MODEM, PCM_OUT, &pcm_config_vx);
+ if (!pcm_is_ready(adev->pcm_modem_dl)) {
+ ALOGE("cannot open PCM modem DL stream: %s", pcm_get_error(adev->pcm_modem_dl));
goto err_open_dl;
}
}
if (adev->pcm_modem_ul == NULL) {
- adev->pcm_modem_ul = pcm_open(0, PORT_MODEM, PCM_IN, &pcm_config_vx);
- if (!pcm_is_ready(adev->pcm_modem_ul)) {
- ALOGE("cannot open PCM modem UL stream: %s", pcm_get_error(adev->pcm_modem_ul));
+ adev->pcm_modem_ul = pcm_open(0, PORT_MODEM, PCM_IN, &pcm_config_vx);
+ if (!pcm_is_ready(adev->pcm_modem_ul)) {
+ ALOGE("cannot open PCM modem UL stream: %s", pcm_get_error(adev->pcm_modem_ul));
goto err_open_ul;
}
}
@@ -742,13 +713,12 @@ err_open_dl:
static void end_call(struct sunxi_audio_device *adev)
{
F_LOG;
- if (CASE_NAME == 1){
+ if (CASE_NAME == 1) {
if (last_call_path_is_bt) {
end_bt_call(adev);
last_call_path_is_bt = 0;
}
- //return 0;
- } else if(CASE_NAME == 2){
+ } else if (CASE_NAME == 2) {
if (last_call_path_is_bt) {
end_bt_call(adev);
last_call_path_is_bt = 0;
@@ -761,154 +731,156 @@ static void end_call(struct sunxi_audio_device *adev)
adev->pcm_modem_dl = NULL;
adev->pcm_modem_ul = NULL;
}
+
mixer_ctl_set_value(adev->mixer_volumectls.spkvolume, 0, spkvolume_init);
mixer_ctl_set_value(adev->mixer_volumectls.earpiecevolume, 0, earpiecevolume_init);
mixer_ctl_set_value(adev->mixer_volumectls.hpvolume, 0, hpvolume_init);
- //clear_phone_route();
+
ALOGD("end_call, bluetooth_nrec=%d", adev->bluetooth_nrec);
}
static void set_incall_device(struct sunxi_audio_device *adev)
{
- int device_type;
+ int device_type;
F_LOG;
- switch(adev->out_device) {
- case AUDIO_DEVICE_OUT_EARPIECE:
- device_type = RIL_AUDIO_PATH_EARPIECE;
- break;
- case AUDIO_DEVICE_OUT_SPEAKER:
- case AUDIO_DEVICE_OUT_AUX_DIGITAL:
- device_type = RIL_AUDIO_PATH_SPK;
- break;
- case AUDIO_DEVICE_OUT_WIRED_HEADSET:
- device_type = RIL_AUDIO_PATH_HEADSET;
- break;
- case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
- device_type = RIL_AUDIO_PATH_HEADSET;
- break;
- case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
- case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
- case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
- device_type = RIL_AUDIO_PATH_BT;
- break;
- default:
- device_type = RIL_AUDIO_PATH_EARPIECE;
- break;
- }
+ switch(adev->out_device) {
+ case AUDIO_DEVICE_OUT_EARPIECE:
+ device_type = RIL_AUDIO_PATH_EARPIECE;
+ break;
+ case AUDIO_DEVICE_OUT_SPEAKER:
+ case AUDIO_DEVICE_OUT_AUX_DIGITAL:
+ device_type = RIL_AUDIO_PATH_SPK;
+ break;
+ case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+ device_type = RIL_AUDIO_PATH_HEADSET;
+ break;
+ case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+ device_type = RIL_AUDIO_PATH_HEADSET;
+ break;
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
+ device_type = RIL_AUDIO_PATH_BT;
+ break;
+ default:
+ device_type = RIL_AUDIO_PATH_EARPIECE;
+ break;
+ }
ril_set_call_audio_path(device_type);
}
static void set_bp_volume(struct sunxi_audio_device *adev, int volume)
{
- int device_type;
+ int device_type;
F_LOG;
- switch(adev->out_device) {
- case AUDIO_DEVICE_OUT_EARPIECE:
- device_type = RIL_AUDIO_PATH_EARPIECE;
- break;
- case AUDIO_DEVICE_OUT_SPEAKER:
- case AUDIO_DEVICE_OUT_AUX_DIGITAL:
- device_type = RIL_AUDIO_PATH_SPK;
- break;
- case AUDIO_DEVICE_OUT_WIRED_HEADSET:
- device_type = RIL_AUDIO_PATH_HEADSET;
- break;
- case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
- device_type = RIL_AUDIO_PATH_HEADSET;
- break;
- case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
- case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
- case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
- device_type = RIL_AUDIO_PATH_BT;
- break;
- default:
- device_type = RIL_AUDIO_PATH_EARPIECE;
- break;
- }
+ switch(adev->out_device) {
+ case AUDIO_DEVICE_OUT_EARPIECE:
+ device_type = RIL_AUDIO_PATH_EARPIECE;
+ break;
+ case AUDIO_DEVICE_OUT_SPEAKER:
+ case AUDIO_DEVICE_OUT_AUX_DIGITAL:
+ device_type = RIL_AUDIO_PATH_SPK;
+ break;
+ case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+ device_type = RIL_AUDIO_PATH_HEADSET;
+ break;
+ case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+ device_type = RIL_AUDIO_PATH_HEADSET;
+ break;
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
+ device_type = RIL_AUDIO_PATH_BT;
+ break;
+ default:
+ device_type = RIL_AUDIO_PATH_EARPIECE;
+ break;
+ }
- ril_set_call_volume(device_type, volume);
+ ril_set_call_volume(device_type, volume);
}
static void force_all_standby(struct sunxi_audio_device *adev)
{
- struct sunxi_stream_in *in;
- struct sunxi_stream_out *out;
+ struct sunxi_stream_in *in;
+ struct sunxi_stream_out *out;
- if (adev->active_output) {
- out = adev->active_output;
- pthread_mutex_lock(&out->lock);
- do_output_standby(out);
- pthread_mutex_unlock(&out->lock);
- }
- if (adev->active_input) {
- in = adev->active_input;
- pthread_mutex_lock(&in->lock);
- do_input_standby(in);
- pthread_mutex_unlock(&in->lock);
- }
+ if (adev->active_output) {
+ out = adev->active_output;
+ pthread_mutex_lock(&out->lock);
+ do_output_standby(out);
+ pthread_mutex_unlock(&out->lock);
+ }
+
+ if (adev->active_input) {
+ in = adev->active_input;
+ pthread_mutex_lock(&in->lock);
+ do_input_standby(in);
+ pthread_mutex_unlock(&in->lock);
+ }
}
static void select_mode(struct sunxi_audio_device *adev)
{
- if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST) {
- //ALOGV("Entering IN_CALL state, in_call=%d, adev->out_device is : %d", adev->in_call, adev->out_device);
- if (!adev->in_call) {
- force_all_standby(adev);
- /* force earpiece route for in call state if speaker is the
- only currently selected route. This prevents having to tear
- down the modem PCMs to change route from speaker to earpiece
- after the ringtone is played, but doesn't cause a route
- change if a headset or bt device is already connected. If
- speaker is not the only thing active, just remove it from
- the route. We'll assume it'll never be used initially during
- a call. This works because we're sure that the audio policy
- manager will update the output device after the audio mode
- change, even if the device selection did not change. */
- if (adev->out_device == AUDIO_DEVICE_OUT_SPEAKER) {
- F_LOG;
- adev->out_device = AUDIO_DEVICE_OUT_EARPIECE;
- adev->in_device = AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN;
- } else{
- F_LOG
- adev->out_device &= ~AUDIO_DEVICE_OUT_SPEAKER;
- }
+ if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST) {
+ //ALOGV("Entering IN_CALL state, in_call=%d, adev->out_device is : %d", adev->in_call, adev->out_device);
+ if (!adev->in_call) {
+ force_all_standby(adev);
+ /* force earpiece route for in call state if speaker is the
+ only currently selected route. This prevents having to tear
+ down the modem PCMs to change route from speaker to earpiece
+ after the ringtone is played, but doesn't cause a route
+ change if a headset or bt device is already connected. If
+ speaker is not the only thing active, just remove it from
+ the route. We'll assume it'll never be used initially during
+ a call. This works because we're sure that the audio policy
+ manager will update the output device after the audio mode
+ change, even if the device selection did not change. */
+ if (adev->out_device == AUDIO_DEVICE_OUT_SPEAKER) {
+ F_LOG;
+ adev->out_device = AUDIO_DEVICE_OUT_EARPIECE;
+ adev->in_device = AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN;
+ } else {
+ F_LOG
+ adev->out_device &= ~AUDIO_DEVICE_OUT_SPEAKER;
+ }
- start_call(adev);
- F_LOG;
- select_device(adev);
- adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
- adev->in_call = 1;
+ start_call(adev);
+ F_LOG;
+ select_device(adev);
+ adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
+ adev->in_call = 1;
+ }
+ } else {
+ ALOGV("Leaving IN_CALL state, in_call=%d, mode=%d",
+ adev->in_call, adev->mode);
+ if (adev->in_call) {
+ adev->in_call = 0;
+ end_call(adev);
+ force_all_standby(adev);
+ //select_device(adev);
+ select_device(adev);
+ }
}
- } else {
- ALOGV("Leaving IN_CALL state, in_call=%d, mode=%d",
- adev->in_call, adev->mode);
- if (adev->in_call) {
- adev->in_call = 0;
- end_call(adev);
+
+ if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
+ ALOGV("AUDIO_MODE_IN_COMMUNICATION");
+ F_LOG;
force_all_standby(adev);
- //select_device(adev);
select_device(adev);
}
- }
- if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
- ALOGV("AUDIO_MODE_IN_COMMUNICATION");
- F_LOG;
- force_all_standby(adev);
- select_device(adev);
- }
-
- if (adev->mode == AUDIO_MODE_FM) {
- force_all_standby(adev);
- F_LOG;
- select_device(adev);
- adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
- }
+ if (adev->mode == AUDIO_MODE_FM) {
+ force_all_standby(adev);
+ F_LOG;
+ select_device(adev);
+ adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
+ }
}
@@ -917,9 +889,9 @@ static int i2s_suspend_get()
int ret = -1, fd = 0;
char i2s_suspend[2] = {0};
fd = open("/sys/module/sunxi_i2s/parameters/i2s_suspend", O_RDONLY);
- if(fd > 0){
+ if (fd > 0) {
ret = read(fd, i2s_suspend, sizeof(i2s_suspend));
- if(ret < 0){
+ if (ret < 0) {
ALOGV("read state fail!");
}
close(fd);
@@ -936,9 +908,9 @@ static int i2s_suspend_set()
int ret = -1, fd = 0;
char state[2] = {0};
fd = open("/sys/module/sunxi_i2s/parameters/i2s_suspend", O_WRONLY);
- if(fd > 0){
+ if (fd > 0) {
ret = write(fd, state, sizeof(state));
- if(ret < 0){
+ if (ret < 0) {
ALOGV("write state fail!");
}
close(fd);
@@ -952,16 +924,15 @@ static int sysopen_music()
{
int ret = -1, fd=0;
int switch_to_headset = 0;
- char h2w_state[2]={0};
+ char h2w_state[2]={0};
fd = open("/sys/class/switch/h2w/state", O_RDONLY);
- if (fd > 0){
+ if (fd > 0) {
ret = read(fd, h2w_state, sizeof(h2w_state));
close(fd);
- if ( (atoi(h2w_state) == 2 || atoi(h2w_state) == 1) )
- {
- ALOGV("h2w_state:erjicharu");
- switch_to_headset =1;
+ if ( (atoi(h2w_state) == 2 || atoi(h2w_state) == 1) ) {
+ ALOGV("h2w_state:erjicharu");
+ switch_to_headset =1;
}
}
@@ -970,26 +941,21 @@ static int sysopen_music()
static int check_hdmi_status()
{
- int hdmi_fd;
+ int hdmi_fd;
int switch_to_hdmi = 0;
hdmi_fd = open("/sys/class/switch/hdmi/state", O_RDONLY);
- if (hdmi_fd)
- {
+
+ if (hdmi_fd) {
char val;
- if (read(hdmi_fd, &val, 1) == 1 && val == '1')
- {
+ if (read(hdmi_fd, &val, 1) == 1 && val == '1') {
ALOGD( "init hdmi_plug: IN");
switch_to_hdmi = 1;
- }
- else
- {
+ } else {
ALOGD( "init hdmi_plug: OUT");
switch_to_hdmi = 0;
}
close(hdmi_fd);
- }
- else
- {
+ } else {
ALOGD("open /sys/class/switch/hdmi/state failed");
switch_to_hdmi = -1;
}
@@ -1008,73 +974,78 @@ static void select_device(struct sunxi_audio_device *adev)
int main_mic_on = 0,sub_mic_on = 0;
int bton_temp = 0;
- if(!adev->ar)
+ if (!adev->ar)
return;
ALOGD(">>>>>> select_device");
audio_route_reset(adev->ar);
- audio_route_update_mixer_old_value(adev->ar);
-
- if(spk_dul_used)
+ if (spk_dul_used)
audio_route_apply_path(adev->ar, "media-speaker-off");
else
audio_route_apply_path(adev->ar, "media-single-speaker-off");
-
- if (adev->mode == AUDIO_MODE_IN_CALL){
- if(CASE_NAME <= 0){
+
+ audio_route_update_mixer(adev->ar);
+
+ /* get phone route */
+ if (adev->mode == AUDIO_MODE_IN_CALL) {
+ if(CASE_NAME <= 0) {
ALOGV("%s,PHONE CASE ERR!!!!!!!!!!!!!!!!!!!! line: %d,CASE_NAME:%d", __FUNCTION__, __LINE__,CASE_NAME);
//return CASE_NAME;
}
+
headset_on = adev->out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p
headphone_on = adev->out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE; // hp3p
speaker_on = adev->out_device & AUDIO_DEVICE_OUT_SPEAKER;
earpiece_on = adev->out_device & AUDIO_DEVICE_OUT_EARPIECE;
bt_on = adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO;
- //audio_route_reset(adev->ar);
ALOGV("****LINE:%d,FUNC:%s, headset_on:%d, headphone_on:%d, speaker_on:%d, earpiece_on:%d, bt_on:%d",__LINE__,__FUNCTION__, headphone_on, headphone_on, speaker_on, earpiece_on, bt_on);
+
if (last_call_path_is_bt && !bt_on) {
end_bt_call(adev);
last_call_path_is_bt = 0;
}
- if ((headset_on || headphone_on) && speaker_on){
+
+ /* get output device id */
+ if ((headset_on || headphone_on) && speaker_on) {
output_device_id = OUT_DEVICE_SPEAKER_AND_HEADSET;
} else if (earpiece_on) {
F_LOG;
- if (NO_EARPIECE)
- {
- F_LOG;
- if(spk_dul_used){
- output_device_id = OUT_DEVICE_SPEAKER;
- }else{
- output_device_id = OUT_DEVICE_SINGLE_SPEAKER;
- }
+ if (NO_EARPIECE) {
+ F_LOG;
+ if (spk_dul_used) {
+ output_device_id = OUT_DEVICE_SPEAKER;
+ } else {
+ output_device_id = OUT_DEVICE_SINGLE_SPEAKER;
}
- else
- {F_LOG;
+ } else {
+ F_LOG;
output_device_id = OUT_DEVICE_EARPIECE;
- }
+ }
} else if (headset_on) {
output_device_id = OUT_DEVICE_HEADSET;
- } else if (headphone_on){
+ } else if (headphone_on) {
output_device_id = OUT_DEVICE_HEADPHONES;
- }else if(bt_on){
+ } else if (bt_on) {
bton_temp = 1;
//bt_start_call(adev);
//last_call_path_is_bt = 1;
output_device_id = OUT_DEVICE_BT_SCO;
- }else if(speaker_on){
- if(spk_dul_used){
+ } else if (speaker_on) {
+ if (spk_dul_used) {
output_device_id = OUT_DEVICE_SPEAKER;
- }else{
+ } else {
output_device_id = OUT_DEVICE_SINGLE_SPEAKER;
}
}
ALOGV("****** output_id is : %d", output_device_id);
+
phone_route = phone_route_configs[CASE_NAME-1][output_device_id];
set_incall_device(adev);
}
+
+ /* get output route */
if (adev->active_output) {
ALOGV("active_output, ****LINE:%d,FUNC:%s, adev->out_device:%d",__LINE__,__FUNCTION__, adev->out_device);
headset_on = adev->out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET; // hp4p
@@ -1082,45 +1053,38 @@ static void select_device(struct sunxi_audio_device *adev)
speaker_on = adev->out_device & AUDIO_DEVICE_OUT_SPEAKER;
earpiece_on = adev->out_device & AUDIO_DEVICE_OUT_EARPIECE;
bt_on = adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO;
- //audio_route_reset(adev->ar);
ALOGV("****LINE:%d,FUNC:%s, headset_on:%d, headphone_on:%d, speaker_on:%d, earpiece_on:%d, bt_on:%d",__LINE__,__FUNCTION__, headset_on, headphone_on, speaker_on, earpiece_on, bt_on);
- if ((headset_on || headphone_on) && speaker_on){
+
+ /* get output device id */
+ if ((headset_on || headphone_on) && speaker_on) {
output_device_id = OUT_DEVICE_SPEAKER_AND_HEADSET;
} else if (earpiece_on) {
- if (NO_EARPIECE){
- if(spk_dul_used){
+ if (NO_EARPIECE) {
+ if (spk_dul_used) {
output_device_id = OUT_DEVICE_SPEAKER;
- }else{
+ } else {
output_device_id = OUT_DEVICE_SINGLE_SPEAKER;
}
- }
- else
+ } else
output_device_id = OUT_DEVICE_EARPIECE;
- //output_device_id = OUT_DEVICE_EARPIECE;
} else if (headset_on) {
output_device_id = OUT_DEVICE_HEADSET;
- } else if (headphone_on){
+ } else if (headphone_on) {
output_device_id = OUT_DEVICE_HEADSET;
- }else if(bt_on){
+ } else if (bt_on) {
output_device_id = OUT_DEVICE_BT_SCO;
- }else if(speaker_on){
- if(spk_dul_used){
+ } else if (speaker_on) {
+ if (spk_dul_used) {
output_device_id = OUT_DEVICE_SPEAKER;
- }else{
+ } else {
output_device_id = OUT_DEVICE_SINGLE_SPEAKER;
}
}
ALOGV("****LINE:%d,FUNC:%s, output_device_id:%d",__LINE__,__FUNCTION__, output_device_id);
- switch (adev->mode){
+
+ switch (adev->mode) {
case AUDIO_MODE_NORMAL:
ALOGV("NORMAL mode, ****LINE:%d,FUNC:%s, adev->out_device:%d",__LINE__,__FUNCTION__, adev->out_device);
- #if 0
- if(sysopen_music())
- output_device_id = OUT_DEVICE_HEADSET;
- else
- output_device_id = OUT_DEVICE_SPEAKER;
- //output_device_id = OUT_DEVICE_HEADSET;
- #endif
output_route = normal_route_configs[output_device_id];
break;
case AUDIO_MODE_RINGTONE:
@@ -1146,30 +1110,30 @@ static void select_device(struct sunxi_audio_device *adev)
if (!pcm_is_ready(adev->pcm_modem_dl)) {
ALOGE("cannot open PCM modem DL stream: %s", pcm_get_error(adev->pcm_modem_dl));
//goto err_open_dl;
- }
}
+ }
if (adev->pcm_modem_ul == NULL) {
adev->pcm_modem_ul = pcm_open(0, 4, PCM_IN, &pcm_config_vx);
if (!pcm_is_ready(adev->pcm_modem_ul)) {
ALOGE("cannot open PCM modem UL stream: %s", pcm_get_error(adev->pcm_modem_ul));
//goto err_open_ul;
- }
}
+ }
/* Open bt PCM channels */
if (adev->pcm_bt_dl == NULL) {
adev->pcm_bt_dl = pcm_open(0, PORT_bt, PCM_OUT, &pcm_config_vx);
if (!pcm_is_ready(adev->pcm_bt_dl)) {
ALOGE("cannot open PCM bt DL stream: %s", pcm_get_error(adev->pcm_bt_dl));
//goto err_open_bt_dl;
- }
}
+ }
if (adev->pcm_bt_ul == NULL) {
adev->pcm_bt_ul = pcm_open(0, PORT_bt, PCM_IN, &pcm_config_vx);
if (!pcm_is_ready(adev->pcm_bt_ul)) {
ALOGE("cannot open PCM bt UL stream: %s", pcm_get_error(adev->pcm_bt_ul));
//goto err_open_bt_ul;
- }
}
+ }
pcm_start(adev->pcm_modem_dl);
pcm_start(adev->pcm_modem_ul);
pcm_start(adev->pcm_bt_dl);
@@ -1181,33 +1145,37 @@ static void select_device(struct sunxi_audio_device *adev)
default:
break;
}
-
}
+
+ /* get input route */
if (adev->active_input) {
- if(adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO){
+ if (adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
adev->in_device = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
}
int bt_on = adev->in_device & AUDIO_DEVICE_IN_ALL_SCO;
ALOGV("record,****LINE:%d,FUNC:%s, adev->in_device:%x,AUDIO_DEVICE_IN_ALL_SCO:%x",__LINE__,__FUNCTION__, adev->in_device,AUDIO_DEVICE_IN_ALL_SCO);
+
if (!bt_on) {
if ((adev->mode != AUDIO_MODE_IN_CALL) && (adev->active_input != 0)) {
- /* sub mic is used for camcorder or VoIP on speaker phone */
- sub_mic_on = (adev->active_input->source == AUDIO_SOURCE_CAMCORDER) ||
- ((adev->out_device & AUDIO_DEVICE_OUT_SPEAKER) &&
- (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION));
- }
- if (!sub_mic_on) {
- headset_on = adev->in_device & AUDIO_DEVICE_IN_WIRED_HEADSET;
- main_mic_on = adev->in_device & AUDIO_DEVICE_IN_BUILTIN_MIC;
- }
+ /* sub mic is used for camcorder or VoIP on speaker phone */
+ sub_mic_on = (adev->active_input->source == AUDIO_SOURCE_CAMCORDER) ||
+ ((adev->out_device & AUDIO_DEVICE_OUT_SPEAKER) &&
+ (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION));
+ }
+ if (!sub_mic_on) {
+ headset_on = adev->in_device & AUDIO_DEVICE_IN_WIRED_HEADSET;
+ main_mic_on = adev->in_device & AUDIO_DEVICE_IN_BUILTIN_MIC;
+ }
}
- if (headset_on){
+
+ /* get input device id */
+ if (headset_on) {
input_device_id = IN_SOURCE_HEADSETMIC;
} else if (main_mic_on) {
input_device_id = IN_SOURCE_MAINMIC;
- }else if (bt_on && (adev->mode == AUDIO_MODE_IN_COMMUNICATION || adev->mode == AUDIO_MODE_IN_CALL)) {
+ } else if (bt_on && (adev->mode == AUDIO_MODE_IN_COMMUNICATION || adev->mode == AUDIO_MODE_IN_CALL)) {
input_device_id = IN_SOURCE_BTMIC;
- }else{
+ } else {
input_device_id = IN_SOURCE_MAINMIC;
}
ALOGV("fm record,****LINE:%d,FUNC:%s,bt_on:%d,headset_on:%d,main_mic_on;%d,adev->in_device:%x,AUDIO_DEVICE_IN_ALL_SCO:%x",__LINE__,__FUNCTION__,bt_on,headset_on,main_mic_on,adev->in_device,AUDIO_DEVICE_IN_ALL_SCO);
@@ -1220,13 +1188,13 @@ static void select_device(struct sunxi_audio_device *adev)
//fm_record_route(adev->in_device);
ALOGV("fm record,****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__);
} else if (adev->mode == AUDIO_MODE_NORMAL) {
- if(dmic_used)
+ if (dmic_used)
input_route = dmic_cap_normal_route_configs[input_device_id];
else
input_route = cap_normal_route_configs[input_device_id];
ALOGV("normal record,****LINE:%d,FUNC:%s,adev->in_device:%d",__LINE__,__FUNCTION__,adev->in_device);
} else if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
- if(dmic_used)
+ if (dmic_used)
input_route = dmic_cap_normal_route_configs[input_device_id];
else
input_route = cap_normal_route_configs[input_device_id];
@@ -1234,15 +1202,18 @@ static void select_device(struct sunxi_audio_device *adev)
}
}
+
if (phone_route)
audio_route_apply_path(adev->ar, phone_route);
if (output_route)
- audio_route_apply_path(adev->ar, output_route);
+ audio_route_apply_path(adev->ar, output_route);
if (input_route)
- audio_route_apply_path(adev->ar, input_route);
+ audio_route_apply_path(adev->ar, input_route);
+
audio_route_update_mixer(adev->ar);
- if (adev->mode == AUDIO_MODE_IN_CALL ){
- if(bton_temp && last_call_path_is_bt == 0){
+
+ if (adev->mode == AUDIO_MODE_IN_CALL ) {
+ if (bton_temp && last_call_path_is_bt == 0) {
bt_start_call(adev);
last_call_path_is_bt = 1;
}
@@ -1257,89 +1228,36 @@ static int start_output_stream(struct sunxi_stream_out *out)
unsigned int port = PORT_CODEC;
unsigned int ret;
F_LOG;
- if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) // 10-16 modify
- {
+ if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) {
return 0;
}
- if (adev->raw_flag)
- {
+ if (adev->raw_flag) {
return 0;
}
- #if 0
- int device = adev->out_device;
- char prop_value[512];
- ret = property_get("audio.routing", prop_value, "");
- if (ret > 0)
- {
- F_LOG;
- if(atoi(prop_value) == AUDIO_DEVICE_OUT_SPEAKER)
- {
- F_LOG;
- ALOGD("start_output_stream, AUDIO_DEVICE_OUT_SPEAKER");
- device = AUDIO_DEVICE_OUT_SPEAKER;
- }
- else if(atoi(prop_value) == AUDIO_DEVICE_OUT_AUX_DIGITAL)
- {
- F_LOG;
- ALOGD("start_output_stream AUDIO_DEVICE_OUT_AUX_DIGITAL");
- device = AUDIO_DEVICE_OUT_AUX_DIGITAL;
- }
- else if(atoi(prop_value) == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)
- {
- F_LOG;
- ALOGD("start_output_stream AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET");
- device = AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
- }
- else
- {
- F_LOG;
- ALOGW("unknown audio.routing : %s", prop_value);
- }
- }
- else
- {
- F_LOG;
- // ALOGW("get audio.routing failed");
- }
- adev->out_device = device;
- #endif
-
- #if 0
- if (1 == check_hdmi_status())
- {
- int device = adev->out_device;
- device = AUDIO_DEVICE_OUT_AUX_DIGITAL;
- adev->out_device = device;
- }
- #endif
-
adev->active_output = out;
- if (adev->mode != AUDIO_MODE_IN_CALL) {
- /* FIXME: only works if only one output can be active at a time */
- select_device(adev);
- } else {
- select_device(adev);
- }
+ select_device(adev);
+
/* S/PDIF takes priority over HDMI audio. In the case of multiple
- * devices, this will cause use of S/PDIF or HDMI only */
+ * devices, this will cause use of S/PDIF or HDMI only */
out->config.rate = MM_SAMPLING_RATE;
if (adev->out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
card = CARD_A1X_SPDIF;
port = PORT_SPDIF;
- } else if(adev->out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
+ } else if (adev->out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
card = CARD_A1X_HDMI;
port = PORT_HDMI;
out->config.rate = MM_SAMPLING_RATE;
- } else if(adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO){
+ } else if (adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
out->config.rate = SAMPLING_RATE_8K;
//out->config.channels = 1;
ALOGV("****LINE:%d,FUNC:%s",__LINE__,__FUNCTION__);
}
+
/* default to low power: will be corrected in out_write if necessary before first write to
- * tinyalsa.
- */
+ * tinyalsa.
+ */
out->write_threshold = PLAYBACK_PERIOD_COUNT * SHORT_PERIOD_SIZE;
out->config.start_threshold = SHORT_PERIOD_SIZE * 2;
out->config.avail_min = SHORT_PERIOD_SIZE;
@@ -1350,351 +1268,344 @@ static int start_output_stream(struct sunxi_stream_out *out)
out->config.stop_threshold = 0;
ALOGV("start_output_stream: card:%d, port:%d, rate:%d, period_count:%d, period_size:%d", card, port, out->config.rate, out->config.period_count, out->config.period_size);
out->pcm = pcm_open(card, port, PCM_OUT | PCM_MONOTONIC, &out->config);
- //out->pcm = pcm_open_req(card, port, PCM_OUT | PCM_MMAP | PCM_NOIRQ, &out->config, DEFAULT_OUT_SAMPLING_RATE);
- if (!pcm_is_ready(out->pcm)) {
- ALOGE("cannot open pcm_out driver: %s", pcm_get_error(out->pcm));
- pcm_close(out->pcm);
- adev->active_output = NULL;
- return -ENOMEM;
- }
- if (adev->echo_reference != NULL)
- out->echo_reference = adev->echo_reference;
+ if (!pcm_is_ready(out->pcm)) {
+ ALOGE("cannot open pcm_out driver: %s", pcm_get_error(out->pcm));
+ pcm_close(out->pcm);
+ adev->active_output = NULL;
+ return -ENOMEM;
+ }
- if (DEFAULT_OUT_SAMPLING_RATE != out->config.rate)
- {
+ if (adev->echo_reference != NULL)
+ out->echo_reference = adev->echo_reference;
+
+ if (DEFAULT_OUT_SAMPLING_RATE != out->config.rate) {
ret = create_resampler(DEFAULT_OUT_SAMPLING_RATE,
- out->config.rate,
- 2,
- RESAMPLER_QUALITY_DEFAULT,
- NULL,
- &out->resampler);
- if (ret != 0)
- {
+ out->config.rate,
+ 2,
+ RESAMPLER_QUALITY_DEFAULT,
+ NULL,
+ &out->resampler);
+ if (ret != 0) {
ALOGE("create out resampler failed, %d -> %d", DEFAULT_OUT_SAMPLING_RATE, out->config.rate);
return ret;
}
ALOGV("create out resampler OK, %d -> %d", DEFAULT_OUT_SAMPLING_RATE, out->config.rate);
- }
- else
- {
+ } else {
ALOGV("do not use out resampler");
}
- if (out->resampler)
- {
- out->resampler->reset(out->resampler);
+ if (out->resampler) {
+ out->resampler->reset(out->resampler);
}
- return 0;
+ return 0;
}
static int check_input_parameters(uint32_t sample_rate, int format, int channel_count)
{
- if (format != AUDIO_FORMAT_PCM_16_BIT)
- return -EINVAL;
+ if (format != AUDIO_FORMAT_PCM_16_BIT)
+ return -EINVAL;
- if ((channel_count < 1) || (channel_count > 2))
- return -EINVAL;
+ if ((channel_count < 1) || (channel_count > 2))
+ return -EINVAL;
- switch(sample_rate) {
- case 8000:
- case 11025:
- case 16000:
- case 22050:
- case 24000:
- case 32000:
- case 44100:
- case 48000:
- break;
- default:
- return -EINVAL;
- }
+ switch (sample_rate) {
+ case 8000:
+ case 11025:
+ case 16000:
+ case 22050:
+ case 24000:
+ case 32000:
+ case 44100:
+ case 48000:
+ break;
+ default:
+ return -EINVAL;
+ }
- return 0;
+ return 0;
}
static size_t get_input_buffer_size(uint32_t sample_rate, int format, int channel_count)
{
- size_t size;
- size_t device_rate;
+ size_t size;
+ size_t device_rate;
- if (check_input_parameters(sample_rate, format, channel_count) != 0)
- return 0;
+ if (check_input_parameters(sample_rate, format, channel_count) != 0)
+ return 0;
- /* take resampling into account and return the closest majoring
- multiple of 16 frames, as audioflinger expects audio buffers to
- be a multiple of 16 frames */
- size = (pcm_config_mm_in.period_size * sample_rate) / pcm_config_mm_in.rate;
- size = ((size + 15) / 16) * 16;
+ /* take resampling into account and return the closest majoring
+ multiple of 16 frames, as audioflinger expects audio buffers to
+ be a multiple of 16 frames */
+ size = (pcm_config_mm_in.period_size * sample_rate) / pcm_config_mm_in.rate;
+ size = ((size + 15) / 16) * 16;
- return size * channel_count * sizeof(short);
+ return size * channel_count * sizeof(short);
}
static void add_echo_reference(struct sunxi_stream_out *out,
- struct echo_reference_itfe *reference)
+ struct echo_reference_itfe *reference)
{
- pthread_mutex_lock(&out->lock);
- out->echo_reference = reference;
- pthread_mutex_unlock(&out->lock);
+ pthread_mutex_lock(&out->lock);
+ out->echo_reference = reference;
+ pthread_mutex_unlock(&out->lock);
}
static void remove_echo_reference(struct sunxi_stream_out *out,
- struct echo_reference_itfe *reference)
+ struct echo_reference_itfe *reference)
{
- pthread_mutex_lock(&out->lock);
- if (out->echo_reference == reference) {
- /* stop writing to echo reference */
- reference->write(reference, NULL);
- out->echo_reference = NULL;
- }
- pthread_mutex_unlock(&out->lock);
+ pthread_mutex_lock(&out->lock);
+ if (out->echo_reference == reference) {
+ /* stop writing to echo reference */
+ reference->write(reference, NULL);
+ out->echo_reference = NULL;
+ }
+ pthread_mutex_unlock(&out->lock);
}
static void put_echo_reference(struct sunxi_audio_device *adev,
- struct echo_reference_itfe *reference)
+ struct echo_reference_itfe *reference)
{
- if (adev->echo_reference != NULL &&
- reference == adev->echo_reference) {
- if (adev->active_output != NULL)
- remove_echo_reference(adev->active_output, reference);
- release_echo_reference(reference);
- adev->echo_reference = NULL;
- }
+ if (adev->echo_reference != NULL &&
+ reference == adev->echo_reference) {
+ if (adev->active_output != NULL)
+ remove_echo_reference(adev->active_output, reference);
+ release_echo_reference(reference);
+ adev->echo_reference = NULL;
+ }
}
static struct echo_reference_itfe *get_echo_reference(struct sunxi_audio_device *adev,
- audio_format_t format,
- uint32_t channel_count,
- uint32_t sampling_rate)
+ audio_format_t format,
+ uint32_t channel_count,
+ uint32_t sampling_rate)
{
- put_echo_reference(adev, adev->echo_reference);
- if (adev->active_output != NULL) {
- struct audio_stream *stream = &adev->active_output->stream.common;
- uint32_t wr_channel_count = popcount(stream->get_channels(stream));
- uint32_t wr_sampling_rate = stream->get_sample_rate(stream);
+ put_echo_reference(adev, adev->echo_reference);
+ if (adev->active_output != NULL) {
+ struct audio_stream *stream = &adev->active_output->stream.common;
+ uint32_t wr_channel_count = popcount(stream->get_channels(stream));
+ uint32_t wr_sampling_rate = stream->get_sample_rate(stream);
- int status = create_echo_reference(AUDIO_FORMAT_PCM_16_BIT,
- channel_count,
- sampling_rate,
- AUDIO_FORMAT_PCM_16_BIT,
- wr_channel_count,
- wr_sampling_rate,
- &adev->echo_reference);
- if (status == 0)
- add_echo_reference(adev->active_output, adev->echo_reference);
- }
- return adev->echo_reference;
+ int status = create_echo_reference(AUDIO_FORMAT_PCM_16_BIT,
+ channel_count,
+ sampling_rate,
+ AUDIO_FORMAT_PCM_16_BIT,
+ wr_channel_count,
+ wr_sampling_rate,
+ &adev->echo_reference);
+ if (status == 0)
+ add_echo_reference(adev->active_output, adev->echo_reference);
+ }
+ return adev->echo_reference;
}
static int get_playback_delay(struct sunxi_stream_out *out,
- size_t frames,
- struct echo_reference_buffer *buffer)
+ size_t frames,
+ struct echo_reference_buffer *buffer)
{
- size_t kernel_frames;
- int status;
+ size_t kernel_frames;
+ int status;
- status = pcm_get_htimestamp(out->pcm, &kernel_frames, &buffer->time_stamp);
- if (status < 0) {
- buffer->time_stamp.tv_sec = 0;
- buffer->time_stamp.tv_nsec = 0;
- buffer->delay_ns = 0;
- ALOGV("get_playback_delay(): pcm_get_htimestamp error,"
- "setting playbackTimestamp to 0");
- return status;
- }
+ status = pcm_get_htimestamp(out->pcm, &kernel_frames, &buffer->time_stamp);
+ if (status < 0) {
+ buffer->time_stamp.tv_sec = 0;
+ buffer->time_stamp.tv_nsec = 0;
+ buffer->delay_ns = 0;
+ ALOGV("get_playback_delay(): pcm_get_htimestamp error,"
+ "setting playbackTimestamp to 0");
+ return status;
+ }
- kernel_frames = pcm_get_buffer_size(out->pcm) - kernel_frames;
+ kernel_frames = pcm_get_buffer_size(out->pcm) - kernel_frames;
- /* adjust render time stamp with delay added by current driver buffer.
- * Add the duration of current frame as we want the render time of the last
- * sample being written. */
- buffer->delay_ns = (long)(((int64_t)(kernel_frames + frames)* 1000000000)/
- MM_SAMPLING_RATE);
+ /* adjust render time stamp with delay added by current driver buffer.
+ * Add the duration of current frame as we want the render time of the last
+ * sample being written. */
+ buffer->delay_ns = (long)(((int64_t)(kernel_frames + frames)* 1000000000)/
+ MM_SAMPLING_RATE);
- return 0;
+ return 0;
}
-
static int out_get_presentation_position(const struct audio_stream_out *stream,
- uint64_t *frames, struct timespec *timestamp)
+ uint64_t *frames, struct timespec *timestamp)
{
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- int ret = -1;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ int ret = -1;
- pthread_mutex_lock(&out->lock);
+ pthread_mutex_lock(&out->lock);
- int i;
- // There is a question how to implement this correctly when there is more than one PCM stream.
- // We are just interested in the frames pending for playback in the kernel buffer here,
- // not the total played since start. The current behavior should be safe because the
- // cases where both cards are active are marginal.
- //for (i = 0; i < PCM_TOTAL; i++)
- if (out->pcm) {
- size_t avail;
- if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) {
- size_t kernel_buffer_size = out->config.period_size * out->config.period_count;
- // FIXME This calculation is incorrect if there is buffering after app processor
- int64_t signed_frames = out->written - kernel_buffer_size + avail;
- // It would be unusual for this value to be negative, but check just in case ...
- if (signed_frames >= 0) {
- *frames = signed_frames;
- ret = 0;
- }
- //break;
- }
- }
+ int i;
+ // There is a question how to implement this correctly when there is more than one PCM stream.
+ // We are just interested in the frames pending for playback in the kernel buffer here,
+ // not the total played since start. The current behavior should be safe because the
+ // cases where both cards are active are marginal.
+ //for (i = 0; i < PCM_TOTAL; i++)
+ if (out->pcm) {
+ size_t avail;
+ if (pcm_get_htimestamp(out->pcm, &avail, timestamp) == 0) {
+ size_t kernel_buffer_size = out->config.period_size * out->config.period_count;
+ // FIXME This calculation is incorrect if there is buffering after app processor
+ int64_t signed_frames = out->written - kernel_buffer_size + avail;
+ // It would be unusual for this value to be negative, but check just in case ...
+ if (signed_frames >= 0) {
+ *frames = signed_frames;
+ ret = 0;
+ }
+ }
+ }
- pthread_mutex_unlock(&out->lock);
+ pthread_mutex_unlock(&out->lock);
- return ret;
+ return ret;
}
-
static uint32_t out_get_sample_rate(const struct audio_stream *stream)
{
- return DEFAULT_OUT_SAMPLING_RATE;
+ return DEFAULT_OUT_SAMPLING_RATE;
}
static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
- return 0;
+ return 0;
}
static size_t out_get_buffer_size(const struct audio_stream *stream)
{
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- /* take resampling into account and return the closest majoring
- multiple of 16 frames, as audioflinger expects audio buffers to
- be a multiple of 16 frames */
- size_t size = (SHORT_PERIOD_SIZE * DEFAULT_OUT_SAMPLING_RATE) / out->config.rate;
- size = ((size + 15) / 16) * 16;
- return size * audio_stream_frame_size((struct audio_stream *)stream);
+ /* take resampling into account and return the closest majoring
+ multiple of 16 frames, as audioflinger expects audio buffers to
+ be a multiple of 16 frames */
+ size_t size = (SHORT_PERIOD_SIZE * DEFAULT_OUT_SAMPLING_RATE) / out->config.rate;
+ size = ((size + 15) / 16) * 16;
+ return size * audio_stream_frame_size((struct audio_stream *)stream);
}
static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
{
- return AUDIO_CHANNEL_OUT_STEREO;
+ return AUDIO_CHANNEL_OUT_STEREO;
}
static audio_format_t out_get_format(const struct audio_stream *stream)
{
- return AUDIO_FORMAT_PCM_16_BIT;
+ return AUDIO_FORMAT_PCM_16_BIT;
}
static int out_set_format(struct audio_stream *stream, audio_format_t format)
{
- return 0;
+ return 0;
}
/* must be called with hw device and output stream mutexes locked */
static int do_output_standby(struct sunxi_stream_out *out)
{
- struct sunxi_audio_device *adev = out->dev;
+ struct sunxi_audio_device *adev = out->dev;
+
+ if (!out->standby) {
+ pcm_close(out->pcm);
+ out->pcm = NULL;
+ adev->active_output = 0;
- if (!out->standby) {
- pcm_close(out->pcm);
- out->pcm = NULL;
- adev->active_output = 0;
if (out->resampler) {
- release_resampler(out->resampler);
- out->resampler = 0;//close resample
- }
- /* stop writing to echo reference */
- if (out->echo_reference != NULL) {
- out->echo_reference->write(out->echo_reference, NULL);
- out->echo_reference = NULL;
- }
- out->standby = 1;
- }
- return 0;
+ release_resampler(out->resampler);
+ out->resampler = 0;//close resample
+ }
+
+ /* stop writing to echo reference */
+ if (out->echo_reference != NULL) {
+ out->echo_reference->write(out->echo_reference, NULL);
+ out->echo_reference = NULL;
+ }
+
+ out->standby = 1;
+ }
+ return 0;
}
static int out_standby(struct audio_stream *stream)
{
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- int status;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ int status;
ALOGD("out_standby");
- //pthread_mutex_lock(&out->dev->lock);
- pthread_mutex_lock(&out->lock);
- status = do_output_standby(out);
- pthread_mutex_unlock(&out->lock);
- //pthread_mutex_unlock(&out->dev->lock);
- return status;
+ pthread_mutex_lock(&out->lock);
+ status = do_output_standby(out);
+ pthread_mutex_unlock(&out->lock);
+ return status;
}
static int out_dump(const struct audio_stream *stream, int fd)
{
- return 0;
+ return 0;
}
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- struct sunxi_audio_device *adev = out->dev;
- struct sunxi_stream_in *in;
- struct str_parms *parms;
- char *str;
- char value[32];
- int ret, val = 0;
- bool force_input_standby = false;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ struct sunxi_audio_device *adev = out->dev;
+ struct sunxi_stream_in *in;
+ struct str_parms *parms;
+ char *str;
+ char value[32];
+ int ret, val = 0;
+ bool force_input_standby = false;
- parms = str_parms_create_str(kvpairs);
+ parms = str_parms_create_str(kvpairs);
ALOGV("out_set_parameters: %s", kvpairs);
ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
if (ret >= 0) {
F_LOG;
- val = atoi(value);
- pthread_mutex_lock(&adev->lock);
- pthread_mutex_lock(&out->lock);
+ val = atoi(value);
+ pthread_mutex_lock(&adev->lock);
+ pthread_mutex_lock(&out->lock);
ALOGV(">>>>>>>> adev->mode:%d,adev->out_device is: %d, val is : %d", adev->mode,adev->out_device, val);
- if ((adev->out_device != val) && (val != 0)) {
- if (out == adev->active_output) {
- F_LOG;
- /* a change in output device may change the microphone selection */
- if (adev->active_input &&
- adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
- force_input_standby = true;
- }
- /* force standby if moving to/from HDMI */
- if (((val & AUDIO_DEVICE_OUT_AUX_DIGITAL) ^
- (adev->out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) ||
- ((val & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) ^
- (adev->out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
- ((val & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) ^
- (adev->out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET)))
- do_output_standby(out);
- }
- adev->out_device = val;
+
+ if ((adev->out_device != val) && (val != 0)) {
+ if (out == adev->active_output) {
+ F_LOG;
+ /* a change in output device may change the microphone selection */
+ if (adev->active_input &&
+ adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+ force_input_standby = true;
+ }
+ /* force standby if moving to/from HDMI */
+ if (((val & AUDIO_DEVICE_OUT_AUX_DIGITAL) ^
+ (adev->out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) ||
+ ((val & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) ^
+ (adev->out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
+ ((val & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) ^
+ (adev->out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET)))
+ do_output_standby(out);
+ }
+ adev->out_device = val;
F_LOG;
- select_device(adev);
+ select_device(adev);
if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM){
adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
}
- }
- pthread_mutex_unlock(&out->lock);
- if (force_input_standby) {
- in = adev->active_input;
- pthread_mutex_lock(&in->lock);
- do_input_standby(in);
- pthread_mutex_unlock(&in->lock);
- }
+ }
+
+ pthread_mutex_unlock(&out->lock);
+ if (force_input_standby) {
+ in = adev->active_input;
+ pthread_mutex_lock(&in->lock);
+ do_input_standby(in);
+ pthread_mutex_unlock(&in->lock);
+ }
pthread_mutex_unlock(&adev->lock);
}
ret = str_parms_get_str(parms, AUDIO_PARAMETER_RAW_DATA_OUT, value, sizeof(value));
- if (ret >= 0)
- {
+ if (ret >= 0) {
bool bval = (atoi(value) == 1) ? true : false;
ALOGV("AUDIO_PARAMETER_RAW_DATA_OUT: %d", bval);
pthread_mutex_lock(&adev->lock);
pthread_mutex_lock(&out->lock);
- if (adev->raw_flag != bval)
- {
+ if (adev->raw_flag != bval) {
adev->raw_flag = bval;
do_output_standby(out);
}
@@ -1702,55 +1613,54 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
pthread_mutex_unlock(&adev->lock);
}
- str_parms_destroy(parms);
- return ret;
+ str_parms_destroy(parms);
+ return ret;
}
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
{
- return strdup("");
+ return strdup("");
}
static uint32_t out_get_latency(const struct audio_stream_out *stream)
{
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- return (SHORT_PERIOD_SIZE * PLAYBACK_PERIOD_COUNT * 1000) / out->config.rate;
+ return (SHORT_PERIOD_SIZE * PLAYBACK_PERIOD_COUNT * 1000) / out->config.rate;
}
static int out_set_volume(struct audio_stream_out *stream, float left,
- float right)
+ float right)
{
- return -ENOSYS;
+ return -ENOSYS;
}
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
- size_t bytes)
+ size_t bytes)
{
- int ret;
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- struct sunxi_audio_device *adev = out->dev;
- size_t frame_size = audio_stream_frame_size(&out->stream.common);
- size_t in_frames = bytes / frame_size;
- size_t out_frames = RESAMPLER_BUFFER_SIZE / frame_size;
- bool force_input_standby = false;
- struct sunxi_stream_in *in;
- int kernel_frames;
- void *buf;
- if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) //10-16 modify
- {
+ int ret;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ struct sunxi_audio_device *adev = out->dev;
+ size_t frame_size = audio_stream_frame_size(&out->stream.common);
+ size_t in_frames = bytes / frame_size;
+ size_t out_frames = RESAMPLER_BUFFER_SIZE / frame_size;
+ bool force_input_standby = false;
+ struct sunxi_stream_in *in;
+ int kernel_frames;
+ void *buf;
+
+ if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) {
return bytes;
- if((CASE_NAME == 2) || adev->out_device==AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
+ if ((CASE_NAME == 2) || adev->out_device==AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
ALOGD("mode in call, do not out_write");
return bytes;
}
-
}
- if (adev->raw_flag)
- {
+ if (adev->raw_flag) {
return 0;
}
+
if (last_communication_is_bt && (adev->mode != AUDIO_MODE_IN_COMMUNICATION || adev->mode == AUDIO_MODE_IN_COMMUNICATION && adev->out_device!=AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET)) {
pcm_stop(adev->pcm_modem_dl);
pcm_stop(adev->pcm_modem_ul);
@@ -1767,160 +1677,117 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
adev->pcm_bt_ul = NULL;
last_communication_is_bt = false;
}
- /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
- * on the output stream mutex - e.g. executing select_mode() while holding the hw device
- * mutex
- */
- pthread_mutex_lock(&adev->lock);
+
+ /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
+ * on the output stream mutex - e.g. executing select_mode() while holding the hw device
+ * mutex
+ */
+ pthread_mutex_lock(&adev->lock);
pthread_mutex_lock(&out->lock);
- if (out->standby) {
- ret = start_output_stream(out);
- if (ret != 0) {
- pthread_mutex_unlock(&adev->lock);
- goto exit;
- }
- out->standby = 0;
- /* a change in output device may change the microphone selection */
- if (adev->active_input &&
- adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION){
- force_input_standby = true;
- F_LOG;
- }
- }
- pthread_mutex_unlock(&adev->lock);
-#if 0
- out->write_threshold = SHORT_PERIOD_SIZE * PLAYBACK_PERIOD_COUNT;
- out->config.avail_min = SHORT_PERIOD_SIZE;
- pcm_set_avail_min(out->pcm, out->config.avail_min);
-#endif
+ if (out->standby) {
+ ret = start_output_stream(out);
+ if (ret != 0) {
+ pthread_mutex_unlock(&adev->lock);
+ goto exit;
+ }
+ out->standby = 0;
+ /* a change in output device may change the microphone selection */
+ if (adev->active_input &&
+ adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION){
+ force_input_standby = true;
+ F_LOG;
+ }
+ }
+ pthread_mutex_unlock(&adev->lock);
+ /* only use resampler if required */
+ if (out->resampler) {
+ out->resampler->resample_from_input(out->resampler,
+ (int16_t *)buffer,
+ &in_frames,
+ (int16_t *)out->buffer,
+ &out_frames);
+ buf = out->buffer;
+ } else {
+ out_frames = in_frames;
+ buf = (void *)buffer;
+ }
- /* only use resampler if required */
- if (out->resampler) {
- out->resampler->resample_from_input(out->resampler,
- (int16_t *)buffer,
- &in_frames,
- (int16_t *)out->buffer,
- &out_frames);
- buf = out->buffer;
- } else {
- out_frames = in_frames;
- buf = (void *)buffer;
- }
- if (out->echo_reference != NULL) {
- struct echo_reference_buffer b;
- b.raw = (void *)buffer;
- b.frame_count = in_frames;
+ if (out->echo_reference != NULL) {
+ struct echo_reference_buffer b;
+ b.raw = (void *)buffer;
+ b.frame_count = in_frames;
- get_playback_delay(out, out_frames, &b);
- out->echo_reference->write(out->echo_reference, &b);
- }
-
-#if 0
- /* do not allow more than out->write_threshold frames in kernel pcm driver buffer */
- do {
- struct timespec time_stamp;
-
- if (pcm_get_htimestamp(out->pcm, (unsigned int *)&kernel_frames, &time_stamp) < 0)
- break;
- kernel_frames = pcm_get_buffer_size(out->pcm) - kernel_frames;
-
- if (kernel_frames > out->write_threshold) {
- unsigned long time = (unsigned long)
- (((int64_t)(kernel_frames - out->write_threshold) * 1000000) /
- MM_SAMPLING_RATE);
- if (time < MIN_WRITE_SLEEP_US)
- time = MIN_WRITE_SLEEP_US;
- usleep(time);
- }
- } while (kernel_frames > out->write_threshold);
-#endif
+ get_playback_delay(out, out_frames, &b);
+ out->echo_reference->write(out->echo_reference, &b);
+ }
if (adev->af_capture_flag && adev->PcmManager.BufExist) {
WritePcmData((void *)buf, out_frames * frame_size, &adev->PcmManager);
memset(buf, 0, out_frames * frame_size); //mute
}
-#if VVS_USED
-{
- char value[PROPERTY_VALUE_MAX];
-
- /* If the library fails, nothing is done. */
- if (vvs.lib_handle == NULL)
- goto vvs_exit;
-
- /* Gets the current switch state. Default value is open. */
- property_get("persist.sys.vvs_switch", value, "1");
- vvs.vvs_used = (atoi(value) != 0);
-
- if (vvs.vvs_used && (adev->out_device &(AUDIO_DEVICE_OUT_WIRED_HEADSET
- | AUDIO_DEVICE_OUT_WIRED_HEADPHONE))){
- vvs.surround_pro_in_out(vvs.vvs_handle, (short*)buf, (short*)buf,
- out_frames * out->config.channels);
- }
- //ALOGV("out_write: vvs_used=%d, out_device=%d", vvs.vvs_used, adev->out_device);
-}
-vvs_exit:
+#if USE_3D_SURROUND
+ if (surround_ready(sur) && surround_use(adev->out_device))
+ surround_process(sur, (short*)buf, out_frames, out->config.channels);
#endif
- ret = pcm_write(out->pcm, (void *)buf, out_frames * frame_size);
- if(ret!=0)
- {
+ ret = pcm_write(out->pcm, (void *)buf, out_frames * frame_size);
+ if (ret!=0) {
do_output_standby(out);
- }else if (ret == 0)
- out->written += bytes / (out->config.channels * sizeof(short)
- );
+ } else if (ret == 0)
+ out->written += bytes / (out->config.channels * sizeof(short));
exit:
- pthread_mutex_unlock(&out->lock);
+ pthread_mutex_unlock(&out->lock);
- if (ret != 0) {
- usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
- out_get_sample_rate(&stream->common));
- }
+ if (ret != 0) {
+ usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+ out_get_sample_rate(&stream->common));
+ }
- if (force_input_standby) {
- pthread_mutex_lock(&adev->lock);
- if (adev->active_input) {
- in = adev->active_input;
- pthread_mutex_lock(&in->lock);
- do_input_standby(in);
- pthread_mutex_unlock(&in->lock);
- }
- pthread_mutex_unlock(&adev->lock);
- }
+ if (force_input_standby) {
+ pthread_mutex_lock(&adev->lock);
+ if (adev->active_input) {
+ in = adev->active_input;
+ pthread_mutex_lock(&in->lock);
+ do_input_standby(in);
+ pthread_mutex_unlock(&in->lock);
+ }
+ pthread_mutex_unlock(&adev->lock);
+ }
- return bytes;
+ return bytes;
}
static int out_get_render_position(const struct audio_stream_out *stream,
- uint32_t *dsp_frames)
+ uint32_t *dsp_frames)
{
- return -EINVAL;
+ return -EINVAL;
}
static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
- return 0;
+ return 0;
}
static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
{
- return 0;
+ return 0;
}
static int out_get_next_write_timestamp(const struct audio_stream_out *stream,
- int64_t *timestamp)
+ int64_t *timestamp)
{
- return -EINVAL;
+ return -EINVAL;
}
/** audio_stream_in implementation **/
static int get_next_buffer(struct resampler_buffer_provider *buffer_provider,
- struct resampler_buffer* buffer);
+ struct resampler_buffer* buffer);
static void release_buffer(struct resampler_buffer_provider *buffer_provider,
- struct resampler_buffer* buffer);
+ struct resampler_buffer* buffer);
/* must be called with hw device and input stream mutexes locked */
static int start_input_stream(struct sunxi_stream_in *in)
@@ -1933,96 +1800,71 @@ static int start_input_stream(struct sunxi_stream_in *in)
if (adev->mode == AUDIO_MODE_IN_CALL) { // && adev->bluetooth_voice
ALOGD("in call mode , start_input_stream, return");
- //return 0;
}
- //if (adev->mode != AUDIO_MODE_IN_CALL) {
F_LOG;
adev->in_device = in->device;
select_device(adev);
- //}
if (in->need_echo_reference && in->echo_reference == NULL)
- in->echo_reference = get_echo_reference(adev,
- AUDIO_FORMAT_PCM_16_BIT,
- in->config.channels,
- in->requested_rate);
+ in->echo_reference = get_echo_reference(adev,
+ AUDIO_FORMAT_PCM_16_BIT,
+ in->config.channels,
+ in->requested_rate);
in_ajust_rate = in->requested_rate;
ALOGD(">>>>>> in_ajust_rate is : %d", in_ajust_rate);
- // out/in stream should be both 44.1K serial
- switch(CASE_NAME){
+ // out/in stream should be both 44.1K serial
+ switch (CASE_NAME) {
case 0 :
case 1 :
in_ajust_rate = SAMPLING_RATE_44K;
ALOGV("%s, line: %d,adev->mode:%d,adev->out_device:%d", __FUNCTION__, __LINE__,adev->mode,adev->out_device);
- //if((adev->mode == AUDIO_MODE_IN_CALL) && (adev->out_device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) )
- if((adev->mode == AUDIO_MODE_IN_CALL) && (adev->out_device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO) ){
+
+ if ((adev->mode == AUDIO_MODE_IN_CALL) && (adev->out_device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO)) {
ALOGV("%s, line: %d,adev->mode:%d,adev->out_device:%d", __FUNCTION__, __LINE__,adev->mode,adev->out_device);
in_ajust_rate = SAMPLING_RATE_8K;
}
- if((adev->mode == AUDIO_MODE_IN_COMMUNICATION) && (adev->out_device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) ){
+ if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) && (adev->out_device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET)) {
ALOGV("%s, line: %d,adev->mode:%d,adev->out_device:%d", __FUNCTION__, __LINE__,adev->mode,adev->out_device);
in_ajust_rate = SAMPLING_RATE_8K;
//in->config.rate = SAMPLING_RATE_8K;
}
break;
case 2 :
- if(adev->mode == AUDIO_MODE_IN_CALL)
+ if (adev->mode == AUDIO_MODE_IN_CALL)
in_ajust_rate = in->requested_rate;
else
in_ajust_rate = SAMPLING_RATE_44K;
default :
break;
-
}
-#if 0
- #ifdef USERECORD_44100_SAMPLERATE
- in_ajust_rate = SAMPLING_RATE_44K;
- #else
- if (!(in->requested_rate % SAMPLING_RATE_11K))
- {
- // OK
- in_ajust_rate = in->requested_rate;
- }
- else
- {
- in_ajust_rate = SAMPLING_RATE_11K * in->requested_rate / SAMPLING_RATE_8K;
- if (in_ajust_rate > SAMPLING_RATE_44K)
- {
- }
- ALOGV("out/in stream should be both 44.1K serial, force capture rate: %d", in_ajust_rate);
- }
- #endif
-#endif
ALOGV("rate:%d, period_count:%d, period_size:%d,channels:%d", in->config.rate, in->config.period_count, in->config.period_size,in->config.channels);
ALOGV("in_ajust_rate:%d", in_ajust_rate);
if (adev->mode == AUDIO_MODE_IN_CALL)
- //in->pcm = pcm_open_req(0, PORT_VIR_CODEC, PCM_IN, &in->config, in_ajust_rate);
- in->pcm = pcm_open(0, PORT_VIR_CODEC, PCM_IN, &in->config);
+ in->pcm = pcm_open(0, PORT_VIR_CODEC, PCM_IN, &in->config);
else
- //in->pcm = pcm_open_req(0, PORT_CODEC, PCM_IN, &in->config, in_ajust_rate);
in->pcm = pcm_open(0, PORT_CODEC, PCM_IN, &in->config);
- if (!pcm_is_ready(in->pcm)) {
- ALOGE("cannot open pcm_in driver: %s", pcm_get_error(in->pcm));
- pcm_close(in->pcm);
- adev->active_input = NULL;
- return -ENOMEM;
- }
+ if (!pcm_is_ready(in->pcm)) {
+ ALOGE("cannot open pcm_in driver: %s", pcm_get_error(in->pcm));
+ pcm_close(in->pcm);
+ adev->active_input = NULL;
+ return -ENOMEM;
+ }
if (in->requested_rate != in->config.rate) {
in->buf_provider.get_next_buffer = get_next_buffer;
in->buf_provider.release_buffer = release_buffer;
ret = create_resampler(in->config.rate,
- in->requested_rate,
- in->config.channels,
- RESAMPLER_QUALITY_DEFAULT,
- &in->buf_provider,
- &in->resampler);
+ in->requested_rate,
+ in->config.channels,
+ RESAMPLER_QUALITY_DEFAULT,
+ &in->buf_provider,
+ &in->resampler);
if (ret != 0) {
ALOGE("create in resampler failed, %d -> %d", in->config.rate, in->requested_rate);
ret = -EINVAL;
@@ -2030,415 +1872,412 @@ static int start_input_stream(struct sunxi_stream_in *in)
}
ALOGV("create in resampler OK, %d -> %d", in->config.rate, in->requested_rate);
- }
- else
- {
+ } else {
ALOGV("do not use in resampler");
}
- /* if no supported sample rate is available, use the resampler */
- if (in->resampler) {
- in->resampler->reset(in->resampler);
- in->frames_in = 0;
- }
- return 0;
+ /* if no supported sample rate is available, use the resampler */
+ if (in->resampler) {
+ in->resampler->reset(in->resampler);
+ in->frames_in = 0;
+ }
+ return 0;
err:
- if (in->resampler) {
- release_resampler(in->resampler);
- }
+ if (in->resampler) {
+ release_resampler(in->resampler);
+ }
- return -1;
+ return -1;
}
static uint32_t in_get_sample_rate(const struct audio_stream *stream)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- return in->requested_rate;
+ return in->requested_rate;
}
static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
- return 0;
+ return 0;
}
static size_t in_get_buffer_size(const struct audio_stream *stream)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- return get_input_buffer_size(in->requested_rate,
- AUDIO_FORMAT_PCM_16_BIT,
- in->config.channels);
+ return get_input_buffer_size(in->requested_rate,
+ AUDIO_FORMAT_PCM_16_BIT,
+ in->config.channels);
}
static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- if (in->config.channels == 1) {
- return AUDIO_CHANNEL_IN_MONO;
- } else {
- return AUDIO_CHANNEL_IN_STEREO;
- }
+ if (in->config.channels == 1) {
+ return AUDIO_CHANNEL_IN_MONO;
+ } else {
+ return AUDIO_CHANNEL_IN_STEREO;
+ }
}
static audio_format_t in_get_format(const struct audio_stream *stream)
{
- return AUDIO_FORMAT_PCM_16_BIT;
+ return AUDIO_FORMAT_PCM_16_BIT;
}
static int in_set_format(struct audio_stream *stream, audio_format_t format)
{
- return 0;
+ return 0;
}
/* must be called with hw device and input stream mutexes locked */
static int do_input_standby(struct sunxi_stream_in *in)
{
- struct sunxi_audio_device *adev = in->dev;
+ struct sunxi_audio_device *adev = in->dev;
- if (!in->standby) {
- pcm_close(in->pcm);
- in->pcm = NULL;
+ if (!in->standby) {
+ pcm_close(in->pcm);
+ in->pcm = NULL;
- adev->active_input = 0;
- if (in->resampler){
- release_resampler(in->resampler);
- in->resampler = 0;
- }
- if (adev->mode != AUDIO_MODE_IN_CALL) {
- adev->in_device = AUDIO_DEVICE_NONE;
- select_device(adev);
- }
+ adev->active_input = 0;
+ if (in->resampler) {
+ release_resampler(in->resampler);
+ in->resampler = 0;
+ }
+ if (adev->mode != AUDIO_MODE_IN_CALL) {
+ adev->in_device = AUDIO_DEVICE_NONE;
+ select_device(adev);
+ }
- if (in->echo_reference != NULL) {
- /* stop reading from echo reference */
- in->echo_reference->read(in->echo_reference, NULL);
- put_echo_reference(adev, in->echo_reference);
- in->echo_reference = NULL;
- }
+ if (in->echo_reference != NULL) {
+ /* stop reading from echo reference */
+ in->echo_reference->read(in->echo_reference, NULL);
+ put_echo_reference(adev, in->echo_reference);
+ in->echo_reference = NULL;
+ }
- in->standby = 1;
- }
- return 0;
+ in->standby = 1;
+ }
+ return 0;
}
static int in_standby(struct audio_stream *stream)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- int status;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ int status;
- pthread_mutex_lock(&in->dev->lock);
- pthread_mutex_lock(&in->lock);
- status = do_input_standby(in);
- pthread_mutex_unlock(&in->lock);
- pthread_mutex_unlock(&in->dev->lock);
- return status;
+ pthread_mutex_lock(&in->dev->lock);
+ pthread_mutex_lock(&in->lock);
+ status = do_input_standby(in);
+ pthread_mutex_unlock(&in->lock);
+ pthread_mutex_unlock(&in->dev->lock);
+ return status;
}
static int in_dump(const struct audio_stream *stream, int fd)
{
- return 0;
+ return 0;
}
static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- struct sunxi_audio_device *adev = in->dev;
- struct str_parms *parms;
- char *str;
- char value[128];
- int ret, val = 0;
- bool do_standby = false;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ struct sunxi_audio_device *adev = in->dev;
+ struct str_parms *parms;
+ char *str;
+ char value[128];
+ int ret, val = 0;
+ bool do_standby = false;
- ALOGV("in_set_parameters: %s", kvpairs);
+ ALOGV("in_set_parameters: %s", kvpairs);
- parms = str_parms_create_str(kvpairs);
+ parms = str_parms_create_str(kvpairs);
- ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_INPUT_SOURCE, value, sizeof(value));
- pthread_mutex_lock(&adev->lock);
- pthread_mutex_lock(&in->lock);
- if (ret >= 0) {
- val = atoi(value);
- /* no audio source uses val == 0 */
- if ((in->source != val) && (val != 0)) {
- in->source = val;
- do_standby = true;
- }
- }
-
- ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
- if (ret >= 0) {
- val = atoi(value) & ~AUDIO_DEVICE_BIT_IN;
- if ((adev->mode != AUDIO_MODE_IN_CALL) && (in->device != val) && (val != 0)) {
- in->device = val;
- do_standby = true;
- } else if((adev->mode == AUDIO_MODE_IN_CALL) && (in->source != val) && (val != 0)) {
- in->device = val;
-
- select_device(adev);
+ pthread_mutex_lock(&adev->lock);
+ pthread_mutex_lock(&in->lock);
+ if (ret >= 0) {
+ val = atoi(value);
+ /* no audio source uses val == 0 */
+ if ((in->source != val) && (val != 0)) {
+ in->source = val;
+ do_standby = true;
}
}
- if (do_standby)
- do_input_standby(in);
- pthread_mutex_unlock(&in->lock);
- pthread_mutex_unlock(&adev->lock);
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
+ if (ret >= 0) {
+ val = atoi(value) & ~AUDIO_DEVICE_BIT_IN;
+ if ((adev->mode != AUDIO_MODE_IN_CALL) && (in->device != val) && (val != 0)) {
+ in->device = val;
+ do_standby = true;
+ } else if ((adev->mode == AUDIO_MODE_IN_CALL) && (in->source != val) && (val != 0)) {
+ in->device = val;
- str_parms_destroy(parms);
- return ret;
+ select_device(adev);
+ }
+ }
+
+ if (do_standby)
+ do_input_standby(in);
+ pthread_mutex_unlock(&in->lock);
+ pthread_mutex_unlock(&adev->lock);
+
+ str_parms_destroy(parms);
+ return ret;
}
static char * in_get_parameters(const struct audio_stream *stream,
- const char *keys)
+ const char *keys)
{
- return strdup("");
+ return strdup("");
}
static int in_set_gain(struct audio_stream_in *stream, float gain)
{
- return 0;
+ return 0;
}
static void get_capture_delay(struct sunxi_stream_in *in,
- size_t frames,
- struct echo_reference_buffer *buffer)
+ size_t frames,
+ struct echo_reference_buffer *buffer)
{
- /* read frames available in kernel driver buffer */
- size_t kernel_frames;
- struct timespec tstamp;
- long buf_delay;
- long rsmp_delay;
- long kernel_delay;
- long delay_ns;
+ /* read frames available in kernel driver buffer */
+ size_t kernel_frames;
+ struct timespec tstamp;
+ long buf_delay;
+ long rsmp_delay;
+ long kernel_delay;
+ long delay_ns;
- if (pcm_get_htimestamp(in->pcm, &kernel_frames, &tstamp) < 0) {
- buffer->time_stamp.tv_sec = 0;
- buffer->time_stamp.tv_nsec = 0;
- buffer->delay_ns = 0;
- ALOGW("read get_capture_delay(): pcm_htimestamp error");
- return;
- }
+ if (pcm_get_htimestamp(in->pcm, &kernel_frames, &tstamp) < 0) {
+ buffer->time_stamp.tv_sec = 0;
+ buffer->time_stamp.tv_nsec = 0;
+ buffer->delay_ns = 0;
+ ALOGW("read get_capture_delay(): pcm_htimestamp error");
+ return;
+ }
- /* read frames available in audio HAL input buffer
- * add number of frames being read as we want the capture time of first sample
- * in current buffer */
- buf_delay = (long)(((int64_t)(in->frames_in + in->proc_frames_in) * 1000000000)
- / in->config.rate);
- /* add delay introduced by resampler */
- rsmp_delay = 0;
- if (in->resampler) {
- rsmp_delay = in->resampler->delay_ns(in->resampler);
- }
+ /* read frames available in audio HAL input buffer
+ * add number of frames being read as we want the capture time of first sample
+ * in current buffer */
+ buf_delay = (long)(((int64_t)(in->frames_in + in->proc_frames_in) * 1000000000)
+ / in->config.rate);
+ /* add delay introduced by resampler */
+ rsmp_delay = 0;
+ if (in->resampler) {
+ rsmp_delay = in->resampler->delay_ns(in->resampler);
+ }
- kernel_delay = (long)(((int64_t)kernel_frames * 1000000000) / in->config.rate);
+ kernel_delay = (long)(((int64_t)kernel_frames * 1000000000) / in->config.rate);
- delay_ns = kernel_delay + buf_delay + rsmp_delay;
+ delay_ns = kernel_delay + buf_delay + rsmp_delay;
- buffer->time_stamp = tstamp;
- buffer->delay_ns = delay_ns;
- ALOGV("get_capture_delay time_stamp = [%ld].[%ld], delay_ns: [%d],"
- " kernel_delay:[%ld], buf_delay:[%ld], rsmp_delay:[%ld], kernel_frames:[%d], "
- "in->frames_in:[%d], in->proc_frames_in:[%d], frames:[%d]",
- buffer->time_stamp.tv_sec , buffer->time_stamp.tv_nsec, buffer->delay_ns,
- kernel_delay, buf_delay, rsmp_delay, kernel_frames,
- in->frames_in, in->proc_frames_in, frames);
+ buffer->time_stamp = tstamp;
+ buffer->delay_ns = delay_ns;
+ ALOGV("get_capture_delay time_stamp = [%ld].[%ld], delay_ns: [%d],"
+ " kernel_delay:[%ld], buf_delay:[%ld], rsmp_delay:[%ld], kernel_frames:[%d], "
+ "in->frames_in:[%d], in->proc_frames_in:[%d], frames:[%d]",
+ buffer->time_stamp.tv_sec , buffer->time_stamp.tv_nsec, buffer->delay_ns,
+ kernel_delay, buf_delay, rsmp_delay, kernel_frames,
+ in->frames_in, in->proc_frames_in, frames);
}
static int32_t update_echo_reference(struct sunxi_stream_in *in, size_t frames)
{
- struct echo_reference_buffer b;
- b.delay_ns = 0;
+ struct echo_reference_buffer b;
+ b.delay_ns = 0;
- ALOGV("update_echo_reference, frames = [%d], in->ref_frames_in = [%d], "
- "b.frame_count = [%d]",
- frames, in->ref_frames_in, frames - in->ref_frames_in);
- if (in->ref_frames_in < frames) {
- if (in->ref_buf_size < frames) {
- in->ref_buf_size = frames;
- in->ref_buf = (int16_t *)realloc(in->ref_buf,
- in->ref_buf_size *
- in->config.channels * sizeof(int16_t));
- }
+ ALOGV("update_echo_reference, frames = [%d], in->ref_frames_in = [%d], "
+ "b.frame_count = [%d]",
+ frames, in->ref_frames_in, frames - in->ref_frames_in);
+ if (in->ref_frames_in < frames) {
+ if (in->ref_buf_size < frames) {
+ in->ref_buf_size = frames;
+ in->ref_buf = (int16_t *)realloc(in->ref_buf,
+ in->ref_buf_size *
+ in->config.channels * sizeof(int16_t));
+ }
- b.frame_count = frames - in->ref_frames_in;
- b.raw = (void *)(in->ref_buf + in->ref_frames_in * in->config.channels);
+ b.frame_count = frames - in->ref_frames_in;
+ b.raw = (void *)(in->ref_buf + in->ref_frames_in * in->config.channels);
- get_capture_delay(in, frames, &b);
+ get_capture_delay(in, frames, &b);
- if (in->echo_reference->read(in->echo_reference, &b) == 0)
- {
- in->ref_frames_in += b.frame_count;
- ALOGV("update_echo_reference: in->ref_frames_in:[%d], "
- "in->ref_buf_size:[%d], frames:[%d], b.frame_count:[%d]",
- in->ref_frames_in, in->ref_buf_size, frames, b.frame_count);
- }
- } else
- ALOGW("update_echo_reference: NOT enough frames to read ref buffer");
- return b.delay_ns;
+ if (in->echo_reference->read(in->echo_reference, &b) == 0) {
+ in->ref_frames_in += b.frame_count;
+ ALOGV("update_echo_reference: in->ref_frames_in:[%d], "
+ "in->ref_buf_size:[%d], frames:[%d], b.frame_count:[%d]",
+ in->ref_frames_in, in->ref_buf_size, frames, b.frame_count);
+ }
+ } else
+ ALOGW("update_echo_reference: NOT enough frames to read ref buffer");
+
+ return b.delay_ns;
}
static int set_preprocessor_param(effect_handle_t handle,
- effect_param_t *param)
+ effect_param_t *param)
{
- uint32_t size = sizeof(int);
- uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
- param->vsize;
+ uint32_t size = sizeof(int);
+ uint32_t psize = ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) +
+ param->vsize;
- int status = (*handle)->command(handle,
- EFFECT_CMD_SET_PARAM,
- sizeof (effect_param_t) + psize,
- param,
- &size,
- ¶m->status);
- if (status == 0)
- status = param->status;
+ int status = (*handle)->command(handle,
+ EFFECT_CMD_SET_PARAM,
+ sizeof (effect_param_t) + psize,
+ param,
+ &size,
+ ¶m->status);
+ if (status == 0)
+ status = param->status;
- return status;
+ return status;
}
static int set_preprocessor_echo_delay(effect_handle_t handle,
- int32_t delay_us)
+ int32_t delay_us)
{
- uint32_t buf[sizeof(effect_param_t) / sizeof(uint32_t) + 2];
- effect_param_t *param = (effect_param_t *)buf;
+ uint32_t buf[sizeof(effect_param_t) / sizeof(uint32_t) + 2];
+ effect_param_t *param = (effect_param_t *)buf;
- param->psize = sizeof(uint32_t);
- param->vsize = sizeof(uint32_t);
- *(uint32_t *)param->data = AEC_PARAM_ECHO_DELAY;
- *((int32_t *)param->data + 1) = delay_us;
+ param->psize = sizeof(uint32_t);
+ param->vsize = sizeof(uint32_t);
+ *(uint32_t *)param->data = AEC_PARAM_ECHO_DELAY;
+ *((int32_t *)param->data + 1) = delay_us;
- return set_preprocessor_param(handle, param);
+ return set_preprocessor_param(handle, param);
}
static void push_echo_reference(struct sunxi_stream_in *in, size_t frames)
{
- /* read frames from echo reference buffer and update echo delay
- * in->ref_frames_in is updated with frames available in in->ref_buf */
- int32_t delay_us = update_echo_reference(in, frames)/1000;
- int i;
- audio_buffer_t buf;
+ /* read frames from echo reference buffer and update echo delay
+ * in->ref_frames_in is updated with frames available in in->ref_buf */
+ int32_t delay_us = update_echo_reference(in, frames)/1000;
+ int i;
+ audio_buffer_t buf;
- if (in->ref_frames_in < frames)
- frames = in->ref_frames_in;
+ if (in->ref_frames_in < frames)
+ frames = in->ref_frames_in;
- buf.frameCount = frames;
- buf.raw = in->ref_buf;
+ buf.frameCount = frames;
+ buf.raw = in->ref_buf;
- for (i = 0; i < in->num_preprocessors; i++) {
- if ((*in->preprocessors[i])->process_reverse == NULL)
- continue;
+ for (i = 0; i < in->num_preprocessors; i++) {
+ if ((*in->preprocessors[i])->process_reverse == NULL)
+ continue;
- (*in->preprocessors[i])->process_reverse(in->preprocessors[i],
- &buf,
- NULL);
- set_preprocessor_echo_delay(in->preprocessors[i], delay_us);
- }
+ (*in->preprocessors[i])->process_reverse(in->preprocessors[i],
+ &buf,
+ NULL);
+ set_preprocessor_echo_delay(in->preprocessors[i], delay_us);
+ }
- in->ref_frames_in -= buf.frameCount;
- if (in->ref_frames_in) {
- memcpy(in->ref_buf,
- in->ref_buf + buf.frameCount * in->config.channels,
- in->ref_frames_in * in->config.channels * sizeof(int16_t));
- }
+ in->ref_frames_in -= buf.frameCount;
+ if (in->ref_frames_in) {
+ memcpy(in->ref_buf,
+ in->ref_buf + buf.frameCount * in->config.channels,
+ in->ref_frames_in * in->config.channels * sizeof(int16_t));
+ }
}
static int get_next_buffer(struct resampler_buffer_provider *buffer_provider,
- struct resampler_buffer* buffer)
+ struct resampler_buffer* buffer)
{
- struct sunxi_stream_in *in;
+ struct sunxi_stream_in *in;
- if (buffer_provider == NULL || buffer == NULL)
- return -EINVAL;
+ if (buffer_provider == NULL || buffer == NULL)
+ return -EINVAL;
- in = (struct sunxi_stream_in *)((char *)buffer_provider -
- offsetof(struct sunxi_stream_in, buf_provider));
+ in = (struct sunxi_stream_in *)((char *)buffer_provider -
+ offsetof(struct sunxi_stream_in, buf_provider));
- if (in->pcm == NULL) {
- buffer->raw = NULL;
- buffer->frame_count = 0;
- in->read_status = -ENODEV;
- return -ENODEV;
- }
+ if (in->pcm == NULL) {
+ buffer->raw = NULL;
+ buffer->frame_count = 0;
+ in->read_status = -ENODEV;
+ return -ENODEV;
+ }
-// ALOGV("get_next_buffer: in->config.period_size: %d, audio_stream_frame_size: %d",
-// in->config.period_size, audio_stream_frame_size(&in->stream.common));
- if (in->frames_in == 0) {
- in->read_status = pcm_read(in->pcm,
- (void*)in->buffer,
- in->config.period_size *
- audio_stream_frame_size(&in->stream.common));
- if (in->read_status != 0) {
- ALOGE("get_next_buffer() pcm_read error %d, %s", in->read_status, strerror(errno));
- buffer->raw = NULL;
- buffer->frame_count = 0;
- return in->read_status;
- }
- in->frames_in = in->config.period_size;
- }
+ if (in->frames_in == 0) {
+ in->read_status = pcm_read(in->pcm,
+ (void*)in->buffer,
+ in->config.period_size *
+ audio_stream_frame_size(&in->stream.common));
+ if (in->read_status != 0) {
+ ALOGE("get_next_buffer() pcm_read error %d, %s", in->read_status, strerror(errno));
+ buffer->raw = NULL;
+ buffer->frame_count = 0;
+ return in->read_status;
+ }
+ in->frames_in = in->config.period_size;
+ }
- buffer->frame_count = (buffer->frame_count > in->frames_in) ?
- in->frames_in : buffer->frame_count;
- buffer->i16 = in->buffer + (in->config.period_size - in->frames_in) *
- in->config.channels;
+ buffer->frame_count = (buffer->frame_count > in->frames_in) ?
+ in->frames_in : buffer->frame_count;
+ buffer->i16 = in->buffer + (in->config.period_size - in->frames_in) *
+ in->config.channels;
- return in->read_status;
+ return in->read_status;
}
static void release_buffer(struct resampler_buffer_provider *buffer_provider,
- struct resampler_buffer* buffer)
+ struct resampler_buffer* buffer)
{
- struct sunxi_stream_in *in;
+ struct sunxi_stream_in *in;
- if (buffer_provider == NULL || buffer == NULL)
- return;
+ if (buffer_provider == NULL || buffer == NULL)
+ return;
- in = (struct sunxi_stream_in *)((char *)buffer_provider -
- offsetof(struct sunxi_stream_in, buf_provider));
+ in = (struct sunxi_stream_in *)((char *)buffer_provider -
+ offsetof(struct sunxi_stream_in, buf_provider));
- in->frames_in -= buffer->frame_count;
+ in->frames_in -= buffer->frame_count;
}
/* read_frames() reads frames from kernel driver, down samples to capture rate
* if necessary and output the number of frames requested to the buffer specified */
static ssize_t read_frames(struct sunxi_stream_in *in, void *buffer, ssize_t frames)
{
- ssize_t frames_wr = 0;
+ ssize_t frames_wr = 0;
- while (frames_wr < frames) {
- size_t frames_rd = frames - frames_wr;
- if (in->resampler != NULL) {
- in->resampler->resample_from_provider(in->resampler,
- (int16_t *)((char *)buffer +
- frames_wr * audio_stream_frame_size(&in->stream.common)),
- &frames_rd);
- } else {
- struct resampler_buffer buf = {
- { raw : NULL, },
- frame_count : frames_rd,
- };
- get_next_buffer(&in->buf_provider, &buf);
- if (buf.raw != NULL) {
- memcpy((char *)buffer +
- frames_wr * audio_stream_frame_size(&in->stream.common),
- buf.raw,
- buf.frame_count * audio_stream_frame_size(&in->stream.common));
- frames_rd = buf.frame_count;
- }
- release_buffer(&in->buf_provider, &buf);
- }
- /* in->read_status is updated by getNextBuffer() also called by
- * in->resampler->resample_from_provider() */
- if (in->read_status != 0)
- return in->read_status;
+ while (frames_wr < frames) {
+ size_t frames_rd = frames - frames_wr;
+ if (in->resampler != NULL) {
+ in->resampler->resample_from_provider(in->resampler,
+ (int16_t *)((char *)buffer +
+ frames_wr * audio_stream_frame_size(&in->stream.common)),
+ &frames_rd);
+ } else {
+ struct resampler_buffer buf = {
+ { raw : NULL, },
+ frame_count : frames_rd,
+ };
+ get_next_buffer(&in->buf_provider, &buf);
+ if (buf.raw != NULL) {
+ memcpy((char *)buffer +
+ frames_wr * audio_stream_frame_size(&in->stream.common),
+ buf.raw,
+ buf.frame_count * audio_stream_frame_size(&in->stream.common));
+ frames_rd = buf.frame_count;
+ }
+ release_buffer(&in->buf_provider, &buf);
+ }
- frames_wr += frames_rd;
- }
- return frames_wr;
+ /* in->read_status is updated by getNextBuffer() also called by
+ * in->resampler->resample_from_provider() */
+ if (in->read_status != 0)
+ return in->read_status;
+
+ frames_wr += frames_rd;
+ }
+ return frames_wr;
}
/* process_frames() reads frames from kernel driver (via read_frames()),
@@ -2446,429 +2285,407 @@ static ssize_t read_frames(struct sunxi_stream_in *in, void *buffer, ssize_t fra
* to the buffer specified */
static ssize_t process_frames(struct sunxi_stream_in *in, void* buffer, ssize_t frames)
{
- ssize_t frames_wr = 0;
- audio_buffer_t in_buf;
- audio_buffer_t out_buf;
- int i;
+ ssize_t frames_wr = 0;
+ audio_buffer_t in_buf;
+ audio_buffer_t out_buf;
+ int i;
- while (frames_wr < frames) {
- /* first reload enough frames at the end of process input buffer */
- if (in->proc_frames_in < (size_t)frames) {
- ssize_t frames_rd;
+ while (frames_wr < frames) {
+ /* first reload enough frames at the end of process input buffer */
+ if (in->proc_frames_in < (size_t)frames) {
+ ssize_t frames_rd;
- if (in->proc_buf_size < (size_t)frames) {
- in->proc_buf_size = (size_t)frames;
- in->proc_buf = (int16_t *)realloc(in->proc_buf,
- in->proc_buf_size *
- in->config.channels * sizeof(int16_t));
- ALOGV("process_frames(): in->proc_buf %p size extended to %d frames",
- in->proc_buf, in->proc_buf_size);
- }
- frames_rd = read_frames(in,
- in->proc_buf +
- in->proc_frames_in * in->config.channels,
- frames - in->proc_frames_in);
- if (frames_rd < 0) {
- frames_wr = frames_rd;
- break;
- }
- in->proc_frames_in += frames_rd;
- }
+ if (in->proc_buf_size < (size_t)frames) {
+ in->proc_buf_size = (size_t)frames;
+ in->proc_buf = (int16_t *)realloc(in->proc_buf,
+ in->proc_buf_size *
+ in->config.channels * sizeof(int16_t));
+ ALOGV("process_frames(): in->proc_buf %p size extended to %d frames",
+ in->proc_buf, in->proc_buf_size);
+ }
+ frames_rd = read_frames(in,
+ in->proc_buf +
+ in->proc_frames_in * in->config.channels,
+ frames - in->proc_frames_in);
+ if (frames_rd < 0) {
+ frames_wr = frames_rd;
+ break;
+ }
+ in->proc_frames_in += frames_rd;
+ }
- if (in->echo_reference != NULL)
- push_echo_reference(in, in->proc_frames_in);
+ if (in->echo_reference != NULL)
+ push_echo_reference(in, in->proc_frames_in);
- /* in_buf.frameCount and out_buf.frameCount indicate respectively
- * the maximum number of frames to be consumed and produced by process() */
- in_buf.frameCount = in->proc_frames_in;
- in_buf.s16 = in->proc_buf;
- out_buf.frameCount = frames - frames_wr;
- out_buf.s16 = (int16_t *)buffer + frames_wr * in->config.channels;
+ /* in_buf.frameCount and out_buf.frameCount indicate respectively
+ * the maximum number of frames to be consumed and produced by process() */
+ in_buf.frameCount = in->proc_frames_in;
+ in_buf.s16 = in->proc_buf;
+ out_buf.frameCount = frames - frames_wr;
+ out_buf.s16 = (int16_t *)buffer + frames_wr * in->config.channels;
- for (i = 0; i < in->num_preprocessors; i++)
- (*in->preprocessors[i])->process(in->preprocessors[i],
- &in_buf,
- &out_buf);
+ for (i = 0; i < in->num_preprocessors; i++)
+ (*in->preprocessors[i])->process(in->preprocessors[i],
+ &in_buf,
+ &out_buf);
- /* process() has updated the number of frames consumed and produced in
- * in_buf.frameCount and out_buf.frameCount respectively
- * move remaining frames to the beginning of in->proc_buf */
- in->proc_frames_in -= in_buf.frameCount;
- if (in->proc_frames_in) {
- memcpy(in->proc_buf,
- in->proc_buf + in_buf.frameCount * in->config.channels,
- in->proc_frames_in * in->config.channels * sizeof(int16_t));
- }
+ /* process() has updated the number of frames consumed and produced in
+ * in_buf.frameCount and out_buf.frameCount respectively
+ * move remaining frames to the beginning of in->proc_buf */
+ in->proc_frames_in -= in_buf.frameCount;
+ if (in->proc_frames_in) {
+ memcpy(in->proc_buf,
+ in->proc_buf + in_buf.frameCount * in->config.channels,
+ in->proc_frames_in * in->config.channels * sizeof(int16_t));
+ }
- /* if not enough frames were passed to process(), read more and retry. */
- if (out_buf.frameCount == 0)
- continue;
+ /* if not enough frames were passed to process(), read more and retry. */
+ if (out_buf.frameCount == 0)
+ continue;
- frames_wr += out_buf.frameCount;
- }
- return frames_wr;
+ frames_wr += out_buf.frameCount;
+ }
+ return frames_wr;
}
static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
- size_t bytes)
+ size_t bytes)
{
- int ret = 0;
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- struct sunxi_audio_device *adev = in->dev;
- size_t frames_rq = bytes / audio_stream_frame_size(&stream->common);
+ int ret = 0;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ struct sunxi_audio_device *adev = in->dev;
+ size_t frames_rq = bytes / audio_stream_frame_size(&stream->common);
+ int is_first_data = 0;
- if (adev->mode == AUDIO_MODE_IN_CALL) {
- //ALOGD("in call mode, in_read, return ;");
- memset(buffer, 0, bytes);
- //usleep(10000);
- //return 1;
- }
+ if (adev->mode == AUDIO_MODE_IN_CALL) {
+ //ALOGD("in call mode, in_read, return ;");
+ memset(buffer, 0, bytes);
+ //usleep(10000);
+ //return 1;
+ }
- /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
- * on the input stream mutex - e.g. executing select_mode() while holding the hw device
- * mutex
- */
- if (adev->af_capture_flag && adev->PcmManager.BufExist) {
- pthread_mutex_lock(&adev->lock);
- pthread_mutex_lock(&in->lock);
- if (in->standby) {
- in->standby = 0;
- }
- pthread_mutex_unlock(&adev->lock);
+ /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
+ * on the input stream mutex - e.g. executing select_mode() while holding the hw device
+ * mutex
+ */
+ if (adev->af_capture_flag && adev->PcmManager.BufExist) {
+ pthread_mutex_lock(&adev->lock);
+ pthread_mutex_lock(&in->lock);
+ if (in->standby) {
+ in->standby = 0;
+ }
+ pthread_mutex_unlock(&adev->lock);
- if (ret < 0)
- goto exit;
+ if (ret < 0)
+ goto exit;
//if (bytes > adev->PcmManager.DataLen)
- //usleep(10000);
+ //usleep(10000);
- ret = ReadPcmData(buffer, bytes, &adev->PcmManager);
+ ret = ReadPcmData(buffer, bytes, &adev->PcmManager);
- if (ret > 0)
- ret = 0;
+ if (ret > 0)
+ ret = 0;
- if (ret == 0 && adev->mic_mute)
- memset(buffer, 0, bytes);
+ if (ret == 0 && adev->mic_mute)
+ memset(buffer, 0, bytes);
- pthread_mutex_unlock(&in->lock);
- return bytes;
+ pthread_mutex_unlock(&in->lock);
+ return bytes;
}
pthread_mutex_lock(&adev->lock);
pthread_mutex_lock(&in->lock);
if (in->standby) {
ret = start_input_stream(in);
+ is_first_data = 1;
if (ret == 0)
in->standby = 0;
}
pthread_mutex_unlock(&adev->lock);
- if (ret < 0)
- goto exit;
+ if (ret < 0)
+ goto exit;
- if (in->num_preprocessors != 0) {
- ret = read_frames(in, buffer, frames_rq);//ret = process_frames(in, buffer, frames_rq);
+ if (in->num_preprocessors != 0) {
+ ret = read_frames(in, buffer, frames_rq);//ret = process_frames(in, buffer, frames_rq);
- } else if (in->resampler != NULL) {
- ret = read_frames(in, buffer, frames_rq);
+ } else if (in->resampler != NULL) {
+ ret = read_frames(in, buffer, frames_rq);
} else {
- ret = pcm_read(in->pcm, buffer, bytes);
+ ret = pcm_read(in->pcm, buffer, bytes);
}
- if (ret > 0)
- ret = 0;
+ /* If connect headset, set the first data to zero.
+ * There may be a noise pulse.
+ */
+ if (is_first_data &&
+ (adev->in_device & AUDIO_DEVICE_IN_WIRED_HEADSET)) {
+ memset(buffer, 0, bytes);
+ }
- if (ret == 0 && adev->mic_mute)
- memset(buffer, 0, bytes);
+ if (ret > 0)
+ ret = 0;
+
+ if (ret == 0 && adev->mic_mute)
+ memset(buffer, 0, bytes);
exit:
- if (ret < 0)
- usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
- in_get_sample_rate(&stream->common));
+ if (ret < 0)
+ usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+ in_get_sample_rate(&stream->common));
- pthread_mutex_unlock(&in->lock);
- return bytes;
+ pthread_mutex_unlock(&in->lock);
+ return bytes;
}
static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
{
- return 0;
+ return 0;
}
static int in_add_audio_effect(const struct audio_stream *stream,
- effect_handle_t effect)
+ effect_handle_t effect)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- int status;
- effect_descriptor_t desc;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ int status;
+ effect_descriptor_t desc;
- pthread_mutex_lock(&in->dev->lock);
- pthread_mutex_lock(&in->lock);
- if (in->num_preprocessors >= MAX_PREPROCESSORS) {
- status = -ENOSYS;
- goto exit;
- }
+ pthread_mutex_lock(&in->dev->lock);
+ pthread_mutex_lock(&in->lock);
+ if (in->num_preprocessors >= MAX_PREPROCESSORS) {
+ status = -ENOSYS;
+ goto exit;
+ }
- status = (*effect)->get_descriptor(effect, &desc);
- if (status != 0)
- goto exit;
+ status = (*effect)->get_descriptor(effect, &desc);
+ if (status != 0)
+ goto exit;
- in->preprocessors[in->num_preprocessors++] = effect;
+ in->preprocessors[in->num_preprocessors++] = effect;
- if (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) {
- in->need_echo_reference = true;
- do_input_standby(in);
- }
+ if (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) {
+ in->need_echo_reference = true;
+ do_input_standby(in);
+ }
exit:
- pthread_mutex_unlock(&in->lock);
- pthread_mutex_unlock(&in->dev->lock);
- return status;
+ pthread_mutex_unlock(&in->lock);
+ pthread_mutex_unlock(&in->dev->lock);
+ return status;
}
static int in_remove_audio_effect(const struct audio_stream *stream,
- effect_handle_t effect)
+ effect_handle_t effect)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- int i;
- int status = -EINVAL;
- bool found = false;
- effect_descriptor_t desc;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ int i;
+ int status = -EINVAL;
+ bool found = false;
+ effect_descriptor_t desc;
- pthread_mutex_lock(&in->dev->lock);
- pthread_mutex_lock(&in->lock);
- if (in->num_preprocessors <= 0) {
- status = -ENOSYS;
- goto exit;
- }
+ pthread_mutex_lock(&in->dev->lock);
+ pthread_mutex_lock(&in->lock);
+ if (in->num_preprocessors <= 0) {
+ status = -ENOSYS;
+ goto exit;
+ }
- for (i = 0; i < in->num_preprocessors; i++) {
- if (found) {
- in->preprocessors[i - 1] = in->preprocessors[i];
- continue;
- }
- if (in->preprocessors[i] == effect) {
- in->preprocessors[i] = NULL;
- status = 0;
- found = true;
- }
- }
+ for (i = 0; i < in->num_preprocessors; i++) {
+ if (found) {
+ in->preprocessors[i - 1] = in->preprocessors[i];
+ continue;
+ }
+ if (in->preprocessors[i] == effect) {
+ in->preprocessors[i] = NULL;
+ status = 0;
+ found = true;
+ }
+ }
- if (status != 0)
- goto exit;
+ if (status != 0)
+ goto exit;
- in->num_preprocessors--;
+ in->num_preprocessors--;
- status = (*effect)->get_descriptor(effect, &desc);
- if (status != 0)
- goto exit;
- if (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) {
- in->need_echo_reference = false;
- do_input_standby(in);
- }
+ status = (*effect)->get_descriptor(effect, &desc);
+ if (status != 0)
+ goto exit;
+ if (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) {
+ in->need_echo_reference = false;
+ do_input_standby(in);
+ }
exit:
- pthread_mutex_unlock(&in->lock);
- pthread_mutex_unlock(&in->dev->lock);
- return status;
+ pthread_mutex_unlock(&in->lock);
+ pthread_mutex_unlock(&in->dev->lock);
+ return status;
}
static int adev_open_output_stream(struct audio_hw_device *dev,
- audio_io_handle_t handle,
- audio_devices_t devices,
- audio_output_flags_t flags,
- struct audio_config *config,
- struct audio_stream_out **stream_out)
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ audio_output_flags_t flags,
+ struct audio_config *config,
+ struct audio_stream_out **stream_out)
{
struct sunxi_audio_device *ladev = (struct sunxi_audio_device *)dev;
- struct sunxi_stream_out *out;
- int ret;
+ struct sunxi_stream_out *out;
+ int ret;
+
-
ALOGV("adev_open_output_stream, flags: %x", flags);
- out = (struct sunxi_stream_out *)calloc(1, sizeof(struct sunxi_stream_out));
- if (!out)
- return -ENOMEM;
+ out = (struct sunxi_stream_out *)calloc(1, sizeof(struct sunxi_stream_out));
+ if (!out)
+ return -ENOMEM;
- out->buffer = malloc(RESAMPLER_BUFFER_SIZE); /* todo: allow for reallocing */
+ out->buffer = malloc(RESAMPLER_BUFFER_SIZE); /* todo: allow for reallocing */
- out->stream.common.get_sample_rate = out_get_sample_rate;
- out->stream.common.set_sample_rate = out_set_sample_rate;
- out->stream.common.get_buffer_size = out_get_buffer_size;
- out->stream.common.get_channels = out_get_channels;
- out->stream.common.get_format = out_get_format;
- out->stream.common.set_format = out_set_format;
- out->stream.common.standby = out_standby;
- out->stream.common.dump = out_dump;
- out->stream.common.set_parameters = out_set_parameters;
- out->stream.common.get_parameters = out_get_parameters;
- out->stream.common.add_audio_effect = out_add_audio_effect;
- out->stream.common.remove_audio_effect = out_remove_audio_effect;
- out->stream.get_latency = out_get_latency;
- out->stream.set_volume = out_set_volume;
- out->stream.write = out_write;
- out->stream.get_render_position = out_get_render_position;
+ out->stream.common.get_sample_rate = out_get_sample_rate;
+ out->stream.common.set_sample_rate = out_set_sample_rate;
+ out->stream.common.get_buffer_size = out_get_buffer_size;
+ out->stream.common.get_channels = out_get_channels;
+ out->stream.common.get_format = out_get_format;
+ out->stream.common.set_format = out_set_format;
+ out->stream.common.standby = out_standby;
+ out->stream.common.dump = out_dump;
+ out->stream.common.set_parameters = out_set_parameters;
+ out->stream.common.get_parameters = out_get_parameters;
+ out->stream.common.add_audio_effect = out_add_audio_effect;
+ out->stream.common.remove_audio_effect = out_remove_audio_effect;
+ out->stream.get_latency = out_get_latency;
+ out->stream.set_volume = out_set_volume;
+ out->stream.write = out_write;
+ out->stream.get_render_position = out_get_render_position;
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
out->stream.get_presentation_position = out_get_presentation_position;
- out->config = pcm_config_mm_out;
+ out->config = pcm_config_mm_out;
- out->dev = ladev;
- out->standby = 1;
+ out->dev = ladev;
+ out->standby = 1;
- /* FIXME: when we support multiple output devices, we will want to
- * do the following:
+ /* FIXME: when we support multiple output devices, we will want to
+ * do the following:
* adev->out_device = out->device;
- * select_output_device(adev);
- * This is because out_set_parameters() with a route is not
- * guaranteed to be called after an output stream is opened. */
+ * select_output_device(adev);
+ * This is because out_set_parameters() with a route is not
+ * guaranteed to be called after an output stream is opened. */
config->format = out_get_format(&out->stream.common);
- config->channel_mask = out_get_channels(&out->stream.common);
- config->sample_rate = out_get_sample_rate(&out->stream.common);
+ config->channel_mask = out_get_channels(&out->stream.common);
+ config->sample_rate = out_get_sample_rate(&out->stream.common);
ALOGV("+++++++++++++++ adev_open_output_stream: req_sample_rate: %d, fmt: %x, channel_count: %d",
- config->sample_rate, config->format, config->channel_mask);
+ config->sample_rate, config->format, config->channel_mask);
-#if VVS_USED
- vvs.lib_handle = NULL;
- vvs.lib_handle = dlopen("libAwHeadpSurround.so",RTLD_LAZY);
- if (vvs.lib_handle == NULL){
- ALOGV("can't open libAwHeadpSurround.so!");
- goto vvs_init_exit;
- }
+ *stream_out = &out->stream;
- vvs.process_init = dlsym(vvs.lib_handle,"process_init");
- vvs.surround_pro_in_out = dlsym(vvs.lib_handle,"surround_pro_in_out");
- vvs.process_exit = dlsym(vvs.lib_handle,"process_exit");
- vvs.set_bass = dlsym(vvs.lib_handle,"set_bass");
- vvs.set_defintion = dlsym(vvs.lib_handle,"set_defintion");
- vvs.set_space = dlsym(vvs.lib_handle,"set_space");
- vvs.vvs_handle = vvs.process_init(vvs.vvs_handle, config->sample_rate, 2, SHORT_PERIOD_SIZE);
- vvs.set_bass(vvs.vvs_handle, 0.33);
- vvs.set_defintion(vvs.vvs_handle, 0.80);
- vvs.set_space(vvs.vvs_handle, 0.50);
-
-vvs_init_exit:
-#endif
-
- *stream_out = &out->stream;
-
- return 0;
+ return 0;
err_open:
- free(out);
- *stream_out = NULL;
- return ret;
+ free(out);
+ *stream_out = NULL;
+ return ret;
}
static void adev_close_output_stream(struct audio_hw_device *dev,
- struct audio_stream_out *stream)
+ struct audio_stream_out *stream)
{
- struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
- struct sunxi_audio_device *adev = out->dev;
+ struct sunxi_stream_out *out = (struct sunxi_stream_out *)stream;
+ struct sunxi_audio_device *adev = out->dev;
- if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM)
- {
+ if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) {
ALOGW("mode in call, do not adev_close_output_stream");
return ;
}
- out_standby(&stream->common);
+ out_standby(&stream->common);
- if (out->buffer){
- free(out->buffer);
+ if (out->buffer) {
+ free(out->buffer);
out->buffer = 0;
}
- if (out->resampler){
- release_resampler(out->resampler);
+ if (out->resampler) {
+ release_resampler(out->resampler);
out->resampler = 0;
- }
- free(stream);
-
-#if VVS_USED
- if (vvs.vvs_handle != NULL)
- vvs.process_exit(vvs.vvs_handle);
- if (vvs.lib_handle != NULL)
- dlclose(vvs.lib_handle);
-#endif
-
+ }
+ free(stream);
}
static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
{
- struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
- struct str_parms *parms;
- char *str;
- char value[32];
- int ret;
+ struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
+ struct str_parms *parms;
+ char *str;
+ char value[32];
+ int ret;
ALOGV("adev_set_parameters, %s", kvpairs);
- parms = str_parms_create_str(kvpairs);
- ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
- if (ret >= 0) {
- int tty_mode;
+ parms = str_parms_create_str(kvpairs);
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
+ if (ret >= 0) {
+ int tty_mode;
- if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
- tty_mode = TTY_MODE_OFF;
- else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
- tty_mode = TTY_MODE_VCO;
- else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
- tty_mode = TTY_MODE_HCO;
- else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
- tty_mode = TTY_MODE_FULL;
- else
- return -EINVAL;
+ if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
+ tty_mode = TTY_MODE_OFF;
+ else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
+ tty_mode = TTY_MODE_VCO;
+ else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
+ tty_mode = TTY_MODE_HCO;
+ else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
+ tty_mode = TTY_MODE_FULL;
+ else
+ return -EINVAL;
- pthread_mutex_lock(&adev->lock);
- if (tty_mode != adev->tty_mode) {
- adev->tty_mode = tty_mode;
- if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) {
- select_device(adev);
- adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
+ pthread_mutex_lock(&adev->lock);
+ if (tty_mode != adev->tty_mode) {
+ adev->tty_mode = tty_mode;
+ if (adev->mode == AUDIO_MODE_IN_CALL || adev->mode == AUDIO_MODE_MODE_FACTORY_TEST || adev->mode == AUDIO_MODE_FM) {
+ select_device(adev);
+ adev_set_voice_volume(&adev->hw_device, adev->voice_volume);
}
- }
- pthread_mutex_unlock(&adev->lock);
- }
+ }
+ pthread_mutex_unlock(&adev->lock);
+ }
- ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
- if (ret >= 0) {
- if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
- adev->bluetooth_nrec = true;
- else
- adev->bluetooth_nrec = false;
- }
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
+ if (ret >= 0) {
+ if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0)
+ adev->bluetooth_nrec = true;
+ else
+ adev->bluetooth_nrec = false;
+ }
- str_parms_destroy(parms);
- return ret;
+ str_parms_destroy(parms);
+ return ret;
}
static char * adev_get_parameters(const struct audio_hw_device *dev,
- const char *keys)
+ const char *keys)
{
- if (!strcmp(keys, "routing"))
- {
- char prop_value[512];
- int ret = property_get("audio.routing", prop_value, "");
- if (ret > 0)
+ if (!strcmp(keys, "routing"))
{
- return strdup(prop_value);
+ char prop_value[512];
+ int ret = property_get("audio.routing", prop_value, "");
+ if (ret > 0) {
+ return strdup(prop_value);
+ }
}
- }
- return strdup("");
+ return strdup("");
}
static int adev_init_check(const struct audio_hw_device *dev)
{
- return 0;
+ return 0;
}
static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
{
- struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
+ struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
ALOGV("adev_set_voice_volume, volume: %f", volume);
@@ -2888,13 +2705,13 @@ static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
if (volume_codec >= 10) {
level = 5;
- } else if (volume_codec >= 8){
+ } else if (volume_codec >= 8) {
level = 4;
- } else if (volume_codec >= 6){
+ } else if (volume_codec >= 6) {
level = 3;
- } else if (volume_codec >= 4){
+ } else if (volume_codec >= 4) {
level = 2;
- } else if (volume_codec >= 2){
+ } else if (volume_codec >= 2) {
level = 1;
} else {
level = 0;
@@ -2902,34 +2719,28 @@ static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
ALOGD("adev_set_voice_volume, speaker_on: %d, earpiece_on: %d, headset_on: %d", speaker_on ,earpiece_on, headset_on);
ALOGD("adev_set_voice_volume, volume:%d, level: %d", volume_codec, level);
- #if 0
- int i=0;
- for(i=0;i<=5;i++){
- ALOGD("\nadev->vol_array->speaker_spk_gain[level]:%d\n",adev->vol_array->speaker_spk_gain[i]);
- ALOGD("\nadev->vol_array->earpiece_hp_gain[level]:%d\n",adev->vol_array->earpiece_hp_gain[i]);
- ALOGD("\nadev->vol_array->headset_hp_gain[level]:%d\n",adev->vol_array->headset_hp_gain[i]);
- }
- #endif
- if (speaker_on || (earpiece_on && (NO_EARPIECE == 1))){
+
+ if (speaker_on || (earpiece_on && (NO_EARPIECE == 1))) {
mixer_ctl_set_value(adev->mixer_volumectls.spkvolume, 0, adev->vol_array->speaker_spk_gain[level]);
ALOGD("adev_set_voice_volume, speaker volume:%d ", adev->vol_array->speaker_spk_gain[level]);
- } else if (earpiece_on && (NO_EARPIECE == 0) ){
+ } else if (earpiece_on && (NO_EARPIECE == 0) ) {
mixer_ctl_set_value(adev->mixer_volumectls.earpiecevolume, 0, adev->vol_array->earpiece_hp_gain[level]);
ALOGD("adev_set_voice_volume, earpiece volume:%d ", adev->vol_array->earpiece_hp_gain[level]);
- } else if (headset_on || headphone_on){
+ } else if (headset_on || headphone_on) {
mixer_ctl_set_value(adev->mixer_volumectls.hpvolume, 0, adev->vol_array->headset_hp_gain[level]);
ALOGD("adev_set_voice_volume, headset volume:%d ", adev->vol_array->headset_hp_gain[level]);
}
+
set_bp_volume(adev,(int)(volume*100/10));
ALOGV("set phone debug,adev_set_voice_volume, volume: %f, intege of volume: %d", volume, (int)(volume*100/10));
}
- return 0;
+ return 0;
}
static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
{
F_LOG;
- return -ENOSYS;
+ return -ENOSYS;
}
static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
@@ -2940,113 +2751,113 @@ static int adev_get_master_volume(struct audio_hw_device *dev, float *volume)
static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
{
- struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
+ struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
- pthread_mutex_lock(&adev->lock);
- if (adev->mode != mode) {
- adev->mode = mode;
- select_mode(adev);
- }
- pthread_mutex_unlock(&adev->lock);
+ pthread_mutex_lock(&adev->lock);
+ if (adev->mode != mode) {
+ adev->mode = mode;
+ select_mode(adev);
+ }
+ pthread_mutex_unlock(&adev->lock);
- return 0;
+ return 0;
}
static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
{
- struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
+ struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
- adev->mic_mute = state;
+ adev->mic_mute = state;
- return 0;
+ return 0;
}
static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
{
- struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
+ struct sunxi_audio_device *adev = (struct sunxi_audio_device *)dev;
- *state = adev->mic_mute;
+ *state = adev->mic_mute;
- return 0;
+ return 0;
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
- const struct audio_config *config)
+ const struct audio_config *config)
{
- size_t size;
- int channel_count = popcount(config->channel_mask);
- if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
- return 0;
+ size_t size;
+ int channel_count = popcount(config->channel_mask);
+ if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
+ return 0;
- return get_input_buffer_size(config->sample_rate, config->format, channel_count);
+ return get_input_buffer_size(config->sample_rate, config->format, channel_count);
}
static int adev_open_input_stream(struct audio_hw_device *dev,
- audio_io_handle_t handle,
- audio_devices_t devices,
- struct audio_config *config,
- struct audio_stream_in **stream_in)
+ audio_io_handle_t handle,
+ audio_devices_t devices,
+ struct audio_config *config,
+ struct audio_stream_in **stream_in)
{
- struct sunxi_audio_device *ladev = (struct sunxi_audio_device *)dev;
- struct sunxi_stream_in *in;
- int ret;
- int channel_count = popcount(config->channel_mask);
+ struct sunxi_audio_device *ladev = (struct sunxi_audio_device *)dev;
+ struct sunxi_stream_in *in;
+ int ret;
+ int channel_count = popcount(config->channel_mask);
- *stream_in = NULL;
+ *stream_in = NULL;
- if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
- return -EINVAL;
+ if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
+ return -EINVAL;
- in = (struct sunxi_stream_in *)calloc(1, sizeof(struct sunxi_stream_in));
- if (!in)
- return -ENOMEM;
+ in = (struct sunxi_stream_in *)calloc(1, sizeof(struct sunxi_stream_in));
+ if (!in)
+ return -ENOMEM;
- in->stream.common.get_sample_rate = in_get_sample_rate;
- in->stream.common.set_sample_rate = in_set_sample_rate;
- in->stream.common.get_buffer_size = in_get_buffer_size;
- in->stream.common.get_channels = in_get_channels;
- in->stream.common.get_format = in_get_format;
- in->stream.common.set_format = in_set_format;
- in->stream.common.standby = in_standby;
- in->stream.common.dump = in_dump;
- in->stream.common.set_parameters = in_set_parameters;
- in->stream.common.get_parameters = in_get_parameters;
- in->stream.common.add_audio_effect = in_add_audio_effect;
- in->stream.common.remove_audio_effect = in_remove_audio_effect;
- in->stream.set_gain = in_set_gain;
- in->stream.read = in_read;
- in->stream.get_input_frames_lost = in_get_input_frames_lost;
+ in->stream.common.get_sample_rate = in_get_sample_rate;
+ in->stream.common.set_sample_rate = in_set_sample_rate;
+ in->stream.common.get_buffer_size = in_get_buffer_size;
+ in->stream.common.get_channels = in_get_channels;
+ in->stream.common.get_format = in_get_format;
+ in->stream.common.set_format = in_set_format;
+ in->stream.common.standby = in_standby;
+ in->stream.common.dump = in_dump;
+ in->stream.common.set_parameters = in_set_parameters;
+ in->stream.common.get_parameters = in_get_parameters;
+ in->stream.common.add_audio_effect = in_add_audio_effect;
+ in->stream.common.remove_audio_effect = in_remove_audio_effect;
+ in->stream.set_gain = in_set_gain;
+ in->stream.read = in_read;
+ in->stream.get_input_frames_lost = in_get_input_frames_lost;
- in->requested_rate = config->sample_rate;
+ in->requested_rate = config->sample_rate;
- // default config
- memcpy(&in->config, &pcm_config_mm_in, sizeof(pcm_config_mm_in));
- in->config.channels = channel_count;
- //in->config.in_init_channels = channel_count;
+ // default config
+ memcpy(&in->config, &pcm_config_mm_in, sizeof(pcm_config_mm_in));
+ in->config.channels = channel_count;
+ //in->config.in_init_channels = channel_count;
- ALOGV("to malloc in-buffer: period_size: %d, frame_size: %d",
- in->config.period_size, audio_stream_frame_size(&in->stream.common));
- in->buffer = malloc(in->config.period_size *
- audio_stream_frame_size(&in->stream.common) * 8);
+ ALOGV("to malloc in-buffer: period_size: %d, frame_size: %d",
+ in->config.period_size, audio_stream_frame_size(&in->stream.common));
+ in->buffer = malloc(in->config.period_size *
+ audio_stream_frame_size(&in->stream.common) * 8);
- if (!in->buffer) {
- ret = -ENOMEM;
- goto err;
- }
- memset(in->buffer, 0, in->config.period_size *
- audio_stream_frame_size(&in->stream.common) * 8); //mute
+ if (!in->buffer) {
+ ret = -ENOMEM;
+ goto err;
+ }
+ memset(in->buffer, 0, in->config.period_size *
+ audio_stream_frame_size(&in->stream.common) * 8); //mute
- ladev->af_capture_flag = false;
- //devices = AUDIO_DEVICE_IN_WIFI_DISPLAY;//for test
+ ladev->af_capture_flag = false;
+ //devices = AUDIO_DEVICE_IN_WIFI_DISPLAY;//for test
- if (devices == AUDIO_DEVICE_IN_AF) {
+ if (devices == AUDIO_DEVICE_IN_AF) {
ALOGV("to malloc PcmManagerBuffer: Buffer_size: %d", AF_BUFFER_SIZE);
ladev->PcmManager.BufStart= (unsigned char *)malloc(AF_BUFFER_SIZE);
if(!ladev->PcmManager.BufStart) {
ret = -ENOMEM;
goto err;
- }
+ }
ladev->PcmManager.BufExist = true;
ladev->PcmManager.BufTotalLen = AF_BUFFER_SIZE;
@@ -3059,54 +2870,54 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
ladev->af_capture_flag = true;
ladev->PcmManager.dev = (struct sunxi_audio_device *)ladev;
- }
+ }
- in->dev = ladev;
- in->standby = 1;
- in->device = devices & ~AUDIO_DEVICE_BIT_IN;
+ in->dev = ladev;
+ in->standby = 1;
+ in->device = devices & ~AUDIO_DEVICE_BIT_IN;
- *stream_in = &in->stream;
- return 0;
+ *stream_in = &in->stream;
+ return 0;
err:
- if (in->resampler)
- release_resampler(in->resampler);
+ if (in->resampler)
+ release_resampler(in->resampler);
- free(in);
- return ret;
+ free(in);
+ return ret;
}
static void adev_close_input_stream(struct audio_hw_device *dev,
- struct audio_stream_in *stream)
+ struct audio_stream_in *stream)
{
- struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
- struct sunxi_audio_device *ladev = (struct sunxi_audio_device *)dev;
+ struct sunxi_stream_in *in = (struct sunxi_stream_in *)stream;
+ struct sunxi_audio_device *ladev = (struct sunxi_audio_device *)dev;
- in_standby(&stream->common);
+ in_standby(&stream->common);
- if (in->buffer) {
- free(in->buffer);
- in->buffer = 0;
- }
- if (in->resampler) {
- release_resampler(in->resampler);
- in->resampler = 0;
- }
- if (ladev->af_capture_flag) {
- ladev->af_capture_flag = false;
- }
- if (ladev->PcmManager.BufStart) {
- ladev->PcmManager.BufExist = false;
- free(ladev->PcmManager.BufStart);
- ladev->PcmManager.BufStart = 0;
- }
- free(stream);
+ if (in->buffer) {
+ free(in->buffer);
+ in->buffer = 0;
+ }
+ if (in->resampler) {
+ release_resampler(in->resampler);
+ in->resampler = 0;
+ }
+ if (ladev->af_capture_flag) {
+ ladev->af_capture_flag = false;
+ }
+ if (ladev->PcmManager.BufStart) {
+ ladev->PcmManager.BufExist = false;
+ free(ladev->PcmManager.BufStart);
+ ladev->PcmManager.BufStart = 0;
+ }
+ free(stream);
- normal_record_enable(false);
- fm_record_enable(false);
- phone_record_enable(false);
- ALOGD("adev_close_input_stream set voice record status");
- return;
+ normal_record_enable(false);
+ fm_record_enable(false);
+ phone_record_enable(false);
+ ALOGD("adev_close_input_stream set voice record status");
+ return;
}
static int adev_dump(const audio_hw_device_t *device, int fd)
@@ -3117,6 +2928,11 @@ static int adev_dump(const audio_hw_device_t *device, int fd)
static int adev_close(hw_device_t *device)
{
struct sunxi_audio_device *adev = (struct sunxi_audio_device *)device;
+
+#if USE_3D_SURROUND
+ surround_exit(&sur);
+#endif
+
audio_route_free(adev->ar);
free(adev->vol_array);
free(device);
@@ -3131,10 +2947,8 @@ static int case_init(void)
char usename[PROPERTY_VALUE_MAX]={0};
ret = property_get("audio.without.earpiece", prop_value, "1");
- if (ret > 0)
- {
- if (atoi(prop_value) == 0)
- {
+ if (ret > 0) {
+ if (atoi(prop_value) == 0) {
NO_EARPIECE = 0;
ALOGD("get property audio.without.earpiece: %d", NO_EARPIECE);
}
@@ -3143,53 +2957,56 @@ static int case_init(void)
ALOGV("****LINE:%d,FUNC:%s, ret:%d",__LINE__,__FUNCTION__, ret);
ret = property_get("ro.dmic.used", usename, "0");
- if(ret <= 0){
+ if (ret <= 0) {
ALOGE("wrn: get ro.dmic.used failed");
}
- if(!strcmp(usename, "true")) {
+ if (!strcmp(usename, "true")) {
dmic_used = true;
- }else{
+ } else {
dmic_used = false;
}
+
ret = property_get("ro.spk_dul.used", usename, "0");
- if(ret <= 0){
+ if (ret <= 0) {
ALOGE("wrn: get ro.dmic.used failed");
}
- if(!strcmp(usename, "true")) {
+ if (!strcmp(usename, "true")) {
spk_dul_used = true;
- }else{
+ } else {
spk_dul_used = false;
}
+
ret = property_get("ro.sw.audio.codec_plan_name", device_name, "0");
- if(ret <= 0){
+ if (ret <= 0) {
ALOGE("wrn: get ro.sw.audio.codec_plan_name failed");
}
ALOGD("PROPERTY_VALUE_MAX:%d,get ro.sw.audio.codec_plan_name =%s", PROPERTY_VALUE_MAX, device_name);
- if (strstr(device_name, "PLAN_ONE") != NULL){
+ if (strstr(device_name, "PLAN_ONE") != NULL) {
/*case:plan_one*/
CASE_NAME = 1;
- }else if (strstr(device_name, "PLAN_TWO") != NULL){
+ } else if (strstr(device_name, "PLAN_TWO") != NULL) {
/*case:plan_two*/
CASE_NAME = 2;
- } else {
- /*case:pad*/
+ } else {
+ /*case:pad*/
CASE_NAME = 0;
}
return ret;
}
+
static int adev_open(const hw_module_t* module, const char* name,
- hw_device_t** device)
+ hw_device_t** device)
{
struct sunxi_audio_device *adev;
int ret;
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
- return -EINVAL;
+ return -EINVAL;
adev = calloc(1, sizeof(struct sunxi_audio_device));
if (!adev)
- return -ENOMEM;
+ return -ENOMEM;
adev->hw_device.common.tag = HARDWARE_DEVICE_TAG;
adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
adev->hw_device.common.module = (struct hw_module_t *) module;
@@ -3197,8 +3014,8 @@ static int adev_open(const hw_module_t* module, const char* name,
adev->hw_device.init_check = adev_init_check;
adev->hw_device.set_voice_volume = adev_set_voice_volume;
-// adev->hw_device.set_master_volume = adev_set_master_volume;
-// adev->hw_device.get_master_volume = adev_get_master_volume;
+ // adev->hw_device.set_master_volume = adev_set_master_volume;
+ // adev->hw_device.get_master_volume = adev_get_master_volume;
adev->hw_device.set_mode = adev_set_mode;
adev->hw_device.set_mic_mute = adev_set_mic_mute;
adev->hw_device.get_mic_mute = adev_get_mic_mute;
@@ -3233,11 +3050,11 @@ static int adev_open(const hw_module_t* module, const char* name,
}
/*volume ctl*/
adev->mixer_volumectls.hpvolume = mixer_get_ctl_by_name(adev->mixer,
- MIXER_HP_VOLUME);
+ MIXER_HP_VOLUME);
adev->mixer_volumectls.spkvolume = mixer_get_ctl_by_name(adev->mixer,
- MIXER_SPK_VOLUME);
+ MIXER_SPK_VOLUME);
adev->mixer_volumectls.earpiecevolume = mixer_get_ctl_by_name(adev->mixer,
- MIXER_EARPIECE_VOLUME);
+ MIXER_EARPIECE_VOLUME);
pthread_mutex_unlock(&adev->lock);
*device = &adev->hw_device.common;
adev->vol_array = calloc(1, sizeof(struct volume_array));
@@ -3248,6 +3065,10 @@ static int adev_open(const hw_module_t* module, const char* name,
}
case_init();
+#if USE_3D_SURROUND
+ surround_init(&sur, MM_SAMPLING_RATE, 2, SHORT_PERIOD_SIZE);
+#endif
+
return 0;
error_out:
@@ -3256,17 +3077,17 @@ error_out:
}
static struct hw_module_methods_t hal_module_methods = {
- .open = adev_open,
+ .open = adev_open,
};
struct audio_module HAL_MODULE_INFO_SYM = {
- .common = {
- .tag = HARDWARE_MODULE_TAG,
- .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = AUDIO_MODULE_API_VERSION_0_1,
.hal_api_version = HARDWARE_HAL_API_VERSION,
- .id = AUDIO_HARDWARE_MODULE_ID,
- .name = "sunxi audio HW HAL",
- .author = "author",
- .methods = &hal_module_methods,
- },
+ .id = AUDIO_HARDWARE_MODULE_ID,
+ .name = "sunxi audio HW HAL",
+ .author = "author",
+ .methods = &hal_module_methods,
+ },
};
diff --git a/audio/tulip/audio_policy.conf b/audio/tulip/audio_policy.conf
index c1ce9e7..f20d248 100755
--- a/audio/tulip/audio_policy.conf
+++ b/audio/tulip/audio_policy.conf
@@ -39,8 +39,8 @@ audio_hw_modules {
}
inputs {
primary {
- sampling_rates 8000|11025|16000|22050|24000|32000|44100|48000
- channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO|AUDIO_CHANNEL_IN_VOICE_UPLINK|AUDIO_CHANNEL_IN_VOICE_DNLINK|AUDIO_CHANNEL_IN_VOICE
+ sampling_rates 44100
+ channel_masks AUDIO_CHANNEL_IN_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET|AUDIO_DEVICE_IN_WIRED_HEADSET|AUDIO_DEVICE_IN_BACK_MIC|AUDIO_DEVICE_IN_AF|AUDIO_DEVICE_IN_VOICE_CALL|AUDIO_DEVICE_IN_FM
}
@@ -75,7 +75,7 @@ audio_hw_modules {
usb_device {
sampling_rates dynamic
channel_masks AUDIO_CHANNEL_IN_STEREO
- formats AUDIO_FORMAT_PCM_16_BIT
+ formats AUDIO_FORMAT_PCM_24_BIT_PACKED
devices AUDIO_DEVICE_IN_USB_DEVICE
}
}
diff --git a/audio/tulip/libcodec_audio/volume_conf.c b/audio/tulip/libcodec_audio/volume_conf.c
index f548747..94139a4 100755
--- a/audio/tulip/libcodec_audio/volume_conf.c
+++ b/audio/tulip/libcodec_audio/volume_conf.c
@@ -1,6 +1,7 @@
#include
#include
#include
+#include
#define LOG_TAG "codec_audio"
#define LOG_NDEBUG 0
diff --git a/client-api/Android.mk b/client-api/Android.mk
index 1f07ecf..44fd01b 100755
--- a/client-api/Android.mk
+++ b/client-api/Android.mk
@@ -1,6 +1,8 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
+ifeq ($(SECURE_OS_OPTEE), no)
+
LOCAL_SRC_FILES:= \
sunxi_tee_api.c
@@ -29,3 +31,5 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:= test_api
#include $(BUILD_EXECUTABLE)
+
+endif
diff --git a/client-api/sunxi_tee_api.c b/client-api/sunxi_tee_api.c
index d38dbf0..2520628 100755
--- a/client-api/sunxi_tee_api.c
+++ b/client-api/sunxi_tee_api.c
@@ -48,6 +48,7 @@ TEEC_Result TEEC_InitializeContext(const char* name, TEEC_Context* context) {
context->fd = ret;
context->session_count = 0;
context->shared_mem_cnt = 0;
+ context->nSessionNum = 0;
INIT_LIST_HEAD(&context->shared_mem_list);
}
return TEEC_SUCCESS;
@@ -325,7 +326,7 @@ TEEC_Result TEEC_InvokeCommand(
(param_types[param_count] == TEEC_MEMREF_PARTIAL_INPUT) ||
(param_types[param_count] == TEEC_MEMREF_PARTIAL_INOUT) ||
(param_types[param_count] == TEEC_MEMREF_PARTIAL_OUTPUT)) {
-
+ //* check the info
if(!operation->params[param_count].memref.parent) {
if(returnOrigin){
*returnOrigin = TEEC_ORIGIN_API;
@@ -393,41 +394,44 @@ TEEC_Result TEEC_InvokeCommand(
break;
}
}
+ //* assign sunxi_tee_param from operation->param
if (param_types[param_count] == TEEC_MEMREF_PARTIAL_INPUT) {
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RO;
- sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer +
+ sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer +
(uint32_t)operation->params[param_count].memref.offset);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
- sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
+ sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}else if((param_types[param_count] == TEEC_MEMREF_PARTIAL_OUTPUT) ||
(param_types[param_count] == TEEC_MEMREF_PARTIAL_INOUT)){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RW;
- sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer +
+ sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer +
(uint32_t)operation->params[param_count].memref.offset);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
- sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
+ sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}else if((param_types[param_count] == TEEC_MEMREF_WHOLE)){
if(operation->params[param_count].memref.parent->flags == TEEC_MEM_INPUT){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RO;
- sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer);
+ sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
- sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
+ sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}
if((operation->params[param_count].memref.parent->flags == TEEC_MEM_OUTPUT) ||
(operation->params[param_count].memref.parent->flags == (TEEC_MEM_INPUT|TEEC_MEM_OUTPUT ))){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_MEM_RW;
- sunxi_tee_param[param_count].u.Mem.base = (void*) ((uint32_t)operation->params[param_count].memref.parent->buffer);
+ sunxi_tee_param[param_count].u.Mem.base = (void*) ((uintptr_t)operation->params[param_count].memref.parent->buffer);
sunxi_tee_param[param_count].u.Mem.len = operation->params[param_count].memref.parent->size;
- sunxi_tee_param[param_count].index = (uint32_t)operation->params[param_count].memref.parent->buffer;
+ sunxi_tee_param[param_count].index = (uintptr_t)operation->params[param_count].memref.parent->buffer;
}
}
}else if(param_types[param_count] == TEEC_NONE){
sunxi_tee_param[param_count].type = TE_PARAM_TYPE_NONE;
}
}
+
+ //* set sunxi_tee_param to cmd
for (param_count = 0; param_count < 4; param_count++) {
if (cmd->launchop.operation.list_count == 0) {
cmd->launchop.operation.list_head = sunxi_tee_param + param_count;
diff --git a/client-api/sunxi_tee_api.h b/client-api/sunxi_tee_api.h
index 6965a0b..d4f5c2a 100755
--- a/client-api/sunxi_tee_api.h
+++ b/client-api/sunxi_tee_api.h
@@ -237,6 +237,8 @@ struct TEEC_Context
struct list shared_mem_list;
/*! Error number from the client driver */
int s_errno;
+
+ int nSessionNum;
};
diff --git a/hwc/octopus/hwc.cpp b/hwc/octopus/hwc.cpp
index d426f79..fb41dcf 100755
--- a/hwc/octopus/hwc.cpp
+++ b/hwc/octopus/hwc.cpp
@@ -54,6 +54,11 @@ static int hwc_blank(struct hwc_composer_device_1* dev, int disp, int blank)
HWC_UNREFERENCED_PARAMETER(blank);
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
+ if(!blank)
+ {
+ Globctx->unblank_flag = 1;
+ return 0;
+ }
unsigned long arg[4]={0};
DisplayInfo *PsDisplayInfo = &Globctx->SunxiDisplay[disp];
if(PsDisplayInfo->VirtualToHWDisplay != -EINVAL)
diff --git a/hwc/octopus/hwc.h b/hwc/octopus/hwc.h
index 14d921b..16b0a27 100755
--- a/hwc/octopus/hwc.h
+++ b/hwc/octopus/hwc.h
@@ -174,6 +174,7 @@ typedef struct {
int share_fd;//ion_handle share_fd
int size_buffer;
bool valid;
+ bool is_secure;
}hwc_cache_t;
typedef struct {
@@ -191,6 +192,7 @@ typedef struct {
int share_fd;
bool needsync;//for sw_write
bool iscursor;
+ bool is_secure;
disp_layer_config hwc_layer_info;
}hwc_commit_layer_t;
@@ -255,6 +257,7 @@ typedef struct layer_info {
bool is3D;
bool is_cursor;
bool need_sync;
+ bool is_secure;
int shared_fd;
AssignDUETO_T info;
hwc_layer_1_t *psLayer;
@@ -407,7 +410,7 @@ typedef struct
mutable android::Condition CommitCondition;
hwc_commit_layer_t cursor_rotate_layer[VIDEO_ROTATE_COUNT];// 0 is 90, 1 is 180,2 is 270;
-
+ int unblank_flag;
}SUNXI_hwcdev_context_t;
typedef struct
diff --git a/hwc/octopus/hwc_commit.cpp b/hwc/octopus/hwc_commit.cpp
index 2b3f1b2..f445364 100755
--- a/hwc/octopus/hwc_commit.cpp
+++ b/hwc/octopus/hwc_commit.cpp
@@ -333,6 +333,7 @@ void *commit_thread(void *priv)
hwc_dispc_data_t *DisplayData = NULL;
int i = 0, j = 0, ret = -1, lyr = 0, rotatecall = 0;
int primary_disp = 0, video_fence_fd = -1, share_fd = -1;
+ int unblank_count = 0;
unsigned long arg[4] = {0};
unsigned int current_sync_count = 0, cusor_sync = 0;
hwc_ioctl_arg hwc_cmd;
@@ -498,6 +499,28 @@ deal_fence:
arg[0] = 0;
arg[1] = (unsigned long)(&hwc_cmd);
ret = ioctl(Globctx->DisplayFd, DISP_HWC_COMMIT, (unsigned long)arg);
+
+ if(Globctx->unblank_flag)
+ {
+ if(unblank_count == 3)
+ {
+ unsigned long arg[4]={0};
+ DisplayInfo *PsDisplayInfo = &Globctx->SunxiDisplay[DisplayData->first_disp];
+
+ if(PsDisplayInfo->VirtualToHWDisplay != -EINVAL)
+ {
+ arg[0] = PsDisplayInfo->VirtualToHWDisplay;
+ arg[1] = 0;
+ if(ioctl(Globctx->DisplayFd, DISP_BLANK, (unsigned long)arg) != 0)
+ ALOGE("##########unblank error!");
+ }
+
+ Globctx->unblank_flag = 0;
+ unblank_count = 0;
+ }
+
+ unblank_count++;
+ }
/* check wb and display to HDMI or miracast */
/* update cursor disp data */
diff --git a/hwc/octopus/hwc_rotate.cpp b/hwc/octopus/hwc_rotate.cpp
index 694748c..03099bb 100755
--- a/hwc/octopus/hwc_rotate.cpp
+++ b/hwc/octopus/hwc_rotate.cpp
@@ -98,7 +98,7 @@ int culate_timeout(disp_rectsz disp_src)
return 32;
}
-static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_count)
+static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_count, bool is_secure)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
hwc_cache_t *wb_cache = NULL;
@@ -130,7 +130,7 @@ static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_coun
close(wb_cache->fd);
wb_cache->fd = -1;
}
- if(wb_cache->share_fd >= 0 && size < wb_cache->size_buffer)
+ if(wb_cache->share_fd >= 0 && size < wb_cache->size_buffer && wb_cache->is_secure == is_secure)
{
if(wb_cache->size_buffer - size > 4096)
{
@@ -148,23 +148,38 @@ static hwc_cache_t *hwc_video_cache_get(int size, int fd, unsigned int sync_coun
}
if(wb_cache->share_fd == -1 || wb_cache->size_buffer == 0)
{
- ret = ion_alloc_fd(Globctx->IonFd, size,
- 4096, ION_HEAP_TYPE_DMA_MASK, 0, &wb_cache->share_fd);
- if(ret < 0)
+ if(is_secure)
{
- ALOGD("alloc err from ION_HEAP_CARVEOUT_MASK");
- ret = ion_alloc_fd(Globctx->IonFd, size,
- 4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &wb_cache->share_fd);
+ ret = ion_alloc_fd(Globctx->IonFd, size,
+ 4096, ION_HEAP_SECURE_MASK, 0, &wb_cache->share_fd);
if(ret < 0)
{
- ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
- wb_cache->share_fd = -1;
- wb_cache->size_buffer = 0;
- return NULL;
+ ALOGD("alloc err from ION_HEAP_SECURE_MASK");
+ return NULL;
+ }
+ wb_cache->is_secure = 1;
+ }else{
+ ret = ion_alloc_fd(Globctx->IonFd, size,
+ 4096, ION_HEAP_TYPE_DMA_MASK, 0, &wb_cache->share_fd);
+ if(ret < 0)
+ {
+ ALOGD("alloc err from ION_HEAP_CARVEOUT_MASK");
+ ret = ion_alloc_fd(Globctx->IonFd, size,
+ 4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &wb_cache->share_fd);
+ if(ret < 0)
+ {
+ ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
+ wb_cache->share_fd = -1;
+ wb_cache->size_buffer = 0;
+ return NULL;
+ }
}
}
- ion_sync_fd(Globctx->IonFd, wb_cache->share_fd);
- wb_cache->size_buffer = size;
+ if(!is_secure)
+ {
+ ion_sync_fd(Globctx->IonFd, wb_cache->share_fd);
+ }
+ wb_cache->size_buffer = size;
}
wb_cache->sync_cnt = sync_count;
wb_cache->valid = 0;
@@ -520,7 +535,7 @@ bool hwc_rotate_layer_video(hwc_dispc_data_t *hwc_layer,
hwc_rotate_settimeout(ret);
Globctx->tr_time_out = ret;
}
- wb_cache = hwc_video_cache_get(size, commit_data->releasefencefd[disp], hwc_layer->sync_count);
+ wb_cache = hwc_video_cache_get(size, commit_data->releasefencefd[disp], hwc_layer->sync_count, commit_layer->is_secure);
if(wb_cache != NULL)
{
memset(&tr_info, 0, sizeof(tr_info));
diff --git a/hwc/octopus/hwc_sunxi.cpp b/hwc/octopus/hwc_sunxi.cpp
index 9076d15..b1379cc 100755
--- a/hwc/octopus/hwc_sunxi.cpp
+++ b/hwc/octopus/hwc_sunxi.cpp
@@ -443,8 +443,8 @@ static inline int check_valid_format(int format)
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
- case HAL_PIXEL_FORMAT_sRGB_A_8888:
- case HAL_PIXEL_FORMAT_sRGB_X_8888:
+ // case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ // case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_YV12:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_BGRX_8888:
@@ -520,8 +520,8 @@ static inline bool check_support_blending(int format)
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
- case HAL_PIXEL_FORMAT_sRGB_A_8888:
- case HAL_PIXEL_FORMAT_sRGB_X_8888:
+ // case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ // case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_BGRX_8888:
return 1;
default:
@@ -764,7 +764,7 @@ static int hwc_can_scale(HwcDisContext_t *Localctx, hwc_layer_1_t *psLayer, bool
{
vsyncPeroid /= 2;
}
- de_freq = 504000000;
+ de_freq = 254000000;
lcd_line_peroid = vsyncPeroid / lcd_h;
layer_line_peroid = (src_w > dst_w)
? (1000000*((long long)(lcd_w - dst_w + src_w))/(de_freq/1000))
@@ -1395,7 +1395,7 @@ ret_ok:
HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout, int zOrder)
{
- bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0;
+ bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0, issecure = 0;
bool is3D = 0, need_sync = 0, is_cursor = 0;
float WscalFac = 1.0, HscaleFac = 1.0;
int CH= -1, tmCnt1 = 0, tmCnt2 = 0, addLayerCnt = 1;
@@ -1444,13 +1444,18 @@ HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout,
goto assign_gpu;
}
- if(check_usage_protected(handle) && !PsDisplayInfo->issecure)
+ if(check_usage_protected(handle))
{
- ALOGV("%s:Video Protected", __func__);
- dueto = D_VIDEO_PD;
- goto assign_gpu;
+ if(!PsDisplayInfo->issecure)
+ {
+ ALOGV("%s:Video Protected", __func__);
+ dueto = D_VIDEO_PD;
+ goto assign_gpu;
+ }else{
+ issecure = 1;
+ }
}
-
+
dueto = check_valid_layer(psLayer, is_cursor);
if(dueto != I_OVERLAY)
{
@@ -1643,8 +1648,9 @@ assign_overlay:
Localctx->psAllLayer[singcout].is3D = is3D;
Localctx->psAllLayer[singcout].info = dueto;
Localctx->psAllLayer[singcout].isvideo= isvideo;
- Localctx->psAllLayer[singcout].need_sync = need_sync;
- Localctx->psAllLayer[singcout].is_cursor= is_cursor;
+ Localctx->psAllLayer[singcout].need_sync = issecure?0:need_sync;
+ Localctx->psAllLayer[singcout].is_cursor = is_cursor;
+ Localctx->psAllLayer[singcout].is_secure = issecure;
if(is_cursor)
{
return ASSIGN_CURSOR;
@@ -1734,6 +1740,7 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
}
hw_layer_config->needsync = psHwlayer_info->need_sync;
hw_layer_config->share_fd = dup(psHwlayer_info->shared_fd);
+ hw_layer_config->is_secure = psHwlayer_info->is_secure;
if(check_is_blending(psLayer))
{
layer_info->alpha_mode = 2;
@@ -2054,6 +2061,9 @@ deal_fence:
&& PsDisplayInfo->VirtualToHWDisplay >= 0)
{
releasefecefd = returnfenceFd[ture_disp];
+ }else{
+ ALOGW("has plugout the disp[%d]",disp);
+ continue;
}
for(i = 0; i < psDisplay->numHwLayers; i++)
{
@@ -2378,7 +2388,7 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
ALOGD("###open /sys/class/disp/disp/attr/runtime_enable fail");
}
- open_fd = open("/sys/devices/platform/sunxi-ddrfreq/devfreq/sunxi-ddrfreq/max_freq", O_RDONLY);
+ open_fd = open("/sys/class/devfreq/sunxi-ddrfreq/max_freq", O_RDONLY);
if(open_fd >= 0)
{
char val_ddr[10] = {0x0,};
@@ -2427,6 +2437,7 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
Globctx->uiBeginFrame = 0;
Globctx->hwcdebug = 0;
Globctx->stop_rotate_hw = 0;
+ Globctx->unblank_flag = 0;
Globctx->ManageLock = PTHREAD_MUTEX_INITIALIZER;
Globctx->AbandonLock = PTHREAD_MUTEX_INITIALIZER;
Globctx->HeadLock = PTHREAD_MUTEX_INITIALIZER;
diff --git a/hwc/tulip/hwc.h b/hwc/tulip/hwc.h
index c6de427..d4cd127 100755
--- a/hwc/tulip/hwc.h
+++ b/hwc/tulip/hwc.h
@@ -185,6 +185,7 @@ typedef struct {
int share_fd;//ion_handle share_fd
int size_buffer;
bool valid;
+ bool is_secure;
}hwc_cache_t;
typedef struct {
@@ -207,6 +208,7 @@ typedef struct {
int share_fd;
bool needsync;//for sw_write
bool iscursor;
+ bool is_secure;
disp_layer_config hwc_layer_info;
}hwc_commit_layer_t;
@@ -286,6 +288,7 @@ typedef struct layer_info {
bool is3D;
bool is_cursor;
bool need_sync;
+ bool is_secure;
int shared_fd;
format_info form_info;
AssignDUETO_T info;
@@ -312,7 +315,6 @@ typedef struct{
bool VsyncEnable;
bool issecure;
bool active;
- bool setblank;
int HwChannelNum;
int LayerNumofCH;
@@ -460,6 +462,7 @@ typedef struct
int fb_pre_mem;
/* end mem limit */
int unblank_flag;
+ unsigned char has_secure;
}SUNXI_hwcdev_context_t;
@@ -603,8 +606,8 @@ static inline int check_valid_format(int format)
//case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
- case HAL_PIXEL_FORMAT_sRGB_A_8888:
- case HAL_PIXEL_FORMAT_sRGB_X_8888:
+ //case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ //case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_YV12:
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
case HAL_PIXEL_FORMAT_BGRX_8888:
@@ -690,8 +693,8 @@ static inline bool check_support_blending(int format)
case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888:
- case HAL_PIXEL_FORMAT_sRGB_A_8888:
- case HAL_PIXEL_FORMAT_sRGB_X_8888:
+ //case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ //case HAL_PIXEL_FORMAT_sRGB_X_8888:
case HAL_PIXEL_FORMAT_BGRX_8888:
return 1;
default:
diff --git a/hwc/tulip/hwc_ion.cpp b/hwc/tulip/hwc_ion.cpp
index a8b0085..04bd0c5 100755
--- a/hwc/tulip/hwc_ion.cpp
+++ b/hwc/tulip/hwc_ion.cpp
@@ -17,6 +17,13 @@
#include "hwc.h"
+typedef struct {
+ ion_user_handle_t handle;
+ unsigned int phys_addr;
+ unsigned int size;
+}sunxi_phys_data;
+#define ION_IOC_SUNXI_PHYS_ADDR 7
+
ion_user_handle_t ion_alloc_buffer(int iAllocBytes, unsigned int heap_mask)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
@@ -36,7 +43,7 @@ ion_user_handle_t ion_alloc_buffer(int iAllocBytes, unsigned int heap_mask)
ALOGW("%s: ION_IOC_ALLOC failed (ret=%d)", __func__, ret);
return (ion_user_handle_t) -1;
}
-
+
return sAllocInfo.handle;
}
@@ -64,7 +71,7 @@ unsigned int ion_get_addr_fromfd(int sharefd)
sunxi_phys_data phys_data;
ion_handle_data freedata;
struct ion_fd_data data ;
-
+
data.fd = sharefd;
ret = ioctl(Globctx->IonFd, ION_IOC_IMPORT, &data);
if (ret < 0)
@@ -88,7 +95,7 @@ unsigned int ion_get_addr_fromfd(int sharefd)
ALOGE("%s: ION_IOC_FREE failed(ret=%d)", __func__, ret);
return 0;
}
- return phys_data.phys_addr;
+ return phys_data.phys_addr;
}
unsigned long ion_get_addr_from_handle(ion_user_handle_t handle)
@@ -122,7 +129,7 @@ ion_user_handle_t ion_handle_add_ref(int sharefd)
ALOGE("%s: ION_IOC_IMPORT failed(ret=%d)", __func__, ret);
return -1;
}
- return data.handle;
+ return data.handle;
}
void ion_handle_dec_ref(ion_user_handle_t handle_id)
@@ -180,7 +187,7 @@ void ion_free_cache(hwc_ion_hold_t *ion_cache)
bool hwc_manage_ref_cache(bool cache, hwc_dispc_data_t *dispc_data)
{
hwc_ion_hold_t *ion_cache = NULL;
- int i, little_sync, cnt = 0, size = 0;
+ int i, little_sync, cnt = 0, size = 0;
hwc_commit_layer_t *commit_layer = NULL;
int *_array = NULL;
@@ -237,8 +244,7 @@ bool hwc_manage_ref_cache(bool cache, hwc_dispc_data_t *dispc_data)
}
ion_cache->num_used = size;
ion_cache->sync_count = dispc_data->sync_count;
-
+
manage_ok:
return 1;
}
-
diff --git a/hwc/tulip/hwc_mem_ctrl.cpp b/hwc/tulip/hwc_mem_ctrl.cpp
index 16e20b9..67c79ff 100755
--- a/hwc/tulip/hwc_mem_ctrl.cpp
+++ b/hwc/tulip/hwc_mem_ctrl.cpp
@@ -144,6 +144,11 @@ void hwc_down_limit(SUNXI_hwcdev_context_t *Globctx, int local_mem[NUMBEROFDISPL
{
HWC_UNREFERENCED_PARAMETER(local_mem);
int i = 0, tmp_mem_thruput0 = 0;
+ if(Globctx->has_secure != 0)
+ {
+ Globctx->memlimit = Globctx->max_mem_limit;
+ return;
+ }
if(Globctx->ForceGPUComp[0] == 0 && Globctx->CanForceGPUCom && force_gpu)
{
if(Globctx->psHwcProcs != NULL
diff --git a/hwc/tulip/hwc_others.cpp b/hwc/tulip/hwc_others.cpp
index 6f0a792..7c7b178 100755
--- a/hwc/tulip/hwc_others.cpp
+++ b/hwc/tulip/hwc_others.cpp
@@ -129,8 +129,6 @@ int _hwc_device_set_enhancemode(int disp, bool on_off, bool half)
int _hwc_device_set_output_mode(int disp, int out_type, int out_mode)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
- if(Globctx->SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI)
- disp = 0;
DisplayInfo *PsDisplayInfo = &Globctx->SunxiDisplay[disp];
int disp_t;
@@ -149,8 +147,6 @@ int _hwc_set_persent(int disp,int para0, int para1)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
DisplayInfo *PsDisplayInfo = NULL;
- if(Globctx->SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI)
- disp = 0;
PsDisplayInfo = &Globctx->SunxiDisplay[disp];
if(PsDisplayInfo->VirtualToHWDisplay != -1 && PsDisplayInfo->DisplayType == DISP_OUTPUT_TYPE_HDMI)
diff --git a/hwc/tulip/hwc_rotate.cpp b/hwc/tulip/hwc_rotate.cpp
index 5d341ae..169edc3 100755
--- a/hwc/tulip/hwc_rotate.cpp
+++ b/hwc/tulip/hwc_rotate.cpp
@@ -15,6 +15,9 @@
*/
#include "hwc.h"
+#define ION_HEAP_TYPE_SECURE (ION_HEAP_TYPE_CUSTOM+1)
+#define ION_HEAP_SECURE_MASK (1 << ION_HEAP_TYPE_SECURE)
+
int hwc_rotate_query(unsigned long tr_handle)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
@@ -129,7 +132,7 @@ static rotate_cache_t *hwc_ratate_cache_manage(SUNXI_hwcdev_context_t *Globctx,
return ratate_cache;
}
-static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int fd, unsigned int sync_count)
+static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int fd, unsigned int sync_count, bool is_secure)
{
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
hwc_cache_t *tr_cache = NULL;
@@ -163,7 +166,7 @@ static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int
close(tr_cache->fd);
tr_cache->fd = -1;
}
- if(tr_cache->share_fd >= 0 && size <= tr_cache->size_buffer)
+ if(tr_cache->share_fd >= 0 && size <= tr_cache->size_buffer && tr_cache->is_secure == is_secure)
{
if(tr_cache->size_buffer - size > 4096)
{
@@ -181,22 +184,35 @@ static hwc_cache_t *hwc_tr_cache_get(rotate_cache_t *rotate_cache, int size, int
}
if(tr_cache->share_fd == -1 || tr_cache->size_buffer == 0)
{
- ret = ion_alloc_fd(Globctx->IonFd, size,
- 4096, ION_HEAP_TYPE_DMA_MASK, 0, &tr_cache->share_fd);
- if(ret < 0)
- {
- ALOGD("alloc err from ION_HEAP_TYPE_DMA_MASK");
- ret = ion_alloc_fd(Globctx->IonFd, size,
- 4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &tr_cache->share_fd);
+ if(is_secure){
+ ret = ion_alloc_fd(Globctx->IonFd, size,
+ 4096, ION_HEAP_SECURE_MASK, 0, &tr_cache->share_fd);
if(ret < 0)
{
- ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
- tr_cache->share_fd = -1;
- tr_cache->size_buffer = 0;
- return NULL;
+ ALOGD("alloc err from ION_HEAP_SECURE_MASK");
+ return NULL;
}
- }
- ion_sync_fd(Globctx->IonFd, tr_cache->share_fd);
+ tr_cache->is_secure = 1;
+ }else{
+ ret = ion_alloc_fd(Globctx->IonFd, size,
+ 4096, ION_HEAP_TYPE_DMA_MASK, 0, &tr_cache->share_fd);
+ if(ret < 0)
+ {
+ ALOGD("alloc err from ION_HEAP_TYPE_DMA_MASK");
+ ret = ion_alloc_fd(Globctx->IonFd, size,
+ 4096, ION_HEAP_SYSTEM_CONTIG_MASK, 0, &tr_cache->share_fd);
+ if(ret < 0)
+ {
+ ALOGD("alloc err from ION_HEAP_SYSTEM_CONTIG_MASK");
+ tr_cache->share_fd = -1;
+ tr_cache->size_buffer = 0;
+ return NULL;
+ }
+ }
+ }
+ if(!is_secure){
+ ion_sync_fd(Globctx->IonFd, tr_cache->share_fd);
+ }
tr_cache->size_buffer = size;
}
tr_cache->sync_cnt = sync_count;
@@ -267,7 +283,7 @@ void hwc_rotate_cache_free(void)
static int inline hwc_disp_pixel_bytes(disp_pixel_format format)
{
- switch(format)
+ switch(format)
{
case DISP_FORMAT_YUV420_P:
case DISP_FORMAT_YUV420_SP_VUVU:
@@ -285,13 +301,13 @@ static int inline hwc_disp_pixel_bytes(disp_pixel_format format)
return 16;
default:
return 0;
- }
+ }
return 0;
}
static inline int hwc_disp_layer_plan(disp_pixel_format format)
{
- switch(format)
+ switch(format)
{
case DISP_FORMAT_YUV420_P:
return 3;
@@ -308,7 +324,7 @@ static inline int hwc_disp_layer_plan(disp_pixel_format format)
return 1;
default:
return 1;
- }
+ }
}
static inline disp_pixel_format tr_to_disp(tr_pixel_format tr_format)
@@ -473,9 +489,9 @@ bool hwc_layer_to_tr(disp_fb_info* hw_layer, tr_info *tr_info, hwc_cache_t *tr_b
/*tr_info->dst_frame.laddr[2] --> V*/
if(cnt != 1)// is YUV Format
{
- tr_info->dst_frame.laddr[2] = tr_info->dst_frame.laddr[0] +
+ tr_info->dst_frame.laddr[2] = tr_info->dst_frame.laddr[0] +
tr_info->dst_frame.pitch[0] * tr_info->dst_frame.height[0];
- tr_info->dst_frame.laddr[1] = tr_info->dst_frame.laddr[2] +
+ tr_info->dst_frame.laddr[1] = tr_info->dst_frame.laddr[2] +
tr_info->dst_frame.pitch[2] * tr_info->dst_frame.height[2];
}
return 1;
@@ -487,7 +503,7 @@ void hwc_resize_crop(disp_fb_info *hw_layer, int w_original, int h_original, tr_
switch(mode)
{
case TR_HFLIP:
- w_diff = hw_layer->size[0].width - w_original;
+ w_diff = hw_layer->size[0].width - w_original;
hw_layer->crop.x + (long long)(((long long)w_diff)<<32);
break;
case TR_VFLIP:
@@ -495,7 +511,7 @@ void hwc_resize_crop(disp_fb_info *hw_layer, int w_original, int h_original, tr_
hw_layer->crop.y + (long long)(((long long)h_diff)<<32);
break;
case TR_ROT_90:
- w_diff = hw_layer->size[0].width - h_original;
+ w_diff = hw_layer->size[0].width - h_original;
hw_layer->crop.x + (long long)(((long long)w_diff)<<32);
h_diff = hw_layer->size[0].height - w_original;
hw_layer->crop.y + (long long)(((long long)h_diff)<<32);
@@ -503,7 +519,7 @@ void hwc_resize_crop(disp_fb_info *hw_layer, int w_original, int h_original, tr_
case TR_ROT_180:
h_diff = hw_layer->size[0].height - h_original;
hw_layer->crop.y + (long long)(((long long)h_diff)<<32);
- w_diff = hw_layer->size[0].width - w_original;
+ w_diff = hw_layer->size[0].width - w_original;
hw_layer->crop.x + (long long)(((long long)w_diff)<<32);
break;
case TR_ROT_270:
@@ -580,7 +596,7 @@ bool hwc_tr_to_layer(disp_fb_info *hw_layer, tr_info *tr_info, hwc_cache_t *tr_b
hw_layer->addr[0] = addr;
if(hw_layer->format == DISP_FORMAT_YUV420_P)
{
- hw_layer->addr[2] = hw_layer->addr[0]
+ hw_layer->addr[2] = hw_layer->addr[0]
+ w_stride * h_stride ;
hw_layer->addr[1] = hw_layer->addr[2]
+ w_stride * h_stride / 4;
@@ -645,7 +661,7 @@ bool hwc_rotate_layer_tr(hwc_dispc_data_t *hwc_layer,
goto translat_err;
}
tr_cache = hwc_tr_cache_get(rotate_cache, size,
- commit_data->releasefencefd[disp], hwc_layer->sync_count);
+ commit_data->releasefencefd[disp], hwc_layer->sync_count,commit_layer->is_secure);
if(tr_cache != NULL)
{
memset(&tr_info, 0, sizeof(tr_info));
@@ -720,6 +736,5 @@ translat_err:
disp_layer->enable =0;
ALOGE("######hwc get a rotate err#####");
return 0;
-
+
}
-
diff --git a/hwc/tulip/hwc_sunxi.cpp b/hwc/tulip/hwc_sunxi.cpp
index 56740da..c66ec79 100755
--- a/hwc/tulip/hwc_sunxi.cpp
+++ b/hwc/tulip/hwc_sunxi.cpp
@@ -178,6 +178,7 @@ static bool reset_globle(SUNXI_hwcdev_context_t *Globctx,
Globctx->currentmem = 0;
Globctx->has_tr_mem = 0;
Globctx->has_tr_cnt = 0;
+ Globctx->has_secure = 0;
int tmp_mem_thruput0 = 0;
int all_mem_diff = 0, all_mem = 0, all_mem_fb = 0, ture_disp;
for(i = 0; i < (int)NumofDisp && i < Globctx->NumberofDisp; i++)
@@ -924,24 +925,6 @@ static bool resize_layer(HwcDisContext_t *Localctx,
layer_info->fb.crop.y = fb_crop->top + ((cut_top == 1) ? cut_mod:0);
layer_info->fb.crop.height = srcdiff - cut_mod;
}
-
-#if defined(HWC_DEBUG)
- ALOGD("\nold:\n[%f,%f]#S[%lld,%lld,%lld,%lld] F[%lld,%lld,%lld,%lld]\n",
- Localctx->WidthScaleFactor, Localctx->HighetScaleFactor,
- layer_info->fb.crop.x, layer_info->fb.crop.y, layer_info->fb.crop.width,
- layer_info->fb.crop.height, layer_info->screen_win.x, layer_info->screen_win.y,
- layer_info->screen_win.width, layer_info->screen_win.height);
-#endif
-
- if(gSunxiHwcDevice.SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI) {
- layer_info->fb.crop.x = (long long)(((long long)(psLayer->sourceCrop.left)) << 32);
- layer_info->fb.crop.width = (long long)(((long long)(psLayer->sourceCrop.right)) << 32);
- layer_info->fb.crop.width -= layer_info->fb.crop.x;
- layer_info->fb.crop.y = (long long)(((long long)(psLayer->sourceCrop.top)) << 32);
- layer_info->fb.crop.height = (long long)(((long long)(psLayer->sourceCrop.bottom)) << 32);
- layer_info->fb.crop.height -= layer_info->fb.crop.y;
- }
-
if(layer_info->b_trd_out == 1)
{
switch(PsDisplayInfo->Current3DMode)
@@ -1045,7 +1028,7 @@ ret_ok:
HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout, int zOrder)
{
- bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0, has_tr = 0;
+ bool needchannel = 1, isvideo = 0, isalpha = 0, isFB = 0, has_tr = 0, issecure = 0;
bool is3D = 0, need_sync = 0, is_cursor = 0;
float WscalFac = 1.0, HscaleFac = 1.0;
int CH= -1, tmCnt1 = 0, tmCnt2 = 0, addLayerCnt = 1;
@@ -1095,11 +1078,16 @@ HwcAssignStatus hwc_try_assign_layer(HwcDisContext_t *Localctx, size_t singcout,
goto assign_gpu;
}
- if(check_usage_protected(handle) && !PsDisplayInfo->issecure)
+ if(check_usage_protected(handle))
{
- ALOGV("%s:Video Protected", __func__);
- dueto = D_VIDEO_PD;
- goto assign_gpu;
+ if(!PsDisplayInfo->issecure)
+ {
+ ALOGV("%s:Video Protected", __func__);
+ dueto = D_VIDEO_PD;
+ goto assign_gpu;
+ }else{
+ issecure = 1;
+ }
}
dueto = check_valid_layer(psLayer);
@@ -1239,7 +1227,7 @@ needchannel:
}
}
/*check the mem thruput*/
- if(!is_cursor)
+ if(!is_cursor && (Globctx->has_secure == 0))
{
dueto = calculate_memthruput(Localctx, &Localctx->psAllLayer[singcout],
WscalFac, HscaleFac, Localctx->HwCHUsedCnt - CHdiff, isFB, isvideo);
@@ -1274,7 +1262,7 @@ needchannel:
if(!Localctx->force_gpu
&& (Localctx->UsedFB? isFB: ((int)singcout == Localctx->numberofLayer - 2)))
{
- if(mem_ctrl_power_policy(Globctx, Localctx))
+ if(mem_ctrl_power_policy(Globctx, Localctx) && (Globctx->has_secure == 0))
{
Localctx->force_gpu = 1;
goto assigned_need_resigne;
@@ -1293,6 +1281,7 @@ assign_overlay:
Globctx->has_tr_cnt += has_tr;
Localctx->tr_mem += has_tr ? (handle->width * handle->height) : 0;
Globctx->has_tr_mem += has_tr ? (handle->width * handle->height) : 0;
+ Globctx->has_secure += issecure;
psCH[Localctx->HwCHUsedCnt - CHdiff].hasVideo = isvideo;
psCH[Localctx->HwCHUsedCnt - CHdiff].iCHFormat =
@@ -1315,8 +1304,9 @@ assign_overlay:
Localctx->psAllLayer[singcout].is3D = is3D;
Localctx->psAllLayer[singcout].info = dueto;
Localctx->psAllLayer[singcout].isvideo = isvideo;
- Localctx->psAllLayer[singcout].need_sync = need_sync;
+ Localctx->psAllLayer[singcout].need_sync = issecure?0:need_sync;
Localctx->psAllLayer[singcout].is_cursor = is_cursor;
+ Localctx->psAllLayer[singcout].is_secure = issecure;
if(is_cursor)
{
return ASSIGN_CURSOR;
@@ -1360,7 +1350,6 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
const DisplayInfo *PsDisplayInfo = Localctx->psDisplayInfo;
ChannelInfo_t *psChannelInfo = Localctx->ChannelInfo;
struct private_handle_t *handle = NULL;
- bool enableLayer = !(PsDisplayInfo->setblank);
ture_disp = PsDisplayInfo->VirtualToHWDisplay;
if(ture_disp < 0 || ture_disp >= NUMBEROFDISPLAY)
@@ -1413,6 +1402,7 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
}
hw_layer_config->needsync = psHwlayer_info->need_sync;
hw_layer_config->share_fd = dup(psHwlayer_info->shared_fd);
+ hw_layer_config->is_secure = psHwlayer_info->is_secure;
if(check_is_blending(psLayer))
{
layer_info->alpha_mode = 2;
@@ -1430,7 +1420,7 @@ int hwc_setup_layer(hwc_dispc_data_t *DisplayData, HwcDisContext_t *Localctx)
layer_info->zorder = zOrder;
layer_info->alpha_value = psChannelInfo[CHCnt].planeAlpha;
- psDisconfig->enable = enableLayer;
+ psDisconfig->enable = 1;
psDisconfig->layer_id = LCnt;
psDisconfig->channel = psChannelInfo[CHCnt].hasVideo ? VideoCnt : UiCnt;
psHwlayer_info->hwchannel = psDisconfig->channel;
@@ -2033,11 +2023,10 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
&& Globctx->SunxiDisplay[1].VirtualToHWDisplay == -EINVAL)
{
hwc_hotplug_switch(1, 1, DISP_TV_MODE_NUM);
- ALOGD("### init hdmi_plug: IN ###");
}
+ ALOGD("### init hdmi_plug: IN ###");
}else{
- if(Globctx->SunxiDisplay[0].DisplayType != DISP_OUTPUT_TYPE_HDMI)
- ALOGD("### init hdmi_plug: OUT ###");
+ ALOGD("### init hdmi_plug: OUT ###");
}
close(open_fd);
}else{
@@ -2119,7 +2108,8 @@ SUNXI_hwcdev_context_t* hwc_create_device(void)
Globctx->layer_st = -1;
Globctx->fBeginTime = 0.0;
Globctx->uiBeginFrame = 0;
- Globctx->unblank_flag = 0;
+ Globctx->unblank_flag = 0;
+ Globctx->has_secure = 0;
hwc_list_init(&Globctx->rotate_cache_list);
Globctx->rotate_hold_cnt = 0;
diff --git a/hwc/tulip/hwc_uevent.cpp b/hwc/tulip/hwc_uevent.cpp
index ff6a8ba..9ff8956 100755
--- a/hwc/tulip/hwc_uevent.cpp
+++ b/hwc/tulip/hwc_uevent.cpp
@@ -146,12 +146,12 @@ int hwc_manage_display(DisplayInfo **retDisplayInfo, int DispInfo, ManageDisp mo
disp_tv_mode get_suitable_hdmi_mode(int select, disp_tv_mode lastmode)
{
+ ALOGI("get_suitable_hdmi_mode select=%d lastmode=%d", select, lastmode);
SUNXI_hwcdev_context_t *Globctx = &gSunxiHwcDevice;
unsigned long arg[4]={0};
arg[0] = select;
int ret, i, j = -1;
disp_tv_mode theMostMode = DISP_TV_MODE_NUM;
- struct disp_output para;
i = sizeof(g_tv_para) / sizeof(g_tv_para[0]);
if(lastmode < DISP_TV_MODE_NUM)
{
@@ -164,41 +164,38 @@ disp_tv_mode get_suitable_hdmi_mode(int select, disp_tv_mode lastmode)
}
}
- if(Globctx->SunxiDisplay[0].DisplayType == DISP_OUTPUT_TYPE_HDMI)
- {
- arg[1] = (unsigned long)¶
- ret = ioctl(Globctx->DisplayFd, DISP_GET_OUTPUT, arg);
- if(ret >= 0)
- {
- theMostMode = (disp_tv_mode)para.mode;
- }
- }else{
- while(i > 0)
- {
- i--;
- if(g_tv_para[i].mode == DISP_TV_MOD_1080P_60HZ)
+theMostMode = DISP_TV_MOD_1080P_60HZ;
+ arg[1] = DISP_OUTPUT_TYPE_HDMI;
+ arg[2] = theMostMode;
+ ret = ioctl(Globctx->DisplayFd, DISP_DEVICE_SWITCH, arg);
+
+ return theMostMode;
+
+ while(i > 0)
+ {
+ i--;
+ if(g_tv_para[i].mode == DISP_TV_MOD_1080P_60HZ)
+ {
+ j = i;
+ }
+ if(j != -1)
+ {
+ arg[1] = DISP_OUTPUT_TYPE_HDMI;
+ arg[2] = g_tv_para[i].mode;
+ ret = ioctl(Globctx->DisplayFd, DISP_DEVICE_SWITCH, arg);
+ if(ret >= 0)
{
- j = i;
+ if(theMostMode == DISP_TV_MODE_NUM)
+ {
+ g_tv_para[sizeof(g_tv_para) / sizeof(g_tv_para[0])-1].support = 1<