[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / interfaces / legacy / RenderCapture.h
blobcf1b93131f44bf5d03464574018ac97d4ed5d3cb
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
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"
18 #include <climits>
20 namespace XBMCAddon
22 namespace xbmc
24 XBMCCOMMONS_STANDARD_EXCEPTION(RenderCaptureException);
27 /// \defgroup python_xbmc_RenderCapture RenderCapture
28 /// \ingroup python_xbmc
29 /// @{
30 /// @brief **Kodi's render capture.**
31 ///
32 /// \python_class{ RenderCapture() }
33 ///
34 ///
35 ///--------------------------------------------------------------------------
36 ///
38 class RenderCapture : public AddonClass
40 unsigned int m_captureId;
41 unsigned int m_width;
42 unsigned int m_height;
43 uint8_t *m_buffer;
45 public:
46 inline RenderCapture()
48 m_captureId = UINT_MAX;
49 m_buffer = nullptr;
50 m_width = 0;
51 m_height = 0;
53 inline ~RenderCapture() override
55 auto& components = CServiceBroker::GetAppComponents();
56 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
57 appPlayer->RenderCaptureRelease(m_captureId);
58 delete [] m_buffer;
61 #ifdef DOXYGEN_SHOULD_USE_THIS
62 ///
63 /// \ingroup python_xbmc_RenderCapture
64 /// @brief \python_func{ getWidth() }
65 /// Get width
66 ///
67 /// To get width of captured image as set during RenderCapture.capture().
68 /// Returns 0 prior to calling capture.
69 ///
70 /// @return Width or 0 prior to calling capture
71 ///
72 getWidth();
73 #else
74 inline int getWidth() { return m_width; }
75 #endif
77 #ifdef DOXYGEN_SHOULD_USE_THIS
78 ///
79 /// \ingroup python_xbmc_RenderCapture
80 /// @brief \python_func{ getHeight() }
81 /// Get height
82 ///
83 /// To get height of captured image as set during RenderCapture.capture().
84 /// Returns 0 prior to calling capture.
85 ///
86 /// @return height or 0 prior to calling capture
87 getHeight();
88 #else
89 inline int getHeight() { return m_height; }
90 #endif
92 #ifdef DOXYGEN_SHOULD_USE_THIS
93 ///
94 /// \ingroup python_xbmc_RenderCapture
95 /// @brief \python_func{ getAspectRatio() }
96 /// Get aspect ratio of currently displayed video.
97 ///
98 /// @return Aspect ratio
99 /// @warning This may be called prior to calling RenderCapture.capture().
101 getAspectRatio();
102 #else
103 inline float getAspectRatio()
105 const auto& components = CServiceBroker::GetAppComponents();
106 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
107 return appPlayer->GetRenderAspectRatio();
109 #endif
111 #ifdef DOXYGEN_SHOULD_USE_THIS
113 /// \ingroup python_xbmc_RenderCapture
114 /// @brief \python_func{ getImageFormat() }
115 /// Get image format
117 /// @return Format of captured image: 'BGRA'
120 ///-----------------------------------------------------------------------
121 /// @python_v17 Image will now always be returned in BGRA
123 getImageFormat()
124 #else
125 inline const char* getImageFormat()
126 #endif
128 return "BGRA";
131 #ifdef DOXYGEN_SHOULD_USE_THIS
133 /// \ingroup python_xbmc_RenderCapture
134 /// @brief \python_func{ getImage([msecs]) }
135 /// Returns captured image as a bytearray.
137 /// @param msecs [opt] Milliseconds to wait. Waits
138 /// 1000ms if not specified
139 /// @return Captured image as a bytearray
141 /// @note The size of the image is m_width * m_height * 4
144 ///-----------------------------------------------------------------------
145 /// @python_v17 Added the option to specify wait time in msec.
147 getImage(...)
148 #else
149 inline XbmcCommons::Buffer getImage(unsigned int msecs = 0)
150 #endif
152 if (!GetPixels(msecs))
153 return XbmcCommons::Buffer(0);
155 size_t size = m_width * m_height * 4;
156 return XbmcCommons::Buffer(m_buffer, size);
159 #ifdef DOXYGEN_SHOULD_USE_THIS
161 /// \ingroup python_xbmc_RenderCapture
162 /// @brief \python_func{ capture(width, height) }
163 /// Issue capture request.
165 /// @param width Width capture image should be rendered to
166 /// @param height Height capture image should should be rendered to
169 ///-----------------------------------------------------------------------
170 /// @python_v17 Removed the option to pass **flags**
172 capture(...)
173 #else
174 inline void capture(int width, int height)
175 #endif
177 auto& components = CServiceBroker::GetAppComponents();
178 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
180 if (m_buffer)
182 appPlayer->RenderCaptureRelease(m_captureId);
183 delete [] m_buffer;
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);
192 // hide these from swig
193 #ifndef SWIG
194 inline bool GetPixels(unsigned int msec)
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);
201 #endif
204 //@}