ByteStreamFileSource.hh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 file source that is a plain byte stream (rather than frames)
  17. // C++ header
  18. #ifndef _BYTE_STREAM_FILE_SOURCE_HH
  19. #define _BYTE_STREAM_FILE_SOURCE_HH
  20. #ifndef _FRAMED_FILE_SOURCE_HH
  21. #include "FramedFileSource.hh"
  22. #endif
  23. class ByteStreamFileSource: public FramedFileSource {
  24. public:
  25. static ByteStreamFileSource* createNew(UsageEnvironment& env,
  26. char const* fileName,
  27. unsigned preferredFrameSize = 0,
  28. unsigned playTimePerFrame = 0);
  29. // "preferredFrameSize" == 0 means 'no preference'
  30. // "playTimePerFrame" is in microseconds
  31. static ByteStreamFileSource* createNew(UsageEnvironment& env,
  32. FILE* fid,
  33. unsigned preferredFrameSize = 0,
  34. unsigned playTimePerFrame = 0);
  35. // an alternative version of "createNew()" that's used if you already have
  36. // an open file.
  37. u_int64_t fileSize() const { return fFileSize; }
  38. // 0 means zero-length, unbounded, or unknown
  39. void seekToByteAbsolute(u_int64_t byteNumber, u_int64_t numBytesToStream = 0);
  40. // if "numBytesToStream" is >0, then we limit the stream to that number of bytes, before treating it as EOF
  41. void seekToByteRelative(int64_t offset, u_int64_t numBytesToStream = 0);
  42. void seekToEnd(); // to force EOF handling on the next read
  43. protected:
  44. ByteStreamFileSource(UsageEnvironment& env,
  45. FILE* fid,
  46. unsigned preferredFrameSize,
  47. unsigned playTimePerFrame);
  48. // called only by createNew()
  49. virtual ~ByteStreamFileSource();
  50. static void fileReadableHandler(ByteStreamFileSource* source, int mask);
  51. void doReadFromFile();
  52. private:
  53. // redefined virtual functions:
  54. virtual void doGetNextFrame();
  55. virtual void doStopGettingFrames();
  56. protected:
  57. u_int64_t fFileSize;
  58. private:
  59. unsigned fPreferredFrameSize;
  60. unsigned fPlayTimePerFrame;
  61. Boolean fFidIsSeekable;
  62. unsigned fLastPlayTime;
  63. Boolean fHaveStartedReading;
  64. Boolean fLimitNumBytesToStream;
  65. u_int64_t fNumBytesToStream; // used iff "fLimitNumBytesToStream" is True
  66. };
  67. #endif