rtp.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * rtp.h
  3. *
  4. * rtp interface for srtp reference implementation
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. *
  9. * data types:
  10. *
  11. * rtp_msg_t an rtp message (the data that goes on the wire)
  12. * rtp_sender_t sender side socket and rtp info
  13. * rtp_receiver_t receiver side socket and rtp info
  14. *
  15. */
  16. /*
  17. *
  18. * Copyright (c) 2001-2017, Cisco Systems, Inc.
  19. * All rights reserved.
  20. *
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. *
  25. * Redistributions of source code must retain the above copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. *
  28. * Redistributions in binary form must reproduce the above
  29. * copyright notice, this list of conditions and the following
  30. * disclaimer in the documentation and/or other materials provided
  31. * with the distribution.
  32. *
  33. * Neither the name of the Cisco Systems, Inc. nor the names of its
  34. * contributors may be used to endorse or promote products derived
  35. * from this software without specific prior written permission.
  36. *
  37. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  38. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  41. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  42. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  43. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  44. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  46. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  48. * OF THE POSSIBILITY OF SUCH DAMAGE.
  49. *
  50. */
  51. #ifndef SRTP_RTP_H
  52. #define SRTP_RTP_H
  53. #ifdef HAVE_NETINET_IN_H
  54. #include <netinet/in.h>
  55. #elif defined HAVE_WINSOCK2_H
  56. #include <winsock2.h>
  57. #endif
  58. #include "srtp_priv.h"
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /*
  63. * RTP_HEADER_LEN indicates the size of an RTP header
  64. */
  65. #define RTP_HEADER_LEN 12
  66. /*
  67. * RTP_MAX_BUF_LEN defines the largest RTP packet in the rtp.c implementation
  68. */
  69. #define RTP_MAX_BUF_LEN 16384
  70. typedef srtp_hdr_t rtp_hdr_t;
  71. typedef struct {
  72. srtp_hdr_t header;
  73. char body[RTP_MAX_BUF_LEN];
  74. } rtp_msg_t;
  75. typedef struct rtp_sender_ctx_t {
  76. rtp_msg_t message;
  77. int socket;
  78. srtp_ctx_t *srtp_ctx;
  79. struct sockaddr_in addr; /* reciever's address */
  80. } rtp_sender_ctx_t;
  81. typedef struct rtp_receiver_ctx_t {
  82. rtp_msg_t message;
  83. int socket;
  84. srtp_ctx_t *srtp_ctx;
  85. struct sockaddr_in addr; /* receiver's address */
  86. } rtp_receiver_ctx_t;
  87. typedef struct rtp_sender_ctx_t *rtp_sender_t;
  88. typedef struct rtp_receiver_ctx_t *rtp_receiver_t;
  89. int rtp_sendto(rtp_sender_t sender, const void *msg, int len);
  90. int rtp_recvfrom(rtp_receiver_t receiver, void *msg, int *len);
  91. int rtp_receiver_init(rtp_receiver_t rcvr,
  92. int sock,
  93. struct sockaddr_in addr,
  94. unsigned int ssrc);
  95. int rtp_sender_init(rtp_sender_t sender,
  96. int sock,
  97. struct sockaddr_in addr,
  98. unsigned int ssrc);
  99. /*
  100. * srtp_sender_init(...) initializes an rtp_sender_t
  101. */
  102. int srtp_sender_init(
  103. rtp_sender_t rtp_ctx, /* structure to be init'ed */
  104. struct sockaddr_in name, /* socket name */
  105. srtp_sec_serv_t security_services, /* sec. servs. to be used */
  106. unsigned char *input_key /* master key/salt in hex */
  107. );
  108. int srtp_receiver_init(
  109. rtp_receiver_t rtp_ctx, /* structure to be init'ed */
  110. struct sockaddr_in name, /* socket name */
  111. srtp_sec_serv_t security_services, /* sec. servs. to be used */
  112. unsigned char *input_key /* master key/salt in hex */
  113. );
  114. int rtp_sender_init_srtp(rtp_sender_t sender, const srtp_policy_t *policy);
  115. int rtp_sender_deinit_srtp(rtp_sender_t sender);
  116. int rtp_receiver_init_srtp(rtp_receiver_t sender, const srtp_policy_t *policy);
  117. int rtp_receiver_deinit_srtp(rtp_receiver_t sender);
  118. rtp_sender_t rtp_sender_alloc(void);
  119. void rtp_sender_dealloc(rtp_sender_t rtp_ctx);
  120. rtp_receiver_t rtp_receiver_alloc(void);
  121. void rtp_receiver_dealloc(rtp_receiver_t rtp_ctx);
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif /* SRTP_RTP_H */