Create mediaserver and several services running in mediaserver.
1. File frameworks/base/Media/mediaserver/main_mediaserver.cpp
Int main (INT argc, char ** argv) {sp <processstate> proc (processstate: Self (); sp <iservicemanager> Sm = defaultservicemanager (); logi ("servicemanager: % P", SM. get (); audioflinger: instantiate (); // create an audioflinger object named "media. audio_flinger "mediaplayerservice: instantiate (); // create a mediaplayerservice object named" media. player "cameraservice: instantiate (); // create a cameraservice object named" media. camera "audiopol Icyservice: instantiate (); // creates an audiopolicyservice object named "media. audio_policy "processstate: Self ()-> startthreadpool (); // creates a thread. The thread name is in the" binder thread # % d "format and D is a numerical code, for example, "binder thread #1" ipcthreadstate: Self ()-> jointhreadpool (); // Add the preceding thread to the binder for inter-process communication in IPC .}
Poolthread inherits from thread and is a thread class.
The process binder supports a maximum of 15 threads. the maximum number of threads of binder_set_max_threads is set in the open_driver () function.
The code is located in the frameworks/base/libs/binder/processstate. cpp file:
#if defined(HAVE_ANDROID_OS) size_t maxThreads = 15; result = ioctl(fd, BINDER_SET_MAX_THREADS, &maxThreads); if (result == -1) { LOGE("Binder ioctl to set max threads failed: %s", strerror(errno)); }#endif
2. Generate the MK file corresponding to the mediaserver and compile the executable file mediaserver.
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Local_src_files: = \
Main_mediaserver.cpp
Local_shared_libraries: = \
Libaudioflinger \
Libcameraservice \
Libmediaplayerservice \
Libutils \
Libbinder
Base: = $ (local_path )/../..
Local_c_includes: = \
$ (Base)/services/audioflinger \
$ (Base)/services/camera/libcameraservice \
$ (Base)/Media/libmediaplayerservice
Local_module: = mediaserver // mediaserver is an executable program.
Include $ (build_executable)