1 | /********** |
2 | This library is free software; you can redistribute it and/or modify it under |
3 | the terms of the GNU Lesser General Public License as published by the |
4 | Free Software Foundation; either version 3 of the License, or (at your |
5 | option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) |
6 | |
7 | This library is distributed in the hope that it will be useful, but WITHOUT |
8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
10 | more details. |
11 | |
12 | You should have received a copy of the GNU Lesser General Public License |
13 | along with this library; if not, write to the Free Software Foundation, Inc., |
14 | 51 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 | |
25 | MPEG1or2DemuxedElementaryStream:: |
26 | MPEG1or2DemuxedElementaryStream(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 | |
40 | MPEG1or2DemuxedElementaryStream::~MPEG1or2DemuxedElementaryStream() { |
41 | fOurSourceDemux.noteElementaryStreamDeletion(this); |
42 | } |
43 | |
44 | void MPEG1or2DemuxedElementaryStream::doGetNextFrame() { |
45 | fOurSourceDemux.getNextFrame(fOurStreamIdTag, fTo, fMaxSize, |
46 | afterGettingFrame, this, |
47 | handleClosure, this); |
48 | } |
49 | |
50 | void MPEG1or2DemuxedElementaryStream::doStopGettingFrames() { |
51 | fOurSourceDemux.stopGettingFrames(fOurStreamIdTag); |
52 | } |
53 | |
54 | char const* MPEG1or2DemuxedElementaryStream::MIMEtype() const { |
55 | return fMIMEtype; |
56 | } |
57 | |
58 | unsigned 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 | |
64 | void 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 | |
75 | void 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 | |