blob: b94d0347413fdab2a6ac77fc12d8e14ac5c91548 [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stdint.h>
kwibergbfefb032016-05-01 14:53:46 -070015#include <memory>
jbauch70625e52015-12-09 14:18:14 -080016#include <string>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000017
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "api/mediastreaminterface.h"
19#include "api/video/video_frame.h"
20#include "api/video/video_sink_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "examples/peerconnection/client/main_wnd.h"
22#include "examples/peerconnection/client/peer_connection_client.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "rtc_base/scoped_ref_ptr.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
25// Forward declarations.
26typedef struct _GtkWidget GtkWidget;
27typedef union _GdkEvent GdkEvent;
28typedef struct _GdkEventKey GdkEventKey;
29typedef struct _GtkTreeView GtkTreeView;
30typedef struct _GtkTreePath GtkTreePath;
31typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
thomasandersonef16e992016-12-13 02:57:43 -080032typedef struct _cairo cairo_t;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34// Implements the main UI of the peer connection client.
35// This is functionally equivalent to the MainWnd class in the Windows
36// implementation.
37class GtkMainWnd : public MainWindow {
38 public:
39 GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
40 ~GtkMainWnd();
41
42 virtual void RegisterObserver(MainWndCallback* callback);
43 virtual bool IsWindow();
44 virtual void SwitchToConnectUI();
45 virtual void SwitchToPeerList(const Peers& peers);
46 virtual void SwitchToStreamingUI();
Yves Gerey665174f2018-06-19 15:03:05 +020047 virtual void MessageBox(const char* caption, const char* text, bool is_error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048 virtual MainWindow::UI current_ui();
49 virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
50 virtual void StopLocalRenderer();
51 virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
52 virtual void StopRemoteRenderer();
53
54 virtual void QueueUIThreadCallback(int msg_id, void* data);
55
56 // Creates and shows the main window with the |Connect UI| enabled.
57 bool Create();
58
59 // Destroys the window. When the window is destroyed, it ends the
60 // main message loop.
61 bool Destroy();
62
63 // Callback for when the main window is destroyed.
64 void OnDestroyed(GtkWidget* widget, GdkEvent* event);
65
66 // Callback for when the user clicks the "Connect" button.
67 void OnClicked(GtkWidget* widget);
68
69 // Callback for keystrokes. Used to capture Esc and Return.
70 void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
71
72 // Callback when the user double clicks a peer in order to initiate a
73 // connection.
Yves Gerey665174f2018-06-19 15:03:05 +020074 void OnRowActivated(GtkTreeView* tree_view,
75 GtkTreePath* path,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 GtkTreeViewColumn* column);
77
78 void OnRedraw();
79
thomasandersonef16e992016-12-13 02:57:43 -080080 void Draw(GtkWidget* widget, cairo_t* cr);
81
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 protected:
nisseacd935b2016-11-11 03:55:13 -080083 class VideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 public:
85 VideoRenderer(GtkMainWnd* main_wnd,
86 webrtc::VideoTrackInterface* track_to_render);
87 virtual ~VideoRenderer();
88
Niels Möller8f597622016-03-23 10:33:07 +010089 // VideoSinkInterface implementation
nisseacd935b2016-11-11 03:55:13 -080090 void OnFrame(const webrtc::VideoFrame& frame) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
Peter Boström0c4e06b2015-10-07 12:23:21 +020092 const uint8_t* image() const { return image_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093
Yves Gerey665174f2018-06-19 15:03:05 +020094 int width() const { return width_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
Yves Gerey665174f2018-06-19 15:03:05 +020096 int height() const { return height_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097
98 protected:
Niels Möller8f597622016-03-23 10:33:07 +010099 void SetSize(int width, int height);
kwibergbfefb032016-05-01 14:53:46 -0700100 std::unique_ptr<uint8_t[]> image_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 int width_;
102 int height_;
103 GtkMainWnd* main_wnd_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000104 rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 };
106
107 protected:
Yves Gerey665174f2018-06-19 15:03:05 +0200108 GtkWidget* window_; // Our main window.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
Yves Gerey665174f2018-06-19 15:03:05 +0200110 GtkWidget* vbox_; // Container for the Connect UI.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 GtkWidget* server_edit_;
112 GtkWidget* port_edit_;
113 GtkWidget* peer_list_; // The list of peers.
114 MainWndCallback* callback_;
115 std::string server_;
116 std::string port_;
117 bool autoconnect_;
118 bool autocall_;
kwibergbfefb032016-05-01 14:53:46 -0700119 std::unique_ptr<VideoRenderer> local_renderer_;
120 std::unique_ptr<VideoRenderer> remote_renderer_;
thomasandersonef16e992016-12-13 02:57:43 -0800121 int width_;
122 int height_;
kwibergbfefb032016-05-01 14:53:46 -0700123 std::unique_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 int draw_buffer_size_;
125};
126
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200127#endif // EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_