Gnash
0.8.11dev
|
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< SimpleBuffer > | getMessage () |
Get an AMF message received from the server. More... | |
std::shared_ptr< SimpleBuffer > | getFLVFrame () |
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 |
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:
gnash::rtmp::RTMP::RTMP | ( | ) |
Construct a non-connected RTMP handler.
gnash::rtmp::RTMP::~RTMP | ( | ) |
References gnash::key::p, and gnash::key::t.
|
inline |
Get our bandwidth.
Referenced by gnash::rtmp::sendCtrl().
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:
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().
void gnash::rtmp::RTMP::close | ( | ) |
Close the connection.
A new connection may now be opened.
References _, _bytesIn, _bytesInSent, _inChunkSize, gnash::Socket::close(), gnash::Socket::connected(), gnash::equal(), error(), gnash::log_debug(), gnash::log_error(), m_nClientBW2, gnash::Socket::read(), RTMP_DEFAULT_CHUNKSIZE, gnash::key::s, and gnash::Socket::write().
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::Socket::connect(), gnash::URL::hostname(), gnash::log_debug(), gnash::log_error(), gnash::key::p, gnash::URL::port(), and gnash::URL::str().
|
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().
|
inline |
|
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.
|
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.
void gnash::rtmp::RTMP::handlePacket | ( | const RTMPPacket & | packet | ) |
Handle an RTMPPacket.
References _, gnash::rtmp::RTMPPacket::buffer, gnash::rtmp::RTMPHeader::channel, gnash::rtmp::RTMPPacket::header, gnash::log_debug(), gnash::log_error(), LOG_ONCE, gnash::log_unimpl(), m_mediaChannel, gnash::rtmp::PACKET_TYPE_AUDIO, gnash::rtmp::PACKET_TYPE_BYTES_READ, gnash::rtmp::PACKET_TYPE_CHUNK_SIZE, gnash::rtmp::PACKET_TYPE_CLIENTBW, gnash::rtmp::PACKET_TYPE_CONTROL, gnash::rtmp::PACKET_TYPE_FLEX_MESSAGE, gnash::rtmp::PACKET_TYPE_FLEX_SHARED_OBJECT, gnash::rtmp::PACKET_TYPE_FLEX_STREAM_SEND, gnash::rtmp::PACKET_TYPE_FLV, gnash::rtmp::PACKET_TYPE_INVOKE, gnash::rtmp::PACKET_TYPE_METADATA, gnash::rtmp::PACKET_TYPE_SERVERBW, gnash::rtmp::PACKET_TYPE_SHARED_OBJECT, gnash::rtmp::PACKET_TYPE_VIDEO, gnash::rtmp::RTMPHeader::packetType, gnash::rtmp::payloadData(), and gnash::rtmp::payloadSize().
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::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().
int gnash::rtmp::RTMP::readSocket | ( | std::uint8_t * | dst, |
int | num | ||
) |
Read from the socket.
References _bytesIn, _bytesInSent, gnash::Socket::bad(), gnash::Socket::connected(), gnash::Socket::eof(), gnash::log_debug(), and gnash::Socket::read().
Referenced by gnash::rtmp::sendServerBW().
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::RTMPHeader::_streamID, gnash::rtmp::RTMPHeader::_timestamp, gnash::key::c, gnash::rtmp::RTMPHeader::channel, gnash::rtmp::RTMPHeader::dataSize, gnash::image::end(), gnash::rtmp::RTMPPacket::header, gnash::rtmp::RTMPHeader::headerType, gnash::hexify(), gnash::log_debug(), gnash::rtmp::PACKET_TYPE_INVOKE, gnash::rtmp::RTMPHeader::packetType, gnash::rtmp::payloadData(), gnash::rtmp::payloadEnd(), gnash::rtmp::payloadSize(), gnash::amf::readString(), gnash::rtmp::RTMP_PACKET_SIZE_LARGE, gnash::rtmp::RTMP_PACKET_SIZE_MEDIUM, gnash::rtmp::RTMP_PACKET_SIZE_MINIMUM, gnash::rtmp::RTMP_PACKET_SIZE_SMALL, gnash::key::s, gnash::amf::STRING_AMF0, and gnash::Socket::write().
Referenced by call(), play(), gnash::rtmp::sendCtrl(), and gnash::rtmp::sendServerBW().
|
inline |
Get the stored server bandwidth.
Referenced by gnash::rtmp::sendServerBW().
|
inline |
Store our bandwidth.
Referenced by gnash::rtmp::sendCtrl().
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::CONTROL_BUFFER_TIME, and gnash::rtmp::sendCtrl().
Referenced by handleInvoke().
|
inline |
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:
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.
size_t gnash::rtmp::RTMP::_bytesIn |
Referenced by close(), readSocket(), and gnash::rtmp::sendCtrl().
size_t gnash::rtmp::RTMP::_bytesInSent |
Referenced by close(), readSocket(), and gnash::rtmp::sendCtrl().
int gnash::rtmp::RTMP::_inChunkSize |
Referenced by close(), gnash::rtmp::sendCtrl(), and gnash::rtmp::sendServerBW().
int gnash::rtmp::RTMP::m_mediaChannel |
Referenced by handlePacket().
std::uint8_t gnash::rtmp::RTMP::m_nClientBW2 |
Referenced by close(), and gnash::rtmp::sendCtrl().