diff options
author | Mamadou DIOP <bossiel@yahoo.fr> | 2015-08-17 01:56:35 +0200 |
---|---|---|
committer | Mamadou DIOP <bossiel@yahoo.fr> | 2015-08-17 01:56:35 +0200 |
commit | 631fffee8a28b1bec5ed1f1d26a20e0135967f99 (patch) | |
tree | 74afe3bf3efe15aa82bcd0272b2b0f4d48c2d837 /tinyRTP/include/tinyrtp | |
parent | 7908865936604036e6f200f1b5e069f8752f3a3a (diff) | |
download | doubango-631fffee8a28b1bec5ed1f1d26a20e0135967f99.zip doubango-631fffee8a28b1bec5ed1f1d26a20e0135967f99.tar.gz |
-
Diffstat (limited to 'tinyRTP/include/tinyrtp')
19 files changed, 1419 insertions, 0 deletions
diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_header.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_header.h new file mode 100644 index 0000000..9cf6a1a --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_header.h @@ -0,0 +1,62 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_HEADER_H +#define TINYRTP_RTCP_HEADER_H + +#include "tinyrtp_config.h" +#include "tinyrtp/rtcp/trtp_rtcp_packet.h" + +#include "tsk_buffer.h" +#include "tsk_list.h" + +#define TRTP_RTCP_HEADER_SIZE 4 +#define TRTP_RTCP_HEADER_VERSION_DEFAULT 2 + +TRTP_BEGIN_DECLS + +typedef struct trtp_rtcp_header_s +{ + TSK_DECLARE_OBJECT; + + unsigned version:2; + unsigned padding:1; + unsigned rc:5; + trtp_rtcp_packet_type_t type; /**< Packet Type on 8bits */ + uint16_t length_in_words_minus1; /**< The length of this RTCP packet in 32-bit words minus one */ + uint32_t length_in_bytes; +} +trtp_rtcp_header_t; + +#define TRTP_DECLARE_RTCP_HEADER trtp_rtcp_header_t __header__ +typedef tsk_list_t trtp_rtcp_headers_L_t; /**< List of @ref trtp_rtcp_header_t elements */ + +TINYRTP_API trtp_rtcp_header_t* trtp_rtcp_header_create_null(); +TINYRTP_API trtp_rtcp_header_t* trtp_rtcp_header_create(uint8_t version, uint8_t padding, uint8_t rc, trtp_rtcp_packet_type_t type, uint16_t length_in_bytes); +TINYRTP_API int trtp_rtcp_header_serialize_to(const trtp_rtcp_header_t *self, void* data, tsk_size_t size); +TINYRTP_API trtp_rtcp_header_t* trtp_rtcp_header_deserialize(const void *data, tsk_size_t size); +TINYRTP_API int trtp_rtcp_header_deserialize_to(trtp_rtcp_header_t** self, const void *data, tsk_size_t size); + +TINYRTP_GEXTERN const tsk_object_def_t *trtp_rtcp_header_def_t; + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_HEADER_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_packet.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_packet.h new file mode 100644 index 0000000..9045be7 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_packet.h @@ -0,0 +1,74 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_PACKET_H +#define TINYRTP_RTCP_PACKET_H + +#include "tinyrtp_config.h" + +#include "tsk_buffer.h" +#include "tsk_list.h" + +TRTP_BEGIN_DECLS + +#define TRTP_RTCP_PACKET(self) ((trtp_rtcp_packet_t*)(self)) +#define TRTP_DECLARE_RTCP_PACKET trtp_rtcp_packet_t __packet__ + +// RFC 3550 12.1 RTCP Packet Types +// RFC 4585 +// RFC 5104 (FIXME: not supported yet!) +typedef enum trtp_rtcp_packet_type_e +{ + trtp_rtcp_packet_type_sr = 200, + trtp_rtcp_packet_type_rr = 201, + trtp_rtcp_packet_type_sdes = 202, + trtp_rtcp_packet_type_bye = 203, + trtp_rtcp_packet_type_app = 204, + trtp_rtcp_packet_type_rtpfb = 205, + trtp_rtcp_packet_type_psfb = 206 +} +trtp_rtcp_packet_type_t; + +typedef struct trtp_rtcp_packet_s +{ + TSK_DECLARE_OBJECT; + + struct trtp_rtcp_header_s *header; +} +trtp_rtcp_packet_t; + +typedef tsk_list_t trtp_rtcp_packets_L_t; /**< List of @ref trtp_rtcp_packet_t elements */ + +trtp_rtcp_packet_t* trtp_rtcp_packet_create(struct trtp_rtcp_header_s* header); +int trtp_rtcp_packet_init(trtp_rtcp_packet_t* self, uint8_t version, uint8_t padding, uint8_t rc, trtp_rtcp_packet_type_t type, uint16_t length_in_bytes); +trtp_rtcp_packet_t* trtp_rtcp_packet_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_packet_serialize_to(const trtp_rtcp_packet_t* self, void* data, tsk_size_t size); +tsk_buffer_t* trtp_rtcp_packet_serialize(const trtp_rtcp_packet_t* self, tsk_size_t num_bytes_pad); +int trtp_rtcp_packet_add_packet(trtp_rtcp_packet_t* self, trtp_rtcp_packet_t* packet, tsk_bool_t front); +TINYRTP_API const trtp_rtcp_packet_t* trtp_rtcp_packet_get_at(const trtp_rtcp_packet_t* self, trtp_rtcp_packet_type_t type, tsk_size_t index); +TINYRTP_API const trtp_rtcp_packet_t* trtp_rtcp_packet_get(const trtp_rtcp_packet_t* self, trtp_rtcp_packet_type_t type); +tsk_size_t trtp_rtcp_packet_get_size(const trtp_rtcp_packet_t* self); + +int trtp_rtcp_packet_deinit(trtp_rtcp_packet_t* self); + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_PACKET_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_rblock.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_rblock.h new file mode 100644 index 0000000..5ea54e6 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_rblock.h @@ -0,0 +1,59 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_RB_H +#define TINYRTP_RTCP_REPORT_RB_H + +#include "tinyrtp_config.h" + +#include "tsk_list.h" + +TRTP_BEGIN_DECLS + +#define TRTP_RTCP_RBLOCK_SIZE 24 + +#define TRTP_RTCP_RBLOCK(self) ((trtp_rtcp_rblock_t*)(self)) + +// RFC 3550 6.4.1 SR: Sender Report RTCP Packet => Report block part +typedef struct trtp_rtcp_rblock_s +{ + TSK_DECLARE_OBJECT; + + uint32_t ssrc; /* data source being reported */ + unsigned int fraction:8; /* fraction lost since last SR/RR */ + int cumulative_no_lost:24; /* cumul. no. pkts lost (signed!) */ + uint32_t last_seq; /* extended last seq. no. received */ + uint32_t jitter; /* interarrival jitter */ + uint32_t lsr; /* last SR packet from this source */ + uint32_t dlsr; /* delay since last SR packet */ +} +trtp_rtcp_rblock_t; + +typedef tsk_list_t trtp_rtcp_rblocks_L_t; /**< List of @ref trtp_rtcp_rblock_t elements */ + +trtp_rtcp_rblock_t* trtp_rtcp_rblock_create_null(); +trtp_rtcp_rblock_t* trtp_rtcp_rblock_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_rblock_deserialize_list(const void* data, tsk_size_t size, trtp_rtcp_rblocks_L_t* dest_list); +int trtp_rtcp_rblock_serialize_to(const trtp_rtcp_rblock_t* self, void* data, tsk_size_t size); + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_REPORT_RB_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report.h new file mode 100644 index 0000000..c30351f --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report.h @@ -0,0 +1,32 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_H +#define TINYRTP_RTCP_REPORT_H + +#include "tinyrtp_config.h" + +TRTP_BEGIN_DECLS + + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_REPORT_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_bye.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_bye.h new file mode 100644 index 0000000..796e9fc --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_bye.h @@ -0,0 +1,45 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_BYE_H +#define TINYRTP_RTCP_REPORT_BYE_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtcp/trtp_rtcp_packet.h" + +typedef struct trtp_rtcp_report_bye_s +{ + TRTP_DECLARE_RTCP_PACKET; + + uint32_t *ssrc_list; + trtp_rtcp_packets_L_t* packets; +} +trtp_rtcp_report_bye_t; + +trtp_rtcp_report_bye_t* trtp_rtcp_report_bye_create_null(); +trtp_rtcp_report_bye_t* trtp_rtcp_report_bye_create(struct trtp_rtcp_header_s* header); +trtp_rtcp_report_bye_t* trtp_rtcp_report_bye_create_2(uint32_t ssrc); +trtp_rtcp_report_bye_t* trtp_rtcp_report_bye_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_report_bye_serialize_to(const trtp_rtcp_report_bye_t* self, void* data, tsk_size_t size); +tsk_size_t trtp_rtcp_report_bye_get_size(const trtp_rtcp_report_bye_t* self); + +#endif /* TINYRTP_RTCP_REPORT_BYE_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_fb.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_fb.h new file mode 100644 index 0000000..1ad30b4 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_fb.h @@ -0,0 +1,152 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_FB_H +#define TINYRTP_RTCP_REPORT_FB_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtcp/trtp_rtcp_packet.h" + +#define TRTP_RTCP_REPORT_FB(self) ((trtp_rtcp_report_fb_t*)(self)) +#define TRTP_DECLARE_RTCP_FB_PACKET trtp_rtcp_report_fb_t __packet_fb__ + +// RFC 4585 6.1. Common Packet Format for Feedback Messages +typedef struct trtp_rtcp_report_fb_s +{ + TRTP_DECLARE_RTCP_PACKET; + + uint32_t ssrc_sender; /* SSRC of packet sender */ + uint32_t ssrc_media; /* SSRC of media source */ +} +trtp_rtcp_report_fb_t; + +typedef enum trtp_rtcp_rtpfb_fci_type_e +{ + trtp_rtcp_rtpfb_fci_type_nack = 1, // RFC 4585 + trtp_rtcp_rtpfb_fci_type_tmmbn = 4, // RFC 5104 +} +trtp_rtcp_rtpfb_fci_type_t; + +// Transport layer FB message +typedef struct trtp_rtcp_report_rtpfb_s +{ + TRTP_DECLARE_RTCP_FB_PACKET; + + trtp_rtcp_rtpfb_fci_type_t fci_type; + union{ + struct{ + tsk_size_t count; // not part of the specification + uint16_t* pid; // 16 bits + uint16_t* blp; // 16 bits + }nack; + struct{ + tsk_size_t count; // not part of the specification + uint32_t* ssrc; // 32 bits + uint8_t* MxTBR_Exp; // 6 bits + uint32_t* MxTBR_Mantissa; // 17 bits + uint16_t* MeasuredOverhead; // 9 bits + }tmmbn; + }; +} +trtp_rtcp_report_rtpfb_t; + +trtp_rtcp_report_rtpfb_t* trtp_rtcp_report_rtpfb_create_null(); +trtp_rtcp_report_rtpfb_t* trtp_rtcp_report_rtpfb_create(struct trtp_rtcp_header_s* header); +trtp_rtcp_report_rtpfb_t* trtp_rtcp_report_rtpfb_create_2(trtp_rtcp_rtpfb_fci_type_t fci_type, uint32_t ssrc_sender, uint32_t ssrc_media_src); +trtp_rtcp_report_rtpfb_t* trtp_rtcp_report_rtpfb_create_nack(uint32_t ssrc_sender, uint32_t ssrc_media_src, const uint16_t* seq_nums, tsk_size_t count); +trtp_rtcp_report_rtpfb_t* trtp_rtcp_report_rtpfb_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_report_rtpfb_serialize_to(const trtp_rtcp_report_rtpfb_t* self, void* data, tsk_size_t size); +tsk_size_t trtp_rtcp_report_rtpfb_get_size(const trtp_rtcp_report_rtpfb_t* self); + + +typedef enum trtp_rtcp_psfb_fci_type_e +{ + trtp_rtcp_psfb_fci_type_pli = 1, /* rfc 4585: Picture Loss Indication (PLI) */ + trtp_rtcp_psfb_fci_type_sli = 2, /* rfc 4585: Slice Loss Indication (SLI) */ + trtp_rtcp_psfb_fci_type_rpsi = 3, /* rfc 4585: Reference Picture Selection Indication (RPSI) */ + trtp_rtcp_psfb_fci_type_fir = 4, /* rfc 5104: Full Intra Request (FIR) Command*/ + trtp_rtcp_psfb_fci_type_afb = 15, /* rfc 4585: Application layer FB (AFB) message */ +} +trtp_rtcp_psfb_fci_type_t; + +/* rfc 4585: Application layer FB (AFB) message */ +typedef enum trtp_rtcp_psfb_afb_type_e +{ + trtp_rtcp_psfb_afb_type_none, + trtp_rtcp_psfb_afb_type_remb // draft-alvestrand-rmcat-remb-02 +} +trtp_rtcp_psfb_afb_type_t; + +// Payload-specific FB message +typedef struct trtp_rtcp_report_psfb_s +{ + TRTP_DECLARE_RTCP_FB_PACKET; + + trtp_rtcp_psfb_fci_type_t fci_type; + union{ + // struct{ //rfc 4585: 6.3.1.2 + // } pli; + struct{ // rfc 4585: 6.3.2.2 + uint16_t* first; + uint16_t* number; + uint8_t* pic_id; + } sli; + struct{ // rfc 4585: 6.3.3.2 + unsigned pb:8; + unsigned pt:7; + uint8_t* bytes; + } rpsi; + struct{// rfc 5104: 4.3.1.1 + tsk_size_t count; + uint32_t* ssrc; // 32 bits + uint8_t* seq_num; // 8 bits + }fir; + struct{ // rfc 4585: 6.4 + trtp_rtcp_psfb_afb_type_t type; + union{ + struct{ // draft-alvestrand-rmcat-remb-02: 2.2 + // MxTBR = mantissa * 2^exp = (mantissa << exp) bps + uint8_t num_ssrc; + uint8_t exp; // 6bits + uint32_t mantissa; // 18bits + uint32_t* ssrc_feedbacks; // 'num_ssrc'nth SSRC entries + }remb; + struct{ + uint8_t* bytes; // store bytes to allow reconstruction + }none; // unknown type + }; + }afb; + }; +} +trtp_rtcp_report_psfb_t; + +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_create_null(); +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_create(struct trtp_rtcp_header_s* header); +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_create_2(trtp_rtcp_psfb_fci_type_t fci_type, uint32_t ssrc_sender, uint32_t ssrc_media_src); +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_create_pli(uint32_t ssrc_sender, uint32_t ssrc_media_src); +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_create_fir(uint8_t seq_num, uint32_t ssrc_sender, uint32_t ssrc_media_src); +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_create_afb_remb(uint32_t ssrc_sender, const uint32_t* ssrc_media_src_list, uint32_t ssrc_media_src_list_count, uint32_t bitrate/*in bps*/); +trtp_rtcp_report_psfb_t* trtp_rtcp_report_psfb_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_report_psfb_serialize_to(const trtp_rtcp_report_psfb_t* self, void* data, tsk_size_t size); +tsk_size_t trtp_rtcp_report_psfb_get_size(const trtp_rtcp_report_psfb_t* self); + +#endif /* TINYRTP_RTCP_REPORT_FB_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_rr.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_rr.h new file mode 100644 index 0000000..2f25779 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_rr.h @@ -0,0 +1,54 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_RR_H +#define TINYRTP_RTCP_REPORT_RR_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtcp/trtp_rtcp_packet.h" +#include "tinyrtp/rtcp/trtp_rtcp_rblock.h" + +TRTP_BEGIN_DECLS + +#define TRTP_RTCP_REPORT_RR(self) ((trtp_rtcp_report_rr_t*)(self)) + +// RFC 3550 6.4.2 RR: Receiver Report RTCP Packet +typedef struct trtp_rtcp_report_rr_s +{ + TRTP_DECLARE_RTCP_PACKET; + + uint32_t ssrc; + trtp_rtcp_rblocks_L_t* blocks; + trtp_rtcp_packets_L_t* packets; +} +trtp_rtcp_report_rr_t; + +trtp_rtcp_report_rr_t* trtp_rtcp_report_rr_create_null(); +trtp_rtcp_report_rr_t* trtp_rtcp_report_rr_create(struct trtp_rtcp_header_s* header); +trtp_rtcp_report_rr_t* trtp_rtcp_report_rr_create_2(uint32_t ssrc); +trtp_rtcp_report_rr_t* trtp_rtcp_report_rr_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_report_rr_serialize_to(const trtp_rtcp_report_rr_t* self, void* data, tsk_size_t size); +tsk_size_t trtp_rtcp_report_rr_get_size(const trtp_rtcp_report_rr_t* self); + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_REPORT_RR_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_sdes.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_sdes.h new file mode 100644 index 0000000..04efb5c --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_sdes.h @@ -0,0 +1,53 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_SDES_H +#define TINYRTP_RTCP_REPORT_SDES_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtcp/trtp_rtcp_packet.h" +#include "tinyrtp/rtcp/trtp_rtcp_sdes_chunck.h" + +TRTP_BEGIN_DECLS + +#define TRTP_RTCP_REPORT_SDES(self) ((trtp_rtcp_report_sdes_t*)(self)) + +/* RFC 3550 6.5 SDES: Source Description RTCP Packet */ +typedef struct trtp_rtcp_report_sdes_s +{ + TRTP_DECLARE_RTCP_PACKET; + trtp_rtcp_sdes_chuncks_L_t* chuncks; +} +trtp_rtcp_report_sdes_t; + +typedef tsk_list_t trtp_rtcp_report_sdess_L_t; /**< List of @ref trtp_rtcp_report_sdes_t elements */ + +trtp_rtcp_report_sdes_t* trtp_rtcp_report_sdes_create_null(); +trtp_rtcp_report_sdes_t* trtp_rtcp_report_sdes_create(struct trtp_rtcp_header_s* header); +trtp_rtcp_report_sdes_t* trtp_rtcp_report_sdes_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_report_sdes_serialize_to(const trtp_rtcp_report_sdes_t* self, void* data, tsk_size_t size); +int trtp_rtcp_report_sdes_add_chunck(trtp_rtcp_report_sdes_t* self, trtp_rtcp_sdes_chunck_t* chunck); +tsk_size_t trtp_rtcp_report_sdes_get_size(const trtp_rtcp_report_sdes_t* self); + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_REPORT_SDES_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_sr.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_sr.h new file mode 100644 index 0000000..09d442f --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_sr.h @@ -0,0 +1,62 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_SR_H +#define TINYRTP_RTCP_REPORT_SR_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtcp/trtp_rtcp_packet.h" +#include "tinyrtp/rtcp/trtp_rtcp_rblock.h" + +TRTP_BEGIN_DECLS + +#define TRTP_RTCP_REPORT_SR(self) ((trtp_rtcp_report_sr_t*)(self)) + +// RFC 3550 6.4.1 SR: Sender Report RTCP Packet +typedef struct trtp_rtcp_report_sr_s +{ + TRTP_DECLARE_RTCP_PACKET; + + uint32_t ssrc; + struct{ + uint32_t ntp_msw; /**< NTP timestamp, most significant word */ + uint32_t ntp_lsw; /**< NTP timestamp, least significant word */ + uint32_t rtp_timestamp;/**< RTP timestamp */ + uint32_t sender_pcount; /**< sender's packet count */ + uint32_t sender_ocount; /**< sender's octet count */ + } sender_info; + + trtp_rtcp_rblocks_L_t* blocks; + trtp_rtcp_packets_L_t* packets; +} +trtp_rtcp_report_sr_t; + +trtp_rtcp_report_sr_t* trtp_rtcp_report_sr_create_null(); +trtp_rtcp_report_sr_t* trtp_rtcp_report_sr_create(struct trtp_rtcp_header_s* header); +trtp_rtcp_report_sr_t* trtp_rtcp_report_sr_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_report_sr_serialize_to(const trtp_rtcp_report_sr_t* self, void* data, tsk_size_t size); +int trtp_rtcp_report_sr_add_block(trtp_rtcp_report_sr_t* self, trtp_rtcp_rblock_t* rblock); +tsk_size_t trtp_rtcp_report_sr_get_size(const trtp_rtcp_report_sr_t* self); + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_REPORT_SR_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_xr.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_xr.h new file mode 100644 index 0000000..b08e096 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_report_xr.h @@ -0,0 +1,32 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_REPORT_XR_H +#define TINYRTP_RTCP_REPORT_XR_H + +#include "tinyrtp_config.h" + +TRTP_BEGIN_DECLS + + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_REPORT_XR_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_sdes_chunck.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_sdes_chunck.h new file mode 100644 index 0000000..ec3a8d8 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_sdes_chunck.h @@ -0,0 +1,56 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_SDES_CHUNCK_H +#define TINYRTP_RTCP_SDES_CHUNCK_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtcp/trtp_rtcp_sdes_item.h" + +#define TRTP_RTCP_SDES_CHUNCK_MIN_SIZE 4 +#define TRTP_RTCP_SDES_CHUNCK_SSRC_OR_CSRC_SIZE 4 + +#define TRTP_RTCP_SDES_CHUNCK(self) ((trtp_rtcp_sdes_chunck_t*)(self)) + +TRTP_BEGIN_DECLS + +typedef struct trtp_rtcp_sdes_chunck_s +{ + TSK_DECLARE_OBJECT; + + uint32_t ssrc; + trtp_rtcp_sdes_items_L_t* items; +} +trtp_rtcp_sdes_chunck_t; + +typedef tsk_list_t trtp_rtcp_sdes_chuncks_L_t; /**< List of @ref trtp_rtcp_sdes_item_t elements */ + +trtp_rtcp_sdes_chunck_t* trtp_rtcp_sdes_chunck_create_null(); +trtp_rtcp_sdes_chunck_t* trtp_rtcp_sdes_chunck_create(uint32_t ssrc); +trtp_rtcp_sdes_chunck_t* trtp_rtcp_sdes_chunck_deserialize(const void* data, tsk_size_t size); +int trtp_rtcp_sdes_chunck_serialize_to(const trtp_rtcp_sdes_chunck_t* self, void* data, tsk_size_t size); +int trtp_rtcp_sdes_chunck_add_item(trtp_rtcp_sdes_chunck_t* self, trtp_rtcp_sdes_item_type_t type, const void* data, uint8_t length); +tsk_size_t trtp_rtcp_sdes_chunck_get_size(const trtp_rtcp_sdes_chunck_t* self); + +TRTP_END_DECLS + +#endif /*TINYRTP_RTCP_SDES_CHUNCK_H*/ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_sdes_item.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_sdes_item.h new file mode 100644 index 0000000..8356a74 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_sdes_item.h @@ -0,0 +1,71 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +#ifndef TINYRTP_RTCP_SDES_ITEM_H +#define TINYRTP_RTCP_SDES_ITEM_H + +#include "tinyrtp_config.h" + +#include "tsk_list.h" +#include "tsk_buffer.h" + +#define TRTP_RTCP_SDES_ITEM_MIN_SIZE 2 /* Type + Length */ + +#define TRTP_RTCP_SDES_ITEM(self) ((trtp_rtcp_sdes_item_t*)(self)) + +TRTP_BEGIN_DECLS + +// RFC 3550 12.2 SDES Types +typedef enum trtp_rtcp_sdes_item_type_e +{ + trtp_rtcp_sdes_item_type_end = 0, /**< end of SDES list */ + trtp_rtcp_sdes_item_type_cname = 1, /**< canonical name*/ + trtp_rtcp_sdes_item_type_name = 2, /**< user name */ + trtp_rtcp_sdes_item_type_email = 3, /**< user's electronic mail address*/ + trtp_rtcp_sdes_item_type_phone = 4, /**< user's phone number */ + trtp_rtcp_sdes_item_type_loc = 5, /**< geographic user location*/ + trtp_rtcp_sdes_item_type_tool = 6, /**< name of application or tool*/ + trtp_rtcp_sdes_item_type_note = 7, /**< notice about the source*/ + trtp_rtcp_sdes_item_type_priv = 8, /**< private extensions*/ +} +trtp_rtcp_sdes_item_type_t; + +typedef struct trtp_rtcp_sdes_item_s +{ + TSK_DECLARE_OBJECT; + + trtp_rtcp_sdes_item_type_t type; + tsk_buffer_t *data; +} +trtp_rtcp_sdes_item_t; + + +typedef tsk_list_t trtp_rtcp_sdes_items_L_t; /**< List of @ref trtp_rtcp_sdes_item_t elements */ + +trtp_rtcp_sdes_item_t* trtp_rtcp_sdes_item_create(trtp_rtcp_sdes_item_type_t type, const void* data, uint8_t length); +trtp_rtcp_sdes_item_t* trtp_rtcp_sdes_item_deserialize(const void* data, tsk_size_t size); +tsk_buffer_t* trtp_rtcp_sdes_item_serialize(const trtp_rtcp_sdes_item_t* self); +int trtp_rtcp_sdes_item_serialize_to(const trtp_rtcp_sdes_item_t* self, void* data, tsk_size_t size); +tsk_size_t trtp_rtcp_sdes_item_get_size(const trtp_rtcp_sdes_item_t* self); + +TRTP_END_DECLS + +#endif /* TINYRTP_RTCP_SDES_ITEM_H */ diff --git a/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_session.h b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_session.h new file mode 100644 index 0000000..34ddbbc --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtcp/trtp_rtcp_session.h @@ -0,0 +1,70 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp_rtcp_session.h + * @brief RTCP session. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + + */ +#ifndef TINYMEDIA_RTCP_SESSION_H +#define TINYMEDIA_RTCP_SESSION_H + +#include "tinyrtp_config.h" +#include "tinyrtp/trtp_srtp.h" + +#include "tnet_types.h" + +#include "tsk_common.h" + +TRTP_BEGIN_DECLS + +struct trtp_rtcp_packet_s; +struct trtp_rtp_packet_s; +struct tnet_ice_ctx_s; +struct tnet_transport_s; + +typedef int (*trtp_rtcp_cb_f)(const void* callback_data, const struct trtp_rtcp_packet_s* packet); + +struct trtp_rtcp_session_s* trtp_rtcp_session_create(uint32_t ssrc, const char* cname); +struct trtp_rtcp_session_s* trtp_rtcp_session_create_2(struct tnet_ice_ctx_s* ice_ctx, uint32_t ssrc, const char* cname); +int trtp_rtcp_session_set_callback(struct trtp_rtcp_session_s* self, trtp_rtcp_cb_f callback, const void* callback_data); +#if HAVE_SRTP +int trtp_rtcp_session_set_srtp_sess(struct trtp_rtcp_session_s* self, const srtp_t* session); +#endif +int trtp_rtcp_session_set_app_bandwidth_max(struct trtp_rtcp_session_s* self, int32_t bw_upload_kbps, int32_t bw_download_kbps); +int trtp_rtcp_session_start(struct trtp_rtcp_session_s* self, tnet_fd_t local_fd, const struct sockaddr* remote_addr); +int trtp_rtcp_session_stop(struct trtp_rtcp_session_s* self); +int trtp_rtcp_session_process_rtp_out(struct trtp_rtcp_session_s* self, const struct trtp_rtp_packet_s* packet_rtp, tsk_size_t size); +int trtp_rtcp_session_process_rtp_in(struct trtp_rtcp_session_s* self, const struct trtp_rtp_packet_s* packet_rtp, tsk_size_t size); +int trtp_rtcp_session_process_rtcp_in(struct trtp_rtcp_session_s* self, const void* buffer, tsk_size_t size); +int trtp_rtcp_session_signal_pkt_loss(struct trtp_rtcp_session_s* self, uint32_t ssrc_media, const uint16_t* seq_nums, tsk_size_t count); +int trtp_rtcp_session_signal_frame_corrupted(struct trtp_rtcp_session_s* self, uint32_t ssrc_media); +int trtp_rtcp_session_signal_jb_error(struct trtp_rtcp_session_s* self, uint32_t ssrc_media); + +tnet_fd_t trtp_rtcp_session_get_local_fd(const struct trtp_rtcp_session_s* self); +int trtp_rtcp_session_set_local_fd(struct trtp_rtcp_session_s* self, tnet_fd_t local_fd); +int trtp_rtcp_session_set_net_transport(struct trtp_rtcp_session_s* self, struct tnet_transport_s* transport); + +TRTP_END_DECLS + +#endif /* TINYMEDIA_RTCP_SESSION_H */ diff --git a/tinyRTP/include/tinyrtp/rtp/trtp_rtp_header.h b/tinyRTP/include/tinyrtp/rtp/trtp_rtp_header.h new file mode 100644 index 0000000..15d177c --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtp/trtp_rtp_header.h @@ -0,0 +1,85 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp_rtp_header.h + * @brief RTP header. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + */ +#ifndef TINYRTP_RTP_HEADER_H +#define TINYRTP_RTP_HEADER_H + +#include "tinyrtp_config.h" +#include "tinymedia/tmedia_codec.h" +#include "tsk_buffer.h" + +TRTP_BEGIN_DECLS + +#define TRTP_RTP_HEADER_MIN_SIZE 12 +#define TRTP_RTP_HEADER(self) ((trtp_rtp_header_t*)(self)) + +typedef struct trtp_rtp_header_s +{ + TSK_DECLARE_OBJECT; + /* RFC 3550 section 5.1 - RTP Fixed Header Fields + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |V=2|P|X| CC |M| PT | sequence number | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | timestamp | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | synchronization source (SSRC) identifier | + +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ + | contributing source (CSRC) identifiers | + | .... | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + unsigned version:2; + unsigned padding:1; + unsigned extension:1; + unsigned csrc_count:4; + unsigned marker:1; + unsigned payload_type:7; + uint16_t seq_num; + uint32_t timestamp; + uint32_t ssrc; + uint32_t csrc[15]; + + // for internal use + enum tmedia_codec_id_e codec_id; +} +trtp_rtp_header_t; + +TINYRTP_API trtp_rtp_header_t* trtp_rtp_header_create_null(); +TINYRTP_API trtp_rtp_header_t* trtp_rtp_header_create(uint32_t ssrc, uint16_t seq_num, uint32_t timestamp, uint8_t payload_type, tsk_bool_t marker); +TINYRTP_API tsk_size_t trtp_rtp_header_guess_serialbuff_size(const trtp_rtp_header_t *self); +TINYRTP_API tsk_size_t trtp_rtp_header_serialize_to(const trtp_rtp_header_t *self, void *buffer, tsk_size_t size); +TINYRTP_API tsk_buffer_t* trtp_rtp_header_serialize(const trtp_rtp_header_t *self); +TINYRTP_API trtp_rtp_header_t* trtp_rtp_header_deserialize(const void *data, tsk_size_t size); + + +TINYRTP_GEXTERN const tsk_object_def_t *trtp_rtp_header_def_t; + +TRTP_END_DECLS + +#endif /* TINYRTP_RTP_HEADER_H */ diff --git a/tinyRTP/include/tinyrtp/rtp/trtp_rtp_packet.h b/tinyRTP/include/tinyrtp/rtp/trtp_rtp_packet.h new file mode 100644 index 0000000..c7f8cf3 --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtp/trtp_rtp_packet.h @@ -0,0 +1,74 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp_rtp_packet.h + * @brief RTP packet. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + */ +#ifndef TINYRTP_RTP_PACKET_H +#define TINYRTP_RTP_PACKET_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtp/trtp_rtp_header.h" + +#include "tsk_object.h" + +TRTP_BEGIN_DECLS + + +typedef struct trtp_rtp_packet_s +{ + TSK_DECLARE_OBJECT; + + trtp_rtp_header_t* header; + + struct{ + void* data; + const void* data_const; // never free()d. an alternative to "data" + tsk_size_t size; + } payload; + + /* extension header as per RFC 3550 section 5.3.1 */ + struct{ + void* data; + tsk_size_t size; /* contains the first two 16-bit fields */ + } extension; +} +trtp_rtp_packet_t; +typedef tsk_list_t trtp_rtp_packets_L_t; + +TINYRTP_API trtp_rtp_packet_t* trtp_rtp_packet_create_null(); +TINYRTP_API trtp_rtp_packet_t* trtp_rtp_packet_create(uint32_t ssrc, uint16_t seq_num, uint32_t timestamp, uint8_t payload_type, tsk_bool_t marker); +TINYRTP_API trtp_rtp_packet_t* trtp_rtp_packet_create_2(const trtp_rtp_header_t* header); +TINYRTP_API tsk_size_t trtp_rtp_packet_guess_serialbuff_size(const trtp_rtp_packet_t *self); +TINYRTP_API tsk_size_t trtp_rtp_packet_serialize_to(const trtp_rtp_packet_t *self, void* buffer, tsk_size_t size); +TINYRTP_API tsk_buffer_t* trtp_rtp_packet_serialize(const trtp_rtp_packet_t *self, tsk_size_t num_bytes_pad); +TINYRTP_API trtp_rtp_packet_t* trtp_rtp_packet_deserialize(const void *data, tsk_size_t size); + + +TINYRTP_GEXTERN const tsk_object_def_t *trtp_rtp_packet_def_t; + +TRTP_END_DECLS + +#endif /* TINYRTP_RTP_PACKET_H */ diff --git a/tinyRTP/include/tinyrtp/rtp/trtp_rtp_session.h b/tinyRTP/include/tinyrtp/rtp/trtp_rtp_session.h new file mode 100644 index 0000000..475502a --- /dev/null +++ b/tinyRTP/include/tinyrtp/rtp/trtp_rtp_session.h @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp_rtp_session.h + * @brief RTP session. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + + */ +#ifndef TINYMEDIA_RTP_SESSION_H +#define TINYMEDIA_RTP_SESSION_H + +#include "tinyrtp_config.h" + +TRTP_BEGIN_DECLS + +struct trtp_rtp_packet_s; + +typedef int (*trtp_rtp_cb_f)(const void* callback_data, const struct trtp_rtp_packet_s* packet); + +TRTP_END_DECLS + +#endif /* TINYMEDIA_RTP_SESSION_H */ diff --git a/tinyRTP/include/tinyrtp/trtp.h b/tinyRTP/include/tinyrtp/trtp.h new file mode 100644 index 0000000..3359a70 --- /dev/null +++ b/tinyRTP/include/tinyrtp/trtp.h @@ -0,0 +1,38 @@ +/* +* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp.h + * @brief tinyRTP (Real-time Transport Protocol) as per RFC 3550. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + + */ +#ifndef TINYMEDIA_TRTP_H +#define TINYMEDIA_TRTP_H + +#include "tinyrtp_config.h" + +TRTP_BEGIN_DECLS + +TRTP_END_DECLS + +#endif /* TINYMEDIA_TRTP_H */ diff --git a/tinyRTP/include/tinyrtp/trtp_manager.h b/tinyRTP/include/tinyrtp/trtp_manager.h new file mode 100644 index 0000000..1594f9c --- /dev/null +++ b/tinyRTP/include/tinyrtp/trtp_manager.h @@ -0,0 +1,227 @@ +/* +* Copyright (C) 2012 Mamadou Diop +* Copyright (C) 2012-2013 Doubango Telecom <http://www.doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp_manager.h + * @brief RTP/RTCP manager. + */ +#ifndef TINYRTP_MANAGER_H +#define TINYRTP_MANAGER_H + +#include "tinyrtp_config.h" + +#include "tinyrtp/rtp/trtp_rtp_session.h" +#include "tinyrtp/rtcp/trtp_rtcp_session.h" +#include "tinyrtp/trtp_srtp.h" + +#include "tinymedia/tmedia_defaults.h" + +#include "tinynet.h" + +TRTP_BEGIN_DECLS + +struct trtp_rtp_packet_s; +struct tnet_proxyinfo_s; + +/** RTP/RTCP manager */ +typedef struct trtp_manager_s +{ + TSK_DECLARE_OBJECT; + + char* local_ip; + tsk_bool_t use_ipv6; + tsk_bool_t is_started; + tsk_bool_t use_rtcp; + tsk_bool_t use_rtcpmux; + tsk_bool_t is_socket_disabled; + tsk_bool_t is_ice_neg_ok; + tsk_bool_t is_ice_turn_active; + tsk_bool_t is_force_symetric_rtp; + tsk_bool_t is_symetric_rtp_checked; + tsk_bool_t is_symetric_rtcp_checked; + int32_t app_bw_max_upload; // application specific (kbps) + int32_t app_bw_max_download; // application specific (kbps) + + tnet_transport_t* transport; + + struct tnet_ice_ctx_s* ice_ctx; + + tsk_timer_manager_handle_t* timer_mgr_global; + + struct{ + tmedia_rtcweb_type_t local; + tmedia_rtcweb_type_t remote; + } rtcweb_type; + + struct { + tsk_bool_t auto_detect; + struct tnet_proxyinfo_s* info; + } + proxy; + + struct{ + uint16_t start; + uint16_t stop; + } port_range; + + struct{ + uint16_t seq_num; + uint32_t timestamp; + uint8_t payload_type; + int32_t dscp; + + char* remote_ip; + tnet_port_t remote_port; + struct sockaddr_storage remote_addr; + + char* public_ip; + tnet_port_t public_port; + + struct{ + uint32_t local; + uint32_t remote; + } ssrc; + + struct{ + const void* usrdata; + trtp_rtp_cb_f fun; + } cb; + + struct{ + void* ptr; + tsk_size_t size; + tsk_size_t index; + } serial_buffer; + } rtp; + + struct{ + char* cname; + char* remote_ip; + tnet_port_t remote_port; + struct sockaddr_storage remote_addr; + tnet_socket_t* local_socket; + + char* public_ip; + tnet_port_t public_port; + + struct{ + const void* usrdata; + trtp_rtcp_cb_f fun; + } cb; + + struct trtp_rtcp_session_s* session; + } rtcp; + + TSK_DECLARE_SAFEOBJ; + +#if HAVE_SRTP + enum tmedia_srtp_type_e srtp_type; + enum tmedia_srtp_mode_e srtp_mode; + trtp_srtp_state_t srtp_state; + trtp_srtp_ctx_xt srtp_contexts[2/*LINE_IDX*/][2/*CRYPTO_TYPE*/]; + const struct trtp_srtp_ctx_xs* srtp_ctx_neg_local; + const struct trtp_srtp_ctx_xs* srtp_ctx_neg_remote; + + struct{ + char* file_ca; + char* file_pbk; + char* file_pvk; + tsk_bool_t cert_verif; + + trtp_srtp_state_t state; + // enable() could be postponed if net transport not ready yet (e.g. when ICE is ON) + tsk_bool_t enable_postponed; + + tsk_bool_t srtp_connected; + tsk_bool_t srtcp_connected; + tsk_bool_t srtp_handshake_succeed; + tsk_bool_t srtcp_handshake_succeed; + + trtp_srtp_crypto_type_t crypto_selected; + + struct{ + uint64_t timeout; + tsk_timer_id_t id; + } timer_hanshaking; + + struct{ + const void* usrdata; + trtp_srtp_dtls_cb_f fun; + } cb; + + struct{ + tnet_fingerprint_t fp; + tnet_dtls_hash_type_t fp_hash; + } remote; + struct{ + tnet_dtls_setup_t setup; + tsk_bool_t connection_new; + }local; + } dtls; +#endif +} +trtp_manager_t; + +TINYRTP_API trtp_manager_t* trtp_manager_create(tsk_bool_t use_rtcp, const char* local_ip, tsk_bool_t use_ipv6, enum tmedia_srtp_type_e srtp_type, enum tmedia_srtp_mode_e srtp_mode); +TINYRTP_API trtp_manager_t* trtp_manager_create_2(struct tnet_ice_ctx_s* ice_ctx, enum tmedia_srtp_type_e srtp_type, enum tmedia_srtp_mode_e srtp_mode); +TINYRTP_API int trtp_manager_set_ice_ctx(trtp_manager_t* self, struct tnet_ice_ctx_s* ice_ctx); +TINYRTP_API int trtp_manager_prepare(trtp_manager_t* self); +#if HAVE_SRTP +TINYRTP_API int trtp_manager_set_dtls_certs(trtp_manager_t* self, const char* ca, const char* pbk, const char* pvk, tsk_bool_t verify); +TINYRTP_API int trtp_manager_set_dtls_remote_fingerprint(trtp_manager_t* self, const tnet_fingerprint_t* fp, const char* hash); +TINYRTP_API enum tnet_dtls_hash_type_e trtp_manager_get_dtls_remote_fingerprint_hash(trtp_manager_t* self); +TINYRTP_API int trtp_manager_set_dtls_local_setup(trtp_manager_t* self, tnet_dtls_setup_t setup, tsk_bool_t connection_new); +TINYRTP_API int trtp_manager_set_dtls_callback(trtp_manager_t* self, const void* usrdata, trtp_srtp_dtls_cb_f fun); +TINYRTP_API const char* trtp_manager_get_dtls_local_fingerprint(trtp_manager_t* self, enum tnet_dtls_hash_type_e hash); +TINYRTP_API tsk_bool_t trtp_manager_is_dtls_enabled(trtp_manager_t* self); +TINYRTP_API tsk_bool_t trtp_manager_is_dtls_activated(trtp_manager_t* self); +TINYRTP_API tsk_bool_t trtp_manager_is_dtls_started(trtp_manager_t* self); +TINYRTP_API tsk_bool_t trtp_manager_is_srtp_activated(trtp_manager_t* self); +TINYRTP_API tsk_bool_t trtp_manager_is_srtp_started(trtp_manager_t* self); +TINYRTP_API int trtp_manager_set_srtp_type_remote(trtp_manager_t* self, enum tmedia_srtp_type_e srtp_type); +TINYRTP_API int trtp_manager_set_srtp_type_local(trtp_manager_t* self, enum tmedia_srtp_type_e srtp_type, enum tmedia_srtp_mode_e srtp_mode); +#endif /* HAVE_SRTP */ +TINYRTP_API tsk_bool_t trtp_manager_is_ready(trtp_manager_t* self); +TINYRTP_API int trtp_manager_set_natt_ctx(trtp_manager_t* self, struct tnet_nat_ctx_s* natt_ctx); +TINYRTP_API int trtp_manager_set_rtp_callback(trtp_manager_t* self, trtp_rtp_cb_f fun, const void* usrdata); +TINYRTP_API int trtp_manager_set_rtcp_callback(trtp_manager_t* self, trtp_rtcp_cb_f fun, const void* usrdata); +TINYRTP_API int trtp_manager_set_rtp_dscp(trtp_manager_t* self, int32_t dscp); +TINYRTP_API int trtp_manager_set_payload_type(trtp_manager_t* self, uint8_t payload_type); +TINYRTP_API int trtp_manager_set_rtp_remote(trtp_manager_t* self, const char* remote_ip, tnet_port_t remote_port); +TINYRTP_API int trtp_manager_set_rtcp_remote(trtp_manager_t* self, const char* remote_ip, tnet_port_t remote_port); +TINYRTP_API int trtp_manager_set_port_range(trtp_manager_t* self, uint16_t start, uint16_t stop); +TINYRTP_API int trtp_manager_set_rtcweb_type_remote(trtp_manager_t* self, tmedia_rtcweb_type_t rtcweb_type); +TINYRTP_API int trtp_manager_set_proxy_auto_detect(trtp_manager_t* self, tsk_bool_t auto_detect); +TINYRTP_API int trtp_manager_set_proxy_info(trtp_manager_t* self, enum tnet_proxy_type_e type, const char* host, tnet_port_t port, const char* login, const char* password); +TINYRTP_API int trtp_manager_start(trtp_manager_t* self); +TINYRTP_API tsk_size_t trtp_manager_send_rtp(trtp_manager_t* self, const void* data, tsk_size_t size, uint32_t duration, tsk_bool_t marker, tsk_bool_t last_packet); +TINYRTP_API tsk_size_t trtp_manager_send_rtp_packet(trtp_manager_t* self, const struct trtp_rtp_packet_s* packet, tsk_bool_t bypass_encrypt); +TINYRTP_API int trtp_manager_get_bytes_count(trtp_manager_t* self, uint64_t* bytes_in, uint64_t* bytes_out); +TINYRTP_API tsk_size_t trtp_manager_send_rtp_raw(trtp_manager_t* self, const void* data, tsk_size_t size); +TINYRTP_API int trtp_manager_set_app_bandwidth_max(trtp_manager_t* self, int32_t bw_upload_kbps, int32_t bw_download_kbps); +TINYRTP_API int trtp_manager_signal_pkt_loss(trtp_manager_t* self, uint32_t ssrc_media, const uint16_t* seq_nums, tsk_size_t count); +TINYRTP_API int trtp_manager_signal_frame_corrupted(trtp_manager_t* self, uint32_t ssrc_media); +TINYRTP_API int trtp_manager_signal_jb_error(trtp_manager_t* self, uint32_t ssrc_media); +TINYRTP_API int trtp_manager_stop(trtp_manager_t* self); + +TINYRTP_GEXTERN const tsk_object_def_t *trtp_manager_def_t; + +TRTP_END_DECLS + +#endif /* TINYRTP_MANAGER_H */ diff --git a/tinyRTP/include/tinyrtp/trtp_srtp.h b/tinyRTP/include/tinyrtp/trtp_srtp.h new file mode 100644 index 0000000..9992bbb --- /dev/null +++ b/tinyRTP/include/tinyrtp/trtp_srtp.h @@ -0,0 +1,131 @@ +/* +* Copyright (C) 2012 Mamadou Diop +* Copyright (C) 2012-2013 Doubango Telecom <http://www.doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* DOUBANGO is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with DOUBANGO. +* +*/ +/**@file trtp_srtp.h + */ +#ifndef TINYRTP_SRTP_H +#define TINYRTP_SRTP_H + +#include "tinyrtp_config.h" + +#if HAVE_SRTP +# include "tsk_common.h" +# include <srtp/srtp.h> + +struct trtp_manager_s; + +typedef enum trtp_srtp_dtls_event_type_e +{ + trtp_srtp_dtls_event_type_handshake_failed, + trtp_srtp_dtls_event_type_handshake_succeed, + trtp_srtp_dtls_event_type_fatal_error, + trtp_srtp_dtls_event_type_started +} +trtp_srtp_dtls_event_type_t; + +typedef enum trtp_srtp_crypto_type_e +{ + NONE = -1, + HMAC_SHA1_80, + HMAC_SHA1_32, + + SRTP_CRYPTO_TYPES_MAX +} +trtp_srtp_crypto_type_t; + +typedef enum trtp_srtp_state_e +{ + trtp_srtp_state_none, + /* at this state we're able to generated DTLS "fingerprints" and SDES "crypro" attributes + but neither encrypt() nor decrypt() is possible. + it's possible to move backward and disable SRTP (e.g. because of negotiation error) + it's required to move to this state in order to be able to negotiate SRTP when mode is "optional" or "mandatory" + */ + trtp_srtp_state_enabled, + /* at this state both required parameters (e.g. "crypto" attributes) have been successfuly proceeded + it's not possible to move backward and disable SRTP + if type="SDES": start()ing the engine means we'll be imediately able to encrypt()/decrypt() data + if type="DTLS": start()ing the engine doesn't mean we will be able to encrypt()/decrypt() data unless handshaking process successfuly completed + */ + trtp_srtp_state_activated, + /* at this state we're able to encrypt()/decrypt() SRTP data + */ + trtp_srtp_state_started +} +trtp_srtp_state_t; + +typedef int (*trtp_srtp_dtls_cb_f)(const void* usrdata, enum trtp_srtp_dtls_event_type_e type, const char* reason); + +#define TRTP_SRTP_AES_CM_128_HMAC_SHA1_80 "AES_CM_128_HMAC_SHA1_80" +#define TRTP_SRTP_AES_CM_128_HMAC_SHA1_32 "AES_CM_128_HMAC_SHA1_32" + +#define TRTP_SRTP_LINE_IDX_LOCAL 0 +#define TRTP_SRTP_LINE_IDX_REMOTE 1 + +static const char* trtp_srtp_crypto_type_strings[2] = +{ + TRTP_SRTP_AES_CM_128_HMAC_SHA1_80, TRTP_SRTP_AES_CM_128_HMAC_SHA1_32 +}; + + +typedef struct trtp_srtp_ctx_internal_xs +{ + int32_t tag; + trtp_srtp_crypto_type_t crypto_type; + char key_str[SRTP_MAX_KEY_LEN]; + char key_bin[SRTP_MASTER_KEY_LEN]; + tsk_bool_t have_valid_key; + + srtp_t session; + srtp_policy_t policy; + tsk_bool_t initialized; +} +trtp_srtp_ctx_internal_xt; + +typedef struct trtp_srtp_ctx_xs +{ + // (rtp == rtcp) for SDES but different for DTLS + struct trtp_srtp_ctx_internal_xs rtp; + struct trtp_srtp_ctx_internal_xs rtcp; +} +trtp_srtp_ctx_xt; + +int trtp_srtp_ctx_internal_init(struct trtp_srtp_ctx_internal_xs* ctx, int32_t tag, trtp_srtp_crypto_type_t type, uint32_t ssrc); +int trtp_srtp_ctx_internal_deinit(struct trtp_srtp_ctx_internal_xs* ctx); +int trtp_srtp_ctx_init(struct trtp_srtp_ctx_xs* ctx, int32_t tag, trtp_srtp_crypto_type_t type, uint32_t ssrc); +int trtp_srtp_ctx_deinit(struct trtp_srtp_ctx_xs* ctx); +TINYRTP_API int trtp_srtp_match_line(const char* crypto_line, int32_t* tag, int32_t* crypto_type, char* key, tsk_size_t key_size); + +TINYRTP_API int trtp_srtp_set_crypto(struct trtp_manager_s* rtp_mgr, const char* crypto_line, int32_t idx); +#define trtp_srtp_set_crypto_local(rtp_mgr, crypto_line) trtp_srtp_set_crypto((rtp_mgr), (crypto_line), TRTP_SRTP_LINE_IDX_LOCAL) +#define trtp_srtp_set_crypto_remote(rtp_mgr, crypto_line) trtp_srtp_set_crypto((rtp_mgr), (crypto_line), TRTP_SRTP_LINE_IDX_REMOTE) +TINYRTP_API int trtp_srtp_set_key_and_salt(struct trtp_manager_s* rtp_mgr, trtp_srtp_crypto_type_t crypto_type, const void* key, tsk_size_t key_size, const void* salt, tsk_size_t salt_size, int32_t idx, tsk_bool_t rtp); +#define trtp_srtp_set_key_and_salt_local(rtp_mgr, crypto_type, key, key_size, salt, salt_size, is_rtp) trtp_srtp_set_key_and_salt((rtp_mgr), (crypto_type), (key), (key_size), (salt), (salt_size), TRTP_SRTP_LINE_IDX_LOCAL, (is_rtp)) +#define trtp_srtp_set_key_and_salt_remote(rtp_mgr, crypto_type, key, key_size, salt, salt_size, is_rtp) trtp_srtp_set_key_and_salt((rtp_mgr), (crypto_type), (key), (key_size), (salt), (salt_size), TRTP_SRTP_LINE_IDX_REMOTE, (is_rtp)) +TINYRTP_API tsk_size_t trtp_srtp_get_local_contexts(struct trtp_manager_s* rtp_mgr, const struct trtp_srtp_ctx_xs ** contexts, tsk_size_t contexts_count); +TINYRTP_API tsk_bool_t trtp_srtp_is_initialized(struct trtp_manager_s* rtp_mgr); +TINYRTP_API tsk_bool_t trtp_srtp_is_started(struct trtp_manager_s* rtp_mgr); + +#endif /* HAVE_SRTP */ + + + + +#endif /* TINYRTP_SRTP_H */ |