* Make GetReadyState accessible via the PeerConnection interface.

* Update PeerConnection implementations to include "virtual"
in the method declarations.
* Add a check for a valid signaling thread in webrtcsession.cc.
Review URL: http://webrtc-codereview.appspot.com/137001

git-svn-id: http://webrtc.googlecode.com/svn/trunk@445 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tommi@webrtc.org 2011-08-25 14:18:25 +00:00
parent 44d356d6df
commit 137ece4ac3
5 changed files with 59 additions and 36 deletions

View File

@ -71,6 +71,13 @@ class PeerConnectionObserver {
class PeerConnection {
public:
enum ReadyState {
NEW = 0,
NEGOTIATING,
ACTIVE,
CLOSED,
};
virtual ~PeerConnection() {}
// Register a listener
@ -121,6 +128,10 @@ class PeerConnection {
// For standalone app, cam_device is the camera name. It will try to
// set the default capture device when cam_device is "".
virtual bool SetVideoCapture(const std::string& cam_device) = 0;
// Returns the state of the PeerConnection object. See the ReadyState
// enum for valid values.
virtual ReadyState GetReadyState() = 0;
};
} // namespace webrtc

View File

@ -54,26 +54,20 @@ class PeerConnectionImpl : public PeerConnection,
talk_base::Thread* signaling_thread);
virtual ~PeerConnectionImpl();
enum ReadyState {
NEW = 0,
NEGOTIATING,
ACTIVE,
CLOSED,
};
// PeerConnection interfaces
void RegisterObserver(PeerConnectionObserver* observer);
bool SignalingMessage(const std::string& msg);
bool AddStream(const std::string& stream_id, bool video);
bool RemoveStream(const std::string& stream_id);
bool Connect();
bool Close();
bool SetAudioDevice(const std::string& wave_in_device,
const std::string& wave_out_device, int opts);
bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer);
bool SetVideoRenderer(const std::string& stream_id,
cricket::VideoRenderer* renderer);
bool SetVideoCapture(const std::string& cam_device);
virtual void RegisterObserver(PeerConnectionObserver* observer);
virtual bool SignalingMessage(const std::string& msg);
virtual bool AddStream(const std::string& stream_id, bool video);
virtual bool RemoveStream(const std::string& stream_id);
virtual bool Connect();
virtual bool Close();
virtual bool SetAudioDevice(const std::string& wave_in_device,
const std::string& wave_out_device, int opts);
virtual bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer);
virtual bool SetVideoRenderer(const std::string& stream_id,
cricket::VideoRenderer* renderer);
virtual bool SetVideoCapture(const std::string& cam_device);
virtual ReadyState GetReadyState();
cricket::ChannelManager* channel_manager() {
return channel_manager_;
@ -91,7 +85,6 @@ class PeerConnectionImpl : public PeerConnection,
bool Init();
private:
ReadyState GetReadyState();
bool ParseConfigString(const std::string& config,
talk_base::SocketAddress* stun_addr);
void SendRemoveSignal(WebRtcSession* session);

View File

@ -45,6 +45,7 @@ enum {
MSG_WEBRTC_SETVIDEOCAPTURE,
MSG_WEBRTC_SETVIDEORENDERER,
MSG_WEBRTC_SIGNALINGMESSAGE,
MSG_WEBRTC_GETREADYSTATE,
};
struct AddStreamParams : public talk_base::MessageData {
@ -194,6 +195,13 @@ bool PeerConnectionProxy::SetVideoCapture(const std::string& cam_device) {
return (Send(MSG_WEBRTC_SETVIDEOCAPTURE, &params) && params.result);
}
PeerConnection::ReadyState PeerConnectionProxy::GetReadyState() {
PeerConnection::ReadyState ready_state = NEW;
Send(MSG_WEBRTC_GETREADYSTATE,
reinterpret_cast<talk_base::MessageData*>(&ready_state));
return ready_state;
}
bool PeerConnectionProxy::Connect() {
ResultParams params;
return (Send(MSG_WEBRTC_CONNECT, &params) && params.result);
@ -254,6 +262,12 @@ void PeerConnectionProxy::OnMessage(talk_base::Message* message) {
params->cam_device);
break;
}
case MSG_WEBRTC_GETREADYSTATE: {
PeerConnection::ReadyState* ready_state =
reinterpret_cast<PeerConnection::ReadyState*>(data);
*ready_state = peerconnection_impl_->GetReadyState();
break;
}
case MSG_WEBRTC_SETVIDEORENDERER: {
SetVideoRendererParams* params =
reinterpret_cast<SetVideoRendererParams*>(data);

View File

@ -51,19 +51,20 @@ class PeerConnectionProxy : public PeerConnection,
talk_base::Thread* signaling_thread);
virtual ~PeerConnectionProxy();
// PeerConnection interfaces
void RegisterObserver(PeerConnectionObserver* observer);
bool SignalingMessage(const std::string& msg);
bool AddStream(const std::string& stream_id, bool video);
bool RemoveStream(const std::string& stream_id);
bool Connect();
bool Close();
bool SetAudioDevice(const std::string& wave_in_device,
const std::string& wave_out_device, int opts);
bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer);
bool SetVideoRenderer(const std::string& stream_id,
cricket::VideoRenderer* renderer);
bool SetVideoCapture(const std::string& cam_device);
// PeerConnection interface implementation.
virtual void RegisterObserver(PeerConnectionObserver* observer);
virtual bool SignalingMessage(const std::string& msg);
virtual bool AddStream(const std::string& stream_id, bool video);
virtual bool RemoveStream(const std::string& stream_id);
virtual bool Connect();
virtual bool Close();
virtual bool SetAudioDevice(const std::string& wave_in_device,
const std::string& wave_out_device, int opts);
virtual bool SetLocalVideoRenderer(cricket::VideoRenderer* renderer);
virtual bool SetVideoRenderer(const std::string& stream_id,
cricket::VideoRenderer* renderer);
virtual bool SetVideoCapture(const std::string& cam_device);
virtual ReadyState GetReadyState();
private:

View File

@ -93,10 +93,14 @@ WebRtcSession::~WebRtcSession() {
}
bool WebRtcSession::Initiate() {
signaling_thread_->Send(this, MSG_WEBRTC_CREATE_TRANSPORT, NULL);
if (transport_ == NULL) {
if (signaling_thread_ == NULL)
return false;
}
signaling_thread_->Send(this, MSG_WEBRTC_CREATE_TRANSPORT, NULL);
if (transport_ == NULL)
return false;
transport_->set_allow_local_ips(true);
// start transports