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 * );
9095static void rtpp_socket_set_stuid (struct rtpp_socket * , uint64_t );
9196static 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
94103static 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
111124struct 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 );
135159e1 :
136160 RTPP_OBJ_DECREF (& (pvt -> pub ));
137161e0 :
@@ -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+ }
0 commit comments