@@ -912,11 +912,10 @@ void videoBroadcastThread(udp::socket &sock) {
912
912
913
913
auto blockIndex = 0 ;
914
914
std::for_each (fec_blocks_begin, fec_blocks_end, [&](std::string_view ¤t_payload) {
915
- auto shards = fec::encode (current_payload, blocksize, fecPercentage, session-> config . minRequiredFecPackets ) ;
915
+ auto packets = (current_payload. size () + ( blocksize - 1 )) / blocksize ;
916
916
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 *)¤t_payload[x * blocksize];
920
919
921
920
inspect->packet .frameIndex = packet->pts ;
922
921
inspect->packet .streamPacketIndex = ((uint32_t )lowseq + x) << 8 ;
@@ -925,21 +924,31 @@ void videoBroadcastThread(udp::socket &sock) {
925
924
inspect->packet .multiFecFlags = 0x10 ;
926
925
inspect->packet .multiFecBlocks = (blockIndex << 4 ) | lastBlockIndex;
927
926
928
- inspect->packet .fecInfo =
929
- (x << 12 |
930
- shards.data_shards << 22 |
931
- shards.percentage << 4 );
932
-
933
927
if (x == 0 ) {
934
928
inspect->packet .flags |= FLAG_SOF;
935
929
}
936
930
937
- if (x == shards. data_shards - 1 ) {
931
+ if (x == packets - 1 ) {
938
932
inspect->packet .flags |= FLAG_EOF;
939
933
}
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 );
940
946
941
947
inspect->rtp .header = 0x80 | FLAG_EXTENSION;
942
948
inspect->rtp .sequenceNumber = util::endian::big<uint16_t >(lowseq + x);
949
+
950
+ inspect->packet .multiFecBlocks = (blockIndex << 4 ) | lastBlockIndex;
951
+ inspect->packet .frameIndex = packet->pts ;
943
952
}
944
953
945
954
for (auto x = 0 ; x < shards.size (); ++x) {
0 commit comments