Optimize the code to set the refernce frame right after reading the header. Change-Id: I495cf4a366e06e3220ed132500b1ba1c8448f708