Developer World
Spresense SDK Library v3.3.0-375c679
al_component.h
1/****************************************************************************
2 * modules/include/audiolite/al_component.h
3 *
4 * Copyright 2023 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef __INCLUDE_AUDIOLITE_COMPONENT_H
37#define __INCLUDE_AUDIOLITE_COMPONENT_H
38
39/****************************************************************************
40 * Included Files
41 ****************************************************************************/
42
43#include <nuttx/config.h>
44
45#include <audiolite/al_nodecomm.h>
46#include <audiolite/al_inputnode.h>
47#include <audiolite/al_outputnode.h>
48
49/****************************************************************************
50 * Class Definitions
51 ****************************************************************************/
52
53/****************************************************************************
54 * class: audiolite_component
55 ****************************************************************************/
56
58{
59 protected:
62 mossfw_callback_op_t *_op;
63 audiolite_mempool *_pool;
64 int _innum;
65 int _outnum;
66 int _state;
67
68 int search_inputidx(audiolite_inputnode *node);
69 static int operate_cb(mossfw_callback_op_t *op, unsigned long arg);
70 void set_operatorname(const char *name);
71
72 audiolite_mem *pop_data(int no = 0, int *used = NULL)
73 {
74 return (_ins && _innum > no) ? _ins[no]->pop_data(used) : NULL;
75 };
76
77 int push_data(audiolite_mem *mem, int no = 0)
78 {
79 if (_outs && _outnum > no) return _outs[no]->push_data(mem);
80 return -1;
81 };
82
83#ifdef _ALDEBUG_ENABLE
84 public:
85 const char *dbg_name;
86#endif
87
88 public:
89 audiolite_component(int inputnum = 1,
90 int outputnum = 1,
91 int depth = 16,
92 bool is_sync = true,
93 int prio = 105,
94 int stack_sz = CONFIG_PTHREAD_STACK_DEFAULT);
95 virtual ~audiolite_component();
96
97 void set_mempool(audiolite_mempool *pool);
98
99 /* Call backs */
100
101 int start(audiolite_inputnode *node);
102 void cancel(audiolite_inputnode *node);
103 void stop(audiolite_inputnode *node);
104 void reflesh(audiolite_inputnode *node);
105
106 int start(audiolite_outputnode *node);
107 void cancel(audiolite_outputnode *node);
108 void stop(audiolite_outputnode *node);
109 void reflesh(audiolite_outputnode *node);
110
111 void data_came(mossfw_callback_op_t *op);
112
113 virtual bool can_breakdata(audiolite_outputnode *out);
114 virtual void on_data();
115 virtual int on_starting(audiolite_inputnode *inode,
116 audiolite_outputnode *onode);
117 virtual void on_started(audiolite_inputnode *inode,
118 audiolite_outputnode *onode);
119 virtual void on_canceled(audiolite_inputnode *inode,
120 audiolite_outputnode *onode);
121 virtual void on_stopping(audiolite_inputnode *inode,
122 audiolite_outputnode *onode);
123 virtual void on_stop(audiolite_inputnode *inode,
124 audiolite_outputnode *onode);
125
126 int publish_event(int evtid, unsigned long arg);
127 int samplingrate();
128 int channels();
129 int samplebitwidth();
130
131 audiolite_inputnode *get_input(int id = 0);
132 audiolite_outputnode *get_output(int id = 0);
133
135 int bind(audiolite_inputnode *in, int outid = 0);
136
137 int unbind(audiolite_inputnode *in);
138 int unbindall();
139
140 virtual int start();
141 virtual void stop();
142 virtual void suspend();
143 virtual int resume();
144};
145
146#endif /* __INCLUDE_AUDIOLITE_COMPONENT_H */
Definition: al_component.h:58
Definition: al_inputnode.h:71
Definition: al_memalloc.h:112
Definition: al_memalloc.h:97
Definition: al_nodecomm.h:57
Definition: al_outputnode.h:65