Skip to content

Commit

Permalink
TT#50652 keep existing SSRC context when starting another playback
Browse files Browse the repository at this point in the history
Change-Id: Ia4e64c39f870d0481847a67dd9c8dac1531e822d
  • Loading branch information
rfuchs committed Mar 6, 2019
1 parent 223996b commit 7e85d1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 6 additions & 2 deletions daemon/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct codec_ssrc_handler {
struct timeval first_send;
unsigned long first_send_ts;
GString *sample_buffer;
int rtp_mark:1;
};
struct transcode_packet {
seq_packet_t p; // must be first
Expand Down Expand Up @@ -189,7 +190,9 @@ struct codec_handler *codec_handler_make_playback(struct rtp_payload_type *src_p
handler->dest_pt = *dst_pt;
handler->func = handler_func_playback;
handler->ssrc_handler = (void *) __ssrc_handler_transcode_new(handler);
handler->ssrc_handler->first_ts = random();
while (handler->ssrc_handler->first_ts == 0)
handler->ssrc_handler->first_ts = random();
handler->ssrc_handler->rtp_mark = 1;

ilog(LOG_DEBUG, "Created media playback context for " STR_FORMAT " -> " STR_FORMAT "",
STR_FMT(&src_pt->encoding_with_params),
Expand Down Expand Up @@ -1070,8 +1073,9 @@ static int __packet_encoded(encoder_t *enc, void *u1, void *u2) {
ilog(LOG_DEBUG, "Received packet of %i bytes from packetizer", inout.len);
__output_rtp(mp, ch, ch->handler, buf, inout.len, ch->first_ts
+ enc->avpkt.pts / enc->def->clockrate_mult,
0, -1, seq_off);
ch->rtp_mark ? 1 : 0, -1, seq_off);
mp->iter++;
ch->rtp_mark = 0;

if (ret == 0) {
// no more to go
Expand Down
15 changes: 9 additions & 6 deletions daemon/media_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ static void media_player_shutdown(struct media_player *mp) {
if (mp->handler)
codec_handler_free(mp->handler);
mp->handler = NULL;
if (mp->ssrc_out)
obj_put(&mp->ssrc_out->parent->h);
mp->ssrc_out = NULL;
if (mp->avioctx) {
if (mp->avioctx->buffer)
av_freep(&mp->avioctx->buffer);
Expand Down Expand Up @@ -70,6 +67,9 @@ static void __media_player_free(void *p) {
ilog(LOG_DEBUG, "freeing media_player");

media_player_shutdown(mp);
if (mp->ssrc_out)
obj_put(&mp->ssrc_out->parent->h);
mp->ssrc_out = NULL;
mutex_destroy(&mp->lock);
obj_put(mp->call);
}
Expand All @@ -81,13 +81,19 @@ struct media_player *media_player_new(struct call_monologue *ml) {
#ifdef WITH_TRANSCODING
ilog(LOG_DEBUG, "creating media_player");

uint32_t ssrc = 0;
while (ssrc == 0)
ssrc = random();
struct ssrc_ctx *ssrc_ctx = get_ssrc_ctx(ssrc, ml->call->ssrc_hash, SSRC_DIR_OUTPUT);

struct media_player *mp = obj_alloc0("media_player", sizeof(*mp), __media_player_free);

mp->tt_obj.tt = &media_player_thread;
mutex_init(&mp->lock);
mp->call = obj_get(ml->call);
mp->ml = ml;
mp->seq = random();
mp->ssrc_out = ssrc_ctx;

av_init_packet(&mp->pkt);
mp->pkt.data = NULL;
Expand Down Expand Up @@ -216,9 +222,6 @@ static int __ensure_codec_handler(struct media_player *mp, AVStream *avs) {
mp->handler = codec_handler_make_playback(&src_pt, dst_pt);
if (!mp->handler)
return -1;
mp->ssrc_out = get_ssrc_ctx(random(), mp->call->ssrc_hash, SSRC_DIR_OUTPUT);
if (!mp->ssrc_out)
return -1;

mp->duration = avs->duration * 1000 * avs->time_base.num / avs->time_base.den;

Expand Down

0 comments on commit 7e85d1a

Please sign in to comment.