From 5e364fb88b210e99ebc3fdeeb4ced89b231cddd4 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Tue, 12 Jul 2022 08:58:55 +0300 Subject: [PATCH] refactoring --- janus/src/client.c | 12 +++++------- janus/src/rtp.c | 7 +++++++ janus/src/rtp.h | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/janus/src/client.c b/janus/src/client.c index 6136460..b60d24f 100644 --- a/janus/src/client.c +++ b/janus/src/client.c @@ -55,10 +55,10 @@ void client_destroy(client_s *client) { } A_THREAD_JOIN(client->video_tid); - QUEUE_FREE_ITEMS_AND_DESTROY(client->video_queue, free); + QUEUE_FREE_ITEMS_AND_DESTROY(client->video_queue, rtp_destroy); if (client->audio_queue != NULL) { A_THREAD_JOIN(client->audio_tid); - QUEUE_FREE_ITEMS_AND_DESTROY(client->audio_queue, free); + QUEUE_FREE_ITEMS_AND_DESTROY(client->audio_queue, rtp_destroy); } free(client); } @@ -70,13 +70,11 @@ void client_send(client_s *client, const rtp_s *rtp) { ) { return; } - rtp_s *new; - A_CALLOC(new, 1); - memcpy(new, rtp, sizeof(rtp_s)); + rtp_s *new = rtp_dup(rtp); if (queue_put((new->video ? client->video_queue : client->audio_queue), new, 0) != 0) { JLOG_ERROR("client", "Session %p %s queue is full", client->session, (new->video ? "video" : "audio")); - free(new); + rtp_destroy(new); } } @@ -107,7 +105,7 @@ static void *_common_thread(void *v_client, bool video) { janus_plugin_rtp_extensions_reset(&packet.extensions); client->gw->relay_rtp(client->session, &packet); } - free(rtp); + rtp_destroy(rtp); } } return NULL; diff --git a/janus/src/rtp.c b/janus/src/rtp.c index 915112a..800d87d 100644 --- a/janus/src/rtp.c +++ b/janus/src/rtp.c @@ -35,6 +35,13 @@ rtp_s *rtp_init(unsigned payload, bool video) { return rtp; } +rtp_s *rtp_dup(const rtp_s *rtp) { + rtp_s *new; + A_CALLOC(new, 1); + memcpy(new, rtp, sizeof(rtp_s)); + return new; +} + void rtp_destroy(rtp_s *rtp) { free(rtp); } diff --git a/janus/src/rtp.h b/janus/src/rtp.h index 4b9c317..454224f 100644 --- a/janus/src/rtp.h +++ b/janus/src/rtp.h @@ -50,6 +50,7 @@ typedef void (*rtp_callback_f)(const rtp_s *rtp); rtp_s *rtp_init(unsigned payload, bool video); +rtp_s *rtp_dup(const rtp_s *rtp); void rtp_destroy(rtp_s *rtp); void rtp_write_header(rtp_s *rtp, uint32_t pts, bool marked);