G711.h 1.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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_G711_H
#define ZLMEDIAKIT_G711_H

#include "Frame.h"
#include "Track.h"

namespace mediakit{

/**
xiongziliang committed
20
 * G711音频通道
21
 */
xiongziliang committed
22
class G711Track : public AudioTrackImp{
23 24
public:
    typedef std::shared_ptr<G711Track> Ptr;
xiongziliang committed
25
    G711Track(CodecId codecId,int sample_rate, int channels, int sample_bit) : AudioTrackImp(codecId,sample_rate,channels,sample_bit){}
26 27

private:
xiongziliang committed
28
    //克隆该Track
29 30 31 32 33 34 35 36
    Track::Ptr clone() override {
        return std::make_shared<std::remove_reference<decltype(*this)>::type >(*this);
    }
    //生成sdp
    Sdp::Ptr getSdp() override ;
};

/**
xiongziliang committed
37 38
 * G711类型SDP
 */
39 40 41
class G711Sdp : public Sdp {
public:
    /**
xiongziliang committed
42 43
     * G711采样率固定为8000
     * @param codecId G711A G711U
xiongziliang committed
44
     * @param sample_rate 音频采样率
xiongziliang committed
45
     * @param payload_type rtp payload
xiongziliang committed
46
     * @param bitrate 比特率
47
     */
xiongziliang committed
48 49 50
    G711Sdp(CodecId codecId,
            int sample_rate,
            int channels,
xiongziliang committed
51 52 53 54
            int payload_type = 98,
            int bitrate = 128) : Sdp(sample_rate,payload_type), _codecId(codecId){
        _printer << "m=audio 0 RTP/AVP " << payload_type << "\r\n";
        _printer << "a=rtpmap:" << payload_type << (codecId == CodecG711A ? " PCMA/" : " PCMU/") << sample_rate  << "/" << channels << "\r\n";
xiongziliang committed
55
        _printer << "a=control:trackID=" << (int)TrackAudio << "\r\n";
56 57 58 59 60 61 62 63 64 65 66
    }

    string getSdp() const override {
        return _printer;
    }

    CodecId getCodecId() const override {
        return _codecId;
    }
private:
    _StrPrinter _printer;
xiongziliang committed
67
    CodecId _codecId;
68 69 70
};

}//namespace mediakit
xiongziliang committed
71
#endif //ZLMEDIAKIT_G711_H