Here is a setupvideiencoder. It seems that the video encoding should be set with different parameters based on different encoding types. This method code directly intercepts some code:
Let's take a look at the key sentence. Here we have created omxcodec and assigned the created encoder to mediasource. mediasource here can be seen as an encapsulation of omxcodec, in this way, the preparation of the encoder is ready:
Return to the startmpeg4recording () method. We can see that metadata is created after the decoder is prepared, and setupmpeg4metadata is called to store media information in metadata, finally, we call the start method of mediawriter to start encoding:
This is the parameter that the setupmpeg4metadata method uses to store media information:
Next, let's take a look at the implementation of mediawriter's start method. meidawriter is just a description file. We call the mpeg4writer's start method to implement this header file. Here we intercept the code we are interested in, here, a thread is enabled and the starttracks method is called:
The implementation in the starttracks method creates an iterator to continuously call the start method:
Here it is the track class. Let's look at the track class, which is the internal class of mpeg4writer:
Next, let's take a look at the implementation of START in the track class. Here we intercept the code we are interested in. The original code called mediasource. we mentioned earlier that mediasource is the encapsulation of omxcodec, now we know that we used to prepare the encoder. Here we start to call the encoder to start encoding, that is, we start from mediarecorder. java calls the start method and omxcodec. CPP start method: