helpers.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. struct ClientTrackData {
  22. std::shared_ptr<rtc::Track> track;
  23. std::shared_ptr<rtc::RTCPSenderReportable> sender;
  24. ClientTrackData(std::shared_ptr<rtc::Track> track, std::shared_ptr<rtc::RTCPSenderReportable> sender);
  25. };
  26. struct Client {
  27. enum class State {
  28. Waiting,
  29. WaitingForVideo,
  30. WaitingForAudio,
  31. Ready
  32. };
  33. const std::shared_ptr<rtc::PeerConnection> & peerConnection = _peerConnection;
  34. Client(std::shared_ptr<rtc::PeerConnection> pc) {
  35. _peerConnection = pc;
  36. }
  37. std::optional<std::shared_ptr<ClientTrackData>> video;
  38. std::optional<std::shared_ptr<ClientTrackData>> audio;
  39. std::optional<std::shared_ptr<rtc::DataChannel>> dataChannel{};
  40. void setState(State state);
  41. State getState();
  42. private:
  43. std::shared_mutex _mutex;
  44. State state = State::Waiting;
  45. std::string id;
  46. std::shared_ptr<rtc::PeerConnection> _peerConnection;
  47. };
  48. struct ClientTrack {
  49. std::string id;
  50. std::shared_ptr<ClientTrackData> trackData;
  51. ClientTrack(std::string id, std::shared_ptr<ClientTrackData> trackData);
  52. };
  53. uint64_t currentTimeInMicroSeconds();
  54. #endif /* helpers_hpp */