Skip to content

Commit 82e2254

Browse files
committed
Cache session and stream in the rtpp_socket object so we can
skip hash table lookup on the second and subsequent packets.
1 parent fee5630 commit 82e2254

File tree

3 files changed

+110
-8
lines changed

3 files changed

+110
-8
lines changed

src/rtpp_proc.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,26 @@ process_rtp_only(const struct rtpp_cfg *cfsp, struct rtpp_polltbl *ptbl,
129129
continue;
130130
}
131131
iskt = ep->data.ptr;
132-
uint64_t stuid = CALL_SMETHOD(iskt, get_stuid);
133-
stp = CALL_SMETHOD(ptbl->streams_wrt, get_by_idx, stuid);
134-
if (stp == NULL)
135-
continue;
136-
sp = CALL_SMETHOD(cfsp->sessions_wrt, get_by_idx, stp->seuid);
132+
sp = CALL_SMETHOD(iskt, get_session_link);
133+
stp = CALL_SMETHOD(iskt, get_stream_link);
134+
if (stp == NULL) {
135+
uint64_t stuid = CALL_SMETHOD(iskt, get_stuid);
136+
137+
stp = CALL_SMETHOD(ptbl->streams_wrt, get_by_idx, stuid);
138+
if (stp == NULL) {
139+
if (sp != NULL)
140+
RTPP_OBJ_DECREF(sp);
141+
continue;
142+
}
143+
CALL_SMETHOD(iskt, link_stream, stp);
144+
}
137145
if (sp == NULL) {
138-
RTPP_OBJ_DECREF(stp);
139-
continue;
146+
sp = CALL_SMETHOD(cfsp->sessions_wrt, get_by_idx, stp->seuid);
147+
if (sp == NULL) {
148+
RTPP_OBJ_DECREF(stp);
149+
continue;
150+
}
151+
CALL_SMETHOD(iskt, link_session, sp);
140152
}
141153
if (sp->complete != 0) {
142154
rxmit_packets(cfsp, stp, dtime, drain_repeat, sender, rsp);

src/rtpp_socket.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@
4444
#include "rtpp_refcnt.h"
4545
#include "rtpp_socket.h"
4646
#include "rtpp_socket_fin.h"
47+
#include "rtpp_session.h"
48+
#include "rtpp_stream.h"
4749
#include "rtpp_netio_async.h"
4850
#include "rtpp_mallocs.h"
4951
#include "rtpp_time.h"
5052
#include "rtpp_network.h"
5153
#include "rtpp_network_io.h"
54+
#include "rtpp_wref.h"
5255
#include "rtp.h"
5356
#include "rtp_packet.h"
5457
#include "rtpp_debug.h"
@@ -68,6 +71,8 @@ struct rtpp_socket_priv {
6871
int fd;
6972
int type;
7073
uint64_t stuid;
74+
struct rtpp_wref *session_wref;
75+
struct rtpp_wref *stream_wref;
7176
rs_rtp_recv_t rtp_recv;
7277
};
7378

@@ -89,6 +94,10 @@ static int rtpp_socket_drain(struct rtpp_socket *, const char *,
8994
struct rtpp_log *);
9095
static void rtpp_socket_set_stuid(struct rtpp_socket *, uint64_t);
9196
static uint64_t rtpp_socket_get_stuid(struct rtpp_socket *);
97+
static void rtpp_socket_link_session(struct rtpp_socket *, struct rtpp_session *);
98+
static struct rtpp_session *rtpp_socket_get_session_link(struct rtpp_socket *);
99+
static void rtpp_socket_link_stream(struct rtpp_socket *, struct rtpp_stream *);
100+
static struct rtpp_stream *rtpp_socket_get_stream_link(struct rtpp_socket *);
92101

93102
#if HAVE_SO_TS_CLOCK
94103
static struct rtp_packet *rtpp_socket_rtp_recv_mono(const struct rs_recv_arg *);
@@ -106,6 +115,10 @@ DEFINE_SMETHODS(rtpp_socket,
106115
.drain = &rtpp_socket_drain,
107116
.set_stuid = &rtpp_socket_set_stuid,
108117
.get_stuid = &rtpp_socket_get_stuid,
118+
.link_session = &rtpp_socket_link_session,
119+
.get_session_link = &rtpp_socket_get_session_link,
120+
.link_stream = &rtpp_socket_link_stream,
121+
.get_stream_link = &rtpp_socket_get_stream_link,
109122
);
110123

111124
struct rtpp_socket *
@@ -131,7 +144,18 @@ rtpp_socket_ctor(struct rtpp_anetio_cf *netio, int domain, int type)
131144
}
132145
pvt->rtp_recv = &rtpp_socket_rtp_recv_simple;
133146
PUBINST_FININIT(&pvt->pub, pvt, rtpp_socket_dtor);
147+
pvt->session_wref = rtpp_wref_ctor();
148+
if (pvt->session_wref == NULL) {
149+
goto e2;
150+
}
151+
pvt->stream_wref = rtpp_wref_ctor();
152+
if (pvt->stream_wref == NULL) {
153+
goto e2;
154+
}
134155
return (&pvt->pub);
156+
e2:
157+
RTPP_OBJ_DECREF(&(pvt->pub));
158+
return (NULL);
135159
e1:
136160
RTPP_OBJ_DECREF(&(pvt->pub));
137161
e0:
@@ -143,6 +167,12 @@ rtpp_socket_dtor(struct rtpp_socket_priv *pvt)
143167
{
144168

145169
rtpp_socket_fin(&pvt->pub);
170+
if (pvt->stream_wref != NULL) {
171+
RTPP_OBJ_DECREF(pvt->stream_wref);
172+
}
173+
if (pvt->session_wref != NULL) {
174+
RTPP_OBJ_DECREF(pvt->session_wref);
175+
}
146176
if (pvt->type != SOCK_DGRAM) {
147177
shutdown(pvt->fd, SHUT_RDWR);
148178
}
@@ -403,3 +433,51 @@ rtpp_socket_get_stuid(struct rtpp_socket *self)
403433

404434
return (pvt->stuid);
405435
}
436+
437+
static void
438+
rtpp_socket_link_session(struct rtpp_socket *self, struct rtpp_session *sp)
439+
{
440+
struct rtpp_socket_priv *pvt;
441+
442+
PUB2PVT(self, pvt);
443+
RTPP_DBG_ASSERT(sp != NULL);
444+
(void)CALL_SMETHOD(pvt->session_wref, setref, sp->rcnt, sp);
445+
}
446+
447+
static struct rtpp_session *
448+
rtpp_socket_get_session_link(struct rtpp_socket *self)
449+
{
450+
struct rtpp_socket_priv *pvt;
451+
const struct rtpp_wref_target *sp_target;
452+
453+
PUB2PVT(self, pvt);
454+
sp_target = CALL_SMETHOD(pvt->session_wref, getref);
455+
if (sp_target != NULL) {
456+
return (sp_target->obj);
457+
}
458+
return (NULL);
459+
}
460+
461+
static void
462+
rtpp_socket_link_stream(struct rtpp_socket *self, struct rtpp_stream *stp)
463+
{
464+
struct rtpp_socket_priv *pvt;
465+
466+
PUB2PVT(self, pvt);
467+
RTPP_DBG_ASSERT(stp != NULL);
468+
(void)CALL_SMETHOD(pvt->stream_wref, setref, stp->rcnt, stp);
469+
}
470+
471+
static struct rtpp_stream *
472+
rtpp_socket_get_stream_link(struct rtpp_socket *self)
473+
{
474+
struct rtpp_socket_priv *pvt;
475+
const struct rtpp_wref_target *stp_target;
476+
477+
PUB2PVT(self, pvt);
478+
stp_target = CALL_SMETHOD(pvt->stream_wref, getref);
479+
if (stp_target != NULL) {
480+
return (stp_target->obj);
481+
}
482+
return (NULL);
483+
}

src/rtpp_socket.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct rtpp_log;
3636
struct rtpp_netaddr;
3737
struct rtpp_timestamp;
3838
struct rtpp_anetio_cf;
39+
struct rtpp_session;
40+
struct rtpp_stream;
3941

4042
DECLARE_CLASS(rtpp_socket, struct rtpp_anetio_cf *, int, int);
4143

@@ -55,6 +57,12 @@ DEFINE_METHOD(rtpp_socket, rtpp_socket_drain, int, const char *,
5557
struct rtpp_log *);
5658
DEFINE_METHOD(rtpp_socket, rtpp_socket_set_stuid, void, uint64_t);
5759
DEFINE_METHOD(rtpp_socket, rtpp_socket_get_stuid, uint64_t);
60+
DEFINE_METHOD(rtpp_socket, rtpp_socket_link_session, void,
61+
struct rtpp_session *);
62+
DEFINE_METHOD(rtpp_socket, rtpp_socket_get_session_link, struct rtpp_session *);
63+
DEFINE_METHOD(rtpp_socket, rtpp_socket_link_stream, void,
64+
struct rtpp_stream *);
65+
DEFINE_METHOD(rtpp_socket, rtpp_socket_get_stream_link, struct rtpp_stream *);
5866

5967
DECLARE_SMETHODS(rtpp_socket)
6068
{
@@ -71,6 +79,10 @@ DECLARE_SMETHODS(rtpp_socket)
7179
METHOD_ENTRY(rtpp_socket_drain, drain);
7280
METHOD_ENTRY(rtpp_socket_set_stuid, set_stuid);
7381
METHOD_ENTRY(rtpp_socket_get_stuid, get_stuid);
82+
METHOD_ENTRY(rtpp_socket_link_session, link_session);
83+
METHOD_ENTRY(rtpp_socket_get_session_link, get_session_link);
84+
METHOD_ENTRY(rtpp_socket_link_stream, link_stream);
85+
METHOD_ENTRY(rtpp_socket_get_stream_link, get_stream_link);
7486
};
7587

76-
DECLARE_CLASS_PUBTYPE(rtpp_socket, {});
88+
DECLARE_CLASS_PUBTYPE(rtpp_socket, {});

0 commit comments

Comments
 (0)