rtp_engine.c: Eliminate rtcp_report_to_json() RAII_VAR usage.

Change-Id: I58a22c2ca82e91d7537409b7b3af2d735827a54d
This commit is contained in:
Richard Mudgett
2015-11-11 16:52:45 -06:00
parent 11a1e07ad2
commit 7054fb8756

View File

@@ -3092,10 +3092,10 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
const struct stasis_message_sanitizer *sanitize) const struct stasis_message_sanitizer *sanitize)
{ {
struct rtcp_message_payload *payload = stasis_message_data(msg); struct rtcp_message_payload *payload = stasis_message_data(msg);
RAII_VAR(struct ast_json *, json_rtcp_report, NULL, ast_json_unref); struct ast_json *json_rtcp_report = NULL;
RAII_VAR(struct ast_json *, json_rtcp_report_blocks, NULL, ast_json_unref); struct ast_json *json_rtcp_report_blocks;
RAII_VAR(struct ast_json *, json_rtcp_sender_info, NULL, ast_json_unref); struct ast_json *json_rtcp_sender_info = NULL;
RAII_VAR(struct ast_json *, json_channel, NULL, ast_json_unref); struct ast_json *json_channel = NULL;
int i; int i;
json_rtcp_report_blocks = ast_json_array_create(); json_rtcp_report_blocks = ast_json_array_create();
@@ -3106,6 +3106,7 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
for (i = 0; i < payload->report->reception_report_count && payload->report->report_block[i]; i++) { for (i = 0; i < payload->report->reception_report_count && payload->report->report_block[i]; i++) {
struct ast_json *json_report_block; struct ast_json *json_report_block;
char str_lsr[32]; char str_lsr[32];
snprintf(str_lsr, sizeof(str_lsr), "%u", payload->report->report_block[i]->lsr); snprintf(str_lsr, sizeof(str_lsr), "%u", payload->report->report_block[i]->lsr);
json_report_block = ast_json_pack("{s: i, s: i, s: i, s: i, s: i, s: s, s: i}", json_report_block = ast_json_pack("{s: i, s: i, s: i, s: i, s: i, s: s, s: i}",
"source_ssrc", payload->report->report_block[i]->source_ssrc, "source_ssrc", payload->report->report_block[i]->source_ssrc,
@@ -3115,11 +3116,9 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
"ia_jitter", payload->report->report_block[i]->ia_jitter, "ia_jitter", payload->report->report_block[i]->ia_jitter,
"lsr", str_lsr, "lsr", str_lsr,
"dlsr", payload->report->report_block[i]->dlsr); "dlsr", payload->report->report_block[i]->dlsr);
if (!json_report_block) { if (!json_report_block
return NULL; || ast_json_array_append(json_rtcp_report_blocks, json_report_block)) {
} ast_json_unref(json_rtcp_report_blocks);
if (ast_json_array_append(json_rtcp_report_blocks, json_report_block)) {
return NULL; return NULL;
} }
} }
@@ -3127,6 +3126,7 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
if (payload->report->type == AST_RTP_RTCP_SR) { if (payload->report->type == AST_RTP_RTCP_SR) {
char sec[32]; char sec[32];
char usec[32]; char usec[32];
snprintf(sec, sizeof(sec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec); snprintf(sec, sizeof(sec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec);
snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec); snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: i, s: i, s: i}", json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: i, s: i, s: i}",
@@ -3136,6 +3136,7 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
"packets", payload->report->sender_information.packet_count, "packets", payload->report->sender_information.packet_count,
"octets", payload->report->sender_information.octet_count); "octets", payload->report->sender_information.octet_count);
if (!json_rtcp_sender_info) { if (!json_rtcp_sender_info) {
ast_json_unref(json_rtcp_report_blocks);
return NULL; return NULL;
} }
} }
@@ -3144,8 +3145,8 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
"ssrc", payload->report->ssrc, "ssrc", payload->report->ssrc,
"type", payload->report->type, "type", payload->report->type,
"report_count", payload->report->reception_report_count, "report_count", payload->report->reception_report_count,
"sender_information", json_rtcp_sender_info ? ast_json_ref(json_rtcp_sender_info) : ast_json_ref(ast_json_null()), "sender_information", json_rtcp_sender_info ?: ast_json_null(),
"report_blocks", ast_json_ref(json_rtcp_report_blocks)); "report_blocks", json_rtcp_report_blocks);
if (!json_rtcp_report) { if (!json_rtcp_report) {
return NULL; return NULL;
} }
@@ -3153,14 +3154,15 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
if (payload->snapshot) { if (payload->snapshot) {
json_channel = ast_channel_snapshot_to_json(payload->snapshot, sanitize); json_channel = ast_channel_snapshot_to_json(payload->snapshot, sanitize);
if (!json_channel) { if (!json_channel) {
ast_json_unref(json_rtcp_report);
return NULL; return NULL;
} }
} }
return ast_json_pack("{s: o, s: o, s: o}", return ast_json_pack("{s: o, s: o, s: o}",
"channel", payload->snapshot ? ast_json_ref(json_channel) : ast_json_ref(ast_json_null()), "channel", payload->snapshot ? json_channel : ast_json_null(),
"rtcp_report", ast_json_ref(json_rtcp_report), "rtcp_report", json_rtcp_report,
"blob", ast_json_deep_copy(payload->blob)); "blob", ast_json_deep_copy(payload->blob) ?: ast_json_null());
} }
static void rtp_rtcp_report_dtor(void *obj) static void rtp_rtcp_report_dtor(void *obj)