HEVC/h.265 ES reader: clear parser's buffer after reading the headers

After reading the headers, the file is read again from the
start. Therefore no data must be left in the parser's internal
buffers. That was the intention behind calling `flush()` - but that
isn't actually what flush does. Instead it tries to use the remaining
data in the buffers as a frame.

This is not only wrong, it can also fail and cause an exception to be
thrown. That in turn causes a failure when reading the headers — both
identification and muxing abort at that point.

This is the HEVC analog for what was fixed for AVC in #2325.
This commit is contained in:
Moritz Bunkus 2018-06-13 17:57:20 +02:00
parent ee46e1c7ab
commit 9afc43b209
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
4 changed files with 13 additions and 3 deletions

View File

@ -8,6 +8,9 @@
* mkvmerge: AVC/h.264: fixed file identification failing for certain
elementary streams due to internal buffers not being cleared properly. Fixes
#2325.
* mkvmerge: HEVC/h.265: fixed file identification failing for certain
elementary streams due to internal buffers not being cleared properly. This
is the HEVC analog to what was fixed for AVC in #2325.
# Version 24.0.0 "Beyond The Pale" 2018-06-10

View File

@ -192,6 +192,13 @@ es_parser_c::flush() {
cleanup();
}
void
es_parser_c::clear() {
m_unparsed_buffer.reset();
m_have_incomplete_frame = false;
m_parsed_position = 0;
}
void
es_parser_c::add_timestamp(int64_t timestamp) {
m_provided_timestamps.emplace_back(timestamp, m_stream_position);

View File

@ -119,6 +119,7 @@ public:
}
void flush();
void clear();
bool frame_available() {
return !m_frames_out.empty();

View File

@ -89,14 +89,13 @@ hevc_es_reader_c::read_headers() {
break;
}
if (parser.headers_parsed())
parser.flush();
m_width = parser.get_width();
m_height = parser.get_height();
m_in->setFilePointer(0, seek_beginning);
parser.clear();
} catch (...) {
throw mtx::input::open_x();
}