Skip to content

Commit

Permalink
WebRTC: Refine code and destroy session when tcp close.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeng19811218 authored and winlinvip committed Sep 4, 2022
1 parent 07339e1 commit efa0851
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 155 deletions.
28 changes: 14 additions & 14 deletions trunk/src/app/srs_app_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,18 +559,18 @@ srs_error_t SrsTcpConnection::writev(const iovec *iov, int iov_size, ssize_t* nw
return skt->writev(iov, iov_size, nwrite);
}

SrsBufferedReader::SrsBufferedReader(ISrsProtocolReadWriter* io)
SrsBufferedReadWriter::SrsBufferedReadWriter(ISrsProtocolReadWriter* io)
{
io_ = io;
buf_ = NULL;
}

SrsBufferedReader::~SrsBufferedReader()
SrsBufferedReadWriter::~SrsBufferedReadWriter()
{
srs_freep(buf_);
}

srs_error_t SrsBufferedReader::peek(char* buf, int* size)
srs_error_t SrsBufferedReadWriter::peek(char* buf, int* size)
{
srs_error_t err = srs_success;

Expand All @@ -588,7 +588,7 @@ srs_error_t SrsBufferedReader::peek(char* buf, int* size)
return err;
}

srs_error_t SrsBufferedReader::reload_buffer()
srs_error_t SrsBufferedReadWriter::reload_buffer()
{
srs_error_t err = srs_success;

Expand All @@ -608,7 +608,7 @@ srs_error_t SrsBufferedReader::reload_buffer()
return err;
}

srs_error_t SrsBufferedReader::read(void* buf, size_t size, ssize_t* nread)
srs_error_t SrsBufferedReadWriter::read(void* buf, size_t size, ssize_t* nread)
{
if (!buf_ || buf_->empty()) {
return io_->read(buf, size, nread);
Expand All @@ -623,7 +623,7 @@ srs_error_t SrsBufferedReader::read(void* buf, size_t size, ssize_t* nread)
return srs_success;
}

srs_error_t SrsBufferedReader::read_fully(void* buf, size_t size, ssize_t* nread)
srs_error_t SrsBufferedReadWriter::read_fully(void* buf, size_t size, ssize_t* nread)
{
if (!buf_ || buf_->empty()) {
return io_->read_fully(buf, size, nread);
Expand All @@ -643,42 +643,42 @@ srs_error_t SrsBufferedReader::read_fully(void* buf, size_t size, ssize_t* nread
return srs_success;
}

void SrsBufferedReader::set_recv_timeout(srs_utime_t tm)
void SrsBufferedReadWriter::set_recv_timeout(srs_utime_t tm)
{
return io_->set_recv_timeout(tm);
}

srs_utime_t SrsBufferedReader::get_recv_timeout()
srs_utime_t SrsBufferedReadWriter::get_recv_timeout()
{
return io_->get_recv_timeout();
}

int64_t SrsBufferedReader::get_recv_bytes()
int64_t SrsBufferedReadWriter::get_recv_bytes()
{
return io_->get_recv_bytes();
}

int64_t SrsBufferedReader::get_send_bytes()
int64_t SrsBufferedReadWriter::get_send_bytes()
{
return io_->get_send_bytes();
}

void SrsBufferedReader::set_send_timeout(srs_utime_t tm)
void SrsBufferedReadWriter::set_send_timeout(srs_utime_t tm)
{
return io_->set_send_timeout(tm);
}

srs_utime_t SrsBufferedReader::get_send_timeout()
srs_utime_t SrsBufferedReadWriter::get_send_timeout()
{
return io_->get_send_timeout();
}

srs_error_t SrsBufferedReader::write(void* buf, size_t size, ssize_t* nwrite)
srs_error_t SrsBufferedReadWriter::write(void* buf, size_t size, ssize_t* nwrite)
{
return io_->write(buf, size, nwrite);
}

srs_error_t SrsBufferedReader::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
srs_error_t SrsBufferedReadWriter::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
{
return io_->writev(iov, iov_size, nwrite);
}
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class SrsTcpConnection : public ISrsProtocolReadWriter

// With a small fast read buffer, to support peek for protocol detecting. Note that directly write to io without any
// cache or buffer.
class SrsBufferedReader : public ISrsProtocolReadWriter
class SrsBufferedReadWriter : public ISrsProtocolReadWriter
{
private:
// The under-layer transport.
Expand All @@ -181,8 +181,8 @@ class SrsBufferedReader : public ISrsProtocolReadWriter
// Current reading position.
SrsBuffer* buf_;
public:
SrsBufferedReader(ISrsProtocolReadWriter* io);
virtual ~SrsBufferedReader();
SrsBufferedReadWriter(ISrsProtocolReadWriter* io);
virtual ~SrsBufferedReadWriter();
public:
// Peek the head of cache to buf in size of bytes.
srs_error_t peek(char* buf, int* size);
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ srs_error_t SrsSecurityTransport::on_dtls_handshake_done()
return srs_error_wrap(err, "srtp init");
}

return network_->on_connection_established();
return network_->on_dtls_handshake_done();
}

srs_error_t SrsSecurityTransport::on_dtls_application_data(const char* buf, const int nb_buf)
Expand Down Expand Up @@ -249,7 +249,7 @@ srs_error_t SrsPlaintextTransport::on_dtls_alert(std::string type, std::string d
srs_error_t SrsPlaintextTransport::on_dtls_handshake_done()
{
srs_trace("RTC: DTLS handshake done.");
return network_->on_connection_established();
return network_->on_dtls_handshake_done();
}

srs_error_t SrsPlaintextTransport::on_dtls_application_data(const char* data, const int len)
Expand Down Expand Up @@ -2166,7 +2166,7 @@ srs_error_t SrsRtcConnection::find_publisher(char* buf, int size, SrsRtcPublishS
return err;
}

srs_error_t SrsRtcConnection::on_connection_established()
srs_error_t SrsRtcConnection::on_dtls_handshake_done()
{
srs_error_t err = srs_success;

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtc_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class SrsRtcConnection : public ISrsResource, public ISrsDisposingHandler, publi
srs_error_t on_rtcp_feedback_twcc(char* buf, int nb_buf);
srs_error_t on_rtcp_feedback_remb(SrsRtcpPsfbCommon *rtcp);
public:
srs_error_t on_connection_established();
srs_error_t on_dtls_handshake_done();
srs_error_t on_dtls_alert(std::string type, std::string desc);
bool is_alive();
void alive();
Expand Down
Loading

1 comment on commit efa0851

@winlinvip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #2852

Please sign in to comment.