WO2018006833A1 - 可变长编码文件的解码方法以及装置 - Google Patents

可变长编码文件的解码方法以及装置 Download PDF

Info

Publication number
WO2018006833A1
WO2018006833A1 PCT/CN2017/091866 CN2017091866W WO2018006833A1 WO 2018006833 A1 WO2018006833 A1 WO 2018006833A1 CN 2017091866 W CN2017091866 W CN 2017091866W WO 2018006833 A1 WO2018006833 A1 WO 2018006833A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
decoded
decoding
index information
threshold
Prior art date
Application number
PCT/CN2017/091866
Other languages
English (en)
French (fr)
Inventor
徐羽琼
周振坤
余涛
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to BR112018077468A priority Critical patent/BR112018077468A2/pt
Priority to EP17823645.1A priority patent/EP3468047A4/en
Priority to KR1020197001291A priority patent/KR102147633B1/ko
Publication of WO2018006833A1 publication Critical patent/WO2018006833A1/zh
Priority to US16/241,058 priority patent/US11284119B2/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/90Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using coding techniques not provided for in groups H04N19/10-H04N19/85, e.g. fractals
    • H04N19/91Entropy coding, e.g. variable length coding [VLC] or arithmetic coding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/42Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by implementation details or hardware specially adapted for video compression or decompression, e.g. dedicated software implementation
    • H04N19/436Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by implementation details or hardware specially adapted for video compression or decompression, e.g. dedicated software implementation using parallelised computational arrangements
    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M7/00Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
    • H03M7/30Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction
    • H03M7/40Conversion to or from variable length codes, e.g. Shannon-Fano code, Huffman code, Morse code
    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M7/00Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
    • H03M7/30Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction
    • H03M7/40Conversion to or from variable length codes, e.g. Shannon-Fano code, Huffman code, Morse code
    • H03M7/42Conversion to or from variable length codes, e.g. Shannon-Fano code, Huffman code, Morse code using table look-up for the coding or decoding process, e.g. using read-only memory
    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M7/00Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
    • H03M7/30Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction
    • H03M7/60General implementation details not specific to a particular type of compression
    • H03M7/6017Methods or arrangements to increase the throughput
    • H03M7/6023Parallelization
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/44Decoders specially adapted therefor, e.g. video decoders which are asymmetric with respect to the encoder
    • H04N19/45Decoders specially adapted therefor, e.g. video decoders which are asymmetric with respect to the encoder performing compensation of the inverse transform mismatch, e.g. Inverse Discrete Cosine Transform [IDCT] mismatch
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/60Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using transform coding

Definitions

  • Embodiments of the present invention relate to a computer decoding method, and in particular, to a decoding method and apparatus for a variable length encoded file.
  • JPEG Joint Photographic Experts Group
  • the JPEG-based image uses variable-length Huffman entropy encoding, so you can get better images with less disk space. quality.
  • the pictures generated by taking pictures of mobile phones, cameras, etc. are all in JPEG format by default.
  • the images saved by most of the retouching software are also JPEG format by default.
  • Increasing the decoding speed of JPEG images can significantly improve the user's picture browsing experience.
  • mobile terminals mainly use two methods to complete the decoding of JPEG pictures: the first one is hardware decoding, that is, a special hardware chip is set in the mobile terminal to complete decoding of JPEG pictures, such as Apple iOS device; the second is software decoding.
  • Hardware decoding has the advantage of fast decoding speed, but it needs to add additional chips for decoding in the device, which will increase the cost of the device. Therefore, there is an urgent need for a technology that can speed up the decoding of software in order to enhance the user's picture browsing experience without increasing the production cost of the device.
  • the software decoding process of JPEG pictures mainly includes three processes: Huffman entropy decoding, inverse discrete cosine transform and color conversion. Among them, the two processes of inverse discrete cosine transform and color conversion can well support parallelization and multi-thread processing.
  • Huffman entropy coding is a kind of Variable-Length Coding (VLC). When decoding, it is impossible to find the decoding boundary and multi-thread parallel processing. Therefore, only single-thread serial decoding can usually be used.
  • the embodiment of the invention provides a decoding method and device for a variable length coded file, which is used to improve the speed of file decoding, and at the same time avoid the system jamming phenomenon which may be caused when the file is decoded.
  • Metadata Generalized metadata refers to data that describes data.
  • the metadata of a file can be stored independently of the file, or it can be stored inside the file, such as the file header or the end of the file.
  • Metadata file A file that stores metadata.
  • the metadata file corresponding to a file refers to storing the file.
  • the metadata file, the file and the metadata file for the file are two different files.
  • Database file A file that holds database data.
  • a SQL Server database provides a file with a .mdf suffix.
  • System file A file that stores the main data of the operating system. Users cannot directly modify it.
  • a metadata file for a Linux system For example, a metadata file for a Linux system.
  • the metadata file of the Linux system includes some metadata files for describing the characteristics of the user file, and the metadata file has an association relationship with the user file described by the metadata file.
  • User file A file created directly by the user or application and can be modified directly by the user.
  • the file to be decoded mentioned in the embodiment of the present invention is usually a user file, for example, a picture file obtained after the user takes a picture with the terminal device.
  • File stream A form of storage of image files or other types of files in computer memory. Data addition, data deletion, data modification, encoding, and/or decoding of the file are performed by operations on the file stream. Before a file is decoded, the file is first loaded into the computer's memory. Therefore, decoding a file may also be referred to as decoding the file stream corresponding to the file.
  • Parallel decoding Multiple (at least two) threads simultaneously perform decoding operations on data in the above file stream.
  • MCU Minimum Coded Unit
  • the smallest processing unit is an MCU, usually a 16*16 pixel matrix, but some image formats (such as grayscale) may also be 8*8 pixel point matrix.
  • a normal-sized JPEG image usually contains thousands of MCUs, that is, the file stream to be decoded corresponding to this picture contains information of thousands of encoded MCUs. Since JPEG uses variable-length Huffman coding, the length of the same-sized MCU after encoding is unknown, and may be the same or different.
  • the data in the above file stream contains a plurality of (at least two) data segments, and in the parallel decoding process, the plurality of data segments are respectively subjected to decoding operations by a plurality of threads. If parallel decoding is performed in units of MCUs, there are too many threads to be started at the same time. Therefore, in general, one of the above data segments includes multiple MCUs, so that the number of threads that need to be simultaneously started can be reduced.
  • Decoding boundary The boundary between the above data segments is the decoding boundary. Specifically, the decoding boundary may be the starting position of each data segment. More specifically, in some embodiments, the decoding boundary is the first MCU included in each data segment. It should be noted that the first MCU of the entire file stream, that is, the first position of the file, although not the boundary between the two data segments, is also a decoding boundary in some embodiments of the present invention.
  • the pre-index information includes information indicating one or more decoding boundaries, and may also include some other information according to the actual needs of the decoding.
  • the information of the decoding boundary is the offset location information of the decoding boundary in the file stream. More specifically, in a file stream to be decoded, the information of the decoding boundary may be the offset position information of the first MCU included in each data segment in the file stream.
  • the data segments decoded in parallel are usually obtained according to the decoding boundary after the decoding boundary is determined, but the number of data segments to be divided (and the number of decoding boundaries related to the number), that is, decoding is performed in parallel. The number of threads can be determined based on information such as the current processing power of the processing resource before the data segment is obtained.
  • Persistent storage Information stored after a computer is powered off or restarted is not lost.
  • Typical persistent storage includes file storage and database storage.
  • an embodiment of the present invention provides a decoding method, which is applicable to decoding a file obtained by variable length coding, such as a JPEG picture.
  • the decoding method includes: reading pre-index information corresponding to the file to be decoded; and performing parallel decoding on the plurality of data segments in the file to be decoded according to the pre-index information.
  • the pre-index information includes information for indicating one or more decoding boundaries, where the plurality of data segments are based on the one or more decoding boundaries. One or more divisions.
  • the pre-index information is stored in other files associated with the file to be decoded, in other words, the pre-index information is stored independently of the file to be decoded.
  • the pre-index information may be stored in a metadata file corresponding to the file to be decoded, where the metadata refers to system data corresponding to the file to be decoded, where the metadata file belongs to a system file, and the like.
  • the storage method since it does not involve the operation of copying the entire file, does not need to read and write the hard disk (or other external memory) for the entire file, and only needs to write the pre-index information which is much less than the data amount of the file to the hard disk. Therefore, the I/O operation is effectively reduced, and the system jamming phenomenon which may be caused by decoding is avoided to some extent, especially when the file is large or the file is large, the effect is more remarkable.
  • the other file may also be a database file, where the database may be a local database or a remote database; in other implementations, the other The file may also be a file with the same file name but different suffix name in the same directory as the file to be decoded, and the suffix name of the other file cannot conflict with the existing suffix name.
  • the pre-index information may also be stored at the end of the file to be decoded. Since the file system supports the operation of appending data to the tail, the storage method stored at the end of the file can avoid the copying operation of the file stream corresponding to the entire file, thereby effectively reducing the I/O operation, thereby avoiding decoding to some extent. Possible system stalls.
  • the pre-index information is obtained and stored in the following manner: when the file to be decoded is detected to be opened for the first time, the pre-index information is extracted. And storing the extracted pre-index information.
  • the storage includes persistent storage, and the specific storage location may refer to the storage location of the pre-index information introduced in the foregoing implementation manner.
  • the process of extracting pre-index information includes performing decoding for variable length coding on the file to be decoded.
  • extracting the pre-index information when it is monitored that the file to be decoded is first opened means that the decoding performed when the file is first opened (other decoding methods such as serial decoding or region decoding) is used. ) Extract pre-index information. Since the decoding for the variable length coding is performed when the file is first opened, for the file using the variable length coding, the decoding can be performed to obtain the information of the coding unit, and then the information of the obtained coding unit is obtained. The information of the partial coding unit is selected as the pre-index information.
  • the pre-index information is extracted when the file is first opened, so that there is no additional power consumption and overhead for the system, and the file can be decoded in parallel according to the pre-index information when the file is opened later, and the file is opened later.
  • the decoding speed at the time is the same.
  • the extraction of the pre-index information may also be performed when it is detected that the file to be decoded is added or the file to be decoded is modified.
  • the process of extracting the pre-index information may only perform decoding for variable length encoding without performing all processing of opening a file, such as during JPEG image opening. Inverse discrete cosine transform and color conversion process.
  • the system may be set at the same time, for example, setting the step of extracting the pre-index information when any of the three conditions is satisfied, unless it is known that the file already has pre-index information; or the system may Only one or two of them are set.
  • the system setting performs the step of extracting the pre-index information for the file when it is detected that the file is first opened, and also performs the extraction of the file when the detected file is modified.
  • the step of pre-indexing information, this setting can improve the parallel decoding efficiency of the original file, and can modify the pre-index information in time after the initial file is modified, thereby ensuring the accuracy of the pre-index information, thereby ensuring that the modified file is still Can achieve better parallel decoding efficiency.
  • the computer system may also initiate the extraction operation of the pre-index information by itself.
  • the system may perform pre-index information extraction every fixed time by default, or perform pre-preparation for the x files every time x files are added.
  • x is an integer greater than 2.
  • the number of decoding boundaries that need to be stored is determined based on the processing capabilities of the processing resources prior to pre-indexing information extraction.
  • the processing resources herein include local processing resources of the computer system in which the file to be decoded is located and/or non-local processing resources that the computer system can invoke.
  • the number of threads that can be executed in parallel is determined according to the processing capability of the processing resource; the extracted pre-index information includes information of a decoding boundary equal to the number of the threads. Assuming that the current CPU of the system has 4 cores, the number of threads that can be executed in parallel is 4, then the information of 4 decoding boundaries including the information of the head position of the file or 3 of the header position information of the file can be extracted and stored.
  • the file first position information is the offset position information of the first MCU block in the file.
  • the number of pre-indexed information extracted and stored and the number of threads that can be executed in parallel may be inaccurately equal, only in a similar number. In this way, it is possible to avoid storing information of an excessive number of decoding boundaries, thereby effectively saving storage space.
  • the pre-indexing information corresponding to the file to be decoded is read, when the size of the file to be decoded is greater than a preset first threshold, in some implementations. And performing parallel decoding based on the pre-index information. Specifically, in an implementation manner, first determine whether the size of the file to be decoded is greater than a preset first threshold; and when the size of the file to be decoded is greater than (or greater than or equal to) the preset first At the threshold, the pre-index information corresponding to the file to be decoded is read, and parallel decoding is performed according to the pre-index information; when the size of the file to be decoded is less than or equal to (or less than) the preset first At the threshold, parallel decoding is not performed, but serial decoding is performed.
  • the solution provided by the embodiment of the present invention can first determine the file size, and perform parallel decoding only on the larger file, thereby improving the decoding efficiency of the larger file. At the same time, it also improves the overall resource utilization of the system.
  • the file to be decoded is modified, or the file to be decoded is first time
  • the pre-index information is extracted according to the determination result. Specifically, in an implementation manner, it is determined whether the size of the file to be decoded is greater than a preset first threshold, and only when the size of the file to be decoded is greater than the preset first threshold. Pre-index information.
  • the size of the file to be decoded is less than or equal to the preset first threshold, it is required to perform an operation according to actual requirements of the file: if the file actually needs to be decoded, for example, when the file is first opened, the file is anyway Need to decode, at this time, although the pre-index information is not obtained, but a series of operations such as serial decoding or region decoding are performed on the file to open the file; if the file does not actually need to be decoded, for example, the file is added or modified, then No decoding-related operations can be performed on the file.
  • the step of determining the file size may be performed before the step of extracting the pre-index information and before reading the pre-index information of the file to be decoded.
  • the preset first threshold may be determined according to experience, or may be for a large number of each After the file of the size is decoded, it is determined according to the effect of the decoding, and the threshold does not generally change once it is determined.
  • the preset first threshold may also be corrected according to actual conditions. Specifically, the preset first threshold may be modified by: after each file to be decoded is decoded, recording related information of the file to be decoded, including file size, decoding time, and whether to perform parallel decoding. If the file to be decoded uses parallel decoding, the decoding time is less than a preset second threshold (for example, 1 ms), and the size of the file to be decoded is greater than the preset first threshold, the pre-modification is modified. The first threshold is set to the size of the file to be decoded.
  • a preset second threshold for example, 1 ms
  • the file to be decoded is found to use parallel decoding and the decoding time is too small, it proves that the file using this size has little effect on parallel decoding.
  • the file smaller than this file uses the parallel decoding band. The effect may be smaller. If the size of the file is larger than the first threshold, the first threshold should be set to the size of the file, so that the first threshold can be corrected in time according to the actual situation, thereby further ensuring the system. The overall utilization of resources.
  • some data preparation is required prior to performing parallel decoding on the file to be decoded. Specifically, assuming that the current system can start R threads in parallel, the file stream of the file to be decoded is subjected to a copy operation (only the file stream pointer needs to be copied) to obtain R file streams, so that each thread can see for itself. The data segments in the file stream perform parallel decoding, and finally the execution results of the R threads are synchronized to obtain the final decoding result. This avoids the problem of mutual interference between threads, thus ensuring the correctness of parallel decoding results. Further, the data preparation also includes other data required to prepare the parallel decoding process, such as creating one or more decoding structures.
  • the pre-index information after the pre-index information is acquired, the pre-index information needs to be integrity-verified, and if the verification is passed, the pre-index information is used according to the pre-index information.
  • the decoded file performs the parallel decoding. If the verification fails, the pre-index information may be lost or modified, in which case the decoded file is subjected to serial decoding. This can avoid parallel decoding failure caused by the loss or modification of the pre-index information of the file.
  • the process of parallel decoding at this time includes: determining, according to information of a plurality of decoding boundaries in the pre-index information, a position of each decoding boundary in the file to be decoded; each of the plurality of threads determining a decoding a boundary, and performing decoding from a position of the decoding boundary in the file to be decoded, wherein each thread executes to the next except for the thread in which the last data segment performs decoding (referred to as the last thread) Stops before a decoding boundary, and the last thread executes to the end of the file (or file stream).
  • each thread except the last thread processes P/M (integer) data segments, The last thread processes the remaining portion, where M is the number of threads and P is the number of data segments that can be partitioned according to the decoding boundary, which in some implementations is the number of decoding boundaries.
  • the number of threads performing parallel decoding may be dynamically changed in the course of parallel decoding according to the actual situation of the processing resources. Specifically, dynamically monitor the currently available processors (such as idle cores), and then adjust (eg, increase) the number of threads to further improve decoding efficiency. rate.
  • the embodiment of the present invention further provides a decoding apparatus, including one or more modules that can implement the first aspect or any one of the foregoing first aspects, and each module can perform one or more steps.
  • an embodiment of the present invention further provides a terminal device, where the terminal device includes a processor and a memory, where the memory is used to store a software program, and the processor is configured to read a software program stored in the memory and implement The method provided by the first aspect or any one of the foregoing first aspects.
  • the embodiment of the present invention further provides a computer storage medium, which may be non-volatile, that is, the content is not lost after power off.
  • the storage medium stores a software program that, when read and executed by one or more processors, implements the method provided by the first aspect or any one of the foregoing first aspects.
  • the method and apparatus provided by the embodiments of the present invention are applicable to all picture formats that apply variable length coding (Huffman), and the JPEG picture is a picture format currently applying variable length coding, and other applications may be variable length.
  • the decoding of the coded picture or the decoding of the picture of the variable length code that may occur in the future may be applied to the method provided by the embodiment of the present invention.
  • Other types of files, such as text, audio, video, etc., may be decoded in the same or similar manner as the methods provided by the embodiments of the present invention.
  • FIG. 1 is a schematic structural diagram of a terminal device according to an embodiment of the present invention.
  • FIG. 2 is a diagram showing an example of a decoding method according to an embodiment of the present invention.
  • FIG. 3 is a schematic diagram of a process of acquiring pre-index information in a decoding method according to an embodiment of the present disclosure
  • FIG. 4 is a schematic flowchart of a parallel decoding method according to an embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of a computer system according to an embodiment of the present invention.
  • FIG. 5b is a schematic structural diagram of a 2D engine in the computer system provided in FIG. 5a;
  • 6a-6b are operational timing diagrams of a parallel decoding method according to an embodiment of the present invention.
  • FIGS. 7a-7c are schematic structural diagrams of a decoding apparatus according to an embodiment of the present invention.
  • the decoding method provided by the embodiment of the present invention is mainly applied to a terminal device, which may also be referred to as a user equipment (User Equipment, referred to as "UE"), a mobile station (Mobile Station, referred to as "MS”), and a mobile terminal.
  • UE User Equipment
  • MS Mobile Station
  • RAN radio access network
  • the terminal can be equipped with a radio access network (Radio Access) Network, RAN)
  • Radio Access Radio Access
  • the terminal can be a mobile phone (or "cellular" phone), or a computer with mobile nature, for example, the terminal can also be portable, pocket Mobile, handheld, computer built-in or in-vehicle mobile devices.
  • the decoding method provided by the embodiment of the present invention can be applied to other types of computer systems in addition to the terminal device.
  • the decoding method provided by the embodiment of the present invention utilizes parallel computing capability on a computer
  • the embodiment of the invention realizes the parallel decoding of the variable length coded file at the software level by using the parallel computing capability on the computer, thereby improving the decoding speed of the file.
  • the following embodiment specifically describes the parallel decoding capability of the file provided in the operating system layer of the computer.
  • the operating system layer can provide the parallel decoding capability to the application layer, thereby improving the file decoding speed of the application layer application (for example, a library). To improve the user experience of the app.
  • FIG. 1 is a schematic structural diagram of a terminal device according to an embodiment of the present invention.
  • the terminal device 100 includes a memory 180, a processor 150, and a display device 140.
  • the memory 180 stores a computer program including an operating system program 182, an application 181, and the like.
  • the processor 150 is configured to read a computer program in the memory 180 and then execute a computer program defined method, for example, the processor 150 reads the operating system program 182 to run an operating system on the terminal device 100 and implement various functions of the operating system. Or reading one or more applications 181 to run the application on the terminal device.
  • Processor 150 may include one or more processors.
  • processor 150 may include one or more central processors or include a central processing unit and a graphics processor.
  • the processor 150 includes a plurality of processors, the plurality of processors may be integrated on the same chip, or may each be a separate chip.
  • a processor may include one or more processing cores. The following embodiments are all described by taking multiple cores as an example.
  • the parallel decoding method provided by the embodiments of the present invention may also be applied to a single core processor, and the time sharing of the single core processor is utilized. The working principle performs parallel decoding, and the number of threads performing parallel decoding can be determined according to the current load of the single core processor.
  • the memory 180 also stores other data 183 in addition to the computer program.
  • the other data 183 may include data generated by the operating system 182 or the application 181 after being run, the data including system data (such as operating system configuration parameters) and User data, such as a photo taken by a user, is typical user data, and is also a decoding object of the method provided by the embodiment of the present invention.
  • Memory 180 generally includes memory and external memory.
  • the memory can be random access memory (RAM), read only memory (ROM), and cache (CACHE).
  • the external storage can be a hard disk, a CD, a USB disk, a floppy disk, or a tape drive.
  • Computer programs are typically stored on external storage, and the processor loads the computer program from external memory into memory before processing.
  • the file to be decoded in the embodiment of the present invention is usually stored in the external memory, and the processor loads the file from the external memory into the memory before performing decoding on the processor.
  • the operating system program 182 includes a computer program that can implement the parallel decoding method provided by the embodiment of the present invention, so that after the processor 150 reads the operating system program 182 and runs the operating system, the operating system can be implemented with the present invention.
  • the parallel decoding function provided by the example. Further, the operating system can open the calling interface of the parallel decoding function to the upper layer application, and the processor 150 can read the application 181 from the memory 180 and run the application, for example, a gallery application, and the application can pass the call.
  • the interface calls the parallel decoding function provided in the operating system to achieve parallel decoding of the file.
  • the terminal device 100 may further include an input device 130 for receiving input digital information, character information or contact touch operation/contactless gesture, and generating user settings and function control with the terminal device 100. Off signal input, etc.
  • the input device 130 may include a touch panel 131.
  • the touch panel 131 also referred to as a touch screen, can collect touch operations on or near the user (such as the user's operation on the touch panel 131 or on the touch panel 131 using any suitable object or accessory such as a finger, a stylus, or the like. ), and drive the corresponding connection device according to a preset program.
  • the touch panel 131 may include two parts: a touch detection device and a touch controller.
  • the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information.
  • the processor 150 is provided and can receive commands from the processor 150 and execute them. For example, the user clicks a picture with a finger on the touch panel 131, the touch detection device detects the signal brought by the click, and then transmits the signal to the touch controller, and the touch controller converts the signal.
  • the coordinates are sent to the processor 150, and the processor 150 performs operations such as decoding the picture according to the coordinates and the type of the signal (click or double click), and finally displays the picture on the display panel 141, thereby implementing "opening". image.
  • the touch panel 131 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves.
  • the input device 130 may further include other input devices 132.
  • the other input devices 132 may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like. One or more of them.
  • the terminal device 100 may further include a display device 140 including a display panel 141 for displaying information input by the user or information provided to the user, various menu interfaces of the terminal device 100, and the like, in the embodiment of the present invention. Mainly used to display decoded pictures or other types of files.
  • the display device 140 may include a display panel 141.
  • the display panel 141 may be configured in the form of an LCD (Liquid Crystal Display) or an OLED (Organic Light-Emitting Diode).
  • the touch panel 131 can cover the display panel 141 to form a touch display screen.
  • the terminal device 100 may further include a power source 190 for supplying power to other modules and a camera 160 for taking a photo or video.
  • the terminal device 100 may also include one or more sensors 120, such as acceleration sensors, light sensors, and the like.
  • the terminal device 100 may further include a radio frequency (RF) circuit 110 for performing network communication with the wireless network device, and may further include a WiFi module 170 for performing WiFi communication with other devices.
  • RF radio frequency
  • the following embodiment will describe the decoding method provided by the embodiment of the present invention by taking the decoding of the JPEG picture as an example.
  • the decoding method provided by the embodiment of the present invention can be implemented in the operating system program 182 shown in FIG. 1. It should be understood that the method provided by the embodiments of the present invention is not limited to decoding of JPEG pictures.
  • FIG. 2 is an exemplary diagram of a decoding method according to an embodiment of the present invention.
  • Huffman entropy decoding accounts for more than half of the total time. Because of variable length entropy coding, the starting position of each MCU (Minimum Coded Unit) cannot be perceived before decoding, and parallel decoding cannot be realized. Assuming that there are 100 MCUs (numbered 1-100) in the picture to be decoded, the original Huffman entropy decoding process uses a single-thread serial decoding of the 100 MCUs before using the parallel decoding scheme provided by the embodiment of the present invention.
  • the main idea of the JPEG parallel decoding scheme is to divide the picture to be decoded into multiple data segments, and save the starting point information of each data segment by recording the pre-index information.
  • the solution provided by the embodiment of the present invention performs Huffman serial decoding in advance on the picture to be decoded, and extracts and records the pre-index information obtained by serial decoding.
  • the pre-index information is the number of 4 in the example of Figure 2.
  • the four data segments are MCU sets numbered 1-25, 26-50, 51-75, 76-100, and the starting position information of the four data segments is numbered 1, respectively.
  • 26, 51 and 76 MCU location information in general, the MCU location information is represented by the MCU offset location information in the file stream corresponding to the picture, the offset location information may be the MCU relative file
  • the offset of the first byte can also be the offset of the MCU relative to the first MCU of the file.
  • the threads 1 - 4 can start decoding from the positions of the 4 MCUs in parallel, and perform decoding on the four data segments in parallel, thereby improving the speed of picture decoding.
  • the decoding method provided by the embodiment of the present invention is introduced by a more detailed method.
  • FIG. 3 is a schematic diagram of a process of acquiring pre-index information in a decoding method according to an embodiment of the present invention.
  • Step 201 When it is detected that a picture is first opened, for example, when it is detected that the user clicks on the picture, pre-processing of the picture is started.
  • the "preprocessing” mentioned in the embodiment of the present invention refers to the extraction process of pre-index information.
  • the startup timing of the pre-processing stage may also be when the picture is added or the picture is modified.
  • the operating system monitors the addition or modification of the image, for example, the media provider mechanism of the Android system provides the monitoring function.
  • the new situation of the picture includes taking a picture with a local camera, downloading pictures from the network to the local, copying pictures from other terminal devices to the local, or editing the local pictures and saving them as a new picture; The situation includes the case where the picture content is modified and not saved as another picture.
  • the preprocessing in these two cases may only include serial Huffman entropy decoding.
  • the pre-processing may also be initiated by the operating system.
  • the operating system may perform serial Huffman entropy decoding on the newly added 10 pictures each time the new picture is full. Extract pre-index information.
  • Step 202 Determine whether the picture has pre-index information.
  • the pre-index information is stored in an extended attribute of a file system corresponding to the picture, and the extended attribute of the file system includes a metadata file corresponding to the picture.
  • the pre-index information may also be stored in other types of files or stored at the end of the picture.
  • step 203 If the pre-index information can be read from the metadata file corresponding to the picture, step 203 is performed, where step 203 means that the pre-processing ends and enters the parallel decoding stage; if the pre-index cannot be obtained from the metadata corresponding to the picture If the information or the obtained pre-index information is empty, step 204 is performed.
  • the determining step of step 202 may not be performed, that is, all the pictures are not pre-indexed when the first time is opened.
  • Step 204 Start the original decoding process of the picture.
  • the current picture to be decoded has no pre-index information, and the original decoding process of the picture serial decoding, inverse discrete cosine transform and color conversion will be normally started and executed.
  • Step 205 Determine whether the size of the picture is smaller than a preset threshold. If the size of the picture is smaller than a preset threshold, the preprocessing is ended, that is, the pre-index information is no longer obtained, but the original decoding process of the picture continues. This is done because the picture is also opened and displayed on the display under the user's open command; if the size of the picture is greater than or equal to the preset threshold, then step 206 is continued.
  • Step 205 mainly considers that the small image adopts parallel decoding, and the gain is not large, and it is not necessary to obtain pre-index information, which can effectively save storage space.
  • the step of determining the size of the picture and the original decoding process of initiating the picture may be performed in an exchange order.
  • Step 206 Extract pre-index information.
  • the Huffman serial decoding of the picture is performed after the step 204, and the Huffman serial decoding process generates the offset position information of all the MCU blocks, and the method provided by the embodiment of the present invention
  • the pre-index information used in the example includes offset location information of one or more of the MCU blocks.
  • the pre-index information also needs to include the DC (Direct Current) variable value of the previous MCU block corresponding to the one or more MCU blocks, respectively. Correction of the Huffman decoding result.
  • the decoding boundary includes the first MCU block of the picture. In other embodiments, the decoding boundary may also not include the first MCU block of the picture.
  • the offset position information of the N MCU blocks is obtained by using 1/N of the picture height as an interval, which is assumed to be equivalent to the data amount of each MCU block;
  • the offset position information of the N MCU blocks is obtained by using 1/N of the picture length (the overall offset of the file stream corresponding to the picture) as an interval, and the sum of the offsets of the N MCUs acquired in this manner is obtained. Is the offset of the entire picture.
  • Step 207 Store the extracted pre-index information.
  • the storage may be performed after the extraction of the offset position information of the plurality of MCUs is completed, or the offset position information of one MCU may be extracted, that is, the storage is performed once.
  • the pre-index information can be stored in the metadata file of the picture.
  • the pre-index information can also be inserted into the tail of the picture, the database file associated with the picture, or The image is in the same directory, with the same file name but different suffixes.
  • a field for integrity verification may also be added to the pre-index information before storage.
  • the foregoing storage methods are all persistent storage.
  • the storage is stored in a file on the external storage (such as a hard disk), so that the pre-index information is not lost, but in other embodiments, If the pre-indexed information can be lost, there is no need to force persistent storage to be performed on it.
  • the above storage method avoids the process of copying the entire picture when the pre-index information is inserted into the picture header, thereby effectively reducing the I/O operation, especially when more pictures or single pictures stored in the system are larger.
  • the method of the embodiment of the invention reduces the number of I/O operations, thereby avoiding the phenomenon of stagnation or suspended animation of the system to some extent.
  • the pre-index information is extracted along with the original decoding process of the picture and stored for the next use, so as to avoid adding too much extra power consumption due to the extraction of the pre-index information.
  • steps 206 and 207 may be performed after the original decoding process is completed, or may be performed along with the original decoding process of the picture 204. Specifically, in the process of performing Huffman serial decoding, as the number of decoded MCU blocks increases, the offset position information of the MCU block is extracted according to a preset interval and stored.
  • the foregoing embodiment generally introduces the extraction process of the pre-index.
  • the following takes the difference encoding and Huffman coding as an example to introduce the composition and specific extraction method of the pre-index information.
  • the picture employs differential encoding
  • at least the offset position information of the MCU block and the DC variable value of the last MCU block of the MCU block need to be included in the pre-index information.
  • some other information that needs to be saved may be included, which is not relevant to the embodiment of the present invention and will not be described in detail.
  • the JPEG decoding library (libjpeg) in the Linux system has provided the capability of serial decoding and region decoder, and the index information of all MCU blocks in the picture can be extracted by serial decoding or region decoding.
  • the index information includes the pre-index information required by the embodiment of the present invention. Therefore, the data structure Huffman_offset_data defined by the index information can be used as the data structure used by the pre-indexing scheme.
  • the parameters and meanings of the Huffman_offset_data structure are as shown in Table 1, in which the "data block" refers to the MCU block in the embodiment of the present invention.
  • the index information of all MCU blocks is obtained by the capability provided by the JPEG decoding library, and the index information of each MCU block is stored in the form of the above data structure, and the parameters included in the data structure can be determined according to actual needs.
  • All index information may exist in the form of a two-dimensional array [X, Y], where X represents the line number of the MCU block in the picture, and Y represents the first few of the MCU block in a certain line.
  • the index information of the appropriate number of MCU blocks is selected from the two-dimensional array as needed to compose the pre-index information required for parallel decoding, and the pre-index information is persistently stored.
  • N pieces of pre-index information are selected and stored in an interval of 1/N of the total number of rows of the array.
  • FIG. 4 is a schematic flowchart diagram of a parallel decoding method according to an embodiment of the present invention. After the pre-indexing information of the picture is extracted and stored by the above method, the parallel decoding method provided by the embodiment of the present invention may be used when the picture needs to be decoded again (the user opens the picture again).
  • Step 301 Determine whether the picture to be decoded has pre-index information. If the picture to be decoded has no pre-index information, perform the original decoding process 302. In the embodiment of the present invention, the original decoding process is a serial decoding process. If the picture to be decoded has pre-index information, step 303 is performed.
  • Step 303 Read pre-index information.
  • the information of the decoding boundary included in the read pre-index information is N.
  • the information of the N decoding boundaries corresponds to N data segments that can be processed in parallel in the picture to be decoded.
  • the offset position information of the first MCU block of the picture to be decoded may not be recorded, that is, only N- is recorded.
  • the information of one decoding boundary can obtain N data segments in parallel processing.
  • the manner of reading the pre-indexed information is related to the storage location of the pre-indexed information.
  • the storage location is described in the foregoing embodiment.
  • the corresponding reading mode is the prior art, and is not described in detail in the embodiment of the present invention.
  • step 301 and step 303 can also be combined into a step of determining whether the picture to be decoded has pre-index information by reading the pre-index information, and if the pre-index information can be read, step 304 is directly performed; If the pre-index information is not read or the read result is empty, step 302 is performed.
  • the step of determining the size of the picture to be decoded may be further included before the pre-index information is read. If the size of the picture to be decoded is smaller than a preset threshold, the original decoding process is performed; otherwise, Then, the parallel decoding process is executed after the pre-index information is read, and if the pre-index information is not read, the original decoding process is executed.
  • the size information of the picture to be decoded is stored in the picture header, and the size information of the picture can be obtained by parsing the picture header, specifically the SOF (Start of Frame) tag.
  • Step 304 Verify the integrity of the read pre-index information.
  • a Secure Hash Algorithm SHA is used to verify the integrity of the pre-index information. If the verification fails, the pre-index information is lost or modified.
  • the original decoding process of step 305 is performed; if the verification is successful, step 306 is performed.
  • the fifth version of the message digest algorithm may be used to perform integrity check of pre-index information, or other types of integrity check algorithms may be used.
  • the step 304 may not be performed, that is, the default pre-index information is complete, or the pre-index information may be protected from being tampered by using encryption or the like before storing the pre-index information, and only needs to be used before being used. Decrypt the pre-index information. It should be noted that, if the integrity verification is performed, an additional verification field is added to the pre-index information after the pre-index information is extracted and is stored. This is an existing integrity verification technology, and the embodiment of the present invention does not. Let me repeat.
  • Step 307 decoding data preparation.
  • the file stream corresponding to the decoded picture is copied.
  • the copy file stream here is only a copy file stream pointer, not a copy of the entire file stream.
  • the decoding structure is a structure designed by the JPEG decoding library for the decoding operation. It includes pre-declared variables such as quantization tables and color channels. In this way, it is ensured that variables are not shared between the decoding structures corresponding to each thread, so that the same variable is not modified by each other in the multi-threading process.
  • each thread can be guaranteed to have its own file stream pointer and decoding structure. This avoids the mutual interference problem caused by the thread modifying the data in the file stream or the decoding structure during the decoding process.
  • the creation of the decoding structure is that memory operations do not affect I/O, while file stream replication simply copies a file stream pointer and does not copy the entire file stream, so the efficiency of parallel decoding is not affected.
  • Step 308 multiple threads perform decoding in parallel. Taking JPEG pictures as an example, each thread will complete the index position recovery, Huffman entropy decoding, Inverse Discrete Cosine Transform (IDCT) and color conversion stages in turn, and finally output the RGB results of the partial regions of the image.
  • IDCT Inverse Discrete Cosine Transform
  • step 308 in the above steps may be performed by one main thread, and step 308 may be performed by multiple sub-threads.
  • FIG. 5 is a schematic structural diagram of a computer system 400 according to an embodiment of the present invention.
  • the computer system 400 can be a terminal device or other type of computer device.
  • the computer system includes an application layer 410 and an operating system layer 450, which may be an Android operating system.
  • the operating system layer 450 is further divided into a framework layer 420, a core library layer 430, and a driver layer 440.
  • the operating system layer 450 in FIG. 5 can be considered as a specific implementation of the operating system 182 in FIG. 1, and the application layer 410 in FIG. 5 can be considered as a specific implementation of the application 181 in FIG.
  • the drive layer 440 includes a CPU driver 441, a GPU driver 442, a display controller driver 443, and the like.
  • the core library layer 430 is a core part of the operating system, including an input/output service 431, a core service 432, a graphics device interface 434, and a graphics engine (Graphics Engine) 433 that implements CPU or GPU graphics processing.
  • the graphics engine 433 may include a 2D engine, a 3D engine, a composition, a frame buffer, an EGL (Embedded-System Graphics Library), etc., where the EGL is a rendering API and an underlying native platform window system.
  • Interface, API refers to the application programming interface (Application Programming Interface).
  • the framework layer 420 may include a Graphic Service 424, a System Service 421, a Web Service 422, and a Customer Service 423, etc.
  • the graphics service 424 may include, for example, a widget (Widget). ), canvas (Canvas) and views (Views).
  • the application layer 410 may include a gallery 411, a media player (412), a browser 413, and the like.
  • computer system 400 also includes a hardware layer 450.
  • the hardware layer of the computer system 400 may include a Central Processing Unit (CPU) 451 and a Graphic Processing Unit (GPU) 452 (corresponding to a specific implementation of the processor 150 in FIG. 1).
  • the memory 453 (corresponding to the memory 180 in FIG. 1), including the memory and the external memory, may further include an input device 454 (corresponding to the input device 132 in FIG. 1) and a display device 455 (corresponding to the display in FIG. 1).
  • Apparatus 140 such as a Liquid Crystal Display (LCD), Holographic, Projector, etc., may also include one or more sensors 456 (equivalent to sensor 120 in FIG. 1).
  • the hardware layer 450 may also include the power source, camera, RF circuit, and WiFi module shown in FIG. 1, and may also include other hardware modules not shown in FIG. 1, such as a memory controller and display control. And so on.
  • FIG. 5b is a schematic structural diagram of the 2D engine shown in FIG. 5a.
  • the 2D engine 500 mainly includes libskia 501 and libjpeg 502, wherein libskia 501 can call the functions provided by libjpeg 502, and libjpeg 502 is equivalent to the JPEG decoding library mentioned in the previous embodiment.
  • the embodiment of the present invention mainly adds the function of parallel decoding in libjpeg 502, and adaptively modifies the interface of libskia 501 to call libjpeg 502.
  • the 2D engine The 500 can also include decoding libraries for other image formats, such as libpng 503 and libgif 504.
  • FIG. 6a and 6b are operational timing diagrams of the parallel decoding method in the 2D engine 500 according to an embodiment of the present invention, wherein FIG. 6a is a process of acquiring pre-index information, and FIG. 6b is a process of performing parallel decoding according to pre-index information. Both of these running sequence diagrams are described by taking a thumbnail of a picture in the user clicking on the gallery 411 (refer to FIG. 5a) as an example.
  • the library 411 sends a decoding request (602a) to libskia 501
  • libskia 501 creates a file stream of the picture, and streams the file to libjpeg502.
  • libjpeg502 fails to read the pre-index information (604a) and returns the result of the failure of the pre-index information acquisition to libskia 501.
  • libskia501 calls the serial decoding function (605a) provided by libjpeg502 according to the returned result, libjpeg502 for the above file
  • the stream performs processes such as serial Huffman decoding (606a).
  • libjpeg 502 extracts pre-index information (608a) according to the decoding result of 606a and stores the extracted pre-index information (609a). After libjpeg 502 completes the picture decoding, the decoding result is returned to the library 411 (610a) through libskia 501, and then the library 411 displays the opened picture (611a) to the user.
  • the serial Huffman decoding is performed by libjpeg 502, so libjpeg 502 can directly extract the pre-index information from the decoding result, but in other embodiments, in order to minimize the original decoding process code, libjpeg502
  • the offset position information of all MCU blocks obtained by decoding is passed to libskia501, and then libskia501 passes the index information of all MCU blocks to libjpeg502, and then libjpeg502 extracts pre-index information from the information.
  • steps 605a and 606a may be replaced with region decoding, and since the extraction of the offset location information for all MCU blocks in the region decoding is prior to the decoding step, steps 607a and 608a may be placed prior to region decoding.
  • the library 411 sends a decoding request (602b) to libskia 501
  • libskia 501 creates a file stream of the picture, and streams the file to libjpeg502 (603b)
  • libjpeg 502 reads the pre-index information (604b) and verifies the integrity of the pre-index information (605b), and then the verification returns the result to libskia 501
  • libskia501 prepares for decoding (607b), including copying M-1 pointers of the above files, etc.
  • libjpeg 502 is called after the copy is completed, and M threads are called by libjpeg to perform parallel decoding (608b) on the above file stream.
  • the decoding result is returned to the library 411 (609b) through libskia 501, and then the library 411 displays the opened picture (610b) to the user.
  • libjpeg 502 reads the description information of the image file (for example, the quantization table, the file size, and the like) in addition to the pre-index information, which are existing technologies and will not be described here.
  • the library 411 calls the libskia 501 in the 2D engine, which can be implemented by calling the BitmapFactory interface in the graphics device interface 434 (refer to FIG. 5a), which is also a prior art and will not be described in detail in the embodiments of the present invention.
  • FIGS. 6a-6b only exemplarily describe the method embodiments provided by the present invention, and the various methods introduced by those skilled in the art according to the foregoing embodiments of the present invention and the two operation timing charts.
  • the example is easy to obtain the running timing diagram corresponding to the other method embodiments provided by the present invention and the corresponding program implementation according to the timing diagram, and details are not described herein again.
  • the computer system applying the parallel decoding method provided by the embodiment of the present invention can effectively avoid the system jamming phenomenon while realizing parallel decoding of files and improving decoding efficiency. And enhance the user experience.
  • FIG. 7 is a schematic structural diagram of a decoding apparatus 700 according to an embodiment of the present invention.
  • the decoding apparatus 700 includes a reading module 701, configured to read, from the memory 800, pre-index information corresponding to a file to be decoded, the pre-index information including information indicating one or more decoding boundaries, and the pre-index information Stored in another file associated with the file to be decoded or at the end of the file to be decoded; and a parallel decoding module 702, configured to: use the plurality of files to be decoded according to the pre-index information
  • the data segment performs parallel decoding, wherein the plurality of data segments are partitioned according to one or more of the one or more decoding boundaries.
  • the memory 800 includes memory and external memory, and the pre-index information is usually stored on the external memory.
  • the decoding apparatus 700 may further include an extracting module 703, configured to: when the file to be decoded is newly added, the file to be decoded is modified, or the file to be decoded When the first time is opened, the pre-index information is extracted; and the storage module 704 is configured to store the extracted pre-index information into the memory 800.
  • an extracting module 703 configured to: when the file to be decoded is newly added, the file to be decoded is modified, or the file to be decoded When the first time is opened, the pre-index information is extracted; and the storage module 704 is configured to store the extracted pre-index information into the memory 800.
  • the decoding apparatus 700 may further include one or two of a determining module 705 and a determining module 706, both determining modules are configured to determine that the file size is greater than a preset threshold, and the extracting module 703 and the reading module 701 are configured according to The determination result respectively performs a corresponding extraction operation and a reading operation. Further, the decoding apparatus 700 may further include a threshold modification module 707 for modifying the thresholds in the determining module 705 and the determining module 706. In some other embodiments, the determination module 705 and the determination module 706 can also be combined into one module.
  • the decoding apparatus 700 may further include an integrity verification module 703 for verifying the integrity of the pre-index information read by the reading module 701, and the parallel decoding module 702 is complete.
  • the verification result of the verification module 703 is to perform parallel decoding on the file when passing.
  • the decoding apparatus 700 may further include a data preparation module 704, configured to copy a file stream of the file to be decoded to obtain a file stream equal to the number of the plurality of threads performing the parallel decoding, where the file is copied
  • a stream refers to a pointer that copies the file stream.
  • the data preparation module 704 can also copy or create other information required for parallel decoding according to requirements.
  • integrity verification module 703 and the data preparation module 704 may also be added based on the decoding apparatus shown in FIG. 7b.
  • the modules indicated by the dashed lines in Figures 7a-7c are all optional modules.
  • the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, ie may be located A place, or it can be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • the connection relationship between the modules indicates that there is a communication connection between them, and specifically, one or more communication buses or signal lines can be realized.
  • the drawing device can be implemented by means of software plus necessary general hardware, and of course, the dedicated hardware can also include an ASIC. , dedicated CPU, dedicated memory, dedicated components, etc. to achieve.
  • functions performed by computer programs can be easily implemented with the corresponding hardware, and the specific hardware structure used to implement the same function can be various, such as analog circuits, digital circuits, or dedicated circuits. Circuits, etc.

Abstract

一种解码方法及装置。该解码方法主要包括提取预索引信息,并将预索引信息存储在与所述待解码的文件关联的其他文件中或所述待解码的文件的尾部,然后在解码之前读取该预索引信息,根据该预索引信息对所述待解码的文件中的多个数据段执行并行解码。预索引信息采用以上存储方法,可以在读取时有效减少I/O操作,从而一定程度上避免解码时可能造成的系统卡顿现象。

Description

可变长编码文件的解码方法以及装置
本申请要求于2016年07月08日提交中国专利局、申请号为CN201610542045.0、申请名称为“可变长编码文件的解码方法以及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明实施例涉及计算机解码方法,尤其涉及可变长编码文件的解码方法以及装置。
背景技术
目前移动设备中最流行的图片格式是JPEG(Joint Photographic Experts Group),基于JPEG格式的图片采用可变长的哈夫曼(Huffman)熵编码,因此可以用较少的磁盘空间得到较好的图像质量。手机、相机等设备拍照所生成的图片默认都是JPEG格式。同时,大部分的修图软件编辑后所保存的图片默认也是JPEG格式。
提升JPEG图片的解码速度能够显著提升用户图片浏览的体验。目前,移动终端主要采用两种方式来完成JPEG图片的解码:第一种是硬件解码,即移动终端中设置专门的硬件芯片以完成JPEG图片的解码,如苹果iOS设备;第二种是软件解码,使用软件解码库完成JPEG图片的解码,如大部分的安卓(Android)设备。硬件解码具有解码速度快的优点,但其需要在设备中额外增加用于解码的芯片,会提升设备的造价。因此,急需一种技术能提升软件解码的速度,以便于提升用户图片浏览体验而同时也不增加设备的生产成本。
JPEG图片的软件解码过程主要包括哈夫曼(Huffman)熵解码、反离散余弦变换和颜色转换三个过程。其中,反离散余弦变换和颜色转换两个过程能够很好地支持并行化和多线程处理。然而,哈夫曼熵编码是可变长编码(Variable-Length Coding,VLC)的一种,在解码时无法准确找到解码边界进而多线程并行处理,因而通常只能使用单线程串行解码。
现有技术中存在一种Huffman并行解码方法,核心是将待解码的文件的解码边界在该文件中的偏移信息插入到该文件的头部,这样在解码时就可以通过解析该头部获得解码的边界从而实现并行解码。但是此种方法在将上述偏移信息插入文件头部时需要将整个文件流进行复制,这样当JPEG图片较大或较多时需要的输入/输出(Input/Output,I/O)操作就会很多,会出现移动设备I/O操作过于频繁引起的系统卡顿甚至系统假死现象。
发明内容
本发明实施例提供一种针对可变长编码文件的解码方法和装置,用以提升文件解码的速度,同时一定程度上避免文件解码时可能造成的系统卡顿现象。
下面首先介绍一下本发明实施例中出现的术语。
元数据(metadata):广义的元数据指的是描述数据的数据。一个文件的元数据可以独立于该文件存储,也可以存储在文件内部,比如文件头部或文件尾部。
元数据文件:存储元数据的文件。一个文件对应的元数据文件,指的就是存储该文件 的元数据的文件,该文件和该文件的元数据文件是两个不同的文件。
数据库文件:存放数据库数据的文件。例如,SQL Server数据库提供的后缀名为.mdf的文件。
系统文件:存放操作系统主要数据的文件,用户不可直接修改。例如Linux系统的元数据文件。Linux系统的元数据文件中包括一些用于描述用户文件的特征的元数据文件,该元数据文件与该元数据文件描述的用户文件具有关联关系。
用户文件:由用户或应用直接创建的文件,且用户可直接修改。本发明实施例中提到的待解码的文件通常是用户文件,例如用户利用终端设备拍照之后获得的图片文件。
文件流:图片文件或其他类型的文件在计算机内存中的存储形式。通过对文件流的操作完成对文件的数据添加、数据删除、数据修改、编码和/或解码等操作。对一个文件执行解码之前,要先将该文件加载到计算机内存中,因此,对一个文件执行解码,也可以称之为对该文件对应的文件流执行解码。
并行解码:多个(至少两个)线程同时对上述文件流中的数据执行解码操作。
最小编码单元(Minimum Coded Unit,MCU):在JPEG编码规范中,最小的处理单元就是一个MCU,通常是16*16的像素点矩阵,但某些图片格式(如灰度图)中也可能是8*8的像素点矩阵。一张普通大小的JPEG图片通常包含成千上万个MCU,也就是说,这张图片对应的的待解码的文件流中包含成千上万个编码后的MCU的信息。由于JPEG采用可变长的Huffman编码,所以同样大小的MCU编码后的长度是未知的,可以相同,也可以不同。
数据段:上述文件流中的数据包含多个(至少两个)数据段,在并行解码过程中,这多个数据段分别被多个线程执行解码操作。如果以MCU为单位进行并行解码需要同时启动的线程太多,因此,一般来说,上述的一个数据段包含多个MCU,这样就可以把需要同时启动的线程数量降低。
解码边界:上述数据段之间的边界就是解码边界。具体的,解码边界可以为每个数据段的起始位置。更具体的,在一些实施例中,解码边界为每个数据段中包含的第一个MCU。需要说明的是,整个文件流的第一个MCU,也就是文件的首位置,虽不是两个数据段之间的边界,但在本发明的某些实施例中也属于解码边界。
预索引信息:该预索引信息包括指示一个或多个解码边界的信息,还可以根据解码的实际需求包含一些其他信息。在一些实施例中,解码边界的信息为解码边界在文件流中的偏移位置信息。更具体的,在一个待解码的文件流中,解码边界的信息可以为每个数据段中包含的第一个MCU在该文件流中的偏移位置信息。需说明的是,并行解码的数据段通常是在解码边界确定后才能根据解码边界划分得到的,但是要划分的数据段的数量(以及与该数量相关的解码边界的数量),即并行执行解码的线程的数量可以在数据段得到之前根据处理资源的当前处理能力等信息确定。
持久化存储:计算机断电或重启后被存储的信息不会丢失。典型的持久化存储包括文件存储和数据库存储。
第一方面,本发明实施例提供一种解码方法,该方法可应用于解码采用可变长编码得到的文件,例如JPEG图片。该解码方法包括读取待解码的文件对应的预索引信息;根据该预索引信息,对该待解码的文件中的多个数据段执行并行解码。其中,该预索引信息包括用于指示一个或多个解码边界的信息,该多个数据段是依据该一个或多个解码边界中的 一个或多个进行划分的。
基于第一方面,在第一种实现方式中,该预索引信息存储在与该待解码的文件关联的其他文件中,换句话说,预索引信息独立于该待解码的文件存储。例如预索引信息可以存储在所述待解码的文件对应的元数据文件中,这里的元数据指的是所述待解码的文件对应的系统数据,这里的元数据文件属于系统文件,采用这种存储方法,由于不涉及复制整个文件的操作,不需要针对整个文件对硬盘(或其他外存)进行读操作和写操作,只需要向硬盘写入比文件的数据量少很多的预索引信息,从而有效减少I/O操作,进而一定程度上避免解码时可能造成的系统卡顿现象,尤其是针对文件较多或文件较大时,效果更显著。
基于第一方面的第一种实现方式,在一些实现方式中,该其他文件还可以为数据库文件,这里的数据库可以是本地数据库,也可以是远端数据库;在另一些实现方式中,该其他文件还可以为与该待解码的文件在同一目录下的,文件名相同但后缀名不同的文件,并且该其他文件的后缀名不能与现有的后缀名冲突。
基于第一方面,在第二种实现方式中,预索引信息还可以存储在所述待解码的文件的尾部。由于文件系统支持在尾部追加数据的操作,所以采用存储在文件尾部这种存储方式,可以避免对整个文件对应的文件流的复制操作,从而有效减少I/O操作,进而一定程度上避免解码时可能造成的系统卡顿现象。
基于第一方面或以上任意一种实现方式,在一些实现方式中,预索引信息通过以下方式获取并存储:当监测到所述待解码的文件第一次被打开时,提取所述预索引信息;存储提取的所述预索引信息。所述存储包括持久化存储,具体存储位置可参考前述实现方式介绍的预索引信息的存储位置。具体的,提取预索引信息的过程包括对所述待解码的文件执行针对可变长编码的解码。
在一些实现方式中,当监测到待解码的文件第一次被打开时提取所述预索引信息,意味着利用文件第一次被打开时执行的解码(串行解码或区域解码等其他解码方法)提取预索引信息。由于文件第一次被打开时要执行针对可变长编码的解码,对于采用可变长编码的文件来说,执行该解码就可以获取到编码单元的信息,然后从获取到的编码单元的信息中选取部分编码单元的信息作为预索引信息。在文件第一次打开时提取预索引信息,这样对系统而言不会有额外的功耗和开销,而且文件以后再被打开时就可以根据该预索引信息并行解码,提高了文件以后被打开时的解码速度。
在另一些实现方式中,预索引信息的提取也可以在监测到所述待解码的文件新增或所述待解码的文件被修改时执行。在这两种实现方式下,由于文件不需要打开,所以提取预索引信息的过程可以仅执行针对可变长编码的解码,而不执行打开一个文件的所有处理过程,例如JPEG图片打开过程中的反离散余弦变换和颜色转换过程。
对于以上实现方式中介绍的三种条件,系统可以同时设置,例如,设置在三种条件任意一种满足时执行提取预索引信息的步骤,除非已经获知该文件已经有预索引信息;或者系统可以仅设置其中的一种或两种,例如,系统设置在监测到文件第一次被打开时对该文件执行提取预索引信息的步骤,也设置在监测到文件被修改时也对该文件执行提取预索引信息的步骤,这种设置即可以提高原始文件的并行解码效率,又可以在初始文件被修改后及时修改预索引信息,保证了预索引信息的准确性,从而保证被修改后的文件仍然能获得较好的并行解码效率。
另外一些实现方式中,计算机系统也可以自行启动预索引信息的提取操作,比如系统可以默认每隔固定时间执行预索引信息的提取,或每新增x个文件就执行针对该x个文件的预索引信息的提取,x为大于2的整数。
在一些实现方式中,在预索引信息提取之前根据处理资源的处理能力确定需要存储的解码边界的数量。这里的处理资源包括待解码的文件所在的计算机系统的本地处理资源和/或该计算机系统能够调用的非本地的处理资源。具体的,根据处理资源的处理能力确定可并行执行的线程的数量;提取的所述预索引信息中包含与所述线程的数量相等的解码边界的信息。假设系统当前的CPU有4个核,那可并行执行的线程数量为4个,那么可提取并存储包括文件首位置信息在内的4个解码边界的信息或除文件首位置信息外的3个解码边界的信息。以JPEG图片为例,文件首位置信息为文件中第一个MCU块的偏移位置信息。另外,需要说明的是,提取并存储的预索引信息的数量和可并行执行的线程的数量可以不精确相等,仅数量相近。这样,可以避免存储过多数量的解码边界的信息,从而有效节省了存储空间。当然也可以在执行提取之后,且执行存储之前才确定处理资源的处理能力,并存储相应数量的解码边界的信息,这样也可以达到类似效果。
基于第一方面或以上任意一种实现方式,在一些实现方式中,在确定所述待解码的文件的大小大于预设的第一阈值时才读取所述待解码的文件对应的预索引信息,并根据所述预索引信息执行并行解码。具体的,在一种实现方式下,先判断待解码的文件的大小是否大于预设的第一阈值;当所述待解码的文件的大小大于(或大于或等于)所述预设的第一阈值时,再读取待解码的文件对应的预索引信息,并根据所述预索引信息执行并行解码;当所述待解码的文件的大小小于或等于(或小于)所述预设的第一阈值时,不执行并行解码,而是执行串行解码。
若文件太小,并行解码带来的收益小于成本,因此采用本发明实施例提供的方案可以先对文件大小进行判断,仅对较大的文件执行并行解码,在提高较大的文件的解码效率同时也提高了系统整体的资源利用率。
基于以上任意一种预索引信息的提取方式,在一些实现方式中,即便当监测到所述待解码的文件新增、所述待解码的文件被修改、或所述待解码的文件第一次被打开时,还要确定所述待解码文件的大小大于预设的第一阈值,然后再根据所述确定结果提取所述预索引信息。具体的,在一种实现方式下,先判断待解码的文件的大小是否大于预设的第一阈值;仅当所述待解码的文件的大小大于所述预设的第一阈值时,提取所述预索引信息。当所述待解码的文件的大小小于或等于所述预设的第一阈值是,需要根据文件的实际需求执行操作:若文件实际需要解码,例如文件第一次被打开时,文件无论如何是需要解码的,此时,虽然不获取预索引信息,但要对文件执行串行解码或区域解码等一系列操作,以打开文件;若文件实际不需要解码,例如文件新增或被修改,那对该文件可以不执行任何与解码相关的操作。
把对文件大小的考虑放到提取预索引信息之前,只针对较大的文件提取预索引信息并存储,可以在不影响系统整体资源利用率的同时进一步节省存储空间。
在其他一些方式中,在提取预索引信息的步骤之前和读取该待解码的文件的预索引信息之前可以都执行文件大小的确定步骤。
在一些实现方式中,上述预设的第一阈值可以根据经验确定,也可以对大量的各 种大小的文件进行解码后,根据解码的效果来确定,阈值一旦确定后一般不发生变化。
在另一些实现方式中,预设的第一阈值也可以根据实际情况进行修正。具体的,预设的第一阈值可以通过以下方式修改:在每个待解码的文件被解码完成后,都记录所述待解码的文件的相关信息,包括文件大小、解码时间以及是否执行并行解码;若所述待解码的文件使用并行解码,所述解码时间小于预设的第二阈值(例如1ms)且所述待解码的文件的大小大于所述预设的第一阈值,修改所述预设的第一阈值为所述待解码的文件的大小。换句话说,如果发现某个待解码的文件使用了并行解码,且解码时间过小,证明这个大小的文件使用并行解码带来的效果已经不大,比这个文件更小的文件使用并行解码带来的效果就可能更小了,若这个文件的大小又比第一阈值大,那就应该将第一阈值设置为这个文件的大小,这样第一阈值可以根据实际情况及时修正,从而进一步保证系统资源的整体利用率。
在其他一些实现方式中,不需要每个文件都记录相关信息,只记录那些解码时间小于一定阈值的文件的相关信息,这样可以节省存储空间。
基于第一方面或以上任意一种实现方式,在一些实现方式中,在对待解码的文件执行并行解码之前需要做一些数据准备。具体的,假设当前系统可以并行启动R个线程,那么对待解码的文件的文件流执行复制操作(只需要复制文件流指针)以获得R个文件流,这样每个线程就可以针对自己看到的文件流中的数据段执行并行解码,最后再将这R个线程的执行结果同步起来获得最终的解码结果。这样可避免线程之间互相干扰的问题,从而保证并行解码结果的正确性。进一步的,数据准备还包括准备并行解码过程需要的其他数据,例如创建一个或多个解码结构体。
基于第一方面或以上任意一种实现方式,在一些实现方式中,获取预索引信息之后需要先对该预索引信息进行完整性验证,若验证通过,再根据所述预索引信息对所述待解码的文件执行所述并行解码。若验证不通过,说明该预索引信息可能丢失或被修改,在这种情况下对待解码的文件执行串行解码。这样可以避免因文件的预索引信息丢失或被修改而造成的并行解码失败。
基于第一方面或以上任意一种实现方式,在一些实现方式中,当线程数量与根据解码边界可划分的数据段的数量相等时,每两个解码边界之间的完整数据段就是一个线程解码的对象,此时并行解码的过程包括:根据预索引信息中多个解码边界的信息确定各个解码边界在所述待解码的文件中的位置;所述多个线程中的每个线程确定一个解码边界,并从所述解码边界在所述待解码的文件中的位置开始执行解码,其中,除了最后一个数据段执行解码的线程(称之为最后一个线程)之外,每个线程执行到下一个解码边界之前即停止,最后一个线程执行到文件(或文件流)的结束位置。
在其他一些实现方式中,当并行解码时可启动的线程数量小于根据解码边界可划分的数据段的数量时,除最后一个线程外的每个线程处理P/M(取整数)个数据段,最后一个线程处理剩余的部分,其中,M为线程数量,P为根据解码边界可划分的数据段的数量,在有些实现方式中就是解码边界的数量。
基于第一方面或以上任意一种实现方式,在一些实现方式中,执行并行解码的线程的数量可以在并行解码的过程中根据处理资源的实际情况动态改变。具体的,动态监测当前可用的处理器(如空闲核数),然后调整(例如增加)线程数量,从而进一步提高解码效 率。
第二方面,本发明实施例还提供一种解码装置,包括可实现第一方面或上述第一方面的任意一种实现方式的一个或多个模块,每个模块可执行一个或多个步骤。
第三方面,本发明实施例还提供一种终端设备,该终端设备包括处理器和存储器,所述存储器用于存储软件程序,所述处理器用于读取所述存储器中存储的软件程序并实现第一方面或上述第一方面的任意一种实现方式提供的方法。
第四方面,本发明实施例中还提供一种计算机存储介质,该存储介质可以是非易失性的,即断电后内容不丢失。该存储介质中存储软件程序,该软件程序在被一个或多个处理器读取并执行时可实现第一方面或上述第一方面的任意一种实现方式提供的方法。
需要说明的是,本发明实施例提供的方法和装置可应用于所有应用可变长编码(Huffman)的图片格式,JPEG图片是目前应用可变长编码的一种图片格式,其他应用可变长编码的图片的解码或未来可能出现的应用可变长编码的图片的解码都可以应用本发明实施例提供的方法。除了图片格式的文件之外,其他类型的文件,例如文本、音频、视频等,若应用可变长编码,也可以采用与本发明实施例提供的方法相同或类似的方法进行解码。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本发明实施例应用的终端设备的结构示意图;
图2为本发明实施例提供的解码方法的示例图;
图3为本发明实施例提供的解码方法中预索引信息的获取过程示意图;
图4为本发明实施例提供的并行解码方法的流程示意图;
图5a为本发明实施例提供的计算机系统的结构示意图;
图5b为图5a提供的计算机系统中2D引擎的结构示意图;
图6a-6b为本发明实施例提供的并行解码方法的运行时序图;
图7a-7c为本发明实施例提供的解码装置的结构示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
本发明实施例提供的解码方法主要应用于终端设备,该终端设备也可称之为用户设备(User Equipment,简称为“UE”)、移动台(Mobile Station,简称为“MS”)、移动终端(Mobile Terminal)等,可选的,该终端可以具备经无线接入网(Radio Access  Network,RAN)与一个或多个核心网进行通信的能力,例如,终端可以是移动电话(或称为“蜂窝”电话)、或具有移动性质的计算机等,例如,终端还可以是便携式、袖珍式、手持式、计算机内置的或者车载的移动装置。应理解的是,除了终端设备以外,本发明实施例提供的解码方法也可以应用于其他类型的计算机系统。
本发明实施例提供的解码方法利用计算机上的并行计算能力,
本发明实施例利用计算机上的并行计算能力,在软件层面实现可变长编码文件的并行解码,从而提高文件的解码速度。以下实施例具体介绍了在计算机的操作系统层提供文件的并行解码能力,进一步可选的,操作系统层可以向应用层提供该并行解码能力,进而提升应用层应用(例如图库)的文件解码速度,从而提升应用的用户体验。
请参考图1,为本发明实施例应用的终端设备的结构示意图。如图1所示,终端设备100包括存储器180、处理器150以及显示设备140。存储器180存储计算机程序,该计算机程序包括操作系统程序182和应用程序181等。处理器150用于读取存储器180中的计算机程序,然后执行计算机程序定义的方法,例如处理器150读取操作系统程序182从而在该终端设备100上运行操作系统以及实现操作系统的各种功能,或读取一种或多种应用程序181,从而在该终端设备上运行应用。
处理器150可以包括一个或多个处理器,例如,处理器150可以包括一个或多个中央处理器,或者包括一个中央处理器和一个图形处理器。当处理器150包括多个处理器时,这多个处理器可以集成在同一块芯片上,也可以各自为独立的芯片。一个处理器可以包括一个或多个处理核,以下实施例均以多核为例来介绍,但是本发明实施例提供的并行解码方法也可以应用于单核处理器,利用单核处理器的分时工作原理执行并行解码,执行并行解码的线程数量可根据该单核处理器当前的负载决定。
另外,存储器180还存储有除计算机程序之外的其他数据183,其他数据183可包括操作系统182或应用程序181被运行后产生的数据,该数据包括系统数据(例如操作系统的配置参数)和用户数据,例如用户拍摄的一张照片就是典型的用户数据,也是本发明实施例提供的方法的一种解码对象。
存储器180一般包括内存和外存。内存可以为随机存储器(RAM),只读存储器(ROM),以及高速缓存(CACHE)等。外存可以为硬盘、光盘、USB盘、软盘或磁带机等。计算机程序通常被存储在外存上,处理器在执行处理前会将计算机程序从外存加载到内存。本发明实施例中待解码的文件通常存储在外存上,处理器在对其执行解码之前会将该文件从外存加载到内存。
操作系统程序182中包含了可实现本发明实施例提供的并行解码方法的计算机程序,从而使得处理器150读取到该操作系统程序182并运行该操作系统后,该操作系统可具备本发明实施例提供的并行解码功能。进一步的,该操作系统可以向上层的应用开放该并行解码功能的调用接口,处理器150从存储器中180中读取应用程序181并运行该应用后,例如图库应用,该应用就可以通过该调用接口调用操作系统中提供的并行解码功能,从而实现文件的并行解码。
终端设备100还可以包括输入设备130,用于接收输入的数字信息、字符信息或接触式触摸操作/非接触式手势,以及产生与终端设备100的用户设置以及功能控制有 关的信号输入等。具体地,本发明实施例中,该输入设备130可以包括触控面板131。触控面板131,也称为触摸屏,可收集用户在其上或附近的触摸操作(比如用户使用手指、触笔等任何适合的物体或附件在触控面板131上或在触控面板131的操作),并根据预先设定的程式驱动相应的连接装置。可选的,触控面板131可包括触摸检测装置和触摸控制器两个部分。其中,触摸检测装置检测用户的触摸方位,并检测触摸操作带来的信号,将信号传送给触摸控制器;触摸控制器从触摸检测装置上接收触摸信息,并将它转换成触点坐标,再送给该处理器150,并能接收处理器150发来的命令并加以执行。例如,用户在触控面板131上用手指单击一张图片,触摸检测装置检测到此次单击带来的这个信号,然后将该信号传送给触摸控制器,触摸控制器再将这个信号转换成坐标发送给处理器150,处理器150根据该坐标和该信号的类型(单击或双击)执行对该图片的解码等操作,最后将该图片显示在显示面板141上,从而实现“打开”图片。
触控面板131可以采用电阻式、电容式、红外线以及表面声波等多种类型实现。除了触控面板131,输入设备130还可以包括其他输入设备132,其他输入设备132可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆等中的一种或多种。
终端设备100还可以包括显示设备140,显示设备140,包括显示面板141,用于显示由用户输入的信息或提供给用户的信息以及终端设备100的各种菜单界面等,在本发明实施例中主要用于显示解码后的图片或其他类型的文件。该显示设备140可包括显示面板141,可选的,可以采用LCD(Liquid Crystal Display,液晶显示器)或OLED(Organic Light-Emitting Diode,有机发光二极管)等形式来配置显示面板141。在其他一些实施例中,触控面板131可覆盖显示面板141上,形成触摸显示屏。
除以上之外,终端设备100还可以包括用于给其他模块供电的电源190以及用于拍摄照片或视频的摄像头160。终端设备100还可以包括一个或多个传感器120,例如加速度传感器、光传感器等。终端设备100还可以包括无线射频(Radio Frequency,RF)电路110,用于与无线网络设备进行网络通信,还可以包括WiFi模块170,用于与其他设备进行WiFi通信。
下面的实施例将以JPEG图片的解码为例介绍本发明实施例提供的解码方法。本发明实施例提供的解码方法可以实现在图1所示的操作系统程序182中。应理解的是,本发明实施例所提供的方法并不局限于JPEG图片的解码。
请参考图2,为本发明实施例提供的解码方法的示例图。在JPEG标准中,并行的最大阻碍在于Huffman熵解码。Huffman熵解码占整体时间的一半以上,由于是可变长熵编码,无法在解码前感知各个MCU(Minimum Coded Unit,最小编码单元)的起始位置,无法实现并行解码。假设待解码的图片中有100个MCU(编号为1-100),在使用本发明实施例提供的并行解码方案之前,原有Huffman熵解码流程是采用单线程串行解码该100个MCU。JPEG并行解码方案的主要思想就是将待解码的图片分成多个数据段,通过记录预索引信息来保存每个数据段的起始点信息。
具体的,本发明实施例提供的方案会对待解码的图片预先执行一次Huffman串行解码,将串行解码得到的预索引信息提取出来并记录下来。该预索引信息就是图2示例中4个数 据段的起始位置信息,4个数据段分别是编号为1-25,26-50,51-75,76-100的MCU集合,4个数据段的起始位置信息分别是编号为1、26、51以及76的MCU的位置信息,一般来说,MCU的位置信息由该MCU在该图片对应的文件流中的偏移位置信息表示,所述偏移位置信息可以为该MCU相对文件的第一个字节的偏移量,也可以是该MCU相对文件的第一个MCU的偏移量。获取这4个MCU的偏移位置信息之后,线程1-线程4就可以分别从这4个MCU的位置开始,并行地对这四个数据段执行解码,从而提升了图片解码的速度。
下面通过更详细的方法过程介绍本发明实施例提供的解码方法。
请参考图3,为本发明实施例提供的解码方法中预索引信息的获取过程示意图。
步骤201、当监测到一张图片第一次被打开时,例如当监测到用户单击这张图片时,启动对该图片的预处理。本发明实施例中提到的“预处理”指的即是预索引信息的提取过程。
在其他一些实施例中,该预处理阶段的启动时机还可以是该图片新增或该图片被修改时。具体的,操作系统会监测到图片的新增或修改,例如Android系统的media provider机制提供该监测功能。举例来说,图片新增的情形包括使用本地的摄像头拍照获得一张图片,从网络下载图片到本地,从其他终端设备拷贝图片到本地,或编辑本地的图片并另存为一个新图片;图片更新的情形包括修改图片内容且未另存为其他图片的情形。这两种情形下的预处理可以仅包括串行Huffman熵解码。
在另外一些实施例中,该预处理也可以由操作系统自行启动,例如可设置每当新增图片满10张时,操作系统就自行对该新增的10张图片执行串行Huffman熵解码以提取预索引信息。
步骤202、判断该图片是否已经有预索引信息。在本发明实施例中,预索引信息被存储在图片对应的文件系统的扩展属性中,文件系统的扩展属性包括该图片对应的元数据文件。在其他一些实施例中,预索引信息还可以存储在其他类型的文件中或存储在该图片的尾部。
若能够从该图片对应的元数据文件中读取到预索引信息,则执行步骤203,步骤203意味着预处理结束,进入并行解码阶段;若不能从该图片对应的元数据中获取到预索引信息或获取到的预索引信息为空,则执行步骤204。
在其他一些实施例中,步骤202的判断步骤也可以不执行,即默认所有的图片在第一次被打开时均没有预索引信息。
步骤204、启动图片的原有解码过程。当前待解码的图片没有预索引信息,那么图片的串行解码、反离散余弦变换和颜色转换这些原有解码过程就会正常启动和执行。
步骤205、判断该图片的大小是否小于预设的阈值,若该图片的大小小于预设的阈值,则结束该预处理,即不再获取预索引信息,但是图片的原有解码过程还要继续进行,因为图片还要在用户的打开命令下打开并显示到显示屏上;若该图片的大小大于或等于预设的阈值,则继续执行步骤206。
步骤205主要是考虑到过小的图片采用并行解码的收益不大,没必要获取预索引信息,这样可有效节省存储空间。在其他一些实施例中,判断图片大小的步骤和启动图片的原有解码过程可以交换顺序执行。
步骤206、提取预索引信息。
如果该图片采用的是Huffman编码,那么步骤204后该图片的Huffman串行解码就会被执行,Huffman串行解码执行后会生成所有MCU块的偏移位置信息,而本发明实施例提供的方法中使用的预索引信息则包含其中的一个或多个MCU块的偏移位置信息。另外,如果图片采用了差分编码(差分编码后再Huffman编码),那么该预索引信息还需要包括这一个或多个MCU块分别对应的上一个MCU块的DC(Direct Current)变量值,以用于Huffman解码结果的修正。
具体的,Huffman串行解码会按照顺序串行处理图片中的所有MCU,处理完成后或在这个处理过程中,按照一定的间隔提取N个MCU块的偏移位置信息。例如,考虑到目前移动终端通常有4个核,因此一般只能同时启动4个线程并行解码,那么就需要将待解码的图片划分为4个数据段,这样就需要提取N=4个MCU块的偏移位置信息(可参考图1理解)。在此实施例中,解码边界包括图片的第一个MCU块,在其他一些实施例中,解码边界也可以不包括图片的第一个MCU块。
为了避免出现多个线程等待一个线程的现象,在划分并行解码的多个数据段时最好能保证这多个数据段的数据量相当,这样多个线程就可以几乎同时完成解码。具体的,在一种实现方式下,以图片高度的1/N作为间隔来获取N个MCU块的偏移位置信息,这种方式是假设每个MCU块的数据量相当;在另一种实现方式下,以图片长度(图片对应的文件流的整体偏移量)的1/N作为间隔来获取N个MCU块的偏移位置信息,这种方式获取的N个MCU的偏移量的总和就是整个图片的偏移量。
步骤207、存储提取出的预索引信息。存储可以在多个MCU的偏移位置信息提取完成之后再执行,也可以提取一个MCU的偏移位置信息即执行一次存储。
步骤202中已经提出预索引信息可以被存储在该图片的元数据文件中,在其他一些实施例中,预索引信息还可以被插入该图片的尾部、与该图片关联的数据库文件中,或与该图片位于同一目录下,文件名相同但后缀名不同的文件中。在其他一些实施例中,为了保证预索引信息的完整性,在存储之前还可以在预索引信息中加入用于完整性验证的字段。
需要说明的是,以上几种存储方式均属于持久化存储,例如存储以文件的形式存储在外存(例如硬盘)上,这样可保证预索引信息掉电不丢失,但是在其他一些实施例中,若预索引信息可以被丢失,则不需要强制对其执行持久化存储。
可见,采用以上存储方法,避免了预索引信息插入图片头部时整个图片的复制过程,从而有效减少了I/O操作,尤其是当系统中存储的较多图片或单张图片较大时,采用本发明实施例的方法减少的I/O操作就会较多,从而一定程度上避免了系统的卡顿或假死现象。而且在图片第一次打开的过程中,伴随着图片的原有解码过程提取预索引信息并存储起来以便下次使用,这样可以避免因预索引信息的提取增加太多额外的功耗。
需说明的是,步骤206和207可以在原有解码过程完成之后再执行,也可以伴随着步骤204即图片的原有解码过程执行的。具体的,图片在进行Huffman串行解码的过程中,随着解码出来的MCU块的增多,根据预设的间隔提取MCU块的偏移位置信息并执行存储。
前述实施例大致介绍了预索引的提取过程,下面以图片采用了差分编码和Huffman编码为例,介绍预索引信息的构成和具体提取方式。
如果图片采用了差分编码,那么预索引信息中至少需要包括MCU块的偏移位置信息和该MCU块的上一个MCU块的DC变量值。在实际解码过程,可能还会包括一些其他需要保存的信息,与本发明实施例相关度不大,不再详细赘述。
目前Linux系统中的JPEG解码库(libjpeg)已经提供了串行解码和区域解码(region decoder)的能力,利用串行解码或区域解码可以提取出图片中所有MCU块的索引信息。通过比较可知,该索引信息中包含本发明实施例需要的预索引信息,因此可借助该索引信息所定义的数据结构Huffman_offset_data作为预索引方案所使用的数据结构。Huffman_offset_data结构体的参数以及含义如表1,其中的“数据块”在本发明实施例中指的是MCU块。
表1预索引信息的数据结构示例
Figure PCTCN2017091866-appb-000001
通过JPEG解码库提供的能力获取到所有MCU块的索引信息,每个MCU块的索引信息都以上数据结构的形式存储,可根据实际需要确定数据结构中包含的参数有哪几个。所有的索引信息可以以二维数组[X,Y]的形式存在,其中X表示MCU块在图片中的行号,Y表示MCU块在某一行的第几个。然后,根据需要从该二维数组中选取出合适数量的MCU块的索引信息组成并行解码需要的预索引信息,并将该预索引信息执行持久化存储。具体的,在一种实现方式下,以该数组总行数的1/N为间隔选取N个预索引信息进行持久化存储。
请参阅图4,为本发明实施例提供的并行解码方法的流程示意图。通过上述方法将图片的预索引信息提取和存储之后,该图片下次再需要解码(用户再次打开图片)时就可以采用本发明实施例提供的并行解码方法。
步骤301、确定待解码的图片是否具有预索引信息,若待解码的图片没有预索引信息,则执行原有的解码流程302,在本发明实施例中,原有的解码流程即串行解码流程;若待解码的图片具备预索引信息则执行步骤303。
步骤303、读取预索引信息。在本发明实施例中,读取到的预索引信息中包含的解码边界的信息为N个。N个解码边界的信息对应待解码的图片中N个可被并行处理的数据段。
在其他一些实施例中,由于总有线程是从待解码的图片的第一个MCU块开始解码,所以待解码的图片的首个MCU块的偏移位置信息可以不记录,即仅记录N-1个解码边界的信息就可以在并行处理时获得N个数据段。
预索引信息的读取方式与它的存储位置相关,前述实施例中已经介绍了可能的存储位置,相对应的读取方式均是现有技术,本发明实施例不再赘述。
需说明的是,步骤301和步骤303也可以合成为一个步骤,即通过读取预索引信息确定待解码的图片是否具有预索引信息,如果能读取到预索引信息,则直接执行步骤304;若读取不到预索引信息或读取结果为空则执行步骤302。
在其他一些实施例中,在读取预索引信息之前还可以包括判断待解码的图片的大小的步骤,若待解码的图片的大小小于预设的阈值,则执行原有的解码流程;否则,则在读取预索引信息后执行并行解码流程,若读取不到预索引信息,则执行原有解码流程。待解码的图片的大小信息存储在图片头部,通过解析图片头部,具体是SOF(Start of Frame,帧开始)标记,即可获得该图片的大小信息。
步骤304、验证读取到的预索引信息的完整性。本发明实施例中采用安全哈希算法(Secure Hash Algorithm,SHA)来验证预索引信息的完整性。如果验证失败,说明预索引信息丢失或被修改,为了保证图片解码的准确性,执行步骤305的原有解码流程;若验证成功,执行步骤306。
在其他一些实施例中还可以采用消息摘要算法第五版(简称MD5算法)来进行预索引信息的完整性校验,或采用其它类型的完整性校验算法。
在其他一些实施例中,步骤304也可以不执行,即默认预索引信息都是完整的,或者,可以在存储预索引信息之前采用加密等手段保证预索引信息不被篡改,只需要在使用前对预索引信息解密即可。需要说明的是,进行完整性验证的话需要在预索引信息被提取后,且被存储之前,在预索引信息中加入额外的验证字段,这属于现有的完整性验证技术,本发明实施例不再赘述。
步骤306、获取当前可用的(空闲的)CPU核数Q,确定可同时开启的线程数量M,M=min(N,Q)。当N小于或等于Q时,M=N,则每个线程分别处理一个数据段。当N大于Q时,M=Q,则除最后一个线程外的每个线程处理N/Q(取整)个数据段,最后一个线程处理剩余的部分。
步骤307、解码数据准备。对待解码的图片对应的文件流进行复制。需说明的是,这里的复制文件流仅是复制文件流指针,不是复制整个文件流。可选的,当利用Linux系统中的JPEG解码库实现该方案时,还需要创建与执行并行解码的线程数量相等的解码结构体,该解码结构体是JPEG解码库为解码操作设计的一个结构体,里面包括量化表、颜色通道等预先声明的变量。这样就可以保证每个线程对应的解码结构体之间不共享变量,这样多线程过程中不会相互修改同一个变量。
通过解码数据准备,可以保证每个线程都有自己的文件流指针和解码结构体。这样可以避免线程在解码过程中对文件流或解码结构体中的数据修改而造成的相互干扰问题。另外,解码结构体的创建是内存操作不会影响I/O,同时文件流复制只是复制一个文件流指针,不复制整个文件流,因此并行解码的效率不会受到影响。
步骤308、多个线程并行执行解码。以JPEG图片为例,每个线程会依次完成索引位置恢复、Huffman熵解码、反离散余弦变换(Inverse Discrete Cosine Transform,IDCT)和颜色转化阶段,最终输出图片部分区域的RGB结果。
所有线程均处理完成后会执行数据同步,即将每个线程的处理结果进行整合。整合时 可通过内存指针的方式避免额外的数据拷贝开销,具体的,所有线程将指向目标内存的指定位置的指针的位置作为输入位置,所有线程的解码结果直接输出到该目标内存的指定位置中,这样可避免将解码结果输出到临时内存空间,再拷贝到目标内存空间所带来的数据拷贝开销。
以上步骤中除步骤308外的步骤可采用一个主线程完成,而步骤308可采用多个子线程完成。
以上主要介绍了本发明实施例提供的方法的具体流程,下面结合图5a、图5b、图6a和图6b将以Android操作系统为例,介绍本发明实施例提供的方法的实现位置和运行时状态,更具体的方法流程可参考前述实施例所述。
请参阅图5a,为本发明实施例提供的计算机系统400的结构示意图。该计算机系统400可以是终端设备,也可以是其他类型的计算机设备。该计算机系统包括应用层410和操作系统层450,该操作系统可以为Android操作系统。操作系统层450又分为框架层420、核心库层430和驱动层440。其中,图5中的操作系统层450可以认为是图1中操作系统182的一种具体实现,图5中的应用层410可以认为是图1中应用程序181的一种具体实现。驱动层440包括CPU驱动441、GPU驱动442以及显示控制器驱动443等。核心库层430是操作系统的核心部分,包括输入/输出服务431、核心服务432、图形设备接口434以及实现CPU或GPU图形处理的图形引擎(Graphics Engine)433等。图形引擎433可包括2D引擎、3D引擎、合成器(Composition)、帧缓冲区(Frame Buffer)、EGL(Embedded-System Graphics Library)等,其中EGL是一种渲染API与底层原始平台窗口系统之间的接口,API指的是应用程序编程接口(Application Programming Interface)。框架层420可包括图形服务(Graphic Service)424、系统服务(System service)421、网页服务(Web Service)422和用户服务(Customer Service)423等;图形服务424中,可包括如微件(Widget)、画布(Canvas)以及视图(Views)等。应用层410可包括图库411、媒体播放器(Media Player)412以及浏览器(Browser)413等。
另外,在驱动层440之下,该计算机系统400还包括硬件层450。该计算机系统400的硬件层可以包括中央处理器(Central Processing Unit,CPU)451和图形处理器(Graphic Processing Unit,GPU)452(相当于图1中的处理器150的一种具体实现),还可以包括存储器453(相当于图1中的存储器180),包括内存和外存,还可以包括输入设备454(相当于图1中的输入设备132)、显示设备455(相当于图1中的显示设备140),例如液晶显示器(Liquid Crystal Display,LCD)、全息成像(Holographic)、投影(Projector)等,还可以包括一个或多个传感器456(相当于图1中的传感器120)。当然除此之外,硬件层450还可以包括图1中示出的电源、摄像头、RF电路和WiFi模块,还可以包括图1中也没有示出的其他硬件模块,例如内存控制器和显示控制器等。
本发明前述任意一个实施例提供的方法均可以实现在图5a所示的2D引擎中。
请参阅图5b,为图5a所示的2D引擎的结构示意图。如图5b所示,该2D引擎500主要包括libskia 501和libjpeg 502,其中libskia501可调用libjpeg502提供的功能,libjpeg 502就相当于前面实施例所提到的JPEG解码库。本发明实施例主要在libjpeg 502中增加了并行解码的功能,并适应性修改了libskia 501调用libjpeg 502的接口。另外,2D引擎 500中还可以包含其他图片格式的解码库,例如libpng 503和libgif 504等。
图6a和6b为本发明实施例提供的并行解码方法在该2D引擎500中的运行时序图,其中图6a为获取预索引信息的过程,图6b为根据预索引信息执行并行解码的过程。这两个运行时序图均以用户点击图库411(参考图5a)中的一张图片的缩略图为例来介绍。
如图6a所示,当用第一次点击该图片的缩略图时(601a),图库411向libskia 501发送解码请求(602a),libskia 501创建该图片的文件流,并将文件流传输给libjpeg502(603a),libjpeg502读取预索引信息失败(604a)后将该预索引信息获取失败的结果返回给libskia 501,libskia501根据该返回结果调用libjpeg502提供的串行解码功能(605a),libjpeg502对上述文件流执行串行Huffman解码(606a)等过程。进一步的,在确定图片大小大于预设的阈值(607a)时,libjpeg502会根据606a的解码结果提取预索引信息(608a)并存储提取出的预索引信息(609a)。libjpeg 502完成图片解码之后会通过libskia 501将解码结果返回到图库411(610a),然后图库411向用户显示打开后的图片(611a)。
在本发明实施例中,串行Huffman解码是libjpeg502执行的,所以libjpeg502可以从解码结果中直接提取预索引信息,但在其他一些实施例中,为了尽量少的改动原有的解码流程代码,libjpeg502解码后将解码获得的所有MCU块的偏移位置信息传递给libskia501,然后libskia501再将所有MCU块的索引信息传递给libjpeg502,然后libjpeg502再从这些信息中提取预索引信息。
在其他一些实施例中,步骤605a和606a可以替换为区域解码,由于区域解码中对所有MCU块的偏移位置信息的提取在解码步骤之前,所以步骤607a和步骤608a可以放到区域解码之前。
如图6b所示,用户点击该图片的缩略图(601b)后,图库411向libskia 501发送解码请求(602b),,libskia 501创建该图片的文件流,并将文件流传输给libjpeg502(603b),libjpeg502读取预索引信息(604b)以及验证预索引信息的完整性(605b),然后验证通过结果返回给libskia 501,libskia501做解码准备(607b),包括复制M-1个上述文件的指针等(M为同时启动的线程数量),复制完成后调用libjpeg 502,由libjpeg调用M个线程执行对上述文件流的并行解码(608b)等过程。libjpeg 502完成图片解码之后会通过libskia 501将解码结果返回到图库411(609b),然后图库411向用户显示打开后的图片(610b)。另外,在实现过程中,libjpeg502除了读取预索引信息外还读取了图像文件的描述信息(例如量化表、文件大小等),这些属于现有有技术,在此不赘述。图库411调用2D引擎中的libskia 501具体可通过调用图形设备接口434(参考图5a)中的BitmapFactory接口实现,这也属于现有技术,本发明实施例不再赘述。
需要说明的是,图6a-6b提供的运行时序图仅示例性的介绍了本发明提供的方法实施例,本领域技术人员根据本发明前述实施例介绍的多种方法以及这两个运行时序图的示例容易得到本发明提供的其他方法实施例对应的运行时序图以及根据时序图做相应的程序实现,在此不再赘述。
通过以上介绍的装置和方法可以看出,应用本发明实施例提供的并行解码方法的计算机系统可以在实现对文件的并行解码,提高解码效率的同时,有效避免系统卡顿现象,从 而提升用户体验。
请参阅图7a,为本发明实施例提供的解码装置700的结构示意图。该解码装置700包括读取模块701,用于从存储器800中读取待解码的文件对应的预索引信息,所述预索引信息包括指示一个或多个解码边界的信息,并且所述预索引信息存储在与所述待解码的文件关联的其他文件中或所述待解码的文件的尾部;以及并行解码模块702,用于根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码,其中所述多个数据段是依据所述一个或多个解码边界中的一个或多个进行划分的。存储器800包括内存和外存,预索引信息通常存储在外存上。
进一步的,如图7b所示,该解码装置700还可以包括提取模块703,用于当监测到所述待解码的文件新增、所述待解码的文件被修改、或所述待解码的文件第一次被打开时,提取所述预索引信息;以及存储模块704,用于存储提取的所述预索引信息到存储器800中。
更进一步的,该解码装置700还可以包括确定模块705和确定模块706中的一个或两个,两个确定模块都用于确定文件大小大于预设的阈值,提取模块703和读取模块701根据该确定结果分别执行相应的提取操作和读取操作。进一步的,该解码装置700还可以包括阈值修改模块707,用于修改确定模块705和确定模块706中的阈值。在其他一些实施例中,确定模块705和确定模块706也可以合并为一个模块。
在图7a的基础上,如图7c所示,该解码装置700还可以包括完整性验证模块703,用于验证读取模块701读取到的预索引信息的完整性,并行解码模块702在完整性验证模块703的验证结果为通过时再对文件执行并行解码。进一步的,该解码装置700还可以包括数据准备模块704,用于复制待解码的文件的文件流以获得与执行所述并行解码的多个线程的数量相等的文件流,其中,复制所述文件流指的是复制所述文件流的指针。根据以上方法实施例的描述可知,数据准备模块704还可以根据需求复制或创建并行解码需要的其他信息。
需要说明的是,完整性验证模块703和数据准备模块704也可以在图7b所示的解码装置的基础上增加。图7a-7c中虚线表示的模块均是可选的模块。
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本发明提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本发明实施例所述的绘图装置可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。

Claims (20)

  1. 一种解码方法,其特征在于,包括:
    读取待解码的文件对应的预索引信息,所述待解码的文件采用可变长编码;其中,所述预索引信息包括指示一个或多个解码边界的信息,所述预索引信息存储在与所述待解码的文件关联的其他文件中或所述待解码的文件的尾部;
    根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码,所述多个数据段是依据所述一个或多个解码边界中的一个或多个进行划分的。
  2. 根据权利要求1所述的方法,其特征在于,在所述读取待解码的文件对应的预索引信息之前,还包括:
    当监测到所述待解码的文件新增、所述待解码的文件被修改、或所述待解码的文件第一次被打开时,提取所述预索引信息;
    存储提取的所述预索引信息。
  3. 根据权利要求2所述的方法,其特征在于,提取的所述预索引信息所指示的解码边界的数量是根据处理资源的处理能力确定的。
  4. 根据权利要求1-3任意一项所述的方法,其特征在于,所述读取所述待解码的文件对应的预索引信息包括:
    确定所述待解码的文件的大小大于预设的第一阈值;
    根据所述确定结果读取所述待解码的文件对应的预索引信息。
  5. 根据权利要求2或3所述的方法,其特征在于,所述提取所述预索引信息包括:
    确定所述待解码文件的大小大于预设的第一阈值;
    根据所述确定结果提取所述预索引信息。
  6. 根据权利要求4或5所述的方法,其特征在于,所述预设的第一阈值通过以下方式修改:
    在所述待解码的文件被解码完成后,记录所述待解码的文件的大小、解码时间以及是否执行并行解码;
    若所述待解码的文件使用并行解码,所述解码时间小于预设的第二阈值且所述待解码的文件的大小大于所述预设的第一阈值,修改所述预设的第一阈值为所述待解码的文件的大小。
  7. 根据权利要求1-6任意一项所述的方法,其特征在于,在根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码之前,所述方法还包括:
    复制所述待解码的文件的文件流以获得与待执行所述并行解码的多个线程的数量相等的文件流,其中,复制所述文件流指的是复制所述文件流的指针。
  8. 根据权利要求1-7任意一项所述的方法,其特征在于,所述根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码包括:
    确定所述预索引信息通过完整性验证;
    在确定所述预索引信息通过完整性验证后,根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码的步骤。
  9. 根据权利要求1-8任意一项所述的方法,其特征在于,所述其他文件为元数据文件、数据库文件、或与所述待解码的文件在同一目录下的,与所述待解码的文件的 文件名相同的文件。
  10. 根据权利要求9所述的方法,其特征在于,所述元数据文件为系统文件。
  11. 一种计算机系统,其特征在于,包括一个或多个处理器,以及与所述一个或多个处理器耦合的存储器;所述存储器用于存储计算机程序,所述一个或多个处理器用于读取所述计算机程序以执行:
    读取待解码的文件对应的预索引信息,所述待解码的文件采用可变长编码;其中,所述预索引信息包括指示一个或多个解码边界的信息,所述预索引信息存储在与所述待解码的文件关联的其他文件中或所述待解码的文件的尾部;以及
    根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码,其中所述多个数据段是依据所述一个或多个解码边界中的一个或多个进行划分的。
  12. 根据权利要求11所述的计算机系统,其特征在于,所述一个或多个处理器还用于:当监测到所述待解码的文件新增、所述待解码的文件被修改、或所述待解码的文件第一次被打开时,提取所述预索引信息;以及存储提取的所述预索引信息。
  13. 根据权利要求12所述的计算机系统,其特征在于,提取的所述预索引信息所指示的解码边界的数量是根据处理资源的处理能力确定的。
  14. 根据权利要求12或13所述的计算机系统,其特征在于,所述一个或多个处理器用于:确定所述待解码文件的大小大于预设的第一阈值;根据所述确定结果提取所述预索引信息。
  15. 根据权利要求14所述的计算机系统,其特征在于,所述一个或多个处理器还用于通过以下方式修改所述预设的第一阈值:在所述待解码的文件被解码完成后,记录所述待解码的文件的大小、解码时间以及是否执行并行解码;若所述待解码的文件使用并行解码,所述解码时间小于预设的第二阈值且所述待解码的文件的大小大于所述预设的第一阈值,修改所述预设的第一阈值为所述待解码的文件的大小。
  16. 根据权利要求11-15任意一项所述的计算机系统,其特征在于,所述其他文件为元数据文件、数据库文件、或与所述待解码的文件在同一目录下的,与所述待解码的文件的文件名相同的文件。
  17. 根据权利要求16所述的计算机系统,其特征在于,所述元数据文件为系统文件。
  18. 一种解码装置,其特征在于,包括:
    读取模块,用于读取待解码的文件对应的预索引信息,所述预索引信息包括指示一个或多个解码边界的信息,所述预索引信息存储在与所述待解码的文件关联的其他文件中或所述待解码的文件的尾部,并且所述待解码的文件采用可变长编码;以及
    并行解码模块,用于根据所述预索引信息,对所述待解码的文件中的多个数据段执行并行解码,其中所述多个数据段是依据所述一个或多个解码边界中的一个或多个进行划分的。
  19. 根据权利要求18所述的解码装置,其特征在于,还包括:
    提取模块,用于当监测到所述待解码的文件新增、所述待解码的文件被修改、或所述待解码的文件第一次被打开时,提取所述预索引信息;
    存储模块,用于存储提取的所述预索引信息。
  20. 根据权利要求19所述的解码装置,其特征在于,所述提取模块提取的所述预索引信息所指示的解码边界的数量是根据处理资源的处理能力确定的。
PCT/CN2017/091866 2016-07-08 2017-07-05 可变长编码文件的解码方法以及装置 WO2018006833A1 (zh)

Priority Applications (4)

Application Number Priority Date Filing Date Title
BR112018077468A BR112018077468A2 (pt) 2016-07-08 2017-07-05 método, aparelho, sistema de computador, produto de programa de software, e mídia de armazenamento para decodificar arquivo codificado de comprimento variável
EP17823645.1A EP3468047A4 (en) 2016-07-08 2017-07-05 METHOD AND DEVICE FOR DECODING A VARIABLE LENGTH ENCODING FILE
KR1020197001291A KR102147633B1 (ko) 2016-07-08 2017-07-05 가변 길이 코딩된 파일을 디코딩하는 방법 및 장치
US16/241,058 US11284119B2 (en) 2016-07-08 2019-01-07 Method and apparatus for decoding variable-length coded file

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610542045.0 2016-07-08
CN201610542045.0A CN107592118B (zh) 2016-07-08 2016-07-08 可变长编码文件的解码方法以及装置

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US16/241,058 Continuation US11284119B2 (en) 2016-07-08 2019-01-07 Method and apparatus for decoding variable-length coded file

Publications (1)

Publication Number Publication Date
WO2018006833A1 true WO2018006833A1 (zh) 2018-01-11

Family

ID=60912369

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/091866 WO2018006833A1 (zh) 2016-07-08 2017-07-05 可变长编码文件的解码方法以及装置

Country Status (6)

Country Link
US (1) US11284119B2 (zh)
EP (1) EP3468047A4 (zh)
KR (1) KR102147633B1 (zh)
CN (1) CN107592118B (zh)
BR (1) BR112018077468A2 (zh)
WO (1) WO2018006833A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115001628A (zh) * 2022-06-07 2022-09-02 北京百度网讯科技有限公司 数据编码的方法及装置、数据解码的方法及装置和数据结构

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109656712B (zh) * 2018-11-29 2022-12-09 中国辐射防护研究院 一种提取grib码数据的方法及系统
CN109656614A (zh) * 2018-12-24 2019-04-19 中国银行股份有限公司 文件的处理方法、装置及系统
CN112835651B (zh) * 2021-04-01 2023-10-20 中国空空导弹研究院 一种多路图像并行解码处理方法
CN114071154A (zh) * 2021-11-10 2022-02-18 湖南国科微电子股份有限公司 一种数据解码方法、装置、电子设备及可读存储介质

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101859585A (zh) * 2010-07-01 2010-10-13 福建省三奥信息科技有限公司 一种对视频素材进行帧精确剪辑的系统和方法
CN102761745A (zh) * 2012-07-12 2012-10-31 国家计算机网络与信息安全管理中心 解码方法和解码设备
CN105578194A (zh) * 2016-01-06 2016-05-11 珠海全志科技股份有限公司 Jpeg图像解码方法和解码器

Family Cites Families (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5381145A (en) * 1993-02-10 1995-01-10 Ricoh Corporation Method and apparatus for parallel decoding and encoding of data
US6043765A (en) 1997-09-26 2000-03-28 Silicon Engineering, Inc. Method and apparatus for performing a parallel speculative Huffman decoding using both partial and full decoders
US7129864B2 (en) * 2004-12-31 2006-10-31 Intel Corporation Fast compact decoder for huffman codes
US8121428B2 (en) 2005-05-31 2012-02-21 Microsoft Corporation Accelerated image rendering
CN100546198C (zh) * 2006-10-20 2009-09-30 宁波大学 一种数字音乐作品认证信息的嵌入方法
SE533185C2 (sv) 2007-02-16 2010-07-13 Scalado Ab Metod för behandling av en digital bild samt bildrepresentationsformat
CN101051846A (zh) * 2007-05-09 2007-10-10 上海广电(集团)有限公司中央研究院 一种基于上下文的快速哈夫曼解码方法
CN101626504B (zh) * 2008-07-09 2012-06-06 上海飞来飞去多媒体创意有限公司 一种高速jpeg解码的方法
US8423520B2 (en) * 2009-11-23 2013-04-16 Dell Products L.P. Methods and apparatus for efficient compression and deduplication
US8520958B2 (en) 2009-12-21 2013-08-27 Stmicroelectronics International N.V. Parallelization of variable length decoding
US8174414B2 (en) * 2010-04-13 2012-05-08 Research In Motion Limited Methods and devices for load balancing in parallel entropy coding and decoding
EP2381685B1 (en) * 2010-04-13 2019-01-02 BlackBerry Limited Methods and devices for load balancing in parallel entropy coding and decoding
EP2622744B1 (en) * 2010-10-01 2019-11-06 BlackBerry Limited Methods and devices for parallel encoding and decoding using a bitstream structured for reduced delay
CN103297767B (zh) 2012-02-28 2016-03-16 三星电子(中国)研发中心 一种适用于多核嵌入式平台的jpeg图像解码方法及解码器
CN103377131A (zh) * 2012-04-13 2013-10-30 索尼公司 数据处理装置和方法
CN102970544A (zh) 2012-12-07 2013-03-13 豪威科技(上海)有限公司 Jpeg编码和解码方法及系统

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101859585A (zh) * 2010-07-01 2010-10-13 福建省三奥信息科技有限公司 一种对视频素材进行帧精确剪辑的系统和方法
CN102761745A (zh) * 2012-07-12 2012-10-31 国家计算机网络与信息安全管理中心 解码方法和解码设备
CN105578194A (zh) * 2016-01-06 2016-05-11 珠海全志科技股份有限公司 Jpeg图像解码方法和解码器

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3468047A4 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115001628A (zh) * 2022-06-07 2022-09-02 北京百度网讯科技有限公司 数据编码的方法及装置、数据解码的方法及装置和数据结构
CN115001628B (zh) * 2022-06-07 2024-02-27 北京百度网讯科技有限公司 数据编码的方法及装置、数据解码的方法及装置和数据结构

Also Published As

Publication number Publication date
KR102147633B1 (ko) 2020-08-25
KR20190020039A (ko) 2019-02-27
CN107592118A (zh) 2018-01-16
CN107592118B (zh) 2021-06-22
US11284119B2 (en) 2022-03-22
BR112018077468A2 (pt) 2019-04-02
EP3468047A1 (en) 2019-04-10
EP3468047A4 (en) 2019-06-26
US20190141356A1 (en) 2019-05-09

Similar Documents

Publication Publication Date Title
WO2018006833A1 (zh) 可变长编码文件的解码方法以及装置
US11347370B2 (en) Method and system for video recording
US20210235093A1 (en) Backward-compatible video capture and distribution
KR102124231B1 (ko) 플레이스홀더 및 콘텐츠 스트리밍 기법
KR102128138B1 (ko) 플레이스홀더에 의한 하이드레이션 및 디하이드레이션 기법
KR102128139B1 (ko) 플레이스홀더에 의한 파일 관리 기법
US8996468B1 (en) Block status mapping system for reducing virtual machine backup storage
CN106453572B (zh) 基于云服务器同步图像的方法及系统
US10430040B2 (en) Method and an apparatus for providing a multitasking view
US20120307078A1 (en) Automatic sharing and replacement of content based on network connectivity
US20140258347A1 (en) Grouping files for optimized file operations
KR102575541B1 (ko) 이미지를 캡처하기 위한 방법, 단말기 및 이의 저장 매체
WO2023083064A1 (zh) 视频处理方法、装置、电子设备及可读存储介质
WO2018201993A1 (zh) 图像绘制方法、终端及存储介质
KR20160131827A (ko) 클라우드 스트리밍 서비스 시스템, 알파 레벨을 이용한 이미지 클라우드 스트리밍 서비스 방법 및 이를 위한 장치
US20210264657A1 (en) Method, system, and non-transitory computer-readable record medium for providing animation using sprite jpeg
CN108235144B (zh) 播放内容获取方法、装置及计算设备
CN104392410A (zh) 皮肤系统中的图片整合方法、皮肤绘制方法及设备
KR102247887B1 (ko) 클라우드 스트리밍 서비스 시스템, 소스 정보를 이용한 클라우드 스트리밍 서비스 방법 및 이를 위한 장치
JP5890674B2 (ja) 情報処理装置、情報処理方法
US11599293B2 (en) Consistent data stream replication and reconstruction in a streaming data storage platform
WO2022111435A1 (zh) 一种usb设备随通道录音的方法、装置及存储介质
KR102425277B1 (ko) 클라우드 스트리밍 서버의 자가 오류 검증을 위한 테스트 화면 제공 방법 및 이를 위한 장치
CN117648142A (zh) 一种图像的获取方法和电子设备
CN116934570A (zh) 一种应用程序页面的图像处理方法、装置及电子设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17823645

Country of ref document: EP

Kind code of ref document: A1

REG Reference to national code

Ref country code: BR

Ref legal event code: B01A

Ref document number: 112018077468

Country of ref document: BR

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 20197001291

Country of ref document: KR

Kind code of ref document: A

ENP Entry into the national phase

Ref document number: 2017823645

Country of ref document: EP

Effective date: 20190103

ENP Entry into the national phase

Ref document number: 112018077468

Country of ref document: BR

Kind code of ref document: A2

Effective date: 20181228