blob: cfb237645fa342e25a0684a0aa44c8a56ad3387b [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
henrike@webrtc.org28e20752013-07-10 00:45:36 +000011#ifndef PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_
12#define PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_
13
Donald E Curtisa8736442015-08-05 15:48:13 -070014#include "webrtc/examples/peerconnection/client/main_wnd.h"
15#include "webrtc/examples/peerconnection/client/peer_connection_client.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
17// Forward declarations.
18typedef struct _GtkWidget GtkWidget;
19typedef union _GdkEvent GdkEvent;
20typedef struct _GdkEventKey GdkEventKey;
21typedef struct _GtkTreeView GtkTreeView;
22typedef struct _GtkTreePath GtkTreePath;
23typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
24
25// Implements the main UI of the peer connection client.
26// This is functionally equivalent to the MainWnd class in the Windows
27// implementation.
28class GtkMainWnd : public MainWindow {
29 public:
30 GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
31 ~GtkMainWnd();
32
33 virtual void RegisterObserver(MainWndCallback* callback);
34 virtual bool IsWindow();
35 virtual void SwitchToConnectUI();
36 virtual void SwitchToPeerList(const Peers& peers);
37 virtual void SwitchToStreamingUI();
38 virtual void MessageBox(const char* caption, const char* text,
39 bool is_error);
40 virtual MainWindow::UI current_ui();
41 virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
42 virtual void StopLocalRenderer();
43 virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
44 virtual void StopRemoteRenderer();
45
46 virtual void QueueUIThreadCallback(int msg_id, void* data);
47
48 // Creates and shows the main window with the |Connect UI| enabled.
49 bool Create();
50
51 // Destroys the window. When the window is destroyed, it ends the
52 // main message loop.
53 bool Destroy();
54
55 // Callback for when the main window is destroyed.
56 void OnDestroyed(GtkWidget* widget, GdkEvent* event);
57
58 // Callback for when the user clicks the "Connect" button.
59 void OnClicked(GtkWidget* widget);
60
61 // Callback for keystrokes. Used to capture Esc and Return.
62 void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
63
64 // Callback when the user double clicks a peer in order to initiate a
65 // connection.
66 void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
67 GtkTreeViewColumn* column);
68
69 void OnRedraw();
70
71 protected:
72 class VideoRenderer : public webrtc::VideoRendererInterface {
73 public:
74 VideoRenderer(GtkMainWnd* main_wnd,
75 webrtc::VideoTrackInterface* track_to_render);
76 virtual ~VideoRenderer();
77
78 // VideoRendererInterface implementation
79 virtual void SetSize(int width, int height);
80 virtual void RenderFrame(const cricket::VideoFrame* frame);
81
82 const uint8* image() const {
83 return image_.get();
84 }
85
86 int width() const {
87 return width_;
88 }
89
90 int height() const {
91 return height_;
92 }
93
94 protected:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000095 rtc::scoped_ptr<uint8[]> 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_;
116 rtc::scoped_ptr<uint8> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 int draw_buffer_size_;
118};
119
120#endif // PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_