Developer World
Spresense SDK Library v3.2.0-ebc0364
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 <audiolite/al_nodecomm.h>
44#include <audiolite/al_inputnode.h>
45#include <audiolite/al_outputnode.h>
46
47/****************************************************************************
48 * Class Definitions
49 ****************************************************************************/
50
51/****************************************************************************
52 * class: audiolite_component
53 ****************************************************************************/
54
56{
57 protected:
60 mossfw_callback_op_t *_op;
61 audiolite_mempool *_pool;
62 int _innum;
63 int _outnum;
64 int _state;
65
66 int search_inputidx(audiolite_inputnode *node);
67 static int operate_cb(mossfw_callback_op_t *op, unsigned long arg);
68 void set_operatorname(const char *name);
69
70 audiolite_mem *pop_data(int no = 0, int *used = NULL)
71 {
72 return (_ins && _innum > no) ? _ins[no]->pop_data(used) : NULL;
73 };
74
75 int push_data(audiolite_mem *mem, int no = 0)
76 {
77 if (_outs && _outnum > no) return _outs[no]->push_data(mem);
78 return -1;
79 };
80
81#ifdef _ALDEBUG_ENABLE
82 public:
83 const char *dbg_name;
84#endif
85
86 public:
87 audiolite_component(int inputnum = 1,
88 int outputnum = 1,
89 int depth = 16,
90 bool is_sync = true,
91 int prio = -1,
92 int stack_sz = -1);
93 virtual ~audiolite_component();
94
95 void set_mempool(audiolite_mempool *pool);
96
97 /* Call backs */
98
99 int start(audiolite_inputnode *node);
100 void cancel(audiolite_inputnode *node);
101 void stop(audiolite_inputnode *node);
102 void reflesh(audiolite_inputnode *node);
103
104 int start(audiolite_outputnode *node);
105 void cancel(audiolite_outputnode *node);
106 void stop(audiolite_outputnode *node);
107 void reflesh(audiolite_outputnode *node);
108
109 void data_came(mossfw_callback_op_t *op);
110
111 virtual bool can_breakdata(audiolite_outputnode *out);
112 virtual void on_data();
113 virtual int on_starting(audiolite_inputnode *inode,
114 audiolite_outputnode *onode);
115 virtual void on_started(audiolite_inputnode *inode,
116 audiolite_outputnode *onode);
117 virtual void on_canceled(audiolite_inputnode *inode,
118 audiolite_outputnode *onode);
119 virtual void on_stopping(audiolite_inputnode *inode,
120 audiolite_outputnode *onode);
121 virtual void on_stop(audiolite_inputnode *inode,
122 audiolite_outputnode *onode);
123
124 int publish_event(int evtid, unsigned long arg);
125 int samplingrate();
126 int channels();
127 int samplebitwidth();
128
129 audiolite_inputnode *get_input(int id = 0);
130 audiolite_outputnode *get_output(int id = 0);
131
132 int bind(audiolite_component *cmp);
133 int bind(audiolite_inputnode *in, int outid = 0);
134
135 int unbind(audiolite_inputnode *in);
136 int unbindall();
137};
138
139#endif /* __INCLUDE_AUDIOLITE_COMPONENT_H */
Definition: al_component.h:56
Definition: al_inputnode.h:71
Definition: al_memalloc.h:111
Definition: al_memalloc.h:97
Definition: al_nodecomm.h:57
Definition: al_outputnode.h:65