Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a line switching control method which effectively ensures the synchronous operation of line switching and screen projection operation.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:
defining an atomic variable type state lock function, and defining a lock function and an unlock function for the state lock function;
in the screen projection operation process, a lock function is called to lock the state lock function, and after screen projection is completed, a unlock function is called to unlock the state lock function;
when the line is switched, judging whether the state lock function is in a locked state, if so, prompting a user to perform line switching operation later, if not, traversing each line, sequentially judging each line, if the current line state is in a selected state, emptying, and if not, not processing; then the
And judging whether the current line is the switching target line again, if so, setting the current line in a selected state, and if not, not processing.
On the basis of the technical scheme, for the locking and unlocking operations of the state lock function:
carrying out setting value operation on the atomic variable to realize locking operation on the state lock function;
and clearing the value set by the atomic variable to realize the unlocking operation of the state lock function.
On the basis of the technical scheme, when the locking operation is carried out on the state lock function, whether the atomic variable is set or not is judged, and if yes, the locking fails.
On the basis of the technical scheme, when the state of the current line is the selected state, the live broadcast mobile terminal acquires a video source from the line and plays a live broadcast picture.
On the basis of the technical scheme, after a certain line is set to be in a selected state, screen throwing operation is carried out between the live broadcast mobile terminal and the television terminal, at the moment, a lock function is called to carry out locking operation on the state lock function, and after the screen throwing operation between the live broadcast mobile terminal and the television terminal is completed, an unlock function is called to carry out unlocking operation on the state lock function.
The invention also provides a storage medium having stored thereon a computer program which, when executed by a processor, implements the method described above.
The invention also provides an electronic device, which comprises a memory and a processor, wherein the memory stores a computer program running on the processor, and the processor executes the computer program to realize the method.
The present invention also provides a line switching control system, including:
the defining module is used for defining an atomic variable type state lock function and defining a lock function and an unlock function for the state lock function;
the upper unlocking module is used for calling a lock function to lock the state lock function in the screen projection operation process, and calling an unlock function to unlock the state lock function after screen projection is finished;
and the judging module is used for judging whether the state lock function is in a locked state when the line is switched, prompting a user to perform line switching operation later if the state lock function is in the locked state, traversing each line if the state lock function is not in the locked state, sequentially judging each line, emptying if the state of the current line is in a selected state, not processing if the current line is in a non-selected state, judging whether the current line is a switching target line again, setting the current line to be in a selected state if the current line is in the selected state, and not processing if the current line is not in the selected state.
On the basis of the technical scheme, the upper unlocking module performs locking and unlocking operations on the state lock function: carrying out setting value operation on the atomic variable to realize locking operation on the state lock function; and clearing the value set by the atomic variable to realize the unlocking operation of the state lock function.
On the basis of the technical scheme, when the state of the current line is the selected state, the live broadcast mobile terminal acquires a video source from the line and plays a live broadcast picture.
Compared with the prior art, the invention has the advantages that: the state lock function is mapped with the screen projection process through the definition of the state lock function, if the screen projection operation is currently carried out, the state lock function is in a locked state, processing is not carried out at the moment, and therefore it is guaranteed that line switching operation cannot be carried out any more when the screen projection operation is carried out, the switching operation and the screen projection operation state of a line are synchronous, and better interaction experience is brought to a user.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples.
Referring to fig. 1, an embodiment of the present invention provides a line switching control method, which is suitable for a screen-casting operation of a live broadcast mobile terminal at a television terminal, and includes:
s1: a status lock function castingLock of an atomic variable type is defined, and a lock function and an unlock function are defined for the status lock function.
The screen projection is a time-consuming process, and when the screen projection for the first time is not completed, the switching operation of the screen projection for the second time is performed, so that unfriendly interactive experience is brought to a user. In the embodiment of the invention, the state lock function is an atomic variable, and the atomic variable is thread-safe in java, so that the abnormal condition can not occur when a plurality of threads operate the state lock function.
In the traditional scheme, the maintenance of the synchronization state when the live broadcast mobile terminal and the television terminal screen cast is changed by using a global variable, but the synchronization state is managed by using the global variable, so that the defects are that firstly, threads are unsafe, namely, the state is disordered when multi-thread operation is carried out, so that the state maintenance is wrong; secondly, the maintenance is complex, and programmers need to spend more time and energy to manage and maintain the synchronous state, so that the waste of human resources is caused; thirdly, due to the difficulty of maintenance, bug with abnormal state is easily introduced, so that the program is not robust enough and the effective and correct execution of the program cannot be ensured.
S2: in the screen projection operation process, a lock function is called to lock the state lock function, and after screen projection is completed, an unlock function is called to unlock the state lock function. For lock and unlock operations of the state lock function: carrying out setting value operation on the atomic variable to realize locking operation on the state lock function; and clearing the value set by the atomic variable to realize the unlocking operation of the state lock function. And when the locking operation is carried out on the state lock function, whether the atomic variable is set or not is judged, if yes, the locking fails, and at the moment, an error message, namely, the lock fails, is returned. Similarly, for unlocking the state lock function, the unlock function clears the value of the atomic variable, and the unlock function clears the atomic variable no matter whether the atomic variable is set with the value or is empty. The screen projection operation process refers to the process from the screen projection start to the screen projection end.
Through the steps, the whole screen projection process is mapped to the state lock function, and the current state condition can be acquired through the state lock function in the later stage when the switching operation of the line is carried out.
S3: when the line is switched, judging whether the state lock function is in a locked state, if so, indicating that screen projection operation is performed at the moment, prompting a user to perform line switching operation later, if not, traversing each line, sequentially judging each line, if the current line state is a selected state, emptying, and if the current line state is a non-selected state, not processing; and then, judging whether the current line is a switching target line or not, wherein the target line is a line to be switched, if so, setting the current line to be in a selected state, otherwise, not processing, and so on, thereby finishing the judgment of all lines and finishing the operation of switching to the target line.
When a certain line is set to be in a selected state, screen throwing operation is carried out between the live broadcast mobile terminal and the television terminal, at the moment, a lock function is called to carry out locking operation on the state lock function, and after the screen throwing operation between the live broadcast mobile terminal and the television terminal is completed, an unlock function is called to carry out unlocking operation on the state lock function. The state lock function is mapped with the screen projection process through the definition of the state lock function, if the screen projection operation is currently carried out, the state lock function is in a locked state, processing is not carried out at the moment, and therefore it is guaranteed that line switching operation cannot be carried out any more when the screen projection operation is carried out, the switching operation and the screen projection operation state of a line are synchronous, and better interaction experience is brought to a user.
In the conventional scheme, the switching of the lines is performed through a global variable, when different lines are selected, the global variable is changed into corresponding line information, and thus state information can be acquired through the global variable.
In an embodiment, when switching lines, after judging that the state lock function is in an unlocked state, the states of all lines are set to be in an unselected state, and then a target line is set to be in a selected state, and if switching is performed from a line 1 to a line 2, the states of all lines are set to be in the unselected state, and then the state of the line 2 is set to be in the selected state, so that switching of the lines is completed.
When the definition of the live-broadcast watching picture is switched, the screen projection operation is carried out again after the definition switching is finished, and different video sources are obtained in principle by switching the definition, so that a method similar to the line switching control method of the embodiment of the invention can be used for synchronizing the definition switching and the screen projection operation.
According to the line switching control method, through the definition of the state lock function, when screen projection operation is carried out between the live broadcast mobile terminal and the television terminal, the lock function is called to carry out locking operation on the state lock function, after the screen projection operation between the live broadcast mobile terminal and the television terminal is completed, the unlock function is called to carry out unlocking operation on the state lock function, mapping between the state lock function and the screen projection process is achieved, if the screen projection operation is carried out currently, the state lock function is in a locking state, processing is not carried out at the time, and therefore the line switching operation cannot be carried out any more when the screen projection operation is carried out, synchronization of the line switching operation and the screen projection operation state is guaranteed, and good interactive experience is brought to a user.
In addition, corresponding to the line switching control method, the present invention further provides a storage medium, where a computer program is stored, and the computer program, when executed by a processor, implements the steps of the line switching control method according to each of the above embodiments. The storage medium includes various media capable of storing program codes, such as a usb disk, a removable hard disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), a magnetic disk, or an optical disk.
Referring to fig. 2, in response to the line switching control method, the present invention further provides an electronic device, which includes a memory and a processor, where the memory stores a computer program running on the processor, and the processor executes the computer program to implement the line switching control method according to the foregoing embodiments.
The invention also provides a line switching control system based on the line switching control method, which comprises a definition module, an upper unlocking module and a judgment module.
The defining module is used for defining an atomic variable type state lock function and defining a lock function and an unlock function for the state lock function; the upper unlocking module is used for calling a lock function to lock the state lock function in the screen projection operation process, and calling an unlock function to unlock the state lock function after screen projection is finished; the judging module is used for judging whether the state lock function is in a locked state when the line is switched, prompting a user to perform line switching operation later if the state lock function is in the locked state, traversing each line if the state lock function is not in the locked state, sequentially judging each line, emptying if the current line is in a selected state, not processing if the current line is in a non-selected state, judging whether the current line is a switching target line again, setting the current line to be in a selected state if the current line is in the selected state, and not processing if the current line is not in the selected state.
The locking and unlocking operations of the locking and unlocking module on the state lock function are as follows: carrying out setting value operation on the atomic variable to realize locking operation on the state lock function; and clearing the value set by the atomic variable to realize the unlocking operation of the state lock function. And when the current line state is the selected state, the live broadcast mobile terminal acquires a video source from the line and plays a live broadcast picture.
According to the line switching control system, through the definition of the state lock function, when screen projection operation is carried out between the live broadcast mobile terminal and the television terminal, the upper unlocking module calls the lock function to carry out locking operation on the state lock function, after the screen projection operation between the live broadcast mobile terminal and the television terminal is completed, the upper unlocking module calls the unlock function to carry out unlocking operation on the state lock function, mapping between the state lock function and the screen projection process is achieved, if the screen projection operation is carried out currently, the state lock function is in the locking state, processing is not carried out at the time, and therefore it is guaranteed that line switching operation cannot be carried out any more when the screen projection operation is carried out currently, synchronization of line switching operation and screen projection operation state is guaranteed, and good interactive experience is brought to users.
The present invention is not limited to the above-described embodiments, and it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements are also considered to be within the scope of the present invention. Those not described in detail in this specification are within the skill of the art.