diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-10-01 20:11:40 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-10-03 17:53:00 +0200 |
| commit | 3f102aefcf7114bc12ab984bb671bd900010338e (patch) | |
| tree | f5473367bea6b326dfe9c7af599735401de2aee0 /src/lib | |
| parent | 011ac67d2340a5f2302f611b0fc92ce80dee8e42 (diff) | |
Return AVERROR_EOF from the avio_read method when appropriate.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ffmpeg.cc | 6 | ||||
| -rw-r--r-- | src/lib/file_group.cc | 7 | ||||
| -rw-r--r-- | src/lib/file_group.h | 12 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index 6c8509b6c..8220962d6 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -273,7 +273,11 @@ FFmpeg::subtitle_codec_context () const int FFmpeg::avio_read (uint8_t* buffer, int const amount) { - return _file_group.read (buffer, amount); + auto result = _file_group.read(buffer, amount); + if (result.eof && result.bytes_read == 0) { + return AVERROR_EOF; + } + return result.bytes_read; } diff --git a/src/lib/file_group.cc b/src/lib/file_group.cc index 71faacc4c..f4d50028e 100644 --- a/src/lib/file_group.cc +++ b/src/lib/file_group.cc @@ -134,9 +134,8 @@ FileGroup::seek (int64_t pos, int whence) const /** Try to read some data from the current position into a buffer. * @param buffer Buffer to write data into. * @param amount Number of bytes to read. - * @return Number of bytes read. */ -int +FileGroup::Result FileGroup::read (uint8_t* buffer, int amount) const { DCPOMATIC_ASSERT (_current_file); @@ -173,13 +172,13 @@ FileGroup::read (uint8_t* buffer, int amount) const if (eof) { /* See if there is another file to use */ if ((_current_path + 1) >= _paths.size()) { - break; + return { read, true }; } ensure_open_path (_current_path + 1); } } - return read; + return { read, false }; } diff --git a/src/lib/file_group.h b/src/lib/file_group.h index 693bf89ba..aac72c228 100644 --- a/src/lib/file_group.h +++ b/src/lib/file_group.h @@ -49,8 +49,18 @@ public: void set_paths (std::vector<boost::filesystem::path> const &); + struct Result { + Result(int bytes_read_, bool eof_) + : bytes_read(bytes_read_) + , eof(eof_) + {} + + int bytes_read = 0; + bool eof = false; + }; + int64_t seek (int64_t, int) const; - int read (uint8_t*, int) const; + Result read (uint8_t*, int) const; int64_t length () const; private: |
