Data transmission method and electronic equipment
By creating shared memory for each business process and notifying the transmission process to read it after writing data in the shared memory, the IPC communication hyper memory and crash problems in multi-service concurrency scenarios are solved, and the number and stability of data transmission concurrency are improved.
Patent Information
- Application Number
- CN202311798896.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-25
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2043-12-25
AI Technical Summary
In multi-service concurrency scenarios, the existing inter-process communication (IPC) methods are prone to hypermemory and crash problems, resulting in data transmission failure.
By creating shared memory for each business process in an electronic device, the business process writes data to the shared memory and notifies the transmission process to read it. The transmission process then reads data from the shared memory and sends it, reducing the size of a single data transmission and avoiding IPC communication hyper memory and crashes.
It effectively solves the problem of super memory and crash in IPC communication in multi-service concurrency scenarios, improves the number of data transmission concurrency, and ensures the stability and efficiency of data transmission.
Smart Images

Figure CN120256155A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electronic technologies, and particularly to a data transmission method and an electronic device. Background Art
[0002] Currently, when data is transmitted between two (or more) electronic devices, it not only supports single-service data transmission but also multi-service concurrent data transmission. For example, when electronic device A is casting a screen to electronic device B and simultaneously initiates a super mouse and keyboard service to electronic device B, then electronic device A needs to transmit the data of the screen-casting service and the data of the super mouse and keyboard service to electronic device B to achieve multi-service concurrent data transmission.
[0003] The currently popular data transmission method is the inter-process communication (IPC) method, that is, the service process and the transmission process in electronic device A are different processes. The service process needs to send service data to the transmission process through the IPC communication mechanism, and then the transmission process sends the service data to electronic device B. If multiple services are started in electronic device A, there will be multiple service processes for data transmission with the transmission process. However, because the IPC communication mechanism has a limit on the size of the data transmitted at one time, if the service data of multiple services is relatively large, problems such as IPC communication out-of-memory and memory crashes may occur during data transmission. Summary of the Invention
[0004] This application provides a data transmission method and an electronic device, which can avoid problems such as IPC communication out-of-memory and crashes in a multi-service concurrent scenario, and at the same time improve the number of concurrent data transmissions.
[0005] In a first aspect, this application provides a data transmission method, which is applied to a first electronic device. There is a communication connection between the first electronic device and a second electronic device. The method includes: when there is service data in multiple service processes in the first electronic device that needs to be sent to the second electronic device, writing the service data to be sent into a first shared memory through a first service process in the first electronic device, where different service processes of different service applications correspond to different shared memories, the first service process is any one of the multiple service processes, and the first service process corresponds to the first shared memory; sending a first notification message to a first transmission process in the first electronic device through the first service process based on the inter-process communication (IPC) communication mechanism, the first notification message is used to instruct the first transmission process to read the service data to be sent from the first shared memory, and the first notification message does not carry the service data to be sent; reading the service data to be sent from the first shared memory by the first transmission process, and sending the service data to be sent to the second electronic device.
[0006] Among them, during the process of the first electronic device (i.e., electronic device A) transmitting service data to the second electronic device (i.e., electronic device B), the service data comes from a service application in the first electronic device. After the service application runs, the corresponding first service process (i.e., service process A) will be started. In this application, the first service process does not directly send the service data to be sent to the first transmission process (i.e., transmission process A), but writes the service data into the created first shared memory, and sends a first notification message to the first transmission process through the IPC communication mechanism to notify the first transmission process that there is service data to be sent currently. Then the first transmission process reads the service data from the first shared memory. It should be noted that the first notification message sent by the first service process does not carry service data. Then, only the notification message needs to be communicated between the first service process and the first transmission process. Even if multiple services are executed concurrently, the size of the communicated messages will not exceed the transmission data size limit of the IPC communication. Therefore, the size of the data sent each time can be reduced, the limitation of the transmission data size during IPC communication in the multi-service concurrent scenario is solved, problems such as communication out-of-memory and crashes are avoided, and at the same time, the concurrent number of data transmissions is increased.
[0007] Combined with the first aspect, in some implementation manners of the first aspect, before the first service process in the first electronic device writes the service data to be sent into the first shared memory, the above method further includes: determining, by the first transmission process, whether a shared memory needs to be created, and creating the first shared memory corresponding to the first service process when it is determined that a shared memory needs to be created.
[0008] As can be seen from the above description, the first service process needs to write service data into the first shared memory. Then, the first shared memory needs to be created in advance. In this application, after the service thread is started, it will instruct to start the service transmission service and start the first transmission process, and then the first transmission process creates the first shared memory. Among them, the first transmission process can first determine whether a shared memory needs to be created, and create the first shared memory corresponding to the first service process when a shared memory needs to be created.
[0009] In some implementation manners, the above determining, by the first transmission process, whether a shared memory needs to be created includes: determining, by the first transmission process, whether a shared memory needs to be created according to the service information corresponding to the first service process, where the service information includes service type and / or service priority.
[0010] Among them, since the transmission traffic required by some business applications is relatively large and that required by some business applications is relatively small, in order to implement a dynamic and intelligent data transmission process, this application can determine whether to create a shared memory according to the service type and / or service priority. If it is necessary to create a shared memory (such as when the transmission traffic is relatively large), it will be created; if it is not necessary to create a shared memory (such as when the transmission traffic is relatively small), it will not be created. It can be understood that in the case of not creating a shared memory, the above-mentioned first service process can directly send service data to the first transmission process, so that the first transmission process can send the service data to the second electronic device.
[0011] In the case of determining whether to create a shared memory according to the service type, if it is a file transfer type or a screen mirroring type, etc., a shared memory needs to be created because the data to be transmitted for these service types is usually relatively large. If it is not a file transfer type and a screen mirroring type, a shared memory does not need to be created.
[0012] In the case of determining whether to create a shared memory according to the service priority, if the priority is relatively high, a shared memory needs to be created; if the priority is relatively low, a shared memory does not need to be created.
[0013] In some scenarios, whether to create a shared memory can also be specified by the business application itself. For example, a screen mirroring application specifies that a shared memory needs to be created.
[0014] Combined with the first aspect, in some implementation manners of the first aspect, in the case of determining that a shared memory needs to be created, the above method further includes: the first electronic device sends a request message to the second electronic device, requesting the second electronic device to create a corresponding second shared memory, and the request message carries an identifier indicating whether to create a shared memory.
[0015] That is to say, in the case where the first electronic device creates a shared memory, it will send a request to the second electronic device, requesting the second electronic device to also create a shared memory to ensure that IPC communication is normal on both sides of the electronic devices. In the request message sent by the first electronic device to the second electronic device, an identifier indicating whether to create a shared memory can be carried. Among them, the identifier indicating whether to create a shared memory can be represented by an int parameter. For example, 1 indicates creating a shared memory, and 0 indicates not creating a shared memory. In the case where the identifier is 1, the second electronic device will also create a shared memory after receiving the request.
[0016] Combined with the first aspect, in some implementation manners of the first aspect, writing the service data to be sent into the first shared memory by the first service process in the first electronic device includes: writing the service data to be sent and the message length corresponding to the service data to be sent into the first shared memory by the first service process.
[0017] When reading and writing service data in the first shared memory, to ensure the accuracy of the read data, that is, to prevent reading incorrect service data, the present application can also perform security verification on the service data in the shared memory. In this implementation, for the service data written in the first shared memory, a data format of message length (length) + message content is adopted. The message length refers to the length of the service data to be sent this time. For example, the message length can occupy 4 bytes, and the message content refers to the specific content of the service data to be sent by the first service process. When the first service process writes service data into the first shared memory, it will first write the message length. For example, it will first write a 4-byte message length, and then write the service data to be sent at a position offset by 4 bytes after writing the message length.
[0018] For this implementation, after the first service process writes the service data into the first shared memory, the first notification message sent by the first service process to the first transmission process can carry the message length corresponding to the service data to be sent, without carrying the service data.
[0019] In some implementations, the above-mentioned process of the first transmission process reading the service data to be sent from the first shared memory includes: the first transmission process reads the first message length from the first shared memory. If the read first message length is equal to the message length corresponding to the service data to be sent carried in the first notification message, then the first transmission process reads the service data to be sent from the first shared memory.
[0020] That is to say, after receiving the first notification message, the first transmission process can read the carried message length (length) from the first notification message. Then the first transmission process reads the first message length (length’) from the first shared memory. If length’ is equal to length, it means that the message verification is successful, and the first transmission process can read the service data at a position offset by 4 bytes after the message length in the first shared memory. If length’ is not equal to length, it means that the message verification fails, and the first transmission process will no longer read the service data, that is, the data transmission fails. Thus, the accuracy in the data transmission process can be improved.
[0021] Combined with the first aspect, in some implementations of the first aspect, the above-mentioned process of the first service process in the first electronic device writing the service data to be sent into the first shared memory includes: the first service process writes the service data to be sent from the starting position of the first shared memory;
[0022] The process of the first transmission process reading the service data to be sent from the first shared memory includes: the first transmission process reads the service data to be sent from the starting position of the first shared memory.
[0023] That is to say, in the present application, the process of the first service process writing service data into the first shared memory and the process of the first transmission process reading service data from the first shared memory can adopt a serialized process, that is, one write is followed by one read, and then another write is followed by one read. For the first shared memory, each write starts from the beginning (i.e., writing at the start position of the shared memory), and each read also starts from the beginning. After each read, the read service data can be deleted, and the writing cycle continues. This can prevent problems such as data being overwritten or data loss when the data is not accessed.
[0024] Combined with the first aspect, in some implementation manners of the first aspect, the first electronic device includes a transmission service middle platform and a transmission dynamic library. The above-mentioned process of the first service process sending a first notification message to the first transmission process in the first electronic device based on the IPC communication mechanism includes: the first service process sending the first notification message to the transmission service middle platform based on the IPC communication mechanism, and the transmission service middle platform notifying the transmission dynamic library to read the service data to be sent from the first shared memory, where the first transmission process is a process pulled up when the transmission service middle platform is started.
[0025] Among them, after the first service process is started, it can instruct the transmission service middle platform to start the service transmission service, and accordingly pull up the first transmission process. Then the first service process can send the first notification message to the transmission service middle platform based on the IPC communication mechanism, and then the transmission service middle platform notifies (which can also be called invoking) the transmission dynamic library to read the service data to be sent from the first shared memory. After the transmission dynamic library reads the service data from the first shared memory, it can send it to the second electronic device.
[0026] In some implementation manners, before the first service process in the first electronic device writes the service data to be sent into the first shared memory, the above method further includes: the first service process instructing the transmission service middle platform to start the service transmission service; the transmission service middle platform determining whether a shared memory needs to be created, and creating the first shared memory corresponding to the first service process when it is determined that a shared memory needs to be created; the transmission service middle platform notifying the transmission dynamic library to pull up the client, and when the transmission dynamic library pulls up the client, saving the identifier of the first shared memory.
[0027] That is to say, the transmission service middleware can determine whether to create a shared memory according to the service type and / or service priority. In the case where a shared memory needs to be created, it creates a first shared memory corresponding to the first service process and records the identifier of the first shared memory (such as the shared memory file descriptor fd). Through this shared memory fd1, the address of the shared memory can be found to read and write data to the shared memory corresponding to this address. Then, the transmission service middleware can notify the transmission dynamic library to start the client, and carry the identifier of the first shared memory when notifying. After that, the transmission dynamic library can start the client, save the identifier of the first shared memory, and return a success message of starting the client to the transmission service middleware. Thus, it can be used for the subsequent first service process to write service data into the first shared memory, without directly sending the service data to the first transmission process, so as to avoid problems such as IPC communication out-of-memory and crashes.
[0028] In a second aspect, the present application provides a data transmission method, which is applied to a second electronic device, and there is a communication connection between the first electronic device and the second electronic device. The method includes: receiving service data from the first electronic device through a second transmission process in the second electronic device, and writing the service data into a second shared memory; sending a second notification message to a second service process in the second electronic device through the second transmission process based on the IPC communication mechanism, where the second notification message is used to instruct the second service process to read the service data from the second shared memory, and the second notification message does not carry the service data; reading the service data from the second shared memory through the second service process, and processing the service data.
[0029] In combination with the second aspect, in some implementation manners of the second aspect, before writing the service data into the second shared memory, the above method further includes: receiving a request message from the first electronic device through the second transmission process, determining whether to create a shared memory according to the request message, and creating a second shared memory in the case where it is determined that a shared memory needs to be created, and the request message carries an identifier of whether to create a shared memory.
[0030] Among them, the second electronic device (i.e., electronic device B) can also adopt the mechanism of shared memory. After receiving the request message from the first electronic device, if it is determined that a shared memory needs to be created, the second shared memory is created. Subsequently, after receiving the service data sent by the first electronic device, the service data can be written into the second shared memory through the second transmission process (i.e., transmission process B), and a second notification message is sent to the second service process (i.e., service process B) to notify the second service process of the service data to be received currently. The second service process then reads the service data from the second shared memory. It should be noted that the second notification message sent by the second transmission process does not carry service data. Then, only the notification message needs to be communicated between the second service process and the second transmission process. Even if multiple services are executed concurrently, the size of the communicated messages will not exceed the transmission data size limit of IPC communication. Therefore, the size of the data sent each time can be reduced, the limitation of the transmission data size in IPC communication in the multi-service concurrent scenario is solved, and problems such as communication out-of-memory and crashes are avoided. At the same time, the concurrent number of data transmissions is increased.
[0031] In a third aspect, the present application provides a device. The device is included in an electronic device and has the function of implementing the behavior of the electronic device in the above first aspect and the possible implementation manners of the first aspect, or has the function of implementing the behavior of the electronic device in the above second aspect and the possible implementation manners of the second aspect. The function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above functions. For example, a receiving module or unit, a processing module or unit, etc.
[0032] In a fourth aspect, the present application provides an electronic device, which includes: a processor, a memory, and an interface; the processor, the memory, and the interface cooperate with each other to enable the electronic device to execute any one of the methods in the technical solution of the first aspect, or execute any one of the methods in the technical solution of the second aspect.
[0033] In a fifth aspect, the present application provides a chip, which includes a processor. The processor is used to read and execute a computer program stored in the memory to execute the method in the first aspect and any possible implementation manner thereof, or execute the method in the second aspect and any possible implementation manner thereof.
[0034] Optionally, the chip further includes a memory, and the memory is connected to the processor through a circuit or a wire.
[0035] Further optionally, the chip further includes a communication interface.
[0036] In a sixth aspect, the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to execute any one of the methods in the technical solutions of the first aspect or any one of the methods in the technical solutions of the second aspect.
[0037] In a seventh aspect, the present application provides a computer program product, which includes computer program code that, when running on an electronic device, causes the electronic device to execute any one of the methods in the technical solutions of the first aspect or any one of the methods in the technical solutions of the second aspect. Description of the Drawings
[0038] Figure 1 is a schematic diagram of an example data transmission process provided by the related art;
[0039] Figure 2 is a schematic diagram of the structure of an example electronic device provided by an embodiment of the present application;
[0040] Figure 3 is a software structure block diagram of an example electronic device provided by an embodiment of the present application;
[0041] Figure 4 is a schematic diagram of the system architecture of an example data transmission process provided by an embodiment of the present application;
[0042] Figure 5 is a schematic diagram of the timing process of an example data transmission method provided by an embodiment of the present application;
[0043] Figure 6 is a schematic diagram of an example serialization read / write process provided by an embodiment of the present application;
[0044] Figure 7 is a schematic diagram of the format of writing data in a shared memory provided by an embodiment of the present application;
[0045] Figure 8 is a schematic diagram of the timing process of another example data transmission method provided by an embodiment of the present application;
[0046] Figure 9 is a schematic diagram of the performance experiment comparison between the scenarios of creating and not creating a shared memory provided by an embodiment of the present application. Detailed Embodiments
[0047] The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings in the embodiments of the present application. Among them, in the description of the embodiments of the present application, unless otherwise specified, " / " means "or". For example, A / B may mean A or B. The "and / or" herein is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B may mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of the present application, "a plurality of" means two or more than two.
[0048] Hereinafter, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first", "second", and "third" may explicitly or implicitly include one or more of such features.
[0049] First of all, it should be noted that the data transmission with multi-service concurrency in the embodiments of the present application can be the data transmission when multiple services are simultaneously initiated between two (or more) electronic devices. Taking electronic device A and electronic device B as an example, multiple services such as super mouse and keyboard, super call, screen mirroring (such as heterogeneous screen mirroring) can be simultaneously initiated between electronic device A and electronic device B. To ensure the normal progress of multiple services, electronic device A needs to send service data corresponding to each service to electronic device B. Among them, the service data sent by electronic device A to electronic device B may include but is not limited to message data, streaming media data, file data, etc.
[0050] Generally, when electronic device A performs data transmission to electronic device B, it adopts the inter-process communication IPC (also known as cross-process communication) method. IPC communication is a capability provided by the operating system for data exchange and sharing between different processes. It allows different processes to perform message passing to achieve functions such as inter-process communication and synchronization. Then, as Figure 1 shown, the process of electronic device A transmitting service data to electronic device B using the IPC communication mechanism may include: The service process in electronic device A (the service process will be correspondingly started when electronic device A starts a service) and the transmission process (the process for transmitting service data to electronic device B) are different processes. The service process needs to send the service data to the transmission process through the IPC communication mechanism, and then the transmission process sends the service data to electronic device B (for example, through the network air interface). After the transmission process of electronic device B receives the service data, it will also send the service data to the service process through the IPC communication mechanism. If multiple services are started in electronic device A, multiple service processes will also be correspondingly started, and these multiple service processes all need to perform data transmission with the transmission process to send their respective corresponding service data to electronic device B.
[0051] In the Android system, the more commonly used IPC communication mechanism is the Binder mechanism. The Binder mechanism is a communication mechanism based on the C / S (Client / Server) model, which enables a process to expose its services to other processes. Other processes can make remote calls through the Binder, providing functions such as cross-process method calls, data transmission, and thread synchronization. However, in the Binder mechanism, it only allows the size of the single transmitted data for upper-layer user space (such as business processes, business applications, etc.) communication to not exceed 1MB (megabyte). This may lead to limitations in data transmission during multi-service concurrent data transmission, resulting in problems such as Binder communication out-of-memory and crashes. For example, when the screen mirroring and super call services are initiated simultaneously between electronic device A and electronic device B, the business process corresponding to the screen mirroring service needs to send business data to the transmission process through the Binder mechanism, and the super call service also needs to send business data to the transmission process through the Binder mechanism. If the business data sent by the business process corresponding to the screen mirroring service through the Binder mechanism reaches 1MB at a single time, then when the super call service sends business data through the Binder mechanism, the normal sending process may not be possible, resulting in problems such as Binder communication out-of-memory and crashes.
[0052] In view of this, the embodiments of the present application provide a data transmission method. By creating a shared memory, each business process corresponds to a shared memory. After the business process writes the business data into the shared memory, it can notify the transmission process (without carrying the business data when notifying), and the transmission process can then read the business data from the shared memory to send the business data to other electronic devices. Thus, the business process does not need to send the business data to the transmission process through the IPC communication mechanism, but only needs to send a notification message, reducing the size of the data sent at a single time, avoiding problems such as the above-mentioned communication out-of-memory and crashes in the multi-service concurrent scenario, and at the same time increasing the number of concurrent data transmissions.
[0053] In addition, the data transmission method provided by the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), intelligent large screens, etc. that can interact with other electronic devices. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.
[0054] Exemplarily,Figure 2 This is a schematic structural diagram of an electronic device 100 provided by an embodiment of this application. Taking the electronic device 100 as a mobile phone as an example, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0055] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.
[0056] Among them, the controller may be the nerve center and command center of the electronic device 100. The controller may generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.
[0057] A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory may store instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0058] The wireless communication function of the electronic device 100 may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modulation and demodulation processor, and the baseband processor, etc.
[0059] The wireless communication module 160 may provide solutions for wireless communications applied to the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. The wireless communication module 160 may be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 may also receive the signal to be sent from the processor 110, perform frequency modulation and amplification on it, and convert it into electromagnetic wave radiation via the antenna 2.
[0060] The electronic device 100 implements the display function through the GPU, the display screen 194, and the application processor, etc. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change the display information.
[0061] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can adopt a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include one or N display screens 194, where N is a positive integer greater than 1.
[0062] The internal memory 121 can be used to store computer-executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.). The data storage area can store the data created during the use of the electronic device 100 (such as audio data, a phone book, etc.). In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0063] The touch sensor 180K, also known as the "touch panel". The touch sensor 180K can be disposed on the display screen 194, and the touch screen, also known as the "touch screen", is composed of the touch sensor 180K and the display screen 194. The touch sensor 180K is used to detect touch operations acting on it or nearby. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In some other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100, at a different position from the display screen 194.
[0064] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0065] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0066] Figure 3 1 is a software structure diagram of the electronic device 100 of the embodiment of the present application. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer. The application layer can include a series of application packages.
[0067] like Figure 3 As shown, the application package may include business applications, including but not limited to camera, gallery, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0068] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0069] like Figure 3 As shown, the application framework layer may include a transmission service middle platform. Among them, the business process corresponding to the business application can call the transmission service middle platform to pull up the business transmission service. The transmission service middle platform can determine whether to use the shared memory transmission solution based on information such as the business type, that is, whether to create shared memory, and create shared memory if it is necessary to create shared memory, and record the shared memory identifier, such as the shared memory file descriptor fd.
[0070] In addition, the application framework layer can also include window managers, content providers, view systems, telephony managers, resource managers, notification managers, etc.
[0071] The window manager is used to manage window programs. The content provider is used to store and retrieve data and make this data accessible to applications. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The telephony manager is used to provide the communication functions of the electronic device 100. The resource manager provides various resources for applications, such as localized strings, icons, pictures, layout files, video files, and so on. The notification manager enables applications to display notification information in the status bar and can be used to convey notification-type messages. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text.
[0072] The Android runtime includes core libraries and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.
[0073] The core libraries consist of two parts: one part is the functional functions that need to be called by the Java language, and the other part is the core libraries of Android.
[0074] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0075] The system libraries can include transport dynamic libraries. Among them, in the case where the above-mentioned transport service middleware determines that a shared memory needs to be created, the transport service middleware can send a notification message to pull up the client to the transport dynamic library and at the same time pass in the shared memory fd. The transport dynamic library can pull up the client and save the shared memory fd and return a message indicating that the client has been pulled up successfully to the transport service middleware.
[0076] After the shared memory is successfully created, if the business application needs to use this shared memory to transfer data subsequently, it can write the business data into the shared memory and send a notification message to the transport service middleware through the IPC communication mechanism to notify the current business data to be sent. At this time, the notification message only carries the notification content and does not carry the content of the business data. Then the transport service middleware notifies the transport dynamic library, and the transport dynamic library reads the business data from the shared memory, encapsulates it, and sends it to other electronic devices through the communication driver.
[0077] In addition, the system libraries can also include a surface manager, medialibraries, 3D graphics processing libraries (such as: OpenGL ES), 2D graphics engines (such as: SGL), etc.
[0078] The surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications. The media library supports the playback and recording of multiple common audio and video formats, as well as static image files, etc. The media library can support multiple audio and video coding formats. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc. The 2D graphics engine is the drawing engine for 2D drawing.
[0079] The kernel layer is the layer between hardware and software. The kernel layer at least includes a display driver, a communication driver, an audio driver, and a sensor driver. The communication driver can include a Wi-Fi driver, a Bluetooth driver, etc., and can be used for network communication with other electronic devices. For example, the above service data can be sent to other electronic devices.
[0080] Based on the electronic device with the above software structure, if electronic device A transfers data to electronic device B, and both electronic device A and electronic device B can have the above software structure, then, the system architecture composed of electronic device A and electronic device B can be as Figure 4 shown. In this system architecture, electronic device A includes business application A, transmission service middleware A, transmission dynamic library A, and communication driver A, and electronic device B includes business application B, transmission service middleware B, transmission dynamic library B, and communication driver B.
[0081] Among them, when implementing the data transmission method of the embodiments of the present application, the system architecture can include a service startup process and a data transmission process. The service startup process can include: when the user clicks on business application A of electronic device A, business process A is started. Business process A calls the transmission service middleware A through the system interface to start the business transmission service. The transmission service middleware A determines whether it is necessary to create a shared memory, and creates a shared memory if it is necessary to create a shared memory, and records the identifier A of the shared memory. The transmission service middleware A instructs the transmission dynamic library A to launch the client and pass in the identifier A of the shared memory. After the transmission dynamic library A launches the client, it saves the identifier A of the shared memory. The transmission dynamic library A returns a message indicating that the client has been successfully launched to the transmission service middleware A. The transmission service middleware A sends a notification message for starting the business transmission service to the transmission service middleware B of electronic device B. The transmission service middleware B determines whether it is necessary to create a shared memory, and creates a shared memory if it is necessary to create a shared memory, and records the identifier B of the shared memory. The transmission service middleware B instructs the transmission dynamic library B to launch the server and pass in the identifier B of the shared memory. After the transmission dynamic library B launches the server, it saves the identifier B of the shared memory. The transmission dynamic library B returns a message indicating that the server has been successfully launched to the transmission service middleware B. The transmission service middleware B sends a notification message indicating that the server has been started to the transmission service middleware A. The transmission service middleware A notifies business process A that the business transmission service has been successfully started, and the transmission service middleware B notifies business process B that the business transmission service has been successfully started.
[0082] The data transmission process may include: The service process A of electronic device A writes service data into the shared memory. The service process A notifies the transmission service middleware A of the service data to be sent currently through the IPC communication mechanism. The transmission service middleware A notifies the transmission dynamic library A of the service data to be sent currently. The transmission dynamic library A reads the service data from the shared memory, encapsulates it, and sends it to the communication driver A in the kernel layer. The communication driver A sends the service data to the communication driver B of electronic device B through the network. The communication driver B sends the service data to the transmission dynamic library B. The transmission dynamic library B receives the service data, writes the service data into the shared memory, and notifies the transmission service middleware B of the service data to be received currently. The transmission service middleware B notifies the service process B of the service data to be received currently through the IPC communication mechanism. The service process B reads the service data from the shared memory and performs corresponding data processing.
[0083] For easier understanding, in the following embodiments of the present application, Figure 4 taking the system architecture shown as an example, in combination with the accompanying drawings and application scenarios, the data transmission method provided in the embodiments of the present application will be specifically described.
[0084] Figure 5 is a schematic timing diagram of a data transmission method provided in an embodiment of the present application. Taking the example of electronic device A sending service data to electronic device B, the method may include:
[0085] S1. The service application A receives the first operation of the user and starts the service process A.
[0086] Among them, the first operation may be an operation to start the running of the service application A by the user, or an operation to start a certain function on the service application A. For example, clicking the screen mirroring control starts the screen mirroring service process, and clicking the super mouse and keyboard control starts the super mouse and keyboard service process, etc.
[0087] S2. The service process A instructs the transmission service middleware A to start the service transmission service.
[0088] Here, the service process A may call the transmission service interface to instruct the transmission service middleware A to start the service transmission service, such as starting the screen mirroring service. In some implementation manners, when the service process A instructs the transmission service middleware A to start the service transmission service, it may carry corresponding service information, including but not limited to service type, service name (or service name), service priority and other information. It can be understood that when the service process A instructs the transmission service middleware A to start the service transmission service, the transmission process is also correspondingly started.
[0089] S3. The Transmission Service Middleware Platform A determines whether to create a shared memory. If it is necessary to create a shared memory, then execute S4. If it is not necessary to create a shared memory, then execute S34 in the following embodiments.
[0090] Among them, the Transmission Service Middleware Platform A can determine whether to create a shared memory according to the service type and / or service priority. In the case of determining whether to create a shared memory according to the service type, if it is a file transfer type, a screen mirroring type, etc., then it is necessary to create a shared memory because the data to be transmitted for these service types is usually relatively large. It can also be understood that when the Transmission Service Middleware Platform A identifies that the transmission traffic required by the current service is relatively large according to the service type and / or service priority, it is determined that a shared memory needs to be created. If it is identified that the transmission traffic required by the current service is relatively small, then it is determined that there is no need to create a shared memory. In some implementation manners, whether to create a shared memory can also be specified by the service application itself. For example, the screen mirroring application specifies that a shared memory needs to be created.
[0091] S4. The Transmission Service Middleware Platform A creates a shared memory corresponding to the service process A.
[0092] In some implementation manners, the Transmission Service Middleware Platform A can apply for a region (such as a region with a specified size) in the memory space of the electronic device A through a system interface as the shared memory corresponding to the above service process. At this time, the identifier A of the shared memory (such as the shared memory file descriptor fd1) can be recorded. Through this shared memory fd1, the address of the shared memory can be found to read and write data to the shared memory corresponding to the address. It can be understood that the shared memory corresponding to the service process A created here is created in the transmission process.
[0093] It should be noted that different service processes correspond to different shared memories. For example, the identifier of the service process or the identifier of the service can be associated and stored with the shared memory fd. Thus, the shared memories between different services are independent of each other and there is no risk of being misused, etc.
[0094] S5. The Transmission Service Middleware Platform A sends a notification message to the Transmission Dynamic Library A to pull up the client.
[0095] Among them, the notification message can carry the identifier A of the above shared memory (such as the shared memory fd1). The Transmission Service Middleware Platform A sends this notification message to the Transmission Dynamic Library A to instruct the Transmission Dynamic Library A to pull up the client. It can be understood that the Transmission Service Middleware Platform A can send a notification message to the Transmission Dynamic Library A by calling the interface of the Transmission Dynamic Library A.
[0096] S6. The Transmission Dynamic Library A pulls up the client and saves the identifier A of the shared memory.
[0097] S7. The transmission dynamic library A returns a successful message for pulling up the client to the transmission service middleware platform A.
[0098] After the transmission dynamic library A receives the notification message sent by the transmission service middleware platform A, it can pull up the client and simultaneously save the identifier A of the shared memory created above (such as shared memory fd1). Subsequently, the transmission dynamic library A can also return a message to the transmission service middleware platform A indicating that the client has been successfully pulled up.
[0099] S8. The transmission service middleware platform A of the electronic device A sends a request to start the service transmission service to the transmission service middleware platform B of the electronic device B.
[0100] That is to say, after the business service is started on the side of the electronic device A and the shared memory is created, a request will be sent to the electronic device B, requesting the electronic device B to also start the service transmission service, create a shared memory, and pull up the corresponding server.
[0101] In some implementation manners, the request sent by the transmission service middleware platform A to the transmission service middleware platform B may carry the identifier of the service transmission service, the device identifier of the electronic device A, and the identifier of whether to use the shared memory, etc. Among them, the identifier of whether to use the shared memory can be represented by an int parameter. For example, 1 indicates using the shared memory, and 0 indicates not using the shared memory. In the case where the identifier is 1, the electronic device B also needs to create a shared memory after receiving the request. Thus, the electronic devices can interact and negotiate whether to use the shared memory. If one side of the electronic device uses the shared memory, the other side of the electronic device will also use the shared memory, achieving the purpose that both sides of the electronic devices will not exceed the memory when implementing multi-service concurrency.
[0102] S9. The transmission service middleware platform B determines whether to create a shared memory. If it is necessary to create a shared memory, then execute S10. If it is not necessary to create a shared memory, then execute S40 in the following embodiments.
[0103] That is, the transmission service middleware platform B can determine whether to create a shared memory according to the identifier of whether to use the shared memory in the above request. For example, in the case where the identifier is 1, the electronic device B needs to create a shared memory.
[0104] S10. The transmission service middleware platform B creates a shared memory corresponding to the service process B.
[0105] In some implementations, the transmission service middle platform B can apply for a region in the memory space of the electronic device B through a system interface as the shared memory corresponding to the service process B. Here, the service process B is the process in the electronic device B that will respond to and execute the service initiated by the electronic device A. At this time, the identifier B of the shared memory (such as the shared memory file descriptor fd2) can be recorded. Through this shared memory fd2, the address of the shared memory can be found to read and write data to the shared memory corresponding to this address. It can be understood that the shared memory corresponding to the service process B created here is created during the transmission process.
[0106] S11. The transmission service middle platform B sends a notification message to the transmission dynamic library B to pull up the server.
[0107] Among them, the notification message can carry the identifier B of the above-mentioned shared memory (such as the shared memory fd2). The transmission service middle platform B sends this notification message to the transmission dynamic library B to instruct the transmission dynamic library B to pull up the server.
[0108] S12. The transmission dynamic library B pulls up the server and saves the identifier B of the shared memory.
[0109] S13. The transmission dynamic library B returns a success message of pulling up the server to the transmission service middle platform B.
[0110] After receiving the notification message sent by the transmission service middle platform B, the transmission dynamic library B can pull up the server and simultaneously save the identifier B of the above-mentioned created shared memory (such as the shared memory fd2). Subsequently, the transmission dynamic library B can also return a message to the transmission service middle platform B indicating that the server has been successfully pulled up.
[0111] S14. The transmission service middle platform B of the electronic device B sends a message indicating the successful start of the service transmission to the transmission service middle platform A of the electronic device A.
[0112] That is to say, after the electronic device B side starts the service transmission service and creates the shared memory, it will send a message indicating successful startup to the electronic device A to notify the electronic device A to perform the next operation.
[0113] S15. The transmission service middle platform A notifies the service process A that the service transmission service has started successfully.
[0114] S16. The service process A converts to obtain the identifier A' of the shared memory, and the service transmission service starts successfully.
[0115] Among them, when the transmission service middleware A notifies the service process A that the service transmission service has been successfully started, it can carry the identifier A of the shared memory (such as shared memory fd1). After receiving this notification, the service process A can convert the identifier A of the shared memory and create an identifier A' of the shared memory that can be recognized by the service process A (such as shared memory fd1'). The identifier A and identifier A' of the shared memory correspond to the same shared memory, that is, the shared memory created by the above-mentioned transmission service middleware A. Thus, the creation of the shared memory on the A side of the electronic device is successful, and the service transmission service is successfully started.
[0116] S17. The transmission service middleware B notifies the service process B that the service transmission service has been successfully started.
[0117] S18. The service process B converts to obtain the identifier B' of the shared memory, and the service transmission service is successfully started.
[0118] Among them, when the transmission service middleware B notifies the service process B that the service transmission service has been successfully started, it can carry the identifier B of the shared memory (such as shared memory fd2). After receiving this notification, the service process B can convert the identifier B of the shared memory and create an identifier B' of the shared memory that can be recognized by the service process B (such as shared memory fd2'). The identifier B and identifier B' of the shared memory correspond to the same shared memory, that is, the shared memory created by the above-mentioned transmission service middleware B. Thus, the creation of the shared memory on the B side of the electronic device is successful, and the service transmission service is successfully started.
[0119] After the service transmission services of both the electronic device A and the electronic device B have been successfully started, the electronic device A can transmit data to the electronic device B. The specific process can be as follows:
[0120] S19. The service process A writes the service data into the shared memory.
[0121] That is to say, when the electronic device A transmits service data to the electronic device B, the service process A in the electronic device A can write the service data to be sent into the above-mentioned created shared memory. Among them, the service process A can find the address of the shared memory through the identifier A' of the shared memory obtained by the above conversion, and then write the service data into the shared memory.
[0122] S20. The service process A notifies the transmission service middleware A through the IPC communication mechanism that there is service data to be sent currently.
[0123] S21. The transmission service middleware A notifies the transmission dynamic library A that there is service data to be sent currently.
[0124] After the service process A writes service data to the shared memory, it can notify the transmission service middleware A of the service data to be sent currently, so that the transmission process can transmit the service data. It should be noted that when the service process A notifies the transmission service middleware A through the IPC communication mechanism, the notification message sent only carries the notification content (such as the notification message for instructing to read data), and does not carry the content of the service data, that is, it reduces the size of the data sent each time and avoids problems such as communication out-of-memory and crashes.
[0125] S22. The transmission dynamic library A reads the service data from the shared memory.
[0126] S23. The transmission dynamic library A sends the service data to the transmission dynamic library B of the electronic device B.
[0127] Among them, the transmission dynamic library A can find the address of the shared memory according to the saved identifier A of the shared memory and read the service data from the shared memory. Then the transmission dynamic library A can send the service data to the communication driver A of the kernel layer. The communication driver A sends the service data to the communication driver B of the electronic device B through the network, and the communication driver B then sends the service data to the transmission dynamic library B.
[0128] In some implementation manners, if there are multiple services executing concurrently currently and multiple services need to transmit service data, since different service processes correspond to different shared memories, for example, the identifier of the service process or the identifier of the service can correspond to the shared memory fd, then the transmission dynamic library A can find the corresponding shared memory fd according to the identifier of each service process or the identifier of the service, and then find the corresponding shared memory according to the shared memory fd to read the corresponding service data, avoiding the risk of service data being misused.
[0129] In some implementation manners, the process of the service process A writing service data to the shared memory in S19 and the process of the transmission dynamic library A reading service data from the shared memory in S22 can adopt a serialized process, that is, one write is followed by one read, and then another write is followed by one read. Among them, as Figure 6 shown, for the shared memory (assuming the size size is 10MB), each write starts from the beginning (assuming 1MB of data is written), each read also starts from the beginning, and the read service data can be deleted after each read, and the write is cycled in turn. This can prevent problems such as data being overwritten or data loss when the data is not accessed.
[0130] In some other implementation manners, when serializing the writing and reading of service data from the shared memory, to further ensure the accuracy of the read data, that is, to prevent reading incorrect service data, the embodiments of the present application can also perform security verification on the service data in the shared memory. Among them, asFigure 7 As shown in Figure 7 , for the service data written into the shared memory, a data format of message length (length) + message content is adopted. The message length refers to the length of the service data to be sent this time. For example, the message length can occupy 4 bytes; the message content refers to the specific content of the service data to be sent by the service process. When the service process writes service data into the shared memory, it will first write the message length. For example, it will first write a 4-byte message length, and then write the service data to be sent at a position 4 bytes offset after writing the message length. After the service process writes the service data into the shared memory, when the service process A in S20 notifies the transmission service middleware A through the IPC communication mechanism that there is service data to be sent currently, the notification message can carry the message length (length), but does not carry the service data.
[0131] Next, when the transmission dynamic library A reads the service data from the shared memory in S22, it will first read the message length (length’). For example, it reads a 4-byte message length. If length’ is equal to length, it means that the message verification is successful, and the transmission dynamic library A can read the service data at a position 4 bytes offset after the message length in the shared memory. If length’ is not equal to length, it means that the message verification fails, and the transmission dynamic library A will no longer read the service data, that is, the data transmission fails. Thus, the accuracy in the data transmission process can be improved.
[0132] S24. The transmission dynamic library B writes the service data into the shared memory.
[0133] After receiving the service data, the transmission dynamic library B can find the address of the shared memory according to the saved identifier B of the shared memory, and write the service data into the shared memory.
[0134] S25. The transmission dynamic library B notifies the transmission service middleware B that there is service data to be received currently.
[0135] S26. The transmission service middleware B notifies the service process B through the IPC communication mechanism that there is service data to be received currently.
[0136] After the transmission dynamic library B writes the service data into the shared memory, it can notify the transmission service middleware B that there is service data to be received currently, so as to notify the service process B to receive the service data. It should be noted that when the transmission service middleware B notifies the service process B through the IPC communication mechanism, the notification message sent also only carries the notification content and does not carry the content of the service data, that is, it reduces the size of the data sent each time and avoids problems such as communication out-of-memory and crashes.
[0137] S27. The service process B reads the service data from the shared memory and performs corresponding data processing.
[0138] The service process B in the electronic device B can read service data from the shared memory and process it, such as decoding and displaying the screen mirroring service data. Among them, the service process B can find the address of the shared memory through the identifier B' of the shared memory obtained by the above conversion, and then read the service data from the shared memory.
[0139] It can be understood that the above describes the data transmission process taking one service process as an example. When there are multiple services in concurrency, multiple shared memories can be created correspondingly, with each service corresponding to one shared memory. Then, when each service needs to send service data, it can write the service data into its corresponding shared memory, and then the transmission process reads the service data from the corresponding shared memory and sends it to the peer electronic device. Thus, in the scenario of multiple services in concurrency, by using the shared memory to read and write data, there is no need to send service data through the IPC communication mechanism, and only the notification message needs to be sent, which can break through the data limit bottleneck of the IPC communication mechanism.
[0140] In the above data transmission method, the electronic device creates a shared memory when the service data traffic is large, so that each service process corresponds to one shared memory. After the service process writes the service data into the shared memory, it can notify the transmission process to read the service data from the shared memory to send the service data to other electronic devices. When the service process notifies the transmission process to read the service data through the IPC communication mechanism, only the notification message needs to be sent, and there is no need to send the service data anymore, which reduces the size of the data sent each time, solves the limitation of the size of the transmitted data during IPC communication in the scenario of multiple services in concurrency, avoids problems such as communication out-of-memory and crashes, and at the same time improves the concurrency number of data transmission.
[0141] The above embodiments describe the scenario of creating a shared memory when the service data traffic is large. If the transmission service middleware A in S3 determines that there is no need to create a shared memory, the shared memory can no longer be created, and the data transmission process in this scenario can be as shown in the following embodiments. Figure 8 It is a schematic diagram of the timing process of another data transmission method provided by the embodiments of the present application, which specifically may include:
[0142] S31. The service application A receives the first operation of the user and starts the service process A.
[0143] S32. The service process A instructs the transmission service middleware A to start the service transmission service.
[0144] Among them, the processes of S31 - S32 can refer to the above S1 - S2, and will not be elaborated here.
[0145] S33. The transmission service middleware A determines whether to create a shared memory. If it does not need to create a shared memory, it executes S34. If it needs to create a shared memory, it executes S4 in the above embodiment.
[0146] Among them, the transmission service middleware A can determine whether to create a shared memory according to the service type and / or service priority. When determining whether to create a shared memory according to the service type, if it is not the file transfer type, screen mirroring type, etc., there is no need to create a shared memory because the data to be transmitted for these service types is usually relatively large. If it is not these service types, the data to be transmitted is relatively small. It can also be understood that when the transmission service middleware A identifies that the transmission traffic required by the current service is relatively small according to the service type and / or service priority, it is determined that there is no need to create a shared memory. In some implementation manners, whether to create a shared memory can also be specified by the service application itself.
[0147] S34. The transmission service middleware A initializes the service transmission service.
[0148] S35. The transmission service middleware A sends a notification message to the transmission dynamic library A to pull up the client.
[0149] Among them, the service identifier of the service transmission service can be carried in the notification message to notify the transmission dynamic library A to pull up the client corresponding to the service.
[0150] S36. The transmission dynamic library A pulls up the client.
[0151] S37. The transmission dynamic library A returns a success message of pulling up the client to the transmission service middleware A.
[0152] After receiving the notification message sent by the transmission service middleware A, the transmission dynamic library A can pull up the client. Subsequently, the transmission dynamic library A can also return a message to the transmission service middleware A indicating that the client has been successfully pulled up.
[0153] S38. The transmission service middleware A of the electronic device A sends a request to start the service transmission service to the transmission service middleware B of the electronic device B.
[0154] That is to say, after the service on the electronic device A side is started, it will send a request to the electronic device B, requesting the electronic device B to also start the service transmission service and pull up the corresponding server.
[0155] In some implementations, the request sent by Transmission Service Middleware A to Transmission Service Middleware B may carry the identifier of the service transmission service, the device identifier of Electronic Device A, and the identifier of whether to use shared memory, etc. Among them, the identifier of whether to use shared memory can be represented by an int parameter. For example, 1 indicates using shared memory, and 0 indicates not using shared memory. In the case where the identifier is 0, after receiving the request, Electronic Device B will no longer create shared memory.
[0156] S39. Transmission Service Middleware B determines whether to create shared memory. If it does not need to create shared memory, it executes S40. If it needs to create shared memory, it executes S10 in the above embodiment.
[0157] That is, Transmission Service Middleware B can determine whether to create shared memory according to the identifier of whether to use shared memory in the above request.
[0158] S40. Transmission Service Middleware B initializes the service transmission service.
[0159] S41. Transmission Service Middleware B sends a notification message to pull up the server to Transmission Dynamic Library B.
[0160] Among them, the notification message may carry the identifier of the service transmission service to notify Transmission Dynamic Library B to pull up the server of the corresponding service.
[0161] S42. Transmission Dynamic Library B pulls up the server.
[0162] S43. Transmission Dynamic Library B returns a success message for pulling up the server to Transmission Service Middleware B.
[0163] After receiving the notification message sent by Transmission Service Middleware B, Transmission Dynamic Library B can pull up the server. Subsequently, Transmission Dynamic Library B can also return a message indicating that the server has been successfully pulled up to Transmission Service Middleware B.
[0164] S44. Transmission Service Middleware B of Electronic Device B sends a message indicating the successful start of the service transmission service to Transmission Service Middleware A of Electronic Device A.
[0165] That is to say, after starting the service transmission service on the side of Electronic Device B, it will send a message indicating successful startup to Electronic Device A to notify Electronic Device A to perform the next operation.
[0166] S45. Transmission Service Middleware A notifies Business Process A that the service transmission service has started successfully.
[0167] S46. Transmission Service Middleware B notifies Business Process B that the service transmission service has started successfully.
[0168] After the business transmission services of electronic device A and electronic device B are successfully started, electronic device A can transmit data to electronic device B. The specific process is as follows:
[0169] S47. Business process A obtains business data.
[0170] Among them, business process A can obtain the business data to be sent to electronic device B, such as the screen mirroring data in the screen mirroring service.
[0171] S48. Business process A notifies transmission service middleware A of the business data to be sent currently through the IPC communication mechanism.
[0172] S49. Transmission service middleware A notifies transmission dynamic library A of the business data to be sent currently.
[0173] After business process A obtains the business data, it can notify transmission service middleware A of the business data to be sent currently, so that the transmission process can transmit the business data. It should be noted that at this time, when business process A notifies transmission service middleware A through the IPC communication mechanism, the notification message sent carries the content of the business data.
[0174] S50. Transmission dynamic library A reads the notified business data.
[0175] S51. Transmission dynamic library A sends the business data to transmission dynamic library B of electronic device B.
[0176] That is to say, when transmission dynamic library A receives the notification message from transmission service middleware A, it can read the business data carried in the notification message to send to transmission dynamic library B of electronic device B.
[0177] In some implementation manners, when the business process sends business data, to ensure the accuracy of data reading, it can also adopt the data format of message length (length) + message content. The message length refers to the length of the business data to be sent this time. For example, the message length can occupy 4 bytes; the message content refers to the specific content of the business data to be sent by the business process. When business process A notifies transmission service middleware A of the business data to be sent currently through the IPC communication mechanism in S48, the notification message can carry the message length (length) and the business data. Then when transmission dynamic library A reads the business data in the notification message, it can also first read the message length (length’). If length’ is equal to length, it means the message verification is successful, and transmission dynamic library A can transmit the business data; if length’ is not equal to length, it means the message verification fails, and transmission dynamic library A will no longer transmit the business data.
[0178] S52. The transmission dynamic library B receives and parses the service data.
[0179] S53. The transmission dynamic library B notifies the transmission service middle platform B of the service data to be received currently.
[0180] S54. The transmission service middle platform B notifies the service process B of the service data to be received currently through the IPC communication mechanism.
[0181] After the transmission dynamic library B receives the service data, it is handed over to the transmission service middle platform B to transmit to the service process B through the IPC communication mechanism. At this time, the notified message also carries the service data.
[0182] S55. The service process B performs corresponding data processing on the service data in the notification.
[0183] The service process B in the electronic device B can process the service data in the notified message, such as decoding and displaying the screen mirroring service data, etc.
[0184] For the above data transmission method, when the electronic device performs data transmission, it can judge the size of the service data traffic. When it recognizes that the service data traffic is large, it creates a shared memory. When the service data traffic is small, it does not create a shared memory, so as to improve the adaptability of the data transmission process.
[0185] For the data transmission method provided in the above embodiments, we also conducted a performance experiment comparison in two scenarios of creating a shared memory and not creating a shared memory, as Figure 9 shown. The abscissa in the figure represents the amount of data transmitted by the service process each time. If it is the scenario of creating a shared memory, it is the amount of data written into the shared memory by the service process each time. If it is the scenario of not creating a shared memory, it is the amount of data transmitted by the service process to the transmission process each time. The ordinate represents the transmission rate, and the unit is MB / second. Curve 1 is the performance curve when creating a shared memory, and Curve 2 is the performance curve when not creating a shared memory. It can be seen that when creating a shared memory, even if the amount of data transmitted by the service process each time is large (such as greater than 1MB), a relatively high transmission rate can still be maintained; when not creating a shared memory, when the amount of data transmitted by the service process is large, the transmission rate is close to 0, that is, there may be a phenomenon of out-of-memory or memory crash. Then, through the performance experiment comparison, it can be known that the data transmission performance when creating a shared memory is significantly higher.
[0186] The examples of the data transmission method provided by the embodiments of the present application are described in detail above. It can be understood that, in order to implement the above functions, the electronic device includes corresponding hardware and / or software modules for executing each function. Those skilled in the art should easily realize that, combining the units and algorithm steps of each example described in the embodiments disclosed in this article, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the way of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described function for each specific application in combination with the embodiments, but such implementation should not be considered to exceed the scope of the present application.
[0187] The embodiments of the present application can divide the electronic device into functional modules according to the above method examples. For example, each function can be corresponding to each functional module, such as a detection unit, a processing unit, a display unit, etc., or two or more functions can be integrated into one module. The above integrated module can be implemented in the form of hardware or in the form of a software functional module. It should be noted that the division of modules in the embodiments of the present application is illustrative, only a logical function division, and there can be other division methods in actual implementation.
[0188] It should be noted that all relevant contents of each step involved in the above method embodiments can be cited in the function description of the corresponding functional module, and will not be repeated here.
[0189] The electronic device provided in this embodiment is used to execute the above data transmission method, so it can achieve the same effect as the above implementation method.
[0190] In the case of adopting an integrated unit, the electronic device may further include a processing module, a storage module, and a communication module. Among them, the processing module can be used to control and manage the actions of the electronic device. The storage module can be used to support the electronic device to execute stored program codes and data, etc. The communication module can be used to support the communication between the electronic device and other devices.
[0191] Among them, the processing module can be a processor or a controller. It can implement or execute various exemplary logical blocks, modules, and circuits described in combination with the disclosure of the present application. The processor can also be a combination that realizes computing functions, such as a combination including one or more microprocessors, a combination of a digital signal processor (DSP) and a microprocessor, and so on. The storage module can be a memory. The communication module can specifically be a device for interacting with other electronic devices, such as a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, etc.
[0192] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in this embodiment may be a device having Figure 2 the structure shown.
[0193] The embodiments of the present application also provide a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the processor is caused to execute the data transmission method in any of the above embodiments. The storage medium may include: various media that can store program codes such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc.
[0194] The embodiments of the present application also provide a computer program product. When the computer program product runs on a computer, the computer is caused to execute the above-related steps to implement the data transmission method in the above embodiments.
[0195] In addition, the embodiments of the present application also provide a device, which may specifically be a chip, a component, or a module. The device may include a processor and a memory connected to each other; wherein, the memory is used to store computer execution instructions. When the device runs, the processor may execute the computer execution instructions stored in the memory, so that the chip executes the data transmission method in each of the above method embodiments.
[0196] Among them, the electronic device, the computer-readable storage medium, the computer program product, or the chip provided in this embodiment are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be elaborated here.
[0197] Through the description of the above embodiments, those skilled in the art can understand that for the convenience and simplicity of description, only the above division of each functional module is used as an example for illustration. In practical applications, the above functions may be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
[0198] In addition, each functional unit in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
[0199] The above content is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A data transmission method, which is applied to a first electronic device, characterized in that, There is a communication connection between the first electronic device and the second electronic device, and the method includes: When there is service data to be sent to the second electronic device among multiple service processes in the first electronic device, write the service data to be sent into the first shared memory through a first service process in the first electronic device. Among them, service processes of different service applications correspond to different shared memories. The first service process is any one of the multiple service processes, and the first service process corresponds to the first shared memory; Send a first notification message to a first transmission process in the first electronic device through the first service process based on the inter-process communication (IPC) mechanism. The first notification message is used to instruct the first transmission process to read the service data to be sent from the first shared memory, and the first notification message does not carry the service data to be sent; Read the service data to be sent from the first shared memory through the first transmission process, and send the service data to be sent to the second electronic device.
2. The method according to claim 1, characterized in that, Before writing the service data to be sent into the first shared memory through the first service process in the first electronic device, the method further includes: Determine whether to create a shared memory through the first transmission process, and create the first shared memory corresponding to the first service process when it is determined that a shared memory needs to be created.
3. The method according to claim 2, wherein The determining whether to create a shared memory through the first transmission process includes: Determine whether to create a shared memory through the first transmission process according to the service information corresponding to the first service process. The service information includes service type and / or service priority.
4. The method according to claim 3, wherein The determining whether to create a shared memory through the first transmission process according to the service information corresponding to the first service process includes: When the service type is a file transfer type or a screen mirroring type, determine that a shared memory needs to be created; When the service type is not a file transfer type and a screen mirroring type, determine that a shared memory does not need to be created.
5. The method according to any one of claims 2 to 4, characterized in that When it is determined that a shared memory needs to be created, the method further includes: The first electronic device sends a request message to the second electronic device, requesting the second electronic device to create a corresponding second shared memory. The request message carries an identifier indicating whether to create a shared memory.
6. The method according to any one of claims 1 to 5, characterized in that, The writing the service data to be sent into the first shared memory through the first service process in the first electronic device includes: Write the service data to be sent and the message length corresponding to the service data to be sent into the first shared memory through the first service process.
7. The method according to claim 6, characterized in that, The first notification message carries the message length corresponding to the service data to be sent.
8. The method according to claim 7, characterized in that, The reading the service data to be sent from the first shared memory through the first transmission process includes: Read the first message length from the first shared memory through the first transmission process. If the read first message length is equal to the message length corresponding to the service data to be sent carried in the first notification message, then read the service data to be sent from the first shared memory.
9. The method according to any one of claims 1 to 8, characterized in that, The writing of the service data to be sent into the first shared memory by the first service process in the first electronic device includes: Write the service data to be sent from the starting position of the first shared memory through the first service process; The reading of the service data to be sent from the first shared memory by the first transmission process includes: Read the service data to be sent from the starting position of the first shared memory through the first transmission process.
10. The method according to claim 1, wherein The first electronic device includes a transmission service middle platform and a transmission dynamic library. The sending of the first notification message from the first service process in the first electronic device to the first transmission process in the first electronic device based on the IPC communication mechanism includes: Send the first notification message to the transmission service middle platform through the first service process based on the IPC communication mechanism. The transmission service middle platform notifies the transmission dynamic library to read the service data to be sent from the first shared memory, where the first transmission process is the process pulled up when the transmission service middle platform is started.
11. The method according to claim 10, wherein Before the service data to be sent is written into the first shared memory by the first service process in the first electronic device, the method further includes: Indicate the transmission service middle platform to start the service transmission service through the first service process; Determine by the transmission service middle platform whether a shared memory needs to be created, and create the first shared memory corresponding to the first service process when it is determined that a shared memory needs to be created; Notify the transmission dynamic library to pull up the client through the transmission service middle platform. When the transmission dynamic library pulls up the client, save the identifier of the first shared memory.
12. A data transmission method, which is applied to a second electronic device, characterized in that, There is a communication connection between the first electronic device and the second electronic device. The method includes: Receive the service data from the first electronic device through the second transmission process in the second electronic device, and write the service data into the second shared memory; Send a second notification message to the second service process in the second electronic device through the second transmission process based on the IPC communication mechanism. The second notification message is used to instruct the second service process to read the service data from the second shared memory, and the second notification message does not carry the service data; Read the service data from the second shared memory through the second service process, and process the service data.
13. The method according to claim 12, characterized in that, Before the service data is written into the second shared memory, the method further includes: Receive a request message from the first electronic device through the second transmission process, determine whether a shared memory needs to be created according to the request message, and create the second shared memory when it is determined that a shared memory needs to be created. The request message carries an identifier indicating whether to create a shared memory.
14. An electronic device, characterized in that, Includes: One or more processors; One or more memories; The memory stores one or more programs which, when executed by the processor, cause the electronic device to perform the method according to any one of claims 1 to 11, or to perform the method according to any one of claims 12 to 13.
15. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium which, when executed by a processor, causes the processor to perform the method according to any one of claims 1 to 11, or to perform the method according to any one of claims 12 to 13.
Citation Information
Patent Citations
Inter-process communication method and inter-process communication device
CN113760560A
Data transmission method and equipment
CN113950033A
IPC data communication method and device, equipment and medium
CN114003413A
Business processing method and device
CN114528126A
Distributing communication of a data stream among multiple devices
US20140040364A1
Cited By
Data transmission method and electronic equipment
CN120256156A
Data transmission methods and electronic devices
CN120256156B