RtspMuxer.cpp 2.34 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.
*/
xiongziliang committed
26

27
#include "RtspMuxer.h"
28
#include "Extension/Factory.h"
xiongziliang committed
29

xiongziliang committed
30
namespace mediakit {
xiongziliang committed
31

32 33 34 35 36
RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title){
    if(!title){
        _sdp = std::make_shared<TitleSdp>()->getSdp();
    } else{
        _sdp = title->getSdp();
xiongziliang committed
37
    }
xiongziliang committed
38
    _rtpRing = std::make_shared<RtpRing::RingType>();
39
}
xiongziliang committed
40

xiongziliang committed
41
void RtspMuxer::addTrack(const Track::Ptr &track) {
3503207480@qq.com committed
42
    //根据track生成sdp
xiongziliang committed
43
    Sdp::Ptr sdp = track->getSdp();
44 45 46
    if (!sdp) {
        return;
    }
xiongziliang committed
47 48 49

    auto &encoder = _encoder[track->getTrackType()];
    encoder = Factory::getRtpEncoderBySdp(sdp);
50 51
    if (!encoder) {
        return;
xiongziliang committed
52
    }
xiongziliang committed
53 54 55 56

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

57 58
    //添加其sdp
    _sdp.append(sdp->getSdp());
xiongziliang committed
59 60
}

xiongziliang committed
61 62 63 64
void RtspMuxer::inputFrame(const Frame::Ptr &frame) {
    auto &encoder = _encoder[frame->getTrackType()];
    if(encoder){
        encoder->inputFrame(frame);
xiongziliang committed
65
    }
xiongziliang committed
66 67 68
}

string RtspMuxer::getSdp() {
xiongziliang committed
69
    return _sdp;
xiongziliang committed
70 71
}

xiongziliang committed
72
RtpRing::RingType::Ptr RtspMuxer::getRtpRing() const {
xiongziliang committed
73 74 75
    return _rtpRing;
}

xiongziliang committed
76 77 78 79 80 81 82
void RtspMuxer::resetTracks() {
    _sdp.clear();
    for(auto &encoder : _encoder){
        encoder = nullptr;
    }
}

83

xiongziliang committed
84
} /* namespace mediakit */