Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / video_render / mac / video_render_mac_cocoa_impl.mm
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 #include "webrtc/modules/video_render/mac/cocoa_render_view.h"
15 #include "webrtc/modules/video_render/mac/video_render_mac_cocoa_impl.h"
16 #include "webrtc/modules/video_render/mac/video_render_nsopengl.h"
17 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
18 #include "webrtc/system_wrappers/interface/trace.h"
19
20 namespace webrtc {
21
22 VideoRenderMacCocoaImpl::VideoRenderMacCocoaImpl(const int32_t id,
23         const VideoRenderType videoRenderType,
24         void* window,
25         const bool fullscreen) :
26 _id(id),
27 _renderMacCocoaCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
28 _fullScreen(fullscreen),
29 _ptrWindow(window)
30 {
31
32     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
33 }
34
35 VideoRenderMacCocoaImpl::~VideoRenderMacCocoaImpl()
36 {
37     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Destructor %s:%d", __FUNCTION__, __LINE__);
38     delete &_renderMacCocoaCritsect;
39     if (_ptrCocoaRender)
40     {
41         delete _ptrCocoaRender;
42         _ptrCocoaRender = NULL;
43     }
44 }
45
46 int32_t
47 VideoRenderMacCocoaImpl::Init()
48 {
49
50     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
51     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s:%d", __FUNCTION__, __LINE__);
52
53     // cast ptrWindow from void* to CocoaRenderer. Void* was once NSOpenGLView, and CocoaRenderer is NSOpenGLView.
54     _ptrCocoaRender = new VideoRenderNSOpenGL((CocoaRenderView*)_ptrWindow, _fullScreen, _id);
55     if (!_ptrWindow)
56     {
57         WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
58         return -1;
59     }
60     int retVal = _ptrCocoaRender->Init();
61     if (retVal == -1)
62     {
63         WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Failed to init %s:%d", __FUNCTION__, __LINE__);
64         return -1;
65     }
66
67     return 0;
68 }
69
70 int32_t
71 VideoRenderMacCocoaImpl::ChangeUniqueId(const int32_t id)
72 {
73     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
74     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
75     _id = id;
76
77     if(_ptrCocoaRender)
78     {
79         _ptrCocoaRender->ChangeUniqueID(_id);
80     }
81
82     return 0;
83 }
84
85 int32_t
86 VideoRenderMacCocoaImpl::ChangeWindow(void* window)
87 {
88
89     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
90     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s changing ID to ", __FUNCTION__, window);
91
92     if (window == NULL)
93     {
94         return -1;
95     }
96     _ptrWindow = window;
97
98
99     _ptrWindow = window;
100     _ptrCocoaRender->ChangeWindow((CocoaRenderView*)_ptrWindow);
101
102     return 0;
103 }
104
105 VideoRenderCallback*
106 VideoRenderMacCocoaImpl::AddIncomingRenderStream(const uint32_t streamId,
107         const uint32_t zOrder,
108         const float left,
109         const float top,
110         const float right,
111         const float bottom)
112 {
113     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
114     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
115     VideoChannelNSOpenGL* nsOpenGLChannel = NULL;
116
117     if(!_ptrWindow)
118     {
119     }
120
121     if(!nsOpenGLChannel)
122     {
123         nsOpenGLChannel = _ptrCocoaRender->CreateNSGLChannel(streamId, zOrder, left, top, right, bottom);
124     }
125
126     return nsOpenGLChannel;
127
128 }
129
130 int32_t
131 VideoRenderMacCocoaImpl::DeleteIncomingRenderStream(const uint32_t streamId)
132 {
133     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
134     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
135     _ptrCocoaRender->DeleteNSGLChannel(streamId);
136
137     return 0;
138 }
139
140 int32_t
141 VideoRenderMacCocoaImpl::GetIncomingRenderStreamProperties(const uint32_t streamId,
142         uint32_t& zOrder,
143         float& left,
144         float& top,
145         float& right,
146         float& bottom) const
147 {
148     return _ptrCocoaRender->GetChannelProperties(streamId, zOrder, left, top, right, bottom);
149 }
150
151 int32_t
152 VideoRenderMacCocoaImpl::StartRender()
153 {
154     return _ptrCocoaRender->StartRender();
155 }
156
157 int32_t
158 VideoRenderMacCocoaImpl::StopRender()
159 {
160     return _ptrCocoaRender->StopRender();
161 }
162
163 VideoRenderType
164 VideoRenderMacCocoaImpl::RenderType()
165 {
166     return kRenderCocoa;
167 }
168
169 RawVideoType
170 VideoRenderMacCocoaImpl::PerferedVideoType()
171 {
172     return kVideoI420;
173 }
174
175 bool
176 VideoRenderMacCocoaImpl::FullScreen()
177 {
178     return false;
179 }
180
181 int32_t
182 VideoRenderMacCocoaImpl::GetGraphicsMemory(uint64_t& totalGraphicsMemory,
183         uint64_t& availableGraphicsMemory) const
184 {
185     totalGraphicsMemory = 0;
186     availableGraphicsMemory = 0;
187     return 0;
188 }
189
190 int32_t
191 VideoRenderMacCocoaImpl::GetScreenResolution(uint32_t& screenWidth,
192         uint32_t& screenHeight) const
193 {
194     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
195     NSScreen* mainScreen = [NSScreen mainScreen];
196
197     NSRect frame = [mainScreen frame];
198
199     screenWidth = frame.size.width;
200     screenHeight = frame.size.height;
201     return 0;
202 }
203
204 uint32_t
205 VideoRenderMacCocoaImpl::RenderFrameRate(const uint32_t streamId)
206 {
207     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
208     return 0;
209 }
210
211 int32_t
212 VideoRenderMacCocoaImpl::SetStreamCropping(const uint32_t streamId,
213         const float left,
214         const float top,
215         const float right,
216         const float bottom)
217 {
218     return 0;
219 }
220
221 int32_t VideoRenderMacCocoaImpl::ConfigureRenderer(const uint32_t streamId,
222                                                    const unsigned int zOrder,
223                                                    const float left,
224                                                    const float top,
225                                                    const float right,
226                                                    const float bottom)
227 {
228     return 0;
229 }
230
231 int32_t
232 VideoRenderMacCocoaImpl::SetTransparentBackground(const bool enable)
233 {
234     return 0;
235 }
236
237 int32_t VideoRenderMacCocoaImpl::SetText(const uint8_t textId,
238                                          const uint8_t* text,
239                                          const int32_t textLength,
240                                          const uint32_t textColorRef,
241                                          const uint32_t backgroundColorRef,
242                                          const float left,
243                                          const float top,
244                                          const float right,
245                                          const float bottom)
246 {
247     return _ptrCocoaRender->SetText(textId, text, textLength, textColorRef, backgroundColorRef, left, top, right, bottom);
248 }
249
250 int32_t VideoRenderMacCocoaImpl::SetBitmap(const void* bitMap,
251                                            const uint8_t pictureId,
252                                            const void* colorKey,
253                                            const float left,
254                                            const float top,
255                                            const float right,
256                                            const float bottom)
257 {
258     return 0;
259 }
260
261 int32_t VideoRenderMacCocoaImpl::FullScreenRender(void* window, const bool enable)
262 {
263     return -1;
264 }
265
266 }  // namespace webrtc
267
268 #endif // COCOA_RENDERING