henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
jbauch | 70625e5 | 2015-12-09 14:18:14 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_ |
| 12 | #define WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_ |
| 13 | |
| 14 | #include <string> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
Donald E Curtis | a873644 | 2015-08-05 15:48:13 -0700 | [diff] [blame] | 16 | #include "webrtc/examples/peerconnection/client/main_wnd.h" |
| 17 | #include "webrtc/examples/peerconnection/client/peer_connection_client.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
| 19 | // Forward declarations. |
| 20 | typedef struct _GtkWidget GtkWidget; |
| 21 | typedef union _GdkEvent GdkEvent; |
| 22 | typedef struct _GdkEventKey GdkEventKey; |
| 23 | typedef struct _GtkTreeView GtkTreeView; |
| 24 | typedef struct _GtkTreePath GtkTreePath; |
| 25 | typedef struct _GtkTreeViewColumn GtkTreeViewColumn; |
| 26 | |
| 27 | // Implements the main UI of the peer connection client. |
| 28 | // This is functionally equivalent to the MainWnd class in the Windows |
| 29 | // implementation. |
| 30 | class GtkMainWnd : public MainWindow { |
| 31 | public: |
| 32 | GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall); |
| 33 | ~GtkMainWnd(); |
| 34 | |
| 35 | virtual void RegisterObserver(MainWndCallback* callback); |
| 36 | virtual bool IsWindow(); |
| 37 | virtual void SwitchToConnectUI(); |
| 38 | virtual void SwitchToPeerList(const Peers& peers); |
| 39 | virtual void SwitchToStreamingUI(); |
| 40 | virtual void MessageBox(const char* caption, const char* text, |
| 41 | bool is_error); |
| 42 | virtual MainWindow::UI current_ui(); |
| 43 | virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video); |
| 44 | virtual void StopLocalRenderer(); |
| 45 | virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video); |
| 46 | virtual void StopRemoteRenderer(); |
| 47 | |
| 48 | virtual void QueueUIThreadCallback(int msg_id, void* data); |
| 49 | |
| 50 | // Creates and shows the main window with the |Connect UI| enabled. |
| 51 | bool Create(); |
| 52 | |
| 53 | // Destroys the window. When the window is destroyed, it ends the |
| 54 | // main message loop. |
| 55 | bool Destroy(); |
| 56 | |
| 57 | // Callback for when the main window is destroyed. |
| 58 | void OnDestroyed(GtkWidget* widget, GdkEvent* event); |
| 59 | |
| 60 | // Callback for when the user clicks the "Connect" button. |
| 61 | void OnClicked(GtkWidget* widget); |
| 62 | |
| 63 | // Callback for keystrokes. Used to capture Esc and Return. |
| 64 | void OnKeyPress(GtkWidget* widget, GdkEventKey* key); |
| 65 | |
| 66 | // Callback when the user double clicks a peer in order to initiate a |
| 67 | // connection. |
| 68 | void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, |
| 69 | GtkTreeViewColumn* column); |
| 70 | |
| 71 | void OnRedraw(); |
| 72 | |
| 73 | protected: |
nisse | db25d2e | 2016-02-26 01:24:58 -0800 | [diff] [blame] | 74 | class VideoRenderer : public rtc::VideoSinkInterface<cricket::VideoFrame> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | public: |
| 76 | VideoRenderer(GtkMainWnd* main_wnd, |
| 77 | webrtc::VideoTrackInterface* track_to_render); |
| 78 | virtual ~VideoRenderer(); |
| 79 | |
Niels Möller | 8f59762 | 2016-03-23 10:33:07 +0100 | [diff] [blame] | 80 | // VideoSinkInterface implementation |
| 81 | void OnFrame(const cricket::VideoFrame& frame) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 83 | const uint8_t* image() const { return image_.get(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | |
| 85 | int width() const { |
| 86 | return width_; |
| 87 | } |
| 88 | |
| 89 | int height() const { |
| 90 | return height_; |
| 91 | } |
| 92 | |
| 93 | protected: |
Niels Möller | 8f59762 | 2016-03-23 10:33:07 +0100 | [diff] [blame] | 94 | void SetSize(int width, int height); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 95 | rtc::scoped_ptr<uint8_t[]> image_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | int width_; |
| 97 | int height_; |
| 98 | GtkMainWnd* main_wnd_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 99 | rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | protected: |
| 103 | GtkWidget* window_; // Our main window. |
| 104 | GtkWidget* draw_area_; // The drawing surface for rendering video streams. |
| 105 | GtkWidget* vbox_; // Container for the Connect UI. |
| 106 | GtkWidget* server_edit_; |
| 107 | GtkWidget* port_edit_; |
| 108 | GtkWidget* peer_list_; // The list of peers. |
| 109 | MainWndCallback* callback_; |
| 110 | std::string server_; |
| 111 | std::string port_; |
| 112 | bool autoconnect_; |
| 113 | bool autocall_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 114 | rtc::scoped_ptr<VideoRenderer> local_renderer_; |
| 115 | rtc::scoped_ptr<VideoRenderer> remote_renderer_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 116 | rtc::scoped_ptr<uint8_t[]> draw_buffer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | int draw_buffer_size_; |
| 118 | }; |
| 119 | |
jbauch | 70625e5 | 2015-12-09 14:18:14 -0800 | [diff] [blame] | 120 | #endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_ |