diff --git a/examples/streamer/h264fileparser.cpp b/examples/streamer/h264fileparser.cpp index cc8a6aa3f..d5bb556df 100644 --- a/examples/streamer/h264fileparser.cpp +++ b/examples/streamer/h264fileparser.cpp @@ -11,6 +11,7 @@ #include "rtc/rtc.hpp" #include +#include #ifdef _WIN32 #include @@ -29,7 +30,9 @@ void H264FileParser::loadNextSample() { while (i < sample.size()) { assert(i + 4 < sample.size()); auto lengthPtr = (uint32_t *) (sample.data() + i); - uint32_t length = ntohl(*lengthPtr); + uint32_t length; + std::memcpy(&length, lengthPtr, sizeof(uint32_t)); + length = ntohl(length); auto naluStartIndex = i + 4; auto naluEndIndex = naluStartIndex + length; assert(naluEndIndex <= sample.size()); diff --git a/src/h264rtppacketizer.cpp b/src/h264rtppacketizer.cpp index cb01d00b2..aa923cfa5 100644 --- a/src/h264rtppacketizer.cpp +++ b/src/h264rtppacketizer.cpp @@ -32,8 +32,9 @@ shared_ptr H264RtpPacketizer::splitMessage(binary_ptr message) { LOG_WARNING << "Invalid NAL Unit data (incomplete length), ignoring!"; break; } - auto lengthPtr = (uint32_t *)(message->data() + index); - uint32_t length = ntohl(*lengthPtr); + uint32_t length; + std::memcpy(&length, message->data() + index, sizeof(uint32_t)); + length = ntohl(length); auto naluStartIndex = index + 4; auto naluEndIndex = naluStartIndex + length; diff --git a/src/h265rtppacketizer.cpp b/src/h265rtppacketizer.cpp index 5776dafa8..e4c60c79a 100644 --- a/src/h265rtppacketizer.cpp +++ b/src/h265rtppacketizer.cpp @@ -32,8 +32,9 @@ shared_ptr H265RtpPacketizer::splitMessage(binary_ptr message) { LOG_WARNING << "Invalid NAL Unit data (incomplete length), ignoring!"; break; } - auto lengthPtr = (uint32_t *)(message->data() + index); - uint32_t length = ntohl(*lengthPtr); + uint32_t length; + std::memcpy(&length, message->data() + index, sizeof(uint32_t)); + length = ntohl(length); auto naluStartIndex = index + 4; auto naluEndIndex = naluStartIndex + length;