Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
4.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // INTEL Corporation Proprietary Information
  3. // This listing is supplied under the terms of a license agreement with Intel
  4. // Corporation and many not be copied nor disclosed except in accordance
  5. // with the terms of that agreement.
  6. // Copyright (c) 1995, 1996 Intel Corporation.
  7. //
  8. //
  9. // Module Name: rtpclass.h
  10. // Environment: MSVC 4.0, OLE 2
  11. /////////////////////////////////////////////////////////////////////////////////
  12. #ifndef RTPCLASS_H
  13. #define RTPCLASS_H
  14. #include "rtp.h"
  15. class RTP_Header {
  16. public:
  17. enum { fixed_header_size = 12 };
  18. private:
  19. #ifdef DEBUG
  20. union {
  21. unsigned char bytes[fixed_header_size];
  22. RTP_HDR_T header; /* This is here for convenience in debugging only */
  23. };
  24. #else
  25. unsigned char bytes[fixed_header_size];
  26. #endif
  27. public:
  28. int v() { return (bytes[0] >> 6) & 3; }
  29. void set_v(int v) { bytes[0] = (bytes[0] & 0x3f) | ((v & 3) << 6); }
  30. int p() { return (bytes[0] >> 5) & 1; }
  31. void set_p(int v) { bytes[0] = (bytes[0] & 0xdf) | ((v & 1) << 5); }
  32. int x() { return (bytes[0] >> 4) & 1; }
  33. void set_x(int v) { bytes[0] = (bytes[0] & 0xef) | ((v & 1) << 4); }
  34. int cc() { return bytes[0] & 0x0f; }
  35. void set_cc(int v) { bytes[0] = (bytes[0] & 0xf0) | (v & 0x0f); }
  36. int m() { return (bytes[1] >> 7) & 1; }
  37. void set_m(int v) { bytes[1] = (bytes[1] & 0x7f) | ((v & 1) << 7); }
  38. int pt() { return (bytes[1] & 0x7f); }
  39. void set_pt(int v) { bytes[1] = (bytes[1] & 0x80) | (v & 0x7f); }
  40. unsigned short seq() { return bytes[2] << 8 | bytes[3]; };
  41. void set_seq(unsigned short v) { bytes[2] = (unsigned char)(v >> 8);
  42. bytes[3] = (unsigned char)(v);
  43. }
  44. unsigned long ts() { return (unsigned long)bytes[4] << 24
  45. | (unsigned long)bytes[5] << 16
  46. | (unsigned long)bytes[6] << 8
  47. | (unsigned long)bytes[7];
  48. }
  49. void set_ts(unsigned long v) { bytes[4] = (unsigned char)(v >> 24);
  50. bytes[5] = (unsigned char)(v >> 16);
  51. bytes[6] = (unsigned char)(v >> 8);
  52. bytes[7] = (unsigned char)(v);
  53. }
  54. unsigned long ssrc() { return (unsigned long)bytes[8] << 24
  55. | (unsigned long)bytes[9] << 16
  56. | (unsigned long)bytes[10] << 8
  57. | (unsigned long)bytes[11];
  58. }
  59. void set_ssrc(unsigned long v) { bytes[8] = (unsigned char)(v >> 24);
  60. bytes[9] = (unsigned char)(v >> 16);
  61. bytes[10] = (unsigned char)(v >> 8);
  62. bytes[11] = (unsigned char)(v);
  63. }
  64. //refer to section 5.3.1 of the RTP spec to understand the RTP Extension header.
  65. int header_size()
  66. {
  67. int NumCSRCBytes = cc() * 4;
  68. int NumExtensionBytes = 0;
  69. if ( x() == 1 )
  70. {
  71. //tmp points to the first word of the extended header.
  72. //bytes 2 and 3 of this word contain the length of the extended header
  73. //in 32-bit words (not counting the first word)
  74. unsigned char *tmp = bytes + fixed_header_size + NumCSRCBytes;
  75. unsigned short x_len = ((unsigned short)tmp[2] << 8) | (unsigned short)tmp[3];
  76. //number of words plus the length field itself.
  77. NumExtensionBytes = (x_len + 1) * 4;
  78. }
  79. //the fixed header plus the csrc list plus the extended header
  80. return ( fixed_header_size + NumCSRCBytes + NumExtensionBytes );
  81. }
  82. };
  83. #endif