Home | History | Annotate | Download | only in mac
      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 #import "cocoa_render_view.h"
     15 
     16 #include "video_render_mac_cocoa_impl.h"
     17 #include "critical_section_wrapper.h"
     18 #include "video_render_nsopengl.h"
     19 #include "trace.h"
     20 
     21 namespace webrtc {
     22 
     23 VideoRenderMacCocoaImpl::VideoRenderMacCocoaImpl(const int32_t id,
     24         const VideoRenderType videoRenderType,
     25         void* window,
     26         const bool fullscreen) :
     27 _id(id),
     28 _renderMacCocoaCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
     29 _fullScreen(fullscreen),
     30 _ptrWindow(window)
     31 {
     32 
     33     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
     34 }
     35 
     36 VideoRenderMacCocoaImpl::~VideoRenderMacCocoaImpl()
     37 {
     38     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Destructor %s:%d", __FUNCTION__, __LINE__);
     39     delete &_renderMacCocoaCritsect;
     40     if (_ptrCocoaRender)
     41     {
     42         delete _ptrCocoaRender;
     43         _ptrCocoaRender = NULL;
     44     }
     45 }
     46 
     47 int32_t
     48 VideoRenderMacCocoaImpl::Init()
     49 {
     50 
     51     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
     52     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s:%d", __FUNCTION__, __LINE__);
     53 
     54     // cast ptrWindow from void* to CocoaRenderer. Void* was once NSOpenGLView, and CocoaRenderer is NSOpenGLView.
     55     _ptrCocoaRender = new VideoRenderNSOpenGL((CocoaRenderView*)_ptrWindow, _fullScreen, _id);
     56     if (!_ptrWindow)
     57     {
     58         WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
     59         return -1;
     60     }
     61     int retVal = _ptrCocoaRender->Init();
     62     if (retVal == -1)
     63     {
     64         WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Failed to init %s:%d", __FUNCTION__, __LINE__);
     65         return -1;
     66     }
     67 
     68     return 0;
     69 }
     70 
     71 int32_t
     72 VideoRenderMacCocoaImpl::ChangeUniqueId(const int32_t id)
     73 {
     74     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
     75     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
     76     _id = id;
     77 
     78     if(_ptrCocoaRender)
     79     {
     80         _ptrCocoaRender->ChangeUniqueID(_id);
     81     }
     82 
     83     return 0;
     84 }
     85 
     86 int32_t
     87 VideoRenderMacCocoaImpl::ChangeWindow(void* window)
     88 {
     89 
     90     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
     91     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s changing ID to ", __FUNCTION__, window);
     92 
     93     if (window == NULL)
     94     {
     95         return -1;
     96     }
     97     _ptrWindow = window;
     98 
     99 
    100     _ptrWindow = window;
    101     _ptrCocoaRender->ChangeWindow((CocoaRenderView*)_ptrWindow);
    102 
    103     return 0;
    104 }
    105 
    106 VideoRenderCallback*
    107 VideoRenderMacCocoaImpl::AddIncomingRenderStream(const uint32_t streamId,
    108         const uint32_t zOrder,
    109         const float left,
    110         const float top,
    111         const float right,
    112         const float bottom)
    113 {
    114     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
    115     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
    116     VideoChannelNSOpenGL* nsOpenGLChannel = NULL;
    117 
    118     if(!_ptrWindow)
    119     {
    120     }
    121 
    122     if(!nsOpenGLChannel)
    123     {
    124         nsOpenGLChannel = _ptrCocoaRender->CreateNSGLChannel(streamId, zOrder, left, top, right, bottom);
    125     }
    126 
    127     return nsOpenGLChannel;
    128 
    129 }
    130 
    131 int32_t
    132 VideoRenderMacCocoaImpl::DeleteIncomingRenderStream(const uint32_t streamId)
    133 {
    134     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "Constructor %s:%d", __FUNCTION__, __LINE__);
    135     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
    136     _ptrCocoaRender->DeleteNSGLChannel(streamId);
    137 
    138     return 0;
    139 }
    140 
    141 int32_t
    142 VideoRenderMacCocoaImpl::GetIncomingRenderStreamProperties(const uint32_t streamId,
    143         uint32_t& zOrder,
    144         float& left,
    145         float& top,
    146         float& right,
    147         float& bottom) const
    148 {
    149     return _ptrCocoaRender->GetChannelProperties(streamId, zOrder, left, top, right, bottom);
    150 }
    151 
    152 int32_t
    153 VideoRenderMacCocoaImpl::StartRender()
    154 {
    155     return _ptrCocoaRender->StartRender();
    156 }
    157 
    158 int32_t
    159 VideoRenderMacCocoaImpl::StopRender()
    160 {
    161     return _ptrCocoaRender->StopRender();
    162 }
    163 
    164 VideoRenderType
    165 VideoRenderMacCocoaImpl::RenderType()
    166 {
    167     return kRenderCocoa;
    168 }
    169 
    170 RawVideoType
    171 VideoRenderMacCocoaImpl::PerferedVideoType()
    172 {
    173     return kVideoI420;
    174 }
    175 
    176 bool
    177 VideoRenderMacCocoaImpl::FullScreen()
    178 {
    179     return false;
    180 }
    181 
    182 int32_t
    183 VideoRenderMacCocoaImpl::GetGraphicsMemory(uint64_t& totalGraphicsMemory,
    184         uint64_t& availableGraphicsMemory) const
    185 {
    186     totalGraphicsMemory = 0;
    187     availableGraphicsMemory = 0;
    188     return 0;
    189 }
    190 
    191 int32_t
    192 VideoRenderMacCocoaImpl::GetScreenResolution(uint32_t& screenWidth,
    193         uint32_t& screenHeight) const
    194 {
    195     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
    196     NSScreen* mainScreen = [NSScreen mainScreen];
    197 
    198     NSRect frame = [mainScreen frame];
    199 
    200     screenWidth = frame.size.width;
    201     screenHeight = frame.size.height;
    202     return 0;
    203 }
    204 
    205 uint32_t
    206 VideoRenderMacCocoaImpl::RenderFrameRate(const uint32_t streamId)
    207 {
    208     CriticalSectionScoped cs(&_renderMacCocoaCritsect);
    209     return 0;
    210 }
    211 
    212 int32_t
    213 VideoRenderMacCocoaImpl::SetStreamCropping(const uint32_t streamId,
    214         const float left,
    215         const float top,
    216         const float right,
    217         const float bottom)
    218 {
    219     return 0;
    220 }
    221 
    222 int32_t VideoRenderMacCocoaImpl::ConfigureRenderer(const uint32_t streamId,
    223                                                    const unsigned int zOrder,
    224                                                    const float left,
    225                                                    const float top,
    226                                                    const float right,
    227                                                    const float bottom)
    228 {
    229     return 0;
    230 }
    231 
    232 int32_t
    233 VideoRenderMacCocoaImpl::SetTransparentBackground(const bool enable)
    234 {
    235     return 0;
    236 }
    237 
    238 int32_t VideoRenderMacCocoaImpl::SetText(const uint8_t textId,
    239                                          const uint8_t* text,
    240                                          const int32_t textLength,
    241                                          const uint32_t textColorRef,
    242                                          const uint32_t backgroundColorRef,
    243                                          const float left,
    244                                          const float top,
    245                                          const float right,
    246                                          const float bottom)
    247 {
    248     return _ptrCocoaRender->SetText(textId, text, textLength, textColorRef, backgroundColorRef, left, top, right, bottom);
    249 }
    250 
    251 int32_t VideoRenderMacCocoaImpl::SetBitmap(const void* bitMap,
    252                                            const uint8_t pictureId,
    253                                            const void* colorKey,
    254                                            const float left,
    255                                            const float top,
    256                                            const float right,
    257                                            const float bottom)
    258 {
    259     return 0;
    260 }
    261 
    262 int32_t VideoRenderMacCocoaImpl::FullScreenRender(void* window, const bool enable)
    263 {
    264     return -1;
    265 }
    266 
    267 }  // namespace webrtc
    268 
    269 #endif // COCOA_RENDERING
    270