/DirectShowFilters/TsWriter/source/MultiFileWriter.h

https://github.com/MediaPortal/MediaPortal-1 · C Header · 124 lines · 72 code · 25 blank · 27 comment · 0 complexity · d04a1281e605d9d3c6a3c235259b3595 MD5 · raw file

  1. /**
  2. * MultiFileWriter.h
  3. * Copyright (C) 2006-2007 nate
  4. *
  5. * This file is part of TSFileSource, a directshow push source filter that
  6. * provides an MPEG transport stream output.
  7. *
  8. * TSFileSource is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * TSFileSource is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with TSFileSource; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * nate can be reached on the forums at
  23. * http://forums.dvbowners.com/
  24. */
  25. #ifndef MULTIFILEWRITER
  26. #define MULTIFILEWRITER
  27. #include "FileWriter.h"
  28. #include "CDiskBuff.h"
  29. #include <vector>
  30. //Variable size buffers are used - CDiskBuff::CDiskBuff(int size)
  31. #define FULL_BUFFERS 256
  32. #define NOT_FULL_BUFFERS 192
  33. //Number of retries allowed when writing buffer files
  34. #define FILE_WRITE_RETRIES 19
  35. //System timer resolution in ms
  36. #define SYS_TIMER_RES 5
  37. typedef struct
  38. {
  39. long minFiles;
  40. long maxFiles;
  41. __int64 maxSize;
  42. __int64 chunkSize;
  43. } MultiFileWriterParam;
  44. class MultiFileWriter
  45. {
  46. public:
  47. MultiFileWriter(MultiFileWriterParam *pWriterParams);
  48. virtual ~MultiFileWriter();
  49. HRESULT Open(LPCWSTR pszFileName);
  50. HRESULT Close();
  51. HRESULT AddToBuffer(byte* pbData, int len, int newBuffSize);
  52. HRESULT DiscardBuffer();
  53. void GetPosition(__int64 * position, long * bufferId);
  54. protected:
  55. HRESULT OpenFile();
  56. HRESULT WriteToDisk(PBYTE pbData, ULONG lDataLength);
  57. HRESULT GetAvailableDiskSpace(__int64* llAvailableDiskSpace);
  58. HRESULT PushBuffer();
  59. HRESULT NewBuffer(int size);
  60. void ClearBuffers();
  61. HRESULT PrepareTSFile();
  62. HRESULT CreateNewTSFile();
  63. HRESULT ReuseTSFile();
  64. HRESULT WriteTSBufferFile();
  65. HRESULT CleanupFiles();
  66. BOOL IsFileLocked(LPWSTR pFilename);
  67. HANDLE m_hTSBufferFile;
  68. LPWSTR m_pTSBufferFileName;
  69. CDiskBuff* m_pDiskBuffer;
  70. CCritSec m_Lock;
  71. CCritSec m_posnLock;
  72. FileWriter *m_pCurrentTSFile;
  73. std::vector<LPWSTR> m_tsFileNames;
  74. long m_filesAdded;
  75. long m_filesRemoved;
  76. long m_currentFilenameId;
  77. long m_currentFileId;
  78. long m_minTSFiles;
  79. long m_maxTSFiles;
  80. __int64 m_maxTSFileSize;
  81. __int64 m_chunkReserve;
  82. UINT m_maxBuffersUsed;
  83. BOOL m_bDiskFull;
  84. BOOL m_bBufferFull;
  85. CCritSec m_qLock;
  86. std::vector<CDiskBuff*> m_writeQueue;
  87. typedef std::vector<CDiskBuff*>::iterator ivecDiskBuff;
  88. BOOL m_bThreadRunning;
  89. HANDLE m_hThreadProc;
  90. CAMEvent m_WakeThreadEvent;
  91. static unsigned __stdcall thread_function(void* p);
  92. unsigned __stdcall ThreadProc();
  93. HRESULT StartThread();
  94. void StopThread();
  95. DWORD m_dwTimerResolution; //Timer resolution variable
  96. UINT m_totalBuffers;
  97. UINT m_totalWakes;
  98. };
  99. #endif