3
* Copyright 2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
#ifndef TALK_APP_WEBRTC_PEERCONNECTIONIMPL_H_
29
#define TALK_APP_WEBRTC_PEERCONNECTIONIMPL_H_
34
#include "talk/app/webrtc/mediastreamsignaling.h"
35
#include "talk/app/webrtc/peerconnection.h"
36
#include "talk/app/webrtc/peerconnectionfactoryimpl.h"
37
#include "talk/app/webrtc/roapsignaling.h"
38
#include "talk/app/webrtc/streamcollectionimpl.h"
39
#include "talk/app/webrtc/webrtcsession.h"
40
#include "talk/base/scoped_ptr.h"
41
#include "talk/p2p/client/httpportallocator.h"
44
class MediaStreamHandlers;
46
// PeerConnectionImpl implements the PeerConnection interface.
47
// It uses RoapSignaling and WebRtcSession to implement
48
// the PeerConnection functionality.
49
class PeerConnection : public PeerConnectionInterface,
50
public RemoteMediaStreamObserver,
51
public talk_base::MessageHandler,
52
public sigslot::has_slots<> {
54
explicit PeerConnection(PeerConnectionFactory* factory);
56
bool Initialize(bool use_roap,
57
const std::string& configuration,
58
PeerConnectionObserver* observer);
60
virtual ~PeerConnection();
62
virtual void ProcessSignalingMessage(const std::string& msg);
63
virtual bool Send(const std::string& msg) {
68
virtual talk_base::scoped_refptr<StreamCollectionInterface> local_streams();
69
virtual talk_base::scoped_refptr<StreamCollectionInterface> remote_streams();
70
virtual void AddStream(LocalMediaStreamInterface* stream);
71
virtual void RemoveStream(LocalMediaStreamInterface* stream);
72
virtual void CommitStreamChanges();
74
virtual ReadyState ready_state();
75
virtual SdpState sdp_state();
78
virtual SessionDescriptionInterface* CreateOffer(const MediaHints& hints);
79
virtual SessionDescriptionInterface* CreateAnswer(
80
const MediaHints& hints,
81
const SessionDescriptionInterface* offer);
83
virtual bool StartIce(IceOptions options);
84
virtual bool SetLocalDescription(Action action,
85
SessionDescriptionInterface* desc);
86
virtual bool SetRemoteDescription(Action action,
87
SessionDescriptionInterface* desc);
88
virtual bool ProcessIceMessage(const IceCandidateInterface* ice_candidate);
89
virtual const SessionDescriptionInterface* local_description() const;
90
virtual const SessionDescriptionInterface* remote_description() const;
93
// Implement talk_base::MessageHandler.
94
void OnMessage(talk_base::Message* msg);
96
// Signals from RoapSignaling.
97
void OnNewPeerConnectionMessage(const std::string& message);
98
void OnSignalingStateChange(RoapSignaling::State state);
100
// Implements RemoteMediaStreamObserver.
101
virtual void OnAddStream(MediaStreamInterface* stream);
102
virtual void OnRemoveStream(MediaStreamInterface* stream);
104
// Signals from WebRtcSession.
105
void OnSessionStateChange(cricket::BaseSession* session,
106
cricket::BaseSession::State state);
108
void ChangeReadyState(PeerConnectionInterface::ReadyState ready_state);
109
void ChangeSdpState(PeerConnectionInterface::SdpState sdp_state);
112
talk_base::Thread* signaling_thread() const {
113
return factory_->signaling_thread();
116
// Storing the factory as a scoped reference pointer ensures that the memory
117
// in the PeerConnectionFactoryImpl remains available as long as the
118
// PeerConnection is running. It is passed to PeerConnection as a raw pointer.
119
// However, since the reference counting is done in the
120
// PeerConnectionFactoryInteface all instances created using the raw pointer
121
// will refer to the same reference count.
122
talk_base::scoped_refptr<PeerConnectionFactory> factory_;
123
PeerConnectionObserver* observer_;
124
ReadyState ready_state_;
126
talk_base::scoped_refptr<StreamCollection> local_media_streams_;
128
talk_base::scoped_ptr<cricket::PortAllocator> port_allocator_;
129
talk_base::scoped_ptr<WebRtcSession> session_;
130
talk_base::scoped_ptr<RoapSignaling> roap_signaling_;
131
talk_base::scoped_ptr<MediaStreamSignaling> mediastream_signaling_;
132
talk_base::scoped_ptr<MediaStreamHandlers> stream_handler_;
135
} // namespace webrtc
137
#endif // TALK_APP_WEBRTC_PEERCONNECTIONIMPL_H_