PusherBase.cpp 1.93 KB
Newer Older
xiongziliang committed
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 12 13 14 15 16 17 18 19

#include <algorithm>
#include "PusherBase.h"
#include "Rtsp/RtspPusher.h"
#include "Rtmp/RtmpPusher.h"

using namespace toolkit;

namespace mediakit {

20 21
PusherBase::Ptr PusherBase::createPusher(const EventPoller::Ptr &poller,
                                         const MediaSource::Ptr &src,
22
                                         const std::string & url) {
xiongziliang committed
23 24 25 26 27 28
    static auto releasePusher = [](PusherBase *ptr){
        onceToken token(nullptr,[&](){
            delete  ptr;
        });
        ptr->teardown();
    };
29
    std::string prefix = FindField(url.data(), NULL, "://");
30 31

    if (strcasecmp("rtsps",prefix.data()) == 0) {
夏楚 committed
32
        return PusherBase::Ptr(new TcpClientWithSSL<RtspPusherImp>(poller, std::dynamic_pointer_cast<RtspMediaSource>(src)), releasePusher);
33 34
    }

xiongziliang committed
35
    if (strcasecmp("rtsp",prefix.data()) == 0) {
夏楚 committed
36
        return PusherBase::Ptr(new RtspPusherImp(poller, std::dynamic_pointer_cast<RtspMediaSource>(src)), releasePusher);
xiongziliang committed
37
    }
38 39

    if (strcasecmp("rtmps",prefix.data()) == 0) {
夏楚 committed
40
        return PusherBase::Ptr(new TcpClientWithSSL<RtmpPusherImp>(poller, std::dynamic_pointer_cast<RtmpMediaSource>(src)), releasePusher);
41 42
    }

xiongziliang committed
43
    if (strcasecmp("rtmp",prefix.data()) == 0) {
夏楚 committed
44
        return PusherBase::Ptr(new RtmpPusherImp(poller, std::dynamic_pointer_cast<RtmpMediaSource>(src)), releasePusher);
xiongziliang committed
45
    }
46

47
    throw std::invalid_argument("not supported push schema:" + url);
xiongziliang committed
48 49 50
}

PusherBase::PusherBase() {
夏楚 committed
51 52
    this->mINI::operator[](Client::kTimeoutMS) = 10000;
    this->mINI::operator[](Client::kBeatIntervalMS) = 5000;
xiongziliang committed
53 54 55
}

} /* namespace mediakit */