CN105791828A - Binary Arithmetic Coder and Its Encoding Method - Google Patents
Binary Arithmetic Coder and Its Encoding Method Download PDFInfo
- Publication number
- CN105791828A CN105791828A CN201511033027.1A CN201511033027A CN105791828A CN 105791828 A CN105791828 A CN 105791828A CN 201511033027 A CN201511033027 A CN 201511033027A CN 105791828 A CN105791828 A CN 105791828A
- Authority
- CN
- China
- Prior art keywords
- coding
- normalization
- interval
- selector
- encoding
- Prior art date
- Legal status (The legal status 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 status listed.)
- Granted
Links
Landscapes
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
Description
技术领域technical field
本发明涉及视频编码技术领域,特别涉及一种编码区间更新与归一化模块、编码下限更新与归一化模块和码流提取模块,还涉及一种包含所述编码区间更新与归一化模块、编码下限更新与归一化模块和码流提取模块的二进制算术编码器及其编码方法。The present invention relates to the technical field of video coding, in particular to a coding interval update and normalization module, a coding lower limit update and normalization module, and a code stream extraction module, and also relates to a coding interval update and normalization module 1. A binary arithmetic coder and a coding method of a coding lower limit update and normalization module and a code stream extraction module.
背景技术Background technique
二进制算术编码器(Context-basedAdaptiveBinaryArithmeticCoder,简称CABAC)是根据二进制算术编码原理设计的编码器,CABAC中的二进制算术编码技术是基于区间的递归划分原理的。CABAC的编码过程包括:二进制化、上下文建模和算术编码。其中,二进制化是将语法元素进行简单变长映射成一串二进制位,算术编码是对每一位进行编码得到H.264/AVC的输出码流,算术编码包括区间细分和区间归一化。Binary arithmetic coder (Context-based Adaptive Binary Arithmetic Coder, referred to as CABAC) is an encoder designed according to the principle of binary arithmetic coding. The binary arithmetic coding technology in CABAC is based on the principle of recursive division of intervals. The coding process of CABAC includes: binarization, context modeling and arithmetic coding. Among them, binarization is to map syntax elements into a series of binary bits through simple variable-length mapping. Arithmetic coding is to encode each bit to obtain the output stream of H.264/AVC. Arithmetic coding includes interval subdivision and interval normalization.
目前,H.264/AVC标准的二进制算术编码有三种模式,分别是常规编码模式、等概率编码模式(bypass编码模式)和截止编码模式。Currently, there are three modes of binary arithmetic coding in the H.264/AVC standard, which are a regular coding mode, an equal-probability coding mode (bypass coding mode) and a cut-off coding mode.
以常规编码模式为例,编码区间(range)分成两个子间隔,即小概率字符(LPS)的区间和大概率字符(MPS)的区间。其中,小概率字符的区间长度用rLPS表示,大概率字符的区间长度用rMPS表示,rMPS=range-rLPS。区间划分时为了减少计算量,二进制算术编码器中通过查表的方式得到rLPS。新的编码区间(range)是根据当前的编码符号(bin)是小概率字符(LPS)还是大概率字符(MPS)来确定的。为了使编码区间(range)保持在一定的范围内,需要对编码区间(range)进行归一化。在常规编码模式中,编码区间(range)的取值范围在28到29之间。若新的编码区间(range)超出了该取值范围,就需要对该编码区间(range)进行归一化,使其保持在28到29之间。归一化过程中还包括对编码下限(low)进行调整,使其与归一化后的编码区间相匹配。Taking the conventional encoding mode as an example, the encoding range (range) is divided into two sub-intervals, namely the interval of low probability characters (LPS) and the interval of high probability characters (MPS). Wherein, the range length of characters with low probability is represented by rLPS, and the range length of characters with high probability is represented by rMPS, rMPS=range-rLPS. In order to reduce the amount of calculation during interval division, the rLPS is obtained by looking up a table in the binary arithmetic coder. The new encoding interval (range) is determined according to whether the current encoding symbol (bin) is a low probability character (LPS) or a high probability character (MPS). In order to keep the coding range within a certain range, the coding range needs to be normalized. In the normal coding mode, the value range of the coding interval (range) is between 2 8 and 2 9 . If the new coding range (range) exceeds the value range, the coding range (range) needs to be normalized to keep it between 2 8 and 2 9 . The normalization process also includes adjusting the encoding lower limit (low) to match the normalized encoding range.
对于等概率编码模式而言,编码区间(range)是固定不变的。当编码符号(bin)为“0”时,编码下限(low)为2*low。当编码符号(bin)为“1”时,编码下限(low)则为2*low+range。For the equal-probability coding mode, the coding interval (range) is fixed. When the encoding symbol (bin) is "0", the encoding lower limit (low) is 2*low. When the coding symbol (bin) is "1", the coding lower limit (low) is 2*low+range.
对于截止编码模式而言,小概率字符的区间长度(rLPS)固定为2,其他操作与常规编码模式相同。For the cut-off encoding mode, the interval length (rLPS) of the low probability character is fixed at 2, and other operations are the same as the regular encoding mode.
可见,三种编码模式各有差异,传统的二进制算术编码器中若要同时处理三种编码模式,必须要设置专门的逻辑控制电路,增加额外的硬件成本。并且,二进制算术编码是串行编码,并行性差,完成当前编码符号(bin)一般需要多次迭代,后续编码符号(bin)的编码依赖于当前编码符号(bin)的迭代结果。而且,在归一化过程中还需要不断调整编码下限(low)的范围,归一化的计算非常复杂。目前,有些二进制算术编码器只能实现部分并行化,还有些二进制算术编码器虽然能够实现完全并行化,但是无法统一处理常规编码模式、等概率编码模式和截止编码模式这三种编码模式,即三种编码模式分开处理,重用性差。此外,目前码流提取的技术也比较落后,一般需要多个时钟周期才能完成一个编码符号(bin)的码流提取操作,为此需要依靠加数据FIFO的方式来解决码流提取操作和归一化操作之间的时间差。It can be seen that the three encoding modes are different from each other. If the traditional binary arithmetic encoder wants to process the three encoding modes at the same time, it is necessary to set up a special logic control circuit and increase additional hardware costs. Moreover, the binary arithmetic coding is a serial coding, and the parallelism is poor. It generally needs multiple iterations to complete the current coding symbol (bin), and the coding of the subsequent coding symbol (bin) depends on the iteration result of the current coding symbol (bin). Moreover, in the process of normalization, it is necessary to continuously adjust the range of the encoding lower limit (low), and the calculation of normalization is very complicated. At present, some binary arithmetic coders can only achieve partial parallelization, and although some binary arithmetic coders can achieve complete parallelization, they cannot uniformly handle the three coding modes of conventional coding mode, equal probability coding mode and cut-off coding mode, namely The three coding modes are handled separately, and the reusability is poor. In addition, the current code stream extraction technology is relatively backward. Generally, multiple clock cycles are required to complete the code stream extraction operation of a coded symbol (bin). Therefore, it is necessary to rely on the method of adding data FIFO to solve the code stream extraction operation and normalization. time difference between operations.
发明内容Contents of the invention
本发明的目的在于提供一种二进制算术编码器及其编码方法,以解决现有的二进制算术编码并行性差的问题。The object of the present invention is to provide a binary arithmetic coder and its coding method, so as to solve the problem of poor parallelism in the existing binary arithmetic codes.
本发明的另一目的在于解决现有技术中二进制算术编码重用性差的问题。Another object of the present invention is to solve the problem of poor reusability of binary arithmetic coding in the prior art.
本发明的又一目的在于解决现有技术中码流提取操作复杂的问题。Another object of the present invention is to solve the problem of complex code stream extraction operations in the prior art.
为解决上述技术问题,本发明提供一种二进制算术编码器,用于输出多种编码模式的二进制算术编码的码流,包括编码区间更新与归一化模块、编码下限更新与归一化模块和码流提取模块,所述编码区间更新与归一化模块、编码下限更新与归一化模块和码流提取模块形成并行的三级流水结构;In order to solve the above technical problems, the present invention provides a binary arithmetic coder for outputting code streams of binary arithmetic codes in multiple coding modes, including a coding interval update and normalization module, a coding lower limit update and normalization module and A code stream extraction module, the encoding interval update and normalization module, the encoding lower limit update and normalization module and the code stream extraction module form a parallel three-stage pipeline structure;
所述编码区间更新与归一化模块,作为第一级流水引擎,用于提取编码状态、编码模式以及编码符号,更新编码区间和完成编码区间的归一化,并输出编码区间归一化的迭代次数以及编码区间至所述编码下限更新与归一化模块;The coding interval update and normalization module, as a first-level pipeline engine, is used to extract the coding state, coding mode and coding symbols, update the coding interval and complete the normalization of the coding interval, and output the normalized coding interval The number of iterations and the coding interval to the coding lower limit update and normalization module;
所述编码下限更新与归一化模块,作为第二级流水引擎,用于提取编码符号、编码模式、编码区间归一化的迭代次数以及编码区间,更新编码下限和完成编码下限的归一化,并输出编码下限的溢出位以及编码下限归一化的迭代次数至码流提取模块;The coding lower limit update and normalization module, as a second-level pipeline engine, is used to extract coding symbols, coding modes, the number of iterations of normalization of coding intervals and coding intervals, update the coding lower limit and complete the normalization of the coding lower limit , and output the overflow bit of the encoding lower limit and the number of iterations of the encoding lower limit normalization to the code stream extraction module;
所述码流提取模块,作为第三级流水引擎,用于提取所述编码下限归一化的迭代次数和编码下限的溢出位,输出变长码流以及码流长度。The code stream extraction module, as a third-stage pipeline engine, is used to extract the number of iterations normalized by the encoding lower limit and the overflow bit of the encoding lower limit, and output a variable-length code stream and the length of the code stream.
优选的,所述的二进制算术编码器中,所述编码区间更新与归一化模块还输出大概率字符的区间长度至所述编码下限更新与归一化模块。Preferably, in the binary arithmetic coder, the encoding interval update and normalization module also outputs the interval length of the high-probability character to the encoding lower limit update and normalization module.
优选的,所述的二进制算术编码器中,通过选择器实现模式复用。Preferably, in the binary arithmetic encoder, mode multiplexing is realized through a selector.
优选的,所述的二进制算术编码器中,所述编码模式包括常规编码模式、等概率编码模式和截止编码模式。Preferably, in the binary arithmetic coder, the coding modes include normal coding mode, equal probability coding mode and cut-off coding mode.
优选的,所述的二进制算术编码器中,模式复用时,所述编码区间更新与归一化模块包括第一选择器、第一减法器、第二选择器、首1检测电路、第一移位器和第一D触发器;其中,第一选择器,用于根据提取的编码模式获得当前编码模式下的小概率字符的区间长度;第一减法器,用于根据当前的编码区间和当前编码模式下的小概率字符的区间长度,获得当前编码模式下的大概率字符的区间长度;第二选择器,用于根据当前编码模式和当前编码符号从当前的编码区间、当前编码模式下的小概率字符的区间长度和当前编码模式下的大概率字符的区间长度中择一作为归一化前的编码区间进行输出;首1检测电路,用于对所述归一化前的编码区间进行前导0计数,得到编码区间归一化的迭代次数;第一移位器,用于根据所述编码区间归一化的迭代次数对归一化前的编码区间进行左移输出归一化后的编码区间,归一化后的编码区间经所述第一D触发器后输出编码区间待下一周期备用。Preferably, in the binary arithmetic encoder, when the mode is multiplexed, the encoding interval update and normalization module includes a first selector, a first subtractor, a second selector, a first 1 detection circuit, a first Shifter and the first D flip-flop; Wherein, the first selector is used to obtain the interval length of the low-probability character under the current encoding mode according to the encoding mode extracted; The interval length of the low-probability character in the current encoding mode is used to obtain the interval length of the high-probability character in the current encoding mode; the second selector is used to select from the current encoding interval and the current encoding mode according to the current encoding mode and the current encoding symbol Select one of the interval length of the small probability character and the interval length of the high probability character under the current encoding mode as the encoding interval before normalization to output; the first 1 detection circuit is used to encode the encoding interval before the normalization Count the leading 0s to obtain the number of iterations of the normalization of the coding interval; the first shifter is used to shift the coding interval before normalization to the left according to the number of iterations of the normalization of the coding interval and output the normalized After the normalized coding interval is passed through the first D flip-flop, the coding interval is output to be used in the next cycle.
优选的,所述的二进制算术编码器中,当所述编码模式是等概率编码模式时,所述编码区间更新与归一化模块包括第一触发器,编码区间直接输出作为归一化后的编码区间,归一化后的编码区间经所述第一D触发器后输出编码区间待下一周期备用。Preferably, in the binary arithmetic encoder, when the encoding mode is an equal probability encoding mode, the encoding interval update and normalization module includes a first trigger, and the encoding interval is directly output as the normalized The coding interval, after the normalized coding interval passes through the first D flip-flop, outputs the coding interval to be used in the next cycle.
优选的,所述的二进制算术编码器中,当所述编码模式是截止编码模式时,所述编码区间更新与归一化模块包括第一减法器、第二选择器、首1检测电路、第一移位器和第一D触发器;其中,第一减法器,用于根据当前的编码区间和当前编码模式下的小概率字符的区间长度,获得当前编码模式下的大概率字符的区间长度;第二选择器,用于根据当前编码模式和当前编码符号,从所述当前编码模式下的小概率字符的区间长度或当前编码模式下的大概率字符的区间长度中择一作为归一化前的编码区间进行输出;首1检测电路,用于对所述归一化前的编码区间进行前导0计数,得到编码区间归一化的迭代次数;第一移位器,用于根据所述编码区间归一化的迭代次数对归一化前的编码区间进行左移输出归一化后的编码区间,归一化后的编码区间经所述第一D触发器后输出编码区间待下一周期备用。Preferably, in the binary arithmetic encoder, when the encoding mode is a cut-off encoding mode, the encoding interval update and normalization module includes a first subtractor, a second selector, a first 1 detection circuit, a first A shifter and the first D flip-flop; wherein, the first subtractor is used to obtain the interval length of the high-probability character under the current encoding mode according to the interval length of the low-probability character under the current encoding interval and the current encoding mode ; The second selector is used to select one of the interval lengths of low-probability characters in the current encoding mode or the interval length of high-probability characters in the current encoding mode as normalization according to the current encoding mode and the current encoding symbol The first 1 detection circuit is used to count the leading 0 of the coding interval before the normalization to obtain the number of iterations of the normalization of the coding interval; the first shifter is used for according to the The number of iterations of the normalization of the coding interval is to shift the coding interval before normalization to the left to output the normalized coding interval, and the normalized coding interval is passed through the first D flip-flop to output the coding interval and wait for the next cycle backup.
优选的,所述的二进制算术编码器中,模式复用时,所述编码下限更新与归一化模块包括第三选择器、第四选择器、第一加法器、第五选择器、第二移位器、第三移位器、第四移位器、第一比较器和第二D触发器;其中,第三选择器,用于根据当前编码模式和当前编码符号,从所述当前的编码区间、当前编码模式下的大概率字符的区间长度和编码下限的默认值中择一作为输出;第四选择器,用于根据当前编码模式从编码下限或2倍的编码下限中择一作为输出;第一加法器,用于根据所述第三选择器和第四选择器获得归一化前的编码下限;第五选择器,用于根据所述编码模式从所述编码区间归一化的迭代次数和编码下限归一化的迭代次数的默认值中择一作为编码下限归一化的迭代次数进行输出;第二移位器,用于根据编码下限归一化的迭代次数将归一化前的编码下限左移,取低9位,得到归一化后的编码下限的低9位;第三移位器,用于将所述第二移位器所得结果右移9位得到编码下限的溢出位;第四移位器,用于根据编码下限归一化的迭代次数将常数0x1ff右移,常数0x1ff右移后与归一化前的编码下限按位或操作的结果通过第一比较器与常数0x3ff进行比较,根据比较结果得到归一化后的编码下限的最高位,归一化后的编码下限经过所述第二D触发器后,输出编码下限待下一周期备用。Preferably, in the binary arithmetic encoder, when the mode is multiplexed, the encoding lower limit update and normalization module includes a third selector, a fourth selector, a first adder, a fifth selector, a second shifter, a third shifter, a fourth shifter, a first comparator and a second D flip-flop; wherein, the third selector is used to select from the current Choose one of the encoding interval, the interval length of the high-probability character in the current encoding mode, and the default value of the encoding lower limit as the output; the fourth selector is used to select one of the encoding lower limit or 2 times the encoding lower limit according to the current encoding mode. output; the first adder is used to obtain the lower limit of coding before normalization according to the third selector and the fourth selector; the fifth selector is used to normalize from the coding interval according to the coding mode The number of iterations of the encoding lower limit normalization and the default value of the number of iterations of the encoding lower limit normalization are selected as the iteration number of the encoding lower limit normalization; the second shifter is used to normalize the number of iterations according to the encoding lower limit normalization The encoding lower limit before normalization is shifted to the left, and the lower 9 bits are taken to obtain the lower 9 bits of the encoding lower limit after normalization; the third shifter is used to shift the result obtained by the second shifter to the right by 9 bits to obtain the encoding The overflow bit of the lower limit; the fourth shifter is used to shift the constant 0x1ff to the right according to the number of iterations normalized by the lower limit of the encoding, and the result of the bitwise OR operation of the constant 0x1ff and the lower limit of the encoding before normalization is passed through the first The comparator compares with the constant 0x3ff, and obtains the highest bit of the normalized coding lower limit according to the comparison result. After the normalized coding lower limit passes through the second D flip-flop, the output coding lower limit is ready for use in the next cycle.
优选的,所述的二进制算术编码器中,当前编码模式为常规编码模式且编码符号为小概率字符的区间长度时,所述第三选择器选择大概率字符的区间长度为输出;当前编码模式为等概率编码模式且编码符号为1时,所述第三选择器选择当前的编码区间为输出;其余情况所述第三选择器选择编码下限的默认值为输出。Preferably, in the binary arithmetic coder, when the current encoding mode is the regular encoding mode and the encoding symbol is the interval length of the low-probability character, the third selector selects the interval length of the high-probability character as output; the current encoding mode When it is an equal probability coding mode and the coding symbol is 1, the third selector selects the current coding interval as output; in other cases, the third selector selects the default value of the coding lower limit as output.
优选的,所述的二进制算术编码器中,当前编码模式为等概率编码模式时,所述第四选择器选择2倍的编码下限为输出,其他情况选择编码下限为输出。Preferably, in the binary arithmetic coder, when the current coding mode is an equal probability coding mode, the fourth selector selects twice the coding lower limit as the output, and otherwise selects the coding lower limit as the output.
优选的,所述的二进制算术编码器中,当前编码模式为等概率编码模式时,所述第五选择器选择编码下限归一化的迭代次数的默认值为输出,其他情况所述第五选择器选择编码区间归一化的迭代次数为输出。Preferably, in the binary arithmetic coder, when the current coding mode is an equal probability coding mode, the fifth selector selects the default value of the number of iterations of coding lower limit normalization as output, and in other cases, the fifth selector selects The number of iterations normalized by the encoder to select the encoding interval is output.
优选的,所述的二进制算术编码器中,所述第四移位器将常数0x1ff右移编码下限归一化的迭代次数位后与归一化前的编码下限按位或输出,所述第一比较器将按位或输出的结果与常数0x3ff进行比较,按位或操作的结果若等于0x3ff,所述归一化后的编码下限的最高位为1,否则为0。Preferably, in the binary arithmetic coder, the fourth shifter shifts the constant 0x1ff to the right by the number of iterations of the normalized lower limit of the encoding, and then outputs the lower limit of the encoding before normalization by bitwise OR, and the fourth shifter A comparator compares the result of the bitwise OR output with the constant 0x3ff. If the result of the bitwise OR operation is equal to 0x3ff, the highest bit of the normalized coding lower limit is 1, otherwise it is 0.
优选的,所述的二进制算术编码器中,当所述编码模式是常规编码模式和/或截止编码模式时,所述编码下限更新与归一化模块包括:第三选择器、第一加法器、第五选择器、第二移位器、第三移位器、第四移位器、第一比较器和第二D触发器;其中,第三选择器,用于根据当前编码符号,选择当前编码模式下的大概率字符的区间长度和编码下限的默认值输出;第一加法器,用于根据所述第三选择器编码下限获得归一化前的编码下限;第五选择器,用于根据所述编码模式,选择所述编码区间归一化的迭代次数作为编码下限归一化的迭代次数进行输出;第二移位器,用于根据编码下限归一化的迭代次数将归一化前的编码下限左移,取低9位,得到归一化后的编码下限的低9位;第三移位器,用于将所述第二移位器所得结果右移9位得到编码下限的溢出位;第四移位器,用于根据编码下限归一化的迭代次数将常数0x1ff右移,常数0x1ff右移后与归一化前的编码下限按位或操作的结果通过第一比较器与常数0x3ff进行比较,根据比较结果得到归一化后的编码下限的最高位,归一化后的编码下限经过所述第二触发器后,输出编码下限待下一周期备用。Preferably, in the binary arithmetic coder, when the coding mode is a normal coding mode and/or a cut-off coding mode, the coding lower limit update and normalization module includes: a third selector, a first adder , the fifth selector, the second shifter, the third shifter, the fourth shifter, the first comparator and the second D flip-flop; wherein, the third selector is used to select according to the current encoding symbol The interval length of the high-probability character under the current encoding mode and the default value output of the encoding lower limit; the first adder is used to obtain the encoding lower limit before normalization according to the third selector encoding lower limit; the fifth selector uses According to the encoding mode, the number of iterations normalized in the encoding interval is selected as the number of iterations normalized by the lower limit of encoding to output; the second shifter is used to normalize the number of iterations normalized according to the lower limit of encoding The encoding lower limit before normalization is shifted to the left, and the lower 9 bits are taken to obtain the lower 9 bits of the encoding lower limit after normalization; the third shifter is used to shift the result obtained by the second shifter to the right by 9 bits to obtain the encoding The overflow bit of the lower limit; the fourth shifter is used to shift the constant 0x1ff to the right according to the number of iterations normalized by the lower limit of the encoding, and the result of the bitwise OR operation of the constant 0x1ff and the lower limit of the encoding before normalization is passed through the first The comparator compares with the constant 0x3ff, and obtains the highest bit of the normalized coding lower limit according to the comparison result. After the normalized coding lower limit passes through the second flip-flop, the output coding lower limit is ready for use in the next cycle.
优选的,所述的二进制算术编码器中,当所述编码模式是等概率编码模式时,所述编码下限更新与归一化模块包括第三选择器、第一加法器、第五选择器、第二移位器、第三移位器、第四移位器、第一比较器和第二D触发器;其中,第三选择器,用于根据当前编码符号,选择所述当前的编码区间和编码下限的默认值作为输出;第一加法器,用于根据所述第三选择器和2倍的编码下限获得归一化前的编码下限;第五选择器,用于根据所述编码模式,选择编码下限归一化的迭代次数的默认值作为编码下限归一化的迭代次数进行输出;第二移位器,用于根据编码下限归一化的迭代次数将归一化前的编码下限左移,取低9位,得到归一化后的编码下限的低9位;第三移位器,用于将所述第二移位器所得结果右移9位得到编码下限的溢出位;第四移位器,用于根据编码下限归一化的迭代次数将常数0x1ff右移,常数0x1ff右移后与归一化前的编码下限按位或操作的结果通过第一比较器与常数0x3ff进行比较,根据比较结果得到归一化后的编码下限的最高位,归一化后的编码下限经过所述第二D触发器后,输出编码下限待下一周期备用。Preferably, in the binary arithmetic coder, when the coding mode is an equal-probability coding mode, the coding lower limit update and normalization module includes a third selector, a first adder, a fifth selector, The second shifter, the third shifter, the fourth shifter, the first comparator, and the second D flip-flop; wherein, the third selector is used to select the current encoding interval according to the current encoding symbol and the default value of the encoding lower limit as output; the first adder is used to obtain the encoding lower limit before normalization according to the third selector and 2 times the encoding lower limit; the fifth selector is used to obtain the encoding lower limit according to the encoding mode , select the default value of the number of iterations of normalization of the lower limit of encoding as the number of iterations of normalization of the lower limit of encoding to output; the second shifter is used to convert the lower limit of encoding before normalization according to the number of iterations of normalization of the lower limit of encoding Shifting left, taking the lower 9 bits to obtain the lower 9 bits of the normalized encoding lower limit; the third shifter is used to shift the result obtained by the second shifter to the right by 9 bits to obtain the overflow bit of the encoding lower limit; The fourth shifter is used to shift the constant 0x1ff to the right according to the number of iterations normalized by the lower limit of the encoding. After the constant 0x1ff is shifted to the right, the result of the bitwise OR operation with the lower limit of the encoding before normalization is passed through the first comparator and the constant 0x3ff The comparison is performed, and the highest bit of the normalized coding lower limit is obtained according to the comparison result. After the normalized coding lower limit passes through the second D flip-flop, the coding lower limit is output for standby in the next cycle.
优选的,所述的二进制算术编码器中,所述码流提取模块包括首0检测电路、第六选择器、第三D触发器、第七选择器和码流输出单元;其中,首0检测电路,用于对编码下限的溢出位进行尾部首0检测,输出第一个0之后出现的1的个数,所述第一个0之后出现的1的个数与编码下限归一化的迭代次数进行比较以得到比较结果;第六选择器,用于根据比较结果从所述第一个0之后出现的1的个数、不确定位个数的默认值和编码下限归一化的迭代次数与不确定位个数之和中择一作为不确定位个数进行输出;第三D触发器,用于对所述第六选择器输出的不确定位个数进行存储作为下一周期备用;第七选择器,用于根据所述比较结果从所述编码下限归一化的迭代次数与不确定位个数之和、码流长度的默认值和编码下限归一化的迭代次数与不确定位个数之和与第一个0之后出现的1的个数的差值中择一作为码流长度进行输出;码流输出单元,用于根据所述编码下限的溢出位输出变长码流。Preferably, in the binary arithmetic encoder, the code stream extraction module includes a first 0 detection circuit, a sixth selector, a third D flip-flop, a seventh selector, and a code stream output unit; wherein, the first 0 detection The circuit is used to detect the first 0 at the end of the overflow bit of the lower limit of the encoding, and output the number of 1s that appear after the first 0, the number of 1s that appear after the first 0 and the iteration of the normalization of the lower limit of the encoding The number of times to compare to obtain the comparison result; the sixth selector is used for the number of 1s that appear after the first 0, the default value of the number of uncertain bits and the number of iterations normalized by the encoding lower limit according to the comparison result Select one of the sum of the number of uncertain bits and output it as the number of uncertain bits; the third D flip-flop is used to store the number of uncertain bits output by the sixth selector as a backup for the next cycle; The seventh selector is used to select from the sum of the number of iterations normalized by the lower limit of encoding and the number of uncertain bits, the default value of the code stream length, and the number of iterations and uncertainties of normalization of the lower limit of encoding according to the comparison result. Choose one of the difference between the sum of the number of bits and the number of 1s that appear after the first 0 as the code stream length and output it; the code stream output unit is used to output a variable-length code stream according to the overflow bit of the encoding lower limit .
优选的,所述的二进制算术编码器中,当所述编码下限归一化的迭代次数小于所述第一个0之后出现的1的个数时,比较结果为0;当所述编码下限归一化的迭代次数等于所述第一个0之后出现的1的个数时,比较结果为1;当所述编码下限归一化的迭代次数大于所述第一个0之后出现的1的个数时,比较结果为2。Preferably, in the binary arithmetic encoder, when the number of iterations of the encoding lower limit normalization is less than the number of 1s that appear after the first 0, the comparison result is 0; when the encoding lower limit normalization When the number of iterations of normalization is equal to the number of 1s that appear after the first 0, the comparison result is 1; when the number of iterations of the encoding lower limit normalization is greater than the number of 1s that appear after the first 0 When counting, the comparison result is 2.
优选的,所述的二进制算术编码器中,当所述比较结果为0时,所述第六选择器将所述编码下限归一化的迭代次数与不确定位个数之和作为输出;当所述比较结果为1时,所述第六选择器将所述不确定位个数的默认值作为输出;当所述比较结果为2时,所述第六选择器将所述第一个0之后出现的1的个数作为输出。Preferably, in the binary arithmetic encoder, when the comparison result is 0, the sixth selector outputs the sum of the number of iterations normalized by the encoding lower limit and the number of uncertain bits as output; when When the comparison result is 1, the sixth selector outputs the default value of the number of uncertain bits; when the comparison result is 2, the sixth selector outputs the first 0 The number of 1s that appear after that is output.
优选的,所述的二进制算术编码器中,当所述比较结果为0时,所述第七选择器输出的码流长度为所述编码下限归一化的迭代次数与不确定位个数之和;当所述比较结果为1时,所述第七选择器输出的码流长度为所述码流长度的默认值;当所述比较结果为2时,所述第七选择器输出的码流长度为所述编码下限归一化的迭代次数与不确定位个数之和与第一个0之后出现的1的个数的差值。Preferably, in the binary arithmetic coder, when the comparison result is 0, the length of the code stream output by the seventh selector is the difference between the number of iterations normalized by the encoding lower limit and the number of uncertain bits. and; when the comparison result is 1, the code stream length output by the seventh selector is the default value of the code stream length; when the comparison result is 2, the code stream output by the seventh selector The stream length is the difference between the sum of the number of iterations normalized by the encoding lower limit and the number of uncertain bits, and the number of 1s that appear after the first 0.
优选的,所述的二进制算术编码器中,所述码流输出单元包括第八选择器、第五移位器和第六移位器;当有效的码流的最高位为0时,第八选择器输出第一常数,当有效的码流的最高位为1时,第八选择器输出第二常数;第五移位器根据63与不确定位个数的差值将第八选择器的输出结果右移,所述第六移位器根据编码下限归一化的迭代次数与1之和将第五移位器的输出结果左移,最后与最末位按位或输出。Preferably, in the binary arithmetic encoder, the code stream output unit includes an eighth selector, a fifth shifter and a sixth shifter; when the highest bit of the effective code stream is 0, the eighth The selector outputs the first constant, and when the highest bit of the effective code stream is 1, the eighth selector outputs the second constant; the fifth shifter shifts the eighth selector’s The output result is shifted to the right, and the sixth shifter shifts the output result of the fifth shifter to the left according to the sum of the number of iterations normalized by the encoding lower limit and 1, and finally outputs it with the last bit by bitwise OR.
优选的,所述的二进制算术编码器中,所述码流输出单元采用左对齐方式依次输出一个最高位、若干个中间位和若干个最末位;其中,所述最高位为1时中间位全为0,所述最高位为0时中间位全为1,所述中间位的个数等于不确定位个数。Preferably, in the binary arithmetic encoder, the code stream output unit sequentially outputs a highest bit, several middle bits and several last bits in a left-aligned manner; wherein, the highest bit is the middle bit when 1 All are 0, when the highest bit is 0, the middle bits are all 1, and the number of the middle bits is equal to the number of uncertain bits.
优选的,所述的二进制算术编码器中,所述码流提取模块在一个时钟周期内完成码流提取操作。Preferably, in the binary arithmetic encoder, the code stream extraction module completes the code stream extraction operation within one clock cycle.
相应的,本发明还提供一种编码区间更新与归一化模块,用于提取编码状态、编码模式以及编码符号,更新编码区间和完成编码区间的归一化,并输出编码区间归一化的迭代次数以及编码区间;Correspondingly, the present invention also provides a coding interval update and normalization module, which is used to extract the coding state, coding mode and coding symbol, update the coding interval and complete the normalization of the coding interval, and output the normalized coding interval The number of iterations and the encoding interval;
所述编码区间更新与归一化模块包括第一选择器、第一减法器、第二选择器、首1检测电路、第一移位器和第一D触发器;其中,The encoding interval update and normalization module includes a first selector, a first subtractor, a second selector, a first 1 detection circuit, a first shifter and a first D flip-flop; wherein,
第一选择器,用于根据提取的编码模式获得当前编码模式下的小概率字符的区间长度;The first selector is used to obtain the interval length of the low-probability character in the current encoding mode according to the extracted encoding mode;
第一减法器,用于根据当前的编码区间和当前编码模式下的小概率字符的区间长度,获得当前编码模式下的大概率字符的区间长度;The first subtractor is used to obtain the interval length of the high-probability character under the current encoding mode according to the interval length of the current encoding interval and the low-probability character under the current encoding mode;
第二选择器,用于根据当前编码模式和当前编码符号从当前的编码区间、当前编码模式下的小概率字符的区间长度和当前编码模式下的大概率字符的区间长度中择一作为归一化前的编码区间进行输出;The second selector is used to select one of the current encoding interval, the interval length of the low-probability character in the current encoding mode, and the interval length of the high-probability character in the current encoding mode as a normalization according to the current encoding mode and the current encoding symbol Output the coding interval before conversion;
首1检测电路,用于对所述归一化前的编码区间进行前导0计数,得到编码区间归一化的迭代次数;The first 1 detection circuit is used to count the leading 0s of the coding interval before the normalization to obtain the number of iterations of the normalization of the coding interval;
第一移位器,用于根据所述编码区间归一化的迭代次数对归一化前的编码区间进行左移输出归一化后的编码区间,归一化后的编码区间经所述第一D触发器后输出编码区间待下一周期备用。The first shifter is used to left-shift the coding interval before normalization according to the number of iterations of the normalization of the coding interval to output the normalized coding interval, and the normalized coding interval passes through the second After a D flip-flop, the output coding interval is reserved for the next cycle.
优选的,在所述的编码区间更新与归一化模块中,当前编码模式为常规编码模式或等概率编码模式时,查表得到4个小概率字符的区间长度初始值,所述第一选择器选择4个小概率字符的区间长度初始值的其中一个作为当前编码模式下的小概率字符的区间长度;当前编码模式为截止编码模式时,所述小概率字符的区间长度等于2。Preferably, in the encoding interval update and normalization module, when the current encoding mode is a conventional encoding mode or an equal probability encoding mode, look up the table to obtain the initial value of the interval length of 4 low probability characters, and the first selection The device selects one of the initial values of the interval lengths of four low-probability characters as the interval length of the low-probability characters in the current encoding mode; when the current encoding mode is the cut-off encoding mode, the interval length of the low-probability characters is equal to 2.
优选的,在所述的编码区间更新与归一化模块中,当前编码模式为等概率编码模式时,所述第二选择器选择当前的编码区间为输出;当前编码模式为截止编码模式且当前编码符号为1,或当前编码模式为常规编码模式下且当前编码符号为0时,所述第二选择器选择当前编码模式下的小概率字符的区间长度为输出;其他情况所述第二选择器选择当前编码模式下的大概率字符的区间长度为输出。Preferably, in the coding interval update and normalization module, when the current coding mode is an equal-probability coding mode, the second selector selects the current coding range as an output; the current coding mode is a cut-off coding mode and the current When the coding symbol is 1, or when the current coding mode is in the conventional coding mode and the current coding symbol is 0, the second selector selects the interval length of the low-probability character in the current coding mode as output; in other cases, the second selection The device selects the interval length of the high-probability character in the current encoding mode as the output.
相应的,本发明还提供一种编码下限更新与归一化模块,用于提取编码符号、编码模式、编码区间归一化的迭代次数以及编码区间,更新编码下限和完成编码下限的归一化,并输出编码下限的溢出位以及编码下限归一化的迭代次数;Correspondingly, the present invention also provides a coding lower limit update and normalization module, which is used to extract coding symbols, coding modes, the number of iterations of normalization of coding intervals and coding intervals, update the coding lower limit and complete the normalization of the coding lower limit , and output the overflow bit of the encoding lower limit and the number of iterations of the encoding lower limit normalization;
所述编码下限更新与归一化模块包括第三选择器、第四选择器、第一加法器、第五选择器、第二移位器、第三移位器、第四移位器、第一比较器和第二D触发器;其中,The encoding lower limit update and normalization module includes a third selector, a fourth selector, a first adder, a fifth selector, a second shifter, a third shifter, a fourth shifter, a a comparator and a second D flip-flop; where,
第三选择器,用于根据当前编码模式和当前编码符号,从所述当前的编码区间、当前编码模式下的大概率字符的区间长度和编码下限的默认值中择一作为输出;The third selector is used to select one of the current encoding interval, the interval length of the high probability character in the current encoding mode, and the default value of the encoding lower limit as output according to the current encoding mode and the current encoding symbol;
第四选择器,用于根据当前编码模式从编码下限或2倍的编码下限中择一作为输出;The fourth selector is used to select one of the encoding lower limit or 2 times the encoding lower limit as output according to the current encoding mode;
第一加法器,用于根据所述第三选择器和第四选择器获得归一化前的编码下限;The first adder is used to obtain the coding lower limit before normalization according to the third selector and the fourth selector;
第五选择器,用于根据所述编码模式从所述编码区间归一化的迭代次数和编码下限归一化的迭代次数的默认值中择一作为编码下限归一化的迭代次数进行输出;The fifth selector is used to select one of the default values of the number of iterations normalized by the encoding interval and the number of iterations normalized by the lower limit of encoding according to the encoding mode to output as the number of iterations normalized by the lower limit of encoding;
第二移位器,用于根据编码下限归一化的迭代次数将归一化前的编码下限左移,取低9位,得到归一化后的编码下限的低9位;The second shifter is used to shift the lower limit of encoding before normalization to the left according to the number of iterations of the lower limit of encoding normalization, and take the lower 9 bits to obtain the lower 9 bits of the lower limit of encoding after normalization;
第三移位器,用于将所述第二移位器所得结果右移9位得到编码下限的溢出位;The third shifter is used to shift the result obtained by the second shifter to the right by 9 bits to obtain the overflow bit of the lower limit of encoding;
第四移位器,用于根据编码下限归一化的迭代次数将常数0x1ff右移,常数0x1ff右移后与归一化前的编码下限按位或操作的结果通过第一比较器与常数0x3ff进行比较,根据比较结果得到归一化后的编码下限的最高位,归一化后的编码下限经过所述第二D触发器后,输出编码下限待下一周期备用。The fourth shifter is used to shift the constant 0x1ff to the right according to the number of iterations normalized by the lower limit of the encoding. After the constant 0x1ff is shifted to the right, the result of the bitwise OR operation with the lower limit of the encoding before normalization is passed through the first comparator and the constant 0x3ff The comparison is performed, and the highest bit of the normalized coding lower limit is obtained according to the comparison result. After the normalized coding lower limit passes through the second D flip-flop, the coding lower limit is output for standby in the next cycle.
优选的,在所述的编码下限更新与归一化模块中,当前编码模式为常规编码模式且编码符号为小概率字符的区间长度时,所述第三选择器选择大概率字符的区间长度为输出;当前编码模式为等概率编码模式且编码符号为1时,所述第三选择器选择当前的编码区间为输出;其余情况所述第三选择器选择编码下限的默认值为输出。Preferably, in the described encoding lower limit update and normalization module, when the current encoding mode is the conventional encoding mode and the encoding symbol is the interval length of the low-probability character, the interval length of the high-probability character selected by the third selector is Output; when the current encoding mode is an equal-probability encoding mode and the encoding symbol is 1, the third selector selects the current encoding interval as output; in other cases, the third selector selects the default value of the encoding lower limit as output.
优选的,在所述的编码下限更新与归一化模块中,当前编码模式为等概率编码模式时,所述第四选择器选择2倍的编码下限为输出,其他情况选择编码下限为输出。Preferably, in the updating and normalization module of the coding lower limit, when the current coding mode is an equal-probability coding mode, the fourth selector selects twice the coding lower limit as the output, and otherwise selects the coding lower limit as the output.
优选的,在所述的编码下限更新与归一化模块中,当前编码模式为等概率编码模式时,所述第五选择器选择编码下限归一化的迭代次数的默认值为输出,其他情况所述第五选择器选择编码区间归一化的迭代次数为输出。Preferably, in the updating and normalization module of the lower limit of encoding, when the current encoding mode is an equal-probability encoding mode, the fifth selector selects the default value of the number of iterations of the lower limit of encoding normalization as output, and in other cases The fifth selector selects the number of iterations of encoding interval normalization as an output.
优选的,在所述的编码下限更新与归一化模块中,所述第四移位器将常数0x1ff右移编码下限归一化的迭代次数位后与归一化前的编码下限按位或输出,所述第一比较器将按位或输出的结果与常数0x3ff进行比较,按位或操作的结果若等于0x3ff,所述归一化后的编码下限的最高位为1,否则为0。Preferably, in the updating and normalization module of the encoding lower limit, the fourth shifter shifts the constant 0x1ff to the right by the number of iterations of the encoding lower limit normalization and bitwise OR with the encoding lower limit before normalization Output, the first comparator compares the result of the bitwise OR output with the constant 0x3ff, if the result of the bitwise OR operation is equal to 0x3ff, the highest bit of the normalized coding lower limit is 1, otherwise it is 0.
相应的,本发明还提供一种码流提取模块,用于提取所述编码下限归一化的迭代次数和编码下限的溢出位,输出变长码流以及码流长度;Correspondingly, the present invention also provides a code stream extraction module, which is used to extract the number of iterations of normalization of the encoding lower limit and the overflow bit of the encoding lower limit, and output a variable-length code stream and the length of the code stream;
所述码流提取模块包括首0检测电路、第六选择器、第三D触发器、第七选择器和码流输出单元;其中,The code stream extraction module includes a first 0 detection circuit, a sixth selector, a third D flip-flop, a seventh selector and a code stream output unit; wherein,
首0检测电路,用于对编码下限的溢出位进行尾部首0检测,输出第一个0之后出现的1的个数,所述第一个0之后出现的1的个数与编码下限归一化的迭代次数进行比较以得到比较结果;The first 0 detection circuit is used to detect the first 0 at the end of the overflow bit of the lower limit of the encoding, and output the number of 1s that appear after the first 0, and the number of 1s that appear after the first 0 is normalized to the lower limit of the encoding The number of iterations optimized is compared to obtain the comparison result;
第六选择器,用于根据比较结果从所述第一个0之后出现的1的个数、不确定位个数的默认值和编码下限归一化的迭代次数与不确定位个数之和中择一作为不确定位个数进行输出;The sixth selector is used for the sum of the number of 1s that appear after the first 0, the default value of the number of uncertain bits, and the number of iterations normalized by the encoding lower limit and the number of uncertain bits according to the comparison result Choose one of them as the number of uncertain bits to output;
第三D触发器,用于对所述第六选择器输出的不确定位个数进行存储作为下一周期备用;The third D flip-flop is used to store the number of uncertain bits output by the sixth selector as a backup for the next cycle;
第七选择器,用于根据所述比较结果从所述编码下限归一化的迭代次数与不确定位个数之和、码流长度的默认值和编码下限归一化的迭代次数与不确定位个数之和与第一个0之后出现的1的个数的差值中择一作为码流长度进行输出;The seventh selector is used to select from the sum of the number of iterations normalized by the lower limit of encoding and the number of uncertain bits, the default value of the code stream length, and the number of iterations and uncertainties of normalization of the lower limit of encoding according to the comparison result. Choose one of the difference between the sum of the number of bits and the number of 1s that appear after the first 0 as the code stream length to output;
码流输出单元,用于根据所述编码下限的溢出位输出变长码流。A code stream output unit, configured to output a variable-length code stream according to the overflow bits of the encoding lower limit.
优选的,在所述的码流提取模块中,当所述编码下限归一化的迭代次数小于所述第一个0之后出现的1的个数时,比较结果为0;当所述编码下限归一化的迭代次数等于所述第一个0之后出现的1的个数时,比较结果为1;当所述编码下限归一化的迭代次数大于所述第一个0之后出现的1的个数时,比较结果为2。Preferably, in the code stream extraction module, when the number of iterations of normalization of the encoding lower limit is less than the number of 1s that appear after the first 0, the comparison result is 0; when the encoding lower limit When the number of iterations of normalization is equal to the number of 1s that appear after the first 0, the comparison result is 1; when the number of iterations of the encoding lower limit normalization is greater than the number of 1s that appear after the first 0 number, the comparison result is 2.
优选的,在所述的码流提取模块中,当所述比较结果为0时,所述第六选择器将所述编码下限归一化的迭代次数与不确定位个数之和作为输出;当所述比较结果为1时,所述第六选择器将所述不确定位个数的默认值作为输出;当所述比较结果为2时,所述第六选择器将所述第一个0之后出现的1的个数作为输出。Preferably, in the code stream extraction module, when the comparison result is 0, the sixth selector outputs the sum of the number of iterations normalized by the encoding lower limit and the number of uncertain bits; When the comparison result is 1, the sixth selector outputs the default value of the number of uncertain bits; when the comparison result is 2, the sixth selector outputs the first The number of 1s that appear after 0 is output.
优选的,在所述的码流提取模块中,当所述比较结果为0时,所述第七选择器输出的码流长度为所述编码下限归一化的迭代次数与不确定位个数之和;当所述比较结果为1时,所述第七选择器输出的码流长度为所述码流长度的默认值;当所述比较结果为2时,所述第七选择器输出的码流长度为所述编码下限归一化的迭代次数与不确定位个数之和与第一个0之后出现的1的个数的差值。Preferably, in the code stream extraction module, when the comparison result is 0, the length of the code stream output by the seventh selector is the number of iterations and the number of uncertain bits normalized by the encoding lower limit sum; when the comparison result is 1, the code stream length output by the seventh selector is the default value of the code stream length; when the comparison result is 2, the code stream length output by the seventh selector The code stream length is the difference between the sum of the number of iterations normalized by the encoding lower limit and the number of uncertain bits and the number of 1s that appear after the first 0.
优选的,在所述的码流提取模块中,所述码流输出单元包括第八选择器、第五移位器和第六移位器;当有效的码流的最高位为0时,第八选择器输出第一常数,当有效的码流的最高位为1时,第八选择器输出第二常数;第五移位器根据63与不确定位个数的差值将第八选择器的输出结果右移,所述第六移位器根据编码下限归一化的迭代次数与1之和将第五移位器的输出结果左移,最后与最末位按位或输出。Preferably, in the code stream extraction module, the code stream output unit includes an eighth selector, a fifth shifter and a sixth shifter; when the highest bit of the effective code stream is 0, the first The eighth selector outputs the first constant. When the highest bit of the effective code stream is 1, the eighth selector outputs the second constant; the fifth shifter shifts the eighth selector to The output result of the fifth shifter is shifted to the right, and the sixth shifter shifts the output result of the fifth shifter to the left according to the sum of the number of iterations normalized by the encoding lower limit and 1, and finally outputs it with the last bit.
优选的,在所述的码流提取模块中,所述码流输出单元采用左对齐方式依次输出一个最高位、若干个中间位和若干个最末位;其中,所述最高位为1时中间位全为0,所述最高位为0时中间位全为1,所述中间位的个数等于不确定位个数。Preferably, in the code stream extraction module, the code stream output unit sequentially outputs a highest bit, several middle bits, and several last bits in a left-aligned manner; wherein, the highest bit is 1 when the middle The bits are all 0, and when the highest bit is 0, the middle bits are all 1, and the number of the middle bits is equal to the number of uncertain bits.
优选的,在所述的码流提取模块中,所述码流提取模块在一个时钟周期内完成码流提取操作。Preferably, in the code stream extraction module, the code stream extraction module completes the code stream extraction operation within one clock cycle.
相应的,本发明还提供一种二进制算术编码器的编码方法,所述二进制算术编码器的编码方法包括:Correspondingly, the present invention also provides a coding method of a binary arithmetic coder, and the coding method of the binary arithmetic coder includes:
步骤S10:编码区间更新与归一化模块作为第一级流水引擎,提取编码状态、编码模式以及编码符号,更新编码区间和完成编码区间的归一化,并输出编码区间归一化的迭代次数以及编码区间;Step S10: The encoding interval update and normalization module acts as the first-level pipeline engine to extract the encoding state, encoding mode and encoding symbols, update the encoding interval and complete the normalization of the encoding interval, and output the number of iterations of the normalization of the encoding interval and the coding interval;
步骤S11:编码下限更新与归一化模块作为第二级流水引擎,提取编码符号、编码模式、编码区间归一化的迭代次数以及编码区间,更新编码下限和完成编码下限的归一化,并输出编码下限的溢出位以及编码下限归一化的迭代次数;Step S11: The coding lower limit update and normalization module is used as the second-level pipeline engine to extract the coding symbol, coding mode, the number of iterations of the normalization of the coding interval and the coding interval, update the coding lower limit and complete the normalization of the coding lower limit, and Output the overflow bit of the encoding lower limit and the number of iterations of the encoding lower limit normalization;
步骤S12:码流提取模块作为第三级流水引擎,提取所述编码下限归一化的迭代次数和编码下限的溢出位,输出变长码流以及码流长度。Step S12: The code stream extraction module acts as a third-stage pipeline engine, extracts the number of iterations normalized by the encoding lower limit and overflow bits of the encoding lower limit, and outputs a variable-length code stream and the length of the code stream.
优选的,所述的二进制算术编码器的编码方法中,在步骤S10中,所述编码区间更新与归一化模块还输出大概率字符的区间长度至所述编码下限更新与归一化模块。Preferably, in the encoding method of the binary arithmetic coder, in step S10, the encoding interval update and normalization module also outputs the interval length of the high-probability character to the encoding lower limit update and normalization module.
优选的,所述的二进制算术编码器的编码方法中,所述编码模式包括常规编码模式、等概率编码模式和截止编码模式。Preferably, in the coding method of the binary arithmetic coder, the coding modes include normal coding mode, equal probability coding mode and cut-off coding mode.
优选的,所述的二进制算术编码器的编码方法中,所述步骤S10进一步包括:Preferably, in the encoding method of the binary arithmetic encoder, the step S10 further includes:
第一选择器根据编码模式获得当前编码模式下的小概率字符的区间长度;The first selector obtains the interval length of the low-probability character in the current encoding mode according to the encoding mode;
第一减法器根据当前的编码区间和当前编码模式下的小概率字符的区间长度,获得当前编码模式下的大概率字符的区间长度;The first subtractor obtains the interval length of the high-probability character under the current encoding mode according to the interval length of the current encoding interval and the low-probability character under the current encoding mode;
第二选择器根据当前编码模式和当前编码符号,从所述当前的编码区间、当前编码模式下的小概率字符的区间长度或当前编码模式下的大概率字符的区间长度中择一作为归一化前的编码区间进行输出;According to the current encoding mode and the current encoding symbol, the second selector selects one of the current encoding interval, the interval length of the low-probability character in the current encoding mode, or the interval length of the high-probability character in the current encoding mode as normalization Output the coding interval before conversion;
首1检测电路对所述归一化前的编码区间进行前导0计数,得到编码区间归一化的迭代次数;The first 1 detection circuit carries out leading 0 counting to the coding interval before the normalization, and obtains the number of iterations of the normalization of the coding interval;
第一移位器根据所述编码区间归一化的迭代次数,对归一化前的编码区间进行左移输出归一化后的编码区间,归一化后的编码区间经一D触发器后,输出编码区间待下一周期备用。The first shifter performs left shift on the coding interval before normalization according to the number of iterations of the normalization of the coding interval to output the normalized coding interval, and the normalized coding interval is passed through a D flip-flop , the output coding interval is reserved for the next cycle.
优选的,所述的二进制算术编码器的编码方法,其特征在于,当前编码模式为常规编码模式或等概率编码模式时,查表得到4个小概率字符的区间长度初始值,所述第一选择器选择4个小概率字符的区间长度初始值的其中一个作为当前编码模式下的小概率字符的区间长度;当前编码模式为截止编码模式时,所述小概率字符的区间长度等于2。Preferably, the coding method of the binary arithmetic coder is characterized in that, when the current coding mode is the conventional coding mode or the equal probability coding mode, the initial value of the interval length of 4 characters with low probability is obtained by looking up the table, and the first The selector selects one of the initial interval lengths of four low-probability characters as the interval length of low-probability characters in the current encoding mode; when the current encoding mode is the cut-off encoding mode, the interval length of the low-probability characters is equal to 2.
优选的,所述的二进制算术编码器的编码方法中,当前编码模式为等概率编码模式时,所述第二选择器选择当前的编码区间为输出;当前编码模式为截止编码模式且当前编码符号为1,或当前编码模式为常规编码模式下且当前编码符号为0时,所述第二选择器选择当前编码模式下的小概率字符的区间长度为输出;其他情况所述第二选择器选择当前编码模式下的大概率字符的区间长度为输出。Preferably, in the coding method of the binary arithmetic coder, when the current coding mode is an equal-probability coding mode, the second selector selects the current coding interval as an output; the current coding mode is a cut-off coding mode and the current coding symbol is 1, or when the current encoding mode is in the conventional encoding mode and the current encoding symbol is 0, the second selector selects the interval length of the low-probability character in the current encoding mode as output; in other cases, the second selector selects The interval length of the high-probability characters in the current encoding mode is output.
优选的,所述的二进制算术编码器的编码方法,其特征在于,步骤S11进一步包括:Preferably, the coding method of the binary arithmetic coder is characterized in that step S11 further includes:
第三选择器根据当前编码模式和当前编码符号,从所述当前的编码区间、当前编码模式下的大概率字符的区间长度或编码下限的默认值中择一作为输出;According to the current encoding mode and the current encoding symbol, the third selector selects one of the current encoding interval, the interval length of the high probability character in the current encoding mode or the default value of the encoding lower limit as an output;
第四选择器根据当前编码模式,从编码下限或2倍的编码下限中择一作为输出;The fourth selector selects one of the encoding lower limit or 2 times the encoding lower limit as output according to the current encoding mode;
第一加法器根据所述第三选择器和第四选择器获得归一化前的编码下限;The first adder obtains the coding lower limit before normalization according to the third selector and the fourth selector;
第五选择器根据所述当前编码模式,从所述编码区间归一化的迭代次数和编码下限归一化的迭代次数的默认值中择一作为编码下限归一化的迭代次数进行输出;According to the current coding mode, the fifth selector selects one of the default values of the number of iterations normalized by the coding interval and the number of iterations normalized by the lower limit of coding to output as the number of iterations of the lower limit normalization of coding;
第二移位器根据所述编码下限归一化的迭代次数将归一化前的编码下限左移,取低9位,得到归一化后的编码下限的低9位;The second shifter shifts the encoding lower limit before normalization to the left according to the number of iterations of the encoding lower limit normalization, and takes the lower 9 bits to obtain the lower 9 bits of the normalized encoding lower limit;
第三移位器将所述第二移位器所得结果右移9位得到编码下限的溢出位;The third shifter shifts the result obtained by the second shifter to the right by 9 bits to obtain the overflow bit of the lower limit of encoding;
第四移位器根据编码下限归一化的迭代次数将常数0x1ff右移,常数0x1ff右移后与归一化前的编码下限按位或操作的结果通过第一比较器与常数0x3ff进行比较,根据比较结果得到归一化后的编码下限的最高位;The fourth shifter shifts the constant 0x1ff to the right according to the number of iterations normalized by the lower limit of the encoding, and the result of the bitwise OR operation of the constant 0x1ff after the right shift and the lower limit of the encoding before normalization is compared with the constant 0x3ff by the first comparator, According to the comparison result, the highest bit of the normalized coding lower limit is obtained;
归一化后的编码下限经过第三D触发器之后,输出编码下限待下一周期备用。After the normalized encoding lower limit passes through the third D flip-flop, the output encoding lower limit is ready for use in the next cycle.
优选的,所述的二进制算术编码器的编码方法中,当前编码模式为常规编码模式且编码符号为小概率字符的区间长度时,所述第三选择器选择大概率字符的区间长度为输出;当前编码模式为等概率编码模式且编码符号为1时,所述第三选择器选择当前的编码区间为输出;其余情况所述第三选择器选择编码下限的默认值为输出。Preferably, in the encoding method of the binary arithmetic coder, when the current encoding mode is the normal encoding mode and the encoding symbol is the interval length of the low-probability character, the third selector selects the interval length of the high-probability character as output; When the current encoding mode is an equal-probability encoding mode and the encoding symbol is 1, the third selector selects the current encoding interval as output; in other cases, the third selector selects the default value of the encoding lower limit as output.
优选的,所述的二进制算术编码器的编码方法中,当前编码模式为等概率编码模式时,所述第四选择器选择2倍的编码下限为输出,其他情况选择编码下限为输出。Preferably, in the coding method of the binary arithmetic coder, when the current coding mode is an equal-probability coding mode, the fourth selector selects twice the coding lower limit as the output, and otherwise selects the coding lower limit as the output.
优选的,所述的二进制算术编码器的编码方法中,当前编码模式为等概率编码模式时,所述第五选择器选择编码下限归一化的迭代次数的默认值为输出,其他情况所述第五选择器选择编码区间归一化的迭代次数为输出。Preferably, in the encoding method of the binary arithmetic encoder, when the current encoding mode is an equal probability encoding mode, the default value of the number of iterations selected by the fifth selector for encoding lower limit normalization is output, and the other conditions The fifth selector selects the number of iterations of encoding interval normalization as output.
优选的,所述的二进制算术编码器的编码方法中,所述第四移位器将常数0x1ff右移编码下限归一化的迭代次数位后与归一化前的编码下限按位或输出,所述第一比较器将按位或输出的结果与常数0x3ff进行比较,按位或操作的结果若等于0x3ff,所述归一化后的编码下限的最高位为1,否则为0。Preferably, in the encoding method of the binary arithmetic encoder, the fourth shifter shifts the constant 0x1ff to the right by the number of iterations of the normalized lower limit of the encoding, and outputs the bitwise OR output with the lower limit of the encoding before normalization, The first comparator compares the result of the bitwise OR output with the constant 0x3ff. If the result of the bitwise OR operation is equal to 0x3ff, the highest bit of the normalized coding lower limit is 1, otherwise it is 0.
优选的,所述的二进制算术编码器的编码方法中,步骤S12进一步包括:Preferably, in the encoding method of the binary arithmetic encoder, step S12 further includes:
首0检测电路对编码下限的溢出位进行尾部首0检测,输出第一个0之后出现的1的个数,所述第一个0之后出现的1的个数与编码下限归一化的迭代次数进行比较;The first 0 detection circuit detects the first 0 at the end of the overflow bit of the lower limit of the encoding, and outputs the number of 1s that appear after the first 0, the number of 1s that appear after the first 0 and the iteration of the normalization of the lower limit of the encoding times to compare;
第六选择器根据比较结果所述从第一个0之后出现的1的个数、不确定位个数的默认值和编码下限归一化的迭代次数与不确定位个数之和中择一作为不确定位个数进行输出;The sixth selector selects one from the number of 1s that appear after the first 0, the default value of the number of uncertain bits, and the sum of the number of iterations normalized by the encoding lower limit and the number of uncertain bits according to the comparison result Output as an indeterminate number of bits;
第三D触发器对所述第六选择器输出的不确定位个数进行存储;The third D flip-flop stores the number of uncertain bits output by the sixth selector;
第七选择器根据所述比较结果从所述编码下限归一化的迭代次数与不确定位个数之和、码流长度的默认值和编码下限归一化的迭代次数与不确定位个数之和与第一个0之后出现的1的个数的差值中择一作为码流长度进行输出;The seventh selector selects from the sum of the number of iterations normalized by the lower limit of encoding and the number of uncertain bits, the default value of the code stream length, and the number of iterations and the number of uncertain bits normalized by the lower limit of encoding according to the comparison result The difference between the sum and the number of 1s that appear after the first 0 is selected as the code stream length for output;
码流输出单元根据所述编码下限的溢出位输出变长码流。The code stream output unit outputs a variable-length code stream according to the overflow bits of the encoding lower limit.
优选的,所述的二进制算术编码器的编码方法中,当所述编码下限归一化的迭代次数小于所述第一个0之后出现的1的个数时,比较结果为0;当所述编码下限归一化的迭代次数等于所述第一个0之后出现的1的个数时,比较结果为1;当所述编码下限归一化的迭代次数大于所述第一个0之后出现的1的个数时,比较结果为2。Preferably, in the encoding method of the binary arithmetic encoder, when the number of iterations of the encoding lower limit normalization is less than the number of 1s that appear after the first 0, the comparison result is 0; when the When the number of iterations of the encoding lower limit normalization is equal to the number of 1s that appear after the first 0, the comparison result is 1; when the number of iterations of the encoding lower limit normalization is greater than the number of 1s that appear after the first 0 1, the comparison result is 2.
优选的,所述的二进制算术编码器的编码方法中,当所述比较结果为0时,所述第六选择器将所述编码下限归一化的迭代次数与不确定位个数之和作为输出;当所述比较结果为1时,所述第六选择器将所述不确定位个数的默认值作为输出;当所述比较结果为2时,所述第六选择器将所述第一个0之后出现的1的个数作为输出。Preferably, in the encoding method of the binary arithmetic encoder, when the comparison result is 0, the sixth selector uses the sum of the number of iterations normalized by the lower limit of encoding and the number of uncertain bits as output; when the comparison result is 1, the sixth selector takes the default value of the number of uncertain bits as output; when the comparison result is 2, the sixth selector takes the first The number of 1s following a 0 is output.
优选的,所述的二进制算术编码器的编码方法中,当所述比较结果为0时,所述第七选择器输出的码流长度为所述编码下限归一化的迭代次数与不确定位个数之和;当所述比较结果为1时,所述第七选择器输出的码流长度为所述码流长度的默认值;当所述比较结果为2时,所述第七选择器输出的码流长度为所述编码下限归一化的迭代次数与不确定位个数之和与第一个0之后出现的1的个数的差值。Preferably, in the encoding method of the binary arithmetic encoder, when the comparison result is 0, the length of the code stream output by the seventh selector is equal to the number of iterations normalized by the encoding lower limit and the uncertain bit The sum of numbers; when the comparison result is 1, the code stream length output by the seventh selector is the default value of the code stream length; when the comparison result is 2, the seventh selector The length of the output code stream is the difference between the sum of the number of iterations normalized by the encoding lower limit and the number of uncertain bits and the number of 1s appearing after the first 0.
优选的,所述的二进制算术编码器的编码方法中,当有效的码流的最高位为0时,第八选择器输出第一常数,当有效的码流的最高位为1时,第八选择器输出第二常数;第五移位器根据63与不确定位个数的差值将第八选择器的输出结果右移,所述第六移位器根据编码下限归一化的迭代次数与1之和将第五移位器的输出结果左移,最后与最末位按位或输出。Preferably, in the encoding method of the binary arithmetic encoder, when the highest bit of the effective code stream is 0, the eighth selector outputs the first constant; when the highest bit of the effective code stream is 1, the eighth selector The selector outputs the second constant; the fifth shifter shifts the output of the eighth selector to the right according to the difference between 63 and the number of uncertain bits, and the sixth shifter normalizes the number of iterations according to the encoding lower limit The sum of 1 and the output result of the fifth shifter is shifted to the left, and finally output with the bitwise OR of the last bit.
优选的,所述的二进制算术编码器的编码方法中,所述码流输出单元采用左对齐方式依次输出一个最高位、若干个中间位和若干个最末位;其中,所述最高位为1时中间位全为0,所述最高位为0时中间位全为1,所述中间位的个数等于不确定位个数。Preferably, in the encoding method of the binary arithmetic encoder, the code stream output unit sequentially outputs a highest bit, several middle bits and several last bits in a left-aligned manner; wherein, the highest bit is 1 When the middle bits are all 0, when the highest bit is 0, the middle bits are all 1, and the number of the middle bits is equal to the number of uncertain bits.
优选的,所述的二进制算术编码器的编码方法中,所述码流提取模块在一个时钟周期内完成码流提取操作。Preferably, in the coding method of the binary arithmetic coder, the code stream extraction module completes the code stream extraction operation within one clock cycle.
在本发明提供的二进制算术编码器及其编码方法中,通过编码区间更新与归一化模块、编码下限更新与归一化模块形成三级流水结构,由此码流提取模块可以在一个时钟周期内处理一个或多个编码符号,实现了完全并行,解决了现有技术中并行差的问题;另外,通过选择器实现不同编码模式的共用,提高了电路的复用性,减少了硬件成本;此外,所述码流提取方法的码流提取操作简单,无须额外的FIFO资源。In the binary arithmetic encoder and its encoding method provided by the present invention, a three-stage pipeline structure is formed by the encoding interval update and normalization module, the encoding lower limit update and normalization module, so that the code stream extraction module can Internal processing of one or more coding symbols realizes complete parallelism and solves the problem of poor parallelism in the prior art; in addition, the sharing of different coding modes is realized through the selector, which improves the reusability of the circuit and reduces the hardware cost; In addition, the code stream extraction operation of the code stream extraction method is simple and does not require additional FIFO resources.
附图说明Description of drawings
图1是本发明实施例的二进制算术编码器的原理框图;Fig. 1 is the functional block diagram of the binary arithmetic coder of the embodiment of the present invention;
图2是本发明实施例的模式复用下的编码区间更新与归一化模块的工作流程示意图;FIG. 2 is a schematic diagram of the workflow of the encoding interval update and normalization module under the mode multiplexing of the embodiment of the present invention;
图3是本发明实施例的常规编码模式下的编码区间更新与归一化模块的工作流程示意图;FIG. 3 is a schematic diagram of the workflow of the encoding interval update and normalization module in the conventional encoding mode of the embodiment of the present invention;
图4是本发明实施例的等概率编码模式下的编码区间更新与归一化模块的工作流程示意图;4 is a schematic diagram of the workflow of the coding interval update and normalization module in the equal probability coding mode of the embodiment of the present invention;
图5是本发明实施例的截止编码模式下的编码区间更新与归一化模块的工作流程示意图;5 is a schematic diagram of the workflow of the coding interval update and normalization module in the cut-off coding mode according to the embodiment of the present invention;
图6中本发明实施例的模式复用下的编码下限更新与归一化模块的工作流程示意图;A schematic diagram of the workflow of the encoding lower limit update and normalization module under the mode multiplexing of the embodiment of the present invention in FIG. 6 ;
图7中本发明实施例的常规编码模式以及截止编码模式下的编码下限更新与归一化模块的工作流程示意图;The schematic diagram of the workflow of the normal coding mode and the coding lower limit update and normalization module in the cut-off coding mode of the embodiment of the present invention in FIG. 7 ;
图8中本发明实施例的等概率编码模式下的编码下限更新与归一化模块的工作流程示意图;In Fig. 8, a schematic diagram of the workflow of the encoding lower limit update and normalization module in the equal probability encoding mode of the embodiment of the present invention;
图9为本发明实施例的码流提取模块的结构示意图;FIG. 9 is a schematic structural diagram of a code stream extraction module according to an embodiment of the present invention;
图10为本发明实施例的二进制算术编码器的编码方法的流程图;FIG. 10 is a flowchart of a coding method of a binary arithmetic coder according to an embodiment of the present invention;
图11为图10中步骤S10的具体流程示意图;FIG. 11 is a schematic flowchart of step S10 in FIG. 10;
图12为图10中步骤S11的具体流程示意图;FIG. 12 is a schematic flowchart of step S11 in FIG. 10;
图13为图10中步骤S12的具体流程示意图。FIG. 13 is a schematic flow chart of step S12 in FIG. 10 .
具体实施方式detailed description
以下结合附图和具体实施例对本发明提出的二进制算术编码器及其编码方法作进一步详细说明。The binary arithmetic encoder and its encoding method proposed by the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
请参考图1,其为本发明实施例的二进制算术编码器的原理框图。所述二进制算术编码器用于输出各种编码模式mode的二进制算术编码的码流,如图1所示,所述二进制算术编码器100包括编码区间更新与归一化模块10、编码下限更新与归一化模块20和码流提取模块30,所述编码区间更新与归一化模块10、编码下限更新与归一化模块20和码流提取模块30形成并行的三级流水结构。Please refer to FIG. 1 , which is a functional block diagram of a binary arithmetic encoder according to an embodiment of the present invention. The binary arithmetic coder is used to output binary arithmetic coded code streams of various encoding modes, as shown in FIG. The normalization module 20 and the code stream extraction module 30, the encoding interval update and normalization module 10, the encoding lower limit update and normalization module 20 and the code stream extraction module 30 form a parallel three-stage pipeline structure.
编码区间更新与归一化模块10,作为第一级流水引擎,用于提取编码状态state、编码模式mode以及编码符号Bin,更新编码区间range和完成编码区间range的归一化,并输出编码区间归一化的迭代次数S、编码区间range以及大概率字符的区间长度rMPS至下一级流水引擎即编码下限更新与归一化模块20。Coding interval update and normalization module 10, as the first-level pipeline engine, is used to extract the encoding state state, encoding mode mode and encoding symbol Bin, update the encoding interval range and complete the normalization of the encoding interval range, and output the encoding interval The normalized number of iterations S, the encoding interval range and the interval length rMPS of high-probability characters are sent to the next-level pipeline engine, which is the encoding lower limit update and normalization module 20 .
编码下限更新与归一化模块20,作为第二级流水引擎,用于提取编码符号Bin、编码模式mode、编码区间归一化的迭代次数S、编码区间range以及大概率字符的区间长度rMPS,更新编码下限(low)和完成编码下限(low)的归一化,并输出编码下限的溢出位overflow_low以及编码下限归一化的迭代次数S1至下一级流水引擎即码流提取模块30。The encoding lower limit update and normalization module 20, as a second-level pipeline engine, is used to extract the encoding symbol Bin, encoding mode mode, the number of iterations S of encoding interval normalization, encoding interval range, and the interval length rMPS of high-probability characters, Update the encoding lower limit (low) and complete the normalization of the encoding lower limit (low), and output the overflow bit overflow_low of the encoding lower limit and the iteration number S1 of the encoding lower limit normalization to the next-level pipeline engine, that is, the stream extraction module 30.
码流提取模块30,作为第三级流水引擎,用于提取所述编码下限归一化的迭代次数S1和编码下限的溢出位overflow_low,输出变长码流bit_stream以及码流长度bit_len。The code stream extracting module 30, as a third-level pipeline engine, is used to extract the iteration number S1 of normalization of the encoding lower limit and the overflow bit overflow_low of the encoding lower limit, and output a variable-length code stream bit_stream and a code stream length bit_len.
本发明通过采用三级流水结构,即采用高度并行的全流水线设计,无须加入任何控制逻辑电路,可以在一个时钟周期内处理一个或多个编码符号,实现了完全并行,解决了现有技术中并行差的问题。The present invention adopts a three-stage pipeline structure, that is, adopts a highly parallel full pipeline design, without adding any control logic circuit, and can process one or more coding symbols in one clock cycle, thereby realizing complete parallelism and solving the problems in the prior art. Parallelism problem.
具体的,所述编码模式mode包括常规编码模式、等概率编码模式和截止编码模式。本实施例中,mode为0表示常规编码模式,mode为1表示等概率编码模式,mode为2表示截止编码模式。Specifically, the coding mode mode includes a normal coding mode, an equal-probability coding mode and a cut-off coding mode. In this embodiment, mode is 0, which means the normal coding mode, mode is 1, which means the equal probability coding mode, and mode is 2, which means the cut-off coding mode.
本实施例中,所述二进制算术编码器中的编码区间更新与归一化模块10和编码下限更新与归一化模块20通过选择器实现不同编码模式的共用,提高了电路的复用性,增加了电路吞吐量率,减少硬件开销。In this embodiment, the encoding interval update and normalization module 10 and the encoding lower limit update and normalization module 20 in the binary arithmetic encoder realize the sharing of different encoding modes through the selector, which improves the reusability of the circuit, Increased circuit throughput rate and reduced hardware overhead.
以下将分别对各个模块进行详细说明。Each module will be described in detail below.
图2是本发明实施例的模式复用下的编码区间更新与归一化模块10的工作流程示意图,图3是本发明实施例的常规编码模式下的编码区间更新与归一化模块10的工作流程示意图,图4是本发明实施例的等概率编码模式下的编码区间更新与归一化模块10的工作流程示意图,图5是本发明实施例的截止编码模式下的编码区间更新与归一化模块10的工作流程示意图。Fig. 2 is a schematic diagram of the workflow of the encoding interval update and normalization module 10 under the mode multiplexing of the embodiment of the present invention, and Fig. 3 is a schematic diagram of the encoding interval update and normalization module 10 under the conventional encoding mode of the embodiment of the present invention Schematic diagram of the workflow, FIG. 4 is a schematic diagram of the workflow of the coding interval update and normalization module 10 in the equal-probability coding mode of the embodiment of the present invention, and FIG. A schematic diagram of the workflow of the chemical module 10.
下面结合图2所示详细介绍模式复用下的编码区间更新与归一化模块10的结构及其工作流程。如图2所示,模式复用下的编码区间更新与归一化模块10包括第一选择器11、第二选择器12、第一减法器13、首1检测电路15、第一移位器16和第一D触发器17。The structure and working process of the encoding interval update and normalization module 10 under mode multiplexing will be described in detail below in conjunction with FIG. 2 . As shown in FIG. 2 , the encoding interval update and normalization module 10 under mode multiplexing includes a first selector 11, a second selector 12, a first subtractor 13, a first 1 detection circuit 15, and a first shifter 16 and the first D flip-flop 17 .
其中,第一选择器11,用于根据提取的编码模式mode获得当前编码模式下的小概率字符的区间长度rLPS,并输出所述当前编码模式下的小概率字符的区间长度rLPS;具体的,当编码模式mode为0或1时,即常规编码模式或等概率编码模式下,根据概率状态state查表结果和range[7:6]得到小概率字符的区间长度rLPS,作为一个非限制性的例子,概率状态state查表得到4个rLPS初始值(rLPS0、rLPS1、rLPS2、rLPS3),第一选择器11根据range[7:6]选择4个初始值的其中一个作为当前编码模式(标准模式)下的小概率字符的区间长度rLPS输出;当编码模式mode为2时,即截止编码模式下,输出的小概率字符的区间长度rLPS等于2。Wherein, the first selector 11 is used to obtain the interval length rLPS of the low-probability character in the current encoding mode according to the extracted encoding mode mode, and output the interval length rLPS of the low-probability character in the current encoding mode; specifically, When the encoding mode mode is 0 or 1, that is, in the conventional encoding mode or the equal probability encoding mode, the interval length rLPS of the low probability character is obtained according to the probability state state table lookup result and range[7:6], as a non-restrictive For example, the probability state state look-up table obtains 4 rLPS initial values (rLPS0, rLPS1, rLPS2, rLPS3), and the first selector 11 selects one of the 4 initial values according to range[7:6] as the current encoding mode (standard mode ) under the low-probability character interval length rLPS output;
其中,第一减法器13,用于根据当前的编码区间range和当前编码模式下的小概率字符的区间长度rLPS,获得当前编码模式下的大概率字符的区间长度rMPS,rMPS的计算公式为:rMPS=range-rLPS。Wherein, the first subtractor 13 is used to obtain the interval length rMPS of the high-probability character under the current encoding mode according to the interval length rLPS of the low-probability character under the current encoding interval range and the current encoding mode, and the calculation formula of rMPS is: rMPS=range-rLPS.
其中,第二选择器12,用于根据当前编码模式mode和当前编码符号bin,从当前的编码区间range、当前编码模式下的小概率字符的区间长度rLPS和当前编码模式下的大概率字符的区间长度rMPS中选择其一作为归一化前的编码区间rangenor进行输出。具体的,模式复用情况下,第二选择器12的输入为当前编码模式下的小概率字符的区间长度rLPS、当前编码模式下的大概率字符的区间长度rMPS以及当前的编码区间range,选择因子为当前编码模式mode以及当前编码符号bin;若当前编码模式mode为1,选择当前的编码区间range为输出;若当前编码模式mode为2且当前编码符号bin为1,或当前编码模式mode为0且当前编码符号bin为0时,选择当前编码模式下的小概率字符的区间长度rLPS为输出;除上述两种之外的其他情况,选择当前编码模式下的大概率字符的区间长度rMPS为输出。Wherein, the second selector 12 is used to select from the current coding interval range, the interval length rLPS of the low-probability character in the current coding mode and the high-probability character in the current coding mode according to the current coding mode mode and the current coding symbol bin. Select one of the interval length rMPS as the encoding interval range nor before normalization for output. Specifically, in the case of mode multiplexing, the input of the second selector 12 is the interval length rLPS of the low-probability character in the current encoding mode, the interval length rMPS of the high-probability character in the current encoding mode, and the current encoding interval range, select The factor is the current encoding mode mode and the current encoding symbol bin; if the current encoding mode mode is 1, select the current encoding interval range as output; if the current encoding mode mode is 2 and the current encoding symbol bin is 1, or the current encoding mode mode is 0 and the current encoding symbol bin is 0, select the interval length rLPS of the low-probability character in the current encoding mode as the output; in other cases except the above two, select the interval length rMPS of the high-probability character in the current encoding mode as output.
其中,首1检测电路15,用于对归一化前的编码区间rangenor进行前导0计数,得到编码区间归一化的迭代次数S,编码区间归一化的迭代次数S将输入到下一级流水引擎,也就是编码下限更新与归一化模块20。Among them, the first 1 detection circuit 15 is used to count the leading 0s of the coding interval range nor before normalization to obtain the iteration number S of the normalization of the coding interval, and the iteration number S of the normalization of the coding interval will be input to the next Level pipeline engine, that is, the encoding lower limit update and normalization module 20.
其中,第一移位器16,用于根据所述归一化前的编码区间rangenor和编码区间归一化的迭代次数S得到归一化后的编码区间rangeO,即通过将归一化前的编码区间rangenor左移S位得到归一化后的编码区间rangeO;归一化后的编码区间rangeO经过第一D触发器17之后,输出编码区间range待编码区间更新与归一化模块10下一周期备用。Wherein, the first shifter 16 is used to obtain the normalized coding range rangeO according to the normalized coding range range nor and the number of iterations S of coding range normalization, that is, by The encoding interval range nor shifts left by S bits to obtain the normalized encoding interval range0; after the normalized encoding interval rangeO passes through the first D flip-flop 17, the output encoding interval range is to be updated with the normalization module 10 Reserved for the next cycle.
下面结合图3所示详细介绍常规编码模式下的编码区间更新与归一化模块10的结构及其工作流程。如图3所示,所述常规编码模式下的编码区间更新与归一化模块10包括第一减法器13、第二选择器12、首1检测电路15、第一移位器16和第一D触发器17。The structure and working process of the coding range update and normalization module 10 in the conventional coding mode will be described in detail below in conjunction with FIG. 3 . As shown in FIG. 3 , the coding interval update and normalization module 10 in the conventional coding mode includes a first subtractor 13, a second selector 12, a first 1 detection circuit 15, a first shifter 16 and a first D flip-flop 17.
其中,第一减法器13,用于根据当前的编码区间range和当前编码模式mode的小概率字符的区间长度rLPS,获得当前编码模式下的大概率字符的区间长度rMPS;rMPS的计算公式为:rMPS=range-rLPS。作为一个非限制性的例子,根据概率状态state查表结果和range[7:6]得到小概率字符的区间长度rLPS。概率状态state查表得到4个rLPS初始值(rLPS0、rLPS1、rLPS2、rLPS3),根据range[7:6]选择4个rLPS初始值的其中一个作为小概率字符的区间长度rLPS输出给第一减法器13,第一减法器13则根据当前的编码区间range和当前编码模式mode的小概率字符的区间长度rLPS,获得当前编码模式下的大概率字符的区间长度rMPS。Wherein, the first subtractor 13 is used to obtain the interval length rMPS of the high-probability character under the current encoding mode according to the interval length rLPS of the low-probability character of the current encoding interval range and the current encoding mode mode; the calculation formula of rMPS is: rMPS=range-rLPS. As a non-limiting example, the interval length rLPS of the low-probability character is obtained according to the probability state state table lookup result and range[7:6]. Probability state state lookup table to get 4 rLPS initial values (rLPS0, rLPS1, rLPS2, rLPS3), select one of the 4 rLPS initial values according to range[7:6] as the interval length rLPS of small probability characters and output to the first subtraction The first subtractor 13 obtains the interval length rMPS of the high-probability character in the current encoding mode according to the current encoding interval range and the interval length rLPS of the low-probability character in the current encoding mode mode.
其中,第二选择器12,用于根据当前编码符号bin,从当前编码模式下的小概率字符的区间长度rLPS和当前模式下的大概率字符的区间长度rMPS中选择其一作为归一化前的编码区间rangenor进行输出。Wherein, the second selector 12 is used to select one of the interval length rLPS of the low-probability character in the current encoding mode and the interval length rMPS of the high-probability character in the current mode according to the current encoding symbol bin as the pre-normalization The encoding interval range nor is output.
其中,首1检测电路15,用于对归一化前的编码区间rangenor进行前导0计数,得到编码区间归一化的迭代次数S,编码区间归一化的迭代次数S将输入到下一级流水引擎,也就是编码下限更新与归一化模块20。Among them, the first 1 detection circuit 15 is used to count the leading 0s of the coding interval range nor before normalization to obtain the iteration number S of the normalization of the coding interval, and the iteration number S of the normalization of the coding interval will be input to the next Level pipeline engine, that is, the encoding lower limit update and normalization module 20.
其中,第一移位器16,用于根据所述归一化前的编码区间rangenor和编码区间归一化的迭代次数S得到归一化后的编码区间rangeO,即通过将归一化前的编码区间rangenor左移S位得到归一化后的编码区间rangeO,归一化后的编码区间rangeO经过第一D触发器17之后,输出编码区间range待编码区间更新与归一化模块10下一周期备用。Wherein, the first shifter 16 is used to obtain the normalized coding range rangeO according to the normalized coding range range nor and the number of iterations S of coding range normalization, that is, by The coding interval range nor shifted to the left by S bits to obtain the normalized coding interval range0, after the normalized coding interval rangeO passes through the first D flip-flop 17, the output coding interval range is to be updated with the normalization module 10 Reserved for the next cycle.
下面结合图4所示详细介绍等概率编码模式下的编码区间更新与归一化模块10的结构及其工作流程。如图4所示,所述等概率编码模式下的编码区间更新与归一化模块10包括第一D触发器17,当前的编码区间range直接输出作为归一化后的编码区间rangeO。归一化后的编码区间rangeO经过第一D触发器17之后,输出编码区间range待编码区间更新与归一化模块10下一周期备用。The structure and working process of the coding interval update and normalization module 10 in the equal-probability coding mode will be described in detail below in conjunction with FIG. 4 . As shown in FIG. 4 , the coding range update and normalization module 10 in the equal probability coding mode includes a first D flip-flop 17 , and the current coding range range is directly output as a normalized coding range rangeO. After the normalized coding interval range0 passes through the first D flip-flop 17, the output coding interval range is to be updated with the normalization module 10 for standby in the next cycle.
下面结合图5所示详细介绍截止编码模式下的编码区间更新与归一化模块10的结构及其工作流程。如图5所示,所述截止编码模式下的编码区间更新与归一化模块10包括:第一减法器13、第二选择器12、首1检测电路15、第一移位器16和第一D触发器17。The structure and working process of the coding interval update and normalization module 10 in the cut-off coding mode will be described in detail below in conjunction with FIG. 5 . As shown in FIG. 5 , the coding interval update and normalization module 10 in the cut-off coding mode includes: a first subtractor 13, a second selector 12, a first 1 detection circuit 15, a first shifter 16 and a first shifter 16. A D flip-flop 17 .
其中,第一减法器13,用于根据当前的编码区间range和当前编码模式mode的小概率字符的区间长度rLPS(截止编码模式下,小概率字符的区间长度rLPS等于2),获得当前编码模式mode下的大概率字符的区间长度rMPS;rMPS的计算公式为:rMPS=range-rLPS。Wherein, the first subtractor 13 is used to obtain the current encoding mode according to the interval length rLPS of the low-probability character of the current encoding interval range and the current encoding mode mode (under the cut-off encoding mode, the interval length rLPS of the low-probability character is equal to 2) The interval length rMPS of high probability characters in mode; the calculation formula of rMPS is: rMPS=range-rLPS.
其中,第二选择器12,用于根据当前编码模式mode和当前编码符号bin,从当前编码模式mode的小概率字符的区间长度rLPS或当前模式mode下大概率字符的区间长度rMPS中选择其一作为归一化前的编码区间rangenor进行输出。Wherein, the second selector 12 is used to select one of the interval length rLPS of the low probability character in the current encoding mode mode or the interval length rMPS of the high probability character in the current mode mode according to the current encoding mode mode and the current encoding symbol bin It is output as the encoding interval range nor before normalization.
其中,首1检测电路15,用于对归一化前的编码区间rangenor进行前导0计数,得到编码区间归一化的迭代次数S。编码区间归一化的迭代次数S将输入到下一级流水引擎,也就是编码下限更新与归一化模块20。Wherein, the first 1 detection circuit 15 is used for counting the leading 0s of the encoding interval range nor before normalization, so as to obtain the iteration number S of the encoding interval normalization. The number of iterations S of the normalization of the encoding interval will be input to the next-level pipeline engine, that is, the encoding lower limit update and normalization module 20 .
其中,第一移位器16,用于根据所述归一化前的编码区间rangenor和编码区间归一化的迭代次数S得到归一化后的编码区间rangeO,即通过将归一化前的编码区间rangenor左移S位得到归一化后的编码区间rangeO。归一化后的编码区间rangeO经过第一D触发器17之后,输出编码区间range待编码区间更新与归一化模块10下一周期备用。Wherein, the first shifter 16 is used to obtain the normalized coding range rangeO according to the normalized coding range range nor and the number of iterations S of coding range normalization, that is, by The coding interval range nor is shifted to the left by S bits to obtain the normalized coding interval rangeO. After the normalized coding interval range0 passes through the first D flip-flop 17, the output coding interval range is to be updated with the normalization module 10 for standby in the next cycle.
图6中本发明实施例的模式复用下的编码下限更新与归一化模块的工作流程示意图,图7中本发明实施例的常规编码模式以及截止编码模式下的编码下限更新与归一化模块的工作流程示意图,图8中本发明实施例的等概率编码模式下的编码下限更新与归一化模块的工作流程示意图。Schematic diagram of the workflow of the coding lower limit update and normalization module under the mode multiplexing of the embodiment of the present invention in FIG. Schematic diagram of the workflow of the module, and a schematic diagram of the workflow of the lower limit update and normalization module of the embodiment of the present invention in the equal-probability coding mode in FIG. 8 .
下面结合图6所示详细介绍本发明实施例的模式复用下的编码下限更新与归一化模块20的结构及其工作流程。如图6所示,所述模式复用下的编码下限更新与归一化模块20包括第三选择器21、第四选择器22、第一加法器23、第五选择器24、第二移位器25、第三移位器26、第四移位器27、第一比较器28和第二D触发器29。The structure and working process of the encoding lower limit update and normalization module 20 under mode multiplexing in the embodiment of the present invention will be described in detail below in conjunction with FIG. 6 . As shown in Figure 6, the encoding lower limit update and normalization module 20 under the mode multiplexing includes a third selector 21, a fourth selector 22, a first adder 23, a fifth selector 24, a second shifter 25, a third shifter 26, a fourth shifter 27, a first comparator 28 and a second D flip-flop 29.
其中,第三选择器21的输入大概率字符的区间长度rMPS和当前的编码区间range以及一编码下限的默认值(在此可以为0),选择因子为编码模式mode和编码符号bin,输出为low_add1。具体来说,当编码模式mode为0且编码符号bin为小概率字符的区间长度rLPS时,第三选择器21输出的low_add1等于rMPS;当mode为1且bin为1时,输出的low_add1等于range;否则输出的low_add1等于0。Wherein, the interval length rMPS of the input high-probability character of the third selector 21 and the default value of the current coding interval range and a coding lower limit (can be 0 here), the selection factor is the coding mode mode and the coding symbol bin, and the output is low_add1. Specifically, when the encoding mode mode is 0 and the encoding symbol bin is the interval length rLPS of a small probability character, the low_add1 output by the third selector 21 is equal to rMPS; when the mode is 1 and the bin is 1, the output low_add1 is equal to range ; otherwise output low_add1 is equal to 0.
其中,第四选择器22的输入为编码下限low或2倍的编码下限(即2*low),选择因子为编码模式mode,输出为low_add0。具体来说,当mode为1时,第四选择器22输出的low_add0为2*low,其他情况选择low为输出。Wherein, the input of the fourth selector 22 is the encoding lower limit low or twice the encoding lower limit (ie 2*low), the selection factor is the encoding mode mode, and the output is low_add0. Specifically, when the mode is 1, the low_add0 output by the fourth selector 22 is 2*low, and low is selected as the output in other cases.
其中,第一加法器23根据所述第三选择器21和第四选择器22的输出获得归一化前的编码下限lownor。Wherein, the first adder 23 obtains the encoding lower limit low nor before normalization according to the outputs of the third selector 21 and the fourth selector 22 .
其中,第五选择器24根据所述编码模式mode得到编码下限归一化的迭代次数S1。第五选择器24的输入为编码区间归一化的迭代次数S和编码下限归一化的迭代次数的默认值(在此可以为1),选择因子为编码模式mode,输出为编码下限归一化的迭代次数S1。具体来说,当mode为1时,即等概率编码模式时,第五选择器24输出的编码下限归一化的迭代次数S1等于1;其他模式下,编码下限归一化的迭代次数S1等于S。Wherein, the fifth selector 24 obtains the iteration number S1 of encoding lower limit normalization according to the encoding mode mode. The input of the 5th selector 24 is the default value (here can be 1) of the number of iterations S of normalized encoding interval normalization and the number of iterations of encoding lower limit normalization, the selection factor is the encoding mode mode, and the output is normalized by the lower limit of encoding The number of iterations S1 of optimization. Specifically, when the mode is 1, that is, in the equal-probability coding mode, the number of iterations S1 of the encoding lower limit normalization output by the fifth selector 24 is equal to 1; in other modes, the number of iterations S1 of the encoding lower limit normalization is equal to S.
其中,第二移位器25将归一化前的编码下限lownor左移S1位,取低9位,得到归一化后的编码下限lowO的低9位,所述第二移位器25所得结果通过第三移位器26右移9位得到编码下限的溢出位overflow_low。编码下限的溢出位overflow_low输入到下一级流水引擎,也就是码流提取模块30。在本实施例中编码下限的溢出位overflow_low的位数为8位,但应理解,本发明并不限定编码下限的溢出位overflow_low的位数。Wherein, the second shifter 25 shifts the coding lower limit low nor before normalization to the left by S1 bits, and takes the lower 9 bits to obtain the lower 9 bits of the normalized coding lower limit low0, and the second shifter 25 The obtained result is shifted right by 9 bits by the third shifter 26 to obtain the overflow bit overflow_low of the encoding lower limit. The overflow bit overflow_low of the encoding lower limit is input to the next-level pipeline engine, that is, the code stream extraction module 30 . In this embodiment, the number of overflow bits overflow_low of the encoding lower limit is 8 bits, but it should be understood that the present invention does not limit the number of overflow bits overflow_low of the encoding lower limit.
其中,归一化后的编码下限lowO的最高位通过如下方式获得:判断lownor的第10位以及其后的S1位是否每一位都为1,如果都为1,则归一化后的编码下限lowO的最高位为1,否则为0。具体实现方式如下,第四移位器27将一常数0x1ff右移S1位后与归一化前的编码下限lownor按位或输出,第一比较器28将按位或输出的结果与一常数0x3ff进行比较,得到归一化后的编码下限lowO的最高位。本实施例中,按位或操作的结果若等于0x3ff,则归一化后的编码下限lowO的最高位为1,否则为0。Among them, the highest bit of the normalized coding lower limit lowO is obtained by the following method: judging whether the 10th bit of low nor and the subsequent S1 bits are all 1, if they are all 1, then the normalized The highest bit of the encoding lower limit lowO is 1, otherwise it is 0. The specific implementation is as follows, the fourth shifter 27 shifts a constant 0x1ff to the right by S1 bits and outputs the code lower limit low nor before normalization, and the first comparator 28 outputs the result of the bitwise OR output with a constant 0x3ff is compared to obtain the highest bit of the normalized coding lower limit lowO. In this embodiment, if the result of the bitwise OR operation is equal to 0x3ff, then the highest bit of the normalized coding lower limit low0 is 1, otherwise it is 0.
归一化后的编码下限lowO经过第二D触发器29之后,输出编码下限low待编码下限更新与归一化模块20下一周期备用。After the normalized encoding lower limit lowO passes through the second D flip-flop 29, the output encoding lower limit low is to be updated with the normalization module 20 for standby in the next cycle.
下面结合图7所示详细介绍本发明实施例的常规编码模式以及截止编码模式下的编码下限更新与归一化模块20的结构及其工作流程。如图7所示,所述常规编码模式以及截止编码模式下的编码下限更新与归一化模块20包括第三选择器21、第一加法器23、第五选择器24、第二移位器25、第三移位器26、第四移位器27、第一比较器28和第二D触发器29。The structure and working flow of the coding lower limit update and normalization module 20 in the conventional coding mode and the cut-off coding mode of the embodiment of the present invention will be described in detail below with reference to FIG. 7 . As shown in FIG. 7 , the encoding lower limit update and normalization module 20 in the normal encoding mode and the cut-off encoding mode includes a third selector 21, a first adder 23, a fifth selector 24, and a second shifter. 25 , a third shifter 26 , a fourth shifter 27 , a first comparator 28 and a second D flip-flop 29 .
其中,第三选择器21的输入为编码区间更新与归一化模块10输出的大概率字符的区间长度rMPS以及一编码下限的默认值(在此可以为0),选择因子为编码符号bin,输出为low_add1。具体来说,编码符号bin为小概率字符rLPS时,第三选择器21输出的low_add1等于rMPS;否则输出的low_add1等于0。Wherein, the input of the third selector 21 is the interval length rMPS of the high-probability character outputted by the encoding interval update and normalization module 10 and a default value of an encoding lower limit (which can be 0 here), and the selection factor is an encoding symbol bin, The output is low_add1. Specifically, when the encoding symbol bin is a low-probability character rLPS, the output low_add1 of the third selector 21 is equal to rMPS; otherwise, the output low_add1 is equal to 0.
其中,第一加法器23根据所述第三选择器21和编码下限low获得归一化前的编码下限lownor。Wherein, the first adder 23 obtains the encoding lower limit low nor before normalization according to the third selector 21 and the encoding lower limit low.
其中,第五选择器24根据所述编码模式mode得到编码下限归一化的迭代次数S1。第五选择器24的输入为编码区间归一化的迭代次数S和编码下限归一化的迭代次数的默认值,在此可以为1,选择因子为编码模式mode,输出为编码下限归一化的迭代次数S1。编码下限归一化的迭代次数S1等于S。Wherein, the fifth selector 24 obtains the iteration number S1 of encoding lower limit normalization according to the encoding mode mode. The input of the fifth selector 24 is the default value of the number of iterations S of the encoding interval normalization and the number of iterations of the encoding lower limit normalization, which can be 1 here, the selection factor is the encoding mode mode, and the output is the encoding lower limit normalization The number of iterations S1. The number of iterations S1 of encoding lower bound normalization is equal to S.
其中,第二移位器25将归一化前的编码下限lownor左移S1位,取低9位,得到归一化后的编码下限lowO的低9位,所述第二移位器25所得结果通过第三移位器26右移9位得到编码下限的溢出位overflow_low。编码下限的溢出位overflow_low输入到下一级流水引擎,也就是码流提取模块30。在本实施例中编码下限的溢出位overflow_low的位数为8位,但应理解,本发明并不限定编码下限的溢出位overflow_low的位数。Wherein, the second shifter 25 shifts the coding lower limit low nor before normalization to the left by S1 bits, and takes the lower 9 bits to obtain the lower 9 bits of the normalized coding lower limit low0, and the second shifter 25 The obtained result is shifted right by 9 bits by the third shifter 26 to obtain the overflow bit overflow_low of the encoding lower limit. The overflow bit overflow_low of the encoding lower limit is input to the next-level pipeline engine, that is, the code stream extraction module 30 . In this embodiment, the number of overflow bits overflow_low of the encoding lower limit is 8 bits, but it should be understood that the present invention does not limit the number of overflow bits overflow_low of the encoding lower limit.
归一化后的编码下限lowO的最高位通过如下方式获得:判断lownor的第10位以及其后的S1位是否每一位都为1,如果都为1,则归一化后的编码下限lowO的最高位为1,否则为0。具体实现方式如下,第四移位器27将常数0x1ff左移S1位后与归一化前的编码下限lownor按位或输出,第一比较器28将按位或输出的结果与一常数0x3ff进行比较,得到归一化后的编码下限lowO的最高位。本实施例中,按位或操作的结果若等于0x3ff,则归一化后的编码下限lowO的最高位为1,否则为0。The highest bit of the normalized coding lower limit lowO is obtained by the following method: judge whether the 10th bit of low nor and the subsequent S1 bits are all 1, and if they are all 1, then the normalized coding lower limit The highest bit of lowO is 1, otherwise it is 0. The specific implementation method is as follows, the fourth shifter 27 shifts the constant 0x1ff to the left by S1 bits and outputs the bitwise OR output with the lower limit low nor of the encoding before normalization, and the first comparator 28 combines the result of the bitwise OR output with a constant 0x3ff Compare to obtain the highest bit of the normalized coding lower limit lowO. In this embodiment, if the result of the bitwise OR operation is equal to 0x3ff, then the highest bit of the normalized coding lower limit low0 is 1, otherwise it is 0.
归一化后的编码下限lowO经过第二D触发器29之后,输出编码下限low待编码下限更新与归一化模块20下一周期备用。After the normalized encoding lower limit lowO passes through the second D flip-flop 29, the output encoding lower limit low is to be updated with the normalization module 20 for standby in the next cycle.
下面结合图8所示详细介绍本发明实施例的等概率编码模式下的编码下限更新与归一化模块20的结构及其工作流程。如图8所示,所述等概率编码模式下的编码下限更新与归一化模块20包括第三选择器21、第一加法器23、第五选择器24、第二移位器25、第三移位器26、第四移位器27、第一比较器28和第二D触发器29。The structure and working process of the coding lower limit update and normalization module 20 in the equal-probability coding mode of the embodiment of the present invention will be described in detail below with reference to FIG. 8 . As shown in FIG. 8 , the coding lower limit update and normalization module 20 in the equal probability coding mode includes a third selector 21, a first adder 23, a fifth selector 24, a second shifter 25, a Three shifters 26 , a fourth shifter 27 , a first comparator 28 and a second D flip-flop 29 .
其中,第三选择器21的输入为编码区间更新与归一化模块10输出的当前的编码区间range和编码下限的默认值(在此可以为0),选择因子为编码符号bin,输出为low_add1。具体来说,当编码符号bin为1时,输出的low_add1等于range;否则输出的low_add1等于0。Wherein, the input of the third selector 21 is the current encoding interval range output by the encoding interval update and normalization module 10 and the default value of the encoding lower limit (here may be 0), the selection factor is the encoding symbol bin, and the output is low_add1 . Specifically, when the encoding symbol bin is 1, the output low_add1 is equal to range; otherwise, the output low_add1 is equal to 0.
其中,第一加法器23根据所述第三选择器21和2倍的编码下限(即2*low)获得归一化前的编码下限lownor。Wherein, the first adder 23 obtains the coding lower limit low nor before normalization according to the third selector 21 and twice the coding lower limit (ie, 2*low).
其中,第五选择器24根据所述编码模式mode得到编码下限归一化的迭代次数S1。第五选择器24的输入为编码区间归一化的迭代次数S和编码下限归一化的迭代次数的默认值,在此可以为1,选择因子为编码模式mode,输出为编码下限归一化的迭代次数S1,编码下限归一化的迭代次数S1等于1。Wherein, the fifth selector 24 obtains the iteration number S1 of encoding lower limit normalization according to the encoding mode mode. The input of the fifth selector 24 is the default value of the number of iterations S of the encoding interval normalization and the number of iterations of the encoding lower limit normalization, which can be 1 here, the selection factor is the encoding mode mode, and the output is the encoding lower limit normalization The number of iterations S1 of the encoding lower limit normalization is equal to 1.
其中,第二移位器25将归一化前的编码下限lownor左移S1位,取低9位,得到归一化后的编码下限lowO的低9位,所述第二移位器25所得结果通过第三移位器26右移9位得到编码下限的溢出位overflow_low。编码下限的溢出位overflow_low输入到下一级流水引擎,也就是码流提取模块30。在本实施例中编码下限的溢出位overflow_low的位数为8位,但应理解,本发明并不限定编码下限的溢出位overflow_low的位数。Wherein, the second shifter 25 shifts the coding lower limit low nor before normalization to the left by S1 bits, and takes the lower 9 bits to obtain the lower 9 bits of the normalized coding lower limit low0, and the second shifter 25 The obtained result is shifted right by 9 bits by the third shifter 26 to obtain the overflow bit overflow_low of the encoding lower limit. The overflow bit overflow_low of the encoding lower limit is input to the next-level pipeline engine, that is, the code stream extraction module 30 . In this embodiment, the number of overflow bits overflow_low of the encoding lower limit is 8 bits, but it should be understood that the present invention does not limit the number of overflow bits overflow_low of the encoding lower limit.
其中,归一化后的编码下限lowO的最高位通过如下方式获得:判断lownor的第10位以及其后的S1位是否每一位都为1,如果都为1,则归一化后的编码下限lowO的最高位为1,否则为0。具体实现方式如下,第四移位器27将常数0x1ff左移S1位后与归一化前的编码下限lownor按位或输出,第一比较器28将按位或输出的结果与一常数0x3ff进行比较,得到归一化后的编码下限lowO的最高位。本实施例中,按位或操作的结果若等于0x3ff,则归一化后的编码下限lowO的最高位为1,否则为0。Among them, the highest bit of the normalized coding lower limit lowO is obtained by the following method: judging whether the 10th bit of the lownor and the subsequent S1 bits are all 1, and if they are all 1, the normalized coding The highest bit of the lower bound lowO is 1, otherwise it is 0. The specific implementation is as follows, the fourth shifter 27 shifts the constant 0x1ff to the left by S1 bits and outputs the bit-wise OR output with the lower limit lownor before normalization, and the first comparator 28 performs bit-wise OR output with a constant 0x3ff Compare to obtain the highest bit of the normalized encoding lower limit lowO. In this embodiment, if the result of the bitwise OR operation is equal to 0x3ff, then the highest bit of the normalized coding lower limit low0 is 1, otherwise it is 0.
归一化后的编码下限lowO经过第二D触发器29之后,输出编码下限low待编码下限更新与归一化模块20下一周期备用。After the normalized encoding lower limit lowO passes through the second D flip-flop 29, the output encoding lower limit low is to be updated with the normalization module 20 for standby in the next cycle.
请参考图9,其为本发明实施例的码流提取模块的结构示意图。如图9所示,所述码流提取模块30包括首0检测电路31、第六选择器32、第三D触发器33、第七选择器34和码流输出单元,所述码流输出单元包括第八选择器35、第五移位器36和第六移位器37。其中,首0检测电路31、第六选择器32、第三D触发器33和第七选择器34用于输出码流长度bit_len,第八选择器35、第五移位器36和第六移位器37用于输出码流bit_stream。Please refer to FIG. 9 , which is a schematic structural diagram of a code stream extraction module according to an embodiment of the present invention. As shown in Figure 9, the code stream extraction module 30 includes the first 0 detection circuit 31, the sixth selector 32, the third D flip-flop 33, the seventh selector 34 and a code stream output unit, the code stream output unit An eighth selector 35 , a fifth shifter 36 and a sixth shifter 37 are included. Among them, the first 0 detection circuit 31, the sixth selector 32, the third D flip-flop 33 and the seventh selector 34 are used to output the code stream length bit_len, the eighth selector 35, the fifth shifter 36 and the sixth shifter The bit device 37 is used to output the code stream bit_stream.
首0检测电路31对上一级流水引擎输出的编码下限的溢出位overflow_low进行尾部首0检测,输出第一个0之后出现的1的个数N,所述第一个0之后出现的1的个数N与编码下限归一化的迭代次数S1进行比较,得到比较结果sel。在此,比较结果sel表示码流提取中S1与N的大小关系,当S1小于N时,sel为0;当S1等于N时,sel为1;当S1大于N时,sel为2。The first 0 detection circuit 31 detects the first 0 at the end of the overflow bit overflow_low of the encoding lower limit output by the upper-level pipeline engine, and outputs the number N of 1s that appear after the first 0, and the number of 1s that appear after the first 0. The number N is compared with the iteration number S1 of the encoding lower limit normalization, and the comparison result sel is obtained. Here, the comparison result sel indicates the size relationship between S1 and N in code stream extraction. When S1 is smaller than N, sel is 0; when S1 is equal to N, sel is 1; when S1 is greater than N, sel is 2.
第六选择器32根据比较结果sel进行选择,得到不确定位个数num_ostd。第六选择器32的输入为N,不确定位个数的默认值,在此可以为0和S1+num_ostd,选择因子为比较结果sel。当比较结果sel为0时,第六选择器32得到的不确定位个数num_ostd为S1+num_ostd;当比较结果sel为1时,得到的不确定位个数num_ostd为0;当比较结果sel为2时,得到的不确定位个数num_ostd为N。The sixth selector 32 selects according to the comparison result sel to obtain the number of uncertain bits num_ostd. The input of the sixth selector 32 is N, and the default value of the number of bits is uncertain, which can be 0 and S1+num_ostd here, and the selection factor is the comparison result sel. When the comparison result sel is 0, the number of uncertain bits num_ostd obtained by the sixth selector 32 is S1+num_ostd; when the comparison result sel is 1, the number of uncertain bits num_ostd obtained is 0; when the comparison result sel is 2, the obtained number of uncertain bits num_ostd is N.
第六选择器32输出的不确定位个数num_ostd输入到第三D触发器33的D端,第三D触发器33存储所述不确定位个数num_ostd作为下一周期备用,第三D触发器33的Q端输出的是当前周期的不确定位个数num_ostd。不确定位是指H.264参考代码中的BitOutStanding,当未能确定最终输出的是‘1’还是‘0’时由num_ostd来计数。不确定位个数num_ostd用于输出当前周期的码流长度bit_len以及计算新的不确定位个数num_ostd。The number of uncertain bits num_ostd output by the sixth selector 32 is input to the D terminal of the third D flip-flop 33, and the third D flip-flop 33 stores the number of uncertain bits num_ostd as a backup for the next cycle, and the third D flip-flop The output of the Q terminal of the device 33 is the number of uncertain bits num_ostd in the current period. The uncertain bit refers to BitOutStanding in the H.264 reference code, which is counted by num_ostd when it is not possible to determine whether the final output is '1' or '0'. The number of uncertain bits num_ostd is used to output the code stream length bit_len of the current period and calculate the new number of uncertain bits num_ostd.
第七选择器34根据比较结果sel输出码流长度bit_len。第七选择器34的输入为S1+num_ostd、码流长度的默认值(在此可以为0)、S1+num_ostd-N,选择因子为比较结果sel。当比较结果sel为0时,输出的码流长度bit_len为S1+num_ostd;当比较结果sel为1时,输出的码流长度bit_len为0;当比较结果sel为2时,输出的码流长度bit_len为S1+num_ostd-N。The seventh selector 34 outputs the code stream length bit_len according to the comparison result sel. The input of the seventh selector 34 is S1+num_ostd, the default value of the code stream length (here may be 0), S1+num_ostd-N, and the selection factor is the comparison result sel. When the comparison result sel is 0, the output code stream length bit_len is S1+num_ostd; when the comparison result sel is 1, the output code stream length bit_len is 0; when the comparison result sel is 2, the output code stream length bit_len It is S1+num_ostd-N.
可见,当sel为0时,码流长度bit_len更新为S1+num_ostd,不确定位个数num_ostd更新为0;当sel为1时,码流长度bit_len更新为0,不确定位个数num_ostd更新为S1+num_ostd;当sel为2时表示S1大于N,码流长度bit_len更新为S1+num_ostd–N,不确定位个数num_ostd更新为N。It can be seen that when sel is 0, the code stream length bit_len is updated to S1+num_ostd, and the number of uncertain bits num_ostd is updated to 0; when sel is 1, the code stream length bit_len is updated to 0, and the number of uncertain bits num_ostd is updated to S1+num_ostd; when sel is 2, it means that S1 is greater than N, the code stream length bit_len is updated to S1+num_ostd–N, and the number of uncertain bits num_ostd is updated to N.
在码流输出单元中,第八选择器35的输入为两个常数,分别是64’h7fffffffffffffff和64’h8000000000000000,第八选择器35的选择因子为有效码流的最高位overflow_low[S1]。当有效码流的最高位overflow_low[S1]为0时,输出为64’h7fffffffffffffff;当有效码流的最高位overflow_low[S1]为1时,输出为64’h8000000000000000。第八选择器35的输出结果经过第五移位器36右移63-num_ostd位,之后经过第六移位器37再左移S1+1位,最后与最末位overflow_low[s1-1:0]按位或输出。In the code stream output unit, the input of the eighth selector 35 is two constants, which are 64'h7fffffffffffffff and 64'h8000000000000000 respectively, and the selection factor of the eighth selector 35 is the highest bit overflow_low[S1] of the effective code stream. When the highest bit overflow_low[S1] of the effective code stream is 0, the output is 64’h7fffffffffffffff; when the highest bit overflow_low[S1] of the effective code stream is 1, the output is 64’h8000000000000000. The output result of the eighth selector 35 is shifted right by 63-num_ostd bits through the fifth shifter 36, then shifted left by S1+1 bits through the sixth shifter 37, and finally with the last bit overflow_low[s1-1:0 ] bitwise OR output.
由此,码流输出单元能够根据上一级流水引擎输入的编码下限的溢出位overflow_low采用左对齐方式依次输出码流的最高位overflow_low[S1]、不确定位个数num_ostd位的中间位!overflow_low[S1]和若干个最末位overflow_low[s1-1:0]。其中,overflow_low[S1]表示编码下限的溢出位overflow_low的第S1+1位,!overflow_low[S1]表示编码下限的溢出位overflow_low的第S1+1位取反,overflow_low[s1-1:0]表示编码下限的溢出位overflow_low的低S1位。码流输出单元输出的码流bit_stream已经包容了各种情况,符合H.264/AVC标准。所述码流提取模块20可在一个时钟周期内完成码流提取操作,码流提取操作非常简便,无需额外的FIFO资源(数据缓存)。As a result, the code stream output unit can output the highest bit overflow_low[S1] of the code stream and the middle bit of the uncertain number of bits num_ostd in sequence according to the overflow bit overflow_low of the lower limit of the encoding input by the upper-level pipeline engine in a left-aligned manner! overflow_low[S1] and several last overflow_low[s1-1:0]. Among them, overflow_low[S1] represents the S1+1th bit of the overflow bit overflow_low of the encoding lower limit, ! overflow_low[S1] indicates the inversion of the S1+1 bit of the overflow bit overflow_low of the encoding lower limit, and overflow_low[s1-1:0] indicates the lower S1 bit of the overflow bit overflow_low of the encoding lower limit. The code stream bit_stream output by the code stream output unit has accommodated various situations and conforms to the H.264/AVC standard. The code stream extraction module 20 can complete the code stream extraction operation within one clock cycle, the code stream extraction operation is very simple, and no additional FIFO resource (data cache) is needed.
由上可知,在本发明实施例提供二进制算术编码器中,编码区间更新与归一化模块10和编码下限更新与归一化模块20通过选择器实现了三种编码模式的共用,无需增加任何控制电路,能够减少硬件成本。而且,由于编码下限归一化的迭代次数S1和编码下限的溢出位overflow_low可以由一个或多个编码符号bin二进制算术编码归一化后得到,因此所述二进制算术编码器可以在一个时钟周期内完成一个或多个编码符号bin的码流提取操作,码流提取操作非常简便,无需额外的FIFO资源(数据缓存)。As can be seen from the above, in the binary arithmetic encoder provided by the embodiment of the present invention, the encoding interval update and normalization module 10 and the encoding lower limit update and normalization module 20 realize the sharing of the three encoding modes through the selector without adding any The control circuit can reduce hardware cost. Moreover, since the number of iterations S1 normalized by the encoding lower limit and the overflow bit overflow_low of the encoding lower limit can be normalized by one or more encoding symbols bin binary arithmetic encoding, the binary arithmetic encoder can The code stream extraction operation of one or more encoding symbol bins is completed, and the code stream extraction operation is very simple, without additional FIFO resources (data cache).
相应的,本实施例还提供了一种二进制算术编码器的编码方法。Correspondingly, this embodiment also provides a coding method of a binary arithmetic coder.
请参考图10,其为本发明实施例的二进制算术编码器的编码方法的流程图。如图10所示,并结合图1,所述二进制算术编码器的编码方法包括以下步骤:Please refer to FIG. 10 , which is a flowchart of an encoding method of a binary arithmetic encoder according to an embodiment of the present invention. As shown in Figure 10, and in conjunction with Figure 1, the coding method of described binary arithmetic coder comprises the following steps:
步骤S10:编码区间更新与归一化模块10作为第一级流水引擎,提取编码状态、编码模式以及编码符号,更新编码区间和完成编码区间的归一化,并输出编码区间归一化的迭代次数、编码区间以及大概率字符的区间长度;Step S10: The encoding interval update and normalization module 10 acts as the first-level pipeline engine to extract the encoding state, encoding mode and encoding symbols, update the encoding interval and complete the normalization of the encoding interval, and output the iteration of the normalization of the encoding interval The number of times, the encoding interval, and the interval length of high-probability characters;
步骤S11:编码下限更新与归一化模块20作为第二级流水引擎,提取编码符号、编码模式、编码区间归一化的迭代次数、编码区间以及大概率字符的区间长度,更新编码下限和完成编码下限的归一化,并输出编码下限的溢出位以及编码下限归一化的迭代次数;Step S11: The encoding lower limit update and normalization module 20 is used as the second-level pipeline engine to extract encoding symbols, encoding modes, the number of iterations of encoding interval normalization, encoding intervals, and the interval length of high-probability characters, and update the encoding lower limit and complete Normalize the lower limit of encoding, and output the overflow bits of the lower limit of encoding and the number of iterations of normalization of the lower limit of encoding;
步骤S12:码流提取模块30作为第三级流水引擎,提取所述编码下限归一化的迭代次数和编码下限的溢出位,输出变长码流以及码流长度。Step S12: The code stream extraction module 30, as a third-stage pipeline engine, extracts the number of iterations normalized by the encoding lower limit and overflow bits of the encoding lower limit, and outputs a variable-length code stream and the length of the code stream.
具体的,请参考图11,本实施例中,步骤S10进一步包括:Specifically, please refer to FIG. 11. In this embodiment, step S10 further includes:
步骤S101:第一选择器11根据编码模式获得当前编码模式下的小概率字符的区间长度rLPS;Step S101: the first selector 11 obtains the interval length rLPS of the low-probability character in the current encoding mode according to the encoding mode;
具体来说,所述编码模式mode包括常规编码模式、等概率编码模式和截止编码模式;本实施例中,mode为0表示常规编码模式,mode为1表示等概率编码模式,mode为2表示截止编码模式。当编码模式mode为0或1时,即常规编码模式或等概率编码模式下,根据概率状态state查表结果和range[7:6]得到小概率字符的区间长度rLPS。概率状态state查表得到4个rLPS初始值(rLPS0、rLPS1、rLPS2、rLPS3),第一选择器11根据range[7:6]选择其中一个作为小概率字符的区间长度rLPS作为输出。当编码模式mode为2时,即截止编码模式下,输出的小概率字符的区间长度rLPS等于2;Specifically, the coding mode mode includes a normal coding mode, an equal probability coding mode, and a cutoff coding mode; encoding mode. When the encoding mode mode is 0 or 1, that is, in the normal encoding mode or the equal probability encoding mode, the interval length rLPS of the low-probability character is obtained according to the result of the probability state state table lookup and range[7:6]. The probability state state looks up the table to obtain 4 rLPS initial values (rLPS0, rLPS1, rLPS2, rLPS3), and the first selector 11 selects one of them as the interval length rLPS of the low-probability character according to range[7:6] as output. When the encoding mode mode is 2, that is, in the cut-off encoding mode, the interval length rLPS of the output low-probability character is equal to 2;
步骤S102:第一减法器12根据当前的编码区间range和当前编码模式下的小概率字符的区间长度rLPS,获得当前编码模式下的大概率字符的区间长度rMPS;具体的,rMPS计算公式为:rMPS=range-rLPS;Step S102: The first subtractor 12 obtains the interval length rMPS of the high-probability character in the current encoding mode according to the current encoding interval range and the interval length rLPS of the low-probability character in the current encoding mode; specifically, the rMPS calculation formula is: rMPS = range-rLPS;
步骤S103:第二选择器12根据当前编码模式mode和当前编码符号bin,从当前的编码区间range、当前编码模式下的小概率字符的区间长度rLPS或当前编码模式下的大概率字符的区间rMPS长度中择一作为归一化前的编码区间rangenor进行输出;本实施例中,若当前编码模式mode为1,选择当前的编码区间range为输出;若当前编码模式mode为2且当前编码符号bin为1,或当前编码模式mode为0且当前编码符号bin为0时,选择当前编码模式下的小概率字符的区间长度rLPS为输出;除上述两种之外的其他情况,选择当前编码模式下的大概率字符的区间长度rMPS为输出;Step S103: The second selector 12 selects from the current coding interval range, the interval length rLPS of low-probability characters in the current coding mode, or the interval rMPS of high-probability characters in the current coding mode according to the current coding mode mode and the current coding symbol bin Choose one of the lengths as the encoding interval range nor before normalization to output; in this embodiment, if the current encoding mode mode is 1, select the current encoding interval range as output; if the current encoding mode mode is 2 and the current encoding symbol When the bin is 1, or the current encoding mode mode is 0 and the current encoding symbol bin is 0, select the interval length rLPS of the low-probability character in the current encoding mode as the output; in other cases except the above two, select the current encoding mode The interval length rMPS of the following high probability characters is output;
步骤S104:首1检测电路15对所述归一化前的编码区间rangenor进行前导0计数,得到编码区间归一化的迭代次数S;编码区间归一化的迭代次数S将输入到下一级流水引擎,也就是编码下限更新与归一化模块20;Step S104: The first 1 detection circuit 15 counts the leading 0s of the encoding interval range nor before normalization to obtain the iteration number S of the encoding interval normalization; the iteration number S of the encoding interval normalization will be input to the next Level pipeline engine, that is, the encoding lower limit update and normalization module 20;
步骤S105:第一移位器16根据所述编码区间归一化的迭代次数S,对归一化前的编码区间rangenor进行左移输出归一化后的编码区间rangeO,rangeO经过第一D触发器17之后,输出编码区间range待下一周期备用。Step S105: The first shifter 16 performs left shift on the coding interval range nor before normalization according to the iteration number S of the normalization of the coding interval and outputs the normalized coding interval rangeO, and rangeO passes through the first D After flip-flop 17, the output encoding interval range is reserved for the next cycle.
具体的,请参考图12,本实施例中,步骤S11进一步包括:Specifically, please refer to FIG. 12. In this embodiment, step S11 further includes:
步骤S111:第三选择器21根据当前编码模式mode和当前编码符号bin,从所述当前的编码区间range、当前编码模式下的大概率字符的区间长度rMPS或编码下限的默认值(在此可以为0)中择一作为输出;本实施例中,当编码模式mode为0且编码符号bin为小概率字符rLPS时,第三选择器21输出的low_add1等于rMPS;当mode为1且bin为1时,输出的low_add1等于range;否则输出的low_add1等于0;Step S111: the third selector 21 selects from the current encoding range range, the interval length rMPS of the high probability character in the current encoding mode or the default value of the encoding lower limit according to the current encoding mode mode and the current encoding symbol bin (here can be is 0) to select one as output; in this embodiment, when the encoding mode mode is 0 and the encoding symbol bin is a small probability character rLPS, the low_add1 output by the third selector 21 is equal to rMPS; when the mode is 1 and the bin is 1 When , the output low_add1 is equal to range; otherwise, the output low_add1 is equal to 0;
步骤S112:第四选择器22根据当前编码模式,从编码下限low或2倍的编码下限2*low中择一作为输出;本实施例中,当mode为1时,第四选择器22输出的low_add0为2*low,其他情况选择low为输出;Step S112: According to the current encoding mode, the fourth selector 22 selects one of the encoding lower limit low or twice the encoding lower limit 2*low as an output; in this embodiment, when the mode is 1, the output of the fourth selector 22 low_add0 is 2*low, select low as output in other cases;
步骤S113:第一加法器23根据所述第三选择器21和第四选择器22获得归一化前的编码下限lownor;Step S113: the first adder 23 obtains the coding lower limit low nor before normalization according to the third selector 21 and the fourth selector 22;
步骤S114:第五选择器24根据所述当前编码模式,从所述编码区间归一化的迭代次数S和编码下限归一化的迭代次数S1的默认值(在此可以为1)中择一作为编码下限归一化的迭代次数进行输出;具体来说,当mode为1时,即等概率编码模式时,第五选择器输出的编码下限归一化的迭代次数S1等于1;其他模式下,编码下限归一化的迭代次数S1等于S;Step S114: According to the current encoding mode, the fifth selector 24 selects one from the default value (here, it may be 1) of the number of iterations S normalized by the encoding interval and the number of iterations S1 normalized by the encoding lower limit. It is output as the number of iterations of encoding lower limit normalization; specifically, when mode is 1, that is, in the equal probability encoding mode, the number of iterations S1 of encoding lower limit normalization output by the fifth selector is equal to 1; in other modes , the number of iterations S1 of coding lower limit normalization is equal to S;
步骤S115:第二移位器25根据所述编码下限归一化的迭代次数将归一化前的编码下限左移,取低9位,得到归一化后的编码下限的低9位;Step S115: The second shifter 25 shifts the lower encoding limit before normalization to the left according to the iteration number of the lower encoding limit normalization, and takes the lower 9 bits to obtain the lower 9 bits of the lower encoding limit after normalization;
步骤S116:第三移位器26将所述第二移位器25所得结果右移9位得到编码下限的溢出位overflow_low;编码下限的溢出位overflow_low输入到下一级流水引擎,也就是码流提取模块;在本实施例中编码下限的溢出位overflow_low的位数为8位;Step S116: The third shifter 26 shifts the result obtained by the second shifter 25 to the right by 9 bits to obtain the overflow bit overflow_low of the encoding lower limit; the overflow bit overflow_low of the encoding lower limit is input to the next-level pipeline engine, that is, the code stream Extraction module; In the present embodiment, the overflow_low of the encoding lower limit has 8 digits;
步骤S117:第四移位器27根据编码下限归一化的迭代次数将常数0x1ff右移,常数0x1ff右移后与归一化前的编码下限lownor按位或操作的结果通过第一比较器28与常数0x3ff进行比较,根据比较结果得到归一化后的编码下限lowO的最高位;本实施例中,按位或操作的结果若等于0x3ff,则归一化后的编码下限lowO的最高位为1,否则为0;归一化后的编码下限lowO经过第二D触发器29之后,输出low待下一周期备用。Step S117: The fourth shifter 27 shifts the constant 0x1ff to the right according to the number of iterations of the lower limit of encoding normalization, and the result of the bitwise OR operation of the constant 0x1ff and the lower limit of encoding before normalization passes through the first comparator 28 is compared with the constant 0x3ff, and the highest bit of the normalized coding lower limit low0 is obtained according to the comparison result; in this embodiment, if the result of the bitwise OR operation is equal to 0x3ff, then the highest bit of the normalized coding lower limit low0 It is 1, otherwise it is 0; after the normalized encoding lower limit low0 passes through the second D flip-flop 29, the output low is to be used in the next cycle.
具体的,请参考图13,所述码流提取方法S12包括:Specifically, please refer to FIG. 13, the code stream extraction method S12 includes:
步骤一:对编码下限的溢出位overflow_low进行尾部首零检测以得到第一个0之后出现的1的个数N;Step 1: Perform trailing zero detection on the overflow bit overflow_low of the encoding lower limit to obtain the number N of 1s that appear after the first 0;
步骤二:比较编码下限归一化的迭代次数S1与第一个0之后出现的1的个数N的大小,得到比较结果sel;Step 2: Compare the number of iterations S1 of encoding lower limit normalization with the number N of 1s that appear after the first 0, and obtain the comparison result sel;
步骤三:根据S1与N的比较结果sel得到不确定位个数num_ostd和输出码流长度bit_len;Step 3: Obtain the number of uncertain bits num_ostd and the length of the output code stream bit_len according to the comparison result sel of S1 and N;
步骤四:输出变长码流。Step 4: Output the variable-length code stream.
其中,如果在步骤二中S1小于N,表示之前积累的不确定位可输出,且当前所有的S1都为确定位可输出,积累的不确定位个数记为num_ostd。在步骤三中得到当前可输出的bit_len为S1+num_ostd,新的不确定位个数num_ostd更新为0。之后输出码流,先输出最高位overflow_low[S1],再输出num_ostd位的中间位!overflow_low[S1],最后输出若干个最末位overflow_low[s1-1:0]。至此,当前码流提取完成。Wherein, if S1 is less than N in step 2, it means that the previously accumulated indeterminate bits can be output, and all the current S1 are definite bits and can be output, and the accumulated indeterminate bits are recorded as num_ostd. In step 3, the currently outputtable bit_len is obtained as S1+num_ostd, and the new uncertain number of bits num_ostd is updated to 0. Then output the code stream, first output the highest bit overflow_low[S1], and then output the middle bit of num_ostd bits! overflow_low[S1], and finally output a number of last bits overflow_low[s1-1:0]. So far, the extraction of the current code stream is completed.
如果在步骤二中S1等于N,表示当前所有的S1位bit都为不确定位,因此,当前无可输出的bit,在步骤三中得到新的不确定位个数num_ostd更新为S1+num_ostd。至此,当前码流提取完成。If S1 is equal to N in step 2, it means that all current S1 bits are indeterminate bits, therefore, there is currently no outputable bit, and the new indeterminate number of bits num_ostd obtained in step 3 is updated to S1+num_ostd. So far, the extraction of the current code stream is completed.
如果S1大于N,表示当前有确定位可将之前的不确定位输出,也有新的不确定位。因此,在步骤三中得到当前输出的bit长度为S1+num_ostd–N,新的不确定位个数num_ostd更新为N。之后输出码流,先输出最高位overflow_low[S1],再输出num_ostd位的中间位!overflow_low[S1],最后输出若干个最末位overflow_low[s1-1:0]。至此,当前码流提取完成。If S1 is greater than N, it means that there are currently certain bits to output the previous uncertain bits, and there are also new uncertain bits. Therefore, the current output bit length obtained in step 3 is S1+num_ostd–N, and the new number of uncertain bits num_ostd is updated to N. Then output the code stream, first output the highest bit overflow_low[S1], and then output the middle bit of num_ostd bits! overflow_low[S1], and finally output a number of last bits overflow_low[s1-1:0]. So far, the extraction of the current code stream is completed.
可见,码流bit_stream由三部分组成,分别是最高位overflow_low[S1]、中间位!overflow_low[S1]和最末位overflow_low[s1-1:0],码流输出时最高位overflow_low[S1]、中间位!overflow_low[S1]和最末位overflow_low[S1-1:0]依次输出。当最高位为1时,首先输出1,其后跟着num_ostd位的0,最后输出overflow_low[s1-1:0]。当最高位为0时,首先输出0,其后跟着num_ostd位的1,最后输出overflow_low[s1-1:0]。It can be seen that the code stream bit_stream consists of three parts, namely the highest bit overflow_low[S1] and the middle bit! overflow_low[S1] and the last bit overflow_low[s1-1:0], the highest bit overflow_low[S1] and the middle bit when the code stream is output! overflow_low[S1] and the last overflow_low[S1-1:0] are output in sequence. When the highest bit is 1, first output 1, followed by 0 of the num_ostd bit, and finally output overflow_low[s1-1:0]. When the highest bit is 0, first output 0, followed by num_ostd bit 1, and finally output overflow_low[s1-1:0].
在所述码流提取方法中,一个时钟周期就能完成一个或多个编码符号bin的码流提取操作,因此无须额外的FIFO资源(数据缓存)。In the code stream extraction method, the code stream extraction operation of one or more coded symbol bins can be completed in one clock cycle, so no additional FIFO resource (data buffer) is needed.
所述二进制算术编码器的编码方法中,根据不同的编码模式可以选择不同的参数,进而实现各种编码模式的共用,包括常规编码模式、等概率编码模式和截止编码模式。而且,码流提取方法中由于归一化的迭代次数S1和编码下限的溢出位overflow_low均可以由一个或多个编码符号bin进行二进制算术编码归一化后得到,因此,所述码流提取方法能够一个周期内完成一个或多个编码符号bin的码流提取操作,有效地提高二进制算术编码的处理速度。In the coding method of the binary arithmetic coder, different parameters can be selected according to different coding modes, so as to realize the sharing of various coding modes, including normal coding mode, equal probability coding mode and cut-off coding mode. Moreover, in the code stream extraction method, both the normalized number of iterations S1 and the overflow_low of the encoding lower limit can be obtained after binary arithmetic coding normalization by one or more code symbols bin, therefore, the code stream extraction method The code stream extraction operation of one or more coding symbol bins can be completed in one cycle, and the processing speed of binary arithmetic coding can be effectively improved.
综上,在本发明实施例提供的二进制算术编码器及其编码方法中,编码区间更新与归一化模块、编码下限更新与归一化模块分别采用选择器以适应各种不同的编码模式,使得所述二进制算术编码器能够进行高效地电路复用,减少了硬件成本。同时,所述码流提取方法可以在一个周期内完成一位或多位的码流提取,而且码流提取操作简单,无须额外的FIFO资源(数据缓存)。To sum up, in the binary arithmetic encoder and its encoding method provided by the embodiment of the present invention, the encoding interval update and normalization module, the encoding lower limit update and normalization module respectively use selectors to adapt to various encoding modes, The binary arithmetic coder can be efficiently multiplexed and the hardware cost is reduced. At the same time, the code stream extraction method can complete the code stream extraction of one or more bits in one cycle, and the code stream extraction operation is simple without additional FIFO resources (data cache).
需要说明的是,本说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似部分互相参见即可。对于实施例公开的方法而言,由于与实施例公开的系统相对应,所以描述的比较简单,相关之处参见系统部分说明即可。It should be noted that each embodiment in this specification is described in a progressive manner, each embodiment focuses on the differences from other embodiments, and the same and similar parts of each embodiment can be referred to each other. As for the method disclosed in the embodiment, since it corresponds to the system disclosed in the embodiment, the description is relatively simple, and for the relevant part, please refer to the description of the system part.
上述描述仅是对本发明较佳实施例的描述,并非对本发明范围的任何限定,本发明领域的普通技术人员根据上述揭示内容做的任何变更、修饰,均属于权利要求书的保护范围。The above description is only a description of the preferred embodiments of the present invention, and does not limit the scope of the present invention. Any changes and modifications made by those of ordinary skill in the field of the present invention based on the above disclosures shall fall within the protection scope of the claims.
Claims (57)
Priority Applications (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201511033027.1A CN105791828B (en) | 2015-12-31 | 2015-12-31 | Binary arithmetic encoder and its encoding method |
| CN201910107577.5A CN109587483B (en) | 2015-12-31 | 2015-12-31 | Code stream extraction module |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201511033027.1A CN105791828B (en) | 2015-12-31 | 2015-12-31 | Binary arithmetic encoder and its encoding method |
Related Child Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910107577.5A Division CN109587483B (en) | 2015-12-31 | 2015-12-31 | Code stream extraction module |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN105791828A true CN105791828A (en) | 2016-07-20 |
| CN105791828B CN105791828B (en) | 2019-05-31 |
Family
ID=56390403
Family Applications (2)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910107577.5A Active CN109587483B (en) | 2015-12-31 | 2015-12-31 | Code stream extraction module |
| CN201511033027.1A Active CN105791828B (en) | 2015-12-31 | 2015-12-31 | Binary arithmetic encoder and its encoding method |
Family Applications Before (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910107577.5A Active CN109587483B (en) | 2015-12-31 | 2015-12-31 | Code stream extraction module |
Country Status (1)
| Country | Link |
|---|---|
| CN (2) | CN109587483B (en) |
Cited By (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107343201A (en) * | 2017-06-21 | 2017-11-10 | 珠海市杰理科技股份有限公司 | CABAC coding methods and system |
| CN108391129A (en) * | 2018-04-25 | 2018-08-10 | 西安万像电子科技有限公司 | Data-encoding scheme and device |
| CN108401158A (en) * | 2017-02-07 | 2018-08-14 | 深圳市中兴微电子技术有限公司 | A kind of context-adaptive binary arithmetic coding renormalization implementation method and device |
| CN110365346A (en) * | 2019-07-22 | 2019-10-22 | 浙江大华技术股份有限公司 | A kind of arithmetic entropy coding method and system |
| CN111787325A (en) * | 2020-07-03 | 2020-10-16 | 北京博雅慧视智能技术研究院有限公司 | Entropy encoder and encoding method thereof |
| CN111818335A (en) * | 2020-07-03 | 2020-10-23 | Tcl华星光电技术有限公司 | Entropy coding method and device and electronic equipment |
| CN113141508A (en) * | 2020-01-17 | 2021-07-20 | 阿里巴巴集团控股有限公司 | Arithmetic encoder, method for realizing arithmetic encoding and image encoding method |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101771879A (en) * | 2010-01-28 | 2010-07-07 | 清华大学 | Parallel normalized coding realization circuit based on CABAC and coding method |
| CN101951516A (en) * | 2010-09-25 | 2011-01-19 | 清华大学 | Parallel encoding realization circuit and encoding method based on CABAC (Context-based Adaptive Binary Arithmetic Coding) in H.264/AVC (Advanced Video Coding) |
| CN102176750A (en) * | 2011-03-10 | 2011-09-07 | 西安电子科技大学 | High-performance adaptive binary arithmetic encoder |
| CN104918049A (en) * | 2015-06-03 | 2015-09-16 | 复旦大学 | Binary arithmetic coding module suitable for HEVC (high efficiency video coding) standards |
Family Cites Families (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103248896A (en) * | 2013-05-15 | 2013-08-14 | 中国科学院光电技术研究所 | MQ arithmetic coder |
| CN103974066B (en) * | 2014-05-14 | 2017-02-01 | 华为技术有限公司 | Video coding method and device |
-
2015
- 2015-12-31 CN CN201910107577.5A patent/CN109587483B/en active Active
- 2015-12-31 CN CN201511033027.1A patent/CN105791828B/en active Active
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101771879A (en) * | 2010-01-28 | 2010-07-07 | 清华大学 | Parallel normalized coding realization circuit based on CABAC and coding method |
| CN101951516A (en) * | 2010-09-25 | 2011-01-19 | 清华大学 | Parallel encoding realization circuit and encoding method based on CABAC (Context-based Adaptive Binary Arithmetic Coding) in H.264/AVC (Advanced Video Coding) |
| CN102176750A (en) * | 2011-03-10 | 2011-09-07 | 西安电子科技大学 | High-performance adaptive binary arithmetic encoder |
| CN104918049A (en) * | 2015-06-03 | 2015-09-16 | 复旦大学 | Binary arithmetic coding module suitable for HEVC (high efficiency video coding) standards |
Non-Patent Citations (2)
| Title |
|---|
| DAJIANG ZHOU ET AL.: "Ultra-High-Throughput VLSI Architecture of H .265/HEVC CABAC Encoder for UHDTV Applications", 《IEEE TRANSACTIONS ON CIRCUITS AND SYSTEMS FOR VIDEO TECHNOLOGY》 * |
| 田晓华: "一种高吞吐率CABAC硬件编码器设计", 《武汉理工大学学报(信息与管理工程版)》 * |
Cited By (14)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN108401158A (en) * | 2017-02-07 | 2018-08-14 | 深圳市中兴微电子技术有限公司 | A kind of context-adaptive binary arithmetic coding renormalization implementation method and device |
| CN108401158B (en) * | 2017-02-07 | 2021-01-22 | 深圳市中兴微电子技术有限公司 | Context adaptive binary arithmetic coding renormalization realization method and device |
| CN107343201B (en) * | 2017-06-21 | 2019-11-26 | 珠海市杰理科技股份有限公司 | CABAC coding method and system |
| CN107343201A (en) * | 2017-06-21 | 2017-11-10 | 珠海市杰理科技股份有限公司 | CABAC coding methods and system |
| CN108391129A (en) * | 2018-04-25 | 2018-08-10 | 西安万像电子科技有限公司 | Data-encoding scheme and device |
| CN110365346B (en) * | 2019-07-22 | 2021-07-06 | 浙江大华技术股份有限公司 | Arithmetic entropy coding method and system |
| CN110365346A (en) * | 2019-07-22 | 2019-10-22 | 浙江大华技术股份有限公司 | A kind of arithmetic entropy coding method and system |
| US11967119B2 (en) | 2019-07-22 | 2024-04-23 | Zhejiang Dahua Technology Co., Ltd. | Systems and methods for coding |
| CN113141508A (en) * | 2020-01-17 | 2021-07-20 | 阿里巴巴集团控股有限公司 | Arithmetic encoder, method for realizing arithmetic encoding and image encoding method |
| WO2021143634A1 (en) * | 2020-01-17 | 2021-07-22 | 阿里巴巴集团控股有限公司 | Arithmetic coder, method for implementing arithmetic coding, and image coding method |
| CN113141508B (en) * | 2020-01-17 | 2024-03-26 | 阿里巴巴集团控股有限公司 | Arithmetic encoder, method for realizing arithmetic encoding and image encoding method |
| CN111818335A (en) * | 2020-07-03 | 2020-10-23 | Tcl华星光电技术有限公司 | Entropy coding method and device and electronic equipment |
| CN111787325B (en) * | 2020-07-03 | 2022-03-08 | 北京博雅慧视智能技术研究院有限公司 | Entropy encoder and encoding method thereof |
| CN111787325A (en) * | 2020-07-03 | 2020-10-16 | 北京博雅慧视智能技术研究院有限公司 | Entropy encoder and encoding method thereof |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109587483A (en) | 2019-04-05 |
| CN109587483B (en) | 2020-11-20 |
| CN105791828B (en) | 2019-05-31 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN105791828B (en) | Binary arithmetic encoder and its encoding method | |
| CN103746706B (en) | Test data compression based on double distance of swimming alternate coded and decompression method | |
| CN110291793A (en) | Method and device for range derivation in context-adaptive binary arithmetic codec | |
| CN101414830B (en) | Method for parallel processing of at least two binary values and corresponding arithmetic coding system | |
| CN107565974A (en) | A kind of parallel full coding implementation method of static Huffman | |
| CN102724505B (en) | Run-length coding FPGA (field programmable gate array) implementing method in JPEG-LS (joint photographic experts group-lossless standard) | |
| WO2021143634A1 (en) | Arithmetic coder, method for implementing arithmetic coding, and image coding method | |
| US9819359B1 (en) | Multi-symbol, multi-format, parallel symbol decoder for hardware decompression engines | |
| US10171103B1 (en) | Hardware data compression architecture including shift register and method thereof | |
| CN103248896A (en) | MQ arithmetic coder | |
| JP6695813B2 (en) | Dedicated arithmetic coding instruction | |
| CN107277553B (en) | A binary arithmetic encoder | |
| US9455742B2 (en) | Compression ratio for a compression engine | |
| CN104284189B (en) | A kind of improved BWT data compression methods and its system for implementing hardware | |
| JP6168595B2 (en) | Data compressor and data decompressor | |
| CN103428502A (en) | Decoding method and decoding system | |
| US9697899B1 (en) | Parallel deflate decoding method and apparatus | |
| US20130222159A1 (en) | Entropy method of binary-ternary lossless data coding | |
| CN111526120B (en) | Method for generating TCP checksum by multistage pipeline circuit | |
| Hameed et al. | A new lossless method of Huffman coding for text data compression and decompression process with FPGA implementation | |
| Chen et al. | Huffman coding method based on parallel implementation of FPGA | |
| CN111181568A (en) | Data compression device and method, data decompression device and method | |
| CN114337682A (en) | Huffman coding and compressing device | |
| CN112911314B (en) | Coding method of entropy coder and entropy coder | |
| Biasizzo et al. | A multi-alphabet arithmetic coding hardware implementation for small FPGA devices |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |