Note: this also contains some bug fixed for scalable nesting SEI itself. These should have gone to the refactoring MR !1627 (merged), but I didn't notice early enough and didn't want to create another MR that this one would depend upon.
Bug fixes are outside the macro.