blob: 68ed8bf99caf1bd489166b1049b916d2fe3fa13e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
Donald E Curtisa8736442015-08-05 15:48:13 -07002 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
Donald E Curtisa8736442015-08-05 15:48:13 -07004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch70625e52015-12-09 14:18:14 -080011#ifndef WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
12#define WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
13
kwibergbfefb032016-05-01 14:53:46 -070014#include <memory>
jbauch70625e52015-12-09 14:18:14 -080015#include <string>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
Donald E Curtisa8736442015-08-05 15:48:13 -070017#include "webrtc/examples/peerconnection/client/main_wnd.h"
18#include "webrtc/examples/peerconnection/client/peer_connection_client.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
20// Forward declarations.
21typedef struct _GtkWidget GtkWidget;
22typedef union _GdkEvent GdkEvent;
23typedef struct _GdkEventKey GdkEventKey;
24typedef struct _GtkTreeView GtkTreeView;
25typedef struct _GtkTreePath GtkTreePath;
26typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
thomasandersonef16e992016-12-13 02:57:43 -080027typedef struct _cairo cairo_t;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
29// Implements the main UI of the peer connection client.
30// This is functionally equivalent to the MainWnd class in the Windows
31// implementation.
32class GtkMainWnd : public MainWindow {
33 public:
34 GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
35 ~GtkMainWnd();
36
37 virtual void RegisterObserver(MainWndCallback* callback);
38 virtual bool IsWindow();
39 virtual void SwitchToConnectUI();
40 virtual void SwitchToPeerList(const Peers& peers);
41 virtual void SwitchToStreamingUI();
42 virtual void MessageBox(const char* caption, const char* text,
43 bool is_error);
44 virtual MainWindow::UI current_ui();
45 virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
46 virtual void StopLocalRenderer();
47 virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
48 virtual void StopRemoteRenderer();
49
50 virtual void QueueUIThreadCallback(int msg_id, void* data);
51
52 // Creates and shows the main window with the |Connect UI| enabled.
53 bool Create();
54
55 // Destroys the window. When the window is destroyed, it ends the
56 // main message loop.
57 bool Destroy();
58
59 // Callback for when the main window is destroyed.
60 void OnDestroyed(GtkWidget* widget, GdkEvent* event);
61
62 // Callback for when the user clicks the "Connect" button.
63 void OnClicked(GtkWidget* widget);
64
65 // Callback for keystrokes. Used to capture Esc and Return.
66 void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
67
68 // Callback when the user double clicks a peer in order to initiate a
69 // connection.
70 void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
71 GtkTreeViewColumn* column);
72
73 void OnRedraw();
74
thomasandersonef16e992016-12-13 02:57:43 -080075 void Draw(GtkWidget* widget, cairo_t* cr);
76
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 protected:
nisseacd935b2016-11-11 03:55:13 -080078 class VideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 public:
80 VideoRenderer(GtkMainWnd* main_wnd,
81 webrtc::VideoTrackInterface* track_to_render);
82 virtual ~VideoRenderer();
83
Niels Möller8f597622016-03-23 10:33:07 +010084 // VideoSinkInterface implementation
nisseacd935b2016-11-11 03:55:13 -080085 void OnFrame(const webrtc::VideoFrame& frame) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
Peter Boström0c4e06b2015-10-07 12:23:21 +020087 const uint8_t* image() const { return image_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
89 int width() const {
90 return width_;
91 }
92
93 int height() const {
94 return height_;
95 }
96
97 protected:
Niels Möller8f597622016-03-23 10:33:07 +010098 void SetSize(int width, int height);
kwibergbfefb032016-05-01 14:53:46 -070099 std::unique_ptr<uint8_t[]> image_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 int width_;
101 int height_;
102 GtkMainWnd* main_wnd_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000103 rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 };
105
106 protected:
107 GtkWidget* window_; // Our main window.
108 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
109 GtkWidget* vbox_; // Container for the Connect UI.
110 GtkWidget* server_edit_;
111 GtkWidget* port_edit_;
112 GtkWidget* peer_list_; // The list of peers.
113 MainWndCallback* callback_;
114 std::string server_;
115 std::string port_;
116 bool autoconnect_;
117 bool autocall_;
kwibergbfefb032016-05-01 14:53:46 -0700118 std::unique_ptr<VideoRenderer> local_renderer_;
119 std::unique_ptr<VideoRenderer> remote_renderer_;
thomasandersonef16e992016-12-13 02:57:43 -0800120 int width_;
121 int height_;
kwibergbfefb032016-05-01 14:53:46 -0700122 std::unique_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 int draw_buffer_size_;
124};
125
jbauch70625e52015-12-09 14:18:14 -0800126#endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_