Blame view

src/decoder/gb28181/rtp/Rtp.h 2.04 KB
150d457d   Hu Chunming   代码暂存,未完成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  //
  // Created by bxc on 2023/4/18.
  // 作者:北小菜
  // 邮箱:bilibili_bxc@126.com
  // 西瓜视频主页:https://www.ixigua.com/home/4171970536803763
  // 哔哩哔哩主页:https://space.bilibili.com/487906612/
  //
  
  #ifndef GB28181PLAYER_RTP_H
  #define GB28181PLAYER_RTP_H
  
  #include <stdint.h>
  
  #define RTP_VESION              2
  #define RTP_PAYLOAD_TYPE_H264   96
  #define RTP_PAYLOAD_TYPE_AAC    97
  
  #define RTP_HEADER_SIZE 12
  #define RTP_MAX_SIZE    1400
  
  /*
   *
   *    0                   1                   2                   3
   *    7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0
   *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   *   |V=2|P|X|  CC   |M|     PT      |       sequence number         |
   *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   *   |                           timestamp                           |
   *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   *   |           synchronization source (SSRC) identifier            |
   *   +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
   *   |            contributing source (CSRC) identifiers             |
   *   :                             ....                              :
   *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   *
   */
  struct RtpHeader{
      /* byte 0 */
      uint8_t csrcLen:4;
      uint8_t extension:1;
      uint8_t padding:1;
      uint8_t version:2; // 最高2
  
      /* byte 1 */
      uint8_t payloadType:7;
      uint8_t marker:1;
  
      /* bytes 2,3 */
      uint16_t seq;
  
      /* bytes 4-7 */
      uint32_t timestamp;
  
      /* bytes 8-11 */
      uint32_t ssrc;
  };
  struct RtpPacket{
      struct RtpHeader rtpHeader;
      uint8_t payload[0];
  };
  
  void rtpHeaderInit(struct RtpPacket* rtpPacket, uint8_t csrcLen, uint8_t extension,
                     uint8_t padding, uint8_t version, uint8_t payloadType, uint8_t marker,
                     uint16_t seq, uint32_t timestamp, uint32_t ssrc);
  
  int parseRtpHeader(uint8_t* headerBuf, struct RtpHeader* rtpHeader);
  
  #endif //GB28181PLAYER_RTP_H