From ffca21f2743a7b367fa212799c6e2fea6190dd5d Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 3 Mar 2015 16:53:59 +0100 Subject: initial commit for kodi master --- xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp (limited to 'xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp') diff --git a/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp new file mode 100644 index 0000000..ab298b2 --- /dev/null +++ b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS) + #include "config.h" +#endif +#include "DVDDemuxUtils.h" +#include "DVDClock.h" +#include "utils/log.h" + +extern "C" { +#include "libavcodec/avcodec.h" +} + +void CDVDDemuxUtils::FreeDemuxPacket(DemuxPacket* pPacket) +{ + if (pPacket) + { + try { + if (pPacket->pData) _aligned_free(pPacket->pData); + delete pPacket; + } + catch(...) { + CLog::Log(LOGERROR, "%s - Exception thrown while freeing packet", __FUNCTION__); + } + } +} + +DemuxPacket* CDVDDemuxUtils::AllocateDemuxPacket(int iDataSize) +{ + DemuxPacket* pPacket = new DemuxPacket; + if (!pPacket) return NULL; + + try + { + memset(pPacket, 0, sizeof(DemuxPacket)); + + if (iDataSize > 0) + { + // need to allocate a few bytes more. + // From avcodec.h (ffmpeg) + /** + * Required number of additionally allocated bytes at the end of the input bitstream for decoding. + * this is mainly needed because some optimized bitstream readers read + * 32 or 64 bit at once and could read over the end
+ * Note, if the first 23 bits of the additional bytes are not 0 then damaged + * MPEG bitstreams could cause overread and segfault + */ + pPacket->pData =(uint8_t*)_aligned_malloc(iDataSize + FF_INPUT_BUFFER_PADDING_SIZE, 16); + if (!pPacket->pData) + { + FreeDemuxPacket(pPacket); + return NULL; + } + + // reset the last 8 bytes to 0; + memset(pPacket->pData + iDataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE); + } + + // setup defaults + pPacket->dts = DVD_NOPTS_VALUE; + pPacket->pts = DVD_NOPTS_VALUE; + pPacket->iStreamId = -1; + } + catch(...) + { + CLog::Log(LOGERROR, "%s - Exception thrown", __FUNCTION__); + FreeDemuxPacket(pPacket); + pPacket = NULL; + } + return pPacket; +} -- cgit v1.2.3