mediahandler.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright (c) 2020 Staz Modrzynski
  3. * Copyright (c) 2020 Paul-Louis Ageneau
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  8. */
  9. #ifndef RTC_MEDIA_HANDLER_H
  10. #define RTC_MEDIA_HANDLER_H
  11. #include "common.hpp"
  12. #include "description.hpp"
  13. #include "message.hpp"
  14. namespace rtc {
  15. class RTC_CPP_EXPORT MediaHandler : public std::enable_shared_from_this<MediaHandler> {
  16. public:
  17. MediaHandler();
  18. virtual ~MediaHandler();
  19. /// Called when a media is added or updated
  20. /// @param desc Description of the media
  21. virtual void media([[maybe_unused]] const Description::Media &desc) {}
  22. /// Called when there is traffic coming from the peer
  23. /// @param messages Incoming messages from the peer, can be modified by the handler
  24. /// @param send Send callback to send messages back to the peer
  25. virtual void incoming([[maybe_unused]] message_vector &messages, [[maybe_unused]] const message_callback &send) {}
  26. /// Called when there is traffic that needs to be sent to the peer
  27. /// @param messages Outgoing messages to the peer, can be modified by the handler
  28. /// @param send Send callback to send messages back to the peer
  29. virtual void outgoing([[maybe_unused]] message_vector &messages, [[maybe_unused]] const message_callback &send) {}
  30. virtual bool requestKeyframe(const message_callback &send);
  31. virtual bool requestBitrate(unsigned int bitrate, const message_callback &send);
  32. void addToChain(shared_ptr<MediaHandler> handler);
  33. void setNext(shared_ptr<MediaHandler> handler);
  34. shared_ptr<MediaHandler> next();
  35. shared_ptr<const MediaHandler> next() const;
  36. shared_ptr<MediaHandler> last(); // never null
  37. shared_ptr<const MediaHandler> last() const; // never null
  38. void mediaChain(const Description::Media &desc);
  39. void incomingChain(message_vector &messages, const message_callback &send);
  40. void outgoingChain(message_vector &messages, const message_callback &send);
  41. private:
  42. shared_ptr<MediaHandler> mNext;
  43. };
  44. } // namespace rtc
  45. #endif // RTC_MEDIA_HANDLER_H