MPEG2IndexFromTransportStream.hh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // A filter that produces a sequence of I-frame indices from a MPEG-2 Transport Stream
  17. // C++ header
  18. #ifndef _MPEG2_IFRAME_INDEX_FROM_TRANSPORT_STREAM_HH
  19. #define _MPEG2_IFRAME_INDEX_FROM_TRANSPORT_STREAM_HH
  20. #ifndef _FRAMED_FILTER_HH
  21. #include "FramedFilter.hh"
  22. #endif
  23. #ifndef TRANSPORT_PACKET_SIZE
  24. #define TRANSPORT_PACKET_SIZE 188
  25. #endif
  26. #ifndef MAX_PES_PACKET_SIZE
  27. #define MAX_PES_PACKET_SIZE 65536
  28. #endif
  29. class IndexRecord; // forward
  30. class MPEG2IFrameIndexFromTransportStream: public FramedFilter {
  31. public:
  32. static MPEG2IFrameIndexFromTransportStream*
  33. createNew(UsageEnvironment& env, FramedSource* inputSource);
  34. protected:
  35. MPEG2IFrameIndexFromTransportStream(UsageEnvironment& env,
  36. FramedSource* inputSource);
  37. // called only by createNew()
  38. virtual ~MPEG2IFrameIndexFromTransportStream();
  39. private:
  40. // Redefined virtual functions:
  41. virtual void doGetNextFrame();
  42. private:
  43. static void afterGettingFrame(void* clientData, unsigned frameSize,
  44. unsigned numTruncatedBytes,
  45. struct timeval presentationTime,
  46. unsigned durationInMicroseconds);
  47. void afterGettingFrame1(unsigned frameSize,
  48. unsigned numTruncatedBytes,
  49. struct timeval presentationTime,
  50. unsigned durationInMicroseconds);
  51. static void handleInputClosure(void* clientData);
  52. void handleInputClosure1();
  53. void analyzePAT(unsigned char* pkt, unsigned size);
  54. void analyzePMT(unsigned char* pkt, unsigned size);
  55. Boolean deliverIndexRecord();
  56. Boolean parseFrame();
  57. Boolean parseToNextCode(unsigned char& nextCode);
  58. void compactParseBuffer();
  59. void addToTail(IndexRecord* newIndexRecord);
  60. private:
  61. Boolean fIsH264; // True iff the video is H.264 (encapsulated in a Transport Stream)
  62. Boolean fIsH265; // True iff the video is H.265 (encapsulated in a Transport Stream)
  63. unsigned long fInputTransportPacketCounter;
  64. unsigned fClosureNumber;
  65. u_int8_t fLastContinuityCounter;
  66. float fFirstPCR, fLastPCR;
  67. Boolean fHaveSeenFirstPCR;
  68. u_int16_t fPMT_PID, fVideo_PID;
  69. // Note: We assume: 1 program per Transport Stream; 1 video stream per program
  70. unsigned char fInputBuffer[TRANSPORT_PACKET_SIZE];
  71. unsigned char* fParseBuffer;
  72. unsigned fParseBufferSize;
  73. unsigned fParseBufferFrameStart;
  74. unsigned fParseBufferParseEnd;
  75. unsigned fParseBufferDataEnd;
  76. IndexRecord* fHeadIndexRecord;
  77. IndexRecord* fTailIndexRecord;
  78. };
  79. #endif