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
This commit is contained in:
perkj@webrtc.org 2011-10-06 20:36:23 +00:00
parent bf54ef9bb7
commit f6ab63c08a
3 changed files with 37 additions and 3 deletions

View File

@ -12,6 +12,7 @@
#include <utility>
#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<webrtc::VideoCaptureModule> Conductor::OpenVideoCaptureDevice() {
webrtc::VideoCaptureModule::DeviceInfo* device_info(
webrtc::videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(0));
scoped_refptr<webrtc::VideoCaptureModule> 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<webrtc::LocalVideoTrack> video_track(
webrtc::CreateLocalVideoTrack(kVideoLabel, NULL));
webrtc::CreateLocalVideoTrack(kVideoLabel, OpenVideoCaptureDevice()));
scoped_refptr<webrtc::VideoRenderer> renderer(webrtc::CreateVideoRenderer(
main_wnd_->local_renderer()));
@ -245,6 +269,7 @@ void Conductor::AddStreams() {
typedef std::pair<std::string, scoped_refptr<webrtc::MediaStream> >
MediaStreamPair;
active_streams_.insert(MediaStreamPair(stream->label(), stream));
main_wnd_->SwitchToStreamingUI();
}
void Conductor::DisconnectFromCurrentPeer() {

View File

@ -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<webrtc::VideoCaptureModule> OpenVideoCaptureDevice();
//
// PeerConnectionObserver implementation.

View File

@ -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/',
],