blob: 226087b888d8bfd029f5e11c69dbfdb6d1dd56e2 [file] [log] [blame]
Quinn Male2e883752019-03-22 11:28:54 -07001/* sml_model_parser.h
2 *
3 * This file contains the structures needed for the updated
4 * sound model library version 3 sound model. These structures
5 * are used to combine multiple sound models together into a
6 * big sound model version 3. These are used in STHAL to parse
7 * out the individual sound models' raw data.
8 *
Quinn Male58749452020-03-26 17:14:56 -07009 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
Quinn Male2e883752019-03-22 11:28:54 -070010 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are
13 * met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * * Neither the name of The Linux Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37
38#ifndef __SML_MODEL_PARSER_H__
39#define __SML_MODEL_PARSER_H__
40
41#if defined(__cplusplus)
42extern "C" {
43#endif
44
45enum {
46 SML_PARSER_SUCCESS = 0,
47 SML_PARSER_ERROR = 1,
48 SML_PARSER_NOT_SUPPORTED_VERSION,
49 SML_PARSER_ID_NOT_EXIST,
50 SML_PARSER_NOT_ALIGNED_SIZE,
51 SML_PARSER_SIZE_MISSMATCH,
52 SML_PARSER_VALUE_MISSMATCH,
53 SML_PARSER_REF_UNINIT_VALUE,
54 SML_PARSER_OUT_OF_RANGE,
55 SML_PARSER_WRONG_MODEL,
56 SML_PARSER_WRONG_VALUE,
57 SML_PARSER_DELETING_LAST_KEYWORD,
58 SML_PARSER_KEYWORD_NOT_FOUND,
59 SML_PARSER_USER_NOT_FOUND,
60 SML_PARSER_USER_ALREADY_EXIST,
61 SML_PARSER_KEYWORD_USER_PAIR_EXIST,
62 SML_PARSER_KEYWORD_USER_PAIR_NOT_EXIST,
63 SML_PARSER_ACTIVE_USER_REMOVE_UDK,
64 SML_PARSER_KEYWORD_ALREADY_EXIST,
65 SML_PARSER_NOTHING_TO_CHANGE,
66};
67
68enum {
69 SML_COMPARATOR_ERROR = -1,
70 SML_COMPARATOR_SAME = 0,
71 SML_COMPARATOR_DIFF = 1,
72};
73
74enum {
75 SML_V3_MAX_PAYLOAD = 10000000,
76 SML_V3_MIN_KEYWORDS = 1,
77 SML_V3_MAX_KEYWORDS = 1,
78 SML_V3_MIN_USERS = 0,
79 SML_V3_MAX_USERS = 1,
80};
81
82enum {
83 SML_GLOBAL_HEADER_MAGIC_NUMBER = 0x00180cc8, // SML03
84 SML_MAX_MODEL_NUM = 3,
85 SML_MAX_STRING_LEN = 200,
86};
87
88typedef enum {
89 ST_SM_ID_SVA_NONE = 0x0000,
90 ST_SM_ID_SVA_GMM = 0x0001,
91 ST_SM_ID_SVA_CNN = 0x0002,
92 ST_SM_ID_SVA_VOP = 0x0004,
Dallas Delaneyf5132c72019-07-01 15:09:06 -070093 ST_SM_ID_SVA_RNN = 0x0008,
94 ST_SM_ID_SVA_KWD = 0x000A, //ST_SM_ID_SVA_CNN | ST_SM_ID_SVA_RNN
Harshal Ahire081894b2020-05-22 03:57:39 +053095 SML_ID_SVA_S_STAGE_UBM = 0x0010,
Quinn Male2e883752019-03-22 11:28:54 -070096 ST_SM_ID_SVA_END = 0x00F0,
97 ST_SM_ID_CUSTOM_START = 0x0100,
98 ST_SM_ID_CUSTOM_END = 0xF000,
99} listen_model_indicator_enum;
100
101typedef struct _SML_GlobalHeaderType {
102 uint32_t magicNumber; // Magic number
103 uint32_t payloadBytes; // Payload bytes size
104 uint32_t modelVersion; // Model version
105} SML_GlobalHeaderType;
106
107typedef struct _SML_HeaderTypeV3 {
108 uint32_t numModels; // number of models
109 uint32_t keywordSpellLength; // length of keyword spell ( include '\0' )
110 uint32_t userNameLength; // length of user name ( include '\0' )
111 char keywordSpell[SML_MAX_STRING_LEN]; // keyword spell
112 char userName[SML_MAX_STRING_LEN]; // user name
113} SML_HeaderTypeV3;
114
115typedef struct _SML_BigSoundModelTypeV3 {
Quinn Male58749452020-03-26 17:14:56 -0700116 uint16_t versionMajor; // major version of sound model
117 uint16_t versionMinor; // minor version of sound model
Quinn Male2e883752019-03-22 11:28:54 -0700118 uint32_t offset; // start address of model data
119 uint32_t size; // model size
120 listen_model_indicator_enum type; // type : Lower 1 byte : 1Stage KW model,
121 // 2Stage KW model,
122 // 2Stage User Model
123 // Upper 1 byte : 3rd Party - 1Stage KW model,
124 // 2Stage KW model,
125 // 2Stage User Model
126}SML_BigSoundModelTypeV3;
127
128
129typedef struct _SML_ModelTypeV3 {
130 SML_HeaderTypeV3 header; // header for v3 model
131 SML_BigSoundModelTypeV3 *modelInfo; // model info, used for dynamic memory allocation.
132 uint8_t* rawData; // actual model data
133} SML_ModelTypeV3;
134
135// all of model versions about SML
136typedef enum _SML_ModelVersion {
137 SML_MODEL_V2 = 0x0200,
138 SML_MODEL_V3 = 0x0300,
139} SML_ModelVersion;
140
141// universial SML model structure
142typedef struct _SML_ModelType {
143
144 SML_GlobalHeaderType header; // global header
145
146 union _sml_model {
147 SML_ModelTypeV3 SMLModelV3; // sml3.0 -- kwihyuk
148 } SMLModel;
149} SML_ModelType;
150
151
152/*
153@brief decode to the SML model structure from serialized memory
154*/
155int sml_model_decoder(uint8_t *buffer, SML_ModelType *model);
156
157
158#ifdef NON_VOICEWAKEUP_CSIM
159/*
160@brief create SML model through heap allocation
161*/
162SML_ModelType *sml_model_create(SML_ModelVersion smmlModelVersion);
163
164/*
165@brief used by encoder, merger, serializer, and migration to estimate serializing SML model size
166*/
167int sml_model_get_size(SML_ModelType *model);
168
169/*
170@brief serialize from encoded SML model structure
171*/
172int sml_model_serializer(SML_ModelType *model, uint8_t *buffer);
173
174
175/*
176@brief merge the base(merged) model and individual model such as GMMSVA, CNNSVA or GMMVoP.
177*/
178int sml_model_merger(uint8_t *binary_model, uint32_t model_size, SML_ModelType *merged_model, uint16_t indicator);
179
180
181/*
182@brief register user
183*/
184int sml_model_register_user(SML_ModelType *model, char *user_spell);
185
186
187/*
188@brief set keyword spell
189*/
190int sml_model_set_keyword_spell(SML_ModelType *model, char *keyword_spell);
191
192
193/*
194@brief delete specific keyword Model from combined(merged Model)
195*/
196int sml_model_deleter(SML_ModelType *merged_model, uint16_t indicator);
197
198
199/*
200@brief destroy SML model from heap allocation
201*/
202void sml_model_destroy(SML_ModelType *pModel);
203#endif
204#if defined(__cplusplus)
205};
206#endif
207
208#endif
209