caching_stream.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * This file is part of the FreeStreamer project,
  3. * (C)Copyright 2011-2018 Matias Muhonen <mmu@iki.fi> 穆马帝
  4. * See the file ''LICENSE'' for using the code.
  5. *
  6. * https://github.com/muhku/FreeStreamer
  7. */
  8. #ifndef ASTREAMER_CACHING_STREAM_H
  9. #define ASTREAMER_CACHING_STREAM_H
  10. #include "input_stream.h"
  11. namespace astreamer {
  12. class File_Output;
  13. class File_Stream;
  14. class Caching_Stream : public Input_Stream, public Input_Stream_Delegate {
  15. private:
  16. Input_Stream *m_target;
  17. File_Output *m_fileOutput;
  18. File_Stream *m_fileStream;
  19. bool m_cacheable;
  20. bool m_writable;
  21. bool m_useCache;
  22. bool m_cacheMetaDataWritten;
  23. CFStringRef m_cacheIdentifier;
  24. CFURLRef m_fileUrl;
  25. CFURLRef m_metaDataUrl;
  26. private:
  27. CFURLRef createFileURLWithPath(CFStringRef path);
  28. void readMetaData();
  29. public:
  30. Caching_Stream(Input_Stream *target);
  31. virtual ~Caching_Stream();
  32. Input_Stream_Position position();
  33. CFStringRef contentType();
  34. size_t contentLength();
  35. bool open();
  36. bool open(const Input_Stream_Position& position);
  37. void close();
  38. void setScheduledInRunLoop(bool scheduledInRunLoop);
  39. void setUrl(CFURLRef url);
  40. void setCacheIdentifier(CFStringRef cacheIdentifier);
  41. static bool canHandleUrl(CFURLRef url);
  42. /* ID3_Parser_Delegate */
  43. void id3metaDataAvailable(std::map<CFStringRef,CFStringRef> metaData);
  44. void id3tagSizeAvailable(UInt32 tagSize);
  45. void streamIsReadyRead();
  46. void streamHasBytesAvailable(UInt8 *data, UInt32 numBytes);
  47. void streamEndEncountered();
  48. void streamErrorOccurred(CFStringRef errorDesc);
  49. void streamMetaDataAvailable(std::map<CFStringRef,CFStringRef> metaData);
  50. void streamMetaDataByteSizeAvailable(UInt32 sizeInBytes);
  51. };
  52. } // namespace astreamer
  53. #endif /* ASTREAMER_CACHING_STREAM_H */