Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added option to set timeshifting buffer sizes

  • Loading branch information...
commit a1035a6965e6fc05bd53d90bff18e2ce7fc8bb68 1 parent ba1636b
yamp authored
Showing with 6,213 additions and 110 deletions.
  1. BIN  TvEngine3/Filters/bin/MPFileWriter.ax
  2. BIN  TvEngine3/Filters/bin/TsWriter.ax
  3. BIN  TvEngine3/Filters/sources/MPWriter/MPFileWriter.suo
  4. +96 −0 TvEngine3/Filters/sources/MPWriter/MPTSWriter.vcproj
  5. BIN  TvEngine3/Filters/sources/MPWriter/Release/BuildLog.htm
  6. +26 −0 TvEngine3/Filters/sources/MPWriter/source/CriticalSection.cpp
  7. +42 −0 TvEngine3/Filters/sources/MPWriter/source/CriticalSection.h
  8. +61 −0 TvEngine3/Filters/sources/MPWriter/source/EnterCriticalSection.cpp
  9. +65 −0 TvEngine3/Filters/sources/MPWriter/source/EnterCriticalSection.h
  10. +529 −0 TvEngine3/Filters/sources/MPWriter/source/FileReader.cpp
  11. +77 −0 TvEngine3/Filters/sources/MPWriter/source/FileReader.h
  12. +425 −0 TvEngine3/Filters/sources/MPWriter/source/Global.h
  13. +7 −1 TvEngine3/Filters/sources/MPWriter/source/MPFileWriter.cpp
  14. +2 −0  TvEngine3/Filters/sources/MPWriter/source/MPFileWriter.h
  15. +94 −0 TvEngine3/Filters/sources/MPWriter/source/MultiFileReader.h
  16. +2 −0  TvEngine3/Filters/sources/MPWriter/source/MultiFileWriter.cpp
  17. +5 −1 TvEngine3/Filters/sources/MPWriter/source/MultiWriterFileSink.cpp
  18. +1 −1  TvEngine3/Filters/sources/MPWriter/source/MultiWriterFileSink.h
  19. +207 −0 TvEngine3/Filters/sources/MPWriter/source/PidInfo.cpp
  20. +95 −0 TvEngine3/Filters/sources/MPWriter/source/PidInfo.h
  21. +2,406 −0 TvEngine3/Filters/sources/MPWriter/source/PidParser.cpp
  22. +145 −0 TvEngine3/Filters/sources/MPWriter/source/PidParser.h
  23. +7 −1 TvEngine3/Filters/sources/MPWriter/source/ProgramToTransportStream.cpp
  24. +5 −0 TvEngine3/Filters/sources/MPWriter/source/ProgramToTransportStream.h
  25. +326 −0 TvEngine3/Filters/sources/MPWriter/source/SampleBuffer.cpp
  26. +258 −0 TvEngine3/Filters/sources/MPWriter/source/TSBuffer.cpp
  27. +60 −0 TvEngine3/Filters/sources/MPWriter/source/TSBuffer.h
  28. +589 −0 TvEngine3/Filters/sources/MPWriter/source/TsFileDuration.cpp
  29. +46 −0 TvEngine3/Filters/sources/MPWriter/source/TsFileDuration.h
  30. +175 −0 TvEngine3/Filters/sources/MPWriter/source/TsStreamFileSource.cpp
  31. +76 −0 TvEngine3/Filters/sources/MPWriter/source/TsStreamFileSource.hh
  32. +64 −0 TvEngine3/Filters/sources/MPWriter/source/samplebuffer.h
  33. +2 −0  TvEngine3/Filters/sources/TsWriter/source/MultiFileWriter.cpp
  34. +10 −0 TvEngine3/Filters/sources/TsWriter/source/TsWriter.cpp
  35. +2 −0  TvEngine3/Filters/sources/TsWriter/source/TsWriter.h
  36. +11 −3 TvEngine3/MPWebGuide/MPGuide/App_Code/WebGuideService.cs
  37. BIN  TvEngine3/MPWebGuide/MPGuideDeploy/MPGuide_deploy/ResolveAssemblyReference.cache
  38. +192 −87 TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.Designer.cs
  39. +28 −1 TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.cs
  40. +0 −10 TvEngine3/TVLibrary/TVLibrary/Implementations/Analog/Graphs/Analog/TvCardAnalog.cs
  41. +14 −0 TvEngine3/TVLibrary/TVLibrary/Implementations/Analog/Graphs/Analog/TvCardAnalogBase.cs
  42. +3 −5 TvEngine3/TVLibrary/TVLibrary/Implementations/DVB/Graphs/TvCardDvbBase.cs
  43. +1 −0  TvEngine3/TVLibrary/TVLibrary/Implementations/DVB/Graphs/TvDvbChannel.cs
  44. +4 −0 TvEngine3/TVLibrary/TVLibrary/Interfaces/Analyzer/IMPRecord.cs
  45. +1 −0  TvEngine3/TVLibrary/TVLibrary/Interfaces/Analyzer/ITsFilter.cs
  46. +49 −0 TvEngine3/TVLibrary/TvLibrary.Interfaces/ScanParameters.cs
  47. +5 −0 TvEngine3/TVLibrary/TvService/TvCard.cs
View
BIN  TvEngine3/Filters/bin/MPFileWriter.ax
Binary file not shown
View
BIN  TvEngine3/Filters/bin/TsWriter.ax
Binary file not shown
View
BIN  TvEngine3/Filters/sources/MPWriter/MPFileWriter.suo
Binary file not shown
View
96 TvEngine3/Filters/sources/MPWriter/MPTSWriter.vcproj
@@ -223,6 +223,30 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
+ RelativePath=".\source\CriticalSection.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\CriticalSection.h"
+ >
+ </File>
+ <File
+ RelativePath=".\source\EnterCriticalSection.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\EnterCriticalSection.h"
+ >
+ </File>
+ <File
+ RelativePath=".\source\FileReader.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\FileReader.h"
+ >
+ </File>
+ <File
RelativePath=".\source\FileWriter.cpp"
>
</File>
@@ -247,6 +271,14 @@
>
</File>
<File
+ RelativePath=".\source\MultiFileReader.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\MultiFileReader.h"
+ >
+ </File>
+ <File
RelativePath=".\source\MultiFileWriter.cpp"
>
</File>
@@ -259,14 +291,62 @@
>
</File>
<File
+ RelativePath=".\source\PidInfo.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\PidInfo.h"
+ >
+ </File>
+ <File
+ RelativePath=".\source\PidParser.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\PidParser.h"
+ >
+ </File>
+ <File
RelativePath=".\source\ProgramToTransportStream.cpp"
>
</File>
<File
+ RelativePath=".\source\SampleBuffer.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\samplebuffer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\source\TSBuffer.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\TSBuffer.h"
+ >
+ </File>
+ <File
+ RelativePath=".\source\TsFileDuration.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\TsFileDuration.h"
+ >
+ </File>
+ <File
RelativePath=".\source\TsHeader.cpp"
>
</File>
<File
+ RelativePath=".\source\TsStreamFileSource.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\source\TsStreamFileSource.hh"
+ >
+ </File>
+ <File
RelativePath=".\source\TSThread.cpp"
>
</File>
@@ -684,10 +764,26 @@
>
</File>
<File
+ RelativePath="..\StreamingServer\StreamingServer\liveMedia\MPEG2TransportStreamIndexFile.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\StreamingServer\StreamingServer\liveMedia\MPEG2TransportStreamIndexFile.hh"
+ >
+ </File>
+ <File
RelativePath="..\StreamingServer\StreamingServer\liveMedia\MPEG2TransportStreamMultiplexor.cpp"
>
</File>
<File
+ RelativePath="..\StreamingServer\StreamingServer\liveMedia\MPEG2TransportStreamTrickModeFilter.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\StreamingServer\StreamingServer\liveMedia\MPEG2TransportStreamTrickModeFilter.hh"
+ >
+ </File>
+ <File
RelativePath="..\StreamingServer\StreamingServer\liveMedia\MPEG4ESVideoRTPSink.cpp"
>
</File>
View
BIN  TvEngine3/Filters/sources/MPWriter/Release/BuildLog.htm
Binary file not shown
View
26 TvEngine3/Filters/sources/MPWriter/source/CriticalSection.cpp
@@ -0,0 +1,26 @@
+// CriticalSection.cpp: implementation of the CCriticalSection class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "CriticalSection.h"
+
+using namespace Mediaportal;
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CCriticalSection::CCriticalSection()
+{
+ ::InitializeCriticalSection( &m_cs );
+}
+
+CCriticalSection::~CCriticalSection()
+{
+ ::DeleteCriticalSection( &m_cs );
+}
+
+CCriticalSection::operator LPCRITICAL_SECTION()
+{
+ return &m_cs;
+}
View
42 TvEngine3/Filters/sources/MPWriter/source/CriticalSection.h
@@ -0,0 +1,42 @@
+// CriticalSection.h: interface for the CCriticalSection class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_CRITICALSECTION_H__3B3A15BD_92D5_4044_8D69_5E1B8F15F369__INCLUDED_)
+#define AFX_CRITICALSECTION_H__3B3A15BD_92D5_4044_8D69_5E1B8F15F369__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#ifndef _WINDOWS_
+#include <Windows.h>
+#endif /* _WINDOWS_ */
+
+
+namespace Mediaportal
+{
+ // Wrapper for critical section struct
+ class CCriticalSection
+ {
+ public:
+ // Constructor
+ // Initializes the critical section struct
+ CCriticalSection();
+ // Destructor
+ virtual ~CCriticalSection();
+
+ // Conversion operator
+ operator LPCRITICAL_SECTION();
+
+ private:
+ // Copy constructor is disabled
+ CCriticalSection(const CCriticalSection& src);
+ // operator= is disabled
+ CCriticalSection& operator=(const CCriticalSection& src);
+
+ CRITICAL_SECTION m_cs;
+ };
+}
+
+#endif // !defined(AFX_CRITICALSECTION_H__3B3A15BD_92D5_4044_8D69_5E1B8F15F369__INCLUDED_)
View
61 TvEngine3/Filters/sources/MPWriter/source/EnterCriticalSection.cpp
@@ -0,0 +1,61 @@
+// EnterCriticalSection.cpp: implementation of the CEnterCriticalSection class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "EnterCriticalSection.h"
+
+using namespace Mediaportal;
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CEnterCriticalSection::CEnterCriticalSection(CCriticalSection& cs)
+: m_cs( cs )
+, m_bIsOwner( false )
+{
+ Enter();
+}
+
+CEnterCriticalSection::CEnterCriticalSection(const CCriticalSection& cs)
+: m_cs( const_cast<CCriticalSection&>(cs) )
+, m_bIsOwner( false )
+{
+ Enter();
+}
+
+CEnterCriticalSection::~CEnterCriticalSection()
+{
+ Leave();
+}
+
+bool CEnterCriticalSection::IsOwner() const
+{
+ return m_bIsOwner;
+}
+
+bool CEnterCriticalSection::Enter()
+{
+ // Test if we already own the critical section
+ if ( true == m_bIsOwner )
+ {
+ return true;
+ }
+
+ // Blocking call
+ ::EnterCriticalSection( m_cs );
+ m_bIsOwner = true;
+
+ return m_bIsOwner;
+}
+
+void CEnterCriticalSection::Leave()
+{
+ if ( false == m_bIsOwner )
+ {
+ return;
+ }
+
+ ::LeaveCriticalSection( m_cs );
+ m_bIsOwner = false;
+}
View
65 TvEngine3/Filters/sources/MPWriter/source/EnterCriticalSection.h
@@ -0,0 +1,65 @@
+// EnterCriticalSection.h: interface for the CEnterCriticalSection class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_ENTERCRITICALSECTION_H__AFDC94FA_28D1_47FA_BB4F_F2F852C1B660__INCLUDED_)
+#define AFX_ENTERCRITICALSECTION_H__AFDC94FA_28D1_47FA_BB4F_F2F852C1B660__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+
+//#ifndef _WINDOWS_
+//// Minimum system required: Windows NT 4.0
+//#define _WIN32_WINNT 0x0400
+//#define WINVER 0x0400
+//#include <Windows.h>
+//#endif /* _WINDOWS_ */
+
+#if !defined(AFX_CRITICALSECTION_H__3B3A15BD_92D5_4044_8D69_5E1B8F15F369__INCLUDED_)
+#include "CriticalSection.h"
+#endif // !defined(AFX_CRITICALSECTION_H__3B3A15BD_92D5_4044_8D69_5E1B8F15F369__INCLUDED_)
+
+
+namespace Mediaportal
+{
+ // Use to enter a critical section
+ // Can only be used in blocking fashion
+ // Critical section ends with object scope
+ class CEnterCriticalSection
+ {
+ public:
+ // Constructor
+ // Obtain ownership of the cricital section
+ CEnterCriticalSection(CCriticalSection& cs);
+ // Constructor
+ // Obtain ownership of the cricital section
+ // The const attribute will be removed with the const_cast operator
+ // This enables the use of critical sections in const members
+ CEnterCriticalSection(const CCriticalSection& cs);
+ // Destructor
+ // Leaves the critical section
+ virtual ~CEnterCriticalSection();
+
+ // Test critical section ownership
+ // Returns true if ownership was granted
+ bool IsOwner() const;
+ // Obtain ownership (may block)
+ // Returns true when ownership was granted
+ bool Enter();
+ // Leave the critical section
+ void Leave();
+
+ private:
+ CEnterCriticalSection(const CEnterCriticalSection& src);
+ CEnterCriticalSection& operator=(const CEnterCriticalSection& src);
+
+ // Reference to critical section object
+ CCriticalSection& m_cs;
+ // Ownership flag
+ bool m_bIsOwner;
+ };
+}
+
+#endif // !defined(AFX_ENTERCRITICALSECTION_H__AFDC94FA_28D1_47FA_BB4F_F2F852C1B660__INCLUDED_)
View
529 TvEngine3/Filters/sources/MPWriter/source/FileReader.cpp
@@ -0,0 +1,529 @@
+/**
+* FileReader.cpp
+* Copyright (C) 2005 nate
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+
+//#include <streams.h>
+#include "FileReader.h"
+#include <stdio.h>
+extern void Log(const char *fmt, ...) ;
+FileReader::FileReader() :
+ m_hFile(INVALID_HANDLE_VALUE),
+ m_bReadOnly(FALSE),
+ m_fileSize(0),
+ m_infoFileSize(0),
+ m_fileStartPos(0),
+ m_hInfoFile(INVALID_HANDLE_VALUE),
+ m_bDelay(FALSE),
+ m_bDebugOutput(FALSE)
+{
+}
+
+FileReader::~FileReader()
+{
+ CloseFile();
+
+}
+
+FileReader* FileReader::CreateFileReader()
+{
+ return new FileReader();
+}
+
+int FileReader::GetFileName(char *lpszFileName)
+{
+ strcpy(lpszFileName,m_fileName);
+ return S_OK;
+}
+
+int FileReader::SetFileName(char* pszFileName)
+{
+ // Is this a valid filename supplied
+ //CheckPointer(pszFileName,E_POINTER);
+
+ strcpy(m_fileName,pszFileName);
+
+ return S_OK;
+}
+
+//
+// OpenFile
+//
+// Opens the file ready for streaming
+//
+int FileReader::OpenFile()
+{
+
+ //printf("FileReader::OpenFile(%s)\n",m_fileName);
+ // Is the file already opened
+ if (m_hFile != INVALID_HANDLE_VALUE)
+ {
+ Log("FileReader::OpenFile() already opened");
+ return NOERROR;
+ }
+
+
+
+ m_bReadOnly = FALSE;
+
+ // Try to open the file
+ m_hFile = CreateFileA((LPCSTR)m_fileName, // The filename
+ GENERIC_READ, // File access
+ FILE_SHARE_READ, // Share access
+ NULL, // Security
+ OPEN_EXISTING, // Open flags
+ (DWORD) 0, // More flags
+ NULL); // Template
+
+ if (m_hFile == INVALID_HANDLE_VALUE)
+ {
+
+ //Test incase file is being recorded to
+ m_hFile = CreateFileA((LPCSTR)m_fileName, // The filename
+ GENERIC_READ, // File access
+ FILE_SHARE_READ |
+ FILE_SHARE_WRITE, // Share access
+ NULL, // Security
+ OPEN_EXISTING, // Open flags
+ FILE_ATTRIBUTE_NORMAL, // More flags
+// FILE_ATTRIBUTE_NORMAL |
+// FILE_FLAG_RANDOM_ACCESS, // More flags
+// FILE_FLAG_SEQUENTIAL_SCAN, // More flags
+ NULL); // Template
+
+ if (m_hFile == INVALID_HANDLE_VALUE)
+ {
+ DWORD dwErr = GetLastError();
+ Log("FileReader::OpenFile(%s) failed:%d",(LPCSTR)m_fileName,dwErr);
+ return (int)dwErr;
+ }
+
+ m_bReadOnly = TRUE;
+ //printf("FileReader::OpenFile() succeeded\n");
+ }
+/*
+ char infoName[512];
+ strcpy(infoName, m_fileName);
+ strcat(infoName, ".info");
+
+ m_hInfoFile = CreateFile(m_fileName, // The filename
+ GENERIC_READ, // File access
+ FILE_SHARE_READ |
+ FILE_SHARE_WRITE, // Share access
+ NULL, // Security
+ OPEN_EXISTING, // Open flags
+ FILE_ATTRIBUTE_NORMAL, // More flags
+// FILE_FLAG_SEQUENTIAL_SCAN, // More flags
+// FILE_ATTRIBUTE_NORMAL |
+// FILE_FLAG_RANDOM_ACCESS, // More flags
+ NULL);
+*/
+ SetFilePointer(0, FILE_BEGIN);
+
+ return S_OK;
+
+} // Open
+
+//
+// CloseFile
+//
+// Closes any dump file we have opened
+//
+int FileReader::CloseFile()
+{
+ // Must lock this section to prevent problems related to
+ // closing the file while still receiving data in Receive()
+
+
+// printf("FileReader::CloseFile()\n");
+ if (m_hFile == INVALID_HANDLE_VALUE) {
+
+ return S_OK;
+ }
+
+ CloseHandle(m_hFile);
+ m_hFile = INVALID_HANDLE_VALUE; // Invalidate the file
+
+ if (m_hInfoFile != INVALID_HANDLE_VALUE)
+ CloseHandle(m_hInfoFile);
+
+ m_hInfoFile = INVALID_HANDLE_VALUE; // Invalidate the file
+
+ return NOERROR;
+
+} // CloseFile
+
+BOOL FileReader::IsFileInvalid()
+{
+ return (m_hFile == INVALID_HANDLE_VALUE);
+}
+
+__int64 FileReader::GetFileSize()
+{
+ __int64 pStartPosition =0;
+ __int64 pLength=0;
+ GetFileSize(&pStartPosition, &pLength);
+ return pLength;
+}
+int FileReader::GetFileSize(__int64 *pStartPosition, __int64 *pLength)
+{
+// CheckPointer(pStartPosition,E_POINTER);
+// CheckPointer(pLength,E_POINTER);
+
+ GetStartPosition(pStartPosition);
+
+ //Do not get file size if static file or first time
+ if (m_bReadOnly || !m_fileSize) {
+
+ if (m_hInfoFile != INVALID_HANDLE_VALUE)
+ {
+ __int64 length = -1;
+ DWORD read = 0;
+ LARGE_INTEGER li;
+ li.QuadPart = 0;
+ ::SetFilePointer(m_hInfoFile, li.LowPart, &li.HighPart, FILE_BEGIN);
+ ReadFile(m_hInfoFile, (PVOID)&length, (DWORD)sizeof(__int64), &read, NULL);
+
+ if(length > -1)
+ {
+ m_fileSize = length;
+ *pLength = length;
+ return S_OK;
+ }
+ }
+
+
+ DWORD dwSizeLow;
+ DWORD dwSizeHigh;
+
+ dwSizeLow = ::GetFileSize(m_hFile, &dwSizeHigh);
+ if ((dwSizeLow == 0xFFFFFFFF) && (GetLastError() != NO_ERROR ))
+ {
+ Log("FileReader::GetFileSize() failed()");
+ return E_FAIL;
+ }
+
+ LARGE_INTEGER li;
+ li.LowPart = dwSizeLow;
+ li.HighPart = dwSizeHigh;
+ m_fileSize = li.QuadPart;
+ }
+ //printf("FileReader::GetFileSize() :%d\n",(int)m_fileSize );
+ *pLength = m_fileSize;
+ return S_OK;
+}
+
+int FileReader::GetInfoFileSize(__int64 *lpllsize)
+{
+ //Do not get file size if static file or first time
+ if (m_bReadOnly || !m_infoFileSize) {
+
+ DWORD dwSizeLow;
+ DWORD dwSizeHigh;
+
+ dwSizeLow = ::GetFileSize(m_hInfoFile, &dwSizeHigh);
+ if ((dwSizeLow == 0xFFFFFFFF) && (GetLastError() != NO_ERROR ))
+ {
+ return E_FAIL;
+ }
+
+ LARGE_INTEGER li;
+ li.LowPart = dwSizeLow;
+ li.HighPart = dwSizeHigh;
+ m_infoFileSize = li.QuadPart;
+
+ }
+ *lpllsize = m_infoFileSize;
+ return S_OK;
+}
+
+int FileReader::GetStartPosition(__int64 *lpllpos)
+{
+ //Do not get file size if static file unless first time
+ if (m_bReadOnly || !m_fileStartPos) {
+
+ if (m_hInfoFile != INVALID_HANDLE_VALUE)
+ {
+ __int64 size = 0;
+ GetInfoFileSize(&size);
+ //Check if timeshift info file
+ if (size > sizeof(__int64))
+ {
+ //Get the file start pointer
+ __int64 length = -1;
+ DWORD read = 0;
+ LARGE_INTEGER li;
+ li.QuadPart = sizeof(__int64);
+ ::SetFilePointer(m_hInfoFile, li.LowPart, &li.HighPart, FILE_BEGIN);
+ ReadFile(m_hInfoFile, (PVOID)&length, (DWORD)sizeof(__int64), &read, NULL);
+
+ if(length > -1)
+ {
+ m_fileStartPos = length;
+ *lpllpos = length;
+ return S_OK;
+ }
+ }
+ }
+ m_fileStartPos = 0;
+ }
+ *lpllpos = m_fileStartPos;
+ return S_OK;
+}
+
+DWORD FileReader::SetFilePointer(__int64 llDistanceToMove, DWORD dwMoveMethod)
+{
+ LARGE_INTEGER li;
+
+ if (dwMoveMethod == FILE_END && m_hInfoFile != INVALID_HANDLE_VALUE)
+ {
+ __int64 startPos = 0;
+ GetStartPosition(&startPos);
+
+ if (startPos > 0)
+ {
+ __int64 start;
+ __int64 fileSize = 0;
+ GetFileSize(&start, &fileSize);
+
+ __int64 filePos = (__int64)((__int64)fileSize + (__int64)llDistanceToMove + (__int64)startPos);
+
+ if (filePos >= fileSize)
+ li.QuadPart = (__int64)((__int64)startPos + (__int64)llDistanceToMove);
+ else
+ li.QuadPart = filePos;
+
+ return ::SetFilePointer(m_hFile, li.LowPart, &li.HighPart, FILE_BEGIN);
+ }
+
+ __int64 start = 0;
+ __int64 length = 0;
+ GetFileSize(&start, &length);
+
+ length = (__int64)((__int64)length + (__int64)llDistanceToMove);
+
+ li.QuadPart = length;
+
+ dwMoveMethod = FILE_BEGIN;
+ }
+ else
+ {
+ __int64 startPos = 0;
+ GetStartPosition(&startPos);
+
+ if (startPos > 0)
+ {
+ __int64 start;
+ __int64 fileSize = 0;
+ GetFileSize(&start, &fileSize);
+
+ __int64 filePos = (__int64)((__int64)startPos + (__int64)llDistanceToMove);
+
+ if (filePos >= fileSize)
+ li.QuadPart = (__int64)((__int64)filePos - (__int64)fileSize);
+ else
+ li.QuadPart = filePos;
+
+ return ::SetFilePointer(m_hFile, li.LowPart, &li.HighPart, dwMoveMethod);
+ }
+ li.QuadPart = llDistanceToMove;
+ }
+
+ return ::SetFilePointer(m_hFile, li.LowPart, &li.HighPart, dwMoveMethod);
+}
+
+__int64 FileReader::GetFilePointer()
+{
+ LARGE_INTEGER li;
+ li.QuadPart = 0;
+ li.LowPart = ::SetFilePointer(m_hFile, 0, &li.HighPart, FILE_CURRENT);
+
+ __int64 start;
+ __int64 length = 0;
+ GetFileSize(&start, &length);
+
+ __int64 startPos = 0;
+ GetStartPosition(&startPos);
+
+ if (startPos > 0)
+ {
+ if(startPos > (__int64)li.QuadPart)
+ li.QuadPart = (__int64)(length - startPos + (__int64)li.QuadPart);
+ else
+ li.QuadPart = (__int64)((__int64)li.QuadPart - startPos);
+ }
+
+ return li.QuadPart;
+}
+
+int FileReader::Read(PBYTE pbData, ULONG lDataLength, ULONG *dwReadBytes)
+{
+ int hr;
+ //printf("FileReader::Read:%d\n", (int)lDataLength);
+ // If the file has already been closed, don't continue
+ if (m_hFile == INVALID_HANDLE_VALUE)
+ return S_FALSE;
+
+ //Get File Position
+ LARGE_INTEGER li;
+ li.QuadPart = 0;
+ li.LowPart = ::SetFilePointer(m_hFile, 0, &li.HighPart, FILE_CURRENT);
+ __int64 m_filecurrent = li.QuadPart;
+
+ if (m_hInfoFile != INVALID_HANDLE_VALUE)
+ {
+ __int64 startPos = 0;
+ GetStartPosition(&startPos);
+
+ if (startPos > 0)
+ {
+ __int64 start;
+ __int64 length = 0;
+ GetFileSize(&start, &length);
+
+ if (length < (__int64)(m_filecurrent + (__int64)lDataLength) && m_filecurrent > startPos)
+ {
+
+ hr = ReadFile(m_hFile, (PVOID)pbData, (DWORD)(length - m_filecurrent), dwReadBytes, NULL);
+ if (FAILED(hr))
+ {
+ //printf(" read failed:%d",hr);
+ return hr;
+ }
+ LARGE_INTEGER li;
+ li.QuadPart = 0;
+ ::SetFilePointer(m_hFile, li.LowPart, &li.HighPart, FILE_BEGIN);
+
+ ULONG dwRead = 0;
+
+ hr = ReadFile(m_hFile,
+ (PVOID)(pbData + (DWORD)(length - m_filecurrent)),
+ (DWORD)((__int64)lDataLength -(__int64)((__int64)length - (__int64)m_filecurrent)),
+ &dwRead,
+ NULL);
+
+ *dwReadBytes = *dwReadBytes + dwRead;
+
+ }
+ else if (startPos < (__int64)(m_filecurrent + (__int64)lDataLength) && m_filecurrent < startPos)
+ hr = ReadFile(m_hFile, (PVOID)pbData, (DWORD)(startPos - m_filecurrent), dwReadBytes, NULL);
+
+ else
+ hr = ReadFile(m_hFile, (PVOID)pbData, (DWORD)lDataLength, dwReadBytes, NULL);
+
+
+ if (FAILED(hr))
+ {
+ //printf(" read failed:%d",hr);
+ return hr;
+ }
+ if (*dwReadBytes < (ULONG)lDataLength)
+ {
+ //printf(" read failed not enough data :%d/%d",(int)(*dwReadBytes), (int)lDataLength);
+ return S_FALSE;
+ }
+
+ return S_OK;
+ }
+
+ __int64 start = 0;
+ __int64 length = 0;
+ GetFileSize(&start, &length);
+ if (length < (__int64)(m_filecurrent + (__int64)lDataLength))
+ hr = ReadFile(m_hFile, (PVOID)pbData, (DWORD)(length - m_filecurrent), dwReadBytes, NULL);
+ else
+ hr = ReadFile(m_hFile, (PVOID)pbData, (DWORD)lDataLength, dwReadBytes, NULL);
+ }
+ else
+ hr = ReadFile(m_hFile, (PVOID)pbData, (DWORD)lDataLength, dwReadBytes, NULL);//Read file data into buffer
+
+ if (FAILED(hr))
+ {
+ //printf(" read failed:%d",hr);
+ return hr;
+ }
+ if (*dwReadBytes < (ULONG)lDataLength)
+ {
+ //printf(" read failed not enough data :%d/%d",(int)(*dwReadBytes), (int)lDataLength);
+ return S_FALSE;
+ }
+ return S_OK;
+}
+
+int FileReader::Read(PBYTE pbData, ULONG lDataLength, ULONG *dwReadBytes, __int64 llDistanceToMove, DWORD dwMoveMethod)
+{
+ //If end method then we want llDistanceToMove to be the end of the buffer that we read.
+ if (dwMoveMethod == FILE_END)
+ llDistanceToMove = 0 - llDistanceToMove - lDataLength;
+
+ SetFilePointer(llDistanceToMove, dwMoveMethod);
+
+ return Read(pbData, lDataLength, dwReadBytes);
+}
+
+int FileReader::get_ReadOnly(WORD *ReadOnly)
+{
+ *ReadOnly = m_bReadOnly;
+ return S_OK;
+}
+
+int FileReader::get_DelayMode(WORD *DelayMode)
+{
+ *DelayMode = m_bDelay;
+ return S_OK;
+}
+
+int FileReader::set_DelayMode(WORD DelayMode)
+{
+ m_bDelay = DelayMode;
+ return S_OK;
+}
+
+int FileReader::get_ReaderMode(WORD *ReaderMode)
+{
+ *ReaderMode = FALSE;
+ return S_OK;
+}
+
+void FileReader::SetDebugOutput(BOOL bDebugOutput)
+{
+ m_bDebugOutput = bDebugOutput;
+}
+
+DWORD FileReader::setFilePointer(__int64 llDistanceToMove, DWORD dwMoveMethod)
+{
+ //Get the file information
+ __int64 fileStart, fileEnd, fileLength;
+ GetFileSize(&fileStart, &fileLength);
+ fileEnd = fileLength;
+ if (dwMoveMethod == FILE_BEGIN)
+ return SetFilePointer((__int64)min(fileEnd, llDistanceToMove), FILE_BEGIN);
+ else
+ return SetFilePointer((__int64)max((__int64)-fileLength, llDistanceToMove), FILE_END);
+}
+
+__int64 FileReader::getFilePointer()
+{
+ return GetFilePointer();
+}
+
View
77 TvEngine3/Filters/sources/MPWriter/source/FileReader.h
@@ -0,0 +1,77 @@
+/**
+* FileReader.h
+* Copyright (C) 2005 nate
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+
+#ifndef FILEREADER
+#define FILEREADER
+
+//#include "PidInfo.h"
+#include <windows.h>
+
+class FileReader
+{
+public:
+
+ FileReader();
+ virtual ~FileReader();
+
+ virtual FileReader* CreateFileReader();
+
+ // Open and write to the file
+ virtual int GetFileName(char *lpszFileName);
+ virtual int SetFileName(char* pszFileName);
+ virtual int OpenFile();
+ virtual int CloseFile();
+ virtual int Read(BYTE* pbData, ULONG lDataLength, ULONG *dwReadBytes);
+ virtual int Read(BYTE* pbData, ULONG lDataLength, ULONG *dwReadBytes, __int64 llDistanceToMove, DWORD dwMoveMethod);
+ virtual int get_ReadOnly(WORD *ReadOnly);
+ virtual int get_DelayMode(WORD *DelayMode);
+ virtual int set_DelayMode(WORD DelayMode);
+ virtual int get_ReaderMode(WORD *ReaderMode);
+ virtual __int64 GetFileSize();
+ virtual int GetFileSize(__int64 *pStartPosition, __int64 *pLength);
+ int GetInfoFileSize(__int64 *lpllsize);
+ int GetStartPosition(__int64 *lpllpos);
+ virtual BOOL IsFileInvalid();
+ virtual DWORD SetFilePointer(__int64 llDistanceToMove, DWORD dwMoveMethod);
+ virtual __int64 GetFilePointer();
+ virtual DWORD setFilePointer(__int64 llDistanceToMove, DWORD dwMoveMethod);
+ virtual __int64 getFilePointer();
+
+ void SetDebugOutput(BOOL bDebugOutput);
+
+protected:
+ HANDLE m_hFile; // Handle to file for streaming
+ HANDLE m_hInfoFile; // Handle to Infofile for filesize from FileWriter
+ char m_fileName[1024]; // The filename where we stream
+ BOOL m_bReadOnly;
+ BOOL m_bDelay;
+ __int64 m_fileSize;
+ __int64 m_infoFileSize;
+ __int64 m_fileStartPos;
+
+ BOOL m_bDebugOutput;
+};
+
+#endif
View
425 TvEngine3/Filters/sources/MPWriter/source/Global.h
@@ -0,0 +1,425 @@
+/**
+* Global.h
+* Copyright (C) 2003 bisswanger
+* Copyright (C) 2004-2006 bear
+* Copyright (C) 2005 nate
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* bisswanger can be reached at WinSTB@hotmail.com
+* Homepage: http://www.winstb.de
+*
+* bear and nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#ifndef ABOVE_NORMAL_PRIORITY_CLASS
+#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
+#endif
+
+#ifndef BELOW_NORMAL_PRIORITY_CLASS
+#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000
+#endif
+
+#ifndef FILE_START_POS_TS
+#define FILE_START_POS_TS 500000 //Minimum file position to begin parsing for TS Mode
+#endif
+
+#ifndef RT_FILE_START_TS
+#define RT_FILE_START_TS 1000000 //0.1sec stream position to begin playing in TS Mode
+#endif
+
+#ifndef FILE_START_POS_PS
+#define FILE_START_POS_PS 1 //Minimum file position to begin parsing for PS Mode
+#endif
+
+#ifndef RT_FILE_START_PS
+#define RT_FILE_START_PS 1 //0sec stream position to begin playing in PS Mode
+#endif
+
+#ifndef MIN_FILE_SIZE
+#define MIN_FILE_SIZE 2000000 //Minimum filesize to parse
+#endif
+
+#ifndef RT_SECOND
+#define RT_SECOND 10000000 //1sec
+#endif
+
+#ifndef RT_2_SECOND
+#define RT_2_SECOND 20000000 //2 sec
+#endif
+
+/**********************************************
+ *
+ * CBufferInfo Class
+ *
+ **********************************************/
+
+class CBufferInfo
+{
+public:
+ CBufferInfo(){};
+ virtual ~CBufferInfo(){};
+
+ BYTE *sample;
+ long size;
+};
+
+class BoostThread
+{
+public:
+ BoostThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ m_nPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL - 1);
+ }
+ #endif
+ }
+
+ ~BoostThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ }
+ #endif
+ }
+
+ int m_nPriority;
+};
+
+class LowBoostThread
+{
+public:
+ LowBoostThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ m_nPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL - 2);
+ }
+ #endif
+ }
+
+ ~LowBoostThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ }
+ #endif
+ }
+
+ int m_nPriority;
+};
+
+class HighestThread
+{
+public:
+ HighestThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ m_nPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+ }
+ #endif
+ }
+
+ ~HighestThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ }
+ #endif
+ }
+
+ int m_nPriority;
+};
+
+class AbnormalThread
+{
+public:
+ AbnormalThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ m_nPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+ }
+ #endif
+ }
+
+ ~AbnormalThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ }
+ #endif
+ }
+
+ int m_nPriority;
+};
+
+class NormalThread
+{
+public:
+ NormalThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ m_nPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+ }
+ #endif
+ }
+
+ ~NormalThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ }
+ #endif
+ }
+
+ int m_nPriority;
+};
+
+class BrakeThread
+{
+public:
+ BrakeThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ m_nPriority = GetThreadPriority(GetCurrentThread());
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
+ }
+ #endif
+ }
+
+ ~BrakeThread()
+ {
+ #ifndef DEBUG
+ if ((int)GetPriorityClass(GetCurrentProcess()) != IDLE_PRIORITY_CLASS)
+ {
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ }
+ #endif
+ }
+
+ int m_nPriority;
+};
+
+class BoostProcess
+{
+public:
+ BoostProcess()
+ {
+ #ifndef DEBUG
+ m_nPriority = GetPriorityClass(GetCurrentProcess());
+ SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
+ #endif
+ }
+
+ ~BoostProcess()
+ {
+ #ifndef DEBUG
+ SetPriorityClass(GetCurrentProcess(), m_nPriority);
+ #endif
+ }
+
+ DWORD m_nPriority;
+};
+
+class HighProcess
+{
+public:
+ HighProcess()
+ {
+ #ifndef DEBUG
+ m_nPriority = GetPriorityClass(GetCurrentProcess());
+ SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
+ #endif
+ }
+
+ ~HighProcess()
+ {
+ #ifndef DEBUG
+ SetPriorityClass(GetCurrentProcess(), m_nPriority);
+ #endif
+ }
+
+ DWORD m_nPriority;
+};
+
+class AbnormalProcess
+{
+public:
+ AbnormalProcess()
+ {
+ #ifndef DEBUG
+ m_nPriority = GetPriorityClass(GetCurrentProcess());
+ SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
+ #endif
+ }
+
+ ~AbnormalProcess()
+ {
+ #ifndef DEBUG
+ SetThreadPriority(GetCurrentThread(), m_nPriority);
+ #endif
+ }
+
+ DWORD m_nPriority;
+};
+
+class NormalProcess
+{
+public:
+ NormalProcess()
+ {
+ #ifndef DEBUG
+ m_nPriority = GetPriorityClass(GetCurrentProcess());
+ SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
+ #endif
+ }
+
+ ~NormalProcess()
+ {
+ #ifndef DEBUG
+ SetPriorityClass(GetCurrentProcess(), m_nPriority);
+ #endif
+ }
+
+ DWORD m_nPriority;
+};
+
+class BelowNormalProcess
+{
+public:
+ BelowNormalProcess()
+ {
+ #ifndef DEBUG
+ m_nPriority = GetPriorityClass(GetCurrentProcess());
+ SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
+ #endif
+ }
+
+ ~BelowNormalProcess()
+ {
+ #ifndef DEBUG
+ SetPriorityClass(GetCurrentProcess(), m_nPriority);
+ #endif
+ }
+
+ DWORD m_nPriority;
+};
+
+class IdleProcess
+{
+public:
+ IdleProcess()
+ {
+ #ifndef DEBUG
+ m_nPriority = GetPriorityClass(GetCurrentProcess());
+ SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
+ #endif
+ }
+
+ ~IdleProcess()
+ {
+ #ifndef DEBUG
+ SetPriorityClass(GetCurrentProcess(), m_nPriority);
+ #endif
+ }
+
+ DWORD m_nPriority;
+};
+
+class FirstAffinity
+{
+public:
+ FirstAffinity()
+ {
+ #ifndef DEBUG
+ m_nAffinity = 0;
+ DWORD SystemAffinityMask = 0;
+ if (GetProcessAffinityMask(GetCurrentProcess(), &m_nAffinity, &SystemAffinityMask)
+ && SystemAffinityMask > 1)
+ SetThreadAffinityMask(GetCurrentThread(), 0x01&m_nAffinity);
+ #endif
+ }
+
+ ~FirstAffinity()
+ {
+ #ifndef DEBUG
+ if (m_nAffinity)
+ SetThreadAffinityMask(GetCurrentThread(), m_nAffinity);
+ #endif
+ }
+
+ DWORD m_nAffinity;
+};
+
+class SecondAffinity
+{
+public:
+ SecondAffinity()
+ {
+ #ifndef DEBUG
+ m_nAffinity = 0;
+ DWORD SystemAffinityMask = 0;
+ if (GetProcessAffinityMask(GetCurrentProcess(), &m_nAffinity, &SystemAffinityMask)
+ && SystemAffinityMask > 1)
+ SetThreadAffinityMask(GetCurrentThread(), 0x10&m_nAffinity);
+ #endif
+ }
+
+ ~SecondAffinity()
+ {
+ #ifndef DEBUG
+ if (m_nAffinity)
+ SetThreadAffinityMask(GetCurrentThread(), m_nAffinity);
+ #endif
+ }
+
+ DWORD m_nAffinity;
+};
+
+#endif
+
+
View
8 TvEngine3/Filters/sources/MPWriter/source/MPFileWriter.cpp
@@ -492,6 +492,12 @@ STDMETHODIMP CDump::SetTimeShiftFileName(char* pszFileName)
strcat(m_strTimeShiftFileName,".tsbuffer");
return S_OK;
}
+
+STDMETHODIMP CDump::SetTimeShiftParams( int minFiles, int maxFiles, ULONG maxFileSize)
+{
+ m_tsWriter.SetTimeShiftParams( minFiles, maxFiles, maxFileSize);
+ return S_OK;
+}
STDMETHODIMP CDump::StartTimeShifting( )
{
CAutoLock lock(&m_Lock);
@@ -616,4 +622,4 @@ STDMETHODIMP CDump::Reset()
{
m_pPin->Reset();
return S_OK;
-}
+}
View
2  TvEngine3/Filters/sources/MPWriter/source/MPFileWriter.h
@@ -31,6 +31,7 @@ DECLARE_INTERFACE_(IMPFileRecord, IUnknown)
STDMETHOD(StartTimeShifting)(THIS_ )PURE;
STDMETHOD(StopTimeShifting)(THIS_ )PURE;
STDMETHOD(PauseTimeShifting)(THIS_ int onOff)PURE;
+ STDMETHOD(SetTimeShiftParams)(THIS_ int minFiles, int maxFiles, ULONG maxFileSize)PURE;
};
// Main filter object
@@ -126,6 +127,7 @@ class CDump : public CUnknown, public IMPFileRecord
STDMETHODIMP StartTimeShifting();
STDMETHODIMP StopTimeShifting();
STDMETHODIMP PauseTimeShifting(int onOff);
+ STDMETHODIMP SetTimeShiftParams( int minFiles, int maxFiles, ULONG maxFileSize);
private:
// Overriden to say what interfaces we support where
View
94 TvEngine3/Filters/sources/MPWriter/source/MultiFileReader.h
@@ -0,0 +1,94 @@
+/**
+* MultiFileReader.h
+* Copyright (C) 2005 nate
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+
+#ifndef MULTIFILEREADER
+#define MULTIFILEREADER
+
+#include "FileReader.h"
+#include <vector>
+
+class MultiFileReaderFile
+{
+public:
+ char filename[1024];
+ __int64 startPosition;
+ __int64 length;
+ long filePositionId;
+};
+
+class MultiFileReader : public FileReader
+{
+public:
+
+ MultiFileReader();
+ virtual ~MultiFileReader();
+
+ virtual FileReader* CreateFileReader();
+
+ virtual int GetFileName(char *lpszFileName);
+ virtual int SetFileName(char *pszFileName);
+ virtual int OpenFile();
+ virtual int CloseFile();
+ virtual int Read(BYTE* pbData, ULONG lDataLength, ULONG *dwReadBytes);
+ virtual int Read(BYTE* pbData, ULONG lDataLength, ULONG *dwReadBytes, __int64 llDistanceToMove, DWORD dwMoveMethod);
+ virtual int get_ReadOnly(WORD *ReadOnly);
+ virtual int set_DelayMode(WORD DelayMode);
+ virtual int get_DelayMode(WORD *DelayMode);
+ virtual int get_ReaderMode(WORD *ReaderMode);
+ virtual DWORD setFilePointer(__int64 llDistanceToMove, DWORD dwMoveMethod);
+ virtual __int64 getFilePointer();
+
+ //TODO: GetFileSize should go since get_FileSize should do the same thing.
+ virtual int GetFileSize(__int64 *pStartPosition, __int64 *pLength);
+
+ virtual BOOL IsFileInvalid();
+
+ virtual DWORD SetFilePointer(__int64 llDistanceToMove, DWORD dwMoveMethod);
+ virtual __int64 GetFilePointer();
+ virtual __int64 GetFileSize();
+
+protected:
+ int RefreshTSBufferFile();
+ int GetFileLength(char* pFilename, __int64 &length);
+ void RefreshFileSize();
+
+ FileReader m_TSBufferFile;
+ __int64 m_startPosition;
+ __int64 m_endPosition;
+ __int64 m_currentPosition;
+ long m_filesAdded;
+ long m_filesRemoved;
+
+ std::vector<MultiFileReaderFile *> m_tsFiles;
+
+ FileReader m_TSFile;
+ long m_TSFileId;
+ BOOL m_bReadOnly;
+ BOOL m_bDelay;
+ __int64 m_cachedFileSize;
+
+};
+
+#endif
View
2  TvEngine3/Filters/sources/MPWriter/source/MultiFileWriter.cpp
@@ -684,6 +684,7 @@ __int64 MultiFileWriter::getMaxTSFileSize(void)
void MultiFileWriter::setMaxTSFileSize(__int64 maxSize)
{
m_maxTSFileSize = maxSize;
+ m_pCurrentTSFile->SetChunkReserve(TRUE, m_chunkReserve, m_maxTSFileSize);
}
__int64 MultiFileWriter::getChunkReserve(void)
@@ -694,4 +695,5 @@ __int64 MultiFileWriter::getChunkReserve(void)
void MultiFileWriter::setChunkReserve(__int64 chunkSize)
{
m_chunkReserve = chunkSize;
+ m_pCurrentTSFile->SetChunkReserve(TRUE, m_chunkReserve, m_maxTSFileSize);
}
View
6 TvEngine3/Filters/sources/MPWriter/source/MultiWriterFileSink.cpp
@@ -31,12 +31,16 @@ CMultiWriterFileSink::~CMultiWriterFileSink()
}
}
-CMultiWriterFileSink* CMultiWriterFileSink::createNew(UsageEnvironment& env, char const* fileName,unsigned bufferSize, Boolean oneFilePerFrame)
+CMultiWriterFileSink* CMultiWriterFileSink::createNew(UsageEnvironment& env, char const* fileName,int minFiles, int maxFiles, ULONG maxFileSize,unsigned bufferSize, Boolean oneFilePerFrame)
{
do
{
LogDebug("CMultiWriterFileSink::create file:%s",fileName);
MultiFileWriter* fid = new MultiFileWriter();
+ fid->setMinTSFiles(minFiles);
+ fid->setMaxTSFiles(maxFiles);
+ fid->setChunkReserve(maxFileSize);
+ fid->setMaxTSFileSize(maxFileSize);
WCHAR wstrFileName[2048];
MultiByteToWideChar(CP_ACP,0,fileName,-1,wstrFileName,1+strlen(fileName));
if (FAILED(fid->OpenFile(wstrFileName)))
View
2  TvEngine3/Filters/sources/MPWriter/source/MultiWriterFileSink.h
@@ -13,7 +13,7 @@
class CMultiWriterFileSink: public MediaSink,public CPacketSync
{
public:
- static CMultiWriterFileSink* createNew(UsageEnvironment& env, char const* fileName,unsigned bufferSize = 20000,Boolean oneFilePerFrame = False);
+ static CMultiWriterFileSink* createNew(UsageEnvironment& env, char const* fileName,int minFiles, int maxFiles, ULONG maxFileSize,unsigned bufferSize = 20000,Boolean oneFilePerFrame = False);
// "bufferSize" should be at least as large as the largest expected
// input frame.
// "oneFilePerFrame" - if True - specifies that each input frame will
View
207 TvEngine3/Filters/sources/MPWriter/source/PidInfo.cpp
@@ -0,0 +1,207 @@
+/**
+* PidInfo.cpp
+* Copyright (C) 2005 nate
+* Copyright (C) 2006 bear
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+
+#include <streams.h>
+#include "PidInfo.h"
+#include <crtdbg.h>
+#include <WXUtil.h>
+
+
+PidInfo::PidInfo()
+{
+ Clear();
+}
+
+PidInfo::~PidInfo()
+{
+}
+
+void PidInfo::Clear()
+{
+ vid = 0;
+ h264 = 0;
+ mpeg4 = 0;
+ aud = 0;
+ aud2 = 0;
+ aac = 0;
+ aac2 = 0;
+ dts = 0;
+ dts2 = 0;
+ ac3 = 0;
+ ac3_2 = 0;
+ chnumb = 0;
+ ZeroMemory(onetname, 128);
+ ZeroMemory(chname, 128);
+ ZeroMemory(sdesc, 128);
+ ZeroMemory(edesc, 600);
+ ZeroMemory(sndesc, 128);
+ ZeroMemory(endesc, 600);
+
+ txt = 0;
+ sub = 0;
+ sid = 0;
+ pmt = 0;
+ pcr = 0;
+ opcr = 0;
+ start = 0;
+ end = 0;
+ dur = 0; //1000000;
+ bitrate = 10000000; //Set reasonable value
+ for (int i = 0 ; i < 16 ; i++ )
+ {
+ TsArray[i] = 0;
+ }
+}
+
+void PidInfo::CopyFrom(PidInfo *pidInfo)
+{
+ vid = pidInfo->vid;
+ h264 = pidInfo->h264;
+ mpeg4 = pidInfo->mpeg4;
+ aud = pidInfo->aud;
+ aud2 = pidInfo->aud2;
+ aac = pidInfo->aac;
+ aac2 = pidInfo->aac2;
+ dts = pidInfo->dts;
+ dts2 = pidInfo->dts2;
+ ac3 = pidInfo->ac3;
+ ac3_2 = pidInfo->ac3_2;
+ chnumb = pidInfo->chnumb;
+ memcpy(onetname, pidInfo->onetname, 128);
+ memcpy(chname, pidInfo->chname, 128);
+ memcpy(sdesc, pidInfo->sdesc, 128);
+ memcpy(edesc, pidInfo->edesc, 600);
+ memcpy(sndesc, pidInfo->sndesc, 128);
+ memcpy(endesc, pidInfo->endesc, 600);
+
+ txt = pidInfo->txt;
+ sub = pidInfo->sub;
+ sid = pidInfo->sid;
+ pmt = pidInfo->pmt;
+ pcr = pidInfo->pcr;
+ opcr = pidInfo->opcr;
+ start = pidInfo->start;
+ end = pidInfo->end;
+ dur = pidInfo->dur;
+
+ bitrate = pidInfo->bitrate;
+ for (int i = 0 ; i < 16 ; i++ )
+ {
+ TsArray[i] = pidInfo->TsArray[i];
+ }
+}
+
+void PidInfo::CopyTo(PidInfo *pidInfo)
+{
+ pidInfo->vid = vid;
+ pidInfo->h264 = h264;
+ pidInfo->mpeg4 = mpeg4;
+ pidInfo->aud = aud;
+ pidInfo->aud2 = aud2;
+ pidInfo->aac = aac;
+ pidInfo->aac2 = aac2;
+ pidInfo->dts = dts;
+ pidInfo->dts2 = dts2;
+ pidInfo->ac3 = ac3;
+ pidInfo->ac3_2 = ac3_2;
+ pidInfo->chnumb = chnumb;
+ memcpy(pidInfo->onetname, onetname, 128);
+ memcpy(pidInfo->chname, chname, 128);
+ memcpy(pidInfo->sdesc, sdesc, 128);
+ memcpy(pidInfo->edesc, edesc, 600);
+ memcpy(pidInfo->sndesc, sndesc, 128);
+ memcpy(pidInfo->endesc, endesc, 600);
+
+ pidInfo->txt = txt;
+ pidInfo->sub = sub;
+ pidInfo->sid = sid;
+ pidInfo->pmt = pmt;
+ pidInfo->pcr = pcr;
+ pidInfo->opcr = opcr;
+ pidInfo->start = start;
+ pidInfo->end = end;
+ pidInfo->dur = dur;
+ pidInfo->bitrate = bitrate;
+
+ for (int i = 0 ; i < 16 ; i++ )
+ {
+ pidInfo->TsArray[i] = TsArray[i];
+ }
+}
+
+PidInfoArray::PidInfoArray()
+{
+}
+
+PidInfoArray::~PidInfoArray()
+{
+// CAutoLock arraylock(&m_ArrayLock);
+ Clear();
+}
+
+void PidInfoArray::Clear()
+{
+// CAutoLock arraylock(&m_ArrayLock);
+
+ std::vector<PidInfo *>::iterator it = m_Array.begin();
+ for ( ; it != m_Array.end() ; it++ )
+ {
+ delete *it;
+ }
+ m_Array.clear();
+}
+
+void PidInfoArray::Add(PidInfo *newPidInfo)
+{
+// CAutoLock arraylock(&m_ArrayLock);
+ m_Array.push_back(newPidInfo);
+}
+
+void PidInfoArray::RemoveAt(int nPosition)
+{
+// CAutoLock arraylock(&m_ArrayLock);
+ if ((nPosition >= 0) && (nPosition < (int)m_Array.size()))
+ {
+ m_Array.erase(m_Array.begin() + nPosition);
+ }
+}
+
+PidInfo &PidInfoArray::operator[](int nPosition)
+{
+// CAutoLock arraylock(&m_ArrayLock);
+ int size = m_Array.size();
+ _ASSERT(nPosition >= 0);
+ _ASSERT(nPosition < size);
+
+ return *m_Array.at(nPosition);
+}
+
+int PidInfoArray::Count()
+{
+// CAutoLock arraylock(&m_ArrayLock);
+ return m_Array.size();
+}
+
View
95 TvEngine3/Filters/sources/MPWriter/source/PidInfo.h
@@ -0,0 +1,95 @@
+/**
+* PidInfo.h
+* Copyright (C) 2005 nate
+* Copyright (C) 2006 bear
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+
+
+#ifndef PIDINFO_H
+#define PIDINFO_H
+
+#include <vector>
+
+class PidInfo
+{
+public:
+ PidInfo();
+ virtual ~PidInfo();
+
+ void Clear();
+ void CopyFrom(PidInfo *pidInfo);
+ void CopyTo(PidInfo *pidInfo);
+
+ int vid;
+ int h264;
+ int mpeg4;
+ int aud;
+ int aud2;
+ int aac;
+ int aac2;
+ int dts;
+ int dts2;
+ int ac3;
+ int ac3_2;
+ int chnumb;
+ int txt;
+ int sub;
+ int sid;
+ int pmt;
+ int pcr;
+ int opcr;
+ long bitrate;
+ __int64 start;
+ __int64 end;
+ __int64 dur;
+ unsigned char chname[128];
+ unsigned char onetname[128];
+ unsigned char sdesc[128];
+ unsigned char edesc[600];
+ unsigned char sndesc[128];
+ unsigned char endesc[600];
+ unsigned long TsArray[16];
+};
+
+class PidInfoArray
+{
+
+public:
+ PidInfoArray();
+ virtual ~PidInfoArray();
+
+ void Clear();
+ void Add(PidInfo *newPidInfo);
+ void RemoveAt(int nPosition);
+
+ PidInfo &operator[](int nPosition);
+ int Count();
+
+private:
+ std::vector<PidInfo *> m_Array;
+
+ CCritSec m_ArrayLock;
+
+};
+
+#endif
View
2,406 TvEngine3/Filters/sources/MPWriter/source/PidParser.cpp
@@ -0,0 +1,2406 @@
+/**
+* PidParser.cpp
+* Copyright (C) 2003 bisswanger
+* Copyright (C) 2004-2006 bear
+* Copyright (C) 2005 nate
+*
+* This file is part of TSFileSource, a directshow push source filter that
+* provides an MPEG transport stream output.
+*
+* TSFileSource is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* TSFileSource is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with TSFileSource; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*
+* bisswanger can be reached at WinSTB@hotmail.com
+* Homepage: http://www.winstb.de
+*
+* bear and nate can be reached on the forums at
+* http://forums.dvbowners.com/
+*/
+
+#include <streams.h>
+#include "PidParser.h"
+#include "Global.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+
+PidParser::PidParser(CSampleBuffer *pSampleBuffer, FileReader *pFileReader)
+{
+ m_pSampleBuffer = pSampleBuffer;
+ m_pFileReader = pFileReader;
+ m_PacketSize = 188; //Start with Transport packet size
+ m_ATSCFlag = false;
+ m_NitPid = 0x10;
+ m_NetworkID = 0; //NID store
+ ZeroMemory(m_NetworkName, 128);
+ m_ONetworkID = 0; //ONID store
+ m_TStreamID = 0; //TSID store
+ m_ProgramSID = 0; //SID store for prog search
+ m_ProgPinMode = FALSE; //Set to Transport Stream Mode
+ m_AsyncMode = FALSE; //Set for control by filter
+ pids.Clear();
+ m_buflen = 0;
+ ZeroMemory(m_pDummy, 0x4000);
+ ZeroMemory(m_shortdescr, 128);
+ ZeroMemory(m_extenddescr, 600);
+ m_pgmnumb = 0;
+ filepos = 0;
+ m_fileLenOffset = 0;
+ m_fileEndOffset = 0;
+ m_fileStartOffset = 0;
+ m_FileStartPointer = 0;
+ m_ParsingLock = FALSE;
+}
+
+PidParser::~PidParser()
+{
+ pidArray.Clear();
+}
+
+HRESULT PidParser::ParsePinMode(__int64 fileStartPointer)
+{
+ HRESULT hr = S_OK;
+
+ if (m_pFileReader->IsFileInvalid())
+ {
+ return NOERROR;
+ }
+
+ //Store file pointer so we can reset it before leaving this method
+ FileReader *pFileReader = m_pFileReader->CreateFileReader(); //new FileReader();
+ char fileName[MAX_PATH];
+ m_pFileReader->GetFileName((char*)&fileName);
+ pFileReader->SetFileName(fileName);
+
+ hr = pFileReader->OpenFile();
+ if (FAILED(hr)){
+ delete pFileReader;
+ return VFW_E_INVALIDMEDIATYPE;
+ }
+
+ __int64 fileStart, filelength;
+ pFileReader->GetFileSize(&fileStart, &filelength);
+
+ //Check if we are locked out
+ int count = 0;
+ while (m_ParsingLock)
+ {
+ Sleep(100);
+ count++;
+ if (count > 10)
+ {
+ pFileReader->CloseFile();
+ delete pFileReader;
+ return S_FALSE;
+ }
+ }
+ //Lock the parser
+ m_ParsingLock = TRUE;
+
+ // Access the sample's data buffer
+ ULONG a = 0;
+ ULONG ulDataLength = min((ULONG)filelength, MIN_FILE_SIZE*2);
+ ULONG ulDataRead = 0;
+ PBYTE pData = new BYTE[ulDataLength];
+ pFileReader->setFilePointer(0, FILE_BEGIN);
+ pFileReader->Read(pData, ulDataLength, &ulDataRead);
+ ulDataLength = ulDataRead;
+
+ if (ulDataLength > 2048*4)
+ {
+ m_PacketSize = 0x800;
+ m_ProgPinMode = TRUE;
+ int count = 0;
+ a = ulDataLength - m_PacketSize;
+ hr = S_OK;
+ while (hr == S_OK && count < 2)
+ {
+ //search at the end of the file for sync bytes
+ hr = FindSyncByte(pData, ulDataLength, &a, -1);
+ if (hr == S_OK)
+ {
+ count++;
+ a -= m_PacketSize;
+ }
+ }
+ if (count < 2)
+ {
+ m_PacketSize = 188;
+ m_ProgPinMode = FALSE;
+ count = 0;
+ a = ulDataLength - m_PacketSize;
+ hr = S_OK;
+ while (hr == S_OK && count < 10)
+ {
+ //search at the end of the file for sync bytes
+ hr = FindSyncByte(pData, ulDataLength, &a, -1);
+ if (hr == S_OK)
+ {
+ count++;
+ a -= m_PacketSize;
+ }
+
+ }
+ if (count < 10)
+ {
+ m_PacketSize = 188;
+ m_ProgPinMode = FALSE;
+ }
+ }
+ }
+
+ //UnLock the parser
+ m_ParsingLock = FALSE;
+ delete[] pData;
+ pFileReader->CloseFile();
+ delete pFileReader;
+ return hr;
+}
+
+HRESULT PidParser::ParseFromFile(__int64 fileStartPointer)
+{
+ HRESULT hr = S_OK;
+
+ if (m_pFileReader->IsFileInvalid() && !m_pSampleBuffer->Count())
+ {
+ return NOERROR;
+ }
+
+
+ //Store file pointer so we can reset it before leaving this method
+ FileReader *pFileReader = m_pFileReader->CreateFileReader(); //new FileReader();
+ char fileName[MAX_PATH];
+ m_pFileReader->GetFileName((char*)&fileName);
+ pFileReader->SetFileName(fileName);
+
+ hr = pFileReader->OpenFile();
+ if (FAILED(hr)){
+ delete pFileReader;
+ return VFW_E_INVALIDMEDIATYPE;
+ }
+
+
+ //Check if we are locked out
+ int count = 0;
+ while (m_ParsingLock)
+ {
+ Sleep(100);
+ count++;
+ if (count > 10)
+ {
+ pFileReader->CloseFile();
+ delete pFileReader;
+ return S_FALSE;
+ }
+ }
+ //Lock the parser
+ m_ParsingLock = TRUE;
+
+ // Access the sample's data buffer
+
+ pids.Clear();
+
+ m_ATSCFlag = false;
+ m_NitPid = 0x10;
+ m_NetworkID = 0; //NID store
+ ZeroMemory(m_NetworkName, 128);
+ m_ONetworkID = 0; //ONID store
+ m_TStreamID = 0; //TSID store
+ m_ProgramSID = 0; //SID store for prog search
+ m_ProgPinMode = FALSE; //Set to Transport Stream Mode
+ m_AsyncMode = FALSE; //Set for control by filter
+
+ __int64 fileStart, filelength;
+ pFileReader->GetFileSize(&fileStart, &filelength);
+ ULONG ulDataLength = (ULONG)min((ULONG)MIN_FILE_SIZE*2, filelength);
+ fileStartPointer = min((__int64)(filelength - (__int64)ulDataLength), fileStartPointer);
+ m_FileStartPointer = max(get_StartOffset(), fileStartPointer);
+ if (filelength < MIN_FILE_SIZE*2)
+ pFileReader->setFilePointer(0, FILE_BEGIN);
+ else
+ pFileReader->setFilePointer(m_FileStartPointer, FILE_BEGIN);
+
+ PBYTE pData = new BYTE[MIN_FILE_SIZE*2];
+ ULONG ulDataRead = 0;
+ if FAILED(m_pSampleBuffer->ReadSampleBuffer(pData, ulDataLength, &ulDataRead))
+ pFileReader->Read(pData, ulDataLength, &ulDataRead);
+
+ if (ulDataRead < 1)
+ {
+ //UnLock the parser and return false
+ m_ParsingLock = FALSE;
+ delete[] pData;
+ pFileReader->CloseFile();
+ delete pFileReader;
+ return S_FALSE;
+ }
+
+ ulDataLength = ulDataRead;
+
+ //check if we have something to give us the media format
+ ULONG a = 0;
+ m_PacketSize = 0x800;
+ m_ProgPinMode = TRUE;
+ count = 0;
+ a = ulDataRead - m_PacketSize;
+ hr = S_OK;
+ while (hr == S_OK && count < 2)
+ {
+ //search back from the end of the file for sync bytes
+ hr = FindSyncByte(pData, ulDataRead, &a, -1);
+ if (hr == S_OK)
+ {
+ count++;
+ a -= m_PacketSize;
+ }
+ }
+ if (count < 2)
+ {
+ m_PacketSize = 188;
+ m_ProgPinMode = FALSE;
+ count = 0;
+ a = ulDataRead - m_PacketSize;
+ hr = S_OK;
+ while (hr == S_OK && count < 10)
+ {
+ //search back from the end of the file for sync bytes
+ hr = FindSyncByte(pData, ulDataRead, &a, -1);
+ if (hr == S_OK)
+ {
+ count++;
+ a -= m_PacketSize;
+ }
+ }
+ if (count < 10)
+ {
+ m_PacketSize = 188;
+ m_ProgPinMode = FALSE;
+ }
+ }
+
+ a = 0;
+ if (ulDataLength > 0)
+ {
+ //Clear all Pid arrays
+ pidArray.Clear();
+ BOOL patfound = false;
+ //skip if we are in program mode
+ if (!m_ProgPinMode)
+ {
+/*
+ a = 0;
+ hr = S_OK;
+ while (hr == S_OK)
+ {
+ //search at the head of the file
+ hr = FindSyncByte(pData, ulDataLength, &a, 1);
+ if (hr == S_OK)
+ {
+ //parse next packet for the PAT
+ if (ParsePAT(pData, ulDataLength, a) == S_OK)
+ {
+ // If second pass
+ if (patfound)
+ {
+ break;
+ }
+ else
+ {
+ //Set to exit after next pat & Erase first occuracnce
+ pidArray.Clear();
+ m_TStreamID = 0; //TSID store
+ patfound = true;
+ }
+ };
+ a += m_PacketSize;
+ }
+ }
+
+ //if no PAT found Scan for PMTs
+ if (pidArray.Count() == 0)
+ {
+ a = 0;
+ pids.sid = 0;
+ pids.pmt = 0;
+ hr = S_OK;
+
+ //Scan buffer for any PMTs
+ while (pids.pmt == 0x00 && hr == S_OK)
+ {
+ //search at the head of the file
+ hr = FindSyncByte(pData, ulDataLength, &a, 1);
+ if (hr == S_OK)
+ {
+ //parse next packet for the PMT
+ if (ParsePMT(pData, ulDataLength, a) == S_OK)
+ {
+ //Check if PMT was already found
+ BOOL pmtfound = false;
+ for (int i = 0; i < pidArray.Count(); i++)
+ {
+ //Search PMT Array for the PMT & SID also
+ if (pidArray[i].sid == pids.sid)
+ {
+ pmtfound = true;
+ break;
+ }
+ }
+ if (!pmtfound)
+ AddPidArray();
+
+ pids.sid = 0x00;
+ pids.pmt = 0x00;
+ }
+ a += m_PacketSize;
+ }
+ }
+ }
+
+ //Loop through Programs found
+ int i = 0;
+ while (i < pidArray.Count())
+ {
+ //filepos = 0;
+ a = 0;
+ pids.Clear();
+ hr = S_OK;
+
+ int curr_pmt = pidArray[i].pmt;
+ int pmtfound = 0;
+ int curr_sid = pidArray[i].sid;
+
+ while (pids.pmt != curr_pmt && hr == S_OK)
+ {
+ //search at the head of the file
+ hr = FindSyncByte(pData, ulDataLength, &a, 1);
+ if (hr != S_OK)
+ break;
+ //parse next packet for the PMT
+ pids.Clear();
+ if (ParsePMT(pData, ulDataLength, a) == S_OK)
+ {
+ //Check PMT & SID matches program
+ if (pids.pmt == curr_pmt && pids.sid == curr_sid && pmtfound > 0)
+ {
+ //Search for valid A/V pids
+ if (IsValidPMT(pData, ulDataLength) == S_OK)
+ {
+ //Set pcr & Store pids from PMT
+ RefreshDuration(FALSE, pFileReader);
+ SetPidArray(i);
+ i++;
+ break;
+ }
+ pids.pmt = 0;
+ pids.sid = 0;
+ break;
+ }
+
+ if (pids.pmt == curr_pmt && pids.sid == curr_sid)
+ {
+ pmtfound++;
+ pids.pmt = 0;
+ pids.sid = 0;
+ }
+ }
+ a += m_PacketSize;
+ };
+
+ if (pids.pmt != curr_pmt || pids.sid != curr_sid || hr != S_OK) //Make sure we have a correct packet
+ pidArray.RemoveAt(i);
+ }
+*/
+ a = ulDataLength - m_PacketSize;
+ hr = S_OK;
+ while (hr == S_OK)
+ {
+ //search at the head of the file
+ hr = FindSyncByte(pData, ulDataLength, &a, -1);
+ if (hr == S_OK)
+ {
+ //parse next packet for the PAT
+ if (ParsePAT(pData, ulDataLength, a) == S_OK)
+ {
+ break;
+ }
+ a -= m_PacketSize;
+ }
+ };
+
+ //if no PAT found Scan for PMTs
+ if (pidArray.Count() == 0)
+ {
+ a = ulDataLength - m_PacketSize;
+ pids.sid = 0;
+ pids.pmt = 0;
+ hr = S_OK;
+
+ //Scan buffer for any PMTs
+ while (pids.pmt == 0x00 && hr == S_OK)
+ {
+ //search at the head of the file
+ hr = FindSyncByte(pData, ulDataLength, &a, -1);
+ if (hr == S_OK)
+ {
+ //parse next packet for the PMT
+ if (ParsePMT(pData, ulDataLength, a) == S_OK)
+ {
+ //Check if PMT was already found
+ BOOL pmtfound = false;
+ for (int i = 0; i < pidArray.Count(); i++)
+ {
+ //Search PMT Array for the PMT & SID also
+ if (pidArray[i].sid == pids.sid)
+ {
+ pmtfound = true;
+ break;
+ }
+ }
+ if (!pmtfound)
+ AddPidArray();
+
+ pids.sid = 0x00;
+ pids.pmt = 0x00;
+ }
+ a -= m_PacketSize;
+ }
+ }
+ }
+
+ //Loop through Programs found
+ int i = 0;
+ while (i < pidArray.Count())
+ {
+ //filepos = 0;
+ pids.Clear();
+ hr = S_OK;
+
+ int curr_pmt = pidArray[i].pmt;
+ int pmtfound = 0;
+ int curr_sid = pidArray[i].sid;
+
+ a = ulDataLength - m_PacketSize;
+ while (pids.pmt != curr_pmt && hr == S_OK)
+ {
+ //search at the head of the file
+ hr = FindSyncByte(pData, ulDataLength, &a, -1);
+ if (hr != S_OK)
+ break;
+ //parse next packet for the PMT
+ pids.Clear();
+ if (ParsePMT(pData, ulDataLength, a) == S_OK)
+ {
+ //Check PMT & SID matches program
+ if (pids.pmt == curr_pmt && pids.sid == curr_sid && pmtfound > 0)
+ {
+ //Search for valid A/V pids
+ if (IsValidPMT(pData, ulDataLength) == S_OK)
+ {
+ //Set pcr & Store pids from PMT
+ RefreshDuration(FALSE, pFileReader);
+ SetPidArray(i);
+ i++;
+ break;
+ }
+ pids.pmt = 0;
+ pids.sid = 0;
+ break;
+ }
+
+ if (pids.pmt == curr_pmt && pids.sid == curr_sid)
+ {
+ pmtfound++;
+ pids.pmt = 0;
+ pids.sid = 0;
+ }
+ }
+ a -= m_PacketSize;
+ };
+
+ if (pids.pmt != curr_pmt || pids.sid != curr_sid || hr != S_OK) //Make sure we have a correct packet
+ pidArray.RemoveAt(i);
+ }
+ }
+
+ //Search for A/V pids if no NIT or valid PMT found.
+ if (pidArray.Count() == 0)
+ {
+ //check if transport mode only
+ if (!m_ProgPinMode)
+ {
+ //Search for any A/V Pids
+ if (ACheckVAPids(pData, ulDataLength) == S_OK)
+ {
+ //Set the pcr to video or audio incase its included in packet
+ USHORT pcrsave = pids.pcr;
+
+ if (!pids.dur && pids.pcr) {
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.vid) {
+ pids.pcr = pids.vid;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.h264) {
+ pids.pcr = pids.h264;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.mpeg4) {
+ pids.pcr = pids.mpeg4;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.aud) {
+ pids.pcr = pids.aud;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.aud2) {
+ pids.pcr = pids.aud2;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.ac3) {
+ pids.pcr = pids.ac3;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.ac3_2) {
+ pids.pcr = pids.ac3_2;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.aac) {
+ pids.pcr = pids.aac;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.aac2) {
+ pids.pcr = pids.aac2;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.dts) {
+ pids.pcr = pids.dts;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.dts2) {
+ pids.pcr = pids.dts2;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.txt) {
+ pids.pcr = pids.txt;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.sub) {
+ pids.pcr = pids.sub;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ if (!pids.dur && pids.vid) {
+ pids.pcr = pids.vid;
+ pids.opcr = pids.pcr;
+ RefreshDuration(FALSE, pFileReader);
+ }
+
+ // restore pcr pid if no matches with A/V pids
+ if (!pids.dur) {
+ //set fake duration if needed
+ pids.pcr = pcrsave;
+ RefreshDuration(FALSE, pFileReader);
+ }
+ else
+ AddPidArray();
+ }
+ }
+
+ if (!pidArray.Count())
+ pids.Clear();
+
+ // If nothing then check for Program Pin Mode
+ if ((pids.vid | pids.h264 | pids.mpeg4 | pids.sub
+ | pids.aud | pids.txt | pids.ac3 | pids.aac
+ | pids.dts | pids.pcr | pids.opcr) == 0)
+ {
+ m_PacketSize = 0x800; //Set for 2048 block
+ m_pFileReader->set_DelayMode(FALSE);//cold start
+ pFileReader->set_DelayMode(FALSE);//cold start
+// m_pFileReader->set_DelayMode(TRUE);
+ m_ProgPinMode = TRUE;
+
+ //Search for any A/V Pids
+ if (CheckVAStreams(pData, ulDataLength) == S_OK)
+ {
+ if (!(pids.vid | pids.h264 | pids.mpeg4 | pids.sub
+ | pids.aud | pids.txt | pids.ac3
+ | pids.aac | pids.dts)){
+
+ m_PacketSize = 0x930; //Set for 2352 block
+ if (CheckVAStreams(pData, ulDataLength) == S_OK)
+ {
+ if (!(pids.vid | pids.h264 | pids.mpeg4 | pids.sub