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(CARBON_RENDERING)
13 
14 #include <AGL/agl.h>
15 #include "webrtc/modules/video_render/mac/video_render_agl.h"
16 #include "webrtc/modules/video_render/mac/video_render_mac_carbon_impl.h"
17 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
18 #include "webrtc/system_wrappers/include/trace.h"
19 
20 namespace webrtc {
21 
VideoRenderMacCarbonImpl(const int32_t id,const VideoRenderType videoRenderType,void * window,const bool fullscreen)22 VideoRenderMacCarbonImpl::VideoRenderMacCarbonImpl(const int32_t id,
23         const VideoRenderType videoRenderType,
24         void* window,
25         const bool fullscreen) :
26 _id(id),
27 _renderMacCarbonCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
28 _fullScreen(fullscreen),
29 _ptrWindow(window)
30 {
31 
32     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
33 
34 }
35 
~VideoRenderMacCarbonImpl()36 VideoRenderMacCarbonImpl::~VideoRenderMacCarbonImpl()
37 {
38     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Destructor %s:%d", __FUNCTION__, __LINE__);
39     delete &_renderMacCarbonCritsect;
40 }
41 
42 int32_t
Init()43 VideoRenderMacCarbonImpl::Init()
44 {
45     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
46     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s:%d", __FUNCTION__, __LINE__);
47 
48     if (!_ptrWindow)
49     {
50         WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
51         return -1;
52     }
53 
54     // We don't know if the user passed us a WindowRef or a HIViewRef, so test.
55     bool referenceIsValid = false;
56 
57     // Check if it's a valid WindowRef
58     //WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s:%d _ptrWindowRef before WindowRef cast: %x", __FUNCTION__, __LINE__, _ptrWindowRef);
59     WindowRef* windowRef = static_cast<WindowRef*>(_ptrWindow);
60     //WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s:%d _ptrWindowRef after cast: %x", __FUNCTION__, __LINE__, _ptrWindowRef);
61     if (IsValidWindowPtr(*windowRef))
62     {
63         _ptrCarbonRender = new VideoRenderAGL(*windowRef, _fullScreen, _id);
64         referenceIsValid = true;
65         WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s:%d Successfully initialized CarbonRenderer with WindowRef:%x", __FUNCTION__, __LINE__, *windowRef);
66     }
67     else
68     {
69         HIViewRef* hiviewRef = static_cast<HIViewRef*>(_ptrWindow);
70         if (HIViewIsValid(*hiviewRef))
71         {
72             _ptrCarbonRender = new VideoRenderAGL(*hiviewRef, _fullScreen, _id);
73             referenceIsValid = true;
74             WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s:%d Successfully initialized CarbonRenderer with HIViewRef:%x", __FUNCTION__, __LINE__, hiviewRef);
75         }
76     }
77 
78     if(!referenceIsValid)
79     {
80         WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s:%d Invalid WindowRef/HIViewRef Returning -1", __FUNCTION__, __LINE__);
81         return -1;
82     }
83 
84     if(!_ptrCarbonRender)
85     {
86         WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s:%d Failed to create an instance of VideoRenderAGL. Returning -1", __FUNCTION__, __LINE__);
87     }
88 
89     int retVal = _ptrCarbonRender->Init();
90     if (retVal == -1)
91     {
92         WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s:%d Failed to init CarbonRenderer", __FUNCTION__, __LINE__);
93         return -1;
94     }
95 
96     return 0;
97 }
98 
99 int32_t
ChangeWindow(void * window)100 VideoRenderMacCarbonImpl::ChangeWindow(void* window)
101 {
102     return -1;
103     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
104     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s changing ID to ", __FUNCTION__, window);
105 
106     if (window == NULL)
107     {
108         return -1;
109     }
110     _ptrWindow = window;
111 
112 
113     _ptrWindow = window;
114 
115     return 0;
116 }
117 
118 VideoRenderCallback*
AddIncomingRenderStream(const uint32_t streamId,const uint32_t zOrder,const float left,const float top,const float right,const float bottom)119 VideoRenderMacCarbonImpl::AddIncomingRenderStream(const uint32_t streamId,
120         const uint32_t zOrder,
121         const float left,
122         const float top,
123         const float right,
124         const float bottom)
125 {
126 
127     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
128     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
129     VideoChannelAGL* AGLChannel = NULL;
130 
131     if(!_ptrWindow)
132     {
133     }
134 
135     if(!AGLChannel)
136     {
137         AGLChannel = _ptrCocoaRender->CreateNSGLChannel(streamId, zOrder, left, top, right, bottom);
138     }
139 
140     return AGLChannel;
141 
142 }
143 
144 int32_t
DeleteIncomingRenderStream(const uint32_t streamId)145 VideoRenderMacCarbonImpl::DeleteIncomingRenderStream(const uint32_t streamId)
146 {
147 
148     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s:%d", __FUNCTION__, __LINE__);
149     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
150     _ptrCarbonRender->DeleteAGLChannel(streamId);
151 
152     return 0;
153 }
154 
155 int32_t
GetIncomingRenderStreamProperties(const uint32_t streamId,uint32_t & zOrder,float & left,float & top,float & right,float & bottom) const156 VideoRenderMacCarbonImpl::GetIncomingRenderStreamProperties(const uint32_t streamId,
157         uint32_t& zOrder,
158         float& left,
159         float& top,
160         float& right,
161         float& bottom) const
162 {
163     return -1;
164     return _ptrCarbonRender->GetChannelProperties(streamId, zOrder, left, top, right, bottom);
165 }
166 
167 int32_t
StartRender()168 VideoRenderMacCarbonImpl::StartRender()
169 {
170     return _ptrCarbonRender->StartRender();
171 }
172 
173 int32_t
StopRender()174 VideoRenderMacCarbonImpl::StopRender()
175 {
176     return _ptrCarbonRender->StopRender();
177 }
178 
179 VideoRenderType
RenderType()180 VideoRenderMacCarbonImpl::RenderType()
181 {
182     return kRenderCarbon;
183 }
184 
185 RawVideoType
PerferedVideoType()186 VideoRenderMacCarbonImpl::PerferedVideoType()
187 {
188     return kVideoI420;
189 }
190 
191 bool
FullScreen()192 VideoRenderMacCarbonImpl::FullScreen()
193 {
194     return false;
195 }
196 
197 int32_t
GetGraphicsMemory(uint64_t & totalGraphicsMemory,uint64_t & availableGraphicsMemory) const198 VideoRenderMacCarbonImpl::GetGraphicsMemory(uint64_t& totalGraphicsMemory,
199         uint64_t& availableGraphicsMemory) const
200 {
201     totalGraphicsMemory = 0;
202     availableGraphicsMemory = 0;
203     return 0;
204 }
205 
206 int32_t
GetScreenResolution(uint32_t & screenWidth,uint32_t & screenHeight) const207 VideoRenderMacCarbonImpl::GetScreenResolution(uint32_t& screenWidth,
208         uint32_t& screenHeight) const
209 {
210     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
211     //NSScreen* mainScreen = [NSScreen mainScreen];
212 
213     //NSRect frame = [mainScreen frame];
214 
215     //screenWidth = frame.size.width;
216     //screenHeight = frame.size.height;
217     return 0;
218 }
219 
220 uint32_t
RenderFrameRate(const uint32_t streamId)221 VideoRenderMacCarbonImpl::RenderFrameRate(const uint32_t streamId)
222 {
223     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
224     return 0;
225 }
226 
227 int32_t
SetStreamCropping(const uint32_t streamId,const float left,const float top,const float right,const float bottom)228 VideoRenderMacCarbonImpl::SetStreamCropping(const uint32_t streamId,
229         const float left,
230         const float top,
231         const float right,
232         const float bottom)
233 {
234     return 0;
235 }
236 
ConfigureRenderer(const uint32_t streamId,const unsigned int zOrder,const float left,const float top,const float right,const float bottom)237 int32_t VideoRenderMacCarbonImpl::ConfigureRenderer(const uint32_t streamId,
238                                                     const unsigned int zOrder,
239                                                     const float left,
240                                                     const float top,
241                                                     const float right,
242                                                     const float bottom)
243 {
244     return 0;
245 }
246 
247 int32_t
SetTransparentBackground(const bool enable)248 VideoRenderMacCarbonImpl::SetTransparentBackground(const bool enable)
249 {
250     return 0;
251 }
252 
SetText(const uint8_t textId,const uint8_t * text,const int32_t textLength,const uint32_t textColorRef,const uint32_t backgroundColorRef,const float left,const float top,const float right,const float bottom)253 int32_t VideoRenderMacCarbonImpl::SetText(const uint8_t textId,
254                                           const uint8_t* text,
255                                           const int32_t textLength,
256                                           const uint32_t textColorRef,
257                                           const uint32_t backgroundColorRef,
258                                           const float left,
259                                           const float top,
260                                           const float right,
261                                           const float bottom)
262 {
263     return 0;
264 }
265 
SetBitmap(const void * bitMap,const uint8_t pictureId,const void * colorKey,const float left,const float top,const float right,const float bottom)266 int32_t VideoRenderMacCarbonImpl::SetBitmap(const void* bitMap,
267                                             const uint8_t pictureId,
268                                             const void* colorKey,
269                                             const float left,
270                                             const float top,
271                                             const float right,
272                                             const float bottom)
273 {
274     return 0;
275 }
276 
277 
278 }  // namespace webrtc
279 
280 #endif // CARBON_RENDERING
281