Search code examples
decodeandroid-mediacodechuawei-mobile-serviceshuawei-developers

Serious delay using Huawei MediaCodec decoding H264 rendering TextureView


"Huawei P30 uses MediaCodec hardware to decode the H264 stream, and then directly render it to TextureView for display."

It is found that compared to other mobile phone platforms, the delay of Huawei P30 is about 200ms longer than other mobile phones.

In the process of configuring the use of MediaCodec, some error logs of the Native fw layer were found, although they can be decoded and rendered normally;

The following error is reported when executing MediaCodec.configure(****):

D/SurfaceUtils: connecting to surface 0xc3a99808, reason connectToSurface
I/MediaCodec: [OMX.hisi.video.decoder.avc] setting surface generation to 33448961
D/SurfaceUtils: disconnecting from surface 0xc3a99808, reason connectToSurface(reconnect)
D/SurfaceUtils: connecting to surface 0xc3a99808, reason connectToSurface(reconnect)
E/ACodec: [OMX.hisi.video.decoder.avc] setPortMode on output to DynamicANWBuffer failed w/ err -2147483648
I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:1(BT709_5), M:1(BT709_5), T:3(SMPTE170M)) err=0 (NO_ERROR)
I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:1(BT709_5), M:1(BT709_5), T:3(SMPTE170M)) err=0 (NO_ERROR)
I/ACodec: [OMX.hisi.video.decoder.avc] using color aspects (R:2(Limited), P:1(BT709_5), M:1(BT709_5), T:3(SMPTE170M)) and dataspace 0x104

The following warning appears during the decoding process:

I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) err=0 (NO_ERROR)
I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) err=0 (NO_ERROR)
I/ACodec: [OMX.hisi.video.decoder.avc] using color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) and dataspace 0x102
I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) err=0 (NO_ERROR)
I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) err=0 (NO_ERROR)
I/ACodec: [OMX.hisi.video.decoder.avc] using color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) and dataspace 0x102
D/SurfaceUtils: disconnecting from surface 0xc3a99808, reason setNativeWindowSizeFormatAndUsage
D/SurfaceUtils: connecting to surface 0xc3a99808, reason setNativeWindowSizeFormatAndUsage
D/SurfaceUtils: set up nativeWindow 0xc3a99808 for 720x1280, color 0x30d, rotation 0, usage 0X20002900
W/ACodec: [OMX.hisi.video.decoder.avc] setting nBufferCountActual to 11 failed: -2147483648"

Solution

  • These logs are not related to the delay. If the OMX.hisi.video.decoder.avc hardware decoder does not support some configurations, the logs are printed to facilitate fault locating.

    (For example, if the DynamicAnwBuffer in bold is a port configuration, the other port mode is used if it is not supported, which does not affect decoding.)

    I do not know how to calculate the delay of 200 ms, which can be divided into the H.264 video decoding time and the time for rendering to TextureView,。

    To obtain the decoding delay, you can obtain the specific time difference by adding logs when the decoded data is input and the decoded output is obtained. Compare the time difference with that of other mobile phones and further analyze the time difference.

    In addition, the decoder and texture configurations (such as the resolution and frame rate) also affect the performance. Alternatively, you can provide a method for R&D engineers to reproduce the problem for analysis.

    Thank you for your support!