track.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 close(void) override;
  39. bool send(message_variant data) override;
  40. bool send(const byte *data, size_t size);
  41. bool isOpen(void) const override;
  42. bool isClosed(void) const override;
  43. size_t maxMessageSize() const override;
  44. // Extended API
  45. size_t availableAmount() const override;
  46. std::optional<message_variant> receive() override;
  47. // RTCP handler
  48. void setRtcpHandler(std::shared_ptr<RtcpHandler> handler);
  49. private:
  50. #if RTC_ENABLE_MEDIA
  51. void open(std::shared_ptr<DtlsSrtpTransport> transport);
  52. std::weak_ptr<DtlsSrtpTransport> mDtlsSrtpTransport;
  53. #endif
  54. bool outgoing(message_ptr message);
  55. void incoming(message_ptr message);
  56. Description::Media mMediaDescription;
  57. std::atomic<bool> mIsClosed = false;
  58. Queue<message_ptr> mRecvQueue;
  59. std::shared_ptr<RtcpHandler> mRtcpHandler;
  60. friend class PeerConnection;
  61. };
  62. } // namespace rtc
  63. #endif