Skip to content

Commit

Permalink
modules/audiolite: Fix a stacking issue when stop() is called after s…
Browse files Browse the repository at this point in the history
…top playing

With audiolite_mp3decorder component, when stop() method is called
on app side after the playing a music is all done, the stop() method
is stacked.
This commit fixed it.
  • Loading branch information
SPRESENSE committed Nov 13, 2024
1 parent d69d58c commit 46fb596
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 7 additions & 2 deletions sdk/modules/audiolite/src/base/al_decoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

audiolite_decoder::audiolite_decoder(const char *name,
int prio, int stack_sz)
: audiolite_component(0, 1),
_stream(NULL), _prio(prio), _stacksz(stack_sz),
: audiolite_component(0, 1), _stream(NULL),
_omempool(NULL), _prio(prio), _stacksz(stack_sz),
_tid(-1), _tname(name), _isplay(false), _ispause(false),
_is_thrdrun(false)
{
Expand Down Expand Up @@ -100,6 +100,11 @@ void audiolite_decoder::stop_thread()
_pool->disable_pool();
}

if (_omempool)
{
_omempool->disable_pool();
}

mossfw_thread_join(&_tid);
_tid = -1;
}
Expand Down
9 changes: 8 additions & 1 deletion sdk/modules/audiolite/src/components/al_mp3dec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ void audiolite_mp3dec::decode_runner()
* It will be done after finishing decode.
*/
}
else
{
/* Yeild */

usleep(10 * 1000);
}
}
else
{
Expand Down Expand Up @@ -253,7 +259,7 @@ int audiolite_mp3dec::handle_mesage(al_comm_msghdr_t hdr,
audiolite_mp3dec::audiolite_mp3dec() : audiolite_decoder("mp3decomem",
CONFIG_ALMP3DEC_INJECTPRIO,
CONFIG_ALMP3DEC_INJECTSTACK),
_omempool(NULL), _worker(),
_worker(),
_inq(SPRMP3_FRAMEMEM_QSIZE / 2),
_outq(SPRMP3_OUTMEM_QSIZE / 2), _frame_eof(false),
_worker_booted(false), _worker_terminated(true)
Expand Down Expand Up @@ -293,6 +299,7 @@ int audiolite_mp3dec::stop_decode()
{
_pool->disable_pool();
}

_inq.disable();

if (_worker_booted)
Expand Down
5 changes: 5 additions & 0 deletions sdk/modules/include/audiolite/al_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class audiolite_decoder : public audiolite_component
{
protected:
audiolite_stream *_stream;
audiolite_mempoolapbuf *_omempool;
int _prio;
int _stacksz;
mossfw_thread_t _tid;
Expand Down Expand Up @@ -86,6 +87,10 @@ class audiolite_decoder : public audiolite_component
virtual int resume_decode() = 0;

void set_stream(audiolite_stream *st) { _stream = st; };
void set_outputmempool(audiolite_mempoolapbuf *pool)
{
_omempool = pool;
}
};

#endif /* __INCLUDE_AUDIOLITE_DECODER_H */
6 changes: 0 additions & 6 deletions sdk/modules/include/audiolite/al_mp3dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
class audiolite_mp3dec : public audiolite_decoder
{
private:
audiolite_mempoolapbuf *_omempool;
audiolite_worker _worker;
audiolite_workermemq _inq;
audiolite_workermemq _outq;
Expand All @@ -78,11 +77,6 @@ class audiolite_mp3dec : public audiolite_decoder
int stop_decode();
int pause_decode() { return OK; };
int resume_decode() { return OK; };

void set_outputmempool(audiolite_mempoolapbuf *pool)
{
_omempool = pool;
}
};

#endif /* __INCLUDE_AUDIOLITE_MP3DEC_H */

0 comments on commit 46fb596

Please sign in to comment.