| 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 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) { | 62 void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) { |
| 63 LRESULT index = ::SendMessageA(listbox, LB_ADDSTRING, 0, | 63 LRESULT index = ::SendMessageA(listbox, LB_ADDSTRING, 0, |
| 64 reinterpret_cast<LPARAM>(str.c_str())); | 64 reinterpret_cast<LPARAM>(str.c_str())); |
| 65 ::SendMessageA(listbox, LB_SETITEMDATA, index, item_data); | 65 ::SendMessageA(listbox, LB_SETITEMDATA, index, item_data); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 MainWnd::MainWnd(const char* server, int port, bool auto_connect, | 70 MainWnd::MainWnd(const char* server, |
| 71 int port, |
| 72 bool auto_connect, |
| 71 bool auto_call) | 73 bool auto_call) |
| 72 : ui_(CONNECT_TO_SERVER), wnd_(NULL), edit1_(NULL), edit2_(NULL), | 74 : ui_(CONNECT_TO_SERVER), |
| 73 label1_(NULL), label2_(NULL), button_(NULL), listbox_(NULL), | 75 wnd_(nullptr), |
| 74 destroyed_(false), callback_(NULL), nested_msg_(NULL), | 76 edit1_(nullptr), |
| 75 server_(server), auto_connect_(auto_connect), auto_call_(auto_call) { | 77 edit2_(nullptr), |
| 78 label1_(nullptr), |
| 79 label2_(nullptr), |
| 80 button_(nullptr), |
| 81 listbox_(nullptr), |
| 82 destroyed_(false), |
| 83 callback_(nullptr), |
| 84 nested_msg_(nullptr), |
| 85 server_(server), |
| 86 auto_connect_(auto_connect), |
| 87 auto_call_(auto_call) { |
| 76 char buffer[10] = {0}; | 88 char buffer[10] = {0}; |
| 77 sprintfn(buffer, sizeof(buffer), "%i", port); | 89 sprintfn(buffer, sizeof(buffer), "%i", port); |
| 78 port_ = buffer; | 90 port_ = buffer; |
| 79 } | 91 } |
| 80 | 92 |
| 81 MainWnd::~MainWnd() { | 93 MainWnd::~MainWnd() { |
| 82 RTC_DCHECK(!IsWindow()); | 94 RTC_DCHECK(!IsWindow()); |
| 83 } | 95 } |
| 84 | 96 |
| 85 bool MainWnd::Create() { | 97 bool MainWnd::Create() { |
| 86 RTC_DCHECK(wnd_ == NULL); | 98 RTC_DCHECK(wnd_ == nullptr); |
| 87 if (!RegisterWindowClass()) | 99 if (!RegisterWindowClass()) |
| 88 return false; | 100 return false; |
| 89 | 101 |
| 90 ui_thread_id_ = ::GetCurrentThreadId(); | 102 ui_thread_id_ = ::GetCurrentThreadId(); |
| 91 wnd_ = ::CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, kClassName, L"WebRTC", | 103 wnd_ = ::CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, kClassName, L"WebRTC", |
| 92 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, | 104 WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, |
| 93 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | 105 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 94 NULL, NULL, GetModuleHandle(NULL), this); | 106 CW_USEDEFAULT, nullptr, nullptr, |
| 107 GetModuleHandle(nullptr), this); |
| 95 | 108 |
| 96 ::SendMessage(wnd_, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()), | 109 ::SendMessage(wnd_, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()), |
| 97 TRUE); | 110 TRUE); |
| 98 | 111 |
| 99 CreateChildWindows(); | 112 CreateChildWindows(); |
| 100 SwitchToConnectUI(); | 113 SwitchToConnectUI(); |
| 101 | 114 |
| 102 return wnd_ != NULL; | 115 return wnd_ != nullptr; |
| 103 } | 116 } |
| 104 | 117 |
| 105 bool MainWnd::Destroy() { | 118 bool MainWnd::Destroy() { |
| 106 BOOL ret = FALSE; | 119 BOOL ret = FALSE; |
| 107 if (IsWindow()) { | 120 if (IsWindow()) { |
| 108 ret = ::DestroyWindow(wnd_); | 121 ret = ::DestroyWindow(wnd_); |
| 109 } | 122 } |
| 110 | 123 |
| 111 return ret != FALSE; | 124 return ret != FALSE; |
| 112 } | 125 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 130 ret = true; | 143 ret = true; |
| 131 } else if (msg->wParam == VK_ESCAPE) { | 144 } else if (msg->wParam == VK_ESCAPE) { |
| 132 if (callback_) { | 145 if (callback_) { |
| 133 if (ui_ == STREAMING) { | 146 if (ui_ == STREAMING) { |
| 134 callback_->DisconnectFromCurrentPeer(); | 147 callback_->DisconnectFromCurrentPeer(); |
| 135 } else { | 148 } else { |
| 136 callback_->DisconnectFromServer(); | 149 callback_->DisconnectFromServer(); |
| 137 } | 150 } |
| 138 } | 151 } |
| 139 } | 152 } |
| 140 } else if (msg->hwnd == NULL && msg->message == UI_THREAD_CALLBACK) { | 153 } else if (msg->hwnd == nullptr && msg->message == UI_THREAD_CALLBACK) { |
| 141 callback_->UIThreadCallback(static_cast<int>(msg->wParam), | 154 callback_->UIThreadCallback(static_cast<int>(msg->wParam), |
| 142 reinterpret_cast<void*>(msg->lParam)); | 155 reinterpret_cast<void*>(msg->lParam)); |
| 143 ret = true; | 156 ret = true; |
| 144 } | 157 } |
| 145 return ret; | 158 return ret; |
| 146 } | 159 } |
| 147 | 160 |
| 148 void MainWnd::SwitchToConnectUI() { | 161 void MainWnd::SwitchToConnectUI() { |
| 149 RTC_DCHECK(IsWindow()); | 162 RTC_DCHECK(IsWindow()); |
| 150 LayoutPeerListUI(false); | 163 LayoutPeerListUI(false); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 VideoRenderer* remote_renderer = remote_renderer_.get(); | 244 VideoRenderer* remote_renderer = remote_renderer_.get(); |
| 232 if (ui_ == STREAMING && remote_renderer && local_renderer) { | 245 if (ui_ == STREAMING && remote_renderer && local_renderer) { |
| 233 AutoLock<VideoRenderer> local_lock(local_renderer); | 246 AutoLock<VideoRenderer> local_lock(local_renderer); |
| 234 AutoLock<VideoRenderer> remote_lock(remote_renderer); | 247 AutoLock<VideoRenderer> remote_lock(remote_renderer); |
| 235 | 248 |
| 236 const BITMAPINFO& bmi = remote_renderer->bmi(); | 249 const BITMAPINFO& bmi = remote_renderer->bmi(); |
| 237 int height = abs(bmi.bmiHeader.biHeight); | 250 int height = abs(bmi.bmiHeader.biHeight); |
| 238 int width = bmi.bmiHeader.biWidth; | 251 int width = bmi.bmiHeader.biWidth; |
| 239 | 252 |
| 240 const uint8_t* image = remote_renderer->image(); | 253 const uint8_t* image = remote_renderer->image(); |
| 241 if (image != NULL) { | 254 if (image != nullptr) { |
| 242 HDC dc_mem = ::CreateCompatibleDC(ps.hdc); | 255 HDC dc_mem = ::CreateCompatibleDC(ps.hdc); |
| 243 ::SetStretchBltMode(dc_mem, HALFTONE); | 256 ::SetStretchBltMode(dc_mem, HALFTONE); |
| 244 | 257 |
| 245 // Set the map mode so that the ratio will be maintained for us. | 258 // Set the map mode so that the ratio will be maintained for us. |
| 246 HDC all_dc[] = { ps.hdc, dc_mem }; | 259 HDC all_dc[] = { ps.hdc, dc_mem }; |
| 247 for (int i = 0; i < arraysize(all_dc); ++i) { | 260 for (int i = 0; i < arraysize(all_dc); ++i) { |
| 248 SetMapMode(all_dc[i], MM_ISOTROPIC); | 261 SetMapMode(all_dc[i], MM_ISOTROPIC); |
| 249 SetWindowExtEx(all_dc[i], width, height, NULL); | 262 SetWindowExtEx(all_dc[i], width, height, nullptr); |
| 250 SetViewportExtEx(all_dc[i], rc.right, rc.bottom, NULL); | 263 SetViewportExtEx(all_dc[i], rc.right, rc.bottom, nullptr); |
| 251 } | 264 } |
| 252 | 265 |
| 253 HBITMAP bmp_mem = ::CreateCompatibleBitmap(ps.hdc, rc.right, rc.bottom); | 266 HBITMAP bmp_mem = ::CreateCompatibleBitmap(ps.hdc, rc.right, rc.bottom); |
| 254 HGDIOBJ bmp_old = ::SelectObject(dc_mem, bmp_mem); | 267 HGDIOBJ bmp_old = ::SelectObject(dc_mem, bmp_mem); |
| 255 | 268 |
| 256 POINT logical_area = { rc.right, rc.bottom }; | 269 POINT logical_area = { rc.right, rc.bottom }; |
| 257 DPtoLP(ps.hdc, &logical_area, 1); | 270 DPtoLP(ps.hdc, &logical_area, 1); |
| 258 | 271 |
| 259 HBRUSH brush = ::CreateSolidBrush(RGB(0, 0, 0)); | 272 HBRUSH brush = ::CreateSolidBrush(RGB(0, 0, 0)); |
| 260 RECT logical_rect = {0, 0, logical_area.x, logical_area.y }; | 273 RECT logical_rect = {0, 0, logical_area.x, logical_area.y }; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 void* prev_nested_msg = me->nested_msg_; | 419 void* prev_nested_msg = me->nested_msg_; |
| 407 me->nested_msg_ = &msg; | 420 me->nested_msg_ = &msg; |
| 408 | 421 |
| 409 bool handled = me->OnMessage(msg, wp, lp, &result); | 422 bool handled = me->OnMessage(msg, wp, lp, &result); |
| 410 if (WM_NCDESTROY == msg) { | 423 if (WM_NCDESTROY == msg) { |
| 411 me->destroyed_ = true; | 424 me->destroyed_ = true; |
| 412 } else if (!handled) { | 425 } else if (!handled) { |
| 413 result = ::DefWindowProc(hwnd, msg, wp, lp); | 426 result = ::DefWindowProc(hwnd, msg, wp, lp); |
| 414 } | 427 } |
| 415 | 428 |
| 416 if (me->destroyed_ && prev_nested_msg == NULL) { | 429 if (me->destroyed_ && prev_nested_msg == nullptr) { |
| 417 me->OnDestroyed(); | 430 me->OnDestroyed(); |
| 418 me->wnd_ = NULL; | 431 me->wnd_ = nullptr; |
| 419 me->destroyed_ = false; | 432 me->destroyed_ = false; |
| 420 } | 433 } |
| 421 | 434 |
| 422 me->nested_msg_ = prev_nested_msg; | 435 me->nested_msg_ = prev_nested_msg; |
| 423 } else { | 436 } else { |
| 424 result = ::DefWindowProc(hwnd, msg, wp, lp); | 437 result = ::DefWindowProc(hwnd, msg, wp, lp); |
| 425 } | 438 } |
| 426 | 439 |
| 427 return result; | 440 return result; |
| 428 } | 441 } |
| 429 | 442 |
| 430 // static | 443 // static |
| 431 bool MainWnd::RegisterWindowClass() { | 444 bool MainWnd::RegisterWindowClass() { |
| 432 if (wnd_class_) | 445 if (wnd_class_) |
| 433 return true; | 446 return true; |
| 434 | 447 |
| 435 WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; | 448 WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; |
| 436 wcex.style = CS_DBLCLKS; | 449 wcex.style = CS_DBLCLKS; |
| 437 wcex.hInstance = GetModuleHandle(NULL); | 450 wcex.hInstance = GetModuleHandle(nullptr); |
| 438 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1); | 451 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1); |
| 439 wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW); | 452 wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW); |
| 440 wcex.lpfnWndProc = &WndProc; | 453 wcex.lpfnWndProc = &WndProc; |
| 441 wcex.lpszClassName = kClassName; | 454 wcex.lpszClassName = kClassName; |
| 442 wnd_class_ = ::RegisterClassEx(&wcex); | 455 wnd_class_ = ::RegisterClassEx(&wcex); |
| 443 RTC_DCHECK(wnd_class_ != 0); | 456 RTC_DCHECK(wnd_class_ != 0); |
| 444 return wnd_class_ != 0; | 457 return wnd_class_ != 0; |
| 445 } | 458 } |
| 446 | 459 |
| 447 void MainWnd::CreateChildWindow(HWND* wnd, MainWnd::ChildWindowID id, | 460 void MainWnd::CreateChildWindow(HWND* wnd, MainWnd::ChildWindowID id, |
| 448 const wchar_t* class_name, DWORD control_style, | 461 const wchar_t* class_name, DWORD control_style, |
| 449 DWORD ex_style) { | 462 DWORD ex_style) { |
| 450 if (::IsWindow(*wnd)) | 463 if (::IsWindow(*wnd)) |
| 451 return; | 464 return; |
| 452 | 465 |
| 453 // Child windows are invisible at first, and shown after being resized. | 466 // Child windows are invisible at first, and shown after being resized. |
| 454 DWORD style = WS_CHILD | control_style; | 467 DWORD style = WS_CHILD | control_style; |
| 455 *wnd = ::CreateWindowEx(ex_style, class_name, L"", style, | 468 *wnd = ::CreateWindowEx(ex_style, class_name, L"", style, 100, 100, 100, 100, |
| 456 100, 100, 100, 100, wnd_, | 469 wnd_, reinterpret_cast<HMENU>(id), |
| 457 reinterpret_cast<HMENU>(id), | 470 GetModuleHandle(nullptr), nullptr); |
| 458 GetModuleHandle(NULL), NULL); | |
| 459 RTC_DCHECK(::IsWindow(*wnd) != FALSE); | 471 RTC_DCHECK(::IsWindow(*wnd) != FALSE); |
| 460 ::SendMessage(*wnd, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()), | 472 ::SendMessage(*wnd, WM_SETFONT, reinterpret_cast<WPARAM>(GetDefaultFont()), |
| 461 TRUE); | 473 TRUE); |
| 462 } | 474 } |
| 463 | 475 |
| 464 void MainWnd::CreateChildWindows() { | 476 void MainWnd::CreateChildWindows() { |
| 465 // Create the child windows in tab order. | 477 // Create the child windows in tab order. |
| 466 CreateChildWindow(&label1_, LABEL1_ID, L"Static", ES_CENTER | ES_READONLY, 0); | 478 CreateChildWindow(&label1_, LABEL1_ID, L"Static", ES_CENTER | ES_READONLY, 0); |
| 467 CreateChildWindow(&edit1_, EDIT_ID, L"Edit", | 479 CreateChildWindow(&edit1_, EDIT_ID, L"Edit", |
| 468 ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, WS_EX_CLIENTEDGE); | 480 ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, WS_EX_CLIENTEDGE); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 } | 537 } |
| 526 | 538 |
| 527 void MainWnd::LayoutPeerListUI(bool show) { | 539 void MainWnd::LayoutPeerListUI(bool show) { |
| 528 if (show) { | 540 if (show) { |
| 529 RECT rc; | 541 RECT rc; |
| 530 ::GetClientRect(wnd_, &rc); | 542 ::GetClientRect(wnd_, &rc); |
| 531 ::MoveWindow(listbox_, 0, 0, rc.right, rc.bottom, TRUE); | 543 ::MoveWindow(listbox_, 0, 0, rc.right, rc.bottom, TRUE); |
| 532 ::ShowWindow(listbox_, SW_SHOWNA); | 544 ::ShowWindow(listbox_, SW_SHOWNA); |
| 533 } else { | 545 } else { |
| 534 ::ShowWindow(listbox_, SW_HIDE); | 546 ::ShowWindow(listbox_, SW_HIDE); |
| 535 InvalidateRect(wnd_, NULL, TRUE); | 547 InvalidateRect(wnd_, nullptr, TRUE); |
| 536 } | 548 } |
| 537 } | 549 } |
| 538 | 550 |
| 539 void MainWnd::HandleTabbing() { | 551 void MainWnd::HandleTabbing() { |
| 540 bool shift = ((::GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0); | 552 bool shift = ((::GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0); |
| 541 UINT next_cmd = shift ? GW_HWNDPREV : GW_HWNDNEXT; | 553 UINT next_cmd = shift ? GW_HWNDPREV : GW_HWNDNEXT; |
| 542 UINT loop_around_cmd = shift ? GW_HWNDLAST : GW_HWNDFIRST; | 554 UINT loop_around_cmd = shift ? GW_HWNDLAST : GW_HWNDFIRST; |
| 543 HWND focus = GetFocus(), next; | 555 HWND focus = GetFocus(), next; |
| 544 do { | 556 do { |
| 545 next = ::GetWindow(focus, next_cmd); | 557 next = ::GetWindow(focus, next_cmd); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 AutoLock<VideoRenderer> lock(this); | 619 AutoLock<VideoRenderer> lock(this); |
| 608 | 620 |
| 609 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( | 621 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
| 610 video_frame.video_frame_buffer()); | 622 video_frame.video_frame_buffer()); |
| 611 if (video_frame.rotation() != webrtc::kVideoRotation_0) { | 623 if (video_frame.rotation() != webrtc::kVideoRotation_0) { |
| 612 buffer = webrtc::I420Buffer::Rotate(*buffer, video_frame.rotation()); | 624 buffer = webrtc::I420Buffer::Rotate(*buffer, video_frame.rotation()); |
| 613 } | 625 } |
| 614 | 626 |
| 615 SetSize(buffer->width(), buffer->height()); | 627 SetSize(buffer->width(), buffer->height()); |
| 616 | 628 |
| 617 RTC_DCHECK(image_.get() != NULL); | 629 RTC_DCHECK(image_.get() != nullptr); |
| 618 libyuv::I420ToARGB(buffer->DataY(), buffer->StrideY(), | 630 libyuv::I420ToARGB(buffer->DataY(), buffer->StrideY(), |
| 619 buffer->DataU(), buffer->StrideU(), | 631 buffer->DataU(), buffer->StrideU(), |
| 620 buffer->DataV(), buffer->StrideV(), | 632 buffer->DataV(), buffer->StrideV(), |
| 621 image_.get(), | 633 image_.get(), |
| 622 bmi_.bmiHeader.biWidth * | 634 bmi_.bmiHeader.biWidth * |
| 623 bmi_.bmiHeader.biBitCount / 8, | 635 bmi_.bmiHeader.biBitCount / 8, |
| 624 buffer->width(), buffer->height()); | 636 buffer->width(), buffer->height()); |
| 625 } | 637 } |
| 626 InvalidateRect(wnd_, NULL, TRUE); | 638 InvalidateRect(wnd_, nullptr, TRUE); |
| 627 } | 639 } |
| OLD | NEW |