rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,23 @@
//
// blocking_queue.h
// pal_sdk
//
#ifndef blocking_queue_h
#define blocking_queue_h
#include "doubly_list.h"
struct blocking_queue_t {
void *mutex;
struct list_entry_t *list;
int length;
};
int blocking_queue_init (struct blocking_queue_t **q);
void blocking_queue_destroy (struct blocking_queue_t **q, void (*free_fn)(void *));
int blocking_queue_add (struct blocking_queue_t *q, void *elem, int raw);
int blocking_queue_get (struct blocking_queue_t *q, int timeout_ms, void **elem, int raw);
int blocking_queue_peek(struct blocking_queue_t *q, void **elem, int tail);
#endif /* blocking_queue_h */

View file

@ -0,0 +1,17 @@
/*
* cjson_utils.h
*
* Created on: Jan 22, 2017
* Author: wj
*/
#ifndef CJSON_UTILS_H_
#define CJSON_UTILS_H_
#include <stdlib.h>
#include <stdarg.h>
#include "cJSON.h"
cJSON* get_service_data(cJSON* service_data, int num, ...);
#endif /* CJSON_UTILS_H_ */

View file

@ -0,0 +1,33 @@
//
// doubly_list.h
// pal_sdk
//
#ifndef doubly_list_h
#define doubly_list_h
struct list_entry_t {
void *elem;
struct list_entry_t *prev;
struct list_entry_t *next;
};
void list_init(struct list_entry_t **head);
void list_destroy(struct list_entry_t **head, void (*free_fn)(void *));
struct list_entry_t *list_new_entry(void *elem);
/**
* return the pointer to the next entry of the target
*/
struct list_entry_t *list_remove_entry(struct list_entry_t *entry);
struct list_entry_t *list_insert_after(struct list_entry_t *target,
struct list_entry_t *entry);
struct list_entry_t *list_insert_before(struct list_entry_t *target,
struct list_entry_t *entry);
struct list_entry_t *list_append(struct list_entry_t *head,
struct list_entry_t *entry);
struct list_entry_t *list_pop(struct list_entry_t *head);
int list_is_empty(struct list_entry_t *head);
struct list_entry_t *list_first_entry_peak(struct list_entry_t *head);
#endif /* doubly_list_h */

View file

@ -0,0 +1,45 @@
/*
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD5 Message-Digest Algorithm (RFC 1321).
*
* Homepage:
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
*
* This software was written by Alexander Peslyak in 2001. No copyright is
* claimed, and the software is hereby placed in the public domain.
* In case this attempt to disclaim copyright and place the software in the
* public domain is deemed null and void, then the software is
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
* general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*
* See md5.c for more information.
*/
#ifdef HAVE_OPENSSL
#include <openssl/md5.h>
#elif !defined(_MD5_H)
#define _MD5_H
/* Any 32-bit or wider unsigned integer data type will do */
typedef unsigned int MD5_u32plus;
typedef struct {
MD5_u32plus lo, hi;
MD5_u32plus a, b, c, d;
unsigned char buffer[64];
MD5_u32plus block[16];
} doug_MD5_CTX;
extern void doug_MD5_Init(doug_MD5_CTX *ctx);
extern void doug_MD5_Update(doug_MD5_CTX *ctx, const void *data, unsigned long size);
extern void doug_MD5_Final(unsigned char *result, doug_MD5_CTX *ctx);
#endif

View file

@ -0,0 +1,26 @@
//
// logger.h
// pal_sdk
//
#ifndef logger_h
#define logger_h
#include <stdio.h>
#include <stdlib.h>
extern int g_pal_log_level;
#ifdef PAL_DEBUG
#define log_error(M, ...) fprintf(stderr,"\033[0;31m%s|%d\t", __FUNCTION__, __LINE__);fprintf(stderr, M, ##__VA_ARGS__);fprintf(stderr, "\033[0m\n");fflush(stderr);
#define log_info(M, ...) fprintf(stdout,"%s|%d\t", __FUNCTION__, __LINE__);fprintf(stdout, M, ##__VA_ARGS__);fprintf(stdout, "\n");fflush(stdout);
#define log_debug(M, ...) fprintf(stdout,"%s|%d\t", __FUNCTION__, __LINE__);fprintf(stdout, M, ##__VA_ARGS__);fprintf(stdout, "\n");fflush(stdout);
#else
#define log_error(M, ...) fprintf(stderr,"\033[0;31m%s|%d\t", __FUNCTION__, __LINE__);fprintf(stderr, M, ##__VA_ARGS__);fprintf(stderr, "\033[0m\n");fflush(stderr);
//#define log_error(M, ...)
#define log_info(M, ...) fprintf(stdout,"%s|%d\t", __FUNCTION__, __LINE__);fprintf(stdout, M, ##__VA_ARGS__);fprintf(stdout, "\n");fflush(stdout);
#define log_debug(M, ...)
#endif
#endif /* logger_h */

View file

@ -0,0 +1,35 @@
//
// opus_codec.h
//
#ifndef opus_codec_h
#define opus_codec_h
#include "opus_defines.h"
#ifdef __cplusplus
extern "C" {
#endif
#define FRAME_SAMPLES (320)
#define MAX_DATA_BYTES (320 * sizeof(short))
int opus_codec_init(int sample_rate, int channels, int VBR, int bit_rate,
int complexity, int signal);
int opus_codec_destroy();
/*
* samples: data, char
* sample_data_len : the number of samples in bytes
* buffer: output , uchar
* buffer_capacity: the number of uchar. for example equal to 2*samples_len
*/
int opus_codec_encode(const char *sample_data, int sample_data_len,
unsigned char *buffer, int buffer_capacity, int *buffer_len);
#ifdef __cplusplus
}
#endif
#endif /* opus_codec_h */

View file

@ -0,0 +1,213 @@
//
// pal.h
// pal_sdk
//
#ifndef pal_h
#define pal_h
#ifdef __cplusplus
extern "C"
{
#endif
/*
* Link-Voice SDK回调callback线程
*/
enum pal_callback_cmd_type {
PAL_CALLBACK_CMD_NOTIFY, //SDK事件通知给设备
PAL_CALLBACK_CMD_QUERY, //SDK向设备查询状态设备的状态拷贝到buffer中传给SDK
PAL_CALLBACK_CMD_ALINK //SDK透传的Alink的ALINK_CLOUD_CONNECTEDALINK_CLOUD_DISCONNECTEDALINK_GET_DEVICE_STATUSALINK_SET_DEVICE_STATUS四个事件给设备
};
/*
* cmd: SDK事件通知设备/json字符串Link_Voice_SDK_protocal_v1.0.0.xlsx
* cmd_type: pal_callback_cmd_type类型
*/
typedef void (*pal_callback)(const char *cmd, int cmd_type, char *buffer, int buffer_capacity, void *user);
/*
* PCMOpus16000Hz16 bits
*/
enum pal_audio_format {
PAL_AUDIO_FORMAT_PCM,
PAL_AUDIO_FORMAT_OPUS
};
/*
* Link-Voice SDK日志级别
*/
enum pal_log_level {
PAL_LOG_LEVEL_DEBUG,
PAL_LOG_LEVEL_INFO,
PAL_LOG_LEVEL_ERROR
};
/*
* Link-Voice SDK环境切换
*/
enum pal_env {
PAL_ENV_RELEASE,
PAL_ENV_PRE_RELEASE,
PAL_ENV_DAILY
};
/*
* ASR模型
* PAL_ASR_MODEL_NEAR_FIELD为近场模型Push-To-Talk/Tap-To-Talk的音箱选择该模型
* PAL_ASR_MODEL_FAR_FIELD为远场模型
*/
enum pal_asr_model {
PAL_ASR_MODEL_NEAR_FIELD,
PAL_ASR_MODEL_FAR_FIELD
};
/*
*
*/
struct pal_config
{
int asr_model; //PAL_ASR_MODEL_NEAR_FIELD 或 PAL_ASR_MODEL_FAR_FIELD
int format; //AUDIO_FORMAT_PCM 或 AUDIO_FORMAT_OPUS
unsigned int sample_rate; //目前仅支持16000Hz
unsigned int channels; //目前仅支持单声道channels = 1
unsigned int bits_per_sample; //目前仅支持16 bits每采样点
char *ca_file_path; //CA证书文件路径如: /tmp/ca.pem。RTOS填NULL
void *user; //用户自定义指针在SDK回调里面会回传可以NULL
pal_callback callback; //SDK回调
};
/*
* Link-Voice SDK初始化
* config configuraion information
* return 0: success
* -1: failed
*/
int pal_init(const struct pal_config *config);
/*
* Link-Voice SDK上报消息
*/
int pal_notify_msg(const char *msg);
/*
* Link-Voice SDK上报ALink消息
*/
int pal_post_alink_msg(const char *msg);
/*
* ALink服务端解绑
* return 0:
-1: ALink会先进行解绑再重新注册
*/
int pal_factory_reset();
/*
* Link-Voice SDK销毁
*/
void pal_destroy();
/*
* Link-Voice SDK version
*/
int pal_version();
/*
* Link-Voice SDK
* 线 PAL_ENV_RELEASE (default)
* PAL_ENV_PRE_RELEASE
* PAL_ENV_DAILY
*/
void pal_set_env(int env);
/*
* Link-Voice SDK : PAL_LOG_LEVEL_DEBUG, PAL_LOG_LEVEL_INFO, PAL_LOG_LEVEL_ERROR
*/
void pal_set_log_level(int level);
/*
*
*/
enum pal_rec_result_status
{
PAL_REC_RESULT_STATUS_NONE = -1,
PAL_REC_RESULT_STATUS_SUCCESS = 0,
PAL_REC_RESULT_STATUS_NETWORKING_ERROR,
PAL_REC_RESULT_STATUS_NETWORKING_TIMEOUT
};
/*
*
* RECOGNIZE_TASK_STATUS_END本轮对话结束RECOGNIZE_TASK_STATUS_WAITING多轮对话
*/
enum pal_rec_task_status {
PAL_REC_TASK_STATUS_END = 0,
PAL_REC_TASK_STATUS_WAITING
};
/*
*
*/
struct pal_rec_result
{
int status; //本次语音识别是否成功 pal_rec_result_status
int should_restore_player_status; //控制播放器是否处理完语音识别事件之后恢复之前的状态0是不恢复1是恢复。
char *asr_result; //ASR结果
int task_status; //语音识别任务状态pal_rec_task_status。PAL_REC_TASK_STATUS_END表示单次会话结束PAL_REC_TASK_STATUS_WAITING表示多轮会话应当播完TTS之后进入拾音状态。
char *tts; //TTS
char *raw; //包含语音识别的结果,透传给设备自己解析并执行相关控制指令
};
enum pal_vad_status
{
PAL_VAD_STATUS_NONE = -1,
PAL_VAD_STATUS_VOICE,
PAL_VAD_STATUS_SILENCE,
PAL_VAD_STATUS_STOP
};
/*
*
* return 0: success
* -1: failed
*/
int pal_asr_start();
/*
* Link-Voice SDK发送语音数据VAD的状态vad_statusIf use pcm format, buffer_len must be 640
*/
int pal_asr_send_buffer(const char *buffer, int buffer_len);
/*
* pal_rec_result_destroy销毁pal_rec_result
*/
struct pal_rec_result* pal_asr_stop();
/*
* pal_rec_result_destroy销毁pal_rec_result
*/
typedef void (*pal_asr_callback)(struct pal_rec_result *result, void *user);
void pal_asr_stop_async(pal_asr_callback callback, void *user);
/*
*
*/
void pal_asr_cancel();
/*
* pal_rec_result_destroy销毁pal_rec_result
*
*/
struct pal_rec_result* pal_get_tts(const char *text);
/*
* pal_rec_result
*/
void pal_rec_result_destroy(struct pal_rec_result *result);
#ifdef __cplusplus
}
#endif
#endif /* pal_h */

View file

@ -0,0 +1,152 @@
//
// pal_platform.h
// pal_sdk
//
#ifndef pal_platform_h
#define pal_platform_h
#include <stdio.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* Comment out this line if stdint.h is not defined */
#define HAVE_STDINT_H
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#endif
extern int gmalloc_count;
extern int gfree_count;
/*
* Create a thread.
* params:
* thread: the new thread handle;
* name: thread name;
* start_routine: user-defined function to be executed by the thread;
* arg: parameter to be passed to start_routine;
* stack_size: thread stack size in bytes;
* return:
* 0: success.
* -1: failed.
*/
int pal_thread_create(void **thread, const char *name, void *(*start_routine)(void *), void *arg, unsigned int stack_size);
/*
* Terminate calling thread
* param:
* thread: thread handle.
*/
void pal_thread_exit(void *thread);
/*
* Join with a terminated thread.
* return:
* 0: success.
* -1: failed.
*/
int pal_thread_join(void *thread);
/*
* Destroy the thread.
*
*/
void pal_thread_destroy(void *thread);
/*
* Initialize a mutex.
* return:
* 0: success.
* -1: failed.
*/
int pal_mutex_init(void **mutex);
/*
* Destroy the mutex.
* return:
* 0: success.
* -1: failed.
*/
int pal_mutex_destroy(void *mutex);
/*
* Lock the mutex.
* return:
* 0: success.
* -1: failed.
*/
int pal_mutex_lock(void *mutex);
/*
* Unlock the mutex.
* return:
* 0: success.
* -1: failed.
*/
int pal_mutex_unlock(void *mutex);
/*
* Initialize an semaphore.
* return:
* the semaphore handle.
*/
void *pal_semaphore_init();
/*
* Destroy the semaphore.
*/
void pal_semaphore_destroy(void *sem);
/*
* Decrements (locks) the semaphore pointed to by sem. If
* the semaphore's value is greater than zero , then the decrement
* proceeds, and the function returns, immediately. Otherwise, wait until timeout_ms in millisecond reached.
* return:
* 0: success.
* -1: failed.
*/
int pal_semaphore_wait(void *sem, int timeout_ms);
/*
* Increments (unlocks) the semaphore pointed to by sem.
*/
void pal_semaphore_post(void *sem);
/*
* Suspend execution for millisecond intervals.
*/
void pal_msleep(int millisecond);
/*
* Allocate dynamic memory of `size' bytes.
*/
void* pal_malloc(int size);
/*
* Free dynamic memory.
*/
void pal_free(void *mem);
/*
* Get UTC time in millisecond.
*/
uint64_t pal_get_utc_time_ms();
#ifdef __cplusplus
}
#endif
#endif /* pal_platform_h */

View file

@ -0,0 +1,36 @@
//
// runloop.h
// pal_sdk
//
#ifndef runloop_h
#define runloop_h
#include "blocking_queue.h"
#include "tic.h"
typedef struct {
int name;
void *param;
int type;
tic_t timestamp;
int delay_ms;
} runloop_event_t;
typedef void (*dispatcher_fn)(runloop_event_t *e, void *extra_params);
typedef void (*destroy_handler_fn)(void *entry);
typedef struct _runloop {
void *thread;
struct blocking_queue_t *q;
int loop_running;
int loop_exit;
void *mutex;
dispatcher_fn dispatcher;
destroy_handler_fn destroy_handler;
} runloop_t;
int runloop_init(runloop_t *run_loop, dispatcher_fn dispatcher, void *dispatcher_param, destroy_handler_fn destroy_handler, const char *name, int stack_size);
void runloop_destroy(runloop_t *run_loop);
#endif /* runloop_h */

View file

@ -0,0 +1,18 @@
//
// tic.h
// pal_sdk
//
#ifndef tic_h
#define tic_h
typedef struct _tic_t {
long tv_sec;
long tv_usec;
}tic_t;
tic_t tic();
long toc(tic_t starter);
int pal_gettimeofday(tic_t *now, void *param);
#endif /* tic_h */

View file

@ -0,0 +1,25 @@
NAME := linkvoice
$(NAME)_TYPE := framework
$(NAME)_COMPONENTS := imbedtls alicrypto connectivity/websockets cjson protocol.alink ywss netmgr
ifeq ($(HOST_ARCH), Cortex-M4)
$(NAME)_PREBUILT_LIBRARY := lib/$(HOST_ARCH)/linkvoice.a
else ifeq ($(HOST_ARCH), linux)
PLATFORM := linuxhost
$(NAME)_PREBUILT_LIBRARY := lib/$(PLATFORM)/linkvoice.a
else
$(error "do not find correct platform!")
endif
GLOBAL_INCLUDES +=inc
#$(NAME)_INCLUDES :=asr ca core
$(NAME)_DEFINES +=PAL_DEBUG