Debian Codegraph @

src/lib/tsreader/MemorySink.cpp

raw
1 /*
2 * Copyright (C) 2005-2012 Team Kodi
3 * https://kodi.tv
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 of the License, or
8 * (at your option) 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 this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 *************************************************************************
19 * This file is a modified version from Team MediaPortal's
20 * TsReader DirectShow filter
21 * MediaPortal is a GPL'ed HTPC-Application
22 * Copyright (C) 2005-2012 Team MediaPortal
23 * http://www.team-mediaportal.com
24 *
25 * Changes compared to Team MediaPortal's version:
26 * - Code cleanup for PVR addon usage
27 * - Code refactoring for cross platform usage
28 */
29
30 #if defined LIVE555
31
32 #include "MemorySink.h"
33 #include "GroupsockHelper.hh"
34 #include <kodi/General.h> //for kodi::Log
35 #include "utils.h"
36
37 #define SUBMIT_BUF_SIZE (1316*30)
38
39 CMemorySink::CMemorySink(UsageEnvironment& env, CMemoryBuffer& buffer, size_t bufferSize)
40 : MediaSink(env),
41 fBufferSize(bufferSize),
42 m_buffer(buffer)
43 {
44 fBuffer = new unsigned char[bufferSize];
45 m_pSubmitBuffer = new unsigned char[SUBMIT_BUF_SIZE];
46 m_iSubmitBufferPos = 0;
47 m_bReEntrant = false;
48 }
49
50 CMemorySink::~CMemorySink()
51 {
52 delete[] fBuffer;
53 delete[] m_pSubmitBuffer;
54 }
55
56 CMemorySink* CMemorySink::createNew(UsageEnvironment& env, CMemoryBuffer& buffer, size_t bufferSize)
57 {
58 return new CMemorySink(env, buffer, bufferSize);
59 }
60
61 Boolean CMemorySink::continuePlaying()
62 {
63 if (fSource == NULL)
64 return False;
65
66 fSource->getNextFrame(fBuffer, (unsigned) fBufferSize, afterGettingFrame, this, onSourceClosure, this);
67 return True;
68 }
69
70 void CMemorySink::afterGettingFrame(void* clientData, unsigned frameSize, unsigned /*numTruncatedBytes*/, struct timeval presentationTime, unsigned /*durationInMicroseconds*/)
71 {
72 CMemorySink* sink = (CMemorySink*)clientData;
73 sink->afterGettingFrame1(frameSize, presentationTime);
74 sink->continuePlaying();
75 }
76
77 void CMemorySink::addData(unsigned char* data, size_t dataSize, struct timeval UNUSED(presentationTime))
78 {
79 if (dataSize == 0 || data == NULL) return;
80
81 if (m_bReEntrant)
82 {
83 kodi::Log(ADDON_LOG_DEBUG, "REENTRANT IN MEMORYSINK.CPP");
84 return;
85 }
86
87 std::lock_guard<std::mutex> BufferLock(m_BufferLock);
88
89 m_bReEntrant = true;
90 m_buffer.PutBuffer(data, dataSize);
91 m_bReEntrant = false;
92 }
93
94
95 void CMemorySink::afterGettingFrame1(unsigned frameSize, struct timeval presentationTime)
96 {
97 addData(fBuffer, frameSize, presentationTime);
98 }
99 #endif //LIVE555