Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
RenderCapture.h
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "AddonClass.h"
12#include "Exception.h"
13#include "ServiceBroker.h"
14#include "application/ApplicationComponents.h"
15#include "application/ApplicationPlayer.h"
16#include "commons/Buffer.h"
17
18#include <climits>
19
20namespace XBMCAddon
21{
22 namespace xbmc
23 {
24 XBMCCOMMONS_STANDARD_EXCEPTION(RenderCaptureException);
25
26 //
37 //
38 class RenderCapture : public AddonClass
39 {
40 unsigned int m_captureId;
41 unsigned int m_width;
42 unsigned int m_height;
43 uint8_t *m_buffer;
44
45 public:
46 inline RenderCapture()
47 {
48 m_captureId = UINT_MAX;
49 m_buffer = nullptr;
50 m_width = 0;
51 m_height = 0;
52 }
53 inline ~RenderCapture() override
54 {
55 auto& components = CServiceBroker::GetAppComponents();
56 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
57 appPlayer->RenderCaptureRelease(m_captureId);
58 delete [] m_buffer;
59 }
60
61#ifdef DOXYGEN_SHOULD_USE_THIS
73#else
74 inline int getWidth() { return m_width; }
75#endif
76
77#ifdef DOXYGEN_SHOULD_USE_THIS
88#else
89 inline int getHeight() { return m_height; }
90#endif
91
92#ifdef DOXYGEN_SHOULD_USE_THIS
102#else
103 inline float getAspectRatio()
104 {
105 const auto& components = CServiceBroker::GetAppComponents();
106 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
107 return appPlayer->GetRenderAspectRatio();
108 }
109#endif
110
111#ifdef DOXYGEN_SHOULD_USE_THIS
124#else
125 inline const char* getImageFormat()
126#endif
127 {
128 return "BGRA";
129 }
130
131#ifdef DOXYGEN_SHOULD_USE_THIS
148#else
149 inline XbmcCommons::Buffer getImage(unsigned int msecs = 0)
150#endif
151 {
152 if (!GetPixels(msecs))
153 return XbmcCommons::Buffer(0);
154
155 size_t size = m_width * m_height * 4;
156 return XbmcCommons::Buffer(m_buffer, size);
157 }
158
159#ifdef DOXYGEN_SHOULD_USE_THIS
173#else
174 inline void capture(int width, int height)
175#endif
176 {
177 auto& components = CServiceBroker::GetAppComponents();
178 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
179
180 if (m_buffer)
181 {
182 appPlayer->RenderCaptureRelease(m_captureId);
183 delete [] m_buffer;
184 }
185 m_captureId = appPlayer->RenderCaptureAlloc();
186 m_width = width;
187 m_height = height;
188 m_buffer = new uint8_t[m_width*m_height*4];
189 appPlayer->RenderCapture(m_captureId, m_width, m_height, CAPTUREFLAG_CONTINUOUS);
190 }
191
192// hide these from swig
193#ifndef SWIG
194 inline bool GetPixels(unsigned int msec)
195 {
196 auto& components = CServiceBroker::GetAppComponents();
197 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
198 return appPlayer->RenderCaptureGetPixels(m_captureId, msec, m_buffer,
199 m_width * m_height * 4);
200 }
201#endif
202
203 };
205 }
206}
Definition RenderCapture.h:39
getImage(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
Definition RenderCapture.h:147
getAspectRatio()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
getHeight()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
getImageFormat()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
Definition RenderCapture.h:123
capture(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...
Definition RenderCapture.h:172
getWidth()
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...