From 5fe68b909777ce763b3a255efb9cee2c099db1df Mon Sep 17 00:00:00 2001 From: Dylan Mikus Date: Mon, 21 Mar 2016 20:36:39 +0000 Subject: [PATCH] Link recording metadata SDP to RTP packet numbers We write out what RTP packet number the SDP came before. When we receive an SDP offer or answer, we write out the RTP packet number that the SDP preceeded. This will let us split the RTP recording PCAP around SDP renegotiation for things like hold/unhold. Also write out whether the SDP was an offer or an answer. --- daemon/call_interfaces.c | 3 ++- daemon/media_socket.c | 1 + daemon/recording.c | 14 ++++++++++++-- daemon/recording.h | 4 +++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 206e9b15d..f1eda99cb 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -744,7 +744,8 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster if (call->record_call && recording != NULL && recording->meta_fp != NULL) { struct iovec *iov = &g_array_index(chopper->iov, struct iovec, 0); int iovcnt = chopper->iov_num; - meta_write_sdp(recording->meta_fp, iov, iovcnt); + meta_write_sdp(recording->meta_fp, iov, iovcnt, + call->recording->packet_num, opmode); } bencode_dictionary_get_str(input, "metadata", &metadata); if (metadata.len > 0 && call->recording != NULL) { diff --git a/daemon/media_socket.c b/daemon/media_socket.c index dba3aa354..a2da1349b 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1202,6 +1202,7 @@ loop_ok: // If recording pcap dumper is set, then we record the call. if (recording_pdumper != NULL && call->record_call) { stream_pcap_dump(recording_pdumper, stream, s); + call->recording->packet_num += 1; } if (handler_ret >= 0) { diff --git a/daemon/recording.c b/daemon/recording.c index 3bd6b7d8d..4db0fb87d 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -136,6 +136,7 @@ int set_record_call(struct call *call, str recordcall) { call->recording = g_slice_alloc0(sizeof(struct recording)); call->recording->recording_pd = NULL; call->recording->recording_pdumper = NULL; + call->recording->packet_num = 0; meta_setup_file(call->recording, call->callid); } } else if (!str_cmp(&recordcall, "no")) { @@ -204,12 +205,21 @@ str *meta_setup_file(struct recording *recording, str callid) { /** * Write out a block of SDP to the metadata file. */ -ssize_t meta_write_sdp(FILE *meta_fp, struct iovec *sdp_iov, int iovcnt) { - fprintf(meta_fp, "\n"); +ssize_t meta_write_sdp(FILE *meta_fp, struct iovec *sdp_iov, int iovcnt, + uint64_t packet_num, enum call_opmode opmode) { int meta_fd = fileno(meta_fp); // File pointers buffer data, whereas direct writing using the file // descriptor does not. Make sure to flush any unwritten contents // so the file contents appear in order. + fprintf(meta_fp, "\nSDP mode: "); + if (opmode == OP_ANSWER) { + fprintf(meta_fp, "answer"); + } else if (opmode == OP_OFFER) { + fprintf(meta_fp, "offer"); + } else { + fprintf(meta_fp, "other"); + } + fprintf(meta_fp, "\nSDP before RTP packet: %llu\n\n", packet_num); fflush(meta_fp); return writev(meta_fd, sdp_iov, iovcnt); } diff --git a/daemon/recording.h b/daemon/recording.h index 824d8132e..2f83b979e 100644 --- a/daemon/recording.h +++ b/daemon/recording.h @@ -20,6 +20,7 @@ struct recording { str *metadata; pcap_t *recording_pd; pcap_dumper_t *recording_pdumper; + uint64_t *packet_num; str *recording_path; }; @@ -79,7 +80,8 @@ str *meta_setup_file(struct recording *recording, str callid); /** * Write out a block of SDP to the metadata file. */ -ssize_t meta_write_sdp(FILE *meta_fp, struct iovec *sdp_iov, int iovcnt); +ssize_t meta_write_sdp(FILE *meta_fp, struct iovec *sdp_iov, int iovcnt, + uint64_t packet_num, enum call_opmode opmode); /** * Writes metadata to metafile, closes file, and moves it to finished location.