G711Rtp.h 2.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
 * 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.
 */

#ifndef ZLMEDIAKIT_G711RTPCODEC_H
#define ZLMEDIAKIT_G711RTPCODEC_H
#include "Rtsp/RtpCodec.h"
#include "Extension/G711.h"
namespace mediakit{
xiongziliang committed
16

17
/**
xiongziliang committed
18
 * rtp转G711类
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 */
class G711RtpDecoder : public RtpCodec , public ResourcePoolHelper<G711Frame> {
public:
    typedef std::shared_ptr<G711RtpDecoder> Ptr;

    G711RtpDecoder(const Track::Ptr &track);
    ~G711RtpDecoder() {}

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

    CodecId getCodecId() const override{
        return _codecid;
    }
xiongziliang committed
37

38
protected:
xiongziliang committed
39 40
    G711RtpDecoder() {}

41 42 43
private:
    void onGetG711(const G711Frame::Ptr &frame);
    G711Frame::Ptr obtainFrame();
xiongziliang committed
44

45
private:
xiongziliang committed
46 47
    G711Frame::Ptr _frame;
    CodecId _codecid;
48 49 50 51 52 53 54 55 56 57 58 59 60
};

/**
 * g711 转rtp类
 */
class G711RtpEncoder : public G711RtpDecoder , public RtpInfo {
public:
    typedef std::shared_ptr<G711RtpEncoder> Ptr;

    /**
     * @param ui32Ssrc ssrc
     * @param ui32MtuSize mtu 大小
     * @param ui32SampleRate 采样率
xiongziliang committed
61
     * @param ui8PayloadType pt类型
62 63 64
     * @param ui8Interleaved rtsp interleaved 值
     */
    G711RtpEncoder(uint32_t ui32Ssrc,
xiongziliang committed
65 66
                   uint32_t ui32MtuSize,
                   uint32_t ui32SampleRate,
xiongziliang committed
67
                   uint8_t ui8PayloadType = 0,
xiongziliang committed
68
                   uint8_t ui8Interleaved = TrackAudio * 2);
69 70 71 72 73 74 75 76 77 78 79 80 81
    ~G711RtpEncoder() {}

    /**
     * @param frame g711数据
     */
    void inputFrame(const Frame::Ptr &frame) override;
private:
    void makeG711Rtp(const void *pData, unsigned int uiLen, bool bMark, uint32_t uiStamp);
};

}//namespace mediakit

#endif //ZLMEDIAKIT_G711RTPCODEC_H