• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

rtmp_server.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 // Define this if you want to use numeric client ID. Undefining this
00042 // create ASCII based client IDs instead.
00043 // #define CLIENT_ID_NUMERIC 1
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     // These are handlers for the various types
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     // Encode a Ping for the client
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     // boost::shared_ptr<cygnal::Buffer> encodeUser(user_control_e type, boost::uint32_t milliseconds);
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     // Encode a onBWDone message for the client
00079     boost::shared_ptr<cygnal::Buffer> encodeBWDone(double id);
00080 
00081     // Parse an Echo Request message coming from the Red5 echo_test.
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     // format a response to the 'echo' test used for testing Gnash.
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     // Create a new client ID
00094 #ifdef CLIENT_ID_NUMERIC
00095     double createClientID();
00096 #else
00097     std::string createClientID();
00098 #endif
00099 
00100     // Create a new stream ID, which is simply an incrementing counter.
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 // This is the thread for all incoming RTMP connections
00153 bool DSOEXPORT rtmp_handler(gnash::Network::thread_params_t *args);
00154 
00155 } // end of gnash namespace
00156 // end of _RTMP_SERVER_H_
00157 #endif
00158 
00159 // local Variables:
00160 // mode: C++
00161 // indent-tabs-mode: t
00162 // End:
00163 

Generated on Thu Sep 30 2010 14:35:02 for Gnash by  doxygen 1.7.1