Changeset 13

Show
Ignore:
Timestamp:
07/24/06 20:45:19 (2 years ago)
Author:
gbooker
Message:

Even if the data is packetized, it is possible to be badly packetized, so run our enforcing rules on the data.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/A52/ACShepA52Decoder.cpp

    r8 r13  
    8484        firstInput = true; 
    8585         
     86        remainingBytesFromLastFrame = 0; 
     87        beginningOfIncompleteHeaderSize = 0;     
     88         
    8689        //fprintf(stderr, "ACShepA52Decoder::Constructor: Number of input formats supported: %lu\n", GetNumberSupportedInputFormats()); 
    8790        //fprintf(stderr, "ACShepA52Decoder::Constructor: Number of output formats supported: %lu\n", GetNumberSupportedOutputFormats()); 
     
    134137         
    135138        firstInput = true; 
     139        remainingBytesFromLastFrame = beginningOfIncompleteHeaderSize = 0; 
    136140         
    137141        //      let our base class clean up it's internal state 
     
    759763} 
    760764 
     765UInt32 ACShepA52Decoder::AppendPacket(const void* inInputData, 
     766                                                                          UInt32 inInputDataSize, 
     767                                                                          UInt32 bufferStartOffset, 
     768                                                                          UInt32 offset, 
     769                                                                          UInt32& packetSize) 
     770{ 
     771        UInt32 bytes_to_read = 0; 
     772        packetSize = 0; 
     773        offset --; 
     774        while(bytes_to_read == 0) 
     775        { 
     776                int packetFlags; 
     777                int packetSampleRate; 
     778                int packetBitrate; 
     779                 
     780                offset++; 
     781                if(offset + 7 > inInputDataSize) 
     782                        break; 
     783                bytes_to_read = a52_syncinfo(static_cast<const uint8_t*>(inInputData) + bufferStartOffset + offset, &packetFlags, &packetSampleRate, &packetBitrate); 
     784        } 
     785        if(bytes_to_read == 0) 
     786                //Broke out of previous loop 
     787                return offset; 
     788         
     789        packetSize = bytes_to_read; 
     790        if(bytes_to_read + offset > inInputDataSize) 
     791                return offset; 
     792        UInt32 bytes_can_copy = GetInputBufferByteSize() - GetUsedInputBufferByteSize(); 
     793        if(bytes_to_read > bytes_can_copy) 
     794                return offset; 
     795         
     796        ACSimpleCodec::AppendInputBuffer(inInputData, bufferStartOffset + offset, bytes_to_read); 
     797        // fprintf(stderr, "ACShepA52Codec::AppendInputData: Copied in %ld:%ld new bytes\n", bytes_to_read, offset); 
     798         
     799        return offset+bytes_to_read; 
     800} 
    761801 
    762802void ACShepA52Decoder::AppendInputData(const void* inInputData, 
     
    786826                                break; 
    787827 
    788                         ACSimpleCodec::AppendInputBuffer(inInputData, inPacketDescription[packets].mStartOffset, packetSize); 
     828                        //Last frame was incommplete, complete it first. 
     829                        if(beginningOfIncompleteHeaderSize != 0) 
     830                        { 
     831                                if(packetSize + beginningOfIncompleteHeaderSize > 7) 
     832                                { 
     833                                        //lets complete the header and party 
     834                                        for(UInt32 i=0; i<beginningOfIncompleteHeaderSize; i++) 
     835                                        { 
     836                                                Byte newHeader[7]; 
     837                                                memcpy(newHeader, beginningOfIncompleteHeader + i, beginningOfIncompleteHeaderSize-i); 
     838                                                memcpy(newHeader+beginningOfIncompleteHeaderSize-i, inInputData, 7-beginningOfIncompleteHeaderSize+i); 
     839                                                 
     840                                                int packetFlags; 
     841                                                int packetSampleRate; 
     842                                                int packetBitrate; 
     843                                                 
     844                                                int bytes_to_read = a52_syncinfo(newHeader, &packetFlags, &packetSampleRate, &packetBitrate); 
     845                                                if(bytes_to_read != 0) 
     846                                                { 
     847                                                        //First add the stuff stuck in the buffer 
     848                                                        beginningOfIncompleteHeaderSize -= i; 
     849                                                        ACSimpleCodec::AppendInputBuffer(static_cast<const void *>(beginningOfIncompleteHeader), (UInt32)i, beginningOfIncompleteHeaderSize); 
     850                                                        //Now, let the below handle the rest 
     851                                                        remainingBytesFromLastFrame = bytes_to_read - beginningOfIncompleteHeaderSize; 
     852                                                } 
     853                                        } 
     854                                } 
     855                                beginningOfIncompleteHeaderSize = 0; 
     856                        } 
     857                         
     858                        UInt32 bytes_to_read = remainingBytesFromLastFrame; 
     859                        if(bytes_to_read > packetSize) 
     860                        { 
     861                                bytes_to_read = packetSize; 
     862                                remainingBytesFromLastFrame -= packetSize; 
     863                        } 
     864                        else 
     865                                remainingBytesFromLastFrame = 0; 
     866                        if(bytes_to_read != 0) 
     867                        { 
     868                                ACSimpleCodec::AppendInputBuffer(inInputData,inPacketDescription[packets].mStartOffset, bytes_to_read); 
     869                        } 
     870                         
     871                        UInt32 offset = bytes_to_read; 
     872                         
     873                        UInt32 frameSize = 0; 
     874                        while(offset < packetSize) 
     875                        { 
     876                                UInt32 offsetIn = offset; 
     877                                offset = AppendPacket(inInputData, packetSize, inPacketDescription[packets].mStartOffset, offset, frameSize); 
     878                                if(offsetIn == offset) 
     879                                        break; 
     880                        } 
     881                        if(offset != packetSize) 
     882                        { 
     883                                if(packetSize - offset < 7) 
     884                                { 
     885                                        //Incomplete header 
     886                                        beginningOfIncompleteHeaderSize = packetSize - offset; 
     887                                        memcpy(beginningOfIncompleteHeader, static_cast<const uint8_t*>(inInputData) + offset + inPacketDescription[packets].mStartOffset, beginningOfIncompleteHeaderSize); 
     888                                } 
     889                                else if(frameSize != 0) 
     890                                { 
     891                                        UInt32 availableInFrame = packetSize - offset; 
     892                                        ACSimpleCodec::AppendInputBuffer(inInputData, offset, availableInFrame); 
     893                                        remainingBytesFromLastFrame = frameSize - availableInFrame; 
     894                                } 
     895                        } 
    789896                        packets++; 
    790897                } 
     
    795902                UInt32 offset = 0; 
    796903        while (packet < ioNumberPackets) { 
    797                         UInt32 bytes_to_read = 0; 
    798                         offset --; 
    799                         while(bytes_to_read == 0) 
    800                         { 
    801                                 int packetFlags; 
    802                                 int packetSampleRate; 
    803                                 int packetBitrate; 
    804  
    805                                 offset++; 
    806                                 if(offset + 7 > ioInputDataByteSize) 
    807                                         break; 
    808                                 bytes_to_read = a52_syncinfo(static_cast<const uint8_t*>(inInputData) + offset, &packetFlags, &packetSampleRate, &packetBitrate); 
    809                         } 
    810                         if(bytes_to_read == 0) 
    811                                 //Broke out of previous loop 
     904                        UInt32 packetSize = 0; 
     905                        offset = AppendPacket(inInputData, ioInputDataByteSize, 0, offset, packetSize); 
     906                        if(packetSize != 0) 
     907                                packet++; 
     908                        else 
    812909                                break; 
    813  
    814                         if(bytes_to_read + offset > ioInputDataByteSize) 
    815                                 break; 
    816                         bytes_can_copy = GetInputBufferByteSize() - GetUsedInputBufferByteSize(); 
    817                         if(bytes_to_read > bytes_can_copy) 
    818                                 break; 
    819                          
    820                         ACSimpleCodec::AppendInputBuffer(inInputData, offset, bytes_to_read); 
    821                         // fprintf(stderr, "ACShepA52Codec::AppendInputData: Copied in %ld:%ld new bytes\n", bytes_to_read, offset); 
    822  
    823                         offset += bytes_to_read; 
    824                         packet++; 
    825910                } 
    826911                ioInputDataByteSize = offset; 
  • trunk/A52/ACShepA52Decoder.h

    r1 r13  
    6262        UInt32  Process32BitSignedInts(void *output_data_untyped, UInt32 output_data_offset, sample_t *output_samples, int a52_flags); 
    6363        UInt32  ProcessFloats(void *output_data_untyped, UInt32 output_data_offset, sample_t *output_samples, int a52_flags); 
    64          
     64        UInt32  AppendPacket(const void* inInputData, UInt32 inInputDataSize, UInt32 bufferStartOffset, UInt32 offset, UInt32& packetSize);             
    6565         
    6666        a52_state_t *decoder_state; 
     
    7373         
    7474        bool firstInput; 
     75         
     76        //For badly packetized data 
     77        UInt32  remainingBytesFromLastFrame; 
     78        Byte    beginningOfIncompleteHeader[6]; 
     79        UInt32  beginningOfIncompleteHeaderSize; 
    7580}; 
    7681