Пример #1
0
        private bool findSPSandPPS()
        {
            /*
             *  SPS and PPS parameters are stored in the avcC box
             *  You may find really useful information about this box
             *  in the document ISO-IEC 14496-15, part 5.2.4.1.1
             *  The box's structure is described there
             *  <pre>
             *  aligned(8) class AVCDecoderConfigurationRecord {
             *		unsigned int(8) configurationVersion = 1;
             *		unsigned int(8) AVCProfileIndication;
             *		unsigned int(8) profile_compatibility;
             *		unsigned int(8) AVCLevelIndication;
             *		bit(6) reserved = ‘111111’b;
             *		unsigned int(2) lengthSizeMinusOne;
             *		bit(3) reserved = ‘111’b;
             *		unsigned int(5) numOfSequenceParameterSets;
             *		for (i=0; i< numOfSequenceParameterSets; i++) {
             *			unsigned int(16) sequenceParameterSetLength ;
             *			bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
             *		}
             *		unsigned int(8) numOfPictureParameterSets;
             *		for (i=0; i< numOfPictureParameterSets; i++) {
             *			unsigned int(16) pictureParameterSetLength;
             *			bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
             *		}
             *	}
             *  </pre>
             */
            try {
                // TODO: Here we assume that numOfSequenceParameterSets = 1, numOfPictureParameterSets = 1 !
                // Here we extract the SPS parameter
                fis.SkipBytes(7);
                spsLength = 0xFF & fis.ReadByte();
                sps       = new byte[spsLength];
                fis.Read(sps, 0, spsLength);
                // Here we extract the PPS parameter
                fis.SkipBytes(2);
                ppsLength = 0xFF & fis.ReadByte();
                pps       = new byte[ppsLength];
                fis.Read(pps, 0, ppsLength);
            } catch (IOException e) {
                return(false);
            }

            return(true);
        }
Пример #2
0
        private void parse(System.String path, long len)
        {
            ByteBuffer byteBuffer;
            long       sum = 0, newlen = 0;

            byte[]           buffer = new byte[8];
            Java.Lang.String name   = null;

            if (!path.Equals(""))
            {
                mBoxes.Add(path, (Long)(mPos - 8));
            }

            while (sum < len)
            {
                mFile.Read(buffer, 0, 8);
                mPos += 8; sum += 8;

                if (validBoxName(buffer))
                {
                    name = new Java.Lang.String(buffer, 4, 4);

                    if (buffer[3] == 1)
                    {
                        // 64 bits atom size
                        mFile.Read(buffer, 0, 8);
                        mPos      += 8; sum += 8;
                        byteBuffer = ByteBuffer.Wrap(buffer, 0, 8);
                        newlen     = byteBuffer.GetLong() - 16;
                    }
                    else
                    {
                        // 32 bits atom size
                        byteBuffer = ByteBuffer.Wrap(buffer, 0, 4);
                        newlen     = byteBuffer.GetInt() - 8;
                    }

                    // 1061109559+8 correspond to "????" in ASCII the HTC Desire S seems to write that sometimes, maybe other phones do
                    // "wide" atom would produce a newlen == 0, and we shouldn't throw an exception because of that
                    if (newlen < 0 || newlen == 1061109559)
                    {
                        throw new IOException();
                    }

                    Log.d(TAG, "Atom -> name: " + name + " position: " + mPos + ", length: " + newlen);
                    sum += newlen;
                    parse(path + '/' + name, newlen);
                }
                else
                {
                    if (len < 8)
                    {
                        mFile.Seek(mFile.FilePointer - 8 + len);
                        sum += len - 8;
                    }
                    else
                    {
                        int skipped = mFile.SkipBytes((int)(len - 8));
                        if (skipped < ((int)(len - 8)))
                        {
                            throw new IOException();
                        }
                        mPos += len - 8;
                        sum  += len - 8;
                    }
                }
            }
        }