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_x11_channel.h" 12 #include "webrtc/modules/video_render/linux/video_x11_render.h" 13 14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 15 #include "webrtc/system_wrappers/interface/trace.h" 16 17 namespace webrtc { 18 19 VideoX11Render::VideoX11Render(Window window) : 20 _window(window), 21 _critSect(*CriticalSectionWrapper::CreateCriticalSection()) 22 { 23 } 24 25 VideoX11Render::~VideoX11Render() 26 { 27 delete &_critSect; 28 } 29 30 int32_t VideoX11Render::Init() 31 { 32 CriticalSectionScoped cs(&_critSect); 33 34 _streamIdToX11ChannelMap.clear(); 35 36 return 0; 37 } 38 39 int32_t VideoX11Render::ChangeWindow(Window window) 40 { 41 CriticalSectionScoped cs(&_critSect); 42 VideoX11Channel* renderChannel = NULL; 43 44 std::map<int, VideoX11Channel*>::iterator iter = 45 _streamIdToX11ChannelMap.begin(); 46 47 while (iter != _streamIdToX11ChannelMap.end()) 48 { 49 renderChannel = iter->second; 50 if (renderChannel) 51 { 52 renderChannel->ChangeWindow(window); 53 } 54 iter++; 55 } 56 57 _window = window; 58 59 return 0; 60 } 61 62 VideoX11Channel* VideoX11Render::CreateX11RenderChannel( 63 int32_t streamId, 64 int32_t zOrder, 65 const float left, 66 const float top, 67 const float right, 68 const float bottom) 69 { 70 CriticalSectionScoped cs(&_critSect); 71 VideoX11Channel* renderChannel = NULL; 72 73 std::map<int, VideoX11Channel*>::iterator iter = 74 _streamIdToX11ChannelMap.find(streamId); 75 76 if (iter == _streamIdToX11ChannelMap.end()) 77 { 78 renderChannel = new VideoX11Channel(streamId); 79 if (!renderChannel) 80 { 81 WEBRTC_TRACE( 82 kTraceError, 83 kTraceVideoRenderer, 84 -1, 85 "Failed to create VideoX11Channel for streamId : %d", 86 streamId); 87 return NULL; 88 } 89 renderChannel->Init(_window, left, top, right, bottom); 90 _streamIdToX11ChannelMap[streamId] = renderChannel; 91 } 92 else 93 { 94 WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, -1, 95 "Render Channel already exists for streamId: %d", streamId); 96 renderChannel = iter->second; 97 } 98 99 return renderChannel; 100 } 101 102 int32_t VideoX11Render::DeleteX11RenderChannel(int32_t streamId) 103 { 104 CriticalSectionScoped cs(&_critSect); 105 106 std::map<int, VideoX11Channel*>::iterator iter = 107 _streamIdToX11ChannelMap.find(streamId); 108 if (iter != _streamIdToX11ChannelMap.end()) 109 { 110 VideoX11Channel *renderChannel = iter->second; 111 if (renderChannel) 112 { 113 renderChannel->ReleaseWindow(); 114 delete renderChannel; 115 renderChannel = NULL; 116 } 117 _streamIdToX11ChannelMap.erase(iter); 118 } 119 120 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, -1, 121 "No VideoX11Channel object exists for stream id: %d", 122 streamId); 123 return -1; 124 } 125 126 int32_t VideoX11Render::GetIncomingStreamProperties( 127 int32_t streamId, 128 uint32_t& zOrder, 129 float& left, 130 float& top, 131 float& right, 132 float& bottom) 133 { 134 CriticalSectionScoped cs(&_critSect); 135 136 std::map<int, VideoX11Channel*>::iterator iter = 137 _streamIdToX11ChannelMap.find(streamId); 138 if (iter != _streamIdToX11ChannelMap.end()) 139 { 140 VideoX11Channel *renderChannel = iter->second; 141 if (renderChannel) 142 { 143 renderChannel->GetStreamProperties(zOrder, left, top, right, bottom); 144 } 145 } 146 147 WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, -1, 148 "No VideoX11Channel object exists for stream id: %d", 149 streamId); 150 return -1; 151 } 152 153 } // namespace webrtc 154