• 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_G711_RTP_CODEC_H
17 #define OHOS_SHARING_G711_RTP_CODEC_H
18 
19 #include "frame/frame.h"
20 #include "frame/h264_frame.h"
21 #include "rtp_codec.h"
22 #include "rtp_maker.h"
23 
24 namespace OHOS {
25 namespace Sharing {
26 class RtpDecoderG711 : public RtpDecoder {
27 public:
28     using Ptr = std::shared_ptr<RtpDecoderG711>;
29     RtpDecoderG711();
30     ~RtpDecoderG711() = default;
31 
32     void InputRtp(const RtpPacket::Ptr &rtp) override;
33     void SetOnFrame(const OnFrame &cb) override;
34 
35 private:
36     FrameImpl::Ptr ObtainFrame();
37 
38 private:
39     bool dropFlag_ = false;
40     uint16_t lastSeq_ = 0;
41     size_t maxFrameSize_ = 0;
42 
43     FrameImpl::Ptr frame_ = nullptr;
44 };
45 
46 class RtpEncoderG711 : public RtpEncoder,
47                        public RtpMaker {
48 public:
49     using Ptr = std::shared_ptr<RtpEncoderG711>;
50 
51     RtpEncoderG711(uint32_t ssrc, uint32_t mtuSize, uint32_t sampleRate, uint8_t payloadType, uint32_t channels = 1,
52                    uint16_t seq = 0);
53     ~RtpEncoderG711() override = default;
54 
55     void SetOnRtpPack(const OnRtpPack &cb) override;
56     void InputFrame(const Frame::Ptr &frame) override;
57 
58 private:
59     uint32_t channels_ = 1;
60     FrameImpl::Ptr cacheFrame_ = nullptr;
61 };
62 } // namespace Sharing
63 } // namespace OHOS
64 #endif