添加GB28181相关c api: #491

This commit is contained in:
xiongziliang 2020-09-20 21:23:33 +08:00
parent 08a5891bdc
commit adb3be70d0
3 changed files with 99 additions and 0 deletions

View File

@ -22,5 +22,6 @@
#include "mk_tcp.h"
#include "mk_util.h"
#include "mk_thread.h"
#include "mk_rtp_server.h"
#endif /* MK_API_H_ */

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* 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.
*/
#include "mk_common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void* mk_rtp_server;
/**
* GB28181 RTP
* @param port 0
* @param enable_tcp udp端口时是否同时监听tcp端口
* @param stream_id id
* @return
*/
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int enable_tcp, const char *stream_id);
/**
* GB28181 RTP
* @param ctx
*/
API_EXPORT void API_CALL mk_rtp_server_release(mk_rtp_server ctx);
/**
*
* @param ctx
* @return
*/
API_EXPORT uint16_t API_CALL mk_rtp_server_port(mk_rtp_server ctx);
/**
* GB28181 RTP
* @param user_data
*/
typedef void(API_CALL *on_mk_rtp_server_detach)(void *user_data);
/**
* B28181 RTP
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_rtp_server_set_on_detach(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* 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.
*/
#include "mk_rtp_server.h"
#include "Rtp/RtpServer.h"
using namespace mediakit;
API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int enable_tcp, const char *stream_id){
RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
(*server)->start(port, stream_id, enable_tcp);
return server;
}
API_EXPORT void API_CALL mk_rtp_server_release(mk_rtp_server ctx){
RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
delete server;
}
API_EXPORT uint16_t API_CALL mk_rtp_server_port(mk_rtp_server ctx){
RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
return (*server)->getPort();
}
API_EXPORT void API_CALL mk_rtp_server_set_on_detach(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data){
RtpServer::Ptr *server = (RtpServer::Ptr *) ctx;
if (cb) {
(*server)->setOnDetach([cb, user_data]() {
cb(user_data);
});
} else {
(*server)->setOnDetach(nullptr);
}
}