1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_SHARING_RTP_PACKGET_H 17 #define OHOS_SHARING_RTP_PACKGET_H 18 19 #include <cstdint> 20 #include <cstdio> 21 #include <memory> 22 #include "frame/frame.h" 23 24 namespace OHOS { 25 namespace Sharing { 26 class RtpHeader { 27 public: 28 uint8_t *GetExtData(); 29 uint8_t *GetCsrcData(); 30 uint8_t *GetPayloadData(); 31 uint16_t GetExtReserved() const; 32 33 size_t GetExtSize() const; 34 size_t GetCsrcSize() const; 35 size_t GetPayloadSize(size_t rtp_size) const; 36 37 private: 38 size_t GetPayloadOffset() const; 39 size_t GetPaddingSize(size_t rtp_size) const; 40 41 public: 42 #if __BYTE_ORDER == __BIG_ENDIAN 43 44 uint32_t version_ : 2; 45 // padding 46 uint32_t padding_ : 1; 47 48 uint32_t ext_ : 1; 49 // csrc 50 uint32_t csrc_ : 4; 51 // mark 52 uint32_t mark_ : 1; 53 54 uint32_t pt_ : 7; 55 #else 56 // csrc 57 uint32_t csrc_ : 4; 58 59 uint32_t ext_ : 1; 60 // padding 61 uint32_t padding_ : 1; 62 63 uint32_t version_ : 2; 64 65 uint32_t pt_ : 7; 66 // mark 67 uint32_t mark_ : 1; 68 #endif 69 70 uint32_t seq_ : 16; 71 72 uint32_t stamp_; 73 // ssrc 74 uint32_t ssrc_; 75 76 uint8_t payload_; 77 } __attribute__((packed)); 78 79 class RtpPacket : public DataBuffer { 80 public: 81 using Ptr = std::shared_ptr<RtpPacket>; 82 enum { 83 RTP_VERSION = 2, 84 RTP_HEADER_SIZE = 12, 85 }; 86 87 uint16_t GetSeq(); 88 uint32_t GetSSRC(); 89 uint32_t GetStamp(); 90 uint8_t *GetPayload(); 91 uint32_t GetStampMS(); 92 RtpHeader *GetHeader(); 93 size_t GetPayloadSize(); 94 95 public: 96 uint32_t sampleRate_; 97 98 uint64_t ntpStamp_; 99 100 TrackType type_ = TRACK_INVALID; 101 }; 102 } // namespace Sharing 103 } // namespace OHOS 104 #endif