Skip to content

Commit

Permalink
scheduler: implement hash packets
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanreg committed May 2, 2024
1 parent 26ccc45 commit 9e43788
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion libavtransport/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ static inline int64_t scheduler_push_internal(AVTScheduler *s,

/* Process segments */
resume:

/* Send a hash data packet if needed */
if (state->p.pl_has_hash && !state->hash_sent) {
acc = avt_pkt_hdr_size(AVT_PKT_HASH_DATA);

if (out_limit < acc)
return AVT_ERROR(EAGAIN);

p = avt_pkt_fifo_push_new(dst, NULL, 0, 0);
if (!p)
return AVT_ERROR(ENOMEM);

p->pkt = AVT_HASH_DATA_HDR(
.stream_id = state->p.pkt.stream_id,
.global_seq = get_seq(s),
.hash_target = state->p.pkt.seq,
);
memcpy(p->pkt.hash_data.hash_data, state->p.pl_hash, 16);

avt_packet_encode_header(p);

/* Enqueue packet */
out_acc += acc;
update_sw(s, acc);

state->hash_sent = true;
}

hdr_size = state->seg_hdr_size;

/* Return if there are no packets we can output in the limit */
Expand Down Expand Up @@ -180,7 +208,8 @@ static inline int64_t scheduler_push_internal(AVTScheduler *s,

if (!out_acc) {
state->seg_offset = 0;
state->present = 0;
state->present = false;
state->hash_sent = false;
}

return out_acc;
Expand Down
1 change: 1 addition & 0 deletions libavtransport/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct AVTSchedulerPacketContext {
/* Unlike with a normal packet, this is state,
* and the payload may not match the packet's contents */
AVTPktd p;
bool hash_sent;

uint32_t seg_offset;
uint32_t pl_left;
Expand Down

0 comments on commit 9e43788

Please sign in to comment.