| 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 <gtk/gtk.h> | 11 #include <gtk/gtk.h> |
| 12 | 12 |
| 13 #include "webrtc/examples/peerconnection/client/conductor.h" | 13 #include "webrtc/examples/peerconnection/client/conductor.h" |
| 14 #include "webrtc/examples/peerconnection/client/flagdefs.h" | 14 #include "webrtc/examples/peerconnection/client/flagdefs.h" |
| 15 #include "webrtc/examples/peerconnection/client/linux/main_wnd.h" | 15 #include "webrtc/examples/peerconnection/client/linux/main_wnd.h" |
| 16 #include "webrtc/examples/peerconnection/client/peer_connection_client.h" | 16 #include "webrtc/examples/peerconnection/client/peer_connection_client.h" |
| 17 | 17 |
| 18 #include "webrtc/base/ssladapter.h" | 18 #include "webrtc/base/ssladapter.h" |
| 19 #include "webrtc/base/thread.h" | 19 #include "webrtc/base/thread.h" |
| 20 | 20 |
| 21 class CustomSocketServer : public rtc::PhysicalSocketServer { | 21 class CustomSocketServer : public rtc::PhysicalSocketServer { |
| 22 public: | 22 public: |
| 23 CustomSocketServer(rtc::Thread* thread, GtkMainWnd* wnd) | 23 explicit CustomSocketServer(GtkMainWnd* wnd) |
| 24 : thread_(thread), wnd_(wnd), conductor_(NULL), client_(NULL) {} | 24 : wnd_(wnd), conductor_(NULL), client_(NULL) {} |
| 25 virtual ~CustomSocketServer() {} | 25 virtual ~CustomSocketServer() {} |
| 26 | 26 |
| 27 void SetMessageQueue(rtc::MessageQueue* queue) override { |
| 28 message_queue_ = queue; |
| 29 } |
| 30 |
| 27 void set_client(PeerConnectionClient* client) { client_ = client; } | 31 void set_client(PeerConnectionClient* client) { client_ = client; } |
| 28 void set_conductor(Conductor* conductor) { conductor_ = conductor; } | 32 void set_conductor(Conductor* conductor) { conductor_ = conductor; } |
| 29 | 33 |
| 30 // Override so that we can also pump the GTK message loop. | 34 // Override so that we can also pump the GTK message loop. |
| 31 virtual bool Wait(int cms, bool process_io) { | 35 virtual bool Wait(int cms, bool process_io) { |
| 32 // Pump GTK events. | 36 // Pump GTK events. |
| 33 // TODO(henrike): We really should move either the socket server or UI to a | 37 // TODO(henrike): We really should move either the socket server or UI to a |
| 34 // different thread. Alternatively we could look at merging the two loops | 38 // different thread. Alternatively we could look at merging the two loops |
| 35 // by implementing a dispatcher for the socket server and/or use | 39 // by implementing a dispatcher for the socket server and/or use |
| 36 // g_main_context_set_poll_func. | 40 // g_main_context_set_poll_func. |
| 37 while (gtk_events_pending()) | 41 while (gtk_events_pending()) |
| 38 gtk_main_iteration(); | 42 gtk_main_iteration(); |
| 39 | 43 |
| 40 if (!wnd_->IsWindow() && !conductor_->connection_active() && | 44 if (!wnd_->IsWindow() && !conductor_->connection_active() && |
| 41 client_ != NULL && !client_->is_connected()) { | 45 client_ != NULL && !client_->is_connected()) { |
| 42 thread_->Quit(); | 46 message_queue_->Quit(); |
| 43 } | 47 } |
| 44 return rtc::PhysicalSocketServer::Wait(0/*cms == -1 ? 1 : cms*/, | 48 return rtc::PhysicalSocketServer::Wait(0/*cms == -1 ? 1 : cms*/, |
| 45 process_io); | 49 process_io); |
| 46 } | 50 } |
| 47 | 51 |
| 48 protected: | 52 protected: |
| 49 rtc::Thread* thread_; | 53 rtc::MessageQueue* message_queue_; |
| 50 GtkMainWnd* wnd_; | 54 GtkMainWnd* wnd_; |
| 51 Conductor* conductor_; | 55 Conductor* conductor_; |
| 52 PeerConnectionClient* client_; | 56 PeerConnectionClient* client_; |
| 53 }; | 57 }; |
| 54 | 58 |
| 55 int main(int argc, char* argv[]) { | 59 int main(int argc, char* argv[]) { |
| 56 gtk_init(&argc, &argv); | 60 gtk_init(&argc, &argv); |
| 57 // g_type_init API is deprecated (and does nothing) since glib 2.35.0, see: | 61 // g_type_init API is deprecated (and does nothing) since glib 2.35.0, see: |
| 58 // https://mail.gnome.org/archives/commits-list/2012-November/msg07809.html | 62 // https://mail.gnome.org/archives/commits-list/2012-November/msg07809.html |
| 59 #if !GLIB_CHECK_VERSION(2, 35, 0) | 63 #if !GLIB_CHECK_VERSION(2, 35, 0) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 // Abort if the user specifies a port that is outside the allowed | 78 // Abort if the user specifies a port that is outside the allowed |
| 75 // range [1, 65535]. | 79 // range [1, 65535]. |
| 76 if ((FLAG_port < 1) || (FLAG_port > 65535)) { | 80 if ((FLAG_port < 1) || (FLAG_port > 65535)) { |
| 77 printf("Error: %i is not a valid port.\n", FLAG_port); | 81 printf("Error: %i is not a valid port.\n", FLAG_port); |
| 78 return -1; | 82 return -1; |
| 79 } | 83 } |
| 80 | 84 |
| 81 GtkMainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall); | 85 GtkMainWnd wnd(FLAG_server, FLAG_port, FLAG_autoconnect, FLAG_autocall); |
| 82 wnd.Create(); | 86 wnd.Create(); |
| 83 | 87 |
| 84 rtc::AutoThread auto_thread; | 88 CustomSocketServer socket_server(&wnd); |
| 85 rtc::Thread* thread = rtc::Thread::Current(); | 89 rtc::AutoSocketServerThread thread(&socket_server); |
| 86 CustomSocketServer socket_server(thread, &wnd); | |
| 87 thread->set_socketserver(&socket_server); | |
| 88 | 90 |
| 89 rtc::InitializeSSL(); | 91 rtc::InitializeSSL(); |
| 90 // Must be constructed after we set the socketserver. | 92 // Must be constructed after we set the socketserver. |
| 91 PeerConnectionClient client; | 93 PeerConnectionClient client; |
| 92 rtc::scoped_refptr<Conductor> conductor( | 94 rtc::scoped_refptr<Conductor> conductor( |
| 93 new rtc::RefCountedObject<Conductor>(&client, &wnd)); | 95 new rtc::RefCountedObject<Conductor>(&client, &wnd)); |
| 94 socket_server.set_client(&client); | 96 socket_server.set_client(&client); |
| 95 socket_server.set_conductor(conductor); | 97 socket_server.set_conductor(conductor); |
| 96 | 98 |
| 97 thread->Run(); | 99 thread.Run(); |
| 98 | 100 |
| 99 // gtk_main(); | 101 // gtk_main(); |
| 100 wnd.Destroy(); | 102 wnd.Destroy(); |
| 101 | 103 |
| 102 thread->set_socketserver(NULL); | |
| 103 // TODO(henrike): Run the Gtk main loop to tear down the connection. | 104 // TODO(henrike): Run the Gtk main loop to tear down the connection. |
| 104 /* | 105 /* |
| 105 while (gtk_events_pending()) { | 106 while (gtk_events_pending()) { |
| 106 gtk_main_iteration(); | 107 gtk_main_iteration(); |
| 107 } | 108 } |
| 108 */ | 109 */ |
| 109 rtc::CleanupSSL(); | 110 rtc::CleanupSSL(); |
| 110 return 0; | 111 return 0; |
| 111 } | 112 } |
| OLD | NEW |