• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2012 The WebRTC Project Authors. All rights reserved.
3  *
4  *  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.
9  */
10 
11 #ifndef EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
12 #define EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
13 
14 #include <stdint.h>
15 
16 #include <memory>
17 #include <string>
18 
19 #include "api/media_stream_interface.h"
20 #include "api/scoped_refptr.h"
21 #include "api/video/video_frame.h"
22 #include "api/video/video_sink_interface.h"
23 #include "examples/peerconnection/client/main_wnd.h"
24 #include "examples/peerconnection/client/peer_connection_client.h"
25 
26 // Forward declarations.
27 typedef struct _GtkWidget GtkWidget;
28 typedef union _GdkEvent GdkEvent;
29 typedef struct _GdkEventKey GdkEventKey;
30 typedef struct _GtkTreeView GtkTreeView;
31 typedef struct _GtkTreePath GtkTreePath;
32 typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
33 typedef struct _cairo cairo_t;
34 
35 // Implements the main UI of the peer connection client.
36 // This is functionally equivalent to the MainWnd class in the Windows
37 // implementation.
38 class 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();
48   virtual void MessageBox(const char* caption, const char* text, bool is_error);
49   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.
75   void OnRowActivated(GtkTreeView* tree_view,
76                       GtkTreePath* path,
77                       GtkTreeViewColumn* column);
78 
79   void OnRedraw();
80 
81   void Draw(GtkWidget* widget, cairo_t* cr);
82 
83  protected:
84   class VideoRenderer : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
85    public:
86     VideoRenderer(GtkMainWnd* main_wnd,
87                   webrtc::VideoTrackInterface* track_to_render);
88     virtual ~VideoRenderer();
89 
90     // VideoSinkInterface implementation
91     void OnFrame(const webrtc::VideoFrame& frame) override;
92 
image()93     const uint8_t* image() const { return image_.get(); }
94 
width()95     int width() const { return width_; }
96 
height()97     int height() const { return height_; }
98 
99    protected:
100     void SetSize(int width, int height);
101     std::unique_ptr<uint8_t[]> image_;
102     int width_;
103     int height_;
104     GtkMainWnd* main_wnd_;
105     rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
106   };
107 
108  protected:
109   GtkWidget* window_;     // Our main window.
110   GtkWidget* draw_area_;  // The drawing surface for rendering video streams.
111   GtkWidget* vbox_;       // Container for the Connect UI.
112   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_;
120   std::unique_ptr<VideoRenderer> local_renderer_;
121   std::unique_ptr<VideoRenderer> remote_renderer_;
122   int width_;
123   int height_;
124   std::unique_ptr<uint8_t[]> draw_buffer_;
125   int draw_buffer_size_;
126 };
127 
128 #endif  // EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
129