Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: refactoring #37

Merged
merged 38 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8974132
vmix: refactor encode handling
sreimers Feb 13, 2024
d0dc913
vmix: refactor record
sreimers Feb 15, 2024
9241f1c
vmix/record: fix close avio mem leak
sreimers Feb 15, 2024
9d18189
misc: enable turn
sreimers Feb 16, 2024
c93bf13
mk,main: use baresip playout_time branch
sreimers Feb 16, 2024
f62f34e
vmix/record: limit videoCodec threads
sreimers Feb 16, 2024
5876bb8
main: disable sip_listen
sreimers Feb 16, 2024
45e6285
vmix: refactor record
sreimers Feb 17, 2024
d812e2c
vmix: limit record threads
sreimers Feb 17, 2024
cd70456
webui: enable StudioNav
sreimers Feb 18, 2024
ca0cf0a
webui: hide extra sources
sreimers Feb 18, 2024
1cd2d59
webui/chat: add unread notifications
sreimers Feb 19, 2024
9409f95
webui: linkify chat
sreimers Feb 19, 2024
fdf5c85
main/conf: fix video jitter buffer size
sreimers Feb 19, 2024
85fc239
increase video buffer
sreimers Feb 19, 2024
6bebf7b
vmix: always enable speaker video
sreimers Feb 20, 2024
2092029
misc: cleanup
sreimers Feb 20, 2024
72e9d87
webui/video: remove PictureInPicture
sreimers Feb 20, 2024
227a820
vmix/rec: improve audio and video bitrate
sreimers Feb 20, 2024
b5ad1cb
webui: refactor dummy source and video mute
sreimers Feb 20, 2024
d4eddc0
webui: npm update
sreimers Feb 20, 2024
8e9f7a0
webui: fix MediaStream return and cleanup
sreimers Feb 21, 2024
366cf6b
webui: fix audiooutput selection
sreimers Feb 21, 2024
3b2e3ad
webui: re-add avdummy stream
sreimers Feb 21, 2024
0af9796
main: use relay only policy
sreimers Feb 21, 2024
f44a828
webui: fix video disabled after hangup
sreimers Feb 21, 2024
e91ea7d
webui/chat: use markdown-it
sreimers Feb 22, 2024
9bd8fb0
misc: add video solo feature
sreimers Feb 22, 2024
9b45855
misc: if not a show allow self managed listener state
sreimers Feb 22, 2024
8df9107
webui/nav: improve listeners counting ui
sreimers Feb 22, 2024
80b7aff
sess: session lookup refactoring
sreimers Feb 23, 2024
9739087
http,webui: fix reauth
sreimers Feb 23, 2024
c5935de
webui/chat: stop auto scroll on up scrolling
sreimers Feb 23, 2024
67a2cde
webui: cleanup audience spacing
sreimers Feb 23, 2024
30d441e
webui/login: prevent default submit buttons
sreimers Feb 23, 2024
e4624b8
vmix: fix mem leak
sreimers Feb 23, 2024
dd3b086
sess: fix session connected solo
sreimers Feb 23, 2024
082346b
sess: if pc connection is established force session connected
sreimers Feb 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
.gdb_history

node_modules

re_trace.json
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ external:
mkdir -p external
git clone --depth 1 -b main \
https://github.com/baresip/re.git external/re
git clone --depth 1 -b main \
git clone --depth 1 -b playout_time \
https://github.com/baresip/baresip.git external/baresip
cd external/re && \
patch -p1 < ../../patches/re_aubuf_timestamp_order_fix.patch
Expand Down
2 changes: 2 additions & 0 deletions include/mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct user {
bool video;
bool audio;
bool hand;
bool solo;
};

struct chat {
Expand Down Expand Up @@ -158,6 +159,7 @@ int slmix_http_listen(struct http_sock **sock, struct mix *mix);
void pc_close(struct session *sess);
int slmix_session_user_updated(struct session *sess);
void slmix_session_video(struct session *sess, bool enable);
void slmix_session_video_solo(struct user *user, bool enable);
int slmix_session_speaker(struct session *sess, bool enable);
int slmix_session_new(struct mix *mix, struct session **sessp,
const struct http_msg *msg);
Expand Down
135 changes: 119 additions & 16 deletions modules/vmix/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ static viddec_update_h *decupdh;
static struct hash *dec_list;
static mtx_t *dec_mtx;

struct enc_pkt {
struct le le;
bool marker;
uint64_t rtp_ts;
struct mbuf *hdr;
size_t hdr_len;
struct mbuf *pld;
size_t pld_len;
};

static struct list enc_pktl = LIST_INIT;
static RE_ATOMIC bool last_keyframe = false;
static RE_ATOMIC bool force_keyframe = false;

enum {
MAX_PKT_TIME = 50, /**< in [ms] */
};
Expand All @@ -34,7 +48,7 @@ struct viddec_state {
const char *dev;
};

struct pkt {
struct dec_pkt {
uint64_t id;
struct le le;
struct mbuf *mb;
Expand Down Expand Up @@ -69,6 +83,53 @@ static void viddec_deref(void *arg)
}


static void enc_pkt_deref(void *arg)
{
struct enc_pkt *pkt = arg;

mem_deref(pkt->hdr);
mem_deref(pkt->pld);
list_unlink(&pkt->le);
}


/* Copy encoded and packetized codec */
static int enc_packet_h(bool marker, uint64_t rtp_ts, const uint8_t *hdr,
size_t hdr_len, const uint8_t *pld, size_t pld_len,
const struct video *vid)
{
(void)vid;
int err;

if (!hdr || !pld)
return EINVAL;

struct enc_pkt *pkt =
mem_zalloc(sizeof(struct enc_pkt), enc_pkt_deref);
if (!pkt)
return ENOMEM;

pkt->marker = marker;
pkt->rtp_ts = rtp_ts;

pkt->hdr = mbuf_alloc(hdr_len);
pkt->pld = mbuf_alloc(pld_len);

err = mbuf_write_mem(pkt->hdr, hdr, hdr_len);
err |= mbuf_write_mem(pkt->pld, pld, pld_len);

if (err)
return err;

mbuf_set_pos(pkt->hdr, 0);
mbuf_set_pos(pkt->pld, 0);

list_append(&enc_pktl, &pkt->le, pkt);

return 0;
}


static int enc_update(struct videnc_state **vesp, const struct vidcodec *vc,
struct videnc_param *prm, const char *fmtp,
videnc_packet_h *pkth, const struct video *vid)
Expand All @@ -86,8 +147,8 @@ static int enc_update(struct videnc_state **vesp, const struct vidcodec *vc,
ves->vid = vid;
ves->pkth = pkth;

err = encupdh((struct videnc_state **)&ves->vesp, vc, prm, fmtp, pkth,
vid);
err = encupdh((struct videnc_state **)&ves->vesp, vc, prm, fmtp,
enc_packet_h, vid);
if (err) {
mem_deref(ves);
return err;
Expand All @@ -102,18 +163,41 @@ static int enc_update(struct videnc_state **vesp, const struct vidcodec *vc,
static int encode(struct videnc_state *ves, bool update,
const struct vidframe *frame, uint64_t timestamp)
{
return ench(ves->vesp, update, frame, timestamp);
bool keyframe = update;

if (re_atomic_rlx(&force_keyframe)) {
keyframe = true;
re_atomic_rlx_set(&force_keyframe, false);
}

re_atomic_rlx_set(&last_keyframe, keyframe);

return ench(ves->vesp, keyframe, frame, timestamp);
}


static int packetize(struct videnc_state *ves, const struct vidpacket *vpkt)
{

if (ves->is_pkt_src) {
uint64_t ts = video_calc_rtp_timestamp_fix(vpkt->timestamp);
return ves->pkth(vpkt->keyframe, ts, NULL, 0, vpkt->buf,
vpkt->size, ves->vid);
}
return packetizeh(ves->vesp, vpkt);

struct le *le;
LIST_FOREACH(&enc_pktl, le)
{
struct enc_pkt *p = le->data;

int err = ves->pkth(p->marker, p->rtp_ts, mbuf_buf(p->hdr),
mbuf_get_left(p->hdr), mbuf_buf(p->pld),
mbuf_get_left(p->pld), ves->vid);
if (err)
return err;
}

return 0;
}


Expand Down Expand Up @@ -151,23 +235,25 @@ static int dec_update(struct viddec_state **vdsp, const struct vidcodec *vc,
return 0;
}


static void pkt_deref(void *arg)
#if 0
static void dec_pkt_deref(void *arg)
{
struct pkt *pkt = arg;
struct dec_pkt *pkt = arg;

mem_deref(pkt->mb);
list_unlink(&pkt->le);
}
#endif


static int decode(struct viddec_state *vds, struct vidframe *frame,
struct viddec_packet *vpkt)
{
if (!vds || !frame || !vpkt || !vpkt->mb)
return EINVAL;

struct pkt *pkt = mem_zalloc(sizeof(struct pkt), pkt_deref);
#if 0
struct dec_pkt *pkt =
mem_zalloc(sizeof(struct dec_pkt), dec_pkt_deref);
if (!pkt)
return ENOMEM;

Expand All @@ -187,17 +273,13 @@ static int decode(struct viddec_state *vds, struct vidframe *frame,

le = le->next;

/* FIXME: Keep SPS/PPS workaround */
if (pkt->id < 200)
continue;

if (pkt->ts > pkt->ts_eol)
mem_deref(pkt);
else
break;
}
mtx_unlock(vds->mtx);

#endif
return dech(vds->vdsp, frame, vpkt);
}

Expand Down Expand Up @@ -228,7 +310,7 @@ static bool list_apply_handler(struct le *le, void *arg)
{
struct vidsrc_st *st = arg;
struct viddec_state *vds = le->data;
struct pkt *pkt = NULL;
struct dec_pkt *pkt = NULL;

if (0 != str_cmp(vds->dev, st->device + sizeof("pktsrc") - 1))
return false;
Expand Down Expand Up @@ -268,6 +350,25 @@ void vmix_codec_pkt(struct vidsrc_st *st)
}


bool vmix_last_keyframe(void)
{
return re_atomic_rlx(&last_keyframe);
}


void vmix_request_keyframe(void)
{
re_atomic_rlx_set(&force_keyframe, true);
}


void vmix_encode_flush(void)
{

list_flush(&enc_pktl);
}


int vmix_codec_init(void)
{
const struct vidcodec *v;
Expand Down Expand Up @@ -317,6 +418,8 @@ void vmix_codec_close(void)
vidcodec_unregister(&h264_0);
vidcodec_unregister(&h264_1);

list_flush(&enc_pktl);

dec_list = mem_deref(dec_list);
dec_mtx = mem_deref(dec_mtx);
}
1 change: 0 additions & 1 deletion modules/vmix/disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ int vmix_disp_alloc(struct vidisp_st **stp, const struct vidisp *vd,
}

st->vidsrc->vidisp = st;
/* vidmix_source_enable(st->vidsrc->vidmix_src, false); */
hash_append(vmix_disp, hash_joaat_str(dev), &st->le, st);

out:
Expand Down
Loading