10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org/* 20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * libjingle 30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Copyright 2012, Google Inc. 40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without 60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * modification, are permitted provided that the following conditions are met: 70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * this list of conditions and the following disclaimer. 100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * this list of conditions and the following disclaimer in the documentation 120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * and/or other materials provided with the distribution. 130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 3. The name of the author may not be used to endorse or promote products 140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * derived from this software without specific prior written permission. 150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * 160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org */ 270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_ 300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_ 310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/examples/peerconnection/client/main_wnd.h" 330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/examples/peerconnection/client/peer_connection_client.h" 340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Forward declarations. 360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef struct _GtkWidget GtkWidget; 370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef union _GdkEvent GdkEvent; 380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef struct _GdkEventKey GdkEventKey; 390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef struct _GtkTreeView GtkTreeView; 400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef struct _GtkTreePath GtkTreePath; 410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgtypedef struct _GtkTreeViewColumn GtkTreeViewColumn; 420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Implements the main UI of the peer connection client. 440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// This is functionally equivalent to the MainWnd class in the Windows 450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// implementation. 460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass GtkMainWnd : public MainWindow { 470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public: 480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall); 490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org ~GtkMainWnd(); 500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void RegisterObserver(MainWndCallback* callback); 520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual bool IsWindow(); 530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void SwitchToConnectUI(); 540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void SwitchToPeerList(const Peers& peers); 550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void SwitchToStreamingUI(); 560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void MessageBox(const char* caption, const char* text, 570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org bool is_error); 580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual MainWindow::UI current_ui(); 590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video); 600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void StopLocalRenderer(); 610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video); 620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void StopRemoteRenderer(); 630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void QueueUIThreadCallback(int msg_id, void* data); 650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // Creates and shows the main window with the |Connect UI| enabled. 670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org bool Create(); 680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // Destroys the window. When the window is destroyed, it ends the 700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // main message loop. 710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org bool Destroy(); 720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // Callback for when the main window is destroyed. 740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void OnDestroyed(GtkWidget* widget, GdkEvent* event); 750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // Callback for when the user clicks the "Connect" button. 770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void OnClicked(GtkWidget* widget); 780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // Callback for keystrokes. Used to capture Esc and Return. 800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void OnKeyPress(GtkWidget* widget, GdkEventKey* key); 810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // Callback when the user double clicks a peer in order to initiate a 830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // connection. 840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, 850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkTreeViewColumn* column); 860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org void OnRedraw(); 880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected: 900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org class VideoRenderer : public webrtc::VideoRendererInterface { 910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public: 920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org VideoRenderer(GtkMainWnd* main_wnd, 930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org webrtc::VideoTrackInterface* track_to_render); 940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual ~VideoRenderer(); 950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org // VideoRendererInterface implementation 970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void SetSize(int width, int height); 980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org virtual void RenderFrame(const cricket::VideoFrame* frame); 990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org const uint8* image() const { 1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org return image_.get(); 1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org } 1030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org int width() const { 1050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org return width_; 1060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org } 1070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org int height() const { 1090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org return height_; 1100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org } 1110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected: 1132a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_ptr<uint8[]> image_; 1140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org int width_; 1150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org int height_; 1160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkMainWnd* main_wnd_; 1172a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_; 1180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org }; 1190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected: 1210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkWidget* window_; // Our main window. 1220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkWidget* draw_area_; // The drawing surface for rendering video streams. 1230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkWidget* vbox_; // Container for the Connect UI. 1240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkWidget* server_edit_; 1250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkWidget* port_edit_; 1260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org GtkWidget* peer_list_; // The list of peers. 1270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org MainWndCallback* callback_; 1280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org std::string server_; 1290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org std::string port_; 1300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org bool autoconnect_; 1310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org bool autocall_; 1322a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_ptr<VideoRenderer> local_renderer_; 1332a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_ptr<VideoRenderer> remote_renderer_; 1342a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org rtc::scoped_ptr<uint8> draw_buffer_; 1350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org int draw_buffer_size_; 1360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}; 1370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org 1380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif // PEERCONNECTION_SAMPLES_CLIENT_LINUX_MAIN_WND_H_ 139