| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 virtual void OnSuccess() { LOG(INFO) << __FUNCTION__; } | 67 virtual void OnSuccess() { LOG(INFO) << __FUNCTION__; } |
| 68 virtual void OnFailure(const std::string& error) { | 68 virtual void OnFailure(const std::string& error) { |
| 69 LOG(INFO) << __FUNCTION__ << " " << error; | 69 LOG(INFO) << __FUNCTION__ << " " << error; |
| 70 } | 70 } |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 DummySetSessionDescriptionObserver() {} | 73 DummySetSessionDescriptionObserver() {} |
| 74 ~DummySetSessionDescriptionObserver() {} | 74 ~DummySetSessionDescriptionObserver() {} |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 class DummyCapturer : public cricket::VideoCapturer { |
| 78 public: |
| 79 cricket::CaptureState Start( |
| 80 const cricket::VideoFormat& capture_format) override { |
| 81 return cricket::CS_RUNNING; |
| 82 } |
| 83 void Stop() override {} |
| 84 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, |
| 85 const rtc::VideoSinkWants& wants) override {} |
| 86 |
| 87 bool IsRunning() override { return true; } |
| 88 bool IsScreencast() const override { return false; } |
| 89 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override { |
| 90 return true; |
| 91 } |
| 92 }; |
| 93 |
| 77 } // namespace | 94 } // namespace |
| 78 | 95 |
| 79 bool SimplePeerConnection::InitializePeerConnection(const char** turn_urls, | 96 bool SimplePeerConnection::InitializePeerConnection(const char** turn_urls, |
| 80 const int no_of_urls, | 97 const int no_of_urls, |
| 81 const char* username, | 98 const char* username, |
| 82 const char* credential, | 99 const char* credential, |
| 83 bool is_receiver) { | 100 bool is_receiver) { |
| 84 RTC_DCHECK(peer_connection_.get() == nullptr); | 101 RTC_DCHECK(peer_connection_.get() == nullptr); |
| 85 | 102 |
| 86 if (g_peer_connection_factory == nullptr) { | 103 if (g_peer_connection_factory == nullptr) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return true; | 221 return true; |
| 205 } | 222 } |
| 206 | 223 |
| 207 void SimplePeerConnection::OnSuccess( | 224 void SimplePeerConnection::OnSuccess( |
| 208 webrtc::SessionDescriptionInterface* desc) { | 225 webrtc::SessionDescriptionInterface* desc) { |
| 209 peer_connection_->SetLocalDescription( | 226 peer_connection_->SetLocalDescription( |
| 210 DummySetSessionDescriptionObserver::Create(), desc); | 227 DummySetSessionDescriptionObserver::Create(), desc); |
| 211 | 228 |
| 212 std::string sdp; | 229 std::string sdp; |
| 213 desc->ToString(&sdp); | 230 desc->ToString(&sdp); |
| 214 | |
| 215 if (OnLocalSdpReady) | 231 if (OnLocalSdpReady) |
| 216 OnLocalSdpReady(desc->type().c_str(), sdp.c_str()); | 232 OnLocalSdpReady(desc->type().c_str(), sdp.c_str()); |
| 217 } | 233 } |
| 218 | 234 |
| 219 void SimplePeerConnection::OnFailure(const std::string& error) { | 235 void SimplePeerConnection::OnFailure(const std::string& error) { |
| 220 LOG(LERROR) << error; | 236 LOG(LERROR) << error; |
| 221 | 237 |
| 222 if (OnFailureMessage) | 238 if (OnFailureMessage) |
| 223 OnFailureMessage(error.c_str()); | 239 OnFailureMessage(error.c_str()); |
| 224 } | 240 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 416 |
| 401 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = | 417 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
| 402 g_peer_connection_factory->CreateLocalMediaStream(kStreamLabel); | 418 g_peer_connection_factory->CreateLocalMediaStream(kStreamLabel); |
| 403 | 419 |
| 404 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | 420 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 405 g_peer_connection_factory->CreateAudioTrack( | 421 g_peer_connection_factory->CreateAudioTrack( |
| 406 kAudioLabel, g_peer_connection_factory->CreateAudioSource(nullptr))); | 422 kAudioLabel, g_peer_connection_factory->CreateAudioSource(nullptr))); |
| 407 std::string id = audio_track->id(); | 423 std::string id = audio_track->id(); |
| 408 stream->AddTrack(audio_track); | 424 stream->AddTrack(audio_track); |
| 409 | 425 |
| 410 if (!audio_only) { | |
| 411 #if defined(WEBRTC_ANDROID) | 426 #if defined(WEBRTC_ANDROID) |
| 412 JNIEnv* env = webrtc::jni::GetEnv(); | 427 JNIEnv* env = webrtc::jni::GetEnv(); |
| 413 jclass pc_factory_class = | 428 jclass pc_factory_class = |
| 414 unity_plugin::FindClass(env, "org/webrtc/UnityUtility"); | 429 unity_plugin::FindClass(env, "org/webrtc/UnityUtility"); |
| 415 jmethodID load_texture_helper_method = webrtc::jni::GetStaticMethodID( | 430 jmethodID load_texture_helper_method = webrtc::jni::GetStaticMethodID( |
| 416 env, pc_factory_class, "LoadSurfaceTextureHelper", | 431 env, pc_factory_class, "LoadSurfaceTextureHelper", |
| 417 "()Lorg/webrtc/SurfaceTextureHelper;"); | 432 "()Lorg/webrtc/SurfaceTextureHelper;"); |
| 418 jobject texture_helper = env->CallStaticObjectMethod( | 433 jobject texture_helper = env->CallStaticObjectMethod( |
| 419 pc_factory_class, load_texture_helper_method); | 434 pc_factory_class, load_texture_helper_method); |
| 420 CHECK_EXCEPTION(env); | 435 CHECK_EXCEPTION(env); |
| 421 RTC_DCHECK(texture_helper != nullptr) | 436 RTC_DCHECK(texture_helper != nullptr) |
| 422 << "Cannot get the Surface Texture Helper."; | 437 << "Cannot get the Surface Texture Helper."; |
| 423 | 438 |
| 424 rtc::scoped_refptr<AndroidVideoTrackSource> source( | 439 rtc::scoped_refptr<webrtc::jni::AndroidVideoTrackSource> source( |
| 425 new rtc::RefCountedObject<AndroidVideoTrackSource>( | 440 new rtc::RefCountedObject<webrtc::jni::AndroidVideoTrackSource>( |
| 426 g_signaling_thread.get(), env, texture_helper, false)); | 441 g_signaling_thread.get(), env, texture_helper, false)); |
| 427 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = | 442 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = |
| 428 webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(), | 443 webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(), |
| 429 g_worker_thread.get(), source); | 444 g_worker_thread.get(), source); |
| 430 | 445 |
| 431 // link with VideoCapturer (Camera); | 446 if (!audio_only) { |
| 432 jmethodID link_camera_method = webrtc::jni::GetStaticMethodID( | 447 // link with VideoCapturer (Camera); |
| 433 env, pc_factory_class, "LinkCamera", | 448 jmethodID link_camera_method = webrtc::jni::GetStaticMethodID( |
| 434 "(JLorg/webrtc/SurfaceTextureHelper;)Lorg/webrtc/VideoCapturer;"); | 449 env, pc_factory_class, "LinkCamera", |
| 435 jobject camera_tmp = | 450 "(JLorg/webrtc/SurfaceTextureHelper;)Lorg/webrtc/VideoCapturer;"); |
| 436 env->CallStaticObjectMethod(pc_factory_class, link_camera_method, | 451 jobject camera_tmp = env->CallStaticObjectMethod( |
| 437 (jlong)proxy_source.get(), texture_helper); | 452 pc_factory_class, link_camera_method, (jlong)proxy_source.get(), |
| 438 CHECK_EXCEPTION(env); | 453 texture_helper); |
| 439 g_camera = (jobject)env->NewGlobalRef(camera_tmp); | 454 CHECK_EXCEPTION(env); |
| 455 g_camera = (jobject)env->NewGlobalRef(camera_tmp); |
| 456 } |
| 440 | 457 |
| 441 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | 458 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 442 g_peer_connection_factory->CreateVideoTrack(kVideoLabel, | 459 g_peer_connection_factory->CreateVideoTrack(kVideoLabel, |
| 443 proxy_source.release())); | 460 proxy_source.release())); |
| 444 stream->AddTrack(video_track); | 461 stream->AddTrack(video_track); |
| 445 #else | 462 #else |
| 446 std::unique_ptr<cricket::VideoCapturer> capture = OpenVideoCaptureDevice(); | 463 std::unique_ptr<cricket::VideoCapturer> capture; |
| 447 if (capture) { | 464 if (!audio_only) { |
| 448 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | 465 capture = OpenVideoCaptureDevice(); |
| 449 g_peer_connection_factory->CreateVideoTrack( | 466 } else { |
| 450 kVideoLabel, g_peer_connection_factory->CreateVideoSource( | 467 capture.reset(new DummyCapturer()); |
| 451 std::move(capture), nullptr))); | 468 } |
| 469 if (capture) { |
| 470 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 471 g_peer_connection_factory->CreateVideoTrack( |
| 472 kVideoLabel, g_peer_connection_factory->CreateVideoSource( |
| 473 std::move(capture), nullptr))); |
| 452 | 474 |
| 453 stream->AddTrack(video_track); | 475 stream->AddTrack(video_track); |
| 454 } | 476 } |
| 477 |
| 455 #endif | 478 #endif |
| 456 if (local_video_observer_ && !stream->GetVideoTracks().empty()) { | 479 if (local_video_observer_ && !stream->GetVideoTracks().empty()) { |
| 457 stream->GetVideoTracks()[0]->AddOrUpdateSink(local_video_observer_.get(), | 480 stream->GetVideoTracks()[0]->AddOrUpdateSink(local_video_observer_.get(), |
| 458 rtc::VideoSinkWants()); | 481 rtc::VideoSinkWants()); |
| 459 } | 482 } |
| 460 } | |
| 461 | 483 |
| 462 if (!peer_connection_->AddStream(stream)) { | 484 if (!peer_connection_->AddStream(stream)) { |
| 463 LOG(LS_ERROR) << "Adding stream to PeerConnection failed"; | 485 LOG(LS_ERROR) << "Adding stream to PeerConnection failed"; |
| 464 } | 486 } |
| 465 | 487 |
| 466 typedef std::pair<std::string, | 488 typedef std::pair<std::string, |
| 467 rtc::scoped_refptr<webrtc::MediaStreamInterface>> | 489 rtc::scoped_refptr<webrtc::MediaStreamInterface>> |
| 468 MediaStreamPair; | 490 MediaStreamPair; |
| 469 active_streams_.insert(MediaStreamPair(stream->label(), stream)); | 491 active_streams_.insert(MediaStreamPair(stream->label(), stream)); |
| 470 } | 492 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 578 |
| 557 for (const auto& param : params) { | 579 for (const auto& param : params) { |
| 558 uint32_t ssrc = param.ssrc.value_or(0); | 580 uint32_t ssrc = param.ssrc.value_or(0); |
| 559 if (ssrc > 0) | 581 if (ssrc > 0) |
| 560 ssrcs.push_back(ssrc); | 582 ssrcs.push_back(ssrc); |
| 561 } | 583 } |
| 562 } | 584 } |
| 563 | 585 |
| 564 return ssrcs; | 586 return ssrcs; |
| 565 } | 587 } |
| OLD | NEW |