tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

main_wnd.h (4338B)


      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/array_view.h"
     20 #include "api/media_stream_interface.h"
     21 #include "api/scoped_refptr.h"
     22 #include "api/video/video_frame.h"
     23 #include "api/video/video_sink_interface.h"
     24 #include "examples/peerconnection/client/main_wnd.h"
     25 #include "examples/peerconnection/client/peer_connection_client.h"
     26 #include "rtc_base/buffer.h"
     27 
     28 // Forward declarations.
     29 typedef struct _GtkWidget GtkWidget;
     30 typedef union _GdkEvent GdkEvent;
     31 typedef struct _GdkEventKey GdkEventKey;
     32 typedef struct _GtkTreeView GtkTreeView;
     33 typedef struct _GtkTreePath GtkTreePath;
     34 typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
     35 typedef struct _cairo cairo_t;
     36 
     37 // Implements the main UI of the peer connection client.
     38 // This is functionally equivalent to the MainWnd class in the Windows
     39 // implementation.
     40 class GtkMainWnd : public MainWindow {
     41 public:
     42  GtkMainWnd(const char* server, int port, bool autoconnect, bool autocall);
     43  ~GtkMainWnd();
     44 
     45  virtual void RegisterObserver(MainWndCallback* callback);
     46  virtual bool IsWindow();
     47  virtual void SwitchToConnectUI();
     48  virtual void SwitchToPeerList(const Peers& peers);
     49  virtual void SwitchToStreamingUI();
     50  virtual void MessageBox(const char* caption, const char* text, bool is_error);
     51  virtual MainWindow::UI current_ui();
     52  virtual void StartLocalRenderer(webrtc::VideoTrackInterface* local_video);
     53  virtual void StopLocalRenderer();
     54  virtual void StartRemoteRenderer(webrtc::VideoTrackInterface* remote_video);
     55  virtual void StopRemoteRenderer();
     56 
     57  virtual void QueueUIThreadCallback(int msg_id, void* data);
     58 
     59  // Creates and shows the main window with the |Connect UI| enabled.
     60  bool Create();
     61 
     62  // Destroys the window.  When the window is destroyed, it ends the
     63  // main message loop.
     64  bool Destroy();
     65 
     66  // Callback for when the main window is destroyed.
     67  void OnDestroyed(GtkWidget* widget, GdkEvent* event);
     68 
     69  // Callback for when the user clicks the "Connect" button.
     70  void OnClicked(GtkWidget* widget);
     71 
     72  // Callback for keystrokes.  Used to capture Esc and Return.
     73  void OnKeyPress(GtkWidget* widget, GdkEventKey* key);
     74 
     75  // Callback when the user double clicks a peer in order to initiate a
     76  // connection.
     77  void OnRowActivated(GtkTreeView* tree_view,
     78                      GtkTreePath* path,
     79                      GtkTreeViewColumn* column);
     80 
     81  void OnRedraw();
     82 
     83  void Draw(GtkWidget* widget, cairo_t* cr);
     84 
     85 protected:
     86  class VideoRenderer : public webrtc::VideoSinkInterface<webrtc::VideoFrame> {
     87   public:
     88    VideoRenderer(GtkMainWnd* main_wnd,
     89                  webrtc::VideoTrackInterface* track_to_render);
     90    virtual ~VideoRenderer();
     91 
     92    // VideoSinkInterface implementation
     93    void OnFrame(const webrtc::VideoFrame& frame) override;
     94 
     95    webrtc::ArrayView<const uint8_t> image() const { return image_; }
     96 
     97    int width() const { return width_; }
     98 
     99    int height() const { return height_; }
    100 
    101   protected:
    102    void SetSize(int width, int height);
    103    webrtc::Buffer image_;
    104    int width_;
    105    int height_;
    106    GtkMainWnd* main_wnd_;
    107    webrtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
    108  };
    109 
    110 protected:
    111  GtkWidget* window_;     // Our main window.
    112  GtkWidget* draw_area_;  // The drawing surface for rendering video streams.
    113  GtkWidget* vbox_;       // Container for the Connect UI.
    114  GtkWidget* server_edit_;
    115  GtkWidget* port_edit_;
    116  GtkWidget* peer_list_;  // The list of peers.
    117  MainWndCallback* callback_;
    118  std::string server_;
    119  std::string port_;
    120  bool autoconnect_;
    121  bool autocall_;
    122  std::unique_ptr<VideoRenderer> local_renderer_;
    123  std::unique_ptr<VideoRenderer> remote_renderer_;
    124  int width_ = 0;
    125  int height_ = 0;
    126  webrtc::Buffer draw_buffer_;
    127  int draw_buffer_size_;
    128 };
    129 
    130 #endif  // EXAMPLES_PEERCONNECTION_CLIENT_LINUX_MAIN_WND_H_