25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.5KB

  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "mk_rtp_server.h"
  11. #include "Util/logger.h"
  12. using namespace toolkit;
  13. #if defined(ENABLE_RTPPROXY)
  14. #include "Rtp/RtpServer.h"
  15. using namespace mediakit;
  16. API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int tcp_mode, const char *stream_id) {
  17. RtpServer::Ptr *server = new RtpServer::Ptr(new RtpServer);
  18. (*server)->start(port, stream_id, (RtpServer::TcpMode)tcp_mode);
  19. return server;
  20. }
  21. 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) {
  22. RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
  23. if (server) {
  24. (*server)->connectToServer(dst_url, dst_port, [cb, user_data](const SockException &ex) {
  25. if (cb) {
  26. cb(user_data, ex.getErrCode(), ex.what(), ex.getCustomCode());
  27. }
  28. });
  29. }
  30. }
  31. API_EXPORT void API_CALL mk_rtp_server_release(mk_rtp_server ctx) {
  32. RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
  33. delete server;
  34. }
  35. API_EXPORT uint16_t API_CALL mk_rtp_server_port(mk_rtp_server ctx) {
  36. RtpServer::Ptr *server = (RtpServer::Ptr *)ctx;
  37. return (*server)->getPort();
  38. }
  39. API_EXPORT void API_CALL mk_rtp_server_set_on_detach(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data) {
  40. RtpServer::Ptr *server = (RtpServer::Ptr *) ctx;
  41. if (cb) {
  42. (*server)->setOnDetach([cb, user_data]() {
  43. cb(user_data);
  44. });
  45. } else {
  46. (*server)->setOnDetach(nullptr);
  47. }
  48. }
  49. #else
  50. API_EXPORT mk_rtp_server API_CALL mk_rtp_server_create(uint16_t port, int enable_tcp, const char *stream_id) {
  51. WarnL << "请打开ENABLE_RTPPROXY后再编译";
  52. return nullptr;
  53. }
  54. API_EXPORT void API_CALL mk_rtp_server_release(mk_rtp_server ctx) {
  55. WarnL << "请打开ENABLE_RTPPROXY后再编译";
  56. }
  57. API_EXPORT uint16_t API_CALL mk_rtp_server_port(mk_rtp_server ctx) {
  58. WarnL << "请打开ENABLE_RTPPROXY后再编译";
  59. return 0;
  60. }
  61. API_EXPORT void API_CALL mk_rtp_server_set_on_detach(mk_rtp_server ctx, on_mk_rtp_server_detach cb, void *user_data) {
  62. WarnL << "请打开ENABLE_RTPPROXY后再编译";
  63. }
  64. #endif