Skip to content

Commit

Permalink
Remove std::optional entirely for compatibility on older toolchains.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmchut authored May 13, 2020
1 parent eff7427 commit b0e3019
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MP4File*>(hFile);
if (phFile->TrackIndexExists(trackId)) {
return phFile->FindTrackIndex(trackId);
}
mp4v2::impl::log.errorf( "%s: failed", __FUNCTION__ );
}
Expand Down
19 changes: 8 additions & 11 deletions src/mp4file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -2932,14 +2930,13 @@ uint16_t MP4File::FindTrackIndex(MP4TrackId trackId)
return (uint16_t)-1; // satisfy MS compiler
}

std::optional<uint16_t> 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)
Expand Down
4 changes: 1 addition & 3 deletions src/mp4file.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#ifndef MP4V2_IMPL_MP4FILE_H
#define MP4V2_IMPL_MP4FILE_H

#include <optional>

namespace mp4v2 { namespace impl {

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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<uint16_t> MaybeFindTrackIndex(MP4TrackId trackId);
bool TrackIndexExists(MP4TrackId trackId);
uint16_t FindTrakAtomIndex(MP4TrackId trackId);

/* track properties */
Expand Down

0 comments on commit b0e3019

Please sign in to comment.