Android Multimedia Framework Summary (21) Mediacodec in the Create to start process (to the JNI section)

Source: Internet
Author: User

Reprint please the head source link and the tail two-dimensional code together reprint, this article from countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/53386117

I am recently participating in the CSDN 2016 Blog Star Award, come, drive, quickly help vote! Time: November 28 to December 18 You can vote for me every day. Address: Http://blog.csdn.net/vote/candidate.html?username=hejjunlin

The previous chapter introduces Mediacodec's description and status diagram, starting today, will be in-depth source to see its process, look at the following agenda:

    • A picture to see Mediacodec from creation to start process
    • Supplementary Mediacodec Basic usage
    • Mediacodec in Bufferinfo inner class:
    • Android_media_mediacodec.cpp
    • Android_media_mediacodec.h

A picture to see Mediacodec from Creation to start (to the JNI section)

Supplementary Mediacodec Basic usage

The use of Mediacodec follows a basic pattern:

    • 1. Creating and configuring Mediacodec objects
    • 2. Perform the following loops:

      • If an input buffer is ready:
      • Read partial data, copy to buffer
      • If an output buffer is ready:
      • Copy to Buffer
    • 3. Destroying MEDIACODEC objects

A Mediacodec object can encode or decode a specific type of data (MP3 audio or H. I video). Because it is operating on the original data, any file header (such as ID3 tags) must be rejected, Mediacodec not interact with any higher level of content, so audio can not be played through the speaker or receive video streams from the network. It reads only the buffer data and then outputs it to the buffer. Mediacodec can remove most of the outer data.

Some codecs are very picky about buffer. For example, buffer must satisfy a particular memory pair, or a certain maximum size, or satisfy several points at the same time. For greater compatibility, the codec obtains the permission to allocate buffer from the application. So, not the buffer with the data directly to Mediacodec, but want to mediacodec request a buffer, and then copy the data in.

This seems to contradict the "zero-copy" principle, but in most cases there is no need to copy because the compiler does not have to copy or tweak the data to meet the requirements. )。 In some cases, you can use the buffer directly, such as reading data directly from the hard disk or the network to buffer, so the copy is not required (this is not a copy?). )

The input of the MEDIACODEC must be processed into a specific format. H264 video encoding When the input is a frame of data, H264 decoding refers to a nal unit. But you can't just submit a single data or data at a time that appears (to be discussed) when it needs to be processed, so that the input looks more like a stream. In fact, the codec has more than one buffer at the same time before the output.

Mediacodec in Bufferinfo inner class:

This article is derived from the countercurrent fish yuiop:http://blog.csdn.net/hejjunlin/article/details/53386117

Mediacodec and MediaPlayer have similarities in many places, and when the Java layer calls Mediacodec.createbycodecname,mediacodec.createdecoderbytype, Mediacodec.createencoderbytype will arrive at the MEDIACODEC structure, which will call Native_setup, as follows:

Which corresponds to having such a paragraph, is equivalent to making a mapping

And then into the Android_media_mediacodec_native_setup function.

The SETMEDIACODEC function is as follows:

Next, look at the structure of Jmediacodec.

After several steps to get Mediacodec on the image, you reach the Java layer call Mediacodec.configure (format,surface,null,0)

By getting the map in format, it is a hashmap that facilitates the format of the video source into two arrays, and then passes the native_configure down


This paper is derived from countercurrent fish YUIOP:
http://blog.csdn.net/hejjunlin/article/details/53386117

When start is called, public native final void start ();

Jmediacodec in Start

Finally, the android_media_mediacodec.h of the corresponding JNI is as follows:




The first time to get blog update reminders, as well as more Android dry, source code Analysis , Welcome to follow my public number, sweep the bottom QR code or long press to identify two-dimensional code, you can pay attention to.




If you feel good, easy to praise, but also to the author's affirmation, can also share this public number to you more people, original not easy

Android Multimedia Framework Summary (21) Mediacodec in the Create to start process (to the JNI section)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.