Rtp.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright @ 2014 Hangzhou Topzen Ltd.
  3. // Author: Tang (tang@hztopzen.com) @ 2014-12
  4. //
  5. #ifndef __RTP_H
  6. #define __RTP_H
  7. #include "BaseTypes.h"
  8. #include "BytesOrder.h"
  9. namespace tzc {
  10. // Notice: in network bytes-order
  11. struct RTPHead {
  12. RTPHead(const TZ_BYTE * net)
  13. {
  14. Attribute = net[0];
  15. TypeInfo = net[1];
  16. memcpy(&Sequence, net + 2, sizeof(Sequence));
  17. memcpy(&Timestamp, net + 4, sizeof(Timestamp));
  18. memcpy(&SSRC, net + 8, sizeof(SSRC));
  19. Sequence = ntoh_16(Sequence);
  20. Timestamp = ntoh_32(Timestamp);
  21. SSRC = ntoh_32(SSRC);
  22. }
  23. TZ_Uint8 IsMarked();
  24. TZ_Uint8 PayloadType();
  25. /* Attribute:
  26. 0 1 2 3 4 5 6 7
  27. |--- --- --- --- --- --- --- ---|
  28. | V | Pad | E | CSRC count |
  29. */
  30. TZ_Uint8 Attribute;
  31. /* TypeInfo:
  32. 0 1 2 3 4 5 6 7
  33. |--- --- --- --- --- --- --- ---|
  34. | M | Payload Type |
  35. */
  36. TZ_Uint8 TypeInfo;
  37. TZ_Uint16 Sequence;
  38. TZ_Uint32 Timestamp;
  39. TZ_Uint32 SSRC;
  40. };
  41. //
  42. // inlines
  43. //
  44. inline TZ_Uint8 RTPHead::IsMarked()
  45. {
  46. return (this->TypeInfo & 0x80) != 0;
  47. }
  48. inline TZ_Uint8 RTPHead::PayloadType()
  49. {
  50. return this->TypeInfo & 0x7F;
  51. }
  52. } // namespace tzc
  53. #endif /* ----- #ifndef __RTP_H ----- */