Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(737)

Side by Side Diff: examples/unityplugin/simple_peer_connection.cc

Issue 3013733002: WebRTC Unity Plugin Rebase
Patch Set: Add Comment Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | examples/unityplugin/unity_plugin_apis.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 417
401 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = 418 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
402 g_peer_connection_factory->CreateLocalMediaStream(kStreamLabel); 419 g_peer_connection_factory->CreateLocalMediaStream(kStreamLabel);
403 420
404 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( 421 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
405 g_peer_connection_factory->CreateAudioTrack( 422 g_peer_connection_factory->CreateAudioTrack(
406 kAudioLabel, g_peer_connection_factory->CreateAudioSource(nullptr))); 423 kAudioLabel, g_peer_connection_factory->CreateAudioSource(nullptr)));
407 std::string id = audio_track->id(); 424 std::string id = audio_track->id();
408 stream->AddTrack(audio_track); 425 stream->AddTrack(audio_track);
409 426
427 #if defined(WEBRTC_ANDROID)
428 JNIEnv* env = webrtc::jni::GetEnv();
429 jclass pc_factory_class =
430 unity_plugin::FindClass(env, "org/webrtc/UnityUtility");
431 jmethodID load_texture_helper_method = webrtc::jni::GetStaticMethodID(
432 env, pc_factory_class, "LoadSurfaceTextureHelper",
433 "()Lorg/webrtc/SurfaceTextureHelper;");
434 jobject texture_helper =
435 env->CallStaticObjectMethod(pc_factory_class, load_texture_helper_method);
436 CHECK_EXCEPTION(env);
437 RTC_DCHECK(texture_helper != nullptr)
438 << "Cannot get the Surface Texture Helper.";
439
440 rtc::scoped_refptr<webrtc::jni::AndroidVideoTrackSource> source(
441 new rtc::RefCountedObject<webrtc::jni::AndroidVideoTrackSource>(
442 g_signaling_thread.get(), env, texture_helper, false));
443 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source =
444 webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(),
445 g_worker_thread.get(), source);
446
447 // link with VideoCapturer (Camera);
410 if (!audio_only) { 448 if (!audio_only) {
411 #if defined(WEBRTC_ANDROID)
412 JNIEnv* env = webrtc::jni::GetEnv();
413 jclass pc_factory_class =
414 unity_plugin::FindClass(env, "org/webrtc/UnityUtility");
415 jmethodID load_texture_helper_method = webrtc::jni::GetStaticMethodID(
416 env, pc_factory_class, "LoadSurfaceTextureHelper",
417 "()Lorg/webrtc/SurfaceTextureHelper;");
418 jobject texture_helper = env->CallStaticObjectMethod(
419 pc_factory_class, load_texture_helper_method);
420 CHECK_EXCEPTION(env);
421 RTC_DCHECK(texture_helper != nullptr)
422 << "Cannot get the Surface Texture Helper.";
423
424 rtc::scoped_refptr<AndroidVideoTrackSource> source(
425 new rtc::RefCountedObject<AndroidVideoTrackSource>(
426 g_signaling_thread.get(), env, texture_helper, false));
427 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source =
428 webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(),
429 g_worker_thread.get(), source);
430
431 // link with VideoCapturer (Camera);
432 jmethodID link_camera_method = webrtc::jni::GetStaticMethodID( 449 jmethodID link_camera_method = webrtc::jni::GetStaticMethodID(
433 env, pc_factory_class, "LinkCamera", 450 env, pc_factory_class, "LinkCamera",
434 "(JLorg/webrtc/SurfaceTextureHelper;)Lorg/webrtc/VideoCapturer;"); 451 "(JLorg/webrtc/SurfaceTextureHelper;)Lorg/webrtc/VideoCapturer;");
435 jobject camera_tmp = 452 jobject camera_tmp =
436 env->CallStaticObjectMethod(pc_factory_class, link_camera_method, 453 env->CallStaticObjectMethod(pc_factory_class, link_camera_method,
437 (jlong)proxy_source.get(), texture_helper); 454 (jlong)proxy_source.get(), texture_helper);
438 CHECK_EXCEPTION(env); 455 CHECK_EXCEPTION(env);
439 g_camera = (jobject)env->NewGlobalRef(camera_tmp); 456 g_camera = (jobject)env->NewGlobalRef(camera_tmp);
457 }
440 458
459 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
460 g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
461 proxy_source.release()));
462 stream->AddTrack(video_track);
463 #else
464 std::unique_ptr<cricket::VideoCapturer> capture;
465 if (!audio_only) {
466 capture = OpenVideoCaptureDevice();
467 } else {
468 capture.reset(new DummyCapturer());
469 }
470 if (capture) {
441 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( 471 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
442 g_peer_connection_factory->CreateVideoTrack(kVideoLabel, 472 g_peer_connection_factory->CreateVideoTrack(
443 proxy_source.release())); 473 kVideoLabel, g_peer_connection_factory->CreateVideoSource(
474 std::move(capture), nullptr)));
475
444 stream->AddTrack(video_track); 476 stream->AddTrack(video_track);
445 #else 477 }
446 std::unique_ptr<cricket::VideoCapturer> capture = OpenVideoCaptureDevice();
447 if (capture) {
448 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
449 g_peer_connection_factory->CreateVideoTrack(
450 kVideoLabel, g_peer_connection_factory->CreateVideoSource(
451 std::move(capture), nullptr)));
452 478
453 stream->AddTrack(video_track);
454 }
455 #endif 479 #endif
456 if (local_video_observer_ && !stream->GetVideoTracks().empty()) { 480 if (local_video_observer_ && !stream->GetVideoTracks().empty()) {
457 stream->GetVideoTracks()[0]->AddOrUpdateSink(local_video_observer_.get(), 481 stream->GetVideoTracks()[0]->AddOrUpdateSink(local_video_observer_.get(),
458 rtc::VideoSinkWants()); 482 rtc::VideoSinkWants());
459 } 483 }
460 }
461 484
462 if (!peer_connection_->AddStream(stream)) { 485 if (!peer_connection_->AddStream(stream)) {
463 LOG(LS_ERROR) << "Adding stream to PeerConnection failed"; 486 LOG(LS_ERROR) << "Adding stream to PeerConnection failed";
464 } 487 }
465 488
466 typedef std::pair<std::string, 489 typedef std::pair<std::string,
467 rtc::scoped_refptr<webrtc::MediaStreamInterface>> 490 rtc::scoped_refptr<webrtc::MediaStreamInterface>>
468 MediaStreamPair; 491 MediaStreamPair;
469 active_streams_.insert(MediaStreamPair(stream->label(), stream)); 492 active_streams_.insert(MediaStreamPair(stream->label(), stream));
470 } 493 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 579
557 for (const auto& param : params) { 580 for (const auto& param : params) {
558 uint32_t ssrc = param.ssrc.value_or(0); 581 uint32_t ssrc = param.ssrc.value_or(0);
559 if (ssrc > 0) 582 if (ssrc > 0)
560 ssrcs.push_back(ssrc); 583 ssrcs.push_back(ssrc);
561 } 584 }
562 } 585 }
563 586
564 return ssrcs; 587 return ssrcs;
565 } 588 }
OLDNEW
« no previous file with comments | « no previous file | examples/unityplugin/unity_plugin_apis.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698