Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
replace id with optional read handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Dec 20, 2022
1 parent 2f9edca commit aa421c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/rem_aumix.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct aumix_source;
*/
typedef void (aumix_frame_h)(const int16_t *sampv, size_t sampc, void *arg);
typedef void (aumix_record_h)(struct auframe *af);
typedef void (aumix_read_h)(struct auframe *af, void *arg);

int aumix_alloc(struct aumix **mixp, uint32_t srate,
uint8_t ch, uint32_t ptime);
Expand All @@ -29,5 +30,6 @@ void aumix_source_enable(struct aumix_source *src, bool enable);
void aumix_source_mute(struct aumix_source *src, bool mute);
int aumix_source_put(struct aumix_source *src, const int16_t *sampv,
size_t sampc);
void aumix_source_readh(struct aumix_source *src, aumix_read_h *readh);
void aumix_source_flush(struct aumix_source *src);
int aumix_debug(struct re_printf *pf, struct aumix *mix);
18 changes: 13 additions & 5 deletions src/aumix/aumix.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ struct aumix {
/** Defines an Audio mixer source */
struct aumix_source {
struct le le;
uint16_t id;
struct auframe af;
int16_t *frame;
struct aubuf *aubuf;
struct aumix *mix;
aumix_frame_h *fh;
aumix_read_h *readh;
void *arg;
bool muted;
};
Expand Down Expand Up @@ -157,7 +157,10 @@ static int aumix_thread(void *arg)
if (src->muted)
continue;

aubuf_read_auframe(src->aubuf, &src->af);
if (src->readh)
src->readh(&src->af, src->arg);
else
aubuf_read_auframe(src->aubuf, &src->af);

if (mix->recordh)
mix->recordh(&src->af);
Expand Down Expand Up @@ -395,14 +398,19 @@ int aumix_source_alloc(struct aumix_source **srcp, struct aumix *mix,
}


void aumix_source_set_id(struct aumix_source *src, uint16_t id)
/**
* Add source read handler (alternative to aumix_source_put)
*
* @param src Audio mixer source
* @param readh Read Handler
*/
void aumix_source_readh(struct aumix_source *src, aumix_read_h *readh)
{
if (!src || !src->mix)
return;

mtx_lock(&src->mix->mutex);
src->id = id;
src->af.id = id;
src->readh = readh;
mtx_unlock(&src->mix->mutex);
}

Expand Down

0 comments on commit aa421c8

Please sign in to comment.