Skip to content

Commit

Permalink
Merge pull request #2 from kierank/srt-new
Browse files Browse the repository at this point in the history
SRT Fixes
  • Loading branch information
funman committed Nov 30, 2023
2 parents 9794a6b + 498c45c commit ef9cf62
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/rist_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ static int start(void)
struct upipe *upipe_srt_handshake = upipe_void_alloc_output(upipe_udpsrc_srt, upipe_srt_handshake_mgr,
uprobe_pfx_alloc_va(uprobe_use(&uprobe_hs), loglevel, "srt handshake %u", z));
upipe_set_option(upipe_srt_handshake, "listener", listener ? "1" : "0");
upipe_srt_handshake_set_password(upipe_srt_handshake, password, key_length / 8);
if (password)
upipe_srt_handshake_set_password(upipe_srt_handshake, password, key_length / 8);

upipe_mgr_release(upipe_srt_handshake_mgr);

Expand Down
29 changes: 29 additions & 0 deletions lib/upipe-srt/upipe_srt_handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,34 @@ static struct uref *upipe_srt_handshake_handle_hs(struct upipe *upipe, const uin
}
}

static struct uref *upipe_srt_handshake_handle_keepalive(struct upipe *upipe, const uint8_t *buf, int size, uint64_t now)
{
struct upipe_srt_handshake *upipe_srt_handshake = upipe_srt_handshake_from_upipe(upipe);
uint32_t timestamp = (now - upipe_srt_handshake->establish_time) / 27;

struct uref *uref = uref_block_alloc(upipe_srt_handshake->uref_mgr,
upipe_srt_handshake->ubuf_mgr, SRT_HEADER_SIZE + 4 /* WTF */);
if (!uref)
return NULL;
uint8_t *out;
int output_size = -1;
if (unlikely(!ubase_check(uref_block_write(uref, 0, &output_size, &out)))) {
uref_free(uref);
upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
}

srt_set_packet_control(out, true);
srt_set_packet_timestamp(out, timestamp);
srt_set_packet_dst_socket_id(out, upipe_srt_handshake->remote_socket_id);
srt_set_control_packet_type(out, SRT_CONTROL_TYPE_KEEPALIVE);
srt_set_control_packet_subtype(out, 0);
srt_set_control_packet_type_specific(out, srt_get_control_packet_type_specific(buf));

uref_block_unmap(uref, 0);
return uref;
// should go to sender
}

static struct uref *upipe_srt_handshake_handle_ack(struct upipe *upipe, const uint8_t *buf, int size, uint64_t now)
{
struct upipe_srt_handshake *upipe_srt_handshake = upipe_srt_handshake_from_upipe(upipe);
Expand Down Expand Up @@ -1373,6 +1401,7 @@ static struct uref *upipe_srt_handshake_input_control(struct upipe *upipe, const
if (type == SRT_CONTROL_TYPE_HANDSHAKE) {
return upipe_srt_handshake_handle_hs(upipe, buf, size, now);
} else if (type == SRT_CONTROL_TYPE_KEEPALIVE) {
return upipe_srt_handshake_handle_keepalive(upipe, buf, size, now);
} else if (type == SRT_CONTROL_TYPE_ACK) {
return upipe_srt_handshake_handle_ack(upipe, buf, size, now);
} else if (type == SRT_CONTROL_TYPE_NAK) {
Expand Down
2 changes: 1 addition & 1 deletion lib/upipe-srt/upipe_srt_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ static inline void upipe_srt_sender_input(struct upipe *upipe, struct uref *uref
srt_set_data_packet_message_number(buf, seqnum);
srt_set_data_packet_seq(buf, seqnum);
srt_set_data_packet_position(buf, SRT_DATA_POSITION_ONLY);
srt_set_data_packet_order(buf, true);
srt_set_data_packet_order(buf, false);
srt_set_data_packet_retransmit(buf, false);

#ifdef UPIPE_HAVE_GCRYPT_H
Expand Down

0 comments on commit ef9cf62

Please sign in to comment.