Summary of the invention
The present invention is directed to and seek initial code operation bigger technical problem consuming time in the prior art in the audio/video decoding course, a kind of video/audio decoding method that can seek initial code fast is provided, improved speed that information is obtained in the audio/video flow and efficient effectively.
For solving the problems of the technologies described above, the present invention is achieved by the following technical solutions:
A kind of video/audio decoding method, comprise the process of seeking initial code, described initial code adds that by the start code prefix of N byte initial code value constitutes, the set of each all value of byte of described start code prefix is Q, described N is a natural number, it is characterized in that the process of described searching initial code is to be the cycle audio/video flow to be searched for judgement with N byte, to seek the process of start code prefix.
Specifically, in the process of described searching initial code, may further comprise the steps:
A, be the cycle, judge the size of current byte value with N byte;
If the current byte value of b belongs to set Q, then enter the deterministic process of concrete start code prefix; Otherwise change the deterministic process of N of a following one-period byte over to.
Wherein, in described concrete start code prefix deterministic process, comprise following spreadability deterministic process:
B1, internal blas amount k of definition, the initial value of k is 1;
B2, judge whether have at least to belong to a set Q in N-k byte value of k byte value in current byte front and current byte back, if, execution in step b3 then; Otherwise, change the deterministic process of N of a following one-period byte over to;
B3, internal blas amount k value add 1;
B4, whether judge the k value less than N, if go to step b2; Otherwise, carry out the process of byte-by-byte judgement start code prefix.
Further, the described byte-by-byte process of judging start code prefix comprises whether continuously arranged N byte value that N byte-by-byte judgement comprises current byte equals the value of a start code prefix corresponding N byte respectively, if once byte-by-byte judgement is set up, judge that then comprising current byte constitutes start code prefix interior N byte; If all N time byte-by-byte judgement all is false, judge that then comprising current byte does not constitute start code prefix in an interior continuously arranged N byte.Because constituting N byte of start code prefix may be from current byte, also may be certain byte of front or certain byte of its back from current byte,, guarantee all possible situation is all judged so need byte-by-byte judgement N time.When carrying out byte-by-byte judgement, at first determine to constitute in the buffering area position of N byte of start code prefix, respectively this N byte value is compared with N byte of known start code prefix in order then, be first byte value in N the byte in the buffering area and first byte value comparison of known start code prefix, second byte value comparison of second byte value in N the byte in the buffering area and known start code prefix, until comparison to last byte value.
Further, described start code prefix comprises three bytes, is specially 0x000001; Be in the process of the cycle start code prefix being judged with three bytes, if current byte value smaller or equal to 1, then enters concrete start code prefix deterministic process; Otherwise three bytes that change following one-period over to are judged.
Start code prefix is under the situation of three bytes, comprises the steps: in concrete start code prefix deterministic process
Whether have a byte value at least smaller or equal to 1 in second byte in back of c1, first byte of front of judging current byte and current byte, if, execution in step c2; Otherwise three bytes that change following one-period over to are judged;
C2: judge in first byte of back of second byte in front of current byte and current byte whether have a byte value at least, if carry out the process of byte-by-byte judgement start code prefix smaller or equal to 1; Otherwise three bytes that change following one-period over to are judged.
Further again, in the process of the byte-by-byte judgement start code prefix of described step c1, comprise the judgement of three kinds of conditions: judge that whether start code prefix is from current byte; Judge that start code prefix is whether from first byte of front of current byte; Judge that start code prefix is whether from second byte in front of current byte.
Described start code prefix from the condition that current byte begins to satisfy is: current byte value is 0, and first byte value of the back of current byte is 0, and second byte value in the back of current byte is 1; Described start code prefix from the condition that first byte of front of current byte begins to satisfy is: current byte value is 0, and first byte value of the front of current byte is 0, and first byte value of the back of current byte is 1; Described start code prefix from the condition that second byte in front of current byte begins to satisfy is: current byte value is 1, and first byte value of the front of current byte is 0, and second byte value in the front of current byte is 0.
Further again, further comprising the steps of before described step a:
A1, in buffering area, determine two pointers: read pointer R and write pointer W, R points to current reading location, and W points to writing position;
A2, whether judge read pointer R less than W-N, if, execution in step a then; Otherwise, wait for that transfer of data is to buffering area.
Further again, in the process of described byte-by-byte judgement start code prefix, if comprising current byte does not constitute start code prefix in an interior continuously arranged N byte, then read pointer R adds N, and is back to step a2.
Preferably, above-mentioned video/audio decoding method be preferably applied to AVS, H.264 or in the audio/video decoding course such as MPEG.
Compared with prior art, advantage of the present invention and good effect are: audio/video decoding course of the present invention, when in buffering area, seeking initial code, the lower characteristics of ratio appear in the compositing characteristic and the initial code that have made full use of start code prefix in audio/video flow, the byte number N that byte-by-byte judgement start code prefix in the prior art is changed into start code prefix judges (N is a natural number) cycle, thereby greatly reduced and judged and to read the operation of chip external memory data consuming time, improve the matching problem of decoding speed in outer start code prefix recognition speed of sheet and the sheet, effectively improved speed that information is obtained in the audio/video flow and efficient.
Embodiment
Below in conjunction with accompanying drawing embodiments of the present invention are described in further detail.
At first, analyzing basic principle of the present invention, for the purpose of sake of clarity, is that example is specifically addressed with the start code prefix 0x000001 of three bytes.
Referring to Fig. 2, the scope that no symbol-byte can be expressed is from 0 to 255, and the start code prefix 0x000001 of three bytes only gets 0 and 1 by its value of byte, and promptly the set Q of each all value of byte of start code prefix is 0 and 1.With regard to ordinary circumstance, the probability that start code prefix occurs is 1/128.With three bytes is the cycle to seek start code prefix, if current byte value is less than or equal to 1, just enters concrete initial code and judges, otherwise skip to back three bytes.Like this, under 127/128 probability situation, save the time of judging, improved the matching problem of decoding speed in outer start code prefix recognition speed of sheet and the sheet.Analyze the situation of three judgement start code prefix 0x000001, R represents current byte location among Fig. 2, R-1 and R-2 represent second byte of first byte of current byte front and front respectively, and R+1 and R+2 represent second byte of first byte of current byte back and back respectively.The value that has all comprised current reading location R place under three kinds of estimate of situations if the value of reading location is not 0 or 1, does not promptly belong to set Q, can determine that immediately these three kinds of situations can not constitute start code prefix.So just can enter in the next judgement, and save the operation of reading the sheet external memory greatly with the fastest speed.Other byte can not play such effect separately, needs per two bytes to cooperate, and plays same effect.As R-2 among the figure and R+1, and R-1 and R+2.If the byte value of R-2 and R+1 is not 0 or 1, promptly not in set Q, can determine that these three kinds of situations can not constitute start code prefix yet.Byte for R-1 and R+2 is also similarly judged.Promptly increase following determining step: whether the byte value of judging R-1 and R+2 all greater than 1, if then skip to three bytes of following one-period; Otherwise whether the byte value of judging R-2 and R+1 all greater than 1, if then skip to three bytes of following one-period; Otherwise, enter concrete initial code and judge.The byte value of R-1 or R+2 has one, and to be less than or equal to 1 probability be 2/256+2/256, just 1/64; Equally, the byte value of R-2 or R+1 has one, and to be less than or equal to 1 probability also be 1/64, thereby the probability that enters concrete start code prefix deterministic process is (1/128) * (1/64) * (1/64), and is very low, so just further improved the efficient of identification initial code.
When utilizing algorithm of the present invention to seek initial code, main purpose is to find start code prefix.At first in buffering area, determine two pointers: read pointer R and write pointer W, R points to current reading location, and W points to writing position.Described start code prefix is a N byte, and N is a natural number; The set of forming each all value of byte of start code prefix is Q; Definition buf is the audio-video code stream buffering area, buf[R] the interior read pointer R byte value pointed of expression buffering area; Definition startcode is a start code prefix, startcode[i] expression N byte start code prefix in i byte value.The main program flow chart of seeking fast initial code in the video/audio decoding method proposed by the invention as shown in Figure 3, concrete steps are as follows:
Step S301: program begins.
Step S302: the stand by tone video stream data is transferred in the buffering area.
Step S303: whether judge read pointer R less than W-N, judge that promptly whether byte number is greater than N in the buffering area.If byte number is not more than N in the buffering area, goes to step S 302 and continue to wait for transfer of data; Otherwise continuing to carry out, program judges.Because initial code is made up of the start code prefix of N byte and the initial code value of several bytes,, can not constitute initial code if having only the N byte in the buffering area.
Step S304: the value buf[R that judges the current byte that read pointer R is pointed] whether belong to set Q, if belong to, continue execution in step S305; Otherwise go to step S312.
Step S305: define an internal blas amount k, and tax k value is 1.
Step S 306: the value buf[R-k that judges k the byte in current byte front] with the value buf[R+N-k of N-k the byte in current byte back] in whether have at least one to belong to and gather Q, if, execution in step S307; Otherwise go to step S312.
Step S307: internal blas amount k value adds 1.
Step S308: whether judge the k value less than N, if go to step S306; Otherwise, execution in step S309.
Step S309: byte-by-byte searching start code prefix.
Step S310: judge whether to search out start code prefix, if find start code prefix, execution in step S311; Otherwise, go to step S312.
Step S311: handle initial code, go to step S313 then.
Step S312: read pointer R adds N, is back to step S303.
Step S313: main program finishes.
Said process is for seeking a cyclic process of initial code, and in the actual application, the data of depositing in the buffering area may comprise multistage information, thereby have a plurality of initial codes.After searching out an initial code, can continue in buffering area, to carry out above-mentioned steps, to search out the initial code that all exist.
The process of the byte-by-byte searching start code prefix of above-mentioned steps S309 comprises that byte-by-byte judgement comprises the process whether continuously arranged N of a current byte byte value equals N byte value of start code prefix respectively.Concrete execution in step is shown in the subroutine flow chart of the byte-by-byte searching start code prefix of Fig. 4:
Step S401: the subprogram flow process begins.
Step S402: define an internal blas amount j, and initialize is N.
Step S403: define a cyclic variable i, the i initial value is 1.
Step S404: the value buf[R-j+i that judges (R-j+i) individual byte] whether with the start code prefix of N byte in i byte value startcode[i] equate, if, execution in step S405 then; Otherwise go to step S408.
Step S405: cyclic variable i value adds 1.
Step S406: whether judge i smaller or equal to N, if, go to step S404, proceed the judgement of byte value; Otherwise, go to step S407.
Step S407: search out start code prefix, go to step S411.
Step S408: internal blas amount j value subtracts 1.
Step S409: whether judge the j value more than or equal to 1,, go to step S403 if more than or equal to 1; Otherwise, execution in step S410.
Step S410: judge not search out start code prefix, go to step S411.
Step S411: the subprogram flow process finishes.
Described respectively above under the situation that start code prefix is made of N byte, how to have realized seeking fast in the video/audio decoding method of the present invention the flow process of initial code.Common initial code all is to adopt the start code prefix 0x000001 of one three byte to add that the initial code value of a byte constitutes in the present Audio Video coding Standard, for this reason, in conjunction with Fig. 5 and Fig. 6, introduce in detail when start code prefix is made of three byte 0x000001, realize that the present invention seeks the flow process of initial code fast.
Figure 5 shows that the main program flow chart of seeking initial code when start code prefix is three bytes fast, concrete steps are as follows:
Step S501: program begins.
Step S502: the stand by tone video stream data is transferred in the buffering area.
Step S503: whether judge read pointer R less than W-3, judge that promptly whether byte number is greater than 3 in the buffering area.If byte number is not more than 3 in the buffering area, goes to step S502 and continue to wait for transfer of data; Otherwise continuing to carry out, program judges.Because initial code is made up of the start code prefix of 3 bytes and the initial code value of a byte,, can not constitute initial code if having only 3 bytes in the buffering area.
Step S504: the value buf[R that judges the current byte that read pointer R is pointed] whether smaller or equal to 1,, continue execution in step S505 if smaller or equal to 1; Otherwise go to step S510.Because start code prefix is 0x000001, the set Q of each all value of byte is 0 and 1, whether can determine whether to belong to set Q smaller or equal to 1 so judge byte value.
Step S505: the value buf[R-1 that judges first byte of current byte front] with the value buf[R+2 of second byte in current byte back] in whether have one at least smaller or equal to 1, if, execution in step S506; Otherwise go to step S510.
Step S506: the value buf[R-2 that judges second byte in current byte front] with the value buf[R+1 of first byte of current byte back] in whether have one at least smaller or equal to 1, if, execution in step S507; Otherwise go to step S510.
Step S507: three byte-by-byte searching start code prefix 0x000001.
Step S508: judge whether to search out start code prefix 0x000001, if find start code prefix, execution in step S509; Otherwise, go to step S510.
Step S509: handle initial code, and go to step S511.
Step S510: read pointer R adds 3, is back to step S503.
Step S511: main program finishes.
Can have three kinds of situations during above-mentioned byte-by-byte searching start code prefix: start code prefix is three bytes that begin from current byte; Start code prefix is three bytes that first byte of front from current byte begins; Start code prefix is three bytes that second byte in front from current byte begins.Need carry out the judgement of three kinds of situations one by one.The concrete subprogram flow process of judging start code prefix as shown in Figure 6, its step is as follows:
Step S601: subprogram begins.
Step S602: judge current byte value buf[R] whether be 0, if be 0, illustrate that initial code may be from current byte, perhaps from byte in front of current byte, go to step S603 and continue to judge; If be not 0, illustrate that current byte value is 1, then initial code can only be second byte in front from current byte, goes to step S609 then and further judges.
Step S603: back first byte value buf[R+1 that judges whether current byte] whether be 0, if be 0, illustrate that start code prefix can only be from current byte, goes to step S604 then and further judges; If be not 0, illustrate that start code prefix can only be first byte of front from current byte, and then go to step S606 and further judge.
Step S604: second the byte value buf[R+2 in back that judges current byte] whether be 1, if 1, then the decidable start code prefix is made up of continuous three bytes that current byte R begins; If be not 1, judge that then comprising current byte does not constitute start code prefix in three interior bytes, goes to step S612.
Step S605: judge that start code prefix from current byte R, goes to the step S509 of main program shown in Figure 5.
Step S606: back first byte value buf[R+1 that judges current byte] whether be 1, if be 1, go to step S607 and further judge; If be not 1, judge that then comprising current byte does not constitute start code prefix in three interior bytes, goes to step S612.
Step S607: front first byte value buf[R-1 that judges current byte] whether be 0, if 0, then the decidable start code prefix is made up of continuous three bytes that current byte front first byte R-1 begins; If be not 1, judge that then comprising current byte does not constitute start code prefix in three interior bytes, goes to step S612.
Step S608: judge that start code prefix from current byte front first byte R-1, goes to the step S509 of main program shown in Figure 5.
Step S609: front first byte value buf[R-1 that judges current byte] whether be 0, if 0, go to step S610 and proceed to judge; Otherwise go to step S612.
Step S610: second the byte value buf[R-2 in front that judges current byte] whether be 0, if 0, go to step S611; Otherwise go to step S612.
Step S611: judge that start code prefix from second the byte R-2 in current byte front, goes to the step S509 of main program shown in Figure 5.
Step S612: do not find start code prefix 0x000001, go to the step S510 of main program shown in Figure 5, continue the judgement of back byte and seek.
Certainly, it is the situation that unit constitutes initial code that the method for above-mentioned quick searching start code prefix is not limited to the byte, also goes for constituting with other units such as position or words the situation of initial code.
Should be understood that; above-mentioned explanation is not to be limitation of the present invention; the present invention also is not limited in above-mentioned giving an example, and modification, distortion, interpolation or replacement that those skilled in the art are made in essential scope of the present invention also should belong to protection scope of the present invention.