Abstract:
A method for auto-detecting a frame header is provided. By searching and comparing content of input frames and predetermined sync words, decoding efficiency is increased and the probability of incurring program errors is reduced. Once decoding errors occur, an auto-recovery mechanism soon recovers the audio decoding system operation.

Description:
CROSS REFERENCE TO RELATED PATENT APPLICATION 
       [0001]    This patent application is based on Taiwan, R.O.C. patent application No. 098124658 filed on Jul. 22, 2009. 
       FIELD OF THE INVENTION 
       [0002]    The present invention relates to the Advance Audio Coding (AAC) technology, and more particularly, to an auto detection method for an AAC frame header. 
       BACKGROUND OF THE INVENTION 
       [0003]    MP3 has prevailed worldwide. Two important audio compression standards, the AAC (MPEG-2) and the latest HE-AAC (high-efficiency AAC) (MPEG-4) standards, based on development of the MPEG technology, are further developed. According to the HE-AAC techniques applying the AAC techniques and the spectral band replication (SBR) techniques, compression efficiency increases by at least 30% from that of the AAC techniques. 
         [0004]      FIG. 1  is a diagram showing a relationship among a transport stream (TS), an audio packetized elementary stream (PES) and a frame. An AAC bit stream is based on frames, each comprising a frame header and a frame raw data block. A common frame raw data block comprises 2048, 1024, 512 or 256 time-domain sampling points. In the AAC standard, an audio data transport stream (ADTS) header is defined for each frame. With respect to the HE-AAC standard, a low-overhead audio stream (LOAS) header or a low-overhead MPEG-4 audio transport multiplex (LATM) header is defined for each frame to record associated decoding information for the frame. The frame is encapsulated into the audio PES. The audio PES is further encapsulated into TS packets for transmission in noisy environment. 
         [0005]    A common TS bit stream, possibly being a mix of the foregoing two audio standards, is received and followed by its TS packets parsed by a stream information parser at a receiving end. When a value in a stream type field of a TS packet is 0xF (e.g., a value in a stream type field in a program map table (PMT)), it indicates that this audio PES supports the MPEG-2 AAC audio compression standard and embeds an ADTS header therein. A conventional stream information parser fills a sync word 0xFFF of the ADTS header into an audio decoder before decoding, so that an AAC decoder identifies the ADTS header or an ADTS frame according to a stream of input frames. Moreover, when a value in the stream type field of the TS packet equals 0x11, the audio PES supports the MPEG-4 HE-AAC audio compression standard and a frame inside the audio PES possesses a LOAS header or a LATM header. A conventional stream information parser loads a sync word 0x2B7 of the LOAS or LATM header into an AAC decoder before decoding, so that the audio decoder identifies a LOAS frame or LATM frame in the input stream. 
         [0006]    However, in complicated software and hardware operation flow, a decoding error of an AAC decoder may occur even if only one of the above steps goes wrong. For example, supposing the stream information parser or an upper layer application program mistakenly loads incorrect sync words into the AAC decoder, or a value in the stream type field of the TS packet does not match with a sync word of a practical audio header, decoding errors may occur such that even a channel may not produce any sound until a user switches the channel. 
       SUMMARY OF THE INVENTION 
       [0007]    In view of the foregoing problem, one object of the present invention is to provide a method for auto detecting a frame header. In this method, decoding efficiency of a system is increased and the probability of incurring program errors is reduced by searching and comparing the content of predetermined sync words of input frames. 
         [0008]    To achieve the foregoing object, the method for auto detecting a frame header according to the invention is applied to a receiving end device for receiving a stream of frames, with each of the frames comprising a frame header and a raw data block. The auto detection method comprises receiving an input frame; correspondingly parsing and audio decoding the input frame when one of a plurality of header flags matches a first predetermined value; and setting a corresponding header flag as the first predetermined value, and parsing and audio decoding the input frame when a plurality of starting bits of the input frame match one of a plurality of sync words. 
         [0009]    The advantages and spirit related to the present invention can be further understood via the following detailed description and drawings. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0010]      FIG. 1  is a diagram of a relationship among a TS, an audio PES and a frame. 
           [0011]      FIG. 2A  and  FIG. 2B  are a flowchart of an auto detection method for a frame header in accordance with an embodiment of the present invention. 
       
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT 
       [0012]      FIG. 2A  and  FIG. 2B  are a flowchart of an auto detection method for a frame header in accordance with an embodiment of the present invention. In this embodiment, the AAC (MPEG-2) standard and the HE-AAC (MPEG-4) standard are simultaneously supported at a receiving end. Suppose that initial values of a LATM flag and an ADTS flag equal “0” (FALSE). During the entire audio decoding cycle, auto-detected mechanism is enabled. 
         [0013]    In Step S 202 , an input frame is received. 
         [0014]    In Step S 204 , it is determined whether the LATM flag is true. If true, Step S 216  is performed; otherwise, Step S 206  is performed. In this embodiment, a highest priority is given to the latest HE-AAC standard to be compared and performed. Persons having ordinary skill in the art may adjust the priority according to actual requirements. 
         [0015]    In Step S 206 , it is determined whether the ADTS flag is true. If true, Step S 220  is performed; otherwise, Step S 208  is performed. 
         [0016]    In Step S 208 , it is determined whether first 11 bits of the input frame equal 0x2B7. If true, S 210  is performed; otherwise, Step S 212  is performed. Step S 208  and Step S 212  search for sync words from the beginning of the input frame. In this embodiment, since the higher priority is given to the HE-AAC standard, the comparison starts with HE-AAC sync words 0x2B7 having a highest priority. 
         [0017]    In Step S 210 , the LATM flag is set as “1”. Preferably, either the LATM flag or the ADTS flag is set as “1”. 
         [0018]    In Step S 212 , it is determined whether the first 12 bits of the input frame equal 0xFFF. If true, Step S 214  is performed; otherwise, Step S 228  is performed. In this embodiment, when the caparison of the HE-AAC sync words 0x2B7 having the highest priority fails, AAC sync word 0xFFF having a lower priority is compared. 
         [0019]    In Step S 214 , the ADTS flag is set as “1”. 
         [0020]    In Step S 216 , a frame header of the input frame is parsed for an LATM header. When the sync words are searched, it is possible that the determined 0x2B7 or 0xFFF represent one portion of the frame raw data block but not the real frame header sync words. Therefore, comparison is further carried out to determine whether data after the determined 0x2B7 or 0xFFF comply with the format of the ADTS or LATM header. 
         [0021]    In Step S 218 , it is determined whether the frame header complies with the format of the LATM header. If true, Step S 224  is performed; otherwise, Step S 228  is performed. 
         [0022]    In Step S 220 , the frame header of the input frame is parsed for the ADTS header. 
         [0023]    In Step S 222 , it is determined whether the frame header complies with the format of the ADTS header. If true, Step S 224  is performed; otherwise, Step S 228  is performed. 
         [0024]    In Step S 224 , audio decoding is performed on the frame raw data block of the input frame to determine whether the frame raw data block can be accurately decoded according to frame header information obtained in Step S 216  or Step S 220 . 
         [0025]    In Step S 226 , it is determined whether the audio decoding is successful. If true, the flow returns to Step S 202 ; otherwise, Step S 228  is performed. 
         [0026]    In Step S 228 , first m bytes of the input frame are discarded, where m is a positive integer. 
         [0027]    In Step S 230 , the LATM flag and the ADTS flag are cleared as “0”, and the flow returns to Step S 202 . 
         [0028]    In Step S 228 , preferably, a value of m is determined according to a processing time of the receiving end device. For example, when sync words are being searched and compared, since the processing time of the receiving end device is short, a frontmost byte (m=1) of the input frame is discarded once the first 11 or 12 bits of the input frame do not match with two predetermined sync words. A next comparison begins with a next byte. Usually, one or two frames at a time, a sync word will be found. A person having ordinary skill in the art may appreciate that various approaches may be utilized to achieve same effect. For example, a comparison pointer is utilized as an index, and a value of the comparison pointer increments by 1 each time the comparison of sync words fails. Considering the worse case, when the comparison of sync words is successful and the frame header also complies with the LATM header or the ADTS header but audio decoding of the frame raw data block fails, a great amount of time has already consumed. At the same time, TS packets continuously enter the receiving end device. Since the receiving end device does not store the TS packets, a previous TS packet with decoding error is overwritten by a subsequent TS packet. Therefore, the receiving end device re-compares and re-searchs for sync words from a new TS packet. 
         [0029]    In this embodiment, comparing two types of sync words of the LATM header and the ADTS header is disclosed. In another embodiment, sync words of p (no less than 2) headers are compared and p header flags are programmed simultaneously. A priority sequence is defined to determine which sync word or header flag is to be first compared and first performed. Preferably, one of the p header flags is defined as “1”. In other words, when the first 11 or 12 bits of the current input frame match with the two sync words, a header flag having a highest priority is set according to the foregoing priority sequence, and the frame header is parsed and the frame raw data block is correspondingly decoded. 
         [0030]    In this embodiment, once a header sync word of the input frame is successfully found and the subsequent parsing and audio decoding are accomplished, a corresponding header flag is set as “1”. Accordingly, for subsequent frames, a comparison time of the header sync word is saved and decoding efficiency of a whole system is increased. Even if parsing errors or decoding errors occur, the header sync word can be identified in a short time to immediately recover normal operations via an auto recovery mechanism disclosed by the present invention. 
         [0031]    To sum up, an auto detection method for a frame header is provided according to the present invention. The method is applied to a receiving end device operating according to a plurality of header flags. The auto detection method comprises receiving an input frame by the receiving end device, the input frame comprising a frame header and a frame raw data block; correspondingly parsing and audio decoding the input frame when one of the header flags equals a first predetermined value; and setting a corresponding header flag as the first predetermined value and parsing and audio decoding the input frame when a plurality of starting bits of the input frame equal one of a plurality of sync words. 
         [0032]    While the invention has been described in terms of what is presently considered to be the most practical and preferred embodiments, it is to be understood that the invention needs not to be limited to the above embodiments. On the contrary, it is intended to cover various modifications and similar arrangements included within the spirit and scope of the appended claims which are to be accorded with the broadest interpretation so as to encompass all such modifications and similar structures.