1 /* 2 * libjingle 3 * Copyright 2011, Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 #ifndef TALK_APP_WEBRTC_PEERCONNECTIONFACTORY_H_ 28 #define TALK_APP_WEBRTC_PEERCONNECTIONFACTORY_H_ 29 30 #include <string> 31 32 #include "talk/app/webrtc/mediastreaminterface.h" 33 #include "talk/app/webrtc/peerconnectioninterface.h" 34 #include "talk/base/scoped_ptr.h" 35 #include "talk/base/thread.h" 36 #include "talk/session/media/channelmanager.h" 37 38 namespace webrtc { 39 40 class PeerConnectionFactory : public PeerConnectionFactoryInterface, 41 public talk_base::MessageHandler { 42 public: SetOptions(const Options & options)43 virtual void SetOptions(const Options& options) { 44 options_ = options; 45 } 46 47 virtual talk_base::scoped_refptr<PeerConnectionInterface> 48 CreatePeerConnection( 49 const PeerConnectionInterface::IceServers& configuration, 50 const MediaConstraintsInterface* constraints, 51 DTLSIdentityServiceInterface* dtls_identity_service, 52 PeerConnectionObserver* observer); 53 54 virtual talk_base::scoped_refptr<PeerConnectionInterface> 55 CreatePeerConnection( 56 const PeerConnectionInterface::IceServers& configuration, 57 const MediaConstraintsInterface* constraints, 58 PortAllocatorFactoryInterface* allocator_factory, 59 DTLSIdentityServiceInterface* dtls_identity_service, 60 PeerConnectionObserver* observer); 61 bool Initialize(); 62 63 virtual talk_base::scoped_refptr<MediaStreamInterface> 64 CreateLocalMediaStream(const std::string& label); 65 66 virtual talk_base::scoped_refptr<AudioSourceInterface> CreateAudioSource( 67 const MediaConstraintsInterface* constraints); 68 69 virtual talk_base::scoped_refptr<VideoSourceInterface> CreateVideoSource( 70 cricket::VideoCapturer* capturer, 71 const MediaConstraintsInterface* constraints); 72 73 virtual talk_base::scoped_refptr<VideoTrackInterface> 74 CreateVideoTrack(const std::string& id, 75 VideoSourceInterface* video_source); 76 77 virtual talk_base::scoped_refptr<AudioTrackInterface> 78 CreateAudioTrack(const std::string& id, 79 AudioSourceInterface* audio_source); 80 81 virtual cricket::ChannelManager* channel_manager(); 82 virtual talk_base::Thread* signaling_thread(); 83 virtual talk_base::Thread* worker_thread(); options()84 const Options& options() const { return options_; } 85 86 protected: 87 PeerConnectionFactory(); 88 PeerConnectionFactory( 89 talk_base::Thread* worker_thread, 90 talk_base::Thread* signaling_thread, 91 AudioDeviceModule* default_adm, 92 cricket::WebRtcVideoEncoderFactory* video_encoder_factory, 93 cricket::WebRtcVideoDecoderFactory* video_decoder_factory); 94 virtual ~PeerConnectionFactory(); 95 96 97 private: 98 bool Initialize_s(); 99 void Terminate_s(); 100 talk_base::scoped_refptr<AudioSourceInterface> CreateAudioSource_s( 101 const MediaConstraintsInterface* constraints); 102 talk_base::scoped_refptr<VideoSourceInterface> CreateVideoSource_s( 103 cricket::VideoCapturer* capturer, 104 const MediaConstraintsInterface* constraints); 105 talk_base::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_s( 106 const PeerConnectionInterface::IceServers& configuration, 107 const MediaConstraintsInterface* constraints, 108 PortAllocatorFactoryInterface* allocator_factory, 109 DTLSIdentityServiceInterface* dtls_identity_service, 110 PeerConnectionObserver* observer); 111 // Implements talk_base::MessageHandler. 112 void OnMessage(talk_base::Message* msg); 113 114 bool owns_ptrs_; 115 talk_base::Thread* signaling_thread_; 116 talk_base::Thread* worker_thread_; 117 Options options_; 118 talk_base::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_; 119 // External Audio device used for audio playback. 120 talk_base::scoped_refptr<AudioDeviceModule> default_adm_; 121 talk_base::scoped_ptr<cricket::ChannelManager> channel_manager_; 122 // External Video encoder factory. This can be NULL if the client has not 123 // injected any. In that case, video engine will use the internal SW encoder. 124 talk_base::scoped_ptr<cricket::WebRtcVideoEncoderFactory> 125 video_encoder_factory_; 126 // External Video decoder factory. This can be NULL if the client has not 127 // injected any. In that case, video engine will use the internal SW decoder. 128 talk_base::scoped_ptr<cricket::WebRtcVideoDecoderFactory> 129 video_decoder_factory_; 130 }; 131 132 } // namespace webrtc 133 134 #endif // TALK_APP_WEBRTC_PEERCONNECTIONFACTORY_H_ 135