RtspMuxer.cpp 1.53 KB
Newer Older
1
/*
xiongziliang committed
2 3
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
xiongziliang committed
5 6 7 8 9
 *
 * 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.
 */
xiongziliang committed
10

11
#include "RtspMuxer.h"
12
#include "Extension/Factory.h"
xiongziliang committed
13

xiongziliang committed
14
namespace mediakit {
xiongziliang committed
15

16 17 18 19 20
RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title){
    if(!title){
        _sdp = std::make_shared<TitleSdp>()->getSdp();
    } else{
        _sdp = title->getSdp();
xiongziliang committed
21
    }
xiongziliang committed
22
    _rtpRing = std::make_shared<RtpRing::RingType>();
23
}
xiongziliang committed
24

xiongziliang committed
25
void RtspMuxer::addTrack(const Track::Ptr &track) {
3503207480@qq.com committed
26
    //根据track生成sdp
xiongziliang committed
27
    Sdp::Ptr sdp = track->getSdp();
28 29 30
    if (!sdp) {
        return;
    }
xiongziliang committed
31 32 33

    auto &encoder = _encoder[track->getTrackType()];
    encoder = Factory::getRtpEncoderBySdp(sdp);
34 35
    if (!encoder) {
        return;
xiongziliang committed
36
    }
xiongziliang committed
37 38 39 40

    //设置rtp输出环形缓存
    encoder->setRtpRing(_rtpRing);

41 42
    //添加其sdp
    _sdp.append(sdp->getSdp());
xiongziliang committed
43 44
}

xiongziliang committed
45 46 47 48
void RtspMuxer::inputFrame(const Frame::Ptr &frame) {
    auto &encoder = _encoder[frame->getTrackType()];
    if(encoder){
        encoder->inputFrame(frame);
xiongziliang committed
49
    }
xiongziliang committed
50 51 52
}

string RtspMuxer::getSdp() {
xiongziliang committed
53
    return _sdp;
xiongziliang committed
54 55
}

xiongziliang committed
56
RtpRing::RingType::Ptr RtspMuxer::getRtpRing() const {
xiongziliang committed
57 58 59
    return _rtpRing;
}

xiongziliang committed
60 61 62 63 64 65 66
void RtspMuxer::resetTracks() {
    _sdp.clear();
    for(auto &encoder : _encoder){
        encoder = nullptr;
    }
}

67

xiongziliang committed
68
} /* namespace mediakit */