Media scanning task execution method, apparatus, equipment and media
By employing a binary search algorithm and concurrent execution mode in the Android system, the slow speed of the native Android media scanning service is solved, resulting in faster loading of media file information.
Patent Information
- Application Number
- CN202410678140.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-28
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2044-05-28
AI Technical Summary
When there are many files on the external storage device, the Android native media scanning service is slow, resulting in slow loading of media file information.
A binary search algorithm is used to traverse the target directory of the external storage device. The parsing thread pool and storage thread concurrent execution mode are used to filter and parse the file information to be parsed, and the database operation objects are processed in batches to generate target identifiers and update the media database.
It improves the speed of media scanning task execution, increases the speed of media file information loading, reduces resource waste, and improves scanning efficiency and database operation efficiency.
Smart Images

Figure CN118331935B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of multimedia playback technology, and in particular to a method, apparatus, device, and medium for performing media scanning tasks. Background Technology
[0002] Android, with its open-source nature, high scalability, and rich ecosystem, has become the preferred operating system for current IVI systems (In-Vehicle Infotainment systems). Media scanning service is a crucial component of the Android multimedia system. When the Android system boots up or an external storage device is connected, the system scans the media files in the corresponding storage space of the external storage device and stores the relevant information in the vehicle's media database. Upper-layer applications can directly query the media database to retrieve multimedia file information and display it to the user as needed.
[0003] Android's native media scanning service is deployed in the system as an app (MediaProvider.apk). The current main technical solution for this service is as follows: When the vehicle's infotainment system powers on or an external storage device is connected, it receives a media scanning broadcast and initiates a scanning service for the storage space. A unique identifier ID is generated for the first-time connection to the external storage device. The scanning service then traverses the directories in the storage space, parses each file in the directory, and performs media database operations on the file data under that identifier ID. However, when there are many files on the external storage device, the Android native media scanning service in the vehicle's infotainment system is slow to scan, which in turn leads to slow loading of media file information.
[0004] In summary, improving the execution speed of media scanning tasks to increase the loading speed of media file information is a problem that needs to be solved in this field. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a media scanning task execution method, apparatus, device, and medium to improve the media scanning task execution speed and thus increase the media file information loading speed. The specific solution is as follows:
[0006] Firstly, this application discloses a method for performing a media scanning task, including:
[0007] The media scanning service is triggered based on the connection operation of the external storage device, and the binary search algorithm is used to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory.
[0008] Obtain the first file information of each media file in the target subdirectory, filter out the file information to be parsed that does not match the file information currently stored in the media database from the first file information, and store the file information to be parsed in the first queue;
[0009] The file information to be parsed is obtained from the first queue and stored in the parsing thread pool so that the parsing thread pool can parse the file information to obtain parsed file information. The parsed file information is then used to generate a database operation object using the storage thread, and the database operation object is stored in the second queue. The parsing thread pool and the storage thread are executed in a concurrent execution mode.
[0010] The database operation objects in the second queue are sequentially saved to the operation array, and the copies in the operation array are processed in batches to generate target identifiers corresponding to the copies. The target identifiers are then saved to the third queue.
[0011] The media file information in the media database is updated based on the target identifier in the third queue to complete the media scanning task.
[0012] Optionally, the media scanning task execution method further includes:
[0013] Receive device start command from vehicle-mounted equipment;
[0014] The data maintenance service is activated according to the device startup command, so that the data maintenance service can clean up the target media data in the media database when the vehicle device is in the target state.
[0015] Optionally, cleaning the target media data in the media database includes:
[0016] Based on a preset time interval, target media data with an unused time greater than a first preset threshold is selected from the media database, and the target media data is then cleaned up.
[0017] Optionally, the step of using a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory includes:
[0018] The current subdirectory is determined in the target directory of the external storage device, and a binary search algorithm is used to determine whether the current subdirectory exists in the preset scanning strategy file;
[0019] If the current subdirectory does not exist in the preset scanning strategy file, then the current subdirectory is determined to be the target subdirectory.
[0020] Optionally, after determining whether the current subdirectory exists in the preset scanning strategy file using the binary search algorithm, the method further includes:
[0021] If the current subdirectory exists in the preset scanning strategy file, then determine whether the current subdirectory exists in the preset non-scanned directory list;
[0022] If the current subdirectory exists in the preset non-scanned directory list, then the current subdirectory is determined to be the target subdirectory;
[0023] If the current subdirectory does not exist in the preset non-scanned directory list, then determine whether the preset non-scanned directory list is empty;
[0024] If the preset non-scanned directory list is empty, then the current subdirectory is determined to be the target subdirectory;
[0025] If the preset non-scanned directory list is not empty, then it is determined whether the current subdirectory exists in the preset forced scanned directory list. If the current subdirectory exists in the preset forced scanned directory list, then the current subdirectory is determined to be the target subdirectory.
[0026] Optionally, the step of filtering out file information to be parsed that does not match the file information currently stored in the media database from the first file information includes:
[0027] The first file information is divided into first media file information and second media file information; wherein, the first media file information is the corresponding media file information that does not exist in the media database, and the second media file information is the corresponding media file information that exists in the media database;
[0028] Determine the second file information stored in the media database that corresponds to the second media file information, and filter out the third media file information that is inconsistent with the second file information from the second media file information;
[0029] The first media file information and the third media file information are identified as the file information to be parsed.
[0030] Optionally, the step of sequentially saving copies of the database operation objects in the second queue to the operation array includes:
[0031] The current database operation object in the second queue is copied to obtain a copy of the current database operation object, the copy is saved to the operation array, and the current database operation object is deleted from the second queue.
[0032] Accordingly, the batch processing of the copies in the operation array to generate a target identifier corresponding to the copy, and saving the target identifier to the third queue, includes:
[0033] Determine whether the current condition is met; wherein, the preset condition is that all the files to be parsed in the first queue have been parsed and the second queue is empty;
[0034] If the current preset condition is not met, the number of replicas currently stored in the operation array is determined. If the number of replicas is equal to the second preset threshold, all replicas in the operation array are processed to generate a target identifier corresponding to each replica. The target identifier is saved to the third queue, and then the operation array is cleared. If the number of replicas is less than the second preset threshold, the process jumps back to the step of determining whether the current preset condition is met.
[0035] If the preset conditions are met, all copies in the operation array are processed to save the generated target identifier to the third queue, and then the operation array is cleared.
[0036] Secondly, this application discloses a media scanning task execution device, comprising:
[0037] The directory scanning module is used to trigger the media scanning service based on the connection operation of the external storage device, and to use a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory.
[0038] The information filtering module is used to obtain the first file information of each media file in the target subdirectory, filter out the file information to be parsed from the first file information that does not match the file information currently stored in the media database, and store the file information to be parsed in the first queue;
[0039] The information parsing module is used to obtain the file information to be parsed in the first queue and store it in the parsing thread pool so that the parsing thread pool can parse the file information to be parsed to obtain parsed file information. The parsed file information is then stored in the second queue as a database operation object using the storage thread. The parsing thread pool and the storage thread are executed in a concurrent execution mode.
[0040] The identifier generation module is used to sequentially save the copies of the database operation objects in the second queue to the operation array, and batch process the copies in the operation array to generate target identifiers corresponding to the copies, and save the target identifiers to the third queue;
[0041] The information update module is used to update the media file information in the media database based on the target identifier in the third queue in order to complete the media scanning task.
[0042] Thirdly, this application discloses an electronic device, including:
[0043] Memory, used to store computer programs;
[0044] A processor is configured to execute the computer program to implement the steps of the aforementioned disclosed media scanning task execution method.
[0045] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed media scanning task execution method.
[0046] The beneficial effects of this application are as follows: This application triggers a media scanning service based on the connection operation of an external storage device, and uses a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory; obtains the first file information of each media file in the target subdirectory, and filters out the file information to be parsed that does not match the file information currently stored in the media database from the first file information, and stores the file information to be parsed in a first queue; obtains the file information to be parsed in the first queue and stores it in a parsing thread pool so that the parsing thread pool can parse the file information to be parsed to obtain parsed file information, uses a storage thread to generate a database operation object from the parsed file information, and stores the database operation object in a second queue; wherein, the execution mode of the parsing thread pool and the storage thread is a concurrent execution mode; sequentially saves copies of the database operation objects in the second queue to an operation array, and processes the copies in the operation array in batches to generate a target identifier corresponding to the copy, and saves the target identifier to a third queue; updates the media file information in the media database based on the target identifier in the third queue to complete the media scanning task. Therefore, it can be seen that after starting the media scanning service, this application uses a binary search algorithm to traverse and scan each subdirectory in the target directory, which can speed up the directory scanning speed. Furthermore, this application uses a parsing thread pool and a storage thread to complete the parsing of the file information to be parsed. The multi-threaded concurrent processing method can improve scanning efficiency. Batch processing of the copies in the operation array can reduce resource waste and improve processing efficiency compared with the scattered processing in the prior art. In this way, this application can improve the execution speed of media scanning tasks, thereby improving the loading speed of media file information. Attached Figure Description
[0047] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0048] Figure 1 This is a flowchart of a media scanning task execution method disclosed in this application;
[0049] Figure 2 This is a schematic diagram illustrating a specific example of redundant data cleanup disclosed in this application;
[0050] Figure 3 This application discloses a specific catalog scanning flowchart;
[0051] Figure 4 This application discloses a specific document information filtering flowchart;
[0052] Figure 5 This is a schematic diagram of a specific document information parsing process disclosed in this application;
[0053] Figure 6 This application discloses a specific flowchart for generating an identifier;
[0054] Figure 7 This is a schematic diagram of the structure of a media scanning task execution device disclosed in this application;
[0055] Figure 8 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0056] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0057] Android's open-source nature, high scalability, and rich ecosystem make it the preferred operating system for current IVI systems. Media scanning service is a crucial component of the Android multimedia system. When the Android system boots up or an external storage device is connected, the system scans the media files in the corresponding storage space of the external storage device and stores the relevant information in the vehicle's media database. Upper-layer applications can directly query the media database to retrieve multimedia file information and display it to the user as needed.
[0058] Android's native media scanning service is deployed in the system as an app (MediaProvider.apk). The current main technical solution for this service is as follows: When the vehicle's infotainment system powers on or an external storage device is connected, it receives a media scanning broadcast and initiates a scanning service for the storage space. A unique identifier ID is generated for the newly connected external storage device. The scanning service traverses the directories in the storage space, parses each file in the directory, and then performs media database operations on the file data under that identifier ID. However, when there are many files on the external storage device, the Android native media scanning service in the vehicle's infotainment system is slow to scan, which in turn leads to slow loading of media file information.
[0059] Therefore, this application provides a media scanning task execution scheme to improve the media scanning task execution speed and thus increase the media file information loading speed.
[0060] See Figure 1 As shown in the figure, this application discloses a media scanning task execution method, including:
[0061] Step S11: Trigger media scanning service based on connection operation of external storage device, and use binary search algorithm to traverse and scan each subdirectory in target directory of external storage device to obtain target subdirectories.
[0062] The media scanning service is started based on the connection operation of the external storage device. When the external storage device is connected to the Android vehicle device, it will receive the MEDIA_MOUNTED (media has been mounted) broadcast, and the media scanning service will be started at this time.
[0063] This embodiment further includes: receiving a device startup command from the vehicle-mounted device; and activating a data maintenance service according to the device startup command, so that the data maintenance service cleans up the target media data in the media database when the vehicle-mounted device is in a target state. For example... Figure 2The diagram illustrates a specific example of redundant data cleanup. Upon receiving a device startup command, a data maintenance service is initiated. This service cleans up target media data in the media database when the device is in a target state, i.e., cleans up redundant data. The target state is when the vehicle-mounted device is charging and idle. This improves the reliability and effectiveness of media data, reduces redundant data and the size of the media database, thereby increasing the efficiency of media database operations. Performing redundant data cleanup while the vehicle-mounted device is charging and idle avoids the data maintenance service preempting the device's computing resources when processing other tasks.
[0064] In this embodiment, cleaning the target media data in the media database includes: filtering target media data from the media database whose unused time exceeds a first preset threshold based on a preset time interval, and then cleaning the target media data. Target media data whose unused time exceeds the first preset threshold can be filtered from the media database based on a preset time interval and then cleaned. For example, a data maintenance service performs redundant data cleanup every two hours. The purpose of the data maintenance service is to clean up redundant data in the media database, which exists in the FILES table of the media database. Redundant data can be data stored in the media database on storage devices that have not been used for a long period of time since their first use, or expired content data stored in the FILES table.
[0065] In this embodiment, the step of using a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory includes: determining the current subdirectory in the target directory of the external storage device, and using a binary search algorithm to determine whether the current subdirectory exists in a preset scanning strategy file; if the current subdirectory does not exist in the preset scanning strategy file, then the current subdirectory is determined to be the target subdirectory. The preset scanning strategy file is an XML format configuration file that sets the scanning strategy used during the media scanning service's scanning process. This file includes a preset non-scanned directory list and a preset non-scanned directory list. The process involves traversing and scanning each subdirectory in the target directory, sequentially taking each subdirectory as the current subdirectory, and using a binary search algorithm to determine whether the current subdirectory exists in the preset scanning strategy file; if the current subdirectory does not exist in the preset scanning strategy file, then the current subdirectory is determined to be the target subdirectory.
[0066] In this embodiment, after determining whether the current subdirectory exists in the preset scanning strategy file using the binary search algorithm, the method further includes: if the current subdirectory exists in the preset scanning strategy file, then determining whether the current subdirectory exists in the preset non-scanned directory list; if the current subdirectory exists in the preset non-scanned directory list, then determining that the current subdirectory is the target subdirectory; if the current subdirectory does not exist in the preset non-scanned directory list, then determining whether the preset non-scanned directory list is empty; if the preset non-scanned directory list is empty, then determining that the current subdirectory is the target subdirectory; if the preset non-scanned directory list is not empty, then determining whether the current subdirectory exists in the preset forced scanning directory list; if the current subdirectory exists in the preset forced scanning directory list, then determining that the current subdirectory is the target subdirectory. For example... Figure 3 The diagram shows a specific directory scanning flowchart. The specific directory scanning process is as follows:
[0067] 1) If the current subdirectory exists in the preset scanning strategy file, then determine whether the current subdirectory exists in the preset non-scanned directory list;
[0068] 2) If the current subdirectory exists in the preset non-scanned directory list, then the current subdirectory is determined to be the target subdirectory;
[0069] 3) If the current subdirectory does not exist in the preset non-scanned directory list, then determine whether the preset non-scanned directory list is empty;
[0070] 3.1) If the preset non-scanned directory list is empty, then the current subdirectory is determined to be the target subdirectory;
[0071] 3.2) If the preset non-scanned directory list is not empty, then determine whether the current subdirectory exists in the preset forced scanned directory list;
[0072] 3.2.1) If the current subdirectory exists in the preset forced scan directory list, determine the current subdirectory as the target subdirectory;
[0073] 3.2.2) If the current subdirectory does not exist in the preset forced scan directory list, the current subdirectory is determined to be a non-target subdirectory;
[0074] Understandably, after determining whether the current subdirectory is the target subdirectory or not, it is necessary to determine the next subdirectory from the target directory, and then repeat the above process until all subdirectories have been scanned, that is, to obtain the judgment result for each subdirectory.
[0075] In this embodiment, a singleton pattern is used to read the preset scanning strategy file. After receiving and starting the media scanning operation, the preset scanning strategy file will be used to determine whether the current subdirectory needs to be traversed and scanned. The parsing of the preset scanning strategy file uses a binary search method to search whether the scan directory exists in the directory strategy of the configuration file, skipping subdirectories that do not need to be scanned, thus speeding up the media scanning speed for the vehicle's built-in storage space.
[0076] Step S12: Obtain the first file information of each media file in the target subdirectory, and based on the first file information, filter out the files to be parsed that do not match the files currently stored in the media database from each of the media files, and store the files to be parsed in the first queue.
[0077] In this embodiment, the step of filtering out file information to be parsed that does not match the file information currently stored in the media database from the first file information includes: dividing the first file information into first media file information and second media file information; wherein, the first media file information is corresponding media file information that does not exist in the media database, and the second media file information is corresponding media file information that exists in the media database; determining the second file information stored in the media database that corresponds to the second media file information, and filtering out third media file information that is inconsistent with the second media file information from the second media file information; and determining the first media file information and the third media file information as file information to be parsed.
[0078] The process retrieves the initial file information for each media file in the target subdirectory. This initial file information includes the size, path, and creation time of each media file. First, this initial file information is divided into two categories: first media file information and second media file information. The first media file information consists of media files whose corresponding information does not exist in the media database. The second media file information consists of media files whose corresponding information exists in the media database. For example, if the first file information is information A, information B, information C, and information D, and the media database contains information a, information b, information c, and information f, then information A, information B, and information C correspond to information a, information b, and information c, respectively. Information corresponding to information D exists; therefore, the first media file information is information D, and the second media file information is information A, information B, and information C. The second file information is information a, information b, and information c. Next, information that is different from the media database is identified from the second media file information, which is the third media file information. For example, although information a in the second file information corresponds to information A, information a is different from information A. However, information b and information c in the second file information are the same as information B and information C, respectively. Therefore, information A is the third media file information. Finally, the first media file information and the third media file information are identified as the file information to be parsed, that is, information D and information A are identified as the file information to be parsed.
[0079] For example Figure 4 The flowchart shown illustrates a specific file information filtering process, which sequentially identifies each media file in the target subdirectory as the current media file. The specific process is as follows:
[0080] 1) Determine whether the media database contains information about the current second file that corresponds to the information about the current first file;
[0081] 2) If the media database does not contain information about the current second file, then the information about the current first file is used as the file information to be parsed and saved to the first queue;
[0082] 3) If the media database stores the information of the current second file, then determine whether the information of the current first file matches the information of the current second file;
[0083] 4) If a match is found, the current first file information is determined to be non-file information to be parsed, that is, the current first file information does not need to be saved to the first queue; if no match is found, the current first file information is treated as file information to be parsed and saved to the first queue.
[0084] 5) If there are untraversed file information, continue traversing; if there are no untraversed file information, complete the file information filtering process.
[0085] Step S13: Obtain the file information to be parsed from the first queue and store it in the parsing thread pool so that the parsing thread pool can parse the file information to be parsed and obtain the parsed file information. Use the storage thread to generate a database operation object from the parsed file and store the database operation object in the second queue; wherein, the execution mode of the parsing thread pool and the storage thread is concurrent execution mode.
[0086] For example Figure 5 The diagram illustrates a specific file information parsing process. In this embodiment, multiple threads are created using the singleton pattern: a parsing thread pool and a storage thread. The parsing thread pool and storage thread execute concurrently. The configuration resources are read using the singleton pattern, and a producer-consumer pattern is used to ensure data synchronization between threads. The specific file information parsing process is as follows:
[0087] 1) Sequentially retrieve the information of each file to be parsed in the first queue, and then store each file information to be parsed in the parsing thread pool in sequence until all the file information to be parsed in the first queue has been retrieved; when scanning the file information to be parsed, you can always scan the first file information in the first queue, add the first file information to be parsed to the parsing thread pool, and then delete the first file information to be parsed from the first queue, that is, the original second file information to be parsed becomes the new first file information to be parsed;
[0088] 2) The parsing thread pool is responsible for parsing the received file information in turn to obtain the parsed file information; it can be understood that the parsing operation of the media scanning service adopts the thread pool method, and the number of threads opened in the parsing operation thread pool can be configured.
[0089] 3) When the storage thread detects the existence of parsed file information, it generates a database operation object from the parsed file information and stores the database operation object in the second queue;
[0090] 4) When the parsing thread pool does not have any file information to be parsed, and the storage thread stores all parsed file information into the second queue, the file information parsing process ends.
[0091] Step S14: Sequentially save the copies of the database operation objects in the second queue to the operation array, and batch process the copies in the operation array to generate target identifiers corresponding to the copies, and save the target identifiers to the third queue.
[0092] In this embodiment, the step of sequentially saving copies of the database operation objects in the second queue to the operation array includes: copying the current database operation object in the second queue to obtain a copy of the current database operation object, saving the copy to the operation array, and deleting the current database operation object from the second queue. This process is repeated sequentially, copying each database operation object, saving the copied copy to the operation array, and deleting database operation objects with existing copies from the second queue, until the second queue is empty and all files to be parsed in the first queue have been parsed. For example, each time, the first database operation object in the second queue is identified as the current database operation object, then the current database operation object is copied, the copied copy is saved to the operation array, and the current database operation object is deleted.
[0093] In this embodiment, the step of batch processing the copies in the operation array to generate target identifiers corresponding to the copies and saving the target identifiers to a third queue includes: determining whether a preset condition is currently met; wherein, the preset condition is that all files to be parsed in the first queue have been parsed and the second queue is empty; if the preset condition is not currently met, then the number of copies currently stored in the operation array is determined; if the number of copies is equal to a second preset threshold, then all copies in the operation array are processed to generate target identifiers corresponding to each copy, the target identifiers are saved to the third queue, and then the operation array is cleared; if the number of copies is less than the second preset threshold, then the process jumps back to the step of determining whether the preset condition is currently met; if the preset condition is currently met, then all copies in the operation array are processed to save the generated target identifiers to the third queue, and then the operation array is cleared. Figure 6The flowchart illustrates a specific identifier generation process. If the parsed file information in the first queue has not been completely parsed and the second queue is not empty, then it is determined whether the number of currently stored replicas in the operation array is equal to a second preset threshold, for example, 32. If the number of replicas is equal to 32, then all replicas in the operation array are processed to generate target identifiers corresponding to each replica, and the target identifiers are saved to the third queue, and then the operation array is cleared. If the number of replicas is less than 32, then the step of determining whether the current condition is met is re-entered. If the current condition is met, then all replicas in the operation array are processed to save the generated target identifiers to the third queue, and then the operation array is cleared. In other words, in this embodiment, for example, replicas in the operation array are processed in groups of 32. When the parsed file information in the first queue has been completely parsed and the second queue is empty, it means that all the parsed file information has been parsed, and there are no database operation objects to be scanned in the second queue. Therefore, even if the number of replicas in the operation array is less than 32, these replicas can be processed in batches. This embodiment can avoid the resource waste caused by processing replicas in a scattered manner, thus saving resources.
[0094] Step S15: Update the media file information in the media database based on the target identifier in the third queue to complete the media scanning task.
[0095] When an external storage device is moved, there may be a situation in the media database where the data is still there but the media file information is no longer available. The target identifier stored in the third queue is consistent with the actual media file information. That is, the target identifier stored in the third queue is the latest and most reliable. Therefore, updating the media file information in the media database based on the target identifier, such as by performing deletion or modification operations, can ensure that the media file information stored in the media database is consistent with the actual media file information, thus guaranteeing the reliability and validity of the data in the media database.
[0096] The beneficial effects of this application are as follows: This application triggers a media scanning service based on the connection operation of an external storage device, and uses a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory; obtains the first file information of each media file in the target subdirectory, and filters out the file information to be parsed that does not match the file information currently stored in the media database from the first file information, and stores the file information to be parsed in a first queue; obtains the file information to be parsed in the first queue and stores it in a parsing thread pool so that the parsing thread pool can parse the file information to be parsed to obtain parsed file information, uses a storage thread to generate a database operation object from the parsed file information, and stores the database operation object in a second queue; wherein, the execution mode of the parsing thread pool and the storage thread is a concurrent execution mode; sequentially saves copies of the database operation objects in the second queue to an operation array, and processes the copies in the operation array in batches to generate a target identifier corresponding to the copy, and saves the target identifier to a third queue; updates the media file information in the media database based on the target identifier in the third queue to complete the media scanning task. Therefore, it can be seen that after starting the media scanning service, this application uses a binary search algorithm to traverse and scan each subdirectory in the target directory, which can speed up the directory scanning speed. Furthermore, this application uses a parsing thread pool and a storage thread to complete the parsing of the file information to be parsed. The multi-threaded concurrent processing method can improve scanning efficiency. Batch processing of the copies in the operation array can reduce resource waste and improve processing efficiency compared with the scattered processing in the prior art. In this way, this application can improve the execution speed of media scanning tasks, thereby improving the loading speed of media file information.
[0097] See Figure 7 As shown in the figure, this application discloses a media scanning task execution device, including:
[0098] The directory scanning module 11 is used to trigger the media scanning service based on the connection operation of the external storage device, and use a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory.
[0099] Information filtering module 12 is used to obtain the first file information of each media file in the target subdirectory, filter out the file information to be parsed from the first file information that does not match the file information currently stored in the media database, and store the file information to be parsed in the first queue;
[0100] The information parsing module 13 is used to obtain the file information to be parsed in the first queue and store it in the parsing thread pool so that the parsing thread pool can parse the file information to be parsed to obtain parsed file information, and use the storage thread to store the parsed file information as a database operation object in the second queue; wherein, the execution mode of the parsing thread pool and the storage thread is the concurrent execution mode;
[0101] The identifier generation module 14 is used to sequentially save the copies of the database operation objects in the second queue to the operation array, and batch process the copies in the operation array to generate target identifiers corresponding to the copies, and save the target identifiers to the third queue;
[0102] The information update module 15 is used to update the media file information in the media database based on the target identifier in the third queue in order to complete the media scanning task.
[0103] The beneficial effects of this application are as follows: This application triggers a media scanning service based on the connection operation of an external storage device, and uses a binary search algorithm to traverse and scan each subdirectory in the target directory of the external storage device to obtain the target subdirectory; obtains the first file information of each media file in the target subdirectory, and filters out the file information to be parsed that does not match the file information currently stored in the media database from the first file information, and stores the file information to be parsed in a first queue; obtains the file information to be parsed in the first queue and stores it in a parsing thread pool so that the parsing thread pool can parse the file information to be parsed to obtain parsed file information, uses a storage thread to generate a database operation object from the parsed file information, and stores the database operation object in a second queue; wherein, the execution mode of the parsing thread pool and the storage thread is a concurrent execution mode; sequentially saves copies of the database operation objects in the second queue to an operation array, and processes the copies in the operation array in batches to generate a target identifier corresponding to the copy, and saves the target identifier to a third queue; updates the media file information in the media database based on the target identifier in the third queue to complete the media scanning task. Therefore, it can be seen that after starting the media scanning service, this application uses a binary search algorithm to traverse and scan each subdirectory in the target directory, which can speed up the directory scanning speed. Furthermore, this application uses a parsing thread pool and a storage thread to complete the parsing of the file information to be parsed. The multi-threaded concurrent processing method can improve scanning efficiency. Batch processing of the copies in the operation array can reduce resource waste and improve processing efficiency compared with the scattered processing in the prior art. In this way, this application can improve the execution speed of media scanning tasks, thereby improving the loading speed of media file information.
[0104] Furthermore, embodiments of this application also provide an electronic device. Figure 8 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0105] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the media scanning task execution method performed by the electronic device disclosed in any of the foregoing embodiments.
[0106] In this embodiment, the power supply 23 is used to provide operating voltage for various hardware devices on the electronic device; the communication interface 24 can create a data transmission channel between the electronic device and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0107] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0108] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored on it include operating system 221, computer program 222 and data 223, etc., and the storage method can be temporary storage or permanent storage.
[0109] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system can be Windows, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the media scanning task execution method disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the electronic device from external devices, as well as data collected by its own input / output interface 25.
[0110] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned media scanning task execution method. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0111] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0112] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application. The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly in hardware, software modules executed by a processor, or a combination of both. The software module may be located in random access memory (RAM), memory, read-only memory (ROM), electrically programmable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, removable disks, CD-ROMs (Compact Disc Read-Only Memory), or any other form of storage medium known in the art.
[0113] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0114] The present invention has provided a detailed description of a media scanning task execution method, apparatus, device, and medium. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A media scan task execution method, characterized by, The method comprises the following steps: Triggering a media scanning service based on a connection operation of an external storage device, and traversing each subdirectory in a target directory of the external storage device by using a binary search algorithm to obtain a target subdirectory; Obtaining first file information of each media file in the target subdirectory, and screening out to-be-analyzed file information that does not match currently stored file information in a media database from the first file information, and storing the to-be-analyzed file information in a first queue; Obtaining the to-be-analyzed file information in the first queue, and storing the to-be-analyzed file information in an analysis thread pool, so that the analysis thread pool analyzes the to-be-analyzed file information to obtain analyzed file information, generates a database operation object from the analyzed file information by using a storage thread, and stores the database operation object in a second queue; wherein an execution mode of the analysis thread pool and the storage thread is a concurrent execution mode; Saving a copy of the database operation object in the second queue to an operation array in sequence, and batch processing the copy in the operation array to generate a target identifier corresponding to the copy, and saving the target identifier to a third queue; Updating media file information in the media database based on the target identifier in the third queue to complete a media scanning task.
2. The media scanning task execution method according to claim 1, characterized by, The method further comprises the following steps: Receiving a device start instruction of a vehicle machine device; Starting a data maintenance service according to the device start instruction, so that the data maintenance service cleans up target media data in the media database when the vehicle machine device is in a target state.
3. The media scanning task execution method according to claim 2, characterized in that, The cleaning up of the target media data in the media database comprises the following steps: Screening out target media data with a usage time greater than a first preset threshold from the media database based on a preset time interval, and cleaning up the target media data.
4. The media scanning task execution method of claim 1, wherein, The traversing and scanning of each subdirectory in the target directory of the external storage device by using the binary search algorithm to obtain the target subdirectory comprises the following steps: Determining a current subdirectory in the target directory of the external storage device, and judging whether the current subdirectory exists in a preset scanning strategy file by using the binary search algorithm; If the current subdirectory does not exist in the preset scanning strategy file, determining that the current subdirectory is a target subdirectory.
5. The media scanning task execution method according to claim 4, characterized by, After the judgment of whether the current subdirectory exists in the preset scanning strategy file by using the binary search algorithm, the method further comprises the following steps: If the current subdirectory exists in the preset scanning strategy file, judging whether the current subdirectory exists in a preset non-scanning directory list; If the current subdirectory exists in the preset non-scanning directory list, determining that the current subdirectory is a target subdirectory; If the current subdirectory does not exist in the preset non-scanning directory list, judging whether the preset non-scanning directory list is empty; If the preset non-scanning directory list is empty, determining that the current subdirectory is a target subdirectory; If the preset non-scanning directory list is not empty, it is judged whether the preset forced scanning directory list contains the current subdirectory, and if the preset forced scanning directory list contains the current subdirectory, the current subdirectory is determined as a target subdirectory.
6. The media scanning task execution method of claim 1, wherein, The first file information is divided into first media file information and second media file information; wherein the first media file information is corresponding media file information that does not exist in the media database, and the second media file information is corresponding media file information that exists in the media database; The second file information corresponding to the second media file information stored in the media database is determined, and third media file information inconsistent with the second file information is screened from the second media file information; The first media file information and the third media file information are determined as to-be-resolved file information. The copy of the database operation object in the second queue is saved to the operation array in sequence, including:
7. The media scanning task execution method according to any one of claims 1 to 6, characterized by, The current database operation object in the second queue is copied to obtain a copy of the current database operation object, the copy is saved to the operation array, and the current database operation object in the second queue is deleted; Correspondingly, the copies in the operation array are batch processed to generate target identifiers corresponding to the copies, and the target identifiers are saved to a third queue, including: It is judged whether the preset condition is met at present; wherein the preset condition is that all the to-be-resolved files in the first queue have been resolved and the second queue is empty; If the preset condition is not met at present, the number of copies currently stored in the operation array is determined, if the number of copies is equal to a second preset threshold, all the copies in the operation array are processed to generate target identifiers corresponding to each of the copies, the target identifiers are saved to a third queue, and then the operation array is emptied; if the number of copies is less than the second preset threshold, the step of judging whether the preset condition is met at present is re-jumped; If the preset condition is met at present, all the copies in the operation array are processed to save the generated target identifiers to a third queue, and then the operation array is emptied. It includes:
8. A media scanning task execution apparatus characterized by comprising: The directory scanning module is used for triggering a media scanning service based on a connection operation of an external storage device, and traversing and scanning each subdirectory in a target directory of the external storage device by using a binary search algorithm to obtain a target subdirectory. The information screening module is used for obtaining first file information of each media file in the target subdirectory, screening to-be-resolved file information from the first file information, and storing the to-be-resolved file information in a first queue. An information analysis module is configured to acquire the file information to be analyzed in the first queue and store the file information to an analysis thread pool, so that the analysis thread pool analyzes the file information to be analyzed to obtain analyzed file information, and a storage thread stores the analyzed file information as a database operation object to a second queue; wherein the execution mode of the analysis thread pool and the storage thread is a concurrent execution mode. An identifier generation module is configured to sequentially save a copy of the database operation object in the second queue to an operation array, batch-process the copy in the operation array, generate a target identifier corresponding to the copy, and save the target identifier to a third queue. An information updating module is configured to update media file information in the media database based on the target identifier in the third queue to complete a media scanning task.
9. An electronic device, comprising: The media scanning task execution method comprises the following steps: A memory is configured to save a computer program; A processor is configured to execute the computer program to implement the steps of the media scanning task execution method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, A computer program is stored in the memory, and the computer program is executed by the processor to implement the steps of the media scanning task execution method according to any one of claims 1 to 7.
Citation Information
Patent Citations
File scanning method and device, terminal equipment and storage medium
CN114706825A
Depth first search of summary change log records for backup
US10061654B1