summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/baresip.h6
-rw-r--r--modules/avcodec/avcodec.h9
-rw-r--r--modules/avcodec/encode.c27
-rw-r--r--modules/gst_video/encode.c13
-rw-r--r--modules/gst_video/gst_video.h6
-rw-r--r--modules/h265/encode.c17
-rw-r--r--modules/h265/h265.h6
-rw-r--r--modules/vidloop/vidloop.c6
-rw-r--r--modules/vpx/encode.c14
-rw-r--r--modules/vpx/vp8.h6
-rw-r--r--src/video.c5
11 files changed, 64 insertions, 51 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 675d8f0..dd9c1c2 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -735,10 +735,10 @@ typedef int (videnc_packet_h)(bool marker, const uint8_t *hdr, size_t hdr_len,
typedef int (videnc_update_h)(struct videnc_state **vesp,
const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp);
-typedef int (videnc_encode_h)(struct videnc_state *ves, bool update,
- const struct vidframe *frame,
+ struct videnc_param *prm, const char *fmtp,
videnc_packet_h *pkth, void *arg);
+typedef int (videnc_encode_h)(struct videnc_state *ves, bool update,
+ const struct vidframe *frame);
typedef int (viddec_update_h)(struct viddec_state **vdsp,
const struct vidcodec *vc, const char *fmtp);
diff --git a/modules/avcodec/avcodec.h b/modules/avcodec/avcodec.h
index 0b275f3..890df5f 100644
--- a/modules/avcodec/avcodec.h
+++ b/modules/avcodec/avcodec.h
@@ -26,13 +26,12 @@ extern const uint8_t h264_level_idc;
struct videnc_state;
int encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp);
-int encode(struct videnc_state *st, bool update, const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg);
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg);
+int encode(struct videnc_state *st, bool update, const struct vidframe *frame);
#ifdef USE_X264
int encode_x264(struct videnc_state *st, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg);
+ const struct vidframe *frame);
#endif
diff --git a/modules/avcodec/encode.c b/modules/avcodec/encode.c
index f68b31f..9d1f3a2 100644
--- a/modules/avcodec/encode.c
+++ b/modules/avcodec/encode.c
@@ -37,6 +37,8 @@ struct videnc_state {
struct videnc_param encprm;
struct vidsz encsize;
enum AVCodecID codec_id;
+ videnc_packet_h *pkth;
+ void *arg;
union {
struct {
@@ -408,12 +410,13 @@ static int open_encoder_x264(struct videnc_state *st, struct videnc_param *prm,
int encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp)
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg)
{
struct videnc_state *st;
int err = 0;
- if (!vesp || !vc || !prm)
+ if (!vesp || !vc || !prm || !pkth)
return EINVAL;
if (*vesp)
@@ -424,6 +427,8 @@ int encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
return ENOMEM;
st->encprm = *prm;
+ st->pkth = pkth;
+ st->arg = arg;
st->codec_id = avcodec_resolve_codecid(vc->name);
if (st->codec_id == AV_CODEC_ID_NONE) {
@@ -475,8 +480,7 @@ int encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
#ifdef USE_X264
int encode_x264(struct videnc_state *st, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg)
+ const struct vidframe *frame)
{
x264_picture_t pic_in, pic_out;
x264_nal_t *nal;
@@ -541,7 +545,7 @@ int encode_x264(struct videnc_state *st, bool update,
err = h264_nal_send(true, true, (i+1)==i_nal, hdr,
nal[i].p_payload + offset,
nal[i].i_payload - offset,
- st->encprm.pktsize, pkth, arg);
+ st->encprm.pktsize, st->pkth, st->arg);
}
return err;
@@ -549,12 +553,11 @@ int encode_x264(struct videnc_state *st, bool update,
#endif
-int encode(struct videnc_state *st, bool update, const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg)
+int encode(struct videnc_state *st, bool update, const struct vidframe *frame)
{
int i, err, ret;
- if (!st || !frame || !pkth || frame->fmt != VID_FMT_YUV420P)
+ if (!st || !frame || frame->fmt != VID_FMT_YUV420P)
return EINVAL;
if (!st->ctx || !vidsz_cmp(&st->encsize, &frame->size)) {
@@ -626,15 +629,17 @@ int encode(struct videnc_state *st, bool update, const struct vidframe *frame,
switch (st->codec_id) {
case AV_CODEC_ID_H263:
- err = h263_packetize(st, st->mb, pkth, arg);
+ err = h263_packetize(st, st->mb, st->pkth, st->arg);
break;
case AV_CODEC_ID_H264:
- err = h264_packetize(st->mb, st->encprm.pktsize, pkth, arg);
+ err = h264_packetize(st->mb, st->encprm.pktsize,
+ st->pkth, st->arg);
break;
case AV_CODEC_ID_MPEG4:
- err = general_packetize(st->mb, st->encprm.pktsize, pkth, arg);
+ err = general_packetize(st->mb, st->encprm.pktsize,
+ st->pkth, st->arg);
break;
default:
diff --git a/modules/gst_video/encode.c b/modules/gst_video/encode.c
index 50b9e48..948b98a 100644
--- a/modules/gst_video/encode.c
+++ b/modules/gst_video/encode.c
@@ -430,7 +430,8 @@ static void param_handler(const struct pl *name, const struct pl *val,
int gst_video_encode_update(struct videnc_state **vesp,
const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp)
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg)
{
struct videnc_state *ves;
int err = 0;
@@ -467,6 +468,8 @@ int gst_video_encode_update(struct videnc_state **vesp,
ves->bitrate = prm->bitrate;
ves->pktsize = prm->pktsize;
ves->fps = prm->fps;
+ ves->pkth = pkth;
+ ves->pkth_arg = arg;
info("gst_video: video encoder %s: %d fps, %d bit/s, pktsize=%u\n",
vc->name, prm->fps, prm->bitrate, prm->pktsize);
@@ -476,15 +479,14 @@ int gst_video_encode_update(struct videnc_state **vesp,
int gst_video_encode(struct videnc_state *st, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg)
+ const struct vidframe *frame)
{
uint8_t *data;
size_t size;
int height;
int err;
- if (!st || !frame || !pkth || frame->fmt != VID_FMT_YUV420P)
+ if (!st || !frame || frame->fmt != VID_FMT_YUV420P)
return EINVAL;
if (!st->gst_inited || !vidsz_cmp(&st->size, &frame->size)) {
@@ -497,9 +499,6 @@ int gst_video_encode(struct videnc_state *st, bool update,
return err;
}
- st->pkth = pkth;
- st->pkth_arg = arg;
-
/* To detect if requested size was changed. */
st->size = frame->size;
}
diff --git a/modules/gst_video/gst_video.h b/modules/gst_video/gst_video.h
index b77e979..16817e1 100644
--- a/modules/gst_video/gst_video.h
+++ b/modules/gst_video/gst_video.h
@@ -11,10 +11,10 @@ struct videnc_state;
int gst_video_encode_update(struct videnc_state **vesp,
const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp);
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg);
int gst_video_encode(struct videnc_state *st, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg);
+ const struct vidframe *frame);
/* SDP */
diff --git a/modules/h265/encode.c b/modules/h265/encode.c
index 7a42ea7..5ff16f9 100644
--- a/modules/h265/encode.c
+++ b/modules/h265/encode.c
@@ -20,6 +20,8 @@ struct videnc_state {
unsigned fps;
unsigned bitrate;
unsigned pktsize;
+ videnc_packet_h *pkth;
+ void *arg;
};
@@ -73,13 +75,14 @@ static int set_params(struct videnc_state *st, unsigned fps, unsigned bitrate)
int h265_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp)
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg)
{
struct videnc_state *ves;
int err = 0;
(void)fmtp;
- if (!vesp || !vc || !prm || prm->pktsize < 3)
+ if (!vesp || !vc || !prm || prm->pktsize < 3 || !pkth)
return EINVAL;
ves = *vesp;
@@ -105,6 +108,8 @@ int h265_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
ves->bitrate = prm->bitrate;
ves->pktsize = prm->pktsize;
ves->fps = prm->fps;
+ ves->pkth = pkth;
+ ves->arg = arg;
err = set_params(ves, prm->fps, prm->bitrate);
if (err)
@@ -175,8 +180,7 @@ static inline int packetize(bool marker, const uint8_t *buf, size_t len,
int h265_encode(struct videnc_state *st, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg)
+ const struct vidframe *frame)
{
x265_picture *pic_in = NULL, pic_out;
x265_nal *nalv;
@@ -184,7 +188,7 @@ int h265_encode(struct videnc_state *st, bool update,
int colorspace;
int n, err = 0;
- if (!st || !frame || !pkth)
+ if (!st || !frame)
return EINVAL;
switch (frame->fmt) {
@@ -261,7 +265,8 @@ int h265_encode(struct videnc_state *st, bool update,
marker = (i+1)==nalc; /* last NAL */
- err = packetize(marker, p, len, st->pktsize, pkth, arg);
+ err = packetize(marker, p, len, st->pktsize,
+ st->pkth, st->arg);
if (err)
goto out;
}
diff --git a/modules/h265/h265.h b/modules/h265/h265.h
index f537ea9..2705cf6 100644
--- a/modules/h265/h265.h
+++ b/modules/h265/h265.h
@@ -57,10 +57,10 @@ const char *h265_nalunit_name(enum h265_naltype type);
/* encoder */
int h265_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp);
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg);
int h265_encode(struct videnc_state *ves, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg);
+ const struct vidframe *frame);
/* decoder */
int h265_decode_update(struct viddec_state **vdsp, const struct vidcodec *vc,
diff --git a/modules/vidloop/vidloop.c b/modules/vidloop/vidloop.c
index aa5f7f9..ee24713 100644
--- a/modules/vidloop/vidloop.c
+++ b/modules/vidloop/vidloop.c
@@ -158,8 +158,7 @@ static void vidsrc_frame_handler(struct vidframe *frame, void *arg)
}
if (vl->vc_enc && vl->enc) {
- (void)vl->vc_enc->ench(vl->enc, false, frame,
- packet_handler, vl);
+ (void)vl->vc_enc->ench(vl->enc, false, frame);
}
else {
vl->stat.bytes += vidframe_size(frame->fmt, &frame->size);
@@ -214,7 +213,8 @@ static int enable_codec(struct video_loop *vl)
info("vidloop: enabled decoder %s\n", vl->vc_dec->name);
- err = vl->vc_enc->encupdh(&vl->enc, vl->vc_enc, &prm, NULL);
+ err = vl->vc_enc->encupdh(&vl->enc, vl->vc_enc, &prm, NULL,
+ packet_handler, vl);
if (err) {
warning("vidloop: update encoder failed: %m\n", err);
return err;
diff --git a/modules/vpx/encode.c b/modules/vpx/encode.c
index 82f6656..0106c0a 100644
--- a/modules/vpx/encode.c
+++ b/modules/vpx/encode.c
@@ -27,6 +27,8 @@ struct videnc_state {
unsigned pktsize;
bool ctxup;
uint16_t picid;
+ videnc_packet_h *pkth;
+ void *arg;
};
@@ -40,7 +42,8 @@ static void destructor(void *arg)
int vp8_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp)
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg)
{
const struct vp8_vidcodec *vp8 = (struct vp8_vidcodec *)vc;
struct videnc_state *ves;
@@ -74,6 +77,8 @@ int vp8_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
ves->bitrate = prm->bitrate;
ves->pktsize = prm->pktsize;
ves->fps = prm->fps;
+ ves->pkth = pkth;
+ ves->arg = arg;
max_fs = vp8_max_fs(fmtp);
if (max_fs > 0)
@@ -173,8 +178,7 @@ static inline int packetize(bool marker, const uint8_t *buf, size_t len,
int vp8_encode(struct videnc_state *ves, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg)
+ const struct vidframe *frame)
{
vpx_enc_frame_flags_t flags = 0;
vpx_codec_iter_t iter = NULL;
@@ -182,7 +186,7 @@ int vp8_encode(struct videnc_state *ves, bool update,
vpx_image_t img;
int err, i;
- if (!ves || !frame || !pkth || frame->fmt != VID_FMT_YUV420P)
+ if (!ves || !frame || frame->fmt != VID_FMT_YUV420P)
return EINVAL;
if (!ves->ctxup || !vidsz_cmp(&ves->size, &frame->size)) {
@@ -244,7 +248,7 @@ int vp8_encode(struct videnc_state *ves, bool update,
pkt->data.frame.buf,
pkt->data.frame.sz,
ves->pktsize, !keyframe, partid, ves->picid,
- pkth, arg);
+ ves->pkth, ves->arg);
if (err)
return err;
}
diff --git a/modules/vpx/vp8.h b/modules/vpx/vp8.h
index fb704c5..934e3ee 100644
--- a/modules/vpx/vp8.h
+++ b/modules/vpx/vp8.h
@@ -11,10 +11,10 @@ struct vp8_vidcodec {
/* Encode */
int vp8_encode_update(struct videnc_state **vesp, const struct vidcodec *vc,
- struct videnc_param *prm, const char *fmtp);
+ struct videnc_param *prm, const char *fmtp,
+ videnc_packet_h *pkth, void *arg);
int vp8_encode(struct videnc_state *ves, bool update,
- const struct vidframe *frame,
- videnc_packet_h *pkth, void *arg);
+ const struct vidframe *frame);
/* Decode */
diff --git a/src/video.c b/src/video.c
index 39909b5..86ac687 100644
--- a/src/video.c
+++ b/src/video.c
@@ -411,7 +411,7 @@ static void encode_rtp_send(struct vtx *vtx, struct vidframe *frame)
return;
/* Encode the whole picture frame */
- err = vtx->vc->ench(vtx->enc, vtx->picup, frame, packet_handler, vtx);
+ err = vtx->vc->ench(vtx->enc, vtx->picup, frame);
if (err)
return;
@@ -1038,7 +1038,8 @@ int video_encoder_set(struct video *v, struct vidcodec *vc,
vc->name, vc->variant, prm.bitrate, prm.fps);
vtx->enc = mem_deref(vtx->enc);
- err = vc->encupdh(&vtx->enc, vc, &prm, params);
+ err = vc->encupdh(&vtx->enc, vc, &prm, params,
+ packet_handler, vtx);
if (err) {
warning("video: encoder alloc: %m\n", err);
return err;