Debian Codegraph @

src/lib/tsreader/PacketSync.cpp

raw
1 /*
2 * Copyright (C) 2006-2008 Team MediaPortal
3 * http://www.team-mediaportal.com
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 GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1335 USA
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 */
22
23 #include "PacketSync.h"
24 #include "utils.h"
25
26 namespace MPTV
27 {
28 CPacketSync::CPacketSync(void)
29 {
30 m_tempBufferPos = -1;
31 }
32
33 CPacketSync::~CPacketSync(void)
34 {
35 }
36
37 void CPacketSync::Reset(void)
38 {
39 m_tempBufferPos = -1;
40 }
41
42 // Ambass : Now, need to have 2 consecutive TS_PACKET_SYNC to try avoiding bad synchronisation.
43 // In case of data flow change ( Seek, tv Zap .... ) Reset() should be called first to flush buffer.
44 void CPacketSync::OnRawData(byte* pData, size_t nDataLen)
45 {
46 size_t syncOffset = 0;
47 if (m_tempBufferPos > 0)
48 {
49 if (pData[TS_PACKET_LEN - m_tempBufferPos] == TS_PACKET_SYNC)
50 {
51 syncOffset = TS_PACKET_LEN - m_tempBufferPos;
52 if (syncOffset)
53 memcpy(&m_tempBuffer[m_tempBufferPos], pData, syncOffset);
54 OnTsPacket(m_tempBuffer);
55 }
56 m_tempBufferPos = 0;
57 }
58
59 while (syncOffset + TS_PACKET_LEN < nDataLen)
60 {
61 if ((pData[syncOffset] == TS_PACKET_SYNC) &&
62 (pData[syncOffset + TS_PACKET_LEN] == TS_PACKET_SYNC))
63 {
64 OnTsPacket(&pData[syncOffset]);
65 syncOffset += TS_PACKET_LEN;
66 }
67 else
68 syncOffset++;
69 }
70
71 // Here we have less than 188+1 bytes
72 while (syncOffset < nDataLen)
73 {
74 if (pData[syncOffset] == TS_PACKET_SYNC)
75 {
76 m_tempBufferPos = nDataLen - syncOffset;
77 memcpy(m_tempBuffer, &pData[syncOffset], m_tempBufferPos);
78 return;
79 }
80 else
81 syncOffset++;
82 }
83
84 m_tempBufferPos = 0;
85 }
86
87 void CPacketSync::OnTsPacket(byte* UNUSED(tsPacket))
88 {
89 }
90 }
91