mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
convert format to unix
This commit is contained in:
parent
145eb7bf29
commit
2c4c91d821
42 changed files with 12527 additions and 12527 deletions
|
@ -1,45 +1,45 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
static int64_t _srs_system_time_us_cache = 0;
|
static int64_t _srs_system_time_us_cache = 0;
|
||||||
|
|
||||||
int64_t srs_get_system_time_ms()
|
int64_t srs_get_system_time_ms()
|
||||||
{
|
{
|
||||||
return _srs_system_time_us_cache / 1000;
|
return _srs_system_time_us_cache / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void srs_update_system_time_ms()
|
void srs_update_system_time_ms()
|
||||||
{
|
{
|
||||||
timeval now;
|
timeval now;
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
// we must convert the tv_sec/tv_usec to int64_t.
|
// we must convert the tv_sec/tv_usec to int64_t.
|
||||||
_srs_system_time_us_cache = now.tv_sec * 1000 * 1000 + now.tv_usec;
|
_srs_system_time_us_cache = now.tv_sec * 1000 * 1000 + now.tv_usec;
|
||||||
|
|
||||||
_srs_system_time_us_cache = srs_max(0, _srs_system_time_us_cache);
|
_srs_system_time_us_cache = srs_max(0, _srs_system_time_us_cache);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,90 +1,90 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_HPP
|
#ifndef SRS_CORE_HPP
|
||||||
#define SRS_CORE_HPP
|
#define SRS_CORE_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the core provides the common defined macros, utilities,
|
* the core provides the common defined macros, utilities,
|
||||||
* user must include the srs_core.hpp before any header, or maybe
|
* user must include the srs_core.hpp before any header, or maybe
|
||||||
* build failed.
|
* build failed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// for int64_t print using PRId64 format.
|
// for int64_t print using PRId64 format.
|
||||||
#ifndef __STDC_FORMAT_MACROS
|
#ifndef __STDC_FORMAT_MACROS
|
||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
#endif
|
#endif
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#define srs_assert(expression) assert(expression)
|
#define srs_assert(expression) assert(expression)
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
// free the p and set to NULL.
|
// free the p and set to NULL.
|
||||||
// p must be a T*.
|
// p must be a T*.
|
||||||
#define srs_freep(p) \
|
#define srs_freep(p) \
|
||||||
if (p) { \
|
if (p) { \
|
||||||
delete p; \
|
delete p; \
|
||||||
p = NULL; \
|
p = NULL; \
|
||||||
} \
|
} \
|
||||||
(void)0
|
(void)0
|
||||||
// free the p which represents a array
|
// free the p which represents a array
|
||||||
#define srs_freepa(p) \
|
#define srs_freepa(p) \
|
||||||
if (p) { \
|
if (p) { \
|
||||||
delete[] p; \
|
delete[] p; \
|
||||||
p = NULL; \
|
p = NULL; \
|
||||||
} \
|
} \
|
||||||
(void)0
|
(void)0
|
||||||
|
|
||||||
// current release version
|
// current release version
|
||||||
#define RTMP_SIG_SRS_VERSION "0.4.0"
|
#define RTMP_SIG_SRS_VERSION "0.4.0"
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "srs"
|
#define RTMP_SIG_SRS_KEY "srs"
|
||||||
#define RTMP_SIG_SRS_ROLE "origin server"
|
#define RTMP_SIG_SRS_ROLE "origin server"
|
||||||
#define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)"
|
#define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)"
|
||||||
#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT
|
#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT
|
||||||
#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server"
|
#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server"
|
||||||
#define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin"
|
#define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin"
|
||||||
#define RTMP_SIG_SRS_EMAIL "winterserver@126.com"
|
#define RTMP_SIG_SRS_EMAIL "winterserver@126.com"
|
||||||
#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)"
|
#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)"
|
||||||
#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013 winlin"
|
#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013 winlin"
|
||||||
|
|
||||||
// compare
|
// compare
|
||||||
#define srs_min(a, b) (((a) < (b))? (a) : (b))
|
#define srs_min(a, b) (((a) < (b))? (a) : (b))
|
||||||
#define srs_max(a, b) (((a) < (b))? (b) : (a))
|
#define srs_max(a, b) (((a) < (b))? (b) : (a))
|
||||||
|
|
||||||
// get current system time in ms, use cache to avoid performance problem
|
// get current system time in ms, use cache to avoid performance problem
|
||||||
extern int64_t srs_get_system_time_ms();
|
extern int64_t srs_get_system_time_ms();
|
||||||
// the deamon st-thread will update it.
|
// the deamon st-thread will update it.
|
||||||
extern void srs_update_system_time_ms();
|
extern void srs_update_system_time_ms();
|
||||||
|
|
||||||
// signal defines.
|
// signal defines.
|
||||||
#define SIGNAL_RELOAD SIGHUP
|
#define SIGNAL_RELOAD SIGHUP
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,319 +1,319 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_AMF0_HPP
|
#ifndef SRS_CORE_AMF0_HPP
|
||||||
#define SRS_CORE_AMF0_HPP
|
#define SRS_CORE_AMF0_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_amf0.hpp>
|
#include <srs_core_amf0.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class SrsStream;
|
class SrsStream;
|
||||||
class SrsAmf0Object;
|
class SrsAmf0Object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* any amf0 value.
|
* any amf0 value.
|
||||||
* 2.1 Types Overview
|
* 2.1 Types Overview
|
||||||
* value-type = number-type | boolean-type | string-type | object-type
|
* value-type = number-type | boolean-type | string-type | object-type
|
||||||
* | null-marker | undefined-marker | reference-type | ecma-array-type
|
* | null-marker | undefined-marker | reference-type | ecma-array-type
|
||||||
* | strict-array-type | date-type | long-string-type | xml-document-type
|
* | strict-array-type | date-type | long-string-type | xml-document-type
|
||||||
* | typed-object-type
|
* | typed-object-type
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0Any
|
struct SrsAmf0Any
|
||||||
{
|
{
|
||||||
char marker;
|
char marker;
|
||||||
|
|
||||||
SrsAmf0Any();
|
SrsAmf0Any();
|
||||||
virtual ~SrsAmf0Any();
|
virtual ~SrsAmf0Any();
|
||||||
|
|
||||||
virtual bool is_string();
|
virtual bool is_string();
|
||||||
virtual bool is_boolean();
|
virtual bool is_boolean();
|
||||||
virtual bool is_number();
|
virtual bool is_number();
|
||||||
virtual bool is_null();
|
virtual bool is_null();
|
||||||
virtual bool is_undefined();
|
virtual bool is_undefined();
|
||||||
virtual bool is_object();
|
virtual bool is_object();
|
||||||
virtual bool is_object_eof();
|
virtual bool is_object_eof();
|
||||||
virtual bool is_ecma_array();
|
virtual bool is_ecma_array();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 string from stream.
|
* read amf0 string from stream.
|
||||||
* 2.4 String Type
|
* 2.4 String Type
|
||||||
* string-type = string-marker UTF-8
|
* string-type = string-marker UTF-8
|
||||||
* @return default value is empty string.
|
* @return default value is empty string.
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0String : public SrsAmf0Any
|
struct SrsAmf0String : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
SrsAmf0String(const char* _value = NULL);
|
SrsAmf0String(const char* _value = NULL);
|
||||||
virtual ~SrsAmf0String();
|
virtual ~SrsAmf0String();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 boolean from stream.
|
* read amf0 boolean from stream.
|
||||||
* 2.4 String Type
|
* 2.4 String Type
|
||||||
* boolean-type = boolean-marker U8
|
* boolean-type = boolean-marker U8
|
||||||
* 0 is false, <> 0 is true
|
* 0 is false, <> 0 is true
|
||||||
* @return default value is false.
|
* @return default value is false.
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0Boolean : public SrsAmf0Any
|
struct SrsAmf0Boolean : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
bool value;
|
bool value;
|
||||||
|
|
||||||
SrsAmf0Boolean(bool _value = false);
|
SrsAmf0Boolean(bool _value = false);
|
||||||
virtual ~SrsAmf0Boolean();
|
virtual ~SrsAmf0Boolean();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 number from stream.
|
* read amf0 number from stream.
|
||||||
* 2.2 Number Type
|
* 2.2 Number Type
|
||||||
* number-type = number-marker DOUBLE
|
* number-type = number-marker DOUBLE
|
||||||
* @return default value is 0.
|
* @return default value is 0.
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0Number : public SrsAmf0Any
|
struct SrsAmf0Number : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
|
|
||||||
SrsAmf0Number(double _value = 0.0);
|
SrsAmf0Number(double _value = 0.0);
|
||||||
virtual ~SrsAmf0Number();
|
virtual ~SrsAmf0Number();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 null from stream.
|
* read amf0 null from stream.
|
||||||
* 2.7 null Type
|
* 2.7 null Type
|
||||||
* null-type = null-marker
|
* null-type = null-marker
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0Null : public SrsAmf0Any
|
struct SrsAmf0Null : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
SrsAmf0Null();
|
SrsAmf0Null();
|
||||||
virtual ~SrsAmf0Null();
|
virtual ~SrsAmf0Null();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 undefined from stream.
|
* read amf0 undefined from stream.
|
||||||
* 2.8 undefined Type
|
* 2.8 undefined Type
|
||||||
* undefined-type = undefined-marker
|
* undefined-type = undefined-marker
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0Undefined : public SrsAmf0Any
|
struct SrsAmf0Undefined : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
SrsAmf0Undefined();
|
SrsAmf0Undefined();
|
||||||
virtual ~SrsAmf0Undefined();
|
virtual ~SrsAmf0Undefined();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2.11 Object End Type
|
* 2.11 Object End Type
|
||||||
* object-end-type = UTF-8-empty object-end-marker
|
* object-end-type = UTF-8-empty object-end-marker
|
||||||
* 0x00 0x00 0x09
|
* 0x00 0x00 0x09
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0ObjectEOF : public SrsAmf0Any
|
struct SrsAmf0ObjectEOF : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
int16_t utf8_empty;
|
int16_t utf8_empty;
|
||||||
|
|
||||||
SrsAmf0ObjectEOF();
|
SrsAmf0ObjectEOF();
|
||||||
virtual ~SrsAmf0ObjectEOF();
|
virtual ~SrsAmf0ObjectEOF();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* to ensure in inserted order.
|
* to ensure in inserted order.
|
||||||
* for the FMLE will crash when AMF0Object is not ordered by inserted,
|
* 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
|
* if ordered in map, the string compare order, the FMLE will creash when
|
||||||
* get the response of connect app.
|
* get the response of connect app.
|
||||||
*/
|
*/
|
||||||
struct SrsUnSortedHashtable
|
struct SrsUnSortedHashtable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef std::pair<std::string, SrsAmf0Any*> SrsObjectPropertyType;
|
typedef std::pair<std::string, SrsAmf0Any*> SrsObjectPropertyType;
|
||||||
std::vector<SrsObjectPropertyType> properties;
|
std::vector<SrsObjectPropertyType> properties;
|
||||||
public:
|
public:
|
||||||
SrsUnSortedHashtable();
|
SrsUnSortedHashtable();
|
||||||
virtual ~SrsUnSortedHashtable();
|
virtual ~SrsUnSortedHashtable();
|
||||||
|
|
||||||
virtual int size();
|
virtual int size();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
virtual std::string key_at(int index);
|
virtual std::string key_at(int index);
|
||||||
virtual SrsAmf0Any* value_at(int index);
|
virtual SrsAmf0Any* value_at(int index);
|
||||||
virtual void set(std::string key, SrsAmf0Any* value);
|
virtual void set(std::string key, SrsAmf0Any* value);
|
||||||
|
|
||||||
virtual SrsAmf0Any* get_property(std::string name);
|
virtual SrsAmf0Any* get_property(std::string name);
|
||||||
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
||||||
virtual SrsAmf0Any* ensure_property_number(std::string name);
|
virtual SrsAmf0Any* ensure_property_number(std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2.5 Object Type
|
* 2.5 Object Type
|
||||||
* anonymous-object-type = object-marker *(object-property)
|
* anonymous-object-type = object-marker *(object-property)
|
||||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
||||||
*/
|
*/
|
||||||
struct SrsAmf0Object : public SrsAmf0Any
|
struct SrsAmf0Object : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsUnSortedHashtable properties;
|
SrsUnSortedHashtable properties;
|
||||||
public:
|
public:
|
||||||
SrsAmf0ObjectEOF eof;
|
SrsAmf0ObjectEOF eof;
|
||||||
|
|
||||||
SrsAmf0Object();
|
SrsAmf0Object();
|
||||||
virtual ~SrsAmf0Object();
|
virtual ~SrsAmf0Object();
|
||||||
|
|
||||||
virtual int size();
|
virtual int size();
|
||||||
virtual std::string key_at(int index);
|
virtual std::string key_at(int index);
|
||||||
virtual SrsAmf0Any* value_at(int index);
|
virtual SrsAmf0Any* value_at(int index);
|
||||||
virtual void set(std::string key, SrsAmf0Any* value);
|
virtual void set(std::string key, SrsAmf0Any* value);
|
||||||
|
|
||||||
virtual SrsAmf0Any* get_property(std::string name);
|
virtual SrsAmf0Any* get_property(std::string name);
|
||||||
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
||||||
virtual SrsAmf0Any* ensure_property_number(std::string name);
|
virtual SrsAmf0Any* ensure_property_number(std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2.10 ECMA Array Type
|
* 2.10 ECMA Array Type
|
||||||
* ecma-array-type = associative-count *(object-property)
|
* ecma-array-type = associative-count *(object-property)
|
||||||
* associative-count = U32
|
* associative-count = U32
|
||||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
||||||
*/
|
*/
|
||||||
struct SrsASrsAmf0EcmaArray : public SrsAmf0Any
|
struct SrsASrsAmf0EcmaArray : public SrsAmf0Any
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsUnSortedHashtable properties;
|
SrsUnSortedHashtable properties;
|
||||||
public:
|
public:
|
||||||
int32_t count;
|
int32_t count;
|
||||||
SrsAmf0ObjectEOF eof;
|
SrsAmf0ObjectEOF eof;
|
||||||
|
|
||||||
SrsASrsAmf0EcmaArray();
|
SrsASrsAmf0EcmaArray();
|
||||||
virtual ~SrsASrsAmf0EcmaArray();
|
virtual ~SrsASrsAmf0EcmaArray();
|
||||||
|
|
||||||
virtual int size();
|
virtual int size();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
virtual std::string key_at(int index);
|
virtual std::string key_at(int index);
|
||||||
virtual SrsAmf0Any* value_at(int index);
|
virtual SrsAmf0Any* value_at(int index);
|
||||||
virtual void set(std::string key, SrsAmf0Any* value);
|
virtual void set(std::string key, SrsAmf0Any* value);
|
||||||
|
|
||||||
virtual SrsAmf0Any* get_property(std::string name);
|
virtual SrsAmf0Any* get_property(std::string name);
|
||||||
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
virtual SrsAmf0Any* ensure_property_string(std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 utf8 string from stream.
|
* read amf0 utf8 string from stream.
|
||||||
* 1.3.1 Strings and UTF-8
|
* 1.3.1 Strings and UTF-8
|
||||||
* UTF-8 = U16 *(UTF8-char)
|
* UTF-8 = U16 *(UTF8-char)
|
||||||
* UTF8-char = UTF8-1 | UTF8-2 | UTF8-3 | UTF8-4
|
* UTF8-char = UTF8-1 | UTF8-2 | UTF8-3 | UTF8-4
|
||||||
* UTF8-1 = %x00-7F
|
* UTF8-1 = %x00-7F
|
||||||
* @remark only support UTF8-1 char.
|
* @remark only support UTF8-1 char.
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_read_utf8(SrsStream* stream, std::string& value);
|
extern int srs_amf0_read_utf8(SrsStream* stream, std::string& value);
|
||||||
extern int srs_amf0_write_utf8(SrsStream* stream, std::string value);
|
extern int srs_amf0_write_utf8(SrsStream* stream, std::string value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 string from stream.
|
* read amf0 string from stream.
|
||||||
* 2.4 String Type
|
* 2.4 String Type
|
||||||
* string-type = string-marker UTF-8
|
* string-type = string-marker UTF-8
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_read_string(SrsStream* stream, std::string& value);
|
extern int srs_amf0_read_string(SrsStream* stream, std::string& value);
|
||||||
extern int srs_amf0_write_string(SrsStream* stream, std::string value);
|
extern int srs_amf0_write_string(SrsStream* stream, std::string value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 boolean from stream.
|
* read amf0 boolean from stream.
|
||||||
* 2.4 String Type
|
* 2.4 String Type
|
||||||
* boolean-type = boolean-marker U8
|
* boolean-type = boolean-marker U8
|
||||||
* 0 is false, <> 0 is true
|
* 0 is false, <> 0 is true
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_read_boolean(SrsStream* stream, bool& value);
|
extern int srs_amf0_read_boolean(SrsStream* stream, bool& value);
|
||||||
extern int srs_amf0_write_boolean(SrsStream* stream, bool value);
|
extern int srs_amf0_write_boolean(SrsStream* stream, bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 number from stream.
|
* read amf0 number from stream.
|
||||||
* 2.2 Number Type
|
* 2.2 Number Type
|
||||||
* number-type = number-marker DOUBLE
|
* number-type = number-marker DOUBLE
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_read_number(SrsStream* stream, double& value);
|
extern int srs_amf0_read_number(SrsStream* stream, double& value);
|
||||||
extern int srs_amf0_write_number(SrsStream* stream, double value);
|
extern int srs_amf0_write_number(SrsStream* stream, double value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 null from stream.
|
* read amf0 null from stream.
|
||||||
* 2.7 null Type
|
* 2.7 null Type
|
||||||
* null-type = null-marker
|
* null-type = null-marker
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_read_null(SrsStream* stream);
|
extern int srs_amf0_read_null(SrsStream* stream);
|
||||||
extern int srs_amf0_write_null(SrsStream* stream);
|
extern int srs_amf0_write_null(SrsStream* stream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 undefined from stream.
|
* read amf0 undefined from stream.
|
||||||
* 2.8 undefined Type
|
* 2.8 undefined Type
|
||||||
* undefined-type = undefined-marker
|
* undefined-type = undefined-marker
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_read_undefined(SrsStream* stream);
|
extern int srs_amf0_read_undefined(SrsStream* stream);
|
||||||
extern int srs_amf0_write_undefined(SrsStream* stream);
|
extern int srs_amf0_write_undefined(SrsStream* stream);
|
||||||
|
|
||||||
extern int srs_amf0_read_any(SrsStream* stream, SrsAmf0Any*& value);
|
extern int srs_amf0_read_any(SrsStream* stream, SrsAmf0Any*& value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 object from stream.
|
* read amf0 object from stream.
|
||||||
* 2.5 Object Type
|
* 2.5 Object Type
|
||||||
* anonymous-object-type = object-marker *(object-property)
|
* anonymous-object-type = object-marker *(object-property)
|
||||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
* 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_read_object(SrsStream* stream, SrsAmf0Object*& value);
|
||||||
extern int srs_amf0_write_object(SrsStream* stream, SrsAmf0Object* value);
|
extern int srs_amf0_write_object(SrsStream* stream, SrsAmf0Object* value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read amf0 object from stream.
|
* read amf0 object from stream.
|
||||||
* 2.10 ECMA Array Type
|
* 2.10 ECMA Array Type
|
||||||
* ecma-array-type = associative-count *(object-property)
|
* ecma-array-type = associative-count *(object-property)
|
||||||
* associative-count = U32
|
* associative-count = U32
|
||||||
* object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker)
|
* 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_read_ecma_array(SrsStream* stream, SrsASrsAmf0EcmaArray*& value);
|
||||||
extern int srs_amf0_write_ecma_array(SrsStream* stream, SrsASrsAmf0EcmaArray* value);
|
extern int srs_amf0_write_ecma_array(SrsStream* stream, SrsASrsAmf0EcmaArray* value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get amf0 objects size.
|
* get amf0 objects size.
|
||||||
*/
|
*/
|
||||||
extern int srs_amf0_get_utf8_size(std::string value);
|
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_string_size(std::string value);
|
||||||
extern int srs_amf0_get_number_size();
|
extern int srs_amf0_get_number_size();
|
||||||
extern int srs_amf0_get_null_size();
|
extern int srs_amf0_get_null_size();
|
||||||
extern int srs_amf0_get_undefined_size();
|
extern int srs_amf0_get_undefined_size();
|
||||||
extern int srs_amf0_get_boolean_size();
|
extern int srs_amf0_get_boolean_size();
|
||||||
extern int srs_amf0_get_object_size(SrsAmf0Object* obj);
|
extern int srs_amf0_get_object_size(SrsAmf0Object* obj);
|
||||||
extern int srs_amf0_get_ecma_array_size(SrsASrsAmf0EcmaArray* arr);
|
extern int srs_amf0_get_ecma_array_size(SrsASrsAmf0EcmaArray* arr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert the any to specified object.
|
* convert the any to specified object.
|
||||||
* @return T*, the converted object. never NULL.
|
* @return T*, the converted object. never NULL.
|
||||||
* @remark, user must ensure the current object type,
|
* @remark, user must ensure the current object type,
|
||||||
* or the covert will cause assert failed.
|
* or the covert will cause assert failed.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
T* srs_amf0_convert(SrsAmf0Any* any)
|
T* srs_amf0_convert(SrsAmf0Any* any)
|
||||||
{
|
{
|
||||||
T* p = dynamic_cast<T*>(any);
|
T* p = dynamic_cast<T*>(any);
|
||||||
srs_assert(p != NULL);
|
srs_assert(p != NULL);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,24 +1,24 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
|
|
|
@ -1,71 +1,71 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_AUTO_FREE_HPP
|
#ifndef SRS_CORE_AUTO_FREE_HPP
|
||||||
#define SRS_CORE_AUTO_FREE_HPP
|
#define SRS_CORE_AUTO_FREE_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* auto free the instance in the current scope.
|
* auto free the instance in the current scope.
|
||||||
*/
|
*/
|
||||||
#define SrsAutoFree(className, instance, is_array) \
|
#define SrsAutoFree(className, instance, is_array) \
|
||||||
__SrsAutoFree<className> _auto_free_##instance(&instance, is_array)
|
__SrsAutoFree<className> _auto_free_##instance(&instance, is_array)
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class __SrsAutoFree
|
class __SrsAutoFree
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
T** ptr;
|
T** ptr;
|
||||||
bool is_array;
|
bool is_array;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* auto delete the ptr.
|
* auto delete the ptr.
|
||||||
* @is_array a bool value indicates whether the ptr is a array.
|
* @is_array a bool value indicates whether the ptr is a array.
|
||||||
*/
|
*/
|
||||||
__SrsAutoFree(T** _ptr, bool _is_array){
|
__SrsAutoFree(T** _ptr, bool _is_array){
|
||||||
ptr = _ptr;
|
ptr = _ptr;
|
||||||
is_array = _is_array;
|
is_array = _is_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~__SrsAutoFree(){
|
virtual ~__SrsAutoFree(){
|
||||||
if (ptr == NULL || *ptr == NULL) {
|
if (ptr == NULL || *ptr == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array) {
|
if (is_array) {
|
||||||
delete[] *ptr;
|
delete[] *ptr;
|
||||||
} else {
|
} else {
|
||||||
delete *ptr;
|
delete *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ptr = NULL;
|
*ptr = NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,84 +1,84 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_buffer.hpp>
|
#include <srs_core_buffer.hpp>
|
||||||
|
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_socket.hpp>
|
#include <srs_core_socket.hpp>
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
|
|
||||||
#define SOCKET_READ_SIZE 4096
|
#define SOCKET_READ_SIZE 4096
|
||||||
|
|
||||||
SrsBuffer::SrsBuffer()
|
SrsBuffer::SrsBuffer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsBuffer::~SrsBuffer()
|
SrsBuffer::~SrsBuffer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsBuffer::size()
|
int SrsBuffer::size()
|
||||||
{
|
{
|
||||||
return (int)data.size();
|
return (int)data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
char* SrsBuffer::bytes()
|
char* SrsBuffer::bytes()
|
||||||
{
|
{
|
||||||
return &data.at(0);
|
return &data.at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsBuffer::erase(int size)
|
void SrsBuffer::erase(int size)
|
||||||
{
|
{
|
||||||
data.erase(data.begin(), data.begin() + size);
|
data.erase(data.begin(), data.begin() + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsBuffer::append(char* bytes, int size)
|
void SrsBuffer::append(char* bytes, int size)
|
||||||
{
|
{
|
||||||
data.insert(data.end(), bytes, bytes + size);
|
data.insert(data.end(), bytes, bytes + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsBuffer::ensure_buffer_bytes(SrsSocket* skt, int required_size)
|
int SrsBuffer::ensure_buffer_bytes(SrsSocket* skt, int required_size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (required_size < 0) {
|
if (required_size < 0) {
|
||||||
ret = ERROR_SYSTEM_SIZE_NEGATIVE;
|
ret = ERROR_SYSTEM_SIZE_NEGATIVE;
|
||||||
srs_error("size is negative. size=%d, ret=%d", required_size, ret);
|
srs_error("size is negative. size=%d, ret=%d", required_size, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (size() < required_size) {
|
while (size() < required_size) {
|
||||||
char buffer[SOCKET_READ_SIZE];
|
char buffer[SOCKET_READ_SIZE];
|
||||||
|
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
if ((ret = skt->read(buffer, SOCKET_READ_SIZE, &nread)) != ERROR_SUCCESS) {
|
if ((ret = skt->read(buffer, SOCKET_READ_SIZE, &nread)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert((int)nread > 0);
|
srs_assert((int)nread > 0);
|
||||||
append(buffer, (int)nread);
|
append(buffer, (int)nread);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,59 +1,59 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_BUFFER_HPP
|
#ifndef SRS_CORE_BUFFER_HPP
|
||||||
#define SRS_CORE_BUFFER_HPP
|
#define SRS_CORE_BUFFER_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_buffer.hpp>
|
#include <srs_core_buffer.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class SrsSocket;
|
class SrsSocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the buffer provices bytes cache for protocol. generally,
|
* the buffer provices bytes cache for protocol. generally,
|
||||||
* protocol recv data from socket, put into buffer, decode to RTMP message.
|
* protocol recv data from socket, put into buffer, decode to RTMP message.
|
||||||
* protocol encode RTMP message to bytes, put into buffer, send to socket.
|
* protocol encode RTMP message to bytes, put into buffer, send to socket.
|
||||||
*/
|
*/
|
||||||
class SrsBuffer
|
class SrsBuffer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<char> data;
|
std::vector<char> data;
|
||||||
public:
|
public:
|
||||||
SrsBuffer();
|
SrsBuffer();
|
||||||
virtual ~SrsBuffer();
|
virtual ~SrsBuffer();
|
||||||
public:
|
public:
|
||||||
virtual int size();
|
virtual int size();
|
||||||
virtual char* bytes();
|
virtual char* bytes();
|
||||||
virtual void erase(int size);
|
virtual void erase(int size);
|
||||||
private:
|
private:
|
||||||
virtual void append(char* bytes, int size);
|
virtual void append(char* bytes, int size);
|
||||||
public:
|
public:
|
||||||
virtual int ensure_buffer_bytes(SrsSocket* skt, int required_size);
|
virtual int ensure_buffer_bytes(SrsSocket* skt, int required_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,488 +1,488 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_client.hpp>
|
#include <srs_core_client.hpp>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_rtmp.hpp>
|
#include <srs_core_rtmp.hpp>
|
||||||
#include <srs_core_protocol.hpp>
|
#include <srs_core_protocol.hpp>
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
#include <srs_core_source.hpp>
|
#include <srs_core_source.hpp>
|
||||||
#include <srs_core_server.hpp>
|
#include <srs_core_server.hpp>
|
||||||
#include <srs_core_pithy_print.hpp>
|
#include <srs_core_pithy_print.hpp>
|
||||||
#include <srs_core_config.hpp>
|
#include <srs_core_config.hpp>
|
||||||
#include <srs_core_refer.hpp>
|
#include <srs_core_refer.hpp>
|
||||||
|
|
||||||
#define SRS_PULSE_TIMEOUT_MS 100
|
#define SRS_PULSE_TIMEOUT_MS 100
|
||||||
#define SRS_SEND_TIMEOUT_MS 5000000L
|
#define SRS_SEND_TIMEOUT_MS 5000000L
|
||||||
#define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS
|
#define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS
|
||||||
|
|
||||||
SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
|
SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
|
||||||
: SrsConnection(srs_server, client_stfd)
|
: SrsConnection(srs_server, client_stfd)
|
||||||
{
|
{
|
||||||
ip = NULL;
|
ip = NULL;
|
||||||
req = new SrsRequest();
|
req = new SrsRequest();
|
||||||
res = new SrsResponse();
|
res = new SrsResponse();
|
||||||
rtmp = new SrsRtmp(client_stfd);
|
rtmp = new SrsRtmp(client_stfd);
|
||||||
refer = new SrsRefer();
|
refer = new SrsRefer();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsClient::~SrsClient()
|
SrsClient::~SrsClient()
|
||||||
{
|
{
|
||||||
srs_freepa(ip);
|
srs_freepa(ip);
|
||||||
srs_freep(req);
|
srs_freep(req);
|
||||||
srs_freep(res);
|
srs_freep(res);
|
||||||
srs_freep(rtmp);
|
srs_freep(rtmp);
|
||||||
srs_freep(refer);
|
srs_freep(refer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsClient::do_cycle()
|
int SrsClient::do_cycle()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if ((ret = get_peer_ip()) != ERROR_SUCCESS) {
|
if ((ret = get_peer_ip()) != ERROR_SUCCESS) {
|
||||||
srs_error("get peer ip failed. ret=%d", ret);
|
srs_error("get peer ip failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_trace("get peer ip success. ip=%s, send_to=%"PRId64", recv_to=%"PRId64"",
|
srs_trace("get peer ip success. ip=%s, send_to=%"PRId64", recv_to=%"PRId64"",
|
||||||
ip, SRS_SEND_TIMEOUT_MS, SRS_RECV_TIMEOUT_MS);
|
ip, SRS_SEND_TIMEOUT_MS, SRS_RECV_TIMEOUT_MS);
|
||||||
|
|
||||||
rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_MS * 1000);
|
rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_MS * 1000);
|
||||||
rtmp->set_send_timeout(SRS_SEND_TIMEOUT_MS * 1000);
|
rtmp->set_send_timeout(SRS_SEND_TIMEOUT_MS * 1000);
|
||||||
|
|
||||||
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
|
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
|
||||||
srs_error("rtmp handshake failed. ret=%d", ret);
|
srs_error("rtmp handshake failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("rtmp handshake success");
|
srs_verbose("rtmp handshake success");
|
||||||
|
|
||||||
if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) {
|
||||||
srs_error("rtmp connect vhost/app failed. ret=%d", ret);
|
srs_error("rtmp connect vhost/app failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("rtmp connect app success");
|
srs_verbose("rtmp connect app success");
|
||||||
|
|
||||||
if ((ret = check_vhost()) != ERROR_SUCCESS) {
|
if ((ret = check_vhost()) != ERROR_SUCCESS) {
|
||||||
srs_error("check vhost failed. ret=%d", ret);
|
srs_error("check vhost failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("check vhost success.");
|
srs_verbose("check vhost success.");
|
||||||
|
|
||||||
srs_trace("rtmp connect app success. "
|
srs_trace("rtmp connect app success. "
|
||||||
"tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s",
|
"tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s",
|
||||||
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
|
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
|
||||||
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),
|
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),
|
||||||
req->app.c_str());
|
req->app.c_str());
|
||||||
|
|
||||||
if ((ret = refer->check(req->pageUrl, config->get_refer(req->vhost))) != ERROR_SUCCESS) {
|
if ((ret = refer->check(req->pageUrl, config->get_refer(req->vhost))) != ERROR_SUCCESS) {
|
||||||
srs_error("check refer failed. ret=%d", ret);
|
srs_error("check refer failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("check refer success.");
|
srs_verbose("check refer success.");
|
||||||
|
|
||||||
if ((ret = rtmp->set_window_ack_size(2.5 * 1000 * 1000)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->set_window_ack_size(2.5 * 1000 * 1000)) != ERROR_SUCCESS) {
|
||||||
srs_error("set window acknowledgement size failed. ret=%d", ret);
|
srs_error("set window acknowledgement size failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("set window acknowledgement size success");
|
srs_verbose("set window acknowledgement size success");
|
||||||
|
|
||||||
if ((ret = rtmp->set_peer_bandwidth(2.5 * 1000 * 1000, 2)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->set_peer_bandwidth(2.5 * 1000 * 1000, 2)) != ERROR_SUCCESS) {
|
||||||
srs_error("set peer bandwidth failed. ret=%d", ret);
|
srs_error("set peer bandwidth failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("set peer bandwidth success");
|
srs_verbose("set peer bandwidth success");
|
||||||
|
|
||||||
if ((ret = rtmp->response_connect_app(req)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->response_connect_app(req)) != ERROR_SUCCESS) {
|
||||||
srs_error("response connect app failed. ret=%d", ret);
|
srs_error("response connect app failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("response connect app success");
|
srs_verbose("response connect app success");
|
||||||
|
|
||||||
if ((ret = rtmp->on_bw_done()) != ERROR_SUCCESS) {
|
if ((ret = rtmp->on_bw_done()) != ERROR_SUCCESS) {
|
||||||
srs_error("on_bw_done failed. ret=%d", ret);
|
srs_error("on_bw_done failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("on_bw_done success");
|
srs_verbose("on_bw_done success");
|
||||||
|
|
||||||
SrsClientType type;
|
SrsClientType type;
|
||||||
if ((ret = rtmp->identify_client(res->stream_id, type, req->stream)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->identify_client(res->stream_id, type, req->stream)) != ERROR_SUCCESS) {
|
||||||
srs_error("identify client failed. ret=%d", ret);
|
srs_error("identify client failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
req->strip();
|
req->strip();
|
||||||
srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str());
|
srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str());
|
||||||
|
|
||||||
int chunk_size = 4096;
|
int chunk_size = 4096;
|
||||||
SrsConfDirective* conf = config->get_chunk_size();
|
SrsConfDirective* conf = config->get_chunk_size();
|
||||||
if (conf && !conf->arg0().empty()) {
|
if (conf && !conf->arg0().empty()) {
|
||||||
chunk_size = ::atoi(conf->arg0().c_str());
|
chunk_size = ::atoi(conf->arg0().c_str());
|
||||||
}
|
}
|
||||||
if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {
|
||||||
srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);
|
srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_trace("set chunk_size=%d success", chunk_size);
|
srs_trace("set chunk_size=%d success", chunk_size);
|
||||||
|
|
||||||
// find a source to publish.
|
// find a source to publish.
|
||||||
SrsSource* source = SrsSource::find(req->get_stream_url());
|
SrsSource* source = SrsSource::find(req->get_stream_url());
|
||||||
srs_assert(source != NULL);
|
srs_assert(source != NULL);
|
||||||
|
|
||||||
bool enabled_cache = true;
|
bool enabled_cache = true;
|
||||||
conf = config->get_gop_cache(req->vhost);
|
conf = config->get_gop_cache(req->vhost);
|
||||||
if (conf && conf->arg0() == "off") {
|
if (conf && conf->arg0() == "off") {
|
||||||
enabled_cache = false;
|
enabled_cache = false;
|
||||||
}
|
}
|
||||||
source->set_cache(enabled_cache);
|
source->set_cache(enabled_cache);
|
||||||
|
|
||||||
srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
|
srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SrsClientPlay: {
|
case SrsClientPlay: {
|
||||||
srs_verbose("start to play stream %s.", req->stream.c_str());
|
srs_verbose("start to play stream %s.", req->stream.c_str());
|
||||||
|
|
||||||
if ((ret = rtmp->start_play(res->stream_id)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->start_play(res->stream_id)) != ERROR_SUCCESS) {
|
||||||
srs_error("start to play stream failed. ret=%d", ret);
|
srs_error("start to play stream failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("start to play stream %s success", req->stream.c_str());
|
srs_info("start to play stream %s success", req->stream.c_str());
|
||||||
return playing(source);
|
return playing(source);
|
||||||
}
|
}
|
||||||
case SrsClientFMLEPublish: {
|
case SrsClientFMLEPublish: {
|
||||||
srs_verbose("FMLE start to publish stream %s.", req->stream.c_str());
|
srs_verbose("FMLE start to publish stream %s.", req->stream.c_str());
|
||||||
|
|
||||||
if ((ret = rtmp->start_fmle_publish(res->stream_id)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->start_fmle_publish(res->stream_id)) != ERROR_SUCCESS) {
|
||||||
srs_error("start to publish stream failed. ret=%d", ret);
|
srs_error("start to publish stream failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("start to publish stream %s success", req->stream.c_str());
|
srs_info("start to publish stream %s success", req->stream.c_str());
|
||||||
ret = publish(source, true);
|
ret = publish(source, true);
|
||||||
source->on_unpublish();
|
source->on_unpublish();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
case SrsClientFlashPublish: {
|
case SrsClientFlashPublish: {
|
||||||
srs_verbose("flash start to publish stream %s.", req->stream.c_str());
|
srs_verbose("flash start to publish stream %s.", req->stream.c_str());
|
||||||
|
|
||||||
if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) {
|
||||||
srs_error("flash start to publish stream failed. ret=%d", ret);
|
srs_error("flash start to publish stream failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("flash start to publish stream %s success", req->stream.c_str());
|
srs_info("flash start to publish stream %s success", req->stream.c_str());
|
||||||
ret = publish(source, false);
|
ret = publish(source, false);
|
||||||
source->on_unpublish();
|
source->on_unpublish();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
ret = ERROR_SYSTEM_CLIENT_INVALID;
|
ret = ERROR_SYSTEM_CLIENT_INVALID;
|
||||||
srs_info("invalid client type=%d. ret=%d", type, ret);
|
srs_info("invalid client type=%d. ret=%d", type, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsClient::check_vhost()
|
int SrsClient::check_vhost()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
srs_assert(req != NULL);
|
srs_assert(req != NULL);
|
||||||
|
|
||||||
SrsConfDirective* vhost = config->get_vhost(req->vhost);
|
SrsConfDirective* vhost = config->get_vhost(req->vhost);
|
||||||
if (vhost == NULL) {
|
if (vhost == NULL) {
|
||||||
ret = ERROR_RTMP_VHOST_NOT_FOUND;
|
ret = ERROR_RTMP_VHOST_NOT_FOUND;
|
||||||
srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret);
|
srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsConfDirective* conf = NULL;
|
SrsConfDirective* conf = NULL;
|
||||||
if ((conf = vhost->get(RTMP_VHOST_ENABLED)) != NULL && conf->arg0() != "on") {
|
if ((conf = vhost->get(RTMP_VHOST_ENABLED)) != NULL && conf->arg0() != "on") {
|
||||||
ret = ERROR_RTMP_VHOST_NOT_FOUND;
|
ret = ERROR_RTMP_VHOST_NOT_FOUND;
|
||||||
srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
|
srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->vhost != vhost->arg0()) {
|
if (req->vhost != vhost->arg0()) {
|
||||||
srs_trace("vhost change from %s to %s", req->vhost.c_str(), vhost->arg0().c_str());
|
srs_trace("vhost change from %s to %s", req->vhost.c_str(), vhost->arg0().c_str());
|
||||||
req->vhost = vhost->arg0();
|
req->vhost = vhost->arg0();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsClient::playing(SrsSource* source)
|
int SrsClient::playing(SrsSource* source)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if ((ret = refer->check(req->pageUrl, config->get_refer_play(req->vhost))) != ERROR_SUCCESS) {
|
if ((ret = refer->check(req->pageUrl, config->get_refer_play(req->vhost))) != ERROR_SUCCESS) {
|
||||||
srs_error("check play_refer failed. ret=%d", ret);
|
srs_error("check play_refer failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("check play_refer success.");
|
srs_verbose("check play_refer success.");
|
||||||
|
|
||||||
SrsConsumer* consumer = NULL;
|
SrsConsumer* consumer = NULL;
|
||||||
if ((ret = source->create_consumer(consumer)) != ERROR_SUCCESS) {
|
if ((ret = source->create_consumer(consumer)) != ERROR_SUCCESS) {
|
||||||
srs_error("create consumer failed. ret=%d", ret);
|
srs_error("create consumer failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(consumer != NULL);
|
srs_assert(consumer != NULL);
|
||||||
SrsAutoFree(SrsConsumer, consumer, false);
|
SrsAutoFree(SrsConsumer, consumer, false);
|
||||||
srs_verbose("consumer created success.");
|
srs_verbose("consumer created success.");
|
||||||
|
|
||||||
rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000);
|
rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000);
|
||||||
|
|
||||||
SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);
|
SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
pithy_print.elapse(SRS_PULSE_TIMEOUT_MS);
|
pithy_print.elapse(SRS_PULSE_TIMEOUT_MS);
|
||||||
|
|
||||||
// switch to other st-threads.
|
// switch to other st-threads.
|
||||||
st_usleep(0);
|
st_usleep(0);
|
||||||
|
|
||||||
// read from client.
|
// read from client.
|
||||||
int ctl_msg_ret = ERROR_SUCCESS;
|
int ctl_msg_ret = ERROR_SUCCESS;
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
ctl_msg_ret = ret = rtmp->recv_message(&msg);
|
ctl_msg_ret = ret = rtmp->recv_message(&msg);
|
||||||
|
|
||||||
srs_verbose("play loop recv message. ret=%d", ret);
|
srs_verbose("play loop recv message. ret=%d", ret);
|
||||||
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
|
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
|
||||||
srs_error("recv client control message failed. ret=%d", ret);
|
srs_error("recv client control message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {
|
if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {
|
||||||
srs_error("process play control message failed. ret=%d", ret);
|
srs_error("process play control message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get messages from consumer.
|
// get messages from consumer.
|
||||||
SrsSharedPtrMessage** msgs = NULL;
|
SrsSharedPtrMessage** msgs = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if ((ret = consumer->get_packets(0, msgs, count)) != ERROR_SUCCESS) {
|
if ((ret = consumer->get_packets(0, msgs, count)) != ERROR_SUCCESS) {
|
||||||
srs_error("get messages from consumer failed. ret=%d", ret);
|
srs_error("get messages from consumer failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reportable
|
// reportable
|
||||||
if (pithy_print.can_print()) {
|
if (pithy_print.can_print()) {
|
||||||
srs_trace("-> clock=%u, time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
|
srs_trace("-> clock=%u, time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
|
||||||
(int)(srs_get_system_time_ms()/1000), pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
|
(int)(srs_get_system_time_ms()/1000), pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
srs_verbose("no packets in queue.");
|
srs_verbose("no packets in queue.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsSharedPtrMessage*, msgs, true);
|
SrsAutoFree(SrsSharedPtrMessage*, msgs, true);
|
||||||
|
|
||||||
// sendout messages
|
// sendout messages
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
SrsSharedPtrMessage* msg = msgs[i];
|
SrsSharedPtrMessage* msg = msgs[i];
|
||||||
|
|
||||||
// the send_message will free the msg,
|
// the send_message will free the msg,
|
||||||
// so set the msgs[i] to NULL.
|
// so set the msgs[i] to NULL.
|
||||||
msgs[i] = NULL;
|
msgs[i] = NULL;
|
||||||
|
|
||||||
if ((ret = rtmp->send_message(msg)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->send_message(msg)) != ERROR_SUCCESS) {
|
||||||
srs_error("send message to client failed. ret=%d", ret);
|
srs_error("send message to client failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsClient::publish(SrsSource* source, bool is_fmle)
|
int SrsClient::publish(SrsSource* source, bool is_fmle)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if ((ret = refer->check(req->pageUrl, config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {
|
if ((ret = refer->check(req->pageUrl, config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {
|
||||||
srs_error("check publish_refer failed. ret=%d", ret);
|
srs_error("check publish_refer failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("check publish_refer success.");
|
srs_verbose("check publish_refer success.");
|
||||||
|
|
||||||
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
|
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// switch to other st-threads.
|
// switch to other st-threads.
|
||||||
st_usleep(0);
|
st_usleep(0);
|
||||||
|
|
||||||
SrsCommonMessage* msg = NULL;
|
SrsCommonMessage* msg = NULL;
|
||||||
if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
|
||||||
srs_error("recv identify client message failed. ret=%d", ret);
|
srs_error("recv identify client message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsAutoFree(SrsCommonMessage, msg, false);
|
SrsAutoFree(SrsCommonMessage, msg, false);
|
||||||
|
|
||||||
pithy_print.set_age(msg->header.timestamp);
|
pithy_print.set_age(msg->header.timestamp);
|
||||||
|
|
||||||
// reportable
|
// reportable
|
||||||
if (pithy_print.can_print()) {
|
if (pithy_print.can_print()) {
|
||||||
srs_trace("<- clock=%u, time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
|
srs_trace("<- clock=%u, time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
|
||||||
(int)(srs_get_system_time_ms()/1000), pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
|
(int)(srs_get_system_time_ms()/1000), pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
|
||||||
}
|
}
|
||||||
|
|
||||||
// process audio packet
|
// process audio packet
|
||||||
if (msg->header.is_audio() && ((ret = source->on_audio(msg)) != ERROR_SUCCESS)) {
|
if (msg->header.is_audio() && ((ret = source->on_audio(msg)) != ERROR_SUCCESS)) {
|
||||||
srs_error("process audio message failed. ret=%d", ret);
|
srs_error("process audio message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// process video packet
|
// process video packet
|
||||||
if (msg->header.is_video() && ((ret = source->on_video(msg)) != ERROR_SUCCESS)) {
|
if (msg->header.is_video() && ((ret = source->on_video(msg)) != ERROR_SUCCESS)) {
|
||||||
srs_error("process video message failed. ret=%d", ret);
|
srs_error("process video message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process onMetaData
|
// process onMetaData
|
||||||
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
|
if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
|
||||||
if ((ret = msg->decode_packet()) != ERROR_SUCCESS) {
|
if ((ret = msg->decode_packet()) != ERROR_SUCCESS) {
|
||||||
srs_error("decode onMetaData message failed. ret=%d", ret);
|
srs_error("decode onMetaData message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPacket* pkt = msg->get_packet();
|
SrsPacket* pkt = msg->get_packet();
|
||||||
if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) {
|
if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) {
|
||||||
SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt);
|
SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt);
|
||||||
if ((ret = source->on_meta_data(msg, metadata)) != ERROR_SUCCESS) {
|
if ((ret = source->on_meta_data(msg, metadata)) != ERROR_SUCCESS) {
|
||||||
srs_error("process onMetaData message failed. ret=%d", ret);
|
srs_error("process onMetaData message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_trace("process onMetaData message success.");
|
srs_trace("process onMetaData message success.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_trace("ignore AMF0/AMF3 data message.");
|
srs_trace("ignore AMF0/AMF3 data message.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process UnPublish event.
|
// process UnPublish event.
|
||||||
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
|
if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
|
||||||
if ((ret = msg->decode_packet()) != ERROR_SUCCESS) {
|
if ((ret = msg->decode_packet()) != ERROR_SUCCESS) {
|
||||||
srs_error("decode unpublish message failed. ret=%d", ret);
|
srs_error("decode unpublish message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// flash unpublish.
|
// flash unpublish.
|
||||||
if (!is_fmle) {
|
if (!is_fmle) {
|
||||||
srs_trace("flash publish finished.");
|
srs_trace("flash publish finished.");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPacket* pkt = msg->get_packet();
|
SrsPacket* pkt = msg->get_packet();
|
||||||
if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
|
if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
|
||||||
SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);
|
SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);
|
||||||
return rtmp->fmle_unpublish(res->stream_id, unpublish->transaction_id);
|
return rtmp->fmle_unpublish(res->stream_id, unpublish->transaction_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_trace("ignore AMF0/AMF3 command message.");
|
srs_trace("ignore AMF0/AMF3 command message.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsClient::get_peer_ip()
|
int SrsClient::get_peer_ip()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
int fd = st_netfd_fileno(stfd);
|
int fd = st_netfd_fileno(stfd);
|
||||||
|
|
||||||
// discovery client information
|
// discovery client information
|
||||||
sockaddr_in addr;
|
sockaddr_in addr;
|
||||||
socklen_t addrlen = sizeof(addr);
|
socklen_t addrlen = sizeof(addr);
|
||||||
if (getpeername(fd, (sockaddr*)&addr, &addrlen) == -1) {
|
if (getpeername(fd, (sockaddr*)&addr, &addrlen) == -1) {
|
||||||
ret = ERROR_SOCKET_GET_PEER_NAME;
|
ret = ERROR_SOCKET_GET_PEER_NAME;
|
||||||
srs_error("discovery client information failed. ret=%d", ret);
|
srs_error("discovery client information failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("get peer name success.");
|
srs_verbose("get peer name success.");
|
||||||
|
|
||||||
// ip v4 or v6
|
// ip v4 or v6
|
||||||
char buf[INET6_ADDRSTRLEN];
|
char buf[INET6_ADDRSTRLEN];
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
if ((inet_ntop(addr.sin_family, &addr.sin_addr, buf, sizeof(buf))) == NULL) {
|
if ((inet_ntop(addr.sin_family, &addr.sin_addr, buf, sizeof(buf))) == NULL) {
|
||||||
ret = ERROR_SOCKET_GET_PEER_IP;
|
ret = ERROR_SOCKET_GET_PEER_IP;
|
||||||
srs_error("convert client information failed. ret=%d", ret);
|
srs_error("convert client information failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("get peer ip of client ip=%s, fd=%d", buf, fd);
|
srs_verbose("get peer ip of client ip=%s, fd=%d", buf, fd);
|
||||||
|
|
||||||
ip = new char[strlen(buf) + 1];
|
ip = new char[strlen(buf) + 1];
|
||||||
strcpy(ip, buf);
|
strcpy(ip, buf);
|
||||||
|
|
||||||
srs_verbose("get peer ip success. ip=%s, fd=%d", ip, fd);
|
srs_verbose("get peer ip success. ip=%s, fd=%d", ip, fd);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsClient::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg)
|
int SrsClient::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
srs_verbose("ignore all empty message.");
|
srs_verbose("ignore all empty message.");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsCommonMessage, msg, false);
|
SrsAutoFree(SrsCommonMessage, msg, false);
|
||||||
|
|
||||||
if (!msg->header.is_amf0_command() && !msg->header.is_amf3_command()) {
|
if (!msg->header.is_amf0_command() && !msg->header.is_amf3_command()) {
|
||||||
srs_info("ignore all message except amf0/amf3 command.");
|
srs_info("ignore all message except amf0/amf3 command.");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = msg->decode_packet()) != ERROR_SUCCESS) {
|
if ((ret = msg->decode_packet()) != ERROR_SUCCESS) {
|
||||||
srs_error("decode the amf0/amf3 command packet failed. ret=%d", ret);
|
srs_error("decode the amf0/amf3 command packet failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("decode the amf0/amf3 command packet success.");
|
srs_info("decode the amf0/amf3 command packet success.");
|
||||||
|
|
||||||
SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(msg->get_packet());
|
SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(msg->get_packet());
|
||||||
if (!pause) {
|
if (!pause) {
|
||||||
srs_info("ignore all amf0/amf3 command except pause.");
|
srs_info("ignore all amf0/amf3 command except pause.");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = rtmp->on_play_client_pause(res->stream_id, pause->is_pause)) != ERROR_SUCCESS) {
|
if ((ret = rtmp->on_play_client_pause(res->stream_id, pause->is_pause)) != ERROR_SUCCESS) {
|
||||||
srs_error("rtmp process play client pause failed. ret=%d", ret);
|
srs_error("rtmp process play client pause failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = consumer->on_play_client_pause(pause->is_pause)) != ERROR_SUCCESS) {
|
if ((ret = consumer->on_play_client_pause(pause->is_pause)) != ERROR_SUCCESS) {
|
||||||
srs_error("consumer process play client pause failed. ret=%d", ret);
|
srs_error("consumer process play client pause failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_info("process pause success, is_pause=%d, time=%d.", pause->is_pause, pause->time_ms);
|
srs_info("process pause success, is_pause=%d, time=%d.", pause->is_pause, pause->time_ms);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,67 +1,67 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_CLIENT_HPP
|
#ifndef SRS_CORE_CLIENT_HPP
|
||||||
#define SRS_CORE_CLIENT_HPP
|
#define SRS_CORE_CLIENT_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_client.hpp>
|
#include <srs_core_client.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <srs_core_conn.hpp>
|
#include <srs_core_conn.hpp>
|
||||||
|
|
||||||
class SrsRtmp;
|
class SrsRtmp;
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
class SrsResponse;
|
class SrsResponse;
|
||||||
class SrsSource;
|
class SrsSource;
|
||||||
class SrsRefer;
|
class SrsRefer;
|
||||||
class SrsConsumer;
|
class SrsConsumer;
|
||||||
class SrsCommonMessage;
|
class SrsCommonMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the client provides the main logic control for RTMP clients.
|
* the client provides the main logic control for RTMP clients.
|
||||||
*/
|
*/
|
||||||
class SrsClient : public SrsConnection
|
class SrsClient : public SrsConnection
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
char* ip;
|
char* ip;
|
||||||
SrsRequest* req;
|
SrsRequest* req;
|
||||||
SrsResponse* res;
|
SrsResponse* res;
|
||||||
SrsRtmp* rtmp;
|
SrsRtmp* rtmp;
|
||||||
SrsRefer* refer;
|
SrsRefer* refer;
|
||||||
public:
|
public:
|
||||||
SrsClient(SrsServer* srs_server, st_netfd_t client_stfd);
|
SrsClient(SrsServer* srs_server, st_netfd_t client_stfd);
|
||||||
virtual ~SrsClient();
|
virtual ~SrsClient();
|
||||||
protected:
|
protected:
|
||||||
virtual int do_cycle();
|
virtual int do_cycle();
|
||||||
private:
|
private:
|
||||||
virtual int check_vhost();
|
virtual int check_vhost();
|
||||||
virtual int playing(SrsSource* source);
|
virtual int playing(SrsSource* source);
|
||||||
virtual int publish(SrsSource* source, bool is_fmle);
|
virtual int publish(SrsSource* source, bool is_fmle);
|
||||||
virtual int get_peer_ip();
|
virtual int get_peer_ip();
|
||||||
virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg);
|
virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,175 +1,175 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_codec.hpp>
|
#include <srs_core_codec.hpp>
|
||||||
|
|
||||||
SrsCodec::SrsCodec()
|
SrsCodec::SrsCodec()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsCodec::~SrsCodec()
|
SrsCodec::~SrsCodec()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsCodec::video_is_keyframe(int8_t* data, int size)
|
bool SrsCodec::video_is_keyframe(int8_t* data, int size)
|
||||||
{
|
{
|
||||||
// E.4.3.1 VIDEODATA
|
// E.4.3.1 VIDEODATA
|
||||||
// Frame Type UB [4]
|
// Frame Type UB [4]
|
||||||
// Type of video frame. The following values are defined:
|
// Type of video frame. The following values are defined:
|
||||||
// 1 = key frame (for AVC, a seekable frame)
|
// 1 = key frame (for AVC, a seekable frame)
|
||||||
// 2 = inter frame (for AVC, a non-seekable frame)
|
// 2 = inter frame (for AVC, a non-seekable frame)
|
||||||
// 3 = disposable inter frame (H.263 only)
|
// 3 = disposable inter frame (H.263 only)
|
||||||
// 4 = generated key frame (reserved for server use only)
|
// 4 = generated key frame (reserved for server use only)
|
||||||
// 5 = video info/command frame
|
// 5 = video info/command frame
|
||||||
//
|
//
|
||||||
// AVCPacketType IF CodecID == 7 UI8
|
// AVCPacketType IF CodecID == 7 UI8
|
||||||
// The following values are defined:
|
// The following values are defined:
|
||||||
// 0 = AVC sequence header
|
// 0 = AVC sequence header
|
||||||
// 1 = AVC NALU
|
// 1 = AVC NALU
|
||||||
// 2 = AVC end of sequence (lower level NALU sequence ender is
|
// 2 = AVC end of sequence (lower level NALU sequence ender is
|
||||||
// not required or supported)
|
// not required or supported)
|
||||||
|
|
||||||
// 2bytes required.
|
// 2bytes required.
|
||||||
if (size < 1) {
|
if (size < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char frame_type = *(char*)data;
|
char frame_type = *(char*)data;
|
||||||
frame_type = (frame_type >> 4) & 0x0F;
|
frame_type = (frame_type >> 4) & 0x0F;
|
||||||
|
|
||||||
return frame_type == 1;
|
return frame_type == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsCodec::video_is_sequence_header(int8_t* data, int size)
|
bool SrsCodec::video_is_sequence_header(int8_t* data, int size)
|
||||||
{
|
{
|
||||||
// E.4.3.1 VIDEODATA
|
// E.4.3.1 VIDEODATA
|
||||||
// Frame Type UB [4]
|
// Frame Type UB [4]
|
||||||
// Type of video frame. The following values are defined:
|
// Type of video frame. The following values are defined:
|
||||||
// 1 = key frame (for AVC, a seekable frame)
|
// 1 = key frame (for AVC, a seekable frame)
|
||||||
// 2 = inter frame (for AVC, a non-seekable frame)
|
// 2 = inter frame (for AVC, a non-seekable frame)
|
||||||
// 3 = disposable inter frame (H.263 only)
|
// 3 = disposable inter frame (H.263 only)
|
||||||
// 4 = generated key frame (reserved for server use only)
|
// 4 = generated key frame (reserved for server use only)
|
||||||
// 5 = video info/command frame
|
// 5 = video info/command frame
|
||||||
//
|
//
|
||||||
// AVCPacketType IF CodecID == 7 UI8
|
// AVCPacketType IF CodecID == 7 UI8
|
||||||
// The following values are defined:
|
// The following values are defined:
|
||||||
// 0 = AVC sequence header
|
// 0 = AVC sequence header
|
||||||
// 1 = AVC NALU
|
// 1 = AVC NALU
|
||||||
// 2 = AVC end of sequence (lower level NALU sequence ender is
|
// 2 = AVC end of sequence (lower level NALU sequence ender is
|
||||||
// not required or supported)
|
// not required or supported)
|
||||||
|
|
||||||
// sequence header only for h264
|
// sequence header only for h264
|
||||||
if (!video_is_h264(data, size)) {
|
if (!video_is_h264(data, size)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2bytes required.
|
// 2bytes required.
|
||||||
if (size < 2) {
|
if (size < 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char frame_type = *(char*)data;
|
char frame_type = *(char*)data;
|
||||||
frame_type = (frame_type >> 4) & 0x0F;
|
frame_type = (frame_type >> 4) & 0x0F;
|
||||||
|
|
||||||
char avc_packet_type = *(char*)(data + 1);
|
char avc_packet_type = *(char*)(data + 1);
|
||||||
|
|
||||||
return frame_type == 1 && avc_packet_type == 0;
|
return frame_type == 1 && avc_packet_type == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsCodec::audio_is_sequence_header(int8_t* data, int size)
|
bool SrsCodec::audio_is_sequence_header(int8_t* data, int size)
|
||||||
{
|
{
|
||||||
// AACPacketType IF SoundFormat == 10 UI8
|
// AACPacketType IF SoundFormat == 10 UI8
|
||||||
// The following values are defined:
|
// The following values are defined:
|
||||||
// 0 = AAC sequence header
|
// 0 = AAC sequence header
|
||||||
// 1 = AAC raw
|
// 1 = AAC raw
|
||||||
|
|
||||||
// sequence header only for aac
|
// sequence header only for aac
|
||||||
if (!audio_is_aac(data, size)) {
|
if (!audio_is_aac(data, size)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2bytes required.
|
// 2bytes required.
|
||||||
if (size < 2) {
|
if (size < 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char aac_packet_type = *(char*)(data + 1);
|
char aac_packet_type = *(char*)(data + 1);
|
||||||
|
|
||||||
return aac_packet_type == 0;
|
return aac_packet_type == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsCodec::video_is_h264(int8_t* data, int size)
|
bool SrsCodec::video_is_h264(int8_t* data, int size)
|
||||||
{
|
{
|
||||||
// E.4.3.1 VIDEODATA
|
// E.4.3.1 VIDEODATA
|
||||||
// CodecID UB [4]
|
// CodecID UB [4]
|
||||||
// Codec Identifier. The following values are defined:
|
// Codec Identifier. The following values are defined:
|
||||||
// 2 = Sorenson H.263
|
// 2 = Sorenson H.263
|
||||||
// 3 = Screen video
|
// 3 = Screen video
|
||||||
// 4 = On2 VP6
|
// 4 = On2 VP6
|
||||||
// 5 = On2 VP6 with alpha channel
|
// 5 = On2 VP6 with alpha channel
|
||||||
// 6 = Screen video version 2
|
// 6 = Screen video version 2
|
||||||
// 7 = AVC
|
// 7 = AVC
|
||||||
|
|
||||||
// 1bytes required.
|
// 1bytes required.
|
||||||
if (size < 1) {
|
if (size < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char codec_id = *(char*)data;
|
char codec_id = *(char*)data;
|
||||||
codec_id = codec_id & 0x0F;
|
codec_id = codec_id & 0x0F;
|
||||||
|
|
||||||
return codec_id == 7;
|
return codec_id == 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsCodec::audio_is_aac(int8_t* data, int size)
|
bool SrsCodec::audio_is_aac(int8_t* data, int size)
|
||||||
{
|
{
|
||||||
// SoundFormat UB [4]
|
// SoundFormat UB [4]
|
||||||
// Format of SoundData. The following values are defined:
|
// Format of SoundData. The following values are defined:
|
||||||
// 0 = Linear PCM, platform endian
|
// 0 = Linear PCM, platform endian
|
||||||
// 1 = ADPCM
|
// 1 = ADPCM
|
||||||
// 2 = MP3
|
// 2 = MP3
|
||||||
// 3 = Linear PCM, little endian
|
// 3 = Linear PCM, little endian
|
||||||
// 4 = Nellymoser 16 kHz mono
|
// 4 = Nellymoser 16 kHz mono
|
||||||
// 5 = Nellymoser 8 kHz mono
|
// 5 = Nellymoser 8 kHz mono
|
||||||
// 6 = Nellymoser
|
// 6 = Nellymoser
|
||||||
// 7 = G.711 A-law logarithmic PCM
|
// 7 = G.711 A-law logarithmic PCM
|
||||||
// 8 = G.711 mu-law logarithmic PCM
|
// 8 = G.711 mu-law logarithmic PCM
|
||||||
// 9 = reserved
|
// 9 = reserved
|
||||||
// 10 = AAC
|
// 10 = AAC
|
||||||
// 11 = Speex
|
// 11 = Speex
|
||||||
// 14 = MP3 8 kHz
|
// 14 = MP3 8 kHz
|
||||||
// 15 = Device-specific sound
|
// 15 = Device-specific sound
|
||||||
// Formats 7, 8, 14, and 15 are reserved.
|
// Formats 7, 8, 14, and 15 are reserved.
|
||||||
// AAC is supported in Flash Player 9,0,115,0 and higher.
|
// AAC is supported in Flash Player 9,0,115,0 and higher.
|
||||||
// Speex is supported in Flash Player 10 and higher.
|
// Speex is supported in Flash Player 10 and higher.
|
||||||
|
|
||||||
// 1bytes required.
|
// 1bytes required.
|
||||||
if (size < 1) {
|
if (size < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char sound_format = *(char*)data;
|
char sound_format = *(char*)data;
|
||||||
sound_format = (sound_format >> 4) & 0x0F;
|
sound_format = (sound_format >> 4) & 0x0F;
|
||||||
|
|
||||||
return sound_format == 10;
|
return sound_format == 10;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,65 +1,65 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_CODEC_HPP
|
#ifndef SRS_CORE_CODEC_HPP
|
||||||
#define SRS_CORE_CODEC_HPP
|
#define SRS_CORE_CODEC_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_codec.hpp>
|
#include <srs_core_codec.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annex E. The FLV File Format
|
* Annex E. The FLV File Format
|
||||||
*/
|
*/
|
||||||
class SrsCodec
|
class SrsCodec
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsCodec();
|
SrsCodec();
|
||||||
virtual ~SrsCodec();
|
virtual ~SrsCodec();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* only check the frame_type, not check the codec type.
|
* only check the frame_type, not check the codec type.
|
||||||
*/
|
*/
|
||||||
virtual bool video_is_keyframe(int8_t* data, int size);
|
virtual bool video_is_keyframe(int8_t* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec h264, keyframe, sequence header
|
* check codec h264, keyframe, sequence header
|
||||||
*/
|
*/
|
||||||
virtual bool video_is_sequence_header(int8_t* data, int size);
|
virtual bool video_is_sequence_header(int8_t* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec aac, sequence header
|
* check codec aac, sequence header
|
||||||
*/
|
*/
|
||||||
virtual bool audio_is_sequence_header(int8_t* data, int size);
|
virtual bool audio_is_sequence_header(int8_t* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec h264.
|
* check codec h264.
|
||||||
*/
|
*/
|
||||||
virtual bool video_is_h264(int8_t* data, int size);
|
virtual bool video_is_h264(int8_t* data, int size);
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* check codec aac.
|
* check codec aac.
|
||||||
*/
|
*/
|
||||||
virtual bool audio_is_aac(int8_t* data, int size);
|
virtual bool audio_is_aac(int8_t* data, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,133 +1,133 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_CONIFG_HPP
|
#ifndef SRS_CORE_CONIFG_HPP
|
||||||
#define SRS_CORE_CONIFG_HPP
|
#define SRS_CORE_CONIFG_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_config.hpp>
|
#include <srs_core_config.hpp>
|
||||||
*/
|
*/
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <srs_core_reload.hpp>
|
#include <srs_core_reload.hpp>
|
||||||
|
|
||||||
// default vhost for rtmp
|
// default vhost for rtmp
|
||||||
#define RTMP_VHOST_DEFAULT "__defaultVhost__"
|
#define RTMP_VHOST_DEFAULT "__defaultVhost__"
|
||||||
|
|
||||||
// conf node: enabled.
|
// conf node: enabled.
|
||||||
#define RTMP_VHOST_ENABLED "enabled"
|
#define RTMP_VHOST_ENABLED "enabled"
|
||||||
|
|
||||||
class SrsFileBuffer
|
class SrsFileBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int fd;
|
int fd;
|
||||||
int line;
|
int line;
|
||||||
// start of buffer.
|
// start of buffer.
|
||||||
char* start;
|
char* start;
|
||||||
// end of buffer.
|
// end of buffer.
|
||||||
char* end;
|
char* end;
|
||||||
// current consumed position.
|
// current consumed position.
|
||||||
char* pos;
|
char* pos;
|
||||||
// last available position.
|
// last available position.
|
||||||
char* last;
|
char* last;
|
||||||
|
|
||||||
SrsFileBuffer();
|
SrsFileBuffer();
|
||||||
virtual ~SrsFileBuffer();
|
virtual ~SrsFileBuffer();
|
||||||
virtual int open(const char* filename);
|
virtual int open(const char* filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsConfDirective
|
class SrsConfDirective
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int conf_line;
|
int conf_line;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
std::vector<SrsConfDirective*> directives;
|
std::vector<SrsConfDirective*> directives;
|
||||||
public:
|
public:
|
||||||
SrsConfDirective();
|
SrsConfDirective();
|
||||||
virtual ~SrsConfDirective();
|
virtual ~SrsConfDirective();
|
||||||
std::string arg0();
|
std::string arg0();
|
||||||
std::string arg1();
|
std::string arg1();
|
||||||
std::string arg2();
|
std::string arg2();
|
||||||
SrsConfDirective* at(int index);
|
SrsConfDirective* at(int index);
|
||||||
SrsConfDirective* get(std::string _name);
|
SrsConfDirective* get(std::string _name);
|
||||||
public:
|
public:
|
||||||
virtual int parse(const char* filename);
|
virtual int parse(const char* filename);
|
||||||
public:
|
public:
|
||||||
enum SrsDirectiveType{parse_file, parse_block};
|
enum SrsDirectiveType{parse_file, parse_block};
|
||||||
virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type);
|
virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type);
|
||||||
virtual int read_token(SrsFileBuffer* buffer, std::vector<std::string>& args);
|
virtual int read_token(SrsFileBuffer* buffer, std::vector<std::string>& args);
|
||||||
virtual int refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart);
|
virtual int refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the config parser.
|
* the config parser.
|
||||||
* for the config supports reload, so never keep the reference cross st-thread,
|
* for the config supports reload, so never keep the reference cross st-thread,
|
||||||
* that is, never save the SrsConfDirective* get by any api of config,
|
* that is, never save the SrsConfDirective* get by any api of config,
|
||||||
* for it maybe free in the reload st-thread cycle.
|
* for it maybe free in the reload st-thread cycle.
|
||||||
* you can keep it before st-thread switch, or simply never keep it.
|
* you can keep it before st-thread switch, or simply never keep it.
|
||||||
*/
|
*/
|
||||||
class SrsConfig
|
class SrsConfig
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool show_help;
|
bool show_help;
|
||||||
bool show_version;
|
bool show_version;
|
||||||
std::string config_file;
|
std::string config_file;
|
||||||
SrsConfDirective* root;
|
SrsConfDirective* root;
|
||||||
std::vector<SrsReloadHandler*> subscribes;
|
std::vector<SrsReloadHandler*> subscribes;
|
||||||
public:
|
public:
|
||||||
SrsConfig();
|
SrsConfig();
|
||||||
virtual ~SrsConfig();
|
virtual ~SrsConfig();
|
||||||
public:
|
public:
|
||||||
virtual int reload();
|
virtual int reload();
|
||||||
virtual void subscribe(SrsReloadHandler* handler);
|
virtual void subscribe(SrsReloadHandler* handler);
|
||||||
virtual void unsubscribe(SrsReloadHandler* handler);
|
virtual void unsubscribe(SrsReloadHandler* handler);
|
||||||
public:
|
public:
|
||||||
virtual int parse_options(int argc, char** argv);
|
virtual int parse_options(int argc, char** argv);
|
||||||
virtual SrsConfDirective* get_vhost(std::string vhost);
|
virtual SrsConfDirective* get_vhost(std::string vhost);
|
||||||
virtual SrsConfDirective* get_gop_cache(std::string vhost);
|
virtual SrsConfDirective* get_gop_cache(std::string vhost);
|
||||||
virtual SrsConfDirective* get_refer(std::string vhost);
|
virtual SrsConfDirective* get_refer(std::string vhost);
|
||||||
virtual SrsConfDirective* get_refer_play(std::string vhost);
|
virtual SrsConfDirective* get_refer_play(std::string vhost);
|
||||||
virtual SrsConfDirective* get_refer_publish(std::string vhost);
|
virtual SrsConfDirective* get_refer_publish(std::string vhost);
|
||||||
virtual SrsConfDirective* get_listen();
|
virtual SrsConfDirective* get_listen();
|
||||||
virtual SrsConfDirective* get_chunk_size();
|
virtual SrsConfDirective* get_chunk_size();
|
||||||
virtual SrsConfDirective* get_pithy_print_publish();
|
virtual SrsConfDirective* get_pithy_print_publish();
|
||||||
virtual SrsConfDirective* get_pithy_print_play();
|
virtual SrsConfDirective* get_pithy_print_play();
|
||||||
private:
|
private:
|
||||||
virtual int parse_file(const char* filename);
|
virtual int parse_file(const char* filename);
|
||||||
virtual int parse_argv(int& i, char** argv);
|
virtual int parse_argv(int& i, char** argv);
|
||||||
virtual void print_help(char** argv);
|
virtual void print_help(char** argv);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deep compare directive.
|
* deep compare directive.
|
||||||
*/
|
*/
|
||||||
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b);
|
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b);
|
||||||
|
|
||||||
// global config
|
// global config
|
||||||
extern SrsConfig* config;
|
extern SrsConfig* config;
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,97 +1,97 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_conn.hpp>
|
#include <srs_core_conn.hpp>
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_server.hpp>
|
#include <srs_core_server.hpp>
|
||||||
|
|
||||||
SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd)
|
SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd)
|
||||||
{
|
{
|
||||||
server = srs_server;
|
server = srs_server;
|
||||||
stfd = client_stfd;
|
stfd = client_stfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsConnection::~SrsConnection()
|
SrsConnection::~SrsConnection()
|
||||||
{
|
{
|
||||||
if (stfd) {
|
if (stfd) {
|
||||||
int fd = st_netfd_fileno(stfd);
|
int fd = st_netfd_fileno(stfd);
|
||||||
st_netfd_close(stfd);
|
st_netfd_close(stfd);
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
|
|
||||||
// st does not close it sometimes,
|
// st does not close it sometimes,
|
||||||
// close it manually.
|
// close it manually.
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConnection::start()
|
int SrsConnection::start()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (st_thread_create(cycle_thread, this, 0, 0) == NULL) {
|
if (st_thread_create(cycle_thread, this, 0, 0) == NULL) {
|
||||||
ret = ERROR_ST_CREATE_CYCLE_THREAD;
|
ret = ERROR_ST_CREATE_CYCLE_THREAD;
|
||||||
srs_error("st_thread_create conn cycle thread error. ret=%d", ret);
|
srs_error("st_thread_create conn cycle thread error. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("create st conn cycle thread success.");
|
srs_verbose("create st conn cycle thread success.");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsConnection::cycle()
|
void SrsConnection::cycle()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
log_context->generate_id();
|
log_context->generate_id();
|
||||||
ret = do_cycle();
|
ret = do_cycle();
|
||||||
|
|
||||||
// if socket io error, set to closed.
|
// if socket io error, set to closed.
|
||||||
if (ret == ERROR_SOCKET_READ || ret == ERROR_SOCKET_READ_FULLY || ret == ERROR_SOCKET_WRITE) {
|
if (ret == ERROR_SOCKET_READ || ret == ERROR_SOCKET_READ_FULLY || ret == ERROR_SOCKET_WRITE) {
|
||||||
ret = ERROR_SOCKET_CLOSED;
|
ret = ERROR_SOCKET_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// success.
|
// success.
|
||||||
if (ret == ERROR_SUCCESS) {
|
if (ret == ERROR_SUCCESS) {
|
||||||
srs_trace("client process normally finished. ret=%d", ret);
|
srs_trace("client process normally finished. ret=%d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
// client close peer.
|
// client close peer.
|
||||||
if (ret == ERROR_SOCKET_CLOSED) {
|
if (ret == ERROR_SOCKET_CLOSED) {
|
||||||
srs_trace("client disconnect peer. ret=%d", ret);
|
srs_trace("client disconnect peer. ret=%d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
server->remove(this);
|
server->remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SrsConnection::cycle_thread(void* arg)
|
void* SrsConnection::cycle_thread(void* arg)
|
||||||
{
|
{
|
||||||
SrsConnection* conn = (SrsConnection*)arg;
|
SrsConnection* conn = (SrsConnection*)arg;
|
||||||
srs_assert(conn != NULL);
|
srs_assert(conn != NULL);
|
||||||
|
|
||||||
conn->cycle();
|
conn->cycle();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,53 +1,53 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_CONN_HPP
|
#ifndef SRS_CORE_CONN_HPP
|
||||||
#define SRS_CORE_CONN_HPP
|
#define SRS_CORE_CONN_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_conn.hpp>
|
#include <srs_core_conn.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <st.h>
|
#include <st.h>
|
||||||
|
|
||||||
class SrsServer;
|
class SrsServer;
|
||||||
class SrsConnection
|
class SrsConnection
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
SrsServer* server;
|
SrsServer* server;
|
||||||
st_netfd_t stfd;
|
st_netfd_t stfd;
|
||||||
public:
|
public:
|
||||||
SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd);
|
SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd);
|
||||||
virtual ~SrsConnection();
|
virtual ~SrsConnection();
|
||||||
public:
|
public:
|
||||||
virtual int start();
|
virtual int start();
|
||||||
protected:
|
protected:
|
||||||
virtual int do_cycle() = 0;
|
virtual int do_cycle() = 0;
|
||||||
private:
|
private:
|
||||||
virtual void cycle();
|
virtual void cycle();
|
||||||
static void* cycle_thread(void* arg);
|
static void* cycle_thread(void* arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,24 +1,24 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
|
|
|
@ -1,110 +1,110 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_ERROR_HPP
|
#ifndef SRS_CORE_ERROR_HPP
|
||||||
#define SRS_CORE_ERROR_HPP
|
#define SRS_CORE_ERROR_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#define ERROR_SUCCESS 0
|
#define ERROR_SUCCESS 0
|
||||||
|
|
||||||
#define ERROR_ST_SET_EPOLL 100
|
#define ERROR_ST_SET_EPOLL 100
|
||||||
#define ERROR_ST_INITIALIZE 101
|
#define ERROR_ST_INITIALIZE 101
|
||||||
#define ERROR_ST_OPEN_SOCKET 102
|
#define ERROR_ST_OPEN_SOCKET 102
|
||||||
#define ERROR_ST_CREATE_LISTEN_THREAD 103
|
#define ERROR_ST_CREATE_LISTEN_THREAD 103
|
||||||
#define ERROR_ST_CREATE_CYCLE_THREAD 104
|
#define ERROR_ST_CREATE_CYCLE_THREAD 104
|
||||||
|
|
||||||
#define ERROR_SOCKET_CREATE 200
|
#define ERROR_SOCKET_CREATE 200
|
||||||
#define ERROR_SOCKET_SETREUSE 201
|
#define ERROR_SOCKET_SETREUSE 201
|
||||||
#define ERROR_SOCKET_BIND 202
|
#define ERROR_SOCKET_BIND 202
|
||||||
#define ERROR_SOCKET_LISTEN 203
|
#define ERROR_SOCKET_LISTEN 203
|
||||||
#define ERROR_SOCKET_CLOSED 204
|
#define ERROR_SOCKET_CLOSED 204
|
||||||
#define ERROR_SOCKET_GET_PEER_NAME 205
|
#define ERROR_SOCKET_GET_PEER_NAME 205
|
||||||
#define ERROR_SOCKET_GET_PEER_IP 206
|
#define ERROR_SOCKET_GET_PEER_IP 206
|
||||||
#define ERROR_SOCKET_READ 207
|
#define ERROR_SOCKET_READ 207
|
||||||
#define ERROR_SOCKET_READ_FULLY 208
|
#define ERROR_SOCKET_READ_FULLY 208
|
||||||
#define ERROR_SOCKET_WRITE 209
|
#define ERROR_SOCKET_WRITE 209
|
||||||
#define ERROR_SOCKET_WAIT 210
|
#define ERROR_SOCKET_WAIT 210
|
||||||
#define ERROR_SOCKET_TIMEOUT 211
|
#define ERROR_SOCKET_TIMEOUT 211
|
||||||
|
|
||||||
#define ERROR_RTMP_PLAIN_REQUIRED 300
|
#define ERROR_RTMP_PLAIN_REQUIRED 300
|
||||||
#define ERROR_RTMP_CHUNK_START 301
|
#define ERROR_RTMP_CHUNK_START 301
|
||||||
#define ERROR_RTMP_MSG_INVLIAD_SIZE 302
|
#define ERROR_RTMP_MSG_INVLIAD_SIZE 302
|
||||||
#define ERROR_RTMP_AMF0_DECODE 303
|
#define ERROR_RTMP_AMF0_DECODE 303
|
||||||
#define ERROR_RTMP_AMF0_INVALID 304
|
#define ERROR_RTMP_AMF0_INVALID 304
|
||||||
#define ERROR_RTMP_REQ_CONNECT 305
|
#define ERROR_RTMP_REQ_CONNECT 305
|
||||||
#define ERROR_RTMP_REQ_TCURL 306
|
#define ERROR_RTMP_REQ_TCURL 306
|
||||||
#define ERROR_RTMP_MESSAGE_DECODE 307
|
#define ERROR_RTMP_MESSAGE_DECODE 307
|
||||||
#define ERROR_RTMP_MESSAGE_ENCODE 308
|
#define ERROR_RTMP_MESSAGE_ENCODE 308
|
||||||
#define ERROR_RTMP_AMF0_ENCODE 309
|
#define ERROR_RTMP_AMF0_ENCODE 309
|
||||||
#define ERROR_RTMP_CHUNK_SIZE 310
|
#define ERROR_RTMP_CHUNK_SIZE 310
|
||||||
#define ERROR_RTMP_TRY_SIMPLE_HS 311
|
#define ERROR_RTMP_TRY_SIMPLE_HS 311
|
||||||
#define ERROR_RTMP_CH_SCHEMA 312
|
#define ERROR_RTMP_CH_SCHEMA 312
|
||||||
#define ERROR_RTMP_PACKET_SIZE 313
|
#define ERROR_RTMP_PACKET_SIZE 313
|
||||||
#define ERROR_RTMP_VHOST_NOT_FOUND 314
|
#define ERROR_RTMP_VHOST_NOT_FOUND 314
|
||||||
#define ERROR_RTMP_ACCESS_DENIED 315
|
#define ERROR_RTMP_ACCESS_DENIED 315
|
||||||
|
|
||||||
#define ERROR_SYSTEM_STREAM_INIT 400
|
#define ERROR_SYSTEM_STREAM_INIT 400
|
||||||
#define ERROR_SYSTEM_PACKET_INVALID 401
|
#define ERROR_SYSTEM_PACKET_INVALID 401
|
||||||
#define ERROR_SYSTEM_CLIENT_INVALID 402
|
#define ERROR_SYSTEM_CLIENT_INVALID 402
|
||||||
#define ERROR_SYSTEM_ASSERT_FAILED 403
|
#define ERROR_SYSTEM_ASSERT_FAILED 403
|
||||||
#define ERROR_SYSTEM_SIZE_NEGATIVE 404
|
#define ERROR_SYSTEM_SIZE_NEGATIVE 404
|
||||||
#define ERROR_SYSTEM_CONFIG_INVALID 405
|
#define ERROR_SYSTEM_CONFIG_INVALID 405
|
||||||
#define ERROR_SYSTEM_CONFIG_DIRECTIVE 406
|
#define ERROR_SYSTEM_CONFIG_DIRECTIVE 406
|
||||||
#define ERROR_SYSTEM_CONFIG_BLOCK_START 407
|
#define ERROR_SYSTEM_CONFIG_BLOCK_START 407
|
||||||
#define ERROR_SYSTEM_CONFIG_BLOCK_END 408
|
#define ERROR_SYSTEM_CONFIG_BLOCK_END 408
|
||||||
#define ERROR_SYSTEM_CONFIG_EOF 409
|
#define ERROR_SYSTEM_CONFIG_EOF 409
|
||||||
|
|
||||||
// see librtmp.
|
// see librtmp.
|
||||||
// failed when open ssl create the dh
|
// failed when open ssl create the dh
|
||||||
#define ERROR_OpenSslCreateDH 500
|
#define ERROR_OpenSslCreateDH 500
|
||||||
// failed when open ssl create the Private key.
|
// failed when open ssl create the Private key.
|
||||||
#define ERROR_OpenSslCreateP 501
|
#define ERROR_OpenSslCreateP 501
|
||||||
// when open ssl create G.
|
// when open ssl create G.
|
||||||
#define ERROR_OpenSslCreateG 502
|
#define ERROR_OpenSslCreateG 502
|
||||||
// when open ssl parse P1024
|
// when open ssl parse P1024
|
||||||
#define ERROR_OpenSslParseP1024 503
|
#define ERROR_OpenSslParseP1024 503
|
||||||
// when open ssl set G
|
// when open ssl set G
|
||||||
#define ERROR_OpenSslSetG 504
|
#define ERROR_OpenSslSetG 504
|
||||||
// when open ssl generate DHKeys
|
// when open ssl generate DHKeys
|
||||||
#define ERROR_OpenSslGenerateDHKeys 505
|
#define ERROR_OpenSslGenerateDHKeys 505
|
||||||
// when open ssl share key already computed.
|
// when open ssl share key already computed.
|
||||||
#define ERROR_OpenSslShareKeyComputed 506
|
#define ERROR_OpenSslShareKeyComputed 506
|
||||||
// when open ssl get shared key size.
|
// when open ssl get shared key size.
|
||||||
#define ERROR_OpenSslGetSharedKeySize 507
|
#define ERROR_OpenSslGetSharedKeySize 507
|
||||||
// when open ssl get peer public key.
|
// when open ssl get peer public key.
|
||||||
#define ERROR_OpenSslGetPeerPublicKey 508
|
#define ERROR_OpenSslGetPeerPublicKey 508
|
||||||
// when open ssl compute shared key.
|
// when open ssl compute shared key.
|
||||||
#define ERROR_OpenSslComputeSharedKey 509
|
#define ERROR_OpenSslComputeSharedKey 509
|
||||||
// when open ssl is invalid DH state.
|
// when open ssl is invalid DH state.
|
||||||
#define ERROR_OpenSslInvalidDHState 510
|
#define ERROR_OpenSslInvalidDHState 510
|
||||||
// when open ssl copy key
|
// when open ssl copy key
|
||||||
#define ERROR_OpenSslCopyKey 511
|
#define ERROR_OpenSslCopyKey 511
|
||||||
// when open ssl sha256 digest key invalid size.
|
// when open ssl sha256 digest key invalid size.
|
||||||
#define ERROR_OpenSslSha256DigestSize 512
|
#define ERROR_OpenSslSha256DigestSize 512
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,76 +1,76 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_HANDSHKAE_HPP
|
#ifndef SRS_CORE_HANDSHKAE_HPP
|
||||||
#define SRS_CORE_HANDSHKAE_HPP
|
#define SRS_CORE_HANDSHKAE_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_complex_handshake.hpp>
|
#include <srs_core_complex_handshake.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
class SrsSocket;
|
class SrsSocket;
|
||||||
class SrsComplexHandshake;
|
class SrsComplexHandshake;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try complex handshake, if failed, fallback to simple handshake.
|
* try complex handshake, if failed, fallback to simple handshake.
|
||||||
*/
|
*/
|
||||||
class SrsSimpleHandshake
|
class SrsSimpleHandshake
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsSimpleHandshake();
|
SrsSimpleHandshake();
|
||||||
virtual ~SrsSimpleHandshake();
|
virtual ~SrsSimpleHandshake();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* simple handshake.
|
* simple handshake.
|
||||||
* @param complex_hs, try complex handshake first,
|
* @param complex_hs, try complex handshake first,
|
||||||
* if failed, rollback to simple handshake.
|
* if failed, rollback to simple handshake.
|
||||||
*/
|
*/
|
||||||
virtual int handshake(SrsSocket& skt, SrsComplexHandshake& complex_hs);
|
virtual int handshake(SrsSocket& skt, SrsComplexHandshake& complex_hs);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rtmp complex handshake,
|
* rtmp complex handshake,
|
||||||
* @see also crtmp(crtmpserver) or librtmp,
|
* @see also crtmp(crtmpserver) or librtmp,
|
||||||
* @see also: http://blog.csdn.net/win_lin/article/details/13006803
|
* @see also: http://blog.csdn.net/win_lin/article/details/13006803
|
||||||
*/
|
*/
|
||||||
class SrsComplexHandshake
|
class SrsComplexHandshake
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsComplexHandshake();
|
SrsComplexHandshake();
|
||||||
virtual ~SrsComplexHandshake();
|
virtual ~SrsComplexHandshake();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* complex hanshake.
|
* complex hanshake.
|
||||||
* @_c1, size of c1 must be 1536.
|
* @_c1, size of c1 must be 1536.
|
||||||
* @remark, user must free the c1.
|
* @remark, user must free the c1.
|
||||||
* @return user must:
|
* @return user must:
|
||||||
* continue connect app if success,
|
* continue connect app if success,
|
||||||
* try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS,
|
* try simple handshake if error is ERROR_RTMP_TRY_SIMPLE_HS,
|
||||||
* otherwise, disconnect
|
* otherwise, disconnect
|
||||||
*/
|
*/
|
||||||
virtual int handshake(SrsSocket& skt, char* _c1);
|
virtual int handshake(SrsSocket& skt, char* _c1);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,126 +1,126 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <st.h>
|
#include <st.h>
|
||||||
|
|
||||||
ILogContext::ILogContext()
|
ILogContext::ILogContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ILogContext::~ILogContext()
|
ILogContext::~ILogContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class LogContext : public ILogContext
|
class LogContext : public ILogContext
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class DateTime
|
class DateTime
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// %d-%02d-%02d %02d:%02d:%02d.%03d
|
// %d-%02d-%02d %02d:%02d:%02d.%03d
|
||||||
#define DATE_LEN 24
|
#define DATE_LEN 24
|
||||||
char time_data[DATE_LEN];
|
char time_data[DATE_LEN];
|
||||||
public:
|
public:
|
||||||
DateTime();
|
DateTime();
|
||||||
virtual ~DateTime();
|
virtual ~DateTime();
|
||||||
public:
|
public:
|
||||||
virtual const char* format_time();
|
virtual const char* format_time();
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
DateTime time;
|
DateTime time;
|
||||||
std::map<st_thread_t, int> cache;
|
std::map<st_thread_t, int> cache;
|
||||||
public:
|
public:
|
||||||
LogContext();
|
LogContext();
|
||||||
virtual ~LogContext();
|
virtual ~LogContext();
|
||||||
public:
|
public:
|
||||||
virtual void generate_id();
|
virtual void generate_id();
|
||||||
virtual int get_id();
|
virtual int get_id();
|
||||||
public:
|
public:
|
||||||
virtual const char* format_time();
|
virtual const char* format_time();
|
||||||
};
|
};
|
||||||
|
|
||||||
ILogContext* log_context = new LogContext();
|
ILogContext* log_context = new LogContext();
|
||||||
|
|
||||||
LogContext::DateTime::DateTime()
|
LogContext::DateTime::DateTime()
|
||||||
{
|
{
|
||||||
memset(time_data, 0, DATE_LEN);
|
memset(time_data, 0, DATE_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogContext::DateTime::~DateTime()
|
LogContext::DateTime::~DateTime()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* LogContext::DateTime::format_time()
|
const char* LogContext::DateTime::format_time()
|
||||||
{
|
{
|
||||||
// clock time
|
// clock time
|
||||||
timeval tv;
|
timeval tv;
|
||||||
if (gettimeofday(&tv, NULL) == -1) {
|
if (gettimeofday(&tv, NULL) == -1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// to calendar time
|
// to calendar time
|
||||||
struct tm* tm;
|
struct tm* tm;
|
||||||
if ((tm = localtime(&tv.tv_sec)) == NULL) {
|
if ((tm = localtime(&tv.tv_sec)) == NULL) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// log header, the time/pid/level of log
|
// log header, the time/pid/level of log
|
||||||
// reserved 1bytes for the new line.
|
// reserved 1bytes for the new line.
|
||||||
snprintf(time_data, DATE_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d",
|
snprintf(time_data, DATE_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d",
|
||||||
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
|
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
|
||||||
(int)(tv.tv_usec / 1000));
|
(int)(tv.tv_usec / 1000));
|
||||||
|
|
||||||
return time_data;
|
return time_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogContext::LogContext()
|
LogContext::LogContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LogContext::~LogContext()
|
LogContext::~LogContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogContext::generate_id()
|
void LogContext::generate_id()
|
||||||
{
|
{
|
||||||
static int id = 1;
|
static int id = 1;
|
||||||
cache[st_thread_self()] = id++;
|
cache[st_thread_self()] = id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LogContext::get_id()
|
int LogContext::get_id()
|
||||||
{
|
{
|
||||||
return cache[st_thread_self()];
|
return cache[st_thread_self()];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* LogContext::format_time()
|
const char* LogContext::format_time()
|
||||||
{
|
{
|
||||||
return time.format_time();
|
return time.format_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,90 +1,90 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_LOG_HPP
|
#ifndef SRS_CORE_LOG_HPP
|
||||||
#define SRS_CORE_LOG_HPP
|
#define SRS_CORE_LOG_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// the context for multiple clients.
|
// the context for multiple clients.
|
||||||
class ILogContext
|
class ILogContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ILogContext();
|
ILogContext();
|
||||||
virtual ~ILogContext();
|
virtual ~ILogContext();
|
||||||
public:
|
public:
|
||||||
virtual void generate_id() = 0;
|
virtual void generate_id() = 0;
|
||||||
virtual int get_id() = 0;
|
virtual int get_id() = 0;
|
||||||
public:
|
public:
|
||||||
virtual const char* format_time() = 0;
|
virtual const char* format_time() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// user must implements the LogContext and define a global instance.
|
// user must implements the LogContext and define a global instance.
|
||||||
extern ILogContext* log_context;
|
extern ILogContext* log_context;
|
||||||
|
|
||||||
// donot print method
|
// donot print method
|
||||||
#if 0
|
#if 0
|
||||||
#define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_warn(msg, ...) printf("[%s][%d][warns] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
#define srs_warn(msg, ...) printf("[%s][%d][warns] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||||
#define srs_error(msg, ...) printf("[%s][%d][error] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
#define srs_error(msg, ...) printf("[%s][%d][error] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||||
// use __FUNCTION__ to print c method
|
// use __FUNCTION__ to print c method
|
||||||
#elif 1
|
#elif 1
|
||||||
#define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
#define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||||
#define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
#define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||||
// use __PRETTY_FUNCTION__ to print c++ class:method
|
// use __PRETTY_FUNCTION__ to print c++ class:method
|
||||||
#else
|
#else
|
||||||
#define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
#define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n")
|
||||||
#define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
#define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||||
#define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
#define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
#undef srs_verbose
|
#undef srs_verbose
|
||||||
#define srs_verbose(msg, ...) (void)0
|
#define srs_verbose(msg, ...) (void)0
|
||||||
#endif
|
#endif
|
||||||
#if 1
|
#if 1
|
||||||
#undef srs_info
|
#undef srs_info
|
||||||
#define srs_info(msg, ...) (void)0
|
#define srs_info(msg, ...) (void)0
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
#undef srs_trace
|
#undef srs_trace
|
||||||
#define srs_trace(msg, ...) (void)0
|
#define srs_trace(msg, ...) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,164 +1,164 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_pithy_print.hpp>
|
#include <srs_core_pithy_print.hpp>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_config.hpp>
|
#include <srs_core_config.hpp>
|
||||||
#include <srs_core_reload.hpp>
|
#include <srs_core_reload.hpp>
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
|
|
||||||
#define SRS_STAGE_DEFAULT_INTERVAL_MS 1200
|
#define SRS_STAGE_DEFAULT_INTERVAL_MS 1200
|
||||||
#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300
|
#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300
|
||||||
#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100
|
#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100
|
||||||
|
|
||||||
struct SrsStageInfo : public SrsReloadHandler
|
struct SrsStageInfo : public SrsReloadHandler
|
||||||
{
|
{
|
||||||
int stage_id;
|
int stage_id;
|
||||||
int pithy_print_time_ms;
|
int pithy_print_time_ms;
|
||||||
int nb_clients;
|
int nb_clients;
|
||||||
|
|
||||||
SrsStageInfo(int _stage_id)
|
SrsStageInfo(int _stage_id)
|
||||||
{
|
{
|
||||||
stage_id = _stage_id;
|
stage_id = _stage_id;
|
||||||
nb_clients = 0;
|
nb_clients = 0;
|
||||||
|
|
||||||
update_print_time();
|
update_print_time();
|
||||||
|
|
||||||
config->subscribe(this);
|
config->subscribe(this);
|
||||||
}
|
}
|
||||||
virtual ~SrsStageInfo()
|
virtual ~SrsStageInfo()
|
||||||
{
|
{
|
||||||
config->unsubscribe(this);
|
config->unsubscribe(this);
|
||||||
}
|
}
|
||||||
void update_print_time()
|
void update_print_time()
|
||||||
{
|
{
|
||||||
switch (stage_id) {
|
switch (stage_id) {
|
||||||
case SRS_STAGE_PLAY_USER: {
|
case SRS_STAGE_PLAY_USER: {
|
||||||
pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS;
|
pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS;
|
||||||
SrsConfDirective* conf = config->get_pithy_print_play();
|
SrsConfDirective* conf = config->get_pithy_print_play();
|
||||||
if (conf && !conf->arg0().empty()) {
|
if (conf && !conf->arg0().empty()) {
|
||||||
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
|
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SRS_STAGE_PUBLISH_USER: {
|
case SRS_STAGE_PUBLISH_USER: {
|
||||||
pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
|
pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
|
||||||
SrsConfDirective* conf = config->get_pithy_print_publish();
|
SrsConfDirective* conf = config->get_pithy_print_publish();
|
||||||
if (conf && !conf->arg0().empty()) {
|
if (conf && !conf->arg0().empty()) {
|
||||||
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
|
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
pithy_print_time_ms = SRS_STAGE_DEFAULT_INTERVAL_MS;
|
pithy_print_time_ms = SRS_STAGE_DEFAULT_INTERVAL_MS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
virtual int on_reload_pithy_print()
|
virtual int on_reload_pithy_print()
|
||||||
{
|
{
|
||||||
update_print_time();
|
update_print_time();
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static std::map<int, SrsStageInfo*> _srs_stages;
|
static std::map<int, SrsStageInfo*> _srs_stages;
|
||||||
|
|
||||||
SrsPithyPrint::SrsPithyPrint(int _stage_id)
|
SrsPithyPrint::SrsPithyPrint(int _stage_id)
|
||||||
{
|
{
|
||||||
stage_id = _stage_id;
|
stage_id = _stage_id;
|
||||||
client_id = enter_stage();
|
client_id = enter_stage();
|
||||||
printed_age = age = 0;
|
printed_age = age = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsPithyPrint::~SrsPithyPrint()
|
SrsPithyPrint::~SrsPithyPrint()
|
||||||
{
|
{
|
||||||
leave_stage();
|
leave_stage();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsPithyPrint::enter_stage()
|
int SrsPithyPrint::enter_stage()
|
||||||
{
|
{
|
||||||
SrsStageInfo* stage = NULL;
|
SrsStageInfo* stage = NULL;
|
||||||
|
|
||||||
std::map<int, SrsStageInfo*>::iterator it = _srs_stages.find(stage_id);
|
std::map<int, SrsStageInfo*>::iterator it = _srs_stages.find(stage_id);
|
||||||
if (it == _srs_stages.end()) {
|
if (it == _srs_stages.end()) {
|
||||||
stage = _srs_stages[stage_id] = new SrsStageInfo(stage_id);
|
stage = _srs_stages[stage_id] = new SrsStageInfo(stage_id);
|
||||||
} else {
|
} else {
|
||||||
stage = it->second;
|
stage = it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_assert(stage != NULL);
|
srs_assert(stage != NULL);
|
||||||
client_id = stage->nb_clients++;
|
client_id = stage->nb_clients++;
|
||||||
|
|
||||||
srs_verbose("enter stage, stage_id=%d, client_id=%d, nb_clients=%d, time_ms=%d",
|
srs_verbose("enter stage, stage_id=%d, client_id=%d, nb_clients=%d, time_ms=%d",
|
||||||
stage->stage_id, client_id, stage->nb_clients, stage->pithy_print_time_ms);
|
stage->stage_id, client_id, stage->nb_clients, stage->pithy_print_time_ms);
|
||||||
|
|
||||||
return client_id;
|
return client_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsPithyPrint::leave_stage()
|
void SrsPithyPrint::leave_stage()
|
||||||
{
|
{
|
||||||
SrsStageInfo* stage = _srs_stages[stage_id];
|
SrsStageInfo* stage = _srs_stages[stage_id];
|
||||||
srs_assert(stage != NULL);
|
srs_assert(stage != NULL);
|
||||||
|
|
||||||
stage->nb_clients--;
|
stage->nb_clients--;
|
||||||
|
|
||||||
srs_verbose("leave stage, stage_id=%d, client_id=%d, nb_clients=%d, time_ms=%d",
|
srs_verbose("leave stage, stage_id=%d, client_id=%d, nb_clients=%d, time_ms=%d",
|
||||||
stage->stage_id, client_id, stage->nb_clients, stage->pithy_print_time_ms);
|
stage->stage_id, client_id, stage->nb_clients, stage->pithy_print_time_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsPithyPrint::elapse(int64_t time_ms)
|
void SrsPithyPrint::elapse(int64_t time_ms)
|
||||||
{
|
{
|
||||||
age += time_ms;
|
age += time_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsPithyPrint::can_print()
|
bool SrsPithyPrint::can_print()
|
||||||
{
|
{
|
||||||
SrsStageInfo* stage = _srs_stages[stage_id];
|
SrsStageInfo* stage = _srs_stages[stage_id];
|
||||||
srs_assert(stage != NULL);
|
srs_assert(stage != NULL);
|
||||||
|
|
||||||
int64_t alive_age = age - printed_age;
|
int64_t alive_age = age - printed_age;
|
||||||
int64_t can_print_age = stage->nb_clients * stage->pithy_print_time_ms;
|
int64_t can_print_age = stage->nb_clients * stage->pithy_print_time_ms;
|
||||||
|
|
||||||
bool can_print = alive_age >= can_print_age;
|
bool can_print = alive_age >= can_print_age;
|
||||||
if (can_print) {
|
if (can_print) {
|
||||||
printed_age = age;
|
printed_age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
return can_print;
|
return can_print;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsPithyPrint::get_age()
|
int64_t SrsPithyPrint::get_age()
|
||||||
{
|
{
|
||||||
return age;
|
return age;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsPithyPrint::set_age(int64_t _age)
|
void SrsPithyPrint::set_age(int64_t _age)
|
||||||
{
|
{
|
||||||
age = _age;
|
age = _age;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,82 +1,82 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_PITHY_PRINT_HPP
|
#ifndef SRS_CORE_PITHY_PRINT_HPP
|
||||||
#define SRS_CORE_PITHY_PRINT_HPP
|
#define SRS_CORE_PITHY_PRINT_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_pithy_print.hpp>
|
#include <srs_core_pithy_print.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
// the pithy stage for all play clients.
|
// the pithy stage for all play clients.
|
||||||
#define SRS_STAGE_PLAY_USER 1
|
#define SRS_STAGE_PLAY_USER 1
|
||||||
// the pithy stage for all publish clients.
|
// the pithy stage for all publish clients.
|
||||||
#define SRS_STAGE_PUBLISH_USER 2
|
#define SRS_STAGE_PUBLISH_USER 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the stage is used for a collection of object to do print,
|
* the stage is used for a collection of object to do print,
|
||||||
* the print time in a stage is constant and not changed.
|
* the print time in a stage is constant and not changed.
|
||||||
* for example, stage #1 for all play clients, print time is 3s,
|
* for example, stage #1 for all play clients, print time is 3s,
|
||||||
* if there is 10clients, then all clients should print in 10*3s.
|
* if there is 10clients, then all clients should print in 10*3s.
|
||||||
*/
|
*/
|
||||||
class SrsPithyPrint
|
class SrsPithyPrint
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int client_id;
|
int client_id;
|
||||||
int stage_id;
|
int stage_id;
|
||||||
int64_t age;
|
int64_t age;
|
||||||
int64_t printed_age;
|
int64_t printed_age;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @param _stage_id defined in SRS_STAGE_xxx, eg. SRS_STAGE_PLAY_USER.
|
* @param _stage_id defined in SRS_STAGE_xxx, eg. SRS_STAGE_PLAY_USER.
|
||||||
*/
|
*/
|
||||||
SrsPithyPrint(int _stage_id);
|
SrsPithyPrint(int _stage_id);
|
||||||
virtual ~SrsPithyPrint();
|
virtual ~SrsPithyPrint();
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* enter the specified stage, return the client id.
|
* enter the specified stage, return the client id.
|
||||||
*/
|
*/
|
||||||
virtual int enter_stage();
|
virtual int enter_stage();
|
||||||
/**
|
/**
|
||||||
* leave the specified stage, release the client id.
|
* leave the specified stage, release the client id.
|
||||||
*/
|
*/
|
||||||
virtual void leave_stage();
|
virtual void leave_stage();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* specified client elapse some time.
|
* specified client elapse some time.
|
||||||
*/
|
*/
|
||||||
virtual void elapse(int64_t time_ms);
|
virtual void elapse(int64_t time_ms);
|
||||||
/**
|
/**
|
||||||
* whether current client can print.
|
* whether current client can print.
|
||||||
*/
|
*/
|
||||||
virtual bool can_print();
|
virtual bool can_print();
|
||||||
/**
|
/**
|
||||||
* get the elapsed time in ms.
|
* get the elapsed time in ms.
|
||||||
*/
|
*/
|
||||||
virtual int64_t get_age();
|
virtual int64_t get_age();
|
||||||
virtual void set_age(int64_t _age);
|
virtual void set_age(int64_t _age);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,88 +1,88 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_refer.hpp>
|
#include <srs_core_refer.hpp>
|
||||||
|
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_config.hpp>
|
#include <srs_core_config.hpp>
|
||||||
|
|
||||||
int SrsRefer::check(std::string page_url, SrsConfDirective* refer)
|
int SrsRefer::check(std::string page_url, SrsConfDirective* refer)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (!refer) {
|
if (!refer) {
|
||||||
srs_verbose("ignore refer check for page_url=%s", page_url.c_str());
|
srs_verbose("ignore refer check for page_url=%s", page_url.c_str());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < (int)refer->args.size(); i++) {
|
for (int i = 0; i < (int)refer->args.size(); i++) {
|
||||||
if ((ret = check_single_refer(page_url, refer->args.at(i))) == ERROR_SUCCESS) {
|
if ((ret = check_single_refer(page_url, refer->args.at(i))) == ERROR_SUCCESS) {
|
||||||
srs_verbose("check refer success. page_url=%s, refer=%s",
|
srs_verbose("check refer success. page_url=%s, refer=%s",
|
||||||
page_url.c_str(), refer->args.at(i).c_str());
|
page_url.c_str(), refer->args.at(i).c_str());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ERROR_RTMP_ACCESS_DENIED;
|
ret = ERROR_RTMP_ACCESS_DENIED;
|
||||||
srs_error("check refer failed. ret=%d", ret);
|
srs_error("check refer failed. ret=%d", ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsRefer::check_single_refer(std::string page_url, std::string refer)
|
int SrsRefer::check_single_refer(std::string page_url, std::string refer)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
size_t pos = std::string::npos;
|
size_t pos = std::string::npos;
|
||||||
|
|
||||||
std::string domain_name = page_url;
|
std::string domain_name = page_url;
|
||||||
if ((pos = domain_name.find("://")) != std::string::npos) {
|
if ((pos = domain_name.find("://")) != std::string::npos) {
|
||||||
domain_name = domain_name.substr(pos + 3);
|
domain_name = domain_name.substr(pos + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pos = domain_name.find("/")) != std::string::npos) {
|
if ((pos = domain_name.find("/")) != std::string::npos) {
|
||||||
domain_name = domain_name.substr(0, pos);
|
domain_name = domain_name.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pos = domain_name.find(":")) != std::string::npos) {
|
if ((pos = domain_name.find(":")) != std::string::npos) {
|
||||||
domain_name = domain_name.substr(0, pos);
|
domain_name = domain_name.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = domain_name.find(refer);
|
pos = domain_name.find(refer);
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
ret = ERROR_RTMP_ACCESS_DENIED;
|
ret = ERROR_RTMP_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
// match primary domain.
|
// match primary domain.
|
||||||
if (pos != domain_name.length() - refer.length()) {
|
if (pos != domain_name.length() - refer.length()) {
|
||||||
ret = ERROR_RTMP_ACCESS_DENIED;
|
ret = ERROR_RTMP_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != ERROR_SUCCESS) {
|
if (ret != ERROR_SUCCESS) {
|
||||||
srs_verbose("access denied, page_url=%s, domain_name=%s, refer=%s, ret=%d",
|
srs_verbose("access denied, page_url=%s, domain_name=%s, refer=%s, ret=%d",
|
||||||
page_url.c_str(), domain_name.c_str(), refer.c_str(), ret);
|
page_url.c_str(), domain_name.c_str(), refer.c_str(), ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,49 +1,49 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_REFER_HPP
|
#ifndef SRS_CORE_REFER_HPP
|
||||||
#define SRS_CORE_REFER_HPP
|
#define SRS_CORE_REFER_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_refer.hpp>
|
#include <srs_core_refer.hpp>
|
||||||
*/
|
*/
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SrsConfDirective;
|
class SrsConfDirective;
|
||||||
|
|
||||||
class SrsRefer
|
class SrsRefer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* to check the refer.
|
* to check the refer.
|
||||||
* @param page_url the client page url.
|
* @param page_url the client page url.
|
||||||
* @param refer the refer in config.
|
* @param refer the refer in config.
|
||||||
*/
|
*/
|
||||||
virtual int check(std::string page_url, SrsConfDirective* refer);
|
virtual int check(std::string page_url, SrsConfDirective* refer);
|
||||||
private:
|
private:
|
||||||
virtual int check_single_refer(std::string page_url, std::string refer);
|
virtual int check_single_refer(std::string page_url, std::string refer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,45 +1,45 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_reload.hpp>
|
#include <srs_core_reload.hpp>
|
||||||
|
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
|
|
||||||
SrsReloadHandler::SrsReloadHandler()
|
SrsReloadHandler::SrsReloadHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsReloadHandler::~SrsReloadHandler()
|
SrsReloadHandler::~SrsReloadHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsReloadHandler::on_reload_listen()
|
int SrsReloadHandler::on_reload_listen()
|
||||||
{
|
{
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsReloadHandler::on_reload_pithy_print()
|
int SrsReloadHandler::on_reload_pithy_print()
|
||||||
{
|
{
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_RELOAD_HPP
|
#ifndef SRS_CORE_RELOAD_HPP
|
||||||
#define SRS_CORE_RELOAD_HPP
|
#define SRS_CORE_RELOAD_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_reload.hpp>
|
#include <srs_core_reload.hpp>
|
||||||
*/
|
*/
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the handler for config reload.
|
* the handler for config reload.
|
||||||
*/
|
*/
|
||||||
class SrsReloadHandler
|
class SrsReloadHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsReloadHandler();
|
SrsReloadHandler();
|
||||||
virtual ~SrsReloadHandler();
|
virtual ~SrsReloadHandler();
|
||||||
public:
|
public:
|
||||||
virtual int on_reload_listen();
|
virtual int on_reload_listen();
|
||||||
virtual int on_reload_pithy_print();
|
virtual int on_reload_pithy_print();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,184 +1,184 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_RTMP_HPP
|
#ifndef SRS_CORE_RTMP_HPP
|
||||||
#define SRS_CORE_RTMP_HPP
|
#define SRS_CORE_RTMP_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_rtmp.hpp>
|
#include <srs_core_rtmp.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <st.h>
|
#include <st.h>
|
||||||
|
|
||||||
class SrsProtocol;
|
class SrsProtocol;
|
||||||
class ISrsMessage;
|
class ISrsMessage;
|
||||||
class SrsCommonMessage;
|
class SrsCommonMessage;
|
||||||
class SrsCreateStreamPacket;
|
class SrsCreateStreamPacket;
|
||||||
class SrsFMLEStartPacket;
|
class SrsFMLEStartPacket;
|
||||||
class SrsPublishPacket;
|
class SrsPublishPacket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the original request from client.
|
* the original request from client.
|
||||||
*/
|
*/
|
||||||
struct SrsRequest
|
struct SrsRequest
|
||||||
{
|
{
|
||||||
std::string tcUrl;
|
std::string tcUrl;
|
||||||
std::string pageUrl;
|
std::string pageUrl;
|
||||||
std::string swfUrl;
|
std::string swfUrl;
|
||||||
double objectEncoding;
|
double objectEncoding;
|
||||||
|
|
||||||
std::string schema;
|
std::string schema;
|
||||||
std::string vhost;
|
std::string vhost;
|
||||||
std::string port;
|
std::string port;
|
||||||
std::string app;
|
std::string app;
|
||||||
std::string stream;
|
std::string stream;
|
||||||
|
|
||||||
SrsRequest();
|
SrsRequest();
|
||||||
virtual ~SrsRequest();
|
virtual ~SrsRequest();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* disconvery vhost/app from tcUrl.
|
* disconvery vhost/app from tcUrl.
|
||||||
*/
|
*/
|
||||||
virtual int discovery_app();
|
virtual int discovery_app();
|
||||||
virtual std::string get_stream_url();
|
virtual std::string get_stream_url();
|
||||||
virtual void strip();
|
virtual void strip();
|
||||||
private:
|
private:
|
||||||
std::string& trim(std::string& str, std::string chs);
|
std::string& trim(std::string& str, std::string chs);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the response to client.
|
* the response to client.
|
||||||
*/
|
*/
|
||||||
struct SrsResponse
|
struct SrsResponse
|
||||||
{
|
{
|
||||||
int stream_id;
|
int stream_id;
|
||||||
|
|
||||||
SrsResponse();
|
SrsResponse();
|
||||||
virtual ~SrsResponse();
|
virtual ~SrsResponse();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the rtmp client type.
|
* the rtmp client type.
|
||||||
*/
|
*/
|
||||||
enum SrsClientType
|
enum SrsClientType
|
||||||
{
|
{
|
||||||
SrsClientUnknown,
|
SrsClientUnknown,
|
||||||
SrsClientPlay,
|
SrsClientPlay,
|
||||||
SrsClientFMLEPublish,
|
SrsClientFMLEPublish,
|
||||||
SrsClientFlashPublish,
|
SrsClientFlashPublish,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the rtmp provices rtmp-command-protocol services,
|
* the rtmp provices rtmp-command-protocol services,
|
||||||
* a high level protocol, media stream oriented services,
|
* a high level protocol, media stream oriented services,
|
||||||
* such as connect to vhost/app, play stream, get audio/video data.
|
* such as connect to vhost/app, play stream, get audio/video data.
|
||||||
*/
|
*/
|
||||||
class SrsRtmp
|
class SrsRtmp
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsProtocol* protocol;
|
SrsProtocol* protocol;
|
||||||
st_netfd_t stfd;
|
st_netfd_t stfd;
|
||||||
public:
|
public:
|
||||||
SrsRtmp(st_netfd_t client_stfd);
|
SrsRtmp(st_netfd_t client_stfd);
|
||||||
virtual ~SrsRtmp();
|
virtual ~SrsRtmp();
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t timeout_us);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t timeout_us);
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
virtual int get_recv_kbps();
|
virtual int get_recv_kbps();
|
||||||
virtual int get_send_kbps();
|
virtual int get_send_kbps();
|
||||||
virtual int recv_message(SrsCommonMessage** pmsg);
|
virtual int recv_message(SrsCommonMessage** pmsg);
|
||||||
virtual int send_message(ISrsMessage* msg);
|
virtual int send_message(ISrsMessage* msg);
|
||||||
public:
|
public:
|
||||||
virtual int handshake();
|
virtual int handshake();
|
||||||
virtual int connect_app(SrsRequest* req);
|
virtual int connect_app(SrsRequest* req);
|
||||||
virtual int set_window_ack_size(int ack_size);
|
virtual int set_window_ack_size(int ack_size);
|
||||||
/**
|
/**
|
||||||
* @type: The sender can mark this message hard (0), soft (1), or dynamic (2)
|
* @type: The sender can mark this message hard (0), soft (1), or dynamic (2)
|
||||||
* using the Limit type field.
|
* using the Limit type field.
|
||||||
*/
|
*/
|
||||||
virtual int set_peer_bandwidth(int bandwidth, int type);
|
virtual int set_peer_bandwidth(int bandwidth, int type);
|
||||||
virtual int response_connect_app(SrsRequest* req);
|
virtual int response_connect_app(SrsRequest* req);
|
||||||
virtual int on_bw_done();
|
virtual int on_bw_done();
|
||||||
/**
|
/**
|
||||||
* recv some message to identify the client.
|
* recv some message to identify the client.
|
||||||
* @stream_id, client will createStream to play or publish by flash,
|
* @stream_id, client will createStream to play or publish by flash,
|
||||||
* the stream_id used to response the createStream request.
|
* the stream_id used to response the createStream request.
|
||||||
* @type, output the client type.
|
* @type, output the client type.
|
||||||
*/
|
*/
|
||||||
virtual int identify_client(int stream_id, SrsClientType& type, std::string& stream_name);
|
virtual int identify_client(int stream_id, SrsClientType& type, std::string& stream_name);
|
||||||
/**
|
/**
|
||||||
* set the chunk size when client type identified.
|
* set the chunk size when client type identified.
|
||||||
*/
|
*/
|
||||||
virtual int set_chunk_size(int chunk_size);
|
virtual int set_chunk_size(int chunk_size);
|
||||||
/**
|
/**
|
||||||
* when client type is play, response with packets:
|
* when client type is play, response with packets:
|
||||||
* StreamBegin,
|
* StreamBegin,
|
||||||
* onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start).,
|
* onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start).,
|
||||||
* |RtmpSampleAccess(false, false),
|
* |RtmpSampleAccess(false, false),
|
||||||
* onStatus(NetStream.Data.Start).
|
* onStatus(NetStream.Data.Start).
|
||||||
*/
|
*/
|
||||||
virtual int start_play(int stream_id);
|
virtual int start_play(int stream_id);
|
||||||
/**
|
/**
|
||||||
* when client(type is play) send pause message,
|
* when client(type is play) send pause message,
|
||||||
* if is_pause, response the following packets:
|
* if is_pause, response the following packets:
|
||||||
* onStatus(NetStream.Pause.Notify)
|
* onStatus(NetStream.Pause.Notify)
|
||||||
* StreamEOF
|
* StreamEOF
|
||||||
* if not is_pause, response the following packets:
|
* if not is_pause, response the following packets:
|
||||||
* onStatus(NetStream.Unpause.Notify)
|
* onStatus(NetStream.Unpause.Notify)
|
||||||
* StreamBegin
|
* StreamBegin
|
||||||
*/
|
*/
|
||||||
virtual int on_play_client_pause(int stream_id, bool is_pause);
|
virtual int on_play_client_pause(int stream_id, bool is_pause);
|
||||||
/**
|
/**
|
||||||
* when client type is publish, response with packets:
|
* when client type is publish, response with packets:
|
||||||
* releaseStream response
|
* releaseStream response
|
||||||
* FCPublish
|
* FCPublish
|
||||||
* FCPublish response
|
* FCPublish response
|
||||||
* createStream response
|
* createStream response
|
||||||
* onFCPublish(NetStream.Publish.Start)
|
* onFCPublish(NetStream.Publish.Start)
|
||||||
* onStatus(NetStream.Publish.Start)
|
* onStatus(NetStream.Publish.Start)
|
||||||
*/
|
*/
|
||||||
virtual int start_fmle_publish(int stream_id);
|
virtual int start_fmle_publish(int stream_id);
|
||||||
/**
|
/**
|
||||||
* process the FMLE unpublish event.
|
* process the FMLE unpublish event.
|
||||||
* @unpublish_tid the unpublish request transaction id.
|
* @unpublish_tid the unpublish request transaction id.
|
||||||
*/
|
*/
|
||||||
virtual int fmle_unpublish(int stream_id, double unpublish_tid);
|
virtual int fmle_unpublish(int stream_id, double unpublish_tid);
|
||||||
/**
|
/**
|
||||||
* when client type is publish, response with packets:
|
* when client type is publish, response with packets:
|
||||||
* onStatus(NetStream.Publish.Start)
|
* onStatus(NetStream.Publish.Start)
|
||||||
*/
|
*/
|
||||||
virtual int start_flash_publish(int stream_id);
|
virtual int start_flash_publish(int stream_id);
|
||||||
private:
|
private:
|
||||||
virtual int identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsClientType& type, std::string& stream_name);
|
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_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);
|
virtual int identify_flash_publish_client(SrsPublishPacket* req, SrsClientType& type, std::string& stream_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,336 +1,336 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_server.hpp>
|
#include <srs_core_server.hpp>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <st.h>
|
#include <st.h>
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_client.hpp>
|
#include <srs_core_client.hpp>
|
||||||
#include <srs_core_config.hpp>
|
#include <srs_core_config.hpp>
|
||||||
|
|
||||||
#define SERVER_LISTEN_BACKLOG 10
|
#define SERVER_LISTEN_BACKLOG 10
|
||||||
#define SRS_TIME_RESOLUTION_MS 500
|
#define SRS_TIME_RESOLUTION_MS 500
|
||||||
|
|
||||||
SrsListener::SrsListener(SrsServer* _server, SrsListenerType _type)
|
SrsListener::SrsListener(SrsServer* _server, SrsListenerType _type)
|
||||||
{
|
{
|
||||||
fd = -1;
|
fd = -1;
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
|
|
||||||
port = 0;
|
port = 0;
|
||||||
server = _server;
|
server = _server;
|
||||||
type = _type;
|
type = _type;
|
||||||
|
|
||||||
tid = NULL;
|
tid = NULL;
|
||||||
loop = false;
|
loop = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsListener::~SrsListener()
|
SrsListener::~SrsListener()
|
||||||
{
|
{
|
||||||
if (stfd) {
|
if (stfd) {
|
||||||
st_netfd_close(stfd);
|
st_netfd_close(stfd);
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tid) {
|
if (tid) {
|
||||||
loop = false;
|
loop = false;
|
||||||
st_thread_interrupt(tid);
|
st_thread_interrupt(tid);
|
||||||
st_thread_join(tid, NULL);
|
st_thread_join(tid, NULL);
|
||||||
tid = NULL;
|
tid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// st does not close it sometimes,
|
// st does not close it sometimes,
|
||||||
// close it manually.
|
// close it manually.
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsListener::listen(int _port)
|
int SrsListener::listen(int _port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
port = _port;
|
port = _port;
|
||||||
|
|
||||||
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||||
ret = ERROR_SOCKET_CREATE;
|
ret = ERROR_SOCKET_CREATE;
|
||||||
srs_error("create linux socket error. ret=%d", ret);
|
srs_error("create linux socket error. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("create linux socket success. fd=%d", fd);
|
srs_verbose("create linux socket success. fd=%d", fd);
|
||||||
|
|
||||||
int reuse_socket = 1;
|
int reuse_socket = 1;
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) {
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) {
|
||||||
ret = ERROR_SOCKET_SETREUSE;
|
ret = ERROR_SOCKET_SETREUSE;
|
||||||
srs_error("setsockopt reuse-addr error. ret=%d", ret);
|
srs_error("setsockopt reuse-addr error. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("setsockopt reuse-addr success. fd=%d", fd);
|
srs_verbose("setsockopt reuse-addr success. fd=%d", fd);
|
||||||
|
|
||||||
sockaddr_in addr;
|
sockaddr_in addr;
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
if (bind(fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) {
|
if (bind(fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) {
|
||||||
ret = ERROR_SOCKET_BIND;
|
ret = ERROR_SOCKET_BIND;
|
||||||
srs_error("bind socket error. ret=%d", ret);
|
srs_error("bind socket error. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("bind socket success. fd=%d", fd);
|
srs_verbose("bind socket success. fd=%d", fd);
|
||||||
|
|
||||||
if (::listen(fd, SERVER_LISTEN_BACKLOG) == -1) {
|
if (::listen(fd, SERVER_LISTEN_BACKLOG) == -1) {
|
||||||
ret = ERROR_SOCKET_LISTEN;
|
ret = ERROR_SOCKET_LISTEN;
|
||||||
srs_error("listen socket error. ret=%d", ret);
|
srs_error("listen socket error. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("listen socket success. fd=%d", fd);
|
srs_verbose("listen socket success. fd=%d", fd);
|
||||||
|
|
||||||
if ((stfd = st_netfd_open_socket(fd)) == NULL){
|
if ((stfd = st_netfd_open_socket(fd)) == NULL){
|
||||||
ret = ERROR_ST_OPEN_SOCKET;
|
ret = ERROR_ST_OPEN_SOCKET;
|
||||||
srs_error("st_netfd_open_socket open socket failed. ret=%d", ret);
|
srs_error("st_netfd_open_socket open socket failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("st open socket success. fd=%d", fd);
|
srs_verbose("st open socket success. fd=%d", fd);
|
||||||
|
|
||||||
if ((tid = st_thread_create(listen_thread, this, 1, 0)) == NULL) {
|
if ((tid = st_thread_create(listen_thread, this, 1, 0)) == NULL) {
|
||||||
ret = ERROR_ST_CREATE_LISTEN_THREAD;
|
ret = ERROR_ST_CREATE_LISTEN_THREAD;
|
||||||
srs_error("st_thread_create listen thread error. ret=%d", ret);
|
srs_error("st_thread_create listen thread error. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("create st listen thread success.");
|
srs_verbose("create st listen thread success.");
|
||||||
|
|
||||||
srs_trace("server started, listen at port=%d, fd=%d", port, fd);
|
srs_trace("server started, listen at port=%d, fd=%d", port, fd);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsListener::listen_cycle()
|
void SrsListener::listen_cycle()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
log_context->generate_id();
|
log_context->generate_id();
|
||||||
srs_trace("listen cycle start, port=%d, type=%d, fd=%d", port, type, fd);
|
srs_trace("listen cycle start, port=%d, type=%d, fd=%d", port, type, fd);
|
||||||
|
|
||||||
while (loop) {
|
while (loop) {
|
||||||
st_netfd_t client_stfd = st_accept(stfd, NULL, NULL, ST_UTIME_NO_TIMEOUT);
|
st_netfd_t client_stfd = st_accept(stfd, NULL, NULL, ST_UTIME_NO_TIMEOUT);
|
||||||
|
|
||||||
if(client_stfd == NULL){
|
if(client_stfd == NULL){
|
||||||
// ignore error.
|
// ignore error.
|
||||||
srs_warn("ignore accept thread stoppped for accept client error");
|
srs_warn("ignore accept thread stoppped for accept client error");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
srs_verbose("get a client. fd=%d", st_netfd_fileno(client_stfd));
|
srs_verbose("get a client. fd=%d", st_netfd_fileno(client_stfd));
|
||||||
|
|
||||||
if ((ret = server->accept_client(type, client_stfd)) != ERROR_SUCCESS) {
|
if ((ret = server->accept_client(type, client_stfd)) != ERROR_SUCCESS) {
|
||||||
srs_warn("accept client error. ret=%d", ret);
|
srs_warn("accept client error. ret=%d", ret);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_verbose("accept client finished. conns=%d, ret=%d", (int)conns.size(), ret);
|
srs_verbose("accept client finished. conns=%d, ret=%d", (int)conns.size(), ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SrsListener::listen_thread(void* arg)
|
void* SrsListener::listen_thread(void* arg)
|
||||||
{
|
{
|
||||||
SrsListener* obj = (SrsListener*)arg;
|
SrsListener* obj = (SrsListener*)arg;
|
||||||
srs_assert(obj != NULL);
|
srs_assert(obj != NULL);
|
||||||
|
|
||||||
obj->loop = true;
|
obj->loop = true;
|
||||||
obj->listen_cycle();
|
obj->listen_cycle();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsServer::SrsServer()
|
SrsServer::SrsServer()
|
||||||
{
|
{
|
||||||
signal_reload = false;
|
signal_reload = false;
|
||||||
|
|
||||||
srs_assert(config);
|
srs_assert(config);
|
||||||
config->subscribe(this);
|
config->subscribe(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsServer::~SrsServer()
|
SrsServer::~SrsServer()
|
||||||
{
|
{
|
||||||
config->unsubscribe(this);
|
config->unsubscribe(this);
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
std::vector<SrsConnection*>::iterator it;
|
std::vector<SrsConnection*>::iterator it;
|
||||||
for (it = conns.begin(); it != conns.end(); ++it) {
|
for (it = conns.begin(); it != conns.end(); ++it) {
|
||||||
SrsConnection* conn = *it;
|
SrsConnection* conn = *it;
|
||||||
srs_freep(conn);
|
srs_freep(conn);
|
||||||
}
|
}
|
||||||
conns.clear();
|
conns.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
close_listeners();
|
close_listeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsServer::initialize()
|
int SrsServer::initialize()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// use linux epoll.
|
// use linux epoll.
|
||||||
if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {
|
if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {
|
||||||
ret = ERROR_ST_SET_EPOLL;
|
ret = ERROR_ST_SET_EPOLL;
|
||||||
srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret);
|
srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("st_set_eventsys use linux epoll success");
|
srs_verbose("st_set_eventsys use linux epoll success");
|
||||||
|
|
||||||
if(st_init() != 0){
|
if(st_init() != 0){
|
||||||
ret = ERROR_ST_INITIALIZE;
|
ret = ERROR_ST_INITIALIZE;
|
||||||
srs_error("st_init failed. ret=%d", ret);
|
srs_error("st_init failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("st_init success");
|
srs_verbose("st_init success");
|
||||||
|
|
||||||
// set current log id.
|
// set current log id.
|
||||||
log_context->generate_id();
|
log_context->generate_id();
|
||||||
srs_info("log set id success");
|
srs_info("log set id success");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsServer::listen()
|
int SrsServer::listen()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
SrsConfDirective* conf = NULL;
|
SrsConfDirective* conf = NULL;
|
||||||
|
|
||||||
// stream service port.
|
// stream service port.
|
||||||
conf = config->get_listen();
|
conf = config->get_listen();
|
||||||
srs_assert(conf);
|
srs_assert(conf);
|
||||||
|
|
||||||
close_listeners();
|
close_listeners();
|
||||||
|
|
||||||
for (int i = 0; i < (int)conf->args.size(); i++) {
|
for (int i = 0; i < (int)conf->args.size(); i++) {
|
||||||
SrsListener* listener = new SrsListener(this, SrsListenerStream);
|
SrsListener* listener = new SrsListener(this, SrsListenerStream);
|
||||||
listeners.push_back(listener);
|
listeners.push_back(listener);
|
||||||
|
|
||||||
int port = ::atoi(conf->args.at(i).c_str());
|
int port = ::atoi(conf->args.at(i).c_str());
|
||||||
if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
|
if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
|
||||||
srs_error("listen at port %d failed. ret=%d", port, ret);
|
srs_error("listen at port %d failed. ret=%d", port, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsServer::cycle()
|
int SrsServer::cycle()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// the deamon thread, update the time cache
|
// the deamon thread, update the time cache
|
||||||
while (true) {
|
while (true) {
|
||||||
st_usleep(SRS_TIME_RESOLUTION_MS * 1000);
|
st_usleep(SRS_TIME_RESOLUTION_MS * 1000);
|
||||||
srs_update_system_time_ms();
|
srs_update_system_time_ms();
|
||||||
|
|
||||||
if (signal_reload) {
|
if (signal_reload) {
|
||||||
signal_reload = false;
|
signal_reload = false;
|
||||||
srs_info("get signal reload, to reload the config.");
|
srs_info("get signal reload, to reload the config.");
|
||||||
|
|
||||||
if ((ret = config->reload()) != ERROR_SUCCESS) {
|
if ((ret = config->reload()) != ERROR_SUCCESS) {
|
||||||
srs_error("reload config failed. ret=%d", ret);
|
srs_error("reload config failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_trace("reload config success.");
|
srs_trace("reload config success.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsServer::remove(SrsConnection* conn)
|
void SrsServer::remove(SrsConnection* conn)
|
||||||
{
|
{
|
||||||
std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);
|
std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);
|
||||||
|
|
||||||
if (it != conns.end()) {
|
if (it != conns.end()) {
|
||||||
conns.erase(it);
|
conns.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_info("conn removed. conns=%d", (int)conns.size());
|
srs_info("conn removed. conns=%d", (int)conns.size());
|
||||||
|
|
||||||
// all connections are created by server,
|
// all connections are created by server,
|
||||||
// so we free it here.
|
// so we free it here.
|
||||||
srs_freep(conn);
|
srs_freep(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsServer::on_signal(int signo)
|
void SrsServer::on_signal(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGNAL_RELOAD) {
|
if (signo == SIGNAL_RELOAD) {
|
||||||
signal_reload = true;
|
signal_reload = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsServer::close_listeners()
|
void SrsServer::close_listeners()
|
||||||
{
|
{
|
||||||
std::vector<SrsListener*>::iterator it;
|
std::vector<SrsListener*>::iterator it;
|
||||||
for (it = listeners.begin(); it != listeners.end(); ++it) {
|
for (it = listeners.begin(); it != listeners.end(); ++it) {
|
||||||
SrsListener* listener = *it;
|
SrsListener* listener = *it;
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
}
|
}
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
|
int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
SrsConnection* conn = NULL;
|
SrsConnection* conn = NULL;
|
||||||
if (type == SrsListenerStream) {
|
if (type == SrsListenerStream) {
|
||||||
conn = new SrsClient(this, client_stfd);
|
conn = new SrsClient(this, client_stfd);
|
||||||
} else {
|
} else {
|
||||||
// handler others
|
// handler others
|
||||||
}
|
}
|
||||||
srs_assert(conn);
|
srs_assert(conn);
|
||||||
|
|
||||||
// directly enqueue, the cycle thread will remove the client.
|
// directly enqueue, the cycle thread will remove the client.
|
||||||
conns.push_back(conn);
|
conns.push_back(conn);
|
||||||
srs_verbose("add conn from port %d to vector. conns=%d", port, (int)conns.size());
|
srs_verbose("add conn from port %d to vector. conns=%d", port, (int)conns.size());
|
||||||
|
|
||||||
// cycle will start process thread and when finished remove the client.
|
// cycle will start process thread and when finished remove the client.
|
||||||
if ((ret = conn->start()) != ERROR_SUCCESS) {
|
if ((ret = conn->start()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
srs_verbose("conn start finished. ret=%d", ret);
|
srs_verbose("conn start finished. ret=%d", ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsServer::on_reload_listen()
|
int SrsServer::on_reload_listen()
|
||||||
{
|
{
|
||||||
return listen();
|
return listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsServer* _server()
|
SrsServer* _server()
|
||||||
{
|
{
|
||||||
static SrsServer server;
|
static SrsServer server;
|
||||||
return &server;
|
return &server;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,94 +1,94 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_SERVER_HPP
|
#ifndef SRS_CORE_SERVER_HPP
|
||||||
#define SRS_CORE_SERVER_HPP
|
#define SRS_CORE_SERVER_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_server.hpp>
|
#include <srs_core_server.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <st.h>
|
#include <st.h>
|
||||||
|
|
||||||
#include <srs_core_reload.hpp>
|
#include <srs_core_reload.hpp>
|
||||||
|
|
||||||
class SrsServer;
|
class SrsServer;
|
||||||
class SrsConnection;
|
class SrsConnection;
|
||||||
|
|
||||||
enum SrsListenerType
|
enum SrsListenerType
|
||||||
{
|
{
|
||||||
SrsListenerStream = 0,
|
SrsListenerStream = 0,
|
||||||
SrsListenerApi
|
SrsListenerApi
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsListener
|
class SrsListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsListenerType type;
|
SrsListenerType type;
|
||||||
private:
|
private:
|
||||||
int fd;
|
int fd;
|
||||||
st_netfd_t stfd;
|
st_netfd_t stfd;
|
||||||
int port;
|
int port;
|
||||||
SrsServer* server;
|
SrsServer* server;
|
||||||
st_thread_t tid;
|
st_thread_t tid;
|
||||||
bool loop;
|
bool loop;
|
||||||
public:
|
public:
|
||||||
SrsListener(SrsServer* _server, SrsListenerType _type);
|
SrsListener(SrsServer* _server, SrsListenerType _type);
|
||||||
virtual ~SrsListener();
|
virtual ~SrsListener();
|
||||||
public:
|
public:
|
||||||
virtual int listen(int port);
|
virtual int listen(int port);
|
||||||
private:
|
private:
|
||||||
virtual void listen_cycle();
|
virtual void listen_cycle();
|
||||||
static void* listen_thread(void* arg);
|
static void* listen_thread(void* arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsServer : public SrsReloadHandler
|
class SrsServer : public SrsReloadHandler
|
||||||
{
|
{
|
||||||
friend class SrsListener;
|
friend class SrsListener;
|
||||||
private:
|
private:
|
||||||
std::vector<SrsConnection*> conns;
|
std::vector<SrsConnection*> conns;
|
||||||
std::vector<SrsListener*> listeners;
|
std::vector<SrsListener*> listeners;
|
||||||
bool signal_reload;
|
bool signal_reload;
|
||||||
public:
|
public:
|
||||||
SrsServer();
|
SrsServer();
|
||||||
virtual ~SrsServer();
|
virtual ~SrsServer();
|
||||||
public:
|
public:
|
||||||
virtual int initialize();
|
virtual int initialize();
|
||||||
virtual int listen();
|
virtual int listen();
|
||||||
virtual int cycle();
|
virtual int cycle();
|
||||||
virtual void remove(SrsConnection* conn);
|
virtual void remove(SrsConnection* conn);
|
||||||
virtual void on_signal(int signo);
|
virtual void on_signal(int signo);
|
||||||
private:
|
private:
|
||||||
virtual void close_listeners();
|
virtual void close_listeners();
|
||||||
virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd);
|
virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd);
|
||||||
public:
|
public:
|
||||||
virtual int on_reload_listen();
|
virtual int on_reload_listen();
|
||||||
};
|
};
|
||||||
|
|
||||||
SrsServer* _server();
|
SrsServer* _server();
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,174 +1,174 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_socket.hpp>
|
#include <srs_core_socket.hpp>
|
||||||
|
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
|
|
||||||
SrsSocket::SrsSocket(st_netfd_t client_stfd)
|
SrsSocket::SrsSocket(st_netfd_t client_stfd)
|
||||||
{
|
{
|
||||||
stfd = client_stfd;
|
stfd = client_stfd;
|
||||||
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
|
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
|
||||||
recv_bytes = send_bytes = 0;
|
recv_bytes = send_bytes = 0;
|
||||||
start_time_ms = srs_get_system_time_ms();
|
start_time_ms = srs_get_system_time_ms();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSocket::~SrsSocket()
|
SrsSocket::~SrsSocket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsSocket::set_recv_timeout(int64_t timeout_us)
|
void SrsSocket::set_recv_timeout(int64_t timeout_us)
|
||||||
{
|
{
|
||||||
recv_timeout = timeout_us;
|
recv_timeout = timeout_us;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsSocket::get_recv_timeout()
|
int64_t SrsSocket::get_recv_timeout()
|
||||||
{
|
{
|
||||||
return recv_timeout;
|
return recv_timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsSocket::set_send_timeout(int64_t timeout_us)
|
void SrsSocket::set_send_timeout(int64_t timeout_us)
|
||||||
{
|
{
|
||||||
send_timeout = timeout_us;
|
send_timeout = timeout_us;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsSocket::get_recv_bytes()
|
int64_t SrsSocket::get_recv_bytes()
|
||||||
{
|
{
|
||||||
return recv_bytes;
|
return recv_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsSocket::get_send_bytes()
|
int64_t SrsSocket::get_send_bytes()
|
||||||
{
|
{
|
||||||
return send_bytes;
|
return send_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSocket::get_recv_kbps()
|
int SrsSocket::get_recv_kbps()
|
||||||
{
|
{
|
||||||
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
||||||
|
|
||||||
if (diff_ms <= 0) {
|
if (diff_ms <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return recv_bytes * 8 / diff_ms;
|
return recv_bytes * 8 / diff_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSocket::get_send_kbps()
|
int SrsSocket::get_send_kbps()
|
||||||
{
|
{
|
||||||
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
||||||
|
|
||||||
if (diff_ms <= 0) {
|
if (diff_ms <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return send_bytes * 8 / diff_ms;
|
return send_bytes * 8 / diff_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSocket::read(const void* buf, size_t size, ssize_t* nread)
|
int SrsSocket::read(const void* buf, size_t size, ssize_t* nread)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
*nread = st_read(stfd, (void*)buf, size, recv_timeout);
|
*nread = st_read(stfd, (void*)buf, size, recv_timeout);
|
||||||
|
|
||||||
// On success a non-negative integer indicating the number of bytes actually read is returned
|
// On success a non-negative integer indicating the number of bytes actually read is returned
|
||||||
// (a value of 0 means the network connection is closed or end of file is reached).
|
// (a value of 0 means the network connection is closed or end of file is reached).
|
||||||
if (*nread <= 0) {
|
if (*nread <= 0) {
|
||||||
if (errno == ETIME) {
|
if (errno == ETIME) {
|
||||||
return ERROR_SOCKET_TIMEOUT;
|
return ERROR_SOCKET_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*nread == 0) {
|
if (*nread == 0) {
|
||||||
errno = ECONNRESET;
|
errno = ECONNRESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SOCKET_READ;
|
return ERROR_SOCKET_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_bytes += *nread;
|
recv_bytes += *nread;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSocket::read_fully(const void* buf, size_t size, ssize_t* nread)
|
int SrsSocket::read_fully(const void* buf, size_t size, ssize_t* nread)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
*nread = st_read_fully(stfd, (void*)buf, size, recv_timeout);
|
*nread = st_read_fully(stfd, (void*)buf, size, recv_timeout);
|
||||||
|
|
||||||
// On success a non-negative integer indicating the number of bytes actually read is returned
|
// On success a non-negative integer indicating the number of bytes actually read is returned
|
||||||
// (a value less than nbyte means the network connection is closed or end of file is reached)
|
// (a value less than nbyte means the network connection is closed or end of file is reached)
|
||||||
if (*nread != (ssize_t)size) {
|
if (*nread != (ssize_t)size) {
|
||||||
if (errno == ETIME) {
|
if (errno == ETIME) {
|
||||||
return ERROR_SOCKET_TIMEOUT;
|
return ERROR_SOCKET_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*nread >= 0) {
|
if (*nread >= 0) {
|
||||||
errno = ECONNRESET;
|
errno = ECONNRESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SOCKET_READ_FULLY;
|
return ERROR_SOCKET_READ_FULLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_bytes += *nread;
|
recv_bytes += *nread;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSocket::write(const void* buf, size_t size, ssize_t* nwrite)
|
int SrsSocket::write(const void* buf, size_t size, ssize_t* nwrite)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
*nwrite = st_write(stfd, (void*)buf, size, send_timeout);
|
*nwrite = st_write(stfd, (void*)buf, size, send_timeout);
|
||||||
|
|
||||||
if (*nwrite <= 0) {
|
if (*nwrite <= 0) {
|
||||||
if (errno == ETIME) {
|
if (errno == ETIME) {
|
||||||
return ERROR_SOCKET_TIMEOUT;
|
return ERROR_SOCKET_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SOCKET_WRITE;
|
return ERROR_SOCKET_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_bytes += *nwrite;
|
send_bytes += *nwrite;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
int SrsSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
*nwrite = st_writev(stfd, iov, iov_size, send_timeout);
|
*nwrite = st_writev(stfd, iov, iov_size, send_timeout);
|
||||||
|
|
||||||
if (*nwrite <= 0) {
|
if (*nwrite <= 0) {
|
||||||
if (errno == ETIME) {
|
if (errno == ETIME) {
|
||||||
return ERROR_SOCKET_TIMEOUT;
|
return ERROR_SOCKET_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SOCKET_WRITE;
|
return ERROR_SOCKET_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_bytes += *nwrite;
|
send_bytes += *nwrite;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,66 +1,66 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_SOCKET_HPP
|
#ifndef SRS_CORE_SOCKET_HPP
|
||||||
#define SRS_CORE_SOCKET_HPP
|
#define SRS_CORE_SOCKET_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_socket.hpp>
|
#include <srs_core_socket.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <st.h>
|
#include <st.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the socket provides TCP socket over st,
|
* the socket provides TCP socket over st,
|
||||||
* that is, the sync socket mechanism.
|
* that is, the sync socket mechanism.
|
||||||
*/
|
*/
|
||||||
class SrsSocket
|
class SrsSocket
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int64_t recv_timeout;
|
int64_t recv_timeout;
|
||||||
int64_t send_timeout;
|
int64_t send_timeout;
|
||||||
int64_t recv_bytes;
|
int64_t recv_bytes;
|
||||||
int64_t send_bytes;
|
int64_t send_bytes;
|
||||||
int64_t start_time_ms;
|
int64_t start_time_ms;
|
||||||
st_netfd_t stfd;
|
st_netfd_t stfd;
|
||||||
public:
|
public:
|
||||||
SrsSocket(st_netfd_t client_stfd);
|
SrsSocket(st_netfd_t client_stfd);
|
||||||
virtual ~SrsSocket();
|
virtual ~SrsSocket();
|
||||||
public:
|
public:
|
||||||
virtual void set_recv_timeout(int64_t timeout_us);
|
virtual void set_recv_timeout(int64_t timeout_us);
|
||||||
virtual int64_t get_recv_timeout();
|
virtual int64_t get_recv_timeout();
|
||||||
virtual void set_send_timeout(int64_t timeout_us);
|
virtual void set_send_timeout(int64_t timeout_us);
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
virtual int get_recv_kbps();
|
virtual int get_recv_kbps();
|
||||||
virtual int get_send_kbps();
|
virtual int get_send_kbps();
|
||||||
public:
|
public:
|
||||||
virtual int read(const void* buf, size_t size, ssize_t* nread);
|
virtual int read(const void* buf, size_t size, ssize_t* nread);
|
||||||
virtual int read_fully(const void* buf, size_t size, ssize_t* nread);
|
virtual int read_fully(const void* buf, size_t size, ssize_t* nread);
|
||||||
virtual int write(const void* buf, size_t size, ssize_t* nwrite);
|
virtual int write(const void* buf, size_t size, ssize_t* nwrite);
|
||||||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,165 +1,165 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_SOURCE_HPP
|
#ifndef SRS_CORE_SOURCE_HPP
|
||||||
#define SRS_CORE_SOURCE_HPP
|
#define SRS_CORE_SOURCE_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_source.hpp>
|
#include <srs_core_source.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SrsCodec;
|
class SrsCodec;
|
||||||
class SrsSource;
|
class SrsSource;
|
||||||
class SrsCommonMessage;
|
class SrsCommonMessage;
|
||||||
class SrsOnMetaDataPacket;
|
class SrsOnMetaDataPacket;
|
||||||
class SrsSharedPtrMessage;
|
class SrsSharedPtrMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the consumer for SrsSource, that is a play client.
|
* the consumer for SrsSource, that is a play client.
|
||||||
*/
|
*/
|
||||||
class SrsConsumer
|
class SrsConsumer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int32_t last_pkt_time;
|
int32_t last_pkt_time;
|
||||||
int32_t last_pkt_correct_time;
|
int32_t last_pkt_correct_time;
|
||||||
SrsSource* source;
|
SrsSource* source;
|
||||||
std::vector<SrsSharedPtrMessage*> msgs;
|
std::vector<SrsSharedPtrMessage*> msgs;
|
||||||
bool paused;
|
bool paused;
|
||||||
SrsCodec* codec;
|
SrsCodec* codec;
|
||||||
public:
|
public:
|
||||||
SrsConsumer(SrsSource* _source);
|
SrsConsumer(SrsSource* _source);
|
||||||
virtual ~SrsConsumer();
|
virtual ~SrsConsumer();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* get current client time, the last packet time.
|
* get current client time, the last packet time.
|
||||||
*/
|
*/
|
||||||
virtual int get_time();
|
virtual int get_time();
|
||||||
/**
|
/**
|
||||||
* enqueue an shared ptr message.
|
* enqueue an shared ptr message.
|
||||||
* @param audio_sample_rate used to calc the audio time delta if time-jitter detected.
|
* @param audio_sample_rate used to calc the audio time delta if time-jitter detected.
|
||||||
* @param video_frame_rate used to calc the video time delta if time-jitter detected.
|
* @param video_frame_rate used to calc the video time delta if time-jitter detected.
|
||||||
*/
|
*/
|
||||||
virtual int enqueue(SrsSharedPtrMessage* msg, int audio_sample_rate, int video_frame_rate);
|
virtual int enqueue(SrsSharedPtrMessage* msg, int audio_sample_rate, int video_frame_rate);
|
||||||
/**
|
/**
|
||||||
* get packets in consumer queue.
|
* get packets in consumer queue.
|
||||||
* @pmsgs SrsMessages*[], output the prt array.
|
* @pmsgs SrsMessages*[], output the prt array.
|
||||||
* @count the count in array.
|
* @count the count in array.
|
||||||
* @max_count the max count to dequeue, 0 to dequeue all.
|
* @max_count the max count to dequeue, 0 to dequeue all.
|
||||||
*/
|
*/
|
||||||
virtual int get_packets(int max_count, SrsSharedPtrMessage**& pmsgs, int& count);
|
virtual int get_packets(int max_count, SrsSharedPtrMessage**& pmsgs, int& count);
|
||||||
/**
|
/**
|
||||||
* when client send the pause message.
|
* when client send the pause message.
|
||||||
*/
|
*/
|
||||||
virtual int on_play_client_pause(bool is_pause);
|
virtual int on_play_client_pause(bool is_pause);
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* when paused, shrink the cache queue,
|
* when paused, shrink the cache queue,
|
||||||
* remove to cache only one gop.
|
* remove to cache only one gop.
|
||||||
*/
|
*/
|
||||||
virtual void shrink();
|
virtual void shrink();
|
||||||
/**
|
/**
|
||||||
* detect the time jitter and correct it.
|
* detect the time jitter and correct it.
|
||||||
*/
|
*/
|
||||||
virtual int jitter_correct(SrsSharedPtrMessage* msg, int audio_sample_rate, int video_frame_rate);
|
virtual int jitter_correct(SrsSharedPtrMessage* msg, int audio_sample_rate, int video_frame_rate);
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* live streaming source.
|
* live streaming source.
|
||||||
*/
|
*/
|
||||||
class SrsSource
|
class SrsSource
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::map<std::string, SrsSource*> pool;
|
static std::map<std::string, SrsSource*> pool;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* find stream by vhost/app/stream.
|
* find stream by vhost/app/stream.
|
||||||
* @stream_url the stream url, for example, myserver.xxx.com/app/stream
|
* @stream_url the stream url, for example, myserver.xxx.com/app/stream
|
||||||
* @return the matched source, never be NULL.
|
* @return the matched source, never be NULL.
|
||||||
* @remark stream_url should without port and schema.
|
* @remark stream_url should without port and schema.
|
||||||
*/
|
*/
|
||||||
static SrsSource* find(std::string stream_url);
|
static SrsSource* find(std::string stream_url);
|
||||||
private:
|
private:
|
||||||
SrsCodec* codec;
|
SrsCodec* codec;
|
||||||
std::string stream_url;
|
std::string stream_url;
|
||||||
std::vector<SrsConsumer*> consumers;
|
std::vector<SrsConsumer*> consumers;
|
||||||
// gop cache for client fast startup.
|
// gop cache for client fast startup.
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* if disabled the gop cache,
|
* if disabled the gop cache,
|
||||||
* the client will wait for the next keyframe for h264,
|
* the client will wait for the next keyframe for h264,
|
||||||
* and will be black-screen.
|
* and will be black-screen.
|
||||||
*/
|
*/
|
||||||
bool enable_gop_cache;
|
bool enable_gop_cache;
|
||||||
/**
|
/**
|
||||||
* the video frame count, avoid cache for pure audio stream.
|
* the video frame count, avoid cache for pure audio stream.
|
||||||
*/
|
*/
|
||||||
int cached_video_count;
|
int cached_video_count;
|
||||||
/**
|
/**
|
||||||
* cached gop.
|
* cached gop.
|
||||||
*/
|
*/
|
||||||
std::vector<SrsSharedPtrMessage*> gop_cache;
|
std::vector<SrsSharedPtrMessage*> gop_cache;
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* the sample rate of audio in metadata.
|
* the sample rate of audio in metadata.
|
||||||
*/
|
*/
|
||||||
int audio_sample_rate;
|
int audio_sample_rate;
|
||||||
/**
|
/**
|
||||||
* the video frame rate in metadata.
|
* the video frame rate in metadata.
|
||||||
*/
|
*/
|
||||||
int video_frame_rate;
|
int video_frame_rate;
|
||||||
private:
|
private:
|
||||||
SrsSharedPtrMessage* cache_metadata;
|
SrsSharedPtrMessage* cache_metadata;
|
||||||
// the cached video sequence header.
|
// the cached video sequence header.
|
||||||
SrsSharedPtrMessage* cache_sh_video;
|
SrsSharedPtrMessage* cache_sh_video;
|
||||||
// the cached audio sequence header.
|
// the cached audio sequence header.
|
||||||
SrsSharedPtrMessage* cache_sh_audio;
|
SrsSharedPtrMessage* cache_sh_audio;
|
||||||
public:
|
public:
|
||||||
SrsSource(std::string _stream_url);
|
SrsSource(std::string _stream_url);
|
||||||
virtual ~SrsSource();
|
virtual ~SrsSource();
|
||||||
public:
|
public:
|
||||||
virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
|
virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);
|
||||||
virtual int on_audio(SrsCommonMessage* audio);
|
virtual int on_audio(SrsCommonMessage* audio);
|
||||||
virtual int on_video(SrsCommonMessage* video);
|
virtual int on_video(SrsCommonMessage* video);
|
||||||
public:
|
public:
|
||||||
virtual int create_consumer(SrsConsumer*& consumer);
|
virtual int create_consumer(SrsConsumer*& consumer);
|
||||||
virtual void on_consumer_destroy(SrsConsumer* consumer);
|
virtual void on_consumer_destroy(SrsConsumer* consumer);
|
||||||
virtual void on_unpublish();
|
virtual void on_unpublish();
|
||||||
virtual void set_cache(bool enabled);
|
virtual void set_cache(bool enabled);
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* only for h264 codec
|
* only for h264 codec
|
||||||
* 1. cache the gop when got h264 video packet.
|
* 1. cache the gop when got h264 video packet.
|
||||||
* 2. clear gop when got keyframe.
|
* 2. clear gop when got keyframe.
|
||||||
*/
|
*/
|
||||||
virtual int cache_last_gop(SrsSharedPtrMessage* msg);
|
virtual int cache_last_gop(SrsSharedPtrMessage* msg);
|
||||||
virtual void clear_gop_cache();
|
virtual void clear_gop_cache();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,202 +1,202 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_stream.hpp>
|
#include <srs_core_stream.hpp>
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
|
|
||||||
SrsStream::SrsStream()
|
SrsStream::SrsStream()
|
||||||
{
|
{
|
||||||
p = bytes = NULL;
|
p = bytes = NULL;
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStream::~SrsStream()
|
SrsStream::~SrsStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsStream::initialize(char* _bytes, int _size)
|
int SrsStream::initialize(char* _bytes, int _size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if (!_bytes) {
|
if (!_bytes) {
|
||||||
ret = ERROR_SYSTEM_STREAM_INIT;
|
ret = ERROR_SYSTEM_STREAM_INIT;
|
||||||
srs_error("stream param bytes must not be NULL. ret=%d", ret);
|
srs_error("stream param bytes must not be NULL. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_size <= 0) {
|
if (_size <= 0) {
|
||||||
ret = ERROR_SYSTEM_STREAM_INIT;
|
ret = ERROR_SYSTEM_STREAM_INIT;
|
||||||
srs_error("stream param size must be positive. ret=%d", ret);
|
srs_error("stream param size must be positive. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = _size;
|
size = _size;
|
||||||
p = bytes = _bytes;
|
p = bytes = _bytes;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::reset()
|
void SrsStream::reset()
|
||||||
{
|
{
|
||||||
p = bytes;
|
p = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsStream::empty()
|
bool SrsStream::empty()
|
||||||
{
|
{
|
||||||
return !p || !bytes || (p >= bytes + size);
|
return !p || !bytes || (p >= bytes + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsStream::require(int required_size)
|
bool SrsStream::require(int required_size)
|
||||||
{
|
{
|
||||||
return !empty() && (required_size <= bytes + size - p);
|
return !empty() && (required_size <= bytes + size - p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::skip(int size)
|
void SrsStream::skip(int size)
|
||||||
{
|
{
|
||||||
p += size;
|
p += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsStream::pos()
|
int SrsStream::pos()
|
||||||
{
|
{
|
||||||
if (empty()) {
|
if (empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p - bytes;
|
return p - bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t SrsStream::read_1bytes()
|
int8_t SrsStream::read_1bytes()
|
||||||
{
|
{
|
||||||
srs_assert(require(1));
|
srs_assert(require(1));
|
||||||
|
|
||||||
return (int8_t)*p++;
|
return (int8_t)*p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SrsStream::read_2bytes()
|
int16_t SrsStream::read_2bytes()
|
||||||
{
|
{
|
||||||
srs_assert(require(2));
|
srs_assert(require(2));
|
||||||
|
|
||||||
int16_t value;
|
int16_t value;
|
||||||
pp = (char*)&value;
|
pp = (char*)&value;
|
||||||
pp[1] = *p++;
|
pp[1] = *p++;
|
||||||
pp[0] = *p++;
|
pp[0] = *p++;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t SrsStream::read_4bytes()
|
int32_t SrsStream::read_4bytes()
|
||||||
{
|
{
|
||||||
srs_assert(require(4));
|
srs_assert(require(4));
|
||||||
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
pp = (char*)&value;
|
pp = (char*)&value;
|
||||||
pp[3] = *p++;
|
pp[3] = *p++;
|
||||||
pp[2] = *p++;
|
pp[2] = *p++;
|
||||||
pp[1] = *p++;
|
pp[1] = *p++;
|
||||||
pp[0] = *p++;
|
pp[0] = *p++;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsStream::read_8bytes()
|
int64_t SrsStream::read_8bytes()
|
||||||
{
|
{
|
||||||
srs_assert(require(8));
|
srs_assert(require(8));
|
||||||
|
|
||||||
int64_t value;
|
int64_t value;
|
||||||
pp = (char*)&value;
|
pp = (char*)&value;
|
||||||
pp[7] = *p++;
|
pp[7] = *p++;
|
||||||
pp[6] = *p++;
|
pp[6] = *p++;
|
||||||
pp[5] = *p++;
|
pp[5] = *p++;
|
||||||
pp[4] = *p++;
|
pp[4] = *p++;
|
||||||
pp[3] = *p++;
|
pp[3] = *p++;
|
||||||
pp[2] = *p++;
|
pp[2] = *p++;
|
||||||
pp[1] = *p++;
|
pp[1] = *p++;
|
||||||
pp[0] = *p++;
|
pp[0] = *p++;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SrsStream::read_string(int len)
|
std::string SrsStream::read_string(int len)
|
||||||
{
|
{
|
||||||
srs_assert(require(len));
|
srs_assert(require(len));
|
||||||
|
|
||||||
std::string value;
|
std::string value;
|
||||||
value.append(p, len);
|
value.append(p, len);
|
||||||
|
|
||||||
p += len;
|
p += len;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::write_1bytes(int8_t value)
|
void SrsStream::write_1bytes(int8_t value)
|
||||||
{
|
{
|
||||||
srs_assert(require(1));
|
srs_assert(require(1));
|
||||||
|
|
||||||
*p++ = value;
|
*p++ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::write_2bytes(int16_t value)
|
void SrsStream::write_2bytes(int16_t value)
|
||||||
{
|
{
|
||||||
srs_assert(require(2));
|
srs_assert(require(2));
|
||||||
|
|
||||||
pp = (char*)&value;
|
pp = (char*)&value;
|
||||||
*p++ = pp[1];
|
*p++ = pp[1];
|
||||||
*p++ = pp[0];
|
*p++ = pp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::write_4bytes(int32_t value)
|
void SrsStream::write_4bytes(int32_t value)
|
||||||
{
|
{
|
||||||
srs_assert(require(4));
|
srs_assert(require(4));
|
||||||
|
|
||||||
pp = (char*)&value;
|
pp = (char*)&value;
|
||||||
*p++ = pp[3];
|
*p++ = pp[3];
|
||||||
*p++ = pp[2];
|
*p++ = pp[2];
|
||||||
*p++ = pp[1];
|
*p++ = pp[1];
|
||||||
*p++ = pp[0];
|
*p++ = pp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::write_8bytes(int64_t value)
|
void SrsStream::write_8bytes(int64_t value)
|
||||||
{
|
{
|
||||||
srs_assert(require(8));
|
srs_assert(require(8));
|
||||||
|
|
||||||
pp = (char*)&value;
|
pp = (char*)&value;
|
||||||
*p++ = pp[7];
|
*p++ = pp[7];
|
||||||
*p++ = pp[6];
|
*p++ = pp[6];
|
||||||
*p++ = pp[5];
|
*p++ = pp[5];
|
||||||
*p++ = pp[4];
|
*p++ = pp[4];
|
||||||
*p++ = pp[3];
|
*p++ = pp[3];
|
||||||
*p++ = pp[2];
|
*p++ = pp[2];
|
||||||
*p++ = pp[1];
|
*p++ = pp[1];
|
||||||
*p++ = pp[0];
|
*p++ = pp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStream::write_string(std::string value)
|
void SrsStream::write_string(std::string value)
|
||||||
{
|
{
|
||||||
srs_assert(require(value.length()));
|
srs_assert(require(value.length()));
|
||||||
|
|
||||||
memcpy(p, value.data(), value.length());
|
memcpy(p, value.data(), value.length());
|
||||||
p += value.length();
|
p += value.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,121 +1,121 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRS_CORE_STREAM_HPP
|
#ifndef SRS_CORE_STREAM_HPP
|
||||||
#define SRS_CORE_STREAM_HPP
|
#define SRS_CORE_STREAM_HPP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <srs_core_stream.hpp>
|
#include <srs_core_stream.hpp>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SrsStream
|
class SrsStream
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
char* p;
|
char* p;
|
||||||
char* pp;
|
char* pp;
|
||||||
char* bytes;
|
char* bytes;
|
||||||
int size;
|
int size;
|
||||||
public:
|
public:
|
||||||
SrsStream();
|
SrsStream();
|
||||||
virtual ~SrsStream();
|
virtual ~SrsStream();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* initialize the stream from bytes.
|
* initialize the stream from bytes.
|
||||||
* @_bytes, must not be NULL, or return error.
|
* @_bytes, must not be NULL, or return error.
|
||||||
* @_size, must be positive, or return error.
|
* @_size, must be positive, or return error.
|
||||||
* @remark, stream never free the _bytes, user must free it.
|
* @remark, stream never free the _bytes, user must free it.
|
||||||
*/
|
*/
|
||||||
virtual int initialize(char* _bytes, int _size);
|
virtual int initialize(char* _bytes, int _size);
|
||||||
/**
|
/**
|
||||||
* reset the position to beginning.
|
* reset the position to beginning.
|
||||||
*/
|
*/
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
/**
|
/**
|
||||||
* whether stream is empty.
|
* whether stream is empty.
|
||||||
* if empty, never read or write.
|
* if empty, never read or write.
|
||||||
*/
|
*/
|
||||||
virtual bool empty();
|
virtual bool empty();
|
||||||
/**
|
/**
|
||||||
* whether required size is ok.
|
* whether required size is ok.
|
||||||
* @return true if stream can read/write specified required_size bytes.
|
* @return true if stream can read/write specified required_size bytes.
|
||||||
*/
|
*/
|
||||||
virtual bool require(int required_size);
|
virtual bool require(int required_size);
|
||||||
/**
|
/**
|
||||||
* to skip some size.
|
* to skip some size.
|
||||||
* @size can be any value. positive to forward; nagetive to backward.
|
* @size can be any value. positive to forward; nagetive to backward.
|
||||||
*/
|
*/
|
||||||
virtual void skip(int size);
|
virtual void skip(int size);
|
||||||
/**
|
/**
|
||||||
* tell the current pos.
|
* tell the current pos.
|
||||||
*/
|
*/
|
||||||
virtual int pos();
|
virtual int pos();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* get 1bytes char from stream.
|
* get 1bytes char from stream.
|
||||||
*/
|
*/
|
||||||
virtual int8_t read_1bytes();
|
virtual int8_t read_1bytes();
|
||||||
/**
|
/**
|
||||||
* get 2bytes int from stream.
|
* get 2bytes int from stream.
|
||||||
*/
|
*/
|
||||||
virtual int16_t read_2bytes();
|
virtual int16_t read_2bytes();
|
||||||
/**
|
/**
|
||||||
* get 4bytes int from stream.
|
* get 4bytes int from stream.
|
||||||
*/
|
*/
|
||||||
virtual int32_t read_4bytes();
|
virtual int32_t read_4bytes();
|
||||||
/**
|
/**
|
||||||
* get 8bytes int from stream.
|
* get 8bytes int from stream.
|
||||||
*/
|
*/
|
||||||
virtual int64_t read_8bytes();
|
virtual int64_t read_8bytes();
|
||||||
/**
|
/**
|
||||||
* get string from stream, length specifies by param len.
|
* get string from stream, length specifies by param len.
|
||||||
*/
|
*/
|
||||||
virtual std::string read_string(int len);
|
virtual std::string read_string(int len);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* write 1bytes char to stream.
|
* write 1bytes char to stream.
|
||||||
*/
|
*/
|
||||||
virtual void write_1bytes(int8_t value);
|
virtual void write_1bytes(int8_t value);
|
||||||
/**
|
/**
|
||||||
* write 2bytes int to stream.
|
* write 2bytes int to stream.
|
||||||
*/
|
*/
|
||||||
virtual void write_2bytes(int16_t value);
|
virtual void write_2bytes(int16_t value);
|
||||||
/**
|
/**
|
||||||
* write 4bytes int to stream.
|
* write 4bytes int to stream.
|
||||||
*/
|
*/
|
||||||
virtual void write_4bytes(int32_t value);
|
virtual void write_4bytes(int32_t value);
|
||||||
/**
|
/**
|
||||||
* write 8bytes int to stream.
|
* write 8bytes int to stream.
|
||||||
*/
|
*/
|
||||||
virtual void write_8bytes(int64_t value);
|
virtual void write_8bytes(int64_t value);
|
||||||
/**
|
/**
|
||||||
* write string to stream
|
* write string to stream
|
||||||
*/
|
*/
|
||||||
virtual void write_string(std::string value);
|
virtual void write_string(std::string value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,60 +1,60 @@
|
||||||
/*
|
/*
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013 winlin
|
Copyright (c) 2013 winlin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
the Software without restriction, including without limitation the rights to
|
the Software without restriction, including without limitation the rights to
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
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,
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
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
|
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
|
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.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_server.hpp>
|
#include <srs_core_server.hpp>
|
||||||
#include <srs_core_config.hpp>
|
#include <srs_core_config.hpp>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
void handler(int signo)
|
void handler(int signo)
|
||||||
{
|
{
|
||||||
srs_trace("get a signal, signo=%d", signo);
|
srs_trace("get a signal, signo=%d", signo);
|
||||||
_server()->on_signal(signo);
|
_server()->on_signal(signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
signal(SIGNAL_RELOAD, handler);
|
signal(SIGNAL_RELOAD, handler);
|
||||||
|
|
||||||
if ((ret = config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
if ((ret = config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = _server()->initialize()) != ERROR_SUCCESS) {
|
if ((ret = _server()->initialize()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = _server()->listen()) != ERROR_SUCCESS) {
|
if ((ret = _server()->listen()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = _server()->cycle()) != ERROR_SUCCESS) {
|
if ((ret = _server()->cycle()) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +1,49 @@
|
||||||
file
|
file
|
||||||
main readonly separator,
|
main readonly separator,
|
||||||
..\main\srs_main_server.cpp,
|
..\main\srs_main_server.cpp,
|
||||||
core readonly separator,
|
core readonly separator,
|
||||||
..\core\srs_core.hpp,
|
..\core\srs_core.hpp,
|
||||||
..\core\srs_core.cpp,
|
..\core\srs_core.cpp,
|
||||||
..\core\srs_core_error.hpp,
|
..\core\srs_core_error.hpp,
|
||||||
..\core\srs_core_error.cpp,
|
..\core\srs_core_error.cpp,
|
||||||
..\core\srs_core_autofree.hpp,
|
..\core\srs_core_autofree.hpp,
|
||||||
..\core\srs_core_autofree.cpp,
|
..\core\srs_core_autofree.cpp,
|
||||||
..\core\srs_core_server.hpp,
|
..\core\srs_core_server.hpp,
|
||||||
..\core\srs_core_server.cpp,
|
..\core\srs_core_server.cpp,
|
||||||
..\core\srs_core_reload.hpp,
|
..\core\srs_core_reload.hpp,
|
||||||
..\core\srs_core_reload.cpp,
|
..\core\srs_core_reload.cpp,
|
||||||
..\core\srs_core_config.hpp,
|
..\core\srs_core_config.hpp,
|
||||||
..\core\srs_core_config.cpp,
|
..\core\srs_core_config.cpp,
|
||||||
..\core\srs_core_refer.hpp,
|
..\core\srs_core_refer.hpp,
|
||||||
..\core\srs_core_refer.cpp,
|
..\core\srs_core_refer.cpp,
|
||||||
..\core\srs_core_conn.hpp,
|
..\core\srs_core_conn.hpp,
|
||||||
..\core\srs_core_conn.cpp,
|
..\core\srs_core_conn.cpp,
|
||||||
..\core\srs_core_client.hpp,
|
..\core\srs_core_client.hpp,
|
||||||
..\core\srs_core_client.cpp,
|
..\core\srs_core_client.cpp,
|
||||||
..\core\srs_core_source.hpp,
|
..\core\srs_core_source.hpp,
|
||||||
..\core\srs_core_source.cpp,
|
..\core\srs_core_source.cpp,
|
||||||
..\core\srs_core_codec.hpp,
|
..\core\srs_core_codec.hpp,
|
||||||
..\core\srs_core_codec.cpp,
|
..\core\srs_core_codec.cpp,
|
||||||
..\core\srs_core_rtmp.hpp,
|
..\core\srs_core_rtmp.hpp,
|
||||||
..\core\srs_core_rtmp.cpp,
|
..\core\srs_core_rtmp.cpp,
|
||||||
..\core\srs_core_handshake.hpp,
|
..\core\srs_core_handshake.hpp,
|
||||||
..\core\srs_core_handshake.cpp,
|
..\core\srs_core_handshake.cpp,
|
||||||
..\core\srs_core_protocol.hpp,
|
..\core\srs_core_protocol.hpp,
|
||||||
..\core\srs_core_protocol.cpp,
|
..\core\srs_core_protocol.cpp,
|
||||||
..\core\srs_core_amf0.hpp,
|
..\core\srs_core_amf0.hpp,
|
||||||
..\core\srs_core_amf0.cpp,
|
..\core\srs_core_amf0.cpp,
|
||||||
..\core\srs_core_stream.hpp,
|
..\core\srs_core_stream.hpp,
|
||||||
..\core\srs_core_stream.cpp,
|
..\core\srs_core_stream.cpp,
|
||||||
..\core\srs_core_socket.hpp,
|
..\core\srs_core_socket.hpp,
|
||||||
..\core\srs_core_socket.cpp,
|
..\core\srs_core_socket.cpp,
|
||||||
..\core\srs_core_buffer.hpp,
|
..\core\srs_core_buffer.hpp,
|
||||||
..\core\srs_core_buffer.cpp,
|
..\core\srs_core_buffer.cpp,
|
||||||
..\core\srs_core_pithy_print.hpp,
|
..\core\srs_core_pithy_print.hpp,
|
||||||
..\core\srs_core_pithy_print.cpp,
|
..\core\srs_core_pithy_print.cpp,
|
||||||
..\core\srs_core_log.hpp,
|
..\core\srs_core_log.hpp,
|
||||||
..\core\srs_core_log.cpp,
|
..\core\srs_core_log.cpp,
|
||||||
research readonly separator,
|
research readonly separator,
|
||||||
..\..\research\ts_info.cc;
|
..\..\research\ts_info.cc;
|
||||||
mainconfig
|
mainconfig
|
||||||
"" = "MAIN";
|
"" = "MAIN";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue