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 20namespace webrtc { 21 22VideoRenderMacCarbonImpl::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 36VideoRenderMacCarbonImpl::~VideoRenderMacCarbonImpl() 37{ 38 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Destructor %s:%d", __FUNCTION__, __LINE__); 39 delete &_renderMacCarbonCritsect; 40} 41 42int32_t 43VideoRenderMacCarbonImpl::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 99int32_t 100VideoRenderMacCarbonImpl::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 118VideoRenderCallback* 119VideoRenderMacCarbonImpl::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 144int32_t 145VideoRenderMacCarbonImpl::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 155int32_t 156VideoRenderMacCarbonImpl::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 167int32_t 168VideoRenderMacCarbonImpl::StartRender() 169{ 170 return _ptrCarbonRender->StartRender(); 171} 172 173int32_t 174VideoRenderMacCarbonImpl::StopRender() 175{ 176 return _ptrCarbonRender->StopRender(); 177} 178 179VideoRenderType 180VideoRenderMacCarbonImpl::RenderType() 181{ 182 return kRenderCarbon; 183} 184 185RawVideoType 186VideoRenderMacCarbonImpl::PerferedVideoType() 187{ 188 return kVideoI420; 189} 190 191bool 192VideoRenderMacCarbonImpl::FullScreen() 193{ 194 return false; 195} 196 197int32_t 198VideoRenderMacCarbonImpl::GetGraphicsMemory(uint64_t& totalGraphicsMemory, 199 uint64_t& availableGraphicsMemory) const 200{ 201 totalGraphicsMemory = 0; 202 availableGraphicsMemory = 0; 203 return 0; 204} 205 206int32_t 207VideoRenderMacCarbonImpl::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 220uint32_t 221VideoRenderMacCarbonImpl::RenderFrameRate(const uint32_t streamId) 222{ 223 CriticalSectionScoped cs(&_renderMacCarbonCritsect); 224 return 0; 225} 226 227int32_t 228VideoRenderMacCarbonImpl::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 237int32_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 247int32_t 248VideoRenderMacCarbonImpl::SetTransparentBackground(const bool enable) 249{ 250 return 0; 251} 252 253int32_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 266int32_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