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 using namespace android;
69 int32_t width, height;
76 enum StageFrightQuirks
82 class CStageFrightVideoPrivate : public MediaBufferObserver
85 CStageFrightVideoPrivate();
87 virtual void signalBufferReturned(MediaBuffer *buffer);
89 MediaBuffer* getBuffer(size_t size);
90 bool inputBufferAvailable();
92 void loadOESShader(GLenum shaderType, const char* pSource, GLuint* outShader);
93 void createOESProgram(const char* pVertexSource, const char* pFragmentSource, GLuint* outPgm);
94 void OES_shader_setUp();
95 void InitializeEGL(int w, int h);
96 void UninitializeEGL();
99 CStageFrightDecodeThread* decode_thread;
101 sp<MediaSource> source;
103 MediaBuffer* inbuf[INBUFCOUNT];
106 GLint mPositionHandle;
107 GLint mTexSamplerHandle;
108 GLint mTexMatrixHandle;
110 CFrameBufferObject fbo;
111 EGLDisplay eglDisplay;
112 EGLSurface eglSurface;
113 EGLContext eglContext;
116 tex_slot slots[NUMFBOTEX];
117 std::list< std::pair<EGLImageKHR, int> > free_queue;
118 std::list< std::pair<EGLImageKHR, int> > busy_queue;
122 std::map<int64_t, Frame*> in_queue;
123 std::map<int64_t, Frame*> out_queue;
124 CCriticalSection in_mutex;
125 CCriticalSection out_mutex;
126 CCriticalSection free_mutex;
127 XbmcThreads::ConditionVariable in_condition;
128 XbmcThreads::ConditionVariable out_condition;
136 int texwidth, texheight;
139 sp<MediaSource> decoder;
140 const char *decoder_component;
141 int videoColorFormat;
143 int videoSliceHeight;
147 #if defined(DEBUG_VERBOSE)
148 unsigned int cycle_time;
151 unsigned int mVideoTextureId;
152 CJNISurfaceTexture* mSurfTexture;
153 CJNISurface* mSurface;
154 sp<ANativeWindow> mVideoNativeWindow;
156 bool InitStagefrightSurface();
157 void UninitStagefrightSurface();
158 void UpdateStagefrightTexture();
159 void GetStagefrightTransformMatrix(float* transformMatrix);