Home | History | Annotate | Download | only in windows
      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 #include "webrtc/modules/video_render/windows/video_render_windows_impl.h"
     13 
     14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
     15 #include "webrtc/system_wrappers/interface/trace.h"
     16 #ifdef DIRECT3D9_RENDERING
     17 #include "webrtc/modules/video_render/windows/video_render_direct3d9.h"
     18 #endif
     19 
     20 #include <tchar.h>
     21 
     22 namespace webrtc {
     23 
     24 VideoRenderWindowsImpl::VideoRenderWindowsImpl(const int32_t id,
     25     const VideoRenderType videoRenderType, void* window, const bool fullscreen)
     26     : _id(id),
     27       _renderWindowsCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
     28       _prtWindow(window),
     29       _fullscreen(fullscreen),
     30       _renderMethod(kVideoRenderWinD3D9),
     31       _ptrRendererWin(NULL) {
     32 }
     33 
     34 VideoRenderWindowsImpl::~VideoRenderWindowsImpl()
     35 {
     36     delete &_renderWindowsCritsect;
     37     if (_ptrRendererWin)
     38     {
     39         delete _ptrRendererWin;
     40         _ptrRendererWin = NULL;
     41     }
     42 }
     43 
     44 int32_t VideoRenderWindowsImpl::Init()
     45 {
     46     // Create the win renderer
     47     switch (_renderMethod)
     48     {
     49         case kVideoRenderWinD3D9:
     50         {
     51 #ifdef DIRECT3D9_RENDERING
     52             VideoRenderDirect3D9* ptrRenderer;
     53             ptrRenderer = new VideoRenderDirect3D9(NULL, (HWND) _prtWindow, _fullscreen);
     54             if (ptrRenderer == NULL)
     55             {
     56                 break;
     57             }
     58             _ptrRendererWin = reinterpret_cast<IVideoRenderWin*>(ptrRenderer);
     59 #else
     60             return NULL;
     61 #endif  //DIRECT3D9_RENDERING
     62         }
     63             break;
     64         default:
     65             break;
     66     }
     67 
     68     //Init renderer
     69     if (_ptrRendererWin)
     70         return _ptrRendererWin->Init();
     71     else
     72         return -1;
     73 }
     74 
     75 int32_t VideoRenderWindowsImpl::ChangeUniqueId(const int32_t id)
     76 {
     77     CriticalSectionScoped cs(&_renderWindowsCritsect);
     78     _id = id;
     79     return 0;
     80 }
     81 
     82 int32_t VideoRenderWindowsImpl::ChangeWindow(void* window)
     83 {
     84     CriticalSectionScoped cs(&_renderWindowsCritsect);
     85     if (!_ptrRendererWin)
     86     {
     87         return -1;
     88     }
     89     else
     90     {
     91         return _ptrRendererWin->ChangeWindow(window);
     92     }
     93 }
     94 
     95 VideoRenderCallback*
     96 VideoRenderWindowsImpl::AddIncomingRenderStream(const uint32_t streamId,
     97                                                 const uint32_t zOrder,
     98                                                 const float left,
     99                                                 const float top,
    100                                                 const float right,
    101                                                 const float bottom)
    102 {
    103     CriticalSectionScoped cs(&_renderWindowsCritsect);
    104     VideoRenderCallback* renderCallback = NULL;
    105 
    106     if (!_ptrRendererWin)
    107     {
    108     }
    109     else
    110     {
    111         renderCallback = _ptrRendererWin->CreateChannel(streamId, zOrder, left,
    112                                                         top, right, bottom);
    113     }
    114 
    115     return renderCallback;
    116 }
    117 
    118 int32_t VideoRenderWindowsImpl::DeleteIncomingRenderStream(
    119                                                                  const uint32_t streamId)
    120 {
    121     CriticalSectionScoped cs(&_renderWindowsCritsect);
    122     int32_t error = -1;
    123     if (!_ptrRendererWin)
    124     {
    125     }
    126     else
    127     {
    128         error = _ptrRendererWin->DeleteChannel(streamId);
    129     }
    130     return error;
    131 }
    132 
    133 int32_t VideoRenderWindowsImpl::GetIncomingRenderStreamProperties(
    134                                                                         const uint32_t streamId,
    135                                                                         uint32_t& zOrder,
    136                                                                         float& left,
    137                                                                         float& top,
    138                                                                         float& right,
    139                                                                         float& bottom) const
    140 {
    141     CriticalSectionScoped cs(&_renderWindowsCritsect);
    142     zOrder = 0;
    143     left = 0;
    144     top = 0;
    145     right = 0;
    146     bottom = 0;
    147 
    148     int32_t error = -1;
    149     if (!_ptrRendererWin)
    150     {
    151     }
    152     else
    153     {
    154         error = _ptrRendererWin->GetStreamSettings(streamId, 0, zOrder, left,
    155                                                    top, right, bottom);
    156     }
    157     return error;
    158 }
    159 
    160 int32_t VideoRenderWindowsImpl::StartRender()
    161 {
    162     CriticalSectionScoped cs(&_renderWindowsCritsect);
    163     int32_t error = -1;
    164     if (!_ptrRendererWin)
    165     {
    166     }
    167     else
    168     {
    169         error = _ptrRendererWin->StartRender();
    170     }
    171     return error;
    172 }
    173 
    174 int32_t VideoRenderWindowsImpl::StopRender()
    175 {
    176     CriticalSectionScoped cs(&_renderWindowsCritsect);
    177     int32_t error = -1;
    178     if (!_ptrRendererWin)
    179     {
    180     }
    181     else
    182     {
    183         error = _ptrRendererWin->StopRender();
    184     }
    185     return error;
    186 }
    187 
    188 VideoRenderType VideoRenderWindowsImpl::RenderType()
    189 {
    190     return kRenderWindows;
    191 }
    192 
    193 RawVideoType VideoRenderWindowsImpl::PerferedVideoType()
    194 {
    195     return kVideoI420;
    196 }
    197 
    198 bool VideoRenderWindowsImpl::FullScreen()
    199 {
    200     CriticalSectionScoped cs(&_renderWindowsCritsect);
    201     bool fullscreen = false;
    202     if (!_ptrRendererWin)
    203     {
    204     }
    205     else
    206     {
    207         fullscreen = _ptrRendererWin->IsFullScreen();
    208     }
    209     return fullscreen;
    210 }
    211 
    212 int32_t VideoRenderWindowsImpl::GetGraphicsMemory(
    213                                                         uint64_t& totalGraphicsMemory,
    214                                                         uint64_t& availableGraphicsMemory) const
    215 {
    216     if (_ptrRendererWin)
    217     {
    218         return _ptrRendererWin->GetGraphicsMemory(totalGraphicsMemory,
    219                                                   availableGraphicsMemory);
    220     }
    221 
    222     totalGraphicsMemory = 0;
    223     availableGraphicsMemory = 0;
    224     return -1;
    225 }
    226 
    227 int32_t VideoRenderWindowsImpl::GetScreenResolution(
    228                                                           uint32_t& screenWidth,
    229                                                           uint32_t& screenHeight) const
    230 {
    231     CriticalSectionScoped cs(&_renderWindowsCritsect);
    232     screenWidth = 0;
    233     screenHeight = 0;
    234     return 0;
    235 }
    236 
    237 uint32_t VideoRenderWindowsImpl::RenderFrameRate(
    238                                                        const uint32_t streamId)
    239 {
    240     CriticalSectionScoped cs(&_renderWindowsCritsect);
    241     return 0;
    242 }
    243 
    244 int32_t VideoRenderWindowsImpl::SetStreamCropping(
    245                                                         const uint32_t streamId,
    246                                                         const float left,
    247                                                         const float top,
    248                                                         const float right,
    249                                                         const float bottom)
    250 {
    251     CriticalSectionScoped cs(&_renderWindowsCritsect);
    252     int32_t error = -1;
    253     if (!_ptrRendererWin)
    254     {
    255     }
    256     else
    257     {
    258         error = _ptrRendererWin->SetCropping(streamId, 0, left, top, right,
    259                                              bottom);
    260     }
    261     return error;
    262 }
    263 
    264 int32_t VideoRenderWindowsImpl::ConfigureRenderer(
    265                                                         const uint32_t streamId,
    266                                                         const unsigned int zOrder,
    267                                                         const float left,
    268                                                         const float top,
    269                                                         const float right,
    270                                                         const float bottom)
    271 {
    272     CriticalSectionScoped cs(&_renderWindowsCritsect);
    273     int32_t error = -1;
    274     if (!_ptrRendererWin)
    275     {
    276     }
    277     else
    278     {
    279         error = _ptrRendererWin->ConfigureRenderer(streamId, 0, zOrder, left,
    280                                                    top, right, bottom);
    281     }
    282 
    283     return error;
    284 }
    285 
    286 int32_t VideoRenderWindowsImpl::SetTransparentBackground(
    287                                                                const bool enable)
    288 {
    289     CriticalSectionScoped cs(&_renderWindowsCritsect);
    290     int32_t error = -1;
    291     if (!_ptrRendererWin)
    292     {
    293     }
    294     else
    295     {
    296         error = _ptrRendererWin->SetTransparentBackground(enable);
    297     }
    298     return error;
    299 }
    300 
    301 int32_t VideoRenderWindowsImpl::SetText(
    302                                               const uint8_t textId,
    303                                               const uint8_t* text,
    304                                               const int32_t textLength,
    305                                               const uint32_t textColorRef,
    306                                               const uint32_t backgroundColorRef,
    307                                               const float left,
    308                                               const float top,
    309                                               const float right,
    310                                               const float bottom)
    311 {
    312     CriticalSectionScoped cs(&_renderWindowsCritsect);
    313     int32_t error = -1;
    314     if (!_ptrRendererWin)
    315     {
    316     }
    317     else
    318     {
    319         error = _ptrRendererWin->SetText(textId, text, textLength,
    320                                          textColorRef, backgroundColorRef,
    321                                          left, top, right, bottom);
    322     }
    323     return error;
    324 }
    325 
    326 int32_t VideoRenderWindowsImpl::SetBitmap(const void* bitMap,
    327                                           const uint8_t pictureId,
    328                                           const void* colorKey,
    329                                           const float left, const float top,
    330                                           const float right, const float bottom)
    331 {
    332     CriticalSectionScoped cs(&_renderWindowsCritsect);
    333     int32_t error = -1;
    334     if (!_ptrRendererWin)
    335     {
    336     }
    337     else
    338     {
    339         error = _ptrRendererWin->SetBitmap(bitMap, pictureId, colorKey, left,
    340                                            top, right, bottom);
    341     }
    342     return error;
    343 }
    344 
    345 }  // namespace webrtc
    346