From: snickersun Date: Tue, 2 Jun 2026 15:05:24 +0000 (+0800) Subject: 添加opus,还不能正常启动 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=874fe55a368431bbe09474a967b4ecddf1fb5329;p=mirrors%2FASR1603_G5.git 添加opus,还不能正常启动 --- diff --git a/.cursor/rules/project.mdc b/.cursor/rules/project.mdc index 914588d8..6a12572b 100644 --- a/.cursor/rules/project.mdc +++ b/.cursor/rules/project.mdc @@ -6,7 +6,8 @@ alwaysApply: true - 你是高级嵌入式工程师,代码必须遵循最佳实践和最佳设计原则 - 本工程是micropython工程, - 2.sdk/Helios_SDK是编译路径,2.sdk/project/7PIN_1_5是项目路径 ,代码优先在项目路径里找,没有的通用代码才在编译路径里。 -- 2.sdk\project\7PIN_1_5\sdk\services\microPython\ports\quectel\core\products\configs\k8\default_config.py 是默认k8 的配置参数。 -- 编译指令是 new_clean.bat k8 1 +- 2.sdk\project\7PIN_1_5\sdk\services\microPython\ports\quectel\core\products\configs\k8v3\default_config.py 是默认k8v3 的配置参数。 +- 编译指令是 new_clean.bat k8v3 1 - 分析日志解决问题时,要考虑根因,不要只是靠简单判断条件进行兜底修复。 -- 每次修改都要考虑副作用,不能拆东墙补西墙 \ No newline at end of file +- 每次修改都要考虑副作用,不能拆东墙补西墙 +- 2.sdk\Helios_SDK\opt\log\build.log 是编译日志,有编译问题,可以直接搜索这个文件 \ No newline at end of file diff --git a/2.sdk/Helios_SDK/comp_info_tell.mk b/2.sdk/Helios_SDK/comp_info_tell.mk index e53ef188..3ff4bb4d 100644 --- a/2.sdk/Helios_SDK/comp_info_tell.mk +++ b/2.sdk/Helios_SDK/comp_info_tell.mk @@ -12,17 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +.DEFAULT_GOAL := all + include $(COMP_MK) all: - @echo "NAME: $(NAME)" - @echo "GLOBAL_INCS: $(GLOBAL_INCS)" - @echo "GLOBAL_DEFINE: $(GLOBAL_DEFINE)" - @echo "LOCAL_CFLAGS: $($(NAME)_CFLAGS)" - @echo "LOCAL_ARCHIVES: $($(NAME)_ARCHIVES)" - @echo "LOCAL_SRCS: $($(NAME)_SRCS)" - @echo "LOCAL_SRCS_2: $($(NAME)_SRCS_2)" - @echo "LOCAL_SRCS_3: $($(NAME)_SRCS_3)" - @echo "LOCAL_INCS: $($(NAME)_INCS)" - @echo "LOCAL_DEFINE: $($(NAME)_DEFINE)" - @echo "COMP_DEPS: $($(NAME)_COMPONENTS)" + @echo NAME: $(NAME) + @echo GLOBAL_INCS: $(GLOBAL_INCS) + @echo GLOBAL_DEFINE: $(GLOBAL_DEFINE) + @echo LOCAL_CFLAGS: $($(NAME)_CFLAGS) + @echo LOCAL_ARCHIVES: $($(NAME)_ARCHIVES) + @echo LOCAL_SRCS: + @echo LOCAL_SRCS_2: + @echo LOCAL_SRCS_3: + @echo LOCAL_INCS: $($(NAME)_INCS) + @echo LOCAL_DEFINE: $($(NAME)_DEFINE) + @echo COMP_DEPS: $($(NAME)_COMPONENTS) diff --git a/2.sdk/Helios_SDK/compile.py b/2.sdk/Helios_SDK/compile.py index 06d3a358..80883408 100644 --- a/2.sdk/Helios_SDK/compile.py +++ b/2.sdk/Helios_SDK/compile.py @@ -14,6 +14,7 @@ import json, os, re, sys, shutil, subprocess +HELIOS_ROOT = os.path.dirname(os.path.abspath(__file__)) dep_dict = {} SYSTEMROOT = os.environ.get('SystemRoot', r'C:\Windows') # 不信任 COMSPEC/ComSpec(批处理/工具链可能把它设成相对路径 cmd.exe),直接固定用系统 cmd.exe 绝对路径 @@ -56,11 +57,104 @@ def path_optimizer(comp_path): app_path_split = comp_path.replace('\\', '/').split('/') return '/'.join(list(filter(not_empty, app_path_split))) +def _comp_info_cmd(comp_mk): + kcfg = os.environ.get('KCONFIG_CONFIG') or 'config.mk' + # comp_info_tell.mk 会 include 组件 mk;有些组件 mk 自己定义了“第一个目标”, + # 不显式指定目标时 make 会默认构建错误目标(常见表现:尝试构建 `config/` 目录)。 + # 这里强制指定目标 `all`,只输出组件信息。 + return 'make --no-print-directory -f comp_info_tell.mk COMP_MK=' + comp_mk + ' KCONFIG_CONFIG=' + kcfg + ' all' + +def _read_src_file(rel_path): + if not rel_path: + return [] + path = rel_path if os.path.isabs(rel_path) else os.path.join(HELIOS_ROOT, rel_path.replace('/', os.sep)) + if not os.path.isfile(path): + return [] + with open(path, 'r', encoding='utf-8', errors='ignore') as f: + return list(filter(not_empty, f.read().split())) + +def _parse_comp_info(ret): + fields = {} + src_files = {} + for line in ret.splitlines(): + if not line or ':' not in line: + continue + key, val = line.split(':', 1) + key = key.strip() + val = val.lstrip() + if key == 'LOCAL_SRCS_FILE': + src_files['LOCAL_SRCS'] = val.strip() + elif key == 'LOCAL_SRCS_2_FILE': + src_files['LOCAL_SRCS_2'] = val.strip() + elif key == 'LOCAL_SRCS_3_FILE': + src_files['LOCAL_SRCS_3'] = val.strip() + else: + fields[key] = val.strip() + + if 'NAME' in fields and 'LOCAL_SRCS' in src_files: + local_srcs = _read_src_file(src_files.get('LOCAL_SRCS')) + local_srcs_2 = _read_src_file(src_files.get('LOCAL_SRCS_2')) + local_srcs_3 = _read_src_file(src_files.get('LOCAL_SRCS_3')) + return { + 'name_list': fields.get('NAME', '').split(), + 'global_incs': fields.get('GLOBAL_INCS', '').split(), + 'global_define': fields.get('GLOBAL_DEFINE', '').split(), + 'local_cflags': fields.get('LOCAL_CFLAGS', '').split(), + 'local_archives': fields.get('LOCAL_ARCHIVES', '').split(), + 'local_srcs': local_srcs, + 'local_srcs_2': local_srcs_2, + 'local_srcs_3': local_srcs_3, + 'local_incs': fields.get('LOCAL_INCS', '').split(), + 'local_define': fields.get('LOCAL_DEFINE', '').split(), + 'comp_deps': [path_optimizer(x) for x in fields.get('COMP_DEPS', '').split()], + } + + # 兼容:comp_info_tell.mk 直接输出 LOCAL_SRCS/LOCAL_SRCS_2/LOCAL_SRCS_3(可能为空), + # 不再强制要求 *_FILE 形式。 + if 'NAME' in fields: + return { + 'name_list': fields.get('NAME', '').split(), + 'global_incs': fields.get('GLOBAL_INCS', '').split(), + 'global_define': fields.get('GLOBAL_DEFINE', '').split(), + 'local_cflags': fields.get('LOCAL_CFLAGS', '').split(), + 'local_archives': fields.get('LOCAL_ARCHIVES', '').split(), + 'local_srcs': fields.get('LOCAL_SRCS', '').split(), + 'local_srcs_2': fields.get('LOCAL_SRCS_2', '').split(), + 'local_srcs_3': fields.get('LOCAL_SRCS_3', '').split(), + 'local_incs': fields.get('LOCAL_INCS', '').split(), + 'local_define': fields.get('LOCAL_DEFINE', '').split(), + 'comp_deps': [path_optimizer(x) for x in fields.get('COMP_DEPS', '').split()], + } + + regex = re.compile(r'NAME: (.*)\nGLOBAL_INCS: (.*)\nGLOBAL_DEFINE: (.*)\nLOCAL_CFLAGS: (.*)\nLOCAL_ARCHIVES: (.*)\nLOCAL_SRCS: (.*)\nLOCAL_SRCS_2: (.*)\nLOCAL_SRCS_3: (.*)\nLOCAL_INCS: (.*)\nLOCAL_DEFINE: (.*)\nCOMP_DEPS: (.*)\n') + mo = regex.findall(ret) + if not mo: + return None + row = mo[0] + return { + 'name_list': row[0].split(), + 'global_incs': row[1].split(), + 'global_define': row[2].split(), + 'local_cflags': row[3].split(), + 'local_archives': row[4].split(), + 'local_srcs': row[5].split(), + 'local_srcs_2': row[6].split(), + 'local_srcs_3': row[7].split(), + 'local_incs': row[8].split(), + 'local_define': row[9].split(), + 'comp_deps': [path_optimizer(x) for x in row[10].split()], + } + animation_idx = 0 +# Windows/cmd 写 build.log 或非 TTY 时 \b 无法原地覆盖,会刷出一长串 |/-\ 像乱码 +_animation_enabled = sys.platform != 'win32' and getattr(sys.stdout, 'isatty', lambda: False)() + def wait_animation(): global animation_idx + if not _animation_enabled: + return animation = "|/-\\" - if(animation_idx >= 4): + if animation_idx >= 4: animation_idx = 0 print('\b\b' + animation[animation_idx] + ' ', end='', flush=True) animation_idx += 1 @@ -73,24 +167,26 @@ def search_for_deps(comp_path): return comp_mk = comp_path + '/' + comp_path.split('/')[-1] + '.mk' - cmd = 'make --no-print-directory -f comp_info_tell.mk' + ' COMP_MK=' + comp_mk + cmd = _comp_info_cmd(comp_mk) ret = run_cmd_capture(cmd).decode(encoding='utf-8', errors='ignore') if not ret: raise RuntimeError('cmd [%s] execution error' % cmd) - regex = re.compile(r'NAME: (.*)\nGLOBAL_INCS: (.*)\nGLOBAL_DEFINE: (.*)\nLOCAL_CFLAGS: (.*)\nLOCAL_ARCHIVES: (.*)\nLOCAL_SRCS: (.*)\nLOCAL_SRCS_2: (.*)\nLOCAL_SRCS_3: (.*)\nLOCAL_INCS: (.*)\nLOCAL_DEFINE: (.*)\nCOMP_DEPS: (.*)\n') - mo = regex.findall(ret) - - name_list = mo[0][0].split(' ') - global_incs = mo[0][1].split(' ') - global_define = mo[0][2].split(' ') - local_cflags = mo[0][3].split(' ') - local_archives = mo[0][4].split(' ') - local_srcs = mo[0][5].split(' ') - local_srcs_2 = mo[0][6].split(' ') - local_srcs_3 = mo[0][7].split(' ') - local_incs = mo[0][8].split(' ') - local_define = mo[0][9].split(' ') - comp_deps = mo[0][10].split(' ') + parsed = _parse_comp_info(ret) + if not parsed: + snippet = ret.strip()[:1500] + raise RuntimeError('comp_info parse failed for %s (cwd=%s); make output:\n%s' % (comp_mk, os.getcwd(), snippet)) + + name_list = parsed['name_list'] + global_incs = parsed['global_incs'] + global_define = parsed['global_define'] + local_cflags = parsed['local_cflags'] + local_archives = parsed['local_archives'] + local_srcs = parsed['local_srcs'] + local_srcs_2 = parsed['local_srcs_2'] + local_srcs_3 = parsed['local_srcs_3'] + local_incs = parsed['local_incs'] + local_define = parsed['local_define'] + comp_deps = parsed['comp_deps'] ''' print('', flush=True) @@ -146,23 +242,38 @@ def search_for_deps(comp_path): if 'COMP_DEPS' in dep_dict[comp_path]: for comp in dep_dict[comp_path]['COMP_DEPS']: - search_for_deps(comp) + search_for_deps(path_optimizer(comp)) + +def _iter_comp_deps(component): + if 'COMP_DEPS' not in dep_dict[component]: + return + for comp in dep_dict[component]['COMP_DEPS']: + comp = path_optimizer(comp) + if comp and comp != component and comp in dep_dict: + yield comp def dependency_proc(component, last = None): global dep_dict + component = path_optimizer(component) wait_animation() + if component not in dep_dict: + return if 'COMP_DEPS' in dep_dict[component]: - if last: + if last and last in dep_dict: last_dep = dep_dict[last]['COMP_DEPS'] for dep in dep_dict[component]['COMP_DEPS']: - if dep not in last_dep: + dep = path_optimizer(dep) + if dep and dep not in last_dep: last_dep.append(dep) - for comp in dep_dict[component]['COMP_DEPS']: + for comp in _iter_comp_deps(component): dependency_proc(comp, component) def compile_option_proc(component, last = []): wait_animation() global dep_dict + component = path_optimizer(component) + if component not in dep_dict: + return if 'LOCAL_INCS' in dep_dict[component]: for inc in dep_dict[component]['LOCAL_INCS']: if 'INC_COLLECT' not in dep_dict[component]: @@ -195,15 +306,11 @@ def compile_option_proc(component, last = []): if 'DEF_COLLECT' in dep_dict[lst] and define not in dep_dict[lst]['DEF_COLLECT']: if 'COMP_DEPS' in dep_dict[lst] and component in dep_dict[lst]['COMP_DEPS']: dep_dict[lst]['DEF_COLLECT'].append(define) - if 'LOCAL_DEFINE' in dep_dict[component]: - for define in dep_dict[component]['LOCAL_DEFINE']: - if 'DEF_COLLECT' not in dep_dict[component]: - dep_dict[component]['DEF_COLLECT'] = [] - if define not in dep_dict[component]['DEF_COLLECT']: - dep_dict[component]['DEF_COLLECT'].append(define) + # LOCAL_DEFINE 不写入 DEF_COLLECT:compilerules.mk å·² include 组件 mk, + # 直接读 $($(NAME)_DEFINE),避免 Windows 下 echo/env 往返时引号被截断(MICROPY_BUILD_DATE)。 if 'COMP_DEPS' in dep_dict[component]: last.append(component) - for comp in dep_dict[component]['COMP_DEPS']: + for comp in _iter_comp_deps(component): compile_option_proc(comp, last) last = [] @@ -211,19 +318,28 @@ def compile_proc(): comp_archive_list = [] user_archive_list = [] for k,v in dep_dict.items(): - if 'LOCAL_SRCS' in v and v['LOCAL_SRCS']: - archive = os.environ['OUTPUT_OBJ_PATH'] + '/' + k + '/lib' + k.split('/')[-1] + '.a' + # 说明: + # - 早期做法依赖 comp_info_tell.mk 打印完整 LOCAL_SRCS,用于判断“是否需要编译该组件”; + # 但在 Windows 环境下 LOCAL_SRCS 过长会导致 Make 输出被截断/解析失败。 + # - 实际上 compilerules.mk 会直接 include 组件 mk 并读取 $(NAME)_SRCS 来决定要编译哪些源文件。 + # 因此这里改为:对 dep_dict 中的组件都尝试构建 archive,构建后仅在文件存在时加入链接列表。 + archive = os.environ['OUTPUT_OBJ_PATH'] + '/' + k + '/lib' + k.split('/')[-1] + '.a' + cmd = 'make --no-print-directory -j12 -f compilerules.mk %s' % archive + os.environ['COMP_PATH'] = k + if 'INC_COLLECT' in v and v['INC_COLLECT']: + comp_iflags = ' '.join(v['INC_COLLECT']) + os.environ['COMP_IFLAGS'] = comp_iflags + else: + os.environ.pop('COMP_IFLAGS', None) + if 'DEF_COLLECT' in v and v['DEF_COLLECT']: + comp_dflags = ' '.join(v['DEF_COLLECT']) + os.environ['COMP_DFLAGS'] = comp_dflags + else: + os.environ.pop('COMP_DFLAGS', None) + if system_cmd(cmd): + raise RuntimeError('cmd [%s] execution error' % cmd) + if os.path.exists(archive): comp_archive_list.append(archive) - cmd = 'make --no-print-directory -j12 -f compilerules.mk' - os.environ['COMP_PATH'] = k - if 'INC_COLLECT' in v and v['INC_COLLECT']: - comp_iflags = ' '.join(v['INC_COLLECT']) - os.environ['COMP_IFLAGS'] = comp_iflags - if 'DEF_COLLECT' in v and v['DEF_COLLECT']: - comp_dflags = ' '.join(v['DEF_COLLECT']) - os.environ['COMP_DFLAGS'] = comp_dflags - if system_cmd(cmd): - raise RuntimeError('cmd [%s] execution error' % cmd) if 'LOCAL_ARCHIVES' in v and v['LOCAL_ARCHIVES']: user_archive_list.extend(list(map(lambda x : k + '/' + x, v['LOCAL_ARCHIVES']))) @@ -243,6 +359,8 @@ def compile_proc(): raise RuntimeError('cmd [make -f link.mk] execution error') def build_proc(app): + os.chdir(HELIOS_ROOT) + os.environ.setdefault('KCONFIG_CONFIG', 'config.mk') print('\n[searching for all components ...] ', end = '', flush=True) search_for_deps(app) print('') diff --git a/2.sdk/Helios_SDK/compilerules.mk b/2.sdk/Helios_SDK/compilerules.mk index 77858b2d..a5f250cb 100644 --- a/2.sdk/Helios_SDK/compilerules.mk +++ b/2.sdk/Helios_SDK/compilerules.mk @@ -19,14 +19,22 @@ make_dep_fnc = $(OUTPUT_OBJ_PATH)/$(strip $(1)).d COMP_MK = $(call make_mk_fnc,$(COMP_PATH)) include $(COMP_MK) -OBJECTS_1 := $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS))), $(call make_obj_fnc, $(n))) -DEPENDS := $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS))), $(call make_dep_fnc, $(n))) -OBJECTS_2 := $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS_2))), $(call make_obj_fnc, $(n))) -DEPENDS += $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS_2))), $(call make_dep_fnc, $(n))) -OBJECTS_3 := $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS_3))), $(call make_obj_fnc, $(n))) -DEPENDS += $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS_3))), $(call make_dep_fnc, $(n))) +OBJECTS_1 := $(foreach n, $(addprefix $(COMP_PATH)/,$(sort $(strip $($(NAME)_SRCS)))), $(call make_obj_fnc, $(n))) +DEPENDS := $(foreach n, $(addprefix $(COMP_PATH)/,$(sort $(strip $($(NAME)_SRCS)))), $(call make_dep_fnc, $(n))) +OBJECTS_2 := $(foreach n, $(addprefix $(COMP_PATH)/,$(sort $(strip $($(NAME)_SRCS_2)))), $(call make_obj_fnc, $(n))) +DEPENDS += $(foreach n, $(addprefix $(COMP_PATH)/,$(sort $(strip $($(NAME)_SRCS_2)))), $(call make_dep_fnc, $(n))) +OBJECTS_3 := $(foreach n, $(addprefix $(COMP_PATH)/,$(sort $(strip $($(NAME)_SRCS_3)))), $(call make_obj_fnc, $(n))) +DEPENDS += $(foreach n, $(addprefix $(COMP_PATH)/,$(sort $(strip $($(NAME)_SRCS_3)))), $(call make_dep_fnc, $(n))) ARCHIVE := $(OUTPUT_OBJ_PATH)/$(COMP_PATH)/lib$(notdir $(COMP_PATH)).a +# 说明:宏参数里如果包含双引号,Windows 下 make 常通过 /usr/bin/bash 执行命令行, +# 会把双引号当作 shell 语法吞掉,导致 gcc 看到的 -D 宏丢失引号(进而报 undeclared / missing terminating)。 +# 这里对 MICROPY_BUILD_DATE 做特殊处理:把值包成 C 字符串,并用反斜杠转义双引号,使其穿透到 gcc。 +DFLAGS_EXPANDED := $(foreach d,$(DFLAGS) $(COMP_DFLAGS) $($(NAME)_DEFINE),\ + $(if $(filter MICROPY_BUILD_DATE=%,$(d)),\ + -DMICROPY_BUILD_DATE='"$(patsubst MICROPY_BUILD_DATE=%,%,$(d))"',\ + -D$(d))) + $(ARCHIVE): $(OBJECTS_1) $(OBJECTS_2) $(OBJECTS_3) @echo ----- archiving $@ @-rm -f $@ @@ -43,7 +51,7 @@ endif $(OBJECTS_1) $(OBJECTS_2) $(OBJECTS_3):$(OUTPUT_OBJ_PATH)/%.o:% @echo ----- compiling $< @mkdir -p $(OUTPUT_OBJ_PATH)/$(dir $<) - $(Q)$(cc) $($(NAME)_CFLAGS) -c $< $(foreach i, $(COMP_IFLAGS) $(IFLAGS), -I$(i)) $(foreach d, $(DFLAGS) $(COMP_DFLAGS), -D$(d)) -o $@ -MMD -MF $(OUTPUT_OBJ_PATH)/$<.d.tmp -MP || (rm -f $(ARCHIVE); exit 1) + $(Q)$(cc) $($(NAME)_CFLAGS) -c $< $(foreach i, $(COMP_IFLAGS) $(IFLAGS), -I$(i)) $(DFLAGS_EXPANDED) -o $@ -MMD -MF $(OUTPUT_OBJ_PATH)/$<.d.tmp -MP || (rm -f $(ARCHIVE); exit 1) $(Q)sed -i '/\\:\\/s/\\:\\/:\\/g' $(OUTPUT_OBJ_PATH)/$<.d.tmp $(Q)mv $(OUTPUT_OBJ_PATH)/$<.d.tmp $(OUTPUT_OBJ_PATH)/$<.d diff --git a/2.sdk/Helios_SDK/link.mk b/2.sdk/Helios_SDK/link.mk index 854c0b3d..b1440ccd 100644 --- a/2.sdk/Helios_SDK/link.mk +++ b/2.sdk/Helios_SDK/link.mk @@ -14,6 +14,12 @@ USE_WHOLE_ARCHIVE ?= y +# 与 compilerules.mk 保持一致:对 MICROPY_BUILD_DATE 做引号穿透,避免 bash/cmd 吞引号 +DFLAGS_EXPANDED := $(foreach d,$(DFLAGS) $(COMP_DFLAGS),\ + $(if $(filter MICROPY_BUILD_DATE=%,$(d)),\ + -DMICROPY_BUILD_DATE='"$(patsubst MICROPY_BUILD_DATE=%,%,$(d))"',\ + -D$(d))) + $(TARGET_BIN): $(TARGET_ELF) ifeq ($(strip $(PLAT)),Qualcomm) $(Q)$(OBJCOPY_PY) --bin $^ --output $@ @@ -32,7 +38,7 @@ $(TARGET_HEX): $(TARGET_ELF) $(OUTPUT_LD_FILE): $(LD_FILE) @echo - $(Q)$(CC) $(foreach inc, $(OUTPUT_SCRIPTS_INCS), -I$(inc)) $(CFLAGS) $(foreach d, $(DFLAGS) $(COMP_DFLAGS), -D$(d)) -E -P -x c -MD -MT $@ -MF $@.d -o $@ -c $< + $(Q)$(CC) $(foreach inc, $(OUTPUT_SCRIPTS_INCS), -I$(inc)) $(CFLAGS) $(DFLAGS_EXPANDED) -E -P -x c -MD -MT $@ -MF $@.d -o $@ -c $< @echo ----- $@ updated $(TARGET_ELF): $(OUTPUT_LD_FILE) $(COMP_ARCHIVES) $(USER_ARCHIVES) $(STD_LIBS) diff --git a/2.sdk/Helios_SDK/services/microPython/microPython.mk b/2.sdk/Helios_SDK/services/microPython/microPython.mk index 6a3e7bc0..afe5b142 100644 --- a/2.sdk/Helios_SDK/services/microPython/microPython.mk +++ b/2.sdk/Helios_SDK/services/microPython/microPython.mk @@ -1,873 +1,875 @@ - -NAME := MICROPYTHON - -include config/$(KCONFIG_CONFIG) - -PY_SRCS = \ - py/argcheck.c \ - py/asmarm.c \ - py/asmbase.c \ - py/asmthumb.c \ - py/asmx64.c \ - py/asmx86.c \ - py/asmxtensa.c \ - py/bc.c \ - py/binary.c \ - py/builtinevex.c \ - py/builtinhelp.c \ - py/builtinimport.c \ - py/compile.c \ - py/emitbc.c \ - py/emitcommon.c \ - py/emitglue.c \ - py/emitinlinethumb.c \ - py/emitinlinextensa.c \ - py/emitnarm.c \ - py/emitnthumb.c \ - py/emitnx64.c \ - py/emitnx86.c \ - py/emitnxtensa.c \ - py/emitnxtensawin.c \ - py/formatfloat.c \ - py/frozenmod.c \ - py/gc.c \ - py/lexer.c \ - py/malloc.c \ - py/map.c \ - py/modarray.c \ - py/modbuiltins.c \ - py/modcmath.c \ - py/modcollections.c \ - py/modgc.c \ - py/modio.c \ - py/modmath.c \ - py/modmicropython.c \ - py/modstruct.c \ - py/modsys.c \ - py/modthread.c \ - py/moduerrno.c \ - py/mpprint.c \ - py/mpstate.c \ - py/mpz.c \ - py/nativeglue.c \ - py/nlr.c \ - py/nlrpowerpc.c \ - py/nlrsetjmp.c \ - py/nlrthumb.c \ - py/nlrx64.c \ - py/nlrx86.c \ - py/nlrxtensa.c \ - py/obj.c \ - py/objarray.c \ - py/objattrtuple.c \ - py/objbool.c \ - py/objboundmeth.c \ - py/objcell.c \ - py/objclosure.c \ - py/objcomplex.c \ - py/objdeque.c \ - py/objdict.c \ - py/objenumerate.c \ - py/objexcept.c \ - py/objfilter.c \ - py/objfloat.c \ - py/objfun.c \ - py/objgenerator.c \ - py/objgetitemiter.c \ - py/objint.c \ - py/objint_longlong.c \ - py/objint_mpz.c \ - py/objlist.c \ - py/objmap.c \ - py/objmodule.c \ - py/objnamedtuple.c \ - py/objnone.c \ - py/objobject.c \ - py/objpolyiter.c \ - py/objproperty.c \ - py/objrange.c \ - py/objreversed.c \ - py/objset.c \ - py/objsingleton.c \ - py/objslice.c \ - py/objstr.c \ - py/objstringio.c \ - py/objstrunicode.c \ - py/objtuple.c \ - py/objtype.c \ - py/objzip.c \ - py/opmethods.c \ - py/pairheap.c \ - py/parse.c \ - py/parsenum.c \ - py/parsenumbase.c \ - py/persistentcode.c \ - py/profile.c \ - py/pystack.c \ - py/qstr.c \ - py/reader.c \ - py/repl.c \ - py/ringbuf.c \ - py/runtime.c \ - py/runtime_utils.c \ - py/scheduler.c \ - py/scope.c \ - py/sequence.c \ - py/showbc.c \ - py/smallint.c \ - py/stackctrl.c \ - py/stream.c \ - py/unicode.c \ - py/vm.c \ - py/vstr.c \ - py/warning.c - - -EXTMOD_SRCS = \ - extmod/mb_ussl_error.c \ - extmod/modaes.c \ - extmod/modhash.c \ - extmod/moduasyncio.c \ - extmod/moduwebsocket.c \ - extmod/modubinascii.c \ - extmod/moducryptolib.c \ - extmod/moductypes.c \ - extmod/moduhashlib.c \ - extmod/modujson.c \ - extmod/modurandom.c \ - extmod/modure.c \ - extmod/moduselect.c \ - extmod/modussl_mbedtls.c \ - extmod/moduzlib.c \ - extmod/utime_mphal.c \ - extmod/vfs.c \ - extmod/vfs_blockdev.c \ - extmod/vfs_efs.c \ - extmod/vfs_efs_file.c \ - extmod/vfs_fat.c \ - extmod/vfs_fat_file.c \ - extmod/vfs_lfs.c \ - extmod/vfs_reader.c \ - extmod/vfs_temp.c \ - extmod/vfs_temp_file.c \ - extmod/vfs_fat_sdio.c \ - extmod/vfs_fat_sdio_file.c \ - lib/littlefs/lfs1.c \ - lib/littlefs/lfs1_util.c \ - lib/littlefs/lfs2.c \ - lib/littlefs/lfs2_util.c \ - lib/mp-readline/readline.c \ - lib/netutils/netutils.c \ - lib/timeutils/timeutils.c \ - lib/utils/interrupt_char.c \ - lib/utils/pyexec.c \ - lib/utils/stdout_helpers.c \ - lib/utils/sys_stdio_mphal.c - - -QPY_SRCS = \ - ports/quectel/core/build/_frozen_mpy.c \ - ports/quectel/core/source/random.c \ - ports/quectel/core/source/audio_audio.c \ - ports/quectel/core/source/audio_handle.c \ - ports/quectel/core/source/audio_queue.c \ - ports/quectel/core/source/audio_record.c \ - ports/quectel/core/source/audio_tts.c \ - ports/quectel/core/source/audiocodec_rt5616.c \ - ports/quectel/core/source/callbackdeal.c \ - ports/quectel/core/source/camera_capture.c \ - ports/quectel/core/source/camera_preview.c \ - ports/quectel/core/source/camera_scandecode.c \ - ports/quectel/core/source/devreport.c \ - ports/quectel/core/source/gccollect.c \ - ports/quectel/core/source/help.c \ - ports/quectel/core/source/linklist.c \ - ports/quectel/core/source/machine_extint.c \ - ports/quectel/core/source/machine_hw_spi.c \ - ports/quectel/core/source/machine_iic.c \ - ports/quectel/core/source/machine_iic_simulation.c \ - ports/quectel/core/source/machine_keypad.c \ - ports/quectel/core/source/machine_lcd.c \ - ports/quectel/core/source/machine_nandflash.c \ - ports/quectel/core/source/machine_pin.c \ - ports/quectel/core/source/machine_rtc.c \ - ports/quectel/core/source/machine_timer.c \ - ports/quectel/core/source/machine_uart.c \ - ports/quectel/core/source/machine_wdt.c \ - ports/quectel/core/source/misc_adc.c \ - ports/quectel/core/source/misc_power.c \ - ports/quectel/core/source/misc_powerkey.c \ - ports/quectel/core/source/misc_pwm.c \ - ports/quectel/core/source/misc_temperature.c \ - ports/quectel/core/source/misc_usb.c \ - ports/quectel/core/source/misc_usbnet.c \ - ports/quectel/core/source/modatcmd.c \ - ports/quectel/core/source/modaudio.c \ - ports/quectel/core/source/modaudiocodec.c \ - ports/quectel/core/source/modble.c \ - ports/quectel/core/source/modbt.c \ - ports/quectel/core/source/modcamera.c \ - ports/quectel/core/source/modcelllocator.c \ - ports/quectel/core/source/modcelllocator_qpy.c \ - ports/quectel/core/source/locator.c \ - ports/quectel/core/source/modcsd.c \ - ports/quectel/core/source/moddatacall.c \ - ports/quectel/core/source/moddev.c \ - ports/quectel/core/source/modethernet.c \ - ports/quectel/core/source/modethernet_dm9051.c \ - ports/quectel/core/source/modethernet_w5500.c \ - ports/quectel/core/source/modethernet_ch395.c \ - ports/quectel/core/source/modexample.c \ - ports/quectel/core/source/modfota.c \ - ports/quectel/core/source/modgnss.c \ - ports/quectel/core/source/modlpm.c \ - ports/quectel/core/source/modlvgl.c \ - ports/quectel/core/source/modlvgl_other_hander.c \ - ports/quectel/core/source/modlwm2m.c \ - ports/quectel/core/source/modmachine.c \ - ports/quectel/core/source/modmisc.c \ - ports/quectel/core/source/modnb.c \ - ports/quectel/core/source/modnet.c \ - ports/quectel/core/source/modostimer.c \ - ports/quectel/core/source/modpoc.c \ - ports/quectel/core/source/modqrcode.c \ - ports/quectel/core/source/modrtmp.c \ - ports/quectel/core/source/modsecuredata.c \ - ports/quectel/core/source/modsensor.c \ - ports/quectel/core/source/modsha1.c \ - ports/quectel/core/source/modsim.c \ - ports/quectel/core/source/modslipif.c \ - ports/quectel/core/source/modsms.c \ - ports/quectel/core/source/modussd.c \ - ports/quectel/core/source/modsocket.c \ - ports/quectel/core/source/modwifi.c \ - ports/quectel/core/source/modtp.c \ - ports/quectel/core/source/moduos.c \ - ports/quectel/core/source/modutils.c \ - ports/quectel/core/source/modutime.c \ - ports/quectel/core/source/modvoicecall.c \ - ports/quectel/core/source/modwifilocator.c \ - ports/quectel/core/source/modwifiscan.c \ - ports/quectel/core/source/mphalport.c \ - ports/quectel/core/source/mpthreadport.c \ - ports/quectel/core/source/nb_aep.c \ - ports/quectel/core/source/nb_oc.c \ - ports/quectel/core/source/nb_onenet.c \ - ports/quectel/core/source/quecpython.c \ - ports/quectel/core/source/sensor_sn95500.c \ - ports/quectel/core/source/sensor_icckey.c \ - ports/quectel/core/source/sensor_gnss.c \ - ports/quectel/core/source/sensor_handmic_key.c \ - ports/quectel/core/source/tp_gt9xx.c \ - ports/quectel/core/source/tp_xpt2046.c \ - ports/quectel/core/source/tp_cst816.c \ - ports/quectel/core/source/tp_ft6x36.c \ - ports/quectel/core/source/tp_st1615.c \ - ports/quectel/core/source/modGsensor.c \ - ports/quectel/core/source/modGsensor_SC7A20.c \ - ports/quectel/core/source/modHsensor.c \ - ports/quectel/core/source/modHsensor_GH3018.c \ - ports/quectel/core/source/modHsensor_HX3918.c \ - ports/quectel/core/source/modgpio_encoder.c \ - ports/quectel/core/source/modVideoCall.c \ - ports/quectel/core/source/modVideoCall_juphoon.c \ - ports/quectel/core/source/modrsa.c \ - ports/quectel/core/source/modsftp.c \ - ports/quectel/core/source/utils_crc32.c \ - ports/quectel/core/source/modwebserver.c \ - ports/quectel/core/source/http_parser.c \ - ports/quectel/core/source/modethernet_yt8512h.c \ - ports/quectel/core/source/sim_esim.c \ - ports/quectel/core/source/modG711.c \ - ports/quectel/core/source/modG729.c \ - ports/quectel/core/source/modG722.c \ - ports/quectel/core/source/modcan_mcp2515.c \ - ports/quectel/core/source/modextuart_wk2114.c \ - ports/quectel/core/source/modgpio_encoder.c \ - ports/quectel/core/source/modextgpio_aw9523.c \ - ports/quectel/core/source/modalipay.c \ - ports/quectel/core/source/machine_key.c \ - ports/quectel/core/source/lpm_wakeup.c \ - ports/quectel/core/source/modnetwork.c \ - ports/quectel/core/source/modwlan_ASR5803.c \ - ports/quectel/core/source/machine_soft_spi.c \ - ports/quectel/core/source/modwlan.c\ - ports/quectel/core/source/code128_p.c \ - ports/quectel/core/source/modmask.c \ - ports/quectel/core/source/modVad.c \ - ports/quectel/core/source/machine_one_wire.c\ - ports/quectel/core/source/modalipay_collection.c \ - ports/quectel/core/source/modsif.c\ - ports/quectel/core/source/jrtc.c \ - ports/quectel/core/source/modnfc.c \ - ports/quectel/core/source/nfc_sl6320.c \ - ports/quectel/core/source/modstk.c \ - ports/quectel/core/source/modalipay_se.c \ - ports/quectel/core/source/modvoip.c \ - ports/quectel/core/source/modipsec.c \ - ports/quectel/core/source/modecdsa.c \ - ports/quectel/core/source/modecdh.c \ - ports/quectel/core/source/moddlms.c \ - ports/quectel/core/source/modai_rtc.c - -ifeq ($(CONFIG_QUECTHING), y) -ifeq ($(strip $(PLAT)),RDA) -QPY_SRCS += ../../components/quecsdk/cloud/python/modquecIot-BC25old.c -else -QPY_SRCS += ../../components/quecsdk/cloud/python/modquecIot.c -endif -endif - - -$(NAME)_ARCHIVES = \ - ports/quectel/core/source/libimslvad.a - -ifeq ($(CONFIG_USQLITE), y) -EXTMOD_SRCS += lib/usqlite/usqlite_connection.c \ - lib/usqlite/usqlite_cursor.c \ - lib/usqlite/usqlite_row.c \ - lib/usqlite/usqlite_file.c \ - lib/usqlite/usqlite_mem.c \ - lib/usqlite/usqlite_vfs.c \ - lib/usqlite/usqlite_utils.c \ - lib/usqlite/usqlite.c \ - lib/usqlite/usqlite_module.c -$(NAME)_INCS += lib/usqlite -endif - - -ifeq ($(CONFIG_LVGL), y) - -LVGL_SRCS_1 += \ -lib/lvgl/src/extra/layouts/flex/lv_flex.c \ -lib/lvgl/src/extra/layouts/grid/lv_grid.c \ -lib/lvgl/src/extra/libs/bmp/lv_bmp.c \ -lib/lvgl/src/extra/libs/ffmpeg/lv_ffmpeg.c \ -lib/lvgl/src/extra/libs/freetype/lv_freetype.c \ -lib/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c \ -lib/lvgl/src/extra/libs/fsdrv/lv_fs_posix.c \ -lib/lvgl/src/extra/libs/fsdrv/lv_fs_helios.c \ -lib/lvgl/src/extra/libs/fsdrv/lv_fs_stdio.c \ -lib/lvgl/src/extra/libs/fsdrv/lv_fs_win32.c \ -lib/lvgl/src/extra/libs/gif/gifdec.c \ -lib/lvgl/src/extra/libs/gif/lv_gif.c \ -lib/lvgl/src/extra/libs/png/lodepng.c \ -lib/lvgl/src/extra/libs/png/lv_png.c \ -lib/lvgl/src/extra/libs/qrcode/lv_qrcode.c \ -lib/lvgl/src/extra/libs/qrcode/qrcodegen.c \ -lib/lvgl/src/extra/libs/rlottie/lv_rlottie.c \ -lib/lvgl/src/extra/libs/sjpg/lv_sjpg.c \ -lib/lvgl/src/extra/libs/sjpg/tjpgd.c \ -lib/lvgl/src/extra/lv_extra.c \ -lib/lvgl/src/extra/others/gridnav/lv_gridnav.c \ -lib/lvgl/src/extra/others/monkey/lv_monkey.c \ -lib/lvgl/src/extra/others/snapshot/lv_snapshot.c \ -lib/lvgl/src/extra/themes/basic/lv_theme_basic.c \ -lib/lvgl/src/extra/themes/default/lv_theme_default.c \ -lib/lvgl/src/extra/themes/mono/lv_theme_mono.c \ -lib/lvgl/src/extra/widgets/animimg/lv_animimg.c \ -lib/lvgl/src/extra/widgets/calendar/lv_calendar.c \ -lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_arrow.c \ -lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_dropdown.c \ -lib/lvgl/src/extra/widgets/chart/lv_chart.c \ -lib/lvgl/src/extra/widgets/colorwheel/lv_colorwheel.c \ -lib/lvgl/src/extra/widgets/imgbtn/lv_imgbtn.c \ -lib/lvgl/src/extra/widgets/keyboard/lv_keyboard.c \ -lib/lvgl/src/extra/widgets/led/lv_led.c \ -lib/lvgl/src/extra/widgets/list/lv_list.c \ -lib/lvgl/src/extra/widgets/menu/lv_menu.c \ -lib/lvgl/src/extra/widgets/meter/lv_meter.c \ -lib/lvgl/src/extra/widgets/msgbox/lv_msgbox.c \ -lib/lvgl/src/extra/widgets/span/lv_span.c \ -lib/lvgl/src/extra/widgets/spinbox/lv_spinbox.c \ -lib/lvgl/src/extra/widgets/spinner/lv_spinner.c \ -lib/lvgl/src/extra/widgets/tabview/lv_tabview.c \ -lib/lvgl/src/extra/widgets/tileview/lv_tileview.c \ -lib/lvgl/src/extra/widgets/win/lv_win.c \ -lib/lvgl/src/extra/others/ime/lv_ime_pinyin.c \ -lib/lvgl/src/core/lv_disp.c \ -lib/lvgl/src/core/lv_group.c \ -lib/lvgl/src/core/lv_indev.c \ -lib/lvgl/src/core/lv_indev_scroll.c \ -lib/lvgl/src/core/lv_obj.c \ -lib/lvgl/src/core/lv_obj_class.c \ -lib/lvgl/src/core/lv_obj_draw.c \ -lib/lvgl/src/core/lv_obj_pos.c \ -lib/lvgl/src/core/lv_obj_scroll.c \ -lib/lvgl/src/core/lv_obj_style.c \ -lib/lvgl/src/core/lv_obj_style_gen.c \ -lib/lvgl/src/core/lv_obj_tree.c \ -lib/lvgl/src/core/lv_event.c \ -lib/lvgl/src/core/lv_refr.c \ -lib/lvgl/src/core/lv_theme.c \ -lib/lvgl/src/draw/lv_draw_arc.c \ -lib/lvgl/src/draw/lv_draw.c \ -lib/lvgl/src/draw/lv_draw_img.c \ -lib/lvgl/src/draw/lv_draw_label.c \ -lib/lvgl/src/draw/lv_draw_layer.c \ -lib/lvgl/src/draw/lv_draw_line.c \ -lib/lvgl/src/draw/lv_draw_mask.c \ -lib/lvgl/src/draw/lv_draw_rect.c \ -lib/lvgl/src/draw/lv_draw_transform.c \ -lib/lvgl/src/draw/lv_draw_triangle.c \ -lib/lvgl/src/draw/lv_img_buf.c \ -lib/lvgl/src/draw/lv_img_cache.c \ -lib/lvgl/src/draw/lv_img_decoder.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_arc.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_bg.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_composite.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_img.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_label.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_line.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_mask.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_polygon.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_rect.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_stack_blur.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_texture_cache.c \ -lib/lvgl/src/draw/sdl/lv_draw_sdl_utils.c \ -lib/lvgl/src/draw/sw/lv_draw_sw.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_arc.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_blend.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_img.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_letter.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_line.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_rect.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_polygon.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_gradient.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_dither.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_transform.c \ -lib/lvgl/src/draw/sw/lv_draw_sw_layer.c \ -lib/lvgl/src/font/lv_font.c \ -lib/lvgl/src/font/lv_font_fmt_txt.c \ -lib/lvgl/src/font/lv_font_loader.c \ -lib/lvgl/src/font/lv_font_dejavu_16_persian_hebrew.c \ -lib/lvgl/src/font/lv_font_montserrat_8.c \ -lib/lvgl/src/font/lv_font_montserrat_10.c \ -lib/lvgl/src/font/lv_font_montserrat_12.c \ -lib/lvgl/src/font/lv_font_montserrat_12_subpx.c \ -lib/lvgl/src/font/lv_font_montserrat_14.c \ -lib/lvgl/src/font/lv_font_montserrat_16.c \ -lib/lvgl/src/font/lv_font_montserrat_18.c \ -lib/lvgl/src/font/lv_font_montserrat_20.c \ -lib/lvgl/src/font/lv_font_montserrat_22.c \ -lib/lvgl/src/font/lv_font_montserrat_24.c \ -lib/lvgl/src/font/lv_font_montserrat_26.c \ -lib/lvgl/src/font/lv_font_montserrat_28.c \ -lib/lvgl/src/font/lv_font_montserrat_28_compressed.c \ -lib/lvgl/src/font/lv_font_montserrat_30.c \ -lib/lvgl/src/font/lv_font_montserrat_32.c \ -lib/lvgl/src/font/lv_font_montserrat_34.c \ -lib/lvgl/src/font/lv_font_montserrat_36.c \ -lib/lvgl/src/font/lv_font_montserrat_38.c \ -lib/lvgl/src/font/lv_font_montserrat_40.c \ -lib/lvgl/src/font/lv_font_montserrat_42.c \ -lib/lvgl/src/font/lv_font_montserrat_44.c \ -lib/lvgl/src/font/lv_font_montserrat_46.c \ -lib/lvgl/src/font/lv_font_montserrat_48.c \ -lib/lvgl/src/font/lv_font_simsun_16_cjk.c \ -lib/lvgl/src/font/lv_font_unscii_8.c \ -lib/lvgl/src/font/lv_font_unscii_16.c \ -lib/lvgl/src/font/lv_font_siyun_18.c \ -lib/lvgl/src/font/lv_font_arial_54.c \ -lib/lvgl/src/font/lv_font_siyuan_32.c \ -lib/lvgl/src/font/lv_font_sdSiyuan16.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_8.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_10.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_12.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_14.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_16.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_18.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_20.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_22.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_24.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_26.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_28.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_30.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_32.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_34.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_36.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_38.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_40.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_42.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_44.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_46.c \ -lib/lvgl/src/font/lv_font_SDsiyuan_48.c \ -lib/lvgl/src/font/lv_11_siyuan_light.c \ - -LVGL_SRCS_2 = \ -lib/lvgl/src/font/lv_14_ali.c \ -lib/lvgl/src/font/lv_font_HarmonyOS_Bold_60.c \ -lib/lvgl/src/font/lv_font_HarmonyOS_Bold_100.c \ -lib/lvgl/src/font/lv_font_HarmonyOS_Regular_28.c \ -lib/lvgl/src/font/lv_font_HarmonyOS_Regular_48.c \ -lib/lvgl/src/font/lv_font_HarmonyOS_Regular_20.c \ -lib/lvgl/src/font/lv_font_siyuan_Bold_26.c \ -lib/lvgl/src/font/lv_font_siyuan_Regular_12.c \ -lib/lvgl/src/font/lv_font_siyuan_Regular_14.c \ -lib/lvgl/src/font/lv_font_siyuan_Regular_16.c \ -lib/lvgl/src/font/lv_font_siyuan_Regular_18.c \ -lib/lvgl/src/font/lv_font_siyuan_Regular_20.c \ -lib/lvgl/src/font/lv_font_siyuan_Regular_22.c \ -lib/lvgl/src/font/lv_bold_18.c \ -lib/lvgl/src/font/lv_bold_34.c \ -lib/lvgl/src/font/lv_bold_48.c \ -lib/lvgl/src/font/lv_regular_12.c \ -lib/lvgl/src/font/lv_regular_14.c \ -lib/lvgl/src/font/lv_regular_18.c \ -lib/lvgl/src/font/lv_regular_20.c \ -lib/lvgl/src/font/lv_regular_22.c \ -lib/lvgl/src/font/lv_regular_24.c \ -lib/lvgl/src/font/lv_regular_29.c \ -lib/lvgl/src/font/lv_font_tianbo_10.c \ -lib/lvgl/src/font/lv_font_tianbo_12.c \ -lib/lvgl/src/font/lv_font_tianbo_14.c \ -lib/lvgl/src/font/lv_font_tianbo_16.c \ -lib/lvgl/src/font/lv_font_12_qs.c \ -lib/lvgl/src/font/lv_font_12.c \ -lib/lvgl/src/font/lv_font_21_light.c \ -lib/lvgl/src/font/lv_font_30_light.c \ -lib/lvgl/src/font/lv_font_14_simsum.c \ -lib/lvgl/src/font/lv_font_16_simsum.c \ -lib/lvgl/src/font/lv_font_18_simsum.c \ -lib/lvgl/src/font/lv_font_70_bold.c \ -lib/lvgl/src/font/lv_font_28_dial.c \ -lib/lvgl/src/font/lv_font_60_main_menu.c \ -lib/lvgl/src/font/lv_font_50_main_menu_e.c \ -lib/lvgl/src/font/K01_font_16_ALL.c \ -lib/lvgl/src/font/K01_font_30_DIAL.c \ -lib/lvgl/src/hal/lv_hal_disp.c \ -lib/lvgl/src/hal/lv_hal_indev.c \ -lib/lvgl/src/hal/lv_hal_tick.c \ -lib/lvgl/src/misc/lv_anim.c \ -lib/lvgl/src/misc/lv_anim_timeline.c \ -lib/lvgl/src/misc/lv_area.c \ -lib/lvgl/src/misc/lv_async.c \ -lib/lvgl/src/misc/lv_bidi.c \ -lib/lvgl/src/misc/lv_color.c \ -lib/lvgl/src/misc/lv_fs.c \ -lib/lvgl/src/misc/lv_gc.c \ -lib/lvgl/src/misc/lv_ll.c \ -lib/lvgl/src/misc/lv_log.c \ -lib/lvgl/src/misc/lv_lru.c \ -lib/lvgl/src/misc/lv_math.c \ -lib/lvgl/src/misc/lv_mem.c \ -lib/lvgl/src/misc/lv_printf.c \ -lib/lvgl/src/misc/lv_style.c \ -lib/lvgl/src/misc/lv_style_gen.c \ -lib/lvgl/src/misc/lv_timer.c \ -lib/lvgl/src/misc/lv_tlsf.c \ -lib/lvgl/src/misc/lv_txt.c \ -lib/lvgl/src/misc/lv_txt_ap.c \ -lib/lvgl/src/misc/lv_utils.c \ -lib/lvgl/src/widgets/lv_arc.c \ -lib/lvgl/src/widgets/lv_bar.c \ -lib/lvgl/src/widgets/lv_btn.c \ -lib/lvgl/src/widgets/lv_btnmatrix.c \ -lib/lvgl/src/widgets/lv_canvas.c \ -lib/lvgl/src/widgets/lv_checkbox.c \ -lib/lvgl/src/widgets/lv_dropdown.c \ -lib/lvgl/src/widgets/lv_img.c \ -lib/lvgl/src/widgets/lv_label.c \ -lib/lvgl/src/widgets/lv_line.c \ -lib/lvgl/src/widgets/lv_roller.c \ -lib/lvgl/src/widgets/lv_slider.c \ -lib/lvgl/src/widgets/lv_switch.c \ -lib/lvgl/src/widgets/lv_table.c \ -lib/lvgl/src/widgets/lv_textarea.c \ -lib/lvgl/freetype-2.11.1/src/autofit/autofit.c \ -lib/lvgl/freetype-2.11.1/src/base/ftbase.c \ -lib/lvgl/freetype-2.11.1/src/base/ftbbox.c \ -lib/lvgl/freetype-2.11.1/src/base/ftbdf.c \ -lib/lvgl/freetype-2.11.1/src/base/ftbitmap.c \ -lib/lvgl/freetype-2.11.1/src/base/ftcid.c \ -lib/lvgl/freetype-2.11.1/src/base/ftfstype.c \ -lib/lvgl/freetype-2.11.1/src/base/ftgasp.c \ -lib/lvgl/freetype-2.11.1/src/base/ftglyph.c \ -lib/lvgl/freetype-2.11.1/src/base/ftgxval.c \ -lib/lvgl/freetype-2.11.1/src/base/ftinit.c \ -lib/lvgl/freetype-2.11.1/src/base/ftmm.c \ -lib/lvgl/freetype-2.11.1/src/base/ftotval.c \ -lib/lvgl/freetype-2.11.1/src/base/ftpatent.c \ -lib/lvgl/freetype-2.11.1/src/base/ftpfr.c \ -lib/lvgl/freetype-2.11.1/src/base/ftstroke.c \ -lib/lvgl/freetype-2.11.1/src/base/ftsynth.c \ -lib/lvgl/freetype-2.11.1/src/base/fttype1.c \ -lib/lvgl/freetype-2.11.1/src/base/ftwinfnt.c \ -lib/lvgl/freetype-2.11.1/src/bdf/bdf.c \ -lib/lvgl/freetype-2.11.1/src/bzip2/ftbzip2.c \ -lib/lvgl/freetype-2.11.1/src/cache/ftcache.c \ -lib/lvgl/freetype-2.11.1/src/cff/cff.c \ -lib/lvgl/freetype-2.11.1/src/cid/type1cid.c \ -lib/lvgl/freetype-2.11.1/src/gzip/ftgzip.c \ -lib/lvgl/freetype-2.11.1/src/lzw/ftlzw.c \ -lib/lvgl/freetype-2.11.1/src/pcf/pcf.c \ -lib/lvgl/freetype-2.11.1/src/pfr/pfr.c \ -lib/lvgl/freetype-2.11.1/src/psaux/psaux.c \ -lib/lvgl/freetype-2.11.1/src/pshinter/pshinter.c \ -lib/lvgl/freetype-2.11.1/src/psnames/psnames.c \ -lib/lvgl/freetype-2.11.1/src/raster/raster.c \ -lib/lvgl/freetype-2.11.1/src/sdf/sdf.c \ -lib/lvgl/freetype-2.11.1/src/sfnt/sfnt.c \ -lib/lvgl/freetype-2.11.1/src/smooth/smooth.c \ -lib/lvgl/freetype-2.11.1/src/truetype/truetype.c \ -lib/lvgl/freetype-2.11.1/src/type1/type1.c \ -lib/lvgl/freetype-2.11.1/src/type42/type42.c \ -lib/lvgl/freetype-2.11.1/src/winfonts/winfnt.c \ -lib/lvgl/freetype-2.11.1/src/base/ftsystem.c \ -lib/lvgl/freetype-2.11.1/src/base/ftdebug.c -endif - - - -$(NAME)_SRCS += $(PY_SRCS) $(EXTMOD_SRCS) $(QPY_SRCS) -ifeq ($(CONFIG_LVGL), y) -$(NAME)_SRCS_2 = $(LVGL_SRCS_1) -$(NAME)_SRCS_3 = $(LVGL_SRCS_2) -endif - -$(NAME)_INCS = \ - . \ - extmod \ - genhdr \ - lib \ - lib/littlefs \ - lib/mp-readline \ - lib/netutils \ - lib/timeutils \ - lib/utils \ - ports/quectel/core/source \ - py - -ifeq ($(CONFIG_LVGL), y) -$(NAME)_INCS += \ - lib/lvgl \ - lib/lvgl \ - lib/lvgl/src \ - lib/lvgl/src/core \ - lib/lvgl/src/draw \ - lib/lvgl/src/extra \ - lib/lvgl/src/font \ - lib/lvgl/src/gpu \ - lib/lvgl/src/hal \ - lib/lvgl/src/misc \ - lib/lvgl/src/widgts \ - lib/lvgl/freetype-2.11.1/include \ - lib/lvgl/freetype-2.11.1/include/dlg \ - lib/lvgl/freetype-2.11.1/include/freetype \ - lib/lvgl/freetype-2.11.1/include/freetype/config \ - lib/lvgl/freetype-2.11.1/include/freetype/internal \ - lib/lvgl/freetype-2.11.1/include/freetype/internal/services \ - lib/lvgl/freetype-2.11.1/src/base \ - lib/lvgl/freetype-2.11.1/src/autofit \ - lib/lvgl/freetype-2.11.1/src/bdf \ - lib/lvgl/freetype-2.11.1/src/bzip2 \ - lib/lvgl/freetype-2.11.1/src/cache \ - lib/lvgl/freetype-2.11.1/src/cff \ - lib/lvgl/freetype-2.11.1/src/cid \ - lib/lvgl/freetype-2.11.1/src/gzip \ - lib/lvgl/freetype-2.11.1/src/lzw \ - lib/lvgl/freetype-2.11.1/src/pcf \ - lib/lvgl/freetype-2.11.1/src/pfr \ - lib/lvgl/freetype-2.11.1/src/psaux \ - lib/lvgl/freetype-2.11.1/src/pshinter \ - lib/lvgl/freetype-2.11.1/src/psnames \ - lib/lvgl/freetype-2.11.1/src/raster \ - lib/lvgl/freetype-2.11.1/src/sdf \ - lib/lvgl/freetype-2.11.1/src/sfnt \ - lib/lvgl/freetype-2.11.1/src/smooth \ - lib/lvgl/freetype-2.11.1/src/truetype \ - lib/lvgl/freetype-2.11.1/src/type1 \ - lib/lvgl/freetype-2.11.1/src/type42 \ - lib/lvgl/freetype-2.11.1/src/winfonts -endif - -EMPTY= -SPACE=$(EMPTY) $(EMPTY) -COMMA=$(EMPTY),$(EMPTY) -BUILD_TIMESTAMP=\\\"$(subst $(SPACE),_,$(subst $(COMMA),,$(shell echo $$(env LANG=en_US.UTF-8 date))))\\\" -$(NAME)_DEFINE = \ - MP_ENDIANNESS_LITTLE \ - MICROPY_BUILD_DATE=${BUILD_TIMESTAMP} - - - -ifneq ($(strip $(PLAT)),Qualcomm) -$(NAME)_CFLAGS = \ - -Wno-error=unused-parameter \ - -Wno-error=format-truncation \ - -Wno-error=unused-variable \ - -Wno-error=unused-function \ - -Wno-error=format= -else -$(NAME)_CFLAGS = -Wno-error=tautological-constant-out-of-range-compare \ - -Wno-error=missing-field-initializers \ - -Wno-error=unused-parameter \ - -Wno-error=unused-variable \ - -Wno-error=unused-function \ - -Wno-error=missing-braces \ - -Wno-error=sometimes-uninitialized -endif - - -ifeq ($(CONFIG_LVGL), y) -$(NAME)_CFLAGS += \ - -Wno-error=incompatible-pointer-types \ - -Wno-error=sign-compare \ - -Wno-error=unused-but-set-variable \ - -Wno-error=switch-unreachable \ - -Wno-error=unused-function \ - -Wno-error=implicit-function-declaration \ - -Wno-error=missing-field-initializers \ - -Wno-error=unused-parameter \ - -Wno-error=unused-variable \ - -Wno-error=type-limits \ - -Wno-error=format= \ - -Wno-error=discarded-qualifiers \ - -Wno-error=maybe-uninitialized \ - -Wno-error=int-conversion -endif - -ifeq ($(CONFIG_SPINAND), y) -$(NAME)_CFLAGS += \ - -Wno-error=restrict \ - -Wno-error=format-overflow= -endif - -$(NAME)_COMPONENTS = peripheral - -$(NAME)_COMPONENTS += driver - -ifeq ($(CONFIG_DECODE_QUECTEL), y) -$(NAME)_COMPONENTS += components/decode/quectel -endif - -ifeq ($(CONFIG_DECODE_QINGYA), y) -ifneq ($(strip $(PLAT)),ASR) -ifneq ($(strip $(PLAT)),ASR_1606) -$(NAME)_COMPONENTS += components/decode/qingya -endif -endif -endif - -ifeq ($(CONFIG_JPEG), y) -$(NAME)_COMPONENTS += components/jpeg -endif - -$(NAME)_COMPONENTS += utilities - - -$(NAME)_COMPONENTS += components/audio - -ifneq (,$(filter y,$(CONFIG_SPINAND) $(CONFIG_SPI_SDCARD))) -$(NAME)_COMPONENTS += components/fs -endif - -ifeq ($(CONFIG_RTMP), y) -$(NAME)_COMPONENTS += components/rtmpdump -endif -ifeq ($(CONFIG_JRTC), y) -$(NAME)_COMPONENTS += components/jpeg -$(NAME)_COMPONENTS += components/jrtc -$(NAME)_INCS += ../../components/jrtc/inc - -endif - -ifeq ($(CONFIG_SENSOR_VC9202), y) -$(NAME)_COMPONENTS += components/sensor/VC9202 -$(NAME)_INCS += ../../components/sensor/VS9202/inc -$(NAME)_INCS += ../../components/sensor/VS9202/algo/inc -endif - -ifeq ($(CONFIG_POC), y) -$(NAME)_CFLAGS += \ - -Wno-error=incompatible-pointer-types \ - -Wno-error=ignored-qualifiers \ - -Wno-error=int-conversion \ - -Wno-error=implicit-function-declaration \ - -Wno-error=discarded-qualifiers \ - -Wno-error=unused-const-variable= - -$(NAME)_COMPONENTS += components/poc -endif - -ifeq ($(CONFIG_QRCODE), y) -$(NAME)_COMPONENTS += components/qrcode -endif - -ifeq ($(CONFIG_HX3918), y) -$(NAME)_COMPONENTS += components/HX3918 -endif -ifeq ($(CONFIG_GH301x), y) -$(NAME)_COMPONENTS += components/GH301X -endif -ifeq ($(CONFIG_SC7A20), y) -$(NAME)_COMPONENTS += components/SC7A20 -endif -ifeq ($(CONFIG_juphoon), y) -$(NAME)_COMPONENTS += components/juphoon -endif - -ifeq ($(CONFIG_LIBSSH2), y) -$(NAME)_INCS += ../../components/ssh2/include \ - ../../components/ssh2/src -$(NAME)_COMPONENTS += components/ssh2 -endif - -ifeq ($(CONFIG_QUECTHING), y) -$(NAME)_INCS += ../../components/quecsdk -$(NAME)_COMPONENTS += components/quecsdk -endif - -ifeq ($(CONFIG_GMSSL), y) -$(NAME)_COMPONENTS += components/GMSSL -endif - -ifeq ($(CONFIG_GB2312), y) -$(NAME)_COMPONENTS += components/decode/gb2312 -endif - -ifeq ($(CONFIG_ESIMSDK), y) -$(NAME)_COMPONENTS += components/esim -endif - -ifeq ($(CONFIG_NFC_SL6320), y) -$(NAME)_COMPONENTS += components/NFC/SL6320 -endif - -ifeq ($(CONFIG_VOIP), y) -$(NAME)_INCS += ../../components/voip/libexosip2/include \ - ../../components/voip/libosip2/include \ - ../../components/voip/rtp -$(NAME)_COMPONENTS += components/voip -endif - -ifeq ($(CONFIG_ETHERNET_W5500), y) -$(NAME)_COMPONENTS += components/ethernet -$(NAME)_INCS += ../../components/ethernet/wiznet -endif - -ifeq ($(CONFIG_SLIP), y) -$(NAME)_COMPONENTS += components/slip -$(NAME)_INCS += ../../components/slip -endif - -ifeq ($(CONFIG_DLMS), y) -$(NAME)_COMPONENTS += components/dlms -endif - -ifeq ($(CONFIG_MICROPYTHON_EXTENSION_PERF), y) -$(NAME)_COMPONENTS += components/micropython_extension -$(NAME)_INCS += ../../components/micropython_extension/perf -endif - -ifeq ($(CONFIG_MICROPYTHON_EXTENSION_SECURE_APP), y) -$(NAME)_COMPONENTS += components/micropython_extension -$(NAME)_INCS += ../../components/micropython_extension/secure_app -endif - -$(NAME)_CFLAGS += -Wno-error=implicit-fallthrough - -$(NAME)_PRIVATE_SCRIPT = private.mk - -$(NAME)_PRIVATE_SCRIPT_TARGETS = construct clean + +NAME := MICROPYTHON + +include config/$(KCONFIG_CONFIG) + +PY_SRCS = \ + py/argcheck.c \ + py/asmarm.c \ + py/asmbase.c \ + py/asmthumb.c \ + py/asmx64.c \ + py/asmx86.c \ + py/asmxtensa.c \ + py/bc.c \ + py/binary.c \ + py/builtinevex.c \ + py/builtinhelp.c \ + py/builtinimport.c \ + py/compile.c \ + py/emitbc.c \ + py/emitcommon.c \ + py/emitglue.c \ + py/emitinlinethumb.c \ + py/emitinlinextensa.c \ + py/emitnarm.c \ + py/emitnthumb.c \ + py/emitnx64.c \ + py/emitnx86.c \ + py/emitnxtensa.c \ + py/emitnxtensawin.c \ + py/formatfloat.c \ + py/frozenmod.c \ + py/gc.c \ + py/lexer.c \ + py/malloc.c \ + py/map.c \ + py/modarray.c \ + py/modbuiltins.c \ + py/modcmath.c \ + py/modcollections.c \ + py/modgc.c \ + py/modio.c \ + py/modmath.c \ + py/modmicropython.c \ + py/modstruct.c \ + py/modsys.c \ + py/modthread.c \ + py/moduerrno.c \ + py/mpprint.c \ + py/mpstate.c \ + py/mpz.c \ + py/nativeglue.c \ + py/nlr.c \ + py/nlrpowerpc.c \ + py/nlrsetjmp.c \ + py/nlrthumb.c \ + py/nlrx64.c \ + py/nlrx86.c \ + py/nlrxtensa.c \ + py/obj.c \ + py/objarray.c \ + py/objattrtuple.c \ + py/objbool.c \ + py/objboundmeth.c \ + py/objcell.c \ + py/objclosure.c \ + py/objcomplex.c \ + py/objdeque.c \ + py/objdict.c \ + py/objenumerate.c \ + py/objexcept.c \ + py/objfilter.c \ + py/objfloat.c \ + py/objfun.c \ + py/objgenerator.c \ + py/objgetitemiter.c \ + py/objint.c \ + py/objint_longlong.c \ + py/objint_mpz.c \ + py/objlist.c \ + py/objmap.c \ + py/objmodule.c \ + py/objnamedtuple.c \ + py/objnone.c \ + py/objobject.c \ + py/objpolyiter.c \ + py/objproperty.c \ + py/objrange.c \ + py/objreversed.c \ + py/objset.c \ + py/objsingleton.c \ + py/objslice.c \ + py/objstr.c \ + py/objstringio.c \ + py/objstrunicode.c \ + py/objtuple.c \ + py/objtype.c \ + py/objzip.c \ + py/opmethods.c \ + py/pairheap.c \ + py/parse.c \ + py/parsenum.c \ + py/parsenumbase.c \ + py/persistentcode.c \ + py/profile.c \ + py/pystack.c \ + py/qstr.c \ + py/reader.c \ + py/repl.c \ + py/ringbuf.c \ + py/runtime.c \ + py/runtime_utils.c \ + py/scheduler.c \ + py/scope.c \ + py/sequence.c \ + py/showbc.c \ + py/smallint.c \ + py/stackctrl.c \ + py/stream.c \ + py/unicode.c \ + py/vm.c \ + py/vstr.c \ + py/warning.c + + +EXTMOD_SRCS = \ + extmod/mb_ussl_error.c \ + extmod/modaes.c \ + extmod/modhash.c \ + extmod/moduasyncio.c \ + extmod/moduwebsocket.c \ + extmod/modubinascii.c \ + extmod/moducryptolib.c \ + extmod/moductypes.c \ + extmod/moduhashlib.c \ + extmod/modujson.c \ + extmod/modurandom.c \ + extmod/modure.c \ + extmod/moduselect.c \ + extmod/modussl_mbedtls.c \ + extmod/moduzlib.c \ + extmod/utime_mphal.c \ + extmod/vfs.c \ + extmod/vfs_blockdev.c \ + extmod/vfs_efs.c \ + extmod/vfs_efs_file.c \ + extmod/vfs_fat.c \ + extmod/vfs_fat_file.c \ + extmod/vfs_lfs.c \ + extmod/vfs_reader.c \ + extmod/vfs_temp.c \ + extmod/vfs_temp_file.c \ + extmod/vfs_fat_sdio.c \ + extmod/vfs_fat_sdio_file.c \ + lib/littlefs/lfs1.c \ + lib/littlefs/lfs1_util.c \ + lib/littlefs/lfs2.c \ + lib/littlefs/lfs2_util.c \ + lib/mp-readline/readline.c \ + lib/netutils/netutils.c \ + lib/timeutils/timeutils.c \ + lib/utils/interrupt_char.c \ + lib/utils/pyexec.c \ + lib/utils/stdout_helpers.c \ + lib/utils/sys_stdio_mphal.c + + +QPY_SRCS = \ + ports/quectel/core/build/_frozen_mpy.c \ + ports/quectel/core/source/random.c \ + ports/quectel/core/source/audio_audio.c \ + ports/quectel/core/source/audio_handle.c \ + ports/quectel/core/source/audio_queue.c \ + ports/quectel/core/source/audio_record.c \ + ports/quectel/core/source/audio_tts.c \ + ports/quectel/core/source/audiocodec_rt5616.c \ + ports/quectel/core/source/callbackdeal.c \ + ports/quectel/core/source/camera_capture.c \ + ports/quectel/core/source/camera_preview.c \ + ports/quectel/core/source/camera_scandecode.c \ + ports/quectel/core/source/devreport.c \ + ports/quectel/core/source/gccollect.c \ + ports/quectel/core/source/help.c \ + ports/quectel/core/source/linklist.c \ + ports/quectel/core/source/machine_extint.c \ + ports/quectel/core/source/machine_hw_spi.c \ + ports/quectel/core/source/machine_iic.c \ + ports/quectel/core/source/machine_iic_simulation.c \ + ports/quectel/core/source/machine_keypad.c \ + ports/quectel/core/source/machine_lcd.c \ + ports/quectel/core/source/machine_nandflash.c \ + ports/quectel/core/source/machine_pin.c \ + ports/quectel/core/source/machine_rtc.c \ + ports/quectel/core/source/machine_timer.c \ + ports/quectel/core/source/machine_uart.c \ + ports/quectel/core/source/machine_wdt.c \ + ports/quectel/core/source/misc_adc.c \ + ports/quectel/core/source/misc_power.c \ + ports/quectel/core/source/misc_powerkey.c \ + ports/quectel/core/source/misc_pwm.c \ + ports/quectel/core/source/misc_temperature.c \ + ports/quectel/core/source/misc_usb.c \ + ports/quectel/core/source/misc_usbnet.c \ + ports/quectel/core/source/modatcmd.c \ + ports/quectel/core/source/modaudio.c \ + ports/quectel/core/source/modaudiocodec.c \ + ports/quectel/core/source/modble.c \ + ports/quectel/core/source/modbt.c \ + ports/quectel/core/source/modcamera.c \ + ports/quectel/core/source/modcelllocator.c \ + ports/quectel/core/source/modcelllocator_qpy.c \ + ports/quectel/core/source/locator.c \ + ports/quectel/core/source/modcsd.c \ + ports/quectel/core/source/moddatacall.c \ + ports/quectel/core/source/moddev.c \ + ports/quectel/core/source/modethernet.c \ + ports/quectel/core/source/modethernet_dm9051.c \ + ports/quectel/core/source/modethernet_w5500.c \ + ports/quectel/core/source/modethernet_ch395.c \ + ports/quectel/core/source/modexample.c \ + ports/quectel/core/source/modfota.c \ + ports/quectel/core/source/modgnss.c \ + ports/quectel/core/source/modlpm.c \ + ports/quectel/core/source/modlvgl.c \ + ports/quectel/core/source/modlvgl_other_hander.c \ + ports/quectel/core/source/modlwm2m.c \ + ports/quectel/core/source/modmachine.c \ + ports/quectel/core/source/modmisc.c \ + ports/quectel/core/source/modnb.c \ + ports/quectel/core/source/modnet.c \ + ports/quectel/core/source/modostimer.c \ + ports/quectel/core/source/modpoc.c \ + ports/quectel/core/source/modqrcode.c \ + ports/quectel/core/source/modrtmp.c \ + ports/quectel/core/source/modsecuredata.c \ + ports/quectel/core/source/modsensor.c \ + ports/quectel/core/source/modsha1.c \ + ports/quectel/core/source/modsim.c \ + ports/quectel/core/source/modslipif.c \ + ports/quectel/core/source/modsms.c \ + ports/quectel/core/source/modussd.c \ + ports/quectel/core/source/modsocket.c \ + ports/quectel/core/source/modwifi.c \ + ports/quectel/core/source/modtp.c \ + ports/quectel/core/source/moduos.c \ + ports/quectel/core/source/modutils.c \ + ports/quectel/core/source/modutime.c \ + ports/quectel/core/source/modvoicecall.c \ + ports/quectel/core/source/modwifilocator.c \ + ports/quectel/core/source/modwifiscan.c \ + ports/quectel/core/source/mphalport.c \ + ports/quectel/core/source/mpthreadport.c \ + ports/quectel/core/source/nb_aep.c \ + ports/quectel/core/source/nb_oc.c \ + ports/quectel/core/source/nb_onenet.c \ + ports/quectel/core/source/quecpython.c \ + ports/quectel/core/source/sensor_sn95500.c \ + ports/quectel/core/source/sensor_icckey.c \ + ports/quectel/core/source/sensor_gnss.c \ + ports/quectel/core/source/sensor_handmic_key.c \ + ports/quectel/core/source/tp_gt9xx.c \ + ports/quectel/core/source/tp_xpt2046.c \ + ports/quectel/core/source/tp_cst816.c \ + ports/quectel/core/source/tp_ft6x36.c \ + ports/quectel/core/source/tp_st1615.c \ + ports/quectel/core/source/modGsensor.c \ + ports/quectel/core/source/modGsensor_SC7A20.c \ + ports/quectel/core/source/modHsensor.c \ + ports/quectel/core/source/modHsensor_GH3018.c \ + ports/quectel/core/source/modHsensor_HX3918.c \ + ports/quectel/core/source/modgpio_encoder.c \ + ports/quectel/core/source/modVideoCall.c \ + ports/quectel/core/source/modVideoCall_juphoon.c \ + ports/quectel/core/source/modrsa.c \ + ports/quectel/core/source/modsftp.c \ + ports/quectel/core/source/utils_crc32.c \ + ports/quectel/core/source/modwebserver.c \ + ports/quectel/core/source/http_parser.c \ + ports/quectel/core/source/modethernet_yt8512h.c \ + ports/quectel/core/source/sim_esim.c \ + ports/quectel/core/source/modG711.c \ + ports/quectel/core/source/modG729.c \ + ports/quectel/core/source/modG722.c \ + ports/quectel/core/source/modcan_mcp2515.c \ + ports/quectel/core/source/modextuart_wk2114.c \ + ports/quectel/core/source/modgpio_encoder.c \ + ports/quectel/core/source/modextgpio_aw9523.c \ + ports/quectel/core/source/modalipay.c \ + ports/quectel/core/source/machine_key.c \ + ports/quectel/core/source/lpm_wakeup.c \ + ports/quectel/core/source/modnetwork.c \ + ports/quectel/core/source/modwlan_ASR5803.c \ + ports/quectel/core/source/machine_soft_spi.c \ + ports/quectel/core/source/modwlan.c\ + ports/quectel/core/source/code128_p.c \ + ports/quectel/core/source/modmask.c \ + ports/quectel/core/source/modVad.c \ + ports/quectel/core/source/machine_one_wire.c\ + ports/quectel/core/source/modalipay_collection.c \ + ports/quectel/core/source/modsif.c\ + ports/quectel/core/source/jrtc.c \ + ports/quectel/core/source/modnfc.c \ + ports/quectel/core/source/nfc_sl6320.c \ + ports/quectel/core/source/modstk.c \ + ports/quectel/core/source/modalipay_se.c \ + ports/quectel/core/source/modvoip.c \ + ports/quectel/core/source/modipsec.c \ + ports/quectel/core/source/modecdsa.c \ + ports/quectel/core/source/modecdh.c \ + ports/quectel/core/source/moddlms.c \ + ports/quectel/core/source/modai_rtc.c + +ifeq ($(CONFIG_QUECTHING), y) +ifeq ($(strip $(PLAT)),RDA) +QPY_SRCS += ../../components/quecsdk/cloud/python/modquecIot-BC25old.c +else +QPY_SRCS += ../../components/quecsdk/cloud/python/modquecIot.c +endif +endif + + +$(NAME)_ARCHIVES = \ + ports/quectel/core/source/libimslvad.a +# Opus:须在 $(NAME)_SRCS)+= 之前;路径相对 Helios 根(勿用 lastword,config.mk include 后会指错目录) +-include services/microPython/microPython_opus.mk + +ifeq ($(CONFIG_USQLITE), y) +EXTMOD_SRCS += lib/usqlite/usqlite_connection.c \ + lib/usqlite/usqlite_cursor.c \ + lib/usqlite/usqlite_row.c \ + lib/usqlite/usqlite_file.c \ + lib/usqlite/usqlite_mem.c \ + lib/usqlite/usqlite_vfs.c \ + lib/usqlite/usqlite_utils.c \ + lib/usqlite/usqlite.c \ + lib/usqlite/usqlite_module.c +$(NAME)_INCS += lib/usqlite +endif + + +ifeq ($(CONFIG_LVGL), y) + +LVGL_SRCS_1 += \ +lib/lvgl/src/extra/layouts/flex/lv_flex.c \ +lib/lvgl/src/extra/layouts/grid/lv_grid.c \ +lib/lvgl/src/extra/libs/bmp/lv_bmp.c \ +lib/lvgl/src/extra/libs/ffmpeg/lv_ffmpeg.c \ +lib/lvgl/src/extra/libs/freetype/lv_freetype.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_fatfs.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_posix.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_helios.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_stdio.c \ +lib/lvgl/src/extra/libs/fsdrv/lv_fs_win32.c \ +lib/lvgl/src/extra/libs/gif/gifdec.c \ +lib/lvgl/src/extra/libs/gif/lv_gif.c \ +lib/lvgl/src/extra/libs/png/lodepng.c \ +lib/lvgl/src/extra/libs/png/lv_png.c \ +lib/lvgl/src/extra/libs/qrcode/lv_qrcode.c \ +lib/lvgl/src/extra/libs/qrcode/qrcodegen.c \ +lib/lvgl/src/extra/libs/rlottie/lv_rlottie.c \ +lib/lvgl/src/extra/libs/sjpg/lv_sjpg.c \ +lib/lvgl/src/extra/libs/sjpg/tjpgd.c \ +lib/lvgl/src/extra/lv_extra.c \ +lib/lvgl/src/extra/others/gridnav/lv_gridnav.c \ +lib/lvgl/src/extra/others/monkey/lv_monkey.c \ +lib/lvgl/src/extra/others/snapshot/lv_snapshot.c \ +lib/lvgl/src/extra/themes/basic/lv_theme_basic.c \ +lib/lvgl/src/extra/themes/default/lv_theme_default.c \ +lib/lvgl/src/extra/themes/mono/lv_theme_mono.c \ +lib/lvgl/src/extra/widgets/animimg/lv_animimg.c \ +lib/lvgl/src/extra/widgets/calendar/lv_calendar.c \ +lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_arrow.c \ +lib/lvgl/src/extra/widgets/calendar/lv_calendar_header_dropdown.c \ +lib/lvgl/src/extra/widgets/chart/lv_chart.c \ +lib/lvgl/src/extra/widgets/colorwheel/lv_colorwheel.c \ +lib/lvgl/src/extra/widgets/imgbtn/lv_imgbtn.c \ +lib/lvgl/src/extra/widgets/keyboard/lv_keyboard.c \ +lib/lvgl/src/extra/widgets/led/lv_led.c \ +lib/lvgl/src/extra/widgets/list/lv_list.c \ +lib/lvgl/src/extra/widgets/menu/lv_menu.c \ +lib/lvgl/src/extra/widgets/meter/lv_meter.c \ +lib/lvgl/src/extra/widgets/msgbox/lv_msgbox.c \ +lib/lvgl/src/extra/widgets/span/lv_span.c \ +lib/lvgl/src/extra/widgets/spinbox/lv_spinbox.c \ +lib/lvgl/src/extra/widgets/spinner/lv_spinner.c \ +lib/lvgl/src/extra/widgets/tabview/lv_tabview.c \ +lib/lvgl/src/extra/widgets/tileview/lv_tileview.c \ +lib/lvgl/src/extra/widgets/win/lv_win.c \ +lib/lvgl/src/extra/others/ime/lv_ime_pinyin.c \ +lib/lvgl/src/core/lv_disp.c \ +lib/lvgl/src/core/lv_group.c \ +lib/lvgl/src/core/lv_indev.c \ +lib/lvgl/src/core/lv_indev_scroll.c \ +lib/lvgl/src/core/lv_obj.c \ +lib/lvgl/src/core/lv_obj_class.c \ +lib/lvgl/src/core/lv_obj_draw.c \ +lib/lvgl/src/core/lv_obj_pos.c \ +lib/lvgl/src/core/lv_obj_scroll.c \ +lib/lvgl/src/core/lv_obj_style.c \ +lib/lvgl/src/core/lv_obj_style_gen.c \ +lib/lvgl/src/core/lv_obj_tree.c \ +lib/lvgl/src/core/lv_event.c \ +lib/lvgl/src/core/lv_refr.c \ +lib/lvgl/src/core/lv_theme.c \ +lib/lvgl/src/draw/lv_draw_arc.c \ +lib/lvgl/src/draw/lv_draw.c \ +lib/lvgl/src/draw/lv_draw_img.c \ +lib/lvgl/src/draw/lv_draw_label.c \ +lib/lvgl/src/draw/lv_draw_layer.c \ +lib/lvgl/src/draw/lv_draw_line.c \ +lib/lvgl/src/draw/lv_draw_mask.c \ +lib/lvgl/src/draw/lv_draw_rect.c \ +lib/lvgl/src/draw/lv_draw_transform.c \ +lib/lvgl/src/draw/lv_draw_triangle.c \ +lib/lvgl/src/draw/lv_img_buf.c \ +lib/lvgl/src/draw/lv_img_cache.c \ +lib/lvgl/src/draw/lv_img_decoder.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_arc.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_bg.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_composite.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_img.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_label.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_line.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_mask.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_polygon.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_rect.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_stack_blur.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_texture_cache.c \ +lib/lvgl/src/draw/sdl/lv_draw_sdl_utils.c \ +lib/lvgl/src/draw/sw/lv_draw_sw.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_arc.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_blend.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_img.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_letter.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_line.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_rect.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_polygon.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_gradient.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_dither.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_transform.c \ +lib/lvgl/src/draw/sw/lv_draw_sw_layer.c \ +lib/lvgl/src/font/lv_font.c \ +lib/lvgl/src/font/lv_font_fmt_txt.c \ +lib/lvgl/src/font/lv_font_loader.c \ +lib/lvgl/src/font/lv_font_dejavu_16_persian_hebrew.c \ +lib/lvgl/src/font/lv_font_montserrat_8.c \ +lib/lvgl/src/font/lv_font_montserrat_10.c \ +lib/lvgl/src/font/lv_font_montserrat_12.c \ +lib/lvgl/src/font/lv_font_montserrat_12_subpx.c \ +lib/lvgl/src/font/lv_font_montserrat_14.c \ +lib/lvgl/src/font/lv_font_montserrat_16.c \ +lib/lvgl/src/font/lv_font_montserrat_18.c \ +lib/lvgl/src/font/lv_font_montserrat_20.c \ +lib/lvgl/src/font/lv_font_montserrat_22.c \ +lib/lvgl/src/font/lv_font_montserrat_24.c \ +lib/lvgl/src/font/lv_font_montserrat_26.c \ +lib/lvgl/src/font/lv_font_montserrat_28.c \ +lib/lvgl/src/font/lv_font_montserrat_28_compressed.c \ +lib/lvgl/src/font/lv_font_montserrat_30.c \ +lib/lvgl/src/font/lv_font_montserrat_32.c \ +lib/lvgl/src/font/lv_font_montserrat_34.c \ +lib/lvgl/src/font/lv_font_montserrat_36.c \ +lib/lvgl/src/font/lv_font_montserrat_38.c \ +lib/lvgl/src/font/lv_font_montserrat_40.c \ +lib/lvgl/src/font/lv_font_montserrat_42.c \ +lib/lvgl/src/font/lv_font_montserrat_44.c \ +lib/lvgl/src/font/lv_font_montserrat_46.c \ +lib/lvgl/src/font/lv_font_montserrat_48.c \ +lib/lvgl/src/font/lv_font_simsun_16_cjk.c \ +lib/lvgl/src/font/lv_font_unscii_8.c \ +lib/lvgl/src/font/lv_font_unscii_16.c \ +lib/lvgl/src/font/lv_font_siyun_18.c \ +lib/lvgl/src/font/lv_font_arial_54.c \ +lib/lvgl/src/font/lv_font_siyuan_32.c \ +lib/lvgl/src/font/lv_font_sdSiyuan16.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_8.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_10.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_12.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_14.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_16.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_18.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_20.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_22.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_24.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_26.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_28.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_30.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_32.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_34.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_36.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_38.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_40.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_42.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_44.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_46.c \ +lib/lvgl/src/font/lv_font_SDsiyuan_48.c \ +lib/lvgl/src/font/lv_11_siyuan_light.c \ + +LVGL_SRCS_2 = \ +lib/lvgl/src/font/lv_14_ali.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Bold_60.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Bold_100.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Regular_28.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Regular_48.c \ +lib/lvgl/src/font/lv_font_HarmonyOS_Regular_20.c \ +lib/lvgl/src/font/lv_font_siyuan_Bold_26.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_12.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_14.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_16.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_18.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_20.c \ +lib/lvgl/src/font/lv_font_siyuan_Regular_22.c \ +lib/lvgl/src/font/lv_bold_18.c \ +lib/lvgl/src/font/lv_bold_34.c \ +lib/lvgl/src/font/lv_bold_48.c \ +lib/lvgl/src/font/lv_regular_12.c \ +lib/lvgl/src/font/lv_regular_14.c \ +lib/lvgl/src/font/lv_regular_18.c \ +lib/lvgl/src/font/lv_regular_20.c \ +lib/lvgl/src/font/lv_regular_22.c \ +lib/lvgl/src/font/lv_regular_24.c \ +lib/lvgl/src/font/lv_regular_29.c \ +lib/lvgl/src/font/lv_font_tianbo_10.c \ +lib/lvgl/src/font/lv_font_tianbo_12.c \ +lib/lvgl/src/font/lv_font_tianbo_14.c \ +lib/lvgl/src/font/lv_font_tianbo_16.c \ +lib/lvgl/src/font/lv_font_12_qs.c \ +lib/lvgl/src/font/lv_font_12.c \ +lib/lvgl/src/font/lv_font_21_light.c \ +lib/lvgl/src/font/lv_font_30_light.c \ +lib/lvgl/src/font/lv_font_14_simsum.c \ +lib/lvgl/src/font/lv_font_16_simsum.c \ +lib/lvgl/src/font/lv_font_18_simsum.c \ +lib/lvgl/src/font/lv_font_70_bold.c \ +lib/lvgl/src/font/lv_font_28_dial.c \ +lib/lvgl/src/font/lv_font_60_main_menu.c \ +lib/lvgl/src/font/lv_font_50_main_menu_e.c \ +lib/lvgl/src/font/K01_font_16_ALL.c \ +lib/lvgl/src/font/K01_font_30_DIAL.c \ +lib/lvgl/src/hal/lv_hal_disp.c \ +lib/lvgl/src/hal/lv_hal_indev.c \ +lib/lvgl/src/hal/lv_hal_tick.c \ +lib/lvgl/src/misc/lv_anim.c \ +lib/lvgl/src/misc/lv_anim_timeline.c \ +lib/lvgl/src/misc/lv_area.c \ +lib/lvgl/src/misc/lv_async.c \ +lib/lvgl/src/misc/lv_bidi.c \ +lib/lvgl/src/misc/lv_color.c \ +lib/lvgl/src/misc/lv_fs.c \ +lib/lvgl/src/misc/lv_gc.c \ +lib/lvgl/src/misc/lv_ll.c \ +lib/lvgl/src/misc/lv_log.c \ +lib/lvgl/src/misc/lv_lru.c \ +lib/lvgl/src/misc/lv_math.c \ +lib/lvgl/src/misc/lv_mem.c \ +lib/lvgl/src/misc/lv_printf.c \ +lib/lvgl/src/misc/lv_style.c \ +lib/lvgl/src/misc/lv_style_gen.c \ +lib/lvgl/src/misc/lv_timer.c \ +lib/lvgl/src/misc/lv_tlsf.c \ +lib/lvgl/src/misc/lv_txt.c \ +lib/lvgl/src/misc/lv_txt_ap.c \ +lib/lvgl/src/misc/lv_utils.c \ +lib/lvgl/src/widgets/lv_arc.c \ +lib/lvgl/src/widgets/lv_bar.c \ +lib/lvgl/src/widgets/lv_btn.c \ +lib/lvgl/src/widgets/lv_btnmatrix.c \ +lib/lvgl/src/widgets/lv_canvas.c \ +lib/lvgl/src/widgets/lv_checkbox.c \ +lib/lvgl/src/widgets/lv_dropdown.c \ +lib/lvgl/src/widgets/lv_img.c \ +lib/lvgl/src/widgets/lv_label.c \ +lib/lvgl/src/widgets/lv_line.c \ +lib/lvgl/src/widgets/lv_roller.c \ +lib/lvgl/src/widgets/lv_slider.c \ +lib/lvgl/src/widgets/lv_switch.c \ +lib/lvgl/src/widgets/lv_table.c \ +lib/lvgl/src/widgets/lv_textarea.c \ +lib/lvgl/freetype-2.11.1/src/autofit/autofit.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbase.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbbox.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbdf.c \ +lib/lvgl/freetype-2.11.1/src/base/ftbitmap.c \ +lib/lvgl/freetype-2.11.1/src/base/ftcid.c \ +lib/lvgl/freetype-2.11.1/src/base/ftfstype.c \ +lib/lvgl/freetype-2.11.1/src/base/ftgasp.c \ +lib/lvgl/freetype-2.11.1/src/base/ftglyph.c \ +lib/lvgl/freetype-2.11.1/src/base/ftgxval.c \ +lib/lvgl/freetype-2.11.1/src/base/ftinit.c \ +lib/lvgl/freetype-2.11.1/src/base/ftmm.c \ +lib/lvgl/freetype-2.11.1/src/base/ftotval.c \ +lib/lvgl/freetype-2.11.1/src/base/ftpatent.c \ +lib/lvgl/freetype-2.11.1/src/base/ftpfr.c \ +lib/lvgl/freetype-2.11.1/src/base/ftstroke.c \ +lib/lvgl/freetype-2.11.1/src/base/ftsynth.c \ +lib/lvgl/freetype-2.11.1/src/base/fttype1.c \ +lib/lvgl/freetype-2.11.1/src/base/ftwinfnt.c \ +lib/lvgl/freetype-2.11.1/src/bdf/bdf.c \ +lib/lvgl/freetype-2.11.1/src/bzip2/ftbzip2.c \ +lib/lvgl/freetype-2.11.1/src/cache/ftcache.c \ +lib/lvgl/freetype-2.11.1/src/cff/cff.c \ +lib/lvgl/freetype-2.11.1/src/cid/type1cid.c \ +lib/lvgl/freetype-2.11.1/src/gzip/ftgzip.c \ +lib/lvgl/freetype-2.11.1/src/lzw/ftlzw.c \ +lib/lvgl/freetype-2.11.1/src/pcf/pcf.c \ +lib/lvgl/freetype-2.11.1/src/pfr/pfr.c \ +lib/lvgl/freetype-2.11.1/src/psaux/psaux.c \ +lib/lvgl/freetype-2.11.1/src/pshinter/pshinter.c \ +lib/lvgl/freetype-2.11.1/src/psnames/psnames.c \ +lib/lvgl/freetype-2.11.1/src/raster/raster.c \ +lib/lvgl/freetype-2.11.1/src/sdf/sdf.c \ +lib/lvgl/freetype-2.11.1/src/sfnt/sfnt.c \ +lib/lvgl/freetype-2.11.1/src/smooth/smooth.c \ +lib/lvgl/freetype-2.11.1/src/truetype/truetype.c \ +lib/lvgl/freetype-2.11.1/src/type1/type1.c \ +lib/lvgl/freetype-2.11.1/src/type42/type42.c \ +lib/lvgl/freetype-2.11.1/src/winfonts/winfnt.c \ +lib/lvgl/freetype-2.11.1/src/base/ftsystem.c \ +lib/lvgl/freetype-2.11.1/src/base/ftdebug.c +endif + + + +$(NAME)_SRCS += $(PY_SRCS) $(EXTMOD_SRCS) $(QPY_SRCS) +ifeq ($(CONFIG_LVGL), y) +$(NAME)_SRCS_2 = $(LVGL_SRCS_1) +$(NAME)_SRCS_3 = $(LVGL_SRCS_2) +endif + +$(NAME)_INCS = \ + . \ + extmod \ + genhdr \ + lib \ + lib/littlefs \ + lib/mp-readline \ + lib/netutils \ + lib/timeutils \ + lib/utils \ + ports/quectel/core/source \ + py + +ifeq ($(CONFIG_LVGL), y) +$(NAME)_INCS += \ + lib/lvgl \ + lib/lvgl \ + lib/lvgl/src \ + lib/lvgl/src/core \ + lib/lvgl/src/draw \ + lib/lvgl/src/extra \ + lib/lvgl/src/font \ + lib/lvgl/src/gpu \ + lib/lvgl/src/hal \ + lib/lvgl/src/misc \ + lib/lvgl/src/widgts \ + lib/lvgl/freetype-2.11.1/include \ + lib/lvgl/freetype-2.11.1/include/dlg \ + lib/lvgl/freetype-2.11.1/include/freetype \ + lib/lvgl/freetype-2.11.1/include/freetype/config \ + lib/lvgl/freetype-2.11.1/include/freetype/internal \ + lib/lvgl/freetype-2.11.1/include/freetype/internal/services \ + lib/lvgl/freetype-2.11.1/src/base \ + lib/lvgl/freetype-2.11.1/src/autofit \ + lib/lvgl/freetype-2.11.1/src/bdf \ + lib/lvgl/freetype-2.11.1/src/bzip2 \ + lib/lvgl/freetype-2.11.1/src/cache \ + lib/lvgl/freetype-2.11.1/src/cff \ + lib/lvgl/freetype-2.11.1/src/cid \ + lib/lvgl/freetype-2.11.1/src/gzip \ + lib/lvgl/freetype-2.11.1/src/lzw \ + lib/lvgl/freetype-2.11.1/src/pcf \ + lib/lvgl/freetype-2.11.1/src/pfr \ + lib/lvgl/freetype-2.11.1/src/psaux \ + lib/lvgl/freetype-2.11.1/src/pshinter \ + lib/lvgl/freetype-2.11.1/src/psnames \ + lib/lvgl/freetype-2.11.1/src/raster \ + lib/lvgl/freetype-2.11.1/src/sdf \ + lib/lvgl/freetype-2.11.1/src/sfnt \ + lib/lvgl/freetype-2.11.1/src/smooth \ + lib/lvgl/freetype-2.11.1/src/truetype \ + lib/lvgl/freetype-2.11.1/src/type1 \ + lib/lvgl/freetype-2.11.1/src/type42 \ + lib/lvgl/freetype-2.11.1/src/winfonts +endif + +EMPTY= +SPACE=$(EMPTY) $(EMPTY) +COMMA=$(EMPTY),$(EMPTY) +BUILD_TIMESTAMP=\\\"$(subst $(SPACE),_,$(subst $(COMMA),,$(shell echo $$(env LANG=en_US.UTF-8 date))))\\\" +$(NAME)_DEFINE = \ + MP_ENDIANNESS_LITTLE \ + MICROPY_BUILD_DATE=${BUILD_TIMESTAMP} + + + +ifneq ($(strip $(PLAT)),Qualcomm) +$(NAME)_CFLAGS = \ + -Wno-error=unused-parameter \ + -Wno-error=format-truncation \ + -Wno-error=unused-variable \ + -Wno-error=unused-function \ + -Wno-error=format= +else +$(NAME)_CFLAGS = -Wno-error=tautological-constant-out-of-range-compare \ + -Wno-error=missing-field-initializers \ + -Wno-error=unused-parameter \ + -Wno-error=unused-variable \ + -Wno-error=unused-function \ + -Wno-error=missing-braces \ + -Wno-error=sometimes-uninitialized +endif + + +ifeq ($(CONFIG_LVGL), y) +$(NAME)_CFLAGS += \ + -Wno-error=incompatible-pointer-types \ + -Wno-error=sign-compare \ + -Wno-error=unused-but-set-variable \ + -Wno-error=switch-unreachable \ + -Wno-error=unused-function \ + -Wno-error=implicit-function-declaration \ + -Wno-error=missing-field-initializers \ + -Wno-error=unused-parameter \ + -Wno-error=unused-variable \ + -Wno-error=type-limits \ + -Wno-error=format= \ + -Wno-error=discarded-qualifiers \ + -Wno-error=maybe-uninitialized \ + -Wno-error=int-conversion +endif + +ifeq ($(CONFIG_SPINAND), y) +$(NAME)_CFLAGS += \ + -Wno-error=restrict \ + -Wno-error=format-overflow= +endif + +$(NAME)_COMPONENTS = peripheral + +$(NAME)_COMPONENTS += driver + +ifeq ($(CONFIG_DECODE_QUECTEL), y) +$(NAME)_COMPONENTS += components/decode/quectel +endif + +ifeq ($(CONFIG_DECODE_QINGYA), y) +ifneq ($(strip $(PLAT)),ASR) +ifneq ($(strip $(PLAT)),ASR_1606) +$(NAME)_COMPONENTS += components/decode/qingya +endif +endif +endif + +ifeq ($(CONFIG_JPEG), y) +$(NAME)_COMPONENTS += components/jpeg +endif + +$(NAME)_COMPONENTS += utilities + + +$(NAME)_COMPONENTS += components/audio + +ifneq (,$(filter y,$(CONFIG_SPINAND) $(CONFIG_SPI_SDCARD))) +$(NAME)_COMPONENTS += components/fs +endif + +ifeq ($(CONFIG_RTMP), y) +$(NAME)_COMPONENTS += components/rtmpdump +endif +ifeq ($(CONFIG_JRTC), y) +$(NAME)_COMPONENTS += components/jpeg +$(NAME)_COMPONENTS += components/jrtc +$(NAME)_INCS += ../../components/jrtc/inc + +endif + +ifeq ($(CONFIG_SENSOR_VC9202), y) +$(NAME)_COMPONENTS += components/sensor/VC9202 +$(NAME)_INCS += ../../components/sensor/VS9202/inc +$(NAME)_INCS += ../../components/sensor/VS9202/algo/inc +endif + +ifeq ($(CONFIG_POC), y) +$(NAME)_CFLAGS += \ + -Wno-error=incompatible-pointer-types \ + -Wno-error=ignored-qualifiers \ + -Wno-error=int-conversion \ + -Wno-error=implicit-function-declaration \ + -Wno-error=discarded-qualifiers \ + -Wno-error=unused-const-variable= + +$(NAME)_COMPONENTS += components/poc +endif + +ifeq ($(CONFIG_QRCODE), y) +$(NAME)_COMPONENTS += components/qrcode +endif + +ifeq ($(CONFIG_HX3918), y) +$(NAME)_COMPONENTS += components/HX3918 +endif +ifeq ($(CONFIG_GH301x), y) +$(NAME)_COMPONENTS += components/GH301X +endif +ifeq ($(CONFIG_SC7A20), y) +$(NAME)_COMPONENTS += components/SC7A20 +endif +ifeq ($(CONFIG_juphoon), y) +$(NAME)_COMPONENTS += components/juphoon +endif + +ifeq ($(CONFIG_LIBSSH2), y) +$(NAME)_INCS += ../../components/ssh2/include \ + ../../components/ssh2/src +$(NAME)_COMPONENTS += components/ssh2 +endif + +ifeq ($(CONFIG_QUECTHING), y) +$(NAME)_INCS += ../../components/quecsdk +$(NAME)_COMPONENTS += components/quecsdk +endif + +ifeq ($(CONFIG_GMSSL), y) +$(NAME)_COMPONENTS += components/GMSSL +endif + +ifeq ($(CONFIG_GB2312), y) +$(NAME)_COMPONENTS += components/decode/gb2312 +endif + +ifeq ($(CONFIG_ESIMSDK), y) +$(NAME)_COMPONENTS += components/esim +endif + +ifeq ($(CONFIG_NFC_SL6320), y) +$(NAME)_COMPONENTS += components/NFC/SL6320 +endif + +ifeq ($(CONFIG_VOIP), y) +$(NAME)_INCS += ../../components/voip/libexosip2/include \ + ../../components/voip/libosip2/include \ + ../../components/voip/rtp +$(NAME)_COMPONENTS += components/voip +endif + +ifeq ($(CONFIG_ETHERNET_W5500), y) +$(NAME)_COMPONENTS += components/ethernet +$(NAME)_INCS += ../../components/ethernet/wiznet +endif + +ifeq ($(CONFIG_SLIP), y) +$(NAME)_COMPONENTS += components/slip +$(NAME)_INCS += ../../components/slip +endif + +ifeq ($(CONFIG_DLMS), y) +$(NAME)_COMPONENTS += components/dlms +endif + +ifeq ($(CONFIG_MICROPYTHON_EXTENSION_PERF), y) +$(NAME)_COMPONENTS += components/micropython_extension +$(NAME)_INCS += ../../components/micropython_extension/perf +endif + +ifeq ($(CONFIG_MICROPYTHON_EXTENSION_SECURE_APP), y) +$(NAME)_COMPONENTS += components/micropython_extension +$(NAME)_INCS += ../../components/micropython_extension/secure_app +endif + +$(NAME)_CFLAGS += -Wno-error=implicit-fallthrough + +$(NAME)_PRIVATE_SCRIPT = private.mk + +$(NAME)_PRIVATE_SCRIPT_TARGETS = construct clean diff --git a/2.sdk/new_clean.bat b/2.sdk/new_clean.bat index 1c0c9961..331534aa 100644 --- a/2.sdk/new_clean.bat +++ b/2.sdk/new_clean.bat @@ -111,6 +111,13 @@ if errorlevel 1 ( ) cd .. +rem sync base release pack config from unpacked source dir +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0project\!PROJ!\tools\sync_base_pack_config.ps1" -Root:"%CD%" -Project:"!PROJ!" -Board:"!BOARD!" +if errorlevel 1 ( + echo [´íÎó] ͬ²½ firmware_base_release_pack ÅäÖÃʧ°Ü + exit /b 1 +) + rem versions.py: generated once inside new.bat (before xcopy/compile) call new.bat !PROJ! !PRODUCT_NAME! if errorlevel 1 ( diff --git a/2.sdk/project/7PIN_1_5/new.bat b/2.sdk/project/7PIN_1_5/new.bat index ed2c4a18..37eabed9 100644 --- a/2.sdk/project/7PIN_1_5/new.bat +++ b/2.sdk/project/7PIN_1_5/new.bat @@ -1,59 +1,74 @@ -@echo off -setlocal EnableDelayedExpansion -rem arg1=project arg2=PRODUCT_NAME (product_%2%.ini) -set "PROJ=%~1" -set "PRODUCT_NAME=%~2" -if "!PROJ!"=="" set "PROJ=7PIN_1_5" -if "!PRODUCT_NAME!"=="" ( - echo [ERROR] usage: new.bat ^ ^ - goto exit -) - -md images -del images /q - -:: 确保 7PIN_1_5 的 customer_fs(/usr) 内包含音频 NVM(增益/语音增强表) -:: 这两份文件会影响录音/通话的场景增益与 VE 参数;缺失时可能回退到默认表导致录音幅度异常。 -if exist "sdk\services\microPython\ports\quectel\core\audio_gain.nvm" ( - copy /y "sdk\services\microPython\ports\quectel\core\audio_gain.nvm" "usr\audio_gain.nvm" >nul -) -if exist "sdk\services\microPython\ports\quectel\core\audio_ve.nvm" ( - copy /y "sdk\services\microPython\ports\quectel\core\audio_ve.nvm" "usr\audio_ve.nvm" >nul -) - -@GOTO :STEP1 -..\..\Helios_SDK\tools\ASR_1606\win32\mklfs.exe -c ext -b 4096 -r 4096 -p 4096 -s 1048576 -i .\images\ext_fs.bin -if errorlevel 1 ( - echo "ext_fs.bin生成失败 !!!!!!!!!!!!!!! " - goto exit -) -if errorlevel 0 ( - echo "ext_fs.bin生成成功 !!!!!!!!!!!!!!! " -) -:STEP1 - -..\..\Helios_SDK\tools\ASR_1606\win32\mklfs.exe -c usr -b 4096 -r 4096 -p 4096 -s 1376256 -i .\images\customer_fs.bin -if errorlevel 1 ( - echo "customer_fs.bin生成失败 请检查usr目录是否大于316K!!!!!!!!!!!!!!!" - goto exit -) -if errorlevel 0 ( - echo "customer_fs.bin生成成功 !!!!!!!!!!!!!!! " -) - -%copy font\ext_font.bin images\ext_font.bin% - -..\..\Helios_SDK\tools\common\win32\7z\7z a sdk\system\platform\ASR_1606\boards\EG810MCN_GA_VOLTE\images\firmware_base_release_pack.zip .\images\ -if errorlevel 0 ( - echo images压缩成功!!!!!!!!!!!!!! -) -if errorlevel 1 ( - echo images压缩失败!!!!!!!!!!!!!!!!!! - goto exit -) -xcopy sdk\ ..\..\Helios_SDK\ /e/h/y -cd ..\..\Helios_SDK -helios.exe make services/microPython @EG810MCN_GA_VOLTE EG810MCN_GA_VOLTE -cd .. -:exit -endlocal +@echo off +setlocal EnableDelayedExpansion +rem arg1=project arg2=PRODUCT_NAME (product_%2%.ini) +cd /d "%~dp0" +set "PROJ=%~1" +set "PRODUCT_NAME=%~2" +if "!PROJ!"=="" set "PROJ=7PIN_1_5" +if "!PRODUCT_NAME!"=="" ( + echo [ERROR] usage: new.bat ^ ^ + exit /b 1 +) + +md images 2>nul +del /q images\* 2>nul + +rem sync audio NVM into usr for customer_fs (gain / VE tables) +if exist "sdk\services\microPython\ports\quectel\core\audio_gain.nvm" ( + copy /y "sdk\services\microPython\ports\quectel\core\audio_gain.nvm" "usr\audio_gain.nvm" >nul +) +if exist "sdk\services\microPython\ports\quectel\core\audio_ve.nvm" ( + copy /y "sdk\services\microPython\ports\quectel\core\audio_ve.nvm" "usr\audio_ve.nvm" >nul +) + +..\..\Helios_SDK\tools\ASR_1606\win32\mklfs.exe -c ext -b 4096 -r 4096 -p 4096 -s 1048576 -i .\images\ext_fs.bin +if errorlevel 1 ( + echo [ERROR] ext_fs.bin failed + exit /b 1 +) +echo [OK] ext_fs.bin + +..\..\Helios_SDK\tools\ASR_1606\win32\mklfs.exe -c usr -b 4096 -r 4096 -p 4096 -s 1007616 -i .\images\customer_fs.bin +if errorlevel 1 ( + echo [ERROR] customer_fs.bin failed - check usr size + exit /b 1 +) +echo [OK] customer_fs.bin + +if exist "font\ext_font.bin" copy /y "font\ext_font.bin" "images\ext_font.bin" >nul + +..\..\Helios_SDK\tools\common\win32\7z\7z a sdk\system\platform\ASR_1606\boards\EG810MCN_GA_VOLTE\images\firmware_base_release_pack.zip .\images\ +if errorlevel 1 ( + echo [ERROR] firmware_base_release_pack.zip failed + exit /b 1 +) +echo [OK] images zip + +rem run sync again before xcopy to avoid stale zip entries +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0tools\sync_base_pack_config.ps1" -Root:"%~dp0..\.." -Project:"!PROJ!" -Board:"EG810MCN_GA_VOLTE" +if errorlevel 1 ( + echo [ERROR] sync_base_pack_config.ps1 failed + exit /b 1 +) + +xcopy sdk\ ..\..\Helios_SDK\ /e/h/y +if errorlevel 1 ( + echo [ERROR] xcopy to Helios_SDK failed + exit /b 1 +) + +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0tools\ensure_helios_opus_mk.ps1" -HeliosRoot:"%~dp0..\..\Helios_SDK" +if errorlevel 1 ( + echo [ERROR] ensure_helios_opus_mk.ps1 failed + exit /b 1 +) + +cd /d "%~dp0..\..\Helios_SDK" +helios.exe make services/microPython @EG810MCN_GA_VOLTE EG810MCN_GA_VOLTE +if errorlevel 1 ( + cd /d "%~dp0" + exit /b 1 +) +cd /d "%~dp0" +exit /b 0 + diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/microPython_opus.mk b/2.sdk/project/7PIN_1_5/sdk/services/microPython/microPython_opus.mk new file mode 100644 index 00000000..f5aab708 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/microPython_opus.mk @@ -0,0 +1,7 @@ +# 7PIN_1_5 Opus(xcopy -> Helios_SDK/services/microPython/microPython_opus.mk) +# 由 microPython.mk 在 $(NAME)_SRCS)+= 之前 -include(目录用 _MP_MK_DIR) +ifeq ($(CONFIG_OPUS), y) +QPY_SRCS += ports/quectel/core/source/modopus.c +$(NAME)_SRCS += ports/quectel/core/source/modopus.c +$(NAME)_ARCHIVES += ports/quectel/core/source/libopus_min.a +endif diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile index cb3ec6aa..26456dd5 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/Makefile @@ -404,6 +404,11 @@ SRC_QSTR += lib/usqlite/usqlite_connection.c \ INC += -Ilib/usqlite endif +ifeq ($(CONFIG_OPUS), y) +SRC_QSTR += source/modopus.c +INC += -Isource/opus +endif + $(BUILD)/%.pp: %.c @$(ECHO) "PreProcess $<" $(Q)$(CPP) $(C_FLAGS) -Wp,-C,-dD,-dI -o $@ $< diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py index 8ed229c7..89fb28ca 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/default_config.py @@ -133,6 +133,12 @@ KEY_RELEASE_DEBOUNCE_COUNT = 5 AI_LONG_PRESS_POWER_OFF_ENABLED = False # AI 键长按 8s 关机 SOS_ENABLED = False # AI 长按 3s SOS、板载 SOS 入口 +# ============================================================================= +# 6.1 看门狗(WDT) +# ============================================================================= +WDT_ENABLED = False +WDT_TIMEOUT_S = 30 # 需大于喂狗周期(默认 10s),建议 >= 15 + # ============================================================================= # 7. VC 会话 / WebSocket / 空闲与休眠 # ============================================================================= diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/opus_codec.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/opus_codec.py new file mode 100644 index 00000000..c4a22281 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/opus_codec.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +"""Opus 编解码薄封装(16kHz 单声道,20ms 帧 = 320 字节 PCM)。""" +try: + from qp_log import qp_print as print +except Exception: + pass + +import opus + +FRAME_PCM_BYTES = opus.FRAME_PCM_BYTES +SAMPLE_RATE = opus.SAMPLE_RATE + + +class OpusCodec: + """上行编码 / 下行解码可独立开关。""" + + def __init__(self, encoder=True, decoder=True): + self._c = opus.OpusCodec(encoder=encoder, decoder=decoder) + + def encode(self, pcm): + if len(pcm) != FRAME_PCM_BYTES: + raise ValueError("pcm must be %d bytes" % FRAME_PCM_BYTES) + return self._c.encode(pcm) + + def decode(self, pkt): + return self._c.decode(pkt) + + def close(self): + self._c.close() diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/products/configs/k8v3/default_config.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/products/configs/k8v3/default_config.py index 8ed229c7..89fb28ca 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/products/configs/k8v3/default_config.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/products/configs/k8v3/default_config.py @@ -133,6 +133,12 @@ KEY_RELEASE_DEBOUNCE_COUNT = 5 AI_LONG_PRESS_POWER_OFF_ENABLED = False # AI 键长按 8s 关机 SOS_ENABLED = False # AI 长按 3s SOS、板载 SOS 入口 +# ============================================================================= +# 6.1 看门狗(WDT) +# ============================================================================= +WDT_ENABLED = False +WDT_TIMEOUT_S = 30 # 需大于喂狗周期(默认 10s),建议 >= 15 + # ============================================================================= # 7. VC 会话 / WebSocket / 空闲与休眠 # ============================================================================= diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/OPUS_BUILD.txt b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/OPUS_BUILD.txt new file mode 100644 index 00000000..7cf0a686 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/OPUS_BUILD.txt @@ -0,0 +1,37 @@ +Opus 集成说明(7PIN_1_5 / EG810MCN_GA_VOLTE) +========================================== + +1. 扩大 APP 分区 + project/.../app_link_start_addr.h 中 APP_FLASH_MAX_SIZE=0x1F8000(对齐 K8) + +2. 头文件与静态库(与 imsl_vad 相同,均在 source/ 下) + source/opus/*.h — 从 opus 官方 include 拷贝的公开头(固件编译用) + source/libopus_min.a — 预编译 Opus 库 + +3. 重新生成 libopus_min.a(可选) + 将 opus-1.4 源码解压到 project/7PIN_1_5/tools/opus_src/ + cd 2.sdk\project\7PIN_1_5\tools + build_opus_min.bat + +4. 配置开关 + config.mk / autoconf.h: CONFIG_OPUS=y + +5. 固件编译 + cd 2.sdk + new_clean.bat k8v3 + xcopy 后 Helios_SDK/services/microPython/microPython_opus.mk 由本工程提供; + new.bat 会 ensure Helios microPython.mk 在 libimslvad 后 -include microPython_opus.mk; + modopus.c 使用 MP_REGISTER_MODULE 注册 import opus(无需改 mpconfigport.h) + +6. REPL 自测 + import opus + print(opus.version()) + c = opus.OpusCodec(encoder=True, decoder=True) + pkt = c.encode(bytes(320)) + pcm = c.decode(pkt) + c.close() + +7. 接入 VC 上行(未默认开启) + 在 vc_session_media.VC_record_thread 中 AI_client_VC_send 前调用 OpusCodec.encode + +注意: 未生成 libopus_min.a 时链接会失败;可临时 CONFIG_OPUS=n。 diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/libopus_min.a b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/libopus_min.a new file mode 100644 index 00000000..5fa37510 Binary files /dev/null and b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/libopus_min.a differ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modopus.c b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modopus.c new file mode 100644 index 00000000..2c7f7180 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/modopus.c @@ -0,0 +1,185 @@ +/* + * MicroPython Opus 编解码(最简 API,16kHz 单声道 VOIP) + * 依赖 libopus_min.a 与 source/opus 下头文件(同 imsl_vad 目录习惯) + */ +#include +#include "py/runtime.h" +#include "py/binary.h" +#include "mperrno.h" +#include "helios_debug.h" +#include "autoconf.h" + +#if CONFIG_OPUS + +#include "opus.h" + +#define MOD_OPUS_LOG(msg, ...) custom_log("modopus", msg, ##__VA_ARGS__) + +#define OPUS_CODEC_SR_HZ 16000 +#define OPUS_CODEC_CHANNELS 1 +#define OPUS_CODEC_FRAME_PCM 320 +#define OPUS_CODEC_MAX_PKT 400 + +typedef struct _mp_obj_OpusCodec_t { + mp_obj_base_t base; + OpusEncoder *enc; + OpusDecoder *dec; + int has_enc; + int has_dec; +} mp_obj_OpusCodec_t; + +static const mp_obj_type_t OpusCodec_type; + +static int opus_codec_check_pcm_len(mp_uint_t len) +{ + if (len != OPUS_CODEC_FRAME_PCM) { + MOD_OPUS_LOG("pcm len=%u expect=%d", (unsigned)len, OPUS_CODEC_FRAME_PCM); + return -1; + } + return 0; +} + +STATIC mp_obj_t OpusCodec_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) +{ + static const mp_arg_t allowed[] = { + { MP_QSTR_encoder, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } }, + { MP_QSTR_decoder, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } }, + }; + mp_arg_val_t parsed[2]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, 2, allowed, parsed); + + mp_obj_OpusCodec_t *self = m_new_obj(mp_obj_OpusCodec_t); + self->base.type = &OpusCodec_type; + self->enc = NULL; + self->dec = NULL; + self->has_enc = 0; + self->has_dec = 0; + + int err = 0; + if (parsed[0].u_bool) { + self->enc = opus_encoder_create(OPUS_CODEC_SR_HZ, OPUS_CODEC_CHANNELS, + OPUS_APPLICATION_VOIP, &err); + if (err != OPUS_OK || self->enc == NULL) { + mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("opus_encoder_create failed")); + } + opus_encoder_ctl(self->enc, OPUS_SET_COMPLEXITY(5)); + opus_encoder_ctl(self->enc, OPUS_SET_BITRATE(24000)); + self->has_enc = 1; + } + if (parsed[1].u_bool) { + self->dec = opus_decoder_create(OPUS_CODEC_SR_HZ, OPUS_CODEC_CHANNELS, &err); + if (err != OPUS_OK || self->dec == NULL) { + if (self->enc) { + opus_encoder_destroy(self->enc); + self->enc = NULL; + } + mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("opus_decoder_create failed")); + } + self->has_dec = 1; + } + if (!self->has_enc && !self->has_dec) { + mp_raise_ValueError(MP_ERROR_TEXT("encoder or decoder required")); + } + return MP_OBJ_FROM_PTR(self); +} + +STATIC mp_obj_t opus_codec_encode(mp_obj_t self_in, mp_obj_t pcm_in) +{ + mp_obj_OpusCodec_t *self = MP_OBJ_TO_PTR(self_in); + if (!self->has_enc || self->enc == NULL) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("encoder not open")); + } + mp_buffer_info_t pcm; + mp_get_buffer_raise(pcm_in, &pcm, MP_BUFFER_READ); + if (opus_codec_check_pcm_len(pcm.len) != 0) { + mp_raise_ValueError(MP_ERROR_TEXT("pcm frame must be 320 bytes")); + } + uint8_t out[OPUS_CODEC_MAX_PKT]; + mp_int_t n = opus_encode(self->enc, (const opus_int16 *)pcm.buf, OPUS_CODEC_FRAME_PCM / 2, + out, OPUS_CODEC_MAX_PKT); + if (n < 0) { + mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("opus_encode %d"), (int)n); + } + return mp_obj_new_bytes(out, (mp_uint_t)n); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(opus_encode_obj, opus_codec_encode); + +STATIC mp_obj_t opus_codec_decode(mp_obj_t self_in, mp_obj_t pkt_in) +{ + mp_obj_OpusCodec_t *self = MP_OBJ_TO_PTR(self_in); + if (!self->has_dec || self->dec == NULL) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("decoder not open")); + } + mp_buffer_info_t pkt; + mp_get_buffer_raise(pkt_in, &pkt, MP_BUFFER_READ); + if (pkt.len == 0 || pkt.len > OPUS_CODEC_MAX_PKT) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid opus packet")); + } + opus_int16 pcm[OPUS_CODEC_FRAME_PCM / 2]; + mp_int_t n = opus_decode(self->dec, pkt.buf, (opus_int32)pkt.len, pcm, + OPUS_CODEC_FRAME_PCM / 2, 0); + if (n < 0) { + mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("opus_decode %d"), (int)n); + } + if (n != OPUS_CODEC_FRAME_PCM / 2) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("opus_decode short frame")); + } + return mp_obj_new_bytes((const byte *)pcm, OPUS_CODEC_FRAME_PCM); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(opus_decode_obj, opus_codec_decode); + +STATIC mp_obj_t opus_close(mp_obj_t self_in) +{ + mp_obj_OpusCodec_t *self = MP_OBJ_TO_PTR(self_in); + if (self->enc) { + opus_encoder_destroy(self->enc); + self->enc = NULL; + } + if (self->dec) { + opus_decoder_destroy(self->dec); + self->dec = NULL; + } + self->has_enc = 0; + self->has_dec = 0; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(opus_close_obj, opus_close); + +STATIC mp_obj_t opus_version(mp_obj_t cls_in) +{ + (void)cls_in; + return mp_obj_new_str(opus_get_version_string(), strlen(opus_get_version_string())); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(opus_version_obj, opus_version); + +STATIC const mp_rom_map_elem_t OpusCodec_locals[] = { + { MP_ROM_QSTR(MP_QSTR_encode), MP_ROM_PTR(&opus_encode_obj) }, + { MP_ROM_QSTR(MP_QSTR_decode), MP_ROM_PTR(&opus_decode_obj) }, + { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&opus_close_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(OpusCodec_locals_dict, OpusCodec_locals); + +STATIC const mp_obj_type_t OpusCodec_type = { + { &mp_type_type }, + .name = MP_QSTR_OpusCodec, + .make_new = OpusCodec_make_new, + .locals_dict = (void *)&OpusCodec_locals_dict, +}; + +STATIC const mp_rom_map_elem_t opus_module_globals[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_opus) }, + { MP_ROM_QSTR(MP_QSTR_OpusCodec), MP_ROM_PTR(&OpusCodec_type) }, + { MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&opus_version_obj) }, + { MP_ROM_QSTR(MP_QSTR_FRAME_PCM_BYTES), MP_ROM_INT(OPUS_CODEC_FRAME_PCM) }, + { MP_ROM_QSTR(MP_QSTR_SAMPLE_RATE), MP_ROM_INT(OPUS_CODEC_SR_HZ) }, +}; +STATIC MP_DEFINE_CONST_DICT(opus_module_globals_dict, opus_module_globals); + +const mp_obj_module_t mp_module_opus = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&opus_module_globals_dict, +}; + +MP_REGISTER_MODULE(MP_QSTR_opus, mp_module_opus, CONFIG_OPUS); + +#endif /* CONFIG_OPUS */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus.h new file mode 100644 index 00000000..0c69c627 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus.h @@ -0,0 +1,981 @@ +/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited + Written by Jean-Marc Valin and Koen Vos */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus.h + * @brief Opus reference implementation API + */ + +#ifndef OPUS_H +#define OPUS_H + +#include "opus_types.h" +#include "opus_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @mainpage Opus + * + * The Opus codec is designed for interactive speech and audio transmission over the Internet. + * It is designed by the IETF Codec Working Group and incorporates technology from + * Skype's SILK codec and Xiph.Org's CELT codec. + * + * The Opus codec is designed to handle a wide range of interactive audio applications, + * including Voice over IP, videoconferencing, in-game chat, and even remote live music + * performances. It can scale from low bit-rate narrowband speech to very high quality + * stereo music. Its main features are: + + * @li Sampling rates from 8 to 48 kHz + * @li Bit-rates from 6 kb/s to 510 kb/s + * @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR) + * @li Audio bandwidth from narrowband to full-band + * @li Support for speech and music + * @li Support for mono and stereo + * @li Support for multichannel (up to 255 channels) + * @li Frame sizes from 2.5 ms to 60 ms + * @li Good loss robustness and packet loss concealment (PLC) + * @li Floating point and fixed-point implementation + * + * Documentation sections: + * @li @ref opus_encoder + * @li @ref opus_decoder + * @li @ref opus_repacketizer + * @li @ref opus_multistream + * @li @ref opus_libinfo + * @li @ref opus_custom + */ + +/** @defgroup opus_encoder Opus Encoder + * @{ + * + * @brief This page describes the process and functions used to encode Opus. + * + * Since Opus is a stateful codec, the encoding process starts with creating an encoder + * state. This can be done with: + * + * @code + * int error; + * OpusEncoder *enc; + * enc = opus_encoder_create(Fs, channels, application, &error); + * @endcode + * + * From this point, @c enc can be used for encoding an audio stream. An encoder state + * @b must @b not be used for more than one stream at the same time. Similarly, the encoder + * state @b must @b not be re-initialized for each frame. + * + * While opus_encoder_create() allocates memory for the state, it's also possible + * to initialize pre-allocated memory: + * + * @code + * int size; + * int error; + * OpusEncoder *enc; + * size = opus_encoder_get_size(channels); + * enc = malloc(size); + * error = opus_encoder_init(enc, Fs, channels, application); + * @endcode + * + * where opus_encoder_get_size() returns the required size for the encoder state. Note that + * future versions of this code may change the size, so no assuptions should be made about it. + * + * The encoder state is always continuous in memory and only a shallow copy is sufficient + * to copy it (e.g. memcpy()) + * + * It is possible to change some of the encoder's settings using the opus_encoder_ctl() + * interface. All these settings already default to the recommended value, so they should + * only be changed when necessary. The most common settings one may want to change are: + * + * @code + * opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)); + * opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); + * opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type)); + * @endcode + * + * where + * + * @arg bitrate is in bits per second (b/s) + * @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest + * @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC + * + * See @ref opus_encoderctls and @ref opus_genericctls for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream. + * + * To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data: + * @code + * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); + * @endcode + * + * where + *
    + *
  • audio_frame is the audio data in opus_int16 (or float for opus_encode_float())
  • + *
  • frame_size is the duration of the frame in samples (per channel)
  • + *
  • packet is the byte array to which the compressed data is written
  • + *
  • max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended). + * Do not use max_packet to control VBR target bitrate, instead use the #OPUS_SET_BITRATE CTL.
  • + *
+ * + * opus_encode() and opus_encode_float() return the number of bytes actually written to the packet. + * The return value can be negative, which indicates that an error has occurred. If the return value + * is 2 bytes or less, then the packet does not need to be transmitted (DTX). + * + * Once the encoder state if no longer needed, it can be destroyed with + * + * @code + * opus_encoder_destroy(enc); + * @endcode + * + * If the encoder was created with opus_encoder_init() rather than opus_encoder_create(), + * then no action is required aside from potentially freeing the memory that was manually + * allocated for it (calling free(enc) for the example above) + * + */ + +/** Opus encoder state. + * This contains the complete state of an Opus encoder. + * It is position independent and can be freely copied. + * @see opus_encoder_create,opus_encoder_init + */ +typedef struct OpusEncoder OpusEncoder; + +/** Gets the size of an OpusEncoder structure. + * @param[in] channels int: Number of channels. + * This must be 1 or 2. + * @returns The size in bytes. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels); + +/** + */ + +/** Allocates and initializes an encoder state. + * There are three coding modes: + * + * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice + * signals. It enhances the input signal by high-pass filtering and + * emphasizing formants and harmonics. Optionally it includes in-band + * forward error correction to protect against packet loss. Use this + * mode for typical VoIP applications. Because of the enhancement, + * even at high bitrates the output may sound different from the input. + * + * @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most + * non-voice signals like music. Use this mode for music and mixed + * (music/voice) content, broadcast, and applications requiring less + * than 15 ms of coding delay. + * + * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that + * disables the speech-optimized mode in exchange for slightly reduced delay. + * This mode can only be set on an newly initialized or freshly reset encoder + * because it changes the codec delay. + * + * This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution). + * @param [in] Fs opus_int32: Sampling rate of input signal (Hz) + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) in input signal + * @param [in] application int: Coding mode (one of @ref OPUS_APPLICATION_VOIP, @ref OPUS_APPLICATION_AUDIO, or @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY) + * @param [out] error int*: @ref opus_errorcodes + * @note Regardless of the sampling rate and number channels selected, the Opus encoder + * can switch to a lower audio bandwidth or number of channels if the bitrate + * selected is too low. This also means that it is safe to always use 48 kHz stereo input + * and let the encoder optimize the encoding. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create( + opus_int32 Fs, + int channels, + int application, + int *error +); + +/** Initializes a previously allocated encoder state + * The memory pointed to by st must be at least the size returned by opus_encoder_get_size(). + * This is intended for applications which use their own allocator instead of malloc. + * @see opus_encoder_create(),opus_encoder_get_size() + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @param [in] st OpusEncoder*: Encoder state + * @param [in] Fs opus_int32: Sampling rate of input signal (Hz) + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) in input signal + * @param [in] application int: Coding mode (one of OPUS_APPLICATION_VOIP, OPUS_APPLICATION_AUDIO, or OPUS_APPLICATION_RESTRICTED_LOWDELAY) + * @retval #OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_encoder_init( + OpusEncoder *st, + opus_int32 Fs, + int channels, + int application +) OPUS_ARG_NONNULL(1); + +/** Encodes an Opus frame. + * @param [in] st OpusEncoder*: Encoder state + * @param [in] pcm opus_int16*: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size int: Number of samples per channel in the + * input signal. + * This must be an Opus frame size for + * the encoder's sampling rate. + * For example, at 48 kHz the permitted + * values are 120, 240, 480, 960, 1920, + * and 2880. + * Passing in a duration of less than + * 10 ms (480 samples at 48 kHz) will + * prevent the encoder from using the LPC + * or hybrid modes. + * @param [out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode( + OpusEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Encodes an Opus frame from floating point input. + * @param [in] st OpusEncoder*: Encoder state + * @param [in] pcm float*: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0. + * Samples with a range beyond +/-1.0 are supported but will + * be clipped by decoders using the integer API and should + * only be used if it is known that the far end supports + * extended dynamic range. + * length is frame_size*channels*sizeof(float) + * @param [in] frame_size int: Number of samples per channel in the + * input signal. + * This must be an Opus frame size for + * the encoder's sampling rate. + * For example, at 48 kHz the permitted + * values are 120, 240, 480, 960, 1920, + * and 2880. + * Passing in a duration of less than + * 10 ms (480 samples at 48 kHz) will + * prevent the encoder from using the LPC + * or hybrid modes. + * @param [out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float( + OpusEncoder *st, + const float *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Frees an OpusEncoder allocated by opus_encoder_create(). + * @param[in] st OpusEncoder*: State to be freed. + */ +OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st); + +/** Perform a CTL function on an Opus encoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @param st OpusEncoder*: Encoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls or + * @ref opus_encoderctls. + * @see opus_genericctls + * @see opus_encoderctls + */ +OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); +/**@}*/ + +/** @defgroup opus_decoder Opus Decoder + * @{ + * + * @brief This page describes the process and functions used to decode Opus. + * + * The decoding process also starts with creating a decoder + * state. This can be done with: + * @code + * int error; + * OpusDecoder *dec; + * dec = opus_decoder_create(Fs, channels, &error); + * @endcode + * where + * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000 + * @li channels is the number of channels (1 or 2) + * @li error will hold the error code in case of failure (or #OPUS_OK on success) + * @li the return value is a newly created decoder state to be used for decoding + * + * While opus_decoder_create() allocates memory for the state, it's also possible + * to initialize pre-allocated memory: + * @code + * int size; + * int error; + * OpusDecoder *dec; + * size = opus_decoder_get_size(channels); + * dec = malloc(size); + * error = opus_decoder_init(dec, Fs, channels); + * @endcode + * where opus_decoder_get_size() returns the required size for the decoder state. Note that + * future versions of this code may change the size, so no assuptions should be made about it. + * + * The decoder state is always continuous in memory and only a shallow copy is sufficient + * to copy it (e.g. memcpy()) + * + * To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data: + * @code + * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); + * @endcode + * where + * + * @li packet is the byte array containing the compressed data + * @li len is the exact number of bytes contained in the packet + * @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float()) + * @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array + * + * opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet. + * If that value is negative, then an error has occurred. This can occur if the packet is corrupted or if the audio + * buffer is too small to hold the decoded audio. + * + * Opus is a stateful codec with overlapping blocks and as a result Opus + * packets are not coded independently of each other. Packets must be + * passed into the decoder serially and in the correct order for a correct + * decode. Lost packets can be replaced with loss concealment by calling + * the decoder with a null pointer and zero length for the missing packet. + * + * A single codec state may only be accessed from a single thread at + * a time and any required locking must be performed by the caller. Separate + * streams must be decoded with separate decoder states and can be decoded + * in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK + * defined. + * + */ + +/** Opus decoder state. + * This contains the complete state of an Opus decoder. + * It is position independent and can be freely copied. + * @see opus_decoder_create,opus_decoder_init + */ +typedef struct OpusDecoder OpusDecoder; + +/** Gets the size of an OpusDecoder structure. + * @param [in] channels int: Number of channels. + * This must be 1 or 2. + * @returns The size in bytes. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels); + +/** Allocates and initializes a decoder state. + * @param [in] Fs opus_int32: Sample rate to decode at (Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) to decode + * @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes + * + * Internally Opus stores data at 48000 Hz, so that should be the default + * value for Fs. However, the decoder can efficiently decode to buffers + * at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use + * data at the full sample rate, or knows the compressed data doesn't + * use the full frequency range, it can request decoding at a reduced + * rate. Likewise, the decoder is capable of filling in either mono or + * interleaved stereo pcm buffers, at the caller's request. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create( + opus_int32 Fs, + int channels, + int *error +); + +/** Initializes a previously allocated decoder state. + * The state must be at least the size returned by opus_decoder_get_size(). + * This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @param [in] st OpusDecoder*: Decoder state. + * @param [in] Fs opus_int32: Sampling rate to decode to (Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param [in] channels int: Number of channels (1 or 2) to decode + * @retval #OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_EXPORT int opus_decoder_init( + OpusDecoder *st, + opus_int32 Fs, + int channels +) OPUS_ARG_NONNULL(1); + +/** Decode an Opus packet. + * @param [in] st OpusDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len opus_int32: Number of bytes in payload* + * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size Number of samples per channel of available space in \a pcm. + * If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will + * not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), + * then frame_size needs to be exactly the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the next incoming packet. For the PLC and + * FEC cases, frame_size must be a multiple of 2.5 ms. + * @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be + * decoded. If no such data is available, the frame is decoded as if it were lost. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode( + OpusDecoder *st, + const unsigned char *data, + opus_int32 len, + opus_int16 *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Decode an Opus packet with floating point output. + * @param [in] st OpusDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len opus_int32: Number of bytes in payload + * @param [out] pcm float*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(float) + * @param [in] frame_size Number of samples per channel of available space in \a pcm. + * If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will + * not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), + * then frame_size needs to be exactly the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the next incoming packet. For the PLC and + * FEC cases, frame_size must be a multiple of 2.5 ms. + * @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be + * decoded. If no such data is available the frame is decoded as if it were lost. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float( + OpusDecoder *st, + const unsigned char *data, + opus_int32 len, + float *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on an Opus decoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @param st OpusDecoder*: Decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls or + * @ref opus_decoderctls. + * @see opus_genericctls + * @see opus_decoderctls + */ +OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); + +/** Frees an OpusDecoder allocated by opus_decoder_create(). + * @param[in] st OpusDecoder*: State to be freed. + */ +OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st); + +/** Parse an opus packet into one or more frames. + * Opus_decode will perform this operation internally so most applications do + * not need to use this function. + * This function does not copy the frames, the returned pointers are pointers into + * the input packet. + * @param [in] data char*: Opus packet to be parsed + * @param [in] len opus_int32: size of data + * @param [out] out_toc char*: TOC pointer + * @param [out] frames char*[48] encapsulated frames + * @param [out] size opus_int16[48] sizes of the encapsulated frames + * @param [out] payload_offset int*: returns the position of the payload within the packet (in bytes) + * @returns number of frames + */ +OPUS_EXPORT int opus_packet_parse( + const unsigned char *data, + opus_int32 len, + unsigned char *out_toc, + const unsigned char *frames[48], + opus_int16 size[48], + int *payload_offset +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5); + +/** Gets the bandwidth of an Opus packet. + * @param [in] data char*: Opus packet + * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) + * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) + * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) + * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) + * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1); + +/** Gets the number of samples per frame from an Opus packet. + * @param [in] data char*: Opus packet. + * This must contain at least one byte of + * data. + * @param [in] Fs opus_int32: Sampling rate in Hz. + * This must be a multiple of 400, or + * inaccurate results will be returned. + * @returns Number of samples per frame. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1); + +/** Gets the number of channels from an Opus packet. + * @param [in] data char*: Opus packet + * @returns Number of channels + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1); + +/** Gets the number of frames in an Opus packet. + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @returns Number of frames + * @retval OPUS_BAD_ARG Insufficient data was passed to the function + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1); + +/** Gets the number of samples of an Opus packet. + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @param [in] Fs opus_int32: Sampling rate in Hz. + * This must be a multiple of 400, or + * inaccurate results will be returned. + * @returns Number of samples + * @retval OPUS_BAD_ARG Insufficient data was passed to the function + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1); + +/** Gets the number of samples of an Opus packet. + * @param [in] dec OpusDecoder*: Decoder state + * @param [in] packet char*: Opus packet + * @param [in] len opus_int32: Length of packet + * @returns Number of samples + * @retval OPUS_BAD_ARG Insufficient data was passed to the function + * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); + +/** Applies soft-clipping to bring a float signal within the [-1,1] range. If + * the signal is already in that range, nothing is done. If there are values + * outside of [-1,1], then the signal is clipped as smoothly as possible to + * both fit in the range and avoid creating excessive distortion in the + * process. + * @param [in,out] pcm float*: Input PCM and modified PCM + * @param [in] frame_size int Number of samples per channel to process + * @param [in] channels int: Number of channels + * @param [in,out] softclip_mem float*: State memory for the soft clipping process (one float per channel, initialized to zero) + */ +OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem); + + +/**@}*/ + +/** @defgroup opus_repacketizer Repacketizer + * @{ + * + * The repacketizer can be used to merge multiple Opus packets into a single + * packet or alternatively to split Opus packets that have previously been + * merged. Splitting valid Opus packets is always guaranteed to succeed, + * whereas merging valid packets only succeeds if all frames have the same + * mode, bandwidth, and frame size, and when the total duration of the merged + * packet is no more than 120 ms. The 120 ms limit comes from the + * specification and limits decoder memory requirements at a point where + * framing overhead becomes negligible. + * + * The repacketizer currently only operates on elementary Opus + * streams. It will not manipualte multistream packets successfully, except in + * the degenerate case where they consist of data from a single stream. + * + * The repacketizing process starts with creating a repacketizer state, either + * by calling opus_repacketizer_create() or by allocating the memory yourself, + * e.g., + * @code + * OpusRepacketizer *rp; + * rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size()); + * if (rp != NULL) + * opus_repacketizer_init(rp); + * @endcode + * + * Then the application should submit packets with opus_repacketizer_cat(), + * extract new packets with opus_repacketizer_out() or + * opus_repacketizer_out_range(), and then reset the state for the next set of + * input packets via opus_repacketizer_init(). + * + * For example, to split a sequence of packets into individual frames: + * @code + * unsigned char *data; + * int len; + * while (get_next_packet(&data, &len)) + * { + * unsigned char out[1276]; + * opus_int32 out_len; + * int nb_frames; + * int err; + * int i; + * err = opus_repacketizer_cat(rp, data, len); + * if (err != OPUS_OK) + * { + * release_packet(data); + * return err; + * } + * nb_frames = opus_repacketizer_get_nb_frames(rp); + * for (i = 0; i < nb_frames; i++) + * { + * out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out)); + * if (out_len < 0) + * { + * release_packet(data); + * return (int)out_len; + * } + * output_next_packet(out, out_len); + * } + * opus_repacketizer_init(rp); + * release_packet(data); + * } + * @endcode + * + * Alternatively, to combine a sequence of frames into packets that each + * contain up to TARGET_DURATION_MS milliseconds of data: + * @code + * // The maximum number of packets with duration TARGET_DURATION_MS occurs + * // when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5) + * // packets. + * unsigned char *data[(TARGET_DURATION_MS*2/5)+1]; + * opus_int32 len[(TARGET_DURATION_MS*2/5)+1]; + * int nb_packets; + * unsigned char out[1277*(TARGET_DURATION_MS*2/2)]; + * opus_int32 out_len; + * int prev_toc; + * nb_packets = 0; + * while (get_next_packet(data+nb_packets, len+nb_packets)) + * { + * int nb_frames; + * int err; + * nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packets]); + * if (nb_frames < 1) + * { + * release_packets(data, nb_packets+1); + * return nb_frames; + * } + * nb_frames += opus_repacketizer_get_nb_frames(rp); + * // If adding the next packet would exceed our target, or it has an + * // incompatible TOC sequence, output the packets we already have before + * // submitting it. + * // N.B., The nb_packets > 0 check ensures we've submitted at least one + * // packet since the last call to opus_repacketizer_init(). Otherwise a + * // single packet longer than TARGET_DURATION_MS would cause us to try to + * // output an (invalid) empty packet. It also ensures that prev_toc has + * // been set to a valid value. Additionally, len[nb_packets] > 0 is + * // guaranteed by the call to opus_packet_get_nb_frames() above, so the + * // reference to data[nb_packets][0] should be valid. + * if (nb_packets > 0 && ( + * ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) || + * opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_frames > + * TARGET_DURATION_MS*48)) + * { + * out_len = opus_repacketizer_out(rp, out, sizeof(out)); + * if (out_len < 0) + * { + * release_packets(data, nb_packets+1); + * return (int)out_len; + * } + * output_next_packet(out, out_len); + * opus_repacketizer_init(rp); + * release_packets(data, nb_packets); + * data[0] = data[nb_packets]; + * len[0] = len[nb_packets]; + * nb_packets = 0; + * } + * err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]); + * if (err != OPUS_OK) + * { + * release_packets(data, nb_packets+1); + * return err; + * } + * prev_toc = data[nb_packets][0]; + * nb_packets++; + * } + * // Output the final, partial packet. + * if (nb_packets > 0) + * { + * out_len = opus_repacketizer_out(rp, out, sizeof(out)); + * release_packets(data, nb_packets); + * if (out_len < 0) + * return (int)out_len; + * output_next_packet(out, out_len); + * } + * @endcode + * + * An alternate way of merging packets is to simply call opus_repacketizer_cat() + * unconditionally until it fails. At that point, the merged packet can be + * obtained with opus_repacketizer_out() and the input packet for which + * opus_repacketizer_cat() needs to be re-added to a newly reinitialized + * repacketizer state. + */ + +typedef struct OpusRepacketizer OpusRepacketizer; + +/** Gets the size of an OpusRepacketizer structure. + * @returns The size in bytes. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void); + +/** (Re)initializes a previously allocated repacketizer state. + * The state must be at least the size returned by opus_repacketizer_get_size(). + * This can be used for applications which use their own allocator instead of + * malloc(). + * It must also be called to reset the queue of packets waiting to be + * repacketized, which is necessary if the maximum packet duration of 120 ms + * is reached or if you wish to submit packets with a different Opus + * configuration (coding mode, audio bandwidth, frame size, or channel count). + * Failure to do so will prevent a new packet from being added with + * opus_repacketizer_cat(). + * @see opus_repacketizer_create + * @see opus_repacketizer_get_size + * @see opus_repacketizer_cat + * @param rp OpusRepacketizer*: The repacketizer state to + * (re)initialize. + * @returns A pointer to the same repacketizer state that was passed in. + */ +OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); + +/** Allocates memory and initializes the new repacketizer with + * opus_repacketizer_init(). + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void); + +/** Frees an OpusRepacketizer allocated by + * opus_repacketizer_create(). + * @param[in] rp OpusRepacketizer*: State to be freed. + */ +OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp); + +/** Add a packet to the current repacketizer state. + * This packet must match the configuration of any packets already submitted + * for repacketization since the last call to opus_repacketizer_init(). + * This means that it must have the same coding mode, audio bandwidth, frame + * size, and channel count. + * This can be checked in advance by examining the top 6 bits of the first + * byte of the packet, and ensuring they match the top 6 bits of the first + * byte of any previously submitted packet. + * The total duration of audio in the repacketizer state also must not exceed + * 120 ms, the maximum duration of a single packet, after adding this packet. + * + * The contents of the current repacketizer state can be extracted into new + * packets using opus_repacketizer_out() or opus_repacketizer_out_range(). + * + * In order to add a packet with a different configuration or to add more + * audio beyond 120 ms, you must clear the repacketizer state by calling + * opus_repacketizer_init(). + * If a packet is too large to add to the current repacketizer state, no part + * of it is added, even if it contains multiple frames, some of which might + * fit. + * If you wish to be able to add parts of such packets, you should first use + * another repacketizer to split the packet into pieces and add them + * individually. + * @see opus_repacketizer_out_range + * @see opus_repacketizer_out + * @see opus_repacketizer_init + * @param rp OpusRepacketizer*: The repacketizer state to which to + * add the packet. + * @param[in] data const unsigned char*: The packet data. + * The application must ensure + * this pointer remains valid + * until the next call to + * opus_repacketizer_init() or + * opus_repacketizer_destroy(). + * @param len opus_int32: The number of bytes in the packet data. + * @returns An error code indicating whether or not the operation succeeded. + * @retval #OPUS_OK The packet's contents have been added to the repacketizer + * state. + * @retval #OPUS_INVALID_PACKET The packet did not have a valid TOC sequence, + * the packet's TOC sequence was not compatible + * with previously submitted packets (because + * the coding mode, audio bandwidth, frame size, + * or channel count did not match), or adding + * this packet would increase the total amount of + * audio stored in the repacketizer state to more + * than 120 ms. + */ +OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); + + +/** Construct a new packet from data previously submitted to the repacketizer + * state via opus_repacketizer_cat(). + * @param rp OpusRepacketizer*: The repacketizer state from which to + * construct the new packet. + * @param begin int: The index of the first frame in the current + * repacketizer state to include in the output. + * @param end int: One past the index of the last frame in the + * current repacketizer state to include in the + * output. + * @param[out] data const unsigned char*: The buffer in which to + * store the output packet. + * @param maxlen opus_int32: The maximum number of bytes to store in + * the output buffer. In order to guarantee + * success, this should be at least + * 1276 for a single frame, + * or for multiple frames, + * 1277*(end-begin). + * However, 1*(end-begin) plus + * the size of all packet data submitted to + * the repacketizer since the last call to + * opus_repacketizer_init() or + * opus_repacketizer_create() is also + * sufficient, and possibly much smaller. + * @returns The total size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BAD_ARG [begin,end) was an invalid range of + * frames (begin < 0, begin >= end, or end > + * opus_repacketizer_get_nb_frames()). + * @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the + * complete output packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Return the total number of frames contained in packet data submitted to + * the repacketizer state so far via opus_repacketizer_cat() since the last + * call to opus_repacketizer_init() or opus_repacketizer_create(). + * This defines the valid range of packets that can be extracted with + * opus_repacketizer_out_range() or opus_repacketizer_out(). + * @param rp OpusRepacketizer*: The repacketizer state containing the + * frames. + * @returns The total number of frames contained in the packet data submitted + * to the repacketizer state. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); + +/** Construct a new packet from data previously submitted to the repacketizer + * state via opus_repacketizer_cat(). + * This is a convenience routine that returns all the data submitted so far + * in a single packet. + * It is equivalent to calling + * @code + * opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp), + * data, maxlen) + * @endcode + * @param rp OpusRepacketizer*: The repacketizer state from which to + * construct the new packet. + * @param[out] data const unsigned char*: The buffer in which to + * store the output packet. + * @param maxlen opus_int32: The maximum number of bytes to store in + * the output buffer. In order to guarantee + * success, this should be at least + * 1277*opus_repacketizer_get_nb_frames(rp). + * However, + * 1*opus_repacketizer_get_nb_frames(rp) + * plus the size of all packet data + * submitted to the repacketizer since the + * last call to opus_repacketizer_init() or + * opus_repacketizer_create() is also + * sufficient, and possibly much smaller. + * @returns The total size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the + * complete output packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1); + +/** Pads a given Opus packet to a larger size (possibly changing the TOC sequence). + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to pad. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @param new_len opus_int32: The desired size of the packet after padding. + * This must be at least as large as len. + * @returns an error code + * @retval #OPUS_OK \a on success. + * @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len); + +/** Remove all padding from a given Opus packet and rewrite the TOC sequence to + * minimize space usage. + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to strip. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @returns The new size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BAD_ARG \a len was less than 1. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len); + +/** Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence). + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to pad. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @param new_len opus_int32: The desired size of the packet after padding. + * This must be at least 1. + * @param nb_streams opus_int32: The number of streams (not channels) in the packet. + * This must be at least as large as len. + * @returns an error code + * @retval #OPUS_OK \a on success. + * @retval #OPUS_BAD_ARG \a len was less than 1. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams); + +/** Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to + * minimize space usage. + * @param[in,out] data const unsigned char*: The buffer containing the + * packet to strip. + * @param len opus_int32: The size of the packet. + * This must be at least 1. + * @param nb_streams opus_int32: The number of streams (not channels) in the packet. + * This must be at least 1. + * @returns The new size of the output packet on success, or an error code + * on failure. + * @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. + * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_H */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_custom.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_custom.h new file mode 100644 index 00000000..2f22d4b3 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_custom.h @@ -0,0 +1,343 @@ +/* Copyright (c) 2007-2008 CSIRO + Copyright (c) 2007-2009 Xiph.Org Foundation + Copyright (c) 2008-2012 Gregory Maxwell + Written by Jean-Marc Valin and Gregory Maxwell */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + @file opus_custom.h + @brief Opus-Custom reference implementation API + */ + +#ifndef OPUS_CUSTOM_H +#define OPUS_CUSTOM_H + +#include "opus_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef CUSTOM_MODES +# define OPUS_CUSTOM_EXPORT OPUS_EXPORT +# define OPUS_CUSTOM_EXPORT_STATIC OPUS_EXPORT +#else +# define OPUS_CUSTOM_EXPORT +# ifdef OPUS_BUILD +# define OPUS_CUSTOM_EXPORT_STATIC static OPUS_INLINE +# else +# define OPUS_CUSTOM_EXPORT_STATIC +# endif +#endif + +/** @defgroup opus_custom Opus Custom + * @{ + * Opus Custom is an optional part of the Opus specification and + * reference implementation which uses a distinct API from the regular + * API and supports frame sizes that are not normally supported.\ Use + * of Opus Custom is discouraged for all but very special applications + * for which a frame size different from 2.5, 5, 10, or 20 ms is needed + * (for either complexity or latency reasons) and where interoperability + * is less important. + * + * In addition to the interoperability limitations the use of Opus custom + * disables a substantial chunk of the codec and generally lowers the + * quality available at a given bitrate. Normally when an application needs + * a different frame size from the codec it should buffer to match the + * sizes but this adds a small amount of delay which may be important + * in some very low latency applications. Some transports (especially + * constant rate RF transports) may also work best with frames of + * particular durations. + * + * Libopus only supports custom modes if they are enabled at compile time. + * + * The Opus Custom API is similar to the regular API but the + * @ref opus_encoder_create and @ref opus_decoder_create calls take + * an additional mode parameter which is a structure produced by + * a call to @ref opus_custom_mode_create. Both the encoder and decoder + * must create a mode using the same sample rate (fs) and frame size + * (frame size) so these parameters must either be signaled out of band + * or fixed in a particular implementation. + * + * Similar to regular Opus the custom modes support on the fly frame size + * switching, but the sizes available depend on the particular frame size in + * use. For some initial frame sizes on a single on the fly size is available. + */ + +/** Contains the state of an encoder. One encoder state is needed + for each stream. It is initialized once at the beginning of the + stream. Do *not* re-initialize the state for every frame. + @brief Encoder state + */ +typedef struct OpusCustomEncoder OpusCustomEncoder; + +/** State of the decoder. One decoder state is needed for each stream. + It is initialized once at the beginning of the stream. Do *not* + re-initialize the state for every frame. + @brief Decoder state + */ +typedef struct OpusCustomDecoder OpusCustomDecoder; + +/** The mode contains all the information necessary to create an + encoder. Both the encoder and decoder need to be initialized + with exactly the same mode, otherwise the output will be + corrupted. The mode MUST NOT BE DESTROYED until the encoders and + decoders that use it are destroyed as well. + @brief Mode configuration + */ +typedef struct OpusCustomMode OpusCustomMode; + +/** Creates a new mode struct. This will be passed to an encoder or + * decoder. The mode MUST NOT BE DESTROYED until the encoders and + * decoders that use it are destroyed as well. + * @param [in] Fs int: Sampling rate (8000 to 96000 Hz) + * @param [in] frame_size int: Number of samples (per channel) to encode in each + * packet (64 - 1024, prime factorization must contain zero or more 2s, 3s, or 5s and no other primes) + * @param [out] error int*: Returned error code (if NULL, no error will be returned) + * @return A newly created mode + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error); + +/** Destroys a mode struct. Only call this after all encoders and + * decoders using this mode are destroyed as well. + * @param [in] mode OpusCustomMode*: Mode to be freed. + */ +OPUS_CUSTOM_EXPORT void opus_custom_mode_destroy(OpusCustomMode *mode); + + +#if !defined(OPUS_BUILD) || defined(CELT_ENCODER_C) + +/* Encoder */ +/** Gets the size of an OpusCustomEncoder structure. + * @param [in] mode OpusCustomMode *: Mode configuration + * @param [in] channels int: Number of channels + * @returns size + */ +OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_encoder_get_size( + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1); + +# ifdef CUSTOM_MODES +/** Initializes a previously allocated encoder state + * The memory pointed to by st must be the size returned by opus_custom_encoder_get_size. + * This is intended for applications which use their own allocator instead of malloc. + * @see opus_custom_encoder_create(),opus_custom_encoder_get_size() + * To reset a previously initialized state use the OPUS_RESET_STATE CTL. + * @param [in] st OpusCustomEncoder*: Encoder state + * @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of + * the stream (must be the same characteristics as used for the + * decoder) + * @param [in] channels int: Number of channels + * @return OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT int opus_custom_encoder_init( + OpusCustomEncoder *st, + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); +# endif +#endif + + +/** Creates a new encoder state. Each stream needs its own encoder + * state (can't be shared across simultaneous streams). + * @param [in] mode OpusCustomMode*: Contains all the information about the characteristics of + * the stream (must be the same characteristics as used for the + * decoder) + * @param [in] channels int: Number of channels + * @param [out] error int*: Returns an error code + * @return Newly created encoder state. +*/ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomEncoder *opus_custom_encoder_create( + const OpusCustomMode *mode, + int channels, + int *error +) OPUS_ARG_NONNULL(1); + + +/** Destroys an encoder state. + * @param[in] st OpusCustomEncoder*: State to be freed. + */ +OPUS_CUSTOM_EXPORT void opus_custom_encoder_destroy(OpusCustomEncoder *st); + +/** Encodes a frame of audio. + * @param [in] st OpusCustomEncoder*: Encoder state + * @param [in] pcm float*: PCM audio in float format, with a normal range of +/-1.0. + * Samples with a range beyond +/-1.0 are supported but will + * be clipped by decoders using the integer API and should + * only be used if it is known that the far end supports + * extended dynamic range. There must be exactly + * frame_size samples per channel. + * @param [in] frame_size int: Number of samples per frame of input signal + * @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. + * @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame + * (can change from one frame to another) + * @return Number of bytes written to "compressed". + * If negative, an error has occurred (see error codes). It is IMPORTANT that + * the length returned be somehow transmitted to the decoder. Otherwise, no + * decoding is possible. + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode_float( + OpusCustomEncoder *st, + const float *pcm, + int frame_size, + unsigned char *compressed, + int maxCompressedBytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Encodes a frame of audio. + * @param [in] st OpusCustomEncoder*: Encoder state + * @param [in] pcm opus_int16*: PCM audio in signed 16-bit format (native endian). + * There must be exactly frame_size samples per channel. + * @param [in] frame_size int: Number of samples per frame of input signal + * @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. + * @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame + * (can change from one frame to another) + * @return Number of bytes written to "compressed". + * If negative, an error has occurred (see error codes). It is IMPORTANT that + * the length returned be somehow transmitted to the decoder. Otherwise, no + * decoding is possible. + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode( + OpusCustomEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *compressed, + int maxCompressedBytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on an Opus custom encoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @see opus_encoderctls + */ +OPUS_CUSTOM_EXPORT int opus_custom_encoder_ctl(OpusCustomEncoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); + + +#if !defined(OPUS_BUILD) || defined(CELT_DECODER_C) +/* Decoder */ + +/** Gets the size of an OpusCustomDecoder structure. + * @param [in] mode OpusCustomMode *: Mode configuration + * @param [in] channels int: Number of channels + * @returns size + */ +OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_decoder_get_size( + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1); + +/** Initializes a previously allocated decoder state + * The memory pointed to by st must be the size returned by opus_custom_decoder_get_size. + * This is intended for applications which use their own allocator instead of malloc. + * @see opus_custom_decoder_create(),opus_custom_decoder_get_size() + * To reset a previously initialized state use the OPUS_RESET_STATE CTL. + * @param [in] st OpusCustomDecoder*: Decoder state + * @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of + * the stream (must be the same characteristics as used for the + * encoder) + * @param [in] channels int: Number of channels + * @return OPUS_OK Success or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT_STATIC int opus_custom_decoder_init( + OpusCustomDecoder *st, + const OpusCustomMode *mode, + int channels +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); + +#endif + + +/** Creates a new decoder state. Each stream needs its own decoder state (can't + * be shared across simultaneous streams). + * @param [in] mode OpusCustomMode: Contains all the information about the characteristics of the + * stream (must be the same characteristics as used for the encoder) + * @param [in] channels int: Number of channels + * @param [out] error int*: Returns an error code + * @return Newly created decoder state. + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomDecoder *opus_custom_decoder_create( + const OpusCustomMode *mode, + int channels, + int *error +) OPUS_ARG_NONNULL(1); + +/** Destroys a decoder state. + * @param[in] st OpusCustomDecoder*: State to be freed. + */ +OPUS_CUSTOM_EXPORT void opus_custom_decoder_destroy(OpusCustomDecoder *st); + +/** Decode an opus custom frame with floating point output + * @param [in] st OpusCustomDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len int: Number of bytes in payload + * @param [out] pcm float*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(float) + * @param [in] frame_size Number of samples per channel of available space in *pcm. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode_float( + OpusCustomDecoder *st, + const unsigned char *data, + int len, + float *pcm, + int frame_size +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Decode an opus custom frame + * @param [in] st OpusCustomDecoder*: Decoder state + * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss + * @param [in] len int: Number of bytes in payload + * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length + * is frame_size*channels*sizeof(opus_int16) + * @param [in] frame_size Number of samples per channel of available space in *pcm. + * @returns Number of decoded samples or @ref opus_errorcodes + */ +OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode( + OpusCustomDecoder *st, + const unsigned char *data, + int len, + opus_int16 *pcm, + int frame_size +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on an Opus custom decoder. + * + * Generally the request and subsequent arguments are generated + * by a convenience macro. + * @see opus_genericctls + */ +OPUS_CUSTOM_EXPORT int opus_custom_decoder_ctl(OpusCustomDecoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_CUSTOM_H */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_defines.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_defines.h new file mode 100644 index 00000000..94b9e0d9 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_defines.h @@ -0,0 +1,801 @@ +/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited + Written by Jean-Marc Valin and Koen Vos */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus_defines.h + * @brief Opus reference implementation constants + */ + +#ifndef OPUS_DEFINES_H +#define OPUS_DEFINES_H + +#include "opus_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @defgroup opus_errorcodes Error codes + * @{ + */ +/** No error @hideinitializer*/ +#define OPUS_OK 0 +/** One or more invalid/out of range arguments @hideinitializer*/ +#define OPUS_BAD_ARG -1 +/** Not enough bytes allocated in the buffer @hideinitializer*/ +#define OPUS_BUFFER_TOO_SMALL -2 +/** An internal error was detected @hideinitializer*/ +#define OPUS_INTERNAL_ERROR -3 +/** The compressed data passed is corrupted @hideinitializer*/ +#define OPUS_INVALID_PACKET -4 +/** Invalid/unsupported request number @hideinitializer*/ +#define OPUS_UNIMPLEMENTED -5 +/** An encoder or decoder structure is invalid or already freed @hideinitializer*/ +#define OPUS_INVALID_STATE -6 +/** Memory allocation has failed @hideinitializer*/ +#define OPUS_ALLOC_FAIL -7 +/**@}*/ + +/** @cond OPUS_INTERNAL_DOC */ +/**Export control for opus functions */ + +#ifndef OPUS_EXPORT +# if defined(_WIN32) +# if defined(OPUS_BUILD) && defined(DLL_EXPORT) +# define OPUS_EXPORT __declspec(dllexport) +# else +# define OPUS_EXPORT +# endif +# elif defined(__GNUC__) && defined(OPUS_BUILD) +# define OPUS_EXPORT __attribute__ ((visibility ("default"))) +# else +# define OPUS_EXPORT +# endif +#endif + +# if !defined(OPUS_GNUC_PREREQ) +# if defined(__GNUC__)&&defined(__GNUC_MINOR__) +# define OPUS_GNUC_PREREQ(_maj,_min) \ + ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) +# else +# define OPUS_GNUC_PREREQ(_maj,_min) 0 +# endif +# endif + +#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) +# if OPUS_GNUC_PREREQ(3,0) +# define OPUS_RESTRICT __restrict__ +# elif (defined(_MSC_VER) && _MSC_VER >= 1400) +# define OPUS_RESTRICT __restrict +# else +# define OPUS_RESTRICT +# endif +#else +# define OPUS_RESTRICT restrict +#endif + +#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) +# if OPUS_GNUC_PREREQ(2,7) +# define OPUS_INLINE __inline__ +# elif (defined(_MSC_VER)) +# define OPUS_INLINE __inline +# else +# define OPUS_INLINE +# endif +#else +# define OPUS_INLINE inline +#endif + +/**Warning attributes for opus functions + * NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out + * some paranoid null checks. */ +#if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) +# define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) +#else +# define OPUS_WARN_UNUSED_RESULT +#endif +#if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) +# define OPUS_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x))) +#else +# define OPUS_ARG_NONNULL(_x) +#endif + +/** These are the actual Encoder CTL ID numbers. + * They should not be used directly by applications. + * In general, SETs should be even and GETs should be odd.*/ +#define OPUS_SET_APPLICATION_REQUEST 4000 +#define OPUS_GET_APPLICATION_REQUEST 4001 +#define OPUS_SET_BITRATE_REQUEST 4002 +#define OPUS_GET_BITRATE_REQUEST 4003 +#define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004 +#define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005 +#define OPUS_SET_VBR_REQUEST 4006 +#define OPUS_GET_VBR_REQUEST 4007 +#define OPUS_SET_BANDWIDTH_REQUEST 4008 +#define OPUS_GET_BANDWIDTH_REQUEST 4009 +#define OPUS_SET_COMPLEXITY_REQUEST 4010 +#define OPUS_GET_COMPLEXITY_REQUEST 4011 +#define OPUS_SET_INBAND_FEC_REQUEST 4012 +#define OPUS_GET_INBAND_FEC_REQUEST 4013 +#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014 +#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015 +#define OPUS_SET_DTX_REQUEST 4016 +#define OPUS_GET_DTX_REQUEST 4017 +#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020 +#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021 +#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022 +#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023 +#define OPUS_SET_SIGNAL_REQUEST 4024 +#define OPUS_GET_SIGNAL_REQUEST 4025 +#define OPUS_GET_LOOKAHEAD_REQUEST 4027 +/* #define OPUS_RESET_STATE 4028 */ +#define OPUS_GET_SAMPLE_RATE_REQUEST 4029 +#define OPUS_GET_FINAL_RANGE_REQUEST 4031 +#define OPUS_GET_PITCH_REQUEST 4033 +#define OPUS_SET_GAIN_REQUEST 4034 +#define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */ +#define OPUS_SET_LSB_DEPTH_REQUEST 4036 +#define OPUS_GET_LSB_DEPTH_REQUEST 4037 +#define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039 +#define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040 +#define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041 +#define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042 +#define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043 +/* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */ +#define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046 +#define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047 +#define OPUS_GET_IN_DTX_REQUEST 4049 + +/** Defines for the presence of extended APIs. */ +#define OPUS_HAVE_OPUS_PROJECTION_H + +/* Macros to trigger compilation errors when the wrong types are provided to a CTL */ +#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x)) +#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr))) +#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr))) +#define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr))) +/** @endcond */ + +/** @defgroup opus_ctlvalues Pre-defined values for CTL interface + * @see opus_genericctls, opus_encoderctls + * @{ + */ +/* Values for the various encoder CTLs */ +#define OPUS_AUTO -1000 /**opus_int32: Allowed values: 0-10, inclusive. + * + * @hideinitializer */ +#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x) +/** Gets the encoder's complexity configuration. + * @see OPUS_SET_COMPLEXITY + * @param[out] x opus_int32 *: Returns a value in the range 0-10, + * inclusive. + * @hideinitializer */ +#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x) + +/** Configures the bitrate in the encoder. + * Rates from 500 to 512000 bits per second are meaningful, as well as the + * special values #OPUS_AUTO and #OPUS_BITRATE_MAX. + * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much + * rate as it can, which is useful for controlling the rate by adjusting the + * output buffer size. + * @see OPUS_GET_BITRATE + * @param[in] x opus_int32: Bitrate in bits per second. The default + * is determined based on the number of + * channels and the input sampling rate. + * @hideinitializer */ +#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x) +/** Gets the encoder's bitrate configuration. + * @see OPUS_SET_BITRATE + * @param[out] x opus_int32 *: Returns the bitrate in bits per second. + * The default is determined based on the + * number of channels and the input + * sampling rate. + * @hideinitializer */ +#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x) + +/** Enables or disables variable bitrate (VBR) in the encoder. + * The configured bitrate may not be met exactly because frames must + * be an integer number of bytes in length. + * @see OPUS_GET_VBR + * @see OPUS_SET_VBR_CONSTRAINT + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Hard CBR. For LPC/hybrid modes at very low bit-rate, this can + * cause noticeable quality degradation.
+ *
1
VBR (default). The exact type of VBR is controlled by + * #OPUS_SET_VBR_CONSTRAINT.
+ *
+ * @hideinitializer */ +#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x) +/** Determine if variable bitrate (VBR) is enabled in the encoder. + * @see OPUS_SET_VBR + * @see OPUS_GET_VBR_CONSTRAINT + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Hard CBR.
+ *
1
VBR (default). The exact type of VBR may be retrieved via + * #OPUS_GET_VBR_CONSTRAINT.
+ *
+ * @hideinitializer */ +#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x) + +/** Enables or disables constrained VBR in the encoder. + * This setting is ignored when the encoder is in CBR mode. + * @warning Only the MDCT mode of Opus currently heeds the constraint. + * Speech mode ignores it completely, hybrid mode may fail to obey it + * if the LPC layer uses more bitrate than the constraint would have + * permitted. + * @see OPUS_GET_VBR_CONSTRAINT + * @see OPUS_SET_VBR + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Unconstrained VBR.
+ *
1
Constrained VBR (default). This creates a maximum of one + * frame of buffering delay assuming a transport with a + * serialization speed of the nominal bitrate.
+ *
+ * @hideinitializer */ +#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x) +/** Determine if constrained VBR is enabled in the encoder. + * @see OPUS_SET_VBR_CONSTRAINT + * @see OPUS_GET_VBR + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Unconstrained VBR.
+ *
1
Constrained VBR (default).
+ *
+ * @hideinitializer */ +#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x) + +/** Configures mono/stereo forcing in the encoder. + * This can force the encoder to produce packets encoded as either mono or + * stereo, regardless of the format of the input audio. This is useful when + * the caller knows that the input signal is currently a mono source embedded + * in a stereo stream. + * @see OPUS_GET_FORCE_CHANNELS + * @param[in] x opus_int32: Allowed values: + *
+ *
#OPUS_AUTO
Not forced (default)
+ *
1
Forced mono
+ *
2
Forced stereo
+ *
+ * @hideinitializer */ +#define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x) +/** Gets the encoder's forced channel configuration. + * @see OPUS_SET_FORCE_CHANNELS + * @param[out] x opus_int32 *: + *
+ *
#OPUS_AUTO
Not forced (default)
+ *
1
Forced mono
+ *
2
Forced stereo
+ *
+ * @hideinitializer */ +#define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x) + +/** Configures the maximum bandpass that the encoder will select automatically. + * Applications should normally use this instead of #OPUS_SET_BANDWIDTH + * (leaving that set to the default, #OPUS_AUTO). This allows the + * application to set an upper bound based on the type of input it is + * providing, but still gives the encoder the freedom to reduce the bandpass + * when the bitrate becomes too low, for better overall quality. + * @see OPUS_GET_MAX_BANDWIDTH + * @param[in] x opus_int32: Allowed values: + *
+ *
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
+ *
+ * @hideinitializer */ +#define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x) + +/** Gets the encoder's configured maximum allowed bandpass. + * @see OPUS_SET_MAX_BANDWIDTH + * @param[out] x opus_int32 *: Allowed values: + *
+ *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
+ *
+ * @hideinitializer */ +#define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) + +/** Sets the encoder's bandpass to a specific value. + * This prevents the encoder from automatically selecting the bandpass based + * on the available bitrate. If an application knows the bandpass of the input + * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH + * instead, which still gives the encoder the freedom to reduce the bandpass + * when the bitrate becomes too low, for better overall quality. + * @see OPUS_GET_BANDWIDTH + * @param[in] x opus_int32: Allowed values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
+ *
+ * @hideinitializer */ +#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x) + +/** Configures the type of signal being encoded. + * This is a hint which helps the encoder's mode selection. + * @see OPUS_GET_SIGNAL + * @param[in] x opus_int32: Allowed values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
+ *
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
+ *
+ * @hideinitializer */ +#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured signal type. + * @see OPUS_SET_SIGNAL + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
+ *
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
+ *
+ * @hideinitializer */ +#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x) + + +/** Configures the encoder's intended application. + * The initial value is a mandatory argument to the encoder_create function. + * @see OPUS_GET_APPLICATION + * @param[in] x opus_int32: Returns one of the following values: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @hideinitializer */ +#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured application. + * @see OPUS_SET_APPLICATION + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @hideinitializer */ +#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x) + +/** Gets the total samples of delay added by the entire codec. + * This can be queried by the encoder and then the provided number of samples can be + * skipped on from the start of the decoder's output to provide time aligned input + * and output. From the perspective of a decoding application the real data begins this many + * samples late. + * + * The decoder contribution to this delay is identical for all decoders, but the + * encoder portion of the delay may vary from implementation to implementation, + * version to version, or even depend on the encoder's initial configuration. + * Applications needing delay compensation should call this CTL rather than + * hard-coding a value. + * @param[out] x opus_int32 *: Number of lookahead samples + * @hideinitializer */ +#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's use of inband forward error correction (FEC). + * @note This is only applicable to the LPC layer + * @see OPUS_GET_INBAND_FEC + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Disable inband FEC (default).
+ *
1
Inband FEC enabled. If the packet loss rate is sufficiently high, Opus will automatically switch to SILK even at high rates to enable use of that FEC.
+ *
2
Inband FEC enabled, but does not necessarily switch to SILK if we have music.
+ *
+ * @hideinitializer */ +#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x) +/** Gets encoder's configured use of inband forward error correction. + * @see OPUS_SET_INBAND_FEC + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Inband FEC disabled (default).
+ *
1
Inband FEC enabled. If the packet loss rate is sufficiently high, Opus will automatically switch to SILK even at high rates to enable use of that FEC.
+ *
2
Inband FEC enabled, but does not necessarily switch to SILK if we have music.
+ *
+ * @hideinitializer */ +#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's expected packet loss percentage. + * Higher values trigger progressively more loss resistant behavior in the encoder + * at the expense of quality at a given bitrate in the absence of packet loss, but + * greater quality under loss. + * @see OPUS_GET_PACKET_LOSS_PERC + * @param[in] x opus_int32: Loss percentage in the range 0-100, inclusive (default: 0). + * @hideinitializer */ +#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured packet loss percentage. + * @see OPUS_SET_PACKET_LOSS_PERC + * @param[out] x opus_int32 *: Returns the configured loss percentage + * in the range 0-100, inclusive (default: 0). + * @hideinitializer */ +#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's use of discontinuous transmission (DTX). + * @note This is only applicable to the LPC layer + * @see OPUS_GET_DTX + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Disable DTX (default).
+ *
1
Enabled DTX.
+ *
+ * @hideinitializer */ +#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x) +/** Gets encoder's configured use of discontinuous transmission. + * @see OPUS_SET_DTX + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
DTX disabled (default).
+ *
1
DTX enabled.
+ *
+ * @hideinitializer */ +#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x) +/** Configures the depth of signal being encoded. + * + * This is a hint which helps the encoder identify silence and near-silence. + * It represents the number of significant bits of linear intensity below + * which the signal contains ignorable quantization or other noise. + * + * For example, OPUS_SET_LSB_DEPTH(14) would be an appropriate setting + * for G.711 u-law input. OPUS_SET_LSB_DEPTH(16) would be appropriate + * for 16-bit linear pcm input with opus_encode_float(). + * + * When using opus_encode() instead of opus_encode_float(), or when libopus + * is compiled for fixed-point, the encoder uses the minimum of the value + * set here and the value 16. + * + * @see OPUS_GET_LSB_DEPTH + * @param[in] x opus_int32: Input precision in bits, between 8 and 24 + * (default: 24). + * @hideinitializer */ +#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured signal depth. + * @see OPUS_SET_LSB_DEPTH + * @param[out] x opus_int32 *: Input precision in bits, between 8 and + * 24 (default: 24). + * @hideinitializer */ +#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x) + +/** Configures the encoder's use of variable duration frames. + * When variable duration is enabled, the encoder is free to use a shorter frame + * size than the one requested in the opus_encode*() call. + * It is then the user's responsibility + * to verify how much audio was encoded by checking the ToC byte of the encoded + * packet. The part of the audio that was not encoded needs to be resent to the + * encoder for the next call. Do not use this option unless you really + * know what you are doing. + * @see OPUS_GET_EXPERT_FRAME_DURATION + * @param[in] x opus_int32: Allowed values: + *
+ *
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
+ *
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
+ *
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
+ *
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
+ *
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
+ *
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
+ *
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
+ *
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
+ *
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
+ *
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
+ *
+ * @hideinitializer */ +#define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured use of variable duration frames. + * @see OPUS_SET_EXPERT_FRAME_DURATION + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
+ *
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
+ *
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
+ *
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
+ *
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
+ *
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
+ *
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
+ *
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
+ *
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
+ *
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
+ *
+ * @hideinitializer */ +#define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x) + +/** If set to 1, disables almost all use of prediction, making frames almost + * completely independent. This reduces quality. + * @see OPUS_GET_PREDICTION_DISABLED + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Enable prediction (default).
+ *
1
Disable prediction.
+ *
+ * @hideinitializer */ +#define OPUS_SET_PREDICTION_DISABLED(x) OPUS_SET_PREDICTION_DISABLED_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured prediction status. + * @see OPUS_SET_PREDICTION_DISABLED + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Prediction enabled (default).
+ *
1
Prediction disabled.
+ *
+ * @hideinitializer */ +#define OPUS_GET_PREDICTION_DISABLED(x) OPUS_GET_PREDICTION_DISABLED_REQUEST, __opus_check_int_ptr(x) + +/**@}*/ + +/** @defgroup opus_genericctls Generic CTLs + * + * These macros are used with the \c opus_decoder_ctl and + * \c opus_encoder_ctl calls to generate a particular + * request. + * + * When called on an \c OpusDecoder they apply to that + * particular decoder instance. When called on an + * \c OpusEncoder they apply to the corresponding setting + * on that encoder instance, if present. + * + * Some usage examples: + * + * @code + * int ret; + * opus_int32 pitch; + * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch)); + * if (ret == OPUS_OK) return ret; + * + * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); + * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE); + * + * opus_int32 enc_bw, dec_bw; + * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw)); + * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw)); + * if (enc_bw != dec_bw) { + * printf("packet bandwidth mismatch!\n"); + * } + * @endcode + * + * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls + * @{ + */ + +/** Resets the codec state to be equivalent to a freshly initialized state. + * This should be called when switching streams in order to prevent + * the back to back decoding from giving different results from + * one at a time decoding. + * @hideinitializer */ +#define OPUS_RESET_STATE 4028 + +/** Gets the final state of the codec's entropy coder. + * This is used for testing purposes, + * The encoder and decoder state should be identical after coding a payload + * (assuming no data corruption or software bugs) + * + * @param[out] x opus_uint32 *: Entropy coder state + * + * @hideinitializer */ +#define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x) + +/** Gets the encoder's configured bandpass or the decoder's last bandpass. + * @see OPUS_SET_BANDWIDTH + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
#OPUS_AUTO
(default)
+ *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
+ *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
+ *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
+ *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
+ *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
+ *
+ * @hideinitializer */ +#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) + +/** Gets the sampling rate the encoder or decoder was initialized with. + * This simply returns the Fs value passed to opus_encoder_init() + * or opus_decoder_init(). + * @param[out] x opus_int32 *: Sampling rate of encoder or decoder. + * @hideinitializer + */ +#define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x) + +/** If set to 1, disables the use of phase inversion for intensity stereo, + * improving the quality of mono downmixes, but slightly reducing normal + * stereo quality. Disabling phase inversion in the decoder does not comply + * with RFC 6716, although it does not cause any interoperability issue and + * is expected to become part of the Opus standard once RFC 6716 is updated + * by draft-ietf-codec-opus-update. + * @see OPUS_GET_PHASE_INVERSION_DISABLED + * @param[in] x opus_int32: Allowed values: + *
+ *
0
Enable phase inversion (default).
+ *
1
Disable phase inversion.
+ *
+ * @hideinitializer */ +#define OPUS_SET_PHASE_INVERSION_DISABLED(x) OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int(x) +/** Gets the encoder's configured phase inversion status. + * @see OPUS_SET_PHASE_INVERSION_DISABLED + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
Stereo phase inversion enabled (default).
+ *
1
Stereo phase inversion disabled.
+ *
+ * @hideinitializer */ +#define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x) +/** Gets the DTX state of the encoder. + * Returns whether the last encoded frame was either a comfort noise update + * during DTX or not encoded because of DTX. + * @param[out] x opus_int32 *: Returns one of the following values: + *
+ *
0
The encoder is not in DTX.
+ *
1
The encoder is in DTX.
+ *
+ * @hideinitializer */ +#define OPUS_GET_IN_DTX(x) OPUS_GET_IN_DTX_REQUEST, __opus_check_int_ptr(x) + +/**@}*/ + +/** @defgroup opus_decoderctls Decoder related CTLs + * @see opus_genericctls, opus_encoderctls, opus_decoder + * @{ + */ + +/** Configures decoder gain adjustment. + * Scales the decoded output by a factor specified in Q8 dB units. + * This has a maximum range of -32768 to 32767 inclusive, and returns + * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment. + * This setting survives decoder reset. + * + * gain = pow(10, x/(20.0*256)) + * + * @param[in] x opus_int32: Amount to scale PCM signal by in Q8 dB units. + * @hideinitializer */ +#define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x) +/** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN + * + * @param[out] x opus_int32 *: Amount to scale PCM signal by in Q8 dB units. + * @hideinitializer */ +#define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x) + +/** Gets the duration (in samples) of the last packet successfully decoded or concealed. + * @param[out] x opus_int32 *: Number of samples (at current sampling rate). + * @hideinitializer */ +#define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x) + +/** Gets the pitch of the last decoded frame, if available. + * This can be used for any post-processing algorithm requiring the use of pitch, + * e.g. time stretching/shortening. If the last frame was not voiced, or if the + * pitch was not coded in the frame, then zero is returned. + * + * This CTL is only implemented for decoder instances. + * + * @param[out] x opus_int32 *: pitch period at 48 kHz (or 0 if not available) + * + * @hideinitializer */ +#define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x) + +/**@}*/ + +/** @defgroup opus_libinfo Opus library information functions + * @{ + */ + +/** Converts an opus error code into a human readable string. + * + * @param[in] error int: Error number + * @returns Error string + */ +OPUS_EXPORT const char *opus_strerror(int error); + +/** Gets the libopus version string. + * + * Applications may look for the substring "-fixed" in the version string to + * determine whether they have a fixed-point or floating-point build at + * runtime. + * + * @returns Version string + */ +OPUS_EXPORT const char *opus_get_version_string(void); +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_DEFINES_H */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_multistream.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_multistream.h new file mode 100644 index 00000000..babcee69 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_multistream.h @@ -0,0 +1,660 @@ +/* Copyright (c) 2011 Xiph.Org Foundation + Written by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus_multistream.h + * @brief Opus reference implementation multistream API + */ + +#ifndef OPUS_MULTISTREAM_H +#define OPUS_MULTISTREAM_H + +#include "opus.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @cond OPUS_INTERNAL_DOC */ + +/** Macros to trigger compilation errors when the wrong types are provided to a + * CTL. */ +/**@{*/ +#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) +#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) +/**@}*/ + +/** These are the actual encoder and decoder CTL ID numbers. + * They should not be used directly by applications. + * In general, SETs should be even and GETs should be odd.*/ +/**@{*/ +#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 +#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 +/**@}*/ + +/** @endcond */ + +/** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs + * + * These are convenience macros that are specific to the + * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl() + * interface. + * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and + * @ref opus_decoderctls may be applied to a multistream encoder or decoder as + * well. + * In addition, you may retrieve the encoder or decoder state for an specific + * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or + * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually. + */ +/**@{*/ + +/** Gets the encoder state for an individual stream of a multistream encoder. + * @param[in] x opus_int32: The index of the stream whose encoder you + * wish to retrieve. + * This must be non-negative and less than + * the streams parameter used + * to initialize the encoder. + * @param[out] y OpusEncoder**: Returns a pointer to the given + * encoder state. + * @retval OPUS_BAD_ARG The index of the requested stream was out of range. + * @hideinitializer + */ +#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) + +/** Gets the decoder state for an individual stream of a multistream decoder. + * @param[in] x opus_int32: The index of the stream whose decoder you + * wish to retrieve. + * This must be non-negative and less than + * the streams parameter used + * to initialize the decoder. + * @param[out] y OpusDecoder**: Returns a pointer to the given + * decoder state. + * @retval OPUS_BAD_ARG The index of the requested stream was out of range. + * @hideinitializer + */ +#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) + +/**@}*/ + +/** @defgroup opus_multistream Opus Multistream API + * @{ + * + * The multistream API allows individual Opus streams to be combined into a + * single packet, enabling support for up to 255 channels. Unlike an + * elementary Opus stream, the encoder and decoder must negotiate the channel + * configuration before the decoder can successfully interpret the data in the + * packets produced by the encoder. Some basic information, such as packet + * duration, can be computed without any special negotiation. + * + * The format for multistream Opus packets is defined in + * RFC 7845 + * and is based on the self-delimited Opus framing described in Appendix B of + * RFC 6716. + * Normal Opus packets are just a degenerate case of multistream Opus packets, + * and can be encoded or decoded with the multistream API by setting + * streams to 1 when initializing the encoder or + * decoder. + * + * Multistream Opus streams can contain up to 255 elementary Opus streams. + * These may be either "uncoupled" or "coupled", indicating that the decoder + * is configured to decode them to either 1 or 2 channels, respectively. + * The streams are ordered so that all coupled streams appear at the + * beginning. + * + * A mapping table defines which decoded channel i + * should be used for each input/output (I/O) channel j. This table is + * typically provided as an unsigned char array. + * Let i = mapping[j] be the index for I/O channel j. + * If i < 2*coupled_streams, then I/O channel j is + * encoded as the left channel of stream (i/2) if i + * is even, or as the right channel of stream (i/2) if + * i is odd. Otherwise, I/O channel j is encoded as + * mono in stream (i - coupled_streams), unless it has the special + * value 255, in which case it is omitted from the encoding entirely (the + * decoder will reproduce it as silence). Each value i must either + * be the special value 255 or be less than streams + coupled_streams. + * + * The output channels specified by the encoder + * should use the + * Vorbis + * channel ordering. A decoder may wish to apply an additional permutation + * to the mapping the encoder used to achieve a different output channel + * order (e.g. for outputing in WAV order). + * + * Each multistream packet contains an Opus packet for each stream, and all of + * the Opus packets in a single multistream packet must have the same + * duration. Therefore the duration of a multistream packet can be extracted + * from the TOC sequence of the first stream, which is located at the + * beginning of the packet, just like an elementary Opus stream: + * + * @code + * int nb_samples; + * int nb_frames; + * nb_frames = opus_packet_get_nb_frames(data, len); + * if (nb_frames < 1) + * return nb_frames; + * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames; + * @endcode + * + * The general encoding and decoding process proceeds exactly the same as in + * the normal @ref opus_encoder and @ref opus_decoder APIs. + * See their documentation for an overview of how to use the corresponding + * multistream functions. + */ + +/** Opus multistream encoder state. + * This contains the complete state of a multistream Opus encoder. + * It is position independent and can be freely copied. + * @see opus_multistream_encoder_create + * @see opus_multistream_encoder_init + */ +typedef struct OpusMSEncoder OpusMSEncoder; + +/** Opus multistream decoder state. + * This contains the complete state of a multistream Opus decoder. + * It is position independent and can be freely copied. + * @see opus_multistream_decoder_create + * @see opus_multistream_decoder_init + */ +typedef struct OpusMSDecoder OpusMSDecoder; + +/**\name Multistream encoder functions */ +/**@{*/ + +/** Gets the size of an OpusMSEncoder structure. + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than 255. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size( + int streams, + int coupled_streams +); + +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size( + int channels, + int mapping_family +); + + +/** Allocates and initializes a multistream encoder state. + * Call opus_multistream_encoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than the number of channels. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than the number of input channels. + * @param[in] mapping const unsigned char[channels]: Mapping from + * encoded channels to input channels, as described in + * @ref opus_multistream. As an extra constraint, the + * multistream encoder does not allow encoding coupled + * streams for which one channel is unused since this + * is never a good idea. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create( + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping, + int application, + int *error +) OPUS_ARG_NONNULL(5); + +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_encoder_create( + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + unsigned char *mapping, + int application, + int *error +) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); + +/** Initialize a previously allocated multistream encoder state. + * The memory pointed to by \a st must be at least the size returned by + * opus_multistream_encoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_multistream_encoder_create + * @see opus_multistream_encoder_get_size + * @param st OpusMSEncoder*: Multistream encoder state to initialize. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than the number of channels. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than the number of input channels. + * @param[in] mapping const unsigned char[channels]: Mapping from + * encoded channels to input channels, as described in + * @ref opus_multistream. As an extra constraint, the + * multistream encoder does not allow encoding coupled + * streams for which one channel is unused since this + * is never a good idea. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_multistream_encoder_init( + OpusMSEncoder *st, + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping, + int application +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); + +OPUS_EXPORT int opus_multistream_surround_encoder_init( + OpusMSEncoder *st, + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + unsigned char *mapping, + int application +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7); + +/** Encodes a multistream Opus frame. + * @param st OpusMSEncoder*: Multistream encoder state. + * @param[in] pcm const opus_int16*: The input signal as interleaved + * samples. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( + OpusMSEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Encodes a multistream Opus frame from floating point input. + * @param st OpusMSEncoder*: Multistream encoder state. + * @param[in] pcm const float*: The input signal as interleaved + * samples with a normal range of + * +/-1.0. + * Samples with a range beyond +/-1.0 + * are supported but will be clipped by + * decoders using the integer API and + * should only be used if it is known + * that the far end supports extended + * dynamic range. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( + OpusMSEncoder *st, + const float *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + +/** Frees an OpusMSEncoder allocated by + * opus_multistream_encoder_create(). + * @param st OpusMSEncoder*: Multistream encoder state to be freed. + */ +OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); + +/** Perform a CTL function on a multistream Opus encoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusMSEncoder*: Multistream encoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_encoderctls, or @ref opus_multistream_ctls. + * @see opus_genericctls + * @see opus_encoderctls + * @see opus_multistream_ctls + */ +OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); + +/**@}*/ + +/**\name Multistream decoder functions */ +/**@{*/ + +/** Gets the size of an OpusMSDecoder structure. + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size( + int streams, + int coupled_streams +); + +/** Allocates and initializes a multistream decoder state. + * Call opus_multistream_decoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] mapping const unsigned char[channels]: Mapping from + * coded channels to output channels, as described in + * @ref opus_multistream. + * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create( + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping, + int *error +) OPUS_ARG_NONNULL(5); + +/** Intialize a previously allocated decoder state object. + * The memory pointed to by \a st must be at least the size returned by + * opus_multistream_encoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_multistream_decoder_create + * @see opus_multistream_deocder_get_size + * @param st OpusMSEncoder*: Multistream encoder state to initialize. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] mapping const unsigned char[channels]: Mapping from + * coded channels to output channels, as described in + * @ref opus_multistream. + * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_multistream_decoder_init( + OpusMSDecoder *st, + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + const unsigned char *mapping +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); + +/** Decode a multistream Opus packet. + * @param st OpusMSDecoder*: Multistream decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( + OpusMSDecoder *st, + const unsigned char *data, + opus_int32 len, + opus_int16 *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Decode a multistream Opus packet with floating point output. + * @param st OpusMSDecoder*: Multistream decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( + OpusMSDecoder *st, + const unsigned char *data, + opus_int32 len, + float *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + +/** Perform a CTL function on a multistream Opus decoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusMSDecoder*: Multistream decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_decoderctls, or @ref opus_multistream_ctls. + * @see opus_genericctls + * @see opus_decoderctls + * @see opus_multistream_ctls + */ +OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); + +/** Frees an OpusMSDecoder allocated by + * opus_multistream_decoder_create(). + * @param st OpusMSDecoder: Multistream decoder state to be freed. + */ +OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); + +/**@}*/ + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_MULTISTREAM_H */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_projection.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_projection.h new file mode 100644 index 00000000..9dabf4e8 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_projection.h @@ -0,0 +1,568 @@ +/* Copyright (c) 2017 Google Inc. + Written by Andrew Allen */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file opus_projection.h + * @brief Opus projection reference API + */ + +#ifndef OPUS_PROJECTION_H +#define OPUS_PROJECTION_H + +#include "opus_multistream.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @cond OPUS_INTERNAL_DOC */ + +/** These are the actual encoder and decoder CTL ID numbers. + * They should not be used directly by applications.c + * In general, SETs should be even and GETs should be odd.*/ +/**@{*/ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST 6001 +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST 6003 +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST 6005 +/**@}*/ + + +/** @endcond */ + +/** @defgroup opus_projection_ctls Projection specific encoder and decoder CTLs + * + * These are convenience macros that are specific to the + * opus_projection_encoder_ctl() and opus_projection_decoder_ctl() + * interface. + * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, + * @ref opus_decoderctls, and @ref opus_multistream_ctls may be applied to a + * projection encoder or decoder as well. + */ +/**@{*/ + +/** Gets the gain (in dB. S7.8-format) of the demixing matrix from the encoder. + * @param[out] x opus_int32 *: Returns the gain (in dB. S7.8-format) + * of the demixing matrix. + * @hideinitializer + */ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST, __opus_check_int_ptr(x) + + +/** Gets the size in bytes of the demixing matrix from the encoder. + * @param[out] x opus_int32 *: Returns the size in bytes of the + * demixing matrix. + * @hideinitializer + */ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST, __opus_check_int_ptr(x) + + +/** Copies the demixing matrix to the supplied pointer location. + * @param[out] x unsigned char *: Returns the demixing matrix to the + * supplied pointer location. + * @param y opus_int32: The size in bytes of the reserved memory at the + * pointer location. + * @hideinitializer + */ +#define OPUS_PROJECTION_GET_DEMIXING_MATRIX(x,y) OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST, x, __opus_check_int(y) + + +/**@}*/ + +/** Opus projection encoder state. + * This contains the complete state of a projection Opus encoder. + * It is position independent and can be freely copied. + * @see opus_projection_ambisonics_encoder_create + */ +typedef struct OpusProjectionEncoder OpusProjectionEncoder; + + +/** Opus projection decoder state. + * This contains the complete state of a projection Opus decoder. + * It is position independent and can be freely copied. + * @see opus_projection_decoder_create + * @see opus_projection_decoder_init + */ +typedef struct OpusProjectionDecoder OpusProjectionDecoder; + + +/**\name Projection encoder functions */ +/**@{*/ + +/** Gets the size of an OpusProjectionEncoder structure. + * @param channels int: The total number of input channels to encode. + * This must be no more than 255. + * @param mapping_family int: The mapping family to use for selecting + * the appropriate projection. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_ambisonics_encoder_get_size( + int channels, + int mapping_family +); + + +/** Allocates and initializes a projection encoder state. + * Call opus_projection_encoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param mapping_family int: The mapping family to use for selecting + * the appropriate projection. + * @param[out] streams int *: The total number of streams that will + * be encoded from the input. + * @param[out] coupled_streams int *: Number of coupled (2 channel) + * streams that will be encoded from the input. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionEncoder *opus_projection_ambisonics_encoder_create( + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + int application, + int *error +) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5); + + +/** Initialize a previously allocated projection encoder state. + * The memory pointed to by \a st must be at least the size returned by + * opus_projection_ambisonics_encoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_projection_ambisonics_encoder_create + * @see opus_projection_ambisonics_encoder_get_size + * @param st OpusProjectionEncoder*: Projection encoder state to initialize. + * @param Fs opus_int32: Sampling rate of the input signal (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels in the input signal. + * This must be at most 255. + * It may be greater than the number of + * coded channels (streams + + * coupled_streams). + * @param streams int: The total number of streams to encode from the + * input. + * This must be no more than the number of channels. + * @param coupled_streams int: Number of coupled (2 channel) streams + * to encode. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * encoded channels (streams + + * coupled_streams) must be no + * more than the number of input channels. + * @param application int: The target encoder application. + * This must be one of the following: + *
+ *
#OPUS_APPLICATION_VOIP
+ *
Process signal for improved speech intelligibility.
+ *
#OPUS_APPLICATION_AUDIO
+ *
Favor faithfulness to the original input.
+ *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
+ *
Configure the minimum possible coding delay by disabling certain modes + * of operation.
+ *
+ * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_projection_ambisonics_encoder_init( + OpusProjectionEncoder *st, + opus_int32 Fs, + int channels, + int mapping_family, + int *streams, + int *coupled_streams, + int application +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); + + +/** Encodes a projection Opus frame. + * @param st OpusProjectionEncoder*: Projection encoder state. + * @param[in] pcm const opus_int16*: The input signal as interleaved + * samples. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode( + OpusProjectionEncoder *st, + const opus_int16 *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + + +/** Encodes a projection Opus frame from floating point input. + * @param st OpusProjectionEncoder*: Projection encoder state. + * @param[in] pcm const float*: The input signal as interleaved + * samples with a normal range of + * +/-1.0. + * Samples with a range beyond +/-1.0 + * are supported but will be clipped by + * decoders using the integer API and + * should only be used if it is known + * that the far end supports extended + * dynamic range. + * This must contain + * frame_size*channels + * samples. + * @param frame_size int: Number of samples per channel in the input + * signal. + * This must be an Opus frame size for the + * encoder's sampling rate. + * For example, at 48 kHz the permitted values + * are 120, 240, 480, 960, 1920, and 2880. + * Passing in a duration of less than 10 ms + * (480 samples at 48 kHz) will prevent the + * encoder from using the LPC or hybrid modes. + * @param[out] data unsigned char*: Output payload. + * This must contain storage for at + * least \a max_data_bytes. + * @param [in] max_data_bytes opus_int32: Size of the allocated + * memory for the output + * payload. This may be + * used to impose an upper limit on + * the instant bitrate, but should + * not be used as the only bitrate + * control. Use #OPUS_SET_BITRATE to + * control the bitrate. + * @returns The length of the encoded packet (in bytes) on success or a + * negative error code (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode_float( + OpusProjectionEncoder *st, + const float *pcm, + int frame_size, + unsigned char *data, + opus_int32 max_data_bytes +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); + + +/** Frees an OpusProjectionEncoder allocated by + * opus_projection_ambisonics_encoder_create(). + * @param st OpusProjectionEncoder*: Projection encoder state to be freed. + */ +OPUS_EXPORT void opus_projection_encoder_destroy(OpusProjectionEncoder *st); + + +/** Perform a CTL function on a projection Opus encoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusProjectionEncoder*: Projection encoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_encoderctls, @ref opus_multistream_ctls, or + * @ref opus_projection_ctls + * @see opus_genericctls + * @see opus_encoderctls + * @see opus_multistream_ctls + * @see opus_projection_ctls + */ +OPUS_EXPORT int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); + + +/**@}*/ + +/**\name Projection decoder functions */ +/**@{*/ + +/** Gets the size of an OpusProjectionDecoder structure. + * @param channels int: The total number of output channels. + * This must be no more than 255. + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @returns The size in bytes on success, or a negative error code + * (see @ref opus_errorcodes) on error. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_decoder_get_size( + int channels, + int streams, + int coupled_streams +); + + +/** Allocates and initializes a projection decoder state. + * Call opus_projection_decoder_destroy() to release + * this object when finished. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix + * that mapping from coded channels to output channels, + * as described in @ref opus_projection and + * @ref opus_projection_ctls. + * @param demixing_matrix_size opus_int32: The size in bytes of the + * demixing matrix, as + * described in @ref + * opus_projection_ctls. + * @param[out] error int *: Returns #OPUS_OK on success, or an error + * code (see @ref opus_errorcodes) on + * failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionDecoder *opus_projection_decoder_create( + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + unsigned char *demixing_matrix, + opus_int32 demixing_matrix_size, + int *error +) OPUS_ARG_NONNULL(5); + + +/** Intialize a previously allocated projection decoder state object. + * The memory pointed to by \a st must be at least the size returned by + * opus_projection_decoder_get_size(). + * This is intended for applications which use their own allocator instead of + * malloc. + * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. + * @see opus_projection_decoder_create + * @see opus_projection_deocder_get_size + * @param st OpusProjectionDecoder*: Projection encoder state to initialize. + * @param Fs opus_int32: Sampling rate to decode at (in Hz). + * This must be one of 8000, 12000, 16000, + * 24000, or 48000. + * @param channels int: Number of channels to output. + * This must be at most 255. + * It may be different from the number of coded + * channels (streams + + * coupled_streams). + * @param streams int: The total number of streams coded in the + * input. + * This must be no more than 255. + * @param coupled_streams int: Number of streams to decode as coupled + * (2 channel) streams. + * This must be no larger than the total + * number of streams. + * Additionally, The total number of + * coded channels (streams + + * coupled_streams) must be no + * more than 255. + * @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix + * that mapping from coded channels to output channels, + * as described in @ref opus_projection and + * @ref opus_projection_ctls. + * @param demixing_matrix_size opus_int32: The size in bytes of the + * demixing matrix, as + * described in @ref + * opus_projection_ctls. + * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) + * on failure. + */ +OPUS_EXPORT int opus_projection_decoder_init( + OpusProjectionDecoder *st, + opus_int32 Fs, + int channels, + int streams, + int coupled_streams, + unsigned char *demixing_matrix, + opus_int32 demixing_matrix_size +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); + + +/** Decode a projection Opus packet. + * @param st OpusProjectionDecoder*: Projection decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode( + OpusProjectionDecoder *st, + const unsigned char *data, + opus_int32 len, + opus_int16 *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + + +/** Decode a projection Opus packet with floating point output. + * @param st OpusProjectionDecoder*: Projection decoder state. + * @param[in] data const unsigned char*: Input payload. + * Use a NULL + * pointer to indicate packet + * loss. + * @param len opus_int32: Number of bytes in payload. + * @param[out] pcm opus_int16*: Output signal, with interleaved + * samples. + * This must contain room for + * frame_size*channels + * samples. + * @param frame_size int: The number of samples per channel of + * available space in \a pcm. + * If this is less than the maximum packet duration + * (120 ms; 5760 for 48kHz), this function will not be capable + * of decoding some packets. In the case of PLC (data==NULL) + * or FEC (decode_fec=1), then frame_size needs to be exactly + * the duration of audio that is missing, otherwise the + * decoder will not be in the optimal state to decode the + * next incoming packet. For the PLC and FEC cases, frame_size + * must be a multiple of 2.5 ms. + * @param decode_fec int: Flag (0 or 1) to request that any in-band + * forward error correction data be decoded. + * If no such data is available, the frame is + * decoded as if it were lost. + * @returns Number of samples decoded on success or a negative error code + * (see @ref opus_errorcodes) on failure. + */ +OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode_float( + OpusProjectionDecoder *st, + const unsigned char *data, + opus_int32 len, + float *pcm, + int frame_size, + int decode_fec +) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); + + +/** Perform a CTL function on a projection Opus decoder. + * + * Generally the request and subsequent arguments are generated by a + * convenience macro. + * @param st OpusProjectionDecoder*: Projection decoder state. + * @param request This and all remaining parameters should be replaced by one + * of the convenience macros in @ref opus_genericctls, + * @ref opus_decoderctls, @ref opus_multistream_ctls, or + * @ref opus_projection_ctls. + * @see opus_genericctls + * @see opus_decoderctls + * @see opus_multistream_ctls + * @see opus_projection_ctls + */ +OPUS_EXPORT int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); + + +/** Frees an OpusProjectionDecoder allocated by + * opus_projection_decoder_create(). + * @param st OpusProjectionDecoder: Projection decoder state to be freed. + */ +OPUS_EXPORT void opus_projection_decoder_destroy(OpusProjectionDecoder *st); + + +/**@}*/ + +/**@}*/ + +#ifdef __cplusplus +} +#endif + +#endif /* OPUS_PROJECTION_H */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_types.h b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_types.h new file mode 100644 index 00000000..7cf67558 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/source/opus/opus_types.h @@ -0,0 +1,166 @@ +/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */ +/* Modified by Jean-Marc Valin */ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/* opus_types.h based on ogg_types.h from libogg */ + +/** + @file opus_types.h + @brief Opus reference implementation types +*/ +#ifndef OPUS_TYPES_H +#define OPUS_TYPES_H + +#define opus_int int /* used for counters etc; at least 16 bits */ +#define opus_int64 long long +#define opus_int8 signed char + +#define opus_uint unsigned int /* used for counters etc; at least 16 bits */ +#define opus_uint64 unsigned long long +#define opus_uint8 unsigned char + +/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */ +#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H)) +#include +# undef opus_int64 +# undef opus_int8 +# undef opus_uint64 +# undef opus_uint8 + typedef int8_t opus_int8; + typedef uint8_t opus_uint8; + typedef int16_t opus_int16; + typedef uint16_t opus_uint16; + typedef int32_t opus_int32; + typedef uint32_t opus_uint32; + typedef int64_t opus_int64; + typedef uint64_t opus_uint64; +#elif defined(_WIN32) + +# if defined(__CYGWIN__) +# include <_G_config.h> + typedef _G_int32_t opus_int32; + typedef _G_uint32_t opus_uint32; + typedef _G_int16 opus_int16; + typedef _G_uint16 opus_uint16; +# elif defined(__MINGW32__) + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; +# elif defined(__MWERKS__) + typedef int opus_int32; + typedef unsigned int opus_uint32; + typedef short opus_int16; + typedef unsigned short opus_uint16; +# else + /* MSVC/Borland */ + typedef __int32 opus_int32; + typedef unsigned __int32 opus_uint32; + typedef __int16 opus_int16; + typedef unsigned __int16 opus_uint16; +# endif + +#elif defined(__MACOS__) + +# include + typedef SInt16 opus_int16; + typedef UInt16 opus_uint16; + typedef SInt32 opus_int32; + typedef UInt32 opus_uint32; + +#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ + +# include + typedef int16_t opus_int16; + typedef u_int16_t opus_uint16; + typedef int32_t opus_int32; + typedef u_int32_t opus_uint32; + +#elif defined(__BEOS__) + + /* Be */ +# include + typedef int16 opus_int16; + typedef u_int16 opus_uint16; + typedef int32_t opus_int32; + typedef u_int32_t opus_uint32; + +#elif defined (__EMX__) + + /* OS/2 GCC */ + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#elif defined (DJGPP) + + /* DJGPP */ + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#elif defined(R5900) + + /* PS2 EE */ + typedef int opus_int32; + typedef unsigned opus_uint32; + typedef short opus_int16; + typedef unsigned short opus_uint16; + +#elif defined(__SYMBIAN32__) + + /* Symbian GCC */ + typedef signed short opus_int16; + typedef unsigned short opus_uint16; + typedef signed int opus_int32; + typedef unsigned int opus_uint32; + +#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) + + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef long opus_int32; + typedef unsigned long opus_uint32; + +#elif defined(CONFIG_TI_C6X) + + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#else + + /* Give up, take a reasonable guess */ + typedef short opus_int16; + typedef unsigned short opus_uint16; + typedef int opus_int32; + typedef unsigned int opus_uint32; + +#endif + +#endif /* OPUS_TYPES_H */ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_buttons.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_buttons.py index 7da3545b..fe414f2b 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_buttons.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_buttons.py @@ -30,7 +30,9 @@ class AI_dev(Abstract): def __init__(self): # if(dev_type != "7PIN"): # set_ipv4_datacall() - self.is_wdt = 0 #是否开启看门狗 + # 看门狗:通过配置启停;默认喂狗点在 AI_dev_timer_event(10s 周期) + self.is_wdt = 1 if cfg_bool("WDT_ENABLED", False) else 0 + self._wdt_timeout_s = cfg_int("WDT_TIMEOUT_S", 30) #AT+QDAI=1,0,0,1,0,0,1,1PCM音频输出设置为主模式、短同步、16 kHz采样率和256 kHz时钟频率,采样位深为16bit,使用的时间间隙数量为1,并且使用第一个时间间隙。 bt_pm_en = cfg_bool("BT_POWER_MOTOR_ENABLED", False) pin_bt_on = cfg_attr("PIN_BT_ON_GPIO", None) @@ -65,7 +67,15 @@ class AI_dev(Abstract): self.KeyAI_press = 0 self.last_ai_key_time = 0#让ai按键不要频繁调用 if self.is_wdt == 1: - self.wdt = WDT(30) #开启看门狗 + try: + # timeout 必须大于喂狗周期(默认 10s),避免误复位 + t = int(self._wdt_timeout_s or 0) + if t < 15: + t = 15 + self.wdt = WDT(t) + except Exception: + # 初始化失败时禁用,避免后续 feed 触发异常 + self.is_wdt = 0 # self.wdt_timer = osTimer() # self.wdt_timer.start(5000, 1, self.wdt_timer_cb) diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_interrupt.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_interrupt.py index c69ab650..00ea6db5 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_interrupt.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_interrupt.py @@ -1,93 +1,93 @@ -# -*- coding: utf-8 -*- -"""长对话/PTT 打断上下文:绑定 turn_gen,收敛 is_ruppt_tts 等 legacy 标志。""" -try: - import utime -except Exception: - utime = None - - -class InterruptContext(object): - KIND_NONE = "" - KIND_LONG_SHORT = "long_short" - KIND_PTT_SHORT = "ptt_short" - KIND_PTT_LONG = "ptt_long" - - def __init__(self): - self.active = 0 - self.kind = self.KIND_NONE - self.gen = 0 - self.pending_uplink = 0 - self.drop_tts = 0 - self.ruppt_tts = 0 - self.settled_ms = 0 - self.cancel_deadline_ms = 0 - - def clear(self, vc=None): - self.active = 0 - self.kind = self.KIND_NONE - self.gen = 0 - self.pending_uplink = 0 - self.drop_tts = 0 - self.ruppt_tts = 0 - self.settled_ms = 0 - self.cancel_deadline_ms = 0 - if vc is not None: - self._sync_legacy(vc) - - def begin(self, vc, kind, pending_uplink=0, cancel_wait_ms=800): - self.gen = int(getattr(vc, "_vc_turn_gen", 0)) - self.active = 1 - self.kind = kind or self.KIND_NONE - self.pending_uplink = 1 if pending_uplink else 0 - self.drop_tts = 1 - self.ruppt_tts = 1 - self.settled_ms = 0 - self.cancel_deadline_ms = 0 - if utime and cancel_wait_ms: - try: - self.cancel_deadline_ms = utime.ticks_add(utime.ticks_ms(), int(cancel_wait_ms)) - except Exception: - pass - self._sync_legacy(vc) - return self.gen - - def settle(self, vc): - """打断开麦完成:清 is_ruppt/drop 以允许新 TTS;保留 settled_ms 供迟到 canceled 判 stale。""" - if utime: - try: - self.settled_ms = utime.ticks_ms() - except Exception: - self.settled_ms = 0 - self.pending_uplink = 0 - self.active = 0 - self.drop_tts = 0 - self.ruppt_tts = 0 - self._sync_legacy(vc) - - def end_drop_window(self, vc): - """新一轮 TTS 开始:结束丢弃窗口。""" - self.drop_tts = 0 - self.ruppt_tts = 0 - self.settled_ms = 0 - self.pending_uplink = 0 - self.active = 0 - self._sync_legacy(vc) - - def is_stale_gen(self, vc): - return int(getattr(vc, "_vc_turn_gen", 0)) != int(self.gen) - - def _sync_legacy(self, vc): - """与 vc_session_io / media 中既有 getattr 兼容。""" - vc._vc_pending_interrupt_uplink = 1 if self.pending_uplink else 0 - vc.is_ruppt_tts = 1 if self.ruppt_tts else 0 - vc._drop_tts_audio = 1 if self.drop_tts else 0 - vc._long_dialogue_interrupt_settled_ms = int(self.settled_ms or 0) - vc._vc_cancel_deadline_ms = int(self.cancel_deadline_ms or 0) - - def load_legacy(self, vc): - self.pending_uplink = 1 if getattr(vc, "_vc_pending_interrupt_uplink", 0) else 0 - self.ruppt_tts = 1 if getattr(vc, "is_ruppt_tts", 0) else 0 - self.drop_tts = 1 if getattr(vc, "_drop_tts_audio", 0) else 0 - self.settled_ms = int(getattr(vc, "_long_dialogue_interrupt_settled_ms", 0) or 0) - self.cancel_deadline_ms = int(getattr(vc, "_vc_cancel_deadline_ms", 0) or 0) - self.active = 1 if (self.pending_uplink or self.ruppt_tts or self.drop_tts) else 0 +# -*- coding: utf-8 -*- +"""长对话/PTT 打断上下文:绑定 turn_gen,收敛 is_ruppt_tts 等 legacy 标志。""" +try: + import utime +except Exception: + utime = None + + +class InterruptContext(object): + KIND_NONE = "" + KIND_LONG_SHORT = "long_short" + KIND_PTT_SHORT = "ptt_short" + KIND_PTT_LONG = "ptt_long" + + def __init__(self): + self.active = 0 + self.kind = self.KIND_NONE + self.gen = 0 + self.pending_uplink = 0 + self.drop_tts = 0 + self.ruppt_tts = 0 + self.settled_ms = 0 + self.cancel_deadline_ms = 0 + + def clear(self, vc=None): + self.active = 0 + self.kind = self.KIND_NONE + self.gen = 0 + self.pending_uplink = 0 + self.drop_tts = 0 + self.ruppt_tts = 0 + self.settled_ms = 0 + self.cancel_deadline_ms = 0 + if vc is not None: + self._sync_legacy(vc) + + def begin(self, vc, kind, pending_uplink=0, cancel_wait_ms=800): + self.gen = int(getattr(vc, "_vc_turn_gen", 0)) + self.active = 1 + self.kind = kind or self.KIND_NONE + self.pending_uplink = 1 if pending_uplink else 0 + self.drop_tts = 1 + self.ruppt_tts = 1 + self.settled_ms = 0 + self.cancel_deadline_ms = 0 + if utime and cancel_wait_ms: + try: + self.cancel_deadline_ms = utime.ticks_add(utime.ticks_ms(), int(cancel_wait_ms)) + except Exception: + pass + self._sync_legacy(vc) + return self.gen + + def settle(self, vc): + """打断开麦完成:清 is_ruppt/drop 以允许新 TTS;保留 settled_ms 供迟到 canceled 判 stale。""" + if utime: + try: + self.settled_ms = utime.ticks_ms() + except Exception: + self.settled_ms = 0 + self.pending_uplink = 0 + self.active = 0 + self.drop_tts = 0 + self.ruppt_tts = 0 + self._sync_legacy(vc) + + def end_drop_window(self, vc): + """新一轮 TTS 开始:结束丢弃窗口。""" + self.drop_tts = 0 + self.ruppt_tts = 0 + self.settled_ms = 0 + self.pending_uplink = 0 + self.active = 0 + self._sync_legacy(vc) + + def is_stale_gen(self, vc): + return int(getattr(vc, "_vc_turn_gen", 0)) != int(self.gen) + + def _sync_legacy(self, vc): + """与 vc_session_io / media 中既有 getattr 兼容。""" + vc._vc_pending_interrupt_uplink = 1 if self.pending_uplink else 0 + vc.is_ruppt_tts = 1 if self.ruppt_tts else 0 + vc._drop_tts_audio = 1 if self.drop_tts else 0 + vc._long_dialogue_interrupt_settled_ms = int(self.settled_ms or 0) + vc._vc_cancel_deadline_ms = int(self.cancel_deadline_ms or 0) + + def load_legacy(self, vc): + self.pending_uplink = 1 if getattr(vc, "_vc_pending_interrupt_uplink", 0) else 0 + self.ruppt_tts = 1 if getattr(vc, "is_ruppt_tts", 0) else 0 + self.drop_tts = 1 if getattr(vc, "_drop_tts_audio", 0) else 0 + self.settled_ms = int(getattr(vc, "_long_dialogue_interrupt_settled_ms", 0) or 0) + self.cancel_deadline_ms = int(getattr(vc, "_vc_cancel_deadline_ms", 0) or 0) + self.active = 1 if (self.pending_uplink or self.ruppt_tts or self.drop_tts) else 0 diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_media_arb.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_media_arb.py index 29596656..fcc0ab08 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_media_arb.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_media_arb.py @@ -1,59 +1,59 @@ -# -*- coding: utf-8 -*- -"""媒体车道仲裁:llm_pcm / notify_tts / local(对齐设计稿幻灯片 4)。""" -try: - import EventMesh -except Exception: - EventMesh = None - -LANE_LLM_PCM = 1 -LANE_NOTIFY = 2 -LANE_LOCAL = 3 - - -class MediaArbiter(object): - @staticmethod - def llm_active(vc): - if hasattr(vc, "_vc_tts_playback_active"): - return vc._vc_tts_playback_active() - return False - - @staticmethod - def before_local(vc): - """local 播:仅打断 llm_pcm;不停录、不断 notify WS。""" - if not MediaArbiter.llm_active(vc): - return - try: - vc._ptt_hard_mute_local_playback() - vc.VC_Play_End() - except Exception: - pass - - @staticmethod - def before_notify(vc): - """notify TTS:关 llm_pcm + local(设计稿;会话接管仍由 play_tts_cb 建链)。""" - MediaArbiter.before_local(vc) - if getattr(vc, "_vc_local_play_busy", None) and vc._vc_local_play_busy(): - try: - vc.aud.stopAll() - except Exception: - pass - if hasattr(vc, "_vc_stop_downlink_for_interrupt"): - vc._vc_stop_downlink_for_interrupt("notify") - - @staticmethod - def before_llm_pcm(vc): - """llm 下行:停 local 短音;notify èµ° defer 队列。""" - if getattr(vc, "_vc_local_play_busy", None) and vc._vc_local_play_busy(): - try: - vc.aud.stopAll() - except Exception: - pass - - @staticmethod - def montage_allowed(vc): - """llm 播时缓存/跳过 montage(vc_buttons 已有类似逻辑,集中判断)。""" - if MediaArbiter.llm_active(vc): - return False - if EventMesh and EventMesh.publish("get_vc_tts_playback_active") == 1: - return False - return True +# -*- coding: utf-8 -*- +"""媒体车道仲裁:llm_pcm / notify_tts / local(对齐设计稿幻灯片 4)。""" +try: + import EventMesh +except Exception: + EventMesh = None + +LANE_LLM_PCM = 1 +LANE_NOTIFY = 2 +LANE_LOCAL = 3 + + +class MediaArbiter(object): + @staticmethod + def llm_active(vc): + if hasattr(vc, "_vc_tts_playback_active"): + return vc._vc_tts_playback_active() + return False + + @staticmethod + def before_local(vc): + """local 播:仅打断 llm_pcm;不停录、不断 notify WS。""" + if not MediaArbiter.llm_active(vc): + return + try: + vc._ptt_hard_mute_local_playback() + vc.VC_Play_End() + except Exception: + pass + + @staticmethod + def before_notify(vc): + """notify TTS:关 llm_pcm + local(设计稿;会话接管仍由 play_tts_cb 建链)。""" + MediaArbiter.before_local(vc) + if getattr(vc, "_vc_local_play_busy", None) and vc._vc_local_play_busy(): + try: + vc.aud.stopAll() + except Exception: + pass + if hasattr(vc, "_vc_stop_downlink_for_interrupt"): + vc._vc_stop_downlink_for_interrupt("notify") + + @staticmethod + def before_llm_pcm(vc): + """llm 下行:停 local 短音;notify èµ° defer 队列。""" + if getattr(vc, "_vc_local_play_busy", None) and vc._vc_local_play_busy(): + try: + vc.aud.stopAll() + except Exception: + pass + + @staticmethod + def montage_allowed(vc): + """llm 播时缓存/跳过 montage(vc_buttons 已有类似逻辑,集中判断)。""" + if MediaArbiter.llm_active(vc): + return False + if EventMesh and EventMesh.publish("get_vc_tts_playback_active") == 1: + return False + return True diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_mode_strategy.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_mode_strategy.py index ee63ccfd..4dfcef81 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_mode_strategy.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_mode_strategy.py @@ -1,73 +1,73 @@ -# -*- coding: utf-8 -*- -"""单对话 / 长对话按键策略:入口仅转发 KeyRouter(设计稿表驱动)。""" -try: - import EventMesh -except Exception: - EventMesh = None -try: - from vc_key_router import KeyRouter -except Exception: - KeyRouter = None - - -class VCModeStrategy(object): - def on_key_press(self, vc): - return False - - def on_key_release(self, vc): - return False - - def on_key_long_press(self, vc): - return False - - -class LongDialogueStrategy(VCModeStrategy): - def on_key_press(self, vc): - if KeyRouter is not None: - return KeyRouter.dispatch_press(vc) - return False - - def on_key_release(self, vc): - return False - - def on_key_long_press(self, vc): - if vc._vc_ms_keys_blocked("AI_long_press"): - return True - if getattr(vc, "trans_flag", 0) == 1: - vc.Close() - EventMesh.publish("start_voice_record", 4) - vc.AI_key_long_press_flag = 1 - if hasattr(vc, "_vc_key_router_press_cb"): - vc._vc_enqueue_btn(vc._vc_key_router_press_cb, priority=1) - else: - vc._vc_enqueue_btn(vc._ai_key_press_long_dialogue_dispatch, priority=1) - return True - - -class PTTStrategy(VCModeStrategy): - def on_key_press(self, vc): - if KeyRouter is not None: - return KeyRouter.dispatch_press(vc) - return True - - def on_key_release(self, vc): - vc._ai_key_release_handle_ptt() - return True - - def on_key_long_press(self, vc): - if vc._vc_ms_keys_blocked("AI_long_press"): - return True - if getattr(vc, "trans_flag", 0) == 1: - vc.Close() - EventMesh.publish("start_voice_record", 4) - vc.AI_key_long_press_flag = 1 - vc._ptt_idle_latch = 0 - vc._ptt_short_press_stop = 0 - vc._vc_enqueue_btn(vc.ptt_begin, priority=1) - return True - - -def strategy_for_mode(vc_mode): - if int(vc_mode) == 1: - return PTTStrategy() - return LongDialogueStrategy() +# -*- coding: utf-8 -*- +"""单对话 / 长对话按键策略:入口仅转发 KeyRouter(设计稿表驱动)。""" +try: + import EventMesh +except Exception: + EventMesh = None +try: + from vc_key_router import KeyRouter +except Exception: + KeyRouter = None + + +class VCModeStrategy(object): + def on_key_press(self, vc): + return False + + def on_key_release(self, vc): + return False + + def on_key_long_press(self, vc): + return False + + +class LongDialogueStrategy(VCModeStrategy): + def on_key_press(self, vc): + if KeyRouter is not None: + return KeyRouter.dispatch_press(vc) + return False + + def on_key_release(self, vc): + return False + + def on_key_long_press(self, vc): + if vc._vc_ms_keys_blocked("AI_long_press"): + return True + if getattr(vc, "trans_flag", 0) == 1: + vc.Close() + EventMesh.publish("start_voice_record", 4) + vc.AI_key_long_press_flag = 1 + if hasattr(vc, "_vc_key_router_press_cb"): + vc._vc_enqueue_btn(vc._vc_key_router_press_cb, priority=1) + else: + vc._vc_enqueue_btn(vc._ai_key_press_long_dialogue_dispatch, priority=1) + return True + + +class PTTStrategy(VCModeStrategy): + def on_key_press(self, vc): + if KeyRouter is not None: + return KeyRouter.dispatch_press(vc) + return True + + def on_key_release(self, vc): + vc._ai_key_release_handle_ptt() + return True + + def on_key_long_press(self, vc): + if vc._vc_ms_keys_blocked("AI_long_press"): + return True + if getattr(vc, "trans_flag", 0) == 1: + vc.Close() + EventMesh.publish("start_voice_record", 4) + vc.AI_key_long_press_flag = 1 + vc._ptt_idle_latch = 0 + vc._ptt_short_press_stop = 0 + vc._vc_enqueue_btn(vc.ptt_begin, priority=1) + return True + + +def strategy_for_mode(vc_mode): + if int(vc_mode) == 1: + return PTTStrategy() + return LongDialogueStrategy() diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_notify.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_notify.py index 781d2cc7..d197bb70 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_notify.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_notify.py @@ -1,127 +1,127 @@ -# -*- coding: utf-8 -*- -"""通知通道:server.started 媒体排队、play_tts 与对话会话分流。""" -try: - from vc_fsm import VCTurnState -except Exception: - VCTurnState = None - -import EventMesh -from vc_utils import cfg_bool - -# play_tts 通道 -CHANNEL_TAKEOVER = "takeover" # 断连重连 WS synthesis(IoT 查找设备/模式切换/无对话) -CHANNEL_DEFER = "defer" # 对话进行中排队,空闲后播放(is_close_VC=0 的 IoT 查询等) - -# TTS 业务种类(_pending_tts_kind / play_tts 第三参数) -TTS_KIND_FIND_DEVICE = "find_device" -TTS_KIND_MODE_SWITCH_LONG = "mode_switch_long" -TTS_KIND_MODE_SWITCH_PTT = "mode_switch_ptt" -TTS_KIND_BOOT_PROMPT = "boot_prompt" -TTS_KIND_PROMPT = "prompt" - -# 须立即占用会话、不可 defer -_TAKEOVER_KINDS = ( - TTS_KIND_FIND_DEVICE, - TTS_KIND_MODE_SWITCH_LONG, - TTS_KIND_MODE_SWITCH_PTT, - TTS_KIND_BOOT_PROMPT, - TTS_KIND_PROMPT, -) - -# server.started plan op -OP_LONG_UPLINK = "long_uplink" -OP_ALARM_VOICE = "alarm_voice" -OP_VOICE_URL = "voice_url" -OP_SYNTHESIS = "synthesis" -OP_SYNTHESIS_HIS_TIMER = "synthesis_his_timer" -OP_SYNTHESIS_WAIT_TIMER = "synthesis_wait_timer" -OP_SYNTHESIS_WAIT_SINGLE = "synthesis_wait_single" -OP_SYNTHESIS_VOICE_TIMER = "synthesis_voice_timer" -OP_SYNTHESIS_MUSIC_TIMER = "synthesis_music_timer" -OP_IDLE_UPLINK = "idle_uplink" -OP_PTT_ROUND = "ptt_round" -OP_UPLOAD_TONE = "upload_tone" - - -def dialog_session_active(vc): - """对话占用中:通知类 play_tts 应 defer。""" - if getattr(vc, "Close_flag", 0) == 1: - return False - if getattr(vc, "VC_satrt_flag", 0) != 1: - return False - if getattr(vc, "AI_client_VC_isconnect", 0) != 1: - return False - if getattr(vc, "VC_Play_flag", 0) == 1: - return True - if getattr(vc, "VC_record_state_flag", 0) != 0: - return True - if getattr(vc, "music_play_flag", 0) == 1: - return True - if VCTurnState is not None and getattr(vc, "fsm", None) is not None: - t = getattr(vc.fsm, "turn", VCTurnState.Idle) - if t not in (VCTurnState.Idle, VCTurnState.Listening): - return True - return False - - -class NotifyScheduler(object): - @staticmethod - def classify_play_tts(vc, is_close_vc): - if is_close_vc: - return CHANNEL_TAKEOVER - k = getattr(vc, "_pending_tts_kind", "") or getattr(vc, "_last_tts_kind", "") or "" - if k in _TAKEOVER_KINDS: - return CHANNEL_TAKEOVER - if dialog_session_active(vc): - return CHANNEL_DEFER - return CHANNEL_TAKEOVER - - @staticmethod - def plan_on_started(vc, skip_long_uplink=0): - """替代 vc_session_io started 内 if-elif 媒体分支。""" - plan = [] - - if ( - not skip_long_uplink - and getattr(vc, "VC_mode", 0) == 0 - and getattr(vc, "Close_flag", 0) == 0 - and not getattr(vc, "_vc_boot_standby", 0) - ): - plan.append({"op": OP_LONG_UPLINK}) - - tts = getattr(vc, "AI_TTS_str", "") or "" - url = getattr(vc, "AI_new_voice_url", "") or "" - alarm = getattr(vc, "alarm_play_flag", 0) == 1 - music = getattr(vc, "music_play_flag", 0) == 1 - - if url and alarm: - plan.append({"op": OP_ALARM_VOICE}) - elif not tts and url and not music: - plan.append({"op": OP_VOICE_URL}) - elif tts and not url: - plan.append({"op": OP_SYNTHESIS}) - elif tts and url and not music: - his = EventMesh.publish("get_history_voice_flag") == 1 - if his: - wait = EventMesh.publish("get_wait_voice_flag") == 0 - if wait: - plan.append({"op": OP_SYNTHESIS_HIS_TIMER}) - else: - notice = getattr(vc, "pwk_notice_flag", 0) == 0 - if notice: - plan.append({"op": OP_SYNTHESIS_WAIT_TIMER}) - else: - plan.append({"op": OP_SYNTHESIS_WAIT_SINGLE}) - else: - plan.append({"op": OP_SYNTHESIS_VOICE_TIMER}) - elif tts and url and music: - plan.append({"op": OP_SYNTHESIS_MUSIC_TIMER}) - else: - if cfg_bool("UPLOAD_START_TONE_ENABLED", False): - plan.append({"op": OP_UPLOAD_TONE}) - if getattr(vc, "VC_mode", 0) == 0: - plan.append({"op": OP_IDLE_UPLINK}) - else: - plan.append({"op": OP_PTT_ROUND}) - - return plan +# -*- coding: utf-8 -*- +"""通知通道:server.started 媒体排队、play_tts 与对话会话分流。""" +try: + from vc_fsm import VCTurnState +except Exception: + VCTurnState = None + +import EventMesh +from vc_utils import cfg_bool + +# play_tts 通道 +CHANNEL_TAKEOVER = "takeover" # 断连重连 WS synthesis(IoT 查找设备/模式切换/无对话) +CHANNEL_DEFER = "defer" # 对话进行中排队,空闲后播放(is_close_VC=0 的 IoT 查询等) + +# TTS 业务种类(_pending_tts_kind / play_tts 第三参数) +TTS_KIND_FIND_DEVICE = "find_device" +TTS_KIND_MODE_SWITCH_LONG = "mode_switch_long" +TTS_KIND_MODE_SWITCH_PTT = "mode_switch_ptt" +TTS_KIND_BOOT_PROMPT = "boot_prompt" +TTS_KIND_PROMPT = "prompt" + +# 须立即占用会话、不可 defer +_TAKEOVER_KINDS = ( + TTS_KIND_FIND_DEVICE, + TTS_KIND_MODE_SWITCH_LONG, + TTS_KIND_MODE_SWITCH_PTT, + TTS_KIND_BOOT_PROMPT, + TTS_KIND_PROMPT, +) + +# server.started plan op +OP_LONG_UPLINK = "long_uplink" +OP_ALARM_VOICE = "alarm_voice" +OP_VOICE_URL = "voice_url" +OP_SYNTHESIS = "synthesis" +OP_SYNTHESIS_HIS_TIMER = "synthesis_his_timer" +OP_SYNTHESIS_WAIT_TIMER = "synthesis_wait_timer" +OP_SYNTHESIS_WAIT_SINGLE = "synthesis_wait_single" +OP_SYNTHESIS_VOICE_TIMER = "synthesis_voice_timer" +OP_SYNTHESIS_MUSIC_TIMER = "synthesis_music_timer" +OP_IDLE_UPLINK = "idle_uplink" +OP_PTT_ROUND = "ptt_round" +OP_UPLOAD_TONE = "upload_tone" + + +def dialog_session_active(vc): + """对话占用中:通知类 play_tts 应 defer。""" + if getattr(vc, "Close_flag", 0) == 1: + return False + if getattr(vc, "VC_satrt_flag", 0) != 1: + return False + if getattr(vc, "AI_client_VC_isconnect", 0) != 1: + return False + if getattr(vc, "VC_Play_flag", 0) == 1: + return True + if getattr(vc, "VC_record_state_flag", 0) != 0: + return True + if getattr(vc, "music_play_flag", 0) == 1: + return True + if VCTurnState is not None and getattr(vc, "fsm", None) is not None: + t = getattr(vc.fsm, "turn", VCTurnState.Idle) + if t not in (VCTurnState.Idle, VCTurnState.Listening): + return True + return False + + +class NotifyScheduler(object): + @staticmethod + def classify_play_tts(vc, is_close_vc): + if is_close_vc: + return CHANNEL_TAKEOVER + k = getattr(vc, "_pending_tts_kind", "") or getattr(vc, "_last_tts_kind", "") or "" + if k in _TAKEOVER_KINDS: + return CHANNEL_TAKEOVER + if dialog_session_active(vc): + return CHANNEL_DEFER + return CHANNEL_TAKEOVER + + @staticmethod + def plan_on_started(vc, skip_long_uplink=0): + """替代 vc_session_io started 内 if-elif 媒体分支。""" + plan = [] + + if ( + not skip_long_uplink + and getattr(vc, "VC_mode", 0) == 0 + and getattr(vc, "Close_flag", 0) == 0 + and not getattr(vc, "_vc_boot_standby", 0) + ): + plan.append({"op": OP_LONG_UPLINK}) + + tts = getattr(vc, "AI_TTS_str", "") or "" + url = getattr(vc, "AI_new_voice_url", "") or "" + alarm = getattr(vc, "alarm_play_flag", 0) == 1 + music = getattr(vc, "music_play_flag", 0) == 1 + + if url and alarm: + plan.append({"op": OP_ALARM_VOICE}) + elif not tts and url and not music: + plan.append({"op": OP_VOICE_URL}) + elif tts and not url: + plan.append({"op": OP_SYNTHESIS}) + elif tts and url and not music: + his = EventMesh.publish("get_history_voice_flag") == 1 + if his: + wait = EventMesh.publish("get_wait_voice_flag") == 0 + if wait: + plan.append({"op": OP_SYNTHESIS_HIS_TIMER}) + else: + notice = getattr(vc, "pwk_notice_flag", 0) == 0 + if notice: + plan.append({"op": OP_SYNTHESIS_WAIT_TIMER}) + else: + plan.append({"op": OP_SYNTHESIS_WAIT_SINGLE}) + else: + plan.append({"op": OP_SYNTHESIS_VOICE_TIMER}) + elif tts and url and music: + plan.append({"op": OP_SYNTHESIS_MUSIC_TIMER}) + else: + if cfg_bool("UPLOAD_START_TONE_ENABLED", False): + plan.append({"op": OP_UPLOAD_TONE}) + if getattr(vc, "VC_mode", 0) == 0: + plan.append({"op": OP_IDLE_UPLINK}) + else: + plan.append({"op": OP_PTT_ROUND}) + + return plan diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ota.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ota.py index e6aa9b60..12e99ea8 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ota.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ota.py @@ -1,266 +1,266 @@ -# -*- coding: utf-8 -*- -"""FOTA / DMP 上报。小程序上的版本,是这个ota接口上报的。""" -try: - from qp_log import qp_print as print -except Exception: - pass -import EventMesh -import usys -import utime -import osTimer -import net -import sim -import modem -import request -import constants -import version_util -from misc import Power -import _thread - -def _build_ota_task_url(source_version): - """OTA 检查任务 URL:default_srv.OTA_TASK_URL_FMT,否则 DMP_BASE + /ota/task。""" - fmt = getattr(constants, "OTA_TASK_URL_FMT", None) or "" - if not fmt: - base = getattr(constants, "DMP_BASE", None) or "" - if base: - fmt = base + "/ota/task?deviceId={}&sourceVersion={}" - if not fmt: - return None - return fmt.format(modem.getDevImei(), source_version) - - -def _build_ota_result_url(current_version): - """OTA 结果上报:DMP_BASE + default_srv.OTA_RESULT_PATH_FMT。""" - path_fmt = getattr( - constants, - "OTA_RESULT_PATH_FMT", - "/ota/result?deviceId={}¤tVersion={}", - ) - base = getattr(constants, "DMP_BASE", None) or "" - return base + path_fmt.format(modem.getDevImei(), current_version) - - -class OTA(): - def __init__(self): - #EventMesh.subscribe("min_sys_ota",self.min_sys_ota) - self.downloadFileVoURL1= "" - self.downloadFileVoURL2= "" - self.downloadFileVoURLBT="" - self.BT_ota_size =0 - self.ota_task_id = None - #蓝牙升级升级,返回0,没有升级;返回,1有升级,正在执行升级;返回2,电压不够 - def bt_ota(self,event=None,msg=None): - print("bt_ota_ota") - signal = net.csqQueryPoll() - if signal == -1 or sim.getStatus() != 1:#网络不正常 - print("bt_ota 无 SIM卡!!!!!!!!\r\n") - return 0 - # return 0 - response = None - ret_str =0 - - self.downloadFileVoURLBT="" - try: - #sourceVersion = versions.Build_Time - # sourceVersion = "7PIN-"+sourceVersion[:10]+"-"+sourceVersion[11:-3] - # print("sourceVersion:{}".format(sourceVersion)) - # sourceVersion = sourceVersion.replace(" ", "0") - # print("sourceVersion2:{}".format(sourceVersion)) - sourceVersion = version_util.get_unified_version() - print("sourceVersion:{}".format(sourceVersion)) - bt_versions = EventMesh.publish("get_bt_versions") - if bt_versions == None: - bt_versions="" - print("bt_versions:{}".format(bt_versions)) - url = _build_ota_task_url(sourceVersion) - if not url: - print("bt_ota: OTA_TASK_URL_FMT 未配置") - return 0 - print(url) - response = request.get(url,timeout=5) - if response.status_code == 200: - data = response.json() - print("OTA升级请求:{}".format(data)) - - if data: - code = data.get("code") - if code == 20007: - file_list = (data.get("data") or {}).get("fileList") - if file_list and data.get("data", {}).get("targetVersion") != bt_versions: - for fileList in file_list: - if fileList.get("fileName") == "update.ufw": - self.BT_ota_size = fileList.get("size", 0) - self.downloadFileVoURLBT = fileList.get("url", "") - elif code == 20006: - ret_str = 0 - else: - print("bt_ota get error") - response.close() - except Exception as e: - usys.print_exception(e) - if response != None: - response.close() - - print("downloadFileVoURLBT{}".format(self.downloadFileVoURLBT)) - print("bt_ota end") - if self.downloadFileVoURLBT !="": - battery = EventMesh.publish("get_battery") - if battery>=40: - self.ota_timer = osTimer() - #self.ota_timer.start(15000, 0, self.ota_timer_cb) - if self.ota_task_id ==None: - self.ota_task_id = _thread.start_new_thread(self.ota_task,()) - ret_str = 1 - else: - ret_str = 2 - return ret_str - #小系统升级,返回0,没有升级;返回,1有升级,正在执行升级;返回2,电压不够 - def min_sys_ota(self,event=None,msg=None): - print("min_sys_ota") - signal = net.csqQueryPoll() - if signal == -1 or sim.getStatus() != 1:#网络不正常 - print("min_sys_ota 无 SIM卡!!!!!!!!\r\n") - return 0 - # return 0 - response = None - ret_str =0 - self.downloadFileVoURL1= "" - self.downloadFileVoURL2= "" - #self.downloadFileVoURLBT="" - try: - sourceVersion = version_util.get_unified_version() - print("sourceVersion:{}".format(sourceVersion)) - url = _build_ota_task_url(sourceVersion) - if not url: - print("min_sys_ota: OTA_TASK_URL_FMT 未配置") - return 0 - print(url) - response = request.get(url,timeout=5) - if response.status_code == 200: - data = response.json() - print("OTA升级请求:{}".format(data)) - - if data: - code = data.get("code") - if code == 20007: - file_list = (data.get("data") or {}).get("fileList") - if file_list: - for fileList in file_list: - name = fileList.get("fileName") - url = fileList.get("url", "") - if name == "dfota_2.bin": - self.downloadFileVoURL2 = url - elif name == "dfota_1.bin": - self.downloadFileVoURL1 = url - elif name == "update.ufw": - self.BT_ota_size = fileList.get("size", 0) - self.downloadFileVoURLBT = url - elif code == 20006: - ret_str = 0 - else: - print("min_sys_ota get error") - response.close() - except Exception as e: - usys.print_exception(e) - if response != None: - response.close() - - print("min_sys_ota:downloadFileVoURL1:{},\ndownloadFileVoURL2:{},\ndownloadFileVoURLBT{}".format(self.downloadFileVoURL1,self.downloadFileVoURL2,self.downloadFileVoURLBT)) - print("min_sys_ota end") - if self.downloadFileVoURL2!="" and self.downloadFileVoURL1!="" : - battery = EventMesh.publish("get_battery") - if battery>=40: - self.ota_timer = osTimer() - #self.ota_timer.start(15000, 0, self.ota_timer_cb) - if self.ota_task_id ==None: - self.ota_task_id = _thread.start_new_thread(self.ota_task,()) - ret_str = 1 - else: - ret_str = 2 - return ret_str - - # def ota_timer_cb(self, *args, **kwargs): - # EventMesh.publish("publish_AI_btnInfo",{"func":self.usb_event}) - - def ota_task(self): - import fota - utime.sleep_ms(15000) - count = 30#最多等待30秒 - while 1: - count-=1 - VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")#获取vc是否在运行 - if VC_satrt_flag == None: - VC_satrt_flag = 0 - voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行 - if voice_record_satrt_flag == None: - voice_record_satrt_flag = 0 - if VC_satrt_flag == 0 or count<=0 or voice_record_satrt_flag == 0: - break - utime.sleep_ms(100) - if self.downloadFileVoURLBT != "" and self.BT_ota_size != 0: - count = 5 #重试5次 - while 1: - count -=1 - ret = EventMesh.publish("bt_ota_run",[self.downloadFileVoURLBT,self.BT_ota_size ]) #升级蓝牙 - - if ret == 0 or count <=0: - break - utime.sleep_ms(1000) - utime.sleep_ms(1000) - #EventMesh.publish("rest_TB") #复位蓝牙 - utime.sleep_ms(50000) - if self.downloadFileVoURL1 == "" and self.downloadFileVoURL2 == "": #cat1没有升级的时候,要重启设备 - Power.powerRestart() - if self.downloadFileVoURL1 != "" and self.downloadFileVoURL2 != "": - fota_obj = fota() - fota_obj.httpDownload(url1=self.downloadFileVoURL1,url2=self.downloadFileVoURL2) - #ota升级结果返回,开机时调用一次即可 - def ota_result(self,event=None,msg=None): - response = None - try: - currentVersion = version_util.get_unified_version() - print("currentVersion:{}".format(currentVersion)) - url = _build_ota_result_url(currentVersion) - print(url) - response = request.post(url,timeout=5) - if response.status_code == 200: - data = response.json() - print("OTA升级结果上报:{}".format(data)) - else: - print("ota_result error!!!!") - for i in response.text: - print(i) - response.close() - except Exception as e: - usys.print_exception(e) - if response != None: - response.close() - #ICCID上传 - def pots_ICCID(self,event=None,msg=None): - response = None - try: - iccid = sim.getIccid() - if iccid != -1 and len(iccid) > 5: - print("pots_ICCID:{}".format(iccid)) - #Headers = {'Transfer-Encodong':'chunked'} - token = EventMesh.publish("get_dev_token") - headers_T = None - if token: - headers_T = {"bz-dt":"{}".format(token)} - #http://dmp.raisound.com/bz-api/dev/iccid?deviceId=866610001099679&iccid=89860002192307889057 - url =None - url = (constants.DMP_BASE + "/dev/iccid?deviceId={}&iccid={}").format(modem.getDevImei(),iccid) - print("{} H:{}".format(url,headers_T)) - response = request.post(url,headers = headers_T,timeout=5) - if response.status_code == 200: - data = response.json() - print("pots_ICCID:{}".format(data)) - else: - print("pots_ICCID error!!!!") - for i in response.text: - print(i) - response.close() - except Exception as e: - usys.print_exception(e) - if response != None: - response.close() +# -*- coding: utf-8 -*- +"""FOTA / DMP 上报。小程序上的版本,是这个ota接口上报的。""" +try: + from qp_log import qp_print as print +except Exception: + pass +import EventMesh +import usys +import utime +import osTimer +import net +import sim +import modem +import request +import constants +import version_util +from misc import Power +import _thread + +def _build_ota_task_url(source_version): + """OTA 检查任务 URL:default_srv.OTA_TASK_URL_FMT,否则 DMP_BASE + /ota/task。""" + fmt = getattr(constants, "OTA_TASK_URL_FMT", None) or "" + if not fmt: + base = getattr(constants, "DMP_BASE", None) or "" + if base: + fmt = base + "/ota/task?deviceId={}&sourceVersion={}" + if not fmt: + return None + return fmt.format(modem.getDevImei(), source_version) + + +def _build_ota_result_url(current_version): + """OTA 结果上报:DMP_BASE + default_srv.OTA_RESULT_PATH_FMT。""" + path_fmt = getattr( + constants, + "OTA_RESULT_PATH_FMT", + "/ota/result?deviceId={}¤tVersion={}", + ) + base = getattr(constants, "DMP_BASE", None) or "" + return base + path_fmt.format(modem.getDevImei(), current_version) + + +class OTA(): + def __init__(self): + #EventMesh.subscribe("min_sys_ota",self.min_sys_ota) + self.downloadFileVoURL1= "" + self.downloadFileVoURL2= "" + self.downloadFileVoURLBT="" + self.BT_ota_size =0 + self.ota_task_id = None + #蓝牙升级升级,返回0,没有升级;返回,1有升级,正在执行升级;返回2,电压不够 + def bt_ota(self,event=None,msg=None): + print("bt_ota_ota") + signal = net.csqQueryPoll() + if signal == -1 or sim.getStatus() != 1:#网络不正常 + print("bt_ota 无 SIM卡!!!!!!!!\r\n") + return 0 + # return 0 + response = None + ret_str =0 + + self.downloadFileVoURLBT="" + try: + #sourceVersion = versions.Build_Time + # sourceVersion = "7PIN-"+sourceVersion[:10]+"-"+sourceVersion[11:-3] + # print("sourceVersion:{}".format(sourceVersion)) + # sourceVersion = sourceVersion.replace(" ", "0") + # print("sourceVersion2:{}".format(sourceVersion)) + sourceVersion = version_util.get_unified_version() + print("sourceVersion:{}".format(sourceVersion)) + bt_versions = EventMesh.publish("get_bt_versions") + if bt_versions == None: + bt_versions="" + print("bt_versions:{}".format(bt_versions)) + url = _build_ota_task_url(sourceVersion) + if not url: + print("bt_ota: OTA_TASK_URL_FMT 未配置") + return 0 + print(url) + response = request.get(url,timeout=5) + if response.status_code == 200: + data = response.json() + print("OTA升级请求:{}".format(data)) + + if data: + code = data.get("code") + if code == 20007: + file_list = (data.get("data") or {}).get("fileList") + if file_list and data.get("data", {}).get("targetVersion") != bt_versions: + for fileList in file_list: + if fileList.get("fileName") == "update.ufw": + self.BT_ota_size = fileList.get("size", 0) + self.downloadFileVoURLBT = fileList.get("url", "") + elif code == 20006: + ret_str = 0 + else: + print("bt_ota get error") + response.close() + except Exception as e: + usys.print_exception(e) + if response != None: + response.close() + + print("downloadFileVoURLBT{}".format(self.downloadFileVoURLBT)) + print("bt_ota end") + if self.downloadFileVoURLBT !="": + battery = EventMesh.publish("get_battery") + if battery>=40: + self.ota_timer = osTimer() + #self.ota_timer.start(15000, 0, self.ota_timer_cb) + if self.ota_task_id ==None: + self.ota_task_id = _thread.start_new_thread(self.ota_task,()) + ret_str = 1 + else: + ret_str = 2 + return ret_str + #小系统升级,返回0,没有升级;返回,1有升级,正在执行升级;返回2,电压不够 + def min_sys_ota(self,event=None,msg=None): + print("min_sys_ota") + signal = net.csqQueryPoll() + if signal == -1 or sim.getStatus() != 1:#网络不正常 + print("min_sys_ota 无 SIM卡!!!!!!!!\r\n") + return 0 + # return 0 + response = None + ret_str =0 + self.downloadFileVoURL1= "" + self.downloadFileVoURL2= "" + #self.downloadFileVoURLBT="" + try: + sourceVersion = version_util.get_unified_version() + print("sourceVersion:{}".format(sourceVersion)) + url = _build_ota_task_url(sourceVersion) + if not url: + print("min_sys_ota: OTA_TASK_URL_FMT 未配置") + return 0 + print(url) + response = request.get(url,timeout=5) + if response.status_code == 200: + data = response.json() + print("OTA升级请求:{}".format(data)) + + if data: + code = data.get("code") + if code == 20007: + file_list = (data.get("data") or {}).get("fileList") + if file_list: + for fileList in file_list: + name = fileList.get("fileName") + url = fileList.get("url", "") + if name == "dfota_2.bin": + self.downloadFileVoURL2 = url + elif name == "dfota_1.bin": + self.downloadFileVoURL1 = url + elif name == "update.ufw": + self.BT_ota_size = fileList.get("size", 0) + self.downloadFileVoURLBT = url + elif code == 20006: + ret_str = 0 + else: + print("min_sys_ota get error") + response.close() + except Exception as e: + usys.print_exception(e) + if response != None: + response.close() + + print("min_sys_ota:downloadFileVoURL1:{},\ndownloadFileVoURL2:{},\ndownloadFileVoURLBT{}".format(self.downloadFileVoURL1,self.downloadFileVoURL2,self.downloadFileVoURLBT)) + print("min_sys_ota end") + if self.downloadFileVoURL2!="" and self.downloadFileVoURL1!="" : + battery = EventMesh.publish("get_battery") + if battery>=40: + self.ota_timer = osTimer() + #self.ota_timer.start(15000, 0, self.ota_timer_cb) + if self.ota_task_id ==None: + self.ota_task_id = _thread.start_new_thread(self.ota_task,()) + ret_str = 1 + else: + ret_str = 2 + return ret_str + + # def ota_timer_cb(self, *args, **kwargs): + # EventMesh.publish("publish_AI_btnInfo",{"func":self.usb_event}) + + def ota_task(self): + import fota + utime.sleep_ms(15000) + count = 30#最多等待30秒 + while 1: + count-=1 + VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")#获取vc是否在运行 + if VC_satrt_flag == None: + VC_satrt_flag = 0 + voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行 + if voice_record_satrt_flag == None: + voice_record_satrt_flag = 0 + if VC_satrt_flag == 0 or count<=0 or voice_record_satrt_flag == 0: + break + utime.sleep_ms(100) + if self.downloadFileVoURLBT != "" and self.BT_ota_size != 0: + count = 5 #重试5次 + while 1: + count -=1 + ret = EventMesh.publish("bt_ota_run",[self.downloadFileVoURLBT,self.BT_ota_size ]) #升级蓝牙 + + if ret == 0 or count <=0: + break + utime.sleep_ms(1000) + utime.sleep_ms(1000) + #EventMesh.publish("rest_TB") #复位蓝牙 + utime.sleep_ms(50000) + if self.downloadFileVoURL1 == "" and self.downloadFileVoURL2 == "": #cat1没有升级的时候,要重启设备 + Power.powerRestart() + if self.downloadFileVoURL1 != "" and self.downloadFileVoURL2 != "": + fota_obj = fota() + fota_obj.httpDownload(url1=self.downloadFileVoURL1,url2=self.downloadFileVoURL2) + #ota升级结果返回,开机时调用一次即可 + def ota_result(self,event=None,msg=None): + response = None + try: + currentVersion = version_util.get_unified_version() + print("currentVersion:{}".format(currentVersion)) + url = _build_ota_result_url(currentVersion) + print(url) + response = request.post(url,timeout=5) + if response.status_code == 200: + data = response.json() + print("OTA升级结果上报:{}".format(data)) + else: + print("ota_result error!!!!") + for i in response.text: + print(i) + response.close() + except Exception as e: + usys.print_exception(e) + if response != None: + response.close() + #ICCID上传 + def pots_ICCID(self,event=None,msg=None): + response = None + try: + iccid = sim.getIccid() + if iccid != -1 and len(iccid) > 5: + print("pots_ICCID:{}".format(iccid)) + #Headers = {'Transfer-Encodong':'chunked'} + token = EventMesh.publish("get_dev_token") + headers_T = None + if token: + headers_T = {"bz-dt":"{}".format(token)} + #http://dmp.raisound.com/bz-api/dev/iccid?deviceId=866610001099679&iccid=89860002192307889057 + url =None + url = (constants.DMP_BASE + "/dev/iccid?deviceId={}&iccid={}").format(modem.getDevImei(),iccid) + print("{} H:{}".format(url,headers_T)) + response = request.post(url,headers = headers_T,timeout=5) + if response.status_code == 200: + data = response.json() + print("pots_ICCID:{}".format(data)) + else: + print("pots_ICCID error!!!!") + for i in response.text: + print(i) + response.close() + except Exception as e: + usys.print_exception(e) + if response != None: + response.close() diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_present.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_present.py index e4fc9815..74961cd7 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_present.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_present.py @@ -1,75 +1,75 @@ -# -*- coding: utf-8 -*- -"""LED 呈现:由 UX 四态 + 覆盖态推导 ai_state(唯一 set_led_state 入口)。""" -try: - from vc_fsm import VCTurnState -except Exception: - VCTurnState = None -try: - from vc_ux import derive_ux_state, UX_RECORDING, UX_THINKING, UX_TTS -except Exception: - derive_ux_state = None - - -def build_present_state(vc): - """只读聚合,不写 vc。""" - st = { - "mode": int(getattr(vc, "VC_mode", 0)), - "turn": int(getattr(getattr(vc, "fsm", None), "turn", -1)), - "force_idle": 0, - "hold_listening": 0, - "prefer_off": 0, - "stream_active": 0, - "ptt_await_server": 0, - "override_ai": None, - "override_prefer_off": 0, - } - ov = getattr(vc, "_led_override", None) - if ov and isinstance(ov, (tuple, list)) and len(ov) >= 1: - st["override_ai"] = ov[0] - st["override_prefer_off"] = 1 if (len(ov) > 1 and ov[1]) else 0 - if hasattr(vc, "_ptt_should_force_idle_led") and vc._ptt_should_force_idle_led(): - st["force_idle"] = 1 - if hasattr(vc, "_vc_should_hold_listening_led") and vc._vc_should_hold_listening_led(): - st["hold_listening"] = 1 - if hasattr(vc, "_vc_led_should_standby_idle") and vc._vc_led_should_standby_idle(): - st["force_idle"] = 1 - if hasattr(vc, "_vc_led_standby_prefer_off") and vc._vc_led_standby_prefer_off(): - st["prefer_off"] = 1 - if hasattr(vc, "_vc_tts_playback_active") and vc._vc_tts_playback_active(): - st["stream_active"] = 1 - st["ptt_await_server"] = 1 if getattr(vc, "_ptt_await_server", 0) else 0 - return st - - -def present_to_led_msg(vc, present=None): - """返回传给 set_led_state 的 dict;不发布。""" - if present is None: - present = build_present_state(vc) - if present.get("override_ai"): - msg = {"ai_state": present["override_ai"]} - if present.get("override_prefer_off") or present.get("prefer_off"): - msg["prefer_off"] = 1 - return msg - if present.get("force_idle"): - msg = {"ai_state": "idle"} - if present.get("prefer_off"): - msg["prefer_off"] = 1 - return msg - if present.get("hold_listening"): - return {"ai_state": "listening"} - if present.get("ptt_await_server") and int(present.get("mode", 0)) == 1: - return {"ai_state": "thinking"} - if present.get("stream_active"): - return {"ai_state": "playing"} - if derive_ux_state is not None: - ux = derive_ux_state(vc) - if ux == UX_RECORDING: - return {"ai_state": "listening"} - if ux == UX_TTS: - return {"ai_state": "playing"} - if ux == UX_THINKING: - return {"ai_state": "thinking"} - msg = {"ai_state": "idle"} - if present.get("prefer_off"): - msg["prefer_off"] = 1 - return msg +# -*- coding: utf-8 -*- +"""LED 呈现:由 UX 四态 + 覆盖态推导 ai_state(唯一 set_led_state 入口)。""" +try: + from vc_fsm import VCTurnState +except Exception: + VCTurnState = None +try: + from vc_ux import derive_ux_state, UX_RECORDING, UX_THINKING, UX_TTS +except Exception: + derive_ux_state = None + + +def build_present_state(vc): + """只读聚合,不写 vc。""" + st = { + "mode": int(getattr(vc, "VC_mode", 0)), + "turn": int(getattr(getattr(vc, "fsm", None), "turn", -1)), + "force_idle": 0, + "hold_listening": 0, + "prefer_off": 0, + "stream_active": 0, + "ptt_await_server": 0, + "override_ai": None, + "override_prefer_off": 0, + } + ov = getattr(vc, "_led_override", None) + if ov and isinstance(ov, (tuple, list)) and len(ov) >= 1: + st["override_ai"] = ov[0] + st["override_prefer_off"] = 1 if (len(ov) > 1 and ov[1]) else 0 + if hasattr(vc, "_ptt_should_force_idle_led") and vc._ptt_should_force_idle_led(): + st["force_idle"] = 1 + if hasattr(vc, "_vc_should_hold_listening_led") and vc._vc_should_hold_listening_led(): + st["hold_listening"] = 1 + if hasattr(vc, "_vc_led_should_standby_idle") and vc._vc_led_should_standby_idle(): + st["force_idle"] = 1 + if hasattr(vc, "_vc_led_standby_prefer_off") and vc._vc_led_standby_prefer_off(): + st["prefer_off"] = 1 + if hasattr(vc, "_vc_tts_playback_active") and vc._vc_tts_playback_active(): + st["stream_active"] = 1 + st["ptt_await_server"] = 1 if getattr(vc, "_ptt_await_server", 0) else 0 + return st + + +def present_to_led_msg(vc, present=None): + """返回传给 set_led_state 的 dict;不发布。""" + if present is None: + present = build_present_state(vc) + if present.get("override_ai"): + msg = {"ai_state": present["override_ai"]} + if present.get("override_prefer_off") or present.get("prefer_off"): + msg["prefer_off"] = 1 + return msg + if present.get("force_idle"): + msg = {"ai_state": "idle"} + if present.get("prefer_off"): + msg["prefer_off"] = 1 + return msg + if present.get("hold_listening"): + return {"ai_state": "listening"} + if present.get("ptt_await_server") and int(present.get("mode", 0)) == 1: + return {"ai_state": "thinking"} + if present.get("stream_active"): + return {"ai_state": "playing"} + if derive_ux_state is not None: + ux = derive_ux_state(vc) + if ux == UX_RECORDING: + return {"ai_state": "listening"} + if ux == UX_TTS: + return {"ai_state": "playing"} + if ux == UX_THINKING: + return {"ai_state": "thinking"} + msg = {"ai_state": "idle"} + if present.get("prefer_off"): + msg["prefer_off"] = 1 + return msg diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py index 3d154554..366edad5 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session.py @@ -224,6 +224,28 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): except Exception: pass + def _vc_local_vad_pending_merge_active(self): + """本地 imsl 句末 defer 后、关麦前:LONG_DIALOGUE_ASR_CONTINUE_MS 内可续说。""" + if not self._vc_is_long_dialogue_mode(): + return False + try: + if not getattr(self, "_vc_local_vad_endpoint", None) or not self._vc_local_vad_endpoint(): + return False + if getattr(self, "_turn_has_llm_created", 0) == 1: + return False + if getattr(self, "_vc_ld_merge_frozen", 0) == 1: + return False + if getattr(self, "_vc_pending_asr_completed_stop", 0) != 1: + return False + anchor = getattr(self, "_vc_asr_completed_ms", 0) + if not anchor: + return False + if utime.ticks_diff(utime.ticks_ms(), anchor) >= self._vc_asr_continue_merge_ms(): + return False + return True + except Exception: + return False + def _vc_asr_continue_merge_active(self): """asr.completed 后短窗内仍有 asr.result → 同轮续说 merge。""" if not self._vc_is_long_dialogue_mode(): @@ -250,6 +272,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): return False if getattr(self, "_vc_vad_had_active_after_silence", 0) == 1: return True + if hasattr(self, "_vc_local_vad_pending_merge_active") and self._vc_local_vad_pending_merge_active(): + return True return self._vc_asr_continue_merge_active() def _vc_note_asr_result_activity(self): @@ -277,6 +301,13 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): return if getattr(self, "record_data_save_flag", 0) != 0: return + # 本地/ASR merge 已恢复上行:迟到的 asr.completed 勿再 silence_gate + if ( + getattr(self, "_server_vad_silence", 0) == 0 + and getattr(self, "VC_record_state_flag", 0) >= 2 + ): + print("[VC][VAD] asr.completed skip stop (merge uplink open)") + return if getattr(self, "_vc_vad_had_active_after_silence", 0) == 1: print("[VC][VAD] asr.completed defer stop (vad pause merged)") return @@ -315,6 +346,8 @@ class AI_VC(VCSessionIoMixin, VCSessionMediaMixin, Abstract): return if getattr(self, "_vc_pending_asr_completed_stop", 0) != 1: return + if getattr(self, "_server_vad_silence", 0) == 0: + return if self._vc_asr_continue_merge_active(): return comp = getattr(self, "_vc_asr_completed_ms", 0) diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_imports.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_imports.py index 59b1e7ab..ecc0de1c 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_imports.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_imports.py @@ -1,88 +1,88 @@ -# -*- coding: utf-8 -*- -"""vc_session 子模块共享 import(io / media / core 显式引用,禁止 import * 扩散到业务外)。""" -from common import Abstract -try: - from qp_log import qp_print as print -except Exception: - pass -import EventMesh -import uwebsocket -import usys -import gc -import urandom -import uhashlib -import ubinascii -import ujson -import osTimer -import _thread -from queue import Queue -import utime -import audio -import uos -from machine import Pin -import modem -import sim -import net -import base64 -import request -import ql_fs -from misc import Power -import ntptime -import machine -import dataCall -import constants -import versions -import version_util -try: - import vc_config -except Exception: - vc_config = None -try: - import vc_text_intent -except Exception: - vc_text_intent = None -try: - import VAD -except Exception: - pass -try: - import usr.ai_alarm as _ai_alarm -except Exception: - import ai_alarm as _ai_alarm -from vc_common import ( - dev_type, - VC_HEARTBEAT_LOG, - VC_PROTO_GUARDS, - VC_WS_IO_LOG, - _VC_KEEPALIVE_RX_EVENTS, - _vc_out_json_event_meta, - PRESS_AUDIO_MODE, -) -from vc_proto import ( - vc_proto_build_ws_url, - vc_proto_pack_wire, - vc_proto_normalize_server, - vc_proto_audio_played_enabled, - vc_proto_log_start_from_v25, - vc_proto_log_started_server, - vc_proto_log_synthesis, - vc_proto_log_tx_wire, - is_v3, - vc_ws_custom_ping_enabled, -) -from vc_fsm import ( - VCSessionState, - VCTurnState, - VC_TtsRxPhase, - VCMode, - VCStateMachine, - VC_record_TYPE_PCM, - VC_record_TYPE_AMR, - VC_play_TYPE_PCM, - VC_play_TYPE_MP3, - AI_client_VC_num, - AI_client_asr_num, -) -from vc_ota import OTA -from vc_utils import num_str_to_chinese - +# -*- coding: utf-8 -*- +"""vc_session 子模块共享 import(io / media / core 显式引用,禁止 import * 扩散到业务外)。""" +from common import Abstract +try: + from qp_log import qp_print as print +except Exception: + pass +import EventMesh +import uwebsocket +import usys +import gc +import urandom +import uhashlib +import ubinascii +import ujson +import osTimer +import _thread +from queue import Queue +import utime +import audio +import uos +from machine import Pin +import modem +import sim +import net +import base64 +import request +import ql_fs +from misc import Power +import ntptime +import machine +import dataCall +import constants +import versions +import version_util +try: + import vc_config +except Exception: + vc_config = None +try: + import vc_text_intent +except Exception: + vc_text_intent = None +try: + import VAD +except Exception: + pass +try: + import usr.ai_alarm as _ai_alarm +except Exception: + import ai_alarm as _ai_alarm +from vc_common import ( + dev_type, + VC_HEARTBEAT_LOG, + VC_PROTO_GUARDS, + VC_WS_IO_LOG, + _VC_KEEPALIVE_RX_EVENTS, + _vc_out_json_event_meta, + PRESS_AUDIO_MODE, +) +from vc_proto import ( + vc_proto_build_ws_url, + vc_proto_pack_wire, + vc_proto_normalize_server, + vc_proto_audio_played_enabled, + vc_proto_log_start_from_v25, + vc_proto_log_started_server, + vc_proto_log_synthesis, + vc_proto_log_tx_wire, + is_v3, + vc_ws_custom_ping_enabled, +) +from vc_fsm import ( + VCSessionState, + VCTurnState, + VC_TtsRxPhase, + VCMode, + VCStateMachine, + VC_record_TYPE_PCM, + VC_record_TYPE_AMR, + VC_play_TYPE_PCM, + VC_play_TYPE_MP3, + AI_client_VC_num, + AI_client_asr_num, +) +from vc_ota import OTA +from vc_utils import num_str_to_chinese + diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py index 817161eb..ac66dd1b 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_session_media.py @@ -568,6 +568,20 @@ class VCSessionMediaMixin: self._uplink_mark_end("local.vad.end") self._vc_local_vad_send_audio_completed(defer_stop=False) + def _vc_local_vad_resume_uplink_merge(self, reason="local.pause"): + """句中短停后续说:开 silence_gate + 新 audio.create,同轮 turn 墙钟不重置。""" + if not self._vc_local_vad_endpoint(): + return False + if getattr(self, "VC_record_state_flag", 0) < 2: + return False + self._server_vad_silence = 0 + self._vc_defer_vad_uplink_stop = 0 + self._vc_pending_asr_completed_stop = 0 + self._turn_has_vad_silence = 0 + self._vc_local_vad_send_audio_create() + print("[VAD][local] continue merge -> resume uplink ({})".format(reason)) + return True + def _vc_vad_on_record_pcm(self, record_buf, record_len): """录音线程喂本地 imsl VAD;endpoint 模式驱动断句,debug_only 仅打日志。""" vad_state = self._vc_vad_feed_record_pcm(record_buf, record_len) @@ -576,12 +590,11 @@ class VCSessionMediaMixin: if prev != 1: print("[VAD][local] speech start") self._vc_local_vad_last_state = 1 - if self._vc_local_vad_endpoint() and self._vc_asr_continue_merge_active(): - self._server_vad_silence = 0 - self._vc_defer_vad_uplink_stop = 0 - self._vc_pending_asr_completed_stop = 0 - self._vc_local_vad_send_audio_create() - print("[VAD][local] continue merge -> resume uplink") + if self._vc_local_vad_endpoint(): + if self._vc_asr_continue_merge_active(): + self._vc_local_vad_resume_uplink_merge("asr.completed") + elif hasattr(self, "_vc_local_vad_pending_merge_active") and self._vc_local_vad_pending_merge_active(): + self._vc_local_vad_resume_uplink_merge("local.pause") self.VAD_count = int(getattr(self, "VAD_count", 0)) + 1 if self.VAD_count >= 20 and self._vc_tts_pipeline_busy(): print("[VAD][local] speech hold {} frames (~400ms) interrupt".format( diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ux.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ux.py index 0d0060f5..112d3638 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ux.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/vc_ux.py @@ -1,47 +1,47 @@ -# -*- coding: utf-8 -*- -"""设计稿 UX 四态:idle / recording / thinking / tts(与 FSM 八态解耦)。""" -try: - from vc_fsm import VCTurnState -except Exception: - VCTurnState = None - -UX_IDLE = 0 -UX_RECORDING = 1 -UX_THINKING = 2 -UX_TTS = 3 - -_UX_NAMES = ("idle", "recording", "thinking", "tts") - - -def ux_name(ux): - i = int(ux) - if 0 <= i < len(_UX_NAMES): - return _UX_NAMES[i] - return "idle" - - -def derive_ux_state(vc): - """对齐 录音上传与播放-演示文稿:按键表与 LED 均基于此四态。""" - if hasattr(vc, "_vc_tts_playback_active") and vc._vc_tts_playback_active(): - return UX_TTS - if getattr(vc, "VC_record_state_flag", 0) != 0: - return UX_RECORDING - if int(getattr(vc, "_ptt_await_server", 0)) == 1: - return UX_THINKING - if VCTurnState is not None: - t = getattr(getattr(vc, "fsm", None), "turn", VCTurnState.Idle) - # PTT 轮间:FSM 仍 Playing 但本地已停播 → 设计 idle - if int(getattr(vc, "VC_mode", 0)) == 1 and t in ( - VCTurnState.Playing, - VCTurnState.AwaitPlayedAck, - ): - return UX_IDLE - if t == VCTurnState.Thinking: - return UX_THINKING - if t in ( - VCTurnState.TtsReceiving, - VCTurnState.Playing, - VCTurnState.AwaitPlayedAck, - ): - return UX_TTS - return UX_IDLE +# -*- coding: utf-8 -*- +"""设计稿 UX 四态:idle / recording / thinking / tts(与 FSM 八态解耦)。""" +try: + from vc_fsm import VCTurnState +except Exception: + VCTurnState = None + +UX_IDLE = 0 +UX_RECORDING = 1 +UX_THINKING = 2 +UX_TTS = 3 + +_UX_NAMES = ("idle", "recording", "thinking", "tts") + + +def ux_name(ux): + i = int(ux) + if 0 <= i < len(_UX_NAMES): + return _UX_NAMES[i] + return "idle" + + +def derive_ux_state(vc): + """对齐 录音上传与播放-演示文稿:按键表与 LED 均基于此四态。""" + if hasattr(vc, "_vc_tts_playback_active") and vc._vc_tts_playback_active(): + return UX_TTS + if getattr(vc, "VC_record_state_flag", 0) != 0: + return UX_RECORDING + if int(getattr(vc, "_ptt_await_server", 0)) == 1: + return UX_THINKING + if VCTurnState is not None: + t = getattr(getattr(vc, "fsm", None), "turn", VCTurnState.Idle) + # PTT 轮间:FSM 仍 Playing 但本地已停播 → 设计 idle + if int(getattr(vc, "VC_mode", 0)) == 1 and t in ( + VCTurnState.Playing, + VCTurnState.AwaitPlayedAck, + ): + return UX_IDLE + if t == VCTurnState.Thinking: + return UX_THINKING + if t in ( + VCTurnState.TtsReceiving, + VCTurnState.Playing, + VCTurnState.AwaitPlayedAck, + ): + return UX_TTS + return UX_IDLE diff --git a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/autoconf.h b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/autoconf.h index 16670f11..cb2852d4 100644 --- a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/autoconf.h +++ b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/autoconf.h @@ -46,5 +46,6 @@ //#define CONFIG_JPEG 1 #define CONFIG_CAMERA_SAVEPHOTOS 1 #define CONFIG_VAD 1 +#define CONFIG_OPUS 1 //闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鐐劤缂嶅﹪寮婚悢鍏尖拻閻庨潧澹婂Σ顔剧磼閻愵剙鍔ょ紓宥咃躬瀵鎮㈤崗灏栨嫽闁诲酣娼ф竟濠偽i鍓х<闁绘劦鍓欓崝銈囩磽瀹ュ拑韬€殿喖顭烽幃銏ゅ礂鐏忔牗瀚介梺璇查叄濞佳勭珶婵犲伣锝夘敊閸撗咃紲闂佺粯鍔﹂崜娆撳礉閵堝洨纾界€广儱鎷戦煬顒傗偓娈垮枛椤兘骞冮姀銈呯閻忓繑鐗楃€氫粙姊虹拠鏌ュ弰婵炰匠鍕彾濠电姴浼i敐澶樻晩闁告挆鍜冪床闂備胶绮崝锕傚礈濞嗘挸绀夐柕鍫濇川绾剧晫鈧箍鍎遍幏鎴︾叕椤掑倵鍋撳▓鍨灈妞ゎ厾鍏樺顐﹀箛椤撶偟绐炴繝鐢靛Т鐎氱兘宕ラ崨瀛樷拻濞达絿鎳撻婊呯磼鐠囨彃鈧潡鐛径濞炬闁靛繒濮烽鎺旂磽閸屾瑧鍔嶆い顓炴喘瀹曘垽鏌嗗鍡忔嫼闂傚倸鐗婄粙鎾存櫠閺囥垺鐓欓柛鎰叀閸欏嫭銇勯姀鈩冾棃妞ゃ垺锕㈡慨鈧柨娑樺楠炴劙姊虹拠鑼闁稿绋掗弲鍫曟寠婢规繆娅i埀顒佺⊕鑿уù婊勭矒閺屾洝绠涙繝鍌氣拤缂備讲鍋撻悗锝庡枟閻撴稑霉閿濆洦鍤€濠殿喖绉堕埀顒冾潐濞叉牕鐣烽鍕厺閹肩补鍨鹃悢鐓庣畳鐎广儱妫楅崫鐑樻叏婵犲偆鐓肩€规洘甯掗埢搴ㄥ箳閹存繂鑵愬┑锛勫亼閸娿倝宕㈡總鍛婂亱闊洦绋戠粻鏍ㄣ亜閺囨浜惧銈冨灪濞茬喖寮崘顔肩劦妞ゆ帒鍊婚惌鍡楊熆閼搁潧濮囩紒鐘侯潐缁绘盯鏁愭惔鈥愁潻婵犲痉銈呬汗缂佽鲸甯¢幃鈺呮濞戞瑧浜梻浣告惈閻ジ宕伴弽褜娼栭柤濮愬€愰崑鎾绘濞戞﹩妫屽┑鈥虫▕閸犳氨妲愰幘瀵哥懝闁搞儜鍌滅泿缂傚倷绀侀ˇ顖滅礊婵犲偆鍤曢悹鍥ㄧゴ濡插牓鏌曡箛濠冩珕闁哄懏绻堝娲箰鎼达絿鐣靛┑鐐茬湴閸旀垿骞冮悙顒傞檮闁告稑艌閹风儤绻涢弶鎴濇倯闁荤啙鍥х濞寸厧鐡ㄩ悡娆戠棯閺夊灝鑸瑰ù婊€鍗抽弻娑㈠煛閸愩劋妲愬Δ鐘靛仜椤戝寮崘顔肩劦妞ゆ帒瀚崑鍌炴煥閻斿搫校闁绘挻娲熼弻宥夊煛娴e憡鐏撳┑鐐茬墛閿氶棁澶愭煟濡寧鐝悘蹇ラ檮閹便劍绻濋崘鈹夸虎濠碘槅鍋勯崯顐﹀煡婢跺ň鏋庢俊顖涙た濡捇姊婚崒娆掑厡妞ゎ厼鐗撻、鏍幢濞戞顔夐梺鎼炲劀鐏炲墽绋侀梻浣瑰劤缁绘锝炴径鎰;婵せ鍋撻柡灞界Ч婵$兘濡烽妷銉ь儓濠电姰鍨奸~澶娒洪弽顓炵厴闁硅揪闄勯崐椋庘偓鐟板閸犳牕鈻撻懜鐢电瘈婵炲牆鐏濋弸鐔兼煙閸涘﹤鈻曢柕鍡曠窔瀵粙顢橀悙鑼垛偓鍨攽閻愭潙鐏︽い顓炴喘閺佸秴鈻庨幘绮规嫼濠殿喚鎳撳ú銈夋倶閳哄懏鐓欓悹鍥囧懐鐦堥梺璇″櫙缁绘繃淇婇悜鑺ユ櫆闁告挆鍛潓闂傚倸鍊搁崐鎼佹偋婵犲嫮鐭欓柟鐑橆檪婢舵劕顫呴幒铏濠婂牆绠规繛锝庡墮閻掔儤绻涢崼鐔割棃婵☆偂鐒﹀鍕偓锝庡墰閻﹀牊绻濋悽闈浶㈤柛濠冩倐椤㈡棃顢曢妶鍥╋紲闂佺粯锚绾绢厽鏅舵潏鈺冪<閺夊牄鍔岀粭褏绱掓潏銊ョ瑨閾伙綁鏌涜箛鏇炲付闁搞劑浜堕弻锝嗘償閵堝孩缍堝┑鐐村絻缁绘ê鐣峰┑瀣闁挎棁銆€閸嬫挻鎷呴崜鍙夊缓闂侀€炲苯澧存鐐插暣婵偓闁靛牆鎳庣粣娑欑節閻㈤潧孝闁稿﹦鏁诲畷鎴﹀箻缂佹鍙嗛柣搴岛閺呮繄绮诲鑸碘拺缂備焦锚婵箑霉濠婂嫮鐭掗柛鈹惧亾濡炪倖鍨堕崕鎶藉焵椤掍胶澧辩紒顔碱儏椤撳ジ宕担鍝勫汲闂備礁澹婇崑鍛崲閸曨垰钃熼柛顐犲劜閻撶喖骞栧ǎ顒€鐏柍顖涙礋閹洦寰勫畝鈧壕濂告偣閸パ冪骇妞ゃ儯鍨介弻锛勪沪閸撗勫垱濡炪們鍨哄ú鐔煎极閹版澘骞㈡繛鍡樕戣ⅲ闂備浇顕уù鐑藉箠閹捐绠熼柨娑樺瀹曟煡鏌涢幇闈涙灈濡楀懘姊洪崨濠冨闁搞劋鍗冲畷姗€鍩€椤掑嫭鈷戦梻鍫熶腹濞戙垹宸濇い鏍ㄨ壘缁犲姊婚崒姘偓椋庣矆娓氣偓楠炴顭ㄩ崼婵堬紱濠电偞鍨崹娲磻婢舵劖鐓熼柟鎯у暱閻︺劍绻涢崗鑲╁⒈缂佽鲸鎸婚幏鍛存嚃閳╁啫鐏﹂柛鎺戯躬楠炴﹢顢欓悾灞藉及闂傚鍋勫ú锕€煤濮椻偓瀹曠敻鍩€椤掑倻纾藉ù锝堫嚃濞堬絿绱掔紒妯肩畵妞ゎ偄绻愮叅妞ゅ繐瀚畵宥咁渻閵堝棙瀵欓柛娑卞幖姝囧┑鐘垫暩婵參骞忛崘顔肩<婵犲﹤鎳愰崢顖炴煟鎼淬値娼愭繛鍙壝悾婵嬪箹娴e搫绁﹂梺鍦劋閸わ箓寮埀顒傛崲濠靛绀冮柍鍝勫€昏ぐ銊︾節閻㈤潧校妞ゆ梹鐗犲畷鏉课旈崨顏佸亾閿曞倸鐐婃い鎺嗗亾闁稿被鍔庨幉绋款吋婢跺﹦鍘洪梺鍦亾濡炲潡寮崘顔界叆闁哄啫娉﹂幒妤€绠繛宸簼閳锋垿鏌涘☉姗堝姛闁宠棄顦甸弻銊╁即濡搫濮曢悗鍨緲鐎氭澘鐣烽悢纰辨晬婵炴垶鑹鹃獮鍫ユ⒒娓氣偓濞佳団€﹂鐘典笉闁规璇差槺閳ь剨缍嗛崜娑氬閸忕浜滈柡鍐e亾妞ゆ垶鐟╁畷闈涒枎閹惧鍘撻梺鑺ッˇ钘壩i幖浣圭厓閻犲洦鐓¢妤併亜閹剧偨鍋㈢€规洜鍠栭、姗€鎮╅搹顐g彜闂傚倸鍊搁崐鎼佸磹妞嬪海鐭嗗ù锝夋交閼板潡姊洪鈧粔瀵稿閸ф鐓忛柛顐g箥濡叉悂鏌涢妸銉モ偓鍧楀蓟濞戔懇鈧箓骞嬪┑鍛晼婵$偑鍊愰弲婊堟偂閿熺姴钃熼柨婵嗩槸缁犳稒銇勯弮鍌氬付濠碘剝妞藉铏圭磼濡闉嶅┑鐐跺皺閸犳牕顕f繝姘櫜濠㈣泛锕ラˉ婵嗏攽閻愬弶顥犻柛瀣崌閹潡宕堕浣叉嫼缂備礁顑呴悘婵嬵敆閵忊剝鍙忓┑鐘插€荤粔鐑橆殽閻愯尙澧﹀┑鈩冩倐閺佸倿宕滆濡插洭姊绘担鍛婂暈婵炶绠撳畷銏ゆ嚃閳哄啰鐣堕梺璺ㄥ枔婵敻鍩涢幋锔界厽闁绘柨鎲$欢鍙変繆閹绘帩鐓奸柡宀€鍠栭幖褰掝敃閵忕媭娼曢梻浣告啞鐢鏁幒妤€鐓濋幖娣妼缁犺崵鈧娲栧ù鍌炲船閸洘鈷戠痪顓炴噹娴滃綊鎮跺☉鏍у姎妞ゎ剙锕ㄩˇ鍦偓瑙勬礃閸ㄥ潡鐛Ο濂借櫣绱掑Ο缁樼彨闂傚倷鑳剁划顖炲礉濡ゅ啯鍋橀柕澶嗘櫅缁狀垱绻涘顔荤凹闁绘挾鍠栭弻锝呂熼崫鍕獓缂備讲鍋撶€光偓閸曨剛鍘撻悷婊勭矒瀹曟粌鈹戦崱蹇旂€洪梺鍝勬储閸ㄦ椽宕愰崼鏇熺厱妞ゆ劗濮撮崝婊堟煃闁垮鐏╃紒杈ㄥ笧閳ь剨缍嗘禍婊堟儍閿熺姵鐓涢柍褜鍓氱换婵嗩潩椤撶姴骞嶆俊鐐€栧濠氬储瑜旈崺鈧い鎺嗗亾婵炲皷鈧磭鏆﹂悷娆忓閸嬪懘鏌涢幇銊︽珕婵炲懎娲铏圭矙閹稿孩鎷卞┑顔角滈崝鎴濈暦閹扮増鍊风€瑰壊鍠楃€靛矂姊洪棃娑氬闁硅櫕鍔楃划濠氬箥椤斿墽锛滄繝銏f硾閺堫剟寮抽鍕厱闁崇懓鐏濋悘鈺呮煟閿濆棛绠炵€规洜鍠栭、妤呭磼濮橆剛顔戦梻鍌欒兌閹虫捇宕ョ€n喗鍋╂い蹇撶墕閺勩儵鏌涢弴銊ョ仩闁汇値鍣i悡顐﹀炊閵娧€濮囬梺缁樻尰濞茬喖寮婚敐鍛傜喓鎷犻幓鎺濇浇婵犵數鍋涢悧濠勫垝瀹ュ鈧啴濡烽埡鍌氣偓鐑芥煙缂佹ê绗氭繛鍫濐煼閹鎲撮崟顒傤槰闁汇埄鍨辩敮锟犳晲閻愭祴鏀介柛銉e妿缁夊爼姊洪棃娑辩叚閻庨潧鐭傚畷顖涙償閵婏腹鎷婚梺绋挎湰閻熝囁囬敂鐣岀瘈闁逞屽墴閺屽棗顓奸崨顖ょ吹闂備線娼ч悧鍡浰囬銏犵劦妞ゆ巻鍋撻柛鐔告綑閻g兘宕¢悙鈺傤潔濠碘槅鍨抽妴瀣椤斿皷鏀介柨娑樺娴犳粍銇勯幋婵囧櫣闂囧顪冪€n亪顎楁い銉﹀哺閺屾稖绠涢弴銊ュ妴婵炲瓨绮嶇划鎾诲蓟閿熺姴绀冮柨婵嗘噸婢规洘淇婇悙顏勨偓鏍垂閸洘鍋¢柕澶嗘杹閳ь剨绠撳畷鍫曨敆閳ь剛绮诲☉銏$厽婵°倐鍋撻柣妤€妫濋崺鈧い鎺嗗亾闁诲繑宀搁獮鍫ュΩ閵夊海鍠栧畷顐﹀礋椤掍胶妲繝鐢靛仜閻°劎鍒掔仦鏂よ€块弶鍫氭櫆椤洟鏌熼悜妯诲鞍缂傚秴娲弻鏇熺節韫囨洜鏆犵紒鍓у亾婵炲﹪骞冨Δ鍐╁枂闁告洦鍓涢ˇ銊╂煟閵忊晛鐏¢悽顖ょ節瀹曟椽濮€閳╁啫鍔呴梺闈涱焾閸庢娊顢樺ú顏呪拺闁圭娴风粻鎾寸箾鐏炲倸濡奸柣锝囧厴瀹曞ジ寮撮悢鍙夊闂備胶顭堥張顒勬偡瑜斿畷婵嗩吋婢跺鍘靛銈嗘閸嬫劙宕洪敐鍥e亾鐟欏嫭绀冪紒璇插缁傛帡鏁冮崒娑樹患闁诲繒鍋熼崑鎾活敊閺囩喍绻嗛柣鎰典簻閳ь剚鐗滈弫顕€骞掑Δ鈧壕鍦磼鐎n偒鍎ラ柛銈嗘礋閺岋紕浠︾拠鎻掑闂佹娊鏀辩敮鎺楁箒闂佹寧绻傞幊蹇涘疮閻愮儤鐓欐い鏍ㄦ皑婢с垻绱掓潏銊ョ瑲鐎垫澘瀚埀顒婄秵閸撴瑥顕i妸鈺傚€甸悷娆忓缁€鍐磼鐠囨彃鈧潡銆佸Ο鑽ら檮缂佸鐏濈粣娑橆渻閵堝懐绠伴柟铏姍閸┾偓妞ゆ帊鐒﹂妵婵囨叏婵犲懏顏犵紒杈ㄥ笒椤粓宕卞▎蹇撔ㄧ紓鍌氬€风欢锟犲闯椤曗偓瀹曞綊宕奸弴鐐电暫闂佺偨鍎查弸濂稿几鎼淬劍鐓欓悗鐢殿焾鍟搁梺鎸庣⊕缁诲啰鎹㈠☉娆愮秶闁告挆鍐ㄧ厒婵$偑鍊ら崑鍛存偋閻樻眹鈧線寮崼婵嗚€垮┑鐐叉缁绘劗鎲撮敃鈧埞鎴炲箠闁稿ě鍛筏濞寸姴顑呴悿顔姐亜閺嶎偄浠﹂柛瀣€块弻娑㈠箛閸忓摜鍑归梺鍝ュУ閸旀牜鎹㈠┑鍥╃瘈闁稿本绮岄。铏圭磽娴f彃浜鹃梺鍓插亞閸犳劙宕h箛鏂剧箚妞ゆ牗纰嶉崑銉╂煕濠靛洦銇濋柡宀嬬節瀹曞崬螣閼测晝鍘滈梻浣告惈閻ジ宕伴弽顓炵畺婵犲﹤鍠氬銊╂煕閳╁喛渚涢柛姘噽缁辨捇宕掑顑藉亾閸濄儳鐭撻柣銏犳啞閸嬪淇婇妶鍛殲鐎规洖寮剁换婵嬫濞戝崬鍓卞銈冨劚閻楀﹦鎹㈠☉銏犵婵犻潧妫滈崺鐐烘⒑閸涘﹥宕岀紒鐘崇墪椤繘鎮滃Ο璇差潯闂佽顔栭崳顔嘉i灏栨斀闁绘劘灏欏﹢鎾煕閺冣偓閸ㄥ潡鎮伴钘夌窞闁归偊鍓欑粣娑欑節閻㈤潧孝闁哥噥鍋婂畷婵嬪川鐎涙ǚ鎷洪梻鍌氱墛娓氭鎮¢鐘电<闁绘ê鍟块悘锔剧磼閸屾稑娴柟顔界懇椤㈡宕掑搴℃櫗闂傚倷绀佸﹢閬嶅磻閹炬剚鐒芥繛鍡樻尰閸婅法鎲搁悧鍫濈瑲闁绘挻娲熼幃妤呮晲鎼粹€茬凹閻庤娲栭惌鍌炲蓟閳ュ磭鏆嗛柍褜鍓熷畷浼村冀椤撴壕鍋撴担绯曟瀻闁瑰濞€閳瑰繘鏌f惔顖滅У闁稿妫濆鎶藉Ψ閳哄倵鎷绘繛杈剧到閹芥粓鏁嶅鍥╃<妞ゆ洖鎳庨悘锔筋殽閻愭潙鐏寸€规洘鍎奸ˇ鎾煛閸☆厼顩柟鍙夋倐閹囧醇濠靛懎鍨旈梻浣芥〃缁€渚€鏁冮鍫濊摕闁挎繂顦伴弲鏌ユ煕濞戝崬寮炬繛鍫弮濮婅櫣娑甸崨顓犳闂佺顑嗛幐楣冨箲閵忕姭鏀介悗锝庡亜娴犳椽姊婚崒姘卞闁告巻鍋撻梺闈涱槴閺呮粓鎮″☉妯忓綊鏁愰崼顐g秷闂佺锕ラ崝妤呭焵椤掑喚娼愭繛鍙夛耿瀹曞綊鎮界粙璺ㄥ弨婵犮垼鍩栭崝鏇綖閸涘瓨鐓冮柍杞扮閺嗙偤鏌e┑鍥╁⒌婵﹦绮粭鐔煎焵椤掆偓椤洩顦圭弧鎾绘煃瑜滈崜娆撳煘閹达箑鐏抽柧蹇e亜閺嬬娀姊虹化鏇熸珖闁稿鐩、妯荤附缁嬪灝绐涘銈呯箰閹冲繘寮堕幖浣光拻濞达綀娅g敮娑㈡煥濮樻墎鍋撳▓鍨灕闁糕晜鐗曢銉╁礋椤栨氨顦板銈嗙墬缁嬫捇宕㈡潏銊х瘈闁汇垽娼у瓭闂佺顑呭Λ婵嬪箖閳╁啰闄勯柛娑橈功閸樻悂鎮楅崗澶婁壕闁诲函缍嗛崜娑㈠汲閻樼粯鐓eù鍏肩懅閸掍即鏌曢崱妯虹瑨妞ゎ偅绻堥幃鈩冩償閿濆嫮鏁炬繝寰锋澘鈧牕螞閸愵煈娼栫紓浣股戞刊鎾煕濞戞﹫宸ラ柡鍡楃墦閺岋箓宕橀缁樺枤闂佸搫鐬奸崰鏍€佸▎鎾村亗閹煎瓨锚娴滈箖鏌熼梻瀵哥瓘缂傚秵鐗犻悡顐﹀炊閵娧€濮囬梺璇″灣閸嬨倝寮诲☉銏℃櫆閻犲洦褰冪粻濠氭⒑缂佹ɑ灏伴柟鐟版搐椤繐煤椤忓嫭宓嶅銈嗘寙閸涱厼歇闂備浇顕х€涒晝绮欓崼銉ョ柧闁绘宕靛畵渚€鐓崶銊р槈缁绢厸鍋撻梻浣虹帛閸ㄩ潧螞濞嗘垟鍋撻棃娑氱劯婵﹥妞藉Λ鍐ㄢ槈濮橆剦鏆梻浣告憸閸c儵宕戦崨顔锯攳濠电姴娲ょ粈鍌炴⒒閸屾凹鍤熺紒鐘宠壘椤啴濡堕崱妤€衼缂備焦褰冮悘婵堝弲闂佸湱铏庨崰妤呮偂閺囥垺鐓冮悷娆忓閸斻倕霉濠婂懎浜惧ǎ鍥э躬閹瑩顢旈崟銊ヤ壕闁哄稁鍋呴弳婊冣攽閻樿弓绱栫憸鐗堝笒閻愬﹪鏌曟繛褍鎳庢鍕節濞堝灝鏋熼柕鍥ㄧ洴瀹曟垿骞樼紒妯煎幐闁诲繒鍋涙晶浠嬪煡婢跺浜滄い鎰剁悼缁犵偞銇勯姀鈽嗘畷鐎垫澘瀚换婵嬪磼濮樺吋顥忕紓鍌氬€搁崐鎼佸磹妞嬪海鐭嗗〒姘e亾闁诡垰鏈幏鍛寸嵁婢跺摜鐭掗梻浣告啞缁哄潡宕曢幓鎺旀殾闁告瑥顦辩弧鈧梻鍌氱墛娓氭宕曡箛娑欑厽闁归偊鍓ㄩ煬顒勬煛鐏炵偓绀冪紒缁樼洴瀹曞綊顢欓悡搴綍闂傚倷鑳堕…鍫ヮ敄閸℃稑绠查柛銉墮閽冪喖鏌曟繛褉鍋撻柛瀣崌閺佹劙宕橀妸銉€辩紓鍌欓檷閸斿矂鈥﹀畡鎷旀盯宕ㄩ幖顓熸櫇闂侀潧绻嗛埀顒佸墯濡查亶姊绘担鐑樺殌闁硅绻濋獮鍐磼閻愵亖鍋撴笟鈧顕€宕煎顎板喚鐔嗛悹杞拌閸庢垿鏌涘鈧禍鍫曞蓟閿濆棙鍎熸い鏍ㄧ矌鏍¢梻浣侯焾椤戝懘骞婃惔銊﹀仼鐎瑰嫭澹嗛弳鍡涙煃瑜滈崜鐔煎春閳ь剚銇勯幒宥囪窗闁哥喎绻橀弻娑㈡偐閾忣偆顦梺鍛婂笚鐢帡鍩㈡惔銊ョ闁瑰吀绀佹禍鎯归敐鍛棌婵炵鍔戦弻宥堫檨闁告挾鍠栭悰顕€宕橀妸銏$€婚棅顐㈡搐閿曘儵鎮樻笟鈧娲捶椤撗呭姼閻庡湱纭堕弲鐘充繆閻戣棄鐓涢柛灞绢殕鐎氬ジ姊绘担鍝勫付妞ゎ偅娲熷畷鎰板即閵忕姴鍤戦梺鐟邦嚟婵澹曢崗绗轰簻闁哄啫娲ゆ禍褰掓煟韫囨稐鎲鹃柡宀€鍠栭悰顕€宕归鍙ョ礄婵°倗濮烽崑娑樏洪銏犺摕闁搞儺鍓氶弲婊堟煠閹帒鍔滈柣婵勫姂濮婂宕掑▎鎴犵崲濠电偘鍖犻崵韬插姂閸┾偓妞ゆ巻鍋撻柍瑙勫灴閸ㄩ箖鎼归銏㈢崺闁诲孩顔栭崯顐﹀炊瑜忛崝锕€顪冮妶鍡楃瑨閻庢凹鍙冮崺娑㈠箣閿旂晫鍘甸梺鍏肩ゴ閺呮稒绂掑鍫熺厱闁哄倸鎼禍楣冩⒒閸屾瑧顦﹂柟璇х磿閸掓帡宕奸妷锕€鈧潡鏌ㄩ弴姘愁唹闁告瑩绠栧濠氬磼濮橆兘鍋撻幖浣哥9闁归棿绀佺壕鐟邦渻鐎n亝鎹i柣顓炴閵嗘帒顫濋敐鍛闁诲氦顫夊ú蹇涘磿閹惰棄鐒垫い鎺戯功缁夌敻鏌涢幘瀵告创闁诡垰鐭傚畷濂稿Ψ閿旀儳骞嶇紓鍌氬€烽梽宥夊垂瑜版帒鍑犳繛鎴欏灪閻撶喖鏌曢崼婵愭Ш闁伙絾妞介弻锛勪沪閻e睗锝嗙箾绾板彉閭柟顔ㄥ洤閱囨慨姗嗗厸婢规洟姊洪棃娑辨Ф闁稿骸绉寸叅妞ゅ繐绉甸弲婊堟⒑閸涘﹥澶勯柛娆忛叄瀹曨垶宕惰閺€浠嬫煟閹邦垰鐓愮憸鎶婂懐纾奸棅顐幘閻瑧鈧娲忛崹褰掆€﹂妸鈺侀唶婵犻潧鐗滈崬鍨節閻㈤潧浠滄俊顖氾攻缁傚秴鈹戠€n亞鍘遍梺鍦劋椤ㄥ棝鎮¢弴銏″€堕柣鎰版涧娴滈箖鏌i妸锕€鐏ユい顓″劵椤﹀磭绱掔€n偅灏垫俊鍙夊姍楠炴帡寮崫鍕闂佹寧绻傛鍛婄濠靛鍊堕煫鍥ㄦ礃閺嗏晝绱掓潏銊ユ诞妞ゃ垺鐟ч崰濠冩綇閳轰焦鍊梻鍌欐祰椤曟牠宕板Δ鍛仭闁冲搫鎳庣粻鏍ㄧ節婵犲倸鎮╅柣鏂垮悑閸嬪倿骞栨潏鍓х?闁汇倕瀚埞鎴︽偐閸偅姣勬繝娈垮枤閸忔ê顕i锕€宸濆┑鐘插暙瀵潡姊洪崷顓℃闁哥姵鐗犻幃鍧楊敋閳ь剟寮婚敐鍛傛棃鍩€椤掑嫭鍋嬪┑鐘插€甸弸宥夋煟濡偐甯涢柣鎾跺枛閺屾洝绠涢弴鐐愶綁鏌涢悢鍝勪槐闁? //#define CONFIG_juphoon 1 diff --git a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/config.mk b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/config.mk index fa64f50d..df238f15 100644 --- a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/config.mk +++ b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/config.mk @@ -64,4 +64,6 @@ CONFIG_VIOCE_CALL=y #CONFIG_SC7A20=y CONFIG_VAD=y # CONFIG_QP_LOG is not set +# Opus 编解码(需先运行 tools\build_opus_min.bat 生成 libopus_min.a) +CONFIG_OPUS=y #CONFIG_juphoon=y diff --git a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/README.md b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/README.md new file mode 100644 index 00000000..c2605df1 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/README.md @@ -0,0 +1,11 @@ +此目录用于“解开管理” `firmware_base_release_pack.zip` 内的配置文件(源文件)。 + +约定: +- 源文件:`firmware_base_release_pack/**`(本目录) +- 打包输入:`firmware_base_release_pack.zip` +- 修改分区/模板等配置时,只改本目录内对应文件 +- 编译/打包前执行 `tools/sync_base_pack_config.bat`,将本目录内容增量更新到 zip +- `new_clean.bat` 与 `new.bat`(xcopy 前)都会自动 sync;脚本会删除 zip 内旧路径条目并做 sha256 校验,避免 7z 产生重复 config 条目 + +注意: +- zip 在编译过程中会被 `new.bat` 更新写入(加入 images/*.bin),因此 zip 仅作为打包输入/发布载体,不作为配置源文件维护。 diff --git a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/config/partition/CRANEL_SINGLE_QUEC_FLASH_LAYOUT_8M_GNSS_OPEN_VOLTE.json b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/config/partition/CRANEL_SINGLE_QUEC_FLASH_LAYOUT_8M_GNSS_OPEN_VOLTE.json new file mode 100644 index 00000000..0342a450 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/config/partition/CRANEL_SINGLE_QUEC_FLASH_LAYOUT_8M_GNSS_OPEN_VOLTE.json @@ -0,0 +1,137 @@ +{ + "name" : "CRANEL_SINGLE_QUEC_FLASH_LAYOUT_8M_GNSS_OPEN_VOLTE", + "partitions" : [ + { + "format" : "flash", + "name" : "qspi", + "partitions" : [ + { + "format" : "ubi", + "name" : "bootloader", + "size" : "88KiB" + }, + { + "format" : "part", + "name" : "system", + "partitions" : [ + { + "format" : "raw", + "name" : "ptable", + "size" : "4KiB" + }, + { + "format" : "raw", + "name" : "fwcerts", + "size" : "12KiB" + }, + { + "format" : "raw", + "name" : "rd", + "size" : "32KiB" + }, + { + "format" : "raw", + "name" : "cp", + "size" : "0" + }, + { + "format" : "raw", + "name" : "dsp", + "size" : "0" + }, + { + "format" : "raw", + "name" : "rfbin", + "size" : "0" + }, + { + "disable" : false, + "format" : "raw", + "name" : "logo", + "size" : "0" + }, + { + "format" : "raw", + "name" : "gnss_boot", + "size" : "0" + }, + { + "format" : "raw", + "name" : "gnss_firm", + "size" : "0" + } + ], + "size" : "0" + }, + { + "format" : "raw", + "name" : "pad", + "size" : "12KiB" + }, + { + "format" : "raw", + "name" : "customer_app", + "size" : "1500KiB" + }, + { + "format" : "raw", + "name" : "customer_fs", + "size" : "984KiB" + }, + { + "format" : "raw", + "name" : "customer_backup_fs", + "size" : "16KiB" + }, + { + "format" : "raw", + "name" : "nvm", + "size" : "196KiB" + }, + { + "format" : "raw", + "name" : "secdat", + "size" : "24KiB" + }, + { + "format" : "raw", + "name" : "erase_rd", + "size" : "4KiB" + }, + { + "format" : "raw", + "name" : "updater", + "size" : "96KiB" + }, + { + "format" : "raw", + "name" : "fota_param", + "size" : "12KiB" + }, + { + "format" : "raw", + "name" : "quec_cfg", + "size" : "32KiB" + }, + { + "format" : "part", + "name" : "factory", + "partitions" : [ + { + "format" : "raw", + "name" : "factory_a", + "size" : "32KiB" + }, + { + "format" : "raw", + "name" : "factory_b", + "size" : "32KiB" + } + ], + "size" : "0" + } + ], + "vstart" : "0x80000000" + } + ] +} diff --git a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/include/app_link_start_addr.h b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/include/app_link_start_addr.h index 80c7a39b..5567586e 100644 --- a/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/include/app_link_start_addr.h +++ b/2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/include/app_link_start_addr.h @@ -1,11 +1,15 @@ - -#ifndef __APP_LINK_START_ADDR_H__ -#define __APP_LINK_START_ADDR_H__ - -#define APP_LINK_START_ADDR 0x80521000 -#define APP_FLASH_MAX_SIZE 0x120000 - -#define APP_RAM_START 0x7E3E0000 -#define APP_RAM_MAX_SIZE 0x180000 - -#endif + +#ifndef __APP_LINK_START_ADDR_H__ +#define __APP_LINK_START_ADDR_H__ + +#define APP_LINK_START_ADDR 0x80521000 +/* 对齐 K8:为 Opus(~250KB) 等扩展预留 APP 区;物理分区需与基线一致 */ +#define APP_FLASH_MAX_SIZE 0x180000 +// 1.5M 大小 0x180000 +// 1.2M 大小 0x120000 +// 1.8M 大小 0x1F8000 + +#define APP_RAM_START 0x7E3E0000 +#define APP_RAM_MAX_SIZE 0x180000 + +#endif diff --git a/2.sdk/project/7PIN_1_5/tools/build_opus_min.bat b/2.sdk/project/7PIN_1_5/tools/build_opus_min.bat new file mode 100644 index 00000000..46f52364 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/tools/build_opus_min.bat @@ -0,0 +1,38 @@ +@echo off +setlocal +REM 将 opus-1.4 源码目录放到 tools\opus_src(仅构建 .a 时用,固件不引用该路径) +set "OPUS_SRC=%~dp0opus_src" +set "OUT_A=%~dp0..\sdk\services\microPython\ports\quectel\core\source\libopus_min.a" +set "BUILD_DIR=%OPUS_SRC%\build-arm-eg810" +set "GCC_ROOT=D:\helios\gcc-arm-none-eabi-10.2.1" +set "CC=D:/helios/gcc-arm-none-eabi-10.2.1/bin/arm-none-eabi-gcc.exe" +set "AR=D:/helios/gcc-arm-none-eabi-10.2.1/bin/arm-none-eabi-ar.exe" +set "SIZE=D:/helios/gcc-arm-none-eabi-10.2.1/bin/arm-none-eabi-size.exe" + +if not exist "%CC%" ( + echo [ERR] missing %CC% + exit /b 1 +) +if not exist "%OPUS_SRC%\CMakeLists.txt" ( + echo [ERR] missing %OPUS_SRC% + exit /b 1 +) + +if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%" +cd /d "%BUILD_DIR%" + +cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Generic -DCMAKE_SYSTEM_PROCESSOR=arm -DCMAKE_C_COMPILER="%CC%" -DCMAKE_AR="%AR%" -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_C_FLAGS="-mthumb -mcpu=cortex-r5 -Os -ffunction-sections -fdata-sections" -DOPUS_FIXED_POINT=ON -DOPUS_ENABLE_FLOAT_API=OFF -DOPUS_CUSTOM_MODES=OFF -DOPUS_BUILD_PROGRAMS=OFF -DOPUS_BUILD_TESTING=OFF -DOPUS_BUILD_SHARED_LIBRARY=OFF -DOPUS_ASSERTIONS=OFF -DOPUS_HARDENING=OFF -DOPUS_FORTIFY_SOURCE=OFF -DOPUS_STACK_PROTECTOR=OFF -DOPUS_DISABLE_INTRINSICS=OFF -DOPUS_INSTALL_PKG_CONFIG_MODULE=OFF -DOPUS_INSTALL_CMAKE_CONFIG_MODULE=OFF "%OPUS_SRC%" +if errorlevel 1 exit /b 1 + +cmake --build . --target opus -j +if errorlevel 1 exit /b 1 + +if not exist "libopus.a" ( + echo [ERR] libopus.a not built + exit /b 1 +) + +copy /y "libopus.a" "%OUT_A%" +echo [OK] %OUT_A% +"%SIZE%" -t x -B "%OUT_A%" +exit /b 0 diff --git a/2.sdk/project/7PIN_1_5/tools/build_opus_min.ps1 b/2.sdk/project/7PIN_1_5/tools/build_opus_min.ps1 new file mode 100644 index 00000000..f32e323d --- /dev/null +++ b/2.sdk/project/7PIN_1_5/tools/build_opus_min.ps1 @@ -0,0 +1,54 @@ +# Cross-build opus-1.4 -> libopus_min.a (ARM thumb, fixed-point, MinSizeRel) +$ErrorActionPreference = "Stop" +$OpusSrc = Join-Path $PSScriptRoot "opus_src" +if (-not (Test-Path (Join-Path $OpusSrc "CMakeLists.txt"))) { + throw "Put opus-1.4 sources under: $OpusSrc" +} +$OpusSrc = (Resolve-Path $OpusSrc).Path +$OutA = Join-Path $PSScriptRoot "..\sdk\services\microPython\ports\quectel\core\source\libopus_min.a" +$BuildDir = Join-Path $OpusSrc "build-arm-eg810" +$GccRoot = "D:\helios\gcc-arm-none-eabi-10.2.1" +$Cc = Join-Path $GccRoot "bin\arm-none-eabi-gcc.exe" +$Ar = Join-Path $GccRoot "bin\arm-none-eabi-ar.exe" +$Size = Join-Path $GccRoot "bin\arm-none-eabi-size.exe" + +if (-not (Test-Path $Cc)) { throw "ARM GCC not found: $Cc" } +if (-not (Test-Path (Join-Path $OpusSrc "CMakeLists.txt"))) { throw "opus source missing: $OpusSrc" } + +New-Item -ItemType Directory -Force -Path $BuildDir | Out-Null +Push-Location $BuildDir +try { + $cmakeArgs = @( + "-G", "Unix Makefiles", + "-DCMAKE_SYSTEM_NAME=Generic", + "-DCMAKE_SYSTEM_PROCESSOR=arm", + "-DCMAKE_C_COMPILER=$Cc", + "-DCMAKE_AR=$Ar", + "-DCMAKE_BUILD_TYPE=MinSizeRel", + '-DCMAKE_C_FLAGS=-mthumb -mcpu=cortex-r5 -Os -ffunction-sections -fdata-sections', + "-DOPUS_FIXED_POINT=ON", + "-DOPUS_ENABLE_FLOAT_API=OFF", + "-DOPUS_CUSTOM_MODES=OFF", + "-DOPUS_BUILD_PROGRAMS=OFF", + "-DOPUS_BUILD_TESTING=OFF", + "-DOPUS_BUILD_SHARED_LIBRARY=OFF", + "-DOPUS_ASSERTIONS=OFF", + "-DOPUS_HARDENING=OFF", + "-DOPUS_FORTIFY_SOURCE=OFF", + "-DOPUS_STACK_PROTECTOR=OFF", + "-DOPUS_DISABLE_INTRINSICS=OFF", + "-DOPUS_INSTALL_PKG_CONFIG_MODULE=OFF", + "-DOPUS_INSTALL_CMAKE_CONFIG_MODULE=OFF", + $OpusSrc + ) + & cmake @cmakeArgs + & cmake --build . --target opus -j + $lib = Join-Path $BuildDir "libopus.a" + if (-not (Test-Path $lib)) { throw "libopus.a not found" } + Copy-Item -Force $lib $OutA + Write-Host "[OK] $OutA" + & $Size -t x -B $OutA +} +finally { + Pop-Location +} diff --git a/2.sdk/project/7PIN_1_5/tools/ensure_helios_opus_mk.ps1 b/2.sdk/project/7PIN_1_5/tools/ensure_helios_opus_mk.ps1 new file mode 100644 index 00000000..ff174eda --- /dev/null +++ b/2.sdk/project/7PIN_1_5/tools/ensure_helios_opus_mk.ps1 @@ -0,0 +1,21 @@ +# xcopy 后确保 Helios microPython.mk 能 -include microPython_opus.mk(仅补一行锚点,可重复执行) +param([string]$HeliosRoot) +$ErrorActionPreference = 'Stop' +if (-not $HeliosRoot) { $HeliosRoot = Join-Path $PSScriptRoot '..\..\Helios_SDK' } +$mk = Join-Path $HeliosRoot 'services\microPython\microPython.mk' +if (-not (Test-Path -LiteralPath $mk)) { Write-Error "missing $mk"; exit 2 } +$enc = New-Object System.Text.UTF8Encoding @($false) +$lines = [System.IO.File]::ReadAllLines($mk, $enc) +if (($lines -join "`n") -match 'services/microPython/microPython_opus\.mk') { Write-Host 'ensure_helios_opus_mk: OK (already)'; exit 0 } +$out = New-Object System.Collections.Generic.List[string] +$done = $false +foreach ($line in $lines) { + [void]$out.Add($line) + if (-not $done -and $line -match 'libimslvad\.a\s*$') { + [void]$out.Add('-include services/microPython/microPython_opus.mk') + $done = $true + } +} +if (-not $done) { Write-Error 'anchor libimslvad.a not found'; exit 3 } +[System.IO.File]::WriteAllLines($mk, $out.ToArray(), $enc) +Write-Host 'ensure_helios_opus_mk: inserted -include microPython_opus.mk' diff --git a/2.sdk/project/7PIN_1_5/tools/sync_base_pack_config.bat b/2.sdk/project/7PIN_1_5/tools/sync_base_pack_config.bat new file mode 100644 index 00000000..f94a5f00 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/tools/sync_base_pack_config.bat @@ -0,0 +1,18 @@ +@echo off +setlocal EnableDelayedExpansion + +rem 2.sdk 根目录(tools 的上两级) +cd /d "%~dp0..\..\" +set "ROOT=%CD%" + +set "PROJECT=7PIN_1_5" +set "BOARD=EG810MCN_GA_VOLTE" + +powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\project\%PROJECT%\tools\sync_base_pack_config.ps1" -Root:"%ROOT%" -Project:"%PROJECT%" -Board:"%BOARD%" +if errorlevel 1 ( + echo [ERROR] sync_base_pack_config failed + exit /b 1 +) + +exit /b 0 + diff --git a/2.sdk/project/7PIN_1_5/tools/sync_base_pack_config.ps1 b/2.sdk/project/7PIN_1_5/tools/sync_base_pack_config.ps1 new file mode 100644 index 00000000..ff994cc6 --- /dev/null +++ b/2.sdk/project/7PIN_1_5/tools/sync_base_pack_config.ps1 @@ -0,0 +1,107 @@ +param( + [string]$Root, + [string]$Project = "7PIN_1_5", + [string]$Board = "EG810MCN_GA_VOLTE" +) + +$ErrorActionPreference = "Stop" + +if ([string]::IsNullOrWhiteSpace($Root)) { + $Root = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path +} +$Root = (Resolve-Path $Root).Path + +$zip = Join-Path $Root ("project\" + $Project + "\sdk\system\platform\ASR_1606\boards\" + $Board + "\images\firmware_base_release_pack.zip") +$src = Join-Path $Root ("project\" + $Project + "\sdk\system\platform\ASR_1606\boards\" + $Board + "\images\firmware_base_release_pack") +$sevenZip = Join-Path $Root "Helios_SDK\tools\common\win32\7z\7z.exe" + +if (-not (Test-Path $src)) { throw ("base pack src dir not found: " + $src) } +if (-not (Test-Path $zip)) { throw ("base pack zip not found: " + $zip) } +if (-not (Test-Path $sevenZip)) { throw ("7z.exe not found: " + $sevenZip) } + +$includeGlobs = @( + "config\partition\*.json", + "config\template\*.json", + "release_info\*.txt" +) + +function Remove-ZipByLeaf([string]$Archive, [string]$LeafName) { + # 旧 7z 在无匹配时会返回非 0,这里不作为失败 + & $sevenZip d -y $Archive ("*" + $LeafName) | Out-Null + $global:LASTEXITCODE = 0 +} + +function Verify-ZipEntry([string]$Archive, [string]$ArcPathWin, [string]$ArcPathUnix, [string]$LocalFile) { + $leaf = [System.IO.Path]::GetFileName($LocalFile) + $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("base_pack_sync_" + [guid]::NewGuid().ToString("N")) + New-Item -ItemType Directory -Force -Path $tmp | Out-Null + try { + $candidates = @($ArcPathWin, $ArcPathUnix, ("*" + $leaf)) | Select-Object -Unique + $ok = $false + foreach ($c in $candidates) { + & $sevenZip e -y ("-o" + $tmp) $Archive $c | Out-Null + if ($LASTEXITCODE -eq 0) { + $filesNow = @(Get-ChildItem -LiteralPath $tmp -File -Recurse -ErrorAction SilentlyContinue) + if ($filesNow.Count -gt 0) { + $ok = $true + break + } + } + } + if (-not $ok) { + throw ("verify extract failed: " + $leaf + " by paths [" + ($candidates -join ", ") + "]") + } + + $picked = Join-Path $tmp $leaf + if (-not (Test-Path $picked)) { + $files = @(Get-ChildItem -LiteralPath $tmp -File -Recurse -ErrorAction SilentlyContinue) + if ($files.Count -eq 1) { + $picked = $files[0].FullName + } else { + $names = ($files | ForEach-Object { $_.FullName }) -join "; " + throw ("verify extract missing: " + $leaf + " under " + $tmp + " got [" + $names + "]") + } + } + + $srcHash = (Get-FileHash -Algorithm SHA256 -Path $LocalFile).Hash + $zipHash = (Get-FileHash -Algorithm SHA256 -Path $picked).Hash + if ($srcHash -ne $zipHash) { + throw ("zip entry mismatch: " + $leaf + " (src=" + $srcHash + " zip=" + $zipHash + ")") + } + } finally { + Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue + } +} + +$updated = 0 +Push-Location $src +try { + foreach ($g in $includeGlobs) { + $matches = @(Get-ChildItem -Path $g -File -ErrorAction SilentlyContinue) + foreach ($m in $matches) { + $relWin = $m.FullName.Substring($src.Length).TrimStart("\") + $local = Join-Path $src $relWin + $leaf = $m.Name + + Remove-ZipByLeaf $zip $leaf + + $addOut = & $sevenZip a -y $zip $relWin 2>&1 + if ($LASTEXITCODE -ne 0) { + throw ("7z add failed: " + $relWin + " :: " + ($addOut -join " | ")) + } + + $arcPathUnix = $relWin -replace "\\", "/" + Verify-ZipEntry $zip $relWin $arcPathUnix $local + $updated++ + Write-Host ("[sync] " + $arcPathUnix) + } + } +} finally { + Pop-Location +} + +if ($updated -eq 0) { + throw ("no config files matched under: " + $src) +} + +Write-Host ("[OK] base pack config synced (" + $updated + " files, sha256 verified) -> " + $zip)