blob: 1a910827689da1373ea8b218df71f1f231139729 [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
Peter Boström0c4e06b2015-10-07 12:23:21 +020082 const uint8_t* image() const { return image_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
84 int width() const {
85 return width_;
86 }
87
88 int height() const {
89 return height_;
90 }
91
92 protected:
Peter Boström0c4e06b2015-10-07 12:23:21 +020093 rtc::scoped_ptr<uint8_t[]> image_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094 int width_;
95 int height_;
96 GtkMainWnd* main_wnd_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000097 rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 };
99
100 protected:
101 GtkWidget* window_; // Our main window.
102 GtkWidget* draw_area_; // The drawing surface for rendering video streams.
103 GtkWidget* vbox_; // Container for the Connect UI.
104 GtkWidget* server_edit_;
105 GtkWidget* port_edit_;
106 GtkWidget* peer_list_; // The list of peers.
107 MainWndCallback* callback_;
108 std::string server_;
109 std::string port_;
110 bool autoconnect_;
111 bool autocall_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000112 rtc::scoped_ptr<VideoRenderer> local_renderer_;
113 rtc::scoped_ptr<VideoRenderer> remote_renderer_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200114 rtc::scoped_ptr<uint8_t[]> draw_buffer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 int draw_buffer_size_;
116};
117
118#endif // PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_