Attitude calculation and how to use it

I’m trying to understand low level attitude estimation of ardupilot. Currently I use extnav (visual odometry) to make transnational data and at the same time listen to /mavros/imu/data topic. I use orientation quaternion from this to make a complete ODOMETRY message and send it to ardupilot .
the issue is, I’m not sure if /mavros/imu/data/orientation is the RAW orientation or orientation estimated by ardupilot ekf . in case if its orientation output of ekf, and i use this to make my odometry extnav message and send it again to ardupilot, then when i switch the source to source 2 (extnav) then I would end up feeding the outputted orientation back to the system. this might result in a circular error growing over time if not corrected by raw sensor measurement in between 2 extnav messages.

ultimately, my idea is to generate transnational data from extnav and continue to use ardupilot’s inbuild attitude estimation (through /mavros/imu/data maybe) to drive the drone. what would be the best way to achieve this ?
and could someone point me to the starting point of the attitude estimation code?

It’s all done in the EKF3. There is documentation about it in the dev documentation and there are Paul Riseborough videos on YouTube about it.

thank you.

can you also give some advise regarding this ? thankss