1 /* 2 * Copyright (C) 2017 peak3d 3 * http://www.peak3d.de 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 * <http://www.gnu.org/licenses/>. 16 * 17 */ 18 19 #pragma once 20 21 #include <stdint.h> 22 #include <vector> 23 #include "../lib/mpegts/tsDemuxer.h" 24 #include "Ap4Types.h" 25 #include <kodi/addon-instance/Inputstream.h> 26 27 class AP4_ByteStream; 28 29 class ATTRIBUTE_HIDDEN TSReader : public TSDemux::TSDemuxer 30 { 31 public: 32 TSReader(AP4_ByteStream *stream, uint32_t requiredMask); 33 virtual ~TSReader(); 34 35 bool Initialize(); 36 37 virtual bool ReadAV(uint64_t pos, unsigned char * data, size_t len) override; 38 39 void Reset(bool resetPackets = true); 40 bool StartStreaming(AP4_UI32 typeMask); 41 bool SeekTime(uint64_t timeInTs, bool preceeding); 42 43 bool GetInformation(kodi::addon::InputstreamInfo& info); 44 bool ReadPacket(bool streamInfo = false); 45 GetDts()46 uint64_t GetDts() const { return m_pkt.dts == PTS_UNSET ? PTS_UNSET : m_pkt.dts; } GetPts()47 uint64_t GetPts() const { return m_pkt.pts == PTS_UNSET ? PTS_UNSET : m_pkt.pts; } GetDuration()48 uint64_t GetDuration() const { return m_pkt.duration; } GetPacketData()49 const AP4_Byte *GetPacketData() const { return m_pkt.data; }; GetPacketSize()50 const AP4_Size GetPacketSize() const { return m_pkt.size; }; 51 const INPUTSTREAM_TYPE GetStreamType() const; 52 53 private: 54 bool GetPacket(); 55 bool HandleProgramChange(); 56 bool HandleStreamChange(uint16_t pid); 57 58 TSDemux::AVContext* m_AVContext; 59 60 AP4_ByteStream *m_stream; 61 62 TSDemux::STREAM_PKT m_pkt; 63 AP4_Position m_startPos; 64 uint32_t m_requiredMask; 65 uint32_t m_typeMask; 66 67 struct TSINFO 68 { TSINFOTSINFO69 TSINFO(TSDemux::ElementaryStream* stream) : m_stream(stream), m_needInfo(true), m_changed(false), m_enabled(false), m_streamType(INPUTSTREAM_TYPE_NONE) {}; 70 71 TSDemux::ElementaryStream* m_stream; 72 bool m_needInfo, m_changed, m_enabled; 73 INPUTSTREAM_TYPE m_streamType; 74 }; 75 std::vector<TSINFO> m_streamInfos; 76 }; 77