@@ -266,8 +266,6 @@ bool FileProcessor::ProcessBlocks()
266266 BlockBuffer block_buffer;
267267 bool success = true ;
268268
269- int64_t frame_begin_offset = util::platform::FileTell (active_files_.find (file_stack_.back ().filename )->second .fd );
270- int64_t frame_begin_block_index = block_index_;
271269
272270 auto err_handler = [this ](BlockIOError err, const char * message) { HandleBlockReadError (err, message); };
273271 BlockParser block_parser (BlockParser::ErrorHandler{ err_handler }, pool_, compressor_.get ());
@@ -277,80 +275,94 @@ bool FileProcessor::ProcessBlocks()
277275 ProcessVisitor process_visitor (*this );
278276 DispatchVisitor dispatch_visitor (decoders_, annotation_handler_);
279277
280- // while (success)
281- // {
282- // PrintBlockInfo ();
283- // success = ContinueDecoding();
284- // }
278+ int64_t frame_begin_offset = - 1 ;
279+ if (!file_stack_. empty () && file_stack_. back (). active_file ) {
280+ frame_begin_offset = file_stack_. back (). active_file -> GetCurrentPos ();
281+ }
282+ int64_t frame_begin_block_index = block_index_;
285283
286- for (int frame_repeat_n = 0 ; frame_repeat_n < repeat_frame_n_times_ + 1 ; ++frame_repeat_n) {
287- if (frame_repeat_n > 0 ) {
284+ for (uint32_t frame_repeat_n = 0 ; frame_repeat_n < repeat_frame_n_times_ + 1 ; ++frame_repeat_n)
285+ {
286+ if (frame_repeat_n > 0 )
287+ {
288288 SeekActiveFile (frame_begin_offset, util::platform::FileSeekSet);
289289 block_index_ = frame_begin_block_index;
290- success = true ;
290+ success = true ;
291291 }
292+
292293 while (success)
293294 {
294- success = GetBlockBuffer (block_parser, block_buffer);
295-
296- for (auto decoder : decoders_)
297- {
298- decoder->SetCurrentBlockIndex (block_index_);
299- }
295+ PrintBlockInfo ();
296+ success = ContinueDecoding ();
300297
301298 if (success)
302299 {
303- if (SkipBlockProcessing ())
300+ success = GetBlockBuffer (block_parser, block_buffer);
301+
302+ for (auto decoder : decoders_)
304303 {
305- GFXRECON_CHECK_CONVERSION_DATA_LOSS ( size_t , block_buffer. Header (). size );
304+ decoder-> SetCurrentBlockIndex (block_index_ );
306305 }
307306
308- else
307+ if (success)
309308 {
310- block_parser.SetBlockIndex (block_index_);
311- block_parser.SetFrameNumber (current_frame_number_);
312- // NOTE: upon successful parsing, the block_buffer block data has been moved to the
313- // parsed_block, though the block header is still valid.
314- ParsedBlock parsed_block = block_parser.ParseBlock (block_buffer);
315-
316- // NOTE: Visitable is either Ready or DeferredDecompression,
317- // Invalid, Unknown, and Skip are not Visitable
318- if (parsed_block.IsVisitable ())
309+ if (SkipBlockProcessing ())
319310 {
320- // Deferred decompress failure implies a late uncovering of an invalid block.
321- success = parsed_block.Decompress (block_parser); // Safe without testing block state.
322- if (success)
311+ GFXRECON_CHECK_CONVERSION_DATA_LOSS (size_t , block_buffer.Header ().size );
312+ }
313+ else
314+ {
315+ block_parser.SetBlockIndex (block_index_);
316+ block_parser.SetFrameNumber (current_frame_number_);
317+ // NOTE: upon successful parsing, the block_buffer block data has been moved to the
318+ // parsed_block, though the block header is still valid.
319+ ParsedBlock parsed_block = block_parser.ParseBlock (block_buffer);
320+
321+ if (parsed_block.Holds <FrameEndMarkerArgs>())
323322 {
324- std::visit (process_visitor, parsed_block.GetArgs ());
325- success = process_visitor.IsSuccess ();
323+ frame_begin_offset = file_stack_.back ().active_file ->GetCurrentPos ();
324+ frame_begin_block_index = block_index_ + 1 ;
325+ }
326+
327+ // NOTE: Visitable is either Ready or DeferredDecompression,
328+ // Invalid, Unknown, and Skip are not Visitable
329+ if (parsed_block.IsVisitable ())
330+ {
331+ // Deferred decompress failure implies a late uncovering of an invalid block.
332+ success = parsed_block.Decompress (block_parser); // Safe without testing block state.
326333 if (success)
327334 {
328- std::visit (dispatch_visitor, parsed_block.GetArgs ());
335+ std::visit (process_visitor, parsed_block.GetArgs ());
336+ success = process_visitor.IsSuccess ();
337+ if (success)
338+ {
339+ std::visit (dispatch_visitor, parsed_block.GetArgs ());
340+ }
329341 }
330342 }
331- }
332343
333- // NOTE: Warnings for unknown/invalid blocks are handled in the BlockParser
344+ // NOTE: Warnings for unknown/invalid blocks are handled in the BlockParser
334345
335- if (process_visitor.IsFrameDelimiter ())
336- {
337- // The ProcessVisitor (pre-dispatch) is not the right place to update the frame state, so do it
338- // here
339- UpdateEndFrameState ();
340- break ;
346+ if (process_visitor.IsFrameDelimiter ())
347+ {
348+ // The ProcessVisitor (pre-dispatch) is not the right place to update the frame state, so do
349+ // it here
350+ UpdateEndFrameState ();
351+ break ;
352+ }
341353 }
342354 }
343- }
344- else
345- {
346355
347- success = HandleBlockEof (" read" , true );
356+ else
357+ {
358+ success = HandleBlockEof (" read" , true );
359+ }
348360 }
349361 ++block_index_;
350- DecrementRemainingCommands ();
362+ if (frame_repeat_n == repeat_frame_n_times_) {
363+ DecrementRemainingCommands ();
364+ }
351365 }
352-
353- DecrementRemainingCommands ();
354366 }
355367 return success;
356368}
0 commit comments