• 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 WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
12 #define WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
13 
14 #include <string>
15 
16 #include "webrtc/examples/peerconnection/client/main_wnd.h"
17 #include "webrtc/examples/peerconnection/client/peer_connection_client.h"
18 
19 // Forward declarations.
20 typedef struct _GtkWidget GtkWidget;
21 typedef union _GdkEvent GdkEvent;
22 typedef struct _GdkEventKey GdkEventKey;
23 typedef struct _GtkTreeView GtkTreeView;
24 typedef struct _GtkTreePath GtkTreePath;
25 typedef 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.
30 class 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:
74   class VideoRenderer : public webrtc::VideoRendererInterface {
75    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);
82     virtual void RenderFrame(const cricket::VideoFrame* frame);
83 
image()84     const uint8_t* image() const { return image_.get(); }
85 
width()86     int width() const {
87       return width_;
88     }
89 
height()90     int height() const {
91       return height_;
92     }
93 
94    protected:
95     rtc::scoped_ptr<uint8_t[]> image_;
96     int width_;
97     int height_;
98     GtkMainWnd* main_wnd_;
99     rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
100   };
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_;
114   rtc::scoped_ptr<VideoRenderer> local_renderer_;
115   rtc::scoped_ptr<VideoRenderer> remote_renderer_;
116   rtc::scoped_ptr<uint8_t[]> draw_buffer_;
117   int draw_buffer_size_;
118 };
119 
120 #endif  // WEBRTC_EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_
121