diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-10-01 20:11:40 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-10-04 23:20:11 +0200 |
| commit | f583e13fe48e8b6cf4f3f9195fd31b603bc41fc2 (patch) | |
| tree | 23ef83b7c40892230455d2a5c5e8d4ea1bad4dd6 /src | |
| parent | be486380a15a9e444c761384cd6c60e77def909f (diff) | |
Return AVERROR_EOF from the avio_read method when appropriate.
Diffstat (limited to 'src')
| -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: |
