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