Codec of WebRTC modular design idea

In order to isolate the coupling problem between different modules, WebRTC makes extensive use of the base class pointer method to the derived class.

Since webRTC is a very large project, many people are developing multiple modules in parallel, and there is a usage relationship between different modules. In order to develop in parallel, an interface class is defined. The methods called between modules are all defined in the interface class, and the methods in the interface class are declared as pure virtual functions without any implementation. For modules that use these methods, as long as you get the interface class file and define a pointer to this class, you can call those virtual functions with your eyes closed, and compile without worry. For the module development that needs to implement the interface class, the same interface class is also used to make a subclass of the interface class, and the subclass implements all functions.

The c++ keyword feature is very useful. The class name + final indicates that this is a final class. This class cannot be inherited. Basically, this class is derived from an interface class. The function of this interface class is to be used for development and debugging between different modules. , which minimizes the impact between the two modules.

The method in the class name + final class is generally modified with override, because the goal of the derived class is to implement the method in the interface class. Adding override can prevent the function name from being wrongly written, the parameter from being wrongly written, etc., and ensure that the interface class will indeed be overloaded. approach, errors are found during compilation rather than debugging.

For example, the functions that the audio encoder should have are defined in the interface class AudioCodingModule,

The AudioCodingModule defines the functions that audio coding should provide, including receiving, sending and statistics. The receiving part will decode the received RTP data (IncomingPacket) and provide it to the playback thread for playback (PlayoutData10Ms). For sending, encoding is required ( Encode), so that the audio encoding module can be used to get this interface class and can be developed. When the audio encoding and decoding function is not fully developed, the two modules are decoupled.

Guess you like

Origin blog.csdn.net/shichaog/article/details/126291091