Skip to content

Commit

Permalink
vmix/codec: refactor fmtp proxy handling and update vp8 patch
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Mar 5, 2024
1 parent 1593237 commit b79f26e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 51 deletions.
117 changes: 66 additions & 51 deletions modules/vmix/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
#include "vmix.h"


struct vmix_proxy {
struct le le;
struct vidcodec codec;
videnc_encode_h *ench;
videnc_update_h *encupdh;
videnc_packetize_h *packetizeh;
viddec_decode_h *dech;
viddec_update_h *decupdh;
struct vmix_vcproxy {
struct vidcodec vc; /* Keep first, to keep vidcodec order */
struct vidcodec *ovc;
struct le ple;
};

static struct hash *dec_list;
Expand All @@ -25,7 +21,7 @@ struct enc_pkt {
size_t hdr_len;
struct mbuf *pld;
size_t pld_len;
const struct vmix_proxy *p;
const struct vmix_vcproxy *p;
};

static struct list enc_pktl = LIST_INIT;
Expand All @@ -42,7 +38,7 @@ struct videnc_state {
uint64_t last_ts;
void *vesp; /* Sub-Codec state */
bool is_pkt_src;
const struct vmix_proxy *p;
const struct vmix_vcproxy *p;
};

struct viddec_state {
Expand All @@ -53,7 +49,7 @@ struct viddec_state {
uint64_t last_id;
mtx_t *mtx;
const char *dev;
const struct vmix_proxy *p;
const struct vmix_vcproxy *p;
};

struct dec_pkt {
Expand All @@ -66,19 +62,19 @@ struct dec_pkt {
};


static const struct vmix_proxy *vmix_proxy_find(const char *name,
const char *variant)
static const struct vmix_vcproxy *vmix_proxy_find(const char *name,
const char *variant)
{
struct le *le;

LIST_FOREACH(&proxyl, le)
{
struct vmix_proxy *p = le->data;
struct vmix_vcproxy *p = le->data;

if (name && 0 != str_casecmp(name, p->codec.name))
if (name && 0 != str_casecmp(name, p->vc.name))
continue;

if (variant && 0 != str_casecmp(variant, p->codec.variant))
if (variant && 0 != str_casecmp(variant, p->vc.variant))
continue;

return p;
Expand Down Expand Up @@ -123,6 +119,24 @@ static void enc_pkt_deref(void *arg)
}


static int fmtp_ench(struct mbuf *mb, const struct sdp_format *fmt, bool offer,
void *data)
{
const struct vmix_vcproxy *p = data;

return p->ovc->fmtp_ench(mb, fmt, offer, p->ovc);
}


static bool fmtp_cmph(const char *params1, const char *params2, void *data)
{

const struct vmix_vcproxy *p = data;

return p->ovc->fmtp_cmph(params1, params2, p->ovc);
}


/* 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,
Expand Down Expand Up @@ -165,6 +179,7 @@ static int enc_update(struct videnc_state **vesp, const struct vidcodec *vc,
videnc_packet_h *pkth, const struct video *vid)
{
struct videnc_state *ves;
const struct vmix_vcproxy *p = (struct vmix_vcproxy *)vc;
int err;

ves = mem_zalloc(sizeof(struct videnc_state), videnc_deref);
Expand All @@ -183,8 +198,8 @@ static int enc_update(struct videnc_state **vesp, const struct vidcodec *vc,
return EINVAL;
}

err = ves->p->encupdh((struct videnc_state **)&ves->vesp, vc, prm,
fmtp, enc_packet_h, (void *)ves->p);
err = ves->p->ovc->encupdh((struct videnc_state **)&ves->vesp, p->ovc,
prm, fmtp, enc_packet_h, (void *)ves->p);
if (err) {
mem_deref(ves);
return err;
Expand All @@ -208,7 +223,7 @@ static int encode(struct videnc_state *ves, bool update,

re_atomic_rlx_set(&last_keyframe, keyframe);

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


Expand Down Expand Up @@ -243,6 +258,7 @@ static int dec_update(struct viddec_state **vdsp, const struct vidcodec *vc,
const char *fmtp, const struct video *vid)
{
struct viddec_state *vds;
const struct vmix_vcproxy *p = (struct vmix_vcproxy *)vc;
int err;

vds = mem_zalloc(sizeof(struct viddec_state), NULL);
Expand All @@ -266,8 +282,8 @@ static int dec_update(struct viddec_state **vdsp, const struct vidcodec *vc,
return EINVAL;
}

err = vds->p->decupdh((struct viddec_state **)&vds->vdsp, vc, fmtp,
vid);
err = vds->p->ovc->decupdh((struct viddec_state **)&vds->vdsp, p->ovc,
fmtp, vid);
if (err) {
mem_deref(vds);
return err;
Expand Down Expand Up @@ -327,7 +343,7 @@ static int decode(struct viddec_state *vds, struct vidframe *frame,
}
mtx_unlock(vds->mtx);
#endif
return vds->p->dech(vds->vdsp, frame, vpkt);
return vds->p->ovc->dech(vds->vdsp, frame, vpkt);
}


Expand Down Expand Up @@ -396,39 +412,37 @@ void vmix_encode_flush(void)

static void proxy_codec_alloc(const char *name, const char *variant)
{
struct vmix_proxy *p;
struct vmix_vcproxy *p;
const struct vidcodec *v;

p = mem_zalloc(sizeof(struct vmix_proxy), NULL);
if (!p)
return;

/* Proxy functions */
p->codec.encupdh = enc_update;
p->codec.ench = encode;
p->codec.decupdh = dec_update;
p->codec.dech = decode;
p->codec.packetizeh = packetize;

v = vidcodec_find(baresip_vidcodecl(), name, variant);
if (!v) {
warning("vmix: proxy_codec_alloc find %s failed\n", name);
return;
}

p = mem_zalloc(sizeof(struct vmix_vcproxy), NULL);
if (!p)
return;


/* Proxy functions */
p->vc.name = name;
p->vc.variant = variant;
p->vc.encupdh = enc_update;
p->vc.ench = encode;
p->vc.decupdh = dec_update;
p->vc.dech = decode;
if (v->fmtp_ench)
p->vc.fmtp_ench = fmtp_ench;
if (v->fmtp_cmph)
p->vc.fmtp_cmph = fmtp_cmph;
p->vc.packetizeh = packetize;

/* Orignal functions */
p->codec.name = name;
p->codec.variant = variant;
p->codec.fmtp_ench = v->fmtp_ench;
p->codec.fmtp_cmph = v->fmtp_cmph;

p->encupdh = v->encupdh;
p->ench = v->ench;
p->decupdh = v->decupdh;
p->dech = v->dech;
p->packetizeh = v->packetizeh;

list_append(&proxyl, &p->le, p);
p->ovc = (void *)v;

list_append(&proxyl, &p->ple, p);
}


Expand All @@ -448,15 +462,16 @@ int vmix_codec_init(void)
#if 0
proxy_codec_alloc("H264", "packetization-mode=0");
proxy_codec_alloc("H264", "packetization-mode=1");
#endif
#else
proxy_codec_alloc("VP8", NULL);
#endif

list_clear(baresip_vidcodecl());

LIST_FOREACH(&proxyl, le)
{
struct vmix_proxy *p = le->data;
vidcodec_register(baresip_vidcodecl(), &p->codec);
struct vmix_vcproxy *p = le->data;
vidcodec_register(baresip_vidcodecl(), (struct vidcodec *)p);
}

return 0;
Expand All @@ -469,8 +484,8 @@ void vmix_codec_close(void)

LIST_FOREACH(&proxyl, le)
{
struct vmix_proxy *p = le->data;
vidcodec_unregister(&p->codec);
struct vmix_vcproxy *p = le->data;
vidcodec_unregister((struct vidcodec *)p);
}

list_flush(&proxyl);
Expand Down
13 changes: 13 additions & 0 deletions patches/baresip_2936.patch
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ index e26fb90e..00cd2d6f 100644
if (res) {
warning("vp8: codec ctrl: %s\n", vpx_codec_err_to_string(res));
}
diff --git a/modules/vp8/vp8.c b/modules/vp8/vp8.c
index 10b06f84..75d9b706 100644
--- a/modules/vp8/vp8.c
+++ b/modules/vp8/vp8.c
@@ -35,7 +35,7 @@ static struct vp8_vidcodec vp8 = {
.fmtp_ench = vp8_fmtp_enc,
.packetizeh = vp8_encode_packetize,
},
- .max_fs = 3600,
+ .max_fs = 8100, /* 1920 x 1080 / (16^2) */
};


diff --git a/src/config.c b/src/config.c
index 9b8698e7..31e43a14 100644
--- a/src/config.c
Expand Down

0 comments on commit b79f26e

Please sign in to comment.