2020-09-20 21:23:33 +08:00
|
|
|
|
/*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
2020-09-20 21:23:33 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
2020-09-20 21:23:33 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Use of this source code is governed by MIT-like license that can be found in the
|
2020-09-20 21:23:33 +08:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mk_rtp_server.h"
|
2020-09-27 16:54:55 +08:00
|
|
|
|
#include "Util/logger.h"
|
|
|
|
|
using namespace toolkit;
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_RTPPROXY)
|
2020-09-20 21:23:33 +08:00
|
|
|
|
#include "Rtp/RtpServer.h"
|
2024-08-19 17:39:50 +08:00
|
|
|
|
#include "Common/config.h"
|
2020-09-20 21:23:33 +08:00
|
|
|
|
using namespace mediakit;
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int tcp_mode, const char *stream_id) {
|
2020-09-20 21:23:33 +08:00
|
|
|
|
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
|
2024-08-01 11:03:26 +08:00
|
|
|
|
GET_CONFIG(std::string, local_ip, General::kListenIP)
|
|
|
|
|
(*server)->start(port, local_ip.c_str(), MediaTuple { DEFAULT_VHOST, kRtpAppName, stream_id, "" }, (RtpServer::TcpMode)tcp_mode);
|
2024-07-09 10:42:10 +08:00
|
|
|
|
return (mk_rtp_server)server;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create2(uint16_t port, int tcp_mode, const char *vhost, const char *app, const char *stream_id) {
|
|
|
|
|
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
|
2024-08-01 11:03:26 +08:00
|
|
|
|
GET_CONFIG(std::string, local_ip, General::kListenIP)
|
|
|
|
|
(*server)->start(port, local_ip.c_str(), MediaTuple { vhost, app, stream_id, "" }, (RtpServer::TcpMode)tcp_mode);
|
2023-02-26 21:45:14 +08:00
|
|
|
|
return (mk_rtp_server)server;
|
2020-09-20 21:23:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_connect(mk_rtp_server ctx, const char *dst_url, uint16_t dst_port, on_mk_rtp_server_connected cb, void *user_data) {
|
2023-02-11 15:14:18 +08:00
|
|
|
|
mk_rtp_server_connect2(ctx, dst_url, dst_port, cb, user_data, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_connect2(mk_rtp_server ctx, const char *dst_url, uint16_t dst_port, on_mk_rtp_server_connected cb, void *user_data, on_user_data_free user_data_free){
|
2022-09-09 10:56:28 +08:00
|
|
|
|
RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
|
|
|
|
|
if (server) {
|
2023-02-11 15:14:18 +08:00
|
|
|
|
std::shared_ptr<void> ptr(user_data, user_data_free ? user_data_free : [](void *) {});
|
|
|
|
|
(*server)->connectToServer(dst_url, dst_port, [cb, ptr](const SockException &ex) {
|
2022-09-09 10:56:28 +08:00
|
|
|
|
if (cb) {
|
2023-02-11 15:14:18 +08:00
|
|
|
|
cb(ptr.get(), ex.getErrCode(), ex.what(), ex.getCustomCode());
|
2022-09-09 10:56:28 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_release(mk_rtp_server ctx) {
|
2020-09-20 21:23:33 +08:00
|
|
|
|
RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
|
|
|
|
|
delete server;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT uint16_t API_CALL mk_rtp_server_port(mk_rtp_server ctx) {
|
2020-09-20 21:23:33 +08:00
|
|
|
|
RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
|
|
|
|
|
return (*server)->getPort();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_set_on_detach(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data) {
|
2023-02-11 15:14:18 +08:00
|
|
|
|
mk_rtp_server_set_on_detach2(ctx, cb, user_data, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_set_on_detach2(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data, on_user_data_free user_data_free){
|
2020-09-20 21:23:33 +08:00
|
|
|
|
RtpServer::Ptr *server = (RtpServer::Ptr *) ctx;
|
|
|
|
|
if (cb) {
|
2023-02-11 15:14:18 +08:00
|
|
|
|
std::shared_ptr<void> ptr(user_data, user_data_free ? user_data_free : [](void *) {});
|
2024-06-09 10:52:10 +08:00
|
|
|
|
(*server)->setOnDetach([cb, ptr](const SockException &ex) {
|
2023-02-11 15:14:18 +08:00
|
|
|
|
cb(ptr.get());
|
2020-09-20 21:23:33 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
(*server)->setOnDetach(nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-27 16:54:55 +08:00
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int enable_tcp, const char *stream_id) {
|
2020-09-27 16:54:55 +08:00
|
|
|
|
WarnL << "请打开ENABLE_RTPPROXY后再编译";
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-09 10:42:10 +08:00
|
|
|
|
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create2(uint16_t port, int tcp_mode, const char *vhost, const char *app, const char *stream_id) {
|
|
|
|
|
WarnL << "请打开ENABLE_RTPPROXY后再编译";
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_release(mk_rtp_server ctx) {
|
2020-09-27 16:54:55 +08:00
|
|
|
|
WarnL << "请打开ENABLE_RTPPROXY后再编译";
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT uint16_t API_CALL mk_rtp_server_port(mk_rtp_server ctx) {
|
2020-09-27 16:54:55 +08:00
|
|
|
|
WarnL << "请打开ENABLE_RTPPROXY后再编译";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 10:56:28 +08:00
|
|
|
|
API_EXPORT void API_CALL mk_rtp_server_set_on_detach(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data) {
|
2020-09-27 16:54:55 +08:00
|
|
|
|
WarnL << "请打开ENABLE_RTPPROXY后再编译";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|