MediaPusher.cpp 1.86 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

#include <algorithm>
#include "MediaPusher.h"
#include "PusherBase.h"

using namespace toolkit;

namespace mediakit {

19 20
MediaPusher::MediaPusher(const MediaSource::Ptr &src,
                         const EventPoller::Ptr &poller) {
xiongziliang committed
21
    _src = src;
22
    _poller = poller ? poller : EventPollerPool::Instance().getPoller();
xiongziliang committed
23 24 25
}

MediaPusher::MediaPusher(const string &schema,
26 27 28
                         const string &vhost,
                         const string &app,
                         const string &stream,
29
                         const EventPoller::Ptr &poller) :
30
        MediaPusher(MediaSource::find(schema, vhost, app, stream), poller){
xiongziliang committed
31 32 33 34
}

MediaPusher::~MediaPusher() {
}
35 36 37 38 39 40 41 42 43 44 45 46

static void setOnCreateSocket_l(const std::shared_ptr<PusherBase> &delegate, const Socket::onCreateSocket &cb){
    auto helper = dynamic_pointer_cast<SocketHelper>(delegate);
    if (helper) {
        helper->setOnCreateSocket(cb);
    }
}

void MediaPusher::publish(const string &url) {
    _delegate = PusherBase::createPusher(_poller, _src.lock(), url);
    assert(_delegate);
    setOnCreateSocket_l(_delegate, _on_create_socket);
xiongziliang committed
47 48 49
    _delegate->setOnShutdown(_shutdownCB);
    _delegate->setOnPublished(_publishCB);
    _delegate->mINI::operator=(*this);
50
    _delegate->publish(url);
xiongziliang committed
51 52 53
}

EventPoller::Ptr MediaPusher::getPoller(){
54
    return _poller;
xiongziliang committed
55 56
}

57 58 59 60
void MediaPusher::setOnCreateSocket(Socket::onCreateSocket cb){
    setOnCreateSocket_l(_delegate, cb);
    _on_create_socket = std::move(cb);
}
xiongziliang committed
61 62

} /* namespace mediakit */