main_wnd.h 4.2 KB

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