Skip to content

Commit

Permalink
refactor source handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Aug 28, 2024
1 parent 43a5302 commit 1c7a55a
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 170 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ RUN cd /opt/mix_build && make release && \

# --- Final image ---
FROM archlinux:latest
RUN pacman -Syu --noconfirm supervisor ca-certificates \
gd opus zlib ffmpeg flac lmdb && \
RUN pacman -Syu --noconfirm ca-certificates gd opus zlib ffmpeg flac lmdb && \
yes | pacman -Scc

COPY --from=build /opt/mix /opt/mix
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved video encode/decode handling


## v0.6.0-beta - 2024-04-10


## v0.5.3-beta - 2023-08-15

### Added
Expand Down
4 changes: 4 additions & 0 deletions include/mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ void vmix_disp_solo(const char *device);
*/
int slmix_source_alloc(struct source_pc **srcp, struct session *sess,
const char *dev);
void slmix_source_deref(struct mix *mix, const struct call *call,
const char *dev);
int slmix_source_start(struct source_pc *src, struct mix *mix);
int slmix_source_append_all(struct mix *mix, struct call *call,
const char *dev);
int slmix_handle_ice_candidate(struct peer_connection *pc,
const struct odict *od);
2 changes: 1 addition & 1 deletion modules/vmix/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <re_atomic.h>
#include "vmix.h"

#define STREAM 0
#define STREAM 1

static struct {
RE_ATOMIC bool run;
Expand Down
7 changes: 7 additions & 0 deletions src/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ static void pc_estab_handler(struct media_track *media, void *arg)
sess->mvideo = media;
stream_enable(media_get_stream(media), false);
stream_enable_tx(media_get_stream(media), true);

if (!sess->user->host)
slmix_source_append_all(sess->mix, NULL,
sess->user->id);

break;

default:
Expand All @@ -159,6 +164,8 @@ static void pc_close_handler(int err, void *arg)

warning("mix: session closed (%m)\n", err);

slmix_source_deref(sess->mix, NULL, sess->user->id);

slmix_session_user_updated(sess);
}

Expand Down
55 changes: 6 additions & 49 deletions src/sip.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
static struct ua *sip_ua;


static void ua_event_handler(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg)
static void ua_event_handler(enum ua_event ev, struct bevent *event, void *arg)
{
struct mix *mix = arg;
struct le *le;
int err;

(void)ua;
(void)prm;
struct call *call = bevent_get_call(event);

switch (ev) {

Expand Down Expand Up @@ -45,50 +40,12 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,

slmix_disp_enable(mix, peer, true);

LIST_FOREACH(&mix->sessl, le)
{
struct session *sesse = le->data;
struct source_pc *src;

if (!sesse->user->host)
continue;
slmix_source_append_all(mix, call, peer);

err = slmix_source_alloc(&src, sesse, peer);
if (err)
return;

err = slmix_source_start(src, mix);
if (err)
return;

src->call = call;
list_append(&sesse->source_pcl, &src->le, src);
}
break;

case UA_EVENT_CALL_CLOSED:

le = mix->sessl.head;
while (le) {
struct session *sesse = le->data;
struct le *le2;
le = le->next;

le2 = sesse->source_pcl.head;
while (le2) {
struct source_pc *src = le2->data;

le2 = le2->next;

if (src->call == call) {
mem_deref(src);
}
}

if (sesse->call == call)
mem_deref(sesse);
}

slmix_source_deref(mix, call, NULL);
break;
default:
break;
Expand All @@ -101,7 +58,7 @@ int slmix_sip_init(struct mix *mix)
int err;
char aor[128];

err = uag_event_register(ua_event_handler, mix);
err = bevent_register(ua_event_handler, mix);
if (err)
return err;

Expand All @@ -119,7 +76,7 @@ int slmix_sip_init(struct mix *mix)

int slmix_sip_close(void)
{
uag_event_unregister(ua_event_handler);
bevent_unregister(ua_event_handler);

return 0;
}
70 changes: 70 additions & 0 deletions src/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ int slmix_source_alloc(struct source_pc **srcp, struct session *sess,
{
int err = 0;

if (!srcp || !sess || !dev)
return EINVAL;

struct source_pc *src =
mem_zalloc(sizeof(struct source_pc), source_dealloc);
if (!src)
Expand Down Expand Up @@ -209,6 +212,10 @@ int slmix_source_start(struct source_pc *src, struct mix *mix)
struct rtc_configuration pc_config = {.offerer = true};
int err;

if (!src || !mix)
return EINVAL;

/* Modify independent config instance */
re_snprintf(config.video.src_mod, sizeof(config.video.src_mod),
"vmix_pktsrc");

Expand Down Expand Up @@ -240,6 +247,69 @@ int slmix_source_start(struct source_pc *src, struct mix *mix)
}


int slmix_source_append_all(struct mix *mix, struct call *call,
const char *dev)
{
struct le *le;
int err;

if (!mix)
return EINVAL;

LIST_FOREACH(&mix->sessl, le)
{
struct session *sesse = le->data;
struct source_pc *src;

if (!sesse->user->host)
continue;

err = slmix_source_alloc(&src, sesse, dev);
if (err)
return err;

err = slmix_source_start(src, mix);
if (err)
return err;

src->call = call;
list_append(&sesse->source_pcl, &src->le, src);
}

return 0;
}


void slmix_source_deref(struct mix *mix, const struct call *call,
const char *dev)
{
struct le *le;

if (!mix)
return;

LIST_FOREACH(&mix->sessl, le)
{
struct session *sess = le->data;

struct le *le2 = sess->source_pcl.head;
while (le2) {
struct source_pc *src = le2->data;

le2 = le2->next;

if (call && src->call == call) {
mem_deref(src);
continue;
}

if (dev && str_cmp(src->dev, dev) == 0)
mem_deref(src);
}
}
}


int slmix_handle_ice_candidate(struct peer_connection *pc,
const struct odict *od)
{
Expand Down
Loading

0 comments on commit 1c7a55a

Please sign in to comment.