1 /*
2  *  Copyright (c) 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_MODULES_VIDEO_RENDER_MAIN_SOURCE_LINUX_VIDEO_X11_CHANNEL_H_
12 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_LINUX_VIDEO_X11_CHANNEL_H_
13 
14 #include <sys/shm.h>
15 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
16 #include "webrtc/modules/video_render/include/video_render_defines.h"
17 
18 #include <X11/Xlib.h>
19 #include <X11/Xutil.h>
20 #include <X11/extensions/XShm.h>
21 
22 namespace webrtc {
23 class CriticalSectionWrapper;
24 
25 #define DEFAULT_RENDER_FRAME_WIDTH 352
26 #define DEFAULT_RENDER_FRAME_HEIGHT 288
27 
28 
29 class VideoX11Channel: public VideoRenderCallback
30 {
31 public:
32     VideoX11Channel(int32_t id);
33 
34     virtual ~VideoX11Channel();
35 
36     virtual int32_t RenderFrame(const uint32_t streamId,
37                                 const I420VideoFrame& videoFrame);
38 
39     int32_t FrameSizeChange(int32_t width, int32_t height,
40                             int32_t numberOfStreams);
41     int32_t DeliverFrame(const I420VideoFrame& videoFrame);
42     int32_t GetFrameSize(int32_t& width, int32_t& height);
43     int32_t Init(Window window, float left, float top, float right,
44                  float bottom);
45     int32_t ChangeWindow(Window window);
46     int32_t
47             GetStreamProperties(uint32_t& zOrder, float& left,
48                                 float& top, float& right, float& bottom) const;
49     int32_t ReleaseWindow();
50 
IsPrepared()51     bool IsPrepared()
52     {
53         return _prepared;
54     }
55 
56 private:
57 
58     int32_t
59             CreateLocalRenderer(int32_t width, int32_t height);
60     int32_t RemoveRenderer();
61 
62     //FIXME a better place for this method? the GetWidthHeight no longer
63     // supported by common_video.
64     int GetWidthHeight(VideoType type, int bufferSize, int& width,
65                        int& height);
66 
67     CriticalSectionWrapper& _crit;
68 
69     Display* _display;
70     XShmSegmentInfo _shminfo;
71     XImage* _image;
72     Window _window;
73     GC _gc;
74     int32_t _width; // incoming frame width
75     int32_t _height; // incoming frame height
76     int32_t _outWidth; // render frame width
77     int32_t _outHeight; // render frame height
78     int32_t _xPos; // position within window
79     int32_t _yPos;
80     bool _prepared; // true if ready to use
81     int32_t _dispCount;
82 
83     unsigned char* _buffer;
84     float _top;
85     float _left;
86     float _right;
87     float _bottom;
88 
89     int32_t _Id;
90 
91 };
92 
93 
94 }  // namespace webrtc
95 
96 #endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_LINUX_VIDEO_X11_CHANNEL_H_
97