Encoder crash on Adreno GPU while encoding from Surface

I've been struggling with this issue for more than a week, and most likely it is a bug in the Qualcomm GPU/hardware video encoder. Since we are pressed to release the application, and their developer forums did not provide any feedback, I am posting it here too, hoping that someone is able to provide some clues, or even better, a workaround so that the bug in the encoder is not triggered.

The application encodes from a Surface. When certain images are rendered to the surface, the encoder fails (100%) in the same place (when the frame currently being encoded is a key frame). The Logcat output from the encoder at the point of the crash is(with the last lines repeated at a very high rate):

11-26 11:41:33.312: E/OMX-VENC-720p(25949): ERROR: async_msg_process() - Error statuscode = 1
11-26 11:41:33.312: E/ACodec(29317): [OMX.qcom.video.encoder.avc] ERROR(0x80001009)
11-26 11:41:33.312: E/MediaCodec(29317): Codec reported an error. (omx error 0x80001009, internalError -2147483648)
11-26 11:41:33.362: E/OMX-VENC-720p(25949): ERROR: venc_use_buf:set input buffer failed 
11-26 11:41:33.362: E/OMX-VENC-720p(25949): ERROR: in dev_use_buf
11-26 11:41:33.362: E/OMX-VENC-720p(25949): ERROR: empty_buffer_done() failed!
11-26 11:41:33.372: E/OMX-VENC-720p(25949): m_fbd_count at o/p flush = 306
11-26 11:41:33.372: E/OMX-VENC-720p(25949): m_etb_count at i/p flush = 313
11-26 11:41:33.372: E/OMX-VENC-720p(25949): ERROR: ioctl VEN_IOCTL_CMD_FILL_OUTPUT_BUFFER failed
11-26 11:41:33.372: E/OMX-VENC-720p(25949): ERROR: dev_fill_buf() Failed
11-26 11:41:33.372: E/OMX-VENC-720p(25949): ERROR: FTBProxy() failed!

I can replicate it also on Grafika by simply replacing in the Record GL app the drawing of two geometric forms with drawing one of the problematic images, full screen, in landscape mode, and changing the bitrate to a higher value (7Mbps). The crash of the encoder happens sooner for larger bitrate.

Here is one image that seems to break it easily and here is RecordFBOActivity.java with the required changes.

With Grafika, I tested and the encoder crashes on both Samsung S4, international version, and on the original Nexus 4. With our software, which is a little more complex than rendering the plain image, it still crashes on both. Did not test on any other Adreno devices. On Samsung S3, with a Mali 400 GPU, it works fine.

At 4Mbps, the encoder in our application still crashes on both S4 and N4, but later. Grafika crashes on N4 in the same place, but not on S4.

EDIT: According to comments bellow, it can be reproduced also when encoding the same image from the buffer. Various tests seem to narrow the conditions to reproduce it at: h264 hw encoder on Qualcomm devices, encoding a still image for many frames (this determines very low bitrates in the encoder due to similar frames), error appearing while encoding a key frame (the error appears only when encoding certain images, which seem to have more detail, i.e. need many bits for intra coding).


Solution 1:

It seems to be a bug as previously stated above.