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(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/interface/critical_section_wrapper.h"
     18 #include "webrtc/system_wrappers/interface/trace.h"
     19 
     20 namespace webrtc {
     21 
     22 VideoRenderMacCarbonImpl::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 
     36 VideoRenderMacCarbonImpl::~VideoRenderMacCarbonImpl()
     37 {
     38     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "Destructor %s:%d", __FUNCTION__, __LINE__);
     39     delete &_renderMacCarbonCritsect;
     40 }
     41 
     42 int32_t
     43 VideoRenderMacCarbonImpl::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 
     99 int32_t
    100 VideoRenderMacCarbonImpl::ChangeUniqueId(const int32_t id)
    101 {
    102     return -1;
    103 
    104     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
    105     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
    106     _id = id;
    107 
    108     if(_ptrCarbonRender)
    109     {
    110         _ptrCarbonRender->ChangeUniqueID(_id);
    111     }
    112 
    113     return 0;
    114 }
    115 
    116 int32_t
    117 VideoRenderMacCarbonImpl::ChangeWindow(void* window)
    118 {
    119     return -1;
    120     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
    121     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s changing ID to ", __FUNCTION__, window);
    122 
    123     if (window == NULL)
    124     {
    125         return -1;
    126     }
    127     _ptrWindow = window;
    128 
    129 
    130     _ptrWindow = window;
    131 
    132     return 0;
    133 }
    134 
    135 VideoRenderCallback*
    136 VideoRenderMacCarbonImpl::AddIncomingRenderStream(const uint32_t streamId,
    137         const uint32_t zOrder,
    138         const float left,
    139         const float top,
    140         const float right,
    141         const float bottom)
    142 {
    143 
    144     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
    145     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s", __FUNCTION__);
    146     VideoChannelAGL* AGLChannel = NULL;
    147 
    148     if(!_ptrWindow)
    149     {
    150     }
    151 
    152     if(!AGLChannel)
    153     {
    154         AGLChannel = _ptrCocoaRender->CreateNSGLChannel(streamId, zOrder, left, top, right, bottom);
    155     }
    156 
    157     return AGLChannel;
    158 
    159 }
    160 
    161 int32_t
    162 VideoRenderMacCarbonImpl::DeleteIncomingRenderStream(const uint32_t streamId)
    163 {
    164 
    165     WEBRTC_TRACE(kTraceDebug, kTraceVideoRenderer, _id, "%s:%d", __FUNCTION__, __LINE__);
    166     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
    167     _ptrCarbonRender->DeleteAGLChannel(streamId);
    168 
    169     return 0;
    170 }
    171 
    172 int32_t
    173 VideoRenderMacCarbonImpl::GetIncomingRenderStreamProperties(const uint32_t streamId,
    174         uint32_t& zOrder,
    175         float& left,
    176         float& top,
    177         float& right,
    178         float& bottom) const
    179 {
    180     return -1;
    181     return _ptrCarbonRender->GetChannelProperties(streamId, zOrder, left, top, right, bottom);
    182 }
    183 
    184 int32_t
    185 VideoRenderMacCarbonImpl::StartRender()
    186 {
    187     return _ptrCarbonRender->StartRender();
    188 }
    189 
    190 int32_t
    191 VideoRenderMacCarbonImpl::StopRender()
    192 {
    193     return _ptrCarbonRender->StopRender();
    194 }
    195 
    196 VideoRenderType
    197 VideoRenderMacCarbonImpl::RenderType()
    198 {
    199     return kRenderCarbon;
    200 }
    201 
    202 RawVideoType
    203 VideoRenderMacCarbonImpl::PerferedVideoType()
    204 {
    205     return kVideoI420;
    206 }
    207 
    208 bool
    209 VideoRenderMacCarbonImpl::FullScreen()
    210 {
    211     return false;
    212 }
    213 
    214 int32_t
    215 VideoRenderMacCarbonImpl::GetGraphicsMemory(uint64_t& totalGraphicsMemory,
    216         uint64_t& availableGraphicsMemory) const
    217 {
    218     totalGraphicsMemory = 0;
    219     availableGraphicsMemory = 0;
    220     return 0;
    221 }
    222 
    223 int32_t
    224 VideoRenderMacCarbonImpl::GetScreenResolution(uint32_t& screenWidth,
    225         uint32_t& screenHeight) const
    226 {
    227     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
    228     //NSScreen* mainScreen = [NSScreen mainScreen];
    229 
    230     //NSRect frame = [mainScreen frame];
    231 
    232     //screenWidth = frame.size.width;
    233     //screenHeight = frame.size.height;
    234     return 0;
    235 }
    236 
    237 uint32_t
    238 VideoRenderMacCarbonImpl::RenderFrameRate(const uint32_t streamId)
    239 {
    240     CriticalSectionScoped cs(&_renderMacCarbonCritsect);
    241     return 0;
    242 }
    243 
    244 int32_t
    245 VideoRenderMacCarbonImpl::SetStreamCropping(const uint32_t streamId,
    246         const float left,
    247         const float top,
    248         const float right,
    249         const float bottom)
    250 {
    251     return 0;
    252 }
    253 
    254 int32_t VideoRenderMacCarbonImpl::ConfigureRenderer(const uint32_t streamId,
    255                                                     const unsigned int zOrder,
    256                                                     const float left,
    257                                                     const float top,
    258                                                     const float right,
    259                                                     const float bottom)
    260 {
    261     return 0;
    262 }
    263 
    264 int32_t
    265 VideoRenderMacCarbonImpl::SetTransparentBackground(const bool enable)
    266 {
    267     return 0;
    268 }
    269 
    270 int32_t VideoRenderMacCarbonImpl::SetText(const uint8_t textId,
    271                                           const uint8_t* text,
    272                                           const int32_t textLength,
    273                                           const uint32_t textColorRef,
    274                                           const uint32_t backgroundColorRef,
    275                                           const float left,
    276                                           const float top,
    277                                           const float right,
    278                                           const float bottom)
    279 {
    280     return 0;
    281 }
    282 
    283 int32_t VideoRenderMacCarbonImpl::SetBitmap(const void* bitMap,
    284                                             const uint8_t pictureId,
    285                                             const void* colorKey,
    286                                             const float left,
    287                                             const float top,
    288                                             const float right,
    289                                             const float bottom)
    290 {
    291     return 0;
    292 }
    293 
    294 
    295 }  // namespace webrtc
    296 
    297 #endif // CARBON_RENDERING
    298