QtlMovie 1.12 (A specialized FFmpeg front-end)
QtsTsFile Class Reference

A subclass of QFile which reads and writes MPEG transport stream packets instead of raw data. More...

Inheritance diagram for QtsTsFile:

Public Types

enum  TsFileType {
  AutoDetect,
  TsFile,
  M2tsFile
}
 Describe the packet format inside a TS file. More...
 

Public Member Functions

 QtsTsFile (QObject *parent=0)
 Constructor. More...
 
 QtsTsFile (const QString &name, TsFileType type=AutoDetect, QObject *parent=0)
 Constructor. More...
 
virtual bool open (OpenMode mode=ReadOnly) Q_DECL_OVERRIDE
 Open the file. More...
 
int read (QtsTsPacket *buffer, int maxPacketCount=1)
 Read as many TS packets as possible from the file. More...
 
void setTsFileType (const TsFileType &tsFileType)
 Set the TS packet format. More...
 
TsFileType tsFileType () const
 Get the TS packet format. More...
 
bool write (const QtsTsPacket *buffer, int packetCount=1)
 Write TS packets to the file. More...
 
bool writeWithTimeStamp (quint32 timeStamp, const QtsTsPacket *packet)
 Write one TS packet with timestamp to the file. More...
 

Private Member Functions

bool autoDetectFileFormat ()
 Read enough packets in _inBuffer to determine the packet size. More...
 
bool fillBuffer (int size)
 Make sure that the internal input buffer contains at least a given number of bytes. More...
 
bool writeRawData (const void *data, int size)
 Write raw data to the file. More...
 

Private Attributes

QtlByteBlock _inBuffer
 Buffer for partially read packets or initial auto-detection. More...
 
TsFileType _tsFileType
 Packet format. More...
 

Detailed Description

A subclass of QFile which reads and writes MPEG transport stream packets instead of raw data.

Member Enumeration Documentation

◆ TsFileType

Describe the packet format inside a TS file.

Enumerator
AutoDetect 

Automatically detect on input, same as TsFile on output.

TsFile 

Standard MPEG-2 Transport Stream file, 188 bytes per TS packet.

M2tsFile 

M2TS file (BluRay and some IP-TV), 4-byte timestamp followed by 188-byte TS packet.

Constructor & Destructor Documentation

◆ QtsTsFile() [1/2]

QtsTsFile::QtsTsFile ( QObject *  parent = 0)
explicit

Constructor.

Parameters
[in]parentOptional parent object.

◆ QtsTsFile() [2/2]

QtsTsFile::QtsTsFile ( const QString &  name,
TsFileType  type = AutoDetect,
QObject *  parent = 0 
)
explicit

Constructor.

Parameters
[in]nameFile name.
[in]typeTS packet format.
[in]parentOptional parent object.

Member Function Documentation

◆ open()

bool QtsTsFile::open ( OpenMode  mode = ReadOnly)
virtual

Open the file.

Reimplemented from QIODevice.

Parameters
[in]modeThe mode into which the file shall been open.
Returns
True on success, false on error.

◆ read()

int QtsTsFile::read ( QtsTsPacket buffer,
int  maxPacketCount = 1 
)

Read as many TS packets as possible from the file.

Parameters
[out]bufferBuffer receiving the TS packets.
[in]maxPacketCountSize in buffer in number of TS packets.
Returns
Number of TS packets actually read or negative on error.

◆ write()

bool QtsTsFile::write ( const QtsTsPacket buffer,
int  packetCount = 1 
)

Write TS packets to the file.

Parameters
[in]bufferBuffer containing the TS packets to write. If the file format is M2tsFile, a zero 4-byte timestamp is inserted before each packet.
[in]packetCountNumber of TS packets to write from buffer.
Returns
True on success, false on error.

◆ writeWithTimeStamp()

bool QtsTsFile::writeWithTimeStamp ( quint32  timeStamp,
const QtsTsPacket packet 
)

Write one TS packet with timestamp to the file.

Parameters
[in]packetTS packet to write.
[in]timeStampTime stamp to write (will be converted to big endian before writing). Ignored if the file format is not M2tsFile.
Returns
True on success, false on error.

◆ tsFileType()

TsFileType QtsTsFile::tsFileType ( ) const
inline

Get the TS packet format.

If initially set to AutoDetect on an input file, the returned value will be either TsFile or M2tsFile after reading the first packet.

Returns
The TS packet format.

◆ setTsFileType()

void QtsTsFile::setTsFileType ( const TsFileType tsFileType)

Set the TS packet format.

Must be called before open().

Returns
The TS packet format.

◆ autoDetectFileFormat()

bool QtsTsFile::autoDetectFileFormat ( )
private

Read enough packets in _inBuffer to determine the packet size.

Returns
True on success, false on error. When true is returned, it is guaranteed that _tsFileType is no longer AutoDetect.

◆ fillBuffer()

bool QtsTsFile::fillBuffer ( int  size)
private

Make sure that the internal input buffer contains at least a given number of bytes.

Read input file if necessary.

Parameters
sizeRequested byte count in buffer.
Returns
False on read error. When true, the target number of bytes may not be reached if no data is currently available from the file.

◆ writeRawData()

bool QtsTsFile::writeRawData ( const void *  data,
int  size 
)
private

Write raw data to the file.

Parameters
[in]dataAddress of data to write.
[in]sizeNumber of bytes to write from data.
Returns
True on success, false on error.

Member Data Documentation

◆ _tsFileType

TsFileType QtsTsFile::_tsFileType
private

Packet format.

◆ _inBuffer

QtlByteBlock QtsTsFile::_inBuffer
private

Buffer for partially read packets or initial auto-detection.


The documentation for this class was generated from the following files: