Data transmission methods and electronic devices
By using a shared memory mechanism in electronic devices, parallel read and write operations of the service process and the transmission process are achieved, which solves the transmission rate limitation of IPC communication in multi-service concurrent scenarios and improves data transmission performance.
Patent Information
- Application Number
- CN202311806621.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-25
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2043-12-25
AI Technical Summary
Existing inter-process communication (IPC) methods are limited by the size of data transmitted in a single transmission when multiple services are transmitting concurrently, resulting in slow transmission rates and problems such as communication exceeding memory limits and crashes.
By adopting a shared memory mechanism, data is written to the shared memory through the business process, and the transmission process reads it in parallel, avoiding direct IPC communication and realizing parallel read and write operations.
It improves the throughput of data transmission and the data transmission performance in multi-service concurrent scenarios, and avoids IPC communication memory overload and crash issues.
Smart Images

Figure CN120256156B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of electronics, in particular to a data transmission method and an electronic device. BACKGROUND
[0002] Currently, when data transmission is performed between two (or multiple) electronic devices, not only single-service data transmission can be supported, but also multi-service concurrent data transmission can be supported. For example, in the process of electronic device A projecting to electronic device B, electronic device A initiates a super-keyboard-and-mouse service to electronic device B, and then electronic device A needs to transmit data of the projection service and data of the super-keyboard-and-mouse service to electronic device B, so as to realize multi-service concurrent data transmission.
[0003] A popular data transmission method at present is an inter process communication (IPC) method, that is, a service process in electronic device A is different from a transmission process, the service process needs to send service data to the transmission process through an 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, multiple service processes will perform data transmission with the transmission process. However, the IPC communication mechanism has a limitation on the size of data transmitted at a time, and if the service data of multiple services is large, the transmission rate is slow during data transmission, and the transmission performance is not high. SUMMARY
[0004] The present application provides a data transmission method and an electronic device, which can improve the throughput of the data transmission process and improve the data transmission performance in a multi-service concurrent scenario.
[0005] In a first aspect, the present application provides a data transmission method, which is applied to a first electronic device, and a second electronic device is communicatively connected to the first electronic device. The method comprises the following steps: when multiple service processes in the first electronic device have service data to be sent to the second electronic device, a first service process in the first electronic device writes the service data to be sent into a first shared memory, wherein the 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; a first transmission process in the first electronic device detects that there is service data to be sent in the first shared memory, reads the service data to be sent from the first shared memory, and sends the service data to be sent to the second electronic device, wherein when there are multiple groups of service data to be sent, the first service process writes the service data to be sent into the first shared memory and the first transmission process reads the service data to be sent from the first shared memory are performed in parallel.
[0006] In the process that the first electronic device (i.e., electronic device A) transmits service data to the second electronic device (i.e., electronic device B), the service data is from a service application in the first electronic device. After the service application is run, a first service process (i.e., service process A) is started accordingly. In the present application, the first service process does not directly send the to-be-sent service data to the first transmission process (i.e., transmission process A), but writes the service data into the first shared memory that has been created. The first transmission process A can detect in real time whether there is to-be-sent service data in the first shared memory, and when there is to-be-sent service data, the first transmission process reads the service data from the first shared memory. Therefore, the first service process and the first transmission process no longer perform IPC communication, which solves the limitation of the size of the transmitted data in the IPC communication, and avoids problems such as communication out of memory and crash. At the same time, the writing operation of the first service process and the reading operation of the first transmission process can be executed in parallel. The first service process does not have to wait for the first transmission process to read the data before writing, and the read service data can be deleted in time to release space for subsequent writing of service data, thereby greatly improving the throughput of the data transmission process and improving the data transmission performance in a multi-service concurrent scenario.
[0007] In combination with the first aspect, in some implementations of the first aspect, a public header is created at the start of the first shared memory, and information in the public header includes at least size information of the first shared memory, current data node number information in the first shared memory, write pointer position offset information, read pointer position offset information, left writeable space information of the write pointer, right writeable space information of the write pointer, and read-write reversal pointer position offset information.
[0008] The information in the public header can be used by the first service process and the first transmission process to determine how to read and write data, for example, at which position to write data and from which position to read data.
[0009] In some implementations, the public header can occupy a space of M size in the shared memory, the size information of the shared memory refers to the size of the created shared memory. The current data node number information (cnt) refers to the number of data blocks in the shared memory that are not read. The left writable space information of the write pointer (leftLen) refers to the writable space of the left part of the write pointer after the business data (or data packet) is accessed. The right writable space information of the write pointer (rightLen) refers to the writable space of the right part of the write pointer in the shared memory except the left writable space. The write pointer position offset information (writeOffset) refers to the starting position of the next write data. The read pointer position offset information (readOffset) refers to the starting position of the next read data. The read-write reverse pointer position offset information (reverseOffset) refers to the write pointer position offset when the right writable space is not enough to continue to write the next data. When the read pointer position offset is equal to the read-write reverse pointer position offset, the data needs to be read from the beginning.
[0010] In combination with the first aspect, in some implementations of the first aspect, the writing, by the first business process in the first electronic device, of the to-be-sent business data into the first shared memory includes: if it is determined, according to the left writable space information of the write pointer, that the left writable space is enough to write the to-be-sent business data, and / or if it is determined, according to the right writable space information of the write pointer, that the right writable space is enough to write the to-be-sent business data, then the first business process writes the to-be-sent business data into the first shared memory.
[0011] That is to say, as long as there is still space in the first shared memory to write the to-be-sent business data, the first business process can write the to-be-sent business data into the first shared memory.
[0012] In combination with the first aspect, in some implementations of the first aspect, if it is determined, according to the left writable space information of the write pointer, that the left writable space is enough to write the to-be-sent business data, and / or if it is determined, according to the right writable space information of the write pointer, that the right writable space is enough to write the to-be-sent business data, then the first business process writes the to-be-sent business data into the first shared memory, including:
[0013] If the left writable space is not enough to write the to-be-sent business data, and the right writable space is enough to write the to-be-sent business data, then the first business process writes the to-be-sent business data into the position pointed to by the write pointer in the first shared memory.
[0014] If the left writable space is enough to write the to-be-sent business data, and the right writable space is also enough to write the to-be-sent business data, then the first business process writes the to-be-sent business data into the position pointed to by the write pointer in the first shared memory.
[0015] if the left writable space is sufficient to write the to-be-sent service data and the right writable space is insufficient to write the to-be-sent service data, reversely moving the write pointer from the first position to the second position, and writing the to-be-sent service data into the second position by the first service process, the first position being a position pointed to by the write pointer when the right writable space is insufficient to write the to-be-sent service data, and the second position being a position after the common header.
[0016] Generally, the write pointer moves from a head position to a tail position of the first shared memory (for example, moves from left to right), but if the left writable space in the first shared memory is insufficient to write the next service data, the write pointer needs to be moved to a position of the right writable space to write the service data. Then, when the service data written into the first shared memory by the first service process is relatively small, the remaining space in the first shared memory is relatively sufficient, in which case, the right writable space of the first shared memory can support the first service process to continue writing the service data, and the write pointer keeps moving from left to right. As the service data written into the first shared memory by the first service process is more and more, the write pointer continues to move to the right and will move to the end of the first shared memory, in which case, the right writable space of the first shared memory can be insufficient to write the next service data, but the left writable space has released a larger space to write the service data, at which time the write pointer needs to be reversely moved to a position of the left writable space to write the service data into the left writable space. Thus, it can be guaranteed that the first service process can successfully write the data into the first shared memory.
[0017] With reference to the first aspect, in some implementations of the first aspect, after reversely moving the write pointer from the first position to the second position, the method further includes: updating the read-write reverse pointer position offset information to offset information corresponding to the first position.
[0018] As the write pointer is reversely moved from the first position to the second position, it indicates that the space left after the first position is insufficient to write a service data, that is, there is no data written after the first position, thus it is needed to record the position of the insufficient space for writing, so that when the subsequent read pointer points to the position, it is used to prompt that there is no data to be read behind, thus the read-write reverse pointer can be moved to the position of the insufficient space for writing to record, that is, the read-write reverse pointer position offset is the offset information corresponding to the first position.
[0019] In some implementations of the first aspect, the detecting, by the first transport process in the first electronic device, that there is service data to be sent in the first shared memory comprises: if the first transport process determines, according to the write pointer position offset information and the read pointer position offset information, that the write pointer position offset is not equal to the read pointer position offset, and / or determines, according to the current data node number information, that the current data node number is not 0, then it is determined that there is service data to be sent in the first shared memory.
[0020] That is, as long as there is service data to be sent in the first shared memory that has not been read, the first transport process can read the service data to be sent from the first shared memory.
[0021] In some implementations of the first aspect, the reading, by the first transport process, the service data to be sent from the first shared memory comprises: determining, according to the read pointer position offset information, a position pointed to by the read pointer in the first shared memory, and reading, by the first transport process, the service data to be sent from the position pointed to by the read pointer.
[0022] Generally, the position pointed to by the read pointer stores the next service data to be sent, so the first transport process can read the service data to be sent according to the position pointed to by the read pointer.
[0023] In some implementations of the first aspect, the reading, by the first transport process, the service data to be sent from the position pointed to by the read pointer comprises:
[0024] In a case where the read pointer position offset information is different from the read-write reverse pointer position offset information, reading, by the first transport process, the service data to be sent from the position pointed to by the read pointer;
[0025] In a case where the read pointer position offset information is the same as the read-write reverse pointer position offset information, reversing the read pointer from a third position to a second position, and reading, by the first transport process, the service data to be sent from the second position, the third position being a position pointed to by the read-write reverse pointer.
[0026] In some implementations of the first aspect, the read pointer can move from a head position to a tail position of the first shared memory (for example, from left to right), and as the read pointer moves, the first transport process can sequentially read the service data to be sent. However, if there is no service data to be read after the position of the read pointer in the first shared memory (i.e., the read pointer position offset information is the same as the read-write reverse pointer position offset information), the read pointer needs to be moved to the position of the unread data to read the service data, i.e., the read pointer is moved to the position (second position) after the common head to start reading the service data again. Thus, it can be ensured that the first transport process can successfully read the data from the first shared memory.
[0027] With reference to the first aspect, in some implementations 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 method further includes: determining, by the first transmission process, whether the shared memory needs to be created, and creating the first shared memory corresponding to the first service process if it is determined that the shared memory needs to be created.
[0028] As can be seen from the above description, the first service process needs to write service data into the first shared memory, so the first shared memory needs to be created in advance in the first electronic device. In the present application, after the service thread is started, the service transmission service is instructed to be started, and the first transmission process is pulled up, and then the first shared memory is created by the first transmission process. The first transmission process can first determine whether the shared memory needs to be created, and create the first shared memory corresponding to the first service process if it is determined that the shared memory needs to be created.
[0029] With reference to the first aspect, in some implementations of the first aspect, the determination, by the first transmission process, of whether the shared memory needs to be created includes: determining, by the first transmission process, whether the shared memory needs to be created according to service information corresponding to the first service process, the service information including a service type and / or a service priority.
[0030] In some implementations of the first aspect, the determination, by the first transmission process, of whether the shared memory needs to be created includes: determining, by the first transmission process, whether the shared memory needs to be created according to service information corresponding to the first service process, the service information including a service type and / or a service priority.
[0031] In some implementations of the first aspect, the determination, by the first transmission process, of whether the shared memory needs to be created includes: determining, by the first transmission process, whether the shared memory needs to be created according to service information corresponding to the first service process, the service information including a service type and / or a service priority.
[0032] In some implementations of the first aspect, the determination, by the first transmission process, of whether the shared memory needs to be created includes: determining, by the first transmission process, whether the shared memory needs to be created according to service information corresponding to the first service process, the service information including a service type and / or a service priority.
[0033] In some implementations of the first aspect, the determination, by the first transmission process, of whether the shared memory needs to be created includes: determining, by the first transmission process, whether the shared memory needs to be created according to service information corresponding to the first service process, the service information including a service type and / or a service priority.
[0034] With reference to the first aspect, in some implementations of the first aspect, in a case where it is determined that the shared memory needs to be created, the method further includes: sending, by the first electronic device, a request message to the second electronic device, requesting the second electronic device to create a corresponding second shared memory, and the request message carrying an identifier of whether to create the shared memory.
[0035] That is, in a case where the first electronic device creates the shared memory, a request is sent to the second electronic device, requesting the second electronic device to also create the shared memory, so as to ensure that the two electronic devices normally perform IPC communication. The request message sent by the first electronic device to the second electronic device can carry an identifier of whether to create the shared memory, where the identifier of whether to create the shared memory can be represented by an int parameter, for example, 1 represents to create the shared memory, and 0 represents not to create the shared memory. In a case where the identifier is 1, the second electronic device will also create the shared memory after receiving the request.
[0036] With reference to the first aspect, in some implementations of the first aspect, the writing, by the first service process in the first electronic device, of the to-be-sent service data into the first shared memory includes: writing, by the first service process, the to-be-sent service data and a message length corresponding to the to-be-sent service data into the first shared memory.
[0037] In reading and writing the service data into the first shared memory, in order to ensure the accuracy of reading data, that is, to prevent reading of incorrect service data, the application can also perform security verification on the service data in the shared memory. In this implementation, for the service data written into the first shared memory, a data format of message length + message content is adopted, where 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 the service data into the first shared memory, the message length is written first, for example, 4 bytes of the message length is written first, and then the to-be-sent service data is written at a position offset by 4 bytes.
[0038] With reference to the first aspect, in some implementations of the first aspect, the reading, from the first shared memory, of the to-be-sent service data includes: reading a first message length from the first shared memory, and if the read first message length is equal to a message length corresponding to the to-be-sent service data written, reading the to-be-sent service data from the first shared memory.
[0039] That is to say, after the first transmission process reads the first message length (length') from the first shared memory, if length' is equal to length (i.e., the message length corresponding to the service data to be sent), it indicates that the message check is successful, and the first transmission process can read the service data from the position 4 bytes after the message length in the first shared memory. If length' is not equal to length, it indicates that the message check fails, and the first transmission process will not read the service data, i.e., the data transmission fails. Thus, the accuracy in the data transmission process can be improved. In some implementations, if the written service data adopts the data format of message length (length) + message content, the first service process can send the message length to the first transmission process for subsequent message check by the first transmission.
[0040] In combination with the first aspect, in some implementations of the first aspect, the first electronic device includes a transmission service middleware and a transmission dynamic library, and before the first service process in the first electronic device writes the service data to be sent into the first shared memory, the method further includes: instructing the transmission service middleware to start the service transmission service by the first service process, starting the first transmission process when the transmission service middleware starts the service transmission service; determining whether the shared memory needs to be created by the transmission service middleware, and creating the first shared memory corresponding to the first service process in the case of determining that the shared memory needs to be created; notifying the transmission dynamic library to pull up the client by the transmission service middleware, saving the identifier of the first shared memory when the transmission dynamic library pulls up the client.
[0041] That is to say, after the first service process is started, it can instruct the transmission service middleware to start the service transmission service, and the first transmission process is pulled up accordingly. Then the transmission service middleware can determine whether the shared memory needs to be created according to the service type and / or the service priority, and create the first shared memory corresponding to the first service process in the case of needing to create the shared memory, and record the identifier (such as the shared memory file descriptor fd) of the first shared memory. The address of the shared memory can be found through the shared memory fd1, so as to read and write data in the shared memory corresponding to the address. Then, the transmission service middleware can notify the transmission dynamic library to pull up the client, and carry the identifier of the first shared memory when notifying, and then the transmission dynamic library can pull up the client, save the identifier of the first shared memory, and return a success message of pulling up the client to the transmission service middleware. Thus, the first service process can write the service data into the first shared memory in the future, without the need to send the service data directly to the first transmission process, so as to avoid the problems of IPC communication exceeding the memory and crashing.
[0042] In some implementations, the first service process can write the service data to be sent into the first shared memory, and the transmission dynamic library can perform real-time detection to detect whether there is service data to be sent in the first shared memory for subsequent data transmission.
[0043] In a second aspect, the present application provides a data transmission method, which is applied to a second electronic device, and a first electronic device and the second electronic device have a communication connection. The method comprises: receiving, by a second transmission process in the second electronic device, service data from the first electronic device, and writing the service data into a second shared memory; detecting, by a second service process in the second electronic device, that there is service data to be received in the second shared memory, reading the service data to be received from the second shared memory, and processing the service data to be received, wherein, in the case that there are multiple groups of service data to be received, the writing of the service data into the second shared memory by the second transmission process and the reading of the service data from the second shared memory by the second service process are performed in parallel.
[0044] In combination with the second aspect, in some implementations of the second aspect, before the service data is written into the second shared memory, the method further comprises: receiving, by the second transmission process, a request message from the first electronic device, determining whether a shared memory needs to be created according to the request message, and creating the second shared memory in the case that it is determined that the shared memory needs to be created, wherein the request message carries an identifier of whether to create the shared memory.
[0045] In combination with the second aspect, in some implementations of the second aspect, before the service data is written into the second shared memory, the method further comprises: receiving, by the second transmission process, a request message from the first electronic device, determining whether a shared memory needs to be created according to the request message, and creating the second shared memory in the case that it is determined that the shared memory needs to be created, wherein the request message carries an identifier of whether to create the shared memory.
[0046] In some implementations, after receiving service data, the second transmission process of the second electronic device writes the service data into the second shared memory. It can then notify the second service process of available service data via IPC communication. The second service process reads the service data from the second shared memory and performs corresponding data processing. Here, when the second transmission process notifies the second service process, it can only carry the notification content, omitting the service data itself, to reduce the size of the data sent in a single transmission and avoid issues such as communication exceeding memory limits or crashes.
[0047] Thirdly, this application provides an apparatus included in an electronic device. This apparatus has the function of implementing the electronic device behavior described in the first aspect and its possible implementations, or it has the function of implementing the electronic device behavior described in the second aspect and its possible implementations. 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.
[0048] Fourthly, this application provides an electronic device, which includes a processor, a memory, and an interface; the processor, memory, and interface cooperate with each other to enable the electronic device to execute any method of the technical solution in the first aspect, or to execute any method of the technical solution in the second aspect.
[0049] Fifthly, this application provides a chip including a processor. The processor is configured to read and execute a computer program stored in a memory to perform the methods of the first aspect and any possible implementation thereof, or to perform the methods of the second aspect and any possible implementation thereof.
[0050] Optionally, the chip may also include a memory, which is connected to the processor via a circuit or wire.
[0051] Alternatively, the chip may also include a communication interface.
[0052] Sixthly, this application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform any method of the technical solution of the first aspect, or any method of the technical solution of the second aspect.
[0053] In a seventh aspect, this application provides a computer program product comprising: computer program code, which, when executed on an electronic device, causes the electronic device to perform any method of the technical solution of the first aspect, or to perform any method of the technical solution of the second aspect. Attached Figure Description
[0054] Figure 1 is a schematic diagram of a data transmission process provided by the related art;
[0055] Figure 2 is a structural schematic diagram of an electronic device provided by an embodiment of the present application;
[0056] Figure 3 is a software structural block diagram of an electronic device provided by an embodiment of the present application;
[0057] Figure 4 is a system architecture schematic diagram of a data transmission process provided by an embodiment of the present application;
[0058] Figure 5 is a timing flow schematic diagram of a data transmission method provided by an embodiment of the present application;
[0059] Figure 6 is a structural schematic diagram of a common header provided by an embodiment of the present application;
[0060] Figure 7 is a schematic diagram of an initial state of a shared memory provided by an embodiment of the present application;
[0061] Figure 8 is a format schematic diagram of data written in a shared memory provided by an embodiment of the present application;
[0062] Figure 9 is a state schematic diagram when data is written in a shared memory provided by an embodiment of the present application;
[0063] Figure 10 is a state schematic diagram when data is written in a shared memory provided by another embodiment of the present application;
[0064] Figure 11 is a state schematic diagram when data is written in a shared memory provided by yet another embodiment of the present application;
[0065] Figure 12 is a timing flow schematic diagram of another data transmission method provided by an embodiment of the present application;
[0066] Figure 13 is a performance experiment comparison schematic diagram in a scenario of creating a shared memory and not creating a shared memory provided by an embodiment of the present application. DETAILED DESCRIPTION
[0067] The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or, for example, A / B can represent A or B; "and / or" herein only describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0068] Hereinafter, the terms "first", "second", "third" are only for description purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second", "third" can explicitly or implicitly include one or more features.
[0069] First of all, the data transmission of the multi-service concurrency in the embodiments of the present application can be the data transmission performed when multiple services are simultaneously initiated between two (or multiple) electronic devices. Taking electronic device A and electronic device B as an example, multiple services such as super keyboard and mouse, super call, screen projection (such as heterogeneous screen projection) can be simultaneously initiated between electronic device A and electronic device B. In order to ensure the normal operation of the 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 can include but is not limited to message data, streaming media data, file data, etc.
[0070] Generally, when electronic device A performs data transmission to electronic device B, it adopts an inter-process communication (IPC) (also referred to as cross-process communication) mode. IPC communication is a capability provided by an operating system for data exchange and sharing between different processes, which can enable message passing between different processes and achieve functions such as process communication and synchronization. Then, as shown in Figure 1 The process of transmitting service data from electronic device A to electronic device B using the IPC communication mechanism can include that the service process (corresponding to the service process started by electronic device A when starting the service) in electronic device A is different from the transmission process (the process for transmitting service data to electronic device B), 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 (for example, through network air interface transmission). After the transmission process of electronic device B receives the service data, it also sends 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 started accordingly, and these multiple service processes all need to perform data transmission with the transmission process to send the service data corresponding to each service to electronic device B.
[0071] In the Android system, the commonly used IPC communication mechanism is the Binder mechanism, which is a communication mechanism based on the C / S (Client / Server) model, so that a process can expose its service to other processes, and other processes can make remote calls through Binder, providing cross-process method calls, data transmission and thread synchronization functions. However, in the Binder mechanism, the single transmission data size of the upper user space (such as a business process, a business application, etc.) communication is not more than 1MB (megabyte), which may cause transmission limitation when multiple businesses are concurrently transmitted, and may cause Binder communication to exceed memory, crash and other problems. For example, in the case of simultaneously initiating a screen projection and a super call business between an electronic device A and an electronic device B, the business process corresponding to the screen projection business needs to send business data to the transmission process through the Binder mechanism, and the super call business also needs to send business data to the transmission process through the Binder mechanism. If the single transmission data of the business process corresponding to the screen projection business through the Binder mechanism reaches 1MB, the super call business may not be able to perform a normal sending process when sending business data through the Binder mechanism, and may cause Binder communication to exceed memory, crash and other problems.
[0072] In the Windows system, the commonly used IPC communication mechanism is the pipe mechanism, and we can call a data stream connected from one process to another process as a "pipe". The pipe can be divided into an anonymous pipe and a named pipe. The anonymous pipe can only communicate between parent and child processes, cannot communicate between networks, and the data transmission is one-way, only one end can write and the other end can read. The command pipe can communicate between any processes, the communication is bidirectional, and any end can read and write, but only one end can read and one end can write at the same time. However, when the data transmission volume is large in the process of multiple business concurrency, the transmission rate of the pipe mechanism becomes a performance bottleneck. For example, when the business process transmits file data to the transmission process through the pipe, assuming that the time consumption of each IPC communication is 20 milliseconds and the data volume transmitted by each communication is 1MB, the transmission rate is only 50MB / s, the transmission speed is slow, and the ideal file transmission rate cannot be achieved. More seriously, when the data volume transmitted by each communication of a business is greater than 1MB, the transmission of business data of another business may cause the pipe communication to exceed the limit and cause memory crash and other phenomena.
[0073] Therefore, the business process does not need to send the business data to the transmission process through the IPC communication mechanism, avoiding problems such as communication out-of-memory and crash, and improving the data transmission concurrency. In addition, when reading and writing the business data in the shared memory, the embodiment of the present application also provides a parallel reading and writing method, which can greatly improve the inter-process data transmission rate and the throughput of the data transmission process.
[0074] In addition, the data transmission method provided by the embodiment of the present application can be applied to a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a smart large screen, and other electronic devices that can interact with other electronic devices. The embodiment of the present application does not make any limitation on the specific type of the electronic device.
[0075] For example, Figure 2 is a structural schematic diagram of an example electronic device 100 provided by the embodiment of the present application. Taking the electronic device 100 as a personal computer PC for example, the electronic device 100 can include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charge management module 140, a power management module 141, a battery 142, a wireless communication module 150, a display screen 160, and the like.
[0076] The processor 110 can include one or more processing units, for example: the processor 110 can 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 can be independent devices, or can be integrated in one or more processors.
[0077] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to instruction operation codes and timing signals, and complete the control of fetching and executing instructions.
[0078] The memory can 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. The memory can save instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to use the instructions or data again, it can be directly called from the memory. This avoids repeated access and reduces the waiting time of the processor 110, thus improving the efficiency of the system.
[0079] The charging management module 140 is configured to receive charging input from a charger. The charger can be a wireless charger or a wired charger. The charging management module 140 can charge the battery 142 and also supply power to the electronic device through the power management module 141.
[0080] The power management module 141 is configured to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display 160, and the wireless communication module 150, etc. In some embodiments, the power management module 141 and the charging management module 140 can also be provided in the same device.
[0081] The wireless communication module 150 can provide a solution for wireless communication including WLAN (e.g., Wi-Fi), Bluetooth, global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, and the like, which are applied on the electronic device 100. For example, in an embodiment of the present application, the electronic device 100 can establish a Bluetooth connection with a terminal device (e.g., a wireless earphone 100) through the wireless communication module 150.
[0082] The wireless communication module 150 can be one or more devices that integrate at least one communication processing module. The wireless communication module 150 receives electromagnetic waves via an antenna, frequency-modulates and filters the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 150 can also receive signals to be transmitted from the processor 110, frequency-modulate them, amplify them, and radiate them as electromagnetic waves via an antenna.
[0083] The electronic device 100 implements a display function through a GPU, a display screen 160, and an application processor, etc. The GPU is a microprocessor for image processing, which is connected to the display screen 160 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.
[0084] The display screen 160 is used to display images, videos, and the like. The display screen 160 includes a display panel.
[0085] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, music, video, and the like files are saved in the external memory card.
[0086] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 performs various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 can execute instructions stored in the internal memory 121, and the internal memory 121 can include a program storage area and a data storage area.
[0087] The storage program area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, and the like), and the like. The storage data area can store data (such as audio data, a phone book, and the like) created during use of the electronic device 100, and the like. In addition, the internal memory 121 can include a high-speed random access memory, and can further include a nonvolatile memory such as at least one of a magnetic disk storage device, a flash memory device, a universal flash storage (UFS), and the like.
[0088] It can be understood that the structure illustrated in the embodiments 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 can include more or fewer components than illustrated, or combine certain components, or split certain components, or different arrangement of components. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.
[0089] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. The embodiments of the present application take a Windows system with a layered architecture as an example to illustrate the software structure of the electronic device 100.
[0090] Figure 3 FIG. 1 is a software structure block diagram of the electronic device 100 according to an embodiment of the present application. The layered architecture divides the software into several layers, each of which has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Windows system is divided into a user state and a kernel state, the user state can include an application layer and a subsystem dynamic link library, and the kernel state can include a kernel layer.
[0091] As shown in FIG. 2, the application layer can include business applications, which include but are not limited to music, video, game, office, and the like. Figure 3
[0092] The subsystem dynamic link library can include a transmission service middleware and a transmission dynamic library. The business process corresponding to the business application can call the transmission service middleware to pull up the business transmission service. The transmission service middleware can determine whether to use a shared memory transmission scheme according to the business type and the like, that is, whether to create a shared memory, and create a shared memory and record the identifier of the shared memory, such as a shared memory file descriptor fd, in the case of creating a shared memory.
[0093] In the case where the transmission service middleware determines that a shared memory needs to be created, the transmission service middleware can send a notification message to the transmission dynamic library to pull up the client, and at the same time, the shared memory fd is transmitted. The transmission dynamic library can pull up the client and save the shared memory fd, and return a message to the transmission service middleware that the client is pulled up successfully.
[0094] In some embodiments, after the shared memory is successfully created, if a business application needs to use the shared memory to transmit data, it can write the business data into the shared memory and send a notification message to the transmission service platform via the IPC communication mechanism to notify that there is business data to be sent. At this time, the notification message only carries the notification content and does not carry the business data content. Then, the transmission service platform notifies the transmission dynamic library, which reads the business data from the shared memory, encapsulates it, and sends it to other electronic devices through the communication driver.
[0095] In some embodiments, when using parallel read / write operations to read and write business data in shared memory, after the business application writes the business data to shared memory, it no longer needs to send a notification message to the transmission service platform via IPC communication. Instead, the transmission dynamic library checks whether there is business data to be sent in shared memory. If so, it reads the business data from shared memory, encapsulates it, and sends it to other electronic devices via the communication driver. This avoids the data transmission rate limitation of IPC communication and improves data transmission performance through parallel read / write.
[0096] The kernel layer is the layer between hardware and software. At a minimum, the kernel layer includes display drivers, communication drivers, audio / video drivers, and sensor drivers. Communication drivers can include Wi-Fi drivers, Bluetooth drivers, etc., and can be used for network communication with other electronic devices; for example, they can send the aforementioned service data to other electronic devices.
[0097] In some embodiments, some electronic devices may be equipped with an Android system. If the Android system supports parallel processes, the data transmission method provided in the embodiments of this application can also be implemented.
[0098] Based on an electronic device with the aforementioned software structure, if electronic device A transmits data to electronic device B, and both electronic device A and electronic device B possess the aforementioned software structure, then the system architecture composed of electronic device A and electronic device B can be as follows: Figure 4 As shown, in this system architecture, electronic device A includes business application A, transmission service platform A, transmission dynamic library A, and communication driver A, while electronic device B includes business application B, transmission service platform B, transmission dynamic library B, and communication driver B.
[0099] The system architecture can include a service starting process and a data transmission process when implementing the data transmission method of the embodiments of the application. The service starting process can include: when a user clicks on a business application A of an electronic device A, starting a business process A, the business process A calling a transmission service middle platform A through a system interface to start a business transmission service. The transmission service middle platform A judges whether to create a shared memory, and creates the shared memory and records an identification A of the shared memory in the case of needing to create the shared memory. The transmission service middle platform A instructs a transmission dynamic library A to pull up a client and input the identification A of the shared memory, and the transmission dynamic library A saves the identification A of the shared memory after pulling up the client. The transmission dynamic library A returns a message of successfully pulling up the client to the transmission service middle platform A. The transmission service middle platform A sends a notification message of starting the business transmission service to a transmission service middle platform B of an electronic device B, the transmission service middle platform B judges whether to create a shared memory, and creates the shared memory and records an identification B of the shared memory in the case of needing to create the shared memory. The transmission service middle platform B instructs a transmission dynamic library B to pull up a server and input the identification B of the shared memory, and the transmission dynamic library B saves the identification B of the shared memory after pulling up the server. The transmission dynamic library B returns a message of successfully pulling up the server to the transmission service middle platform B. The transmission service middle platform B sends a notification message of the server being started to the transmission service middle platform A. The transmission service middle platform A notifies the business process A of the business transmission service being successfully started, and the transmission service middle platform B notifies the business process B of the business transmission service being successfully started.
[0100] The data transmission process can adopt a serialization process or a parallelization process. The serialization process can include: the business process A of the electronic device A writing business data into a shared memory, the business process A notifying the transmission service middle platform A of currently having business data to be sent through an IPC communication mechanism, and the transmission service middle platform A notifying the transmission dynamic library A of currently having business data to be sent. The transmission dynamic library A reads the business data from the shared memory, encapsulates and sends the business data to a communication driver A of a kernel layer, and the communication driver A sends the business data to the communication driver B of the electronic device B through a network. The communication driver B sends the business data to the transmission dynamic library B, the transmission dynamic library B receives the business data, writes the business data into a shared memory, and notifies the transmission service middle platform B of currently having business data to be received. The transmission service middle platform B notifies the business process B of currently having business data to be received through an IPC communication mechanism, and the business process B reads the business data from the shared memory and performs corresponding data processing. However, in the serialization process, the transmission dynamic library A needs to perform a reading operation after the business process A performs a writing operation, so that the transmission rate is relatively slow when the amount of transmission data is large.
[0101] The parallelization process can include: the business process A of the electronic device A writes the business data into the shared memory, the transmission dynamic library A detects that there is business data to be sent in the shared memory, reads the business data from the shared memory, encapsulates and then sends to the communication driver A of the kernel layer, the communication driver A sends the business data to the communication driver B of the electronic device B through the network. The communication driver B sends the business data to the transmission dynamic library B, the transmission dynamic library B receives the business data, writes the business data into the shared memory, and notifies the transmission service middle station B that there is business data to be received at present. The transmission service middle station B notifies the business process B that there is business data to be received at present through the IPC communication mechanism, and the business process B reads the business data from the shared memory and performs corresponding data processing. Alternatively, after the transmission dynamic library B writes the business data into the shared memory in the electronic device B, the business process B can also detect that there is business data to be received in the shared memory, read the business data from the shared memory and perform corresponding data processing. Wherein, the business process A and the transmission dynamic library A of the electronic device A can read and write the business data in the shared memory in parallel, for example, when the transmission dynamic library A reads the first business data, the business process A can write the next business data into the shared memory.
[0102] For better understanding, the following embodiments of the application will be described with reference to the system architecture shown in the drawings and application scenarios. Figure 4 The following embodiments are described by taking the parallelization process as an example.
[0103] Figure 5 is a time sequence flow diagram of a data transmission method provided by an embodiment of the application, taking the electronic device A sending business data to the electronic device B as an example. The method can include:
[0104] S1, the business application A receives the first operation of the user, and starts the business process A.
[0105] The first operation can be a user operation to start the business application A, or an operation to start a certain function of the business application A, for example, clicking the screen projection control to start the screen projection business process, clicking the super mouse control to start the super mouse business process, etc.
[0106] S2, the business process A instructs the transmission service middle station A to start the business transmission service.
[0107] Here, the business process A can call the transmission service interface to instruct the transmission service middleware A to start the business transmission service, for example, to start the screen projection service. In some implementations, when the business process A instructs the transmission service middleware A to start the business transmission service, the business process A can carry corresponding business information, including but not limited to the business type, the business name (or service name), the business priority, and the like. It can be understood that when the business process A instructs the transmission service middleware A to start the business transmission service, the transmission process is also started accordingly.
[0108] S3, the transmission service middleware A determines whether to create a shared memory. If the shared memory needs to be created, S4 is performed. If the shared memory does not need to be created, S34 in the following embodiment is performed.
[0109] The transmission service middleware A can determine whether to create a shared memory according to the business type and / or the business priority. In the case of determining whether to create a shared memory according to the business type, if it is a file transmission type and a screen projection type, etc., a shared memory needs to be created, because the data to be transmitted by these business types is usually large. It can also be understood that when the transmission service middleware A identifies that the transmission flow required by the current business is large according to the business type and / or the business priority, it is determined that a shared memory needs to be created, and if it is identified that the transmission flow required by the current business is small, it is determined that a shared memory does not need to be created. In some implementations, whether to create a shared memory can also be specified by the business application itself, such as a screen projection application specifying that a shared memory needs to be created.
[0110] S4, the transmission service middleware A creates a shared memory corresponding to the business process A.
[0111] In some implementations, the transmission service middleware A can apply for a region (such as a region of a specified size) in the memory space of the electronic device A through a system interface as the shared memory corresponding to the above-mentioned business process, at this time, the identification A (such as the shared memory file descriptor fd1) of the shared memory can be recorded, and through the shared memory fd1, the address of the shared memory can be found to read and write data in the shared memory corresponding to the address. It can be understood that the shared memory corresponding to the business process A created here is created in the transmission process.
[0112] It should be noted that different business processes correspond to different shared memories, for example, the identification of the business process or the identification of the business service can be associated with the storage of the shared memory fd, so that the shared memories between different businesses are independent of each other and do not have the risk of being used together.
[0113] In some implementations, after the transport service creates the shared memory of a specified size, a public header can also be created at the beginning of the shared memory. The information in the public header can include, but is not limited to, the shared memory size (also referred to as capacity), the current number of data nodes, the left writable space, the right writable space, the write pointer position offset, the read pointer position offset, and the read-write reverse pointer position offset, etc. The information in the public header can be used by the subsequent business process A and the transport dynamic library A to determine how to read and write data, such as where to write data, where to read data, etc.
[0114] In this implementation, the public header can occupy a space of M size in the shared memory, for example, M is 26 bytes. For example, as shown in FIG. 1, from the beginning of the shared memory (assuming the shared memory size size is 10MB), the first 26 bytes are the public header, and the 26 bytes of the public header can be further allocated for the contained information (shared memory size, current number of data nodes, left writable space, right writable space, write pointer position offset, read pointer position offset, and read-write reverse pointer position offset). Figure 6 Figure 6 For example, as shown in FIG. 1, the shared memory size information (size) occupies 4 bytes, the current number of data nodes information (cnt) occupies 2 bytes, the left writable space information (leftLen) occupies 4 bytes, the right writable space information (rightLen) occupies 4 bytes, the write pointer position offset information (writeOffset) occupies 4 bytes, the read pointer position offset information (readOffset) occupies 4 bytes, and the read-write reverse pointer position offset information (reverseOffset) occupies 4 bytes.
[0115] The shared memory size information (size) refers to the size of the shared memory created by the transmission service platform A. The current data node count information (cnt) refers to the number of unread data blocks in the shared memory. The current data node count is incremented by 1 each time business process A writes business data (or data packets) to the shared memory, and decremented by 1 each time the transmission process reads business data (or data packets). The initial value of the current data node count information is 0, meaning that initially, no data has been written to the shared memory. The left writable space information (leftLen) refers to the writable space to the left of the write pointer after business data (or data packets) has been accessed. Generally, the left writable space information is initialized to 0 because business data is written into the shared memory from left to right, and initially, no data has been read, so there is no writable space on the left. The right-hand writable space (rightLen) refers to the writable space to the right of the write pointer in shared memory, excluding the left-hand writable space. Generally, the right-hand writable space is initialized to the shared memory size minus the common header size; that is, when no data is being written to shared memory, the space to the right of the common header can be written to. The write pointer offset (writeOffset) indicates the starting position for the next data write, and the read pointer offset (readOffset) indicates the starting position for the next data read. Initially, both the write and read pointer offsets are equal to the common header size, meaning both pointers point to the first character position after the common header in shared memory. The reverse offset (reverseOffset) is the write pointer offset when the right-hand writable space is insufficient to continue writing data. When the read pointer offset equals the reverse offset, data needs to be read from the beginning. Initially, the reverse offset is equal to the shared memory size, meaning the reverse pointer points to the end of shared memory.
[0116] For example, such as Figure 7 The diagram illustrates an initial state of shared memory, where no business data has been written yet, hence the current data node count is 0. Both the write and read pointers point to the first character position after the common header in the shared memory, with offsets of M (e.g., 26 bytes). If business data is written, the write pointer can be shifted backward. The left writable space is 0, and the right writable space is size-M, for example, 10MB-M = 10MB-26 bytes. The read / write reversal pointer points to the end of the shared memory, with an offset of size.
[0117] S5. Transmission service platform A sends a notification message to transmission dynamic library A to start the client.
[0118] The notification message can carry the identifier A (such as the shared memory fd1) of the shared memory. The transmission service middle station A sends the notification message to the transmission dynamic library A, so as to instruct the transmission dynamic library A to pull up the client. It can be understood that the transmission service middle station A can send the notification message to the transmission dynamic library A by calling the interface of the transmission dynamic library A.
[0119] S6. The transmission dynamic library A pulls up the client and saves the identifier A of the shared memory.
[0120] S7. The transmission dynamic library A returns a success message of pulling up the client to the transmission service middle station A.
[0121] After receiving the notification message sent by the transmission service middle station A, the transmission dynamic library A can pull up the client and save the identifier A (such as the shared memory fd1) of the shared memory created above. Then the transmission dynamic library A can also return a message to the transmission service middle station A that the client has been successfully pulled up.
[0122] S8. The transmission service middle station A of the electronic device A sends a request of starting the business transmission service to the transmission service middle station B of the electronic device B.
[0123] That is to say, after the electronic device A side starts the business service and creates the shared memory, the electronic device A sends a request to the electronic device B, requesting the electronic device B to also start the business transmission service and create the shared memory and pull up the corresponding server.
[0124] In some implementations, the request sent by the transmission service middle station A to the transmission service middle station B can carry the identifier of the business transmission service, the device identifier of the electronic device A and the identifier of whether to use the shared memory. The identifier of whether to use the shared memory can be represented by an int parameter, for example, 1 represents using the shared memory and 0 represents not using the shared memory. In the case of identifier 1, the electronic device B will also create the shared memory after receiving the request. Therefore, 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, so as to achieve the purpose of not exceeding the memory when multiple businesses are concurrently implemented on both sides of the electronic devices.
[0125] S9. The transmission service middle station B determines whether to create the shared memory. If the shared memory needs to be created, S10 is performed. If the shared memory does not need to be created, S40 in the following embodiment is performed.
[0126] That is, the transmission service middle station B can determine whether to create the shared memory according to the identifier of whether to use the shared memory in the request. For example, in the case of identifier 1, the electronic device B needs to create the shared memory.
[0127] S10, the transmission service middle station B creates a shared memory corresponding to the service process B.
[0128] In some implementations, the transmission service middle station B can apply a region to the memory space of the electronic device B through the 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 the execution of the service initiated by the electronic device A. At this time, the identification B (such as the shared memory file descriptor fd2) of the shared memory can be recorded, and the address of the shared memory can be found through the shared memory fd2 to read and write data in the shared memory corresponding to the address. It can be understood that the shared memory corresponding to the service process B created here is created in the transmission process.
[0129] The transmission service middle station B can create the shared memory in the manner described above with reference to the process of creating the shared memory by the transmission service middle station A, that is, a common header can also be created at the beginning of the shared memory to record various information of the shared memory, which will not be described here.
[0130] S11, the transmission service middle station B sends a notification message to the transmission dynamic library B to pull up the service end.
[0131] The notification message can carry the identification B (such as the shared memory fd2) of the shared memory, and the transmission service middle station B sends the notification message to the transmission dynamic library B to instruct the transmission dynamic library B to pull up the service end.
[0132] S12, the transmission dynamic library B pulls up the service end and saves the identification B of the shared memory.
[0133] S13, the transmission dynamic library B returns a success message of pulling up the service end to the transmission service middle station B.
[0134] After receiving the notification message sent by the transmission service middle station B, the transmission dynamic library B can pull up the service end and save the identification B (such as the shared memory fd2) of the shared memory created above. Then, the transmission dynamic library B can also return a message to the transmission service middle station B that the service end has been successfully pulled up.
[0135] S14, the transmission service middle station B of the electronic device B sends a message to the transmission service middle station A of the electronic device A that the service transmission service has been started successfully.
[0136] That is, after the electronic device B side starts the service transmission service and creates the shared memory, it sends a message to the electronic device A that the service transmission service has been started successfully, notifying the electronic device A to perform the next operation.
[0137] S15, the transmission service middle station A notifies the service process A that the service transmission service has been started successfully.
[0138] S16, the service process A converts to obtain the shared memory identifier A', and the service transmission service is started successfully.
[0139] In the transmission service middle station A, when the service transmission service is started successfully, the shared memory identifier A (such as shared memory fd1) can be carried. After the service process A receives the notification, the shared memory identifier A can be converted to create the shared memory identifier A' (such as shared memory fd1') that can be recognized by the service process A. The shared memory identifier A and the shared memory identifier A' correspond to the same shared memory, that is, the shared memory created by the transmission service middle station A. Thus, the shared memory on the electronic device A side is created successfully, and the service transmission service is started successfully.
[0140] S17, the transmission service middle station B notifies the service process B that the service transmission service is started successfully.
[0141] S18, the service process B converts to obtain the shared memory identifier B', and the service transmission service is started successfully.
[0142] In the transmission service middle station B, when the service transmission service is started successfully, the shared memory identifier B (such as shared memory fd2) can be carried. After the service process B receives the notification, the shared memory identifier B can be converted to create the shared memory identifier B' (such as shared memory fd2') that can be recognized by the service process B. The shared memory identifier B and the shared memory identifier B' correspond to the same shared memory, that is, the shared memory created by the transmission service middle station B. Thus, the shared memory on the electronic device B side is created successfully, and the service transmission service is started successfully.
[0143] After the service transmission service of the electronic device A and the electronic device B are both started successfully, the electronic device A can perform data transmission to the electronic device B, and the specific process can be as follows:
[0144] S19, the service process A writes the service data into the shared memory.
[0145] That is to say, when the electronic device A transmits the service data to the electronic device B, the service process A in the electronic device A can write the to-be-sent service data into the shared memory created above. The service process A can find the address of the shared memory through the shared memory identifier A' obtained by the conversion, and then write the service data into the shared memory.
[0146] In some implementations, when the business process A writes the business data into the shared memory, the business process A can determine whether the current write operation can be performed according to the information of the common header in the shared memory. Since the left writable space information and the right writable space information are included in the common header, if it is determined through the left writable space information that the left writable space is sufficient for writing the current business data, or it is determined through the right writable space information that the right writable space is sufficient for writing the current business data, the business process A can write the business data into the shared memory.
[0147] S20, the transmission dynamic library A detects that there is business data to be sent in the shared memory.
[0148] In the process of writing the business data into the shared memory by the business process A, the transmission dynamic library A can perform real-time detection to detect whether there is business data to be sent in the shared memory, so as to facilitate the subsequent data transmission process. It should be noted that the business process A does not need to send the business data to the transmission service middle station A and the transmission dynamic library A through the IPC communication mechanism, nor does it need to send any notification message, etc., thereby avoiding the problems of communication out-of-memory, crash, etc. caused by the IPC communication limitation.
[0149] In some implementations, when the transmission dynamic library A detects whether there is business data to be sent in the shared memory, the transmission dynamic library A can determine whether there is business data to be sent according to the information of the common header in the shared memory. If it is determined according to the write pointer position offset information and the read pointer position offset information that the read pointer position offset is not equal to the write pointer position offset (i.e., there is unread business data), or it is determined according to the current data node number information that the current data node number is not 0, the transmission dynamic library A can determine that there is business data to be sent in the shared memory.
[0150] S21, the transmission dynamic library A reads the business data from the shared memory.
[0151] S22, the transmission dynamic library A sends the business data to the transmission dynamic library B of the electronic device B.
[0152] 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 business data from the shared memory. Then the transmission dynamic library A can send the business data to the communication driver A in the kernel layer, the communication driver A sends the business data to the communication driver B of the electronic device B through the network, and the communication driver B sends the business data to the transmission dynamic library B.
[0153] In some implementations, if multiple services are concurrently executed at present and all of them need to transmit service data, different service processes correspond to different shared memories, for example, the identification of a service process or the identification of a service service can correspond to a shared memory fd, then the transmission dynamic library A can find the corresponding shared memory fd according to the identification of each service process or the identification of a service service, and then find the corresponding shared memory according to the shared memory fd to read the corresponding service data, thereby avoiding the risk of service data being used in series.
[0154] In some implementations, if multiple services are concurrently executed at present and all of them need to transmit service data, different service processes correspond to different shared memories, for example, the identification of a service process or the identification of a service service can correspond to a shared memory fd, then the transmission dynamic library A can find the corresponding shared memory fd according to the identification of each service process or the identification of a service service, and then find the corresponding shared memory according to the shared memory fd to read the corresponding service data, thereby avoiding the risk of service data being used in series. Figure 8
[0155] Next, in S21, the transmission dynamic library A reads the service data from the shared memory, and first reads the message length (length'), for example, 4 bytes of 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 from the shared memory at a position offset by 4 bytes after the message length. If length' is not equal to length, it means that the message verification fails, and the transmission dynamic library A will not read the service data, that is, the data transmission fails. In this way, the accuracy in the data transmission process can be improved.
[0156] S23, the transmission dynamic library B writes the service data into the shared memory.
[0157] After receiving the service data, the transmission dynamic library B can find the address of the shared memory according to the saved identification B of the shared memory, and write the service data into the shared memory.
[0158] S24, the service process B detects that there is service data to be received in the shared memory.
[0159] In the process that the transmission dynamic library B of the electronic device B writes the service data into the shared memory, the service process B can perform real-time detection to detect whether there is service data to be received in the shared memory, and if there is service data to be received, read the service data from the shared memory. The service process B can also determine whether there is service data to be received according to the information in the common header in the shared memory.
[0160] In some implementations, after the transmission dynamic library B writes the service data into the shared memory, the transmission service platform B can also be notified that there is service data to be received, and the transmission service platform B further notifies the service process B that there is service data to be received through the IPC communication mechanism. It should be noted that when the transmission service platform B notifies the service process B through the IPC communication mechanism, the notification message sent by the transmission service platform B can only carry the notification content, and does not carry the service data content, that is, the size of the data sent at a time is reduced, and problems such as communication out-of-memory and crash are avoided.
[0161] S25, the service process B reads the service data from the shared memory and performs corresponding data processing.
[0162] The service process B in the electronic device B can read the service data from the shared memory and perform processing, for example, decoding and displaying the screen projection service data. The service process B can find the address of the shared memory through the identifier B' of the shared memory obtained by the conversion, and then read the service data from the shared memory.
[0163] It can be understood that the above is a data transmission process described by taking one service process as an example. If multiple services are concurrent, multiple shared memories can be created corresponding to the multiple services, and each service corresponds to a shared memory. When each service transmits service data, the service data can be written into the shared memory corresponding to the service, and then the transmission process reads the service data from the corresponding shared memory and transmits the service data to the opposite electronic device. Thus, in the multiple-service concurrent scenario, the data is read and written through the shared memory, and the service data no longer needs to be transmitted through the IPC communication mechanism, which can break through the data limitation bottleneck of the IPC communication mechanism.
[0164] It can also be understood that after the business process A writes the first business data into the shared memory, the transmission dynamic library A can read the first business data from the shared memory, and at the same time, the business process can write the second business data, the third business data into the shared memory, and the transmission dynamic library A can continue to read the second business data, the third business data from the shared memory at the same time, that is, the writing operation of the business process A and the reading operation of the transmission dynamic library A can be executed in parallel, as long as there is unread business data in the shared memory, the transmission dynamic library A can read, as long as there is space in the shared memory for business data to be written, the business process A can write, that is, the business process A does not have to wait for the transmission dynamic library A to read the data before writing, and the read business data can be deleted in time to release space for subsequent business data writing. Thus, the throughput of the data transmission process is greatly improved.
[0165] The above data transmission method, the electronic device creates a shared memory when the business data traffic is large, so that each business process corresponds to a shared memory, and after the business process writes the business data into the shared memory, the transmission process can detect the existence of the business data to be sent in the shared memory and read the business data to send the business data to other electronic devices. In the data transmission process, the business process and the transmission process no longer communicate with each other through IPC, solving the limitation of the size of the transmitted data when communicating through IPC, avoiding communication out of memory, crash and other problems, and improving the data transmission concurrency. In addition, the business process and the transmission process can read and write business data to the shared memory in parallel, improving the rate and throughput of the data transmission process and improving the data transmission performance in a multi-service concurrent scenario.
[0166] For the parallel execution process of the writing operation of the business process A into the shared memory and the reading operation of the transmission dynamic library A from the shared memory in the above embodiment, if the space in the shared memory is fixed, if the cyclic reuse is to be realized, the shared memory needs to be reasonably managed and controlled to ensure the normal execution of the parallel reading and writing process.
[0167] As described above, the shared memory has a common header. This header records information such as the shared memory size, the current number of data nodes, the left writable space, the right writable space, the write pointer offset, the read pointer offset, and the read-write inversion pointer offset. Using this information, business process A can determine where to write business data, and the transmission dynamic library A can determine where to read business data. Generally, the write and read pointers move from the head to the tail of the shared memory (e.g., from left to right). However, if the left writable space in the shared memory is insufficient to write the next piece of business data, the write pointer needs to be moved to the right writable space to write the data. Similarly, if there is no business data to read after the read pointer position, the read pointer needs to be moved to the unread position to read the data. Therefore, this embodiment can control the write pointer offset, read pointer offset, and read-write inversion pointer offset to ensure that business process A successfully writes business data and the transmission dynamic library A successfully reads business data.
[0168] In some embodiments, when the amount of business data written to shared memory by business process A is relatively small, the remaining space in shared memory is ample. In this case, the writable space on the right side of shared memory can support business process A to continue writing business data. The write pointer continues to move from left to right, while the read pointer also moves from left to right to read business data. However, the offset of the read pointer position must be less than or equal to the offset of the write pointer position to ensure that business data is written before it is read. It can be understood that as the transport dynamic library A reads data from shared memory, the read pointer moves to the right, the space occupied by the read business data is released, and the writable space on the left side gradually increases. It can also be understood that at this time, the read / write inversion pointer still points to the end of shared memory.
[0169] For example, such as Figure 9 As shown, the read pointer position is shifted to the position before data 1, indicating that data 1 is about to be read. The write pointer position is shifted to the position after datak, indicating that data is about to be written after datak. At this time, there is still 2MB of writable space on the right and 4MB of writable space on the left that has been freed up. The read / write inversion pointer points to the end of the shared memory.
[0170] If business process A writes business data (occupying one node length) to shared memory, the current data node count (cnt) will increment by 1, the write pointer offset (writeOffset) will increment by one node length (i.e., the write pointer moves one node length to the right), and the right writable space (rightLen) will decrease by one node length. If transport dynamic library A reads business data (occupying one node length) from shared memory, the current data node count (cnt) will decrement by 1, the read pointer offset (writeOffset) will increment by one node length (i.e., the read pointer moves one node length to the right), and after the space is released, the left writable space (leftLen) will increment by one node length. Here, the byte length can be the message length plus the message content in bytes. It can be understood that all these changes will be synchronously updated in the shared memory's common header information.
[0171] In this embodiment, since the read pointer position offset is less than or equal to the write pointer position offset, in some scenarios, if the transmission dynamic library A reads business data relatively quickly, causing the read pointer position offset to be equal to the write pointer offset, but no new business data has been written, then there is no new business data to read after the read pointer. At this time, electronic device A can instruct transmission dynamic library A to stop reading business data and wait for new business data to be written before reading data again.
[0172] In other embodiments, as business process A writes more and more business data into the shared memory, the write pointer continues to move to the right and is about to reach the end of the shared memory. In this case, the right writable space of the shared memory may not be enough to write the next business data, but the left writable space will be freed up because business data has been read, so that business data can be written. At this time, it is necessary to reverse the write pointer to the position of the left writable space in order to write business data into the left writable space.
[0173] For example, such as Figure 10 As shown, the read pointer position is shifted to the position before data 1, indicating that data 1 is about to be read. The write pointer position is shifted to the position after datak, indicating that data is about to be written after datak. At this time, there are still 10KB of writable space remaining on the right, which is insufficient to write the next business data. The writable space on the left that has been released is 6MB. The read / write inversion pointer points to the end of the shared memory.
[0174] At this time, since the right writable space is not enough to write the next service data, the write pointer needs to be reversed to the position of the left writable space. In some implementable manners, the write pointer can be reversed to the position after the common header of the shared memory, i.e., the position of the write pointer at the beginning, and the write pointer position offset (writeOffset) is the size of the common header (for example, M=26 bytes). Since the remaining 10 KB space of the right writable space is not written with data, the position of the insufficient space to write (i.e., the position before the write pointer is reversed) needs to be recorded, and therefore, the read-write reversal pointer can be moved to the position of the insufficient space to write for recording, i.e., the read-write reversal pointer position offset is (the size of the shared memory (size)-10 KB). In other implementable manners, the read-write reversal pointer position offset can be first assigned as the write pointer position offset when the insufficient space to write the next service data, and then the write pointer position offset is assigned as the size of the common header. It can be understood that if the subsequent read pointer moves to the position of the read-write reversal pointer, there is no service data to read behind, and the read pointer also needs to be reversed and start reading the service data from the beginning.
[0175] After the write pointer is reversed, the write pointer position offset is smaller than the read pointer position offset, and the service process A can write service data to the left writable space. During the process of writing data, the write pointer continues to move from left to right, and the read pointer also moves from left to right to read the remaining service data.
[0176] Exemplarily, as shown in Figure 11 , the read pointer position offset is to the position before data 1, i.e., data 1 is about to be read, and the write pointer position offset is to the position after data k, i.e., data is about to be written after data k. At this time, since the write pointer has been reversed, the left writable space is full of data, i.e., the left writable space is 0, the right writable space still has (the size of the shared memory (size)-the size of the written service data), and the read-write reversal pointer points to the position of the insufficient space to write the next service data. It can be understood that in the initial stage of the write pointer reversal, the right writable space should be assigned as the size of the original left writable space (i.e., as shown in Figure 10 ).
[0177] At this time, if the service process A writes a service data (occupying a node length) into the shared memory, the current data node number (cnt) is increased by 1, the write pointer position offset (writeOffset) is increased by a node length, that is, the write pointer moves right by a node length, the left writable space (leftLen) is 0, and the right writable space (rightLen) is reduced by a node length. If the transmission dynamic library A reads a service data (occupying a node length) from the shared memory, the current data node number (cnt) is reduced by 1, the read pointer position offset (writeOffset) is increased by a node length, that is, the read pointer moves right by a node length, and the right writable space (leftLen) is increased by a node length after the space is released. Here, the node length can be the message length (length) + the byte length of the message content. It can be understood that the changes of the above information are synchronously updated to the public header information in the shared memory. It can also be understood that if the read pointer position offset is equal to the read-write reverse pointer position offset at a certain moment, that is, there is no service data to be read behind the read pointer, the read pointer can be reversed to a position after the public header to continue reading data, at this time, the read pointer position offset is less than the write pointer position offset, that is, it enters the above-mentioned "the remaining space in the shared memory is relatively sufficient" scenario, and the parallel reading and writing process of the service process and the transmission process is realized through repeated operations.
[0178] In this embodiment, because the write pointer position offset is less than the read pointer position offset, in some scenarios, if the writing speed of the service process A is relatively fast, the write pointer position offset has been equal to the read pointer offset (or the right writable space of the write pointer is not enough to write the next service data), and if the service process A continues to write service data, the new service data will cover the previously unread service data, which will cause the transmission dynamic library A to read errors. At this time, the electronic device A can instruct the service process A to stop writing service data, and wait until the right writable space is enough to write the next service data before writing.
[0179] It should be noted that the above reading and writing operations of the shared memory are realized without locking, that is, the reading and writing of the service data are not locked, so as to avoid affecting the parallel reading and writing process. The process of the transmission process B in the electronic device B writing data into the shared memory and the process of the service process B reading data from the shared memory can also be referred to the description of this embodiment, which will not be described here.
[0180] Through the above control of the reading and writing pointers in the shared memory, it can be ensured that the service process and the transmission process successfully read and write during the reading and writing operation process, so as to improve the throughput of the data transmission process.
[0181] The above embodiment describes a scenario of creating shared memory when the service data traffic is large. If the S3 transmission service station A judges that shared memory does not need to be created, shared memory can no longer be created. The data transmission process in this scenario can be as shown in the following embodiment. Figure 12 is another example of a time sequence flow diagram of a data transmission method provided by the embodiment of the application, which can specifically include:
[0182] S31, the service application A receives the first operation of the user, and starts the service process A.
[0183] S32, the service process A instructs the transmission service station A to start the service transmission service.
[0184] The processes of S31-S32 can be referred to the above S1-S2, which will not be described here.
[0185] S33, the transmission service station A judges whether shared memory needs to be created. If shared memory does not need to be created, S34 is executed. If shared memory needs to be created, S4 in the above embodiment is executed.
[0186] The transmission service station A can judge whether shared memory needs to be created according to the service type and / or service priority. In the case of judging whether shared memory needs to be created according to the service type, if it is not a file transmission type and a screen projection type, shared memory does not need to be created, because the data to be transmitted by these service types is usually large, and the data to be transmitted by other service types is small. It can also be understood that when the transmission service station A identifies that the current service needs to transmit a small amount of traffic according to the service type and / or service priority, it is determined that shared memory does not need to be created. In some implementations, whether shared memory needs to be created can also be specified by the service application itself.
[0187] S34, the transmission service station A performs service transmission service initialization.
[0188] S35, the transmission service station A sends a notification message of pulling up the client to the transmission dynamic library A.
[0189] The notification message can carry the identifier of the service transmission service to notify the transmission dynamic library A to pull up the client of the corresponding service.
[0190] S36, the transmission dynamic library A pulls up the client.
[0191] S37, the transmission dynamic library A returns a success message of pulling up the client to the transmission service station A.
[0192] The transmission dynamic library A receives the notification message sent by the transmission service middle station A in the transmission service, and can pull up the client. Then, the transmission dynamic library A can also return a message to the transmission service middle station A that the client has been successfully pulled up.
[0193] S38, the transmission service middle station A of the electronic device A sends a request for starting the business transmission service to the transmission service middle station B of the electronic device B.
[0194] That is, after the business service on the electronic device A side is started, a request is sent to the electronic device B, requesting the electronic device B to also start the business transmission service and pull up the corresponding service end.
[0195] In some implementations, the request sent by the transmission service middle station A to the transmission service middle station B can carry the identification of the business transmission service, the device identification of the electronic device A, and the identification of whether to use shared memory, etc. The identification of whether to use shared memory can be represented by an int parameter, for example, 1 represents using shared memory, and 0 represents not using shared memory. In the case of identification 0, the electronic device B does not create shared memory after receiving the request.
[0196] S39, the transmission service middle station B judges whether shared memory needs to be created. If shared memory does not need to be created, S40 is executed, and if shared memory needs to be created, S10 in the above embodiment is executed.
[0197] That is, the transmission service middle station B can determine whether shared memory needs to be created according to the identification of whether to use shared memory in the above request.
[0198] S40, the transmission service middle station B performs business transmission service initialization.
[0199] S41, the transmission service middle station B sends a notification message for pulling up the service end to the transmission dynamic library B.
[0200] The notification message can carry the identification of the business transmission service to notify the transmission dynamic library B to pull up the service end of the corresponding service.
[0201] S42, the transmission dynamic library B pulls up the service end.
[0202] S43, the transmission dynamic library B returns a success message for pulling up the service end to the transmission service middle station B.
[0203] The transmission dynamic library B receives the notification message sent by the transmission service middle station B, and can pull up the service end. Then, the transmission dynamic library B can also return a message to the transmission service middle station B that the service end has been successfully pulled up.
[0204] S44, the transmission service middle station B of the electronic device B sends a message that the business transmission service is started successfully to the transmission service middle station A of the electronic device A.
[0205] That is, after the electronic device B side starts the service transmission service, a message of successful start is sent to the electronic device A, and the electronic device A is notified to perform the next step.
[0206] S45, the transmission service middleware A notifies the service process A that the service transmission service is successfully started.
[0207] S46, the transmission service middleware B notifies the service process B that the service transmission service is successfully started.
[0208] After the service transmission services of the electronic device A and the electronic device B are both successfully started, the electronic device A can perform data transmission to the electronic device B, and the specific process can be as follows:
[0209] S47, the service process A acquires service data.
[0210] The service process A can acquire service data to be sent to the electronic device B, such as screen projection data in a screen projection service.
[0211] S48, the service process A notifies the transmission service middleware A that there is service data to be sent at present through an IPC communication mechanism.
[0212] S49, the transmission service middleware A notifies the transmission dynamic library A that there is service data to be sent at present.
[0213] After the service process A acquires the service data, the transmission service middleware A can be notified that there is service data to be sent at present, so that the transmission process transmits 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 carries the content of the service data.
[0214] S50, the transmission dynamic library A reads the notified service data.
[0215] S51, the transmission dynamic library A sends the service data to the transmission dynamic library B of the electronic device B.
[0216] That is, when the transmission dynamic library A receives the notification message of the transmission service middleware A, the service data carried in the notification message can be read and sent to the transmission dynamic library B of the electronic device B.
[0217] In some implementations, the business process can also use a data format of message length + message content when sending the business data to ensure the accuracy of reading the data. 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. In S48, the business process A notifies the transmission service platform A that there is business data to be sent by using the IPC communication mechanism. The notification message can carry the message length (length) and the business data. Then, when the transmission dynamic library A reads the business data in the notification message, the message length (length') can also be read first. If length' is equal to length, it means that the message verification is successful, and the transmission dynamic library A can transmit the business data. If length' is not equal to length, it means that the message verification fails, and the transmission dynamic library A will not transmit the business data.
[0218] S52, the transmission dynamic library B receives and parses the business data.
[0219] S53, the transmission dynamic library B notifies the transmission service platform B that there is business data to be received.
[0220] S54, the transmission service platform B notifies the business process B that there is business data to be received by using the IPC communication mechanism.
[0221] After the transmission dynamic library B receives the business data, it is transmitted to the business process B by the transmission service platform B through the IPC communication mechanism. At this time, the notification message sent also carries the business data.
[0222] S55, the business process B performs corresponding data processing on the business data in the notification.
[0223] The business process B in the electronic device B can process the business data in the notification message, for example, decode and display the screen projection business data.
[0224] The above data transmission method can determine the size of the business data flow when the electronic device transmits data, create shared memory when the business data flow is large, and not create shared memory when the business data flow is small, so as to improve the adaptability of the data transmission process.
[0225] For the data transmission method provided by the above embodiment, we also compare the performance of the two scenarios of creating shared memory and not creating shared memory, as follows: Figure 13As shown in the figure, the abscissa represents the data amount transmitted by the service process each time, the data amount written into the shared memory each time if the shared memory is created, or the data amount transmitted to the transmission process each time if the shared memory is not created, and the ordinate represents the transmission rate, in units of MB / s. Curve 1 is the performance curve when the shared memory is created, and curve 2 is the performance curve when the shared memory is not created. As can be seen, when the shared memory is created, even if the data amount transmitted by the service process each time is large (such as greater than 1 MB), a high transmission rate can still be maintained; when the shared memory is not created, when the data amount transmitted by the service process is large, the transmission rate is close to 0, that is, the phenomenon of out-of-memory or memory crash may have occurred. Therefore, it can be known through performance comparison that the data transmission performance when the shared memory is created is obviously higher.
[0226] The above describes an example of the data transmission method provided by the embodiments of the present application in detail. It can be understood that, in order to implement the above functions, the electronic device comprises hardware and / or software modules corresponding to the functions. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of the examples described in the embodiments disclosed in the present application, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is implemented in the form 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 functions for each specific application in combination with the embodiments, but such implementation should not be considered beyond the scope of the present application.
[0227] The embodiments of the present application can divide the functional modules of the electronic device according to the above method examples. For example, each functional module such as a detection unit, a processing unit, and a display unit can be divided according to each function, or two or more functions can be integrated in one module. The integrated module can be implemented in the form of hardware or a software functional module. It should be noted that the division of the modules in the embodiments of the present application is illustrative, and is only a logical function division. Actual implementation can have another division manner.
[0228] It should be noted that all related contents of each step involved in the above method embodiments can be cited to the function description of the corresponding functional module, which will not be repeated here.
[0229] The electronic device provided by the embodiments of the present application is used to execute the above data transmission method, and thus can achieve the same effect as the above implementation method.
[0230] In the case of employing the integrated unit, the electronic device can further include a processing module, a storage module and a communication module. 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 the storage of program codes and data, etc. The communication module can be used to support the communication between the electronic device and other devices.
[0231] 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. The processor can also be a combination of computing functions, such as a combination of one or more microprocessors, a combination of digital signal processors (DSP) and microprocessors, etc. The storage module can be a memory. The communication module can be a device for interacting with other electronic devices, such as a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, etc.
[0232] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in the embodiment can be a device with the structure shown in the figure. Figure 2
[0233] The embodiment of the present application also provides a computer readable storage medium, and the computer readable storage medium stores a computer program. When the computer program is executed by a processor, the processor executes the data transmission method of any one of the above embodiments. The storage medium can include a U disk, a mobile hard disk, a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various storage program codes.
[0234] The embodiment of the present application also provides a computer program product, which, when running on a computer, causes the computer to execute the related steps to realize the data transmission method in the above embodiment.
[0235] In addition, the embodiment of the present application also provides an apparatus, which can be a chip, a component or a module. The apparatus can include a processor and a memory connected to each other. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to make the chip execute the data transmission method in the above method embodiments.
[0236] The electronic device, the computer readable storage medium, the computer program product or the chip provided in the embodiment can be used to execute the corresponding method provided above, and thus the beneficial effects achieved thereby can refer to the beneficial effects of the corresponding method provided above, which will not be described here.
[0237] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity of description, only the division of the above functional modules is exemplified, and in actual application, the above functions can be completed by 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.
[0238] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0239] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A data transmission method, the method being applied on a first electronic device, characterized in that, The first electronic device and a second electronic device are in communication connection, and the method comprises: When a plurality of service processes in the first electronic device have service data to be sent to the second electronic device, writing, by a first service process in the first electronic device, the service data to be sent into a first shared memory, wherein the service processes of different service applications correspond to different shared memories, the first service process is any one of the plurality of service processes, and the first service process corresponds to the first shared memory; Detecting, by a first transmission process in the first electronic device, that the first shared memory has service data to be sent, reading the service data to be sent from the first shared memory, and sending the service data to be sent to the second electronic device, wherein, in the case of a plurality of groups of service data to be sent, the first service process writes service data to be sent into the first shared memory in parallel with the first transmission process reading service data to be sent from the first shared memory; Deleting the read service data to be sent from the first shared memory.
2. The method of claim 1, wherein, A public header is created at a starting position of the first shared memory, and information in the public header at least includes size information of the first shared memory, current data node number information in the first shared memory, write pointer position offset information, read pointer position offset information, left part writeable space information of the write pointer, right part writeable space information of the write pointer, and read-write reversal pointer position offset information.
3. The method of claim 2, wherein, The writing, by the first service process in the first electronic device, of the service data to be sent into the first shared memory comprises: If it is determined according to the left part writeable space information of the write pointer that the left part writeable space is sufficient to write the service data to be sent, and / or it is determined according to the right part writeable space information of the write pointer that the right part writeable space is sufficient to write the service data to be sent, then the first service process writes the service data to be sent into the first shared memory.
4. The method of claim 3, wherein, The writing, by the first service process in the first electronic device, of the service data to be sent into the first shared memory comprises: If the left part writeable space is not sufficient to write the service data to be sent, and the right part writeable space is sufficient to write the service data to be sent, then the first service process writes the service data to be sent into the first shared memory at a position pointed to by the write pointer; If the left part writeable space is sufficient to write the service data to be sent, and the right part writeable space is also sufficient to write the service data to be sent, then the first service process writes the service data to be sent into the first shared memory at the position pointed to by the write pointer; if the left writable space is enough to write the to-be-sent service data and the right writable space is not enough to write the to-be-sent service data, reversely moving the write pointer from a first position to a second position, the first position being a position pointed to by the write pointer when the right writable space is not enough to write the to-be-sent service data, and the second position being a position after the common header, and writing, by the first service process, the to-be-sent service data into the second position.
5. The method of claim 4, wherein, After the reversely moving the write pointer from the first position to the second position, the method further comprises: updating the read-write reverse pointer position offset information to offset information corresponding to the first position.
6. The method according to any one of claims 2 to 5, characterized in that, The detecting, by the first transmission process in the first electronic device, that there is to-be-sent service data in the first shared memory comprises: if the first transmission process determines, according to the write pointer position offset information and the read pointer position offset information, that the write pointer position offset is not equal to the read pointer position offset, and / or determines, according to the current data node number information, that the current data node number is not 0, then it is determined that there is to-be-sent service data in the first shared memory.
7. The method of claim 6, wherein, The reading, by the first transmission process, the to-be-sent service data from the first shared memory comprises: determining, according to the read pointer position offset information, a position pointed to by a read pointer in the first shared memory, and reading, by the first transmission process, the to-be-sent service data from the position pointed to by the read pointer.
8. The method of claim 7, wherein, The reading, by the first transmission process, the to-be-sent service data from the position pointed to by the read pointer comprises: in a case where the read pointer position offset information is different from the read-write reverse pointer position offset information, reading, by the first transmission process, the to-be-sent service data from the position pointed to by the read pointer; in a case where the read pointer position offset information is the same as the read-write reverse pointer position offset information, reversely moving the read pointer from a third position to a second position, the third position being a position pointed to by a read-write reverse pointer, and reading, by the first transmission process, the to-be-sent service data from the second position.
9. The method of claim 1, wherein, Before the writing, by the first service process in the first electronic device, the to-be-sent service data into the first shared memory, the method further comprises: 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 in a case where it is determined that the shared memory needs to be created.
10. The method of claim 9, wherein, The determining, by the first transmission process, whether the shared memory needs to be created comprises: determining, by the first transmission process, whether the shared memory needs to be created according to service information corresponding to the first service process, the service information comprising a service type and / or a service priority.
11. The method of claim 10, wherein, The determining, by the first transmission process, whether the shared memory needs to be created according to the service information corresponding to the first service process comprises: in a case where the service type is a file transmission type or a screen projection type, it is determined that the shared memory needs to be created; In a case where the service type is not the file transmission type or the screen projection type, it is determined that the shared memory does not need to be created.
12. The method according to any one of claims 9 to 11, characterized in that, In a case where it is determined that the 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, and the request message carries an identifier of whether the shared memory is created.
13. The method of claim 1, wherein, The first service process in the first electronic device writes the to-be-sent service data into the first shared memory, including: The first service process writes the to-be-sent service data and a message length corresponding to the to-be-sent service data into the first shared memory.
14. The method of claim 13, wherein, The first service process reads the to-be-sent service data from the first shared memory, including: The first service process reads a first message length from the first shared memory, and if the read first message length is equal to the message length corresponding to the to-be-sent service data written, reads the to-be-sent service data from the first shared memory.
15. The method of claim 1, wherein, The first electronic device includes a transmission service platform and a transmission dynamic library, and before the first service process in the first electronic device writes the to-be-sent service data into the first shared memory, the method further includes: The first service process instructs the transmission service platform to start a service transmission service, and when the transmission service platform starts the service transmission service, the first transmission process is pulled up; The transmission service platform determines whether the shared memory needs to be created, and in a case where it is determined that the shared memory needs to be created, the first shared memory corresponding to the first service process is created; The transmission service platform notifies the transmission dynamic library to pull up a client, and when the transmission dynamic library pulls up the client, an identifier of the first shared memory is saved.
16. A data transmission method, said method being applied to a second electronic device, characterized in that, The first electronic device and the second electronic device are in communication connection, and the method includes: A second transmission process in the second electronic device receives service data from the first electronic device and writes the service data into a second shared memory; A second service process in the second electronic device detects that there is to-be-received service data in the second shared memory, reads the to-be-received service data from the second shared memory, and processes the to-be-received service data, wherein in a case where there are multiple groups of to-be-received service data, the second transmission process writes service data into the second shared memory in parallel with the second service process reading service data from the second shared memory; The to-be-received service data that has been read is deleted from the second shared memory.
17. The method of claim 16, wherein, Before the service data is written into the second shared memory, the method further includes: The second transmission process receives a request message from the first electronic device, determines whether the shared memory needs to be created according to the request message, and in a case where it is determined that the shared memory needs to be created, creates the second shared memory, and the request message carries an identifier of whether the shared memory is created.
18. An electronic device, comprising: including: 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 of any one of claims 1-15, or perform the method of any one of claims 16-17.
19. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the method of any one of claims 1-15, or perform the method of any one of claims 16-17.
Citation Information
Patent Citations
Data transmission method and electronic equipment
CN120256155A