From 7db06fe42f40366c29ab328173ec6c2bffd9ba40 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 20 May 2017 20:19:50 +0200 Subject: vidcodec: make the API re-entrant --- include/baresip.h | 13 ++++++----- modules/av1/av1.c | 2 +- modules/avcodec/avcodec.c | 9 ++++---- modules/daala/daala.c | 2 +- modules/gst_video/gst_video.c | 2 +- modules/gst_video1/gst_video.c | 2 +- modules/h265/h265.c | 2 +- modules/v4l2_codec/v4l2_codec.c | 2 +- modules/vidloop/vidloop.c | 5 +++-- modules/vp8/vp8.c | 2 +- modules/vp9/vp9.c | 2 +- src/account.c | 6 +++-- src/baresip.c | 8 +++++++ src/conf.c | 2 +- src/vidcodec.c | 49 ++++++++++++++++++----------------------- src/video.c | 4 +++- test/mock/mock_vidcodec.c | 2 +- 17 files changed, 62 insertions(+), 52 deletions(-) diff --git a/include/baresip.h b/include/baresip.h index 748f1fd..4654415 100644 --- a/include/baresip.h +++ b/include/baresip.h @@ -883,12 +883,14 @@ struct vidcodec { sdp_fmtp_cmp_h *fmtp_cmph; }; -void vidcodec_register(struct vidcodec *vc); +void vidcodec_register(struct list *vidcodecl, struct vidcodec *vc); void vidcodec_unregister(struct vidcodec *vc); -const struct vidcodec *vidcodec_find(const char *name, const char *variant); -const struct vidcodec *vidcodec_find_encoder(const char *name); -const struct vidcodec *vidcodec_find_decoder(const char *name); -struct list *vidcodec_list(void); +const struct vidcodec *vidcodec_find(const struct list *vidcodecl, + const char *name, const char *variant); +const struct vidcodec *vidcodec_find_encoder(const struct list *vidcodecl, + const char *name); +const struct vidcodec *vidcodec_find_decoder(const struct list *vidcodecl, + const char *name); /* @@ -1139,6 +1141,7 @@ struct list *baresip_aucodecl(void); struct list *baresip_ausrcl(void); struct list *baresip_auplayl(void); struct list *baresip_aufiltl(void); +struct list *baresip_vidcodecl(void); #ifdef __cplusplus diff --git a/modules/av1/av1.c b/modules/av1/av1.c index 2c89ffb..e0590e4 100644 --- a/modules/av1/av1.c +++ b/modules/av1/av1.c @@ -29,7 +29,7 @@ static struct vidcodec av1 = { static int module_init(void) { - vidcodec_register(&av1); + vidcodec_register(baresip_vidcodecl(), &av1); return 0; } diff --git a/modules/avcodec/avcodec.c b/modules/avcodec/avcodec.c index 5144403..f8d9830 100644 --- a/modules/avcodec/avcodec.c +++ b/modules/avcodec/avcodec.c @@ -183,6 +183,7 @@ static struct vidcodec mpg4 = { static int module_init(void) { + struct list *vidcodecl = baresip_vidcodecl(); char h264enc[64]; char h264dec[64]; @@ -209,18 +210,18 @@ static int module_init(void) h264dec); return ENOENT; } - vidcodec_register(&h264); + vidcodec_register(vidcodecl, &h264); } else { if (avcodec_find_decoder(AV_CODEC_ID_H264)) - vidcodec_register(&h264); + vidcodec_register(vidcodecl, &h264); } if (avcodec_find_decoder(AV_CODEC_ID_H263)) - vidcodec_register(&h263); + vidcodec_register(vidcodecl, &h263); if (avcodec_find_decoder(AV_CODEC_ID_MPEG4)) - vidcodec_register(&mpg4); + vidcodec_register(vidcodecl, &mpg4); if (0 == conf_get_str(conf_cur(), "avcodec_h264enc", h264enc, sizeof(h264enc))) { diff --git a/modules/daala/daala.c b/modules/daala/daala.c index 112f49e..3ea7e27 100644 --- a/modules/daala/daala.c +++ b/modules/daala/daala.c @@ -41,7 +41,7 @@ static int module_init(void) { info("daala: using version '%s'\n", daala_version_string()); - vidcodec_register(&daala); + vidcodec_register(baresip_vidcodecl(), &daala); return 0; } diff --git a/modules/gst_video/gst_video.c b/modules/gst_video/gst_video.c index b0afa06..8807caf 100644 --- a/modules/gst_video/gst_video.c +++ b/modules/gst_video/gst_video.c @@ -40,7 +40,7 @@ static int module_init(void) { gst_init(NULL, NULL); - vidcodec_register(&h264); + vidcodec_register(baresip_vidcodecl(), &h264); info("gst_video: using gstreamer H.264 encoder\n"); diff --git a/modules/gst_video1/gst_video.c b/modules/gst_video1/gst_video.c index e0a4286..c15efac 100644 --- a/modules/gst_video1/gst_video.c +++ b/modules/gst_video1/gst_video.c @@ -40,7 +40,7 @@ static int module_init(void) { gst_init(NULL, NULL); - vidcodec_register(&h264); + vidcodec_register(baresip_vidcodecl(), &h264); info("gst_video: using gstreamer (%s)\n", gst_version_string()); diff --git a/modules/h265/h265.c b/modules/h265/h265.c index 5f1dfa6..fc289e2 100644 --- a/modules/h265/h265.c +++ b/modules/h265/h265.c @@ -45,7 +45,7 @@ static int module_init(void) avcodec_register_all(); - vidcodec_register(&h265); + vidcodec_register(baresip_vidcodecl(), &h265); return 0; } diff --git a/modules/v4l2_codec/v4l2_codec.c b/modules/v4l2_codec/v4l2_codec.c index 83eedf2..bf77029 100644 --- a/modules/v4l2_codec/v4l2_codec.c +++ b/modules/v4l2_codec/v4l2_codec.c @@ -562,7 +562,7 @@ static int module_init(void) { info("v4l2_codec inited\n"); - vidcodec_register(&h264); + vidcodec_register(baresip_vidcodecl(), &h264); return vidsrc_register(&vidsrc, "v4l2_codec", src_alloc, NULL); } diff --git a/modules/vidloop/vidloop.c b/modules/vidloop/vidloop.c index 513af7d..69dbb56 100644 --- a/modules/vidloop/vidloop.c +++ b/modules/vidloop/vidloop.c @@ -233,6 +233,7 @@ static void vidloop_destructor(void *arg) static int enable_codec(struct video_loop *vl, const char *name) { + struct list *vidcodecl = baresip_vidcodecl(); struct videnc_param prm; int err; @@ -243,7 +244,7 @@ static int enable_codec(struct video_loop *vl, const char *name) /* Use the first video codec */ - vl->vc_enc = vidcodec_find_encoder(name); + vl->vc_enc = vidcodec_find_encoder(vidcodecl, name); if (!vl->vc_enc) { warning("vidloop: could not find encoder (%s)\n", name); return ENOENT; @@ -252,7 +253,7 @@ static int enable_codec(struct video_loop *vl, const char *name) info("vidloop: enabled encoder %s (%u fps, %u bit/s)\n", vl->vc_enc->name, prm.fps, prm.bitrate); - vl->vc_dec = vidcodec_find_decoder(name); + vl->vc_dec = vidcodec_find_decoder(vidcodecl, name); if (!vl->vc_dec) { warning("vidloop: could not find decoder (%s)\n", name); return ENOENT; diff --git a/modules/vp8/vp8.c b/modules/vp8/vp8.c index acaad12..18937d3 100644 --- a/modules/vp8/vp8.c +++ b/modules/vp8/vp8.c @@ -40,7 +40,7 @@ static struct vp8_vidcodec vp8 = { static int module_init(void) { - vidcodec_register((struct vidcodec *)&vp8); + vidcodec_register(baresip_vidcodecl(), (struct vidcodec *)&vp8); return 0; } diff --git a/modules/vp9/vp9.c b/modules/vp9/vp9.c index 676d5c5..44a7481 100644 --- a/modules/vp9/vp9.c +++ b/modules/vp9/vp9.c @@ -44,7 +44,7 @@ static struct vp9_vidcodec vp9 = { static int module_init(void) { - vidcodec_register((struct vidcodec *)&vp9); + vidcodec_register(baresip_vidcodecl(), (struct vidcodec *)&vp9); return 0; } diff --git a/src/account.c b/src/account.c index 6142a2e..e23d5c8 100644 --- a/src/account.c +++ b/src/account.c @@ -245,6 +245,7 @@ static int audio_codecs_decode(struct account *acc, const struct pl *prm) #ifdef USE_VIDEO static int video_codecs_decode(struct account *acc, const struct pl *prm) { + struct list *vidcodecl = baresip_vidcodecl(); struct pl tmp; if (!acc || !prm) @@ -263,7 +264,8 @@ static int video_codecs_decode(struct account *acc, const struct pl *prm) while (0 == csl_parse(&vcs, cname, sizeof(cname))) { struct vidcodec *vc; - vc = (struct vidcodec *)vidcodec_find(cname, NULL); + vc = (struct vidcodec *)vidcodec_find(vidcodecl, + cname, NULL); if (!vc) { warning("account: video codec not found: %s\n", cname); @@ -487,7 +489,7 @@ struct list *account_aucodecl(const struct account *acc) struct list *account_vidcodecl(const struct account *acc) { return (acc && !list_isempty(&acc->vidcodecl)) - ? (struct list *)&acc->vidcodecl : vidcodec_list(); + ? (struct list *)&acc->vidcodecl : baresip_vidcodecl(); } #endif diff --git a/src/baresip.c b/src/baresip.c index dbed532..ce3f1aa 100644 --- a/src/baresip.c +++ b/src/baresip.c @@ -24,6 +24,7 @@ static struct baresip { struct list ausrcl; struct list auplayl; struct list aufiltl; + struct list vidcodecl; } baresip; @@ -41,6 +42,7 @@ int baresip_init(struct config *cfg, bool prefer_ipv6) list_init(&baresip.aucodecl); list_init(&baresip.ausrcl); list_init(&baresip.auplayl); + list_init(&baresip.vidcodecl); /* Initialise Network */ err = net_alloc(&baresip.net, &cfg->net, @@ -152,3 +154,9 @@ struct list *baresip_aufiltl(void) { return &baresip.aufiltl; } + + +struct list *baresip_vidcodecl(void) +{ + return &baresip.vidcodecl; +} diff --git a/src/conf.c b/src/conf.c index 9a85c5d..7f7441b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -355,7 +355,7 @@ int conf_modules(void) print_populated("audio codec", list_count(baresip_aucodecl())); print_populated("audio filter", list_count(baresip_aufiltl())); #ifdef USE_VIDEO - print_populated("video codec", list_count(vidcodec_list())); + print_populated("video codec", list_count(baresip_vidcodecl())); print_populated("video filter", list_count(vidfilt_list())); #endif diff --git a/src/vidcodec.c b/src/vidcodec.c index 620674a..cd335ad 100644 --- a/src/vidcodec.c +++ b/src/vidcodec.c @@ -8,20 +8,18 @@ #include -static struct list vidcodecl; - - /** * Register a Video Codec * - * @param vc Video Codec + * @param vidcodecl List of video-codecs + * @param vc Video Codec */ -void vidcodec_register(struct vidcodec *vc) +void vidcodec_register(struct list *vidcodecl, struct vidcodec *vc) { - if (!vc) + if (!vidcodecl || !vc) return; - list_append(&vidcodecl, &vc->le, vc); + list_append(vidcodecl, &vc->le, vc); info("vidcodec: %s\n", vc->name); } @@ -44,16 +42,18 @@ void vidcodec_unregister(struct vidcodec *vc) /** * Find a Video Codec by name * - * @param name Name of the Video Codec to find - * @param variant Codec Variant + * @param vidcodecl List of video-codecs + * @param name Name of the Video Codec to find + * @param variant Codec Variant * * @return Matching Video Codec if found, otherwise NULL */ -const struct vidcodec *vidcodec_find(const char *name, const char *variant) +const struct vidcodec *vidcodec_find(const struct list *vidcodecl, + const char *name, const char *variant) { struct le *le; - for (le=vidcodecl.head; le; le=le->next) { + for (le=list_head(vidcodecl); le; le=le->next) { struct vidcodec *vc = le->data; @@ -73,15 +73,17 @@ const struct vidcodec *vidcodec_find(const char *name, const char *variant) /** * Find a Video Encoder by name * - * @param name Name of the Video Encoder to find + * @param vidcodecl List of video-codecs + * @param name Name of the Video Encoder to find * * @return Matching Video Encoder if found, otherwise NULL */ -const struct vidcodec *vidcodec_find_encoder(const char *name) +const struct vidcodec *vidcodec_find_encoder(const struct list *vidcodecl, + const char *name) { struct le *le; - for (le=vidcodecl.head; le; le=le->next) { + for (le=list_head(vidcodecl); le; le=le->next) { struct vidcodec *vc = le->data; @@ -99,15 +101,17 @@ const struct vidcodec *vidcodec_find_encoder(const char *name) /** * Find a Video Decoder by name * - * @param name Name of the Video Decoder to find + * @param vidcodecl List of video-codecs + * @param name Name of the Video Decoder to find * * @return Matching Video Decoder if found, otherwise NULL */ -const struct vidcodec *vidcodec_find_decoder(const char *name) +const struct vidcodec *vidcodec_find_decoder(const struct list *vidcodecl, + const char *name) { struct le *le; - for (le=vidcodecl.head; le; le=le->next) { + for (le=list_head(vidcodecl); le; le=le->next) { struct vidcodec *vc = le->data; @@ -120,14 +124,3 @@ const struct vidcodec *vidcodec_find_decoder(const char *name) return NULL; } - - -/** - * Get the list of Video Codecs - * - * @return List of Video Codecs - */ -struct list *vidcodec_list(void) -{ - return &vidcodecl; -} diff --git a/src/video.c b/src/video.c index 2d6a470..9c1ec56 100644 --- a/src/video.c +++ b/src/video.c @@ -1142,11 +1142,13 @@ int video_decoder_set(struct video *v, struct vidcodec *vc, int pt_rx, /* handle vidcodecs without a decoder */ if (!vc->decupdh) { + struct list *vidcodecl = baresip_vidcodecl(); struct vidcodec *vcd; info("video: vidcodec '%s' has no decoder\n", vc->name); - vcd = (struct vidcodec *)vidcodec_find_decoder(vc->name); + vcd = (struct vidcodec *)vidcodec_find_decoder(vidcodecl, + vc->name); if (!vcd) { warning("video: could not find decoder (%s)\n", vc->name); diff --git a/test/mock/mock_vidcodec.c b/test/mock/mock_vidcodec.c index 037a0b9..745e43f 100644 --- a/test/mock/mock_vidcodec.c +++ b/test/mock/mock_vidcodec.c @@ -194,7 +194,7 @@ static struct vidcodec vc_dummy = { void mock_vidcodec_register(void) { - vidcodec_register(&vc_dummy); + vidcodec_register(baresip_vidcodecl(), &vc_dummy); } -- cgit v1.2.3