Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _RTMP_SERVER_H_
00020 #define _RTMP_SERVER_H_
00021
00022 #include <vector>
00023 #include <boost/cstdint.hpp>
00024 #include <boost/shared_ptr.hpp>
00025 #include <boost/array.hpp>
00026 #include <string>
00027 #include <map>
00028
00029 #include "rtmp.h"
00030 #include "amf.h"
00031 #include "handler.h"
00032 #include "network.h"
00033 #include "buffer.h"
00034 #include "diskstream.h"
00035 #include "rtmp_msg.h"
00036 #include "dsodefs.h"
00037
00038 namespace cygnal
00039 {
00040
00041
00042
00043
00044
00045 class RTMPServer : public gnash::RTMP
00046 {
00047 public:
00048 RTMPServer();
00049 ~RTMPServer();
00050
00059 boost::shared_ptr<cygnal::Element> processClientHandShake(int fd);
00060
00061 bool packetSend(cygnal::Buffer &buf);
00062 bool packetRead(cygnal::Buffer &buf);
00063
00064
00065 boost::shared_ptr<cygnal::Buffer> encodeResult(gnash::RTMPMsg::rtmp_status_e status);
00066 boost::shared_ptr<cygnal::Buffer> encodeResult(gnash::RTMPMsg::rtmp_status_e status, const std::string &filename);
00067 boost::shared_ptr<cygnal::Buffer> encodeResult(gnash::RTMPMsg::rtmp_status_e status, const std::string &filename, double &transid);
00068 boost::shared_ptr<cygnal::Buffer> encodeResult(gnash::RTMPMsg::rtmp_status_e status, double &transid);
00069 boost::shared_ptr<cygnal::Buffer> encodeResult(gnash::RTMPMsg::rtmp_status_e status, const std::string &filename, double &transid, double &clientid);
00070
00071
00072 boost::shared_ptr<cygnal::Buffer> encodePing(rtmp_ping_e type, boost::uint32_t milliseconds);
00073 boost::shared_ptr<cygnal::Buffer> encodePing(rtmp_ping_e type);
00074
00075 boost::shared_ptr<cygnal::Buffer> encodeAudio(boost::uint8_t *data, size_t size);
00076 boost::shared_ptr<cygnal::Buffer> encodeVideo(boost::uint8_t *data, size_t size);
00077
00078
00079 boost::shared_ptr<cygnal::Buffer> encodeBWDone(double id);
00080
00081
00082 std::vector<boost::shared_ptr<cygnal::Element > > parseEchoRequest(cygnal::Buffer &buf) { return parseEchoRequest(buf.reference(), buf.size()); };
00083 std::vector<boost::shared_ptr<cygnal::Element > > parseEchoRequest(boost::uint8_t *buf, size_t size);
00084
00085 boost::shared_ptr<cygnal::Buffer> formatEchoResponse(double num, cygnal::Element &el);
00086 boost::shared_ptr<cygnal::Buffer> formatEchoResponse(double num, cygnal::Buffer &data);
00087 boost::shared_ptr<cygnal::Buffer> formatEchoResponse(double num, boost::uint8_t *data, size_t size);
00088 void addReference(boost::uint16_t index, cygnal::Element &el) { _references[index] = el; };
00089 cygnal::Element &getReference(boost::uint16_t index) { return _references[index]; };
00090
00091 bool sendFile(int fd, const std::string &filespec);
00092
00093
00094 #ifdef CLIENT_ID_NUMERIC
00095 double createClientID();
00096 #else
00097 std::string createClientID();
00098 #endif
00099
00100
00101 double createStreamID();
00102
00103 void setStreamID(double id) { _streamid = id; };
00104 double getStreamID() { return _streamid; };
00105
00106 size_t sendToClient(std::vector<int> &fds, boost::uint8_t *data,
00107 size_t size);
00108 size_t sendToClient(std::vector<int> &fds,cygnal::Buffer &data);
00109
00110 void setNetConnection(gnash::RTMPMsg *msg) { _netconnect.reset(msg); };
00111 void setNetConnection(boost::shared_ptr<gnash::RTMPMsg> msg) { _netconnect = msg; };
00112 boost::shared_ptr<gnash::RTMPMsg> getNetConnection() { return _netconnect;};
00113 void dump();
00114
00115 private:
00120 boost::shared_ptr<cygnal::Buffer> serverFinish(int fd,
00121 cygnal::Buffer &handshake1, cygnal::Buffer &handshake2);
00125 bool handShakeResponse(int fd, cygnal::Buffer &buf);
00126
00129 typedef boost::char_separator<char> Sep;
00130 typedef boost::tokenizer<Sep> Tok;
00131
00132
00133 gnash::DiskStream::filetype_e _filetype;
00134 std::string _docroot;
00135 std::string _filespec;
00136 boost::uint32_t _filesize;
00137 std::map<boost::uint16_t, cygnal::Element> _references;
00138 #ifdef CLIENT_ID_NUMERIC
00139 std::array<double> _clientids;
00140 #else
00141 boost::array<std::string, 1000> _clientids;
00142 #endif
00143 double _streamid;
00149 boost::shared_ptr<gnash::RTMPMsg> _netconnect;
00150 };
00151
00152
00153 bool DSOEXPORT rtmp_handler(gnash::Network::thread_params_t *args);
00154
00155 }
00156
00157 #endif
00158
00159
00160
00161
00162
00163