mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
rename pro to rtmp protocol.
This commit is contained in:
parent
8d5806154b
commit
4c498b67da
12 changed files with 18 additions and 18 deletions
1243
trunk/src/rtmp/srs_protocol_amf0.cpp
Normal file
1243
trunk/src/rtmp/srs_protocol_amf0.cpp
Normal file
File diff suppressed because it is too large
Load diff
319
trunk/src/rtmp/srs_protocol_amf0.hpp
Normal file
319
trunk/src/rtmp/srs_protocol_amf0.hpp
Normal file
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_PROTOCOL_AMF0_HPP
|
||||
#define SRS_PROTOCOL_AMF0_HPP
|
||||
|
||||
/*
|
||||
#include <srs_protocol_amf0.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SrsStream;
|
||||
class SrsAmf0Object;
|
||||
|
||||
/**
|
||||
* any amf0 value.
|
||||
* 2.1 Types Overview
|
||||
* value-type = number-type | boolean-type | string-type | object-type
|
||||
* | null-marker | undefined-marker | reference-type | ecma-array-type
|
||||
* | strict-array-type | date-type | long-string-type | xml-document-type
|
||||
* | typed-object-type
|
||||
*/
|
||||
struct SrsAmf0Any
|
||||
{
|
||||
char marker;
|
||||
|
||||
SrsAmf0Any();
|
||||
virtual ~SrsAmf0Any();
|
||||
|
||||
virtual bool is_string();
|
||||
virtual bool is_boolean();
|
||||
virtual bool is_number();
|
||||
virtual bool is_null();
|
||||
virtual bool is_undefined();
|
||||
virtual bool is_object();
|
||||
virtual bool is_object_eof();
|
||||
virtual bool is_ecma_array();
|
||||
};
|
||||
|
||||
/**
|
||||
* read amf0 string from stream.
|
||||
* 2.4 String Type
|
||||
* string-type = string-marker UTF-8
|
||||
* @return default value is empty string.
|
||||
*/
|
||||
struct SrsAmf0String : public SrsAmf0Any
|
||||
{
|
||||
std::string value;
|
||||
|
||||
SrsAmf0String(const char* _value = NULL);
|
||||
virtual ~SrsAmf0String();
|
||||
};
|
||||
|
||||
/**
|
||||
* read amf0 boolean from stream.
|
||||
* 2.4 String Type
|
||||
* boolean-type = boolean-marker U8
|
||||
* 0 is false, <> 0 is true
|
||||
* @return default value is false.
|
||||
*/
|
||||
struct SrsAmf0Boolean : public SrsAmf0Any
|
||||
{
|
||||
bool value;
|
||||
|
||||
SrsAmf0Boolean(bool _value = false);
|
||||
virtual ~SrsAmf0Boolean();
|
||||
};
|
||||
|
||||
/**
|
||||
* read amf0 number from stream.
|
||||
* 2.2 Number Type
|
||||
* number-type = number-marker DOUBLE
|
||||
* @return default value is 0.
|
||||
*/
|
||||
struct SrsAmf0Number : public SrsAmf0Any
|
||||
{
|
||||
double value;
|
||||
|
||||
SrsAmf0Number(double _value = 0.0);
|
||||
virtual ~SrsAmf0Number();
|
||||
};
|
||||
|
||||
/**
|
||||
* read amf0 null from stream.
|
||||
* 2.7 null Type
|
||||
* null-type = null-marker
|
||||
*/
|
||||
struct SrsAmf0Null : public SrsAmf0Any
|
||||
{
|
||||
SrsAmf0Null();
|
||||
virtual ~SrsAmf0Null();
|
||||
};
|
||||
|
||||
/**
|
||||
* read amf0 undefined from stream.
|
||||
* 2.8 undefined Type
|
||||
* undefined-type = undefined-marker
|
||||
*/
|
||||
struct SrsAmf0Undefined : public SrsAmf0Any
|
||||
{
|
||||
SrsAmf0Undefined();
|
||||
virtual ~SrsAmf0Undefined();
|
||||
};
|
||||
|
||||
/**
|
||||
* 2.11 Object End Type
|
||||
* object-end-type = UTF-8-empty object-end-marker
|
||||
* 0x00 0x00 0x09
|
||||
*/
|
||||
struct SrsAmf0ObjectEOF : public SrsAmf0Any
|
||||
{
|
||||
int16_t utf8_empty;
|
||||
|
||||
SrsAmf0ObjectEOF();
|
||||
virtual ~SrsAmf0ObjectEOF();
|
||||
};
|
||||
|
||||
/**
|
||||
* to ensure in inserted order.
|
||||
* for the FMLE will crash when AMF0Object is not ordered by inserted,
|
||||
* if ordered in map, the string compare order, the FMLE will creash when
|
||||
* get the response of connect app.
|
||||
*/
|
||||
struct SrsUnSortedHashtable
|
||||
{
|
||||
private:
|
||||
typedef std::pair<std::string, SrsAmf0Any*> SrsObjectPropertyType;
|
||||
std::vector<SrsObjectPropertyType> properties;
|
||||
public:
|
||||
SrsUnSortedHashtable();
|
||||
virtual ~SrsUnSortedHashtable();
|
||||
|
||||
virtual int size();
|
||||
virtual void clear();
|
||||
virtual std::string key_at(int index);
|
||||
virtual SrsAmf0Any* value_at(int index);
|
||||
virtual void set(std::string key, SrsAmf0Any* value);
|
||||
|
||||
virtual SrsAmf0Any* get_property(std::string name);
|
||||
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
||||
virtual SrsAmf0Any* ensure_property_number(std::string name);
|
||||
};
|
||||
|
||||
/**
|
||||
* 2.5 Object Type
|
||||
* anonymous-object-type = object-marker *(object-property)
|
||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
||||
*/
|
||||
struct SrsAmf0Object : public SrsAmf0Any
|
||||
{
|
||||
private:
|
||||
SrsUnSortedHashtable properties;
|
||||
public:
|
||||
SrsAmf0ObjectEOF eof;
|
||||
|
||||
SrsAmf0Object();
|
||||
virtual ~SrsAmf0Object();
|
||||
|
||||
virtual int size();
|
||||
virtual std::string key_at(int index);
|
||||
virtual SrsAmf0Any* value_at(int index);
|
||||
virtual void set(std::string key, SrsAmf0Any* value);
|
||||
|
||||
virtual SrsAmf0Any* get_property(std::string name);
|
||||
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
||||
virtual SrsAmf0Any* ensure_property_number(std::string name);
|
||||
};
|
||||
|
||||
/**
|
||||
* 2.10 ECMA Array Type
|
||||
* ecma-array-type = associative-count *(object-property)
|
||||
* associative-count = U32
|
||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
||||
*/
|
||||
struct SrsASrsAmf0EcmaArray : public SrsAmf0Any
|
||||
{
|
||||
private:
|
||||
SrsUnSortedHashtable properties;
|
||||
public:
|
||||
int32_t count;
|
||||
SrsAmf0ObjectEOF eof;
|
||||
|
||||
SrsASrsAmf0EcmaArray();
|
||||
virtual ~SrsASrsAmf0EcmaArray();
|
||||
|
||||
virtual int size();
|
||||
virtual void clear();
|
||||
virtual std::string key_at(int index);
|
||||
virtual SrsAmf0Any* value_at(int index);
|
||||
virtual void set(std::string key, SrsAmf0Any* value);
|
||||
|
||||
virtual SrsAmf0Any* get_property(std::string name);
|
||||
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
||||
};
|
||||
|
||||
/**
|
||||
* read amf0 utf8 string from stream.
|
||||
* 1.3.1 Strings and UTF-8
|
||||
* UTF-8 = U16 *(UTF8-char)
|
||||
* UTF8-char = UTF8-1 | UTF8-2 | UTF8-3 | UTF8-4
|
||||
* UTF8-1 = %x00-7F
|
||||
* @remark only support UTF8-1 char.
|
||||
*/
|
||||
extern int srs_amf0_read_utf8(SrsStream* stream, std::string& value);
|
||||
extern int srs_amf0_write_utf8(SrsStream* stream, std::string value);
|
||||
|
||||
/**
|
||||
* read amf0 string from stream.
|
||||
* 2.4 String Type
|
||||
* string-type = string-marker UTF-8
|
||||
*/
|
||||
extern int srs_amf0_read_string(SrsStream* stream, std::string& value);
|
||||
extern int srs_amf0_write_string(SrsStream* stream, std::string value);
|
||||
|
||||
/**
|
||||
* read amf0 boolean from stream.
|
||||
* 2.4 String Type
|
||||
* boolean-type = boolean-marker U8
|
||||
* 0 is false, <> 0 is true
|
||||
*/
|
||||
extern int srs_amf0_read_boolean(SrsStream* stream, bool& value);
|
||||
extern int srs_amf0_write_boolean(SrsStream* stream, bool value);
|
||||
|
||||
/**
|
||||
* read amf0 number from stream.
|
||||
* 2.2 Number Type
|
||||
* number-type = number-marker DOUBLE
|
||||
*/
|
||||
extern int srs_amf0_read_number(SrsStream* stream, double& value);
|
||||
extern int srs_amf0_write_number(SrsStream* stream, double value);
|
||||
|
||||
/**
|
||||
* read amf0 null from stream.
|
||||
* 2.7 null Type
|
||||
* null-type = null-marker
|
||||
*/
|
||||
extern int srs_amf0_read_null(SrsStream* stream);
|
||||
extern int srs_amf0_write_null(SrsStream* stream);
|
||||
|
||||
/**
|
||||
* read amf0 undefined from stream.
|
||||
* 2.8 undefined Type
|
||||
* undefined-type = undefined-marker
|
||||
*/
|
||||
extern int srs_amf0_read_undefined(SrsStream* stream);
|
||||
extern int srs_amf0_write_undefined(SrsStream* stream);
|
||||
|
||||
extern int srs_amf0_read_any(SrsStream* stream, SrsAmf0Any*& value);
|
||||
|
||||
/**
|
||||
* read amf0 object from stream.
|
||||
* 2.5 Object Type
|
||||
* anonymous-object-type = object-marker *(object-property)
|
||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
||||
*/
|
||||
extern int srs_amf0_read_object(SrsStream* stream, SrsAmf0Object*& value);
|
||||
extern int srs_amf0_write_object(SrsStream* stream, SrsAmf0Object* value);
|
||||
|
||||
/**
|
||||
* read amf0 object from stream.
|
||||
* 2.10 ECMA Array Type
|
||||
* ecma-array-type = associative-count *(object-property)
|
||||
* associative-count = U32
|
||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
||||
*/
|
||||
extern int srs_amf0_read_ecma_array(SrsStream* stream, SrsASrsAmf0EcmaArray*& value);
|
||||
extern int srs_amf0_write_ecma_array(SrsStream* stream, SrsASrsAmf0EcmaArray* value);
|
||||
|
||||
/**
|
||||
* get amf0 objects size.
|
||||
*/
|
||||
extern int srs_amf0_get_utf8_size(std::string value);
|
||||
extern int srs_amf0_get_string_size(std::string value);
|
||||
extern int srs_amf0_get_number_size();
|
||||
extern int srs_amf0_get_null_size();
|
||||
extern int srs_amf0_get_undefined_size();
|
||||
extern int srs_amf0_get_boolean_size();
|
||||
extern int srs_amf0_get_object_size(SrsAmf0Object* obj);
|
||||
extern int srs_amf0_get_ecma_array_size(SrsASrsAmf0EcmaArray* arr);
|
||||
|
||||
/**
|
||||
* convert the any to specified object.
|
||||
* @return T*, the converted object. never NULL.
|
||||
* @remark, user must ensure the current object type,
|
||||
* or the covert will cause assert failed.
|
||||
*/
|
||||
template<class T>
|
||||
T* srs_amf0_convert(SrsAmf0Any* any)
|
||||
{
|
||||
T* p = dynamic_cast<T*>(any);
|
||||
srs_assert(p != NULL);
|
||||
return p;
|
||||
}
|
||||
|
||||
#endif
|
1296
trunk/src/rtmp/srs_protocol_handshake.cpp
Normal file
1296
trunk/src/rtmp/srs_protocol_handshake.cpp
Normal file
File diff suppressed because it is too large
Load diff
78
trunk/src/rtmp/srs_protocol_handshake.hpp
Normal file
78
trunk/src/rtmp/srs_protocol_handshake.hpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_PROTOCOL_HANDSHKAE_HPP
|
||||
#define SRS_PROTOCOL_HANDSHKAE_HPP
|
||||
|
||||
/*
|
||||
#include <srs_protocol_handshake.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
class ISrsProtocolReaderWriter;
|
||||
class SrsComplexHandshake;
|
||||
|
||||
/**
|
||||
* try complex handshake, if failed, fallback to simple handshake.
|
||||
*/
|
||||
class SrsSimpleHandshake
|
||||
{
|
||||
public:
|
||||
SrsSimpleHandshake();
|
||||
virtual ~SrsSimpleHandshake();
|
||||
public:
|
||||
/**
|
||||
* simple handshake.
|
||||
* @param complex_hs, try complex handshake first,
|
||||
* if failed, rollback to simple handshake.
|
||||
*/
|
||||
virtual int handshake_with_client(ISrsProtocolReaderWriter* io, SrsComplexHandshake& complex_hs);
|
||||
virtual int handshake_with_server(ISrsProtocolReaderWriter* io, SrsComplexHandshake& complex_hs);
|
||||
};
|
||||
|
||||
/**
|
||||
* rtmp complex handshake,
|
||||
* @see also crtmp(crtmpserver) or librtmp,
|
||||
* @see also: http://blog.csdn.net/win_lin/article/details/13006803
|
||||
*/
|
||||
class SrsComplexHandshake
|
||||
{
|
||||
public:
|
||||
SrsComplexHandshake();
|
||||
virtual ~SrsComplexHandshake();
|
||||
public:
|
||||
/**
|
||||
* complex hanshake.
|
||||
* @_c1, size of c1 must be 1536.
|
||||
* @remark, user must free the c1.
|
||||
* @return user must:
|
||||
* continue connect app if success,
|
||||
* try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS,
|
||||
* otherwise, disconnect
|
||||
*/
|
||||
virtual int handshake_with_client(ISrsProtocolReaderWriter* io, char* _c1);
|
||||
virtual int handshake_with_server(ISrsProtocolReaderWriter* io);
|
||||
};
|
||||
|
||||
#endif
|
48
trunk/src/rtmp/srs_protocol_io.cpp
Normal file
48
trunk/src/rtmp/srs_protocol_io.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <srs_protocol_io.hpp>
|
||||
|
||||
ISrsProtocolReader::ISrsProtocolReader()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsProtocolReader::~ISrsProtocolReader()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsProtocolWriter::ISrsProtocolWriter()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsProtocolWriter::~ISrsProtocolWriter()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsProtocolReaderWriter::ISrsProtocolReaderWriter()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsProtocolReaderWriter::~ISrsProtocolReaderWriter()
|
||||
{
|
||||
}
|
87
trunk/src/rtmp/srs_protocol_io.hpp
Normal file
87
trunk/src/rtmp/srs_protocol_io.hpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_PROTOCOL_IO_HPP
|
||||
#define SRS_PROTOCOL_IO_HPP
|
||||
|
||||
/*
|
||||
#include <srs_protocol_io.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <srs_kernel_buffer.hpp>
|
||||
|
||||
/**
|
||||
* the reader for the protocol to read from whatever channel.
|
||||
*/
|
||||
class ISrsProtocolReader : public ISrsBufferReader
|
||||
{
|
||||
public:
|
||||
ISrsProtocolReader();
|
||||
virtual ~ISrsProtocolReader();
|
||||
// for protocol
|
||||
public:
|
||||
virtual void set_recv_timeout(int64_t timeout_us) = 0;
|
||||
virtual int64_t get_recv_timeout() = 0;
|
||||
virtual int64_t get_recv_bytes() = 0;
|
||||
virtual int get_recv_kbps() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* the writer for the protocol to write to whatever channel.
|
||||
*/
|
||||
class ISrsProtocolWriter
|
||||
{
|
||||
public:
|
||||
ISrsProtocolWriter();
|
||||
virtual ~ISrsProtocolWriter();
|
||||
// for protocol
|
||||
public:
|
||||
virtual void set_send_timeout(int64_t timeout_us) = 0;
|
||||
virtual int64_t get_send_timeout() = 0;
|
||||
virtual int64_t get_send_bytes() = 0;
|
||||
virtual int get_send_kbps() = 0;
|
||||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite) = 0;
|
||||
};
|
||||
|
||||
class ISrsProtocolReaderWriter : public ISrsProtocolReader, public ISrsProtocolWriter
|
||||
{
|
||||
public:
|
||||
ISrsProtocolReaderWriter();
|
||||
virtual ~ISrsProtocolReaderWriter();
|
||||
// for protocol
|
||||
public:
|
||||
/**
|
||||
* whether the specified timeout_us is never timeout.
|
||||
*/
|
||||
virtual bool is_never_timeout(int64_t timeout_us) = 0;
|
||||
// for handshake.
|
||||
public:
|
||||
virtual int read_fully(const void* buf, size_t size, ssize_t* nread) = 0;
|
||||
virtual int write(const void* buf, size_t size, ssize_t* nwrite) = 0;
|
||||
};
|
||||
|
||||
#endif
|
1220
trunk/src/rtmp/srs_protocol_rtmp.cpp
Normal file
1220
trunk/src/rtmp/srs_protocol_rtmp.cpp
Normal file
File diff suppressed because it is too large
Load diff
236
trunk/src/rtmp/srs_protocol_rtmp.hpp
Normal file
236
trunk/src/rtmp/srs_protocol_rtmp.hpp
Normal file
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_PROTOCOL_RTMP_HPP
|
||||
#define SRS_PROTOCOL_RTMP_HPP
|
||||
|
||||
/*
|
||||
#include <srs_protocol_rtmp.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
class SrsProtocol;
|
||||
class ISrsProtocolReaderWriter;
|
||||
class ISrsMessage;
|
||||
class SrsCommonMessage;
|
||||
class SrsCreateStreamPacket;
|
||||
class SrsFMLEStartPacket;
|
||||
class SrsPublishPacket;
|
||||
class SrsSharedPtrMessage;
|
||||
class SrsOnMetaDataPacket;
|
||||
class SrsPlayPacket;
|
||||
|
||||
/**
|
||||
* the original request from client.
|
||||
*/
|
||||
struct SrsRequest
|
||||
{
|
||||
/**
|
||||
* tcUrl: rtmp://request_vhost:port/app/stream
|
||||
* support pass vhost in query string, such as:
|
||||
* rtmp://ip:port/app?vhost=request_vhost/stream
|
||||
* rtmp://ip:port/app...vhost...request_vhost/stream
|
||||
*/
|
||||
std::string tcUrl;
|
||||
std::string pageUrl;
|
||||
std::string swfUrl;
|
||||
double objectEncoding;
|
||||
|
||||
std::string schema;
|
||||
std::string vhost;
|
||||
std::string port;
|
||||
std::string app;
|
||||
std::string stream;
|
||||
|
||||
SrsRequest();
|
||||
virtual ~SrsRequest();
|
||||
|
||||
/**
|
||||
* deep copy the request, for source to use it to support reload,
|
||||
* for when initialize the source, the request is valid,
|
||||
* when reload it, the request maybe invalid, so need to copy it.
|
||||
*/
|
||||
virtual SrsRequest* copy();
|
||||
|
||||
/**
|
||||
* disconvery vhost/app from tcUrl.
|
||||
*/
|
||||
virtual int discovery_app();
|
||||
virtual std::string get_stream_url();
|
||||
virtual void strip();
|
||||
private:
|
||||
std::string& trim(std::string& str, std::string chs);
|
||||
};
|
||||
|
||||
/**
|
||||
* the response to client.
|
||||
*/
|
||||
struct SrsResponse
|
||||
{
|
||||
int stream_id;
|
||||
|
||||
SrsResponse();
|
||||
virtual ~SrsResponse();
|
||||
};
|
||||
|
||||
/**
|
||||
* the rtmp client type.
|
||||
*/
|
||||
enum SrsClientType
|
||||
{
|
||||
SrsClientUnknown,
|
||||
SrsClientPlay,
|
||||
SrsClientFMLEPublish,
|
||||
SrsClientFlashPublish,
|
||||
};
|
||||
|
||||
/**
|
||||
* implements the client role protocol.
|
||||
*/
|
||||
class SrsRtmpClient
|
||||
{
|
||||
protected:
|
||||
SrsProtocol* protocol;
|
||||
ISrsProtocolReaderWriter* io;
|
||||
public:
|
||||
SrsRtmpClient(ISrsProtocolReaderWriter* skt);
|
||||
virtual ~SrsRtmpClient();
|
||||
public:
|
||||
virtual void set_recv_timeout(int64_t timeout_us);
|
||||
virtual void set_send_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_recv_bytes();
|
||||
virtual int64_t get_send_bytes();
|
||||
virtual int get_recv_kbps();
|
||||
virtual int get_send_kbps();
|
||||
virtual int recv_message(SrsCommonMessage** pmsg);
|
||||
virtual int send_message(ISrsMessage* msg);
|
||||
public:
|
||||
virtual int handshake();
|
||||
virtual int connect_app(std::string app, std::string tc_url);
|
||||
virtual int create_stream(int& stream_id);
|
||||
virtual int play(std::string stream, int stream_id);
|
||||
virtual int publish(std::string stream, int stream_id);
|
||||
};
|
||||
|
||||
/**
|
||||
* the rtmp provices rtmp-command-protocol services,
|
||||
* a high level protocol, media stream oriented services,
|
||||
* such as connect to vhost/app, play stream, get audio/video data.
|
||||
*/
|
||||
// TODO: FIXME: rename to SrsRtmpServer
|
||||
class SrsRtmp
|
||||
{
|
||||
private:
|
||||
SrsProtocol* protocol;
|
||||
ISrsProtocolReaderWriter* io;
|
||||
public:
|
||||
SrsRtmp(ISrsProtocolReaderWriter* skt);
|
||||
virtual ~SrsRtmp();
|
||||
public:
|
||||
virtual SrsProtocol* get_protocol();
|
||||
virtual void set_recv_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_recv_timeout();
|
||||
virtual void set_send_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_send_timeout();
|
||||
virtual int64_t get_recv_bytes();
|
||||
virtual int64_t get_send_bytes();
|
||||
virtual int get_recv_kbps();
|
||||
virtual int get_send_kbps();
|
||||
virtual int recv_message(SrsCommonMessage** pmsg);
|
||||
virtual int send_message(ISrsMessage* msg);
|
||||
public:
|
||||
virtual int handshake();
|
||||
virtual int connect_app(SrsRequest* req);
|
||||
virtual int set_window_ack_size(int ack_size);
|
||||
/**
|
||||
* @type: The sender can mark this message hard (0), soft (1), or dynamic (2)
|
||||
* using the Limit type field.
|
||||
*/
|
||||
virtual int set_peer_bandwidth(int bandwidth, int type);
|
||||
/**
|
||||
* @param server_ip the ip of server.
|
||||
*/
|
||||
virtual int response_connect_app(SrsRequest* req, const char* server_ip = NULL);
|
||||
virtual void response_connect_reject(SrsRequest* req, const char* desc);
|
||||
virtual int on_bw_done();
|
||||
/**
|
||||
* recv some message to identify the client.
|
||||
* @stream_id, client will createStream to play or publish by flash,
|
||||
* the stream_id used to response the createStream request.
|
||||
* @type, output the client type.
|
||||
*/
|
||||
virtual int identify_client(int stream_id, SrsClientType& type, std::string& stream_name);
|
||||
/**
|
||||
* set the chunk size when client type identified.
|
||||
*/
|
||||
virtual int set_chunk_size(int chunk_size);
|
||||
/**
|
||||
* when client type is play, response with packets:
|
||||
* StreamBegin,
|
||||
* onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start).,
|
||||
* |RtmpSampleAccess(false, false),
|
||||
* onStatus(NetStream.Data.Start).
|
||||
*/
|
||||
virtual int start_play(int stream_id);
|
||||
/**
|
||||
* when client(type is play) send pause message,
|
||||
* if is_pause, response the following packets:
|
||||
* onStatus(NetStream.Pause.Notify)
|
||||
* StreamEOF
|
||||
* if not is_pause, response the following packets:
|
||||
* onStatus(NetStream.Unpause.Notify)
|
||||
* StreamBegin
|
||||
*/
|
||||
virtual int on_play_client_pause(int stream_id, bool is_pause);
|
||||
/**
|
||||
* when client type is publish, response with packets:
|
||||
* releaseStream response
|
||||
* FCPublish
|
||||
* FCPublish response
|
||||
* createStream response
|
||||
* onFCPublish(NetStream.Publish.Start)
|
||||
* onStatus(NetStream.Publish.Start)
|
||||
*/
|
||||
virtual int start_fmle_publish(int stream_id);
|
||||
/**
|
||||
* process the FMLE unpublish event.
|
||||
* @unpublish_tid the unpublish request transaction id.
|
||||
*/
|
||||
virtual int fmle_unpublish(int stream_id, double unpublish_tid);
|
||||
/**
|
||||
* when client type is publish, response with packets:
|
||||
* onStatus(NetStream.Publish.Start)
|
||||
*/
|
||||
virtual int start_flash_publish(int stream_id);
|
||||
private:
|
||||
virtual int identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsClientType& type, std::string& stream_name);
|
||||
virtual int identify_fmle_publish_client(SrsFMLEStartPacket* req, SrsClientType& type, std::string& stream_name);
|
||||
virtual int identify_flash_publish_client(SrsPublishPacket* req, SrsClientType& type, std::string& stream_name);
|
||||
private:
|
||||
virtual int identify_play_client(SrsPlayPacket* req, SrsClientType& type, std::string& stream_name);
|
||||
};
|
||||
|
||||
#endif
|
3376
trunk/src/rtmp/srs_protocol_rtmp_stack.cpp
Normal file
3376
trunk/src/rtmp/srs_protocol_rtmp_stack.cpp
Normal file
File diff suppressed because it is too large
Load diff
1268
trunk/src/rtmp/srs_protocol_rtmp_stack.hpp
Normal file
1268
trunk/src/rtmp/srs_protocol_rtmp_stack.hpp
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue