alman
alman

Reputation: 83

MediaCodec fails for jnilibs/arm64-v8a

I'm maintaining an Android video replay app through Android Studio. All aspects of the application work fine across multiple devices (Samsung S8, S10, S20 etc) except for 64bit devices where the video decode fails. I'm looking for advice and/or an explaination as to what's causing the problem.

Below is a snippet of the code that is causing me grief. Below are the resultant logs. Basically the application works fine when run using jniLibs/armeabi however fails when run using jnilibs/arm64-v8a. The decoder threads keep failing with IllogicalArgumentException.

Code:

    private class PlayerThread3 extends Thread {
    private MediaCodec decoder;
    private Surface surface;
    public PlayerThread3(Surface surface) {
        this.surface = surface;
    }
    @Override
    public void run() {
        Log.d("PlayerThread3->Run", "Entry surface=" + surface.toString());
        MediaFormat format = MediaFormat.createVideoFormat("video/avc", mSurfaceWidth, mSurfaceHeight);
        try {
            Log.d("PlayerThread3->Run", "MediaFormat=" + format.toString());
            decoder = MediaCodec.createByCodecName("OMX.google.h264.decoder");
            Log.d("PlayerThread3->Run", "MediaCodec=" + decoder.toString());
            if (surface.isValid()) {
                Log.d("PlayerThread3->Run", "surface.isValid=" + surface.toString());
                decoder.configure(format, surface, null, 0);
            } else {
                Log.i("debug","decoder31");
                Message msg = Message.obtain();
                msg.what = 3;
                msg.obj = "Failed to start live video(surface)";
                handler.sendMessage(msg);
                return;
            }
        } catch (IllegalArgumentException e) {
            Log.d("PlayerThread3->Run", "IA surface=" + surface.toString());
            e.printStackTrace();
            Log.i("debug", "decoder32");
            Message msg = Message.obtain();
            msg.what = 3;
            msg.obj = "Failed to start live video(arg)";
            handler.sendMessage(msg);
            return;
        } catch (IOException e) {
            e.printStackTrace();
            Log.i("debug", "decoder33");
            Message msg = Message.obtain();
            msg.what = 3;
            msg.obj = "Failed to start live video(IO)";
            handler.sendMessage(msg);
            return;
        }
        try {
            decoder.start();
            inputBuffers3 = decoder.getInputBuffers();
            Message msg = Message.obtain();
            msg.what = 3;
            handler.sendMessage(msg);
            while (preferences_isAlways.getBoolean("indexDecode3" + index, false)) {
                if (decoder_array3 != null) {
                    offerDecoder(decoder_array3, decoder_array3.length);
                    decoder_array3 = null;
                }
            }
            decoder.stop();
            decoder.release();
        } catch (IllegalStateException e) {
            e.printStackTrace();
            Log.i("debug", "decoder34");
            Message msg = Message.obtain();
            msg.what = 3;
            msg.obj = "Failed to start live video(IS)";
            handler.sendMessage(msg);
        }
    }

Log:

    I/frameRate: 2
I/whichPartOfFrame: 0
I/s_frame_serial: 40
I/frame_packet_body: 1952
D/PlayerThread3->Run: Entry surface=Surface(name=null)/@0x68f7d48
D/PlayerThread3->Run: MediaFormat={mime=video/avc, width=536, height=437}
D/CCodec: allocate(c2.android.avc.decoder)
I/CCodec: Created component [c2.android.avc.decoder]
D/CCodecConfig: read media type: video/avc
D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.max-count.values
    extent() != 1 for single value type: output.subscribed-indices.values
D/ReflectedParamUpdater: extent() != 1 for single value type: input.buffers.allocator-ids.values
    extent() != 1 for single value type: output.buffers.allocator-ids.values
    extent() != 1 for single value type: algo.buffers.allocator-ids.values
    extent() != 1 for single value type: output.buffers.pool-ids.values
D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.pool-ids.values
D/ReflectedParamUpdater: ignored struct field coded.color-format.locations
D/CCodecConfig: ignoring local param raw.size (0xd2001800) as it is already supported
    ignoring local param raw.color (0xd2001809) as it is already supported
D/ReflectedParamUpdater: ignored struct field raw.hdr-static-info.mastering
I/CCodecConfig: query failed after returning 12 values (BAD_INDEX)
D/CCodecConfig: c2 config is Dict {
      c2::u32 coded.pl.level = 20496
      c2::u32 coded.pl.profile = 20481
      c2::u32 coded.vui.color.matrix = 0
      c2::u32 coded.vui.color.primaries = 0
      c2::u32 coded.vui.color.range = 2
      c2::u32 coded.vui.color.transfer = 0
      c2::u32 default.color.matrix = 0
      c2::u32 default.color.primaries = 0
      c2::u32 default.color.range = 0
      c2::u32 default.color.transfer = 0
      c2::u32 input.buffers.max-size.value = 57600
      c2::u32 input.delay.value = 0
      string input.media-type.value = "video/avc"
      c2::u32 output.delay.value = 8
      string output.media-type.value = "video/raw"
      c2::u32 raw.color.matrix = 0
      c2::u32 raw.color.primaries = 0
      c2::u32 raw.color.range = 2
      c2::u32 raw.color.transfer = 0
      c2::u32 raw.max-size.height = 240
      c2::u32 raw.max-size.width = 320
      c2::u32 raw.pixel-format.value = 35
      c2::i32 raw.rotation.flip = 0
      c2::i32 raw.rotation.value = 0
      c2::u32 raw.sar.height = 1
      c2::u32 raw.sar.width = 1
      c2::u32 raw.size.height = 240
      c2::u32 raw.size.width = 320
      c2::u32 ra
W/ColorUtils: expected specified color aspects (2:0:0:0)
D/PlayerThread3->Run: MediaCodec=android.media.MediaCodec@da3c906
    surface.isValid=Surface(name=null)/@0x68f7d48
D/SurfaceUtils: connecting to surface 0x7645de8010, reason connectToSurface
I/MediaCodec: [c2.android.avc.decoder] setting surface generation to 27948035
D/SurfaceUtils: disconnecting from surface 0x7645de8010, reason connectToSurface(reconnect)
    connecting to surface 0x7645de8010, reason connectToSurface(reconnect)
D/CCodecConfig: no c2 equivalents for native-window
    config failed => CORRUPTED
    Bad parameter value
D/CCodecConfig: c2 config is Dict {
      c2::u32 coded.pl.level = 20496
      c2::u32 coded.pl.profile = 20481
      c2::u32 coded.vui.color.matrix = 0
      c2::u32 coded.vui.color.primaries = 0
      c2::u32 coded.vui.color.range = 2
      c2::u32 coded.vui.color.transfer = 0
      c2::u32 default.color.matrix = 0
      c2::u32 default.color.primaries = 0
      c2::u32 default.color.range = 0
      c2::u32 default.color.transfer = 0
      c2::u32 input.buffers.max-size.value = 57600
      c2::u32 input.delay.value = 0
      string input.media-type.value = "video/avc"
      c2::u32 output.delay.value = 8
      string output.media-type.value = "video/raw"
      c2::u32 raw.color.matrix = 0
      c2::u32 raw.color.primaries = 0
      c2::u32 raw.color.range = 2
      c2::u32 raw.color.transfer = 0
      c2::u32 raw.max-size.height = 240
      c2::u32 raw.max-size.width = 320
      c2::u32 raw.pixel-format.value = 35
      c2::i32 raw.rotation.flip = 0
      c2::i32 raw.rotation.value = 0
      c2::u32 raw.sar.height = 1
      c2::u32 raw.sar.width = 1
      c2::u32 raw.size.height = 240
      c2::u32 raw.size.width = 536
      c2::u32 ra
W/CCodec: failed to configure c2 params
E/MediaCodec: Codec reported err 0xffffffea, actionCode 0, while in state 3
D/SurfaceUtils: disconnecting from surface 0x7645de8010, reason disconnectFromSurface
E/MediaCodec: configure failed with err 0xffffffea, resetting...
I/MediaCodec: Codec shutdown complete
D/CCodec: allocate(c2.android.avc.decoder)
I/CCodec: Created component [c2.android.avc.decoder]
D/CCodecConfig: read media type: video/avc
D/ReflectedParamUpdater: extent() != 1 for single value type: algo.buffers.max-count.values
    extent() != 1 for single value type: output.subscribed-indices.values
    extent() != 1 for single value type: input.buffers.allocator-ids.values
    extent() != 1 for single value type: output.buffers.allocator-ids.values
    extent() != 1 for single value type: algo.buffers.allocator-ids.values
    extent() != 1 for single value type: output.buffers.pool-ids.values
    extent() != 1 for single value type: algo.buffers.pool-ids.values
D/ReflectedParamUpdater: ignored struct field coded.color-format.locations
I/frameRate: 2
I/whichPartOfFrame: 0
I/s_frame_serial: 41
I/frame_packet_body: 46
D/CCodecConfig: ignoring local param raw.size (0xd2001800) as it is already supported
    ignoring local param raw.color (0xd2001809) as it is already supported
D/ReflectedParamUpdater: ignored struct field raw.hdr-static-info.mastering
I/CCodecConfig: query failed after returning 12 values (BAD_INDEX)
D/CCodecConfig: c2 config is Dict {
      c2::u32 coded.pl.level = 20496
      c2::u32 coded.pl.profile = 20481
      c2::u32 coded.vui.color.matrix = 0
      c2::u32 coded.vui.color.primaries = 0
      c2::u32 coded.vui.color.range = 2
      c2::u32 coded.vui.color.transfer = 0
      c2::u32 default.color.matrix = 0
      c2::u32 default.color.primaries = 0
      c2::u32 default.color.range = 0
      c2::u32 default.color.transfer = 0
      c2::u32 input.buffers.max-size.value = 57600
      c2::u32 input.delay.value = 0
      string input.media-type.value = "video/avc"
      c2::u32 output.delay.value = 8
      string output.media-type.value = "video/raw"
      c2::u32 raw.color.matrix = 0
      c2::u32 raw.color.primaries = 0
      c2::u32 raw.color.range = 2
      c2::u32 raw.color.transfer = 0
      c2::u32 raw.max-size.height = 240
      c2::u32 raw.max-size.width = 320
      c2::u32 raw.pixel-format.value = 35
      c2::i32 raw.rotation.flip = 0
      c2::i32 raw.rotation.value = 0
      c2::u32 raw.sar.height = 1
      c2::u32 raw.sar.width = 1
      c2::u32 raw.size.height = 240
      c2::u32 raw.size.width = 320
      c2::u32 ra
W/ColorUtils: expected specified color aspects (2:0:0:0)
D/PlayerThread3->Run: IA surface=Surface(name=null)/@0x68f7d48
W/System.err: java.lang.IllegalArgumentException
        at android.media.MediaCodec.native_configure(Native Method)
W/System.err:     at android.media.MediaCodec.configure(MediaCodec.java:2023)
        at android.media.MediaCodec.configure(MediaCodec.java:1951)
        at au.com.FreedomVMS.iFreedomVMSpro.live.ShowFragment$PlayerThread3.run(ShowFragment.java:5789)
I/debug: decoder32
I/.iFreedomVMSpr: Compiler allocated 15MB to compile void au.com.FreedomVMS.iFreedomVMSpro.live.ShowFragment.handleSocket1(int, byte, java.lang.String, int, java.lang.String, java.lang.String)
I/frameRate: 2
I/whichPartOfFrame: 1
I/s_frame_serial: 42
I/frame_packet_body: 10240
    

Upvotes: 0

Views: 1790

Answers (1)

alman
alman

Reputation: 83

Simples, problem solved. Surface dimensions, width and height, have to be multiples of 16 under Android 10. The earlier versions of Android tested against don't appear to be worried by this constraint.

Upvotes: 1

Related Questions