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 "Application.h"
36 #include "ApplicationMessenger.h"
37 #include "windowing/WindowingFactory.h"
38 #include "settings/AdvancedSettings.h"
40 #include "DllLibStageFrightCodec.h"
42 #define CLASSNAME "CDVDVideoCodecStageFright"
43 ////////////////////////////////////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////////////////////////////
46 DllLibStageFrightCodec* CDVDVideoCodecStageFright::m_stf_dll = NULL;
48 CDVDVideoCodecStageFright::CDVDVideoCodecStageFright()
50 , m_convert_bitstream(false), m_converter(NULL)
53 m_pFormatName = "stf-xxxx";
56 m_stf_dll = new DllLibStageFrightCodec;
59 CDVDVideoCodecStageFright::~CDVDVideoCodecStageFright()
64 bool CDVDVideoCodecStageFright::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
66 // we always qualify even if DVDFactoryCodec does this too.
67 if (CSettings::Get().GetBool("videoplayer.usestagefright") && !hints.software)
69 m_convert_bitstream = false;
71 "%s::%s - trying to open, codec(%d), profile(%d), level(%d)",
72 CLASSNAME, __func__, hints.codec, hints.profile, hints.level);
77 m_pFormatName = "stf-h264";
78 if (hints.extrasize < 7 || hints.extradata == NULL)
81 "%s::%s - avcC data too small or missing", CLASSNAME, __func__);
84 m_converter = new CBitstreamConverter();
85 m_convert_bitstream = m_converter->Open(hints.codec, (uint8_t *)hints.extradata, hints.extrasize, true);
88 case CODEC_ID_MPEG2VIDEO:
89 m_pFormatName = "stf-mpeg2";
92 m_pFormatName = "stf-mpeg4";
98 m_pFormatName = "stf-vpx";
102 m_pFormatName = "stf-wmv";
109 if (!(m_stf_dll && m_stf_dll->Load()))
111 m_stf_dll->EnableDelayedUnload(false);
113 m_stf_handle = m_stf_dll->create_stf(&g_application, &CApplicationMessenger::Get(), &g_Windowing, &g_advancedSettings);
115 if (!m_stf_dll->stf_Open(m_stf_handle, hints))
118 "%s::%s - failed to open, codec(%d), profile(%d), level(%d)",
119 CLASSNAME, __func__, hints.codec, hints.profile, hints.level);
130 void CDVDVideoCodecStageFright::Dispose()
134 m_converter->Close();
140 m_stf_dll->stf_Dispose(m_stf_handle);
141 m_stf_dll->destroy_stf(m_stf_handle);
146 void CDVDVideoCodecStageFright::SetDropState(bool bDrop)
148 m_stf_dll->stf_SetDropState(m_stf_handle, bDrop);
151 int CDVDVideoCodecStageFright::Decode(uint8_t *pData, int iSize, double dts, double pts)
153 #if defined(DEBUG_VERBOSE)
154 unsigned int time = XbmcThreads::SystemClockMillis();
157 int demuxer_bytes = iSize;
158 uint8_t *demuxer_content = pData;
160 if (m_convert_bitstream && demuxer_content)
162 // convert demuxer packet from bitstream to bytestream (AnnexB)
163 if (m_converter->Convert(demuxer_content, demuxer_bytes))
165 demuxer_content = m_converter->GetConvertBuffer();
166 demuxer_bytes = m_converter->GetConvertSize();
169 CLog::Log(LOGERROR,"%s::%s - bitstream_convert error", CLASSNAME, __func__);
171 #if defined(DEBUG_VERBOSE)
172 CLog::Log(LOGDEBUG, ">>> decode conversion - tm:%d\n", XbmcThreads::SystemClockMillis() - time);
175 rtn = m_stf_dll->stf_Decode(m_stf_handle, demuxer_content, demuxer_bytes, dts, pts);
180 void CDVDVideoCodecStageFright::Reset(void)
182 m_stf_dll->stf_Reset(m_stf_handle);
185 bool CDVDVideoCodecStageFright::GetPicture(DVDVideoPicture* pDvdVideoPicture)
187 pDvdVideoPicture->stf = this;
188 return m_stf_dll->stf_GetPicture(m_stf_handle, pDvdVideoPicture);
191 bool CDVDVideoCodecStageFright::ClearPicture(DVDVideoPicture* pDvdVideoPicture)
193 return m_stf_dll->stf_ClearPicture(m_stf_handle, pDvdVideoPicture);
196 void CDVDVideoCodecStageFright::SetSpeed(int iSpeed)
198 m_stf_dll->stf_SetSpeed(m_stf_handle, iSpeed);
201 int CDVDVideoCodecStageFright::GetDataSize(void)
206 double CDVDVideoCodecStageFright::GetTimeSize(void)
211 void CDVDVideoCodecStageFright::LockBuffer(EGLImageKHR eglimg)
213 m_stf_dll->stf_LockBuffer(m_stf_handle, eglimg);
216 void CDVDVideoCodecStageFright::ReleaseBuffer(EGLImageKHR eglimg)
218 m_stf_dll->stf_ReleaseBuffer(m_stf_handle, eglimg);