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 WIN32)
29 #if defined(HAS_LIBSTAGEFRIGHT)
31 #include "settings/Settings.h"
32 #include "DVDStreamInfo.h"
33 #include "DVDVideoCodecStageFright.h"
34 #include "StageFrightVideo.h"
35 #include "utils/log.h"
37 #define CLASSNAME "CDVDVideoCodecStageFright"
38 ////////////////////////////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////////////////////////////////////
40 CDVDVideoCodecStageFright::CDVDVideoCodecStageFright()
42 , m_stf_decoder(NULL), m_converter(NULL), m_convert_bitstream(false)
44 m_pFormatName = "stf-xxxx";
47 CDVDVideoCodecStageFright::~CDVDVideoCodecStageFright()
52 bool CDVDVideoCodecStageFright::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
54 // we always qualify even if DVDFactoryCodec does this too.
55 if (CSettings::Get().GetBool("videoplayer.usestagefright") && !hints.software)
57 m_convert_bitstream = false;
59 "%s::%s - trying to open, codec(%d), profile(%d), level(%d)",
60 CLASSNAME, __func__, hints.codec, hints.profile, hints.level);
65 m_pFormatName = "stf-h264";
66 if (hints.extrasize < 7 || hints.extradata == NULL)
69 "%s::%s - avcC data too small or missing", CLASSNAME, __func__);
72 m_converter = new CBitstreamConverter();
73 m_convert_bitstream = m_converter->Open(hints.codec, (uint8_t *)hints.extradata, hints.extrasize, true);
76 case CODEC_ID_MPEG2VIDEO:
77 m_pFormatName = "stf-mpeg2";
80 m_pFormatName = "stf-mpeg4";
86 m_pFormatName = "stf-vpx";
90 m_pFormatName = "stf-wmv";
97 m_stf_decoder = new CStageFrightVideo;
98 if (!m_stf_decoder->Open(hints))
101 "%s::%s - failed to open, codec(%d), profile(%d), level(%d)",
102 CLASSNAME, __func__, hints.codec, hints.profile, hints.level);
103 delete m_stf_decoder;
104 m_stf_decoder = NULL;
108 m_converter->Close();
121 void CDVDVideoCodecStageFright::Dispose()
125 m_converter->Close();
131 m_stf_decoder->Close();
132 delete m_stf_decoder;
133 m_stf_decoder = NULL;
137 void CDVDVideoCodecStageFright::SetDropState(bool bDrop)
139 m_stf_decoder->SetDropState(bDrop);
142 int CDVDVideoCodecStageFright::Decode(uint8_t *pData, int iSize, double dts, double pts)
144 #if defined(DEBUG_VERBOSE)
145 unsigned int time = XbmcThreads::SystemClockMillis();
148 int demuxer_bytes = iSize;
149 uint8_t *demuxer_content = pData;
151 if (m_convert_bitstream && demuxer_content)
153 // convert demuxer packet from bitstream to bytestream (AnnexB)
154 if (m_converter->Convert(demuxer_content, demuxer_bytes))
156 demuxer_content = m_converter->GetConvertBuffer();
157 demuxer_bytes = m_converter->GetConvertSize();
160 CLog::Log(LOGERROR,"%s::%s - bitstream_convert error", CLASSNAME, __func__);
162 #if defined(DEBUG_VERBOSE)
163 CLog::Log(LOGDEBUG, ">>> decode conversion - tm:%d\n", XbmcThreads::SystemClockMillis() - time);
166 rtn = m_stf_decoder->Decode(demuxer_content, demuxer_bytes, dts, pts);
171 void CDVDVideoCodecStageFright::Reset(void)
173 m_stf_decoder->Reset();
176 bool CDVDVideoCodecStageFright::GetPicture(DVDVideoPicture* pDvdVideoPicture)
178 return m_stf_decoder->GetPicture(pDvdVideoPicture);
181 bool CDVDVideoCodecStageFright::ClearPicture(DVDVideoPicture* pDvdVideoPicture)
183 return m_stf_decoder->ClearPicture(pDvdVideoPicture);
186 void CDVDVideoCodecStageFright::SetSpeed(int iSpeed)
188 m_stf_decoder->SetSpeed(iSpeed);
191 int CDVDVideoCodecStageFright::GetDataSize(void)
196 double CDVDVideoCodecStageFright::GetTimeSize(void)