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, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 #include <boost/shared_ptr.hpp>
27 #include "DVDVideoCodec.h"
28 #include "DVDStreamInfo.h"
29 #include "threads/Thread.h"
30 #include "threads/SingleLock.h"
33 class CJNISurfaceTexture;
35 class CDVDMediaCodecOnFrameAvailable;
37 class CBitstreamConverter;
39 typedef struct amc_demux {
46 class CDVDMediaCodecInfo
49 CDVDMediaCodecInfo( int index,
51 boost::shared_ptr<CJNIMediaCodec> &codec,
52 boost::shared_ptr<CJNISurfaceTexture> &surfacetexture,
53 boost::shared_ptr<CDVDMediaCodecOnFrameAvailable> &frameready);
56 CDVDMediaCodecInfo* Retain();
60 void Validate(bool state);
62 void ReleaseOutputBuffer(bool render);
63 // SurfaceTexture released
65 int GetTextureID() const;
66 void GetTransformMatrix(float *textureMatrix);
67 void UpdateTexImage();
70 // private because we are reference counted
71 virtual ~CDVDMediaCodecInfo();
76 unsigned int m_texture;
78 CCriticalSection m_section;
79 // shared_ptr bits, shared between
80 // CDVDVideoCodecAndroidMediaCodec and LinuxRenderGLES.
81 boost::shared_ptr<CJNIMediaCodec> m_codec;
82 boost::shared_ptr<CJNISurfaceTexture> m_surfacetexture;
83 boost::shared_ptr<CDVDMediaCodecOnFrameAvailable> m_frameready;
86 class CDVDVideoCodecAndroidMediaCodec : public CDVDVideoCodec
89 CDVDVideoCodecAndroidMediaCodec();
90 virtual ~CDVDVideoCodecAndroidMediaCodec();
93 virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options);
94 virtual void Dispose();
95 virtual int Decode(uint8_t *pData, int iSize, double dts, double pts);
97 virtual bool GetPicture(DVDVideoPicture *pDvdVideoPicture);
98 virtual bool ClearPicture(DVDVideoPicture* pDvdVideoPicture);
99 virtual void SetDropState(bool bDrop);
100 virtual int GetDataSize(void);
101 virtual double GetTimeSize(void);
102 virtual const char* GetName(void) { return m_formatname; }
103 virtual unsigned GetAllowedReferences();
106 void FlushInternal(void);
107 bool ConfigureMediaCodec(void);
108 int GetOutputPicture(void);
109 void OutputFormatChanged(void);
111 // surface handling functions
112 static void CallbackInitSurfaceTexture(void*);
113 void InitSurfaceTexture(void);
114 void ReleaseSurfaceTexture(void);
116 CDVDStreamInfo m_hints;
118 std::string m_codecname;
119 const char *m_formatname;
123 CJNISurface *m_surface;
124 unsigned int m_textureId;
125 // we need these as shared_ptr because CDVDVideoCodecAndroidMediaCodec
126 // will get deleted before CLinuxRendererGLES is shut down and
127 // CLinuxRendererGLES refs them via CDVDMediaCodecInfo.
128 boost::shared_ptr<CJNIMediaCodec> m_codec;
129 boost::shared_ptr<CJNISurfaceTexture> m_surfaceTexture;
130 boost::shared_ptr<CDVDMediaCodecOnFrameAvailable> m_frameAvailable;
132 std::queue<amc_demux> m_demux;
133 std::vector<CJNIByteBuffer> m_input;
134 std::vector<CJNIByteBuffer> m_output;
135 std::vector<CDVDMediaCodecInfo*> m_inflight;
137 CBitstreamConverter *m_bitstream;
138 DVDVideoPicture m_videobuffer;