GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
Executable
+30
@@ -0,0 +1,30 @@
|
||||
ifeq ($(CFG_XMEDIA_EXPORT_FLAG),)
|
||||
SDK_DIR := $(shell cd $(CURDIR)/../.. && /bin/pwd)
|
||||
endif
|
||||
|
||||
include $(SDK_DIR)/build/base.mk
|
||||
include $(SAMPLE_DIR)/sample_base.mk
|
||||
|
||||
TARGET := sample_aov
|
||||
|
||||
LIBS := $(SAMPLE_LIBS) $(SAMPLE_COMMON_LIB)
|
||||
|
||||
INCLUDES := $(SAMPLE_INCLUDES)
|
||||
|
||||
CFLAGS := $(SAMPLE_CFLAGS) $(LIBS) $(INCLUDES)
|
||||
|
||||
SRCS := $(wildcard ./*.c)
|
||||
|
||||
OBJS := $(patsubst %.c, %.o, $(SRCS))
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OBJS)
|
||||
$(AT)$(CC) -o $(TARGET) $^ $(CFLAGS)
|
||||
$(AT)$(STRIP) $(TARGET)
|
||||
|
||||
%.o : %.c
|
||||
$(AT)$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
clean:
|
||||
$(AT)rm -rf $(OBJS) $(TARGET)
|
||||
Executable
+2213
File diff suppressed because it is too large
Load Diff
Executable
+523
@@ -0,0 +1,523 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "sample_aov_audio.h"
|
||||
#ifdef NORMAL_SUPPORT_AUDIO
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
#define SAMPLE_AOV_AUDIO_ADEC_CHN 1
|
||||
|
||||
#define SAMPLE_AOV_AUDIO_ADEC_RATE 16000
|
||||
#define SAMPLE_AOV_AUDIO_AO_RATE 16000
|
||||
#define SAMPLE_AOV_AUDIO_AI_RATE 16000
|
||||
#define SAMPLE_AOV_AUDIO_AENC_RATE 16000
|
||||
|
||||
|
||||
#define SAMPLE_AOV_AUDIO_AENC_VOL 20
|
||||
#define SAMPLE_AOV_AUDIO_ADEC_BASE_FILE_PATH "/usr/param/chn" //chn0.mp3
|
||||
#define SAMPLE_AOV_AUDIO_AENC_FILE_PATH "/tmp/sd/aov_audio.aac"
|
||||
|
||||
static sample_ao_config g_ao_config = {0};
|
||||
static ao_vqe_attr_v2 ao_vqev2_attr = {0};
|
||||
static ao_vqe_attr_v1 ao_vqev1_attr = {0};
|
||||
static sample_adec_config g_adec_config[SAMPLE_AOV_AUDIO_ADEC_CHN] = {0};
|
||||
static FILE *adec_input_fd[SAMPLE_AOV_AUDIO_ADEC_CHN];
|
||||
static FILE *aenc_output_fd = XMEDIA_NULL;
|
||||
|
||||
static sample_ai_config g_ai_config = {0};
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v2 ai_vqev2_attr = {0};
|
||||
|
||||
static xmedia_s32 sample_aov_audio_play_thread_start()
|
||||
{
|
||||
xmedia_s32 i = 0;
|
||||
xmedia_char buf[256] = {0};
|
||||
xmedia_s32 s32Ret = XMEDIA_SUCCESS;
|
||||
|
||||
for (i = 0; i < SAMPLE_AOV_AUDIO_ADEC_CHN; i++) {
|
||||
memset(buf, 0 , sizeof(buf));
|
||||
snprintf(buf, 256, "%s%d%s", SAMPLE_AOV_AUDIO_ADEC_BASE_FILE_PATH,i,".mp3");
|
||||
|
||||
adec_input_fd[i] = fopen(buf, "rb");
|
||||
if (adec_input_fd[i] == XMEDIA_NULL) {
|
||||
for (;i >= 0; i --) {
|
||||
sample_comm_adec_destroy_input_thread_from_file(&g_adec_config[i]);
|
||||
fclose(adec_input_fd[i]);
|
||||
}
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret |= sample_comm_adec_create_input_thread_from_file(&g_adec_config[i], &adec_input_fd[i]);
|
||||
}
|
||||
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aov_audio_play_thread_stop()
|
||||
{
|
||||
xmedia_s32 i = 0;
|
||||
xmedia_s32 s32Ret = XMEDIA_SUCCESS;
|
||||
|
||||
for (i = 0; i < SAMPLE_AOV_AUDIO_ADEC_CHN; i++) {
|
||||
s32Ret |= sample_comm_adec_destroy_input_thread_from_file(&g_adec_config[i]);
|
||||
fclose(adec_input_fd[i]);
|
||||
adec_input_fd[i] = XMEDIA_NULL;
|
||||
}
|
||||
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_adec_start()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
xmedia_s32 i = 0;
|
||||
xmedia_char buf[256] = {0};
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
for (i = 0; i < SAMPLE_AOV_AUDIO_ADEC_CHN; i++) {
|
||||
memset(buf, 0 , sizeof(buf));
|
||||
snprintf(buf, 256, "%s%d%s", SAMPLE_AOV_AUDIO_ADEC_BASE_FILE_PATH,i,".mp3");
|
||||
s32Ret = sample_comm_get_codec_info(buf, &type, &format);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
goto ADEC_ERR;
|
||||
}
|
||||
|
||||
g_adec_config[i].sample_rate = SAMPLE_AOV_AUDIO_ADEC_RATE;
|
||||
g_adec_config[i].chn = i;
|
||||
g_adec_config[i].type = type;
|
||||
g_adec_config[i].format = format;
|
||||
|
||||
s32Ret = sample_comm_adec_register(g_adec_config[i].type);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_adec_register fail\n");
|
||||
goto ADEC_ERR;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_adec_start(&g_adec_config[i]);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_adec_start fail\n");
|
||||
goto ADEC_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
ADEC_ERR:
|
||||
for (;i >= 0; i --) {
|
||||
sample_comm_adec_stop(&g_adec_config[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < SAMPLE_AOV_AUDIO_ADEC_CHN; i++) {
|
||||
sample_comm_adec_unregister(g_adec_config[i].type);
|
||||
}
|
||||
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_adec_stop()
|
||||
{
|
||||
xmedia_s32 i = 0;
|
||||
|
||||
for (i = 0; i < SAMPLE_AOV_AUDIO_ADEC_CHN; i++) {
|
||||
sample_comm_adec_stop(&g_adec_config[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < SAMPLE_AOV_AUDIO_ADEC_CHN; i++) {
|
||||
sample_comm_adec_unregister(g_adec_config[i].type);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_void sample_aov_audio_ao_load_vqe_v1(ao_vqe_attr *vqe_attr)
|
||||
{
|
||||
vqe_attr->attr = (xmedia_void*)&ao_vqev1_attr;
|
||||
vqe_attr->version = AO_VQE_ENHANCE_ATTR_VERSION_1;
|
||||
|
||||
ao_vqev1_attr.mask = VQE_V1_MASK_AGC | VQE_V1_MASK_ANR | VQE_V1_MASK_HPF | VQE_V1_MASK_EQ;
|
||||
ao_vqev1_attr.agc_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
ao_vqev1_attr.agc_attr.target_level = -8;
|
||||
ao_vqev1_attr.agc_attr.max_boost_gain = 25;
|
||||
ao_vqev1_attr.agc_attr.noise_floor = -120;
|
||||
ao_vqev1_attr.agc_attr.ratio = 12;
|
||||
ao_vqev1_attr.agc_attr.attack_time = 2;
|
||||
ao_vqev1_attr.agc_attr.release_time = 20;
|
||||
|
||||
ao_vqev1_attr.anr_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
ao_vqev1_attr.anr_attr.usr_scene = VQE_V1_ANR_SCENE_NORMAL;
|
||||
ao_vqev1_attr.anr_attr.nr_mode = VQE_V1_NR_MODE_SPEECH;
|
||||
ao_vqev1_attr.anr_attr.max_suppress_gain = 6;
|
||||
ao_vqev1_attr.anr_attr.suppress_level = 0x0;
|
||||
ao_vqev1_attr.anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
ao_vqev1_attr.hpf_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
ao_vqev1_attr.hpf_attr.freq = VQE_V1_HPF_FREQ_80;
|
||||
|
||||
memset(&ao_vqev1_attr.eq_attr, 0, sizeof(vqe_eq_attr_v1));
|
||||
}
|
||||
|
||||
xmedia_void sample_aov_audio_ao_load_vqe_v2(ao_vqe_attr *vqe_attr)
|
||||
{
|
||||
vqe_attr->attr = (xmedia_void*)&ao_vqev2_attr;
|
||||
vqe_attr->version = AO_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
|
||||
ao_vqev2_attr.mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_HPF | VQE_V2_MASK_EQ;
|
||||
|
||||
ao_vqev2_attr.agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ao_vqev2_attr.agc_attr.target_level = -6;
|
||||
ao_vqev2_attr.agc_attr.max_boost_gain = 20;
|
||||
ao_vqev2_attr.agc_attr.noise_floor = -65;
|
||||
ao_vqev2_attr.agc_attr.ratio = 10;
|
||||
ao_vqev2_attr.agc_attr.attack_time = 20;
|
||||
ao_vqev2_attr.agc_attr.release_time = 20;
|
||||
|
||||
ao_vqev2_attr.anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ao_vqev2_attr.anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
ao_vqev2_attr.anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
ao_vqev2_attr.anr_attr.max_suppress_gain = 6;
|
||||
ao_vqev2_attr.anr_attr.suppress_level = 0x2;
|
||||
ao_vqev2_attr.anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
ao_vqev2_attr.hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ao_vqev2_attr.hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
memset(&ao_vqev2_attr.eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
xmedia_void sample_aov_audio_ai_load_vqe_v2(ai_vqe_attr *vqe_attr)
|
||||
{
|
||||
vqe_attr->attr = (xmedia_void*)&ai_vqev2_attr;
|
||||
|
||||
vqe_attr->version = AI_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
vqe_attr->work_sample_rate = AUDIO_SAMPLE_RATE_16000;
|
||||
vqe_attr->in_channels = 2;
|
||||
vqe_attr->attr = (xmedia_void*)&ai_vqev2_attr;
|
||||
ai_vqev2_attr.mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_HPF | VQE_V2_MASK_BF;
|
||||
|
||||
ai_vqev2_attr.aec_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ai_vqev2_attr.aec_attr.cng_enable = XMEDIA_TRUE;
|
||||
ai_vqev2_attr.aec_attr.freq_boundary = 1800;
|
||||
ai_vqev2_attr.aec_attr.low_suppress_level = 0x7;
|
||||
ai_vqev2_attr.aec_attr.high_suppress_level = 0x5;
|
||||
|
||||
ai_vqev2_attr.agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ai_vqev2_attr.agc_attr.target_level = -6;
|
||||
ai_vqev2_attr.agc_attr.max_boost_gain = 20;
|
||||
ai_vqev2_attr.agc_attr.noise_floor = -100;
|
||||
ai_vqev2_attr.agc_attr.ratio = 12;
|
||||
ai_vqev2_attr.agc_attr.attack_time = 8;
|
||||
ai_vqev2_attr.agc_attr.release_time = 20;
|
||||
|
||||
ai_vqev2_attr.anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ai_vqev2_attr.anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
ai_vqev2_attr.anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
ai_vqev2_attr.anr_attr.max_suppress_gain = 6;
|
||||
ai_vqev2_attr.anr_attr.suppress_level = 0x2;
|
||||
ai_vqev2_attr.anr_attr.nonstationary_suppress_level = 0x0;
|
||||
|
||||
ai_vqev2_attr.bf_attr.reserved = 0;
|
||||
|
||||
ai_vqev2_attr.vad_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ai_vqev2_attr.vad_attr.sensitivity_level = 5;
|
||||
|
||||
ai_vqev2_attr.hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
ai_vqev2_attr.hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
memset(&ai_vqev2_attr.eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_ao_start()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
g_ao_config.dev = XMEDIA_AO_DEV_DAC0;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = 1;
|
||||
g_ao_config.dev_attr.sample_rate = 16000;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_ao_config.dev_attr.sample_rate / 1000;
|
||||
g_ao_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_MONO;
|
||||
g_ao_config.dev_attr.pcm_frame_max_num = 12;
|
||||
g_ao_config.vqe_enable = XMEDIA_TRUE;
|
||||
sample_aov_audio_ao_load_vqe_v2(&g_ao_config.vqe_attr);
|
||||
if ((g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ao_config.frame_info.frm_rate != g_ao_config.dev_attr.sample_rate)) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
g_ao_config.binder_src = MOD_ID_ADEC;
|
||||
|
||||
s32Ret = sample_comm_ao_register(ao_vqev2_attr.mask, AO_VQE_ENHANCE_ATTR_VERSION_2, g_ao_config.res_enable);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_ao_register fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_ao_start(&g_ao_config);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_ao_start fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_ao_stop()
|
||||
{
|
||||
return sample_comm_ao_stop(&g_ao_config);
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_ai_start()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
xmedia_s32 codec_vol = SAMPLE_AOV_AUDIO_AENC_VOL;
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = AUDIO_CHANNEL_2;
|
||||
g_ai_config.dev_attr.sample_rate = SAMPLE_AOV_AUDIO_AI_RATE;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * SAMPLE_AOV_AUDIO_AI_RATE / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = SAMPLE_AOV_AUDIO_AI_RATE;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
sample_aov_audio_ai_load_vqe_v2(&g_ai_config.vqe_attr);
|
||||
|
||||
s32Ret = sample_comm_ai_register(ai_vqev2_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_ai_register fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_ai_start(&g_ai_config);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_ai_start fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&codec_vol);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_ai_set_dev_param fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_ai_stop()
|
||||
{
|
||||
return sample_comm_ai_stop(&g_ai_config);
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_aenc_start()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
s32Ret = sample_comm_get_codec_info(SAMPLE_AOV_AUDIO_AENC_FILE_PATH, &type, &format);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_get_codec_info fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
aenc_output_fd = fopen(SAMPLE_AOV_AUDIO_AENC_FILE_PATH, "ab");
|
||||
if (aenc_output_fd == XMEDIA_NULL) {
|
||||
SAMPLE_ERR("open aenc output file fail errno %s\n",strerror(errno));
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
g_aenc_config.sample_rate = SAMPLE_AOV_AUDIO_AENC_RATE;
|
||||
g_aenc_config.channels = 1; // ai open vqev2
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
|
||||
s32Ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_aenc_register fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_aenc_start fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, &aenc_output_fd);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_aenc_create_output_thread_to_file fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_aenc_stop()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
|
||||
s32Ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_aenc_destroy_output_thread_to_file fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
fflush(aenc_output_fd);
|
||||
fsync(fileno(aenc_output_fd));
|
||||
fclose(aenc_output_fd);
|
||||
aenc_output_fd = XMEDIA_NULL;
|
||||
|
||||
s32Ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_aenc_stop fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
s32Ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("sample_comm_aenc_unregister fail\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_init()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
|
||||
s32Ret = xmedia_ai_init();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_ai_init fail\n");
|
||||
}
|
||||
|
||||
s32Ret = xmedia_ao_init();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_ao_init fail\n");
|
||||
}
|
||||
|
||||
s32Ret = xmedia_adec_init();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_adec_init fail\n");
|
||||
}
|
||||
|
||||
s32Ret = xmedia_aenc_init();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_aenc_init fail\n");
|
||||
}
|
||||
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_exit()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
|
||||
s32Ret = xmedia_ai_exit();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_ai_exit fail\n");
|
||||
}
|
||||
|
||||
s32Ret = xmedia_ao_exit();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_ao_exit fail\n");
|
||||
}
|
||||
|
||||
s32Ret = xmedia_adec_exit();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_adec_exit fail\n");
|
||||
}
|
||||
|
||||
s32Ret = xmedia_aenc_exit();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("xmedia_aenc_exit fail\n");
|
||||
}
|
||||
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_aov_audio_start_play()
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_FAILURE;
|
||||
|
||||
s32Ret = sample_aov_audio_adec_start();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("audio adec start fail\n");
|
||||
goto ERR_ADEC_START;
|
||||
}
|
||||
|
||||
s32Ret = sample_aov_audio_ao_start();
|
||||
if (s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("audio ao start fail\n");
|
||||
goto ERR_AO_START;
|
||||
}
|
||||
|
||||
sample_aov_audio_play_thread_start();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
ERR_AO_START:
|
||||
sample_aov_audio_ao_stop();
|
||||
|
||||
ERR_ADEC_START:
|
||||
sample_aov_audio_adec_stop();
|
||||
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_stop_play()
|
||||
{
|
||||
sample_aov_audio_play_thread_stop();
|
||||
|
||||
sample_aov_audio_ao_stop();
|
||||
|
||||
sample_aov_audio_adec_stop();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_start_record()
|
||||
{
|
||||
sample_aov_audio_ai_start();
|
||||
|
||||
sample_aov_audio_aenc_start();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_aov_audio_stop_record()
|
||||
{
|
||||
sample_aov_audio_aenc_stop();
|
||||
|
||||
sample_aov_audio_ai_stop();
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#ifndef __SAMPLE_AOV_AUDIO_H__
|
||||
#define __SAMPLE_AOV_AUDIO_H__
|
||||
|
||||
#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
//#define NORMAL_SUPPORT_AUDIO 1
|
||||
|
||||
#ifdef NORMAL_SUPPORT_AUDIO
|
||||
xmedia_s32 sample_aov_audio_init();
|
||||
xmedia_s32 sample_aov_audio_exit();
|
||||
xmedia_s32 sample_aov_audio_start_play();
|
||||
xmedia_s32 sample_aov_audio_stop_play();
|
||||
xmedia_s32 sample_aov_audio_start_record();
|
||||
xmedia_s32 sample_aov_audio_stop_record();
|
||||
#endif
|
||||
|
||||
#endif //__SAMPLE_AOV_AUDIO_H__
|
||||
@@ -0,0 +1,158 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/times.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "sample_osd_time.h"
|
||||
|
||||
#ifdef SUPPORT_OSD_TIME
|
||||
|
||||
static xmedia_s32 g_rgn_hdl = RGN_HANDLE_MAX - 1;
|
||||
static xmedia_s32 g_osd_init_flag = 0;
|
||||
static misc_osd_time_attr_t g_osd_time_attr;
|
||||
static xmedia_s32 g_misc_fd = -1;
|
||||
|
||||
xmedia_u32 custom_tick_get(void)
|
||||
{
|
||||
static xmedia_u64 start_time = 0;
|
||||
xmedia_u64 now_time = 0;
|
||||
xmedia_u32 time_ms;
|
||||
struct timespec st_timespec_now;
|
||||
|
||||
if(start_time == 0) {
|
||||
struct timespec st_timespec_start;
|
||||
clock_gettime(CLOCK_MONOTONIC, &st_timespec_start);
|
||||
start_time = st_timespec_start.tv_sec * 1000 + st_timespec_start.tv_nsec / 1000000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &st_timespec_now);
|
||||
now_time = st_timespec_now.tv_sec * 1000 + st_timespec_now.tv_nsec / 1000000;
|
||||
|
||||
time_ms = now_time - start_time;
|
||||
return time_ms;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_osd_time_init()
|
||||
{
|
||||
xmedia_rgn_attr region;
|
||||
|
||||
if(g_osd_init_flag) {
|
||||
SAMPLE_ERR("The OSD has already been initialized and no need reinitialization!!!\n");
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
g_misc_fd = sample_comm_aov_get_misc_fd();
|
||||
if(g_misc_fd < 0) {
|
||||
SAMPLE_ERR("Should open /dev/misc first!!!\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
memset(&g_osd_time_attr, 0, sizeof(misc_osd_time_attr_t));
|
||||
region.type = XMEDIA_RGN_TYPE_OVERLAY;
|
||||
region.attr.overlay.pixel_format = XMEDIA_VIDEO_PIXEL_FMT_ARGB_1555;
|
||||
region.attr.overlay.size.width = RGN_DEFAULT_WIDTH;
|
||||
region.attr.overlay.size.height = RGN_DEFAULT_HEIGHT;
|
||||
region.attr.overlay.bg_color = 0xffff;
|
||||
region.attr.overlay.canvas_num = 2;
|
||||
|
||||
g_osd_time_attr.rgn_hdl = g_rgn_hdl;
|
||||
memcpy(&g_osd_time_attr.rgn_attr, ®ion, sizeof(xmedia_rgn_attr));
|
||||
|
||||
g_osd_time_attr.font_size_scale = 2;
|
||||
g_osd_time_attr.text_color = ARGB1555_YELLOW;
|
||||
g_osd_time_attr.bg_color = ARGB1555_DARKBLUE;
|
||||
|
||||
g_osd_init_flag = 1;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_osd_time_attach_to_chn(xmedia_chn_info *mpp_chn, xmedia_rgn_chn_attr *chn_attr)
|
||||
{
|
||||
xmedia_s32 s32Ret = XMEDIA_SUCCESS;
|
||||
|
||||
if(mpp_chn == XMEDIA_NULL || chn_attr == XMEDIA_NULL) {
|
||||
SAMPLE_ERR("invalid parameter!\n");
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
memcpy(&g_osd_time_attr.attach_obj[g_osd_time_attr.rgn_attach_num].mpp_chn, mpp_chn, sizeof(xmedia_chn_info));
|
||||
memcpy(&g_osd_time_attr.attach_obj[g_osd_time_attr.rgn_attach_num].chn_attr, chn_attr, sizeof(xmedia_rgn_chn_attr));
|
||||
g_osd_time_attr.rgn_attach_num++;
|
||||
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_osd_time_start()
|
||||
{
|
||||
xmedia_s32 tz_minuteswest = -480; // TimeZone UTC+8
|
||||
xmedia_s32 s32Ret = XMEDIA_SUCCESS;
|
||||
|
||||
SAMPLE_PRT("rgn_hdl:%d, font_size_scale:%d, text_color:0x%x, bg_color:0x%x, obj size:%d\n",
|
||||
g_osd_time_attr.rgn_hdl, g_osd_time_attr.font_size_scale, g_osd_time_attr.text_color, g_osd_time_attr.bg_color, sizeof(misc_osd_time_attr_t));
|
||||
|
||||
s32Ret = ioctl(g_misc_fd, XMEDIA_MISC_OSD_TIME_CREATE_CTRL, &g_osd_time_attr);
|
||||
if(s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("misc driver osd time create failed with %#x!\n", s32Ret);
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
s32Ret = ioctl(g_misc_fd, XMEDIA_MISC_OSD_TIME_UPDATE_TIMEZONE_CTRL, &tz_minuteswest);
|
||||
if(s32Ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_ERR("misc driver osd time set timezone failed with %#x!\n", s32Ret);
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
return s32Ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_osd_time_destroy()
|
||||
{
|
||||
if(g_misc_fd != -1) {
|
||||
ioctl(g_misc_fd, XMEDIA_MISC_OSD_TIME_DESTROY_CTRL, &g_osd_time_attr);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_osd_time_update(xmedia_u32 time_interval, sample_aov_work_mode work_mode) {
|
||||
static xmedia_u32 record_cnt = 0;
|
||||
static xmedia_u32 last_update_time = 0, next_update_time = 0;
|
||||
xmedia_u32 cur_time = 0;
|
||||
struct timeval tv_start;
|
||||
|
||||
if(record_cnt == 0) {
|
||||
goto DO_UPDATE_OSD;
|
||||
}
|
||||
else if(work_mode == MEDIA_WORK_NORMAL && (record_cnt * time_interval *3/2 >= next_update_time)) {
|
||||
cur_time = custom_tick_get();
|
||||
if((cur_time - last_update_time)*1000 >= next_update_time) {
|
||||
goto DO_UPDATE_OSD;
|
||||
}
|
||||
else {
|
||||
record_cnt++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
record_cnt++;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
DO_UPDATE_OSD:
|
||||
if(g_misc_fd != -1) {
|
||||
gettimeofday(&tv_start, NULL);
|
||||
//SAMPLE_PRT("cur time:%ums, delta time:%ums, tv_sec:%lu, tv_usec:%lu\n", cur_time, cur_time - last_update_time, tv_start.tv_sec, tv_start.tv_usec);
|
||||
|
||||
ioctl(g_misc_fd, XMEDIA_MISC_OSD_TIME_UPDATE_CTRL, &g_osd_time_attr);
|
||||
last_update_time = cur_time;
|
||||
next_update_time = 1000000 - tv_start.tv_usec;
|
||||
record_cnt = 1;
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
#endif //SUPPORT_OSD_TIME
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef __SAMPLE_OSD_TIME_H__
|
||||
#define __SAMPLE_OSD_TIME_H__
|
||||
|
||||
#include "sample_comm_aov.h"
|
||||
#include "sample_comm.h"
|
||||
#include "drv_osd_draw_time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_OSD_TIME
|
||||
|
||||
#define RGN_DEFAULT_WIDTH (352)
|
||||
#define RGN_DEFAULT_HEIGHT (60)
|
||||
|
||||
xmedia_s32 sample_osd_time_init();
|
||||
xmedia_s32 sample_osd_time_attach_to_chn(xmedia_chn_info *mpp_chn, xmedia_rgn_chn_attr *chn_attr);
|
||||
xmedia_s32 sample_osd_time_start();
|
||||
xmedia_s32 sample_osd_time_update(xmedia_u32 time_interval, sample_aov_work_mode work_mode);
|
||||
xmedia_s32 sample_osd_time_destroy();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //__SAMPLE_OSD_TIME_H__
|
||||
Reference in New Issue
Block a user