Blame view

src/decoder/gb28181/rtp2/Rtp.cpp 1.87 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
  //
  // Created by bxc on 2023/4/18.
  // 作者:北小菜
  // 邮箱:bilibili_bxc@126.com
  // 西瓜视频主页:https://www.ixigua.com/home/4171970536803763
  // 哔哩哔哩主页:https://space.bilibili.com/487906612/
  //
  
  #include "Rtp.h"
  #include <stdio.h>
  #include <string.h>
  
  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){
      rtpPacket->rtpHeader.csrcLen = csrcLen;
      rtpPacket->rtpHeader.extension = extension;
      rtpPacket->rtpHeader.padding = padding;
      rtpPacket->rtpHeader.version = version;
      rtpPacket->rtpHeader.payloadType =  payloadType;
      rtpPacket->rtpHeader.marker = marker;
      rtpPacket->rtpHeader.seq = seq;
      rtpPacket->rtpHeader.timestamp = timestamp;
      rtpPacket->rtpHeader.ssrc = ssrc;
  }
3c9776e9   Hu Chunming   代码优化
26
  
150d457d   Hu Chunming   代码暂存,未完成
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  int parseRtpHeader(uint8_t* headerBuf, struct RtpHeader* rtpHeader){
      memset(rtpHeader,0,sizeof(*rtpHeader));
      /* byte 0 */
      rtpHeader->version = (headerBuf[0] & 0xC0) >> 6;
      rtpHeader->padding = (headerBuf[0] & 0x20) >> 5;
      rtpHeader->extension = (headerBuf[0] & 0x10) >> 4;
      rtpHeader->csrcLen = (headerBuf[0] & 0x0F);
      /* byte 1 */
      rtpHeader->marker = (headerBuf[1] & 0x80) >> 7;
      rtpHeader->payloadType = (headerBuf[1] & 0x7F);
      /* bytes 2,3 */
      rtpHeader->seq = ((headerBuf[2] & 0xFF) << 8) | (headerBuf[3] & 0xFF);
      /* bytes 4-7 */
      rtpHeader->timestamp = ((headerBuf[4] & 0xFF) << 24) | ((headerBuf[5] & 0xFF) << 16)
              | ((headerBuf[6] & 0xFF) << 8)
              | ((headerBuf[7] & 0xFF));
      /* bytes 8-11 */
      rtpHeader->ssrc = ((headerBuf[8] & 0xFF) << 24) | ((headerBuf[9] & 0xFF) << 16)
                             | ((headerBuf[10] & 0xFF) << 8)
                             | ((headerBuf[11] & 0xFF));
  
      return 0;
  }