OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/examples/peerconnection/client/conductor.h" | 11 #include "webrtc/examples/peerconnection/client/conductor.h" |
12 | 12 |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/api/videosourceinterface.h" | 16 #include "webrtc/api/videosourceinterface.h" |
17 #include "webrtc/api/test/fakeconstraints.h" | 17 #include "webrtc/api/test/fakeconstraints.h" |
18 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
19 #include "webrtc/base/json.h" | 19 #include "webrtc/base/json.h" |
20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
21 #include "webrtc/examples/peerconnection/client/defaults.h" | 21 #include "webrtc/examples/peerconnection/client/defaults.h" |
22 #include "webrtc/media/devices/devicemanager.h" | 22 #include "webrtc/media/engine/webrtcvideocapturerfactory.h" |
| 23 #include "webrtc/modules/video_capture/video_capture_factory.h" |
23 | 24 |
24 // Names used for a IceCandidate JSON object. | 25 // Names used for a IceCandidate JSON object. |
25 const char kCandidateSdpMidName[] = "sdpMid"; | 26 const char kCandidateSdpMidName[] = "sdpMid"; |
26 const char kCandidateSdpMlineIndexName[] = "sdpMLineIndex"; | 27 const char kCandidateSdpMlineIndexName[] = "sdpMLineIndex"; |
27 const char kCandidateSdpName[] = "candidate"; | 28 const char kCandidateSdpName[] = "candidate"; |
28 | 29 |
29 // Names used for a SessionDescription JSON object. | 30 // Names used for a SessionDescription JSON object. |
30 const char kSessionDescriptionTypeName[] = "type"; | 31 const char kSessionDescriptionTypeName[] = "type"; |
31 const char kSessionDescriptionSdpName[] = "sdp"; | 32 const char kSessionDescriptionSdpName[] = "sdp"; |
32 | 33 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 363 |
363 if (InitializePeerConnection()) { | 364 if (InitializePeerConnection()) { |
364 peer_id_ = peer_id; | 365 peer_id_ = peer_id; |
365 peer_connection_->CreateOffer(this, NULL); | 366 peer_connection_->CreateOffer(this, NULL); |
366 } else { | 367 } else { |
367 main_wnd_->MessageBox("Error", "Failed to initialize PeerConnection", true); | 368 main_wnd_->MessageBox("Error", "Failed to initialize PeerConnection", true); |
368 } | 369 } |
369 } | 370 } |
370 | 371 |
371 cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() { | 372 cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() { |
372 rtc::scoped_ptr<cricket::DeviceManagerInterface> dev_manager( | 373 std::vector<std::string> device_names; |
373 cricket::DeviceManagerFactory::Create()); | 374 { |
374 if (!dev_manager->Init()) { | 375 std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info( |
375 LOG(LS_ERROR) << "Can't create device manager"; | 376 webrtc::VideoCaptureFactory::CreateDeviceInfo(0)); |
376 return NULL; | 377 if (!info) { |
| 378 return nullptr; |
| 379 } |
| 380 int num_devices = info->NumberOfDevices(); |
| 381 for (int i = 0; i < num_devices; ++i) { |
| 382 const uint32_t kSize = 256; |
| 383 char name[kSize] = {0}; |
| 384 char id[kSize] = {0}; |
| 385 if (info->GetDeviceName(i, name, kSize, id, kSize) != -1) { |
| 386 device_names.push_back(name); |
| 387 } |
| 388 } |
377 } | 389 } |
378 std::vector<cricket::Device> devs; | 390 |
379 if (!dev_manager->GetVideoCaptureDevices(&devs)) { | 391 cricket::WebRtcVideoDeviceCapturerFactory factory; |
380 LOG(LS_ERROR) << "Can't enumerate video devices"; | 392 cricket::VideoCapturer* capturer = nullptr; |
381 return NULL; | 393 for (const auto& name : device_names) { |
382 } | 394 capturer = factory.Create(cricket::Device(name, 0)); |
383 std::vector<cricket::Device>::iterator dev_it = devs.begin(); | 395 if (capturer) { |
384 cricket::VideoCapturer* capturer = NULL; | |
385 for (; dev_it != devs.end(); ++dev_it) { | |
386 capturer = dev_manager->CreateVideoCapturer(*dev_it); | |
387 if (capturer != NULL) | |
388 break; | 396 break; |
| 397 } |
389 } | 398 } |
390 return capturer; | 399 return capturer; |
391 } | 400 } |
392 | 401 |
393 void Conductor::AddStreams() { | 402 void Conductor::AddStreams() { |
394 if (active_streams_.find(kStreamLabel) != active_streams_.end()) | 403 if (active_streams_.find(kStreamLabel) != active_streams_.end()) |
395 return; // Already added. | 404 return; // Already added. |
396 | 405 |
397 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | 406 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
398 peer_connection_factory_->CreateAudioTrack( | 407 peer_connection_factory_->CreateAudioTrack( |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 } | 540 } |
532 | 541 |
533 void Conductor::OnFailure(const std::string& error) { | 542 void Conductor::OnFailure(const std::string& error) { |
534 LOG(LERROR) << error; | 543 LOG(LERROR) << error; |
535 } | 544 } |
536 | 545 |
537 void Conductor::SendMessage(const std::string& json_object) { | 546 void Conductor::SendMessage(const std::string& json_object) { |
538 std::string* msg = new std::string(json_object); | 547 std::string* msg = new std::string(json_object); |
539 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg); | 548 main_wnd_->QueueUIThreadCallback(SEND_MESSAGE_TO_PEER, msg); |
540 } | 549 } |
OLD | NEW |