blob: 3b31e1be3bd799babb2c9cb36938518c74b1fe77 [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
kwibergbfefb032016-05-01 14:53:46 -070016#include <memory>
jbauch70625e52015-12-09 14:18:14 -080017#include <string>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
Steve Anton10542f22019-01-11 09:11:00 -080019#include "api/media_stream_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010020#include "api/scoped_refptr.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "api/video/video_frame.h"
22#include "api/video/video_sink_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "examples/peerconnection/client/main_wnd.h"
24#include "examples/peerconnection/client/peer_connection_client.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
26// Forward declarations.
27typedef struct _GtkWidget GtkWidget;
28typedef union _GdkEvent GdkEvent;
29typedef struct _GdkEventKey GdkEventKey;
30typedef struct _GtkTreeView GtkTreeView;
31typedef struct _GtkTreePath GtkTreePath;
32typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
thomasandersonef16e992016-12-13 02:57:43 -080033typedef struct _cairo cairo_t;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034
35// Implements the main UI of the peer connection client.
36// This is functionally equivalent to the MainWnd class in the Windows
37// implementation.
38class GtkMainWnd : public MainWindow {
39 public:
40 GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
41 ~GtkMainWnd();
42
43 virtual void RegisterObserver(MainWndCallback* callback);
44 virtual bool IsWindow();
45 virtual void SwitchToConnectUI();
46 virtual void SwitchToPeerList(const Peers& peers);
47 virtual void SwitchToStreamingUI();
Yves Gerey665174f2018-06-19 15:03:05 +020048 virtual void MessageBox(const char* caption, const char* text, bool is_error);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049 virtual MainWindow::UI current_ui();
50 virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
51 virtual void StopLocalRenderer();
52 virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
53 virtual void StopRemoteRenderer();
54
55 virtual void QueueUIThreadCallback(int msg_id, void* data);
56
57 // Creates and shows the main window with the |Connect UI| enabled.
58 bool Create();
59
60 // Destroys the window. When the window is destroyed, it ends the
61 // main message loop.
62 bool Destroy();
63
64 // Callback for when the main window is destroyed.
65 void OnDestroyed(GtkWidget* widget, GdkEvent* event);
66
67 // Callback for when the user clicks the "Connect" button.
68 void OnClicked(GtkWidget* widget);
69
70 // Callback for keystrokes. Used to capture Esc and Return.
71 void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
72
73 // Callback when the user double clicks a peer in order to initiate a
74 // connection.
Yves Gerey665174f2018-06-19 15:03:05 +020075 void OnRowActivated(GtkTreeView* tree_view,
76 GtkTreePath* path,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 GtkTreeViewColumn* column);
78
79 void OnRedraw();
80
thomasandersonef16e992016-12-13 02:57:43 -080081 void Draw(GtkWidget* widget, cairo_t* cr);
82
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 protected:
nisseacd935b2016-11-11 03:55:13 -080084 class VideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 public:
86 VideoRenderer(GtkMainWnd* main_wnd,
87 webrtc::VideoTrackInterface* track_to_render);
88 virtual ~VideoRenderer();
89
Niels Möller8f597622016-03-23 10:33:07 +010090 // VideoSinkInterface implementation
nisseacd935b2016-11-11 03:55:13 -080091 void OnFrame(const webrtc::VideoFrame& frame) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
Peter Boström0c4e06b2015-10-07 12:23:21 +020093 const uint8_t* image() const { return image_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
Yves Gerey665174f2018-06-19 15:03:05 +020095 int width() const { return width_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
Yves Gerey665174f2018-06-19 15:03:05 +020097 int height() const { return height_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098
99 protected:
Niels Möller8f597622016-03-23 10:33:07 +0100100 void SetSize(int width, int height);
kwibergbfefb032016-05-01 14:53:46 -0700101 std::unique_ptr<uint8_t[]> image_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 int width_;
103 int height_;
104 GtkMainWnd* main_wnd_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000105 rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 };
107
108 protected:
Yves Gerey665174f2018-06-19 15:03:05 +0200109 GtkWidget* window_; // Our main window.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
Yves Gerey665174f2018-06-19 15:03:05 +0200111 GtkWidget* vbox_; // Container for the Connect UI.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 GtkWidget* server_edit_;
113 GtkWidget* port_edit_;
114 GtkWidget* peer_list_; // The list of peers.
115 MainWndCallback* callback_;
116 std::string server_;
117 std::string port_;
118 bool autoconnect_;
119 bool autocall_;
kwibergbfefb032016-05-01 14:53:46 -0700120 std::unique_ptr<VideoRenderer> local_renderer_;
121 std::unique_ptr<VideoRenderer> remote_renderer_;
thomasandersonef16e992016-12-13 02:57:43 -0800122 int width_;
123 int height_;
kwibergbfefb032016-05-01 14:53:46 -0700124 std::unique_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 int draw_buffer_size_;
126};
127
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200128#endif // EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_