3 * Copyright (C) 2010-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #if defined(HAVE_OMXLIB)
26 #include <IL/OMX_Video.h>
29 #if defined(STANDALONE)
30 #define XB_FMT_A8R8G8B8 1
33 #include "filesystem/File.h"
34 #include "guilib/XBTF.h"
37 #include "system_gl.h"
39 #include <EGL/eglext.h>
40 #include "threads/Thread.h"
42 using namespace XFILE;
47 class COMXImage : public CThread
49 enum TextureAction {TEXTURE_ALLOC, TEXTURE_DELETE };
55 EGLImageKHR egl_image;
62 virtual void OnStartup();
63 virtual void OnExit();
64 virtual void Process();
70 static COMXImageFile *LoadJpeg(const CStdString& texturePath);
71 static void CloseJpeg(COMXImageFile *file);
73 static bool DecodeJpeg(COMXImageFile *file, unsigned int maxWidth, unsigned int maxHeight, unsigned int stride, void *pixels);
74 static bool CreateThumbnailFromSurface(unsigned char* buffer, unsigned int width, unsigned int height,
75 unsigned int format, unsigned int pitch, const CStdString& destFile);
76 static bool ClampLimits(unsigned int &width, unsigned int &height, unsigned int m_width, unsigned int m_height, bool transposed = false);
77 static bool CreateThumb(const CStdString& srcFile, unsigned int width, unsigned int height, std::string &additional_info, const CStdString& destFile);
78 bool DecodeJpegToTexture(COMXImageFile *file, unsigned int width, unsigned int height, void **userdata);
79 void DestroyTexture(void *userdata);
80 void GetTexture(void *userdata, GLuint *texture);
82 EGLDisplay m_egl_display;
83 EGLContext m_egl_context;
86 CCriticalSection m_texqueue_lock;
87 XbmcThreads::ConditionVariable m_texqueue_cond;
88 std::queue <struct textureinfo *> m_texqueue;
89 void AllocTextureInternal(struct textureinfo *tex);
90 void DestroyTextureInternal(struct textureinfo *tex);
97 virtual ~COMXImageFile();
98 bool ReadFile(const CStdString& inputFile);
99 int GetOrientation() { return m_orientation; };
100 unsigned int GetWidth() { return m_width; };
101 unsigned int GetHeight() { return m_height; };
102 unsigned long GetImageSize() { return m_image_size; };
103 const uint8_t *GetImageBuffer() { return (const uint8_t *)m_image_buffer; };
104 const char *GetFilename() { return m_filename; };
106 OMX_IMAGE_CODINGTYPE GetCodingType(unsigned int &width, unsigned int &height);
107 uint8_t *m_image_buffer;
108 unsigned long m_image_size;
109 unsigned int m_width;
110 unsigned int m_height;
112 const char * m_filename;
119 virtual ~COMXImageDec();
121 // Required overrides
123 bool Decode(const uint8_t *data, unsigned size, unsigned int width, unsigned int height, unsigned stride, void *pixels);
124 unsigned int GetDecodedWidth() { return (unsigned int)m_decoded_format.format.image.nFrameWidth; };
125 unsigned int GetDecodedHeight() { return (unsigned int)m_decoded_format.format.image.nFrameHeight; };
126 unsigned int GetDecodedStride() { return (unsigned int)m_decoded_format.format.image.nStride; };
128 bool HandlePortSettingChange(unsigned int resize_width, unsigned int resize_height);
130 COMXCoreComponent m_omx_decoder;
131 COMXCoreComponent m_omx_resize;
132 COMXCoreTunel m_omx_tunnel_decode;
133 OMX_BUFFERHEADERTYPE *m_decoded_buffer;
134 OMX_PARAM_PORTDEFINITIONTYPE m_decoded_format;
135 CCriticalSection m_OMXSection;
142 virtual ~COMXImageEnc();
144 // Required overrides
145 bool CreateThumbnailFromSurface(unsigned char* buffer, unsigned int width, unsigned int height,
146 unsigned int format, unsigned int pitch, const CStdString& destFile);
148 bool Encode(unsigned char *buffer, int size, unsigned int width, unsigned int height, unsigned int pitch);
150 COMXCoreComponent m_omx_encoder;
151 OMX_BUFFERHEADERTYPE *m_encoded_buffer;
152 OMX_PARAM_PORTDEFINITIONTYPE m_encoded_format;
153 CCriticalSection m_OMXSection;
160 virtual ~COMXImageReEnc();
162 // Required overrides
164 bool ReEncode(COMXImageFile &srcFile, unsigned int width, unsigned int height, void * &pDestBuffer, unsigned int &nDestSize);
166 bool HandlePortSettingChange(unsigned int resize_width, unsigned int resize_height, bool port_settings_changed);
168 COMXCoreComponent m_omx_decoder;
169 COMXCoreComponent m_omx_resize;
170 COMXCoreComponent m_omx_encoder;
171 COMXCoreTunel m_omx_tunnel_decode;
172 COMXCoreTunel m_omx_tunnel_resize;
173 OMX_BUFFERHEADERTYPE *m_encoded_buffer;
174 CCriticalSection m_OMXSection;
176 unsigned int m_nDestAllocSize;
183 virtual ~COMXTexture();
185 // Required overrides
187 bool Decode(const uint8_t *data, unsigned size, unsigned int width, unsigned int height, void *egl_image, void *egl_display);
189 bool HandlePortSettingChange(unsigned int resize_width, unsigned int resize_height, void *egl_image, void *egl_display, bool port_settings_changed);
192 COMXCoreComponent m_omx_decoder;
193 COMXCoreComponent m_omx_resize;
194 COMXCoreComponent m_omx_egl_render;
196 COMXCoreTunel m_omx_tunnel_decode;
197 COMXCoreTunel m_omx_tunnel_egl;
199 OMX_BUFFERHEADERTYPE *m_egl_buffer;
200 CCriticalSection m_OMXSection;
203 extern COMXImage g_OMXImage;