Gnash  0.8.11dev
Public Member Functions | Public Attributes | List of all members
gnash::rtmp::RTMP Struct Reference

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

#include <RTMP.h>

Public Member Functions

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

Public Attributes

int _inChunkSize
 
int m_mediaChannel
 
std::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

§ RTMP()

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

Construct a non-connected RTMP handler.

§ ~RTMP()

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

References gnash::key::p, and gnash::key::t.

Member Function Documentation

§ bandwidth()

std::uint32_t gnash::rtmp::RTMP::bandwidth ( ) const
inline

Get our bandwidth.

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

§ call()

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

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

§ close()

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

§ connect()

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::Socket::connect(), gnash::URL::hostname(), gnash::log_debug(), gnash::log_error(), gnash::key::p, gnash::URL::port(), and gnash::URL::str().

§ connected()

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

§ error()

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

Whether the RTMP connection is in error condition.

This is a fatal error.

Referenced by close(), and update().

§ getFLVFrame()

std::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.

§ getMessage()

std::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.

§ handlePacket()

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

§ play()

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::rtmp::RTMPHeader::channel, gnash::rtmp::CHANNEL_VIDEO, gnash::SimpleBuffer::data(), gnash::rtmp::RTMPPacket::header, gnash::rtmp::PACKET_TYPE_INVOKE, sendPacket(), and gnash::SimpleBuffer::size().

Referenced by sendPausePacket(), and sendPlayPacket().

§ readSocket()

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

§ sendPacket()

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

§ serverBandwidth()

std::uint32_t gnash::rtmp::RTMP::serverBandwidth ( ) const
inline

Get the stored server bandwidth.

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

§ setBandwidth()

void gnash::rtmp::RTMP::setBandwidth ( std::uint32_t  bw)
inline

Store our bandwidth.

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

§ setBufferTime()

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::CONTROL_BUFFER_TIME, and gnash::rtmp::sendCtrl().

Referenced by handleInvoke().

§ setServerBandwidth()

void gnash::rtmp::RTMP::setServerBandwidth ( std::uint32_t  bw)
inline

Store the server bandwidth.

Not sure why we need this.

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

§ update()

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 gnash::rtmp::RTMPHeader::channel, gnash::rtmp::clearPayload(), connected(), error(), handlePacket(), gnash::rtmp::hasPayload(), gnash::rtmp::RTMPPacket::header, gnash::key::i, gnash::rtmp::isReady(), gnash::log_debug(), and gnash::key::p.

Member Data Documentation

§ _bytesIn

size_t gnash::rtmp::RTMP::_bytesIn

§ _bytesInSent

size_t gnash::rtmp::RTMP::_bytesInSent

§ _inChunkSize

int gnash::rtmp::RTMP::_inChunkSize

§ m_mediaChannel

int gnash::rtmp::RTMP::m_mediaChannel

Referenced by handlePacket().

§ m_nClientBW2

std::uint8_t gnash::rtmp::RTMP::m_nClientBW2

Referenced by close(), and gnash::rtmp::sendCtrl().


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