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/include/critical_section_wrapper.h" 18#include "webrtc/system_wrappers/include/trace.h" 19 20namespace webrtc { 21 22VideoRenderMacCocoaImpl::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 35VideoRenderMacCocoaImpl::~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 46int32_t 47VideoRenderMacCocoaImpl::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 70int32_t 71VideoRenderMacCocoaImpl::ChangeWindow(void* window) 72{ 73 74 CriticalSectionScoped cs(&_renderMacCocoaCritsect); 75 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s changing ID to ", __FUNCTION__, window); 76 77 if (window == NULL) 78 { 79 return -1; 80 } 81 _ptrWindow = window; 82 83 84 _ptrWindow = window; 85 _ptrCocoaRender->ChangeWindow((CocoaRenderView*)_ptrWindow); 86 87 return 0; 88} 89 90VideoRenderCallback* 91VideoRenderMacCocoaImpl::AddIncomingRenderStream(const uint32_t streamId, 92 const uint32_t zOrder, 93 const float left, 94 const float top, 95 const float right, 96 const float bottom) 97{ 98 CriticalSectionScoped cs(&_renderMacCocoaCritsect); 99 WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s", __FUNCTION__); 100 VideoChannelNSOpenGL* nsOpenGLChannel = NULL; 101 102 if(!_ptrWindow) 103 { 104 } 105 106 if(!nsOpenGLChannel) 107 { 108 nsOpenGLChannel = _ptrCocoaRender->CreateNSGLChannel(streamId, zOrder, left, top, right, bottom); 109 } 110 111 return nsOpenGLChannel; 112 113} 114 115int32_t 116VideoRenderMacCocoaImpl::DeleteIncomingRenderStream(const uint32_t streamId) 117{ 118 WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__); 119 CriticalSectionScoped cs(&_renderMacCocoaCritsect); 120 _ptrCocoaRender->DeleteNSGLChannel(streamId); 121 122 return 0; 123} 124 125int32_t 126VideoRenderMacCocoaImpl::GetIncomingRenderStreamProperties(const uint32_t streamId, 127 uint32_t& zOrder, 128 float& left, 129 float& top, 130 float& right, 131 float& bottom) const 132{ 133 return _ptrCocoaRender->GetChannelProperties(streamId, zOrder, left, top, right, bottom); 134} 135 136int32_t 137VideoRenderMacCocoaImpl::StartRender() 138{ 139 return _ptrCocoaRender->StartRender(); 140} 141 142int32_t 143VideoRenderMacCocoaImpl::StopRender() 144{ 145 return _ptrCocoaRender->StopRender(); 146} 147 148VideoRenderType 149VideoRenderMacCocoaImpl::RenderType() 150{ 151 return kRenderCocoa; 152} 153 154RawVideoType 155VideoRenderMacCocoaImpl::PerferedVideoType() 156{ 157 return kVideoI420; 158} 159 160bool 161VideoRenderMacCocoaImpl::FullScreen() 162{ 163 return false; 164} 165 166int32_t 167VideoRenderMacCocoaImpl::GetGraphicsMemory(uint64_t& totalGraphicsMemory, 168 uint64_t& availableGraphicsMemory) const 169{ 170 totalGraphicsMemory = 0; 171 availableGraphicsMemory = 0; 172 return 0; 173} 174 175int32_t 176VideoRenderMacCocoaImpl::GetScreenResolution(uint32_t& screenWidth, 177 uint32_t& screenHeight) const 178{ 179 CriticalSectionScoped cs(&_renderMacCocoaCritsect); 180 NSScreen* mainScreen = [NSScreen mainScreen]; 181 182 NSRect frame = [mainScreen frame]; 183 184 screenWidth = frame.size.width; 185 screenHeight = frame.size.height; 186 return 0; 187} 188 189uint32_t 190VideoRenderMacCocoaImpl::RenderFrameRate(const uint32_t streamId) 191{ 192 CriticalSectionScoped cs(&_renderMacCocoaCritsect); 193 return 0; 194} 195 196int32_t 197VideoRenderMacCocoaImpl::SetStreamCropping(const uint32_t streamId, 198 const float left, 199 const float top, 200 const float right, 201 const float bottom) 202{ 203 return 0; 204} 205 206int32_t VideoRenderMacCocoaImpl::ConfigureRenderer(const uint32_t streamId, 207 const unsigned int zOrder, 208 const float left, 209 const float top, 210 const float right, 211 const float bottom) 212{ 213 return 0; 214} 215 216int32_t 217VideoRenderMacCocoaImpl::SetTransparentBackground(const bool enable) 218{ 219 return 0; 220} 221 222int32_t VideoRenderMacCocoaImpl::SetText(const uint8_t textId, 223 const uint8_t* text, 224 const int32_t textLength, 225 const uint32_t textColorRef, 226 const uint32_t backgroundColorRef, 227 const float left, 228 const float top, 229 const float right, 230 const float bottom) 231{ 232 return _ptrCocoaRender->SetText(textId, text, textLength, textColorRef, backgroundColorRef, left, top, right, bottom); 233} 234 235int32_t VideoRenderMacCocoaImpl::SetBitmap(const void* bitMap, 236 const uint8_t pictureId, 237 const void* colorKey, 238 const float left, 239 const float top, 240 const float right, 241 const float bottom) 242{ 243 return 0; 244} 245 246int32_t VideoRenderMacCocoaImpl::FullScreenRender(void* window, const bool enable) 247{ 248 return -1; 249} 250 251} // namespace webrtc 252 253#endif // COCOA_RENDERING 254