AACRtp.h 2.12 KB
Newer Older
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
3
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
5
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
9
 */
10 11 12 13

#ifndef ZLMEDIAKIT_AACRTPCODEC_H
#define ZLMEDIAKIT_AACRTPCODEC_H

xiongziliang committed
14
#include "Rtsp/RtpCodec.h"
15
#include "Extension/AAC.h"
xiongziliang committed
16
namespace mediakit{
17 18 19
/**
 * aac rtp转adts类
 */
20
class AACRtpDecoder : public RtpCodec {
21
public:
xiongziliang committed
22 23
    typedef std::shared_ptr<AACRtpDecoder> Ptr;

24
    AACRtpDecoder(const Track::Ptr &track);
xiongziliang committed
25 26
    ~AACRtpDecoder() {}

27 28 29 30 31
    /**
     * 输入rtp并解码
     * @param rtp rtp数据包
     * @param key_pos 此参数内部强制转换为false,请忽略之
     */
xiongziliang committed
32
    bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = false) override;
33

34
    CodecId getCodecId() const override {
35 36
        return CodecAAC;
    }
37

38 39
protected:
    AACRtpDecoder();
40

41
private:
42
    void obtainFrame();
43
    void flushData();
44

45
private:
46
    uint32_t _last_dts = 0;
47 48
    string _aac_cfg;
    FrameImp::Ptr _frame;
49 50 51
};


52 53 54
/**
 * aac adts转rtp类
 */
55
class AACRtpEncoder : public AACRtpDecoder , public RtpInfo {
xiongziliang committed
56
public:
xiongziliang committed
57 58
    typedef std::shared_ptr<AACRtpEncoder> Ptr;

59 60 61 62
    /**
     * @param ui32Ssrc ssrc
     * @param ui32MtuSize mtu 大小
     * @param ui32SampleRate 采样率
xiongziliang committed
63
     * @param ui8PayloadType pt类型
64 65
     * @param ui8Interleaved rtsp interleaved 值
     */
xiongziliang committed
66 67 68
    AACRtpEncoder(uint32_t ui32Ssrc,
                  uint32_t ui32MtuSize,
                  uint32_t ui32SampleRate,
xiongziliang committed
69
                  uint8_t ui8PayloadType = 97,
xiongziliang committed
70 71 72
                  uint8_t ui8Interleaved = TrackAudio * 2);
    ~AACRtpEncoder() {}

73 74 75 76
    /**
     * 输入aac 数据,必须带dats头
     * @param frame 带dats头的aac数据
     */
77
    void inputFrame(const Frame::Ptr &frame) override;
78

xiongziliang committed
79
private:
80
    void makeAACRtp(const void *pData, size_t uiLen, bool bMark, uint32_t uiStamp);
81

xiongziliang committed
82
private:
xiongziliang committed
83
    unsigned char _section_buf[1600];
xiongziliang committed
84 85
};

xiongziliang committed
86
}//namespace mediakit
xiongziliang committed
87

88
#endif //ZLMEDIAKIT_AACRTPCODEC_H