diff options
-rw-r--r-- | include/baresip.h | 1 | ||||
-rw-r--r-- | modules/vidloop/vidloop.c | 20 | ||||
-rw-r--r-- | src/config.c | 31 | ||||
-rw-r--r-- | src/video.c | 13 |
4 files changed, 45 insertions, 20 deletions
diff --git a/include/baresip.h b/include/baresip.h index 1e7e862..5ca2759 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -221,6 +221,7 @@ struct config_video { uint32_t bitrate; /**< Encoder bitrate in [bit/s] */ uint32_t fps; /**< Video framerate */ bool fullscreen; /**< Enable fullscreen display */ + int enc_fmt; /**< Encoder pixelfmt (enum vidfmt) */ }; #endif diff --git a/modules/vidloop/vidloop.c b/modules/vidloop/vidloop.c index d99fa49..6deddf2 100644 --- a/modules/vidloop/vidloop.c +++ b/modules/vidloop/vidloop.c @@ -32,12 +32,6 @@ */ -/** Internal pixel-format */ -#ifndef VIDLOOP_INTERNAL_FMT -#define VIDLOOP_INTERNAL_FMT (VID_FMT_YUV420P) -#endif - - /** Video Statistics */ struct vstat { uint64_t tsamp; @@ -181,17 +175,17 @@ static void vidsrc_frame_handler(struct vidframe *frame, void *arg) ++vl->stat.frames; - if (frame->fmt != VIDLOOP_INTERNAL_FMT) { + if (frame->fmt != vl->cfg.enc_fmt) { if (!vl->need_conv) { info("vidloop: NOTE: pixel-format conversion" " needed: %s --> %s\n", vidfmt_name(frame->fmt), - vidfmt_name(VIDLOOP_INTERNAL_FMT)); + vidfmt_name(vl->cfg.enc_fmt)); vl->need_conv = true; } - if (vidframe_alloc(&f2, VIDLOOP_INTERNAL_FMT, &frame->size)) + if (vidframe_alloc(&f2, vl->cfg.enc_fmt, &frame->size)) return; vidconv(f2, frame, 0); @@ -209,7 +203,10 @@ 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); + err = vl->vc_enc->ench(vl->enc, false, frame); + if (err) { + warning("vidloop: encoder error (%m)\n", err); + } } else { vl->stat.bytes += vidframe_size(frame->fmt, &frame->size); @@ -287,10 +284,11 @@ static void print_status(struct video_loop *vl) { (void)re_fprintf(stdout, "\rstatus:" - " [%s] [%s] intra=%zu " + " [%s] [%s] fmt=%s intra=%zu " " EFPS=%.1f %u kbit/s \r", vl->vc_enc ? vl->vc_enc->name : "", vl->vc_dec ? vl->vc_dec->name : "", + vidfmt_name(vl->cfg.enc_fmt), vl->stat.n_intra, vl->stat.efps, vl->stat.bitrate); fflush(stdout); diff --git a/src/config.c b/src/config.c index 77f4a5b..8727031 100644 --- a/src/config.c +++ b/src/config.c @@ -71,6 +71,7 @@ static struct config core_config = { 500000, 25, true, + VID_FMT_YUV420P, }, #endif @@ -180,6 +181,34 @@ static int conf_get_aufmt(const struct conf *conf, const char *name, } +static int conf_get_vidfmt(const struct conf *conf, const char *name, + int *fmtp) +{ + struct pl pl; + int fmt; + int err; + + err = conf_get(conf, name, &pl); + if (err) + return err; + + for (fmt=0; fmt<VID_FMT_N; fmt++) { + + const char *str = vidfmt_name(fmt); + + if (0 == pl_strcasecmp(&pl, str)) { + + *fmtp = fmt; + return 0; + } + } + + warning("config: %s: pixel format not supported (%r)\n", name, &pl); + + return ENOENT; +} + + /** * Parse the core configuration file and update baresip core config * @@ -290,6 +319,8 @@ int config_parse_conf(struct config *cfg, const struct conf *conf) (void)conf_get_u32(conf, "video_bitrate", &cfg->video.bitrate); (void)conf_get_u32(conf, "video_fps", &cfg->video.fps); (void)conf_get_bool(conf, "video_fullscreen", &cfg->video.fullscreen); + + conf_get_vidfmt(conf, "videnc_format", &cfg->video.enc_fmt); #else (void)size; #endif diff --git a/src/video.c b/src/video.c index a2e58bc..e1ff867 100644 --- a/src/video.c +++ b/src/video.c @@ -18,12 +18,6 @@ #include "magic.h" -/** Internal video-encoder format */ -#ifndef VIDENC_INTERNAL_FMT -#define VIDENC_INTERNAL_FMT (VID_FMT_YUV420P) -#endif - - enum { MAX_MUTED_FRAMES = 3, }; @@ -404,13 +398,14 @@ static void encode_rtp_send(struct vtx *vtx, struct vidframe *frame) lock_write_get(vtx->lock); /* Convert image */ - if (frame->fmt != VIDENC_INTERNAL_FMT) { + if (frame->fmt != vtx->video->cfg.enc_fmt) { vtx->vsrc_size = frame->size; if (!vtx->frame) { - err = vidframe_alloc(&vtx->frame, VIDENC_INTERNAL_FMT, + err = vidframe_alloc(&vtx->frame, + vtx->video->cfg.enc_fmt, &vtx->vsrc_size); if (err) goto unlock; @@ -941,7 +936,7 @@ static int set_encoder_format(struct vtx *vtx, const char *src, } vtx->mute_frame = mem_deref(vtx->mute_frame); - err = vidframe_alloc(&vtx->mute_frame, VIDENC_INTERNAL_FMT, size); + err = vidframe_alloc(&vtx->mute_frame, vtx->video->cfg.enc_fmt, size); if (err) return err; |