WebRtcPusher.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT-like 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. #ifndef ZLMEDIAKIT_WEBRTCPUSHER_H
  11. #define ZLMEDIAKIT_WEBRTCPUSHER_H
  12. #include "WebRtcTransport.h"
  13. #include "Rtsp/RtspMediaSource.h"
  14. namespace mediakit {
  15. class WebRtcPusher : public WebRtcTransportImp, public MediaSourceEvent {
  16. public:
  17. using Ptr = std::shared_ptr<WebRtcPusher>;
  18. static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
  19. const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option);
  20. protected:
  21. ///////WebRtcTransportImp override///////
  22. void onStartWebRTC() override;
  23. void onDestory() override;
  24. void onRtcConfigure(RtcConfigure &configure) const override;
  25. void onRecvRtp(MediaTrack &track, const std::string &rid, RtpPacket::Ptr rtp) override;
  26. void onShutdown(const SockException &ex) override;
  27. void onRtcpBye() override;
  28. // // dtls相关的回调 //// [AUTO-TRANSLATED:31a1f32c]
  29. // // dtls related callbacks ////
  30. void OnDtlsTransportClosed(const RTC::DtlsTransport *dtlsTransport) override;
  31. protected:
  32. ///////MediaSourceEvent override///////
  33. // 关闭 [AUTO-TRANSLATED:92392f02]
  34. // Close
  35. bool close(MediaSource &sender) override;
  36. // 播放总人数 [AUTO-TRANSLATED:c42a3161]
  37. // Total number of players
  38. int totalReaderCount(MediaSource &sender) override;
  39. // 获取媒体源类型 [AUTO-TRANSLATED:34290a69]
  40. // Get media source type
  41. MediaOriginType getOriginType(MediaSource &sender) const override;
  42. // 获取媒体源url或者文件路径 [AUTO-TRANSLATED:fa34d795]
  43. // Get media source url or file path
  44. std::string getOriginUrl(MediaSource &sender) const override;
  45. // 获取媒体源客户端相关信息 [AUTO-TRANSLATED:037ef910]
  46. // Get media source client related information
  47. std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
  48. // 由于支持断连续推,存在OwnerPoller变更的可能 [AUTO-TRANSLATED:1c863b40]
  49. // Due to support for discontinuous pushing, there is a possibility of OwnerPoller changes
  50. toolkit::EventPoller::Ptr getOwnerPoller(MediaSource &sender) override;
  51. // 获取丢包率 [AUTO-TRANSLATED:ec61b378]
  52. // Get packet loss rate
  53. float getLossRate(MediaSource &sender,TrackType type) override;
  54. private:
  55. WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
  56. const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option);
  57. private:
  58. bool _simulcast = false;
  59. // 断连续推延时 [AUTO-TRANSLATED:13ad578a]
  60. // Discontinuous pushing delay
  61. uint32_t _continue_push_ms = 0;
  62. // 媒体相关元数据 [AUTO-TRANSLATED:f4cf8045]
  63. // Media related metadata
  64. MediaInfo _media_info;
  65. // 推流的rtsp源 [AUTO-TRANSLATED:4f976bca]
  66. // Rtsp source of the stream
  67. RtspMediaSource::Ptr _push_src;
  68. // 推流所有权 [AUTO-TRANSLATED:d0ddf5c7]
  69. // Stream ownership
  70. std::shared_ptr<void> _push_src_ownership;
  71. // 推流的rtsp源,支持simulcast [AUTO-TRANSLATED:44be9120]
  72. // Rtsp source of the stream, supports simulcast
  73. std::recursive_mutex _mtx;
  74. std::unordered_map<std::string/*rid*/, RtspMediaSource::Ptr> _push_src_sim;
  75. std::unordered_map<std::string/*rid*/, std::shared_ptr<void> > _push_src_sim_ownership;
  76. };
  77. }// namespace mediakit
  78. #endif //ZLMEDIAKIT_WEBRTCPUSHER_H