track.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "rtcp.hpp"
  26. #include <atomic>
  27. #include <variant>
  28. namespace rtc {
  29. #if RTC_ENABLE_MEDIA
  30. class DtlsSrtpTransport;
  31. #endif
  32. class Track final : public std::enable_shared_from_this<Track>, public Channel {
  33. public:
  34. Track(Description::Media description);
  35. ~Track() = default;
  36. string mid() const;
  37. Description::Media description() const;
  38. void setDescription(Description::Media description);
  39. void close(void) override;
  40. bool send(message_variant data) override;
  41. bool send(const byte *data, size_t size);
  42. bool isOpen(void) const override;
  43. bool isClosed(void) const override;
  44. size_t maxMessageSize() const override;
  45. // Extended API
  46. size_t availableAmount() const override;
  47. std::optional<message_variant> receive() override;
  48. std::optional<message_variant> peek() override;
  49. bool requestKeyframe();
  50. // RTCP handler
  51. void setRtcpHandler(std::shared_ptr<RtcpHandler> handler);
  52. std::shared_ptr<RtcpHandler> getRtcpHandler();
  53. private:
  54. #if RTC_ENABLE_MEDIA
  55. void open(std::shared_ptr<DtlsSrtpTransport> transport);
  56. std::weak_ptr<DtlsSrtpTransport> mDtlsSrtpTransport;
  57. #endif
  58. bool outgoing(message_ptr message);
  59. void incoming(message_ptr message);
  60. Description::Media mMediaDescription;
  61. std::atomic<bool> mIsClosed = false;
  62. Queue<message_ptr> mRecvQueue;
  63. std::shared_ptr<RtcpHandler> mRtcpHandler;
  64. friend class PeerConnection;
  65. };
  66. } // namespace rtc
  67. #endif