Chromium Code Reviews| Index: content/renderer/media/media_stream_impl.cc |
| diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc |
| index 52e9ec2eaaed9f442477afabad0ce93110abc9d5..668f5c06757cc35ea6998fd3c746d2f10d73e937 100644 |
| --- a/content/renderer/media/media_stream_impl.cc |
| +++ b/content/renderer/media/media_stream_impl.cc |
| @@ -4,12 +4,34 @@ |
| #include "content/renderer/media/media_stream_impl.h" |
| -#include "base/string_util.h" |
| +#include <vector> |
| + |
| +#include "base/logging.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "content/common/media/media_stream_options.h" |
| #include "content/renderer/media/capture_video_decoder.h" |
| +#include "content/renderer/media/media_stream_dispatcher.h" |
| +#include "content/renderer/media/rtc_video_decoder.h" |
| #include "content/renderer/media/video_capture_impl_manager.h" |
| -#include "googleurl/src/gurl.h" |
| +#include "content/renderer/media/video_capture_module_impl.h" |
| +#include "content/renderer/media/webrtc_audio_device_impl.h" |
| +#include "content/renderer/p2p/ipc_network_manager.h" |
| +#include "content/renderer/p2p/ipc_socket_factory.h" |
| +#include "content/renderer/p2p/socket_dispatcher.h" |
| +#include "jingle/glue/thread_wrapper.h" |
| #include "media/base/message_loop_factory.h" |
| -#include "media/base/pipeline.h" |
| +#include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h" |
| +#include "third_party/libjingle/source/talk/session/phone/dummydevicemanager.h" |
| +#include "third_party/libjingle/source/talk/session/phone/webrtcmediaengine.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamController.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistry.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamTrackList.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamTrack.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| namespace { |
| @@ -17,24 +39,288 @@ static const int kVideoCaptureWidth = 352; |
| static const int kVideoCaptureHeight = 288; |
| static const int kVideoCaptureFramePerSecond = 30; |
| -static const int kStartOpenSessionId = 1; |
| +} // namespace |
| -// TODO(wjia): remove this string when full media stream code is checked in. |
| -static const char kRawMediaScheme[] = "mediastream"; |
| +MediaStreamImpl::MediaStreamImpl( |
| + MediaStreamDispatcher* media_stream_dispatcher, |
| + content::P2PSocketDispatcher* p2p_socket_dispatcher, |
| + VideoCaptureImplManager* vc_manager) |
| + : controller_(NULL), |
| + media_stream_dispatcher_(media_stream_dispatcher), |
| + media_engine_(NULL), |
| + p2p_socket_dispatcher_(p2p_socket_dispatcher), |
| + vc_manager_(vc_manager), |
| + peer_connection_id_(-1), |
| + signaling_thread_(NULL), |
| + worker_thread_(NULL), |
| + chrome_worker_thread_("Chrome_libJingle_WorkerThread"), |
| + call_state_(NOT_STARTED), |
| + vcm_is_created_(false) { |
| + message_loop_proxy_ = base::MessageLoopProxy::current(); |
| + chrome_worker_thread_.Start(); |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
should we do this in newPeerConnection instead? (
grunell (dont use)
2011/09/29 13:38:17
I think so, moved it and added check of return val
|
| +} |
| -} // namespace |
| +MediaStreamImpl::~MediaStreamImpl() { |
| + if (peer_connection_.get()) { |
| + peer_connection_->RegisterObserver(NULL); |
| + peer_connection_->Close(); |
| + } |
| +} |
| + |
| +void MediaStreamImpl::setController( |
| + WebKit::WebMediaStreamController* controller) { |
| + controller_.reset(controller); |
| +} |
| + |
| +void MediaStreamImpl::mediaStreamDestroyed() { |
| + controller_.reset(); |
| +} |
| + |
| +void MediaStreamImpl::generateStream( |
| + int requestId, WebKit::WebGenerateStreamOptionFlags flags, |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
see 'BadWrappingStyle' under function declarations
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + const WebKit::WebSecurityOrigin& webSecurityOrigin) { |
| + |
| + bool audio = flags & WebKit::WebGenerateStreamRequestAudio; |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
won't this generate a compiler warning? Should pe
grunell (dont use)
2011/09/29 13:38:17
No it doesn't. It will evaluate and assign with im
|
| + media_stream::StreamOptions::VideoOption video_option = |
| + media_stream::StreamOptions::kNoCamera; |
| + |
| + if ((flags & WebKit::WebGenerateStreamRequestVideoFacingUser) && |
| + (flags & WebKit::WebGenerateStreamRequestVideoFacingEnvironment)) { |
| + video_option = media_stream::StreamOptions::kFacingBoth; |
| + } else { |
| + if (flags & WebKit::WebGenerateStreamRequestVideoFacingEnvironment) |
| + video_option = media_stream::StreamOptions::kFacingEnvironment; |
| + if (flags & WebKit::WebGenerateStreamRequestVideoFacingUser) |
| + video_option = media_stream::StreamOptions::kFacingUser; |
| + } |
| + |
| + VLOG(1) << "MediaStreamImpl::generateStream(" |
| + << requestId << ", [ " |
| + << (audio ? "audio " : "") |
| + << ((flags & |
| + flags & WebKit::WebGenerateStreamRequestVideoFacingUser) ? |
| + "video_facing_user " : "") |
| + << ((flags & |
| + WebKit::WebGenerateStreamRequestVideoFacingEnvironment) ? |
| + "video_facing_environment " : "") |
| + << "], " |
| + << static_cast<string16>(webSecurityOrigin.toString()) << ")"; |
| + |
| + media_stream_dispatcher_->GenerateStream(requestId, this, |
| + media_stream::StreamOptions(audio, video_option), |
| + UTF16ToUTF8(webSecurityOrigin.toString())); |
| +} |
| + |
| +void MediaStreamImpl::recordStream( |
| + const WebKit::WebString& streamLabel, int recorderId) { |
| + // TODO(grunell): Implement. |
| +} |
| + |
| +void MediaStreamImpl::getRecordedData( |
| + const WebKit::WebString& streamLabel, int recorderId, int requestId) { |
| + // TODO(grunell): Implement. |
| +} |
| + |
| +void MediaStreamImpl::disposeRecordedData( |
| + const WebKit::WebString& streamLabel, int recorderId) { |
| + // TODO(grunell): Implement. |
| +} |
| + |
| +void MediaStreamImpl::stopGeneratedStream( |
| + const WebKit::WebString& streamLabel) { |
| + std::string label = UTF16ToUTF8(streamLabel); |
| + media_stream_dispatcher_->StopStream(label); |
| +} |
| + |
| +void MediaStreamImpl::setMediaStreamTrackEnabled( |
| + const WebKit::WebString& trackId, bool enabled) { |
| + // TODO(grunell): Implement. |
| +} |
| + |
| +void MediaStreamImpl::processSignalingMessage(int peerConnectionId, |
| + const WebKit::WebString& message) { |
| + VLOG(1) << "MediaStreamImpl::processSignalingMessage(" |
| + << UTF16ToUTF8(message) << ")"; |
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + DCHECK(peer_connection_.get()); |
| + peer_connection_->SignalingMessage(UTF16ToUTF8(message)); |
| +} |
| + |
| +void MediaStreamImpl::message( |
| + int peerConnectionId, const WebKit::WebString& message) { |
| + VLOG(1) << "MediaStreamImpl::message(" << UTF16ToUTF8(message) << ")"; |
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + // TODO(grunell): Implement. |
| +} |
| + |
| +void MediaStreamImpl::addStream(int peerConnectionId, |
| + const WebKit::WebString& streamLabel) { |
| + VLOG(1) << "MediaStreamImpl::addStream(" << peerConnectionId << ", " |
| + << UTF16ToUTF8(streamLabel) << ")"; |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
align <<
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + |
| + // TODO(grunell): Fix code in this function after libjingle with new |
| + // PeerConnection version has been rolled out. |
| + |
| + if (call_state_ == NOT_STARTED) { |
| + DCHECK(peer_connection_.get()); |
| + // TODO(grunell): Add audio and/or video depending on what's enabled |
| + // in the stream. |
| + std::string label = UTF16ToUTF8(streamLabel); |
| + std::string audioLabel = label; |
| + audioLabel.append("-audio"); |
| + peer_connection_->AddStream(audioLabel, false); // Audio |
| + peer_connection_->AddStream(label, true); // Video |
| + local_label_ = label; |
| + call_state_ = INITIATING; |
| + } |
| + if (call_state_ == INITIATING || call_state_ == RECEIVING) { |
| + if (!vcm_is_created_) { |
| + // Set the capture device |
| + // TODO(grunell): instead of using the first track, |
| + // the selected track should be used. |
| + int id = media_stream_dispatcher_->video_session_id(local_label_, 0); |
| + if (id != media_stream::StreamDeviceInfo::kNoId) { |
| + webrtc::VideoCaptureModule* vcm = new VideoCaptureModuleImpl( |
| + id, vc_manager_.get()); |
| + vcm_is_created_ = true; |
| + media_engine_->SetVideoCaptureModule(vcm); |
| + peer_connection_->SetVideoCapture(""); |
| + } |
| + } |
| + if (call_state_ == INITIATING) |
| + peer_connection_->Connect(); |
| + else if (call_state_ == RECEIVING) |
| + call_state_ = SENDING_AND_RECEIVING; |
| + } else { |
| + DLOG(ERROR) << __FUNCTION__ << ": Multiple calls not supported"; |
| + return; |
| + } |
| +} |
| + |
| +void MediaStreamImpl::newPeerConnection(int peerConnectionId, |
| + const WebKit::WebString& configuration) { |
| + if (peer_connection_.get()) { |
| + LOG(ERROR) << __FUNCTION__ << ": A PeerConnection already exists"; |
| + return; |
| + } |
| + |
| + if (!media_engine_) { |
| + webrtc::AudioDeviceModule* adm = new WebRtcAudioDeviceImpl(); |
| + webrtc::AudioDeviceModule* adm_sc = new WebRtcAudioDeviceImpl(); |
| + media_engine_ = new cricket::WebRtcMediaEngine(adm, adm_sc, NULL); |
| + } |
| + |
| + if (!signaling_thread_) { |
| + jingle_glue::JingleThreadWrapper::EnsureForCurrentThread(); |
| + jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); |
| + signaling_thread_ = jingle_glue::JingleThreadWrapper::current(); |
| + } |
| + |
| + if (!worker_thread_) { |
| + base::WaitableEvent event(true, false); |
| + chrome_worker_thread_.message_loop()->PostTask( |
| + FROM_HERE, NewRunnableMethod( |
| + this, &MediaStreamImpl::initializeWorkerThread, |
| + &worker_thread_, &event)); |
| + event.Wait(); |
| + DCHECK(worker_thread_); |
| + } |
| + |
| + if (!pc_factory_.get()) { |
| + ipc_network_manager_.reset( |
| + new content::IpcNetworkManager(p2p_socket_dispatcher_)); |
| + ipc_socket_factory_.reset( |
| + new content::IpcPacketSocketFactory(p2p_socket_dispatcher_)); |
| + port_allocator_ = new cricket::HttpPortAllocator( |
| + ipc_network_manager_.get(), ipc_socket_factory_.get(), |
| + "PeerConnection"); |
| + // TODO(mallinath) - Following flags added to solve crash in HttpClient |
| + port_allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| + cricket::PORTALLOCATOR_DISABLE_RELAY); |
| + |
| + // TODO(mallinath) - PeerConnectionFactory constructor changed in latest |
| + // code and it no more accepts config string. Config string must be parsed |
| + // here and set in HttpPortAllocator. Now using standard google STUN server |
| + // address. |
| + std::vector<talk_base::SocketAddress> stun_hosts; |
| + stun_hosts.push_back(talk_base::SocketAddress("stun.l.google.com", 19302)); |
| + port_allocator_->SetStunHosts(stun_hosts); |
| + |
| + pc_factory_.reset(new webrtc::PeerConnectionFactory(port_allocator_, |
| + media_engine_, new cricket::DummyDeviceManager(), worker_thread_)); |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
run gcl lint?
grunell (dont use)
2011/09/29 13:38:17
Yes I had done so, no complaints. I fixed the inde
|
| + if (!pc_factory_->Initialize()) { |
| + LOG(ERROR) << __FUNCTION__ << ": Could not initialize PeerConnection " |
| + "factory"; |
| + return; |
| + } |
| + } |
| + |
| + peer_connection_.reset(pc_factory_.get()->CreatePeerConnection( |
| + signaling_thread_)); |
| + DCHECK(peer_connection_.get()); |
| + peer_connection_id_ = peerConnectionId; |
| + peer_connection_->RegisterObserver(this); |
| +} |
| -MediaStreamImpl::MediaStreamImpl(VideoCaptureImplManager* vc_manager) |
| - : vc_manager_(vc_manager) { |
| +void MediaStreamImpl::closePeerConnection(int peerConnectionId) { |
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + // TODO(grunell): Fix code in this function after libjingle with new |
| + // PeerConnection version has been rolled out. |
| + if (call_state_ == RECEIVING || call_state_ == SENDING_AND_RECEIVING) |
| + call_state_ = TERMINATING; |
| + if (peer_connection_.get()) |
| + DeletePeerConnection(); |
| +} |
| + |
| +void MediaStreamImpl::startNegotiation(int peerConnectionId) { |
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + // TODO(grunell): Implement. Currently not supported in libjingle. |
| +} |
| + |
| +void MediaStreamImpl::removeStream(int peerConnectionId, |
| + const WebKit::WebString& streamLabel) { |
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + // TODO(grunell): Implement. Currently not supported in libjingle. |
| } |
| -MediaStreamImpl::~MediaStreamImpl() {} |
| +void MediaStreamImpl::commitStreamChanges(int peerConnectionId) { |
| + if (peerConnectionId != peer_connection_id_) { |
| + DLOG(ERROR) << __FUNCTION__ << ": PeerConnection is not valid"; |
| + return; |
| + } |
| + // TODO(grunell): Implement. Currently not supported in libjingle. |
| +} |
| scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
| const GURL& url, media::MessageLoopFactory* message_loop_factory) { |
| - bool raw_media = (url.spec().find(kRawMediaScheme) == 0); |
| + std::string label = |
| + UTF16ToUTF8(WebKit::WebMediaStreamRegistry::mediaStreamLabel(url)); |
| + if (label.size() == 0) |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
if (label.empty())
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + return NULL; // This is not a valid stream. |
| + |
| media::VideoDecoder* decoder = NULL; |
| - if (raw_media) { |
| + if (media_stream_dispatcher_->IsStream(label)) { |
| + // It's a local stream. |
| + int video_session_id = media_stream_dispatcher_->video_session_id(label, 0); |
| media::VideoCapture::VideoCaptureCapability capability; |
| capability.width = kVideoCaptureWidth; |
| capability.height = kVideoCaptureHeight; |
| @@ -43,10 +329,206 @@ scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
| capability.raw_type = media::VideoFrame::I420; |
| capability.interlaced = false; |
| capability.resolution_fixed = false; |
| - |
| decoder = new CaptureVideoDecoder( |
| - message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoder").get(), |
| - kStartOpenSessionId, vc_manager_.get(), capability); |
| + message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoderThread"), |
| + video_session_id, vc_manager_.get(), capability); |
| + } else { |
| + // It's a remote stream. |
| + DCHECK(label.size()); |
| + if (rtc_video_decoder_.get()) { |
| + // The renderer is used by PeerConnection, release it first. |
| + size_t found = label.rfind("-remote"); |
| + if (found != std::string::npos) |
| + label = label.substr(0, found); |
| + if (peer_connection_.get()) { |
| + peer_connection_->SetVideoRenderer(label, NULL); |
| + } |
| + } |
| + rtc_video_decoder_ = new RTCVideoDecoder( |
| + message_loop_factory->GetMessageLoop("RtcVideoDecoderThread"), |
| + url.spec()); |
| + decoder = rtc_video_decoder_; |
| + size_t found = label.rfind("-remote"); |
| + if (found != std::string::npos) |
| + label = label.substr(0, found); |
| + if (peer_connection_.get()) { |
| + peer_connection_->SetVideoRenderer(label, rtc_video_decoder_); |
| + } |
| + } |
| + scoped_refptr<media::VideoDecoder> sr_decoder(decoder); |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
why not make decoder a scoped_refptr from the begi
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + return sr_decoder; |
| +} |
| + |
| +void MediaStreamImpl::OnStreamGenerated( |
| + int requestId, const std::string& label, |
| + const media_stream::StreamDeviceInfoArray& audio_array, |
| + const media_stream::StreamDeviceInfoArray& video_array) { |
| + VLOG(1) << "MediaStreamImpl::OnStreamGenerated(" << requestId << ", " |
| + << label << ")"; |
| + DCHECK(controller_.get()); |
| + |
| + WebKit::WebVector<WebKit::WebMediaStreamTrack> web_track_vector( |
| + audio_array.size() + video_array.size()); |
| + |
| + int track_num = 0; |
| + for (media_stream::StreamDeviceInfoArray::const_iterator |
| + it = audio_array.begin(); it != audio_array.end(); ++it) { |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
indent
tommi (sloooow) - chröme
2011/09/23 13:02:42
is the iterator used?
Could you instead just do:
grunell (dont use)
2011/09/29 13:38:17
Agree, with some modification to set audio and vid
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + web_track_vector[track_num].initialize( |
| + WebKit::WebString::fromUTF8(""), |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
initialize all these strings outside the loop.
grunell (dont use)
2011/09/29 13:38:17
Done.
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + WebKit::WebString::fromUTF8("main"), |
| + WebKit::WebString::fromUTF8("AudioDevice")); |
| + ++track_num; |
| + } |
| + |
| + for (media_stream::StreamDeviceInfoArray::const_iterator |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
same iterator question
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + it = video_array.begin(); it != video_array.end(); ++it) { |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
indent
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + web_track_vector[track_num].initialize( |
| + WebKit::WebString::fromUTF8(""), |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
initialize outside of the loop
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + WebKit::WebString::fromUTF8("main"), |
| + WebKit::WebString::fromUTF8("VideoCapture")); |
| + ++track_num; |
| + } |
| + |
| + local_label_ = label; |
| + |
| + WebKit::WebMediaStreamTrackList web_track_list; |
| + web_track_list.initialize(web_track_vector); |
| + controller_->streamGenerated( |
| + requestId, UTF8ToUTF16(label), web_track_list); |
| +} |
| + |
| +void MediaStreamImpl::OnStreamGenerationFailed(int requestId) { |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
fix parameter names to chromium style.
grunell (dont use)
2011/09/29 13:38:17
Done for all functions.
|
| + VLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed(" |
| + << requestId << ")\n"; |
| + DCHECK(controller_.get()); |
| + controller_->streamGenerationFailed( |
| + requestId, |
| + WebKit::WebMediaStreamController::ErrorPermissionDenied); |
| +} |
| + |
| +void MediaStreamImpl::OnVideoDeviceFailed(const std::string& label, |
| + int index) { |
| + VLOG(1) << "MediaStreamImpl::OnVideoDeviceFailed(" |
| + << label << ", " << index << ")\n"; |
| + DCHECK(controller_.get()); |
| + controller_->streamFailed(UTF8ToUTF16(label)); |
| +} |
| + |
| +void MediaStreamImpl::OnAudioDeviceFailed(const std::string& label, |
| + int index) { |
| + VLOG(1) << "MediaStreamImpl::OnAudioDeviceFailed(" |
| + << label << ", " << index << ")\n"; |
| + DCHECK(controller_.get()); |
| + controller_->streamFailed(UTF8ToUTF16(label)); |
| +} |
| + |
| +void MediaStreamImpl::OnError() { |
| + VLOG(1) << "MediaStreamImpl::OnError()"; |
| + |
| + if (!message_loop_proxy_->BelongsToCurrentThread()) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, &MediaStreamImpl::OnError)); |
| + } |
| + |
| + DCHECK(controller_.get()); |
| + WebKit::WebString message("PeerConnection error."); |
| + controller_->error(peer_connection_id_, message); |
| +} |
| + |
| +void MediaStreamImpl::OnSignalingMessage(const std::string& msg) { |
| + VLOG(1) << "MediaStreamImpl::OnSignalingMessage(" << msg << ")"; |
| + |
| + if (!message_loop_proxy_->BelongsToCurrentThread()) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, &MediaStreamImpl::OnSignalingMessage, msg)); |
| + return; |
| } |
| - return decoder; |
| + |
| + DCHECK(controller_.get()); |
| + controller_->onSignalingMessage(peer_connection_id_, UTF8ToUTF16(msg)); |
| +} |
| + |
| +void MediaStreamImpl::OnAddStream(const std::string& stream_id, bool video) { |
| + VLOG(1) << "MediaStreamImpl::OnAddStream(" << stream_id << ", " |
| + << video << ")"; |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
indent
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + |
| + DCHECK(controller_.get()); |
| + |
| + // TODO(grunell): Fix code in this function after libjingle with new |
| + // PeerConnection version has been rolled out. |
| + if (video) { |
| + if (call_state_ == NOT_STARTED) { |
| + remote_label_ = stream_id; |
| + call_state_ = RECEIVING; |
| + } else if (call_state_ == INITIATING) { |
| + std::string label = local_label_; |
| + label += "-remote"; |
| + remote_label_ = label; |
| + call_state_ = SENDING_AND_RECEIVING; |
| + } |
| + |
| + if (!message_loop_proxy_->BelongsToCurrentThread()) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, |
| + &MediaStreamImpl::OnAddStreamCallback, |
| + remote_label_)); |
| + return; |
| + } else { |
| + OnAddStreamCallback(remote_label_); |
| + } |
| + } |
| +} |
| + |
| +void MediaStreamImpl::OnRemoveStream(const std::string& stream_id, bool video) { |
| + VLOG(1) << "MediaStreamImpl::OnRemoveStream(" << stream_id << ", " |
| + << video << ")"; |
| + |
| + if (video) { |
| + if (!message_loop_proxy_->BelongsToCurrentThread()) |
|
tommi (sloooow) - chröme
2011/09/23 13:02:42
use braces
grunell (dont use)
2011/09/29 13:38:17
Done.
|
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, &MediaStreamImpl::OnRemoveStreamCallback, |
| + remote_label_)); |
| + else |
| + OnRemoveStreamCallback(remote_label_); |
| + } |
| +} |
| + |
| +void MediaStreamImpl::OnAddStreamCallback(std::string streamLabel) { |
| + size_t size = 1; |
| + WebKit::WebVector<WebKit::WebMediaStreamTrack> web_track_vector(size); |
| + web_track_vector[0].initialize(WebKit::WebString::fromUTF8(""), |
| + WebKit::WebString::fromUTF8("main"), |
| + WebKit::WebString::fromUTF8(streamLabel)); |
| + WebKit::WebMediaStreamTrackList web_track_list; |
| + web_track_list.initialize(web_track_vector); |
| + controller_->onAddStream(peer_connection_id_, |
| + UTF8ToUTF16(streamLabel), web_track_list); |
| +} |
| + |
| +void MediaStreamImpl::OnRemoveStreamCallback(std::string streamLabel) { |
| + DCHECK(controller_.get()); |
| + controller_->onRemoveStream(peer_connection_id_, UTF8ToUTF16(streamLabel)); |
| +} |
| + |
| +void MediaStreamImpl::DeletePeerConnection() { |
| + DCHECK(peer_connection_.get()); |
| + peer_connection_->RegisterObserver(NULL); |
| + peer_connection_.reset(); |
| + peer_connection_id_ = -1; |
| + rtc_video_decoder_ = NULL; |
| + media_engine_->SetVideoCaptureModule(NULL); |
| + vcm_is_created_ = false; |
| + call_state_ = NOT_STARTED; |
| +} |
| + |
| +void MediaStreamImpl::initializeWorkerThread(talk_base::Thread** thread, |
| + base::WaitableEvent* event) { |
| + jingle_glue::JingleThreadWrapper::EnsureForCurrentThread(); |
| + jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); |
| + *thread = jingle_glue::JingleThreadWrapper::current(); |
| + event->Signal(); |
| } |