blob: 3c718577d1024bcd039eddeb97e2736041e1c313 [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;
27
28// Implements the main UI of the peer connection client.
29// This is functionally equivalent to the MainWnd class in the Windows
30// implementation.
31class GtkMainWnd : public MainWindow {
32 public:
33 GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
34 ~GtkMainWnd();
35
36 virtual void RegisterObserver(MainWndCallback* callback);
37 virtual bool IsWindow();
38 virtual void SwitchToConnectUI();
39 virtual void SwitchToPeerList(const Peers& peers);
40 virtual void SwitchToStreamingUI();
41 virtual void MessageBox(const char* caption, const char* text,
42 bool is_error);
43 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.
69 void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
70 GtkTreeViewColumn* column);
71
72 void OnRedraw();
73
74 protected:
nissedb25d2e2016-02-26 01:24:58 -080075 class VideoRenderer : public rtc::VideoSinkInterface<cricket::VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 public:
77 VideoRenderer(GtkMainWnd* main_wnd,
78 webrtc::VideoTrackInterface* track_to_render);
79 virtual ~VideoRenderer();
80
Niels Möller8f597622016-03-23 10:33:07 +010081 // VideoSinkInterface implementation
82 void OnFrame(const cricket::VideoFrame& frame) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
Peter Boström0c4e06b2015-10-07 12:23:21 +020084 const uint8_t* image() const { return image_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
86 int width() const {
87 return width_;
88 }
89
90 int height() const {
91 return height_;
92 }
93
94 protected:
Niels Möller8f597622016-03-23 10:33:07 +010095 void SetSize(int width, int height);
kwibergbfefb032016-05-01 14:53:46 -070096 std::unique_ptr<uint8_t[]> image_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097 int width_;
98 int height_;
99 GtkMainWnd* main_wnd_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000100 rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 };
102
103 protected:
104 GtkWidget* window_; // Our main window.
105 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
106 GtkWidget* vbox_; // Container for the Connect UI.
107 GtkWidget* server_edit_;
108 GtkWidget* port_edit_;
109 GtkWidget* peer_list_; // The list of peers.
110 MainWndCallback* callback_;
111 std::string server_;
112 std::string port_;
113 bool autoconnect_;
114 bool autocall_;
kwibergbfefb032016-05-01 14:53:46 -0700115 std::unique_ptr<VideoRenderer> local_renderer_;
116 std::unique_ptr<VideoRenderer> remote_renderer_;
117 std::unique_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 int draw_buffer_size_;
119};
120
jbauch70625e52015-12-09 14:18:14 -0800121#endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_