3 * Copyright (C) 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/>.
21 /***************************************************************************/
23 #include "threads/Thread.h"
24 #include "xbmc/guilib/FrameBufferObject.h"
25 #include "cores/VideoRenderers/RenderFormats.h"
27 #include <android/native_window.h>
28 #include <android/native_window_jni.h>
30 #include <media/stagefright/MetaData.h>
31 #include <media/stagefright/MediaBuffer.h>
32 #include <media/stagefright/MediaBufferGroup.h>
33 #include <media/stagefright/MediaDefs.h>
34 #include <media/stagefright/MediaSource.h>
36 #include <binder/ProcessState.h>
37 #include <media/stagefright/OMXClient.h>
38 #include <media/stagefright/OMXCodec.h>
39 #include <media/stagefright/foundation/ABuffer.h>
40 #include <utils/List.h>
41 #include <utils/RefBase.h>
42 #include <ui/GraphicBuffer.h>
43 #include <ui/PixelFormat.h>
44 #include <gui/SurfaceTexture.h>
46 #include "system_gl.h"
54 class CStageFrightDecodeThread;
56 class CJNISurfaceTexture;
58 class CAdvancedSettings;
60 using namespace android;
71 int32_t width, height;
78 enum StageFrightQuirks
84 class CStageFrightVideoPrivate : public MediaBufferObserver
87 CStageFrightVideoPrivate();
89 virtual void signalBufferReturned(MediaBuffer *buffer);
91 MediaBuffer* getBuffer(size_t size);
92 bool inputBufferAvailable();
94 void loadOESShader(GLenum shaderType, const char* pSource, GLuint* outShader);
95 void createOESProgram(const char* pVertexSource, const char* pFragmentSource, GLuint* outPgm);
96 void OES_shader_setUp();
97 void InitializeEGL(int w, int h);
98 void UninitializeEGL();
101 CStageFrightDecodeThread* decode_thread;
103 sp<MediaSource> source;
105 MediaBuffer* inbuf[INBUFCOUNT];
108 GLint mPositionHandle;
109 GLint mTexSamplerHandle;
110 GLint mTexMatrixHandle;
112 CWinSystemEGL* m_g_Windowing;
113 CAdvancedSettings* m_g_advancedSettings;
115 CFrameBufferObject fbo;
116 EGLDisplay eglDisplay;
117 EGLSurface eglSurface;
118 EGLContext eglContext;
121 tex_slot slots[NUMFBOTEX];
122 std::list< std::pair<EGLImageKHR, int> > free_queue;
123 std::list< std::pair<EGLImageKHR, int> > busy_queue;
127 std::map<int64_t, Frame*> in_queue;
128 std::map<int64_t, Frame*> out_queue;
129 CCriticalSection in_mutex;
130 CCriticalSection out_mutex;
131 CCriticalSection free_mutex;
132 XbmcThreads::ConditionVariable in_condition;
133 XbmcThreads::ConditionVariable out_condition;
141 int texwidth, texheight;
144 sp<MediaSource> decoder;
145 const char *decoder_component;
146 int videoColorFormat;
148 int videoSliceHeight;
152 #if defined(DEBUG_VERBOSE)
153 unsigned int cycle_time;
156 unsigned int mVideoTextureId;
157 CJNISurfaceTexture* mSurfTexture;
158 CJNISurface* mSurface;
159 sp<ANativeWindow> mVideoNativeWindow;
161 bool InitStagefrightSurface();
162 void UninitStagefrightSurface();
163 void UpdateStagefrightTexture();
164 void GetStagefrightTransformMatrix(float* transformMatrix);