| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 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 #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_WINDOWS_VIDEO_RENDER_DIRECT3D9_H
_ | |
| 12 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_WINDOWS_VIDEO_RENDER_DIRECT3D9_H
_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/modules/video_render/windows/i_video_render_win.h" | |
| 17 | |
| 18 #include <d3d9.h> | |
| 19 #include <ddraw.h> | |
| 20 | |
| 21 #include <Map> | |
| 22 | |
| 23 // Added | |
| 24 #include "webrtc/base/platform_thread.h" | |
| 25 #include "webrtc/modules/video_render/video_render_defines.h" | |
| 26 | |
| 27 #pragma comment(lib, "d3d9.lib") // located in DirectX SDK | |
| 28 | |
| 29 namespace webrtc { | |
| 30 class CriticalSectionWrapper; | |
| 31 class EventTimerWrapper; | |
| 32 class Trace; | |
| 33 | |
| 34 class D3D9Channel: public VideoRenderCallback | |
| 35 { | |
| 36 public: | |
| 37 D3D9Channel(LPDIRECT3DDEVICE9 pd3DDevice, | |
| 38 CriticalSectionWrapper* critSect, Trace* trace); | |
| 39 | |
| 40 virtual ~D3D9Channel(); | |
| 41 | |
| 42 // Inherited from VideoRencerCallback, called from VideoAPI class. | |
| 43 // Called when the incomming frame size and/or number of streams in mix chan
ges | |
| 44 virtual int FrameSizeChange(int width, int height, int numberOfStreams); | |
| 45 | |
| 46 // A new frame is delivered. | |
| 47 virtual int DeliverFrame(const VideoFrame& videoFrame); | |
| 48 virtual int32_t RenderFrame(const uint32_t streamId, | |
| 49 const VideoFrame& videoFrame); | |
| 50 | |
| 51 // Called to check if the video frame is updated. | |
| 52 int IsUpdated(bool& isUpdated); | |
| 53 // Called after the video frame has been render to the screen | |
| 54 int RenderOffFrame(); | |
| 55 // Called to get the texture that contains the video frame | |
| 56 LPDIRECT3DTEXTURE9 GetTexture(); | |
| 57 // Called to get the texture(video frame) size | |
| 58 int GetTextureWidth(); | |
| 59 int GetTextureHeight(); | |
| 60 // | |
| 61 void SetStreamSettings(uint16_t streamId, | |
| 62 uint32_t zOrder, | |
| 63 float startWidth, | |
| 64 float startHeight, | |
| 65 float stopWidth, | |
| 66 float stopHeight); | |
| 67 int GetStreamSettings(uint16_t streamId, | |
| 68 uint32_t& zOrder, | |
| 69 float& startWidth, | |
| 70 float& startHeight, | |
| 71 float& stopWidth, | |
| 72 float& stopHeight); | |
| 73 | |
| 74 int ReleaseTexture(); | |
| 75 int RecreateTexture(LPDIRECT3DDEVICE9 pd3DDevice); | |
| 76 | |
| 77 protected: | |
| 78 | |
| 79 private: | |
| 80 //critical section passed from the owner | |
| 81 CriticalSectionWrapper* _critSect; | |
| 82 LPDIRECT3DDEVICE9 _pd3dDevice; | |
| 83 LPDIRECT3DTEXTURE9 _pTexture; | |
| 84 | |
| 85 bool _bufferIsUpdated; | |
| 86 // the frame size | |
| 87 int _width; | |
| 88 int _height; | |
| 89 //sream settings | |
| 90 //TODO support multiple streams in one channel | |
| 91 uint16_t _streamId; | |
| 92 uint32_t _zOrder; | |
| 93 float _startWidth; | |
| 94 float _startHeight; | |
| 95 float _stopWidth; | |
| 96 float _stopHeight; | |
| 97 }; | |
| 98 | |
| 99 class VideoRenderDirect3D9: IVideoRenderWin | |
| 100 { | |
| 101 public: | |
| 102 VideoRenderDirect3D9(Trace* trace, HWND hWnd, bool fullScreen); | |
| 103 ~VideoRenderDirect3D9(); | |
| 104 | |
| 105 public: | |
| 106 //IVideoRenderWin | |
| 107 | |
| 108 /************************************************************************** | |
| 109 * | |
| 110 * Init | |
| 111 * | |
| 112 ***************************************************************************
/ | |
| 113 virtual int32_t Init(); | |
| 114 | |
| 115 /************************************************************************** | |
| 116 * | |
| 117 * Incoming Streams | |
| 118 * | |
| 119 ***************************************************************************
/ | |
| 120 virtual VideoRenderCallback | |
| 121 * CreateChannel(const uint32_t streamId, | |
| 122 const uint32_t zOrder, | |
| 123 const float left, | |
| 124 const float top, | |
| 125 const float right, | |
| 126 const float bottom); | |
| 127 | |
| 128 virtual int32_t DeleteChannel(const uint32_t streamId); | |
| 129 | |
| 130 virtual int32_t GetStreamSettings(const uint32_t channel, | |
| 131 const uint16_t streamId, | |
| 132 uint32_t& zOrder, | |
| 133 float& left, float& top, | |
| 134 float& right, float& bottom); | |
| 135 | |
| 136 /************************************************************************** | |
| 137 * | |
| 138 * Start/Stop | |
| 139 * | |
| 140 ***************************************************************************
/ | |
| 141 | |
| 142 virtual int32_t StartRender(); | |
| 143 virtual int32_t StopRender(); | |
| 144 | |
| 145 /************************************************************************** | |
| 146 * | |
| 147 * Properties | |
| 148 * | |
| 149 ***************************************************************************
/ | |
| 150 | |
| 151 virtual bool IsFullScreen(); | |
| 152 | |
| 153 virtual int32_t SetCropping(const uint32_t channel, | |
| 154 const uint16_t streamId, | |
| 155 const float left, const float top, | |
| 156 const float right, const float bottom); | |
| 157 | |
| 158 virtual int32_t ConfigureRenderer(const uint32_t channel, | |
| 159 const uint16_t streamId, | |
| 160 const unsigned int zOrder, | |
| 161 const float left, const float top, | |
| 162 const float right, const float bottom); | |
| 163 | |
| 164 virtual int32_t SetTransparentBackground(const bool enable); | |
| 165 | |
| 166 virtual int32_t ChangeWindow(void* window); | |
| 167 | |
| 168 virtual int32_t GetGraphicsMemory(uint64_t& totalMemory, | |
| 169 uint64_t& availableMemory); | |
| 170 | |
| 171 virtual int32_t SetText(const uint8_t textId, | |
| 172 const uint8_t* text, | |
| 173 const int32_t textLength, | |
| 174 const uint32_t colorText, | |
| 175 const uint32_t colorBg, | |
| 176 const float left, const float top, | |
| 177 const float rigth, const float bottom); | |
| 178 | |
| 179 virtual int32_t SetBitmap(const void* bitMap, | |
| 180 const uint8_t pictureId, | |
| 181 const void* colorKey, | |
| 182 const float left, const float top, | |
| 183 const float right, const float bottom); | |
| 184 | |
| 185 public: | |
| 186 // Get a channel by channel id | |
| 187 D3D9Channel* GetD3DChannel(int channel); | |
| 188 int UpdateRenderSurface(); | |
| 189 | |
| 190 protected: | |
| 191 // The thread rendering the screen | |
| 192 static bool ScreenUpdateThreadProc(void* obj); | |
| 193 bool ScreenUpdateProcess(); | |
| 194 | |
| 195 private: | |
| 196 // Init/close the d3d device | |
| 197 int InitDevice(); | |
| 198 int CloseDevice(); | |
| 199 | |
| 200 // Transparent related functions | |
| 201 int SetTransparentColor(LPDIRECT3DTEXTURE9 pTexture, | |
| 202 DDCOLORKEY* transparentColorKey, | |
| 203 DWORD width, | |
| 204 DWORD height); | |
| 205 | |
| 206 CriticalSectionWrapper& _refD3DCritsect; | |
| 207 Trace* _trace; | |
| 208 // TODO(pbos): Remove unique_ptr and use PlatformThread directly. | |
| 209 std::unique_ptr<rtc::PlatformThread> _screenUpdateThread; | |
| 210 EventTimerWrapper* _screenUpdateEvent; | |
| 211 | |
| 212 HWND _hWnd; | |
| 213 bool _fullScreen; | |
| 214 RECT _originalHwndRect; | |
| 215 //FIXME we probably don't need this since all the information can be get fro
m _d3dChannels | |
| 216 int _channel; | |
| 217 //Window size | |
| 218 UINT _winWidth; | |
| 219 UINT _winHeight; | |
| 220 | |
| 221 // Device | |
| 222 LPDIRECT3D9 _pD3D; // Used to create the D3DDevice | |
| 223 LPDIRECT3DDEVICE9 _pd3dDevice; // Our rendering device | |
| 224 LPDIRECT3DVERTEXBUFFER9 _pVB; // Buffer to hold Vertices | |
| 225 LPDIRECT3DTEXTURE9 _pTextureLogo; | |
| 226 | |
| 227 std::map<int, D3D9Channel*> _d3dChannels; | |
| 228 std::multimap<int, unsigned int> _d3dZorder; | |
| 229 | |
| 230 // The position where the logo will be placed | |
| 231 float _logoLeft; | |
| 232 float _logoTop; | |
| 233 float _logoRight; | |
| 234 float _logoBottom; | |
| 235 | |
| 236 typedef HRESULT (WINAPI *DIRECT3DCREATE9EX)(UINT SDKVersion, IDirect3D9Ex**)
; | |
| 237 LPDIRECT3DSURFACE9 _pd3dSurface; | |
| 238 | |
| 239 DWORD GetVertexProcessingCaps(); | |
| 240 int InitializeD3D(HWND hWnd, D3DPRESENT_PARAMETERS* pd3dpp); | |
| 241 | |
| 242 D3DPRESENT_PARAMETERS _d3dpp; | |
| 243 int ResetDevice(); | |
| 244 | |
| 245 int UpdateVerticeBuffer(LPDIRECT3DVERTEXBUFFER9 pVB, int offset, | |
| 246 float startWidth, float startHeight, | |
| 247 float stopWidth, float stopHeight); | |
| 248 | |
| 249 //code for providing graphics settings | |
| 250 DWORD _totalMemory; | |
| 251 DWORD _availableMemory; | |
| 252 }; | |
| 253 | |
| 254 } // namespace webrtc | |
| 255 | |
| 256 #endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_WINDOWS_VIDEO_RENDER_DIRECT3D9
_H_ | |
| OLD | NEW |