Disclosure of Invention
In view of the above, an object of the present invention is to provide a method, an apparatus and a device for Miracast message processing based on an inheritable state machine, so as to improve the above problems.
The embodiment of the invention provides a Miracast message processing method based on an inheritable state machine, which comprises the following steps:
when detecting that screen projection equipment is accessed, establishing virtual equipment for the screen projection equipment, and distributing a state machine for the virtual equipment; the state machine comprises a plurality of states at different levels, and inheritance relationships exist among the states at different levels;
acquiring an execution action of the screen projection equipment, and triggering the state machine to enter a corresponding state according to the execution action;
receiving a message to be processed, and judging whether the message needs to be processed or not according to the message to be processed and the current state;
and when the message is judged to need to be processed, acquiring a state corresponding to the message from the current state and a parent state inherited from the current state, and processing the message in the corresponding state.
Preferably, the method further comprises the following steps:
discarding the message when it is determined that the message does not need to be processed.
Preferably, the state corresponding to the message is obtained through a preset message-state mapping table.
Preferably, the state machine comprises:
a default state at a first level;
a P2P connection state and a P2P connection state at a second level, the P2P connection state and P2P connection state both inherit the default state;
an authentication state, an IP acquisition state, an IP valid state, an IP invalid state and a disconnection waiting state which are positioned at the third level and inherit from the connection state of the P2P;
a WFD valid state at a fourth level that inherits the IP valid state;
and the RTSP state, the WFD on state and the cleaning state which are inherited from the WFD effective state and are positioned in the fourth layer level.
Preferably, the method further comprises the following steps:
upon entering and leaving a predetermined state of the state machine, an operation corresponding to the state is performed by default.
Preferably, when entering and leaving a predetermined state of the state machine, executing by default an operation corresponding to said state comprises:
starting a screen projection interface when entering a WFD (Windows presentation device) effective state;
and when the WFD valid state is left, the screen throwing interface is cancelled.
An embodiment of the present invention further provides a Miracast message processing apparatus based on an inheritable state machine, including:
the state machine allocation unit is used for creating a virtual device for the screen projection device and allocating a state machine for the virtual device when the screen projection device is detected to be accessed; the state machine comprises a plurality of states at different levels, and inheritance relationships exist among the states at different levels;
the state triggering unit is used for acquiring the execution action of the screen projection equipment and triggering the state machine to enter a corresponding state according to the execution action;
the message judging unit is used for receiving the message to be processed and judging whether the message needs to be processed or not according to the message to be processed and the current state;
and the message processing unit is used for acquiring the state corresponding to the message from the current state and the parent state inherited from the current state when the message is judged to need to be processed, and processing the message in the corresponding state.
Preferably, the method further comprises the following steps:
a discarding unit configured to discard the message when it is determined that the message does not need to be processed.
Preferably, the state corresponding to the message is obtained through a preset message-state mapping table.
The embodiment of the invention also provides Miracast message processing equipment based on the inheritable state machine, which comprises a memory and a processor, wherein a computer program is stored in the memory and can be executed by the processor, so that the Miracast message processing method based on the inheritable state machine is realized.
In the embodiment, when multiple Miracast screen projection devices appear, one state machine is allocated to each screen projection device, one state machine can only be in one state, the corresponding message processing modes in each state are different, and different states correspond to different states of different levels of P2P and rtsp, so that a P2P connection process is attached, and the purposes of reducing errors and improving the connection success rate are achieved. Research shows that the average success rate can be improved to more than 98% from about 80% by the method.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
For better understanding of the technical solutions of the present invention, the following detailed descriptions of the embodiments of the present invention are provided with reference to the accompanying drawings.
It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
The invention is described in further detail below with reference to the following detailed description and accompanying drawings:
referring to fig. 1, a first embodiment of the present invention provides a method for Miracast message processing based on inheritable state machines, which is executed by a Miracast message processing device based on inheritable state machines (hereinafter referred to as a message processing device), and in particular, executed by one or more processors in the message processing device, to implement the following steps:
s101, when detecting that screen projection equipment is accessed, establishing virtual equipment for the screen projection equipment, and distributing a state machine for the virtual equipment; the state machine comprises a plurality of states at different levels, and inheritance relationships exist among the states at the different levels.
In this embodiment, the message processing device may be, for example, a smart television, a smart projector, a smart tablet, or the like, and may receive a screen projection picture sent by a screen projection device, such as a mobile phone, and display the screen projection picture on a display of the message processing device.
In this embodiment, the screen projection device and the message processing device may be connected through P2P, and when the message processing device detects that the screen projection device is accessed, the message processing device creates a virtual device for the screen projection device and allocates a state machine for the virtual device; the state machine comprises a plurality of states at different levels, and inheritance relationships exist among the states at the different levels.
As shown in fig. 2, fig. 2 shows one possible state machine. In fig. 2, the state machine includes:
a default state at a first level;
a P2P connection state and a P2P connection state at a second level, the P2P connection state and P2P connection state both inherit the default state;
an authentication state, an IP acquisition state, an IP valid state, an IP invalid state and a disconnection waiting state which are positioned at the third level and inherit from the connection state of the P2P;
a WFD valid state at a fourth level that inherits the IP valid state;
and the RTSP state, the WFD on state and the cleaning state which are inherited from the WFD effective state and are positioned in the fourth layer level.
In which a device can only be in one state, and if the device is in the P2P connection state, it is impossible to be in the P2P disconnection state at the same time. An inheritance relationship exists between the states, the inheritance relationship is represented by arrows in fig. 2, the WFD (Wi-Fi Direct, i.e., Wi-Fi screen projection) is in a sub-state of the WFD valid state, and the WFD valid state is in a sub-state of the IP valid state.
It should be noted that, in the embodiment of the present invention, the different states correspond to different states of different levels of P2P and rtsp, so as to conform to the P2P connection flow. In other embodiments of the present invention, the states of the state machine and the inheritance relationship between the states may also be set according to actual needs, and the state machine is only an example of the present invention and is not to be construed as a limitation of the present invention.
S102, obtaining the execution action of the screen projection equipment, and triggering the state machine to enter a corresponding state according to the execution action.
S103, receiving the message to be processed, and judging whether the message needs to be processed or not according to the message to be processed and the current state.
S104, when the message is judged to need to be processed, acquiring the state corresponding to the message from the current state and the parent state inherited from the current state, and processing the message in the corresponding state.
In the present embodiment, the messages can be processed in different states, for example, in the P2P disconnection state, the messages of P2P disconnection can be not processed, i.e., the messages are directly discarded. And when the P2P connection state receives the P2P disconnection message, some disconnection operations are needed.
In this embodiment, the message that is not processed by the child state may be handed over to the parent state, for example, the IP acquiring state may choose not to process the P2P disconnect message and be handed over to the parent state P2P connection state (as compared with the prior art, the P2P disconnect message needs to be processed step by step according to the connection flow, that is, the P2P disconnect message needs to be processed three times).
In this embodiment, the message processing mode may be defined by a preset message-state mapping table, which defines messages that may need to be processed and their corresponding states, so as to ensure accurate processing of the messages.
In addition, some operations can be selected when entering and leaving the state machine, such as entering the WFD conducting state, the screen projection interface can be started, and leaving the WFD state, the screen projection interface can be cancelled.
In summary, in this embodiment, when multiple Miracast screen projection occurs, one state machine is allocated to each screen projection device, and one state machine can only be in one state, the manner of processing the corresponding message in each state is different, and different states correspond to different states of different levels of P2P and rtsp, so as to attach the P2P connection flow, thereby achieving the purposes of reducing errors and improving the connection success rate. Research shows that the average success rate can be improved to more than 98% from about 80% by the method.
Referring to fig. 3, a second embodiment of the present invention further provides a Miracast message processing apparatus based on an inheritable state machine, which includes:
the state machine allocation unit 210 is configured to, when it is detected that a screen projection device is accessed, create a virtual device for the screen projection device, and allocate a state machine to the virtual device; the state machine comprises a plurality of states at different levels, and inheritance relationships exist among the states at different levels;
thestate triggering unit 220 is configured to acquire an execution action of the screen projection device, and trigger the state machine to enter a corresponding state according to the execution action;
a message determining unit 230, configured to receive a message to be processed, and determine whether the message needs to be processed according to the message to be processed and a current state;
a message processing unit 240, configured to, when it is determined that the message needs to be processed, obtain a state corresponding to the message from the current state and a parent state inherited from the current state, and process the message in the corresponding state.
Preferably, the method further comprises the following steps:
a discarding unit configured to discard the message when it is determined that the message does not need to be processed.
Preferably, the state corresponding to the message is obtained through a preset message-state mapping table.
The third embodiment of the present invention further provides a Miracast message processing device based on an inheritable state machine, which includes a memory and a processor, where a computer program is stored in the memory, and the computer program can be executed by the processor, so as to implement the Miracast message processing method based on the inheritable state machine.
In the embodiments provided in the present invention, it should be understood that the disclosed method can be implemented in other ways. The apparatus and method embodiments described above are illustrative only, as the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes. It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.