AACRtp.h 2.15 KB
Newer Older
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
3 4 5
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
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 , public ResourcePoolHelper<AACFrame> {
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 35 36

    CodecId getCodecId() const override{
        return CodecAAC;
    }
37 38
protected:
    AACRtpDecoder();
39
private:
40
    AACFrame::Ptr obtainFrame();
41
    void flushData();
42
private:
43
    AACFrame::Ptr _adts;
44
    string _aac_cfg;
45 46 47
};


48 49 50
/**
 * aac adts转rtp类
 */
51
class AACRtpEncoder : public AACRtpDecoder , public RtpInfo {
xiongziliang committed
52
public:
xiongziliang committed
53 54
    typedef std::shared_ptr<AACRtpEncoder> Ptr;

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

69 70 71 72
    /**
     * 输入aac 数据,必须带dats头
     * @param frame 带dats头的aac数据
     */
73
    void inputFrame(const Frame::Ptr &frame) override;
xiongziliang committed
74 75 76
private:
    void makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
private:
77
    unsigned char _aucSectionBuf[1600];
xiongziliang committed
78 79
};

xiongziliang committed
80
}//namespace mediakit
xiongziliang committed
81

82
#endif //ZLMEDIAKIT_AACRTPCODEC_H