track.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Copyright (c) 2020 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_TRACK_H
  19. #define RTC_TRACK_H
  20. #include "channel.hpp"
  21. #include "description.hpp"
  22. #include "include.hpp"
  23. #include "message.hpp"
  24. #include "queue.hpp"
  25. #include "rtcphandler.hpp"
  26. #include <atomic>
  27. #include <variant>
  28. #include <shared_mutex>
  29. namespace rtc {
  30. #if RTC_ENABLE_MEDIA
  31. class DtlsSrtpTransport;
  32. #endif
  33. class RTC_CPP_EXPORT Track final : public std::enable_shared_from_this<Track>, public Channel {
  34. public:
  35. Track(Description::Media description);
  36. ~Track() = default;
  37. string mid() const;
  38. Description::Media description() const;
  39. void setDescription(Description::Media description);
  40. void close(void) override;
  41. bool send(message_variant data) override;
  42. bool send(const byte *data, size_t size) override;
  43. bool isOpen(void) const override;
  44. bool isClosed(void) const override;
  45. size_t maxMessageSize() const override;
  46. // Extended API
  47. size_t availableAmount() const override;
  48. std::optional<message_variant> receive() override;
  49. std::optional<message_variant> peek() override;
  50. bool requestKeyframe();
  51. // RTCP handler
  52. void setRtcpHandler(std::shared_ptr<RtcpHandler> handler);
  53. std::shared_ptr<RtcpHandler> getRtcpHandler();
  54. private:
  55. #if RTC_ENABLE_MEDIA
  56. void open(std::shared_ptr<DtlsSrtpTransport> transport);
  57. std::weak_ptr<DtlsSrtpTransport> mDtlsSrtpTransport;
  58. #endif
  59. void incoming(message_ptr message);
  60. bool outgoing(message_ptr message);
  61. Description::Media mMediaDescription;
  62. std::atomic<bool> mIsClosed = false;
  63. Queue<message_ptr> mRecvQueue;
  64. std::shared_mutex mRtcpHandlerMutex;
  65. std::shared_ptr<RtcpHandler> mRtcpHandler;
  66. friend class PeerConnection;
  67. };
  68. } // namespace rtc
  69. #endif