Gnash
0.8.10
|
This class is for handling the RTMP protocol. More...
#include <RTMP.h>
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< SimpleBuffer > | getMessage () |
Get an AMF message received from the server. | |
boost::shared_ptr< SimpleBuffer > | getFLVFrame () |
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 |
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().
gnash::rtmp::RTMP::RTMP | ( | ) |
Construct a non-connected RTMP handler.
gnash::rtmp::RTMP::~RTMP | ( | ) |
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.
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.
bool gnash::rtmp::RTMP::error | ( | ) | const [inline] |
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.
References gnash::rtmp::RTMPPacket::header, gnash::rtmp::RTMPHeader::packetType, gnash::rtmp::PACKET_TYPE_CHUNK_SIZE, gnash::rtmp::PACKET_TYPE_BYTES_READ, gnash::rtmp::PACKET_TYPE_CONTROL, gnash::rtmp::PACKET_TYPE_SERVERBW, gnash::rtmp::PACKET_TYPE_CLIENTBW, gnash::rtmp::PACKET_TYPE_AUDIO, m_mediaChannel, gnash::rtmp::RTMPHeader::channel, gnash::rtmp::PACKET_TYPE_VIDEO, gnash::rtmp::PACKET_TYPE_FLEX_STREAM_SEND, LOG_ONCE, _, gnash::rtmp::PACKET_TYPE_FLEX_SHARED_OBJECT, gnash::rtmp::PACKET_TYPE_FLEX_MESSAGE, gnash::rtmp::RTMPPacket::buffer, gnash::rtmp::PACKET_TYPE_METADATA, gnash::rtmp::payloadData(), gnash::rtmp::payloadSize(), gnash::rtmp::PACKET_TYPE_SHARED_OBJECT, gnash::rtmp::PACKET_TYPE_INVOKE, and gnash::rtmp::PACKET_TYPE_FLV.
Referenced by update().
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.
id | The 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 | ||
) |
Read from the socket.
References assert, gnash::Socket::read(), gnash::Socket::bad(), gnash::Socket::eof(), gnash::Socket::connected(), _bytesIn, and _bytesInSent.
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.
References gnash::rtmp::RTMPPacket::header, gnash::rtmp::RTMPHeader::dataSize, gnash::rtmp::payloadSize(), gnash::rtmp::RTMPHeader::channel, assert, gnash::rtmp::RTMPHeader::headerType, gnash::rtmp::RTMP_PACKET_SIZE_LARGE, gnash::rtmp::RTMPHeader::_timestamp, gnash::rtmp::RTMP_PACKET_SIZE_MEDIUM, gnash::rtmp::RTMPHeader::packetType, gnash::rtmp::RTMP_PACKET_SIZE_SMALL, gnash::rtmp::RTMP_PACKET_SIZE_MINIMUM, gnash::key::c, gnash::rtmp::payloadData(), gnash::rtmp::RTMPHeader::_streamID, gnash::rtmp::payloadEnd(), gnash::Socket::write(), gnash::rtmp::PACKET_TYPE_INVOKE, gnash::amf::STRING_AMF0, gnash::image::end(), gnash::key::s, and gnash::amf::readString().
Referenced by call(), play(), gnash::rtmp::sendServerBW(), and gnash::rtmp::sendCtrl().
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.
time | time in milliseconds. |
streamID | the 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().
size_t gnash::rtmp::RTMP::_bytesIn |
Referenced by readSocket(), and close().
Referenced by readSocket(), and close().
Referenced by close().
Referenced by handlePacket().
boost::uint8_t gnash::rtmp::RTMP::m_nClientBW2 |
Referenced by close().