objc_call_client.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2018 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_
  11. #define EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_
  12. #include <memory>
  13. #include <string>
  14. #import "sdk/objc/base/RTCMacros.h"
  15. #include "api/peer_connection_interface.h"
  16. #include "api/scoped_refptr.h"
  17. #include "rtc_base/synchronization/mutex.h"
  18. #include "rtc_base/thread_checker.h"
  19. @class RTC_OBJC_TYPE(RTCVideoCapturer);
  20. @protocol RTC_OBJC_TYPE
  21. (RTCVideoRenderer);
  22. namespace webrtc_examples {
  23. class ObjCCallClient {
  24. public:
  25. ObjCCallClient();
  26. void Call(RTC_OBJC_TYPE(RTCVideoCapturer) * capturer,
  27. id<RTC_OBJC_TYPE(RTCVideoRenderer)> remote_renderer);
  28. void Hangup();
  29. private:
  30. class PCObserver : public webrtc::PeerConnectionObserver {
  31. public:
  32. explicit PCObserver(ObjCCallClient* client);
  33. void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
  34. void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
  35. void OnRenegotiationNeeded() override;
  36. void OnIceConnectionChange(
  37. webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
  38. void OnIceGatheringChange(
  39. webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
  40. void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
  41. private:
  42. ObjCCallClient* const client_;
  43. };
  44. void CreatePeerConnectionFactory() RTC_RUN_ON(thread_checker_);
  45. void CreatePeerConnection() RTC_RUN_ON(thread_checker_);
  46. void Connect() RTC_RUN_ON(thread_checker_);
  47. rtc::ThreadChecker thread_checker_;
  48. bool call_started_ RTC_GUARDED_BY(thread_checker_);
  49. const std::unique_ptr<PCObserver> pc_observer_;
  50. rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf_ RTC_GUARDED_BY(thread_checker_);
  51. std::unique_ptr<rtc::Thread> network_thread_ RTC_GUARDED_BY(thread_checker_);
  52. std::unique_ptr<rtc::Thread> worker_thread_ RTC_GUARDED_BY(thread_checker_);
  53. std::unique_ptr<rtc::Thread> signaling_thread_ RTC_GUARDED_BY(thread_checker_);
  54. std::unique_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> remote_sink_
  55. RTC_GUARDED_BY(thread_checker_);
  56. rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> video_source_
  57. RTC_GUARDED_BY(thread_checker_);
  58. webrtc::Mutex pc_mutex_;
  59. rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc_ RTC_GUARDED_BY(pc_mutex_);
  60. };
  61. } // namespace webrtc_examples
  62. #endif // EXAMPLES_OBJCNATIVEAPI_OBJCCALLCLIENT_H_