AACRtp.h 3.08 KB
Newer Older
1 2 3
/*
 * MIT License
 *
xiongziliang committed
4
 * Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
26 27 28 29

#ifndef ZLMEDIAKIT_AACRTPCODEC_H
#define ZLMEDIAKIT_AACRTPCODEC_H

xiongziliang committed
30
#include "Rtsp/RtpCodec.h"
31
#include "Extension/AAC.h"
xiongziliang committed
32
namespace mediakit{
33 34 35
/**
 * aac rtp转adts类
 */
36
class AACRtpDecoder : public RtpCodec , public ResourcePoolHelper<AACFrame> {
37
public:
xiongziliang committed
38 39
    typedef std::shared_ptr<AACRtpDecoder> Ptr;

40
    AACRtpDecoder(const Track::Ptr &track);
xiongziliang committed
41 42
    ~AACRtpDecoder() {}

43 44 45 46 47
    /**
     * 输入rtp并解码
     * @param rtp rtp数据包
     * @param key_pos 此参数内部强制转换为false,请忽略之
     */
xiongziliang committed
48
    bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = false) override;
49 50 51 52 53 54 55

    TrackType getTrackType() const override{
        return TrackAudio;
    }
    CodecId getCodecId() const override{
        return CodecAAC;
    }
56 57
protected:
    AACRtpDecoder();
58
private:
59
    void onGetAAC(const AACFrame::Ptr &frame);
60
    AACFrame::Ptr obtainFrame();
61
private:
62
    AACFrame::Ptr _adts;
63
    string _aac_cfg;
64 65 66
};


67 68 69
/**
 * aac adts转rtp类
 */
70
class AACRtpEncoder : public AACRtpDecoder , public RtpInfo {
xiongziliang committed
71
public:
xiongziliang committed
72 73
    typedef std::shared_ptr<AACRtpEncoder> Ptr;

74 75 76 77 78 79 80
    /**
     * @param ui32Ssrc ssrc
     * @param ui32MtuSize mtu 大小
     * @param ui32SampleRate 采样率
     * @param ui8PlayloadType pt类型
     * @param ui8Interleaved rtsp interleaved 值
     */
xiongziliang committed
81 82 83 84 85 86 87
    AACRtpEncoder(uint32_t ui32Ssrc,
                  uint32_t ui32MtuSize,
                  uint32_t ui32SampleRate,
                  uint8_t ui8PlayloadType = 97,
                  uint8_t ui8Interleaved = TrackAudio * 2);
    ~AACRtpEncoder() {}

88 89 90 91
    /**
     * 输入aac 数据,必须带dats头
     * @param frame 带dats头的aac数据
     */
92
    void inputFrame(const Frame::Ptr &frame) override;
xiongziliang committed
93 94 95
private:
    void makeAACRtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
private:
96
    unsigned char _aucSectionBuf[1600];
xiongziliang committed
97 98
};

xiongziliang committed
99
}//namespace mediakit
xiongziliang committed
100

101
#endif //ZLMEDIAKIT_AACRTPCODEC_H