1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
18// A filter for converting a stream of MPEG PES packets to a MPEG-2 Transport Stream
19// Implementation
20
21#include "MPEG2TransportStreamFromPESSource.hh"
22
23#define MAX_PES_PACKET_SIZE (6+65535)
24
25MPEG2TransportStreamFromPESSource* MPEG2TransportStreamFromPESSource
26::createNew(UsageEnvironment& env, MPEG1or2DemuxedElementaryStream* inputSource) {
27 return new MPEG2TransportStreamFromPESSource(env, inputSource);
28}
29
30MPEG2TransportStreamFromPESSource
31::MPEG2TransportStreamFromPESSource(UsageEnvironment& env,
32 MPEG1or2DemuxedElementaryStream* inputSource)
33 : MPEG2TransportStreamMultiplexor(env),
34 fInputSource(inputSource) {
35 fInputBuffer = new unsigned char[MAX_PES_PACKET_SIZE];
36}
37
38MPEG2TransportStreamFromPESSource::~MPEG2TransportStreamFromPESSource() {
39 Medium::close(fInputSource);
40 delete[] fInputBuffer;
41}
42
43void MPEG2TransportStreamFromPESSource::doStopGettingFrames() {
44 fInputSource->stopGettingFrames();
45}
46
47void MPEG2TransportStreamFromPESSource
48::awaitNewBuffer(unsigned char* /*oldBuffer*/) {
49 fInputSource->getNextFrame(fInputBuffer, MAX_PES_PACKET_SIZE,
50 afterGettingFrame, this,
51 FramedSource::handleClosure, this);
52}
53
54void MPEG2TransportStreamFromPESSource
55::afterGettingFrame(void* clientData, unsigned frameSize,
56 unsigned numTruncatedBytes,
57 struct timeval presentationTime,
58 unsigned durationInMicroseconds) {
59 MPEG2TransportStreamFromPESSource* source
60 = (MPEG2TransportStreamFromPESSource*)clientData;
61 source->afterGettingFrame1(frameSize, numTruncatedBytes,
62 presentationTime, durationInMicroseconds);
63}
64
65void MPEG2TransportStreamFromPESSource
66::afterGettingFrame1(unsigned frameSize,
67 unsigned /*numTruncatedBytes*/,
68 struct timeval /*presentationTime*/,
69 unsigned /*durationInMicroseconds*/) {
70 if (frameSize < 4) return;
71
72 handleNewBuffer(fInputBuffer, frameSize,
73 fInputSource->mpegVersion(), fInputSource->lastSeenSCR());
74}
75