From f6ab63c08ad8c60b3651b77b17c3ccca12b2c749 Mon Sep 17 00:00:00 2001 From: "perkj@webrtc.org" Date: Thu, 6 Oct 2011 20:36:23 +0000 Subject: [PATCH] Update PeerConnection_client to open a video capture device. BUG= TEST= Review URL: http://webrtc-codereview.appspot.com/205001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@707 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../peerconnection_client/conductor.cc | 31 +++++++++++++++++-- .../peerconnection_client/conductor.h | 5 +++ .../peerconnection_client.gyp | 4 +++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc index 34959c573..15877f5a1 100644 --- a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc +++ b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.cc @@ -12,6 +12,7 @@ #include +#include "modules/video_capture/main/source/video_capture_impl.h" #include "talk/examples/peerconnection_client/defaults.h" #include "talk/base/common.h" #include "talk/base/logging.h" @@ -213,14 +214,37 @@ void Conductor::ConnectToPeer(int peer_id) { if (InitializePeerConnection()) { peer_id_ = peer_id; - main_wnd_->SwitchToStreamingUI(); - EnsureStreamingUI(); AddStreams(); } else { main_wnd_->MessageBox("Error", "Failed to initialize PeerConnection", true); } } +scoped_refptr Conductor::OpenVideoCaptureDevice() { + webrtc::VideoCaptureModule::DeviceInfo* device_info( + webrtc::videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(0)); + scoped_refptr video_device; + + const size_t kMaxDeviceNameLength = 128; + const size_t kMaxUniqueIdLength = 256; + uint8 device_name[kMaxDeviceNameLength]; + uint8 unique_id[kMaxUniqueIdLength]; + + const size_t device_count = device_info->NumberOfDevices(); + for (size_t i = 0; i < device_count; ++i) { + // Get the name of the video capture device. + device_info->GetDeviceName(i, device_name, kMaxDeviceNameLength, unique_id, + kMaxUniqueIdLength); + // Try to open this device. + video_device = + webrtc::videocapturemodule::VideoCaptureImpl::Create(0, unique_id); + if (video_device.get()) + break; + } + webrtc::videocapturemodule::VideoCaptureImpl::DestroyDeviceInfo(device_info); + return video_device; +} + void Conductor::AddStreams() { if (active_streams_.find(kStreamLabel) != active_streams_.end()) return; // Already added. @@ -229,7 +253,7 @@ void Conductor::AddStreams() { webrtc::CreateLocalAudioTrack(kAudioLabel, NULL)); scoped_refptr video_track( - webrtc::CreateLocalVideoTrack(kVideoLabel, NULL)); + webrtc::CreateLocalVideoTrack(kVideoLabel, OpenVideoCaptureDevice())); scoped_refptr renderer(webrtc::CreateVideoRenderer( main_wnd_->local_renderer())); @@ -245,6 +269,7 @@ void Conductor::AddStreams() { typedef std::pair > MediaStreamPair; active_streams_.insert(MediaStreamPair(stream->label(), stream)); + main_wnd_->SwitchToStreamingUI(); } void Conductor::DisconnectFromCurrentPeer() { diff --git a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.h b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.h index ed0fe2131..27de81773 100644 --- a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.h +++ b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/conductor.h @@ -23,6 +23,10 @@ #include "talk/app/webrtc_dev/peerconnection.h" #include "talk/base/scoped_ptr.h" +namespace webrtc { +class VideoCaptureModule; +} // namespace webrtc + namespace cricket { class VideoRenderer; } // namespace cricket @@ -54,6 +58,7 @@ class Conductor void DeletePeerConnection(); void EnsureStreamingUI(); void AddStreams(); + scoped_refptr OpenVideoCaptureDevice(); // // PeerConnectionObserver implementation. diff --git a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peerconnection_client.gyp b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peerconnection_client.gyp index 27cce641e..4592646ef 100644 --- a/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peerconnection_client.gyp +++ b/third_party_mods/libjingle/source/talk/examples/peerconnection_client/peerconnection_client.gyp @@ -26,12 +26,16 @@ ], 'dependencies': [ '../../../../libjingle.gyp:libjingle_app', + '../../../../../../src/modules/modules.gyp:video_capture_module', + '../../../../../../src/system_wrappers/source/' + 'system_wrappers.gyp:system_wrappers', # TODO(tommi): Switch to this and remove specific gtk dependency # sections below for cflags and link_settings. # '<(DEPTH)/build/linux/system.gyp:gtk', ], 'include_dirs': [ '../../../', + '../../../../../../src', # webrtc modules #TODO(perkj): Remove when this project is in the correct folder. '../../../../../../third_party/libjingle/source/', ],