Summary of the invention
Technical problem to be solved by this invention is how to adopt a kind of simple effective method, realizes the entropy decoding to two kinds of video data encoders of CAVLC and CABAC on MAE, can guarantee the quality and the decoding efficiency of decoding, and simple in structure being easy to again realized.
The objective of the invention is to disclose a kind of method and device of among the MAE that H.264 decodes entropy coding residual error data etc. being decoded that be exclusively used in, because the method for the invention has adopted cooperative work of software and hardware, make entropy decoder under the prerequisite that guarantees acquisition reliable decoding efficient and decoding quality, greatly reduce the complexity and the computation complexity of structure, thereby effectively solved the contradiction between structure and the efficient, realized decoding smoothly CAVLC and CABAC entropy coding code stream.
Based on the implementation method of H.264 entropy decoder, it is characterized in that: this method has adopted the work of software and hardware association, uses the part that takies ample resources in the decode procedure instead the software program method and realizes, comprises the steps:
Step 1: entropy decoding control module (6) is selected decoding process according to the entropy coding mode flags: promptly be that the CAVLC encoding code stream is decoded or the CABAC encoding code stream is decoded;
Step 2: the decoding type selected according to step (1) is that unit decodes to CAVLC or CABAC encoding code stream with sheet (slice) data;
Step 3: after decoding is finished, judge whether last sheet data into CAVLC or CABAC encoding code stream, if not, return step (2) and continue the data of next sheet (Slice) are decoded, otherwise decode procedure finishes.
Implementation method based on H.264 entropy decoder, describedly use the part that takies ample resources in the decode procedure instead the software program method and realize, it is characterized in that: described software program method is meant the mode of utilizing embedded cpu to replace hardware circuit to carry out computing, rather than simple finger is realized some computing function in the entropy decoding with computer software.
The implementation method of described entropy decoder based on H.264, it is characterized in that: the selected decoding type of the basis described in this method step (2) is that unit decodes to the CAVLC encoding code stream with the sheet data, and wherein said decoding to the CAVLC encoding code stream also comprises following concrete steps:
Step 2.1: entropy decoding control module (6) is sent commencing signal to software module (4), begins to find the solution and relevant variable and the parameter of decoding;
Step 2.2: after software module (4) is received commencing signal from entropy decoding control module (6), also finally obtain required encoded data stream via ue/se/te decoding unit (2), obtain required macroblock parameters and other syntactic elements except that residual error coefficient through decoding by BSI peek module (1);
Step 2.3: after entropy decoding control module (6) is received the end signal that software module (4) sends, send to CAVLC residual error decoding module (3) and to separate the residual error commencing signal;
Step 2.4:CAVLC residual error decoding module (3) begins residual error decoding after receiving the commencing signal that entropy decoding control module (6) sends, and obtains the required coded data of decoding by the BSI module (1) of fetching data, and obtains the residual error coefficient value of luminance block and chrominance block;
Step 2.5: whether what judge decoding is last macro block of sheet data, if not, then turn back to step (2.1) and continue to separate next macro block, otherwise decoding finishes.
The implementation method of described entropy decoder based on H.264, it is characterized in that: to be unit decode to the CAVLC encoding code stream with the sheet data is that described decoding to single macro block comprises following step by realization that each macro block of forming the sheet data is decoded:
Step 1: find the solution and relevant variable and the parameter of macro block decoding by software module;
Step 2: after the required parameter of decodings such as required current macro and the adjacent macroblocks of obtaining decoding according to above-mentioned steps (1), macro block is decoded according to the order of chrominance block after the first luminance block;
Step 3: luminance block is decoded; With the 4x4 piece is basic decoding unit, promptly a 4x4 luminance block is carried out the piece decoding at every turn, earlier direct current (DC) coefficient of luminance block is decoded, and then the ac coefficient (AC) of luminance block is decoded;
Step 4: after the luminance block of having decoded, chrominance block is decoded; With the 4x4 piece is basic decoding unit, according to the order of Cr piece behind the first Cb piece, and the DC coefficient of the chrominance block of decoding earlier, the ac coefficient of the chrominance block of decoding again;
Step 5: repeat above-mentioned steps, continue to separate next macro block.
The implementation method of described entropy decoder based on H.264, the selected decoding process of the described basis of this method step (2) is that unit decodes to the CABAC encoding code stream with the sheet data, and it is characterized in that: wherein said decoding to the CABAC encoding code stream also comprises following concrete steps:
Step 2.1 ': the required context model of CABAC decoding is carried out initialization, and the initialization probability interval;
Step 2.2 ': entropy decoding control module (6) is sent commencing signal to software module (4), begins other syntactic elements except that residual error coefficient, motion vector mvd_10, decodings such as mvd_11, and find the solution the macroblock parameters of using in the residual error decoding;
Step 2.3 ': after software module (4) is received commencing signal from entropy decoding control module (6), also finally obtain required encoded data stream by BSI peek module (1) via binary arithmetic decoding unit (5), decoding obtains required macroblock parameters and other syntactic elements except that residual error coefficient;
Step 2.4 ': entropy decoding control module (6) is sent to CABAC residual error decoding module (7) and is separated the residual error commencing signal;
Step 2.5 ': CABAC residual error decoding module (7) begins residual error decoding after receiving the commencing signal that entropy decoding control module (6) sends, also finally obtain required encoded data stream by BSI peek module (1) via binary arithmetic decoding unit (5), decoding obtains the residual error coefficient value of brightness (luma) and colourity (chroma) piece;
Step 2.6 ': whether the macro block of judging decoding is last macro block of sheet (slice), if not, then turn back to step (2.1 ') and continue to separate next macro block, otherwise decoding finishes.
The implementation method of the entropy decoder based on H.264 of the present invention, it is characterized in that: described to be unit decode to the CABAC encoding code stream is that described decoding to single macro block comprises following step by realization that each macro block of forming the sheet data is decoded with the sheet data:
Step 1: context model and probability interval are carried out initialization;
Step 2: begin other syntactic elements beyond the residual error coefficient are decoded, and macroblock parameters and other parameters that will use in the residual error decoding by adopting software approach to find the solution;
Step 3: the order according to colourity after the first brightness is decoded to residual error macro block;
Step 4: to the decoding of luminance block; With 4x4 piece or 8x8 piece is base unit, earlier the brightness DC coefficient is decoded, and more remaining brightness ac coefficient is decoded, and finishes the decode procedure to luminance block;
Step 5: to the decoding of chrominance block; Order according to Cr piece behind the first Cb is that unit decodes to two chrominance block Cb and Cr piece with the 4x4 piece, separates the DC coefficient of Cb and Cr piece earlier, and then separates the ac coefficient of Cb and Cr piece;
Step 6: repeat above-mentioned steps, continue to separate next macro block.
The invention also discloses a kind of entropy decoder device based on H.264, this device comprises as lower module:
The BSI module of peeking: be responsible for obtaining the required bit stream data of decoding, when receiving the peek request of other modules, return the bit stream data of respective length from the outside;
The ue/se/te decoding unit: the decoding request that the receiving software module is sent is also returned decoded parameter value;
CAVLC residual error decoding mould is fast: with ' 4X4 piece ' is unit, the relevant parameter that decoding obtains according to software module, residual error coefficient to brightness and colourity is decoded, and sends end signal to entropy decoding control module after decoding is finished, and the residual error coefficient that decoding is come out deposits counter-scanning RAM in;
Software module: parameter and variable that residual error decoding needs are decoded, find the solution the parameter relevant by the ue/se/te decoding unit with CAVLC, find the solution the parameter relevant with CABAC by the binary arithmetic decoding unit, the parameter that finally obtains offers CAVCL again or CABAC residual error decoding module is used;
Binary arithmetic decoding unit: when the parameter of decoding relevant,, return the binary result that obtains through decoding when the decoding request of receiving that software module is sent with macro block; In addition carry out the CABAC residual error decoding the time, when receiving the decoding request that CABAC residual error decoding mould sends soon, return the binary result that obtains through decoding;
Entropy decoding control module: control whole decoding process, elder generation's Control Software module is found the solution relevant parameter, be responsible for sending the beginning decoded signal to CAVLC residual error decoding module or CABAC residual error decoding module, after receiving the decoding end signal, the corresponding residual error coefficient that decoding is obtained writes counter-scanning RAM;
CABAC residual error decoding module: with ' 4X4 ' piece or ' 8X8 ' piece is unit, the relevant parameter that decoding obtains according to software module, residual error coefficient to brightness and colourity is decoded, send end signal to entropy decoding control module after decoding is finished, the residual error coefficient that decoding is come out deposits counter-scanning RAM in;
Counter-scanning RAM: the residual error coefficient that storage is fast through CAVLC residual error decoding mould or the decoding of CABAC residual error decoding module obtains.
Remarkable beneficial effect of the present invention is: in the decode procedure of CAVLC and CABAC, especially in decode procedure to the CABAC code stream, the CABAC decoding itself is exactly the process of a complexity, and when other syntactic elements beyond the residual error are decoded, the coded system of CABAC has determined the complexity of decoding, incident is the complexity of calculating, in the ASIC design, if adopting pure hardware fully realizes, this not only will take a large amount of hardware resources, and will certainly increase the difficulty of design greatly.
The present invention proposes a kind of method of among the MAE that H.264 decodes entropy coding residual error data etc. being decoded that is exclusively used in, owing to adopted cooperative work of software and hardware, using the part that takies great amount of hardware resources in the decode procedure instead software mode realizes, make entropy decoder under the prerequisite that guarantees acquisition reliable decoding efficient and decoding quality, greatly reduce the complexity of structure and the complexity of calculating, thereby effectively solved the contradiction between speed and the efficient, realized decoding smoothly CAVLC and CABAC entropy coding code stream.And, owing to adopt solution of the present invention, make entropy decoder can be applied in the actual circuit design, owing to support the decoding of CABAC, can accelerate the H.264 application aspect multimedia video, can be used for the stored digital of SD and other real-time application, as video storage, VOIP, video telephone etc.
Embodiment
Below with reference to Figure of description, specify implementation procedure of the present invention.As shown in Figure 1: the entropy decoder device based on H.264 of the present invention, this device comprises as lower module:
The BSI module 1 of peeking: be responsible for obtaining the required bit stream data of decoding, when receiving the peek request of other modules, return the bit stream data of respective length from the outside;
Ue/se/te decoding unit 2: the ue that the receiving software module is sent, se or te decoding request, and return decoded parameter value;
CAVLC residual error decoding mould fast 3: with ' 4X4 piece ' is unit, the relevant parameter that decoding obtains according to software module, residual error coefficient to brightness and colourity is decoded, and sends end signal to entropy decoding control module after decoding is finished, and the residual error coefficient that decoding is come out deposits counter-scanning RAM in;
Software module 4: some are all decoded with local parameter and variable to residual error decoding needs, find the solution the parameter relevant by the ue/se/te decoding unit with CAVLC, find the solution the parameter relevant with CABAC by the binary arithmetic decoding unit, the parameter that finally obtains offers CAVCL again or CABAC residual error decoding module is used;
Binary arithmetic decoding unit 5: except software module need be by this module when the decoding parameter relevant with residual error, when carrying out the CABAC residual error decoding, CABAC residual error decoding mould sends the decoding request to this module soon, through decoding, returns and obtains binary result;
Entropy decoding control module 6: control whole decoding process, elder generation's Control Software module is found the solution relevant parameter, be responsible for sending the beginning decoded signal to CAVLC residual error decoding module or CABAC residual error decoding module, after receiving the decoding end signal, the corresponding residual error coefficient that decoding is obtained writes counter-scanning RAM;
CABAC residual error decoding module 7: with ' 4X4 ' piece or ' 8X8 ' piece is unit, the relevant parameter that decoding obtains according to software module, residual error coefficient to brightness and colourity is decoded, send end signal to entropy decoding control module after decoding is finished, the residual error coefficient that decoding is come out deposits counter-scanning RAM. in
Counter-scanning RAM8: or signal that CABAC residual error decoding module send fast, the residual error coefficient that storage is fast through CAVLC residual error decoding mould or the decoding of CABAC residual error decoding module obtains according to CAVLC residual error decoding mould.
Entropy decoding at first will be determined the coded system of encoding code stream, and the determining of coded system obtains according to the coding mode sign, and as shown in Figure 2, the presentation code mode is the CAVLC coding when coding mode sign entropy_mode_flag=0; The presentation code mode is the CABAC coding when coding mode sign entropy_mode_flag=1, according to the corresponding coding/decoding method of the coding mode selection of judging.
Decode procedure below in conjunction with accompanying drawing 1 explanation entropy decoder:
Step 1: determined after the coded system of code stream entropy decoding control module 6 type that decision is decoded according to coded system: promptly be to decode to the decoding of CAVLC encoding code stream or to the CABAC encoding code stream; If separate the CAVLC encoding code stream, then enter step 2 and carry out, if separate the CABAC encoding code stream, then enter step 3 and carry out;
Step 2: carry out the CAVLC decoding;
Step 3: carry out the CABAC decoding;
Step 4: after step (2) or step (3) are finished, turn back to step (1), the data that continue to separate next sheet (slice).
As shown in Figure 1, the concrete steps of the described CAVLC of the carrying out decoding of above-mentioned steps (2) are:
Step 2.1: entropy decoding control module 6 is sent commencing signal to software module 4, finds the solution and the relevant non-residual error syntactic element of decoding, and as mb_type, sub_mb_type, motion vector mvd_10, mvd_11 etc.;
Step 2.2: after software module 4 is received commencing signal from entropy decoding control module 6, also finally obtain required encoded data stream by BSI peek module 1 via ue/se/te module 2, decoding obtains required other syntactic elements except that macroblock parameters and residual error coefficient;
Step 2.3: after entropy decoding control module 6 is received the end signal that software module 4 sends, send to CAVLC residual error decoding module 3 and to separate the residual error commencing signal;
Step 2.4:CAVLC residual error decoding module 3 begins residual error decoding after receiving the commencing signal that entropy decoding control module 6 sends, and obtains the required coded data of decoding by the BSI module 1 of fetching data, and final decoding obtains the residual error coefficient value of brightness and chrominance block;
Step 2.5: if decoding is not last macro block of sheet (slice), then turn back to step 2.2, continue to separate next macro block, otherwise finish.
As shown in Figure 1, the described concrete steps to the CABAC decoding of step (3) are:
Step 3.1: the required context model of CABAC decoding is carried out initialization, and the initialization probability interval;
Step 3.2: entropy decoding decoding control module 6 is to 4 commencing signals of software module, begin other syntactic elements such as mb_type beyond the residual error coefficient, sub_mb_type, motion vector mvd_10, decodings such as mvd_11, and find the solution macroblock parameters and other parameters that will use in the residual error decoding;
Step 3.3: after software module 4 is received commencing signal from entropy decoding decoding control module 6, also finally obtain required encoded data stream by BSI peek module 1 via binary arithmetic decoding unit 5, decoding obtains required macroblock parameters and other syntactic elements except that residual error coefficient;
Step 3.4: entropy decoding control module 6 is sent to CABAC residual error decoding module 7 and is separated the residual error commencing signal;
Step 3.5:CABAC residual error decoding module 7 begins residual error decoding after receiving the commencing signal that entropy decoding control module 6 sends, also finally obtain required encoded data stream by BSI peek module 1 via binary arithmetic decoding unit 5 equally, final decoding obtains the residual error coefficient value of brightness and chrominance block;
Step 3.6: if decoding is not last macro block of sheet (slice), get back to step 3.2, otherwise finish.
The macro block of sheet data is carried out the flow process of CAVLC decoding below with reference to Fig. 3 explanation:
Step 1: finish by software module and to obtain variable and the parameter relevant, as mb_type, mb_skip_flag, sub_mb_type, mvd_10, mvd_11, ref_idx_10, ref_idx_11, mb_qp_delta, intra_chroma_pred_mode etc. with macro block decoding;
Step 2: when obtaining decoding after the required parameter of decodings such as required current macro and adjacent macroblocks by step 1, because a macro block comprises the luminance block of a 16x16 and chrominance block Cb and the Cr of two 8x8, so following order according to colourity after the first brightness is decoded to macro block.
Luminance block is decoded:
Carrying out luminance block when decoding, because luminance block comprises 16x16 pixel, is basic decoding unit with the 4x4 piece during decoding, promptly a 4x4 piece is decoded at every turn, is divided into the decoding of finishing a 16x16 luminance block for 16 times.In each 16x16 luminance block, each 4x4 piece has a DC coefficient, and 16 4x4 luminance block have 16 DC coefficient; During decoding at first direct current (DC) coefficient to 16 brightness decode, then the ac coefficient (AC) of 16 4x4 luminance block is decoded, each 4x4 ac coefficient piece has 15 ac coefficients.
Chrominance block is decoded:
After the 16x16 luminance block of having decoded, then to two 8x8 chrominance block decodings, same is basic decoding unit with the 4x4 piece, the same DC coefficient of decoding earlier.Each 8x8 chrominance block has 4 DC coefficient, finish decoding respectively to the DC coefficient of Cb and Cr piece after, again the ac coefficient of Cb and Cr piece is decoded, all be Cr piece behind the first Cb piece to the decoding order of two chrominance block.
Step 3: finish after the decoding to 16x16 luminance block and Cb and Cr chrominance block, the data of a macro block just decoding are over, and can continue the decoding of next macro block.
Below with reference to Fig. 4 a brightness 4x4 piece or colourity 4x4 piece residual error coefficient are carried out the process of CAVLC decoding explanation CAVLC residual error decoding:
Step 401: determining that the coefficient that will decode is luminance factor or chromaticity coefficent, is DC coefficient or ac coefficient;
Step 402: if the colourity DC coefficient is 1, parameter nC=1 is that the colourity DC coefficient is decoded, otherwise nC=(nA+nB)/2, nA wherein, nB represent respectively the decoded residual piece the left side and directly over the number of nonzero coefficient in the reference block.
Step 403: because CAVLC is variable-length encoding, employing be not the code table of fixing, therefore, which code table is the value of the nC that obtains according to step 2 adopt when determining to decode, and is to adopt variable length code table or fixed length code table or do not use code table.
Step 404: table look-up and find the solution numtrailingones, wherein numtrailingones represents the coefficient that trails, i.e. 1 and-1 the number (can comprise 0 between 1 and-1) that begins to run into continuously forward from last high frequency residual error coefficient, the value of numtrailingones is no more than 3.The effect of numtrailingones is, when encoding, coefficient for 4x4 piece medium-high frequency part mostly is 1,0 ,-1 situation is in the time of coding, can only write down 1,-1 number and sign bit get final product, and need not will whole coefficient value level to be encoded as other residual error coefficient, have improved code efficiency.
Step 405: the coefficient symbols to hangover coefficient trailingones part is decoded, and obtains the value of the amplitude level of trailingones part, 1 or-1.
Step 406: remove the value level of other nonzero coefficients outside the hangover coefficient, add the level value of the hangover coefficient part that obtains in the step 5, obtain the zero coefficient values level[i in the 4x4 piece], the I here represents the sequence number of amplitude level.
Step 407: try to achieve the value of TotalZeros according to corresponding code table, TotalZeros represents the number of last nonzero coefficient leading zero among the 4x4.
Step 408: ask each nonzero coefficient to get the value of run, run represents the number of each nonzero coefficient leading zero, uses run[i respectively] expression, wherein i is the sequence number of nonzero coefficient level.
Step 409: finish: according to the level[i that obtains previously], run[i] value just can recover the residual error coefficient value of 16 4x4 pieces from first coefficient of low frequency part.
Illustrate numtrailingones below, numcoeff, TotalZeros, level[j], run[j] implication: 16 residual error coefficients that are a 4x4 piece as shown in Figure 7: numtrailingones=3 here, numcoeff=6, TotalZeros=10, level[j], run[j] value indicate in the drawings.Symbol i wherein represents the sequence number of residual error coefficient in the 4x4 piece, level[j], run[j] in symbol j represent nonzero coefficient level[j] and zero stroke run[j] sequence number.
A macro block in the sheet data is carried out the flow process of CABAC decoding below with reference to Fig. 5 explanation:
Step 1: context model and probability interval are carried out initialization; CABAC is adaptive binary arithmetic coding, thus be all must carry out initialization earlier to its context model and probability interval in decoding or when coding, in the time of could guaranteeing decoding when encoding use be identical context model and probability interval;
Step 2: begin to other syntactic elements beyond the residual error coefficient, as mb_type, sub_mb_type, motion vector mvd_10, decodings such as mvd_11, and find the solution the macroblock parameters that will use in the residual error decoding, because this part need take more ground hardware resource, so adopt the mode of software to finish here;
Step 3 a: following residual error macro block is decoded; A macro block comprises the luminance block of a 16x16 and chrominance block Cb and the Cr of two 8x8, and the decoding order with CAVLC is the same herein, still according to the order of colourity after the first brightness macro block is decoded;
Step 4: with 4x4 piece or 8x8 piece is that base unit is decoded to brightness.If DC coefficient is arranged, earlier the brightness DC coefficient is decoded, altogether 16 brightness dc coefficients; Be base unit with the 4x4 piece then, remaining brightness ac coefficient is decoded, totally 16 4x4 ac coefficient pieces; If have only ac coefficient, be that base unit is decoded to ac coefficient directly with 4x4 piece or 8x8 piece.So just finished the decode procedure of luminance block;
Step 5: the order according to Cr piece behind the Cb of AC coefficient elder generation behind the first DC coefficient is decoded to two chrominance block Cb and Cr piece, separate the DC coefficient of Cb and Cr piece earlier, and then separate the AC coefficient of Cb and Cr piece, each 8x8 chrominance block obtains 4 DC coefficients and 60 AC coefficients altogether;
Step 6: continue to separate next macro block.
Is the decode procedure that example illustrates CABAC below with reference to Fig. 6 to separate a 4x4 residual error data piece:
Step 601: the value according to sign coded_block_flag determines whether needs are decoded to this 4x4 piece.If coded_block_flag=0 represents that coefficient is zero entirely in this 4x4 piece,, when coded_block_flag=1, carry out next step so needn't decode;
Step 602: the amplitude coeffLevel[i that calculates nonzero coefficient in the 4x4 piece], the order from the low frequency to the high frequency is represented the label of coefficient with i;
Step 603: the coeffLevel[i that calculates nonzero coefficient] absolute value abs (coeffLevel[i]);
Step 604: the symbol sign that calculates nonzero coefficient;
Step 605~606: the value that determines nonzero coefficient by the symbol of the top nonzero coefficient that obtains;
Step 607: size and positional information according to existing residual error coefficient, add symbolic information, 16 residual error coefficients of 4x4 piece are recovered, obtain the value of 16 residual error coefficients of 4x4 piece;
The said software mode of the present invention is meant the mode of utilizing embedded cpu to replace hardware circuit to carry out computing, rather than simple finger is realized some computing function in the entropy decoding with computer software.
The used example of the present invention just is used for a kind of of decoding function who is supported in the above-mentioned decoder explained; do not represent invention which is intended to be protected to only limit to this; mentioned method and structure among all employing the present invention; perhaps adopt replacement scheme to some part identical function; all at protection range of the presently claimed invention, the technical staff who is engaged in the industry is understood that this.