From 785ff38db435e14c3994b2239ca2eb8417c69215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 29 Jul 2019 22:42:11 +0200 Subject: [PATCH] Add Corrupt Frame Reporting --- lib/include/chiaki/streamconnection.h | 2 ++ lib/include/chiaki/takion.h | 2 +- lib/src/streamconnection.c | 22 ++++++++++++++++++++++ lib/src/takion.c | 4 ++-- lib/src/videoreceiver.c | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/include/chiaki/streamconnection.h b/lib/include/chiaki/streamconnection.h index fd6b409..b1e3fb7 100644 --- a/lib/include/chiaki/streamconnection.h +++ b/lib/include/chiaki/streamconnection.h @@ -81,6 +81,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio */ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_stop(ChiakiStreamConnection *stream_connection); +CHIAKI_EXPORT ChiakiErrorCode stream_connection_send_corrupt_frame(ChiakiStreamConnection *stream_connection, ChiakiSeqNum16 start, ChiakiSeqNum16 end); + #ifdef __cplusplus } #endif diff --git a/lib/include/chiaki/takion.h b/lib/include/chiaki/takion.h index 38cf3d1..9236a6a 100644 --- a/lib/include/chiaki/takion.h +++ b/lib/include/chiaki/takion.h @@ -194,7 +194,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send(ChiakiTakion *takion, uint8_t * /** * Thread-safe while Takion is running. */ -CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_message_data(ChiakiTakion *takion, uint8_t flags, uint16_t channel, uint8_t *buf, size_t buf_size); +CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_message_data(ChiakiTakion *takion, uint8_t chunk_flags, uint16_t channel, uint8_t *buf, size_t buf_size); /** * Thread-safe while Takion is running. diff --git a/lib/src/streamconnection.c b/lib/src/streamconnection.c index 303a1b3..78cb887 100644 --- a/lib/src/streamconnection.c +++ b/lib/src/streamconnection.c @@ -754,3 +754,25 @@ static ChiakiErrorCode stream_connection_send_heartbeat(ChiakiStreamConnection * return chiaki_takion_send_message_data(&stream_connection->takion, 1, 1, buf, stream.bytes_written); } + +CHIAKI_EXPORT ChiakiErrorCode stream_connection_send_corrupt_frame(ChiakiStreamConnection *stream_connection, ChiakiSeqNum16 start, ChiakiSeqNum16 end) +{ + tkproto_TakionMessage msg = { 0 }; + msg.type = tkproto_TakionMessage_PayloadType_CORRUPTFRAME; + msg.has_corrupt_payload = true; + msg.corrupt_payload.start = start; + msg.corrupt_payload.end = end; + + uint8_t buf[0x10]; + + pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); + bool pbr = pb_encode(&stream, tkproto_TakionMessage_fields, &msg); + if(!pbr) + { + CHIAKI_LOGE(stream_connection->log, "StreamConnection heartbeat protobuf encoding failed"); + return CHIAKI_ERR_UNKNOWN; + } + + CHIAKI_LOGD(stream_connection->log, "StreamConnection reporting corrupt frame(s) from %u to %u\n", (unsigned int)start, (unsigned int)end); + return chiaki_takion_send_message_data(&stream_connection->takion, 1, 2, buf, stream.bytes_written); +} diff --git a/lib/src/takion.c b/lib/src/takion.c index e150629..ec84bfc 100644 --- a/lib/src/takion.c +++ b/lib/src/takion.c @@ -341,7 +341,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send(ChiakiTakion *takion, uint8_t * return chiaki_takion_send_raw(takion, buf, buf_size); } -CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_message_data(ChiakiTakion *takion, uint8_t flags, uint16_t channel, uint8_t *buf, size_t buf_size) +CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_message_data(ChiakiTakion *takion, uint8_t chunk_flags, uint16_t channel, uint8_t *buf, size_t buf_size) { // TODO: can we make this more memory-efficient? // TODO: split packet if necessary? @@ -357,7 +357,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_message_data(ChiakiTakion *taki return CHIAKI_ERR_MEMORY; packet_buf[0] = TAKION_PACKET_TYPE_CONTROL; - takion_write_message_header(packet_buf + 1, takion->tag_remote, key_pos, TAKION_CHUNK_TYPE_DATA, flags, 9 + buf_size); + takion_write_message_header(packet_buf + 1, takion->tag_remote, key_pos, TAKION_CHUNK_TYPE_DATA, chunk_flags, 9 + buf_size); uint8_t *msg_payload = packet_buf + 1 + TAKION_MESSAGE_HEADER_SIZE; ChiakiSeqNum32 seq_num = takion->seq_num_local++; diff --git a/lib/src/videoreceiver.c b/lib/src/videoreceiver.c index f3f829e..6234d36 100644 --- a/lib/src/videoreceiver.c +++ b/lib/src/videoreceiver.c @@ -105,7 +105,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re && !(frame_index == 1 && video_receiver->frame_index_cur < 0)) // ok for frame 1 { CHIAKI_LOGW(video_receiver->log, "Detected missing or corrupt frame(s) from %d to %d", next_frame_expected, (int)frame_index); - // TODO: report + stream_connection_send_corrupt_frame(&video_receiver->session->stream_connection, next_frame_expected, frame_index - 1); } video_receiver->frame_index_cur = frame_index;