blob: a2edb7475770a14694ddd6549429a378191cc321 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
12#define EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
jbauch70625e52015-12-09 14:18:14 -080013
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "examples/peerconnection/client/main_wnd.h"
18#include "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();
Yves Gerey665174f2018-06-19 15:03:05 +020042 virtual void MessageBox(const char* caption, const char* text, bool is_error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043 virtual MainWindow::UI current_ui();
44 virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
45 virtual void StopLocalRenderer();
46 virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
47 virtual void StopRemoteRenderer();
48
49 virtual void QueueUIThreadCallback(int msg_id, void* data);
50
51 // Creates and shows the main window with the |Connect UI| enabled.
52 bool Create();
53
54 // Destroys the window. When the window is destroyed, it ends the
55 // main message loop.
56 bool Destroy();
57
58 // Callback for when the main window is destroyed.
59 void OnDestroyed(GtkWidget* widget, GdkEvent* event);
60
61 // Callback for when the user clicks the "Connect" button.
62 void OnClicked(GtkWidget* widget);
63
64 // Callback for keystrokes. Used to capture Esc and Return.
65 void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
66
67 // Callback when the user double clicks a peer in order to initiate a
68 // connection.
Yves Gerey665174f2018-06-19 15:03:05 +020069 void OnRowActivated(GtkTreeView* tree_view,
70 GtkTreePath* path,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 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
Yves Gerey665174f2018-06-19 15:03:05 +020089 int width() const { return width_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
Yves Gerey665174f2018-06-19 15:03:05 +020091 int height() const { return height_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
93 protected:
Niels Möller8f597622016-03-23 10:33:07 +010094 void SetSize(int width, int height);
kwibergbfefb032016-05-01 14:53:46 -070095 std::unique_ptr<uint8_t[]> image_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096 int width_;
97 int height_;
98 GtkMainWnd* main_wnd_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000099 rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100 };
101
102 protected:
Yves Gerey665174f2018-06-19 15:03:05 +0200103 GtkWidget* window_; // Our main window.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
Yves Gerey665174f2018-06-19 15:03:05 +0200105 GtkWidget* vbox_; // Container for the Connect UI.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 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_;
kwibergbfefb032016-05-01 14:53:46 -0700114 std::unique_ptr<VideoRenderer> local_renderer_;
115 std::unique_ptr<VideoRenderer> remote_renderer_;
thomasandersonef16e992016-12-13 02:57:43 -0800116 int width_;
117 int height_;
kwibergbfefb032016-05-01 14:53:46 -0700118 std::unique_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 int draw_buffer_size_;
120};
121
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200122#endif // EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_