1ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org/*
2ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *
4ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *  Use of this source code is governed by a BSD-style license
5ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *  that can be found in the LICENSE file in the root of the source
6ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *  tree. An additional intellectual property rights grant can be found
7ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *  in the file PATENTS.  All contributing project authors may
8ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org */
10ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
11ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include <assert.h>
12ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
136f8ce060a21fcdc1c951fbf06768eb0cc0083b2fkjellander#include "webrtc/common_video/include/incoming_video_stream.h"
14ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/engine_configurations.h"
15ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/i_video_render.h"
165dda80abea311731144b1d544aff61c408412f12Henrik Kjellander#include "webrtc/modules/video_render/video_render_defines.h"
17ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/video_render_impl.h"
1898f53510b222f71fdd8b799b2f33737ceeb28c61Henrik Kjellander#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
1998f53510b222f71fdd8b799b2f33737ceeb28c61Henrik Kjellander#include "webrtc/system_wrappers/include/trace.h"
20ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
21ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined (_WIN32)
22ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/windows/video_render_windows_impl.h"
23ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderWindows
24ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
25ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org// WEBRTC_IOS should go before WEBRTC_MAC because WEBRTC_MAC
26ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org// gets defined if WEBRTC_IOS is defined
27ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_IOS)
28ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderiOS
29ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/ios/video_render_ios_impl.h"
30ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_MAC)
31ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(COCOA_RENDERING)
32ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderCocoa
33ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/mac/video_render_mac_cocoa_impl.h"
34ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(CARBON_RENDERING)
35ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderCarbon
36ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/mac/video_render_mac_carbon_impl.h"
37ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
38ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
39ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_ANDROID)
40ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/android/video_render_android_impl.h"
41ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/android/video_render_android_native_opengl2.h"
42ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/android/video_render_android_surface_view.h"
43ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderAndroid
44ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
45ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_LINUX)
46ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/linux/video_render_linux_impl.h"
47ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderX11
48ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
49ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#else
50ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org//Other platforms
51ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
52ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
53ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org// For external rendering
54ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#include "webrtc/modules/video_render/external/video_render_external_impl.h"
55ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#ifndef STANDARD_RENDERING
56ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#define STANDARD_RENDERING kRenderExternal
57ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif  // STANDARD_RENDERING
58ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
59ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgnamespace webrtc {
60ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
61ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgVideoRender*
62ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgVideoRender::CreateVideoRender(const int32_t id,
63ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                               void* window,
64ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                               const bool fullscreen,
65ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                               const VideoRenderType videoRenderType/*=kRenderDefault*/)
66ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
67ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderType resultVideoRenderType = videoRenderType;
68ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (videoRenderType == kRenderDefault)
69ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
70ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        resultVideoRenderType = STANDARD_RENDERING;
71ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
72ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return new ModuleVideoRenderImpl(id, resultVideoRenderType, window,
73ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                     fullscreen);
74ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
75ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
76ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgvoid VideoRender::DestroyVideoRender(
77ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                         VideoRender* module)
78ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
79ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (module)
80ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
81ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        delete module;
82ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
83ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
84ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
85ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgModuleVideoRenderImpl::ModuleVideoRenderImpl(
86ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const int32_t id,
87ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const VideoRenderType videoRenderType,
88ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             void* window,
89ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const bool fullscreen) :
90ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _id(id), _moduleCrit(*CriticalSectionWrapper::CreateCriticalSection()),
91ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _ptrWindow(window), _fullScreen(fullscreen), _ptrRenderer(NULL)
92ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
93ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
94ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Create platform specific renderer
95ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    switch (videoRenderType)
96ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
97ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(_WIN32)
98ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderWindows:
99ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
100ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            VideoRenderWindowsImpl* ptrRenderer;
101ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            ptrRenderer = new VideoRenderWindowsImpl(_id, videoRenderType, window, _fullScreen);
102ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if (ptrRenderer)
103ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
104ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = reinterpret_cast<IVideoRender*>(ptrRenderer);
105ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
106ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
107ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        break;
108ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
109ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_IOS)
110ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderiOS:
111ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
112ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            VideoRenderIosImpl* ptrRenderer = new VideoRenderIosImpl(_id, window, _fullScreen);
113ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if(ptrRenderer)
114ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
115ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = reinterpret_cast<IVideoRender*>(ptrRenderer);
116ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
117ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
118ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        break;
119ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
120ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_MAC)
121ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
122ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(COCOA_RENDERING)
123ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderCocoa:
124ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
125ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            VideoRenderMacCocoaImpl* ptrRenderer = new VideoRenderMacCocoaImpl(_id, videoRenderType, window, _fullScreen);
126ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if(ptrRenderer)
127ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
128ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = reinterpret_cast<IVideoRender*>(ptrRenderer);
129ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
130ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
131ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
132ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        break;
133ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(CARBON_RENDERING)
134ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderCarbon:
135ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
136ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            VideoRenderMacCarbonImpl* ptrRenderer = new VideoRenderMacCarbonImpl(_id, videoRenderType, window, _fullScreen);
137ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if(ptrRenderer)
138ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
139ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = reinterpret_cast<IVideoRender*>(ptrRenderer);
140ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
141ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
142ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        break;
143ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
144ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
145ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_ANDROID)
146ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderAndroid:
147ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
148ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if(AndroidNativeOpenGl2Renderer::UseOpenGL2(window))
149ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
150ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                AndroidNativeOpenGl2Renderer* ptrRenderer = NULL;
151ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                ptrRenderer = new AndroidNativeOpenGl2Renderer(_id, videoRenderType, window, _fullScreen);
152ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                if (ptrRenderer)
153ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                {
154ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                    _ptrRenderer = reinterpret_cast<IVideoRender*> (ptrRenderer);
155ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                }
156ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
157ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            else
158ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
159ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                AndroidSurfaceViewRenderer* ptrRenderer = NULL;
160ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                ptrRenderer = new AndroidSurfaceViewRenderer(_id, videoRenderType, window, _fullScreen);
161ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                if (ptrRenderer)
162ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                {
163ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                    _ptrRenderer = reinterpret_cast<IVideoRender*> (ptrRenderer);
164ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                }
165ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
166ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
167ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
168ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        break;
169ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_LINUX)
170ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderX11:
171ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
172ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            VideoRenderLinuxImpl* ptrRenderer = NULL;
173ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            ptrRenderer = new VideoRenderLinuxImpl(_id, videoRenderType, window, _fullScreen);
174ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if ( ptrRenderer )
175ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
176ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = reinterpret_cast<IVideoRender*> (ptrRenderer);
177ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
178ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
179ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        break;
180ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
181ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#else
182ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        // Other platforms
183ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
184ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        case kRenderExternal:
185ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
186ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            VideoRenderExternalImpl* ptrRenderer(NULL);
187ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            ptrRenderer = new VideoRenderExternalImpl(_id, videoRenderType,
188ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                      window, _fullScreen);
189ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            if (ptrRenderer)
190ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
191ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = reinterpret_cast<IVideoRender*> (ptrRenderer);
192ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
193ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
194ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
195ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        default:
196ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            // Error...
197ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
198ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
199ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (_ptrRenderer)
200ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
201ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        if (_ptrRenderer->Init() == -1)
202ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
203ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
204ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
205ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
206ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
207ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgModuleVideoRenderImpl::~ModuleVideoRenderImpl()
208ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
209ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    delete &_moduleCrit;
210ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
211ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    for (IncomingVideoStreamMap::iterator it = _streamRenderMap.begin();
212ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org         it != _streamRenderMap.end();
213ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org         ++it) {
214ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org      delete it->second;
215ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
216ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
217ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Delete platform specific renderer
218ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (_ptrRenderer)
219ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
220ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        VideoRenderType videoRenderType = _ptrRenderer->RenderType();
221ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
222ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        switch (videoRenderType)
223ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        {
224ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderExternal:
225ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
226ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                VideoRenderExternalImpl
227ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                        * ptrRenderer =
228ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                reinterpret_cast<VideoRenderExternalImpl*> (_ptrRenderer);
229ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = NULL;
230ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                delete ptrRenderer;
231ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
232ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
233ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(_WIN32)
234ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderWindows:
235ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
236ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                VideoRenderWindowsImpl* ptrRenderer = reinterpret_cast<VideoRenderWindowsImpl*>(_ptrRenderer);
237ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = NULL;
238ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                delete ptrRenderer;
239ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
240ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
241ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_IOS)
242ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderiOS:
243ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
244ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org              VideoRenderIosImpl* ptrRenderer = reinterpret_cast<VideoRenderIosImpl*> (_ptrRenderer);
245ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org              _ptrRenderer = NULL;
246ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org              delete ptrRenderer;
247ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
248ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
249ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_MAC)
250ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
251ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(COCOA_RENDERING)
252ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderCocoa:
253ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
254ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                VideoRenderMacCocoaImpl* ptrRenderer = reinterpret_cast<VideoRenderMacCocoaImpl*> (_ptrRenderer);
255ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = NULL;
256ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                delete ptrRenderer;
257ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
258ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
259ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(CARBON_RENDERING)
260ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderCarbon:
261ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
262ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                VideoRenderMacCarbonImpl* ptrRenderer = reinterpret_cast<VideoRenderMacCarbonImpl*> (_ptrRenderer);
263ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = NULL;
264ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                delete ptrRenderer;
265ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
266ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
267ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
268ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
269ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_ANDROID)
270ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderAndroid:
271ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
272ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                VideoRenderAndroid* ptrRenderer = reinterpret_cast<VideoRenderAndroid*> (_ptrRenderer);
273ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = NULL;
274ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                delete ptrRenderer;
275ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
276ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
277ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
278ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_LINUX)
279ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            case kRenderX11:
280ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            {
281ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                VideoRenderLinuxImpl* ptrRenderer = reinterpret_cast<VideoRenderLinuxImpl*> (_ptrRenderer);
282ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                _ptrRenderer = NULL;
283ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                delete ptrRenderer;
284ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            }
285ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            break;
286ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#else
287ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            //other platforms
288ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
289ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
290ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            default:
291ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                // Error...
292ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                break;
293ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        }
294ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
295ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
296ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
2970b1534c52eab79372557a6d81aaf4dd9407f55d3pkasting@chromium.orgint64_t ModuleVideoRenderImpl::TimeUntilNextProcess()
298ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
299ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Not used
300ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return 50;
301ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
302ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::Process()
303ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
304ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Not used
305ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return 0;
306ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
307ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
308ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgvoid*
309ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgModuleVideoRenderImpl::Window()
310ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
311ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
312ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrWindow;
313ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
314ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
315ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::ChangeWindow(void* window)
316ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
317ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
318ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
319ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
320ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(WEBRTC_IOS) // WEBRTC_IOS must go before WEBRTC_MAC
321ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _ptrRenderer = NULL;
322ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    delete _ptrRenderer;
323ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
324ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderIosImpl* ptrRenderer;
325ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    ptrRenderer = new VideoRenderIosImpl(_id, window, _fullScreen);
326ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!ptrRenderer)
327ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
328ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
329ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
330ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _ptrRenderer = reinterpret_cast<IVideoRender*>(ptrRenderer);
331ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->ChangeWindow(window);
332ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(WEBRTC_MAC)
333ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
334ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _ptrRenderer = NULL;
335ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    delete _ptrRenderer;
336ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
337ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#if defined(COCOA_RENDERING)
338ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderMacCocoaImpl* ptrRenderer;
339ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    ptrRenderer = new VideoRenderMacCocoaImpl(_id, kRenderCocoa, window, _fullScreen);
340ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#elif defined(CARBON_RENDERING)
341ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderMacCarbonImpl* ptrRenderer;
342ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    ptrRenderer = new VideoRenderMacCarbonImpl(_id, kRenderCarbon, window, _fullScreen);
343ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
344ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!ptrRenderer)
345ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
346ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
347ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
348ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _ptrRenderer = reinterpret_cast<IVideoRender*>(ptrRenderer);
349ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->ChangeWindow(window);
350ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
351ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#else
352ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
353ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
354ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
355ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
356ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
357ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
358ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->ChangeWindow(window);
359ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
360ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org#endif
361ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
362ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
363ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::Id()
364ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
365ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
366ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _id;
367ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
368ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
369ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orguint32_t ModuleVideoRenderImpl::GetIncomingFrameRate(const uint32_t streamId) {
370ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  CriticalSectionScoped cs(&_moduleCrit);
371ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
372ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  IncomingVideoStreamMap::iterator it = _streamRenderMap.find(streamId);
373ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
374ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  if (it == _streamRenderMap.end()) {
375ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // This stream doesn't exist
376ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    WEBRTC_TRACE(kTraceError,
377ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 kTraceVideoRenderer,
378ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 _id,
379ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 "%s: stream doesn't exist",
380ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 __FUNCTION__);
381ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return 0;
382ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  }
383ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  assert(it->second != NULL);
384ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  return it->second->IncomingRate();
385ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
386ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
387ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgVideoRenderCallback*
388ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgModuleVideoRenderImpl::AddIncomingRenderStream(const uint32_t streamId,
389ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                               const uint32_t zOrder,
390ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                               const float left,
391ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                               const float top,
392ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                               const float right,
393ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                               const float bottom)
394ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
395ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
396ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
397ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
398ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
399ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
400ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
401ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return NULL;
402ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
403ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
404ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (_streamRenderMap.find(streamId) != _streamRenderMap.end()) {
405ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        // The stream already exists...
406ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
407ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: stream already exists", __FUNCTION__);
408ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return NULL;
409ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
410ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
411ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderCallback* ptrRenderCallback =
412ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org            _ptrRenderer->AddIncomingRenderStream(streamId, zOrder, left, top,
413ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                  right, bottom);
414ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (ptrRenderCallback == NULL)
415ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
416ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
417ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: Can't create incoming stream in renderer",
418ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     __FUNCTION__);
419ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return NULL;
420ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
421ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
422ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Create platform independant code
423444682acf9804c5fcbddaded9e900ba3cc6921fcqiangchen    IncomingVideoStream* ptrIncomingStream =
424444682acf9804c5fcbddaded9e900ba3cc6921fcqiangchen        new IncomingVideoStream(streamId, false);
425c043afc60534786c88d0cf0f1a96c70a50df87b1Peter Boström    ptrIncomingStream->SetRenderCallback(ptrRenderCallback);
426c043afc60534786c88d0cf0f1a96c70a50df87b1Peter Boström    VideoRenderCallback* moduleCallback = ptrIncomingStream->ModuleCallback();
427ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
428ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Store the stream
429ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _streamRenderMap[streamId] = ptrIncomingStream;
430ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
431ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return moduleCallback;
432ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
433ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
434ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::DeleteIncomingRenderStream(
435ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                                const uint32_t streamId)
436ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
437ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
438ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
439ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
440ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
441ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
442ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
443ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
444ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
445ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
446ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId);
447ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item == _streamRenderMap.end())
448ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
449ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
450ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: stream doesn't exist", __FUNCTION__);
451ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
452ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
453ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
454ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    delete item->second;
455ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
456ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _ptrRenderer->DeleteIncomingRenderStream(streamId);
457ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
458ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    _streamRenderMap.erase(item);
459ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
460ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return 0;
461ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
462ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
463ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::AddExternalRenderCallback(
464ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    const uint32_t streamId,
465ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderCallback* renderObject) {
466ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
467ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
468ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId);
469ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
470ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item == _streamRenderMap.end())
471ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
472ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
473ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: stream doesn't exist", __FUNCTION__);
474ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
475ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
476ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
477ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item->second == NULL) {
478ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
479ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: could not get stream", __FUNCTION__);
480ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
481ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
482c043afc60534786c88d0cf0f1a96c70a50df87b1Peter Boström    item->second->SetExternalCallback(renderObject);
483c043afc60534786c88d0cf0f1a96c70a50df87b1Peter Boström    return 0;
484ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
485ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
486ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::GetIncomingRenderStreamProperties(
487ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    const uint32_t streamId,
488ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    uint32_t& zOrder,
489ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    float& left,
490ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    float& top,
491ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    float& right,
492ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    float& bottom) const {
493ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
494ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
495ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
496ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
497ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
498ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
499ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
500ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
501ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
502ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->GetIncomingRenderStreamProperties(streamId, zOrder,
503ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                           left, top, right,
504ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                           bottom);
505ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
506ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
507ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orguint32_t ModuleVideoRenderImpl::GetNumIncomingRenderStreams() const
508ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
509ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
510ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
511ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return static_cast<uint32_t>(_streamRenderMap.size());
512ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
513ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
514ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgbool ModuleVideoRenderImpl::HasIncomingRenderStream(
515ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    const uint32_t streamId) const {
516ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  CriticalSectionScoped cs(&_moduleCrit);
517ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
518ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  return _streamRenderMap.find(streamId) != _streamRenderMap.end();
519ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
520ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
521ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::RegisterRawFrameCallback(
522ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    const uint32_t streamId,
523ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    VideoRenderCallback* callbackObj) {
524ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  return -1;
525ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
526ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
527ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::StartRender(const uint32_t streamId)
528ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
529ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
530ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
531ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
532ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
533ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
534ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
535ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
536ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
537ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
538ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Start the stream
539ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId);
540ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
541ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item == _streamRenderMap.end())
542ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
543ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
544ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
545ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
546ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item->second->Start() == -1)
547ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
548ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
549ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
550ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
551ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Start the HW renderer
552ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (_ptrRenderer->StartRender() == -1)
553ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
554ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
555ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
556ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return 0;
557ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
558ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
559ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::StopRender(const uint32_t streamId)
560ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
561ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
562ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
563ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
564ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
565ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
566ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s(%d): No renderer", __FUNCTION__, streamId);
567ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
568ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
569ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
570ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Stop the incoming stream
571ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    IncomingVideoStreamMap::iterator item = _streamRenderMap.find(streamId);
572ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
573ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item == _streamRenderMap.end())
574ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
575ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
576ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
577ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
578ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item->second->Stop() == -1)
579ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
580ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
581ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
582ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
583ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return 0;
584ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
585ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
586ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::ResetRender()
587ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
588ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
589ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
590ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    int32_t ret = 0;
591ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // Loop through all incoming streams and reset them
592ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    for (IncomingVideoStreamMap::iterator it = _streamRenderMap.begin();
593ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org         it != _streamRenderMap.end();
594ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org         ++it) {
595ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org      if (it->second->Reset() == -1)
596ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        ret = -1;
597ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
598ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return ret;
599ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
600ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
601ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgRawVideoType ModuleVideoRenderImpl::PreferredVideoType() const
602ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
603ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
604ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
605ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (_ptrRenderer == NULL)
606ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
607ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return kVideoI420;
608ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
609ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
610ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->PerferedVideoType();
611ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
612ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
613ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgbool ModuleVideoRenderImpl::IsFullScreen()
614ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
615ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
616ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
617ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
618ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
619ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
620ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
621ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return false;
622ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
623ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->FullScreen();
624ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
625ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
626ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::GetScreenResolution(
627ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                         uint32_t& screenWidth,
628ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                         uint32_t& screenHeight) const
629ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
630ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
631ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
632ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
633ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
634ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
635ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
636ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return false;
637ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
638ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->GetScreenResolution(screenWidth, screenHeight);
639ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
640ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
641ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orguint32_t ModuleVideoRenderImpl::RenderFrameRate(
642ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                      const uint32_t streamId)
643ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
644ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
645ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
646ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
647ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
648ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
649ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
650ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return false;
651ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
652ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->RenderFrameRate(streamId);
653ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
654ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
655ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::SetStreamCropping(
656ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const uint32_t streamId,
657ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float left,
658ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float top,
659ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float right,
660ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float bottom)
661ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
662ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
663ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
664ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
665ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
666ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
667ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
668ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return false;
669ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
670ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->SetStreamCropping(streamId, left, top, right, bottom);
671ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
672ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
673ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::SetTransparentBackground(const bool enable)
674ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
675ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
676ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
677ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
678ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
679ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
680ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
681ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return false;
682ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
683ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->SetTransparentBackground(enable);
684ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
685ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
686ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::FullScreenRender(void* window, const bool enable)
687ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
688ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return -1;
689ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
690ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
691ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::SetText(
692ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const uint8_t textId,
693ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const uint8_t* text,
694ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const int32_t textLength,
695ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const uint32_t textColorRef,
696ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const uint32_t backgroundColorRef,
697ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const float left, const float top,
698ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const float right,
699ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                             const float bottom)
700ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
701ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
702ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
703ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
704ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
705ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
706ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
707ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
708ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
709ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->SetText(textId, text, textLength, textColorRef,
710ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                 backgroundColorRef, left, top, right, bottom);
711ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
712ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
713ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::SetBitmap(const void* bitMap,
714ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                         const uint8_t pictureId,
715ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                         const void* colorKey,
716ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                         const float left,
717ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                         const float top,
718ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                         const float right,
719ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                         const float bottom)
720ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
721ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
722ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
723ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
724ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
725ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
726ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
727ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
728ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
729ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->SetBitmap(bitMap, pictureId, colorKey, left, top,
730ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                   right, bottom);
731ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
732ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
733ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::SetExpectedRenderDelay(
734ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    uint32_t stream_id, int32_t delay_ms) {
735ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  CriticalSectionScoped cs(&_moduleCrit);
736ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
737ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  if (!_ptrRenderer) {
738ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
739ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 "%s: No renderer", __FUNCTION__);
740ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return false;
741ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  }
742ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
743ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  IncomingVideoStreamMap::const_iterator item =
744ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org      _streamRenderMap.find(stream_id);
745ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  if (item == _streamRenderMap.end()) {
746ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    // This stream doesn't exist
747ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
748ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 "%s(%u, %d): stream doesn't exist", __FUNCTION__, stream_id,
749ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                 delay_ms);
750ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return -1;
751ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  }
752ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
753ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  assert(item->second != NULL);
754ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org  return item->second->SetExpectedRenderDelay(delay_ms);
755ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
756ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
757ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.orgint32_t ModuleVideoRenderImpl::ConfigureRenderer(
758ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const uint32_t streamId,
759ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const unsigned int zOrder,
760ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float left,
761ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float top,
762ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float right,
763ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                                       const float bottom)
764ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org{
765ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
766ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
767ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
768ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
769ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
770ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
771ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return false;
772ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
773ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return _ptrRenderer->ConfigureRenderer(streamId, zOrder, left, top, right,
774ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                                           bottom);
775ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
776ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
7774765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchezint32_t ModuleVideoRenderImpl::SetStartImage(const uint32_t streamId,
7784765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez                                             const VideoFrame& videoFrame) {
779ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
780ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
781ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
782ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
783ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
784ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
785ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
786ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
787ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
788ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    IncomingVideoStreamMap::const_iterator item =
789ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        _streamRenderMap.find(streamId);
790ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item == _streamRenderMap.end())
791ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
792ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        // This stream doesn't exist
793ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
794ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: stream doesn't exist", __FUNCTION__);
795ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
796ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
797ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    assert (item->second != NULL);
798ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return item->second->SetStartImage(videoFrame);
799ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
800ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
801ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
8024765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchezint32_t ModuleVideoRenderImpl::SetTimeoutImage(const uint32_t streamId,
8034765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez                                               const VideoFrame& videoFrame,
8044765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez                                               const uint32_t timeout) {
805ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    CriticalSectionScoped cs(&_moduleCrit);
806ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
807ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (!_ptrRenderer)
808ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
809ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
810ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: No renderer", __FUNCTION__);
811ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
812ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
813ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
814ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    IncomingVideoStreamMap::const_iterator item =
815ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        _streamRenderMap.find(streamId);
816ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    if (item == _streamRenderMap.end())
817ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    {
818ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        // This stream doesn't exist
819ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id,
820ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org                     "%s: stream doesn't exist", __FUNCTION__);
821ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org        return -1;
822ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    }
823ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    assert(item->second != NULL);
824ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org    return item->second->SetTimeoutImage(videoFrame, timeout);
825ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}
826ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org
827ab071daab89462db77158e637ba059dba8c9ece7andresp@webrtc.org}  // namespace webrtc
828