OLD | NEW |
| (Empty) |
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 #include "webrtc/engine_configurations.h" | |
12 #if defined(COCOA_RENDERING) | |
13 | |
14 #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_NSOPENGL_H_ | |
15 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_NSOPENGL_H_ | |
16 | |
17 #import <Cocoa/Cocoa.h> | |
18 #import <OpenGL/OpenGL.h> | |
19 #import <OpenGL/glext.h> | |
20 #import <OpenGL/glu.h> | |
21 #include <QuickTime/QuickTime.h> | |
22 #include <list> | |
23 #include <map> | |
24 #include <memory> | |
25 | |
26 #include "webrtc/base/thread_annotations.h" | |
27 #include "webrtc/modules/video_render/video_render_defines.h" | |
28 | |
29 #import "webrtc/modules/video_render/mac/cocoa_full_screen_window.h" | |
30 #import "webrtc/modules/video_render/mac/cocoa_render_view.h" | |
31 | |
32 class Trace; | |
33 | |
34 namespace rtc { | |
35 class PlatformThread; | |
36 } // namespace rtc | |
37 | |
38 namespace webrtc { | |
39 class EventTimerWrapper; | |
40 class VideoRenderNSOpenGL; | |
41 class CriticalSectionWrapper; | |
42 | |
43 class VideoChannelNSOpenGL : public VideoRenderCallback { | |
44 public: | |
45 VideoChannelNSOpenGL(NSOpenGLContext *nsglContext, int iId, VideoRenderNSOpe
nGL* owner); | |
46 virtual ~VideoChannelNSOpenGL(); | |
47 | |
48 // A new frame is delivered | |
49 virtual int DeliverFrame(const VideoFrame& videoFrame); | |
50 | |
51 // Called when the incoming frame size and/or number of streams in mix | |
52 // changes. | |
53 virtual int FrameSizeChange(int width, int height, int numberOfStreams); | |
54 | |
55 virtual int UpdateSize(int width, int height); | |
56 | |
57 // Setup | |
58 int SetStreamSettings(int streamId, float startWidth, float startHeight, flo
at stopWidth, float stopHeight); | |
59 int SetStreamCropSettings(int streamId, float startWidth, float startHeight,
float stopWidth, float stopHeight); | |
60 | |
61 // Called when it's time to render the last frame for the channel | |
62 int RenderOffScreenBuffer(); | |
63 | |
64 // Returns true if a new buffer has been delivered to the texture | |
65 int IsUpdated(bool& isUpdated); | |
66 virtual int UpdateStretchSize(int stretchHeight, int stretchWidth); | |
67 | |
68 // ********** new module functions ************ // | |
69 virtual int32_t RenderFrame(const uint32_t streamId, | |
70 const VideoFrame& videoFrame); | |
71 | |
72 // ********** new module helper functions ***** // | |
73 int ChangeContext(NSOpenGLContext *nsglContext); | |
74 int32_t GetChannelProperties(float& left, | |
75 float& top, | |
76 float& right, | |
77 float& bottom); | |
78 | |
79 private: | |
80 | |
81 NSOpenGLContext* _nsglContext; | |
82 const int _id; | |
83 VideoRenderNSOpenGL* _owner; | |
84 int32_t _width; | |
85 int32_t _height; | |
86 float _startWidth; | |
87 float _startHeight; | |
88 float _stopWidth; | |
89 float _stopHeight; | |
90 int _stretchedWidth; | |
91 int _stretchedHeight; | |
92 int _oldStretchedHeight; | |
93 int _oldStretchedWidth; | |
94 unsigned char* _buffer; | |
95 size_t _bufferSize; | |
96 size_t _incomingBufferSize; | |
97 bool _bufferIsUpdated; | |
98 int _numberOfStreams; | |
99 GLenum _pixelFormat; | |
100 GLenum _pixelDataType; | |
101 unsigned int _texture; | |
102 }; | |
103 | |
104 class VideoRenderNSOpenGL | |
105 { | |
106 | |
107 public: // methods | |
108 VideoRenderNSOpenGL(CocoaRenderView *windowRef, bool fullScreen, int iId); | |
109 ~VideoRenderNSOpenGL(); | |
110 | |
111 static int GetOpenGLVersion(int& nsglMajor, int& nsglMinor); | |
112 | |
113 // Allocates textures | |
114 int Init(); | |
115 VideoChannelNSOpenGL* CreateNSGLChannel(int streamID, int zOrder, float star
tWidth, float startHeight, float stopWidth, float stopHeight); | |
116 VideoChannelNSOpenGL* ConfigureNSGLChannel(int channel, int zOrder, float st
artWidth, float startHeight, float stopWidth, float stopHeight); | |
117 int DeleteNSGLChannel(int channel); | |
118 int DeleteAllNSGLChannels(); | |
119 int StopThread(); | |
120 bool IsFullScreen(); | |
121 bool HasChannels(); | |
122 bool HasChannel(int channel); | |
123 int GetChannels(std::list<int>& channelList); | |
124 void LockAGLCntx() EXCLUSIVE_LOCK_FUNCTION(_nsglContextCritSec); | |
125 void UnlockAGLCntx() UNLOCK_FUNCTION(_nsglContextCritSec); | |
126 | |
127 // ********** new module functions ************ // | |
128 int ChangeWindow(CocoaRenderView* newWindowRef); | |
129 int32_t StartRender(); | |
130 int32_t StopRender(); | |
131 int32_t DeleteNSGLChannel(const uint32_t streamID); | |
132 int32_t GetChannelProperties(const uint16_t streamId, | |
133 uint32_t& zOrder, | |
134 float& left, | |
135 float& top, | |
136 float& right, | |
137 float& bottom); | |
138 | |
139 int32_t SetText(const uint8_t textId, | |
140 const uint8_t* text, | |
141 const int32_t textLength, | |
142 const uint32_t textColorRef, | |
143 const uint32_t backgroundColorRef, | |
144 const float left, | |
145 const float top, | |
146 const float right, | |
147 const float bottom); | |
148 | |
149 // ********** new module helper functions ***** // | |
150 int configureNSOpenGLEngine(); | |
151 int configureNSOpenGLView(); | |
152 int setRenderTargetWindow(); | |
153 int setRenderTargetFullScreen(); | |
154 | |
155 protected: // methods | |
156 static bool ScreenUpdateThreadProc(void* obj); | |
157 bool ScreenUpdateProcess(); | |
158 int GetWindowRect(Rect& rect); | |
159 | |
160 private: // methods | |
161 | |
162 int CreateMixingContext(); | |
163 int RenderOffScreenBuffers(); | |
164 int DisplayBuffers(); | |
165 | |
166 private: // variables | |
167 | |
168 | |
169 CocoaRenderView* _windowRef; | |
170 bool _fullScreen; | |
171 int _id; | |
172 CriticalSectionWrapper& _nsglContextCritSec; | |
173 // TODO(pbos): Remove unique_ptr and use PlatformThread directly. | |
174 std::unique_ptr<rtc::PlatformThread> _screenUpdateThread; | |
175 EventTimerWrapper* _screenUpdateEvent; | |
176 NSOpenGLContext* _nsglContext; | |
177 NSOpenGLContext* _nsglFullScreenContext; | |
178 CocoaFullScreenWindow* _fullScreenWindow; | |
179 Rect _windowRect; // The size of the window | |
180 int _windowWidth; | |
181 int _windowHeight; | |
182 std::map<int, VideoChannelNSOpenGL*> _nsglChannels; | |
183 std::multimap<int, int> _zOrderToChannel; | |
184 bool _renderingIsPaused; | |
185 NSView* _windowRefSuperView; | |
186 NSRect _windowRefSuperViewFrame; | |
187 }; | |
188 | |
189 } // namespace webrtc | |
190 | |
191 #endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_NSOPENGL_H_ | |
192 #endif // COCOA_RENDERING | |
OLD | NEW |