blob: a63732f6b4e4be15a42aae8e2735e4eb1c496804 [file] [log] [blame]
Quinn Male2e883752019-03-22 11:28:54 -07001/* st_hw_session_gcs.h
2 *
3 * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * * Neither the name of The Linux Foundation nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30#ifndef ST_HW_SESSION_GCS
31#define ST_HW_SESSION_GCS
32
33#include <pthread.h>
34#include "sound_trigger_platform.h"
35#include "st_hw_session.h"
36#include "st_common_defs.h"
37
38#define ST_GRAPHITE_LAB_PERIOD_COUNT (4)
39#define ST_BYTES_PER_SAMPLE (2)
40#define MAX_DETECTION_PAYLOAD_SZ 256
41
42#define ST_GRAPHITE_LAB_PERIOD_SIZE_IN_SAMPLES \
43 CALCULATE_PERIOD_SIZE(ST_GRAPHITE_LAB_BUF_DURATION_MS, \
44 SOUND_TRIGGER_SAMPLING_RATE_16000, ST_GRAPHITE_LAB_PERIOD_COUNT, 32)
45
46#define ST_GCS_READ_BUF_SIZE (ST_GRAPHITE_LAB_PERIOD_SIZE_IN_SAMPLES * \
47 ST_BYTES_PER_SAMPLE)
48
49/*
50 * The chosen theshold for determining FTRT vs. RT data is half the buffer
51 * duration. There can be frames received that are partially FTRT and
52 * partially RT, so the threshold should be less than the full buffer duration
53 * to account for that usecase. However, if the threshold is too small, then
54 * some issue in the lower layers could lead to false identification of RT
55 * data.
56 */
57#define GCS_MAX_LAB_FTRT_FRAME_RD_TIME_NS \
58 ((ST_GRAPHITE_LAB_BUF_DURATION_MS * NSECS_PER_MSEC) \
59 / (2 * ST_GRAPHITE_LAB_PERIOD_COUNT))
60
61struct sound_trigger_device;
62
63typedef struct st_hw_session_gcs {
64 st_hw_session_t common;
65 struct st_gcs_params* gcs_usecase;
66 uint32_t graph_handle;
67 uint32_t loaded_sm_handle;
68 void* nonpersistent_cal;
69 size_t nonpersistent_cal_size;
70 struct gcs_det_engine_start_custom_config *start_engine_cal;
71 size_t start_engine_cal_size;
72
73 uint8_t detect_payload[MAX_DETECTION_PAYLOAD_SZ];
74 size_t detect_payload_size;
75
76 bool detection_signaled;
77 bool exit_buffering;
78 bool exit_detection;
79 bool lab_processing_active;
80
81 pthread_t callback_thread;
82 pthread_cond_t callback_thread_cond;
83 pthread_mutex_t callback_thread_lock;
84
85 pthread_mutex_t lock;
86 pthread_cond_t cond;
87 uint32_t read_rsp_cnt; /* keeps track of how many read responses were
88 received so we know how many read_req to send when sender thread runs */
89 uint32_t unread_bytes;
90 uint32_t bytes_written;
91 bool move_client_ptr;
92 uint64_t frame_send_time;
93 uint64_t frame_receive_time;
94
95 uint8_t *mulaw_op_buf;
Quinn Male3d7d9d42019-05-20 13:35:01 -070096 FILE *lab_fp_gcs;
97 FILE *lab_fp_client;
Quinn Male2e883752019-03-22 11:28:54 -070098} st_hw_session_gcs_t;
99
100int st_hw_sess_gcs_init(st_hw_session_t *const p_ses,
101 hw_ses_event_callback_t cb, void *cookie, st_exec_mode_t exec_mode,
102 struct st_vendor_info *v_info, sound_model_handle_t sm_handle,
103 struct sound_trigger_device *stdev);
104
105void st_hw_sess_gcs_deinit(st_hw_session_t *const p_ses);
106
107int st_hw_gcs_init(void);
108
109void st_hw_gcs_deinit(void);
110
111int st_hw_gcs_load_wdsp(bool load);
112#endif /* ST_HW_SESSION_GCS */