How to make more secure and efficient use of open source projects? Pay attention to wechat public number: “GitChat technology talk” seriously talk about technology
【 Don’t miss the Easter egg 】
In the usual development process, will inevitably encounter this or that kind of problem, or some complicated and don’t want to pure manual function to do it, for these problems, solve the posture has a lot of kinds, can through the communication between colleagues, search information, go to the website to find documents, etc., with open source to promote and perfect, looking for the right source project support, is a very good method.
Now on the market and evil people mixed up of open source projects, and some projects have already stopped updating maintenance, run the demo, how to do how to correct, the one in the project, only to find that which is not appropriate, such as lower version can run, high version delete some methods, or conflict with some new technology package, etc., in many open source projects, Which posture should we use to choose the best solution? Just listen to me slowly.
PS: At present, I am mainly engaged in mobile client development. The following examples will give some examples of daily development.
Correctly understand and identify requirements
“I like apples, but you gave me a carload of bananas, and then you said you were moved by yourself and asked me why I wasn’t. I was speechless, and then you told the world that you spent all your money to buy me a car full of bananas, but I was not a little touched, I must be a hard-hearted person! There’s something wrong with my character! I just like apples.”
For such a problem, often encountered in the process of our development, product manager just want one apple, and we have brought him a large package of bananas, which is not appropriate, which was later found to determine demand and product managers, just discover oneself want to is wrong, believe that such examples, in each person had, because there is no timely communication, Cause late maintenance costs greatly increased, if found early ok, in the face of such problems online, this must be a bolt from the blue.
Correct understanding and determination of requirements are of great help to the development of third-party open source or native, which can greatly reduce the later maintenance costs.
Some time ago, the company wanted to access the camera to complete the live video broadcast function, using M3U8 format to achieve, and there will be no other formats to access, from the developer documents, Android native controls only support MP4 format, for the compatibility of other formats, there are still big problems, that is to say, it can not be perfectly compatible with M3U8. At this point, we just need to find solutions supported by M3U8 format, and in the search journey, we have narrowed the field considerably.
compatibility
Do client development, regarding the compatibility issue, there are always thousands of words, from the initial layout to integration, to the later system upgrade, the ever-present dealing with compatibility, especially in the swift was born a year or two, every major version change API, it’s a bit of a bull, developers to bear. Companies are afraid to try it.
The compatibility of layout adaptation will not be discussed today, and the topic of the above video will continue. After some comparison, I have targeted Google ExoPlayer and Bilibili iJkPlayer, both of which are open source projects and can be found on Github. The address is as follows: Click to jump to:
Ijkplayer making address: https://github.com/Bilibili/ijkplayer
ExoPlayer making address: https://github.com/google/ExoPlayer
My initial choice is iJkPlayer, and I have a special affection for domestic open source projects. Domestic products should be self-strengthening. When DISCUSSING with my friends, several friends also recommended iJkPlayer to me, including one from B station, but he was not involved in this open source project. It can indeed play M3U8 perfectly. When I put it into our project, I found an error. Check the imported package again, as follows:
dependencies {
# required, enough for most devices.
compile 'TV. Danmaku. Ijk. Media: ijkplayer - Java: 0.8.3'
compile 'TV. Danmaku. Ijk. Media: ijkplayer - armv7a: 0.8.3'
# Other ABIs: optional
compile 'TV. Danmaku. Ijk. Media: ijkplayer - armv5:0.8.3'
compile 'TV. Danmaku. Ijk. Media: ijkplayer - arm64:0.8.3'
compile 'TV. Danmaku. Ijk. Media: ijkplayer - x86:0.8.3'
compile 'TV. Danmaku. Ijk. Media: ijkplayer - x86_64:0.8.3'
# ExoPlayer as IMediaPlayer: optional, experimental
compile 'TV. Danmaku. Ijk. Media: ijkplayer - exobiology: 0.8.3'
}Copy the code
There is an internal conflict in the package, as follows:
defaultConfig {
minSdkVersion 21
targetSdkVersion rootProject.ext.targetSdkVersion
}Copy the code
There are three solutions: don’t import the 64-bit package, or modify the source code and recompile it. The last one is unrealistic, that is, change the lowest version of the company’s project. We still have some Android 4.3 users.
There must be a better solution, well, there must be, with a try attitude, accidentally found ExoPlayer.
Check out the ExoPlayer developer documentation
ExoPlayer’s Standard Audio and Video Components rely on Android’s MediaCodec API, Android 4.1 (API Level 16). Hence they do not work on earlier versions of Android. Widevine common Encryption is available on Android 4.4 (API Level 19) and higher.
The lowest supported version is Android 4.1. Currently, the lowest supported version is Android 4.2, which is quite in line with our taste.
Summary: Compatibility has always been a very complicated problem, version update is too fast, technology constantly updated, some unsafe or unnecessary methods are deleted from THE API, and then some new API, reasonable investigation and research, can save a lot of detour.
sanity
For sanity, mainly reflected in the document of the health and integrity of the data, if it is a new technology, the official did not provide a sound API, there is not some integrated document, this kind of open source project, best not to step in to the project, as the first person to try to eat a spider, can eat into the bitter water that brings a mouth.
When I first tested iJkPlayer, I did a quick scan to get an idea of what technology to use, and then I went to the documentation. Gosh, I only saw the packages to import for integration, the environment and tools to compile, and I only found sample. This is embarrassing, such a big and excellent project, there is no official documents, instantly fell to a negative level, went to the Internet to search the information, the information is still very sound, there are many excellent developers in the integration, put some necessary notes on it, it looks at a glance.
Later, when I investigated Google ExoPlayer, I found a qualitative gap as follows:
ExoPlayer source code:
Github.com/google/ExoP…
ExoPlayer API address:
Google. Making. IO/ExoPlayer/d…
ExoPlayer Developer Guide:
Google. Making. IO/ExoPlayer/g…
This is really great, integration, can solve a lot of detours, encountered problems, but also have some solutions, expansion, but also for their own increased confidence.
I think of a slogan in middle school: “Details determine success or failure, attitude determines height”. In daily use or learning of third-party open source projects, the implementation of functions is not the first factor, but should pay more attention to the integrity of API and data, which I have always appreciated Google and Square. Not to mention Google, WHEN LEARNING Square Retrofit, API still gave me a lot of help. It is really quite detailed, at a glance, each note has a detailed explanation, let the learner feel more intimate.
Realize the principle of
For the implementation principle, some early and intermediate developers do not pay attention to this topic, always feel that they do not understand the source code, do not understand those so-called advanced technology, this is a wrong attitude, the source code is not understand is also very normal, such as iJkPlayer by encapsulation, modify and extend FFmpeg to implement, FFmpeg, this is really more advanced, Although I have learned C language and FFmpeg for some time, IT is also difficult to read some internal codes, but I can always understand the documents, or so much information on the Internet, I can always get a general idea, at least I can know the format supported by iJkPlayer, the technology adopted, the way of decoding, the required package…
One of my predecessors advised me that it is best not to use a technology if no one on the team is familiar with it and no one has read and understood the source code. Once it is used, it may bring a lot of complicated problems in the future.
It is really like, like more than three years ago at the time of an outsourcing company, then on the market has not been too many documents about instant messaging, at the time of the third party is not so much choice, the company decided to use XMPP + openfire to realize, when our team no one contact with this piece of content, project to promote in the crawl, A friend function kept a colleague engaged for several days (this does not deny the colleague’s ability and carelessness, because of his English problem, he did not read the official documents, and did not do too much research).
I appreciate Cao Cao very much, appreciate his suspect person need not, choose and employ persons not suspect. If Cao Cao is a programmer, must be a very good code home, with Cao Cao’s character, will certainly understand a technology, and then apply what he has learned, draw inferiorisms, as far as possible a technology to the extreme.
performance
No matter adopt what kind of open source projects, performance is definitely an important reference, even if the project to write better, the function is all ready, once the performance has a problem, it will be a fatal blow, as a player, no hands, sprint is the first long, let him to go to the table tennis match, to cow force of the coach is also a face of meng force.
Back to the previous topic, the choice between ExoPlayer and iJKPlayer is largely due to performance issues. Performance issues directly point to the difference between hard decoding and soft decoding.
Hard decoding: it is to call the special module of GPU for decoding, and the graphics card core GPU for decoding the video.
Soft decoding: let the CPU decode the video through software.
I believe that for soft decoding and hard decoding, most people are not strange, here do not do more and repeat.
A picture is worth a thousand words. Here’s a comparison:
Contrast above one is the power consumption is the total power consumption, this is easy to understand, the GPU circuit is more complex, and parallel computing ability is far higher than that of the CPU, so power consumption is higher, the GPU power consumption is big, but running faster, more power consumption = * time, so even if power by four, but time is divided by 10, total energy consumption is reduced.
For hard decoding and soft decoding choice, this really can’t say which is better, according to the needs of the project, now almost all of the equipment support hard decoding and soft decoding, support only one Android mobile equipment has is antique, I haven’t seen before, is before more people are willing to choose soft decoding, a bigger reason is that the hardware decoding supported formats is less, Soft decoding is not restricted to the format.
Now, with the continuous improvement of hardware and the continuous maturity and perfection of decoding technology, I prefer hard decoding. However, with the improvement of hardware, CPU is also constantly optimized and improved, and there is no need to save CPU as much as possible as before. Now, in the era of excess performance, CPU is hardly under load. The choice of soft decoding or hard decoding is no one is right or wrong, the advantages of both have been posted and marked on the diagram just, according to the needs of the project.
At that time, I chose ExoPlayer with hard decoding because it only needs to play video in M3U8 format, and the screen is not so high. For such demand, hard decoding is more in line with the taste of the company and user experience, and at least it can save more power.
Features and Extensions
For products often change requirements, this is common, we should not spend more time arguing with product managers, but how to better deal with this problem.
When I first learned software development, it was mentioned in the book that a good programmer would better consider the maintainability, reusability, extensibility and flexibility of the code.
Before access to a third party, familiar with the function of it is inevitable, because of some and some function attract that we use the third party, in order to facilitate future expansion, should read a few times or developer documentation, as much as you can understand and be familiar with the internal structure, in the developer documentation, generally have detailed instructions.
For expansibility, this is inseparable from the document and source code, always can’t write their own puzzling code, this is not realistic, I think every qualified programmer should develop the good habit of reading source code, which has great help for their own improvement and function expansion.
integration
For integration, my first reaction is to think of the WeChat and pay treasure to pay, this is definitely a far cry from two years ago, a colleague and I are connected to pay treasure and WeChat pay, I pay treasure, access and read the document and run the demo, in less than an hour to run through, and he observed letter to pay, also not fix a day, Then and I said wechat pay all kinds of pits, was also dubious, even if pit point, also do not need more than a day, so much content. Later, I had a private job, which also required access to Alipay and wechat Payment. Alipay’s document was very detailed, while wechat’s document was messy. What’s more disgusting is that the callback class must be a fixed class name under a fixed package, which seriously damaged the package structure of the project.
With open SDKS, I think we should provide users with more comprehensive documentation and take a different perspective.
conclusion
How much more safe and efficient use of third party open source project, in order to improve the maintainability and extensibility of code later, we should read more to research and developer documentation, knife don’t miss your job, a good developers, should put more time in thinking and research, finish demand rather than speed, then put more time to change the bug.
【GitChat Talent Course 】
- Front-end Villain in the Desert: Getting Started with Angular For Beginners
- · Zoom.Quiet: GitQ: GitHub In Taste
- How to Learn the React Stack from Scratch
- GordonChoi, early adopter of GA: GA e-commerce data analysis practice course