How to get SPS/PPS data out of hardware encoder?

Hi,
Please refer to this patch:
Xavier AGX : Video encoding crash - #15 by DaneLLL

The first buffer has SPS/PPS, please read NAL unit type to get the information.