mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
substitute all TAB with 4spaces.
This commit is contained in:
parent
e5770b10b1
commit
c85dde7f3f
64 changed files with 14105 additions and 14105 deletions
|
@ -34,25 +34,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <sys/uio.h>
|
||||
|
||||
#ifndef ST_UTIME_NO_TIMEOUT
|
||||
#define ST_UTIME_NO_TIMEOUT -1
|
||||
#define ST_UTIME_NO_TIMEOUT -1
|
||||
#endif
|
||||
|
||||
SimpleSocketStream::SimpleSocketStream()
|
||||
{
|
||||
fd = -1;
|
||||
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
|
||||
recv_bytes = send_bytes = 0;
|
||||
|
||||
srs_update_system_time_ms();
|
||||
start_time_ms = srs_get_system_time_ms();
|
||||
fd = -1;
|
||||
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
|
||||
recv_bytes = send_bytes = 0;
|
||||
|
||||
srs_update_system_time_ms();
|
||||
start_time_ms = srs_get_system_time_ms();
|
||||
}
|
||||
|
||||
SimpleSocketStream::~SimpleSocketStream()
|
||||
{
|
||||
if (fd != -1) {
|
||||
::close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
if (fd != -1) {
|
||||
::close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int SimpleSocketStream::create_socket()
|
||||
|
@ -61,7 +61,7 @@ int SimpleSocketStream::create_socket()
|
|||
return -1;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int SimpleSocketStream::connect(const char* server_ip, int port)
|
||||
|
@ -75,23 +75,23 @@ int SimpleSocketStream::connect(const char* server_ip, int port)
|
|||
return -1;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
// ISrsBufferReader
|
||||
int SimpleSocketStream::read(const void* buf, size_t size, ssize_t* nread)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
*nread = ::recv(fd, (void*)buf, size, 0);
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
*nread = ::recv(fd, (void*)buf, size, 0);
|
||||
|
||||
// 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).
|
||||
if (*nread <= 0) {
|
||||
if (errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
if (errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
if (*nread == 0) {
|
||||
errno = ECONNRESET;
|
||||
}
|
||||
|
@ -100,131 +100,131 @@ int SimpleSocketStream::read(const void* buf, size_t size, ssize_t* nread)
|
|||
}
|
||||
|
||||
recv_bytes += *nread;
|
||||
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ISrsProtocolReader
|
||||
void SimpleSocketStream::set_recv_timeout(int64_t timeout_us)
|
||||
{
|
||||
recv_timeout = timeout_us;
|
||||
recv_timeout = timeout_us;
|
||||
}
|
||||
|
||||
int64_t SimpleSocketStream::get_recv_timeout()
|
||||
{
|
||||
return recv_timeout;
|
||||
return recv_timeout;
|
||||
}
|
||||
|
||||
int64_t SimpleSocketStream::get_recv_bytes()
|
||||
{
|
||||
return recv_bytes;
|
||||
return recv_bytes;
|
||||
}
|
||||
|
||||
int SimpleSocketStream::get_recv_kbps()
|
||||
{
|
||||
srs_update_system_time_ms();
|
||||
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
||||
|
||||
if (diff_ms <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return recv_bytes * 8 / diff_ms;
|
||||
srs_update_system_time_ms();
|
||||
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
||||
|
||||
if (diff_ms <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return recv_bytes * 8 / diff_ms;
|
||||
}
|
||||
|
||||
// ISrsProtocolWriter
|
||||
void SimpleSocketStream::set_send_timeout(int64_t timeout_us)
|
||||
{
|
||||
send_timeout = timeout_us;
|
||||
send_timeout = timeout_us;
|
||||
}
|
||||
|
||||
int64_t SimpleSocketStream::get_send_timeout()
|
||||
{
|
||||
return send_timeout;
|
||||
return send_timeout;
|
||||
}
|
||||
|
||||
int64_t SimpleSocketStream::get_send_bytes()
|
||||
{
|
||||
return send_bytes;
|
||||
return send_bytes;
|
||||
}
|
||||
|
||||
int SimpleSocketStream::get_send_kbps()
|
||||
{
|
||||
srs_update_system_time_ms();
|
||||
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
||||
|
||||
if (diff_ms <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return send_bytes * 8 / diff_ms;
|
||||
srs_update_system_time_ms();
|
||||
int64_t diff_ms = srs_get_system_time_ms() - start_time_ms;
|
||||
|
||||
if (diff_ms <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return send_bytes * 8 / diff_ms;
|
||||
}
|
||||
|
||||
int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
*nwrite = ::writev(fd, iov, iov_size);
|
||||
|
||||
if (*nwrite <= 0) {
|
||||
if (errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
if (errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
return ERROR_SOCKET_WRITE;
|
||||
}
|
||||
|
||||
send_bytes += *nwrite;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ISrsProtocolReaderWriter
|
||||
bool SimpleSocketStream::is_never_timeout(int64_t timeout_us)
|
||||
{
|
||||
return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT;
|
||||
return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT;
|
||||
}
|
||||
|
||||
int SimpleSocketStream::read_fully(const void* buf, size_t size, ssize_t* nread)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
size_t left = size;
|
||||
*nread = 0;
|
||||
|
||||
while (left > 0) {
|
||||
char* this_buf = (char*)buf + *nread;
|
||||
ssize_t this_nread;
|
||||
|
||||
if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*nread += this_nread;
|
||||
left -= this_nread;
|
||||
}
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
size_t left = size;
|
||||
*nread = 0;
|
||||
|
||||
while (left > 0) {
|
||||
char* this_buf = (char*)buf + *nread;
|
||||
ssize_t this_nread;
|
||||
|
||||
if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
*nread += this_nread;
|
||||
left -= this_nread;
|
||||
}
|
||||
|
||||
recv_bytes += *nread;
|
||||
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SimpleSocketStream::write(const void* buf, size_t size, ssize_t* nwrite)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
*nwrite = ::send(fd, (void*)buf, size, 0);
|
||||
|
||||
if (*nwrite <= 0) {
|
||||
if (errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
if (errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
return ERROR_SOCKET_WRITE;
|
||||
}
|
||||
|
||||
send_bytes += *nwrite;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,37 +39,37 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
class SimpleSocketStream : public ISrsProtocolReaderWriter
|
||||
{
|
||||
private:
|
||||
int64_t start_time_ms;
|
||||
int64_t recv_timeout;
|
||||
int64_t send_timeout;
|
||||
int64_t recv_bytes;
|
||||
int64_t send_bytes;
|
||||
int fd;
|
||||
int64_t start_time_ms;
|
||||
int64_t recv_timeout;
|
||||
int64_t send_timeout;
|
||||
int64_t recv_bytes;
|
||||
int64_t send_bytes;
|
||||
int fd;
|
||||
public:
|
||||
SimpleSocketStream();
|
||||
virtual ~SimpleSocketStream();
|
||||
public:
|
||||
virtual int create_socket();
|
||||
virtual int connect(const char* server, int port);
|
||||
virtual int create_socket();
|
||||
virtual int connect(const char* server, int port);
|
||||
// ISrsBufferReader
|
||||
public:
|
||||
virtual int read(const void* buf, size_t size, ssize_t* nread);
|
||||
// ISrsProtocolReader
|
||||
public:
|
||||
virtual void set_recv_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_recv_timeout();
|
||||
virtual int64_t get_recv_bytes();
|
||||
virtual int get_recv_kbps();
|
||||
virtual void set_recv_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_recv_timeout();
|
||||
virtual int64_t get_recv_bytes();
|
||||
virtual int get_recv_kbps();
|
||||
// ISrsProtocolWriter
|
||||
public:
|
||||
virtual void set_send_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_send_timeout();
|
||||
virtual int64_t get_send_bytes();
|
||||
virtual int get_send_kbps();
|
||||
virtual void set_send_timeout(int64_t timeout_us);
|
||||
virtual int64_t get_send_timeout();
|
||||
virtual int64_t get_send_bytes();
|
||||
virtual int get_send_kbps();
|
||||
virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);
|
||||
// ISrsProtocolReaderWriter
|
||||
public:
|
||||
virtual bool is_never_timeout(int64_t timeout_us);
|
||||
virtual bool is_never_timeout(int64_t timeout_us);
|
||||
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);
|
||||
};
|
||||
|
|
|
@ -38,9 +38,9 @@ using namespace std;
|
|||
|
||||
// if user want to define log, define the folowing macro.
|
||||
#ifndef SRS_RTMP_USER_DEFINED_LOG
|
||||
// kernel module.
|
||||
ISrsLog* _srs_log = new ISrsLog();
|
||||
ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
||||
// kernel module.
|
||||
ISrsLog* _srs_log = new ISrsLog();
|
||||
ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -48,14 +48,14 @@ using namespace std;
|
|||
*/
|
||||
struct Context
|
||||
{
|
||||
std::string url;
|
||||
std::string tcUrl;
|
||||
std::string host;
|
||||
std::string port;
|
||||
std::string vhost;
|
||||
std::string app;
|
||||
std::string stream;
|
||||
|
||||
std::string url;
|
||||
std::string tcUrl;
|
||||
std::string host;
|
||||
std::string port;
|
||||
std::string vhost;
|
||||
std::string app;
|
||||
std::string stream;
|
||||
|
||||
SrsRtmpClient* rtmp;
|
||||
SimpleSocketStream* skt;
|
||||
int stream_id;
|
||||
|
@ -73,68 +73,68 @@ struct Context
|
|||
|
||||
int srs_librtmp_context_connect(Context* context)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// parse uri
|
||||
size_t pos = string::npos;
|
||||
string uri = context->url;
|
||||
// tcUrl, stream
|
||||
if ((pos = uri.rfind("/")) != string::npos) {
|
||||
context->stream = uri.substr(pos + 1);
|
||||
context->tcUrl = uri = uri.substr(0, pos);
|
||||
}
|
||||
// schema
|
||||
if ((pos = uri.find("rtmp://")) != string::npos) {
|
||||
uri = uri.substr(pos + 7);
|
||||
}
|
||||
// host/vhost/port
|
||||
if ((pos = uri.find(":")) != string::npos) {
|
||||
context->vhost = context->host = uri.substr(0, pos);
|
||||
uri = uri.substr(pos + 1);
|
||||
|
||||
if ((pos = uri.find("/")) != string::npos) {
|
||||
context->port = uri.substr(0, pos);
|
||||
uri = uri.substr(pos + 1);
|
||||
}
|
||||
} else {
|
||||
if ((pos = uri.find("/")) != string::npos) {
|
||||
context->vhost = context->host = uri.substr(0, pos);
|
||||
uri = uri.substr(pos + 1);
|
||||
}
|
||||
context->port = RTMP_DEFAULT_PORT;
|
||||
}
|
||||
// app
|
||||
context->app = uri;
|
||||
// query of app
|
||||
if ((pos = uri.find("?")) != string::npos) {
|
||||
context->app = uri.substr(0, pos);
|
||||
string query = uri.substr(pos + 1);
|
||||
if ((pos = query.find("vhost=")) != string::npos) {
|
||||
context->vhost = query.substr(pos + 6);
|
||||
if ((pos = context->vhost.find("&")) != string::npos) {
|
||||
context->vhost = context->vhost.substr(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
size_t pos = string::npos;
|
||||
string uri = context->url;
|
||||
// tcUrl, stream
|
||||
if ((pos = uri.rfind("/")) != string::npos) {
|
||||
context->stream = uri.substr(pos + 1);
|
||||
context->tcUrl = uri = uri.substr(0, pos);
|
||||
}
|
||||
// schema
|
||||
if ((pos = uri.find("rtmp://")) != string::npos) {
|
||||
uri = uri.substr(pos + 7);
|
||||
}
|
||||
// host/vhost/port
|
||||
if ((pos = uri.find(":")) != string::npos) {
|
||||
context->vhost = context->host = uri.substr(0, pos);
|
||||
uri = uri.substr(pos + 1);
|
||||
|
||||
if ((pos = uri.find("/")) != string::npos) {
|
||||
context->port = uri.substr(0, pos);
|
||||
uri = uri.substr(pos + 1);
|
||||
}
|
||||
} else {
|
||||
if ((pos = uri.find("/")) != string::npos) {
|
||||
context->vhost = context->host = uri.substr(0, pos);
|
||||
uri = uri.substr(pos + 1);
|
||||
}
|
||||
context->port = RTMP_DEFAULT_PORT;
|
||||
}
|
||||
// app
|
||||
context->app = uri;
|
||||
// query of app
|
||||
if ((pos = uri.find("?")) != string::npos) {
|
||||
context->app = uri.substr(0, pos);
|
||||
string query = uri.substr(pos + 1);
|
||||
if ((pos = query.find("vhost=")) != string::npos) {
|
||||
context->vhost = query.substr(pos + 6);
|
||||
if ((pos = context->vhost.find("&")) != string::npos) {
|
||||
context->vhost = context->vhost.substr(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create socket
|
||||
srs_freep(context->skt);
|
||||
context->skt = new SimpleSocketStream();
|
||||
|
||||
if ((ret = context->skt->create_socket()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// connect to server:port
|
||||
string server = srs_dns_resolve(context->host);
|
||||
if (server.empty()) {
|
||||
return -1;
|
||||
}
|
||||
if ((ret = context->skt->connect(server.c_str(), ::atoi(context->port.c_str()))) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
srs_freep(context->skt);
|
||||
context->skt = new SimpleSocketStream();
|
||||
|
||||
if ((ret = context->skt->create_socket()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// connect to server:port
|
||||
string server = srs_dns_resolve(context->host);
|
||||
if (server.empty()) {
|
||||
return -1;
|
||||
}
|
||||
if ((ret = context->skt->connect(server.c_str(), ::atoi(context->port.c_str()))) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -144,7 +144,7 @@ extern "C"{
|
|||
srs_rtmp_t srs_rtmp_create(const char* url)
|
||||
{
|
||||
Context* context = new Context();
|
||||
context->url = url;
|
||||
context->url = url;
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -158,8 +158,8 @@ void srs_rtmp_destroy(srs_rtmp_t rtmp)
|
|||
|
||||
int srs_simple_handshake(srs_rtmp_t rtmp)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
|
@ -167,26 +167,26 @@ int srs_simple_handshake(srs_rtmp_t rtmp)
|
|||
if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// simple handshake
|
||||
srs_freep(context->rtmp);
|
||||
context->rtmp = new SrsRtmpClient(context->skt);
|
||||
|
||||
if ((ret = context->rtmp->simple_handshake()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
// simple handshake
|
||||
srs_freep(context->rtmp);
|
||||
context->rtmp = new SrsRtmpClient(context->skt);
|
||||
|
||||
if ((ret = context->rtmp->simple_handshake()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_complex_handshake(srs_rtmp_t rtmp)
|
||||
{
|
||||
#ifndef SRS_SSL
|
||||
return ERROR_RTMP_HS_SSL_REQUIRE;
|
||||
return ERROR_RTMP_HS_SSL_REQUIRE;
|
||||
#endif
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
|
@ -194,43 +194,43 @@ int srs_complex_handshake(srs_rtmp_t rtmp)
|
|||
if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// complex handshake
|
||||
srs_freep(context->rtmp);
|
||||
context->rtmp = new SrsRtmpClient(context->skt);
|
||||
|
||||
if ((ret = context->rtmp->complex_handshake()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
// complex handshake
|
||||
srs_freep(context->rtmp);
|
||||
context->rtmp = new SrsRtmpClient(context->skt);
|
||||
|
||||
if ((ret = context->rtmp->complex_handshake()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_connect_app(srs_rtmp_t rtmp)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
string tcUrl = "rtmp://";
|
||||
tcUrl += context->vhost;
|
||||
tcUrl += ":";
|
||||
tcUrl += context->port;
|
||||
tcUrl += "/";
|
||||
tcUrl += context->app;
|
||||
|
||||
if ((ret = context->rtmp->connect_app(context->app, tcUrl)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
string tcUrl = "rtmp://";
|
||||
tcUrl += context->vhost;
|
||||
tcUrl += ":";
|
||||
tcUrl += context->port;
|
||||
tcUrl += "/";
|
||||
tcUrl += context->app;
|
||||
|
||||
if ((ret = context->rtmp->connect_app(context->app, tcUrl)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_play_stream(srs_rtmp_t rtmp)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
|
@ -241,13 +241,13 @@ int srs_play_stream(srs_rtmp_t rtmp)
|
|||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_publish_stream(srs_rtmp_t rtmp)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
|
@ -255,30 +255,30 @@ int srs_publish_stream(srs_rtmp_t rtmp)
|
|||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* srs_type2string(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SRS_RTMP_TYPE_AUDIO: return "Audio";
|
||||
case SRS_RTMP_TYPE_VIDEO: return "Video";
|
||||
case SRS_RTMP_TYPE_SCRIPT: return "Data";
|
||||
default: return "Unknown";
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
switch (type) {
|
||||
case SRS_RTMP_TYPE_AUDIO: return "Audio";
|
||||
case SRS_RTMP_TYPE_VIDEO: return "Video";
|
||||
case SRS_RTMP_TYPE_SCRIPT: return "Data";
|
||||
default: return "Unknown";
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** data, int* size)
|
||||
{
|
||||
*type = 0;
|
||||
*timestamp = 0;
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
*type = 0;
|
||||
*timestamp = 0;
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
|
@ -322,81 +322,81 @@ int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** dat
|
|||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, int size)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
SrsSharedPtrMessage* msg = NULL;
|
||||
|
||||
if (type == SRS_RTMP_TYPE_AUDIO) {
|
||||
SrsMessageHeader header;
|
||||
header.initialize_audio(size, timestamp, context->stream_id);
|
||||
|
||||
msg = new SrsSharedPtrMessage();
|
||||
if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) {
|
||||
srs_freepa(data);
|
||||
return ret;
|
||||
}
|
||||
} else if (type == SRS_RTMP_TYPE_VIDEO) {
|
||||
SrsMessageHeader header;
|
||||
header.initialize_video(size, timestamp, context->stream_id);
|
||||
|
||||
msg = new SrsSharedPtrMessage();
|
||||
if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) {
|
||||
srs_freepa(data);
|
||||
return ret;
|
||||
}
|
||||
} else if (type == SRS_RTMP_TYPE_SCRIPT) {
|
||||
SrsMessageHeader header;
|
||||
header.initialize_amf0_script(size, context->stream_id);
|
||||
|
||||
msg = new SrsSharedPtrMessage();
|
||||
if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) {
|
||||
srs_freepa(data);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
// send out encoded msg.
|
||||
if ((ret = context->rtmp->send_message(msg)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
// directly free data if not sent out.
|
||||
srs_freepa(data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
SrsSharedPtrMessage* msg = NULL;
|
||||
|
||||
if (type == SRS_RTMP_TYPE_AUDIO) {
|
||||
SrsMessageHeader header;
|
||||
header.initialize_audio(size, timestamp, context->stream_id);
|
||||
|
||||
msg = new SrsSharedPtrMessage();
|
||||
if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) {
|
||||
srs_freepa(data);
|
||||
return ret;
|
||||
}
|
||||
} else if (type == SRS_RTMP_TYPE_VIDEO) {
|
||||
SrsMessageHeader header;
|
||||
header.initialize_video(size, timestamp, context->stream_id);
|
||||
|
||||
msg = new SrsSharedPtrMessage();
|
||||
if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) {
|
||||
srs_freepa(data);
|
||||
return ret;
|
||||
}
|
||||
} else if (type == SRS_RTMP_TYPE_SCRIPT) {
|
||||
SrsMessageHeader header;
|
||||
header.initialize_amf0_script(size, context->stream_id);
|
||||
|
||||
msg = new SrsSharedPtrMessage();
|
||||
if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) {
|
||||
srs_freepa(data);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
// send out encoded msg.
|
||||
if ((ret = context->rtmp->send_message(msg)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
// directly free data if not sent out.
|
||||
srs_freepa(data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_ssl_enabled()
|
||||
{
|
||||
#ifndef SRS_SSL
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int srs_version_major()
|
||||
{
|
||||
return ::atoi(VERSION_MAJOR);
|
||||
return ::atoi(VERSION_MAJOR);
|
||||
}
|
||||
|
||||
int srs_version_minor()
|
||||
{
|
||||
return ::atoi(VERSION_MINOR);
|
||||
return ::atoi(VERSION_MINOR);
|
||||
}
|
||||
|
||||
int srs_version_revision()
|
||||
{
|
||||
return ::atoi(VERSION_REVISION);
|
||||
return ::atoi(VERSION_REVISION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef void* srs_rtmp_t;
|
|||
/**
|
||||
* create/destroy a rtmp protocol stack.
|
||||
* @url rtmp url, for example:
|
||||
* rtmp://127.0.0.1/live/livestream
|
||||
* rtmp://127.0.0.1/live/livestream
|
||||
* @return a rtmp handler, or NULL if error occured.
|
||||
*/
|
||||
srs_rtmp_t srs_rtmp_create(const char* url);
|
||||
|
@ -113,23 +113,23 @@ int srs_publish_stream(srs_rtmp_t rtmp);
|
|||
#define SRS_RTMP_TYPE_SCRIPT 18
|
||||
/**
|
||||
* convert the flv tag type to string.
|
||||
* SRS_RTMP_TYPE_AUDIO to "Audio"
|
||||
* SRS_RTMP_TYPE_VIDEO to "Video"
|
||||
* SRS_RTMP_TYPE_SCRIPT to "Data"
|
||||
* otherwise, "Unknown"
|
||||
* SRS_RTMP_TYPE_AUDIO to "Audio"
|
||||
* SRS_RTMP_TYPE_VIDEO to "Video"
|
||||
* SRS_RTMP_TYPE_SCRIPT to "Data"
|
||||
* otherwise, "Unknown"
|
||||
*/
|
||||
const char* srs_type2string(int type);
|
||||
/**
|
||||
* read a audio/video/script-data packet from rtmp stream.
|
||||
* @param type, output the packet type, macros:
|
||||
* SRS_RTMP_TYPE_AUDIO, FlvTagAudio
|
||||
* SRS_RTMP_TYPE_VIDEO, FlvTagVideo
|
||||
* SRS_RTMP_TYPE_SCRIPT, FlvTagScript
|
||||
* SRS_RTMP_TYPE_AUDIO, FlvTagAudio
|
||||
* SRS_RTMP_TYPE_VIDEO, FlvTagVideo
|
||||
* SRS_RTMP_TYPE_SCRIPT, FlvTagScript
|
||||
* @param timestamp, in ms, overflow in 50days
|
||||
* @param data, the packet data, according to type:
|
||||
* FlvTagAudio, @see "E.4.2.1 AUDIODATA"
|
||||
* FlvTagVideo, @see "E.4.3.1 VIDEODATA"
|
||||
* FlvTagScript, @see "E.4.4.1 SCRIPTDATA"
|
||||
* FlvTagAudio, @see "E.4.2.1 AUDIODATA"
|
||||
* FlvTagVideo, @see "E.4.3.1 VIDEODATA"
|
||||
* FlvTagScript, @see "E.4.4.1 SCRIPTDATA"
|
||||
* @param size, size of packet.
|
||||
* @return the error code. 0 for success; otherwise, error.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue