track.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2020-2021 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_IMPL_TRACK_H
  19. #define RTC_IMPL_TRACK_H
  20. #include "channel.hpp"
  21. #include "common.hpp"
  22. #include "description.hpp"
  23. #include "mediahandler.hpp"
  24. #include "queue.hpp"
  25. #if RTC_ENABLE_MEDIA
  26. #include "dtlssrtptransport.hpp"
  27. #endif
  28. #include <atomic>
  29. #include <shared_mutex>
  30. namespace rtc::impl {
  31. struct PeerConnection;
  32. class Track final : public std::enable_shared_from_this<Track>, public Channel {
  33. public:
  34. Track(weak_ptr<PeerConnection> pc, Description::Media description);
  35. ~Track();
  36. void close();
  37. void incoming(message_ptr message);
  38. bool outgoing(message_ptr message);
  39. optional<message_variant> receive() override;
  40. optional<message_variant> peek() override;
  41. size_t availableAmount() const override;
  42. bool isOpen() const;
  43. bool isClosed() const;
  44. size_t maxMessageSize() const;
  45. string mid() const;
  46. Description::Direction direction() const;
  47. Description::Media description() const;
  48. void setDescription(Description::Media description);
  49. shared_ptr<MediaHandler> getMediaHandler();
  50. void setMediaHandler(shared_ptr<MediaHandler> handler);
  51. #if RTC_ENABLE_MEDIA
  52. void open(shared_ptr<DtlsSrtpTransport> transport);
  53. #endif
  54. private:
  55. bool transportSend(message_ptr message);
  56. const weak_ptr<PeerConnection> mPeerConnection;
  57. #if RTC_ENABLE_MEDIA
  58. weak_ptr<DtlsSrtpTransport> mDtlsSrtpTransport;
  59. #endif
  60. Description::Media mMediaDescription;
  61. shared_ptr<MediaHandler> mMediaHandler;
  62. mutable std::shared_mutex mMutex;
  63. std::atomic<bool> mIsClosed = false;
  64. Queue<message_ptr> mRecvQueue;
  65. };
  66. } // namespace rtc::impl
  67. #endif