summaryrefslogtreecommitdiffstats
path: root/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp')
-rw-r--r--xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxUtils.cpp89
1 files changed, 89 insertions, 0 deletions
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 @@
1/*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
4 *
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)
8 * any later version.
9 *
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.
14 *
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/>.
18 *
19 */
20
21#if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
22 #include "config.h"
23#endif
24#include "DVDDemuxUtils.h"
25#include "DVDClock.h"
26#include "utils/log.h"
27
28extern "C" {
29#include "libavcodec/avcodec.h"
30}
31
32void CDVDDemuxUtils::FreeDemuxPacket(DemuxPacket* pPacket)
33{
34 if (pPacket)
35 {
36 try {
37 if (pPacket->pData) _aligned_free(pPacket->pData);
38 delete pPacket;
39 }
40 catch(...) {
41 CLog::Log(LOGERROR, "%s - Exception thrown while freeing packet", __FUNCTION__);
42 }
43 }
44}
45
46DemuxPacket* CDVDDemuxUtils::AllocateDemuxPacket(int iDataSize)
47{
48 DemuxPacket* pPacket = new DemuxPacket;
49 if (!pPacket) return NULL;
50
51 try
52 {
53 memset(pPacket, 0, sizeof(DemuxPacket));
54
55 if (iDataSize > 0)
56 {
57 // need to allocate a few bytes more.
58 // From avcodec.h (ffmpeg)
59 /**
60 * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
61 * this is mainly needed because some optimized bitstream readers read
62 * 32 or 64 bit at once and could read over the end<br>
63 * Note, if the first 23 bits of the additional bytes are not 0 then damaged
64 * MPEG bitstreams could cause overread and segfault
65 */
66 pPacket->pData =(uint8_t*)_aligned_malloc(iDataSize + FF_INPUT_BUFFER_PADDING_SIZE, 16);
67 if (!pPacket->pData)
68 {
69 FreeDemuxPacket(pPacket);
70 return NULL;
71 }
72
73 // reset the last 8 bytes to 0;
74 memset(pPacket->pData + iDataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
75 }
76
77 // setup defaults
78 pPacket->dts = DVD_NOPTS_VALUE;
79 pPacket->pts = DVD_NOPTS_VALUE;
80 pPacket->iStreamId = -1;
81 }
82 catch(...)
83 {
84 CLog::Log(LOGERROR, "%s - Exception thrown", __FUNCTION__);
85 FreeDemuxPacket(pPacket);
86 pPacket = NULL;
87 }
88 return pPacket;
89}