From b0e3019fb301362dedd376ba3f4fb7263b277c11 Mon Sep 17 00:00:00 2001 From: erikmchut Date: Wed, 13 May 2020 11:49:41 -0700 Subject: [PATCH] Remove std::optional entirely for compatibility on older toolchains. --- src/mp4.cpp | 6 +++--- src/mp4file.cpp | 19 ++++++++----------- src/mp4file.h | 4 +--- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/mp4.cpp b/src/mp4.cpp index 42fb8dd..70b2145 100644 --- a/src/mp4.cpp +++ b/src/mp4.cpp @@ -2236,9 +2236,9 @@ MP4FileHandle MP4ReadProvider( const char* fileName, const MP4FileProvider* file MP4FileHandle hFile, MP4TrackId trackId) { if (MP4_IS_VALID_FILE_HANDLE(hFile)) { - auto index = ((MP4File*)hFile)->MaybeFindTrackIndex(trackId); - if (index.has_value()) { - return index.value(); + MP4File* phFile = reinterpret_cast(hFile); + if (phFile->TrackIndexExists(trackId)) { + return phFile->FindTrackIndex(trackId); } mp4v2::impl::log.errorf( "%s: failed", __FUNCTION__ ); } diff --git a/src/mp4file.cpp b/src/mp4file.cpp index 8cba2e8..a77fa21 100644 --- a/src/mp4file.cpp +++ b/src/mp4file.cpp @@ -2857,8 +2857,7 @@ MP4TrackId MP4File::AllocTrackId() if (trackId <= 0xFFFF) { // check that nextTrackid is correct - auto index = MaybeFindTrackIndex(trackId); - if (!index.has_value()) { + if (!TrackIndexExists(trackId)) { // OK, this trackId is not in use, proceed SetIntegerProperty("moov.mvhd.nextTrackId", trackId + 1); return trackId; @@ -2867,8 +2866,7 @@ MP4TrackId MP4File::AllocTrackId() // we need to search for a track id for (trackId = 1; trackId <= 0xFFFF; trackId++) { - auto index = MaybeFindTrackIndex(trackId); - if (!index.has_value()) { + if (!TrackIndexExists(trackId)) { // OK, this trackId is not in use, proceed return trackId; } @@ -2932,14 +2930,13 @@ uint16_t MP4File::FindTrackIndex(MP4TrackId trackId) return (uint16_t)-1; // satisfy MS compiler } -std::optional MP4File::MaybeFindTrackIndex(MP4TrackId trackId) -{ - for (uint32_t i = 0; i < m_pTracks.Size() && i <= 0xFFFF; i++) { - if (m_pTracks[i]->GetId() == trackId) { - return (uint16_t)i; - } +bool MP4File::TrackIndexExists(MP4TrackId trackId) { + for (uint32_t i = 0; i < m_pTracks.Size() && i <= 0xFFFF; i++) { + if (m_pTracks[i]->GetId() == trackId) { + return true; } - return {}; + } + return false; } uint16_t MP4File::FindTrakAtomIndex(MP4TrackId trackId) diff --git a/src/mp4file.h b/src/mp4file.h index 45686c3..9a62d42 100644 --- a/src/mp4file.h +++ b/src/mp4file.h @@ -33,8 +33,6 @@ #ifndef MP4V2_IMPL_MP4FILE_H #define MP4V2_IMPL_MP4FILE_H -#include - namespace mp4v2 { namespace impl { /////////////////////////////////////////////////////////////////////////////// @@ -148,7 +146,7 @@ class MP4File MP4TrackId FindTrackId(uint16_t trackIndex, const char* type = NULL, uint8_t subType = 0); uint16_t FindTrackIndex(MP4TrackId trackId); - std::optional MaybeFindTrackIndex(MP4TrackId trackId); + bool TrackIndexExists(MP4TrackId trackId); uint16_t FindTrakAtomIndex(MP4TrackId trackId); /* track properties */