简体   繁体   English

Android MediaCodec如何创建解码器?

[英]How does Android MediaCodec create a decoder?

I've noticed that java/android/media has a method called createDecoderByType() that is supposed to return a MediaCodec object. 我注意到java/android/media有一个名为createDecoderByType()的方法,该方法应该返回MediaCodec对象。 However, when I look at the MediaCodec.java source code on GoogleGit , I can't really see how the actual decoder is generated. 但是,当我查看GoogleGit上的MediaCodec.java 源代码时 ,我真的看不到实际的解码器是如何生成的。 Here is the code for that method: 这是该方法的代码:

    public static MediaCodec createDecoderByType(String type) {
    return new MediaCodec(type, true /* nameIsType */, false /* encoder */);
}

Then when I look at the constructor to see what is returned, this is what I see: 然后,当我查看构造函数以查看返回的内容时,这就是我看到的内容:

    private MediaCodec(
        String name, boolean nameIsType, boolean encoder) {
    native_setup(name, nameIsType, encoder);
}

Okay, great. 好,太棒了。 Let's look at native_setup() . 让我们看一下native_setup() Here's the definition: 定义如下:

    private native final void native_setup(
        String name, boolean nameIsType, boolean encoder);

That function appears to have no body! 该功能似乎没有主体!

At first I assumed that this meant the method would be defined in a child class. 起初,我认为这意味着该方法将在子类中定义。 But I am seeing this method called directly on MediaCodec itself in other functioning source code. 但是我看到此方法在其他功能正常的源代码中直接在MediaCodec本身上调用。

So my question is: Is there any way I can trace down and see how Android creates a decoder of a given type depending on the environment and parameters? 所以我的问题是:有什么办法可以追踪并查看Android如何根据环境和参数创建给定类型的解码器? I seem to have hit a dead end, and no amount of Googling is giving me any helpful results. 我似乎走到了尽头,谷歌搜索没有给我任何有益的结果。

Just found the answer to this the minute after I posted it...of course. 我刚发布它的那一刻才找到答案。 The issue is with the native keyword. 问题出在native关键字。 From GeeksforGeeks: 来自GeeksforGeeks:

The native keyword is applied to a method to indicates that the method is implemented in native code using JNI (Java Native Interface). 将native关键字应用于方法,以指示该方法是使用JNI(Java本机接口)以本机代码实现的。

This means that it can be written in another language such as C or C++, or invoke hardware stuff. 这意味着它可以用其他语言(例如C或C ++)编写,也可以调用硬件。 The MediaCodec JNI code that I was looking for is here . 我正在寻找的MediaCodec JNI代码在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM