diff --git a/daemon/call.c b/daemon/call.c index 7729d4840..f11e6d2ea 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2490,10 +2490,8 @@ static void __call_free(void *p) { crypto_cleanup(&ps->crypto); g_queue_clear(&ps->sfds); g_hash_table_destroy(ps->rtp_stats); - if (ps->ssrc_in) - obj_put(&ps->ssrc_in->parent->h); - if (ps->ssrc_out) - obj_put(&ps->ssrc_out->parent->h); + ssrc_ctx_put(&ps->ssrc_in); + ssrc_ctx_put(&ps->ssrc_out); g_slice_free1(sizeof(*ps), ps); } diff --git a/daemon/media_player.c b/daemon/media_player.c index 91ca9c910..7f43dfcaf 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -92,9 +92,7 @@ static void __media_player_free(void *p) { ilog(LOG_DEBUG, "freeing media_player"); media_player_shutdown(mp); - if (mp->ssrc_out) - obj_put(&mp->ssrc_out->parent->h); - mp->ssrc_out = NULL; + ssrc_ctx_put(&mp->ssrc_out); mutex_destroy(&mp->lock); obj_put(mp->call); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 64d94e894..8565f0883 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1285,17 +1285,14 @@ static void __stream_ssrc(struct packet_stream *in_srtp, struct packet_stream *o mutex_lock(&in_srtp->in_lock); (*ssrc_in_p) = in_srtp->ssrc_in; - if (*ssrc_in_p) - obj_hold(&(*ssrc_in_p)->parent->h); + ssrc_ctx_hold(*ssrc_in_p); if (G_UNLIKELY(!(*ssrc_in_p) || (*ssrc_in_p)->parent->h.ssrc != in_ssrc)) { // SSRC mismatch - get the new entry - if (*ssrc_in_p) - obj_put(&(*ssrc_in_p)->parent->h); - if (in_srtp->ssrc_in) - obj_put(&in_srtp->ssrc_in->parent->h); + ssrc_ctx_put(ssrc_in_p); + ssrc_ctx_put(&in_srtp->ssrc_in); (*ssrc_in_p) = in_srtp->ssrc_in = get_ssrc_ctx(in_ssrc, ssrc_hash, SSRC_DIR_INPUT); - obj_hold(&in_srtp->ssrc_in->parent->h); + ssrc_ctx_hold(in_srtp->ssrc_in); // might have created a new entry, which would have a new random // ssrc_map_out. we don't need this if we're not transcoding @@ -1310,17 +1307,14 @@ static void __stream_ssrc(struct packet_stream *in_srtp, struct packet_stream *o mutex_lock(&out_srtp->out_lock); (*ssrc_out_p) = out_srtp->ssrc_out; - if (*ssrc_out_p) - obj_hold(&(*ssrc_out_p)->parent->h); + ssrc_ctx_hold(*ssrc_out_p); if (G_UNLIKELY(!(*ssrc_out_p) || (*ssrc_out_p)->parent->h.ssrc != out_ssrc)) { // SSRC mismatch - get the new entry - if (*ssrc_out_p) - obj_put(&(*ssrc_out_p)->parent->h); - if (out_srtp->ssrc_out) - obj_put(&out_srtp->ssrc_out->parent->h); + ssrc_ctx_put(ssrc_out_p); + ssrc_ctx_put(&out_srtp->ssrc_out); (*ssrc_out_p) = out_srtp->ssrc_out = get_ssrc_ctx(out_ssrc, ssrc_hash, SSRC_DIR_OUTPUT); - obj_hold(&out_srtp->ssrc_out->parent->h); + ssrc_ctx_hold(out_srtp->ssrc_out); // reverse SSRC mapping (*ssrc_out_p)->ssrc_map_out = in_ssrc; @@ -1904,14 +1898,8 @@ out: g_queue_clear_full(&phc->mp.packets_out, codec_packet_free); - if (phc->mp.ssrc_in) { - obj_put(&phc->mp.ssrc_in->parent->h); - phc->mp.ssrc_in = NULL; - } - if (phc->mp.ssrc_out) { - obj_put(&phc->mp.ssrc_out->parent->h); - phc->mp.ssrc_out = NULL; - } + ssrc_ctx_put(&phc->mp.ssrc_in); + ssrc_ctx_put(&phc->mp.ssrc_out); return ret; } diff --git a/include/ssrc.h b/include/ssrc.h index b066ea27b..a87b8889d 100644 --- a/include/ssrc.h +++ b/include/ssrc.h @@ -204,5 +204,22 @@ void payload_tracker_init(struct payload_tracker *t); void payload_tracker_add(struct payload_tracker *, int); +INLINE void ssrc_ctx_put(struct ssrc_ctx **c) { + if (!c || !*c) + return; + obj_put(&(*c)->parent->h); + *c = NULL; +} +INLINE struct ssrc_ctx *ssrc_ctx_get(struct ssrc_ctx *c) { + if (!c) + return NULL; + obj_hold(&c->parent->h); + return c; +} +INLINE void ssrc_ctx_hold(struct ssrc_ctx *c) { + ssrc_ctx_get(c); +} + + #endif