Add Corrupt Frame Reporting

This commit is contained in:
Florian Märkl 2019-07-29 22:42:11 +02:00
commit 785ff38db4
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
5 changed files with 28 additions and 4 deletions

View file

@ -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

View file

@ -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.

View file

@ -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);
}

View file

@ -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++;

View file

@ -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;