• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_QUEUE_H
17 #define OHOS_SHARING_RTP_QUEUE_H
18 
19 #include <cstdlib>
20 #include <functional>
21 #include <map>
22 #include "rtp_packet.h"
23 
24 namespace OHOS {
25 namespace Sharing {
26 class RtpPacketSortor {
27 public:
28     using Ptr = std::shared_ptr<RtpPacketSortor>;
29     using OnSort = std::function<void(uint16_t seq, const RtpPacket::Ptr &packet)>;
30 
31     RtpPacketSortor(int32_t sampleRate, size_t kMax = 1024, size_t kMin = 16);
32     ~RtpPacketSortor() = default;
33 
34     void Clear();
35     void Flush();
36     void SetOnSort(const OnSort &cb);
37     void SortPacket(uint16_t seq, RtpPacket::Ptr packet);
38     void InputRtp(TrackType type, uint8_t *ptr, size_t len);
39 
40     uint32_t GetSSRC() const;
41 
42     size_t GetJitterSize() const;
43     size_t GetCycleCount() const;
44 
45 private:
46     void PopPacket();
47     void SetSortSize();
48     void TryPopPacket();
49     void PopIterator(std::map<uint16_t, RtpPacket::Ptr>::iterator it);
50 
51 private:
52     uint16_t nextSeqOut_ = 0;
53 
54     uint32_t ssrc_ = 0;
55     int32_t sampleRate_ = 0;
56 
57     size_t kMin_ = 16;
58     size_t kMax_ = 1024;
59     size_t seqCycleCount_ = 0;
60     size_t maxSortSize_ = kMin_;
61 
62     std::map<uint16_t, RtpPacket::Ptr> pktSortCacheMap_;
63 
64     OnSort onSort_ = nullptr;
65 };
66 } // namespace Sharing
67 } // namespace OHOS
68 #endif