Public Member Functions | Public Attributes

gnash::rtmp::RTMP Struct Reference

This class is for handling the RTMP protocol. More...

#include <RTMP.h>

Collaboration diagram for gnash::rtmp::RTMP:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RTMP ()
 Construct a non-connected RTMP handler.
 ~RTMP ()
bool connect (const URL &url)
 Initiate a network connection.
void call (const SimpleBuffer &amf)
 This is used for sending call requests from the core.
void play (const SimpleBuffer &amf, int id)
 This is used for sending NetStream requests.
void setBufferTime (size_t time, int streamID)
 Instruct server to buffer this much data.
bool connected () const
 Whether we have a basic connection to a server.
bool error () const
 Whether the RTMP connection is in error condition.
void update ()
 This function handles reading incoming data and filling data queues.
void close ()
 Close the connection.
boost::shared_ptr< SimpleBuffergetMessage ()
 Get an AMF message received from the server.
boost::shared_ptr< SimpleBuffergetFLVFrame ()
 Get an FLV packet received from the server.
void handlePacket (const RTMPPacket &packet)
 Handle an RTMPPacket.
int readSocket (boost::uint8_t *dst, int num)
 Read from the socket.
bool sendPacket (RTMPPacket &packet)
 Send an RTMPPacket on the connection.
void setServerBandwidth (boost::uint32_t bw)
 Store the server bandwidth.
boost::uint32_t serverBandwidth () const
 Get the stored server bandwidth.
void setBandwidth (boost::uint32_t bw)
 Store our bandwidth.
boost::uint32_t bandwidth () const
 Get our bandwidth.

Public Attributes

int _inChunkSize
int m_mediaChannel
boost::uint8_t m_nClientBW2
size_t _bytesIn
size_t _bytesInSent

Detailed Description

This class is for handling the RTMP protocol.

Only the RTMP protocol itself is handled in this class. An RTMP connection is valid only when connected() is true. An RTMP object may be closed and reconnected. As soon as connect() returns true, callers are responsible for calling close(). RTMP has a set of channels for incoming and outgoing packets. Packets are stored here for two reasons: 1. The payload size exceeds the chunk size, so a single payload requires several complete packets. A packet is not 'ready' unless it has a complete payload, or is the packet that completes the payload of previous packets. 2. Subsequent packets sent on the same channel can be compressed if they have the same header information. The stored packet header is used for comparison. For this case, the payload is no longer necessary. A different case applies to incomplete packets. The payload of a single packet (whether the packet is 'ready' or not) is the smaller of (a) the advertised data size and (b) the chunk size. Until this much data has been read, the packet is incomplete. Whereas Gnash always expects a complete header to be available or none at all, the payload can be read over several calls to update().


Constructor & Destructor Documentation

gnash::rtmp::RTMP::RTMP (  ) 

Construct a non-connected RTMP handler.

gnash::rtmp::RTMP::~RTMP (  ) 

Member Function Documentation

boost::uint32_t gnash::rtmp::RTMP::bandwidth (  )  const [inline]

Get our bandwidth.

void gnash::rtmp::RTMP::call ( const SimpleBuffer amf  ) 

This is used for sending call requests from the core.

These are sent as invoke packets on CHANNEL_CONTROL2. The AMF data should contain: 1. method name, 2. callback number, 3. null, 4. arg0..argn

References gnash::rtmp::CONTROL_BUFFER_TIME, and gnash::rtmp::sendCtrl().

Referenced by replyBWCheck(), sendCheckBW(), sendConnectPacket(), sendCreateStream(), sendDeleteStream(), and sendFCSubscribe().

void gnash::rtmp::RTMP::close ( void   ) 

Close the connection.

A new connection may now be opened.

Referenced by handleInvoke().

bool gnash::rtmp::RTMP::connect ( const URL url  ) 

Initiate a network connection.

Note that this only creates the TCP connection and carries out the handshake. An active data connection needs an AMF connect request, which is not part of the RTMP protocol.

Returns:
true if the connection attempt starts, otherwise false. A return of false means that the RTMP object is in a closed state and can be reconnected.

Referenced by main().

bool gnash::rtmp::RTMP::connected (  )  const [inline]

Whether we have a basic connection to a server.

This only means that the handshake is complete and that AMF requests can be sent to the server. It does not mean that was can send or receive media streams. You should ensure that connected() is true before attempting to send or receive data.

Referenced by main().

bool gnash::rtmp::RTMP::error (  )  const [inline]

Whether the RTMP connection is in error condition.

This is a fatal error.

References _error.

Referenced by main().

boost::shared_ptr<SimpleBuffer> gnash::rtmp::RTMP::getFLVFrame (  )  [inline]

Get an FLV packet received from the server.

TODO: this returns the whole RTMP message, which is ugly. And it only returns one at time, and can return a null pointer. We need a better way to retrieve the frames.

References gnash::key::b.

Referenced by main().

boost::shared_ptr<SimpleBuffer> gnash::rtmp::RTMP::getMessage (  )  [inline]

Get an AMF message received from the server.

TODO: this returns the whole RTMP message, which is ugly. And it only returns one at time, and can return a null pointer. We need a better way to retrieve the messages.

References gnash::key::b.

Referenced by main().

void gnash::rtmp::RTMP::handlePacket ( const RTMPPacket packet  ) 

Handle an RTMPPacket.

void gnash::rtmp::RTMP::play ( const SimpleBuffer amf,
int  id 
)

This is used for sending NetStream requests.

These include play and pause. They are sent as invoke packets on the video channel.

Parameters:
id The stream ID to control. This is encoded in the header, not the AMF payload.

Referenced by sendPausePacket(), and sendPlayPacket().

int gnash::rtmp::RTMP::readSocket ( boost::uint8_t *  dst,
int  num 
)

Read from the socket.

bool gnash::rtmp::RTMP::sendPacket ( RTMPPacket packet  ) 

Send an RTMPPacket on the connection.

Add space for absolute timestamp if necessary.

Encode dataSize and packet type for medium packets.

Encode streamID for large packets.

boost::uint32_t gnash::rtmp::RTMP::serverBandwidth (  )  const [inline]

Get the stored server bandwidth.

void gnash::rtmp::RTMP::setBandwidth ( boost::uint32_t  bw  )  [inline]

Store our bandwidth.

void gnash::rtmp::RTMP::setBufferTime ( size_t  time,
int  streamID 
)

Instruct server to buffer this much data.

Parameters:
time time in milliseconds.
streamID the ID of the stream to set buffer time on.

Referenced by handleInvoke().

void gnash::rtmp::RTMP::setServerBandwidth ( boost::uint32_t  bw  )  [inline]

Store the server bandwidth.

Not sure why we need this.

void gnash::rtmp::RTMP::update (  ) 

This function handles reading incoming data and filling data queues.

You should call this function regularly once the initial connection has been initiated. Its tasks involve: 1. completing the handshake 2. checking for socket errors 3. reading incoming data 4. filling data queues. None of those things should concern you. Just call the function regularly and use connected(), error(), and check the message queues.

No need to continue reading (though it should do no harm).

Referenced by main().


Member Data Documentation


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