Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / examples / peerconnection / client / linux / main_wnd.h
1 /*
2  * libjingle
3  * Copyright 2012, Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *  1. Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *  3. The name of the author may not be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28
29 #ifndef PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_
30 #define PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_
31
32 #include "talk/examples/peerconnection/client/main_wnd.h"
33 #include "talk/examples/peerconnection/client/peer_connection_client.h"
34
35 // Forward declarations.
36 typedef struct _GtkWidget GtkWidget;
37 typedef union _GdkEvent GdkEvent;
38 typedef struct _GdkEventKey GdkEventKey;
39 typedef struct _GtkTreeView GtkTreeView;
40 typedef struct _GtkTreePath GtkTreePath;
41 typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
42
43 // Implements the main UI of the peer connection client.
44 // This is functionally equivalent to the MainWnd class in the Windows
45 // implementation.
46 class GtkMainWnd : public MainWindow {
47  public:
48   GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
49   ~GtkMainWnd();
50
51   virtual void RegisterObserver(MainWndCallback* callback);
52   virtual bool IsWindow();
53   virtual void SwitchToConnectUI();
54   virtual void SwitchToPeerList(const Peers& peers);
55   virtual void SwitchToStreamingUI();
56   virtual void MessageBox(const char* caption, const char* text,
57                           bool is_error);
58   virtual MainWindow::UI current_ui();
59   virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
60   virtual void StopLocalRenderer();
61   virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
62   virtual void StopRemoteRenderer();
63
64   virtual void QueueUIThreadCallback(int msg_id, void* data);
65
66   // Creates and shows the main window with the |Connect UI| enabled.
67   bool Create();
68
69   // Destroys the window.  When the window is destroyed, it ends the
70   // main message loop.
71   bool Destroy();
72
73   // Callback for when the main window is destroyed.
74   void OnDestroyed(GtkWidget* widget, GdkEvent* event);
75
76   // Callback for when the user clicks the "Connect" button.
77   void OnClicked(GtkWidget* widget);
78
79   // Callback for keystrokes.  Used to capture Esc and Return.
80   void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
81
82   // Callback when the user double clicks a peer in order to initiate a
83   // connection.
84   void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path,
85                       GtkTreeViewColumn* column);
86
87   void OnRedraw();
88
89  protected:
90   class VideoRenderer : public webrtc::VideoRendererInterface {
91    public:
92     VideoRenderer(GtkMainWnd* main_wnd,
93                   webrtc::VideoTrackInterface* track_to_render);
94     virtual ~VideoRenderer();
95
96     // VideoRendererInterface implementation
97     virtual void SetSize(int width, int height);
98     virtual void RenderFrame(const cricket::VideoFrame* frame);
99
100     const uint8* image() const {
101       return image_.get();
102     }
103
104     int width() const {
105       return width_;
106     }
107
108     int height() const {
109       return height_;
110     }
111
112    protected:
113     rtc::scoped_ptr<uint8[]> image_;
114     int width_;
115     int height_;
116     GtkMainWnd* main_wnd_;
117     rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
118   };
119
120  protected:
121   GtkWidget* window_;  // Our main window.
122   GtkWidget* draw_area_;  // The drawing surface for rendering video streams.
123   GtkWidget* vbox_;  // Container for the Connect UI.
124   GtkWidget* server_edit_;
125   GtkWidget* port_edit_;
126   GtkWidget* peer_list_;  // The list of peers.
127   MainWndCallback* callback_;
128   std::string server_;
129   std::string port_;
130   bool autoconnect_;
131   bool autocall_;
132   rtc::scoped_ptr<VideoRenderer> local_renderer_;
133   rtc::scoped_ptr<VideoRenderer> remote_renderer_;
134   rtc::scoped_ptr<uint8> draw_buffer_;
135   int draw_buffer_size_;
136 };
137
138 #endif  // PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_