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/modules/video_render/linux/video_render_linux_impl.h" 12 13 #include "webrtc/modules/video_render/linux/video_x11_render.h" 14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 15 #include "webrtc/system_wrappers/interface/trace.h" 16 17 #include <X11/Xlib.h> 18 19 namespace webrtc { 20 21 VideoRenderLinuxImpl::VideoRenderLinuxImpl( 22 const int32_t id, 23 const VideoRenderType videoRenderType, 24 void* window, const bool fullscreen) : 25 _id(id), 26 _renderLinuxCritsect( 27 *CriticalSectionWrapper::CreateCriticalSection()), 28 _ptrWindow(window), _ptrX11Render(NULL) 29 { 30 } 31 32 VideoRenderLinuxImpl::~VideoRenderLinuxImpl() 33 { 34 if (_ptrX11Render) 35 delete _ptrX11Render; 36 37 delete &_renderLinuxCritsect; 38 } 39 40 int32_t VideoRenderLinuxImpl::Init() 41 { 42 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 43 __FUNCTION__); 44 45 CriticalSectionScoped cs(&_renderLinuxCritsect); 46 _ptrX11Render = new VideoX11Render((Window) _ptrWindow); 47 if (!_ptrX11Render) 48 { 49 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 50 "%s", 51 "Failed to create instance of VideoX11Render object"); 52 return -1; 53 } 54 int retVal = _ptrX11Render->Init(); 55 if (retVal == -1) 56 { 57 return -1; 58 } 59 60 return 0; 61 62 } 63 64 int32_t VideoRenderLinuxImpl::ChangeUniqueId(const int32_t id) 65 { 66 CriticalSectionScoped cs(&_renderLinuxCritsect); 67 68 _id = id; 69 return 0; 70 } 71 72 int32_t VideoRenderLinuxImpl::ChangeWindow(void* window) 73 { 74 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 75 __FUNCTION__); 76 77 CriticalSectionScoped cs(&_renderLinuxCritsect); 78 _ptrWindow = window; 79 80 if (_ptrX11Render) 81 { 82 return _ptrX11Render->ChangeWindow((Window) window); 83 } 84 85 return -1; 86 } 87 88 VideoRenderCallback* VideoRenderLinuxImpl::AddIncomingRenderStream( 89 const uint32_t streamId, 90 const uint32_t zOrder, 91 const float left, 92 const float top, 93 const float right, 94 const float bottom) 95 { 96 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 97 __FUNCTION__); 98 CriticalSectionScoped cs(&_renderLinuxCritsect); 99 100 VideoRenderCallback* renderCallback = NULL; 101 if (_ptrX11Render) 102 { 103 VideoX11Channel* renderChannel = 104 _ptrX11Render->CreateX11RenderChannel(streamId, zOrder, left, 105 top, right, bottom); 106 if (!renderChannel) 107 { 108 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 109 "Render channel creation failed for stream id: %d", 110 streamId); 111 return NULL; 112 } 113 renderCallback = (VideoRenderCallback *) renderChannel; 114 } 115 else 116 { 117 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 118 "_ptrX11Render is NULL"); 119 return NULL; 120 } 121 return renderCallback; 122 } 123 124 int32_t VideoRenderLinuxImpl::DeleteIncomingRenderStream( 125 const uint32_t streamId) 126 { 127 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 128 __FUNCTION__); 129 CriticalSectionScoped cs(&_renderLinuxCritsect); 130 131 if (_ptrX11Render) 132 { 133 return _ptrX11Render->DeleteX11RenderChannel(streamId); 134 } 135 return -1; 136 } 137 138 int32_t VideoRenderLinuxImpl::GetIncomingRenderStreamProperties( 139 const uint32_t streamId, 140 uint32_t& zOrder, 141 float& left, 142 float& top, 143 float& right, 144 float& bottom) const 145 { 146 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 147 __FUNCTION__); 148 CriticalSectionScoped cs(&_renderLinuxCritsect); 149 150 if (_ptrX11Render) 151 { 152 return _ptrX11Render->GetIncomingStreamProperties(streamId, zOrder, 153 left, top, right, 154 bottom); 155 } 156 return -1; 157 } 158 159 int32_t VideoRenderLinuxImpl::StartRender() 160 { 161 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 162 __FUNCTION__); 163 return 0; 164 } 165 166 int32_t VideoRenderLinuxImpl::StopRender() 167 { 168 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", 169 __FUNCTION__); 170 return 0; 171 } 172 173 VideoRenderType VideoRenderLinuxImpl::RenderType() 174 { 175 return kRenderX11; 176 } 177 178 RawVideoType VideoRenderLinuxImpl::PerferedVideoType() 179 { 180 return kVideoI420; 181 } 182 183 bool VideoRenderLinuxImpl::FullScreen() 184 { 185 return false; 186 } 187 188 int32_t VideoRenderLinuxImpl::GetGraphicsMemory( 189 uint64_t& /*totalGraphicsMemory*/, 190 uint64_t& /*availableGraphicsMemory*/) const 191 { 192 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 193 "%s - not supported on Linux", __FUNCTION__); 194 return -1; 195 } 196 197 int32_t VideoRenderLinuxImpl::GetScreenResolution( 198 uint32_t& /*screenWidth*/, 199 uint32_t& /*screenHeight*/) const 200 { 201 return -1; 202 } 203 204 uint32_t VideoRenderLinuxImpl::RenderFrameRate(const uint32_t /*streamId*/) 205 { 206 return -1; 207 } 208 209 int32_t VideoRenderLinuxImpl::SetStreamCropping( 210 const uint32_t /*streamId*/, 211 const float /*left*/, 212 const float /*top*/, 213 const float /*right*/, 214 const float /*bottom*/) 215 { 216 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 217 "%s - not supported on Linux", __FUNCTION__); 218 return -1; 219 } 220 221 int32_t VideoRenderLinuxImpl::SetTransparentBackground(const bool /*enable*/) 222 { 223 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 224 "%s - not supported on Linux", __FUNCTION__); 225 return -1; 226 } 227 228 int32_t VideoRenderLinuxImpl::ConfigureRenderer( 229 const uint32_t streamId, 230 const unsigned int zOrder, 231 const float left, 232 const float top, 233 const float right, 234 const float bottom) 235 { 236 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 237 "%s - not supported on Linux", __FUNCTION__); 238 return -1; 239 } 240 241 int32_t VideoRenderLinuxImpl::SetText( 242 const uint8_t textId, 243 const uint8_t* text, 244 const int32_t textLength, 245 const uint32_t textColorRef, 246 const uint32_t backgroundColorRef, 247 const float left, const float top, 248 const float rigth, 249 const float bottom) 250 { 251 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 252 "%s - not supported on Linux", __FUNCTION__); 253 return -1; 254 } 255 256 int32_t VideoRenderLinuxImpl::SetBitmap(const void* bitMap, 257 const uint8_t pictureId, 258 const void* colorKey, 259 const float left, 260 const float top, 261 const float right, 262 const float bottom) 263 { 264 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, 265 "%s - not supported on Linux", __FUNCTION__); 266 return -1; 267 } 268 269 } // namespace webrtc 270