Skip to content

Commit 5ff5942

Browse files
author
loki
committed
Fix video packet corruption after error correction
1 parent 8c803e6 commit 5ff5942

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

sunshine/stream.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,10 @@ void videoBroadcastThread(udp::socket &sock) {
912912

913913
auto blockIndex = 0;
914914
std::for_each(fec_blocks_begin, fec_blocks_end, [&](std::string_view &current_payload) {
915-
auto shards = fec::encode(current_payload, blocksize, fecPercentage, session->config.minRequiredFecPackets);
915+
auto packets = (current_payload.size() + (blocksize - 1)) / blocksize;
916916

917-
// set FEC info now that we know for sure what our percentage will be for this frame
918-
for(auto x = 0; x < shards.size(); ++x) {
919-
auto *inspect = (video_packet_raw_t *)shards.data(x);
917+
for(int x = 0; x < packets; ++x) {
918+
auto *inspect = (video_packet_raw_t *)&current_payload[x * blocksize];
920919

921920
inspect->packet.frameIndex = packet->pts;
922921
inspect->packet.streamPacketIndex = ((uint32_t)lowseq + x) << 8;
@@ -925,21 +924,31 @@ void videoBroadcastThread(udp::socket &sock) {
925924
inspect->packet.multiFecFlags = 0x10;
926925
inspect->packet.multiFecBlocks = (blockIndex << 4) | lastBlockIndex;
927926

928-
inspect->packet.fecInfo =
929-
(x << 12 |
930-
shards.data_shards << 22 |
931-
shards.percentage << 4);
932-
933927
if(x == 0) {
934928
inspect->packet.flags |= FLAG_SOF;
935929
}
936930

937-
if(x == shards.data_shards - 1) {
931+
if(x == packets - 1) {
938932
inspect->packet.flags |= FLAG_EOF;
939933
}
934+
}
935+
936+
auto shards = fec::encode(current_payload, blocksize, fecPercentage, session->config.minRequiredFecPackets);
937+
938+
// set FEC info now that we know for sure what our percentage will be for this frame
939+
for(auto x = 0; x < shards.size(); ++x) {
940+
auto *inspect = (video_packet_raw_t *)shards.data(x);
941+
942+
inspect->packet.fecInfo =
943+
(x << 12 |
944+
shards.data_shards << 22 |
945+
shards.percentage << 4);
940946

941947
inspect->rtp.header = 0x80 | FLAG_EXTENSION;
942948
inspect->rtp.sequenceNumber = util::endian::big<uint16_t>(lowseq + x);
949+
950+
inspect->packet.multiFecBlocks = (blockIndex << 4) | lastBlockIndex;
951+
inspect->packet.frameIndex = packet->pts;
943952
}
944953

945954
for(auto x = 0; x < shards.size(); ++x) {

0 commit comments

Comments
 (0)