From aae703182ffaf9faf5540bcc3ffbca11734c2324 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sun, 12 Mar 2023 17:18:28 +0100 Subject: [PATCH] VIDEO: MKV: Make mkvparser not use STL --- video/mkv/mkvparser.cpp | 47 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/video/mkv/mkvparser.cpp b/video/mkv/mkvparser.cpp index feadda1eeb6..71a19cd40a7 100644 --- a/video/mkv/mkvparser.cpp +++ b/video/mkv/mkvparser.cpp @@ -5,37 +5,24 @@ // tree. An additional intellectual property rights grant can be found // in the file PATENTS. All contributing project authors may // be found in the AUTHORS file in the root of the source tree. + +#include "common/math.h" +#include "common/ptr.h" +#include "common/str.h" + #include "video/mkv/mkvparser.h" - -#if defined(_MSC_VER) && _MSC_VER < 1800 -#include // _isnan() / _finite() -#define MSC_COMPAT -#endif - -#include -#include -#include -#include -#include -#include -#include - #include "video/mkv/webmids.h" +#ifndef LLONG_MAX +#define LLONG_MAX 9223372036854775807LL +#endif + namespace mkvparser { const long long kStringElementSizeLimit = 20 * 1000 * 1000; const float MasteringMetadata::kValueNotPresent = FLT_MAX; const long long Colour::kValueNotPresent = LLONG_MAX; const float Projection::kValueNotPresent = FLT_MAX; -#ifdef MSC_COMPAT -inline bool isnan(double val) { return !!_isnan(val); } -inline bool isinf(double val) { return !_finite(val); } -#else -inline bool isnan(double val) { return std::isnan(val); } -inline bool isinf(double val) { return std::isinf(val); } -#endif // MSC_COMPAT - template Type* SafeArrayAlloc(unsigned long long num_elements, unsigned long long element_size) { @@ -281,7 +268,7 @@ long UnserializeFloat(IMkvReader* pReader, long long pos, long long size_, result = d; } - if (mkvparser::isinf(result) || mkvparser::isnan(result)) + if (isinf(result) || isnan(result)) return E_FILE_FORMAT_INVALID; return 0; @@ -4552,7 +4539,7 @@ int Track::Info::CopyStr(char* Info::*str, Info& dst_) const { if (dst == NULL) return -1; - strcpy(dst, src); + Common::strlcpy(dst, src, len + 1); return 0; } @@ -5018,7 +5005,7 @@ bool MasteringMetadata::Parse(IMkvReader* reader, long long mm_start, if (!reader || *mm) return false; - std::unique_ptr mm_ptr(new MasteringMetadata()); + Common::ScopedPtr mm_ptr(new MasteringMetadata()); if (!mm_ptr.get()) return false; @@ -5107,7 +5094,7 @@ bool Colour::Parse(IMkvReader* reader, long long colour_start, if (!reader || *colour) return false; - std::unique_ptr colour_ptr(new Colour()); + Common::ScopedPtr colour_ptr(new Colour()); if (!colour_ptr.get()) return false; @@ -5205,7 +5192,7 @@ bool Projection::Parse(IMkvReader* reader, long long start, long long size, if (!reader || *projection) return false; - std::unique_ptr projection_ptr(new Projection()); + Common::ScopedPtr projection_ptr(new Projection()); if (!projection_ptr.get()) return false; @@ -5309,7 +5296,7 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info, long long stereo_mode = 0; double rate = 0.0; - std::unique_ptr colour_space_ptr; + Common::ScopedPtr> colour_space_ptr; IMkvReader* const pReader = pSegment->m_pReader; @@ -5322,8 +5309,8 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info, const long long stop = pos + s.size; - std::unique_ptr colour_ptr; - std::unique_ptr projection_ptr; + Common::ScopedPtr colour_ptr; + Common::ScopedPtr projection_ptr; while (pos < stop) { long long id, size;