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 MPEG 1 or 2 Elementary Stream, demultiplexed from a Program Stream
19// Implementation
20
21#include "MPEG1or2DemuxedElementaryStream.hh"
22
23////////// MPEG1or2DemuxedElementaryStream //////////
24
25MPEG1or2DemuxedElementaryStream::
26MPEG1or2DemuxedElementaryStream(UsageEnvironment& env, u_int8_t streamIdTag,
27 MPEG1or2Demux& sourceDemux)
28 : FramedSource(env),
29 fOurStreamIdTag(streamIdTag), fOurSourceDemux(sourceDemux), fMPEGversion(0) {
30 // Set our MIME type string for known media types:
31 if ((streamIdTag&0xE0) == 0xC0) {
32 fMIMEtype = "audio/MPEG";
33 } else if ((streamIdTag&0xF0) == 0xE0) {
34 fMIMEtype = "video/MPEG";
35 } else {
36 fMIMEtype = MediaSource::MIMEtype();
37 }
38}
39
40MPEG1or2DemuxedElementaryStream::~MPEG1or2DemuxedElementaryStream() {
41 fOurSourceDemux.noteElementaryStreamDeletion(this);
42}
43
44void MPEG1or2DemuxedElementaryStream::doGetNextFrame() {
45 fOurSourceDemux.getNextFrame(fOurStreamIdTag, fTo, fMaxSize,
46 afterGettingFrame, this,
47 handleClosure, this);
48}
49
50void MPEG1or2DemuxedElementaryStream::doStopGettingFrames() {
51 fOurSourceDemux.stopGettingFrames(fOurStreamIdTag);
52}
53
54char const* MPEG1or2DemuxedElementaryStream::MIMEtype() const {
55 return fMIMEtype;
56}
57
58unsigned MPEG1or2DemuxedElementaryStream::maxFrameSize() const {
59 return 6+65535;
60 // because the MPEG spec allows for PES packets as large as
61 // (6 + 65535) bytes (header + data)
62}
63
64void MPEG1or2DemuxedElementaryStream
65::afterGettingFrame(void* clientData,
66 unsigned frameSize, unsigned numTruncatedBytes,
67 struct timeval presentationTime,
68 unsigned durationInMicroseconds) {
69 MPEG1or2DemuxedElementaryStream* stream
70 = (MPEG1or2DemuxedElementaryStream*)clientData;
71 stream->afterGettingFrame1(frameSize, numTruncatedBytes,
72 presentationTime, durationInMicroseconds);
73}
74
75void MPEG1or2DemuxedElementaryStream
76::afterGettingFrame1(unsigned frameSize, unsigned numTruncatedBytes,
77 struct timeval presentationTime,
78 unsigned durationInMicroseconds) {
79 fFrameSize = frameSize;
80 fNumTruncatedBytes = numTruncatedBytes;
81 fPresentationTime = presentationTime;
82 fDurationInMicroseconds = durationInMicroseconds;
83
84 fLastSeenSCR = fOurSourceDemux.lastSeenSCR();
85 fMPEGversion = fOurSourceDemux.mpegVersion();
86
87 FramedSource::afterGetting(this);
88}
89