Gnash  0.8.10
Public Member Functions | Public Attributes
gnash::rtmp::RTMP Struct Reference

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

#include <RTMP.h>

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::key::p, gnash::SimpleBuffer::size(), gnash::SimpleBuffer::data(), and sendPacket().

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

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

Close the connection.

A new connection may now be opened.

References gnash::Socket::close(), _inChunkSize, RTMP_DEFAULT_CHUNKSIZE, _bytesIn, _bytesInSent, and m_nClientBW2.

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.

References gnash::URL::str(), gnash::URL::hostname(), gnash::key::p, gnash::URL::port(), gnash::Socket::connect(), and _.

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 update(), and 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 update(), and 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)
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:
idThe stream ID to control. This is encoded in the header, not the AMF payload.

References gnash::SimpleBuffer::size(), gnash::rtmp::RTMPPacket::header, gnash::rtmp::RTMPHeader::channel, gnash::rtmp::CHANNEL_VIDEO, gnash::rtmp::PACKET_TYPE_INVOKE, gnash::SimpleBuffer::data(), and sendPacket().

Referenced by sendPausePacket(), and sendPlayPacket().

int gnash::rtmp::RTMP::readSocket ( boost::uint8_t *  dst,
int  num 
)
bool gnash::rtmp::RTMP::sendPacket ( RTMPPacket packet)
boost::uint32_t gnash::rtmp::RTMP::serverBandwidth ( ) const [inline]

Get the stored server bandwidth.

Referenced by gnash::rtmp::sendServerBW().

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:
timetime in milliseconds.
streamIDthe ID of the stream to set buffer time on.

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

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).

References connected(), gnash::key::i, error(), gnash::key::p, gnash::rtmp::hasPayload(), gnash::rtmp::RTMPPacket::header, gnash::rtmp::RTMPHeader::channel, gnash::rtmp::isReady(), gnash::rtmp::clearPayload(), and handlePacket().

Referenced by main().


Member Data Documentation

Referenced by readSocket(), and close().

Referenced by readSocket(), and close().

Referenced by close().

Referenced by handlePacket().

Referenced by close().


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