helpers.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "helpers.hpp"
  19. #include <sys/time.h>
  20. using namespace std;
  21. using namespace rtc;
  22. ClientTrackData::ClientTrackData(shared_ptr<Track> track, shared_ptr<RTCPSenderReportable> sender) {
  23. this->track = track;
  24. this->sender = sender;
  25. }
  26. void Client::setState(State state) {
  27. std::unique_lock lock(_mutex);
  28. this->state = state;
  29. }
  30. Client::State Client::getState() {
  31. std::shared_lock lock(_mutex);
  32. return state;
  33. }
  34. ClientTrack::ClientTrack(string id, shared_ptr<ClientTrackData> trackData) {
  35. this->id = id;
  36. this->trackData = trackData;
  37. }
  38. uint64_t currentTimeInMicroSeconds() {
  39. struct timeval time;
  40. gettimeofday(&time, NULL);
  41. return uint64_t(time.tv_sec) * 1000 * 1000 + time.tv_usec;
  42. }