Skip to content

Commit 1a46e7a

Browse files
committed
Conver player feature to use pproc_manager.
1 parent b5de107 commit 1a46e7a

File tree

3 files changed

+78
-35
lines changed

3 files changed

+78
-35
lines changed

src/rtpp_proc_async.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,19 @@ relay_packet(const struct pkt_proc_ctx *pktxp)
274274
* Check that we have some address to which packet is to be
275275
* sent out, drop otherwise.
276276
*/
277-
if (!CALL_SMETHOD(stp_out, issendable) || CALL_SMETHOD(stp_out, isplayer_active)) {
277+
if (!CALL_SMETHOD(stp_out, issendable)) {
278278
return PPROC_ACT_DROP;
279279
}
280280
CALL_SMETHOD(stp_out, send_pkt, packet->sender, packet);
281-
CALL_SMETHOD(stp_in->pcount, reg_reld);
282-
if (pktxp->rsp != NULL) {
283-
pktxp->rsp->npkts_relayed.cnt++;
284-
} else {
285-
struct rtpp_proc_async_cf *proc_cf = pktxp->pproc->arg;
286-
CALL_SMETHOD(proc_cf->cf_save->rtpp_stats, updatebyidx, proc_cf->npkts_relayed_idx, 1);
281+
if ((pktxp->flags & PPROC_FLAG_LGEN) == 0) {
282+
CALL_SMETHOD(stp_in->pcount, reg_reld);
283+
if (pktxp->rsp != NULL) {
284+
pktxp->rsp->npkts_relayed.cnt++;
285+
} else {
286+
struct rtpp_proc_async_cf *proc_cf = pktxp->pproc->arg;
287+
CALL_SMETHOD(proc_cf->cf_save->rtpp_stats, updatebyidx,
288+
proc_cf->npkts_relayed_idx, 1);
289+
}
287290
}
288291
return PPROC_ACT_TAKE;
289292
}

src/rtpp_proc_servers.c

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include "rtpp_mallocs.h"
5252
#include "rtpp_stats.h"
5353
#include "rtpp_debug.h"
54+
#include "advanced/packet_processor.h"
55+
#include "advanced/pproc_manager.h"
5456

5557
struct rtpp_proc_servers_priv {
5658
struct rtpp_proc_servers pub;
@@ -64,49 +66,59 @@ struct foreach_args {
6466
double dtime;
6567
struct sthread_args *sender;
6668
struct rtpp_proc_stat *npkts_played;
67-
struct rtpp_weakref_obj *rtp_streams_wrt;
69+
const struct rtpp_cfg *cfsp;
6870
};
6971

7072
static int
7173
process_rtp_servers_foreach(void *dp, void *ap)
7274
{
73-
struct foreach_args *fap;
75+
const struct foreach_args *fap;
7476
struct rtpp_server *rsrv;
7577
struct rtp_packet *pkt;
7678
int len;
77-
struct rtpp_stream *rsop;
79+
struct rtpp_stream *strmp_out;
80+
struct rtpp_stream *strmp_in;
7881

7982
fap = (struct foreach_args *)ap;
8083
/*
8184
* This method does not need us to bump ref, since we are in the
8285
* locked context of the rtpp_hash_table, which holds its own ref.
8386
*/
8487
rsrv = (struct rtpp_server *)dp;
85-
rsop = CALL_METHOD(fap->rtp_streams_wrt, get_by_idx, rsrv->stuid);
86-
if (rsop == NULL) {
87-
return (RTPP_WR_MATCH_CONT);
88-
}
88+
strmp_out = CALL_METHOD(fap->cfsp->rtp_streams_wrt, get_by_idx, rsrv->stuid);
89+
if (strmp_out == NULL)
90+
goto e0;
91+
strmp_in = CALL_SMETHOD(strmp_out, get_sender, fap->cfsp);
92+
if (strmp_in == NULL)
93+
goto e1;
8994
for (;;) {
9095
pkt = CALL_SMETHOD(rsrv, get, fap->dtime, &len);
9196
if (pkt == NULL) {
9297
if (len == RTPS_EOF) {
93-
CALL_SMETHOD(rsop, finish_playback, rsrv->sruid);
94-
RTPP_OBJ_DECREF(rsop);
98+
CALL_SMETHOD(strmp_out, finish_playback, rsrv->sruid);
99+
RTPP_OBJ_DECREF(strmp_in);
100+
RTPP_OBJ_DECREF(strmp_out);
95101
return (RTPP_WR_MATCH_DEL);
96102
} else if (len != RTPS_LATER) {
97103
/* XXX some error, brag to logs */
98104
}
99105
break;
100106
}
101-
if (CALL_SMETHOD(rsop, issendable) == 0) {
102-
/* We have a packet, but nowhere to send it, drop */
103-
RTPP_OBJ_DECREF(pkt);
104-
continue;
105-
}
106-
CALL_SMETHOD(rsop, send_pkt, fap->sender, pkt);
107-
fap->npkts_played->cnt++;
107+
pkt->sender = fap->sender;
108+
struct pkt_proc_ctx pktx = {
109+
.strmp_in = strmp_in,
110+
.strmp_out = strmp_out,
111+
.pktp = pkt,
112+
.flags = PPROC_FLAG_LGEN,
113+
};
114+
if (CALL_SMETHOD(strmp_in->pproc_manager, handleat, &pktx,
115+
PPROC_ORD_PLAY + 1) & PPROC_ACT_TAKE)
116+
fap->npkts_played->cnt++;
108117
}
109-
RTPP_OBJ_DECREF(rsop);
118+
RTPP_OBJ_DECREF(strmp_in);
119+
e1:
120+
RTPP_OBJ_DECREF(strmp_out);
121+
e0:
110122
return (RTPP_WR_MATCH_CONT);
111123
}
112124

@@ -115,15 +127,15 @@ static enum rtpp_timed_cb_rvals
115127
run_servers(double dtime, void *arg)
116128
{
117129
struct rtpp_proc_servers_priv *tp = arg;
118-
struct foreach_args fargs;
119-
120-
fargs.dtime = dtime;
121-
fargs.sender = rtpp_anetio_pick_sender(tp->netio);
122-
fargs.npkts_played = &tp->npkts_played;
123-
fargs.rtp_streams_wrt = tp->cfsp->rtp_streams_wrt;
130+
const struct foreach_args fargs = {
131+
.dtime = dtime,
132+
.sender = rtpp_anetio_pick_sender(tp->netio),
133+
.npkts_played = &tp->npkts_played,
134+
.cfsp = tp->cfsp,
135+
};
124136

125137
CALL_METHOD(tp->cfsp->servers_wrt, foreach, process_rtp_servers_foreach,
126-
&fargs);
138+
(void *)&fargs);
127139

128140
rtpp_anetio_pump_q(fargs.sender);
129141
FLUSH_STAT(tp->cfsp->rtpp_stats, tp->npkts_played);

src/rtpp_stream.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ player_predestroy_cb(struct rtpp_stats *rtpp_stats)
432432
CALL_SMETHOD(rtpp_stats, updatebyname, "nplrs_destroyed", 1);
433433
}
434434

435+
static enum pproc_action
436+
drop_packets(const struct pkt_proc_ctx *pktxp)
437+
{
438+
439+
return (PPROC_ACT_DROP);
440+
}
441+
435442
static int
436443
rtpp_stream_handle_play(struct rtpp_stream *self, const char *codecs,
437444
const char *pname, int playcount, struct rtpp_command *cmd, int ptime)
@@ -447,13 +454,21 @@ rtpp_stream_handle_play(struct rtpp_stream *self, const char *codecs,
447454
.ptime = ptime};
448455

449456
PUB2PVT(self, pvt);
457+
458+
const struct packet_processor_if drop_on_pa_poi = {
459+
.descr = "drop_packets(player_active)",
460+
.arg = (void *)pvt,
461+
.key = (void *)(pvt + 2),
462+
.enqueue = &drop_packets
463+
};
464+
450465
pthread_mutex_lock(&pvt->lock);
451466
plerror = "reason unknown";
452467
while (*codecs != '\0') {
453468
n = strtol(codecs, &cp, 10);
454469
if (cp == codecs) {
455470
plerror = "invalid codecs";
456-
break;
471+
goto e0;
457472
}
458473
codecs = cp;
459474
if (*codecs != '\0')
@@ -466,16 +481,21 @@ rtpp_stream_handle_play(struct rtpp_stream *self, const char *codecs,
466481
plerror = "rtpp_server_ctor() failed";
467482
if (sca.result == RTPP_SERV_NOENT)
468483
continue;
469-
break;
484+
goto e0;
470485
}
471486
rsrv->stuid = self->stuid;
472487
ssrc = CALL_SMETHOD(rsrv, get_ssrc);
473488
seq = CALL_SMETHOD(rsrv, get_seq);
474489
_s_rtps(pvt, rsrv->sruid, 0);
490+
int regres = CALL_SMETHOD(self->pproc_manager->reverse, reg, PPROC_ORD_PLAY,
491+
&drop_on_pa_poi);
492+
if (regres < 0) {
493+
plerror = "pproc_manager->reg() method failed";
494+
goto e1;
495+
}
475496
if (CALL_METHOD(pvt->servers_wrt, reg, rsrv->rcnt, rsrv->sruid) != 0) {
476-
RTPP_OBJ_DECREF(rsrv);
477497
plerror = "servers_wrt->reg() method failed";
478-
break;
498+
goto e2;
479499
}
480500
if (pvt->rtps.inact == 0) {
481501
CALL_SMETHOD(rsrv, start, cmd->dtime->mono);
@@ -490,6 +510,12 @@ rtpp_stream_handle_play(struct rtpp_stream *self, const char *codecs,
490510
playcount, pname, n, ssrc, seq);
491511
return 0;
492512
}
513+
goto e0;
514+
e2:
515+
CALL_SMETHOD(self->pproc_manager->reverse, unreg, drop_on_pa_poi.key);
516+
e1:
517+
RTPP_OBJ_DECREF(rsrv);
518+
e0:
493519
pthread_mutex_unlock(&pvt->lock);
494520
RTPP_LOG(pvt->pub.log, RTPP_LOG_ERR, "can't create player: %s", plerror);
495521
return -1;
@@ -508,6 +534,7 @@ rtpp_stream_handle_noplay(struct rtpp_stream *self)
508534
ruid = pvt->rtps.uid;
509535
pthread_mutex_unlock(&pvt->lock);
510536
if (ruid != RTPP_UID_NONE) {
537+
CALL_SMETHOD(self->pproc_manager->reverse, unreg, pvt + 2);
511538
if (CALL_METHOD(pvt->servers_wrt, unreg, ruid) != NULL) {
512539
pthread_mutex_lock(&pvt->lock);
513540
if (pvt->rtps.uid == ruid) {
@@ -545,6 +572,7 @@ rtpp_stream_finish_playback(struct rtpp_stream *self, uint64_t sruid)
545572
PUB2PVT(self, pvt);
546573
pthread_mutex_lock(&pvt->lock);
547574
if (pvt->rtps.uid != RTPP_UID_NONE && pvt->rtps.uid == sruid) {
575+
CALL_SMETHOD(self->pproc_manager->reverse, unreg, pvt + 2);
548576
_s_rtps(pvt, RTPP_UID_NONE, 1);
549577
RTPP_LOG(pvt->pub.log, RTPP_LOG_INFO,
550578
"player at port %d has finished", self->port);

0 commit comments

Comments
 (0)