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/linux/main_wnd.h" | 11 #include "webrtc/examples/peerconnection/client/linux/main_wnd.h" |
12 | 12 |
13 #include <gdk/gdkkeysyms.h> | 13 #include <gdk/gdkkeysyms.h> |
14 #include <gtk/gtk.h> | 14 #include <gtk/gtk.h> |
15 #include <stddef.h> | 15 #include <stddef.h> |
16 | 16 |
17 #include "libyuv/convert_from.h" | 17 #include "libyuv/convert_from.h" |
18 #include "webrtc/api/video/i420_buffer.h" | 18 #include "webrtc/api/video/i420_buffer.h" |
19 #include "webrtc/examples/peerconnection/client/defaults.h" | 19 #include "webrtc/examples/peerconnection/client/defaults.h" |
| 20 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/common.h" | 21 #include "webrtc/base/common.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/stringutils.h" | 23 #include "webrtc/base/stringutils.h" |
23 | 24 |
24 using rtc::sprintfn; | 25 using rtc::sprintfn; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // | 29 // |
29 // Simple static functions that simply forward the callback to the | 30 // Simple static functions that simply forward the callback to the |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool autocall) | 136 bool autocall) |
136 : window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL), | 137 : window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL), |
137 port_edit_(NULL), peer_list_(NULL), callback_(NULL), | 138 port_edit_(NULL), peer_list_(NULL), callback_(NULL), |
138 server_(server), autoconnect_(autoconnect), autocall_(autocall) { | 139 server_(server), autoconnect_(autoconnect), autocall_(autocall) { |
139 char buffer[10]; | 140 char buffer[10]; |
140 sprintfn(buffer, sizeof(buffer), "%i", port); | 141 sprintfn(buffer, sizeof(buffer), "%i", port); |
141 port_ = buffer; | 142 port_ = buffer; |
142 } | 143 } |
143 | 144 |
144 GtkMainWnd::~GtkMainWnd() { | 145 GtkMainWnd::~GtkMainWnd() { |
145 ASSERT(!IsWindow()); | 146 RTC_DCHECK(!IsWindow()); |
146 } | 147 } |
147 | 148 |
148 void GtkMainWnd::RegisterObserver(MainWndCallback* callback) { | 149 void GtkMainWnd::RegisterObserver(MainWndCallback* callback) { |
149 callback_ = callback; | 150 callback_ = callback; |
150 } | 151 } |
151 | 152 |
152 bool GtkMainWnd::IsWindow() { | 153 bool GtkMainWnd::IsWindow() { |
153 return window_ != NULL && GTK_IS_WINDOW(window_); | 154 return window_ != NULL && GTK_IS_WINDOW(window_); |
154 } | 155 } |
155 | 156 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void GtkMainWnd::StopRemoteRenderer() { | 192 void GtkMainWnd::StopRemoteRenderer() { |
192 remote_renderer_.reset(); | 193 remote_renderer_.reset(); |
193 } | 194 } |
194 | 195 |
195 void GtkMainWnd::QueueUIThreadCallback(int msg_id, void* data) { | 196 void GtkMainWnd::QueueUIThreadCallback(int msg_id, void* data) { |
196 g_idle_add(HandleUIThreadCallback, | 197 g_idle_add(HandleUIThreadCallback, |
197 new UIThreadCallbackData(callback_, msg_id, data)); | 198 new UIThreadCallbackData(callback_, msg_id, data)); |
198 } | 199 } |
199 | 200 |
200 bool GtkMainWnd::Create() { | 201 bool GtkMainWnd::Create() { |
201 ASSERT(window_ == NULL); | 202 RTC_DCHECK(window_ == NULL); |
202 | 203 |
203 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 204 window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
204 if (window_) { | 205 if (window_) { |
205 gtk_window_set_position(GTK_WINDOW(window_), GTK_WIN_POS_CENTER); | 206 gtk_window_set_position(GTK_WINDOW(window_), GTK_WIN_POS_CENTER); |
206 gtk_window_set_default_size(GTK_WINDOW(window_), 640, 480); | 207 gtk_window_set_default_size(GTK_WINDOW(window_), 640, 480); |
207 gtk_window_set_title(GTK_WINDOW(window_), "PeerConnection client"); | 208 gtk_window_set_title(GTK_WINDOW(window_), "PeerConnection client"); |
208 g_signal_connect(G_OBJECT(window_), "delete-event", | 209 g_signal_connect(G_OBJECT(window_), "delete-event", |
209 G_CALLBACK(&OnDestroyedCallback), this); | 210 G_CALLBACK(&OnDestroyedCallback), this); |
210 g_signal_connect(window_, "key-press-event", G_CALLBACK(OnKeyPressCallback), | 211 g_signal_connect(window_, "key-press-event", G_CALLBACK(OnKeyPressCallback), |
211 this); | 212 this); |
(...skipping 10 matching lines...) Expand all Loading... |
222 | 223 |
223 gtk_widget_destroy(window_); | 224 gtk_widget_destroy(window_); |
224 window_ = NULL; | 225 window_ = NULL; |
225 | 226 |
226 return true; | 227 return true; |
227 } | 228 } |
228 | 229 |
229 void GtkMainWnd::SwitchToConnectUI() { | 230 void GtkMainWnd::SwitchToConnectUI() { |
230 LOG(INFO) << __FUNCTION__; | 231 LOG(INFO) << __FUNCTION__; |
231 | 232 |
232 ASSERT(IsWindow()); | 233 RTC_DCHECK(IsWindow()); |
233 ASSERT(vbox_ == NULL); | 234 RTC_DCHECK(vbox_ == NULL); |
234 | 235 |
235 gtk_container_set_border_width(GTK_CONTAINER(window_), 10); | 236 gtk_container_set_border_width(GTK_CONTAINER(window_), 10); |
236 | 237 |
237 if (peer_list_) { | 238 if (peer_list_) { |
238 gtk_widget_destroy(peer_list_); | 239 gtk_widget_destroy(peer_list_); |
239 peer_list_ = NULL; | 240 peer_list_ = NULL; |
240 } | 241 } |
241 | 242 |
242 #if GTK_MAJOR_VERSION == 2 | 243 #if GTK_MAJOR_VERSION == 2 |
243 vbox_ = gtk_vbox_new(FALSE, 5); | 244 vbox_ = gtk_vbox_new(FALSE, 5); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 for (Peers::const_iterator i = peers.begin(); i != peers.end(); ++i) | 316 for (Peers::const_iterator i = peers.begin(); i != peers.end(); ++i) |
316 AddToList(peer_list_, i->second.c_str(), i->first); | 317 AddToList(peer_list_, i->second.c_str(), i->first); |
317 | 318 |
318 if (autocall_ && peers.begin() != peers.end()) | 319 if (autocall_ && peers.begin() != peers.end()) |
319 g_idle_add(SimulateLastRowActivated, peer_list_); | 320 g_idle_add(SimulateLastRowActivated, peer_list_); |
320 } | 321 } |
321 | 322 |
322 void GtkMainWnd::SwitchToStreamingUI() { | 323 void GtkMainWnd::SwitchToStreamingUI() { |
323 LOG(INFO) << __FUNCTION__; | 324 LOG(INFO) << __FUNCTION__; |
324 | 325 |
325 ASSERT(draw_area_ == NULL); | 326 RTC_DCHECK(draw_area_ == NULL); |
326 | 327 |
327 gtk_container_set_border_width(GTK_CONTAINER(window_), 0); | 328 gtk_container_set_border_width(GTK_CONTAINER(window_), 0); |
328 if (peer_list_) { | 329 if (peer_list_) { |
329 gtk_widget_destroy(peer_list_); | 330 gtk_widget_destroy(peer_list_); |
330 peer_list_ = NULL; | 331 peer_list_ = NULL; |
331 } | 332 } |
332 | 333 |
333 draw_area_ = gtk_drawing_area_new(); | 334 draw_area_ = gtk_drawing_area_new(); |
334 gtk_container_add(GTK_CONTAINER(window_), draw_area_); | 335 gtk_container_add(GTK_CONTAINER(window_), draw_area_); |
335 g_signal_connect(G_OBJECT(draw_area_), "draw", G_CALLBACK(&::Draw), this); | 336 g_signal_connect(G_OBJECT(draw_area_), "draw", G_CALLBACK(&::Draw), this); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 break; | 390 break; |
390 | 391 |
391 default: | 392 default: |
392 break; | 393 break; |
393 } | 394 } |
394 } | 395 } |
395 } | 396 } |
396 | 397 |
397 void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, | 398 void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, |
398 GtkTreeViewColumn* column) { | 399 GtkTreeViewColumn* column) { |
399 ASSERT(peer_list_ != NULL); | 400 RTC_DCHECK(peer_list_ != NULL); |
400 GtkTreeIter iter; | 401 GtkTreeIter iter; |
401 GtkTreeModel* model; | 402 GtkTreeModel* model; |
402 GtkTreeSelection* selection = | 403 GtkTreeSelection* selection = |
403 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | 404 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); |
404 if (gtk_tree_selection_get_selected(selection, &model, &iter)) { | 405 if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
405 char* text; | 406 char* text; |
406 int id = -1; | 407 int id = -1; |
407 gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1); | 408 gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1); |
408 if (id != -1) | 409 if (id != -1) |
409 callback_->ConnectToPeer(id); | 410 callback_->ConnectToPeer(id); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 libyuv::I420ToRGBA(buffer->DataY(), buffer->StrideY(), | 534 libyuv::I420ToRGBA(buffer->DataY(), buffer->StrideY(), |
534 buffer->DataU(), buffer->StrideU(), | 535 buffer->DataU(), buffer->StrideU(), |
535 buffer->DataV(), buffer->StrideV(), | 536 buffer->DataV(), buffer->StrideV(), |
536 image_.get(), width_ * 4, | 537 image_.get(), width_ * 4, |
537 buffer->width(), buffer->height()); | 538 buffer->width(), buffer->height()); |
538 | 539 |
539 gdk_threads_leave(); | 540 gdk_threads_leave(); |
540 | 541 |
541 g_idle_add(Redraw, main_wnd_); | 542 g_idle_add(Redraw, main_wnd_); |
542 } | 543 } |
OLD | NEW |