Skip to content

Commit

Permalink
RTC: Refine static cast for RTC connection
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 5, 2021
1 parent d526e17 commit 9c17721
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
7 changes: 5 additions & 2 deletions trunk/src/app/srs_app_rtc_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,11 @@ class ISrsRtcConnectionHijacker
};

// A RTC Peer Connection, SDP level object.
class SrsRtcConnection : virtual public ISrsHourGlass, virtual public ISrsResource
, virtual public ISrsDisposingHandler
//
// For performance, we use non-virtual public from resource,
// see https://stackoverflow.com/questions/3747066/c-cannot-convert-from-base-a-to-derived-type-b-via-virtual-base-a
class SrsRtcConnection : public ISrsResource
, virtual public ISrsHourGlass, virtual public ISrsDisposingHandler
{
friend class SrsSecurityTransport;
friend class SrsRtcPlayStream;
Expand Down
16 changes: 5 additions & 11 deletions trunk/src/app/srs_app_rtc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,12 @@ srs_error_t SrsRtcServer::on_udp_packet(SrsUdpMuxSocket* skt)
string peer_id = skt->peer_id();
char* data = skt->data(); int size = skt->size();

SrsRtcConnection* session = NULL;
if (true) {
ISrsResource* conn = _srs_rtc_manager->find_by_id(peer_id);
if (conn) {
// Switch to the session to write logs to the context.
session = dynamic_cast<SrsRtcConnection*>(conn);
session->switch_to_context();
}
}

// When got any packet, the session is alive now.
SrsRtcConnection* session = (SrsRtcConnection*)_srs_rtc_manager->find_by_id(peer_id);
if (session) {
// Switch to the session to write logs to the context.
session->switch_to_context();

// When got any packet, the session is alive now.
session->alive();
}

Expand Down

0 comments on commit 9c17721

Please sign in to comment.