diff --git a/libs/srtp/include/srtp.h b/libs/srtp/include/srtp.h index b90ed7eb8a..cb78f7e9c9 100644 --- a/libs/srtp/include/srtp.h +++ b/libs/srtp/include/srtp.h @@ -51,7 +51,6 @@ extern "C" { #endif #ifdef _MSC_VER -#pragma pack(4) #pragma warning(disable:4214) #endif @@ -895,6 +894,10 @@ srtp_install_event_handler(srtp_event_handler_func_t func); * is not identical) */ +#ifdef _MSC_VER +#pragma pack(push, r1, 1) +#endif + #ifndef WORDS_BIGENDIAN typedef struct { @@ -904,9 +907,9 @@ typedef struct { unsigned version:2; /* protocol version */ unsigned pt:7; /* payload type */ unsigned m:1; /* marker bit */ - uint16_t seq; /* sequence number */ - uint32_t ts; /* timestamp */ - uint32_t ssrc; /* synchronization source */ + unsigned seq:16; /* sequence number */ + unsigned ts:32; /* timestamp */ + unsigned ssrc:32; /* synchronization source */ } srtp_hdr_t; #else /* BIG_ENDIAN */ @@ -918,9 +921,9 @@ typedef struct { unsigned cc:4; /* CSRC count */ unsigned m:1; /* marker bit */ unsigned pt:7; /* payload type */ - uint16_t seq; /* sequence number */ - uint32_t ts; /* timestamp */ - uint32_t ssrc; /* synchronization source */ + unsigned seq:16; /* sequence number */ + unsigned ts:32; /* timestamp */ + unsigned ssrc:32; /* synchronization source */ } srtp_hdr_t; #endif @@ -945,8 +948,8 @@ typedef struct { unsigned p:1; /* padding flag */ unsigned version:2; /* protocol version */ unsigned pt:8; /* payload type */ - uint16_t len; /* length */ - uint32_t ssrc; /* synchronization source */ + unsigned len:16; /* length */ + unsigned ssrc:32; /* synchronization source */ } srtcp_hdr_t; typedef struct { @@ -964,8 +967,8 @@ typedef struct { unsigned p:1; /* padding flag */ unsigned rc:5; /* reception report count */ unsigned pt:8; /* payload type */ - uint16_t len; /* length */ - uint32_t ssrc; /* synchronization source */ + unsigned len:16; /* length */ + unsigned ssrc:32; /* synchronization source */ } srtcp_hdr_t; typedef struct { @@ -973,7 +976,7 @@ typedef struct { unsigned int p:1; /* padding flag */ unsigned int count:5; /* varies by packet type */ unsigned int pt:8; /* payload type */ - uint16_t length; /* len of uint32s of packet less header */ + unsigned length:16; /* len of uint32s of packet less header */ } rtcp_common_t; typedef struct { @@ -992,7 +995,7 @@ typedef struct { #define SRTCP_INDEX_MASK 0x7fffffff #ifdef _MSC_VER -#pragma pack() +#pragma pack(pop, r1) #endif #ifdef __cplusplus diff --git a/libs/srtp/srtp/srtp.c b/libs/srtp/srtp/srtp.c index 2d09555c2b..2db745d2bb 100644 --- a/libs/srtp/srtp/srtp.c +++ b/libs/srtp/srtp/srtp.c @@ -684,7 +684,7 @@ srtp_stream_init(srtp_stream_ctx_t *srtp, * estimate the packet index using the start of the replay window * and the sequence number from the header */ - delta = rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq)); + delta = rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs((uint16_t)hdr->seq)); status = rdbx_check(&stream->rtp_rdbx, delta); if (status) return status; /* we've been asked to reuse an index */ @@ -842,7 +842,7 @@ srtp_unprotect(srtp_ctx_t *ctx, void *srtp_hdr, int *pkt_octet_len) { est = (xtd_seq_num_t) make64(0,ntohs(hdr->seq)); delta = low32(est); #else - est = (xtd_seq_num_t) ntohs(hdr->seq); + est = (xtd_seq_num_t) ntohs((uint16_t)hdr->seq); delta = (int)est; #endif } else { @@ -856,7 +856,7 @@ srtp_unprotect(srtp_ctx_t *ctx, void *srtp_hdr, int *pkt_octet_len) { } else { /* estimate packet index from seq. num. in header */ - delta = rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq)); + delta = rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs((uint16_t)hdr->seq)); /* check replay database */ status = rdbx_check(&stream->rtp_rdbx, delta); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 120c7d507a..d5557d67f1 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -467,7 +467,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session rtp_session->recv_msg.header.x = 0; rtp_session->recv_msg.header.cc = 0; - rtp_session->seq = rtp_session->send_msg.header.seq; + rtp_session->seq = (uint16_t)rtp_session->send_msg.header.seq; rtp_session->payload = payload; rtp_session->ms_per_packet = ms_per_packet; rtp_session->packet_size = packet_size; @@ -896,7 +896,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_GOOGLEHACK) && rtp_session->recv_msg.header.pt == 102) { rtp_session->recv_msg.header.pt = 97; } - rtp_session->rseq = ntohs(rtp_session->recv_msg.header.seq); + rtp_session->rseq = ntohs((uint16_t)rtp_session->recv_msg.header.seq); rtp_session->rpayload = (switch_payload_t)rtp_session->recv_msg.header.pt; } else { if (rtp_session->recv_msg.header.version == 0 && rtp_session->ice_user) { @@ -1296,7 +1296,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data if (!rtp_session->mini && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) { rtp_session->mini++; rtp_session->rpayload = (switch_payload_t)send_msg->header.pt; - rtp_session->rseq = ntohs(send_msg->header.seq); + rtp_session->rseq = ntohs((uint16_t)send_msg->header.seq); } }