2 * Copyright (C) 2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 //#define DEBUG_VERBOSE 1
23 #if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
25 #elif defined(TARGET_WINDOWS)
29 #if defined(HAS_LIBSTAGEFRIGHT)
31 #include "settings/Settings.h"
32 #include "DVDStreamInfo.h"
33 #include "DVDVideoCodecStageFright.h"
34 #include "utils/log.h"
35 #include "windowing/WindowingFactory.h"
36 #include "settings/AdvancedSettings.h"
38 #include "DllLibStageFrightCodec.h"
40 #define CLASSNAME "CDVDVideoCodecStageFright"
41 ////////////////////////////////////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////////////////////////////////////
44 DllLibStageFrightCodec* CDVDVideoCodecStageFright::m_stf_dll = NULL;
46 CDVDVideoCodecStageFright::CDVDVideoCodecStageFright()
48 , m_convert_bitstream(false), m_converter(NULL)
51 m_pFormatName = "stf-xxxx";
54 m_stf_dll = new DllLibStageFrightCodec;
57 CDVDVideoCodecStageFright::~CDVDVideoCodecStageFright()
62 bool CDVDVideoCodecStageFright::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
64 // we always qualify even if DVDFactoryCodec does this too.
65 if (CSettings::Get().GetBool("videoplayer.usestagefright") && !hints.software)
67 m_convert_bitstream = false;
69 "%s::%s - trying to open, codec(%d), profile(%d), level(%d)",
70 CLASSNAME, __func__, hints.codec, hints.profile, hints.level);
75 m_pFormatName = "stf-h264";
76 if (hints.extrasize < 7 || hints.extradata == NULL)
79 "%s::%s - avcC data too small or missing", CLASSNAME, __func__);
82 m_converter = new CBitstreamConverter();
83 m_convert_bitstream = m_converter->Open(hints.codec, (uint8_t *)hints.extradata, hints.extrasize, true);
86 case CODEC_ID_MPEG2VIDEO:
87 m_pFormatName = "stf-mpeg2";
90 m_pFormatName = "stf-mpeg4";
96 m_pFormatName = "stf-vpx";
100 m_pFormatName = "stf-wmv";
107 if (!(m_stf_dll && m_stf_dll->Load()))
109 m_stf_dll->EnableDelayedUnload(false);
111 m_stf_handle = m_stf_dll->create_stf(&g_Windowing, &g_advancedSettings);
113 if (!m_stf_dll->stf_Open(m_stf_handle, hints))
116 "%s::%s - failed to open, codec(%d), profile(%d), level(%d)",
117 CLASSNAME, __func__, hints.codec, hints.profile, hints.level);
128 void CDVDVideoCodecStageFright::Dispose()
132 m_converter->Close();
138 m_stf_dll->stf_Close(m_stf_handle);
139 m_stf_dll->destroy_stf(m_stf_handle);
144 void CDVDVideoCodecStageFright::SetDropState(bool bDrop)
146 m_stf_dll->stf_SetDropState(m_stf_handle, bDrop);
149 int CDVDVideoCodecStageFright::Decode(uint8_t *pData, int iSize, double dts, double pts)
151 #if defined(DEBUG_VERBOSE)
152 unsigned int time = XbmcThreads::SystemClockMillis();
155 int demuxer_bytes = iSize;
156 uint8_t *demuxer_content = pData;
158 if (m_convert_bitstream && demuxer_content)
160 // convert demuxer packet from bitstream to bytestream (AnnexB)
161 if (m_converter->Convert(demuxer_content, demuxer_bytes))
163 demuxer_content = m_converter->GetConvertBuffer();
164 demuxer_bytes = m_converter->GetConvertSize();
167 CLog::Log(LOGERROR,"%s::%s - bitstream_convert error", CLASSNAME, __func__);
169 #if defined(DEBUG_VERBOSE)
170 CLog::Log(LOGDEBUG, ">>> decode conversion - tm:%d\n", XbmcThreads::SystemClockMillis() - time);
173 rtn = m_stf_dll->stf_Decode(m_stf_handle, demuxer_content, demuxer_bytes, dts, pts);
178 void CDVDVideoCodecStageFright::Reset(void)
180 m_stf_dll->stf_Reset(m_stf_handle);
183 bool CDVDVideoCodecStageFright::GetPicture(DVDVideoPicture* pDvdVideoPicture)
185 pDvdVideoPicture->stf = this;
186 return m_stf_dll->stf_GetPicture(m_stf_handle, pDvdVideoPicture);
189 bool CDVDVideoCodecStageFright::ClearPicture(DVDVideoPicture* pDvdVideoPicture)
191 return m_stf_dll->stf_ClearPicture(m_stf_handle, pDvdVideoPicture);
194 void CDVDVideoCodecStageFright::SetSpeed(int iSpeed)
196 m_stf_dll->stf_SetSpeed(m_stf_handle, iSpeed);
199 int CDVDVideoCodecStageFright::GetDataSize(void)
204 double CDVDVideoCodecStageFright::GetTimeSize(void)
209 void CDVDVideoCodecStageFright::LockBuffer(EGLImageKHR eglimg)
211 m_stf_dll->stf_LockBuffer(m_stf_handle, eglimg);
214 void CDVDVideoCodecStageFright::ReleaseBuffer(EGLImageKHR eglimg)
216 m_stf_dll->stf_ReleaseBuffer(m_stf_handle, eglimg);