Skip to content

Commit

Permalink
modules/audiolite: Add worker component
Browse files Browse the repository at this point in the history
Add worker component for making a component with worker offload
easier.
  • Loading branch information
SPRESENSE committed Nov 11, 2024
1 parent 1b1b475 commit a0db06c
Show file tree
Hide file tree
Showing 35 changed files with 2,740 additions and 134 deletions.
48 changes: 46 additions & 2 deletions examples/audiolite_mp3player/event_str.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
/****************************************************************************
* examples/audiolite_mp3player/event_str.h
*
* Copyright 2024 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* 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.
*
****************************************************************************/

#ifndef __EXAMPLES_AUDIOLITE_MP3PLAYER_EVENT_STR_H
#define __EXAMPLES_AUDIOLITE_MP3PLAYER_EVENT_STR_H

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define STRINGCASE(e) case AL_EVENT_##e: return #e;

static const char *convert_evtid(int id)
Expand Down Expand Up @@ -26,11 +68,13 @@ static const char *convert_evtid(int id)
STRINGCASE(SENDERROR)
STRINGCASE(MP3FRAMEINFO)
STRINGCASE(MP3DECWORKEREND)
STRINGCASE(MP3DECUNKNOWNEVT)
STRINGCASE(UNKNOWN)
STRINGCASE(MP3DECERROR)
STRINGCASE(MP3DEC_WRONGTYPE)
STRINGCASE(MP3DEC_WRONGVER)
STRINGCASE(WRONGVERSION)
default:
return "not event id...";
}
}

#endif /* __EXAMPLES_AUDIOLITE_MP3PLAYER_EVENT_STR_H */
4 changes: 3 additions & 1 deletion examples/audiolite_rec2net/event_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ static const char *convert_evtid(int id)
STRINGCASE(SENDERROR)
STRINGCASE(MP3FRAMEINFO)
STRINGCASE(MP3DECWORKEREND)
STRINGCASE(MP3DECUNKNOWNEVT)
STRINGCASE(UNKNOWN)
STRINGCASE(MP3DECERROR)
STRINGCASE(MP3DEC_WRONGTYPE)
STRINGCASE(WRONGVERSION)
default:
return "not event id...";
}
Expand Down
52 changes: 51 additions & 1 deletion examples/audiolite_wavplayer/event_str.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
/****************************************************************************
* examples/audiolite_wavplayer/event_str.h
*
* Copyright 2024 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* 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.
*
****************************************************************************/

#ifndef __EXAMPLES_AUDIOLITE_WAVPLAYER_EVENT_STR_H
#define __EXAMPLES_AUDIOLITE_WAVPLAYER_EVENT_STR_H

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define STRINGCASE(e) case AL_EVENT_##e: return #e;

/****************************************************************************
* Private Functions
****************************************************************************/

static const char *convert_evtid(int id)
{
switch (id)
Expand All @@ -26,9 +72,13 @@ static const char *convert_evtid(int id)
STRINGCASE(SENDERROR)
STRINGCASE(MP3FRAMEINFO)
STRINGCASE(MP3DECWORKEREND)
STRINGCASE(MP3DECUNKNOWNEVT)
STRINGCASE(UNKNOWN)
STRINGCASE(MP3DECERROR)
STRINGCASE(MP3DEC_WRONGTYPE)
STRINGCASE(WRONGVERSION)
default:
return "not event id...";
}
}

#endif /* __EXAMPLES_AUDIOLITE_WAVPLAYER_EVENT_STR_H */
52 changes: 51 additions & 1 deletion examples/audiolite_wavrecorder/event_str.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
/****************************************************************************
* examples/audiolite_wavrecorder/event_str.h
*
* Copyright 2024 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* 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.
*
****************************************************************************/

#ifndef __EXAMPLES_AUDIOLITE_WAVRECORDER_EVENT_STR_H
#define __EXAMPLES_AUDIOLITE_WAVRECORDER_EVENT_STR_H

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define STRINGCASE(e) case AL_EVENT_##e: return #e;

/****************************************************************************
* Private Functions
****************************************************************************/

static const char *convert_evtid(int id)
{
switch (id)
Expand All @@ -26,9 +72,13 @@ static const char *convert_evtid(int id)
STRINGCASE(SENDERROR)
STRINGCASE(MP3FRAMEINFO)
STRINGCASE(MP3DECWORKEREND)
STRINGCASE(MP3DECUNKNOWNEVT)
STRINGCASE(UNKNOWN)
STRINGCASE(MP3DECERROR)
STRINGCASE(MP3DEC_WRONGTYPE)
STRINGCASE(WRONGVERSION)
default:
return "not event id...";
}
}

#endif /* __EXAMPLES_AUDIOLITE_WAVRECORDER_EVENT_STR_H */
3 changes: 2 additions & 1 deletion sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ Make.dep
/.project
/.settings
/pcode
/tags
tags
/*.log
.*.tmp
.context
/Kconfig
/workerspks
.built
sdk-export.tar.gz
3 changes: 2 additions & 1 deletion sdk/modules/audiolite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CXXSRCS += src/base/al_evthandler.cxx
CXXSRCS += src/base/al_inputnode.cxx
CXXSRCS += src/base/al_memalloc.cxx
CXXSRCS += src/base/al_outputnode.cxx
CXXSRCS += src/base/al_thread.cxx
CXXSRCS += src/base/al_workercomp.cxx
CXXSRCS += src/base/al_stream.cxx
CXXSRCS += src/base/al_decoder.cxx
CXXSRCS += src/base/al_worker.cxx
Expand Down Expand Up @@ -80,4 +82,3 @@ clean_mp3dec:
@$(MAKE) -C worker/mp3dec TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean

clean:: clean_mp3dec

53 changes: 50 additions & 3 deletions sdk/modules/audiolite/src/base/al_component.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,17 @@ void audiolite_component::on_data()

if (_outnum > 0)
{
_outs[0]->push_data(mem);
if (mem->get_storedsize() != 0)
{
_outs[0]->push_data(mem);
}
else
{
printf("[AudioLite] %s(%d) : ZERO size memory is pushed\n"
" This might be BUG. \n"
" Check it if it is expected\n",
__func__, __LINE__);
}
}

mem->release();
Expand Down Expand Up @@ -561,9 +571,10 @@ audiolite_outputnode *audiolite_component::get_output(int id)
return NULL;
}

int audiolite_component::bind(audiolite_component *cmp)
audiolite_component *audiolite_component::bind(audiolite_component *cmp)
{
return bind(cmp->get_input(), 0);
bind(cmp->get_input(), 0);
return cmp;
}

int audiolite_component::bind(audiolite_inputnode *in, int outid)
Expand Down Expand Up @@ -607,6 +618,42 @@ int audiolite_component::unbindall()
return 0;
}

int audiolite_component::start()
{
if (_innum != 0)
{
return -ENOTSUP;
}

return start((audiolite_inputnode *)NULL);
}

void audiolite_component::stop()
{
if (_innum == 0)
{
stop((audiolite_inputnode *)NULL);
}
}

void audiolite_component::suspend()
{
if (_innum == 0)
{
stop((audiolite_inputnode *)NULL);
}
}

int audiolite_component::resume()
{
if (_innum != 0)
{
return -ENOTSUP;
}

return start((audiolite_inputnode *)NULL);
}

/***********************************************
* Static Protected Class audiolite_component Methods
***********************************************/
Expand Down
2 changes: 1 addition & 1 deletion sdk/modules/audiolite/src/base/al_decoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

audiolite_decoder::audiolite_decoder(const char *name,
int prio, int stack_sz)
: audiolite_source(0, 1),
: audiolite_component(0, 1),
_stream(NULL), _prio(prio), _stacksz(stack_sz),
_tid(-1), _tname(name), _isplay(false), _ispause(false),
_is_thrdrun(false)
Expand Down
2 changes: 1 addition & 1 deletion sdk/modules/audiolite/src/base/al_evthandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SINGLETON_INST(audiolite_evthandler);
***********************************************/

audiolite_evthandler::audiolite_evthandler(int memnum)
: _fs(0), _chnum(0), _bitwidth(0), _listen(NULL)
: _fs(48000), _chnum(2), _bitwidth(16), _listen(NULL)
{
_pool = new audiolite_mempoolsysmsg;
_pool->create_instance(memnum);
Expand Down
14 changes: 10 additions & 4 deletions sdk/modules/audiolite/src/base/al_memalloc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ audiolite_mem *audiolite_mempoolapbuf::allocate(bool blocking)
{
int qsz;
audiolite_memapbuf *ret = NULL;
dq_entry_t *tmp;
dq_entry_t *tmp = NULL;

mossfw_lock_take(&_lock);

Expand All @@ -431,11 +431,17 @@ audiolite_mem *audiolite_mempoolapbuf::allocate(bool blocking)
measure_start();
}

tmp = dq_remfirst(&_free_mem);
while (_pool_enable && blocking && tmp == NULL)
if (_pool_enable)
{
mossfw_condition_wait(&_cond, &_lock);
tmp = dq_remfirst(&_free_mem);
while (_pool_enable && blocking && tmp == NULL)
{
mossfw_condition_wait(&_cond, &_lock);
if (_pool_enable)
{
tmp = dq_remfirst(&_free_mem);
}
}
}

update_remain(qsz);
Expand Down
Loading

0 comments on commit a0db06c

Please sign in to comment.