Mode switching method, electronic device and storage medium
By synchronizing mode switching process and resource configuration in camera applications, the problem of slow camera mode switching speed is solved and the user experience is improved.
Patent Information
- Application Number
- CN202310820628.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-05
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2043-07-05
AI Technical Summary
During the camera mode switching process, due to the influence of the system resource supply status, the mode switching speed is slow, affecting the user experience.
In the process of turning off the first shooting mode, the second shooting mode is started based on a plurality of startup threads, so that the mode switching process is synchronized, and the terminal lens status is detected using the thread blocking service to ensure the normal progress of the resource configuration process.
It improves the switching speed of shooting mode, reduces the time to wait for the closing process to be completed, avoids the abnormal problem of thread blocking service, and improves the user experience.
Smart Images

Figure CN117729426B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a mode switching method, an electronic device and a storage medium. Background Art
[0002] At present, the camera application installed on the terminal can support multiple shooting modes, such as photo mode, video mode, portrait mode, night scene mode, multi-scene video mode (simultaneous shooting with front and rear lenses), etc. Users can freely choose the shooting mode to experience different shooting effects.
[0003] However, during the camera mode switching process, it is very likely that the mode switching speed will be slow due to the influence of the system resource supply status, thereby affecting the user experience. Summary of the invention
[0004] The present application provides a mode switching method, an electronic device and a storage medium, which are used to increase the switching speed of shooting modes.
[0005] In order to achieve the above objectives, this application adopts the following technical solutions:
[0006] In a first aspect, a mode switching method is provided, the method comprising:
[0007] Displaying a first interface of a camera application; the first interface is an interface of a first shooting mode, in which a single lens is used to collect image data;
[0008] In response to an operation of switching the first shooting mode to the second shooting mode at a first time point, displaying a second interface of the camera application at a second time point; the second interface is an interface of the second shooting mode, in which multiple lenses are used to collect image data;
[0009] Wherein, between the first time point and the second time point, there is an overlap between the first time period and the second time period; the first time period is a time period for closing the first shooting mode based on the closing thread, and the second time period is a time period for opening the second shooting mode based on multiple starting threads, and the multiple starting threads correspond one to one to the multiple lenses;
[0010] A third time period is also included between the first time point and the second time point. The third time period is a time period in which the configuration flow thread is started to configure resources for the second shooting mode when all lenses included in the terminal are not executing the shutdown thread; whether all lenses included in the terminal are executing the shutdown thread is implemented based on a thread blocking service; the thread blocking service is called after the startup thread is executed, and during the process of the thread blocking service being called, it is not allowed to be called after other startup threads are executed.
[0011] In the above technical solution, when the camera application is switched from the first shooting mode to the second shooting mode, the second shooting mode can be started based on multiple startup threads in the process of closing the first shooting mode based on the shutdown thread, so that the closing process of the first shooting mode and the startup process of the second shooting mode can be performed synchronously. In this way, the time waiting for the completion of the closing process of the first shooting mode is reduced, which is conducive to improving the switching speed of the shooting mode. Furthermore, based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread. In the case that all the lenses included in the terminal are not executing the closing thread, the configuration flow thread is started to configure resources for the second shooting mode. Among them, during the process of calling the thread blocking service, it is not allowed to be called after the execution of other startup threads is completed. In this way, it can be ensured that the thread blocking service is only called by one startup thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0012] In a possible implementation manner of the first aspect, the multiple startup threads include a first startup thread, and the first startup thread is any one of the multiple startup threads;
[0013] The method further includes:
[0014] When the thread blocking service is called after the first startup thread is executed, the thread blocking service is locked;
[0015] Based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread; when all the lenses included in the terminal are not executing the closing thread, the thread blocking service is unlocked.
[0016] In this possible implementation, a method based on a lock mechanism is provided to ensure thread blocking services. By locking the thread blocking service, it can be ensured that the thread blocking service is only called by one starting thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0017] In another possible implementation manner of the first aspect, the multiple startup threads further include a second startup thread, and the second startup thread calls the thread blocking service after the first startup thread;
[0018] The method further includes:
[0019] When the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in a locked state, waiting for the thread blocking service to be unlocked; or,
[0020] When the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in an unlocked state, the thread blocking service is locked; based on the thread blocking service, it is detected whether all lenses included in the terminal are executing a shutdown thread; if all lenses included in the terminal are not executing a shutdown thread, the thread blocking service is unlocked.
[0021] In this possible implementation, when the thread blocking service is in a locked state, wait for it to be unlocked before performing the subsequent detection process. When the thread blocking service is in an unlocked state, the subsequent detection process can be performed. In this way, it can be ensured that the thread blocking service is only called by one starting thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0022] In another possible implementation of the first aspect, based on the thread blocking service, detecting whether all lenses included in the terminal are after executing the closing thread, the method further includes:
[0023] When any lens among all the lenses included in the terminal is executing a closing thread, the configuration flow thread is blocked from executing to wait for the closing thread to be completed.
[0024] In this possible implementation, when any one of all the lenses included in the terminal executes a shutdown thread, the configuration stream thread is prevented from executing, ensuring that when all the lenses included in the terminal have not executed the shutdown thread, the subsequent configuration stream thread is executed to configure resources for the second shooting mode, so that the configuration stream thread can normally configure the resources for the second shooting mode and avoid abnormalities in the configuration process.
[0025] In another possible implementation of the first aspect, based on the thread blocking service, detecting whether all lenses included in the terminal are executing a closing thread includes:
[0026] Based on the thread blocking service, polling is performed to detect whether all lenses included in the terminal are executing the closing thread.
[0027] In another possible implementation of the first aspect, based on the thread blocking service, polling and detecting whether all lenses included in the terminal are executing a closing thread includes:
[0028] Based on the thread blocking service, traverse the thread status of all lenses included in the terminal corresponding to the closed thread;
[0029] Based on the thread states of the closing threads corresponding to all the lenses included in the terminal, it is detected whether all the lenses included in the terminal are executing the closing threads.
[0030] In another possible implementation of the first aspect, based on thread states of the closing threads corresponding to all lenses included in the terminal, detecting whether all lenses included in the terminal are executing the closing threads includes:
[0031] For a closing thread corresponding to any lens among all lenses included in the terminal, if the thread state of the closing thread is a terminated state, it is determined that the lens has not executed the closing thread; or,
[0032] For a closing thread corresponding to any lens among all lenses included in the terminal, if the thread state of the closing thread is not a terminated state, the lens is determined to execute the closing thread.
[0033] In this possible implementation, a method based on polling detection is provided to determine whether the closing thread is completed. By traversing all lenses included in the terminal, it is ensured that all lenses included in the terminal have not executed the closing thread, thereby ensuring that the subsequent configuration flow thread normally configures the resources of the second shooting mode.
[0034] In another possible implementation manner of the first aspect, in response to an operation of switching the first shooting mode to the second shooting mode at a first time point, the method further includes:
[0035] When the preset conditions are met, the closing thread is created;
[0036] The first shooting mode has configured camera service resources;
[0037] The application identifier of the camera application belongs to a preset application identifier; the preset application identifier is an application identifier that supports the creation of the closing thread;
[0038] The function switch for creating the shutdown thread is turned on;
[0039] The shutdown thread during the last mode switching process is idle;
[0040] The target module of the camera application is initialized; the initialization of the target module is related to the configuration flow thread.
[0041] In this possible implementation, by setting a preset condition, it is determined whether the condition for creating a shutdown thread is currently met. Then, it is ensured that when the condition for creating a shutdown thread is met, the process of creating a shutdown thread is executed, thereby ensuring the smooth creation of the shutdown thread. Among them, multiple types of preset conditions are provided to ensure that when the condition for creating a shutdown thread is met, the process of creating a shutdown thread is executed, thereby ensuring the smooth creation of the shutdown thread.
[0042] In another possible implementation manner of the first aspect, the method further includes at least one of the following:
[0043] Set the thread attribute of the shutdown thread to the target attribute;
[0044] Set the priority of the shutdown thread to the highest priority.
[0045] In this possible implementation, by setting at least one of the thread attribute and the priority of the shutdown thread, it is possible to ensure that the shutdown thread obtains sufficient CPU performance, thereby ensuring that the shutdown thread works normally.
[0046] In another possible implementation manner of the first aspect, the method further includes:
[0047] In response to the completion of the creation of the closing thread, triggering a notification message of the completion of the closing thread;
[0048] Based on the notification message, the start thread is called to start the second shooting mode.
[0049] In this possible implementation, when the closing thread is created, the starting thread can be called to start the second shooting mode without waiting for the closing process of the first shooting mode to end, so that the closing process of the first shooting mode and the starting process of the second shooting mode can be performed synchronously. In this way, the time for waiting for the closing process of the first shooting mode to be completed is reduced, which is conducive to improving the switching speed of the shooting mode.
[0050] In a second aspect, the present application provides an electronic device, including: a processor and a memory. The memory is used to store program codes, and the processor is used to call the program codes stored in the memory, so as to implement any one of the methods provided in the first aspect.
[0051] According to a third aspect, a computer-readable storage medium is provided, comprising a program code. When the program code is executed on an electronic device, the electronic device executes any one of the methods provided in the first aspect.
[0052] According to a fourth aspect, a computer program product is provided, including a program code. When the program code is executed on an electronic device, the electronic device executes any one of the methods provided in the first aspect.
[0053] It should be noted that the technical effects brought about by any implementation method in the second to fourth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 A schematic diagram of an implementation environment of a mode switching method provided in an embodiment of the present application;
[0055] Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0056] Figure 3 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application;
[0057] Figure 4 A schematic diagram of a flow chart of a mode switching method provided in an embodiment of the present application;
[0058] Figure 5 A schematic diagram of a flow chart of a mode switching method provided in an embodiment of the present application;
[0059] Figure 6 A schematic diagram of a program code of a mode switching method provided in an embodiment of the present application;
[0060] Figure 7 A schematic diagram of an architecture flow of a mode switching method provided in an embodiment of the present application;
[0061] Figure 8 A program scheduling diagram of a mode switching method provided in an embodiment of the present application;
[0062] Fig. 9 A hierarchical interaction diagram of a mode switching method provided in an embodiment of the present application;
[0063] Fig.10 A schematic diagram of a flow chart of a mode switching method provided in an embodiment of the present application;
[0064] Fig.11 A flowchart of another mode switching method provided in an embodiment of the present application;
[0065] Fig.12 A schematic diagram of a framework of a mode switching device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0066] In the description of this application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "plurality" means two or more. The words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not limit them to be different.
[0067] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0068] The mode switching method provided in the embodiment of the present application can be applied in the field of terminal technology, and can be specifically applied in the mode switching scenario of camera applications. Wherein, mode switching refers to switching the camera application from one shooting mode to another shooting mode.
[0069] At present, the camera application installed on the terminal can support multiple shooting modes, such as photo mode, video mode, portrait mode, night scene mode, multi-scene video mode (simultaneous shooting with front and rear lenses), etc. Users can freely choose the shooting mode to experience different shooting effects.
[0070] However, during the camera mode switching process, it is very likely that the mode switching speed will be slow due to the influence of the system resource supply status, thereby affecting the user experience.
[0071] It should be understood that different types of devices have different central processing unit (CPU) resources and memory configurations. During the camera mode switching process, sufficient CPU performance scheduling and memory resource supply may not be available at all times, which will greatly affect the user experience.
[0072] In view of this, an embodiment of the present application provides a mode switching method. When the camera application is switched from the first shooting mode to the second shooting mode, the second shooting mode can be started based on multiple startup threads in the process of closing the first shooting mode based on the shutdown thread, so that the closing process of the first shooting mode and the startup process of the second shooting mode can be performed synchronously. In this way, the time waiting for the completion of the closing process of the first shooting mode is reduced, which is conducive to improving the switching speed of the shooting mode. Furthermore, based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread. In the case that all the lenses included in the terminal are not executing the closing thread, the configuration flow thread is started to configure resources for the second shooting mode. Among them, during the process of calling the thread blocking service, it is not allowed to be called after the execution of other startup threads is completed. In this way, it can be ensured that the thread blocking service is only called by one startup thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0073] In a possible implementation, the mode switching method provided in the embodiment of the present application can be applied to Figure 1 The electronic device 100 shown is exemplary. Figure 1 A schematic diagram of an implementation environment of a mode switching method provided in an embodiment of the present application.
[0074] The electronic device 100 may be a terminal device, which is referred to as a terminal in the following embodiments of the present application. For example, the electronic device 100 may be at least one of a smart phone, a smart watch, a smart TV, a desktop computer, a laptop, a tablet computer, a wearable device, a virtual reality terminal, an augmented reality terminal, a wireless terminal (such as a wireless terminal in industrial control, a wireless terminal in unmanned driving, a wireless terminal in remote surgery, a wireless terminal in a smart grid, a wireless terminal in transportation safety, a wireless terminal in a smart city, a wireless terminal in a smart home, etc.), and a laptop computer.
[0075] In a possible implementation, different types of applications (APPs) may be installed in the electronic device 100, such as camera, gallery, calendar, call, map, navigation, music, video, short message and other applications.
[0076] In the embodiment of the present application, the electronic device 100 provides a mode switching function. Figure 1 In the interface shown in A, the user can trigger the electronic device 100 to display the shooting interface of the camera application by clicking the icon of the camera application on the electronic device 100, such as Figure 1 The interface shown in B. At this time, the shooting interface includes a preview area 1001 and a shooting mode selection area 1002.
[0077] The preview area 1001 is used to display a pre-shooting picture (or preview picture) of the object to be photographed. The shooting mode selection area 1002 is used to provide multiple shooting mode options of the camera application. Figure 1 , Figure 1 For example, the currently selected shooting mode is the photo mode. For example, the user can click a shooting mode in the shooting mode selection area 1002 to switch the shooting mode, or the user can slide left and right in the shooting mode selection area 1002 to switch the shooting mode.
[0078] Then, in response to the user's mode switching operation in the shooting mode selection area 1002 (such as the above-mentioned operation of clicking the shooting mode or the operation of sliding left and right), the electronic device 100 can be triggered to display the interface after the mode switching. In this way, the mode switching of the camera application is completed.
[0079] In an embodiment of the present application, the electronic device 100 is used to display a first interface of a camera application, and in response to an operation of switching a first shooting mode to a second shooting mode at a first time point, displays a second interface of the camera application at a second time point. The time period for closing the first shooting mode based on the shutdown thread overlaps with the time period for starting the second shooting mode based on multiple startup threads. In addition, when all lenses included in the terminal are not executing the shutdown thread, the configuration flow thread is started to configure resources for the second shooting mode. Whether all lenses included in the terminal are executing the shutdown thread is implemented based on the thread blocking service. The thread blocking service is called after the startup thread is executed, and during the process of the thread blocking service being called, it is not allowed to be called after other startup threads are executed.
[0080] For example, Figure 1 The structural diagram of the electronic device 100 is shown in FIG. Figure 2 shown. Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.
[0081] See also Figure 2 The electronic device 100 may include a processor 210, an external memory interface 220, an internal memory 221, a universal serial bus (USB) interface 230, a charging management module 240, an antenna 1, an antenna 2, a mobile communication module 250, a wireless communication module 260, an audio module 270, a sensor module 280, a button 290, a camera 291, a display screen 292, etc. The sensor module 280 may include a pressure sensor 280A, a gyroscope sensor 280B, an air pressure sensor 280C, a magnetic sensor 280D, an acceleration sensor 280E, a distance sensor 280F, a proximity light sensor 280G, a fingerprint sensor 280H, a temperature sensor 280J, a touch sensor 280K, an ambient light sensor 280L, a bone conduction sensor 280M, etc.
[0082] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0083] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processor (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. Different processing units may be independent devices or integrated into one or more processors.
[0084] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0085] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.
[0086] In some embodiments, the processor 210 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0087] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 210 may include multiple I2C buses. The processor 210 may be coupled to the touch sensor 280K, the charger, the flash, the camera 291, etc. through different I2C bus interfaces.
[0088] The I2S interface may be used for audio communication. In some embodiments, the processor 210 may include multiple sets of I2S buses.
[0089] The PCM interface can also be used for audio communication to sample, quantize and encode analog signals.
[0090] The UART interface is a universal serial data bus used for asynchronous communication.
[0091] The MIPI interface can be used to connect the processor 210 with peripheral devices such as the camera 291 and the display screen 292. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 210 and the camera 291 communicate via the CSI interface to realize the shooting function of the electronic device 100. The processor 210 and the display screen 292 communicate via the DSI interface to realize the display function of the electronic device 100.
[0092] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 210 with the camera 291, the display screen 292, the wireless communication module 260, the audio module 270, the sensor module 280, etc.
[0093] The USB interface 230 is an interface that complies with USB standard specifications, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
[0094] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0095] The charging management module 240 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.
[0096] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 250, the wireless communication module 260, the modem processor and the baseband processor.
[0097] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0098] The mobile communication module 250 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 250 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 250 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 250 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 250 can be set in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 250 can be set in the same device as at least some of the modules of the processor 210.
[0099] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device, or displays an image or video through a display screen 292. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 210 and be set in the same device as the mobile communication module 250 or other functional modules.
[0100] The wireless communication module 260 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (bluetoo2, BT), global navigation satellite system (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR), etc. applied to the electronic device 100. The wireless communication module 260 can be one or more devices integrating at least one communication processing module. The wireless communication module 260 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and filters it, and sends the processed signal to the processor 210. The wireless communication module 260 can also receive the signal to be sent from the processor 210, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0101] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 250, and antenna 2 is coupled to wireless communication module 260, so that electronic device 100 can communicate with the network and other devices through wireless communication technology.
[0102] The electronic device 100 implements the display function through a GPU, a display screen 292, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 292 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 210 may include one or more GPUs, which execute program instructions to generate or change display information.
[0103] The display screen 292 is used to display images, videos, etc. The display screen 292 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 292, where N is a positive integer greater than 1.
[0104] The electronic device 100 can realize the shooting function through the ISP, the camera 291, the video codec, the GPU, the display screen 292 and the application processor.
[0105] The ISP is used to process the data fed back by the camera 291. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converts it into an image visible to the naked eye. The ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. The ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP can be set in the camera 291.
[0106] The camera 291 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 291, where N is a positive integer greater than 1. In an embodiment of the present application, the camera 291 can be used as a lens installed on the terminal.
[0107] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0108] The video codec is used to compress or decompress digital video. The electronic device 100 may support one or more video codecs.
[0109] NPU is a neural-network (NN) computing processor. It can quickly process input information by drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, and can also continuously self-learn.
[0110] The external memory interface 220 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 210 through the external memory interface 220 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0111] The internal memory 221 can be used to store computer executable program codes, which include instructions. The processor 210 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 221. The internal memory 221 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 221 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0112] The audio module 270 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signal. The audio module 270 can also be used to encode and decode audio signals. In some embodiments, the audio module 270 can be arranged in the processor 210, or some functional modules of the audio module 270 can be arranged in the processor 210.
[0113] The key 290 includes a power key, a volume key, etc. The key 290 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0114] It should be pointed out that Figure 2 The structure shown in the figure does not constitute a limitation on the electronic device, except Figure 2 In addition to the components shown, the electronic device may include more or fewer components than shown, or combine certain components, or arrange the components differently.
[0115] The software system of the electronic device can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to illustrate the software structure of the electronic device. Figure 3 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application.
[0116] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer (application, APP), an application framework layer (application framework), a hardware abstraction layer (hardware abstraction layer, HAL), a kernel layer (kernel), and a system library. In some embodiments, the Android system also includes an Android runtime (Android runtime).
[0117] Among them, the application layer can include a series of application packages.
[0118] like Figure 3 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0119] In some embodiments, the application layer runs the application by calling an application programming interface (API) provided by the application framework layer.
[0120] The application framework layer provides an application program interface and a programming framework for the application program of the application program layer. In some embodiments, the application framework layer includes some predefined functions (which may be referred to as programming services). For example, in some embodiments, the application framework layer can provide programming services to the application program layer for calling through the application program interface.
[0121] like Figure 3 As shown, the application framework layer may include a camera service module, a content provider, a view system, a phone manager, a resource manager, a notification manager, a window manager, and the like.
[0122] The camera service module can provide camera service. In the embodiment of the present application, the camera service module is used to control the relevant processes of the camera application, such as the mode switching process. For example, in the mode switching process, the camera service module can be used to trigger the shutdown process of the first shooting mode, trigger the startup process of the second shooting mode, trigger the configuration process of the second shooting mode, and trigger the request for image data, etc.
[0123] Content providers are used to store and retrieve data and make it accessible to applications. This data can include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0124] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0125] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0126] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0127] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0128] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0129] The hardware abstraction layer is an interface layer between the kernel layer and the hardware, which can be used to abstract the hardware. Figure 3As shown, the hardware abstraction layer may include camera interfaces, such as a shutdown interface, a startup interface, a configuration stream interface, etc. In the embodiment of the present application, the hardware abstraction layer is used to execute the mode switching process of the camera application. For example, in the mode switching process, the hardware abstraction layer can be used to execute processes such as determining whether the conditions for creating a shutdown thread are met, creating a shutdown thread, and detecting whether the shutdown thread is completed.
[0130] The kernel layer is the layer between hardware and software. The kernel layer provides the underlying drivers for various hardware of the mobile phone. For example, Figure 3 As shown, the kernel layer includes camera driver module, thread manager, display driver, camera driver, audio driver, and sensor driver.
[0131] Among them, the thread manager is responsible for creating threads and terminating threads. It should be understood that the underlying support for threads is provided in the kernel layer. In some embodiments, the thread manager is responsible for allocating threads to be executed to the CPU, and then triggering the CPU to execute the threads allocated by the thread manager.
[0132] The system library may include multiple functional modules, such as a surface manager, a media library, a 3D graphics processing library (such as OpenGL ES), a 2D graphics engine (such as SGL), etc.
[0133] In some embodiments, the Android runtime includes core libraries and a virtual machine.
[0134] The following is an illustrative description of the workflow of the software and hardware of the electronic device 100 in conjunction with a shooting scenario.
[0135] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into an original input event (including touch coordinates, timestamp of the touch operation, and other information). The original input event is stored in the kernel layer. The application framework layer obtains the original input event from the kernel layer and identifies the control corresponding to the input event. For example, if the touch operation is a touch single-click operation and the control corresponding to the single-click operation is the icon of the camera application, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer, and shoots a static image or video through the camera 291.
[0136] Figure 4 A schematic diagram of a mode switching method provided in an embodiment of the present application. Figure 4 The method includes the following S401-S402:
[0137] S401: The terminal displays a first interface of a camera application.
[0138] The first interface is an interface of a first shooting mode, in which a single lens is used to collect image data.
[0139] S402: In response to the operation of switching the first shooting mode to the second shooting mode at the first time point, the terminal displays the second interface of the camera application at the second time point.
[0140] The second interface is an interface of the second shooting mode, in which multiple lenses are used to collect image data.
[0141] In an embodiment of the present application, there is an overlap between the first time point and the second time point, the first time period and the second time period; the first time period is a time period based on a shutdown thread to shut down the first shooting mode, and the second time period is a time period based on multiple startup threads to start the second shooting mode, and the multiple startup threads correspond one-to-one to the multiple lenses.
[0142] A third time period is also included between the first time point and the second time point. The third time period is a time period in which the configuration flow thread is started to configure resources for the second shooting mode when all lenses included in the terminal are not executing the shutdown thread; whether all lenses included in the terminal are executing the shutdown thread is implemented based on a thread blocking service; the thread blocking service is called after the startup thread is executed, and during the process of the thread blocking service being called, it is not allowed to be called after other startup threads are executed.
[0143] The technical solution provided by the embodiment of the present application can start the second shooting mode based on multiple startup threads when the camera application is switched from the first shooting mode to the second shooting mode, while the first shooting mode is closed based on the shutdown thread, so that the closing process of the first shooting mode and the startup process of the second shooting mode can be performed synchronously. In this way, the time waiting for the completion of the closing process of the first shooting mode is reduced, which is conducive to improving the switching speed of the shooting mode. Furthermore, based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread. In the case that all the lenses included in the terminal are not executing the closing thread, the configuration flow thread is started to configure resources for the second shooting mode. Among them, during the process of calling the thread blocking service, it is not allowed to be called after the execution of other startup threads is completed. In this way, it can be ensured that the thread blocking service is only called by one startup thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0144] Figure 5 A schematic diagram of a mode switching method provided in an embodiment of the present application. Figure 5 The method includes the following S501-S506:
[0145] S501: The terminal displays a first interface of a camera application.
[0146] Among them, the first interface is an interface of the first shooting mode, in which a single lens is used to collect image data. Exemplarily, the first shooting mode can be a single-shot mode, such as a photo mode. In the embodiment of the present application, the first shooting mode can represent the previous shooting mode, that is, the shooting mode before switching.
[0147] Generally, a camera application can support multiple shooting modes, such as photo mode, video mode, portrait mode, large aperture, night scene mode, multi-scene video mode, etc. Users can freely choose the shooting mode to experience different shooting effects.
[0148] S502: In response to the operation of switching the first shooting mode to the second shooting mode, the terminal creates a closing thread when a preset condition is met.
[0149] In this second shooting mode, multiple lenses are used to collect image data. Exemplarily, the first shooting mode may be a dual-camera mode (i.e., shooting with a main lens and an auxiliary lens), such as a portrait mode. In the embodiment of the present application, the second shooting mode represents the next shooting mode, i.e., the shooting mode after switching.
[0150] In some embodiments, the operation of switching the first shooting mode to the second shooting mode may be a click operation, a left-right sliding operation, or other types of operations, which are not limited in the embodiments of the present application.
[0151] The preset condition is used to determine whether the condition for creating a closing thread is currently met. It should be understood that if the preset condition is currently met, it indicates that the condition for creating a closing thread is currently met. If the preset condition is not currently met, it indicates that the condition for creating a closing thread is not currently met. In the embodiment of the present application, the closing thread can be a close thread (or asynchronous close thread), which is used to close the first shooting mode.
[0152] In some embodiments, the above-mentioned preset condition may include at least one of the following (1) to (5):
[0153] (1) The camera service resources have been configured for the first shooting mode.
[0154] The camera service resources may include a channel established for the shooting mode and resources applied for the shooting mode, such as subsystem services, memory resources, and input / output (I / O) resources.
[0155] It should be noted that the subsequent process of closing the first shooting mode by closing the thread is also the process of releasing the camera service resources of the first shooting mode. It should be understood that if the first shooting mode has configured camera service resources, it is necessary to create a closing thread to execute the subsequent process of releasing resources. If the first shooting mode has not configured camera service resources, it is not necessary to create a closing thread to execute the subsequent process of releasing resources.
[0156] (2) The application ID of the camera application is a preset application ID.
[0157] The application identifier may be represented by an application package name, an application number or an application ID (identity document). The preset application identifier is a preset application identifier that supports the creation of the closed thread. In some embodiments, the number of preset application identifiers may be one or more.
[0158] It should be understood that if the application identifier of the camera application belongs to the preset application identifier, it indicates that the camera application supports the creation of the closing thread. If the application identifier of the camera application does not belong to the preset application identifier, it indicates that the camera application does not support the creation of the closing thread.
[0159] (3) The function switch for creating the shutdown thread is in the turned-on state.
[0160] It should be understood that if the function switch of the closing thread is in the on state, it indicates that the subsequent creation of the closing thread and the subsequent process based on the closing thread are allowed. If the function switch of the closing thread is in the off state, it indicates that the subsequent creation of the closing thread and the subsequent process based on the closing thread are not allowed.
[0161] For the conditions shown in (2) and (3) above, the first preset function can be used to determine whether the application identifier belongs to the preset application identifier and whether the function switch for closing the thread is turned on, so as to determine whether the conditions for creating a closing thread are currently met.
[0162] For example, the first preset function may be the IsSupportAsyncCloseProcessApp function.
[0163] In some embodiments, the IsSupportAsyncCloseProcessApp function is used to check the configuration parameters in the product.xml file to determine whether the application identifier belongs to the preset application identifier and whether the function switch for closing the thread is turned on, so as to determine whether the conditions for creating a closing thread are currently met.
[0164] The configuration parameters may include the state parameters of the function switch and the application package name (i.e., the preset application identifier) that supports the creation of a shutdown thread, etc. It should be noted that before implementing this solution, the state parameters of the function switch and the application package name that supports the creation of a shutdown thread, etc., may be configured in the product.xml file.
[0165] For example, in the product.xml file, the isAvailable parameter can be used as the state parameter of the function switch (or master switch) to refer to the state of the function switch for closing threads. When the isAvailable parameter is configured to 0, it means that the function switch for closing threads is not turned on, and when the isAvailable parameter is configured to 1, it means that the function switch for closing threads is turned on.
[0166] For another example, in the product.xml file, the supportAppNameList parameter can be used as a preset application identifier to refer to the pre-set application package name that supports the creation and closing of threads. When the application package name indicated by the supportAppNameList parameter is consistent with the application package name of the current camera application, it indicates that the application identifier belongs to the preset application identifier; when the application package name indicated by the supportAppNameList parameter is inconsistent with the application package name of the current camera application, it indicates that the application identifier does not belong to the preset application identifier.
[0167] In the above embodiment, by setting the first preset function, it is possible to quickly determine whether the application identifier belongs to the preset application identifier and whether the function switch for closing the thread is turned on, thereby quickly determining whether the conditions for creating a closing thread are currently met, thereby improving the judgment efficiency for the preset conditions and thus improving the efficiency of mode switching.
[0168] (4) The shutdown thread during the last mode switching process is in an idle state.
[0169] It should be understood that if the shutdown thread in the last mode switching process is in an idle state, it means that the shutdown thread in the last mode switching process has been completed, and the current mode switching can be allowed at this time. If the shutdown thread in the last mode switching process is not in an idle state, it means that the shutdown thread in the last mode switching process has not been completed (still in progress), and the current mode switching is not allowed at this time. Among them, the shutdown thread has been completed, which means that the process of closing the first shooting mode based on the shutdown thread has been completed. The shutdown thread is not completed, which means that the process of closing the first shooting mode based on the shutdown thread is not completed.
[0170] In some embodiments, whether the shutdown thread in the last mode switching process is in an idle state can be determined based on the state variable of the shutdown thread in the last mode switching process to determine whether the conditions for creating a shutdown thread are currently met.
[0171] For example, the state variable for closing a thread may be the g_hAsyncCloseProcessthreadHandle variable.
[0172] In some embodiments, it is possible to determine whether the shutdown thread is in an idle state by determining whether the state variable of the shutdown thread in the last mode switching process is empty. If the state variable of the shutdown thread in the last mode switching process is empty, it indicates that the shutdown thread in the last mode switching process is in an idle state. If the state variable of the shutdown thread in the last mode switching process is not empty, it indicates that the shutdown thread in the last mode switching process is not in an idle state.
[0173] It should be noted that if the shutdown thread in the previous mode switching process is not completed when the current mode switching process begins, the two shutdown threads may operate a data structure or global variable at the same time, which may cause data confusion and thus cause thread safety issues. Therefore, by determining whether the shutdown thread in the previous mode switching process is idle, the problem of data confusion can be effectively avoided, thereby improving the safety of the shutdown thread in this mode switching process.
[0174] (5) The target module of the camera application is initialized.
[0175] Among them, the target module can be a CHI module.
[0176] In the embodiment of the present application, the initialization of the target module is related to the configuration flow thread. For example, if the target module is initialized, it indicates that the configuration flow thread of the terminal can run normally. If the target module is not initialized, it indicates that the configuration flow thread of the terminal cannot run normally.
[0177] In some embodiments, a second preset function may be used to detect the initialization state of the target module to determine whether the target module has been initialized.
[0178] For example, the second preset function may be the IsCHIModuleInitialized function.
[0179] Exemplarily, in the IsCHIModuleInitialized function, a flag bit may be set to indicate the initialization state of the CHI module. For example, if the flag bit is true, it indicates that the CHI module initialization is complete, and if the flag bit is false, it indicates that the CHI module initialization is not complete.
[0180] In the above embodiment, by setting the preset conditions, it is determined whether the conditions for creating a shutdown thread are currently met. Further, it is ensured that the process of creating a shutdown thread is executed when the conditions for creating a shutdown thread are met, thereby ensuring the smooth creation of the shutdown thread. Among them, multiple types of preset conditions are provided to ensure that the process of creating a shutdown thread is executed when the conditions for creating a shutdown thread are met, thereby ensuring the smooth creation of the shutdown thread.
[0181] Based on one, two or more of the conditions shown in (1) to (5) above, when it is determined that the conditions for creating a shutdown thread are currently met, a shutdown thread is created.
[0182] In some embodiments, the hardware abstraction layer may maintain a camxhal3.cpp file, which provides a closing interface (ie, close interface). Further, the closing interface in the camxhal3.cpp file may be used to call a third preset function to create a closing thread.
[0183] For example, the third preset function may be a ThreadCreate function. For example, the ThreadCreate function may be used to create an asynchronous thread to carry the subsequent closing process of the first shooting mode, that is, the process of closing the first shooting mode.
[0184] In some embodiments, the process of the terminal creating a shutdown thread can be completed by the cooperation of the hardware abstraction layer and the kernel layer. The corresponding process can be: the hardware abstraction layer writes the parameters required to create the shutdown thread in the interface provided by the thread manager of the kernel layer, and then the thread manager of the kernel layer creates the shutdown thread according to the parameters required to create the shutdown thread written in the interface. Among them, the interface provided by the thread manager of the kernel layer is also the interface used for information transmission between the hardware abstraction layer and the kernel layer.
[0185] In some embodiments, when creating a shutdown thread, at least one of the following settings may be performed for the shutdown thread: setting the thread attribute (policy) of the shutdown thread to the target attribute; setting the priority (priority) of the shutdown thread to the highest priority.
[0186] The target attribute may be a normal attribute (or a default attribute). It should be understood that threads with normal attributes can usually cover most thread functions. Thus, by setting at least one of the thread attribute and priority of the closed thread, it is possible to ensure that the closed thread obtains sufficient CPU performance, thereby ensuring that the closed thread works normally.
[0187] It should be noted that the above process of determining whether the conditions for creating and closing a thread are met, creating an asynchronous thread, and setting thread attributes and priorities can be comprehensively executed using the CreateAsyncCloseProcess function. That is, the CreateAsyncCloseProcess function can provide the above first preset function, the second preset function, the third preset function, the state variable of the closing thread, and the function of setting thread attributes and priorities.
[0188] In some embodiments, in response to a mode switching operation on the camera application, the camera application may flush the camera's usecase resources before creating a shutdown thread.
[0189] S503: The terminal closes the first shooting mode based on the closing thread, and starts the second shooting mode based on the multiple starting threads.
[0190] The multiple startup threads correspond one-to-one to the multiple lenses corresponding to the second shooting mode.
[0191] In the embodiment of the present application, the time period for closing the first shooting mode based on the closing thread overlaps with the time period for starting the second shooting mode based on multiple starting threads. That is, the process of closing the first shooting mode based on the closing thread overlaps with the process of starting the second shooting mode based on multiple starting threads in time. For example, the process of starting the second shooting mode based on multiple starting threads can be executed in the process of closing the first shooting mode based on the closing thread.
[0192] After the shutdown thread is created based on the kernel layer in S502, the thread manager of the kernel layer can start the shutdown thread to close the first shooting mode, that is, to release the camera service resources of the first shooting mode. Optionally, the process of the kernel layer thread manager starting the shutdown thread can be: the kernel layer thread manager assigns the shutdown thread to the CPU, and the CPU starts the shutdown thread to release the camera service resources of the first shooting mode.
[0193] In some embodiments, a fourth preset function may be used to execute the above process of turning off the first shooting mode.
[0194] For example, the fourth preset function may be an AsyncCloseProcess function. For example, the fourth preset function includes a pHALDevice->Close() function, which is used to execute a process of releasing camera service resources of the first shooting mode.
[0195] Furthermore, in some embodiments, after releasing the camera service resource of the first shooting mode, the memory occupied by the camera service resource is also released, for example, the memory occupied by the camera3_device_t and HALDevice classes is released.
[0196] During the running process of the above-mentioned closing thread, the NotifyCameraClose notification of the pOfflineLoggerASCII and pOfflineLoggerBinary offline log mechanisms must be completed during the running process of the closing thread to avoid conflicts with the NotifyCameraOpen in the running process of the subsequent opening thread, thereby causing errors.
[0197] In some embodiments, in response to the completion of the creation of the closing thread, a notification message of the completion of the closing thread is triggered. Based on the notification message, the start thread is called to start the second shooting mode.
[0198] The startup thread may be an open thread, which is used to start the second shooting mode. In this embodiment, when the closing thread is created, a notification message of the completion of the closing thread can be triggered. In order to call the startup thread in time to start the second shooting mode, the closing process of the first shooting mode and the starting process of the second shooting mode can be carried out synchronously. In this way, the time waiting for the closing process of the first shooting mode to be completed is reduced, which is conducive to improving the switching speed of the shooting mode.
[0199] In some embodiments, the thread manager of the kernel layer can start the startup thread to start the second shooting mode, that is, to obtain the camera parameters and basic resources of the second shooting mode. Optionally, the process of the thread manager of the kernel layer starting the startup thread can be: the thread manager of the kernel layer assigns the startup thread to the CPU, and the CPU starts to execute the startup process of the second shooting mode. Among them, the camera parameters can be mode identifiers (such as ID), state machines, etc., and the basic resources can be operators of the hardware abstraction layer, etc.
[0200] In some embodiments, when the shutdown thread is created based on the kernel layer in S502 above, the kernel layer sends the creation result of the shutdown thread to the hardware abstraction layer, and the creation result indicates that the shutdown thread has been created. Then, the hardware abstraction layer receives the creation result from the kernel layer, and can respond to the completion of the shutdown thread creation within a relatively fast time (1-2ms) without waiting for the shutdown process of the first shooting mode to end, and trigger a notification message of the completion of the shutdown thread. Then, the notification message of the completion of the shutdown thread is returned to the camera application through the application framework layer, so that the camera application can start the startup process of the second shooting mode without waiting for the shutdown process to end. For example, see Figure 5 In step S503, the closing process of the first shooting mode and the starting process of the second shooting mode can be performed synchronously. It should be understood that when the hardware abstraction layer returns the notification of the completion of the closing, the closing thread for closing the first shooting mode is actually still in progress.
[0201] S504: After any one of the multiple startup threads is executed, the terminal detects whether all lenses included in the terminal are executing a shutdown thread based on a thread blocking service.
[0202] The thread blocking service is called after the startup thread is executed, and during the process of calling the thread blocking service, it is not allowed to be called after other startup threads are executed.
[0203] In some embodiments, the multiple startup threads include a first startup thread, and the first startup thread is any one of the multiple startup threads. Accordingly, when the thread blocking service is called after the first startup thread is executed, the thread blocking service is locked. Based on the thread blocking service, it is detected whether all lenses included in the terminal are executing a shutdown thread. In the case that all lenses included in the terminal are not executing a shutdown thread, the thread blocking service is unlocked.
[0204] Furthermore, in some embodiments, the multiple startup threads also include a second startup thread, and the second startup thread calls the thread blocking service after the first startup thread. Accordingly, when the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in a locked state, the thread blocking service is waited to be unlocked. Or, when the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in an unlocked state, the thread blocking service is locked. Based on the thread blocking service, it is detected whether all lenses included in the terminal are executing a shutdown thread. In the case that all lenses included in the terminal are not executing a shutdown thread, the thread blocking service is unlocked.
[0205] In this way, when the thread blocking service is in a locked state, wait for it to be unlocked before performing the subsequent detection process. When the thread blocking service is in an unlocked state, the subsequent detection process can be performed. In this way, it can be ensured that the thread blocking service is only called by one starting thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0206] Understandably, the thread blocking service only provides services for a lens (lens identification, such as lens ID) corresponding to a startup thread in one thread blocking process. For example, taking the second shooting mode as a portrait mode (including the main lens of the front camera and the auxiliary lens of the rear camera, that is, including two lenses) as an example, the thread blocking service can provide services for one lens in the second shooting mode in one thread blocking process, and provide services for another lens in the second shooting mode in the next thread blocking process.
[0207] In one example, taking the portrait mode as the second shooting mode, after a lens in the second shooting mode is started up, the lens identifier (such as lens ID) of the lens can be input into the thread blocking service, and the thread blocking service is locked to ensure that only this lens is provided with service in this thread blocking process. Then, it is detected whether all lenses included in the terminal are executing the closing thread. If all lenses included in the terminal are not executing the closing thread, the thread blocking service is unlocked. In this way, the first thread blocking process is completed, and at this time, the thread blocking service is in an unlocked state. Then, if another lens in the second shooting mode is also started up, the other lens can be input into the thread blocking service, and the thread blocking service is locked again. It is detected whether all lenses included in the terminal are executing the closing thread. If all lenses included in the terminal are not executing the closing thread, the thread blocking service is unlocked again. It should be noted that if the above-mentioned other lens is started up and the thread blocking service is in a locked state, the lens needs to wait for the thread blocking service to be unlocked before executing the subsequent detection process.
[0208] In the above embodiment, a method for protecting thread blocking service based on lock mechanism is provided. By locking the thread blocking service, it can be ensured that the thread blocking service is only called by one starting thread in a thread blocking process, and the abnormal problem caused by repeated calling of thread blocking service can be avoided.
[0209] The process of detecting whether the closing thread is completed may include: based on the thread blocking service, polling to detect whether all lenses included in the terminal are executing the closing thread.
[0210] In some embodiments, based on the thread blocking service, the thread states of all lenses included in the terminal corresponding to the closing thread can be traversed. Based on the thread states of all lenses included in the terminal corresponding to the closing thread, it is detected whether all lenses included in the terminal are executing the closing thread.
[0211] Among them, for the closing thread corresponding to any one of all the lenses included in the terminal, if the thread state of the closing thread is a terminated state, it is determined that the lens has not executed the closing thread; or, for the closing thread corresponding to any one of all the lenses included in the terminal, if the thread state of the closing thread is not a terminated state, it is determined that the lens executes the closing thread.
[0212] In this embodiment, a method based on polling detection is provided to determine whether the closing thread is completed. By traversing all lenses included in the terminal, it is ensured that all lenses included in the terminal have not executed the closing thread, thereby ensuring that the subsequent configuration flow thread normally configures the resources of the second shooting mode.
[0213] The above embodiment takes the case where all the lenses included in the terminal are not executing the closing thread as an example to illustrate the solution. In other embodiments, when any lens among all the lenses included in the terminal is executing the closing thread, the configuration flow thread is blocked to wait for the closing thread to complete.
[0214] In this way, when any of the lenses included in all the lenses of the terminal executes the shutdown thread, the configuration flow thread is prevented from executing, ensuring that the subsequent configuration flow thread is executed to configure resources for the second shooting mode when all the lenses included in the terminal have not executed the shutdown thread, so that the configuration flow thread can normally configure the resources for the second shooting mode and avoid abnormalities in the configuration process.
[0215] In some embodiments, the thread blocking service may be a piece of program code based on the threadwait function provided in the configuration flow thread, which is used to trigger the normal operation of the configuration flow thread when the operation conditions are met, and to prevent the configuration flow thread from running when the operation conditions are not met. In the embodiment of the present application, the operation condition may be the completion of the closing thread. It should be understood that the completion of the closing thread indicates that the operation conditions are met, and the thread can be controlled to run normally at this time. The incomplete closing of the thread indicates that the operation conditions are not met, and the thread can be prevented from running.
[0216] The configuration stream thread may be a configure_streams thread.
[0217] In some embodiments, after any one of the multiple startup threads is completed, it is necessary to detect whether the shutdown thread is completed. In response to the shutdown thread not being completed, the configure_streams thread can be actively blocked, and the configure_streams thread can be restarted after the shutdown thread is completed.
[0218] For example, in some embodiments, the camxhal3.cpp file maintained by the hardware abstraction layer also provides a configuration stream interface (i.e., configure_streams interface). Further, in the camxhal3.cpp file, when the configure_streams interface is called, it can detect whether the shutdown thread is completed. If not, it needs to wait for the shutdown thread to be completed before being called.
[0219] It should be noted that the configuration stream thread and the shutdown thread are coupled in terms of the creation of related services and memory application. Therefore, when executing subsequent configuration processes based on the configuration stream thread, it is necessary to wait for the shutdown thread to complete. For example, if both apply for the same memory space, the memory space applied for the second shooting mode may be released by the shutdown thread, causing the camera service resources configured by the camera application for the second shooting mode to be abnormal. Therefore, before starting the configuration stream thread, it is necessary to first detect whether the shutdown thread has ended, and then start the configuration stream thread when the shutdown thread has ended. This is conducive to the camera application to normally configure the camera service resources for the second shooting mode and avoid abnormalities in the camera process.
[0220] Exemplarily, in the code logic, the hardware abstraction layer can configure the thread blocking service for the configuration stream thread. If the shutdown thread has not been completed, but the camera application has been scheduled to the configuration stream thread, then during the execution of the configuration stream thread, the hardware abstraction layer detects whether the shutdown thread is completed. If not, the hardware abstraction layer instructs the thread manager not to assign the configuration stream thread to the CPU, and after the shutdown thread is completed, the hardware abstraction layer instructs the thread manager to assign the configuration stream thread to the CPU, and the CPU executes the process of configuring camera service resources. If it has been completed, the hardware abstraction layer instructs the kernel layer to start the configuration stream thread.
[0221] For example, Figure 6 A schematic diagram of a program code of a mode switching method provided in an embodiment of the present application. Figure 6 , Figure 6 The first line of code in the code segment 601 in the terminal is used to poll and detect whether the lens installed on the terminal has the process executed by the above-mentioned closing thread. If so, the lens in the second shooting mode is controlled to wait for the closing thread to be completed. Figure 6The last two lines of code in code segment 601 in the first shooting mode are used to ensure the process timing of the closing thread of the first shooting mode and the configuration flow thread of the second shooting mode, ensuring that the configuration process of the configuration flow thread is executed after the closing thread is completed.
[0222] Figure 6 The code segment 602 in the example is used to determine whether the lens installed on the terminal has the above-mentioned process of closing the thread execution, that is, to determine whether the current cameraId has a closing thread working. If so, lock it to ensure the timing.
[0223] Figure 6 The code segment 603 in is used to determine whether the lens installed on the terminal has the above-mentioned process of closing the thread execution, that is, to determine whether the current cameraId has completed closing, and if completed, unlock it.
[0224] S505: When all lenses included in the terminal are not executing a closing thread, start a configuration flow thread to configure resources for the second shooting mode.
[0225] In some embodiments, based on the configuration flow thread, the platform session, pipeline and node are configured for the second shooting mode to complete the channel creation of the second shooting mode, and the hardware (such as the lens) is initialized to configure the resource flow to be displayed (start the flow).
[0226] S506: The terminal displays the second interface of the camera application.
[0227] The second interface is an interface of the second shooting mode, in which multiple lenses are used to collect image data.
[0228] In some embodiments, the camera application requests image data from the hardware abstraction layer, and the hardware abstraction layer returns the image data to the camera application, and then the camera application displays the pre-shot image in the second interface of the camera application according to the image data. It should be noted that for each frame of the image data, a request to obtain the image needs to be sent once.
[0229] In this way, by acquiring the image data in the second shooting mode and then presenting the pre-shooting picture in the second shooting mode, the user experience of the camera application is improved.
[0230] For example, Figure 7 A schematic diagram of the architecture flow of a mode switching method provided in an embodiment of the present application. Figure 7In response to the mode switching operation on the camera application, the camera application first cleans up the use case resources of the camera application. It is determined whether the use case resources of the camera application have been cleaned up. After the use case resources of the camera application have been cleaned up, a shutdown thread is created if the preset conditions are met. The process of determining whether the preset conditions are met includes: first checking the configuration parameters in the product.xml file to determine whether the application identifier belongs to the preset application identifier and whether the function switch of the shutdown thread is turned on, and then checking the initialization state of the CHI module of the camera application to determine whether the CHI module has been initialized.
[0231] In one possible case, when the application identifier belongs to the preset application identifier, the function switch of the shutdown thread is turned on, and the CHI module is initialized, the preset conditions are met at this time, and the mode switching process can be executed in an asynchronous manner. Among them, the process of executing the mode switching process in an asynchronous manner can be: creating a shutdown thread and setting the thread attributes and priority of the shutdown thread. When the shutdown thread is created, the message of creation completion can be quickly returned to the camera application to trigger the camera application to call the startup thread. Then, based on the created shutdown thread, the shutdown process of the first shooting mode is executed, and the startup thread is called to execute the startup process of the second shooting mode. After the startup thread completes the startup process of the second shooting mode, it is necessary to first detect whether the shutdown thread has completed the shutdown process of the first shooting mode based on the thread blocking service in the configuration flow thread. When the shutdown thread completes the shutdown process of the first shooting mode, the configuration flow thread is called to configure camera service resources for the second shooting mode.
[0232] In another possible case, when the application identifier does not belong to the preset application identifier, the function switch of the shutdown thread is turned off, and the CHI module is not initialized, the preset conditions are not met at this time, and the mode switching can be performed in a non-asynchronous manner. Among them, the process of executing the mode switching process in a non-asynchronous manner can be: calling the established shutdown thread to execute the shutdown process of the first shooting mode. After the shutdown thread completes the shutdown process of the first shooting mode, calling the startup thread to execute the startup process of the second shooting mode. After the startup thread completes the startup process of the second shooting mode, calling the configuration flow thread to configure camera service resources for the second shooting mode.
[0233] For example, Figure 8 A program scheduling diagram of a mode switching method provided in an embodiment of the present application. Figure 8 First, use the close interface in the camxhal3.cpp file to call the CreateAsyncCloseProcess function to create a closing thread.
[0234] Among them, before creating the closing thread, in the camxhwenvironment subfile of the camxhal3.cpp file, the IsSupportAsyncCloseProcessApp function is used to determine whether the application identifier belongs to the preset application identifier and whether the function switch of the closing thread is turned on. When the application identifier belongs to the preset application identifier and the function switch of the closing thread is turned on, in the camxhaldevice of the camxhal3.cpp file, the IsCHIModuleInitialized function is used to detect the initialization state of the CHI module to determine whether the CHI module has been initialized. When the CHI module has been initialized, the g_hAsyncCloseProcessthreadHandle variable of the closing thread in the last mode switching process is used to determine whether the closing thread in the last mode switching process is in an idle state. When the closing thread in the last mode switching process is in an idle state, a closing thread is created.
[0235] Then, the closing process of the first shooting mode is executed based on the created closing thread, and the starting thread is called to execute the starting process of the second shooting mode. After the starting thread completes the starting process of the second shooting mode, it is necessary to first detect whether the closing thread has completed the closing process of the first shooting mode (pHALDevice->Close() function) based on the thread blocking service (threadwait function) in the configuration flow thread. When the closing thread completes the closing process of the first shooting mode, the configuration flow thread is called to configure the camera service resources for the second shooting mode.
[0236] based on Figure 3 the software architecture of the electronic device described, and Figure 5 The process of the mode switching method described is shown as follows Fig. 9 The hierarchical interaction diagram of the mode switching method shown in FIG. Fig. 9 , taking the interaction between the camera application, the application framework layer, the hardware abstraction layer and the kernel layer as an example, the mode switching method is described. Among them, the close thread is used to refer to the closing thread, the open thread is used to refer to the starting thread, and the configure_streams thread is used to refer to the configuration stream thread. The method includes S901 to S930:
[0237] S901: In response to a mode switching operation on a camera application, the camera application sends a mode switching instruction to an application framework layer.
[0238] The mode switching instruction is used to instruct the camera application to switch from the first shooting mode to the second shooting mode.
[0239] In some embodiments, the com.hihonor.camera process of the camera application sends the mode switching instruction to the camera server process of the application framework layer by calling the close interface of the application framework layer.
[0240] S902: The application framework layer sends the mode switching instruction to the hardware abstraction layer.
[0241] In some embodiments, the application framework layer sends the mode switching instruction to the android.hardware.camera.provider@2.4-server_64 process (which may be referred to as the provider process) of the hardware abstraction layer through the close interface.
[0242] After S901 and S902, the camera application can pass the mode switching instruction to the hardware abstraction layer by calling the close interface of the application framework layer, so as to call the close thread of the hardware abstraction layer to execute the close process. It should be noted that the close process in the embodiment of the present application refers to the process of closing the first shooting mode based on the close thread. Of course, this process can also be called an asynchronous close process.
[0243] S903: The hardware abstraction layer determines whether the conditions for creating a close thread are met. If yes, execute S904.
[0244] S904: The hardware abstraction layer sends an instruction to create a close thread to the kernel layer.
[0245] S905: The kernel layer creates a close thread.
[0246] S906: The kernel layer starts a close thread to execute a close process of the first shooting mode.
[0247] S907: The kernel layer sends a creation result to the hardware abstraction layer to indicate that the close thread creation is completed.
[0248] S908. In response to the completion of the close thread creation, the hardware abstraction layer returns a first feedback result (ie, a notification message of the completion of the close thread) to the application framework layer to indicate that the close process of the first shooting mode has been completed.
[0249] It should be understood that the hardware abstraction layer returns the first feedback result to the application framework layer based on the completion of the creation of the close thread. In fact, the close thread for closing the first shooting mode is still in progress.
[0250] S909: The application framework layer returns a first feedback result to the camera application.
[0251] After S908 and S909 , the hardware abstraction layer may pass the first feedback result to the camera application by calling the close interface of the application framework layer.
[0252] After receiving the first feedback result, the camera application can execute S910 so that the open process does not need to wait for the close process to end, so that the close thread and the open thread can be executed synchronously. It should be noted that the open process in the embodiment of the present application refers to the process of starting the second shooting mode based on the open thread.
[0253] S910: The camera application sends an instruction to execute an open process to the application framework layer to instruct the start of an open thread of the second shooting mode.
[0254] In some embodiments, the com.hihonor.camera process of the camera application sends the instruction to execute the open process to the camera server process of the application framework layer by calling the open interface of the application framework layer.
[0255] S911. The application framework layer sends the instruction for executing the open process to the hardware abstraction layer.
[0256] In some embodiments, the application framework layer can send the instruction to execute the open process to the provider process of the hardware abstraction layer through the open interface.
[0257] After S910 and S911, the camera application can pass the instruction for executing the open process to the hardware abstraction layer by calling the open interface of the application framework layer, so as to start the open thread of the hardware abstraction layer to execute the open process of the second shooting mode.
[0258] S912: The hardware abstraction layer sends an instruction to execute an open process to the kernel layer, so as to instruct the kernel layer to start an open thread to execute the open process of the second shooting mode.
[0259] S913: The kernel layer starts an open thread to execute an open process of the second shooting mode.
[0260] S914: After the open process of the second shooting mode is completed, the kernel layer sends a second feedback result to the hardware abstraction layer to indicate that the open process of the second shooting mode has been completed.
[0261] S915. The hardware abstraction layer sends the second feedback result to the application framework layer.
[0262] S916. The application framework layer sends the second feedback result to the camera application.
[0263] S917: The camera application sends an instruction to execute the configure_streams process to the application framework layer to instruct to start the configure_streams thread of the second shooting mode.
[0264] It should be noted that the configure_streams process in the embodiment of the present application refers to the process of configuring camera service resources for the second shooting mode based on the configure_streams thread.
[0265] S918. The application framework layer sends the instruction for executing the configure_streams process to the hardware abstraction layer.
[0266] Optionally, the application framework layer sends the instruction to execute the configure_streams process to the provider process of the hardware abstraction layer through the configure_streams interface.
[0267] After S917 and S918, the camera application can pass the instruction for executing the configure_streams process to the hardware abstraction layer by calling the configure_streams interface of the application framework layer, so as to start the configure_streams thread of the hardware abstraction layer to execute the configure_streams process of the second shooting mode.
[0268] S919. The hardware abstraction layer detects whether the close thread is finished.
[0269] In some embodiments, after receiving the instruction to execute the configure_streams process from the application framework layer, the hardware abstraction layer first detects whether the close thread ends based on the thread blocking service, that is, detects whether the release of resources based on the close thread is completed. After determining that the close thread ends, the hardware abstraction layer instructs the kernel layer to start the configure_streams thread.
[0270] S920: When the close thread ends, the hardware abstraction layer sends an instruction to execute the configure_streams process to the kernel layer, so as to instruct the kernel layer to start the configure_streams thread to execute the configure_streams process of the second shooting mode.
[0271] S921. The kernel layer starts the configure_streams thread to execute the configure_streams process of the second shooting mode.
[0272] S922: After the configure_streams process of the second shooting mode is completed, the kernel layer sends a third feedback result to the hardware abstraction layer to indicate that the configure_streams process of the second shooting mode has been completed.
[0273] S923. The kernel layer sends image data to the hardware abstraction layer.
[0274] During the execution of the configure_streams process, when the lens is created, the hardware abstraction layer will send hardware initialization instructions to the kernel layer, and the kernel layer will start to initialize the lens after receiving the hardware initialization instructions. After the hardware initialization is completed, the lens starts to collect image data and returns the image data to the hardware abstraction layer through the kernel layer.
[0275] S924. The hardware abstraction layer sends the third feedback result to the application framework layer.
[0276] S925. The application framework layer sends the third feedback result to the camera application.
[0277] S926: The camera application sends a start instruction to the application framework layer to indicate a request to obtain image data.
[0278] It should be understood that the image data is the image data captured by the lens as described in S923.
[0279] S927. The application framework layer sends a repeating instruction to the hardware abstraction layer. The repeating instruction is used to instruct the hardware abstraction layer to return image data frame by frame and indicate the storage space of the image data.
[0280] S928. The hardware abstraction layer sends image data to the application framework layer.
[0281] In some embodiments, the hardware abstraction layer may write each frame of image data into a storage space (rotating buffer) for transmission.
[0282] S929. The application framework layer sends the image data to the camera application.
[0283] S930: The camera application displays a pre-shooting picture based on the received image data.
[0284] exist Fig. 9In the described embodiment, the transmission between each layer or each module is actually implemented by function calling. In the above embodiment, since the close process and the open process of the camera application are not coupled when the mode is switched, when the close process of the first shooting mode is executed, the open thread of the hardware abstraction layer can be called to execute the open process of the second shooting mode. In addition, there is idle time between the end of the open process of the second shooting mode and the start of the configure_streams process of the second shooting mode. Usually, the length of this idle time can meet the length of time required to execute the close process of the first shooting mode. In this way, the terminal can make full use of the hardware resources (CPU and memory) of the device, and fully dispatch the idle CPU to process the close thread through software parallel processing, which will not bring additional cost burden to the terminal and effectively improve the speed of mode switching.
[0285] For example, Fig.10 A schematic diagram of a mode switching method provided in an embodiment of the present application. Fig.10 , the camera application first calls the close process of the hardware abstraction layer to close the first shooting mode, and the hardware abstraction layer creates a close thread to carry the closing process of the first shooting mode. During the closing process, the camera application calls the open process of the hardware abstraction layer to start the second shooting mode of the camera application. After the startup process is completed, the camera application calls the configure_streams thread of the hardware abstraction layer to configure the platform session, pipeline and node, initialize the hardware, and configure the resource streams to be displayed. After that, the camera application sends a repeating instruction to the hardware abstraction layer to request image data collected by the lens. The hardware abstraction layer returns multiple frames of images to the camera application, and the camera application displays the pre-shot picture in the preview area based on the multiple frames of images. It should be noted that Fig.10 The mode switching process shown takes approximately 700ms.
[0286] exist Fig.10 In the embodiment shown, a solution is provided to implement mode switching based on an asynchronous shutdown process. Fig.11 , and also provides a solution for realizing mode switching based on a non-asynchronous shutdown process in a related technology.
[0287] See also Fig.11In the process of the camera application switching from the first shooting mode to the second shooting mode, the camera application first calls the close process of the hardware abstraction layer to close the first shooting mode. After the first shooting mode is closed, the camera application calls the open process of the hardware abstraction layer to start the second shooting mode of the camera application. After the startup process ends, the camera application calls the configure_streams thread of the hardware abstraction layer to configure the platform session, pipeline and node, initialize the hardware, and configure the resource streams to be displayed. After that, the camera application sends a repeating instruction to the hardware abstraction layer to request the image data collected by the lens. The hardware abstraction layer returns multiple frames of images to the camera application, and the camera application displays the pre-shot picture in the preview area based on the multiple frames of images. It should be noted that Fig.11 The mode switching process shown takes approximately 810 ms.
[0288] In the process of mode switching in the above-mentioned related technology, after the closing process of the first shooting mode is completed, the camera application calls the open process to start the second shooting mode. After the startup process of the second shooting mode is completed, the camera application calls the configure_streams process to configure the platform session, pipeline and node. It can be seen that the close process of the first shooting mode and the open process of the second shooting mode are executed serially. In other words, only after the closing process of the first shooting mode is completed, the camera application will call the open process to start the second shooting mode. For some terminals with poor performance, when the first shooting mode of the camera application is closed, operations such as memory release, thread scheduling, and data processing cannot obtain CPU resources in time, which will result in a longer time to close the first shooting mode, reduce the switching speed of the shooting mode, and thus affect the user experience.
[0289] Compare Fig.10 and Fig.11 It can be seen that since the closing process of the first shooting mode is carried in the close thread, the camera application can quickly call the startup process of the second shooting mode without waiting for the closing process of the first shooting mode to end. The closing process of the first shooting mode and the startup process of the second shooting mode can be executed synchronously, which improves the speed of mode switching.
[0290] It should be noted that, in some other embodiments, if the conditions for creating a shutdown thread are not met, the terminal may execute the following Fig.11The described mode switching process, that is, without creating a shutdown thread, executes the shutdown process of the first shooting mode by calling the established shutdown thread, and after the shutdown process of the first shooting mode is completed, executes the startup process of the second shooting mode. Furthermore, after the startup process of the second shooting mode is completed, the camera application calls the configuration flow thread to configure the camera service resources for the second shooting mode.
[0291] The technical solution provided by the embodiment of the present application can start the second shooting mode based on multiple startup threads when the camera application is switched from the first shooting mode to the second shooting mode, while the first shooting mode is closed based on the shutdown thread, so that the closing process of the first shooting mode and the startup process of the second shooting mode can be performed synchronously. In this way, the time waiting for the completion of the closing process of the first shooting mode is reduced, which is conducive to improving the switching speed of the shooting mode. Furthermore, based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread. In the case that all the lenses included in the terminal are not executing the closing thread, the configuration flow thread is started to configure resources for the second shooting mode. Among them, during the process of calling the thread blocking service, it is not allowed to be called after the execution of other startup threads is completed. In this way, it can be ensured that the thread blocking service is only called by one startup thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0292] Fig.12 This is a schematic diagram of a mode switching device provided in an embodiment of the present application. Fig.12 The mode switching device includes a display module 1201 and a switching module 1202 .
[0293] The display module 1201 is used to display a first interface of the camera application; the first interface is an interface of a first shooting mode, in which a single lens is used to collect image data;
[0294] A switching module 1202, configured to, in response to an operation of switching the first shooting mode to the second shooting mode at a first time point, display a second interface of the camera application at a second time point; the second interface is an interface of the second shooting mode, in which multiple lenses are used to collect image data;
[0295] Wherein, between the first time point and the second time point, there is an overlap between the first time period and the second time period; the first time period is a time period for closing the first shooting mode based on the closing thread, and the second time period is a time period for opening the second shooting mode based on multiple starting threads, and the multiple starting threads correspond one to one to the multiple lenses;
[0296] A third time period is also included between the first time point and the second time point. The third time period is a time period in which the configuration flow thread is started to configure resources for the second shooting mode when all lenses included in the terminal are not executing the shutdown thread; whether all lenses included in the terminal are executing the shutdown thread is implemented based on a thread blocking service; the thread blocking service is called after the startup thread is executed, and during the process of the thread blocking service being called, it is not allowed to be called after other startup threads are executed.
[0297] The technical solution provided by the embodiment of the present application can start the second shooting mode based on multiple startup threads when the camera application is switched from the first shooting mode to the second shooting mode, while the first shooting mode is closed based on the shutdown thread, so that the closing process of the first shooting mode and the startup process of the second shooting mode can be performed synchronously. In this way, the time waiting for the completion of the closing process of the first shooting mode is reduced, which is conducive to improving the switching speed of the shooting mode. Furthermore, based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread. In the case that all the lenses included in the terminal are not executing the closing thread, the configuration flow thread is started to configure resources for the second shooting mode. Among them, during the process of calling the thread blocking service, it is not allowed to be called after the execution of other startup threads is completed. In this way, it can be ensured that the thread blocking service is only called by one startup thread in a thread blocking process, and the abnormal problem caused by repeated calling of the thread blocking service can be avoided.
[0298] In some embodiments, the plurality of launch threads include a first launch thread, the first launch thread being any one of the plurality of launch threads;
[0299] The method further includes:
[0300] When the thread blocking service is called after the first startup thread is executed, the thread blocking service is locked;
[0301] Based on the thread blocking service, it is detected whether all the lenses included in the terminal are executing the closing thread; when all the lenses included in the terminal are not executing the closing thread, the thread blocking service is unlocked.
[0302] In some embodiments, the plurality of start threads further include a second start thread, the second start thread calling the thread blocking service after the first start thread;
[0303] The method further includes:
[0304] When the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in a locked state, waiting for the thread blocking service to be unlocked; or,
[0305] When the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in an unlocked state, the thread blocking service is locked; based on the thread blocking service, it is detected whether all lenses included in the terminal are executing a shutdown thread; if all lenses included in the terminal are not executing a shutdown thread, the thread blocking service is unlocked.
[0306] In some embodiments, based on the thread blocking service, detecting whether all lenses included in the terminal are executing the closing thread, the method further includes:
[0307] When any lens among all the lenses included in the terminal is executing a closing thread, the configuration flow thread is blocked from executing to wait for the closing thread to be completed.
[0308] In some embodiments, based on the thread blocking service, detecting whether all lenses included in the terminal are executing a closing thread includes:
[0309] Based on the thread blocking service, polling is performed to detect whether all lenses included in the terminal are executing the closing thread.
[0310] In some embodiments, based on the thread blocking service, polling and detecting whether all lenses included in the terminal are executing the closing thread includes:
[0311] Based on the thread blocking service, traverse the thread status of all lenses included in the terminal corresponding to the closed thread;
[0312] Based on the thread states of the closing threads corresponding to all the lenses included in the terminal, it is detected whether all the lenses included in the terminal are executing the closing threads.
[0313] In some embodiments, based on the thread status of the closing threads corresponding to all the lenses included in the terminal, detecting whether all the lenses included in the terminal are executing the closing threads includes:
[0314] For a closing thread corresponding to any lens among all lenses included in the terminal, if the thread state of the closing thread is a terminated state, it is determined that the lens has not executed the closing thread; or,
[0315] For a closing thread corresponding to any lens among all lenses included in the terminal, if the thread state of the closing thread is not a terminated state, the lens is determined to execute the closing thread.
[0316] In some embodiments, in response to the operation of switching the first shooting mode to the second shooting mode at a first time point, the method further includes:
[0317] When the preset conditions are met, the closing thread is created;
[0318] The precondition includes at least one of the following:
[0319] The first shooting mode has configured camera service resources;
[0320] The application identifier of the camera application belongs to a preset application identifier; the preset application identifier is an application identifier that supports the creation of the closing thread;
[0321] The function switch for creating the shutdown thread is turned on;
[0322] The shutdown thread during the last mode switching process is idle;
[0323] The target module of the camera application is initialized; the initialization of the target module is related to the configuration flow thread.
[0324] In some embodiments, the method further comprises at least one of the following:
[0325] Set the thread attribute of the shutdown thread to the target attribute;
[0326] Set the priority of the shutdown thread to the highest priority.
[0327] In some embodiments, the method further comprises:
[0328] In response to the completion of the creation of the closing thread, triggering a notification message of the completion of the closing thread;
[0329] Based on the notification message, the start thread is called to start the second shooting mode.
[0330] It is understandable that the electronic device (such as terminal) in the embodiment of the present application includes a hardware structure and / or software module corresponding to each function in order to realize the above functions. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present application.
[0331] The embodiment of the present application further provides an electronic device, including: a processor and a memory. The processor is connected to the memory, the memory is used to store program codes, and the processor executes the program codes stored in the memory, thereby implementing the mode switching method provided in the embodiment of the present application.
[0332] An embodiment of the present application further provides a computer-readable storage medium having program code stored thereon. When the program code is executed on an electronic device, the electronic device executes each function or step executed by the electronic device in the above method embodiment.
[0333] An embodiment of the present application also provides a computer program product, including program code. When the program code is executed on an electronic device, the electronic device executes each function or step executed by the electronic device in the above method embodiment.
[0334] Among them, the electronic device, computer-readable storage medium or computer program product provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0335] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device (such as an electronic device) is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device (such as an electronic device) and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0336] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices (such as electronic devices) and methods can be implemented in other ways. For example, the device (such as electronic device) embodiments described above are only schematic. For example, the division of the module or unit is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0337] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0338] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0339] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method of each embodiment of the present application. The aforementioned storage medium includes: flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk and other media that can store program codes.
[0340] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A mode switching method, characterized in that: include: Display the first interface of the camera application; The first interface is an interface of a first shooting mode, in which a single lens is used to collect image data; In response to an operation of switching the first shooting mode to a second shooting mode at a first time point, displaying a second interface of the camera application at a second time point; the second interface is an interface of the second shooting mode, and multiple lenses are used to collect image data in the second shooting mode; Wherein, between the first time point and the second time point, a first time period and a second time period overlap; the first time period is a time period for closing the first shooting mode based on a closing thread, and the second time period is a time period for opening the second shooting mode based on multiple starting threads, and the multiple starting threads correspond one to one to the multiple lenses; A third time period is also included between the first time point and the second time point, and the third time period is a time period for starting the configuration flow thread to configure resources for the second shooting mode when all lenses included in the terminal are not executing the shutdown thread; whether all lenses included in the terminal are executing the shutdown thread is implemented based on a thread blocking service; the thread blocking service is called after the execution of the startup thread is completed, and during the process of the thread blocking service being called, it is not allowed to be called after the execution of other startup threads is completed; For any first startup thread among the multiple startup threads, when the thread blocking service is called after the first startup thread is executed, the thread blocking service is locked; based on the thread blocking service, the thread states of the closing threads corresponding to all lenses included in the terminal are traversed; for the closing thread corresponding to any lens among all lenses included in the terminal, if the thread state of the closing thread is a terminated state, it is determined that the lens has not executed the closing thread; if the thread state of the closing thread is not a terminated state, it is determined that the lens has executed the closing thread; when all lenses included in the terminal are not executing the closing thread, the thread blocking service is unlocked.
2. The method according to claim 1, characterized in that The multiple startup threads further include a second startup thread, and the second startup thread calls the thread blocking service after the first startup thread; The method further comprises: When the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in a locked state, waiting for the thread blocking service to be unlocked; or, When the thread blocking service is called after the second startup thread is executed, in response to the thread blocking service being in an unlocked state, the thread blocking service is locked; based on the thread blocking service, it is detected whether all lenses included in the terminal are executing a shutdown thread; if all lenses included in the terminal are not executing a shutdown thread, the thread blocking service is unlocked.
3. The method according to claim 2, characterized in that Based on the thread blocking service, detecting whether all lenses included in the terminal are after executing the closing thread, the method further includes: When any lens among all the lenses included in the terminal is executing a closing thread, the configuration flow thread is blocked from being executed to wait for the closing thread to be completed.
4. The method according to claim 1, characterized in that: After the operation of switching the first shooting mode to the second shooting mode at a first time point in response, the method further includes: When the preset conditions are met, the closing thread is created; The preset condition includes at least one of the following: The first shooting mode has configured camera service resources; The application identifier of the camera application belongs to a preset application identifier; the preset application identifier is an application identifier that supports the creation of the closing thread; The function switch for creating the closing thread is in the on state; The shutdown thread during the last mode switching process is idle; The target module of the camera application is initialized; the initialization of the target module is related to the configuration flow thread.
5. The method according to claim 4, characterized in that The method further comprises at least one of the following: Setting the thread attribute of the closed thread to the target attribute; The priority of the shutdown thread is set to the highest priority.
6. The method according to claim 4, characterized in that The method further comprises: In response to the completion of the creation of the shutdown thread, triggering a notification message of the completion of the shutdown thread; Based on the notification message, the start thread is called to start the second shooting mode.
7. An electronic device, characterized in that: It comprises a memory and a processor; the memory is used to store program code; the processor is used to call the program code to execute the method according to any one of claims 1-6.
8. A computer-readable storage medium, characterized in that: The method comprises a program code, and when the program code is executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 6.
