FIX: [stagefright] dyload the whole codec to prevent potential future api breakage
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDCodecs / Video / libstagefrightICS / StageFrightVideoPrivate.h
1 #pragma once
2 /*
3  *      Copyright (C) 2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21 /***************************************************************************/
22
23 #include "threads/Thread.h"
24 #include "xbmc/guilib/FrameBufferObject.h"
25 #include "cores/VideoRenderers/RenderFormats.h"
26
27 #include <android/native_window.h>
28 #include <android/native_window_jni.h>
29
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>
35
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>
45
46 #include "system_gl.h"
47
48 #include <map>
49 #include <list>
50
51 #define NUMFBOTEX 4
52 #define INBUFCOUNT 16
53
54 class CStageFrightDecodeThread;
55 class CJNISurface;
56 class CJNISurfaceTexture;
57 class CWinSystemEGL;
58 class CAdvancedSettings;
59
60 using namespace android;
61
62 struct tex_slot
63 {
64   GLuint texid;
65   EGLImageKHR eglimg;
66 };
67
68 struct Frame
69 {
70   status_t status;
71   int32_t width, height;
72   int64_t pts;
73   ERenderFormat format;
74   EGLImageKHR eglimg;
75   MediaBuffer* medbuf;
76 };
77
78 enum StageFrightQuirks
79 {
80   QuirkNone = 0,
81   QuirkSWRender = 0x01,
82 };
83
84 class CStageFrightVideoPrivate : public MediaBufferObserver
85 {
86 public:
87   CStageFrightVideoPrivate();
88
89   virtual void signalBufferReturned(MediaBuffer *buffer);
90
91   MediaBuffer* getBuffer(size_t size);
92   bool inputBufferAvailable();
93
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();
99
100 public:
101   CStageFrightDecodeThread* decode_thread;
102
103   sp<MediaSource> source;
104
105   MediaBuffer* inbuf[INBUFCOUNT];
106
107   GLuint mPgm;
108   GLint mPositionHandle;
109   GLint mTexSamplerHandle;
110   GLint mTexMatrixHandle;
111
112   CWinSystemEGL* m_g_Windowing;
113   CAdvancedSettings* m_g_advancedSettings;
114
115   CFrameBufferObject fbo;
116   EGLDisplay eglDisplay;
117   EGLSurface eglSurface;
118   EGLContext eglContext;
119   bool eglInitialized;
120
121   tex_slot slots[NUMFBOTEX];
122   std::list< std::pair<EGLImageKHR, int> > free_queue;
123   std::list< std::pair<EGLImageKHR, int> > busy_queue;
124
125   sp<MetaData> meta;
126   int64_t framecount;
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;
134
135   int quirks;
136   Frame *cur_frame;
137   Frame *prev_frame;
138   bool source_done;
139   int x, y;
140   int width, height;
141   int texwidth, texheight;
142
143   OMXClient *client;
144   sp<MediaSource> decoder;
145   const char *decoder_component;
146   int videoColorFormat;
147   int videoStride;
148   int videoSliceHeight;
149
150   bool drop_state;
151   bool resetting;
152 #if defined(DEBUG_VERBOSE)
153   unsigned int cycle_time;
154 #endif
155
156   unsigned int mVideoTextureId;
157   CJNISurfaceTexture* mSurfTexture;
158   CJNISurface* mSurface;
159   sp<ANativeWindow> mVideoNativeWindow;
160
161   bool InitStagefrightSurface();
162   void UninitStagefrightSurface();
163   void UpdateStagefrightTexture();
164   void GetStagefrightTransformMatrix(float* transformMatrix);
165 };