helpers.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * libdatachannel streamer example
  3. * Copyright (c) 2020 Filip Klembara (in2core)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef helpers_hpp
  19. #define helpers_hpp
  20. #include "rtc/rtc.hpp"
  21. #include <shared_mutex>
  22. struct ClientTrackData {
  23. std::shared_ptr<rtc::Track> track;
  24. std::shared_ptr<rtc::RtcpSrReporter> sender;
  25. ClientTrackData(std::shared_ptr<rtc::Track> track, std::shared_ptr<rtc::RtcpSrReporter> sender);
  26. };
  27. struct Client {
  28. enum class State {
  29. Waiting,
  30. WaitingForVideo,
  31. WaitingForAudio,
  32. Ready
  33. };
  34. const std::shared_ptr<rtc::PeerConnection> & peerConnection = _peerConnection;
  35. Client(std::shared_ptr<rtc::PeerConnection> pc) {
  36. _peerConnection = pc;
  37. }
  38. std::optional<std::shared_ptr<ClientTrackData>> video;
  39. std::optional<std::shared_ptr<ClientTrackData>> audio;
  40. std::optional<std::shared_ptr<rtc::DataChannel>> dataChannel{};
  41. void setState(State state);
  42. State getState();
  43. private:
  44. std::shared_mutex _mutex;
  45. State state = State::Waiting;
  46. std::string id;
  47. std::shared_ptr<rtc::PeerConnection> _peerConnection;
  48. };
  49. struct ClientTrack {
  50. std::string id;
  51. std::shared_ptr<ClientTrackData> trackData;
  52. ClientTrack(std::string id, std::shared_ptr<ClientTrackData> trackData);
  53. };
  54. uint64_t currentTimeInMicroSeconds();
  55. #endif /* helpers_hpp */