MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
FLV::Tag Class Reference

This class is used to hold, work with and get information about a single FLV tag. More...

#include <flv_tag.h>

Public Member Functions

 Tag ()
 Constructor for a new, empty, tag. More...
 
 Tag ()
 Constructor for a new, empty, tag. More...
 
 Tag (const Tag &O)
 Copy constructor, copies the contents of an existing tag. More...
 
 Tag (const Tag &O)
 Copy constructor, copies the contents of an existing tag. More...
 
 Tag (const RTMPStream::Chunk &O)
 Copy constructor from a RTMP chunk. More...
 
 Tag (const RTMPStream::Chunk &O)
 Copy constructor from a RTMP chunk. More...
 
 ~Tag ()
 Generic destructor. More...
 
 ~Tag ()
 Generic destructor. More...
 
bool ChunkLoader (const RTMPStream::Chunk &O)
 
bool ChunkLoader (const RTMPStream::Chunk &O)
 FLV loader function from chunk. More...
 
bool DTSCAudioInit (DTSC::Track &audio)
 FLV Audio init data loader function from JSON. More...
 
bool DTSCAudioInit (DTSC::Track &audio)
 
bool DTSCLoader (DTSC::Packet &packData, DTSC::Track &track)
 
bool DTSCLoader (DTSC::Packet &packData, DTSC::Track &track)
 
bool DTSCMetaInit (DTSC::Meta &M, std::set< long unsigned int > &selTracks)
 
bool DTSCMetaInit (DTSC::Meta &M, std::set< long unsigned int > &selTracks)
 
bool DTSCVideoInit (DTSC::Track &video)
 FLV Video init data loader function from JSON. More...
 
bool DTSCVideoInit (DTSC::Track &video)
 
bool FileLoader (FILE *f)
 Try to load a tag from a file. More...
 
bool FileLoader (FILE *f)
 
const char * getAudioCodec ()
 Returns a c-string with the audio codec name. More...
 
const char * getAudioCodec ()
 Returns a c-string with the audio codec name. More...
 
char * getData ()
 Returns a pointer to the raw media data for this packet. More...
 
char * getData ()
 
unsigned int getDataLen ()
 Returns the length of the raw media data for this packet. More...
 
unsigned int getDataLen ()
 
unsigned int getTrackID ()
 Returns 1 for video, 2 for audio, 3 for meta, 0 otherwise. More...
 
unsigned int getTrackID ()
 
const char * getVideoCodec ()
 Returns a c-string with the video codec name. More...
 
const char * getVideoCodec ()
 Returns a c-string with the video codec name. More...
 
bool isInitData ()
 True if current tag is init data for this media type. More...
 
bool isInitData ()
 True if current tag is init data for this media type. More...
 
bool MemLoader (char *D, unsigned int S, unsigned int &P)
 Try to load a tag from a data buffer in memory. More...
 
bool MemLoader (char *D, unsigned int S, unsigned int &P)
 
bool needsInitData ()
 True if this media type requires init data. More...
 
bool needsInitData ()
 True if this media type requires init data. More...
 
int offset ()
 Returns the 24-bit offset of this tag. More...
 
int offset ()
 
void offset (int o)
 
void offset (int o)
 Sets the 24-bit offset of this tag. More...
 
Tagoperator= (const Tag &O)
 Assignment operator - works exactly like the copy constructor. More...
 
Tagoperator= (const Tag &O)
 Assignment operator - works exactly like the copy constructor. More...
 
unsigned int tagTime ()
 
unsigned int tagTime ()
 Returns the 32-bit timestamp of this tag. More...
 
void tagTime (unsigned int T)
 Sets the 32-bit timestamp of this tag. More...
 
void tagTime (unsigned int T)
 
std::string tagType ()
 Returns a std::string describing the tag in detail. More...
 
std::string tagType ()
 Returns a std::string describing the tag in detail. More...
 
JSON::Value toJSON (DTSC::Meta &metadata, AMF::Object &amf_storage, unsigned int reTrack=0)
 
JSON::Value toJSON (DTSC::Meta &metadata, AMF::Object &amf_storage, unsigned int reTrack=0)
 

Data Fields

char * data
 Pointer to tag buffer. More...
 
bool isKeyframe
 True if current tag is a video keyframe. More...
 
int len
 Actual length of tag. More...
 

Protected Member Functions

bool checkBufferSize ()
 Checks if buf is large enough to contain len. More...
 
bool checkBufferSize ()
 
bool FileReadUntil (char *buffer, unsigned int count, unsigned int &sofar, FILE *f)
 Helper function for FLV::FileLoader. More...
 
bool FileReadUntil (char *buffer, unsigned int count, unsigned int &sofar, FILE *f)
 
bool MemReadUntil (char *buffer, unsigned int count, unsigned int &sofar, char *D, unsigned int S, unsigned int &P)
 
bool MemReadUntil (char *buffer, unsigned int count, unsigned int &sofar, char *D, unsigned int S, unsigned int &P)
 Helper function for FLV::MemLoader. More...
 
bool Meta_Has (JSON::Value &meta, std::string cat, std::string elem)
 
bool Meta_Has (JSON::Value &meta, std::string cat, std::string elem)
 
void Meta_Put (JSON::Value &meta, std::string cat, std::string elem, std::string val)
 
void Meta_Put (JSON::Value &meta, std::string cat, std::string elem, std::string val)
 
void Meta_Put (JSON::Value &meta, std::string cat, std::string elem, uint64_t val)
 
void Meta_Put (JSON::Value &meta, std::string cat, std::string elem, uint64_t val)
 
void setLen ()
 
void setLen ()
 Helper function that properly sets the tag length from the internal len variable. More...
 

Protected Attributes

int buf
 Maximum length of buffer space. More...
 
bool done
 Body reading done? More...
 
unsigned int sofar
 How many bytes are read sofar? More...
 

Detailed Description

This class is used to hold, work with and get information about a single FLV tag.

Constructor & Destructor Documentation

FLV::Tag::Tag ( )

Constructor for a new, empty, tag.

The buffer length is initialized to 0, and later automatically increased if neccesary.

FLV::Tag::Tag ( const Tag O)

Copy constructor, copies the contents of an existing tag.

The buffer length is initialized to the actual size of the tag that is being copied, and later automaticallt increased if neccesary.

FLV::Tag::Tag ( const RTMPStream::Chunk O)

Copy constructor from a RTMP chunk.

Copies the contents of a RTMP chunk into a valid FLV tag. Exactly the same as making a chunk by through the default (empty) constructor and then calling FLV::Tag::ChunkLoader with the chunk as argument.

FLV::Tag::~Tag ( )

Generic destructor.

Generic destructor that frees the allocated memory in the internal data variable, if any.

FLV::Tag::Tag ( )

Constructor for a new, empty, tag.

FLV::Tag::Tag ( const Tag O)

Copy constructor, copies the contents of an existing tag.

FLV::Tag::Tag ( const RTMPStream::Chunk O)

Copy constructor from a RTMP chunk.

FLV::Tag::~Tag ( )

Generic destructor.

Member Function Documentation

bool FLV::Tag::checkBufferSize ( )
protected

Checks if buf is large enough to contain len.

Attempts to resize data buffer if not/

Returns
True if buffer is large enough, false otherwise.
bool FLV::Tag::checkBufferSize ( )
protected
bool FLV::Tag::ChunkLoader ( const RTMPStream::Chunk O)

FLV loader function from chunk.

Copies the contents and wraps it in a FLV header.

bool FLV::Tag::ChunkLoader ( const RTMPStream::Chunk O)
bool FLV::Tag::DTSCAudioInit ( DTSC::Track audio)
bool FLV::Tag::DTSCAudioInit ( DTSC::Track audio)

FLV Audio init data loader function from JSON.

bool FLV::Tag::DTSCLoader ( DTSC::Packet packData,
DTSC::Track track 
)
bool FLV::Tag::DTSCLoader ( DTSC::Packet packData,
DTSC::Track track 
)
bool FLV::Tag::DTSCMetaInit ( DTSC::Meta M,
std::set< long unsigned int > &  selTracks 
)
bool FLV::Tag::DTSCMetaInit ( DTSC::Meta M,
std::set< long unsigned int > &  selTracks 
)
bool FLV::Tag::DTSCVideoInit ( DTSC::Track video)
bool FLV::Tag::DTSCVideoInit ( DTSC::Track video)

FLV Video init data loader function from JSON.

bool FLV::Tag::FileLoader ( FILE *  f)

Try to load a tag from a file.

This is a stateful function - if fed incorrect data, it will most likely never return true again! While this function returns false, the Tag might not contain valid data.

Parameters
fThe file to read from.
Returns
True if a whole tag is succesfully read, false otherwise.
bool FLV::Tag::FileLoader ( FILE *  f)
bool FLV::Tag::FileReadUntil ( char *  buffer,
unsigned int  count,
unsigned int &  sofar,
FILE *  f 
)
protected

Helper function for FLV::FileLoader.

This function will try to read count bytes from file f into buffer. This function should be called repeatedly until true.

Parameters
bufferThe target buffer.
countAmount of bytes to read.
sofarCurrent amount read.
fFile to read from.
Returns
True if count bytes are read succesfully, false otherwise.
bool FLV::Tag::FileReadUntil ( char *  buffer,
unsigned int  count,
unsigned int &  sofar,
FILE *  f 
)
protected
const char * FLV::Tag::getAudioCodec ( )

Returns a c-string with the audio codec name.

const char* FLV::Tag::getAudioCodec ( )

Returns a c-string with the audio codec name.

char * FLV::Tag::getData ( )

Returns a pointer to the raw media data for this packet.

char* FLV::Tag::getData ( )
unsigned int FLV::Tag::getDataLen ( )
unsigned int FLV::Tag::getDataLen ( )

Returns the length of the raw media data for this packet.

unsigned int FLV::Tag::getTrackID ( )

Returns 1 for video, 2 for audio, 3 for meta, 0 otherwise.

unsigned int FLV::Tag::getTrackID ( )
const char* FLV::Tag::getVideoCodec ( )

Returns a c-string with the video codec name.

const char * FLV::Tag::getVideoCodec ( )

Returns a c-string with the video codec name.

bool FLV::Tag::isInitData ( )

True if current tag is init data for this media type.

bool FLV::Tag::isInitData ( )

True if current tag is init data for this media type.

bool FLV::Tag::MemLoader ( char *  D,
unsigned int  S,
unsigned int &  P 
)

Try to load a tag from a data buffer in memory.

This is a stateful function - if fed incorrect data, it will most likely never return true again! While this function returns false, the Tag might not contain valid data.

Parameters
DThe location of the data buffer.
SThe size of the data buffer.
PThe current position in the data buffer. Will be updated to reflect new position.
Returns
True if a whole tag is succesfully read, false otherwise.
bool FLV::Tag::MemLoader ( char *  D,
unsigned int  S,
unsigned int &  P 
)
bool FLV::Tag::MemReadUntil ( char *  buffer,
unsigned int  count,
unsigned int &  sofar,
char *  D,
unsigned int  S,
unsigned int &  P 
)
protected

Helper function for FLV::MemLoader.

This function will try to read count bytes from data buffer D into buffer. This function should be called repeatedly until true. P and sofar are not the same value, because D may not start with the current tag.

Parameters
bufferThe target buffer.
countAmount of bytes to read.
sofarCurrent amount read.
DThe location of the data buffer.
SThe size of the data buffer.
PThe current position in the data buffer. Will be updated to reflect new position.
Returns
True if count bytes are read succesfully, false otherwise.
bool FLV::Tag::MemReadUntil ( char *  buffer,
unsigned int  count,
unsigned int &  sofar,
char *  D,
unsigned int  S,
unsigned int &  P 
)
protected
bool FLV::Tag::Meta_Has ( JSON::Value meta,
std::string  cat,
std::string  elem 
)
protected
bool FLV::Tag::Meta_Has ( JSON::Value meta,
std::string  cat,
std::string  elem 
)
protected
void FLV::Tag::Meta_Put ( JSON::Value meta,
std::string  cat,
std::string  elem,
std::string  val 
)
protected
void FLV::Tag::Meta_Put ( JSON::Value meta,
std::string  cat,
std::string  elem,
std::string  val 
)
protected
void FLV::Tag::Meta_Put ( JSON::Value meta,
std::string  cat,
std::string  elem,
uint64_t  val 
)
protected
void FLV::Tag::Meta_Put ( JSON::Value meta,
std::string  cat,
std::string  elem,
uint64_t  val 
)
protected
bool FLV::Tag::needsInitData ( )

True if this media type requires init data.

Will always return false if the tag type is not 0x08 or 0x09. Returns true for H263, AVC (H264), AAC.

Todo:
Check if MP3 does or does not require init data...
bool FLV::Tag::needsInitData ( )

True if this media type requires init data.

int FLV::Tag::offset ( )

Returns the 24-bit offset of this tag.

Returns 0 if the tag isn't H264

int FLV::Tag::offset ( )
void FLV::Tag::offset ( int  o)

Sets the 24-bit offset of this tag.

Ignored if the tag isn't H264

void FLV::Tag::offset ( int  o)
Tag& FLV::Tag::operator= ( const Tag O)

Assignment operator - works exactly like the copy constructor.

FLV::Tag & FLV::Tag::operator= ( const Tag O)

Assignment operator - works exactly like the copy constructor.

This operator checks for self-assignment.

void FLV::Tag::setLen ( )
protected
void FLV::Tag::setLen ( )
protected

Helper function that properly sets the tag length from the internal len variable.

unsigned int FLV::Tag::tagTime ( )
unsigned int FLV::Tag::tagTime ( )

Returns the 32-bit timestamp of this tag.

void FLV::Tag::tagTime ( unsigned int  T)
void FLV::Tag::tagTime ( unsigned int  T)

Sets the 32-bit timestamp of this tag.

std::string FLV::Tag::tagType ( )

Returns a std::string describing the tag in detail.

The string includes information about whether the tag is audio, video or metadata, what encoding is used, and the details of the encoding itself.

std::string FLV::Tag::tagType ( )

Returns a std::string describing the tag in detail.

JSON::Value FLV::Tag::toJSON ( DTSC::Meta metadata,
AMF::Object amf_storage,
unsigned int  reTrack = 0 
)
JSON::Value FLV::Tag::toJSON ( DTSC::Meta metadata,
AMF::Object amf_storage,
unsigned int  reTrack = 0 
)

Field Documentation

int FLV::Tag::buf
protected

Maximum length of buffer space.

char * FLV::Tag::data

Pointer to tag buffer.

bool FLV::Tag::done
protected

Body reading done?

bool FLV::Tag::isKeyframe

True if current tag is a video keyframe.

int FLV::Tag::len

Actual length of tag.

unsigned int FLV::Tag::sofar
protected

How many bytes are read sofar?


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