Skip to content

Commit

Permalink
Fix reading MP4 (bug from #205) (#207)
Browse files Browse the repository at this point in the history
After #205, tsMuxer is reading over the end of the mp4 file, which results in erratic behavior -Visual Studio build works correctly, but cmake build does not.
This fix allows to stop the reading of the mp4 file at the last atom, before end of file.
  • Loading branch information
jcdr428 authored Feb 27, 2020
1 parent 1bead15 commit fcaf4cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tsMuxer/movDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,16 @@ void MovDemuxer::openFile(const std::string& streamName)
num_tracks = 0;

readClose();

BufferedFileReader* fileReader = dynamic_cast<BufferedFileReader*>(m_bufferedReader);
if (!m_bufferedReader->openStream(m_readerID, streamName.c_str()))
THROW(ERR_FILE_NOT_FOUND, "Can't open stream " << streamName);

File tmpFile;
tmpFile.open(streamName.c_str(), File::ofRead);
tmpFile.size(&m_fileSize);
tmpFile.close();

m_processedBytes = 0;
m_isEOF = false;
readHeaders();
Expand Down Expand Up @@ -829,13 +836,13 @@ int MovDemuxer::mov_read_default(MOVAtom atom)
break;
}
}
if (m_processedBytes + left >= m_fileSize)
return 0;

skip_bytes(left);

a.offset += a.size;
total_size += a.size;

if (m_curPos == m_bufEnd)
m_isEOF = true;
}

if (!err && total_size < atom.size && atom.size < 0x7ffff)
Expand Down
1 change: 1 addition & 0 deletions tsMuxer/movDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MovDemuxer : public IOContextDemuxer
bool found_moof;
int64_t m_mdat_pos;
int64_t m_mdat_size;
uint64_t m_fileSize;
std::vector<std::pair<int64_t, uint64_t>> m_mdat_data;
int itunes_metadata; ///< metadata are itunes style
int64_t moof_offset;
Expand Down

0 comments on commit fcaf4cb

Please sign in to comment.