⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

NDK media codec configuration error (AMediaCodec_configure)

  • Hi Forum,

    I have a problem during my Android application initialization stage. I am looking to use the NDK native media codec directely. Everything seems to be ok until I call the function AMediaCodec_configure, that works correctly if I do not give it a reference on the native_window, but that produces an error (see below) if I give it a native_window obtained by the function getNativeWindow (see below). The getNativeWindow gives me a correct native window reference. The error returned is :

    D libndkmediacodec.so: (null):0 ((null)): This is a ANativeWindow 0xc6e94808 800 1248
    D SurfaceUtils: connecting to surface 0xc6e94808, reason connectToSurface
    E SurfaceUtils: Failed to connect to surface 0xc6e94808, err -22
    E MediaCodec: nativeWindowConnect returned an error: Invalid argument (-22)
    E MediaCodec: configure failed with err 0xffffffea, resetting...
    I ACodec : [OMX.Exynos.avc.dec] Now uninitialized
    I ACodec : [] Now kWhatShutdownCompleted event : 8532
    I MediaCodec: Codec shutdown complete
    I ACodec : [] Now uninitialized
    I ACodec : [] onAllocateComponent
    I ACodec : Set Google AAC Dec for aacProfile 0
    I OMXClient: Treble IOmx obtained
    I ACodec : [OMX.Exynos.avc.dec] Now Loaded
    E NdkMediaCodec: sf error code: -22
    W libndkmediacodec.so: (null):0 ((null)): Error occurred: -10000
    E NdkMediaCodec: sf error code: -38
    W libndkmediacodec.so: (null):0 ((null)): Error occurred: -10000
    D libndkmediacodec.so: (null):0 ((null)): Decoder ready!
    W AMessage: failed to deliver message as target handler 1 is gone.

    Context : Qt 5.11, Android 8 (armeabi_v7a), NDK r10e, SDK API 24, android-g++

    Thanks for your ideas, suggestions or help.



    • \brief NativeCodecReader::getNativeWindow
      ANativeWindow *native_window = nullptr;
      QPlatformNativeInterface *nativeInterface = QApplication::platformNativeInterface();
      jobject activity = (jobject)nativeInterface->nativeResourceForIntegration("QtActivity");
      QAndroidJniEnvironment *qjniEnv;
      JNIEnv *jniEnv;
      JavaVM *jvm = qjniEnv->javaVM();

      jvm->GetEnv(reinterpret_cast<void**>(&qjniEnv), JNI_VERSION_1_6);

      jint r_id_content = QAndroidJniObject::getStaticField<jint>("android/R$id", "content");

      // Finds the first descendant view with the given ID,
      QAndroidJniObject view = ((QAndroidJniObject) activity).callObjectMethod("findViewById", "(I)Landroid/view/View;", r_id_content);
      if (view.isValid())
      // Returns the view at the specified position in the group
      QAndroidJniObject child1 = view.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0);
      QAndroidJniObject child2 = child1.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0);
      if (child2.isValid())
      // Get a surface holder from Java
      QAndroidJniObject sHolder = child2.callObjectMethod("getHolder","()Landroid/view/SurfaceHolder;");
      if (sHolder.isValid())
      // Request a surface to Java
      QAndroidJniObject theSurface = sHolder.callObjectMethod("getSurface","()Landroid/view/Surface;");
      if (theSurface.isValid())
      // Return the ANativeWindow associated with a Java Surface object, for interacting with it through native code
      native_window = ANativeWindow_fromSurface(jniEnv, theSurface.object());

                   int32_t height,width;
                   width   = ANativeWindow_getWidth(native_window);
                   height  = ANativeWindow_getHeight(native_window);
                   qDebug() << "This is a ANativeWindow " << native_window << width << height;
           qDebug() << "Views are not loaded yet or you are not in the Qt UI Thread";

      return native_window;

Log in to reply