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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | examples/unityplugin/unity_plugin_apis.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/unityplugin/simple_peer_connection.cc
diff --git a/examples/unityplugin/simple_peer_connection.cc b/examples/unityplugin/simple_peer_connection.cc
index fe59d53a6f5728517762300d0f2a60ff546f398e..ce6eb9d6889afe5e54d07eb4f981f2f22e0d6829 100644
--- a/examples/unityplugin/simple_peer_connection.cc
+++ b/examples/unityplugin/simple_peer_connection.cc
@@ -74,6 +74,23 @@ class DummySetSessionDescriptionObserver
~DummySetSessionDescriptionObserver() {}
};
+class DummyCapturer : public cricket::VideoCapturer {
+ public:
+ cricket::CaptureState Start(
+ const cricket::VideoFormat& capture_format) override {
+ return cricket::CS_RUNNING;
+ }
+ void Stop() override {}
+ void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
+ const rtc::VideoSinkWants& wants) override {}
+
+ bool IsRunning() override { return true; }
+ bool IsScreencast() const override { return false; }
+ bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override {
+ return true;
+ }
+};
+
} // namespace
bool SimplePeerConnection::InitializePeerConnection(const char** turn_urls,
@@ -407,28 +424,28 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
std::string id = audio_track->id();
stream->AddTrack(audio_track);
- if (!audio_only) {
#if defined(WEBRTC_ANDROID)
- JNIEnv* env = webrtc::jni::GetEnv();
- jclass pc_factory_class =
- unity_plugin::FindClass(env, "org/webrtc/UnityUtility");
- jmethodID load_texture_helper_method = webrtc::jni::GetStaticMethodID(
- env, pc_factory_class, "LoadSurfaceTextureHelper",
- "()Lorg/webrtc/SurfaceTextureHelper;");
- jobject texture_helper = env->CallStaticObjectMethod(
- pc_factory_class, load_texture_helper_method);
- CHECK_EXCEPTION(env);
- RTC_DCHECK(texture_helper != nullptr)
- << "Cannot get the Surface Texture Helper.";
-
- rtc::scoped_refptr<AndroidVideoTrackSource> source(
- new rtc::RefCountedObject<AndroidVideoTrackSource>(
- g_signaling_thread.get(), env, texture_helper, false));
- rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source =
- webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(),
- g_worker_thread.get(), source);
-
- // link with VideoCapturer (Camera);
+ JNIEnv* env = webrtc::jni::GetEnv();
+ jclass pc_factory_class =
+ unity_plugin::FindClass(env, "org/webrtc/UnityUtility");
+ jmethodID load_texture_helper_method = webrtc::jni::GetStaticMethodID(
+ env, pc_factory_class, "LoadSurfaceTextureHelper",
+ "()Lorg/webrtc/SurfaceTextureHelper;");
+ jobject texture_helper =
+ env->CallStaticObjectMethod(pc_factory_class, load_texture_helper_method);
+ CHECK_EXCEPTION(env);
+ RTC_DCHECK(texture_helper != nullptr)
+ << "Cannot get the Surface Texture Helper.";
+
+ rtc::scoped_refptr<webrtc::jni::AndroidVideoTrackSource> source(
+ new rtc::RefCountedObject<webrtc::jni::AndroidVideoTrackSource>(
+ g_signaling_thread.get(), env, texture_helper, false));
+ rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source =
+ webrtc::VideoTrackSourceProxy::Create(g_signaling_thread.get(),
+ g_worker_thread.get(), source);
+
+ // link with VideoCapturer (Camera);
+ if (!audio_only) {
jmethodID link_camera_method = webrtc::jni::GetStaticMethodID(
env, pc_factory_class, "LinkCamera",
"(JLorg/webrtc/SurfaceTextureHelper;)Lorg/webrtc/VideoCapturer;");
@@ -437,27 +454,33 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
(jlong)proxy_source.get(), texture_helper);
CHECK_EXCEPTION(env);
g_camera = (jobject)env->NewGlobalRef(camera_tmp);
+ }
+ rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
+ g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
+ proxy_source.release()));
+ stream->AddTrack(video_track);
+#else
+ std::unique_ptr<cricket::VideoCapturer> capture;
+ if (!audio_only) {
+ capture = OpenVideoCaptureDevice();
+ } else {
+ capture.reset(new DummyCapturer());
+ }
+ if (capture) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
- g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
- proxy_source.release()));
+ g_peer_connection_factory->CreateVideoTrack(
+ kVideoLabel, g_peer_connection_factory->CreateVideoSource(
+ std::move(capture), nullptr)));
+
stream->AddTrack(video_track);
-#else
- std::unique_ptr<cricket::VideoCapturer> capture = OpenVideoCaptureDevice();
- if (capture) {
- rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
- g_peer_connection_factory->CreateVideoTrack(
- kVideoLabel, g_peer_connection_factory->CreateVideoSource(
- std::move(capture), nullptr)));
-
- stream->AddTrack(video_track);
- }
+ }
+
#endif
if (local_video_observer_ && !stream->GetVideoTracks().empty()) {
stream->GetVideoTracks()[0]->AddOrUpdateSink(local_video_observer_.get(),
rtc::VideoSinkWants());
}
- }
if (!peer_connection_->AddStream(stream)) {
LOG(LS_ERROR) << "Adding stream to PeerConnection failed";
« 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