1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #742, use ms for application clock tbn.

This commit is contained in:
winlin 2017-01-17 12:25:30 +08:00
parent dca9749f37
commit 3fe338d1c5
43 changed files with 437 additions and 435 deletions

View file

@ -66,24 +66,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <errno.h>
#include <srs_kernel_utility.hpp>
#ifndef ST_UTIME_NO_TIMEOUT
#define ST_UTIME_NO_TIMEOUT -1
#endif
#include <srs_kernel_consts.hpp>
// when io not hijacked, use simple socket, the block sync stream.
#ifndef SRS_HIJACK_IO
struct SrsBlockSyncSocket
{
SOCKET fd;
int64_t recv_timeout;
int64_t send_timeout;
int64_t recv_bytes;
int64_t send_bytes;
int64_t rbytes;
int64_t sbytes;
// The send/recv timeout in ms.
int64_t rtm;
int64_t stm;
SrsBlockSyncSocket() {
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0;
stm = rtm = SRS_CONSTS_NO_TMMS;
rbytes = sbytes = 0;
SOCKET_RESET(fd);
SOCKET_SETUP();
@ -156,66 +154,75 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return ERROR_SOCKET_READ;
}
skt->recv_bytes += nb_read;
skt->rbytes += nb_read;
return ret;
}
int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm)
{
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
int sec = (int)(timeout_us / 1000000LL);
int microsec = (int)(timeout_us % 1000000LL);
// The default for this option is zero,
// which indicates that a receive operation shall not time out.
int32_t sec = 0;
int32_t usec = 0;
sec = srs_max(0, sec);
microsec = srs_max(0, microsec);
if (tm != SRS_CONSTS_NO_TMMS) {
sec = (int32_t)(tm / 1000);
usec = (int32_t)((tm % 1000)*1000);
}
struct timeval tv = { sec , microsec };
struct timeval tv = { sec , usec };
if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
return SOCKET_ERRNO();
}
skt->recv_timeout = timeout_us;
skt->rtm = tm;
return ERROR_SUCCESS;
}
int64_t srs_hijack_io_get_recv_timeout(srs_hijack_io_t ctx)
{
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
return skt->recv_timeout;
return skt->rtm;
}
int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx)
{
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
return skt->recv_bytes;
return skt->rbytes;
}
int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm)
{
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
int sec = (int)(timeout_us / 1000000LL);
int microsec = (int)(timeout_us % 1000000LL);
sec = srs_max(0, sec);
microsec = srs_max(0, microsec);
struct timeval tv = { sec , microsec };
// The default for this option is zero,
// which indicates that a receive operation shall not time out.
int32_t sec = 0;
int32_t usec = 0;
if (tm != SRS_CONSTS_NO_TMMS) {
sec = (int32_t)(tm / 1000);
usec = (int32_t)((tm % 1000)*1000);
}
struct timeval tv = { sec , usec };
if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) {
return SOCKET_ERRNO();
}
skt->send_timeout = timeout_us;
skt->stm = tm;
return ERROR_SUCCESS;
}
int64_t srs_hijack_io_get_send_timeout(srs_hijack_io_t ctx)
{
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
return skt->send_timeout;
return skt->stm;
}
int64_t srs_hijack_io_get_send_bytes(srs_hijack_io_t ctx)
{
SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
return skt->send_bytes;
return skt->sbytes;
}
int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite)
{
@ -241,13 +248,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return ERROR_SOCKET_WRITE;
}
skt->send_bytes += nb_write;
skt->sbytes += nb_write;
return ret;
}
bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm)
{
return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT;
return tm == SRS_CONSTS_NO_TMMS;
}
int srs_hijack_io_read_fully(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread)
{
@ -273,7 +280,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if (nread) {
*nread = nb_read;
}
skt->recv_bytes += nb_read;
skt->rbytes += nb_read;
return ret;
}
@ -298,7 +305,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return ERROR_SOCKET_WRITE;
}
skt->send_bytes += nb_write;
skt->sbytes += nb_write;
return ret;
}
@ -342,10 +349,10 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread)
}
// ISrsProtocolReader
void SimpleSocketStream::set_recv_timeout(int64_t timeout_us)
void SimpleSocketStream::set_recv_timeout(int64_t tm)
{
srs_assert(io);
srs_hijack_io_set_recv_timeout(io, timeout_us);
srs_hijack_io_set_recv_timeout(io, tm);
}
int64_t SimpleSocketStream::get_recv_timeout()
@ -361,10 +368,10 @@ int64_t SimpleSocketStream::get_recv_bytes()
}
// ISrsProtocolWriter
void SimpleSocketStream::set_send_timeout(int64_t timeout_us)
void SimpleSocketStream::set_send_timeout(int64_t tm)
{
srs_assert(io);
srs_hijack_io_set_send_timeout(io, timeout_us);
srs_hijack_io_set_send_timeout(io, tm);
}
int64_t SimpleSocketStream::get_send_timeout()
@ -386,10 +393,10 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
}
// ISrsProtocolReaderWriter
bool SimpleSocketStream::is_never_timeout(int64_t timeout_us)
bool SimpleSocketStream::is_never_timeout(int64_t tm)
{
srs_assert(io);
return srs_hijack_io_is_never_timeout(io, timeout_us);
return srs_hijack_io_is_never_timeout(io, tm);
}
int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread)

View file

@ -58,18 +58,18 @@ public:
virtual int read(void* buf, size_t size, ssize_t* nread);
// ISrsProtocolReader
public:
virtual void set_recv_timeout(int64_t timeout_us);
virtual void set_recv_timeout(int64_t tm);
virtual int64_t get_recv_timeout();
virtual int64_t get_recv_bytes();
// ISrsProtocolWriter
public:
virtual void set_send_timeout(int64_t timeout_us);
virtual void set_send_timeout(int64_t tm);
virtual int64_t get_send_timeout();
virtual int64_t get_send_bytes();
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 tm);
virtual int read_fully(void* buf, size_t size, ssize_t* nread);
virtual int write(void* buf, size_t size, ssize_t* nwrite);
};

View file

@ -54,8 +54,8 @@ using namespace std;
ISrsLog* _srs_log = new ISrsLog();
ISrsThreadContext* _srs_context = new ISrsThreadContext();
// use this default timeout in us, if user not set.
#define SRS_SOCKET_DEFAULT_TIMEOUT 30 * 1000 * 1000LL
// The default socket timeout in ms.
#define SRS_SOCKET_DEFAULT_TMMS (30 * 1000)
/**
* export runtime context.
@ -108,7 +108,7 @@ struct Context
// the aac sequence header.
std::string aac_specific_config;
// user set timeout, in us.
// user set timeout, in ms.
int64_t stimeout;
int64_t rtimeout;
@ -120,7 +120,7 @@ struct Context
h264_sps_pps_sent = false;
h264_sps_changed = false;
h264_pps_changed = false;
rtimeout = stimeout = -1;
rtimeout = stimeout = SRS_CONSTS_NO_TMMS;
}
virtual ~Context() {
srs_freep(req);
@ -580,8 +580,8 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_
Context* context = (Context*)rtmp;
context->stimeout = send_timeout_ms * 1000;
context->rtimeout = recv_timeout_ms * 1000;
context->stimeout = send_timeout_ms;
context->rtimeout = recv_timeout_ms;
context->skt->set_recv_timeout(context->rtimeout);
context->skt->set_send_timeout(context->stimeout);
@ -646,12 +646,12 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp)
Context* context = (Context*)rtmp;
// set timeout if user not set.
if (context->stimeout == -1) {
context->stimeout = SRS_SOCKET_DEFAULT_TIMEOUT;
if (context->stimeout == SRS_CONSTS_NO_TMMS) {
context->stimeout = SRS_SOCKET_DEFAULT_TMMS;
context->skt->set_send_timeout(context->stimeout);
}
if (context->rtimeout == -1) {
context->rtimeout = SRS_SOCKET_DEFAULT_TIMEOUT;
if (context->rtimeout == SRS_CONSTS_NO_TMMS) {
context->rtimeout = SRS_SOCKET_DEFAULT_TMMS;
context->skt->set_recv_timeout(context->rtimeout);
}

View file

@ -1020,10 +1020,10 @@ typedef void* srs_hijack_io_t;
*/
extern int srs_hijack_io_read(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread);
/**
* set the socket recv timeout.
* set the socket recv timeout in ms.
* @return 0, success; otherswise, failed.
*/
extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm);
/**
* get the socket recv timeout.
* @return 0, success; otherswise, failed.
@ -1035,10 +1035,10 @@ typedef void* srs_hijack_io_t;
*/
extern int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx);
/**
* set the socket send timeout.
* set the socket send timeout in ms.
* @return 0, success; otherswise, failed.
*/
extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm);
/**
* get the socket send timeout.
* @return 0, success; otherswise, failed.
@ -1055,10 +1055,11 @@ typedef void* srs_hijack_io_t;
*/
extern int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite);
/**
* whether the timeout is never timeout.
* whether the timeout is never timeout in ms.
* @return 0, success; otherswise, failed.
*/
extern bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
// TODO: FIXME: Upgrade srs-bench and change the us to ms for timeout.
extern bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm);
/**
* read fully, fill the buf exactly size bytes.
* @return 0, success; otherswise, failed.