blob: a7eb25e9b1ea7ffa18ba1aaf6e1d6b308087e64a [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
14#include <string>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
Donald E Curtisa8736442015-08-05 15:48:13 -070016#include "webrtc/examples/peerconnection/client/main_wnd.h"
17#include "webrtc/examples/peerconnection/client/peer_connection_client.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
19// Forward declarations.
20typedef struct _GtkWidget GtkWidget;
21typedef union _GdkEvent GdkEvent;
22typedef struct _GdkEventKey GdkEventKey;
23typedef struct _GtkTreeView GtkTreeView;
24typedef struct _GtkTreePath GtkTreePath;
25typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
26
27// Implements the main UI of the peer connection client.
28// This is functionally equivalent to the MainWnd class in the Windows
29// implementation.
30class GtkMainWnd : public MainWindow {
31 public:
32 GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
33 ~GtkMainWnd();
34
35 virtual void RegisterObserver(MainWndCallback* callback);
36 virtual bool IsWindow();
37 virtual void SwitchToConnectUI();
38 virtual void SwitchToPeerList(const Peers& peers);
39 virtual void SwitchToStreamingUI();
40 virtual void MessageBox(const char* caption, const char* text,
41 bool is_error);
42 virtual MainWindow::UI current_ui();
43 virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
44 virtual void StopLocalRenderer();
45 virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
46 virtual void StopRemoteRenderer();
47
48 virtual void QueueUIThreadCallback(int msg_id, void* data);
49
50 // Creates and shows the main window with the |Connect UI| enabled.
51 bool Create();
52
53 // Destroys the window. When the window is destroyed, it ends the
54 // main message loop.
55 bool Destroy();
56
57 // Callback for when the main window is destroyed.
58 void OnDestroyed(GtkWidget* widget, GdkEvent* event);
59
60 // Callback for when the user clicks the "Connect" button.
61 void OnClicked(GtkWidget* widget);
62
63 // Callback for keystrokes. Used to capture Esc and Return.
64 void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
65
66 // Callback when the user double clicks a peer in order to initiate a
67 // connection.
68 void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
69 GtkTreeViewColumn* column);
70
71 void OnRedraw();
72
73 protected:
nissedb25d2e2016-02-26 01:24:58 -080074 class VideoRenderer : public rtc::VideoSinkInterface<cricket::VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 public:
76 VideoRenderer(GtkMainWnd* main_wnd,
77 webrtc::VideoTrackInterface* track_to_render);
78 virtual ~VideoRenderer();
79
80 // VideoRendererInterface implementation
81 virtual void SetSize(int width, int height);
nissedb25d2e2016-02-26 01:24:58 -080082 virtual void OnFrame(const cricket::VideoFrame& frame);
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:
Peter Boström0c4e06b2015-10-07 12:23:21 +020095 rtc::scoped_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:
103 GtkWidget* window_; // Our main window.
104 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
105 GtkWidget* vbox_; // Container for the Connect UI.
106 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_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000114 rtc::scoped_ptr<VideoRenderer> local_renderer_;
115 rtc::scoped_ptr<VideoRenderer> remote_renderer_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200116 rtc::scoped_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 int draw_buffer_size_;
118};
119
jbauch70625e52015-12-09 14:18:14 -0800120#endif // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_